Blame lib/printf-parse.h

Packit 33f14e
/* Parse printf format string.
Packit 33f14e
   Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2017 Free Software
Packit 33f14e
   Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software; you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3, or (at your option)
Packit 33f14e
   any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License along
Packit 33f14e
   with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
#ifndef _PRINTF_PARSE_H
Packit 33f14e
#define _PRINTF_PARSE_H
Packit 33f14e
Packit 33f14e
/* This file can be parametrized with the following macros:
Packit 33f14e
     ENABLE_UNISTDIO    Set to 1 to enable the unistdio extensions.
Packit 33f14e
     STATIC             Set to 'static' to declare the function static.  */
Packit 33f14e
Packit 33f14e
#if HAVE_FEATURES_H
Packit 33f14e
# include <features.h> /* for __GLIBC__, __UCLIBC__ */
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
#include "printf-args.h"
Packit 33f14e
Packit 33f14e
Packit 33f14e
/* Flags */
Packit 33f14e
#define FLAG_GROUP       1      /* ' flag */
Packit 33f14e
#define FLAG_LEFT        2      /* - flag */
Packit 33f14e
#define FLAG_SHOWSIGN    4      /* + flag */
Packit 33f14e
#define FLAG_SPACE       8      /* space flag */
Packit 33f14e
#define FLAG_ALT        16      /* # flag */
Packit 33f14e
#define FLAG_ZERO       32
Packit 33f14e
#if __GLIBC__ >= 2 && !defined __UCLIBC__
Packit 33f14e
# define FLAG_LOCALIZED 64      /* I flag, uses localized digits */
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
/* arg_index value indicating that no argument is consumed.  */
Packit 33f14e
#define ARG_NONE        (~(size_t)0)
Packit 33f14e
Packit 33f14e
/* xxx_directive: A parsed directive.
Packit 33f14e
   xxx_directives: A parsed format string.  */
