printf-parse.h 2.1 KB

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