/* The unnecessary pointer compare is there * to check for type safety (n must be 64bit)
*/ # define do_div(n,base) ({ \ unsignedint __base = (base); \ unsignedint __rem; \
(void)(((typeof((n)) *)0) == ((unsignedlonglong *)0)); \ if (((n) >> 32) == 0) { \
__rem = (unsignedint)(n) % __base; \
(n) = (unsignedint)(n) / __base; \
} else \
__rem = __div64_32(&(n), __base); \
__rem; \
})
#endif/* __powerpc64__ */
staticint skip_atoi(constchar **s)
{ int i, c;
for (i = 0; '0' <= (c = **s) && c <= '9'; ++*s)
i = i*10 + c - '0'; return i;
}
#define ZEROPAD 1 /* pad with zero */ #define SIGN 2 /* unsigned/signed long */ #define PLUS 4 /* show plus */ #define SPACE 8 /* space if plus */ #define LEFT 16 /* left justified */ #define SPECIAL 32 /* 0x */ #define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
staticchar * number(char * str, unsignedlonglong num, int base, int size, int precision, int type)
{ char c,sign,tmp[66]; constchar *digits="0123456789abcdefghijklmnopqrstuvwxyz"; int i;
if (type & LARGE)
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (type & LEFT)
type &= ~ZEROPAD; if (base < 2 || base > 36) return 0;
c = (type & ZEROPAD) ? '0' : ' ';
sign = 0; if (type & SIGN) { if ((signedlonglong)num < 0) {
sign = '-';
num = - (signedlonglong)num;
size--;
} elseif (type & PLUS) {
sign = '+';
size--;
} elseif (type & SPACE) {
sign = ' ';
size--;
}
} if (type & SPECIAL) { if (base == 16)
size -= 2; elseif (base == 8)
size--;
}
i = 0; if (num == 0)
tmp[i++]='0'; elsewhile (num != 0) {
tmp[i++] = digits[do_div(num, base)];
} if (i > precision)
precision = i;
size -= precision; if (!(type&(ZEROPAD+LEFT))) while(size-->0)
*str++ = ' '; if (sign)
*str++ = sign; if (type & SPECIAL) { if (base==8)
*str++ = '0'; elseif (base==16) {
*str++ = '0';
*str++ = digits[33];
}
} if (!(type & LEFT)) while (size-- > 0)
*str++ = c; while (i < precision--)
*str++ = '0'; while (i-- > 0)
*str++ = tmp[i]; while (size-- > 0)
*str++ = ' '; return str;
}
int vsprintf(char *buf, constchar *fmt, va_list args)
{ int len; unsignedlonglong num; int i, base; char * str; constchar *s;
int flags; /* flags to number() */
int field_width; /* width of output field */ int precision; /* min. # of digits for integers; max
number of chars for from string */ int qualifier; /* 'h', 'l', or 'L' for integer fields */ /* 'z' support added 23/7/1999 S.H. */ /* 'z' changed to 'Z' --davidm 1/25/99 */
for (str=buf ; *fmt ; ++fmt) { if (*fmt != '%') {
*str++ = *fmt; continue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.