36#ifndef WDL_LINEPARSE_H_
37#define WDL_LINEPARSE_H_
41#ifndef WDL_LINEPARSER_HAS_LINEPARSERINT
42#define WDL_LINEPARSER_HAS_LINEPARSERINT
45#ifdef WDL_LINEPARSE_ATOF
48 #define WDL_LINEPARSE_ATOF atof
51#ifndef WDL_LINEPARSE_IMPL_ONLY
57 #ifdef WDL_LINEPARSE_INTF_ONLY
59 int parseDestroyBuffer(
char *line,
bool ignore_commentchars =
true,
bool backtickquote =
true,
bool allowunterminatedquotes =
false);
87#ifndef WDL_LINEPARSE_INTF_ONLY
88 #ifdef WDL_LINEPARSE_IMPL_ONLY
89 #define WDL_LINEPARSE_PREFIX LineParserInt::
90 #define WDL_LINEPARSE_DEFPARM(x)
92 #define WDL_LINEPARSE_PREFIX
93 #define WDL_LINEPARSE_DEFPARM(x) =(x)
100 if (!line)
return -1;
105 while ((thischar=*line) ==
' ' || thischar ==
'\t') line++;
106 if (!thischar)
return 0;
110 static const char tab[4]={0,
'"',
'\'',
'`'};
117 if (!ignore_commentchars)
return 0;
119 case '"': line++; lstate=1;
break;
120 case '\'': line++; lstate=2;
break;
121 case '`':
if (backtickquote) { line++; lstate=3; }
break;
124 const char *basep = line;
126 if (!lstate)
while ((thischar=*line) && thischar !=
' ' && thischar !=
'\t') line++;
127 else while ((thischar=*line) && thischar != tab[lstate]) line++;
129 const char oldterm = *line;
147 if (lstate && !allowunterminatedquotes)
156 while ((thischar=*line) ==
' ' || thischar ==
'\t') line++;
157 if (!thischar)
return 0;
165 if ((
unsigned int)token >=
m_nt)
167 if (success) *success=0;
177 while (*
t&&ot<(
int)
sizeof(buf)-1)
180 if (
c ==
',')
c =
'.';
181 else if (success && (
c <
'0' ||
c >
'9') &&
c !=
'.') *success=0;
192 if ((
unsigned int)token >=
m_nt || !((tok=
m_tokens[token])[0]))
194 if (success) *success=0;
199 if (tok[0] ==
'-')
l=(
int)strtol(tok,&tmp,0);
200 else l=(
int)strtoul(tok,&tmp,0);
201 if (success) *success=! (
int)(*tmp);
209 if ((
unsigned int)token >=
m_nt || !((tok=
m_tokens[token])[0]))
211 if (success) *success=0;
216 if (
p[0] ==
'-') ++
p;
217 unsigned int val=(
int)strtoul(
p, &tmp, 0);
218 if (success) *success=! (
int)(*tmp);
225 if ((
unsigned int)token >=
m_nt)
return "";
232 if ((
unsigned int)token >=
m_nt)
return 0;
237 case '"':
return '"';
238 case '`':
return '`';
239 case '\'':
return '\'';
247 if ((
unsigned int)token >=
m_nt)
return -1;
251 if (*tt)
while (*strlist)
256 if (!strcasecmp(tt,strlist))
return x;
258 while (*strlist) strlist++;
265#ifndef WDL_LINEPARSE_IMPL_ONLY
270 #undef WDL_LINEPARSE_PREFIX
271 #undef WDL_LINEPARSE_DEFPARM
274#ifndef WDL_LINEPARSE_IMPL_ONLY
295#ifndef WDL_LINEPARSE_IMPL_ONLY
301 #ifdef WDL_LINEPARSE_INTF_ONLY
303 int parse_ex(
const char *line,
bool ignore_commentchars =
true,
bool backtickquote =
true,
bool allowunterminatedquotes =
false);
315#ifndef WDL_LINEPARSE_INTF_ONLY
316 #ifdef WDL_LINEPARSE_IMPL_ONLY
317 #define WDL_LINEPARSE_PREFIX LineParser::
318 #define WDL_LINEPARSE_DEFPARM(x)
320 #define WDL_LINEPARSE_PREFIX
321 #define WDL_LINEPARSE_DEFPARM(x) =(x)
339 int linelen = (
int)strlen(line);
342 if (linelen >= (
int)
sizeof(
m_tmpbuf))
344 usebuf = (
char *)
m_tmpbuf_big.ResizeOK(linelen+1,
false);
351 memcpy(usebuf,line,linelen+1);
355 #undef WDL_LINEPARSE_PREFIX
356 #undef WDL_LINEPARSE_DEFPARM
359#ifndef WDL_LINEPARSE_IMPL_ONLY
LineParser(bool ignoredLegacyValue=false)
Definition lineparse.h:309
char *WDL_LINEPARSE_PREFIX __get_tmpbuf(const char *line)
Definition lineparse.h:337
int WDL_LINEPARSE_PREFIX parse_ex(const char *line, bool ignore_commentchars WDL_LINEPARSE_DEFPARM(true), bool backtickquote WDL_LINEPARSE_DEFPARM(true), bool allowunterminatedquotes WDL_LINEPARSE_DEFPARM(false))
Definition lineparse.h:324
char m_tmpbuf[2048]
Definition lineparse.h:363
int parse(const char *line)
Definition lineparse.h:299
void WDL_LINEPARSE_PREFIX set_one_token(const char *line)
Definition lineparse.h:329
WDL_HeapBuf m_tmpbuf_big
Definition lineparse.h:362
int WDL_LINEPARSE_PREFIX gettoken_enum(int token, const char *strlist) const
Definition lineparse.h:244
WDL_TypedBuf< const char * > m_toklist_big
Definition lineparse.h:277
double WDL_LINEPARSE_PREFIX gettoken_float(int token, int *success WDL_LINEPARSE_DEFPARM(NULL)) const
Definition lineparse.h:162
const char *WDL_LINEPARSE_PREFIX gettoken_str(int token) const
Definition lineparse.h:222
const char * m_toklist_small[64]
Definition lineparse.h:284
unsigned int WDL_LINEPARSE_PREFIX gettoken_uint(int token, int *success WDL_LINEPARSE_DEFPARM(NULL)) const
Definition lineparse.h:205
LineParserInt()
Definition lineparse.h:72
char WDL_LINEPARSE_PREFIX gettoken_quotingchar(int token) const
Definition lineparse.h:229
int WDL_LINEPARSE_PREFIX parseDestroyBuffer(char *line, bool ignore_commentchars WDL_LINEPARSE_DEFPARM(true), bool backtickquote WDL_LINEPARSE_DEFPARM(true), bool allowunterminatedquotes WDL_LINEPARSE_DEFPARM(false))
Definition lineparse.h:96
unsigned int m_nt
Definition lineparse.h:279
~LineParserInt()
Definition lineparse.h:79
const char ** m_tokens
Definition lineparse.h:282
unsigned int m_eat
Definition lineparse.h:279
const char * m_tokenbasebuffer
Definition lineparse.h:281
void eattoken()
Definition lineparse.h:69
int WDL_LINEPARSE_PREFIX gettoken_int(int token, int *success WDL_LINEPARSE_DEFPARM(NULL)) const
Definition lineparse.h:188
int getnumtokens() const
Definition lineparse.h:55
int * l
Definition inflate.c:1579
struct huft * t
Definition inflate.c:943
unsigned x[BMAX+1]
Definition inflate.c:1586
int val
Definition jpeglib.h:956
#define WDL_LINEPARSE_ATOF
Definition lineparse.h:48
#define WDL_LINEPARSE_PREFIX
Definition lineparse.h:92
#define WDL_LINEPARSE_DEFPARM(x)
Definition lineparse.h:93
#define stricmp(x, y)
Definition swell-types.h:68
uch * p
Definition crypt.c:594
return c
Definition crypt.c:175
memcpy(hh, h, RAND_HEAD_LEN)
typedef int(UZ_EXP MsgFn)()