[coreboot-gerrit] Change in coreboot[master]: util/blobtool: clean up blobtool.l a bit

Martin Roth (Code Review) gerrit at coreboot.org
Mon Apr 10 18:52:48 CEST 2017


Martin Roth has uploaded a new change for review. ( https://review.coreboot.org/19230 )

Change subject: util/blobtool: clean up blobtool.l a bit
......................................................................

util/blobtool: clean up blobtool.l a bit

- Clean up regular expressions - Get rid of DIGITS, HEX_DIGITS, & CHARS
- Add characters '~!#$%^&*?' to the list of special characters.  These
previously caused syntax errors if they were in a comment.
- 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 at google.com>
---
M util/blobtool/blobtool.l
M util/blobtool/blobtool.lex.c_shipped
2 files changed, 85 insertions(+), 87 deletions(-)


  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/30/19230/1

diff --git a/util/blobtool/blobtool.l b/util/blobtool/blobtool.l
index 43c2b15..2c4ef92 100644
--- a/util/blobtool/blobtool.l
+++ b/util/blobtool/blobtool.l
@@ -45,14 +45,16 @@
 {
 	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;
 }
 
 %}
@@ -62,25 +64,22 @@
 
 DIGIT1to9 [1-9]
 DIGIT [0-9]
-DIGITS {DIGIT}+
-INT {DIGIT}|{DIGIT1to9}{DIGITS}|-{DIGIT}|-{DIGIT1to9}{DIGITS}
-FRAC [.]{DIGITS}
+INT [-]?{DIGIT}|[-]?{DIGIT1to9}{DIGIT}+
+FRAC [.]{DIGIT}+
 E [eE][+-]?
-EXP {E}{DIGITS}
+EXP {E}{DIGIT}+
 HEX_DIGIT [0-9a-fA-F]
