Blame gl/printf-parse.h

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