Packit 33f14e
Packit 33f14e
/* Number of directly allocated directives (no malloc() needed).  */
Packit 33f14e
#define N_DIRECT_ALLOC_DIRECTIVES 7
Packit 33f14e
Packit 33f14e
/* A parsed directive.  */
Packit 33f14e
typedef struct
Packit 33f14e
{
Packit 33f14e
  const char* dir_start;
Packit 33f14e
  const char* dir_end;
Packit 33f14e
  int flags;
Packit 33f14e
  const char* width_start;
Packit 33f14e
  const char* width_end;
Packit 33f14e
  size_t width_arg_index;
Packit 33f14e
  const char* precision_start;
Packit 33f14e
  const char* precision_end;
Packit 33f14e
  size_t precision_arg_index;
Packit 33f14e
  char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
Packit 33f14e
  size_t arg_index;
Packit 33f14e
}
Packit 33f14e
char_directive;
Packit 33f14e
Packit 33f14e
/* A parsed format string.  */
Packit 33f14e
typedef struct
Packit 33f14e
{
Packit 33f14e
  size_t count;
Packit 33f14e
  char_directive *dir;
Packit 33f14e
  size_t max_width_length;
Packit 33f14e
  size_t max_precision_length;
Packit 33f14e
  char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
Packit 33f14e
}
Packit 33f14e
char_directives;
Packit 33f14e
Packit 33f14e
#if ENABLE_UNISTDIO
Packit 33f14e
Packit 33f14e
/* A parsed directive.  */
Packit 33f14e
typedef struct
Packit 33f14e
{
Packit 33f14e
  const uint8_t* dir_start;
Packit 33f14e
  const uint8_t* dir_end;
Packit 33f14e
  int flags;
Packit 33f14e
  const uint8_t* width_start;
Packit 33f14e
  const uint8_t* width_end;
Packit 33f14e
  size_t width_arg_index;
Packit 33f14e
  const uint8_t* precision_start;
Packit 33f14e
  const uint8_t* precision_end;
Packit 33f14e
  size_t precision_arg_index;
Packit 33f14e
  uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
Packit 33f14e
  size_t arg_index;
Packit 33f14e
}
Packit 33f14e
u8_directive;
Packit 33f14e
Packit 33f14e
/* A parsed format string.  */
Packit 33f14e
typedef struct
Packit 33f14e
{
Packit 33f14e
  size_t count;
Packit 33f14e
  u8_directive *dir;
Packit 33f14e
  size_t max_width_length;
Packit 33f14e
  size_t max_precision_length;
Packit 33f14e
  u8_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
Packit 33f14e
}
Packit 33f14e
u8_directives;
Packit 33f14e
Packit 33f14e
/* A parsed directive.  */
Packit 33f14e
typedef struct
Packit 33f14e
{
Packit 33f14e
  const uint16_t* dir_start;
Packit 33f14e
  const uint16_t* dir_end;
Packit 33f14e
  int flags;
Packit 33f14e
  const uint16_t* width_start;
Packit 33f14e
  const uint16_t* width_end;
Packit 33f14e
  size_t width_arg_index;
Packit 33f14e
  const uint16_t* precision_start;
Packit 33f14e
  const uint16_t* precision_end;
Packit 33f14e
  size_t precision_arg_index;
Packit 33f14e
  uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
Packit 33f14e
  size_t arg_index;
Packit 33f14e
}
Packit 33f14e
u16_directive;
Packit 33f14e
Packit 33f14e
/* A parsed format string.  */
Packit 33f14e
typedef struct
Packit 33f14e
{
Packit 33f14e
  size_t count;
Packit 33f14e
  u16_directive *dir;
Packit 33f14e
  size_t max_width_length;
Packit 33f14e
  size_t max_precision_length;
Packit 33f14e
  u16_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
Packit 33f14e
}
Packit 33f14e
u16_directives;
Packit 33f14e
Packit 33f14e
/* A parsed directive.  */
Packit 33f14e
typedef struct
Packit 33f14e
{
Packit 33f14e
  const uint32_t* dir_start;
Packit 33f14e
  const uint32_t* dir_end;
Packit 33f14e
  int flags;
Packit 33f14e
  const uint32_t* width_start;
Packit 33f14e
  const uint32_t* width_end;
Packit 33f14e
  size_t width_arg_index;
Packit 33f14e
  const uint32_t* precision_start;
Packit 33f14e
  const uint32_t* precision_end;
Packit 33f14e
  size_t precision_arg_index;
Packit 33f14e
  uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
Packit 33f14e
  size_t arg_index;
Packit 33f14e
}
Packit 33f14e
u32_directive;
Packit 33f14e
Packit 33f14e
/* A parsed format string.  */
Packit 33f14e
typedef struct
Packit 33f14e
{
Packit 33f14e
  size_t count;
Packit 33f14e
  u32_directive *dir;
Packit 33f14e
  size_t max_width_length;
Packit 33f14e
  size_t max_precision_length;
Packit 33f14e
  u32_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
Packit 33f14e
}
Packit 33f14e
u32_directives;
Packit 33f14e
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
Packit 33f14e
/* Parses the format string.  Fills in the number N of directives, and fills
Packit 33f14e
   in directives[0], ..., directives[N-1], and sets directives[N].dir_start
Packit 33f14e
   to the end of the format string.  Also fills in the arg_type fields of the
Packit 33f14e
   arguments and the needed count of arguments.  */
Packit 33f14e
#if ENABLE_UNISTDIO
Packit 33f14e
extern int
Packit 33f14e
       ulc_printf_parse (const char *format, char_directives *d, arguments *a);
Packit 33f14e
extern int
Packit 33f14e
       u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
Packit 33f14e
extern int
Packit 33f14e
       u16_printf_parse (const uint16_t *format, u16_directives *d,
Packit 33f14e
                         arguments *a);
Packit 33f14e
extern int
Packit 33f14e
       u32_printf_parse (const uint32_t *format, u32_directives *d,
Packit 33f14e
                         arguments *a);
Packit 33f14e
#else
Packit 33f14e
# ifdef STATIC
Packit 33f14e
STATIC
Packit 33f14e
# else
Packit 33f14e
extern
Packit 33f14e
# endif
Packit 33f14e
int printf_parse (const char *format, char_directives *d, arguments *a);
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
#endif /* _PRINTF_PARSE_H */