- if (lng)
- {
- lvalue = va_arg(*arg, long);
- }
- else if (half)
- {
- lvalue = va_arg(*arg, short);
- }
- else
- {
- lvalue = va_arg(*arg, int);
- }
- ulvalue = (unsigned long)lvalue;
- if ((lvalue < 0) && ((specifier == 'd') || (specifier == 'i')))
- {
- neg = 1;
- ulvalue = -lvalue;
- }
- else
- {
- neg = 0;
- }
- if ((specifier == 'X') || (specifier == 'x') || (specifier == 'p'))
- {
- base = 16;
- }
- else if (specifier == 'o')
- {
- base = 8;
- }
- else
- {
- base = 10;
- }
- if (specifier == 'p')
- {
-#if defined(__OS2__) || defined(__PDOS__)
- precision = 8;
-#endif
-#if defined(__MSDOS__) && !defined(__PDOS__)
- precision = 9;
-#endif
- }
- x = 0;
- while (ulvalue > 0)
- {
- rem = (int)(ulvalue % base);
- if (rem < 10)
- {
- work[x] = (char)('0' + rem);
- }
- else
- {
- if ((specifier == 'X') || (specifier == 'p'))
- {
- work[x] = (char)('A' + (rem - 10));
- }
- else
- {
- work[x] = (char)('a' + (rem - 10));
- }
- }
- x++;
-#if defined(__MSDOS__) && !defined(__PDOS__)
- if ((x == 4) && (specifier == 'p'))
- {
- work[x] = ':';
- x++;
- }
-#endif
- ulvalue = ulvalue / base;
- }
- while (x < precision)
- {
- work[x] = '0';
- x++;
- }
- if (neg)
- {
- work[x++] = '-';
- }
- if (flagZero)
- {
- fillCh = '0';
- }
- else
- {
- fillCh = ' ';
- }
- y = x;
- if (!flagMinus)
- {
- while (y < width)
- {
- outch(fillCh);
- extraCh++;
- y++;
- }
- }
- if (flagHash && (toupper(specifier) == 'X'))
- {
- outch('0');
- outch('x');
- extraCh += 2;
- }
- x--;
- while (x >= 0)
- {
- outch(work[x]);
- extraCh++;
- x--;
- }
- if (flagMinus)
- {
- while (y < width)
- {
- outch(fillCh);
- extraCh++;
- y++;
- }
- }
- }
- else if (specifier == 's')
- {
- svalue = va_arg(*arg, char *);
- fillCh = ' ';
- if (precision > 1)
- {
- char *p;
-
- p = memchr(svalue, '\0', precision);
- if (p != NULL)
- {
- length = (int)(p - svalue);
- }
- else
- {
- length = precision;
- }
- }
- else
- {
- length = strlen(svalue);
- }
- if (!flagMinus)
- {
- if (length < width)
- {
- extraCh += (width - length);
- for (x = 0; x < (width - length); x++)
- {
- outch(fillCh);
- }
- }
- }
- for (x = 0; x < length; x++)
- {
- outch(svalue[x]);
- }
- extraCh += length;
- if (flagMinus)
- {
- if (length < width)
- {
- extraCh += (width - length);
- for (x = 0; x < (width - length); x++)
- {
- outch(fillCh);
- }
- }
- }
- }
- *formt = format;
- return (extraCh);
-}
-*/