[PATCH 1/6] scripts: imx-image: allow semicolon as command delimiter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When we want to pass the imxcfg files through cpp we also want to
allow defines which define multiple commands. For this to work we
have to use an additional command delimiter as we can't pass '\n'
though cpp. Use ';' for this.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 scripts/imx/imx-image.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 2f52015..09fdc5f 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -492,12 +492,40 @@ struct command cmds[] = {
 	},
 };
 
+static char *readcmd(FILE *f)
+{
+	static char *buf;
+	char *str;
+	ssize_t ret;
+
+	if (!buf) {
+		buf = malloc(4096);
+		if (!buf)
+			return NULL;
+	}
+
+	str = buf;
+	*str = 0;
+
+	while (1) {
+		ret = fread(str, 1, 1, f);
+		if (!ret)
+			return strlen(buf) ? buf : NULL;
+
+		if (*str == '\n' || *str == ';') {
+			*str = 0;
+			return buf;
+		}
+
+		str++;
+	}
+}
+
 static int parse_config(const char *filename)
 {
 	FILE *f;
 	int lineno = 0;
 	char *line = NULL, *tmp;
-	size_t len;
 	char *argv[MAXARGS];
 	int nargs, i, ret;
 
@@ -507,15 +535,16 @@ static int parse_config(const char *filename)
 		exit(1);
 	}
 
-	while ((getline(&line, &len, f)) > 0) {
+	while (1) {
+		line = readcmd(f);
+		if (!line)
+			break;
+
 		lineno++;
 
 		tmp = strchr(line, '#');
 		if (tmp)
 			*tmp = 0;
-		tmp = strrchr(line, '\n');
-		if (tmp)
-			*tmp = 0;
 
 		nargs = parse_line(line, argv);
 		if (!nargs)
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux