pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: stralloc.c,v 1.187 2004/11/08 10:30:50 grubba Exp $ + || $Id: stralloc.c,v 1.188 2004/11/09 12:27:53 grubba Exp $   */      #include "global.h"   #include "stralloc.h"   #include "pike_macros.h"   #include "dynamic_buffer.h"   #include "pike_macros.h"   #include "pike_memory.h"   #include "pike_error.h"   #include "gc.h"
pike.git/src/stralloc.c:2299:    */    string_builder_fill(s, min_width - len, MKPCHARP(" ", 0),    4, 0);    }   }      /* Values used internally in string_builder_vsprintf() */   #define STATE_MIN_WIDTH 1   #define STATE_PRECISION 2    - static LONGEST pike_va_int(va_list *args, int flags) + /* Kludge around brokeness of gcc/x86_64 */ + #ifdef VA_LIST_IS_STATE_PTR + #define VA_LIST_PTR va_list + #define VA_LIST_ADDR(X) (X) + #define VA_LIST_DEREF(X) (X) + #else + #define VA_LIST_PTR va_list * + #define VA_LIST_ADDR(X) (&(X)) + #define VA_LIST_DEREF(X) (*(X)) + #endif +  + static LONGEST pike_va_int(VA_LIST_PTR args, int flags)   {    switch (flags & (APPEND_WIDTH_MASK|APPEND_SIGNED)) {    case APPEND_WIDTH_HALF: -  return va_arg(*args, unsigned int) & 0xffff; +  return va_arg(VA_LIST_DEREF(args), unsigned int) & 0xffff;    case APPEND_WIDTH_HALF|APPEND_SIGNED: -  return (short)va_arg(*args, int); +  return (short)va_arg(VA_LIST_DEREF(args), int);    case 0: -  return va_arg(*args, unsigned int); +  return va_arg(VA_LIST_DEREF(args), unsigned int);    case APPEND_SIGNED: -  return va_arg(*args, int); +  return va_arg(VA_LIST_DEREF(args), int);    case APPEND_WIDTH_LONG: -  return va_arg(*args, unsigned long); +  return va_arg(VA_LIST_DEREF(args), unsigned long);    case APPEND_WIDTH_LONG|APPEND_SIGNED: -  return va_arg(*args, long); +  return va_arg(VA_LIST_DEREF(args), long);   #ifdef INT64    case APPEND_WIDTH_LONG_LONG: -  return va_arg(*args, unsigned INT64); +  return va_arg(VA_LIST_DEREF(args), unsigned INT64);    case APPEND_WIDTH_LONG_LONG|APPEND_SIGNED: -  return va_arg(*args, INT64); +  return va_arg(VA_LIST_DEREF(args), INT64);   #endif /* INT64 */    }    Pike_fatal("string_builder_append_integerv(): Unsupported flags: 0x%04x\n",    flags);    return 0;   }      PMOD_EXPORT void string_builder_vsprintf(struct string_builder *s,    const char *fmt,    va_list args)
pike.git/src/stralloc.c:2469:    } else {    string_builder_binary_strcat(s, str, len);    }    }    break;    case 'c':    /* FIXME: Doesn't care about field or integer widths yet. */    string_builder_putchar(s, va_arg(args, int));    break;    case 'b': -  string_builder_append_integer(s, pike_va_int(&args, flags), 2, +  string_builder_append_integer(s, pike_va_int(VA_LIST_ADDR(args), flags), 2,    flags, min_width, precision);    break;    case 'o': -  string_builder_append_integer(s, pike_va_int(&args, flags), 8, +  string_builder_append_integer(s, pike_va_int(VA_LIST_ADDR(args), flags), 8,    flags, min_width, precision);    break;    case 'x': -  string_builder_append_integer(s, pike_va_int(&args, flags), 16, +  string_builder_append_integer(s, pike_va_int(VA_LIST_ADDR(args), flags), 16,    flags, min_width, precision);    break;    case 'X': -  string_builder_append_integer(s, pike_va_int(&args, flags), 16, +  string_builder_append_integer(s, pike_va_int(VA_LIST_ADDR(args), flags), 16,    flags | APPEND_UPPER_CASE,    min_width, precision);    break;    case 'u': -  string_builder_append_integer(s, pike_va_int(&args, flags), 10, +  string_builder_append_integer(s, pike_va_int(VA_LIST_ADDR(args), flags), 10,    flags, min_width, precision);    break;    case 'd': -  string_builder_append_integer(s, pike_va_int(&args, flags), 10, +  string_builder_append_integer(s, pike_va_int(VA_LIST_ADDR(args), flags), 10,    flags | APPEND_SIGNED,    min_width, precision);    break;       /* FIMXE: TODO: Doubles (ie 'a', 'e', 'E', 'f', 'g', 'G'). */       default:    Pike_fatal("string_builder_vsprintf(): Invalid formatting method: "    "'%c' 0x%x.\n", fmt[-1], fmt[-1]);    }
pike.git/src/stralloc.c:2512:    }    } else {    const char *start = fmt;    while (*fmt && (*fmt != '%'))    fmt++;    string_builder_binary_strcat(s, start, fmt-start);    }    }   }    +    PMOD_EXPORT void string_builder_sprintf(struct string_builder *s,    const char *fmt, ...)   {    va_list args;    va_start(args, fmt);    string_builder_vsprintf(s, fmt, args);    va_end(args);   }