64,691
社区成员
发帖
与我相关
我的任务
分享
#ifndef INIFILEOP_H
#define INIFILEOP_H
#ifdef __cplusplus
extern "C"{
#endif
int FileCopy(void *source_file, void *dest_file);
int SplitSectionToNameIndex(char *section, char **name, char **index);
int JoinNameIndexToSection(char **section, char *name, char *index);
int ConfigGetKey(void *CFG_file, void *section, void *key, void *buf);
int ConfigSetKey(void *CFG_file, void *section, void *key, void *buf);
int ConfigGetSections(void *CFG_file, char *sections[]);
int ConfigGetKeys(void *CFG_file, void *section, char *keys[]);
void INIFileTstmain(void);
#ifdef __cplusplus
}
#endif
#endif
int ConfigGetSections(void *CFG_file, char *sections[])
{
FILE *fp;
char buf1[MAX_CFG_BUF + 1];
int n, n_sections = 0, ret;
if((fp = fopen(CFG_file, "rb")) == NULL) return CFG_ERR_OPEN_FILE;
while(1)
{
ret = CFG_ERR_READ_FILE;
n = FileGetLine(fp, buf1, MAX_CFG_BUF);
if(n < -1) goto cfg_scts_end;
if(n < 0) break;
n = (int)strlen(strtriml(strtrimr(buf1)));
if(n == 0 || buf1[0] == CFG_nts) continue;
ret = CFG_ERR_FILE_FORMAT;
if(n > 2 && ((buf1[0] == CFG_ssl && buf1[n-1] != CFG_ssr)))
goto cfg_scts_end;
if(buf1[0] == CFG_ssl)
{
buf1[n-1] = 0x00;
strcpy(sections[n_sections], buf1+1);
n_sections++;
}
}
ret = n_sections;
cfg_scts_end:
if(fp != NULL) fclose(fp);
return ret;
}