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