Skip to contentSkip to conversation

mkenvimage: Fix some typos

PATCH New Horst Kronstorfer 2 participants 13 messages Dec 5, 2011 – Dec 22, 2011 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 mkenvimage: Fix some typos

---
 tools/mkenvimage.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
tools/mkenvimage.c +4 -4
index 9c32f4a..b7b0e0f 100644
@@ -116,7 +116,7 @@ int main(int argc, char **argv)
 	/* Check datasize and allocate the data */
 	if (datasize == 0) {
 		fprintf(stderr,
-			"Please specify the size of the envrionnment "
+			"Please specify the size of the environment "
 			"partition.\n");
 		usage(argv[0]);
 		return EXIT_FAILURE;
@@ -182,12 +182,12 @@ int main(int argc, char **argv)
 		ret = close(txt_fd);
 	}
 	/*
-	 * The right test to do is "=>" (not ">") because of the additionnal
+	 * The right test to do is "=>" (not ">") because of the additional
 	 * ending \0. See below.
 	 */
 	if (filesize >= envsize) {
 		fprintf(stderr, "The input file is larger than the "
-				"envrionnment partition size\n");
+				"environment partition size\n");
 		return EXIT_FAILURE;
 	}
 
@@ -196,7 +196,7 @@ int main(int argc, char **argv)
 		if (filebuf[fp] == '\n') {
 			if (fp == 0) {
 				/*
-				 * Newline at the beggining of the file ?
+				 * Newline at the beginning of the file ?
 				 * Ignore it.
 				 */
 				continue;
Signature · 1 line
1.7.7.3
#1 lore raw

PATCH 2/4 mkenvimage: Fix getopt() error handling

Since the original implementation indicates explicit error handling we turn off getopt()'s internal error messaging to avoid duplicate error messages. Additionally we add ':' (missing option argument) error handling.

---
 tools/mkenvimage.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
tools/mkenvimage.c +10 -2
index b7b0e0f..22d1b88 100644
@@ -80,8 +80,11 @@ int main(int argc, char **argv)
 
 	int fp, ep;
 
+	/* Turn off getopt()'s internal error message */
+	opterr = 0;
+
 	/* Parse the cmdline */
-	while ((option = getopt(argc, argv, "s:o:rbp:h")) != -1) {
+	while ((option = getopt(argc, argv, ":s:o:rbp:h")) != -1) {
 		switch (option) {
 		case 's':
 			datasize = strtol(optarg, NULL, 0);
@@ -106,8 +109,13 @@ int main(int argc, char **argv)
 		case 'h':
 			usage(argv[0]);
 			return EXIT_SUCCESS;
+		case ':':
+			fprintf(stderr, "Missing argument for option -%c\n",
+				optopt);
+			usage(argv[0]);
+			return EXIT_FAILURE;
 		default:
-			fprintf(stderr, "Wrong option -%c\n", option);
+			fprintf(stderr, "Wrong option -%c\n", optopt);
 			usage(argv[0]);
 			return EXIT_FAILURE;
 		}
Signature · 1 line
1.7.7.3
#2 lore raw

PATCH 2/4 mkenvimage: Fix getopt() error handling

Dear Horst Kronstorfer,

Quoted 9 lines · In message <[email protected]> you wrote:

Since the original implementation indicates explicit error handling we turn off getopt()'s internal error messaging to avoid duplicate error messages. Additionally we add ':' (missing option argument) error handling.

---
 tools/mkenvimage.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

Applied to "next" branch, thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Whom the gods would destroy, they first teach BASIC.
#3 lore raw

PATCH 3/4 mkenvimage: Print program basename instead of whole path in usage()

In reply to Horst Kronstorfer
---
 tools/mkenvimage.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
tools/mkenvimage.c +9 -4
index 22d1b88..3e7f967 100644
@@ -79,6 +79,11 @@ int main(int argc, char **argv)
 	struct stat txt_file_stat;
 
 	int fp, ep;
+	const char *prg;
+
+	/* Parse program basename */
+	prg = strrchr(argv[0], '/');
+	prg = (prg) ? prg + 1 : argv[0];
 
 	/* Turn off getopt()'s internal error message */
 	opterr = 0;
@@ -107,16 +112,16 @@ int main(int argc, char **argv)
 			padbyte = strtol(optarg, NULL, 0);
 			break;
 		case 'h':
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_SUCCESS;
 		case ':':
 			fprintf(stderr, "Missing argument for option -%c\n",
 				optopt);
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_FAILURE;
 		default:
 			fprintf(stderr, "Wrong option -%c\n", optopt);
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_FAILURE;
 		}
 	}
@@ -126,7 +131,7 @@ int main(int argc, char **argv)
 		fprintf(stderr,
 			"Please specify the size of the environment "
 			"partition.\n");
-		usage(argv[0]);
+		usage(prg);
 		return EXIT_FAILURE;
 	}
 
Signature · 1 line
1.7.7.3
#4 lore raw

PATCH 3/4 mkenvimage: Print program basename instead of whole path in usage()

Dear Horst Kronstorfer,

Quoted 10 lines · In message <[email protected]> you wrote:
---
 tools/mkenvimage.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
tools/mkenvimage.c +0 -0
index 22d1b88..3e7f967 100644

tools/mkenvimage.c int main(int argc, char **argv) · line 86

Quoted 8 lines
tools/mkenvimage.c +5 -0
@@ -79,6 +79,11 @@ int main(int argc, char **argv)
 	struct stat txt_file_stat;
 
 	int fp, ep;
+	const char *prg;
+
+	/* Parse program basename */
+	prg = strrchr(argv[0], '/');
+	prg = (prg) ? prg + 1 : argv[0];

Any reason for not using basename() here?

Best regards,

Wolfgang Denk

Signature · 8 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The manager will be continually amazed that policies he took for com-
mon knowledge are totally unknown by some member of his  team.  Since
his fundamental job is to keep everybody going in the same direction,
his chief daily task will be communication, not decision-making.
                              - Fred Brooks, "The Mythical Man Month"

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

PATCH 3/4 mkenvimage: Print program basename instead of whole path in usage()

Dear KRONSTORFER Horst,

Quoted 8 lines · In message <[email protected]>…
Quoted 6 lines

tools/mkenvimage.c int main(int argc, char **argv) · line 86

Quoted 4 lines
tools/mkenvimage.c +3 -0
+	/* Parse program basename */
+	prg = strrchr(argv[0], '/');
+	prg = (prg) ? prg + 1 : argv[0];

Any reason for not using basename() here?

i'm just used to not using basename() ... do you want an updated patch?

Yes, please. Using available standard functions is always better than reinventing the wheel.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Unix is supported by IBM, like a hanging man is supported by rope.
		        - Don Libes & Sandy Ressler: _Life With Unix_
#7 lore raw

PATCH v2 1/1 Print program basename instead of whole path in usage()

In reply to Horst Kronstorfer

---
Changes for v2:
- Use the GNU version of basename().
- Rebased against branch 'next.'

 tools/mkenvimage.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
tools/mkenvimage.c +10 -4
index 753d9e6..6a6a392 100644
@@ -25,6 +25,9 @@
  * MA 02111-1307 USA
  */
 
+/* We want the GNU version of basename() */
+#define _GNU_SOURCE
+
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -81,6 +84,9 @@ int main(int argc, char **argv)
 	struct stat txt_file_stat;
 
 	int fp, ep;
+	const char *prg;
+
+	prg = basename(argv[0]);
 
 	/* Turn off getopt()'s internal error message */
 	opterr = 0;
@@ -109,7 +115,7 @@ int main(int argc, char **argv)
 			padbyte = strtol(optarg, NULL, 0);
 			break;
 		case 'h':
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_SUCCESS;
 		case 'V':
 			printf("%s version %s\n", prg, PLAIN_VERSION);
@@ -117,11 +123,11 @@ int main(int argc, char **argv)
 		case ':':
 			fprintf(stderr, "Missing argument for option -%c\n",
 				optopt);
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_FAILURE;
 		default:
 			fprintf(stderr, "Wrong option -%c\n", optopt);
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_FAILURE;
 		}
 	}
