source: trunk/third/gettext/lib/printf-prs.c @ 16931

Revision 16931, 2.5 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16930, which included commits to RCS files with non-trunk default branches.
Line 
1/* Copyright (C) 1991, 1992, 1995, 1996 Free Software Foundation, Inc.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation; either version 2, or (at your option)
6any later version.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20
21#include <stdio.h>
22#include <printf.h>
23#if HAVE_STDLIB_H
24# include <stdlib.h>
25#endif
26
27#include "printf-parse.h"
28
29
30size_t
31parse_printf_format (fmt, n, argtypes)
32      const char *fmt;
33      size_t n;
34      int *argtypes;
35{
36  size_t nargs;                 /* Number of arguments.  */
37  size_t max_ref_arg;           /* Highest index used in a positional arg.  */
38  struct printf_spec spec;
39
40  nargs = 0;
41  max_ref_arg = 0;
42
43  /* Search for format specifications.  */
44  for (fmt = find_spec (fmt); *fmt != '\0'; fmt = spec.next_fmt)
45    {
46      /* Parse this spec.  */
47      nargs += parse_one_spec (fmt, nargs, &spec, &max_ref_arg);
48
49      /* If the width is determined by an argument this is an int.  */
50      if (spec.width_arg != -1 && (size_t) spec.width_arg < n)
51        argtypes[spec.width_arg] = PA_INT;
52
53      /* If the precision is determined by an argument this is an int.  */
54      if (spec.prec_arg != -1 && (size_t) spec.prec_arg < n)
55        argtypes[spec.prec_arg] = PA_INT;
56
57      if ((size_t) spec.data_arg < n)
58        switch (spec.ndata_args)
59          {
60          case 0:               /* No arguments.  */
61            break;
62          case 1:               /* One argument; we already have the type.  */
63            argtypes[spec.data_arg] = spec.data_arg_type;
64            break;
65          default:
66            /* We don't handle this here.  Beside GNU libc no other
67               libc provides printf function registration.  But while
68               having this feature it also provides this function, so
69               that using *this* file is not needed.  */
70#if 0
71            /* We have more than one argument for this format spec.  We must
72               call the arginfo function again to determine all the types.  */
73            (void) (*__printf_arginfo_table[spec.info.spec])
74              (&spec.info, n - spec.data_arg, &argtypes[spec.data_arg]);
75#endif
76            break;
77          }
78    }
79
80  return MAX (nargs, max_ref_arg);
81}
Note: See TracBrowser for help on using the repository browser.