CVS update: php3/functions

From: Date: Fri, 13 Nov 1998 14:52:34 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-2384@lists.php.net to get a copy of this message
Date: Friday November 13, 1998 @ 9:52 Author: ssb Update of /repository/php3/functions In directory asf:/u2/tmp/cvs-serv1582 Modified Files: formatted_print.c Log Message: get rid of a strlen() Index: php3/functions/formatted_print.c diff -c php3/functions/formatted_print.c:1.39 php3/functions/formatted_print.c:1.40 *** php3/functions/formatted_print.c:1.39 Thu May 21 19:57:29 1998 --- php3/functions/formatted_print.c Fri Nov 13 09:52:33 1998 *************** *** 27,33 **** +----------------------------------------------------------------------+ */ ! /* $Id: formatted_print.c,v 1.39 1998/05/21 23:57:29 zeev Exp $ */ #include <math.h> /* modf() */ #ifdef THREAD_SAFE --- 27,33 ---- +----------------------------------------------------------------------+ */ ! /* $Id: formatted_print.c,v 1.40 1998/11/13 14:52:33 ssb Exp $ */ #include <math.h> /* modf() */ #ifdef THREAD_SAFE *************** *** 49,56 **** #define FLOAT_PRECISION 6 #define MAX_FLOAT_DIGITS 38 #define MAX_FLOAT_PRECISION 40 - #undef SPRINTF_DEBUG static char hexchars[] = "0123456789abcdef"; static char HEXCHARS[] = "0123456789ABCDEF"; --- 49,62 ---- #define FLOAT_PRECISION 6 #define MAX_FLOAT_DIGITS 38 #define MAX_FLOAT_PRECISION 40 + #if 0 + /* trick to control varargs functions through cpp */ + # define PRINTF_DEBUG(arg) php3_printf arg + #else + # define PRINTF_DEBUG(arg) + #endif + static char hexchars[] = "0123456789abcdef"; static char HEXCHARS[] = "0123456789ABCDEF"; *************** *** 67,73 **** * sign is set to 0 for positive, 1 for negative */ static char * ! _php3_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag) { register int r2; double fi, fj; --- 73,79 ---- * sign is set to 0 for positive, 1 for negative */ static char * ! _php3_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag) { register int r2; double fi, fj; *************** *** 145,181 **** } ! inline static void _php3_sprintf_appendchar(char **buffer, int *pos, int *size, char add) { if ((*pos + 1) >= *size) { *size <<= 1; ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: ereallocing buffer to %d bytes\n", *size); ! #endif *buffer = erealloc(*buffer, *size); } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: appending '%c', pos=\n", add, *pos); ! #endif (*buffer)[(*pos)++] = add; } ! inline static void _php3_sprintf_appendstring(char **buffer, int *pos, int *size, char *add, ! int min_width, int max_width, char padding, ! int alignment) { ! register int len = strlen(add), npad = min_width - MIN(len,(max_width?max_width:len)); if (npad<0) { npad=0; } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n", ! *buffer, *pos, *size, add, min_width, padding, alignment); ! #endif ! if (max_width == 0) { max_width = MAX(min_width,len); } --- 151,182 ---- } ! inline static void ! _php3_sprintf_appendchar(char **buffer, int *pos, int *size, char add) { if ((*pos + 1) >= *size) { *size <<= 1; ! PRINTF_DEBUG(("sprintf: ereallocing buffer to %d bytes\n", *size)); *buffer = erealloc(*buffer, *size); } ! PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos)); (*buffer)[(*pos)++] = add; } ! inline static void ! _php3_sprintf_appendstring(char **buffer, int *pos, int *size, char *add, ! int min_width, int max_width, char padding, ! int alignment, int len) { ! register int npad = min_width - MIN(len,(max_width?max_width:len)); if (npad<0) { npad=0; } ! PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n", ! *buffer, *pos, *size, add, min_width, padding, alignment)); if (max_width == 0) { max_width = MAX(min_width,len); } *************** *** 183,191 **** while ((*pos + max_width) >= *size) { *size <<= 1; } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf ereallocing buffer to %d bytes\n", *size); ! #endif *buffer = erealloc(*buffer, *size); } if (alignment == ALIGN_RIGHT) { --- 184,190 ---- while ((*pos + max_width) >= *size) { *size <<= 1; } ! PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", *size)); *buffer = erealloc(*buffer, *size); } if (alignment == ALIGN_RIGHT) { *************** *** 193,201 **** (*buffer)[(*pos)++] = padding; } } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: appending \"%s\"\n", add); ! #endif strncpy(&(*buffer)[*pos], add, max_width); *pos += MIN(max_width,len); if (alignment == ALIGN_LEFT) { --- 192,198 ---- (*buffer)[(*pos)++] = padding; } } ! PRINTF_DEBUG(("sprintf: appending \"%s\"\n", add)); strncpy(&(*buffer)[*pos], add, max_width); *pos += MIN(max_width,len); if (alignment == ALIGN_LEFT) { *************** *** 206,222 **** } ! inline static void _php3_sprintf_appendint(char **buffer, int *pos, int *size, int number, ! int width, char padding, int alignment) { char numbuf[NUM_BUF_SIZE]; register unsigned int magn, nmagn, i = NUM_BUF_SIZE - 1, neg = 0; - - #ifdef SPRINTF_DEBUG - php3_printf("sprintf: appendint(%x, %x, %x, %d, %d, '%c', %d)\n", - *buffer, pos, size, number, width, padding, alignment); - #endif if (number < 0) { neg = 1; magn = ((unsigned int) -(number + 1)) + 1; --- 203,217 ---- } ! inline static void ! _php3_sprintf_appendint(char **buffer, int *pos, int *size, int number, ! int width, char padding, int alignment) { char numbuf[NUM_BUF_SIZE]; register unsigned int magn, nmagn, i = NUM_BUF_SIZE - 1, neg = 0; + PRINTF_DEBUG(("sprintf: appendint(%x, %x, %x, %d, %d, '%c', %d)\n", + *buffer, pos, size, number, width, padding, alignment)); if (number < 0) { neg = 1; magn = ((unsigned int) -(number + 1)) + 1; *************** *** 236,267 **** if (neg) { numbuf[--i] = '-'; } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: appending %d as \"%s\", i=%d\n", ! number, &numbuf[i], i); ! #endif ! _php3_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0, ! padding, alignment); } ! inline static void _php3_sprintf_appenddouble(char **buffer, int *pos, ! int *size, double number, ! int width, char padding, ! int alignment, int precision, ! int adjust, char fmt) { char numbuf[NUM_BUF_SIZE]; char *cvt; register int i = 0, j = 0; int sign, decpt; - - #ifdef SPRINTF_DEBUG - php3_printf("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n", - *buffer, pos, size, number, width, padding, alignment, fmt); - #endif if ((adjust & ADJ_PRECISION) == 0) { precision = FLOAT_PRECISION; } else if (precision > MAX_FLOAT_PRECISION) { --- 231,257 ---- if (neg) { numbuf[--i] = '-'; } ! PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n", ! number, &numbuf[i], i)); _php3_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0, ! padding, alignment, (NUM_BUF_SIZE - 1) - i); } ! inline static void ! _php3_sprintf_appenddouble(char **buffer, int *pos, ! int *size, double number, ! int width, char padding, ! int alignment, int precision, ! int adjust, char fmt) { char numbuf[NUM_BUF_SIZE]; char *cvt; register int i = 0, j = 0; int sign, decpt; + PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n", + *buffer, pos, size, number, width, padding, alignment, fmt)); if ((adjust & ADJ_PRECISION) == 0) { precision = FLOAT_PRECISION; } else if (precision > MAX_FLOAT_PRECISION) { *************** *** 305,328 **** width += (precision + 1); } _php3_sprintf_appendstring(buffer, pos, size, numbuf, width, 0, padding, ! alignment); } ! inline static void _php3_sprintf_append2n(char **buffer, int *pos, int *size, int number, ! int width, char padding, int alignment, int n, ! char *chartable) { char numbuf[NUM_BUF_SIZE]; register unsigned int num, i = NUM_BUF_SIZE - 1, neg = 0; register int andbits = (1 << n) - 1; ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: append2n(%x, %x, %x, %d, %d, '%c', %d, %d, %x)\n", ! *buffer, pos, size, number, width, padding, alignment, n, ! chartable); ! php3_printf("sprintf: append2n 2^%d andbits=%x\n", n, andbits); ! #endif if (number < 0) { neg = 1; --- 295,317 ---- width += (precision + 1); } _php3_sprintf_appendstring(buffer, pos, size, numbuf, width, 0, padding, ! alignment, i); } ! inline static void ! _php3_sprintf_append2n(char **buffer, int *pos, int *size, int number, ! int width, char padding, int alignment, int n, ! char *chartable) { char numbuf[NUM_BUF_SIZE]; register unsigned int num, i = NUM_BUF_SIZE - 1, neg = 0; register int andbits = (1 << n) - 1; ! PRINTF_DEBUG(("sprintf: append2n(%x, %x, %x, %d, %d, '%c', %d, %d, %x)\n", ! *buffer, pos, size, number, width, padding, alignment, n, ! chartable)); ! PRINTF_DEBUG(("sprintf: append2n 2^%d andbits=%x\n", n, andbits)); if (number < 0) { neg = 1; *************** *** 343,353 **** numbuf[--i] = '-'; } _php3_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0, ! padding, alignment); } ! inline static int _php3_sprintf_getnumber(char *buffer, int *pos) { char *endptr; register int num = strtol(&buffer[*pos], &endptr, 10); --- 332,343 ---- numbuf[--i] = '-'; } _php3_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0, ! padding, alignment, (NUM_BUF_SIZE - 1) - i); } ! inline static int ! _php3_sprintf_getnumber(char *buffer, int *pos) { char *endptr; register int num = strtol(&buffer[*pos], &endptr, 10); *************** *** 356,364 **** if (endptr != NULL) { i = (endptr - &buffer[*pos]); } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf_getnumber: number was %d bytes long\n", i); ! #endif *pos += i; return num; } --- 346,352 ---- if (endptr != NULL) { i = (endptr - &buffer[*pos]); } ! PRINTF_DEBUG(("sprintf_getnumber: number was %d bytes long\n", i)); *pos += i; return num; } *************** *** 387,393 **** * "X" integer argument is printed as uppercase hexadecimal * */ ! static char *php3_formatted_print(HashTable *ht) { pval **args; int argc, size = 240, inpos = 0, outpos = 0; --- 375,382 ---- * "X" integer argument is printed as uppercase hexadecimal * */ ! static char * ! php3_formatted_print(HashTable *ht) { pval **args; int argc, size = 240, inpos = 0, outpos = 0; *************** *** 412,421 **** currarg = 1; while (format[inpos]) { ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: format[%d]='%c'\n", inpos, format[inpos]); ! php3_printf("sprintf: outpos=%d\n", outpos); ! #endif if (format[inpos] != '%') { _php3_sprintf_appendchar(&result, &outpos, &size, format[inpos++]); } else if (format[inpos + 1] == '%') { --- 401,408 ---- currarg = 1; while (format[inpos]) { ! PRINTF_DEBUG(("sprintf: format[%d]='%c'\n", inpos, format[inpos])); ! PRINTF_DEBUG(("sprintf: outpos=%d\n", outpos)); if (format[inpos] != '%') { _php3_sprintf_appendchar(&result, &outpos, &size, format[inpos++]); } else if (format[inpos + 1] == '%') { *************** *** 432,449 **** padding = ' '; inpos++; /* skip the '%' */ ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: first looking at '%c', inpos=%d\n", ! format[inpos], inpos); ! #endif ! if (isascii((int)format[inpos]) && !isalpha((int)format[inpos])) { /* first look for modifiers */ ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: looking for modifiers\n" ! "sprintf: now looking at '%c', inpos=%d\n", ! format[inpos], inpos); ! #endif for (;; inpos++) { if (format[inpos] == ' ' || format[inpos] == '0') { padding = format[inpos]; --- 419,431 ---- padding = ' '; inpos++; /* skip the '%' */ ! PRINTF_DEBUG(("sprintf: first looking at '%c', inpos=%d\n", ! format[inpos], inpos)); if (isascii((int)format[inpos]) && !isalpha((int)format[inpos])) { /* first look for modifiers */ ! PRINTF_DEBUG(("sprintf: looking for modifiers\n" ! "sprintf: now looking at '%c', inpos=%d\n", ! format[inpos], inpos)); for (;; inpos++) { if (format[inpos] == ' ' || format[inpos] == '0') { padding = format[inpos]; *************** *** 453,491 **** } else if (format[inpos] == '\'') { padding = format[++inpos]; } else { ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: end of modifiers\n"); ! #endif break; } } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: padding='%c'\n", padding); ! php3_printf("sprintf: alignment=%s\n", ! (alignment == ALIGN_LEFT) ? "left" : "right"); ! #endif /* after modifiers comes width */ if (isdigit((int)format[inpos])) { ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: getting width\n"); ! #endif width = _php3_sprintf_getnumber(format, &inpos); adjusting |= ADJ_WIDTH; } else { width = 0; } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: width=%d\n", width); ! #endif /* after width comes precision */ if (format[inpos] == '.') { inpos++; ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: getting precision\n"); ! #endif if (isdigit((int)format[inpos])) { precision = _php3_sprintf_getnumber(format, &inpos); adjusting |= ADJ_PRECISION; --- 435,463 ---- } else if (format[inpos] == '\'') { padding = format[++inpos]; } else { ! PRINTF_DEBUG(("sprintf: end of modifiers\n")); break; } } ! PRINTF_DEBUG(("sprintf: padding='%c'\n", padding)); ! PRINTF_DEBUG(("sprintf: alignment=%s\n", ! (alignment == ALIGN_LEFT) ? "left" : "right")); /* after modifiers comes width */ if (isdigit((int)format[inpos])) { ! PRINTF_DEBUG(("sprintf: getting width\n")); width = _php3_sprintf_getnumber(format, &inpos); adjusting |= ADJ_WIDTH; } else { width = 0; } ! PRINTF_DEBUG(("sprintf: width=%d\n", width)); /* after width comes precision */ if (format[inpos] == '.') { inpos++; ! PRINTF_DEBUG(("sprintf: getting precision\n")); if (isdigit((int)format[inpos])) { precision = _php3_sprintf_getnumber(format, &inpos); adjusting |= ADJ_PRECISION; *************** *** 495,503 **** } else { precision = 0; } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: precision=%d\n", precision); ! #endif } else { width = precision = 0; } --- 467,473 ---- } else { precision = 0; } ! PRINTF_DEBUG(("sprintf: precision=%d\n", precision)); } else { width = precision = 0; } *************** *** 505,521 **** if (format[inpos] == 'l') { inpos++; } ! #ifdef SPRINTF_DEBUG ! php3_printf("sprintf: format character='%c'\n", format[inpos]); ! #endif /* now we expect to find a type specifier */ switch (format[inpos]) { case 's': convert_to_string(args[currarg]); _php3_sprintf_appendstring(&result, &outpos, &size, ! args[currarg]->value.str.val, width, precision, padding, ! alignment); break; case 'd': --- 475,490 ---- if (format[inpos] == 'l') { inpos++; } ! PRINTF_DEBUG(("sprintf: format character='%c'\n", format[inpos])); /* now we expect to find a type specifier */ switch (format[inpos]) { case 's': convert_to_string(args[currarg]); _php3_sprintf_appendstring(&result, &outpos, &size, ! args[currarg]->value.str.val, width, precision, padding, ! alignment, ! args[currarg]->value.str.len); break; case 'd': *************** *** 595,601 **** } ! void php3_user_sprintf(INTERNAL_FUNCTION_PARAMETERS) { char *result; TLS_VARS; --- 564,570 ---- } ! PHP_FUNCTION(user_printf) { char *result; TLS_VARS; *************** *** 608,614 **** } ! void php3_user_printf(INTERNAL_FUNCTION_PARAMETERS) { char *result; TLS_VARS; --- 577,583 ---- } ! PHP_FUNCTION(user_sprintf) { char *result; TLS_VARS; -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#2384) next »