Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
hexnum.c
Go to the documentation of this file.
1/*
2 * Hexadecimal number parser.
3 *
4 * Retail object 0x452930-0x4529FF (link order; see docs/ORDER.md).
5 */
6#include "game.h"
7
8/* Digit values by position; a space reads as 0. */
9static char g_szHexDigits[] = "0123456789ABCDEF "; /* 0x0049be70 */
10
11/* Function start: 0x452930 */
12/* Converts up to four hexadecimal digits; anything else gives 0. A space
13 * counts as 0. */
14short ParseHexNumber(char *text)
15{
16 short length;
17 short value;
18 short position;
19 char *match;
20
21 length = DosStrlen(text);
22 value = 0;
23 if (length > 4)
24 return 0;
25 for (position = length - 1; position > -1; position--) {
26 value <<= 4;
27 match = DosStrchr(g_szHexDigits, toupper(text[position]));
28 if (match == 0)
29 return 0;
30 if (*match == ' ')
31 match = g_szHexDigits;
32 value += match - g_szHexDigits;
33 }
34 return value;
35}
short DosStrlen(const char *s)
Definition eventmgr.c:479
char * DosStrchr(const char *s, short c)
Definition eventmgr.c:459
short ParseHexNumber(char *text)
Definition hexnum.c:14
Shared Win32 declarations, types and library interfaces.
static char g_szHexDigits[]
Definition hexnum.c:9