1*946379e7Schristos /* Parse printf format string. 2*946379e7Schristos Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. 3*946379e7Schristos 4*946379e7Schristos This program is free software; you can redistribute it and/or modify it 5*946379e7Schristos under the terms of the GNU Library General Public License as published 6*946379e7Schristos by the Free Software Foundation; either version 2, or (at your option) 7*946379e7Schristos any later version. 8*946379e7Schristos 9*946379e7Schristos This program is distributed in the hope that it will be useful, 10*946379e7Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 11*946379e7Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12*946379e7Schristos Library General Public License for more details. 13*946379e7Schristos 14*946379e7Schristos You should have received a copy of the GNU Library General Public 15*946379e7Schristos License along with this program; if not, write to the Free Software 16*946379e7Schristos Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 17*946379e7Schristos USA. */ 18*946379e7Schristos 19*946379e7Schristos #ifndef _PRINTF_PARSE_H 20*946379e7Schristos #define _PRINTF_PARSE_H 21*946379e7Schristos 22*946379e7Schristos #include "printf-args.h" 23*946379e7Schristos 24*946379e7Schristos 25*946379e7Schristos /* Flags */ 26*946379e7Schristos #define FLAG_GROUP 1 /* ' flag */ 27*946379e7Schristos #define FLAG_LEFT 2 /* - flag */ 28*946379e7Schristos #define FLAG_SHOWSIGN 4 /* + flag */ 29*946379e7Schristos #define FLAG_SPACE 8 /* space flag */ 30*946379e7Schristos #define FLAG_ALT 16 /* # flag */ 31*946379e7Schristos #define FLAG_ZERO 32 32*946379e7Schristos 33*946379e7Schristos /* arg_index value indicating that no argument is consumed. */ 34*946379e7Schristos #define ARG_NONE (~(size_t)0) 35*946379e7Schristos 36*946379e7Schristos /* A parsed directive. */ 37*946379e7Schristos typedef struct 38*946379e7Schristos { 39*946379e7Schristos const char* dir_start; 40*946379e7Schristos const char* dir_end; 41*946379e7Schristos int flags; 42*946379e7Schristos const char* width_start; 43*946379e7Schristos const char* width_end; 44*946379e7Schristos size_t width_arg_index; 45*946379e7Schristos const char* precision_start; 46*946379e7Schristos const char* precision_end; 47*946379e7Schristos size_t precision_arg_index; 48*946379e7Schristos char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ 49*946379e7Schristos size_t arg_index; 50*946379e7Schristos } 51*946379e7Schristos char_directive; 52*946379e7Schristos 53*946379e7Schristos /* A parsed format string. */ 54*946379e7Schristos typedef struct 55*946379e7Schristos { 56*946379e7Schristos size_t count; 57*946379e7Schristos char_directive *dir; 58*946379e7Schristos size_t max_width_length; 59*946379e7Schristos size_t max_precision_length; 60*946379e7Schristos } 61*946379e7Schristos char_directives; 62*946379e7Schristos 63*946379e7Schristos 64*946379e7Schristos /* Parses the format string. Fills in the number N of directives, and fills 65*946379e7Schristos in directives[0], ..., directives[N-1], and sets directives[N].dir_start 66*946379e7Schristos to the end of the format string. Also fills in the arg_type fields of the 67*946379e7Schristos arguments and the needed count of arguments. */ 68*946379e7Schristos #ifdef STATIC 69*946379e7Schristos STATIC 70*946379e7Schristos #else 71*946379e7Schristos extern 72*946379e7Schristos #endif 73*946379e7Schristos int printf_parse (const char *format, char_directives *d, arguments *a); 74*946379e7Schristos 75*946379e7Schristos #endif /* _PRINTF_PARSE_H */ 76