NSI. */ if (precision < 0) precision = 1; /* default precision */ else flags &= ~FL_LEADZERO; /* 4. Check if data is 0; if so, turn off hex prefix */ if (number == 0) prefixlen = 0; /* 5. Convert data to ASCII -- note if precision is zero */ /* and number is zero, we get no digits at all. */ text.sz = &buffer.sz[BUFFERSIZE-1]; /* last digit at end of buffer */ while (precision-- > 0 || number != 0) { digit = (int)(number % radix) + '0'; number /= radix; /* reduce number */ if (digit > '9') { /* a hex digit, make it a letter */ digit += hexadd; } *text.sz-- = (char)digit; /* store the digit */ } textlen = (char *)&buffer.sz[BUFFERSIZE-1] - text.sz; /* compute length of number */ ++text.sz; /* text points to first digit now */ /* 6. Force a leading zero if FORCEOCTAL flag set */ if ((flags & FL_FORCEOCTAL) && (text.sz[0] != '0' || textlen == 0)) { *--text.sz = '0'; ++textlen; /* add a zero */ } } break; } /* At this point, we have done the specific conversion, and */ /* 'text' points to text to print; 'textlen' is length. Now we */ /* justify it, put on prefixes, leading zeros, and then */ /* print it. */ if (!no_output) { int padding; /* amount of padding, negative means zero */ if (flags & FL_SIGNED) { if (flags & FL_NEGATIVE) { /* prefix is a '-' */ prefix[0] = _T('-'); prefixlen = 1; } else if (flags & FL_SIGN) { /* prefix is '+' */ prefix[0] = _T('+'); prefixlen = 1; } else if (flags & FL_SIGNSP) { /* prefix is ' ' */ prefix[0] = _T(' '); prefixlen = 1; } } /* calculate amount of padding -- might be negative, */ /* but this will just mean zero */ padding = fldwidth - textlen - prefixlen; /* put out the padding, prefix, and text, in the correct order */ if (!(flags & (FL_LEFT | FL_LEADZERO))) { /* pad on left with blanks */ WRITE_MULTI_CHAR(_T(' '), padding, &charsout); } /* write prefix */ WRITE_STRING(prefix, prefixlen, &charsout); if ((flags & FL_LEADZERO) && !(flags & FL_LEFT)) { /* write leading zeros */ WRITE_MULTI_CHAR(_T('0'), padding, &charsout); } /* write text */ #ifndef WPRFLAG if (bufferiswide && (textlen > 0)) { wchar_t *p; int retval, count; char buffer[MB_LEN_MAX+1]; p = text.wz; count = textlen; while (count--) { retval = wctomb(buffer, *p++); if (retval <= 0) break; WRITE_STRING(buffer, retval, &charsout); } } else { WRITE_STRING(text.sz, textlen, &charsout); } #else if (!bufferiswide && textlen > 0) { char *p; int retval, count; p = text.sz; count = textlen; |