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