Blame gnulib-tests/printf-parse.h

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