From: Eric Bollengier Date: Wed, 17 Dec 2008 14:03:44 +0000 (+0000) Subject: ebl Add 64bit routine for range scan X-Git-Tag: Release-7.0.0~3619 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b5426d4bf78a8201b62237e021ba5fc8fea3c8e8;p=bacula%2Fbacula ebl Add 64bit routine for range scan git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8176 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index 808b23a5a7..03b64ac0d2 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -351,6 +351,23 @@ static uint32_t scan_pint(LEX *lf, char *str) return (uint32_t)val; } +static uint64_t scan_pint64(LEX *lf, char *str) +{ + uint64_t val = 0; + if (!is_a_number(str)) { + scan_err1(lf, _("expected a positive integer number, got: %s"), str); + /* NOT REACHED */ + } else { + errno = 0; + val = str_to_uint64(str); + if (errno != 0) { + scan_err1(lf, _("expected a positive integer number, got: %s"), str); + /* NOT REACHED */ + } + } + return val; +} + /* * * Get the next token from the input @@ -729,6 +746,26 @@ lex_get_token(LEX *lf, int expect) } break; + case T_PINT64_RANGE: + if (token == T_NUMBER) { + lf->pint64_val = scan_pint64(lf, lf->str); + lf->pint64_val2 = lf->pint64_val; + token = T_PINT64; + } else { + char *p = strchr(lf->str, '-'); + if (!p) { + scan_err2(lf, _("expected an integer or a range, got %s: %s"), + lex_tok_to_str(token), lf->str); + token = T_ERROR; + break; + } + *p++ = 0; /* terminate first half of range */ + lf->pint64_val = scan_pint64(lf, lf->str); + lf->pint64_val2 = scan_pint64(lf, p); + token = T_PINT64_RANGE; + } + break; + case T_NAME: if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) { scan_err2(lf, _("expected a name, got %s: %s"), diff --git a/bacula/src/lib/lex.h b/bacula/src/lib/lex.h index b4cebb5ba0..4a24f898fe 100644 --- a/bacula/src/lib/lex.h +++ b/bacula/src/lib/lex.h @@ -73,6 +73,8 @@ #define T_INT64 117 /* 64 bit integer */ #define T_NAME 118 /* name max 128 chars */ #define T_STRING 119 /* string */ +#define T_PINT64_RANGE 120 /* positive integer range */ +#define T_PINT64 121 /* positive integer range */ #define T_ALL 0 /* no expectations */ @@ -116,6 +118,8 @@ typedef struct s_lex_context { uint32_t pint32_val2; int32_t int32_val; int64_t int64_val; + uint64_t pint64_val; + uint64_t pint64_val2; void (*scan_error)(const char *file, int line, struct s_lex_context *lc, const char *msg, ...); int err_type; /* message level for scan_error (M_..) */ void *caller_ctx; /* caller private data */