annotate loadtools/hexdecode.c @ 769:6a0a7c273b3d

ss_em.c compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 12 Oct 2014 00:42:45 +0000
parents aa1f6fe16fef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the decode_hex_byte() function,
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * which is used by the SREC file reader and will likely be used
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * by other code as well, such as the dump-to-file function
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 * of loadtool.
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 */
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <ctype.h>
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 decode_hex_byte(s)
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 char *s;
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 {
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 register int u, l;
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 if (!isxdigit(s[0]) || !isxdigit(s[1]))
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 return(-1);
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 if (isdigit(s[0]))
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 u = s[0] - '0';
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 else if (isupper(s[0]))
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 u = s[0] - 'A' + 10;
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 else
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 u = s[0] - 'a' + 10;
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 if (isdigit(s[1]))
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 l = s[1] - '0';
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 else if (isupper(s[1]))
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 l = s[1] - 'A' + 10;
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 else
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 l = s[1] - 'a' + 10;
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 return((u << 4) | l);
aa1f6fe16fef loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 }