ignore more stuff
[fw/altos] / ccdbg-hex.c
index d9d27cdf00a1b2fc42a3128f64c2f2b929cdacf1..86478da07b8c5f262c6adfb675cccf6aa11f2528 100644 (file)
@@ -119,6 +119,8 @@ ccdbg_hex_read_record(struct hex_input *input)
                        ccdbg_hex_error(input, "Unexpected EOF");
                        goto bail;
                }
+               if (c == ' ')
+                       continue;
                if (c == '\n')
                        input->line++;
                switch (state) {
@@ -228,7 +230,7 @@ ccdbg_hex_file_free(struct hex_file *hex)
                return;
        for (i = 0; i < hex->nrecord; i++)
                ccdbg_hex_free(hex->records[i]);
-       free (hex);
+       free(hex);
 }
 
 static int
@@ -249,7 +251,7 @@ ccdbg_hex_file_read(FILE *file, char *name)
        int srecord = 1;
        int done = 0;
 
-       hex = calloc (1, sizeof (struct hex_file) + sizeof (struct hex_record *));
+       hex = calloc(sizeof (struct hex_file) + sizeof (struct hex_record *), 1);
        input.name = name;
        input.line = 1;
        input.file = file;
@@ -282,3 +284,47 @@ bail:
        return NULL;
 }
 
+struct hex_image *
+ccdbg_hex_image_create(struct hex_file *hex)
+{
+       struct hex_image *image;
+       struct hex_record *first, *last, *record;
+       int i;
+       uint32_t base, bound;
+       uint32_t offset;
+       int length;
+
+       first = hex->records[0];
+       last = hex->records[hex->nrecord - 2];  /* skip EOF */
+       base = (uint32_t) first->address;
+       bound = (uint32_t) last->address + (uint32_t) last->length;
+       length = bound - base;
+       image = calloc(sizeof(struct hex_image) + length, 1);
+       if (!image)
+               return NULL;
+       image->address = base;
+       image->length = length;
+       memset(image->data, 0xff, length);
+       for (i = 0; i < hex->nrecord - 1; i++) {
+               record = hex->records[i];
+               offset = record->address - base;
+               memcpy(image->data + offset, record->data, record->length);
+       }
+       return image;
+}
+
+void
+ccdbg_hex_image_free(struct hex_image *image)
+{
+       free(image);
+}
+
+int
+ccdbg_hex_image_equal(struct hex_image *a, struct hex_image *b)
+{
+       if (a->length != b->length)
+               return 0;
+       if (memcmp(a->data, b->data, a->length) != 0)
+               return 0;
+       return 1;
+}