changeset 201:fc1635333d81

allow comments in hex data files
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 03:58:49 +0000
parents bca0f86d9efe
children 3f6f50103dd3
files libutil/hexread.c
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libutil/hexread.c	Sun Mar 07 03:41:06 2021 +0000
+++ b/libutil/hexread.c	Sun Mar 07 03:58:49 2021 +0000
@@ -24,12 +24,18 @@
 		perror(filename);
 		return(-1);
 	}
-	for (count = 0; ; count++) {
+	for (count = 0; ; ) {
 		do
 			c = getc(inf);
 		while (isspace(c));
 		if (c < 0)
 			break;
+		if (c == '#') {
+			do
+				c = getc(inf);
+			while (c >= 0 && c != '\n');
+			continue;
+		}
 		if (!isxdigit(c)) {
 inv_input:		fprintf(stderr, "%s: invalid hex file input\n",
 				filename);
@@ -45,8 +51,8 @@
 			fclose(inf);
 			return(-1);
 		}
-		databuf[count] = (decode_hex_digit(c) << 4) |
-				 decode_hex_digit(c2);
+		databuf[count++] = (decode_hex_digit(c) << 4) |
+				   decode_hex_digit(c2);
 	}
 	fclose(inf);
 	if (!count) {