1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-20 16:43:03 +03:00

Fri Mar 24 02:35:37 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>

* stdio/printf-parse.h: New file, mostly written by drepper.
	* stdio/vfprintf.c: Rewritten, mostly by drepper.
	* stdio/printf-prs.c: Rewritten.
	* stdio/Makefile (distribute): Add printf-parse.h.

Thu Mar 23 22:03:44 1995  Roland McGrath  <roland@churchy.gnu.ai.mit.edu>

	* sysdeps/unix/start.c [! NO_UNDERSCORES]: Don't declare _start
 	with asm name.  Just do a ".set start, __start".

	* malloc/realloc.c: Call _free_internal instead of free.

	* stdlib/Makefile: All the mpn stuff moved here from stdio/Makefile.
This commit is contained in:
Roland McGrath
1995-03-24 07:44:08 +00:00
parent 3ef21326e9
commit a04e740593
6 changed files with 943 additions and 739 deletions

View File

@ -16,196 +16,57 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stdio.h>
#include <printf.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef __GNUC__
#define HAVE_LONGLONG
#endif
#include "printf-parse.h"
extern printf_arginfo_function *__printf_arginfo_table[];
size_t
DEFUN(parse_printf_format, (fmt, n, argtypes),
CONST char *fmt AND size_t n AND int *argtypes)
parse_printf_format (fmt, n, argtypes)
const char *fmt;
size_t n;
int *argtypes;
{
register CONST char *f;
size_t need = 0;
size_t nargs; /* Number of arguments. */
size_t max_ref_arg; /* Highest index used in a positional arg. */
struct printf_spec spec;
for (f = strchr (fmt, '%'); f != NULL; f = strchr (f, '%'))
nargs = 0;
max_ref_arg = 0;
/* Search for format specifications. */
for (fmt = find_spec (fmt); *fmt != '\0'; fmt = spec.next_fmt)
{
struct printf_info info;
printf_arginfo_function *arginfo;
/* Parse this spec. */
nargs += parse_one_spec (fmt, nargs, &spec, &max_ref_arg);
++f;
/* If the width is determined by an argument this is an int. */
if (spec.width_arg != -1 && spec.width_arg < n)
argtypes[spec.width_arg] = PA_INT;
info.space = info.showsign = info.left = info.alt = info.group = 0;
info.pad = ' ';
while (*f == ' ' || *f == '+' || *f == '-' || *f == '#' || *f == '0' ||
*f == '\'')
switch (*f++)
/* If the precision is determined by an argument this is an int. */
if (spec.prec_arg != -1 && spec.prec_arg < n)
argtypes[spec.prec_arg] = PA_INT;
if (spec.data_arg < n)
switch (spec.ndata_args)
{
case ' ':
info.space = 1;
case 0: /* No arguments. */
break;
case '+':
info.showsign = 1;
case 1: /* One argument; we already have the type. */
argtypes[spec.data_arg] = spec.data_arg_type;
break;
case '-':
info.left = 1;
break;
case '#':
info.alt = 1;
break;
case '\'':
info.group = 1;
break;
case '0':
info.pad = '0';
default:
/* We have more than one argument for this format spec. We must
call the arginfo function again to determine all the types. */
(void) (*__printf_arginfo_table[spec.info.spec])
(&spec.info, n - spec.data_arg, &argtypes[spec.data_arg]);
break;
}
if (info.left)
info.pad = ' ';
/* Get the field width. */
if (*f == '*')
{
if (++need < n)
*argtypes++ = PA_INT;
info.width = INT_MIN;
++f;
}
else
{
info.width = 0;
while (isdigit(*f))
{
info.width *= 10;
info.width += *f++ - '0';
}
}
/* Get the precision. */
/* -1 means none given; 0 means explicit 0. */
info.prec = -1;
if (*f == '.')
{
++f;
if (*f == '*')
{
/* The precision is given in an argument. */
if (++need < n)
*argtypes++ = PA_INT;
info.prec = INT_MIN;
++f;
}
else if (isdigit(*f))
{
info.prec = 0;
while (*f != '\0' && isdigit(*f))
{
info.prec *= 10;
info.prec += *f++ - '0';
}
}
}
/* Check for type modifiers. */
info.is_short = info.is_long = info.is_long_double = 0;
while (*f == 'h' || *f == 'l' || *f == 'L')
switch (*f++)
{
case 'h':
/* int's are short int's. */
info.is_short = 1;
break;
case 'l':
#ifdef HAVE_LONGLONG
if (info.is_long)
/* A double `l' is equivalent to an `L'. */
info.is_long_double = 1;
else
#endif
/* int's are long int's. */
info.is_long = 1;
break;
case 'L':
/* double's are long double's, and int's are long long int's. */
info.is_long_double = 1;
break;
}
if (*f == '\0')
return need;
info.spec = *f++;
arginfo = __printf_arginfo_table[info.spec];
if (arginfo != NULL)
{
size_t nargs
= (*arginfo) (&info, need > n ? 0 : n - need, argtypes);
need += nargs;
argtypes += nargs;
}
else
{
int type;
switch (info.spec)
{
case 'i':
case 'd':
case 'u':
case 'o':
case 'X':
case 'x':
type = PA_INT;
break;
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
type = PA_DOUBLE;
break;
case 'c':
type = PA_CHAR;
break;
case 's':
type = PA_STRING;
break;
case 'p':
type = PA_POINTER;
break;
case 'n':
type = PA_INT | PA_FLAG_PTR;
break;
default:
/* No arg for an unknown spec. */
continue;
}
if (info.is_long_double)
type |= PA_FLAG_LONG_DOUBLE;
if (info.is_long)
type |= PA_FLAG_LONG;
if (info.is_short)
type |= PA_FLAG_SHORT;
if (++need < n)
*argtypes++ = type;
}
}
return need;
return MAX (nargs, max_ref_arg);
}