@@ -131,7 +137,7 @@ int main(int argc, char **argv)
 		fprintf(stderr,
 			"Please specify the size of the environment "
 			"partition.\n");
-		usage(argv[0]);
+		usage(prg);
 		return EXIT_FAILURE;
 	}
 
Signature · 1 line
1.7.7.4
#8 lore raw

PATCH v2 1/1 Print program basename instead of whole path in usage()

Dear Horst Kronstorfer,

Quoted 8 lines · In message <[email protected]> you…

---
Changes for v2:
- Use the GNU version of basename().
- Rebased against branch 'next.'

 tools/mkenvimage.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

This does not apply cleanly against current master:

Applying: Print program basename instead of whole path in usage() Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge... Auto-merging tools/mkenvimage.c
CONFLICT (content): Merge conflict in tools/mkenvimage.c Failed to merge in the changes.
Patch failed at 0001 Print program basename instead of whole path in usage()

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If all you have is a hammer, everything looks like a nail.
#9 lore raw

PATCH v3 1/1 Print program basename instead of whole path in usage()

In reply to Horst Kronstorfer

---
Changes for v2:
- Use the GNU version of basename().
- Rebase against branch 'next.'
Changes for v3:
- Rebase against branch 'master.'

 tools/mkenvimage.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
tools/mkenvimage.c +9 -3
index 9c32f4a..3bb471d 100644
@@ -25,6 +25,9 @@
  * MA 02111-1307 USA
  */
 
