[coreboot] [commit] r5701 - trunk/util/sconfig

repository service svn at coreboot.org
Mon Aug 16 20:21:57 CEST 2010


Author: stepan
Date: Mon Aug 16 20:21:56 2010
New Revision: 5701
URL: https://tracker.coreboot.org/trac/coreboot/changeset/5701

Log:
sconfig parser:
 - print erroneous string in error message
 - print line numbers starting from 1 instead of 0
 - exit with return code 1 on errors
 - check return values of fopen operations
 - only create output file if input file was parsed without errors

Signed-off-by: Stefan Reinauer <stepan at coresystems.de>
Acked-by: Patrick Georgi <patrick.georgi at coresystems.de>

Modified:
   trunk/util/sconfig/main.c

Modified: trunk/util/sconfig/main.c
==============================================================================
--- trunk/util/sconfig/main.c	Mon Aug 16 20:04:13 2010	(r5700)
+++ trunk/util/sconfig/main.c	Mon Aug 16 20:21:56 2010	(r5701)
@@ -89,7 +89,9 @@
 
 void yyerror (char const *str)
 {
-	fprintf (stderr, "line %d: %s\n", linenum, str);
+	extern char *yytext;
+	fprintf (stderr, "line %d: %s: %s\n", linenum + 1, yytext, str);
+	exit(1);
 }
 
 void postprocess_devtree(void) {
@@ -408,12 +410,18 @@
 	sprintf(headers.next->name, "mainboard/%s", mainboard);
 
 	FILE *filec = fopen(devtree, "r");
-	yyrestart(filec);
+	if (!filec) {
+		fprintf(stderr, "Could not open file '%s' for reading: ", devtree);
+		perror(NULL);
+		exit(1);
+	}
 
-	FILE *staticc = fopen(outputc, "w");
+	yyrestart(filec);
 
 	lastdev = head = &root;
+
 	yyparse();
+
 	fclose(filec);
 
 	if ((head->type == chip) && (!head->chiph_exists)) {
@@ -422,6 +430,13 @@
 		while (head->next != tmp) head = head->next;
 	}
 
+	FILE *staticc = fopen(outputc, "w");
+	if (!staticc) {
+		fprintf(stderr, "Could not open file '%s' for writing: ", outputc);
+		perror(NULL);
+		exit(1);
+	}
+
 	fprintf(staticc, "#include <device/device.h>\n");
 	fprintf(staticc, "#include <device/pci.h>\n");
 	struct header *h = &headers;
@@ -435,5 +450,6 @@
 	walk_device_tree(staticc, &root, pass1, NULL);
 
 	fclose(staticc);
+
 	return 0;
 }




More information about the coreboot mailing list