projects
/
fw
/
sdcc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Martins commands patch
[fw/sdcc]
/
packihx
/
packihx.c
diff --git
a/packihx/packihx.c
b/packihx/packihx.c
index 8675f19038ca5a529bc4a762732cc6fcc7d58cd6..a9cf4e7a48785ed808036485f68faf3dc81f66a2 100644
(file)
--- a/
packihx/packihx.c
+++ b/
packihx/packihx.c
@@
-1,7
+1,7
@@
/*-----------------------------------------------------------------------
* packihx.c:
*
/*-----------------------------------------------------------------------
* packihx.c:
*
- * utility to pack an Inte
r
HEX format file by removing redundant
+ * utility to pack an Inte
l
HEX format file by removing redundant
* extended offset records and accumulating data records up to
* OUTPUT_CHUNK (currently 16) bytes.
*
* extended offset records and accumulating data records up to
* OUTPUT_CHUNK (currently 16) bytes.
*
@@
-14,13
+14,21
@@
#include <ctype.h>
#include <assert.h>
#include <ctype.h>
#include <assert.h>
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+
+typedef unsigned char Uint8 ;
+typedef unsigned Uint16 ;
+
+#else
+
#include "config.h"
#include "config.h"
+#endif
/* A cooked line of input. */
typedef struct _Line
{
Uint8 len; /* length of data portion of record. */
/* A cooked line of input. */
typedef struct _Line
{
Uint8 len; /* length of data portion of record. */
- Uint16
offset;
+ Uint16 offset;
Uint8 type;
Uint8 *data;
Uint8 checksum;
Uint8 type;
Uint8 *data;
Uint8 checksum;
@@
-98,7
+106,7
@@
Line *readLine(FILE *inFile)
{
return NULL;
}
{
return NULL;
}
- ++lineno;
+
++lineno;
if (!buffer[0] || buffer[0] == '\r' || buffer[0] == '\n')
{
if (!buffer[0] || buffer[0] == '\r' || buffer[0] == '\n')
{
@@
-144,8
+152,10
@@
Line *readLine(FILE *inFile)
return NULL;
}
bp += 2; /* Two digits consumed. */
return NULL;
}
bp += 2; /* Two digits consumed. */
-
- line->data = (Uint8 *)malloc(line->len);
+
+ /* Hack - always allocate something, even if len is zero.
+ * Avoids special case for len == 0. */
+ line->data = (Uint8 *)malloc(line->len ? line->len : 1);
if (!line->data)
{
free(line);
if (!line->data)
{
free(line);
@@
-153,7
+163,7
@@
Line *readLine(FILE *inFile)
return NULL;
}
return NULL;
}
- for (i = 0; i < line->len; i++)
+ for (i = 0; i <
(unsigned)
line->len; i++)
{
if (getHexByte(bp, &(line->data[i])))
{
{
if (getHexByte(bp, &(line->data[i])))
{
@@
-175,7
+185,7
@@
Line *readLine(FILE *inFile)
free(line);
return NULL;
}
free(line);
return NULL;
}
- bp += 2; /* Two digits consumed. */
+ /* bp += 2; */ /* Two digits consumed. */
return line;
}
return line;
}
@@
-184,7
+194,7
@@
Line *readLine(FILE *inFile)
Uint16 lineChecksum(unsigned len, unsigned offset, unsigned type,
const Uint8 *data)
{
Uint16 lineChecksum(unsigned len, unsigned offset, unsigned type,
const Uint8 *data)
{
- Uint16
checksum = 0
;
+ Uint16
checksum
;
unsigned i;
checksum = len + type + (offset >> 8) +
unsigned i;
checksum = len + type + (offset >> 8) +
@@
-213,7
+223,7
@@
int validateChecksum(Line *line)
if (checksum != line->checksum)
{
fprintf(stderr, "packihx: invalid checksum %X (want %X) @ line %d\n",
if (checksum != line->checksum)
{
fprintf(stderr, "packihx: invalid checksum %X (want %X) @ line %d\n",
- (unsigned)
checksum, (unsigned)(line->checksum),
+ (unsigned)
(line->checksum), (unsigned)checksum,
lineno);
return -1;
}
lineno);
return -1;
}
@@
-300,7
+310,7
@@
int flushPendingData(void)
int writeLine(Line *line)
{
static Uint16 lastExtendedOffset = 0;
int writeLine(Line *line)
{
static Uint16 lastExtendedOffset = 0;
- int
rc = 0
;
+ int
rc
;
if (line->type)
{
if (line->type)
{
@@
-341,7
+351,7
@@
int writeLine(Line *line)
}
else
{
}
else
{
- if (pendingOffset + pendingLen != line->offset)
+ if (pendingOffset + pendingLen !=
(unsigned)
line->offset)
{
/* This line is not contigous with the last one. Dump pending. */
if (flushPendingData())
{
/* This line is not contigous with the last one. Dump pending. */
if (flushPendingData())