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>
This commit is contained in:
Martin Roth
2017-04-08 17:05:23 -06:00
parent 097d753980
commit 6d189cc47b
2 changed files with 76 additions and 110 deletions

View File

@ -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);
}