FireBirdLib - Topfield TMS PVR TAP Programming Library
INIGetHexWord.c
Go to the documentation of this file.
1#include <string.h>
2#include <stdlib.h>
3#include <ctype.h>
4#include "FBLib_ini.h"
5#include "libFireBird.h"
6
7word INIGetHexWord(char *Key, word DefaultValue, word MinValue, word MaxValue)
8{
10
11 char *i = NULL, *j = NULL, *k;
12 char TempKey[80];
13 dword l, x;
14
15 if(!Key)
16 {
17 TRACEEXIT();
18 return 0;
19 }
20
21 strncpy(TempKey, Key, sizeof(TempKey) - 2);
22 TempKey[sizeof(TempKey) - 2] = '\0';
23 strcat(TempKey, "=");
24 l = strlen(TempKey);
25
26 INIFindStartEnd(TempKey, &i, &j, l + sizeof(word) * 2);
27
28 if(!i || !j || (j < i + l))
29 {
30 TRACEEXIT();
31 return DefaultValue;
32 }
33
34 for(k = i + l; k <= j; k++)
35 if(!isxdigit(*k))
36 {
37 TRACEEXIT();
38 return DefaultValue;
39 }
40
41 x = (word) strtoul(i + l, NULL, 16);
42
43 if(x < MinValue) x = MinValue;
44 if(x > MaxValue) x = MaxValue;
45
46 TRACEEXIT();
47 return x;
48}
void INIFindStartEnd(char *, char **, char **, dword)
word INIGetHexWord(char *Key, word DefaultValue, word MinValue, word MaxValue)
Definition: INIGetHexWord.c:7
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243