annotate frbl/test/hexdecode.c @ 352:bc5ddad215f2

fluid-mnf/Makefile: install added
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Mar 2020 19:22:48 +0000
parents cefa700d1b8f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
323
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains the decode_hex_byte() function,
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * which is used by the SREC file reader and will likely be used
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * by other code as well, such as the dump-to-file function
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * of loadtool.
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <ctype.h>
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 decode_hex_byte(s)
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 char *s;
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 register int u, l;
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 if (!isxdigit(s[0]) || !isxdigit(s[1]))
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 return(-1);
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 if (isdigit(s[0]))
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 u = s[0] - '0';
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 else if (isupper(s[0]))
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u = s[0] - 'A' + 10;
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 else
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 u = s[0] - 'a' + 10;
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (isdigit(s[1]))
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 l = s[1] - '0';
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 else if (isupper(s[1]))
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 l = s[1] - 'A' + 10;
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 else
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 l = s[1] - 'a' + 10;
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return((u << 4) | l);
cefa700d1b8f frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }