]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Correct handling of installable printf handlers.
authorUlrich Drepper <drepper@redhat.com>
Sat, 5 Apr 1997 00:43:06 +0000 (00:43 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 5 Apr 1997 00:43:06 +0000 (00:43 +0000)
stdio-common/printf-parse.h
stdio-common/printf.h
stdio-common/vfprintf.c

index 141164b04bc11e5b50abb149857fec31e70b618a..f1fecdb2759b3ce805012714827325e63b29d004 100644 (file)
@@ -1,5 +1,5 @@
 /* Internal header for parsing printf format strings.
-   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
    This file is part of th GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -106,8 +106,9 @@ find_spec (const char *format, mbstate_t *ps)
 }
 
 
-/* This is defined in reg-printf.c.  */
-extern printf_arginfo_function **__printf_arginfo_table;
+/* These are defined in reg-printf.c.  */
+extern printf_arginfo_function *__printf_arginfo_table[];
+extern printf_function **__printf_function_table;
 
 
 /* FORMAT must point to a '%' at the beginning of a spec.  Fills in *SPEC
@@ -299,8 +300,9 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
 
   /* Get the format specification.  */
   spec->info.spec = (wchar_t) *format++;
-  if (__printf_arginfo_table != NULL &&
-      __printf_arginfo_table[spec->info.spec] != NULL)
+  if (__printf_function_table != NULL
+      && spec->info.spec <= UCHAR_MAX
+      && __printf_arginfo_table[spec->info.spec] != NULL)
     /* We don't try to get the types for all arguments if the format
        uses more than one.  The normal case is covered though.  */
     spec->ndata_args = (*__printf_arginfo_table[spec->info.spec])
@@ -362,15 +364,14 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
          spec->ndata_args = 0;
          break;
        }
+    }
 
-      if (spec->data_arg == -1 && spec->ndata_args > 0)
-       {
-         /* There are args consumed, but no positional spec.
-            Use the next sequential arg position.  */
-         spec->data_arg = posn;
-         posn += spec->ndata_args;
-         nargs += spec->ndata_args;
-       }
+  if (spec->data_arg == -1 && spec->ndata_args > 0)
+    {
+      /* There are args consumed, but no positional spec.  Use the
+        next sequential arg position.  */
+      spec->data_arg = posn;
+      nargs += spec->ndata_args;
     }
 
   if (spec->info.spec == L'\0')
index 6d9e8a455f3cea1bda03fda80ae06f91ef491772..c49172b88c0ea050b8f0ef0509985ec01e9e2532 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 95, 96 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -122,6 +122,21 @@ enum
 #define        PA_FLAG_PTR             (1 << 11)
 
 
+
+/* Function which can be registered as `printf'-handlers.  */
+
+/* Print floating point value using using abbreviations for the orders
+   of magnitude used for numbers ('k' for kilo, 'm' for mega etc).  If
+   the format specifier is a uppercase character powers of 1000 are
+   used.  Otherwise powers of 1024.  */
+extern int printf_size __P ((FILE *__fp, __const struct printf_info *__info,
+                            __const void *__const *args));
+
+/* This is the appropriate argument information function for `printf_size'.  */
+extern int printf_size_info __P ((__const struct printf_info *__info,
+                                 size_t __n, int *__argtypes));
+
+
 __END_DECLS
 
 #endif /* printf.h  */
index 4bd564fdc064d0e6fa6ae1aa7965985ab1b10106..82348af2377dfc89754e4cc324272d1f3ceb9bc2 100644 (file)
@@ -1084,6 +1084,9 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
          goto do_positional;
        }
 
+      /* The format is correctly handled.  */
+      ++nspecs_done;
+
       /* Look for next format specifier.  */
       f = find_spec ((end_of_spec = ++f), &mbstate);