Blame lib/printf-parse.h

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