rev 515 - trunk/src
SVN User <[email protected]> Thu, 20 May 2004 13:04:43 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-20 13:04:39 -0400 (Thu, 20 May 2004)
New Revision: 515
Modified:
trunk/src/pr_snprintf.c
Log:
fixed %x in str.mod_()
Modified: trunk/src/pr_snprintf.c
===================================================================
--- trunk/src/pr_snprintf.c 2004-05-20 15:56:46 UTC (rev 514)
+++ trunk/src/pr_snprintf.c 2004-05-20 17:04:39 UTC (rev 515)
@@ -445,6 +445,38 @@
/*
+ * Convert num to a base X number where X is a power of 2. nbits determines X.
+ * For example, if nbits is 3, we do base 8 conversion
+ * Return value:
+ * a pointer to a string containing the number
+ *
+ * The caller provides a buffer for the string: that is the buf_end argument
+ * which is a pointer to the END of the buffer + 1 (i.e. if the buffer
+ * is declared as buf[ 100 ], buf_end should be &buf[ 100 ])
+ *
+ * As with conv_10, we have a faster version which is used when
+ * the number isn't quad size.
+ */
+static char *conv_p2(register u_wide_int num, register int nbits,
+ char format, char *buf_end, register int *len)
+{
+ register int mask = (1 << nbits) - 1;
+ register char *p = buf_end;
+ static const char low_digits[] = "0123456789abcdef";
+ static const char upper_digits[] = "0123456789ABCDEF";
+ register const char *digits = (format == 'X') ? upper_digits : low_digits;
+
+ do {
+ *--p = digits[num & mask];
+ num >>= nbits;
+ }
+ while (num);
+
+ *len = (int)(buf_end - p);
+ return (p);
+}
+
+/*
* Convert a floating point number to a string formats 'f', 'e' or 'E'.
* The result is placed in buf, and len denotes the length of the string
* The sign is returned in the is_negative argument (and is not placed
@@ -757,6 +789,31 @@
prefix_char = ' ';
break;
+ case 'x':
+ case 'X':
+ if (var_type == IS_QUAD) {
+ i_quad = pr_arg_int(ap); if_prerr_rtrn;
+ s = conv_10_quad(i_quad, 0, &is_negative,
+ &num_buf[NUM_BUF_SIZE], &s_len);
+ }
+ else {
+ if (var_type == IS_LONG)
+ i_num = (wide_int) pr_arg_int(ap); if_prerr_rtrn;
+ else if (var_type == IS_SHORT)
+ i_num = (wide_int) (short) pr_arg_int(ap); if_prerr_rtrn;
+ else
+ i_num = (wide_int) pr_arg_int(ap); if_prerr_rtrn;
+ s = conv_p2(i_num, 4, *fmt,
+ &num_buf[NUM_BUF_SIZE], &s_len);
+ }
+ FIX_PRECISION(adjust_precision, precision, s, s_len);
+ if (alternate_form && i_num != 0) {
+ *--s = *fmt; /* 'x' or 'X' */
+ *--s = '0';
+ s_len += 2;
+ }
+ break;
+
case 's':
s = pr_arg_string(ap);
if_prerr_rtrn;