FireBirdLib - Topfield TMS PVR TAP Programming Library
INIFindStartEnd.c
Go to the documentation of this file.
1#include <string.h>
2#include "FBLib_ini.h"
3#include "libFireBird.h"
4
5void INIFindStartEnd(char *Key, char **Start, char **End, dword MaxEntrylen)
6{
8
9 char *CR, *LF, *p;
10
11 if(!Start || !End || !MaxEntrylen)
12 {
13 TRACEEXIT();
14 return;
15 }
16
17 if(!INIBuffer)
18 {
19 *Start = NULL;
20
21 TRACEEXIT();
22 return;
23 }
24
25 *End = NULL;
26 *Start = INIBuffer - 1;
27 do
28 {
29 *Start = stricstr(*Start + 1, Key);
30 if(*Start == NULL)
31 {
32 TRACEEXIT();
33 return;
34 }
35
36 if (*Start > INIBuffer) p = *Start - 1;
37 else p = "\n";
38 }
39 while (*p != '\n' && *p != '\r' && *p != '\t' && *p != ' ');
40
41 CR = strchr(*Start, '\x0d');
42 LF = strchr(*Start, '\x0a');
43
44 if(CR)
45 {
46 if(LF)
47 {
48 if(CR + 1 == LF)
49 *End = CR - 1; // Windows
50 else // junk
51 {
52 *End = LF - 1;
53
54 TRACEEXIT();
55 return;
56 }
57 }
58 else *End = CR - 1; // Mac
59 }
60 else
61 if(LF)
62 *End = LF - 1; // Unix
63 else // junk
64 {
65 *End = NULL;
66
67 TRACEEXIT();
68 return;
69 }
70
71 if(*End >= *Start + MaxEntrylen) *End = *Start + MaxEntrylen - 1;
72
73 TRACEEXIT();
74}
char * stricstr(const char *, const char *)
Definition: stricstr.c:8
char * INIBuffer
Definition: INIOpenFile.c:6
void INIFindStartEnd(char *Key, char **Start, char **End, dword MaxEntrylen)
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243