Some intel hex file parsing fixes
authorJelmer Vernooij <jelmer@vernstok.nl>
Wed, 6 Oct 2004 08:36:49 +0000 (09:36 +0100)
committerJelmer Vernooij <jelmer@vernstok.nl>
Wed, 6 Oct 2004 08:36:49 +0000 (09:36 +0100)
at89prog.c
hexfile.c
hexfile.h

index 2a921c709bab3024278dd0bad08c5567251aabbf..2006b260537edb9b1d0b10fdfd7b45ff7f1cd514 100644 (file)
@@ -109,6 +109,10 @@ int writehex(FILE *fd, char do_verify, char datamem)
                        fprintf(stderr, "Corrupt line %d in intel hex file\n", i);
                        errors++;
                        return errors;
+               case HEX_FILE_UNKNOWN_TYPE:
+                       fprintf(stderr, "Unknown file type at line %d in intel hex file\n", i);
+                       errors++;
+                       break;
                case HEX_FILE_END_OF_FILE:
                        if(progress)fputc('\n', stderr);
                        return errors;
index 23aae66c37dbb96010d457490ce7335350d3428a..5843e3c5a7a4d015903c70377679239046f04088 100644 (file)
--- a/hexfile.c
+++ b/hexfile.c
@@ -36,14 +36,17 @@ int readhexline(FILE *fd, void **data, size_t *len, long *address)
 
        do { 
                checksum1 = 0;
-               if(feof(fd)) {
-                       return HEX_FILE_END_OF_FILE;
-               }
 
                if(fscanf(fd, ":%2x%2x%2x%2x", &length, &addr1, &addr2, &type) < 3) {
                        return HEX_FILE_CORRUPT_LINE;
                }
-       } while(type == 1 || type == 2);
+       } while(type == 2);
+
+       if(type == 0x01) return HEX_FILE_END_OF_FILE;
+
+       if(type != 0x00) {
+               return HEX_FILE_UNKNOWN_TYPE;
+       }
 
        checksum1+=length;
        checksum1+=type;
index d8f1b6a3b3dc8f9cdc8d304f5f8ce85a3f20b80e..3fc490fcea7a982e27563f96c8c13c707cab03c6 100644 (file)
--- a/hexfile.h
+++ b/hexfile.h
@@ -5,5 +5,6 @@ int readhexline(FILE *fd, void **data, size_t *len, long *address);
 #define HEX_FILE_ERR_CHECKSUM -1                       /* Invalid checksum */
 #define HEX_FILE_CORRUPT_LINE -2                       /* Corrupt line, no data read */
 #define HEX_FILE_END_OF_FILE  -3                       /* End of line */
+#define HEX_FILE_UNKNOWN_TYPE -4                       /* Unknown type */
 
 #endif /* __HEXFILE_H__ */