From ca36e5653468aa8d1526a78028d57e618c3de00a Mon Sep 17 00:00:00 2001 From: NicJA Date: Mon, 11 Jun 2018 21:15:04 +0000 Subject: [PATCH] tabs -> spaces git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@55305 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- compiler/stdc/__vcformat.c | 766 ++++++++++++++++++++++----------------------- 1 file changed, 383 insertions(+), 383 deletions(-) diff --git a/compiler/stdc/__vcformat.c b/compiler/stdc/__vcformat.c index 9382ef9459..3ef07d0ca8 100644 --- a/compiler/stdc/__vcformat.c +++ b/compiler/stdc/__vcformat.c @@ -41,17 +41,17 @@ /* a little macro to make life easier */ #define OUT(c) do \ - { if((*outc)((unsigned char)(c),data)==EOF) \ - return outcount; \ - outcount++; \ - }while(0) + { if((*outc)((unsigned char)(c),data)==EOF) \ + return outcount; \ + outcount++; \ + }while(0) #define MINFLOATSIZE (DBL_DIG+1) /* Why not 1 more - it's 97% reliable */ #define MININTSIZE (sizeof(unsigned long)*BITSPERBYTE/3+1) #define MINPOINTSIZE (sizeof(void *)*BITSPERBYTE/4+1) #define REQUIREDBUFFER (MININTSIZE>MINPOINTSIZE? \ - (MININTSIZE>MINFLOATSIZE?MININTSIZE:MINFLOATSIZE): \ - (MINPOINTSIZE>MINFLOATSIZE?MINPOINTSIZE:MINFLOATSIZE)) + (MININTSIZE>MINFLOATSIZE?MININTSIZE:MINFLOATSIZE): \ + (MINPOINTSIZE>MINFLOATSIZE?MINPOINTSIZE:MINFLOATSIZE)) #define ALTERNATEFLAG 1 /* '#' is set */ #define ZEROPADFLAG 2 /* '0' is set */ @@ -81,34 +81,34 @@ static size_t format_long(char *buffer, char type, int base, unsigned long v) break; case 'o': - shift = 3; - mask = 0x07; + shift = 3; + mask = 0x07; if (base == 10) base = 8; - break; + break; default: /* 'd' and 'u' */ - /* Use slow divide operations for decimal numbers */ - do - { - char c = v % base; + /* Use slow divide operations for decimal numbers */ + do + { + char c = v % base; *--buffer = c + '0'; v /= base; size++; - } while (v); + } while (v); - return size; + return size; } /* Divisor is a power of 2, so use fast shifts for division */ do { - char c = v & mask; + char c = v & mask; - *--buffer = (c < 10) ? c + '0' : c + hex; - v >>= shift; - size++; + *--buffer = (c < 10) ? c + '0' : c + hex; + v >>= shift; + size++; } while (v); return size; @@ -141,11 +141,11 @@ static size_t format_longlong(char *buffer, char type, int base, unsigned long l break; case 'o': - shift = 3; - mask = 0x07; + shift = 3; + mask = 0x07; if (base == 10) base = 8; - break; + break; default: /* @@ -159,26 +159,26 @@ static size_t format_longlong(char *buffer, char type, int base, unsigned long l * output or fix this. */ #ifndef STDC_LIB32 - do - { - char c = v % base; + do + { + char c = v % base; *--buffer = c + '0'; v /= base; size++; - } while (v); + } while (v); #endif - return size; + return size; } do { - char c = v & mask; + char c = v & mask; - *--buffer = (c < 10) ? c + '0' : c + hex; - v >>= shift; - size++; + *--buffer = (c < 10) ? c + '0' : c + hex; + v >>= shift; + size++; } while (v); return size; @@ -190,28 +190,28 @@ static size_t format_longlong(char *buffer, char type, int base, unsigned long l NAME */ - int __vcformat ( + int __vcformat ( /* SYNOPSIS */ - void * data, - int (* outc)(int, void *), - const char * format, - va_list args) + void * data, + int (* outc)(int, void *), + const char * format, + va_list args) /* FUNCTION - Format a list of arguments and call a function for each char - to print. + Format a list of arguments and call a function for each char + to print. INPUTS - data - This is passed to the user callback outc as its second argument. - outc - Call this function for every character that should be - emitted. The function should return EOF on error and - > 0 otherwise. - format - A printf() format string. - args - A list of arguments for the format string. + data - This is passed to the user callback outc as its second argument. + outc - Call this function for every character that should be + emitted. The function should return EOF on error and + > 0 otherwise. + format - A printf() format string. + args - A list of arguments for the format string. RESULT - The number of characters written. + The number of characters written. NOTES @@ -244,48 +244,48 @@ static size_t format_longlong(char *buffer, char type, int base, unsigned long l const char *ptr=format+1; /* pointer to format string */ size_t i,pad; /* Some temporary variables */ union { /* floating point arguments %[aAeEfFgG] */ - double dbl; - long double ldbl; + double dbl; + long double ldbl; } fparg; do /* read flags */ - for(i=0;i=0) - preci=a; - }else - { preci=0; - while(isdigit(*ptr)) - preci=preci*10+(*ptr++-'0'); - } + if(*ptr=='*') /* read precision from arguments */ + { signed int a; + ptr++; + a=va_arg(args,signed int); + if(a>=0) + preci=a; + }else + { preci=0; + while(isdigit(*ptr)) + preci=preci*10+(*ptr++-'0'); + } } if (*ptr == 'h' || *ptr == 'l' || *ptr == 'L' || *ptr == 'z') - subtype=*ptr++; + subtype=*ptr++; if (*ptr == 'l' || *ptr == 'q') { @@ -314,156 +314,156 @@ static size_t format_longlong(char *buffer, char type, int base, unsigned long l unsigned long v = 0; int base = 10; - if (type=='p') /* This is written as 0x08lx (or 0x016lx on 64 bits) */ - { - subtype = 'l'; - type = 'x'; - if (!width) - width = sizeof(void *) * 2; - flags |= ZEROPADFLAG; - } - - if (type=='d' || type=='i') /* These are signed */ - { + if (type=='p') /* This is written as 0x08lx (or 0x016lx on 64 bits) */ + { + subtype = 'l'; + type = 'x'; + if (!width) + width = sizeof(void *) * 2; + flags |= ZEROPADFLAG; + } + + if (type=='d' || type=='i') /* These are signed */ + { signed long v2; - if (subtype=='l') + if (subtype=='l') { #ifdef AROS_HAVE_LONG_LONG - if (lltype) - { - signed long long llv2; - - llv2 = va_arg(args, signed long long); - if (llv2 < 0) - { - llv = - llv2; - v2 = -1; /* Assign a dummy value to v2 in order to process sign below */ - } - else - { - llv = llv2; - v2 = llv2 ? 1 : 0; - } - } + if (lltype) + { + signed long long llv2; + + llv2 = va_arg(args, signed long long); + if (llv2 < 0) + { + llv = - llv2; + v2 = -1; /* Assign a dummy value to v2 in order to process sign below */ + } + else + { + llv = llv2; + v2 = llv2 ? 1 : 0; + } + } else #endif - v2=va_arg(args, signed long); - } - else if (subtype=='z') - v2 = va_arg(args,size_t); - else - v2 = va_arg(args,signed int); - - if (v2 < 0) - { - buffer1[size1++]='-'; - v = -v2; - } - else - { - if (flags & SIGNFLAG) - buffer1[size1++] = '+'; - else if (flags & BLANKFLAG) - buffer1[size1++] = ' '; - v = v2; - } - } - else /* These are unsigned */ - { - if (subtype=='l') + v2=va_arg(args, signed long); + } + else if (subtype=='z') + v2 = va_arg(args,size_t); + else + v2 = va_arg(args,signed int); + + if (v2 < 0) + { + buffer1[size1++]='-'; + v = -v2; + } + else + { + if (flags & SIGNFLAG) + buffer1[size1++] = '+'; + else if (flags & BLANKFLAG) + buffer1[size1++] = ' '; + v = v2; + } + } + else /* These are unsigned */ + { + if (subtype=='l') { #ifdef AROS_HAVE_LONG_LONG if (lltype) - llv = va_arg(args, unsigned long long); + llv = va_arg(args, unsigned long long); else #endif - v = va_arg(args,unsigned long); - } - else if (subtype == 'z') - v = va_arg(args, size_t); - else - v = va_arg(args, unsigned int); - - if (flags & ALTERNATEFLAG) - { - if (type == 'o' && preci && v) - buffer1[size1++] = '0'; - if ((type == 'x' || type == 'X') && v) - { - buffer1[size1++] = '0'; - buffer1[size1++] = type; - } - } - } - - buffer2 = &buffer[sizeof(buffer)]; /* Calculate body string */ + v = va_arg(args,unsigned long); + } + else if (subtype == 'z') + v = va_arg(args, size_t); + else + v = va_arg(args, unsigned int); + + if (flags & ALTERNATEFLAG) + { + if (type == 'o' && preci && v) + buffer1[size1++] = '0'; + if ((type == 'x' || type == 'X') && v) + { + buffer1[size1++] = '0'; + buffer1[size1++] = type; + } + } + } + + buffer2 = &buffer[sizeof(buffer)]; /* Calculate body string */ #ifdef AROS_HAVE_LONG_LONG - /* - * For long long type we have actual value in llv. - * For long we have actual value in v. - * This avoids slow 64-bit operations on 32-bit processors - * when not needed. - */ - if (lltype) - size2 = format_longlong(buffer2, type, base, llv); - else + /* + * For long long type we have actual value in llv. + * For long we have actual value in v. + * This avoids slow 64-bit operations on 32-bit processors + * when not needed. + */ + if (lltype) + size2 = format_longlong(buffer2, type, base, llv); + else #endif - size2 = format_long(buffer2, type, base, v); - /* Position to the beginning of the string */ - buffer2 -= size2; - - if (preci == ULONG_MAX) /* default */ - preci = 0; - else - flags &= ~ZEROPADFLAG; - break; + size2 = format_long(buffer2, type, base, v); + /* Position to the beginning of the string */ + buffer2 -= size2; + + if (preci == ULONG_MAX) /* default */ + preci = 0; + else + flags &= ~ZEROPADFLAG; + break; } case 'c': - if (subtype=='l') + if (subtype=='l') { #ifdef AROS_HAVE_LONG_LONG if (lltype) - *buffer2 = va_arg(args, long long); + *buffer2 = va_arg(args, long long); else #endif - *buffer2 = va_arg(args, long); - } - else - *buffer2 = va_arg(args, int); + *buffer2 = va_arg(args, long); + } + else + *buffer2 = va_arg(args, int); - size2 = 1; - preci = 0; - break; + size2 = 1; + preci = 0; + break; case 's': - buffer2 = va_arg(args, char *); - if (!buffer2) - buffer2 = "(null)"; - size2 = strlen(buffer2); - size2 = size2 <= preci ? size2 : preci; - preci = 0; - break; + buffer2 = va_arg(args, char *); + if (!buffer2) + buffer2 = "(null)"; + size2 = strlen(buffer2); + size2 = size2 <= preci ? size2 : preci; + preci = 0; + break; case 'b': - buffer2 = BADDR(va_arg(args, BPTR)); - if (buffer2) + buffer2 = BADDR(va_arg(args, BPTR)); + if (buffer2) #if AROS_FAST_BSTR - size2 = strlen(buffer2); + size2 = strlen(buffer2); #else - size2 = *(unsigned char *)buffer2++; + size2 = *(unsigned char *)buffer2++; #endif - else - { - buffer2 = "(null)"; - size2 = 6; - } + else + { + buffer2 = "(null)"; + size2 = 6; + } - size2 = size2 <= preci ? size2 : preci; - preci = 0; - break; + size2 = size2 <= preci ? size2 : preci; + preci = 0; + break; #ifdef FULL_SPECIFIERS case 'a': @@ -475,243 +475,243 @@ static size_t format_longlong(char *buffer, char type, int base, unsigned long l case 'g': case 'G': { - char killzeros=0,sign=0; /* some flags */ - int ex1,ex2; /* Some temporary variables */ - size_t size,dnum,dreq; - char *udstr=NULL; + char killzeros=0,sign=0; /* some flags */ + int ex1,ex2; /* Some temporary variables */ + size_t size,dnum,dreq; + char *udstr=NULL; - if (subtype=='L') - { flags|=LDBLFLAG; + if (subtype=='L') + { flags|=LDBLFLAG; fparg.ldbl=va_arg(args,long double); }else - { flags&=~LDBLFLAG; + { flags&=~LDBLFLAG; fparg.dbl=va_arg(args,double); } - if(isinf(fparg.dbl)) - { if(fparg.dbl>0) - udstr="+inf"; - else - udstr="-inf"; - }else if(isnan(fparg.dbl)) - udstr="NaN"; - - if(udstr!=NULL) - { size2=strlen(udstr); - preci=0; - buffer2=udstr; - break; } - - if(preci==ULONG_MAX) /* old default */ - preci=6; /* new default */ - - if(((subtype!='L') && (fparg.dbl<0.0)) || ((subtype=='L') && (fparg.ldbl<0.0))) - { sign='-'; + if(isinf(fparg.dbl)) + { if(fparg.dbl>0) + udstr="+inf"; + else + udstr="-inf"; + }else if(isnan(fparg.dbl)) + udstr="NaN"; + + if(udstr!=NULL) + { size2=strlen(udstr); + preci=0; + buffer2=udstr; + break; } + + if(preci==ULONG_MAX) /* old default */ + preci=6; /* new default */ + + if(((subtype!='L') && (fparg.dbl<0.0)) || ((subtype=='L') && (fparg.ldbl<0.0))) + { sign='-'; if (subtype=='L') - fparg.ldbl=-fparg.ldbl; + fparg.ldbl=-fparg.ldbl; else - fparg.dbl=-fparg.dbl; - }else - { if(flags&SIGNFLAG) - sign='+'; - else if(flags&BLANKFLAG) - sign=' '; - } - - ex1=0; + fparg.dbl=-fparg.dbl; + }else + { if(flags&SIGNFLAG) + sign='+'; + else if(flags&BLANKFLAG) + sign=' '; + } + + ex1=0; if (subtype!='L') { if(fparg.dbl!=0.0) - { ex1=log10(fparg.dbl); - if(fparg.dbl<1.0) - fparg.dbl=fparg.dbl*pow(10,- --ex1); /* Caution: (int)log10(.5)!=-1 */ - else - fparg.dbl=fparg.dbl/pow(10,ex1); - if(fparg.dbl<1.0) /* adjust if we are too low (log10(.1)=-.999999999) */ - { fparg.dbl*=10.0; /* luckily this cannot happen with FLT_MAX and FLT_MIN */ - ex1--; } /* The case too high (log(10.)=.999999999) is done later */ - } + { ex1=log10(fparg.dbl); + if(fparg.dbl<1.0) + fparg.dbl=fparg.dbl*pow(10,- --ex1); /* Caution: (int)log10(.5)!=-1 */ + else + fparg.dbl=fparg.dbl/pow(10,ex1); + if(fparg.dbl<1.0) /* adjust if we are too low (log10(.1)=-.999999999) */ + { fparg.dbl*=10.0; /* luckily this cannot happen with FLT_MAX and FLT_MIN */ + ex1--; } /* The case too high (log(10.)=.999999999) is done later */ + } }else { if(fparg.ldbl!=0.0) - { ex1=log10l(fparg.ldbl); - if(fparg.ldbl<1.0) - fparg.ldbl=fparg.ldbl*powl(10,- --ex1); - else - fparg.ldbl=fparg.ldbl/powl(10,ex1); - if(fparg.ldbl<1.0) - { fparg.ldbl*=10.0; - ex1--; } - } + { ex1=log10l(fparg.ldbl); + if(fparg.ldbl<1.0) + fparg.ldbl=fparg.ldbl*powl(10,- --ex1); + else + fparg.ldbl=fparg.ldbl/powl(10,ex1); + if(fparg.ldbl<1.0) + { fparg.ldbl*=10.0; + ex1--; } + } } - ex2=preci; - if(type=='f' || type=='F') - ex2+=ex1; - if(tolower(type)=='g') - ex2--; + ex2=preci; + if(type=='f' || type=='F') + ex2+=ex1; + if(tolower(type)=='g') + ex2--; if (subtype!='L') { fparg.dbl+=.5/pow(10,ex2=10.0) /* Adjusts log10(10.)=.999999999 too */ - { fparg.dbl/=10.0; - ex1++; } + { fparg.dbl/=10.0; + ex1++; } }else { fparg.ldbl+=.5/powl(10,ex2=10.0) /* Adjusts log10(10.)=.999999999 too */ - { fparg.ldbl/=10.0; - ex1++; } + if(fparg.ldbl>=10.0) /* Adjusts log10(10.)=.999999999 too */ + { fparg.ldbl/=10.0; + ex1++; } + } + + if(tolower(type)=='g') /* This changes to one of the other types */ + { if(ex1<(signed long)preci&&ex1>=-4) + { type='f'; + preci-=ex1; + }else + type=type=='g'?'e':'E'; + preci--; + if(!(flags&ALTERNATEFLAG)) + killzeros=1; /* set flag to kill trailing zeros */ } - if(tolower(type)=='g') /* This changes to one of the other types */ - { if(ex1<(signed long)preci&&ex1>=-4) - { type='f'; - preci-=ex1; - }else - type=type=='g'?'e':'E'; - preci--; - if(!(flags&ALTERNATEFLAG)) - killzeros=1; /* set flag to kill trailing zeros */ - } - - dreq=preci+1; /* Calculate number of decimal places required */ - if(type=='f') - dreq+=ex1; /* even more before the decimal point */ - - dnum=0; - while(dnumdnum||buffer[dreq]=='0')) - preci--; - - if(tolower(type)=='f')/* Calculate actual size of string (without sign) */ - { size=preci+1; /* numbers after decimal point + 1 before */ - if(ex1>0) - size+=ex1; /* numbers >= 10 */ - if(preci||flags&ALTERNATEFLAG) - size++; /* 1 for decimal point */ - }else - { size=preci+5; /* 1 for the number before the decimal point, and 4 for the exponent */ - if(preci||flags&ALTERNATEFLAG) - size++; - if(ex1>99||ex1<-99) - size++; /* exponent needs an extra decimal place */ - } - - pad=size+(sign!=0); - pad=pad>=width?0:width-pad; - - if(sign&&flags&ZEROPADFLAG) - OUT(sign); - - if(!(flags&LALIGNFLAG)) - for(i=0;idnum||buffer[dreq]=='0')) + preci--; + + if(tolower(type)=='f')/* Calculate actual size of string (without sign) */ + { size=preci+1; /* numbers after decimal point + 1 before */ + if(ex1>0) + size+=ex1; /* numbers >= 10 */ + if(preci||flags&ALTERNATEFLAG) + size++; /* 1 for decimal point */ + }else + { size=preci+5; /* 1 for the number before the decimal point, and 4 for the exponent */ + if(preci||flags&ALTERNATEFLAG) + size++; + if(ex1>99||ex1<-99) + size++; /* exponent needs an extra decimal place */ + } + + pad=size+(sign!=0); + pad=pad>=width?0:width-pad; + + if(sign&&flags&ZEROPADFLAG) + OUT(sign); + + if(!(flags&LALIGNFLAG)) + for(i=0;i=0) - { OUT(dreq99) - OUT(ex1/100+'0'); - OUT(ex1/10%10+'0'); - OUT(ex1%10+'0'); - } - - if(flags&LALIGNFLAG) - for(i=0;i=0) + { OUT(dreq99) + OUT(ex1/100+'0'); + OUT(ex1/10%10+'0'); + OUT(ex1%10+'0'); + } + + if(flags&LALIGNFLAG) + for(i=0;i=preci?size2:preci); /* Calculate the number of characters */ pad=pad>=width?0:width-pad; /* and the number of resulting pad bytes */ if(flags&ZEROPADFLAG) /* print sign and that like */ - for(i=0;i