1 /* scanner generator for flashmap descriptor language */
2 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include "fmd_parser.h"
10 int parse_integer(char *src, int base);
11 int copy_string(const char *src);
20 [[:space:]]+ /* Eat whitespace. */
21 #.*$ /* Eat comments. */
22 \( BEGIN(FLAGS); return *yytext;
23 <FLAGS>\) BEGIN(INITIAL); return *yytext;
24 <FLAGS>CBFS return FLAG_CBFS;
25 <FLAGS>PRESERVE return FLAG_PRESERVE;
27 [1-9][0-9]*{MULTIPLIER}? return parse_integer(yytext, 10);
28 0[0-9]+{MULTIPLIER}? return OCTAL;
29 0[xX][0-9a-fA-F]+{MULTIPLIER}? return parse_integer(yytext + 2, 16);
30 [^#@{}()[:space:]]* return copy_string(yytext);
35 int parse_integer(char *src, int base)
37 char *multiplier = NULL;
38 unsigned val = strtoul(src, &multiplier, base);
49 val *= 1024*1024*1024;
52 // If we ever get here, the MULTIPLIER regex is allowing
53 // multiplier suffixes not handled by this code.
62 int copy_string(const char *src)
64 yylval.strval = strdup(src);