FireBirdLib - Topfield TMS PVR TAP Programming Library
INIGetInt.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
7long int INIGetInt(char *Key, long int DefaultValue, long int MinValue, long int MaxValue)
8{
10
11 char *i = NULL, *j = NULL, *k;
12 char TempKey[80];
13 long int 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 + 11); // max. digits for long int plus sign
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 {
36 if(k == i + l && *k == '-' && k < j) continue;
37 if(!isdigit(*k))
38 {
39 TRACEEXIT();
40 return DefaultValue;
41 }
42 }
43
44 x = strtoul(i + l, NULL, 10);
45
46 if(x < MinValue) x = MinValue;
47 if(x > MaxValue) x = MaxValue;
48
49 TRACEEXIT();
50 return x;
51}
void INIFindStartEnd(char *, char **, char **, dword)
long int INIGetInt(char *Key, long int DefaultValue, long int MinValue, long int MaxValue)
Definition: INIGetInt.c:7
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243