X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdio%2Fvfprintf.c;h=8e24d795c55476f3336417aee1c7e769a7e5f1bc;hp=7bbc212a747be96ff791e614d9c115bc937b7bb8;hb=3c60673fd7479218b6f8069b848a1f5c2bd10114;hpb=0a5395faab237ba9008352b0f4bee9659bbd3d5f diff --git a/functions/stdio/vfprintf.c b/functions/stdio/vfprintf.c index 7bbc212..8e24d79 100644 --- a/functions/stdio/vfprintf.c +++ b/functions/stdio/vfprintf.c @@ -1,409 +1,285 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* $Id$ */ -int vfprintf( FILE * restrict stream, const char * restrict format, va_list ap ) { /* TODO */ }; +/* vfprintf( FILE *, const char *, va_list ) -/* PDPC code - unreviewed -{ - int ret; - - ret = vvprintf(format, arg, stream, NULL); - return (ret); -} - -{ - int fin = 0; - int vint; - char *vcptr; - int chcount = 0; - size_t len; - char numbuf[50]; - char *nptr; - - while (!fin) - { - if (*format == '\0') - { - fin = 1; - } - else if (*format == '%') - { - format++; - if (*format == 'd') - { - int neg = 0; + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ - vint = va_arg(arg, int); - if (vint < 0) - { - neg = 1; - vint = -vint; - } - nptr = numbuf; - do - { - *nptr++ = (char)('0' + vint % 10); - vint /= 10; - } while (vint > 0); - if (neg) - { - *nptr++ = '-'; - } - do - { - nptr--; - outch(*nptr); - chcount++; - } while (nptr != numbuf); - } - else if (*format == 's') - { - vcptr = va_arg(arg, char *); - if (fq == NULL) - { - len = strlen(vcptr); - memcpy(s, vcptr, len); - s += len; - chcount += len; - } - else - { - fputs(vcptr, fq); - chcount += strlen(vcptr); - } - } - else if (*format == 'c') - { - vint = va_arg(arg, int); - outch(vint); - chcount++; - } - else if (*format == '%') - { - outch('%'); - chcount++; - } - else - { - int extraCh; +#include +#include +#include - extraCh = examine(&format, fq, s, &arg, chcount); - chcount += extraCh; - if (s != NULL) - { - s += extraCh; - } - } - } - else - { - outch(*format); - chcount++; - } - format++; - } - return (chcount); -} +#ifndef REGTEST -static int examine(const char **formt, FILE *fq, char *s, va_list *arg, - int chcount) +int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg ) { - int extraCh = 0; - int flagMinus = 0; - int flagPlus = 0; - int flagSpace = 0; - int flagHash = 0; - int flagZero = 0; - int width = 0; - int precision = -1; - int half = 0; - int lng = 0; - int specifier = 0; - int fin; - long lvalue; - unsigned long ulvalue; - char *svalue; - char work[50]; - int x; - int y; - int rem; - const char *format; - int base; - int fillCh; - int neg; - int length; + /* TODO: This function should interpret format as multibyte characters. */ + struct _PDCLIB_status_t status; + status.base = 0; + status.flags = 0; + status.n = SIZE_MAX; + status.i = 0; + status.current = 0; + status.s = NULL; + status.width = 0; + status.prec = 0; + status.stream = stream; + va_copy( status.arg, arg ); - unused(chcount); - format = *formt; - /* processing flags */ - fin = 0; - while (!fin) + while ( *format != '\0' ) { - switch (*format) + const char * rc; + if ( ( *format != '%' ) || ( ( rc = _PDCLIB_print( format, &status ) ) == format ) ) { - case '-': flagMinus = 1; - break; - case '+': flagPlus = 1; - break; - case ' ': flagSpace = 1; - break; - case '#': flagHash = 1; - break; - case '0': flagZero = 1; - break; - default: fin = 1; - break; - } - if (!fin) - { - format++; + /* No conversion specifier, print verbatim */ + putc( *(format++), stream ); + status.i++; } else { - if (flagSpace && flagPlus) - { - flagSpace = 0; - } - if (flagMinus) - { - flagZero = 0; - } + /* Continue parsing after conversion specifier */ + format = rc; } } + va_end( status.arg ); + return status.i; +} - /* processing width */ - if (isdigit((unsigned char)*format)) - { - while (isdigit((unsigned char)*format)) - { - width = width * 10 + (*format - '0'); - format++; - } - } +#endif - /* processing precision */ - if (*format == '.') - { - format++; - precision = 0; - while (isdigit((unsigned char)*format)) - { - precision = precision * 10 + (*format - '0'); - format++; - } - } +#ifdef TEST +#include +#include +#include +#include <_PDCLIB_test.h> - /* processing h/l/L */ - if (*format == 'h') - { - half = 1; - } - else if (*format == 'l') - { - lng = 1; - } - else if (*format == 'L') - { - lng = 1; - } - else - { - format--; - } - format++; +static int testprintf( FILE * stream, size_t n, const char * format, ... ) +{ + int i; + va_list arg; + va_start( arg, format ); + i = vfprintf( stream, format, arg ); + va_end( arg ); + return i; +} - if (precision < 0) +int main( void ) +{ + FILE * buffer; + TESTCASE( ( buffer = fopen( "testfile", "w" ) ) != NULL ); + TESTCASE( testprintf( buffer, 100, "%hhd", CHAR_MIN ) == 4 ); + //TESTCASE( strcmp( buffer, "-128" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hhd", CHAR_MAX ) == 3 ); + //TESTCASE( strcmp( buffer, "127" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hhd", 0 ) == 1 ); + //TESTCASE( strcmp( buffer, "0" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hd", SHRT_MIN ) == 6 ); + //TESTCASE( strcmp( buffer, "-32768" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hd", SHRT_MAX ) == 5 ); + //TESTCASE( strcmp( buffer, "32767" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hd", 0 ) == 1 ); + //TESTCASE( strcmp( buffer, "0" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%d", 0 ) == 1 ); + //TESTCASE( strcmp( buffer, "0" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%ld", LONG_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%ld", LONG_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%ld", 0l ) == 1 ); + //TESTCASE( strcmp( buffer, "0" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%lld", LLONG_MIN ) == 20 ); + //TESTCASE( strcmp( buffer, "-9223372036854775808" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%lld", LLONG_MAX ) == 19 ); + //TESTCASE( strcmp( buffer, "9223372036854775807" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%lld", 0ll ) ); + //TESTCASE( strcmp( buffer, "0" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hhu", UCHAR_MAX ) == 3 ); + //TESTCASE( strcmp( buffer, "255" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hhu", (unsigned char)-1 ) == 3 ); + //TESTCASE( strcmp( buffer, "255" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hu", USHRT_MAX ) == 5 ); + //TESTCASE( strcmp( buffer, "65535" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%hu", (unsigned short)-1 ) == 5 ); + //TESTCASE( strcmp( buffer, "65535" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%u", UINT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "4294967295" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%u", -1u ) == 10 ); + //TESTCASE( strcmp( buffer, "4294967295" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%lu", ULONG_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "4294967295" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%lu", -1ul ) == 10 ); + //TESTCASE( strcmp( buffer, "4294967295" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%llu", ULLONG_MAX ) == 20 ); + //TESTCASE( strcmp( buffer, "18446744073709551615" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%llu", -1ull ) == 20 ); + //TESTCASE( strcmp( buffer, "18446744073709551615" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%X", UINT_MAX ) == 8 ); + //TESTCASE( strcmp( buffer, "FFFFFFFF" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#X", -1u ) == 10 ); + //TESTCASE( strcmp( buffer, "0XFFFFFFFF" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%x", UINT_MAX ) == 8 ); + //TESTCASE( strcmp( buffer, "ffffffff" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#x", -1u ) == 10 ); + //TESTCASE( strcmp( buffer, "0xffffffff" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%o", UINT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "37777777777" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#o", -1u ) == 12 ); + //TESTCASE( strcmp( buffer, "037777777777" ) == 0 ); + /* TODO: This test case is broken, doesn't test what it was intended to. */ + TESTCASE( testprintf( buffer, 100, "%.0#o", 0 ) == 5 ); + //TESTCASE( strcmp( buffer, "%.0#o" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%+d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%+d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "+2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%+d", 0 ) == 2 ); + //TESTCASE( strcmp( buffer, "+0" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%+u", UINT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "4294967295" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%+u", -1u ) == 10 ); + //TESTCASE( strcmp( buffer, "4294967295" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "% d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "% d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, " 2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "% d", 0 ) == 2 ); + //TESTCASE( strcmp( buffer, " 0" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "% u", UINT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "4294967295" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "% u", -1u ) == 10 ); + //TESTCASE( strcmp( buffer, "4294967295" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%9d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%9d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%10d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%10d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%11d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%11d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, " 2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%12d", INT_MIN ) == 12 ); + //TESTCASE( strcmp( buffer, " -2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%12d", INT_MAX ) == 12 ); + //TESTCASE( strcmp( buffer, " 2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-9d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-9d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-10d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-10d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-11d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-11d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "2147483647 " ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-12d", INT_MIN ) == 12 ); + //TESTCASE( strcmp( buffer, "-2147483648 " ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-12d", INT_MAX ) == 12 ); + //TESTCASE( strcmp( buffer, "2147483647 " ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%09d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%09d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%010d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%010d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%011d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%011d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "02147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%012d", INT_MIN ) == 12 ); + //TESTCASE( strcmp( buffer, "-02147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%012d", INT_MAX ) == 12 ); + //TESTCASE( strcmp( buffer, "002147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-09d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-09d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-010d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-010d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-011d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-011d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "2147483647 " ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-012d", INT_MIN ) == 12 ); + //TESTCASE( strcmp( buffer, "-2147483648 " ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%-012d", INT_MAX ) == 12 ); + //TESTCASE( strcmp( buffer, "2147483647 " ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%030.20d", INT_MAX ) == 30 ); + //TESTCASE( strcmp( buffer, " 00000000002147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%.6x", UINT_MAX ) == 8 ); + //TESTCASE( strcmp( buffer, "ffffffff" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#6.3x", UINT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "0xffffffff" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#3.6x", UINT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "0xffffffff" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%.6d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%6.3d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%3.6d", INT_MIN ) == 11 ); + //TESTCASE( strcmp( buffer, "-2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#0.6x", UINT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "0xffffffff" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#06.3x", UINT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "0xffffffff" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#03.6x", UINT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "0xffffffff" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#0.6d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#06.3d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#03.6d", INT_MAX ) == 10 ); + //TESTCASE( strcmp( buffer, "2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#+.6d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "+2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#+6.3d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "+2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%#+3.6d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "+2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%+0.6d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "+2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%+06.3d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "+2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%+03.6d", INT_MAX ) == 11 ); + //TESTCASE( strcmp( buffer, "+2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "- %d", INT_MAX ) == 12 ); + //TESTCASE( strcmp( buffer, "- 2147483647" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "- %d %% %d", INT_MAX, INT_MIN ) == 26 ); + //TESTCASE( strcmp( buffer, "- 2147483647 % -2147483648" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%c", 'x' ) == 1 ); + //TESTCASE( strcmp( buffer, "x" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%s", "abcdef" ) == 6 ); + //TESTCASE( strcmp( buffer, "abcdef" ) == 0 ); + TESTCASE( testprintf( buffer, 100, "%p", (void *)0xdeadbeef ) == 10 ); + //TESTCASE( strcmp( buffer, "0xdeadbeef" ) == 0 ); { - precision = 1; + int val1, val2; + TESTCASE( testprintf( buffer, 100, "123456%n789%n", &val1, &val2 ) == 9 ); + //TESTCASE( strcmp( buffer, "123456789" ) == 0 ); + TESTCASE( val1 == 6 ); + TESTCASE( val2 == 9 ); } - /* processing specifier */ - specifier = *format; + TESTCASE( fclose( buffer ) == 0 ); + char readbuffer[1000]; + TESTCASE( ( buffer = fopen( "testfile", "r" ) ) != NULL ); + TESTCASE( fread( readbuffer, 1, 1000, buffer ) == 985 ); + TESTCASE( fclose( buffer ) == 0 ); + TESTCASE( remove( "testfile" ) == 0 ); + TESTCASE( memcmp( readbuffer, "-1281270-32768327670-214748364821474836470-214748364821474836470-922337203685477580892233720368547758070255255655356553542949672954294967295429496729542949672951844674407370955161518446744073709551615FFFFFFFF0XFFFFFFFFffffffff0xffffffff37777777777037777777777%.0#o-2147483648+2147483647+042949672954294967295-2147483648 2147483647 042949672954294967295-21474836482147483647-21474836482147483647-2147483648 2147483647 -2147483648 2147483647-21474836482147483647-21474836482147483647-21474836482147483647 -2147483648 2147483647 -21474836482147483647-21474836482147483647-214748364802147483647-02147483648002147483647-21474836482147483647-21474836482147483647-21474836482147483647 -2147483648 2147483647 00000000002147483647ffffffff0xffffffff0xffffffff-2147483648-2147483648-21474836480xffffffff0xffffffff0xffffffff214748364721474836472147483647+2147483647+2147483647+2147483647+2147483647+2147483647+2147483647- 2147483647- 2147483647 % -2147483648xabcdef0xdeadbeef123456789", 985 ) == 0 ); + return TEST_RESULTS; +} - if (strchr("dxXuiop", specifier) != NULL) - { -#if defined(__MSDOS__) && !defined(__PDOS__) - if (specifier == 'p') - { - lng = 1; - } -#endif - 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); -} -*/