Exemplo n.º 1
0
int
parse_ihex(FILE *file, uint8_t *buffer, unsigned int size,
	   unsigned int *min, unsigned int *max)
{
  int ch;
  *max = 0;
  *min = (unsigned int)-1;

  while(1) {
    unsigned int check;
    unsigned int b;
    int length;
    int addr;
    int type;
    skip_white(file);
    if (feof(file)) break;
    ch = getc(file);
    if (ch != ':') return -1;
    check = 0;
    length = get_hex2(file, &check);
    if (length < 0) return length;
    addr = get_hex4(file, &check);
    if (addr < 0) return addr;
    type = get_hex2(file, &check);
    if (type < 0) return type;
    if (type == 0) {
      if (addr >= size) return -2;
      for (b = 0; b < length; b++) {
	int v = get_hex2(file, &check);
	if (v < 0) return v;
	buffer[addr] = v;
	if (addr > *max) *max = addr;
	if (addr < *min) *min = addr;
	addr++;
      }
      
    } else if (type == 1) {
      return 0;
    }
    ch = get_hex2(file, &check);
    if (ch < 0) return ch;
    if ((check & 0xff) != 0) return -3;
  }
  return 0;
}
Exemplo n.º 2
0
unsigned int get_hex8(unsigned char *p)
{
    return (get_hex4(p) << 4) + get_hex4(p+1);
}
uchar get_hex8(
    uchar	*p)		// convert this hex string to unsigned integer
{
    return (get_hex4(p) << 4) + get_hex4(p+1);
}