2N/A/* Parse printf format string.
2N/A Copyright (C) 1999, 2002-2003, 2005, 2007, 2009-2010 Free Software
2N/A Foundation, Inc.
2N/A
2N/A This program is free software; you can redistribute it and/or modify
2N/A it under the terms of the GNU General Public License as published by
2N/A the Free Software Foundation; either version 3, or (at your option)
2N/A any later version.
2N/A
2N/A This program is distributed in the hope that it will be useful,
2N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A GNU General Public License for more details.
2N/A
2N/A You should have received a copy of the GNU General Public License along
2N/A with this program; if not, write to the Free Software Foundation,
2N/A Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
2N/A
2N/A#ifndef _PRINTF_PARSE_H
2N/A#define _PRINTF_PARSE_H
2N/A
2N/A/* This file can be parametrized with the following macros:
2N/A ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
2N/A STATIC Set to 'static' to declare the function static. */
2N/A
2N/A#include "printf-args.h"
2N/A
2N/A
2N/A/* Flags */
2N/A#define FLAG_GROUP 1 /* ' flag */
2N/A#define FLAG_LEFT 2 /* - flag */
2N/A#define FLAG_SHOWSIGN 4 /* + flag */
2N/A#define FLAG_SPACE 8 /* space flag */
2N/A#define FLAG_ALT 16 /* # flag */
2N/A#define FLAG_ZERO 32
2N/A
2N/A/* arg_index value indicating that no argument is consumed. */
2N/A#define ARG_NONE (~(size_t)0)
2N/A
2N/A/* xxx_directive: A parsed directive.
2N/A xxx_directives: A parsed format string. */
2N/A
2N/A/* A parsed directive. */
2N/Atypedef struct
2N/A{
2N/A const char* dir_start;
2N/A const char* dir_end;
2N/A int flags;
2N/A const char* width_start;
2N/A const char* width_end;
2N/A size_t width_arg_index;
2N/A const char* precision_start;
2N/A const char* precision_end;
2N/A size_t precision_arg_index;
2N/A 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 */
2N/A size_t arg_index;
2N/A}
2N/Achar_directive;
2N/A
2N/A/* A parsed format string. */
2N/Atypedef struct
2N/A{
2N/A size_t count;
2N/A char_directive *dir;
2N/A size_t max_width_length;
2N/A size_t max_precision_length;
2N/A}
2N/Achar_directives;
2N/A
2N/A#if ENABLE_UNISTDIO
2N/A
2N/A/* A parsed directive. */
2N/Atypedef struct
2N/A{
2N/A const uint8_t* dir_start;
2N/A const uint8_t* dir_end;
2N/A int flags;
2N/A const uint8_t* width_start;
2N/A const uint8_t* width_end;
2N/A size_t width_arg_index;
2N/A const uint8_t* precision_start;
2N/A const uint8_t* precision_end;
2N/A size_t precision_arg_index;
2N/A 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 */
2N/A size_t arg_index;
2N/A}
2N/Au8_directive;
2N/A
2N/A/* A parsed format string. */
2N/Atypedef struct
2N/A{
2N/A size_t count;
2N/A u8_directive *dir;
2N/A size_t max_width_length;
2N/A size_t max_precision_length;
2N/A}
2N/Au8_directives;
2N/A
2N/A/* A parsed directive. */
2N/Atypedef struct
2N/A{
2N/A const uint16_t* dir_start;
2N/A const uint16_t* dir_end;
2N/A int flags;
2N/A const uint16_t* width_start;
2N/A const uint16_t* width_end;
2N/A size_t width_arg_index;
2N/A const uint16_t* precision_start;
2N/A const uint16_t* precision_end;
2N/A size_t precision_arg_index;
2N/A 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 */
2N/A size_t arg_index;
2N/A}
2N/Au16_directive;
2N/A
2N/A/* A parsed format string. */
2N/Atypedef struct
2N/A{
2N/A size_t count;
2N/A u16_directive *dir;
2N/A size_t max_width_length;
2N/A size_t max_precision_length;
2N/A}
2N/Au16_directives;
2N/A
2N/A/* A parsed directive. */
2N/Atypedef struct
2N/A{
2N/A const uint32_t* dir_start;
2N/A const uint32_t* dir_end;
2N/A int flags;
2N/A const uint32_t* width_start;
2N/A const uint32_t* width_end;
2N/A size_t width_arg_index;
2N/A const uint32_t* precision_start;
2N/A const uint32_t* precision_end;
2N/A size_t precision_arg_index;
2N/A 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 */
2N/A size_t arg_index;
2N/A}
2N/Au32_directive;
2N/A
2N/A/* A parsed format string. */
2N/Atypedef struct
2N/A{
2N/A size_t count;
2N/A u32_directive *dir;
2N/A size_t max_width_length;
2N/A size_t max_precision_length;
2N/A}
2N/Au32_directives;
2N/A
2N/A#endif
2N/A
2N/A
2N/A/* Parses the format string. Fills in the number N of directives, and fills
2N/A in directives[0], ..., directives[N-1], and sets directives[N].dir_start
2N/A to the end of the format string. Also fills in the arg_type fields of the
2N/A arguments and the needed count of arguments. */
2N/A#if ENABLE_UNISTDIO
2N/Aextern int
2N/A ulc_printf_parse (const char *format, char_directives *d, arguments *a);
2N/Aextern int
2N/A u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
2N/Aextern int
2N/A u16_printf_parse (const uint16_t *format, u16_directives *d,
2N/A arguments *a);
2N/Aextern int
2N/A u32_printf_parse (const uint32_t *format, u32_directives *d,
2N/A arguments *a);
2N/A#else
2N/A# ifdef STATIC
2N/ASTATIC
2N/A# else
2N/Aextern
2N/A# endif
2N/Aint printf_parse (const char *format, char_directives *d, arguments *a);
2N/A#endif
2N/A
2N/A#endif /* _PRINTF_PARSE_H */