conclude escalation handlers
author"Darron Broad" <darron@kewl.org>
Thu, 20 Jun 2019 07:48:46 +0100
changeset 1098 f6e8a76176f7
parent 1097 360de600eba2
child 1099 964cd52eb914
conclude escalation handlers
src/inhx32.c
--- a/src/inhx32.c	Wed Jun 19 19:00:12 2019 +0100
+++ b/src/inhx32.c	Thu Jun 20 07:48:46 2019 +0100
@@ -157,18 +157,23 @@
 	return -8; /* Invalid record type for this architecture */
 }
 
+/*
+ * Display input line warning or error message
+ *
+ * Return true if escalated to an error
+ */
 static int
 inhx32_error(int err, int val)
 {
 	static char warning[] = "warning", error[] = "error";
 	char *msg;
-	int rc = 0;		/* No error */
+	int rc = 0;
 
 	if (err >= 0)
 		return rc;
 	
 	if (p.error & BADINPUT) {
-		rc = -1;	/* Error */
+		rc = 1;		/* Error escalation */
 		msg = error;
 	} else {
 		msg = warning;
@@ -198,7 +203,7 @@
 /*
  * Get data
  *  
- *  Returns number of bytes, 0 = EOF and < 0 is error
+ *  Returns number of bytes or 0 for EOF or -1 for error escalation
  */
 int
 inhx32_get(FILE *fp, pic_data **data)
@@ -214,7 +219,7 @@
 		rc = inhx32_fgets(line, fp, &bb, &aaaa, &tt, &extended_addr);
 		if (rc == 0 || tt == TT_EOF)
 			return 0;	/* EOF */
-		if (inhx32_error(rc, tt) < 0)
+		if (inhx32_error(rc, tt))
 			return -1;	/* Error */
 	}
 	while (tt != TT_DATA);		/* Skip non data records */
@@ -415,7 +420,7 @@
 		io_exit(EX_OSERR); /* Panic */
 	}
 
-	/* While not EOF or error, process data */
+	/* While not EOF or error process data */
 	while ((rc = inhx32_get(fp, &data)) > 0) {
 		(*pdata)[index++] = data;
 	}
@@ -489,7 +494,7 @@
 		io_exit(EX_OSERR); /* Panic */
 	}
 
-	/* While not EOF, process data */
+	/* While not EOF or error process data */
 	while ((rc = inhx32_get(fp, &data)) > 0) {
 		for (i = 0; i < data->nbytes; ++i)
 			(*pmem)[index++] = data->bytes[i];
@@ -561,7 +566,8 @@
 	uint32_t nbytes = 0;
 	void *entry;
 	pic_data *data;
-	
+	int rc;
+
 	*count = 0;
 
 	/* Open file or stdin */
@@ -571,8 +577,8 @@
 		return 0; /* Empty */
 	}
 
-	/* While not EOF, process data */
-	while ((data = inhx32_get(fp)) != NULL) {
+	/* While not EOF or error process data */
+	while ((rc = inhx32_get(fp, &data)) > 0) {
 		/* Detect duplicate data in tree */
 		entry = tfind((void *)data, root, inhx32_tree_compare);
 		if (entry != NULL) {
@@ -597,6 +603,10 @@
 	if (strcmp(filename, "-"))
 		fclose(fp);
 
+	/* Exit on error condition */
+	if (rc < 0)
+		io_exit(BADINPUT);
+
 	/* Information */
 	if (nbytes == 0)
 		printf("%s: information: no valid input data\n", __func__);