summaryrefslogtreecommitdiff
path: root/util/blobtool/blobtool.l
diff options
context:
space:
mode:
authorMartin Roth <martinroth@google.com>2017-04-08 17:05:23 -0600
committerMartin Roth <martinroth@google.com>2017-04-24 19:00:45 +0200
commit6d189cc47bf1f0c7d7f7cbf7efbe5a41ebcbc4af (patch)
treebc6357f6205d8397e2f7c9e5f7306b95e3075a4b /util/blobtool/blobtool.l
parent097d75398081093f2a95abee0994362ddb838d18 (diff)
downloadcoreboot-6d189cc47bf1f0c7d7f7cbf7efbe5a41ebcbc4af.tar.xz
util/blobtool: clean up blobtool.l a bit
- Rewrite STRING and COMMENT expressions to remove need for CHARS. - Clean up regular expressions - get rid of unnecessary expressions. - Remove extra newline from the end of the file. - Clean up stripquotes() function -- Remove unnecessary backslashes in '\"' -- Check malloc for failure -- Remove unnecessary assignment of 0 to the end of the new string, snprintf will take care of it. - Update blobtool.lex.c_shipped to the new version. Change-Id: I002962cfae0816ed3c7a5811dfb1b8b48fdc5729 Signed-off-by: Martin Roth <martinroth@google.com> Reviewed-on: https://review.coreboot.org/19230 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'util/blobtool/blobtool.l')
-rw-r--r--util/blobtool/blobtool.l40
1 files changed, 14 insertions, 26 deletions
diff --git a/util/blobtool/blobtool.l b/util/blobtool/blobtool.l
index 43c2b15971..b80cc5550d 100644
--- a/util/blobtool/blobtool.l
+++ b/util/blobtool/blobtool.l
@@ -45,14 +45,16 @@ char* stripquotes (char *string)
{
char *stripped;
unsigned int len = strlen(string);
- if (len >= 2 && string[0] == '\"' && string[len-1] == '\"') {
- stripped = (char *) malloc (len - 2 + 1);
- snprintf (stripped, len - 2 + 1, "%s", string+1);
- stripped[len-2] = '\0';
+ if (len >= 2 && string[0] == '"' && string[len - 1] == '"') {
+ stripped = (char *) malloc (len - 1);
+ if (stripped == NULL) {
+ printf("Out of memory\n");
+ exit(1);
+ }
+ snprintf (stripped, len - 1, "%s", string + 1);
return stripped;
- } else {
- return 0;
}
+ return NULL;
}
%}
@@ -60,27 +62,14 @@ char* stripquotes (char *string)
%option noyywrap
%option nounput
-DIGIT1to9 [1-9]
DIGIT [0-9]
-DIGITS {DIGIT}+
-INT {DIGIT}|{DIGIT1to9}{DIGITS}|-{DIGIT}|-{DIGIT1to9}{DIGITS}
-FRAC [.]{DIGITS}
-E [eE][+-]?
-EXP {E}{DIGITS}
-HEX_DIGIT [0-9a-fA-F]
-HEX_DIGITS {HEX_DIGIT}+
+INT [-]?{DIGIT}|[-]?[1-9]{DIGIT}+
+FRAC [.]{DIGIT}+
+EXP [eE][+-]?{DIGIT}+
NUMBER {INT}|{INT}{FRAC}|{INT}{EXP}|{INT}{FRAC}{EXP}
-UNICODECHAR \\u{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}
-ALPHA [a-zA-Z]
-SPECIAL [()\[\]"'@_\-+:;/\\.,<> ]
-VARCHAR {ALPHA}|{DIGIT}|{SPECIAL}
-CHAR {VARCHAR}|{UNICODECHAR}
-CHARS {CHAR}+
-QUOTE ["]
-HEX_PREFIX [0][x]
-HEX {HEX_PREFIX}{HEX_DIGITS}
-STRING {QUOTE}{QUOTE}|{QUOTE}{CHARS}{QUOTE}
-COMMENT [#]{CHARS}[\n]|[#]\n
+HEX [0][x][0-9a-fA-F]+
+STRING ["][^"]*["]
+COMMENT [#][^\n]*$
%%
@@ -142,4 +131,3 @@ COMMENT [#]{CHARS}[\n]|[#]\n
void set_input_string(char* in) {
yy_scan_string(in);
}
-