Back to index

nagios-plugins  1.4.16
printf-parse.h
Go to the documentation of this file.
00001 /* Parse printf format string.
00002    Copyright (C) 1999, 2002-2003, 2005, 2007, 2009-2010 Free Software
00003    Foundation, Inc.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 3, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License along
00016    with this program; if not, write to the Free Software Foundation,
00017    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00018 
00019 #ifndef _PRINTF_PARSE_H
00020 #define _PRINTF_PARSE_H
00021 
00022 /* This file can be parametrized with the following macros:
00023      ENABLE_UNISTDIO    Set to 1 to enable the unistdio extensions.
00024      STATIC             Set to 'static' to declare the function static.  */
00025 
00026 #include "printf-args.h"
00027 
00028 
00029 /* Flags */
00030 #define FLAG_GROUP       1      /* ' flag */
00031 #define FLAG_LEFT        2      /* - flag */
00032 #define FLAG_SHOWSIGN    4      /* + flag */
00033 #define FLAG_SPACE       8      /* space flag */
00034 #define FLAG_ALT        16      /* # flag */
00035 #define FLAG_ZERO       32
00036 
00037 /* arg_index value indicating that no argument is consumed.  */
00038 #define ARG_NONE        (~(size_t)0)
00039 
00040 /* xxx_directive: A parsed directive.
00041    xxx_directives: A parsed format string.  */
00042 
00043 /* A parsed directive.  */
00044 typedef struct
00045 {
00046   const char* dir_start;
00047   const char* dir_end;
00048   int flags;
00049   const char* width_start;
00050   const char* width_end;
00051   size_t width_arg_index;
00052   const char* precision_start;
00053   const char* precision_end;
00054   size_t precision_arg_index;
00055   char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
00056   size_t arg_index;
00057 }
00058 char_directive;
00059 
00060 /* A parsed format string.  */
00061 typedef struct
00062 {
00063   size_t count;
00064   char_directive *dir;
00065   size_t max_width_length;
00066   size_t max_precision_length;
00067 }
00068 char_directives;
00069 
00070 #if ENABLE_UNISTDIO
00071 
00072 /* A parsed directive.  */
00073 typedef struct
00074 {
00075   const uint8_t* dir_start;
00076   const uint8_t* dir_end;
00077   int flags;
00078   const uint8_t* width_start;
00079   const uint8_t* width_end;
00080   size_t width_arg_index;
00081   const uint8_t* precision_start;
00082   const uint8_t* precision_end;
00083   size_t precision_arg_index;
00084   uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
00085   size_t arg_index;
00086 }
00087 u8_directive;
00088 
00089 /* A parsed format string.  */
00090 typedef struct
00091 {
00092   size_t count;
00093   u8_directive *dir;
00094   size_t max_width_length;
00095   size_t max_precision_length;
00096 }
00097 u8_directives;
00098 
00099 /* A parsed directive.  */
00100 typedef struct
00101 {
00102   const uint16_t* dir_start;
00103   const uint16_t* dir_end;
00104   int flags;
00105   const uint16_t* width_start;
00106   const uint16_t* width_end;
00107   size_t width_arg_index;
00108   const uint16_t* precision_start;
00109   const uint16_t* precision_end;
00110   size_t precision_arg_index;
00111   uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
00112   size_t arg_index;
00113 }
00114 u16_directive;
00115 
00116 /* A parsed format string.  */
00117 typedef struct
00118 {
00119   size_t count;
00120   u16_directive *dir;
00121   size_t max_width_length;
00122   size_t max_precision_length;
00123 }
00124 u16_directives;
00125 
00126 /* A parsed directive.  */
00127 typedef struct
00128 {
00129   const uint32_t* dir_start;
00130   const uint32_t* dir_end;
00131   int flags;
00132   const uint32_t* width_start;
00133   const uint32_t* width_end;
00134   size_t width_arg_index;
00135   const uint32_t* precision_start;
00136   const uint32_t* precision_end;
00137   size_t precision_arg_index;
00138   uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
00139   size_t arg_index;
00140 }
00141 u32_directive;
00142 
00143 /* A parsed format string.  */
00144 typedef struct
00145 {
00146   size_t count;
00147   u32_directive *dir;
00148   size_t max_width_length;
00149   size_t max_precision_length;
00150 }
00151 u32_directives;
00152 
00153 #endif
00154 
00155 
00156 /* Parses the format string.  Fills in the number N of directives, and fills
00157    in directives[0], ..., directives[N-1], and sets directives[N].dir_start
00158    to the end of the format string.  Also fills in the arg_type fields of the
00159    arguments and the needed count of arguments.  */
00160 #if ENABLE_UNISTDIO
00161 extern int
00162        ulc_printf_parse (const char *format, char_directives *d, arguments *a);
00163 extern int
00164        u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
00165 extern int
00166        u16_printf_parse (const uint16_t *format, u16_directives *d,
00167                          arguments *a);
00168 extern int
00169        u32_printf_parse (const uint32_t *format, u32_directives *d,
00170                          arguments *a);
00171 #else
00172 # ifdef STATIC
00173 STATIC
00174 # else
00175 extern
00176 # endif
00177 int printf_parse (const char *format, char_directives *d, arguments *a);
00178 #endif
00179 
00180 #endif /* _PRINTF_PARSE_H */