You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

printf-parse.h 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 it
  4. under the terms of the GNU Library General Public License as published
  5. by 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 GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  14. USA. */
  15. #ifndef _PRINTF_PARSE_H
  16. #define _PRINTF_PARSE_H
  17. #include "printf-args.h"
  18. /* Flags */
  19. #define FLAG_GROUP 1 /* ' flag */
  20. #define FLAG_LEFT 2 /* - flag */
  21. #define FLAG_SHOWSIGN 4 /* + flag */
  22. #define FLAG_SPACE 8 /* space flag */
  23. #define FLAG_ALT 16 /* # flag */
  24. #define FLAG_ZERO 32
  25. /* arg_index value indicating that no argument is consumed. */
  26. #define ARG_NONE (~(size_t)0)
  27. /* A parsed directive. */
  28. typedef struct
  29. {
  30. const char* dir_start;
  31. const char* dir_end;
  32. int flags;
  33. const char* width_start;
  34. const char* width_end;
  35. size_t width_arg_index;
  36. const char* precision_start;
  37. const char* precision_end;
  38. size_t precision_arg_index;
  39. char conversion; /* d i o u x X f e E g G c s p n U % but not C S */
  40. size_t arg_index;
  41. }
  42. char_directive;
  43. /* A parsed format string. */
  44. typedef struct
  45. {
  46. size_t count;
  47. char_directive *dir;
  48. size_t max_width_length;
  49. size_t max_precision_length;
  50. }
  51. char_directives;
  52. /* Parses the format string. Fills in the number N of directives, and fills
  53. in directives[0], ..., directives[N-1], and sets directives[N].dir_start
  54. to the end of the format string. Also fills in the arg_type fields of the
  55. arguments and the needed count of arguments. */
  56. #ifdef STATIC
  57. STATIC
  58. #else
  59. extern
  60. #endif
  61. int printf_parse (const char *format, char_directives *d, arguments *a);
  62. #endif /* _PRINTF_PARSE_H */