-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfg.c
76 lines (71 loc) · 1.85 KB
/
cfg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* (C) Mr. Ka 1999*/
/*#include <malloc.h> // For DOS only*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "cfg.h"
#include "cfg_.h"
#include "html.h"
/* Вернуть значение параметра из массива данных файла конфигурации */
char *GetCfgValue(char *StrData, char *szNameValue)
{
char *Dst, *szTmp;
int iSizeBuff, i;
unsigned char blQuat;
iSizeBuff=MAX_PARAM;
Dst=malloc(iSizeBuff);
if(Dst==NULL)
{
fprintf(stderr,"CGF Error:GetCfgValue, Value %s. No memory for Dst.\n", szNameValue);
return FALSE;
}
do
{
if((!strncmp(StrData, szNameValue, strlen(szNameValue))) && (StrData[strlen(szNameValue)] == ' '))
{
/* Parameter found! */
StrData += strlen(szNameValue) + 1;
while(*StrData==' ' || *StrData=='\t')
StrData++;
blQuat=FALSE;
if(*StrData=='"')
{
blQuat=TRUE;
StrData++;
}
i=0;
while((StrData[i] != '\n') && (StrData[i] != '\0') && (StrData[i] != '"'))
{
if((StrData[i]==' '|| *StrData=='\t') && blQuat==FALSE)
break;
Dst[i] = StrData[i];
if(i==(iSizeBuff-2))
{
iSizeBuff+=ENV_INCREM;
szTmp=malloc(iSizeBuff);
if(!szTmp)
{
fprintf(stderr,"CFG Error:GetCfgValue, Value %s. No memory for resize Dst.\n", szNameValue);
return FALSE;
}
strcpy(szTmp,Dst);
free(Dst);
Dst=szTmp;
}
i++;
}
Dst[i] = '\0';
if(i>0)
return Dst;
}
/* Next parameter */
while((*StrData != '\n') && (*StrData != '\0'))
StrData++;
}
while(*(StrData++) != '\0');
free(Dst);
/* fprintf(stderr,"%sCFG Error: GetCfgValue. Not Value %s",HTML_NXTSTR, szNameValue); /* For Debug*/
return NULL;
}