+/* We want the GNU version of basename() */
+#define _GNU_SOURCE
+
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -79,6 +82,9 @@ int main(int argc, char **argv)
 	struct stat txt_file_stat;
 
 	int fp, ep;
+	const char *prg;
+
+	prg = basename(argv[0]);
 
 	/* Parse the cmdline */
 	while ((option = getopt(argc, argv, "s:o:rbp:h")) != -1) {
@@ -104,11 +110,11 @@ int main(int argc, char **argv)
 			padbyte = strtol(optarg, NULL, 0);
 			break;
 		case 'h':
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_SUCCESS;
 		default:
 			fprintf(stderr, "Wrong option -%c\n", option);
-			usage(argv[0]);
+			usage(prg);
 			return EXIT_FAILURE;
 		}
 	}
@@ -118,7 +124,7 @@ int main(int argc, char **argv)
 		fprintf(stderr,
 			"Please specify the size of the envrionnment "
 			"partition.\n");
-		usage(argv[0]);
+		usage(prg);
 		return EXIT_FAILURE;
 	}
 
Signature · 1 line
1.7.7.4
#10 lore raw

PATCH v3 1/1 Print program basename instead of whole path in usage()

Dear Horst Kronstorfer,

Quoted 10 lines · In message <[email protected]> you wrote:

---
Changes for v2:
- Use the GNU version of basename().
- Rebase against branch 'next.'
Changes for v3:
- Rebase against branch 'master.'

 tools/mkenvimage.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It all seemed, he thought, to be rather a lot of  trouble  to  go  to
just sharpen a razor blade.  - Terry Pratchett, _The Light Fantastic_
#11 lore raw

PATCH 4/4 mkenvimage: Add version info switch (-V)

In reply to Horst Kronstorfer
---
 tools/mkenvimage.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
tools/mkenvimage.c +6 -1
index 3e7f967..046661d 100644
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 
 #include <u-boot/crc.h>
+#include <version.h>
 
 #define CRC_SIZE sizeof(uint32_t)
 
@@ -56,6 +57,7 @@ static void usage(const char *exec_name)
 	       "\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"
+	       "\t-V : print version information and exit\n"
 	       "\n"
 	       "If the input file is \"-\", data is read from standard input\n",
 	       exec_name);
@@ -89,7 +91,7 @@ int main(int argc, char **argv)
 	opterr = 0;
 
 	/* Parse the cmdline */
-	while ((option = getopt(argc, argv, ":s:o:rbp:h")) != -1) {
+	while ((option = getopt(argc, argv, ":s:o:rbp:hV")) != -1) {
 		switch (option) {
 		case 's':
 			datasize = strtol(optarg, NULL, 0);
@@ -114,6 +116,9 @@ int main(int argc, char **argv)
 		case 'h':
 			usage(prg);
 			return EXIT_SUCCESS;
+		case 'V':
+			printf("%s version %s\n", prg, PLAIN_VERSION);
+			return EXIT_SUCCESS;
 		case ':':
 			fprintf(stderr, "Missing argument for option -%c\n",
 				optopt);
Signature · 1 line
1.7.7.3
#12 lore raw

PATCH 4/4 mkenvimage: Add version info switch (-V)

Dear Horst Kronstorfer,

Quoted 4 lines · In message <[email protected]> you wrote:
---
 tools/mkenvimage.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

Applied to "next" branch, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Q:  Why do mountain climbers rope themselves together?
A:  To prevent the sensible ones from going home.
#13 lore raw

PATCH 1/4 mkenvimage: Fix some typos

In reply to Horst Kronstorfer

Dear Horst Kronstorfer,

Quoted 4 lines · In message <[email protected]> you wrote:
---
 tools/mkenvimage.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Applied to "next" branch, thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Genius doesn't work on an assembly line basis.  You can't simply say,
"Today I will be brilliant."
	-- Kirk, "The Ultimate Computer", stardate 4731.3