Blame glib/gnulib/printf-parse.h

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