diff mbox

[U-Boot] Added support for comments in input to mkenvimage.

Message ID A7EA75EC00413B4EB750D04B08CE1BBC4E7668C7@FRAVM350400.darmstadt.bkvibro.de
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Dominik Muth Aug. 28, 2014, 11:17 a.m. UTC
From 4877c78a6b11ebf90fe25376f1362b12d233797a Mon Sep 17 00:00:00 2001
From: Dominik Muth <dominik.muth@bkvibro.com>
Date: Thu, 28 Aug 2014 12:25:27 +0200
Subject: [PATCH] Added support for comments in input to mkenvimage.

This patch adds support for comments in the input to mkenvimage, i.e. in
the environment source: All lines starting with a # in the firs column
will be ignored.

Additionally empty lines will also be ignored.

Signed-off-by: Dominik Muth <dominik.muth@bkvibro.com>
---
 tools/mkenvimage.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

--
1.7.9.5

Comments

Tom Rini Nov. 10, 2014, 9:28 p.m. UTC | #1
On Thu, Aug 28, 2014 at 11:17:17AM +0000, Dominik Muth wrote:

> >From 4877c78a6b11ebf90fe25376f1362b12d233797a Mon Sep 17 00:00:00 2001
> From: Dominik Muth <dominik.muth@bkvibro.com>
> Date: Thu, 28 Aug 2014 12:25:27 +0200
> Subject: [PATCH] Added support for comments in input to mkenvimage.
> 
> This patch adds support for comments in the input to mkenvimage, i.e. in
> the environment source: All lines starting with a # in the firs column
> will be ignored.
> 
> Additionally empty lines will also be ignored.
> 
> Signed-off-by: Dominik Muth <dominik.muth@bkvibro.com>

Applied to u-boot/master (after re-working whitespace and git diff
-b'ing), thanks!
diff mbox

Patch

diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c
index bbd3041..4f75338 100644
--- a/tools/mkenvimage.c
+++ b/tools/mkenvimage.c
@@ -37,6 +37,8 @@  static void usage(const char *exec_name)
               "\t\tkey1=value1\n"
               "\t\tkey2=value2\n"
               "\t\t...\n"
+              "\tEmpty lines are skipped, and lines with a # in the first\n"
+              "\tcolumn are treated as comments (also skipped).\n"
               "\t-r : the environment has multiple copies in flash\n"
               "\t-b : the target is big endian (default is little endian)\n"
               "\t-p <byte> : fill the image with <byte> bytes instead of 0xff bytes\n"
@@ -221,10 +223,9 @@  int main(int argc, char **argv)
        /* Replace newlines separating variables with \0 */
        for (fp = 0, ep = 0 ; fp < filesize ; fp++) {
                if (filebuf[fp] == '\n') {
-                       if (ep == 0) {
+                       if (fp == 0 || filebuf[fp-1] == '\n') {
                                /*
-                                * Newlines at the beginning of the file ?
-                                * Ignore them.
+                                * Skip empty lines.
                                 */
                                continue;
                        } else if (filebuf[fp-1] == '\\') {
@@ -240,6 +241,10 @@  int main(int argc, char **argv)
                                /* End of a variable */
                                envptr[ep++] = '\0';
                        }
+               } else if ((fp == 0 || filebuf[fp-1] == '\n') && filebuf[fp] == '#') {
+                       /* Comment, skip the line. */
+                       while (++fp < filesize && filebuf[fp] != '\n')
+                               continue;
                } else {
                        envptr[ep++] = filebuf[fp];
                }