-HEX_DIGITS {HEX_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 [()\[\]"'@_\-+:;/\\.,<> 	]
+SPECIAL [()\[\]"'~!@#$%^&*_\-+:;/?\\.,<> \t]
 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 {HEX_PREFIX}{HEX_DIGIT}+
+STRING {QUOTE}{CHAR}*{QUOTE}
+COMMENT [#]{CHAR}*[\n]
 
 %%
 
@@ -142,4 +141,3 @@
 void set_input_string(char* in) {
 	yy_scan_string(in);
 }
-
diff --git a/util/blobtool/blobtool.lex.c_shipped b/util/blobtool/blobtool.lex.c_shipped
index 3da69e2..eb6fc72 100644
--- a/util/blobtool/blobtool.lex.c_shipped
+++ b/util/blobtool/blobtool.lex.c_shipped
@@ -381,13 +381,13 @@
 	flex_int32_t yy_verify;
 	flex_int32_t yy_nxt;
 	};
-static yyconst flex_int16_t yy_accept[51] =
+static yyconst flex_int16_t yy_accept[50] =
     {   0,
         0,    0,   15,   14,   11,   14,   14,   13,    8,   14,
         2,    2,    9,   10,    6,    7,    4,    5,   11,    0,
         1,    0,    0,   12,    0,    2,    2,    0,    0,    0,
-        2,    0,    0,    2,    2,    0,    2,    3,    0,    0,
-        0,    0,    0,    0,    2,    0,    0,    0,    0,    0
+        2,    0,    0,    2,    0,    2,    3,    0,    0,    0,
+        0,    0,    0,    2,    0,    0,    0,    0,    0
     } ;
 
 static yyconst flex_int32_t yy_ec[256] =
@@ -395,17 +395,17 @@
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    2,    1,    4,    5,    1,    6,    1,    7,    7,
-        7,    1,    8,    9,   10,   11,    7,   12,   13,   13,
-       13,   13,   13,   13,   13,   13,   13,   14,    7,    7,
-       15,    7,    1,    7,   16,   16,   16,   16,   17,   16,
+        1,    2,    4,    5,    6,    4,    7,    4,    4,    4,
+        4,    4,    8,    9,   10,   11,    4,   12,   13,   13,
+       13,   13,   13,   13,   13,   13,   13,   14,    4,    4,
+       15,    4,    4,    4,   16,   16,   16,   16,   17,   16,
        18,   18,   18,   18,   18,   18,   18,   18,   18,   18,
        18,   18,   18,   18,   18,   18,   18,   18,   18,   18,
-       19,   20,   21,    1,    7,    1,   16,   16,   16,   16,
+       19,   20,   21,    4,    4,    1,   16,   16,   16,   16,
 
        17,   16,   18,   18,   18,   18,   18,   18,   18,   18,
        18,   18,   18,   18,   18,   18,   22,   18,   18,   23,
-       18,   18,   24,    1,   25,    1,    1,    1,    1,    1,
+       18,   18,   24,    1,   25,    4,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
@@ -424,77 +424,75 @@
 
 static yyconst flex_int32_t yy_meta[26] =
     {   0,
-        1,    2,    3,    2,    1,    1,    2,    2,    2,    2,
+        1,    2,    3,    2,    2,    2,    2,    2,    2,    2,
         2,    4,    4,    2,    1,    4,    4,    2,    2,    2,
         2,    2,    2,    1,    1
     } ;
 
-static yyconst flex_int16_t yy_base[54] =
+static yyconst flex_int16_t yy_base[53] =
     {   0,
-        0,    0,   37,  156,   24,   24,   26,  156,  156,   18,
-       22,   36,  156,  156,  156,  156,  156,  156,   32,   32,
-       34,   36,   39,  156,   40,   40,   51,   53,   59,    0,
-        0,   69,   87,    0,   62,   64,   71,    0,   96,  102,
-      112,  114,  120,   75,   79,  126,  132,   74,   77,  156,
-      148,  151,   28
+        0,    0,   63,  150,   24,   23,   26,  150,  150,   18,
+       21,   36,  150,  150,  150,  150,  150,  150,   31,   30,
+       31,   32,   36,  150,   37,   44,    0,   29,   54,    0,
+        0,   63,   81,   57,   59,   65,    0,   90,   96,  106,
+      108,  114,   69,   73,  120,  126,   40,   70,  150,  142,
+      145,   54
     } ;
 
-static yyconst flex_int16_t yy_def[54] =
+static yyconst flex_int16_t yy_def[53] =
     {   0,
-       50,    1,   50,   50,   50,   51,   52,   50,   50,   50,
-       50,   50,   50,   50,   50,   50,   50,   50,   50,   51,
-       51,   51,   52,   50,   52,   50,   12,   50,   50,   53,
-       12,   51,   52,   27,   50,   50,   50,   53,   32,   33,
-       50,   32,   33,   50,   50,   32,   33,   51,   52,    0,
-       50,   50,   50
+       49,    1,   49,   49,   49,   50,   51,   49,   49,   49,
+       49,   49,   49,   49,   49,   49,   49,   49,   49,   50,
+       50,   50,   51,   49,   51,   49,   12,   49,   49,   52,
+       12,   50,   51,   49,   49,   49,   52,   32,   33,   49,
+       32,   33,   49,   49,   32,   33,   50,   51,    0,   49,
+       49,   49
     } ;
 
-static yyconst flex_int16_t yy_nxt[182] =
+static yyconst flex_int16_t yy_nxt[176] =
     {   0,
-        4,    5,    5,    6,    7,    8,    4,    4,    9,   10,
+        4,    5,    5,    4,    6,    7,    8,    4,    9,   10,
         4,   11,   12,   13,   14,    4,    4,    4,   15,    4,
        16,    4,    4,   17,   18,   19,   19,   21,   24,   26,
-       27,   38,   28,   19,   19,   21,   50,   21,   29,   21,
-       50,   24,   24,   22,   30,   25,   28,   31,   31,   50,
-       28,   22,   29,   22,   50,   22,   29,   32,   25,   25,
-       50,   33,   34,   34,   35,   35,   36,   50,   36,   50,
-       37,   37,   21,   35,   35,   37,   37,   21,   41,   24,
-       39,   39,   37,   37,   39,   39,   45,   45,   22,   24,
-       45,   45,   50,   22,   50,   50,   25,   50,   40,   40,
+       27,   28,   19,   19,   21,   21,   21,   29,   24,   24,
+       34,   34,   22,   30,   21,   25,   28,   31,   31,   22,
+       22,   22,   29,   32,   28,   25,   25,   37,   33,   22,
+       29,   35,   49,   35,   49,   36,   36,   21,   34,   34,
+       36,   36,   24,   40,   38,   38,   36,   36,   38,   38,
+       44,   44,   22,   24,   44,   44,   49,   49,   49,   25,
+       49,   49,   39,   39,   49,   49,   39,   39,   49,   49,
 
-       50,   50,   40,   40,   50,   50,   25,   42,   42,   50,
-       50,   42,   42,   43,   43,   50,   50,   43,   43,   44,
-       50,   44,   50,   45,   45,   46,   46,   50,   50,   46,
-       46,   47,   47,   50,   50,   47,   47,   48,   48,   50,
-       50,   48,   48,   49,   49,   50,   50,   49,   49,   20,
-       50,   20,   23,   23,   23,    3,   50,   50,   50,   50,
-       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
-       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
-       50
+       25,   41,   41,   49,   49,   41,   41,   42,   42,   49,
+       49,   42,   42,   43,   49,   43,   49,   44,   44,   45,
+       45,   49,   49,   45,   45,   46,   46,   49,   49,   46,
+       46,   47,   47,   49,   49,   47,   47,   48,   48,   49,
+       49,   48,   48,   20,   49,   20,   23,   23,   23,    3,
+       49,   49,   49,   49,   49,   49,   49,   49,   49,   49,
+       49,   49,   49,   49,   49,   49,   49,   49,   49,   49,
+       49,   49,   49,   49,   49
     } ;
 
-static yyconst flex_int16_t yy_chk[182] =
+static yyconst flex_int16_t yy_chk[176] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    5,    5,    6,    7,   10,
-       10,   53,   11,   19,   19,   20,    3,   21,   11,   22,
-        0,   23,   25,    6,   11,    7,   12,   12,   12,    0,
-       26,   20,   12,   21,    0,   22,   26,   22,   23,   25,
-        0,   25,   27,   27,   28,   28,   29,    0,   29,    0,
-       29,   29,   32,   35,   35,   36,   36,   48,   35,   49,
-       32,   32,   37,   37,   32,   32,   44,   44,   32,   33,
-       45,   45,    0,   48,    0,    0,   49,    0,   33,   33,
+       10,   11,   19,   19,   20,   21,   22,   11,   23,   25,
+       28,   28,    6,   11,   47,    7,   12,   12,   12,   20,
+       21,   22,   12,   22,   26,   23,   25,   52,   25,   47,
+       26,   29,    3,   29,    0,   29,   29,   32,   34,   34,
+       35,   35,   48,   34,   32,   32,   36,   36,   32,   32,
+       43,   43,   32,   33,   44,   44,    0,    0,    0,   48,
+        0,    0,   33,   33,    0,    0,   33,   33,    0,    0,
 
-        0,    0,   33,   33,    0,    0,   33,   39,   39,    0,
-        0,   39,   39,   40,   40,    0,    0,   40,   40,   41,
-        0,   41,    0,   41,   41,   42,   42,    0,    0,   42,
-       42,   43,   43,    0,    0,   43,   43,   46,   46,    0,
-        0,   46,   46,   47,   47,    0,    0,   47,   47,   51,
-        0,   51,   52,   52,   52,   50,   50,   50,   50,   50,
-       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
-       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
-       50
+       33,   38,   38,    0,    0,   38,   38,   39,   39,    0,
+        0,   39,   39,   40,    0,   40,    0,   40,   40,   41,
+       41,    0,    0,   41,   41,   42,   42,    0,    0,   42,
+       42,   45,   45,    0,    0,   45,   45,   46,   46,    0,
+        0,   46,   46,   50,    0,   50,   51,   51,   51,   49,
+       49,   49,   49,   49,   49,   49,   49,   49,   49,   49,
+       49,   49,   49,   49,   49,   49,   49,   49,   49,   49,
+       49,   49,   49,   49,   49
     } ;
 
 static yy_state_type yy_last_accepting_state;
@@ -556,14 +554,16 @@
 {
 	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;
 }
 
 #define INITIAL 0
@@ -802,13 +802,13 @@
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 				{
 				yy_current_state = (int) yy_def[yy_current_state];
-				if ( yy_current_state >= 51 )
+				if ( yy_current_state >= 50 )
 					yy_c = yy_meta[(unsigned int) yy_c];
 				}
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
 			++yy_cp;
 			}
-		while ( yy_base[yy_current_state] != 156 );
+		while ( yy_base[yy_current_state] != 150 );
 
 yy_find_action:
 		yy_act = yy_accept[yy_current_state];
@@ -1208,7 +1208,7 @@
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 			{
 			yy_current_state = (int) yy_def[yy_current_state];
-			if ( yy_current_state >= 51 )
+			if ( yy_current_state >= 50 )
 				yy_c = yy_meta[(unsigned int) yy_c];
 			}
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1236,11 +1236,11 @@
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 		{
 		yy_current_state = (int) yy_def[yy_current_state];
-		if ( yy_current_state >= 51 )
+		if ( yy_current_state >= 50 )
 			yy_c = yy_meta[(unsigned int) yy_c];
 		}
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-	yy_is_jam = (yy_current_state == 50);
+	yy_is_jam = (yy_current_state == 49);
 
 		return yy_is_jam ? 0 : yy_current_state;
 }

-- 
To view, visit https://review.coreboot.org/19230
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I002962cfae0816ed3c7a5811dfb1b8b48fdc5729
Gerrit-PatchSet: 1
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Owner: Martin Roth <martinroth at google.com>



More information about the coreboot-gerrit mailing list