From: pk910 Date: Sun, 6 Nov 2011 08:21:57 +0000 (+0100) Subject: removed old bogus ini parser X-Git-Tag: v5.3~199 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=8cdb9939ec5f90e931fce1be1aaab1baa206e205 removed old bogus ini parser --- diff --git a/src/lib/ini.c b/src/lib/ini.c deleted file mode 100644 index b9e8f97..0000000 --- a/src/lib/ini.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * modified port of Cini project - * original by: - * liukui,liukee2009@foxmail.com -*/ -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include -#include "ini.h" - -#define CHECK_FILE(f) if((f)==NULL) return FILE_NO_FILE - -typedef struct FIELD { - struct FIELD *fNext; - char FieldName[FIELDNAME_LEN]; - char FieldValue[FIELDVALUE_LEN]; -} FIELD; -typedef struct tagSECTION { - struct tagSECTION *sNext; - char SectionName[SECTION_LEN]; - FIELD *fNext; -} SECTION; - -static SECTION *g_INIlist = NULL; - -static void removeSpace(char *str) { - int i; - int start=0; - int end=strlen(str); - while(0x20 == str[start])start++; - for(i=start;i=0;i--) { - if (str[i] == 0x20) { - str[i]='\0'; - } else - break; - } -} - -void WriteString(char *SectionName, char *FieldName, char *FieldValue) { - SECTION *sect = NULL, *preSect = NULL; - FIELD *Field = NULL, *preField = NULL; - - if (!g_INIlist) - { - sect = malloc(sizeof(*sect)); - memset(sect,0,sizeof(*sect)); - strcpy(sect->SectionName, SectionName); - g_INIlist = sect; - } else { - sect = g_INIlist; - while(sect) { - if(!strcmp(sect->SectionName, SectionName)) - break; - preSect = sect; - sect = sect->sNext; - } - if (!sect) { - sect = malloc(sizeof(*sect)); - memset(sect,0,sizeof(*sect)); - strcpy(sect->SectionName, SectionName); - preSect->sNext = sect; - } - } - if (!sect->fNext) { - Field = malloc(sizeof(*Field)); - memset(Field,0,sizeof(*Field)); - strcpy(Field->FieldName, FieldName); - sect->fNext = Field; - } else { - Field = sect->fNext; - while(Field) { - if(!strcmp(Field->FieldName, FieldName)) - break; - preField=Field; - Field=Field->fNext; - } - - if (!Field) { - Field = malloc(sizeof(*Field)); - memset(Field,0,sizeof(*Field)); - strcpy(Field->FieldName, FieldName); - preField->fNext = Field; - } - } - strcpy(Field->FieldValue, FieldValue); - return; -} - -/* 0:ok;1:no section;2:no filename; */ -void ReadString(char *SectionName,char *FieldName,char *FieldValue) { - SECTION *sect = NULL; - FIELD *Field = NULL; - if (NULL == g_INIlist) - return; - sect=g_INIlist; - while(sect) { - if(!strcmp(sect->SectionName, SectionName)) - break; - sect = sect->sNext; - } - if (!sect) - return; - if (!sect->fNext) - return; - Field = sect->fNext; - while(Field) { - if(!strcmp(Field->FieldName, FieldName)) - break; - Field = Field->fNext; - } - if (!Field) - return; - strcpy(FieldValue, Field->FieldValue); - return; -} - -int loadINI(char *filename) { - FILE *f; - int i, fpointer = 0; - char SectionName[SECTION_LEN], FieldName[FIELDNAME_LEN], FieldValue[FIELDVALUE_LEN], ch; - - f=fopen(filename,"rb"); - CHECK_FILE(f); - - while(!feof(f)) { - while(!feof(f)) { - fread(&ch,sizeof(char),1,f); - if (ch == '[') - break; - } - i=0; - while(!feof(f)) - { - fread(&ch,sizeof(char),1,f); - if (ch != ']') - SectionName[i++] = ch; - else { - SectionName[i]='\0'; - break; - } - } - removeSpace(SectionName); - while(!feof(f)) { - fread(&ch,sizeof(char),1,f); - if (ch == '\r' || ch == '\n') - break; - } - if (SectionName[0] == '\0') - continue; - while(!feof(f)) { - while(!feof(f)) { - fpointer = ftell(f); - fread(&ch,sizeof(char),1,f); - if (isalnum(ch) || ch=='[') - break; - } - if(feof(f)) - break; - if (ch=='[') { - fseek(f,fpointer,SEEK_SET); - break; - } - i=0; - FieldName[i++] = ch; - while(!feof(f)) - { - fread(&ch,sizeof(char),1,f); - if (ch != '=') - FieldName[i++] = ch; - else { - FieldName[i] = '\0'; - break; - } - } - removeSpace(FieldName); - if (FieldName[0]=='\0') - continue; - i=0; - while(!feof(f)) { - fread(&ch,sizeof(char),1,f); - if (ch != '\r' && ch != '\n') - FieldValue[i++] = ch; - else { - FieldValue[i] = '\0'; - break; - } - } - removeSpace(FieldValue); - WriteString(SectionName,FieldName,FieldValue); - } - } - fclose(f); - return FILE_SUCCESS; -} - -int saveINI(char *filename) { - SECTION *sect = NULL, *preSect; - FIELD *Field = NULL, *preField; - char *pSBracket = "[", *pEBracket="]", *peq="=", *pend="\r\n"; - - if (NULL == g_INIlist) - return FILE_SUCCESS; - FILE *f = fopen(filename,"wb"); - CHECK_FILE(f); - sect = g_INIlist; - while(sect) { - preSect = sect; - fwrite(pSBracket,1,strlen(pSBracket),f); - fwrite(&(preSect->SectionName),1,strlen((char *)&(preSect->SectionName)),f); - fwrite(pEBracket,1,strlen(pEBracket),f); - fwrite(pend,1,strlen(pend),f); - if (NULL != sect->fNext) { - Field = sect->fNext; - while(Field) { - preField = Field; - fwrite(&(preField->FieldName),1,strlen(preField->FieldName),f); - fwrite(peq,1,strlen(peq),f); - fwrite(&(preField->FieldValue),1,strlen(preField->FieldValue),f); - fwrite(pend,1,strlen(pend),f); - Field = Field->fNext; - free(preField); - } - } - sect=sect->sNext; - free(preSect); - } - fflush(f); - fclose(f); - g_INIlist = NULL; - return FILE_SUCCESS; -} - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/src/lib/ini.h b/src/lib/ini.h deleted file mode 100644 index f3d03bb..0000000 --- a/src/lib/ini.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * modified port of Cini project - * original by: - * liukui,liukee2009@foxmail.com -*/ -#ifndef _INI_INCLUDE -#define _INI_INCLUDE - -#ifdef __cplusplus -extern "C" { -#endif - -#define SECTION_LEN 256 -#define FIELDNAME_LEN 256 -#define FIELDVALUE_LEN 256 - -#define FILE_SUCCESS 0 -#define FILE_NO_FILE 1 - -int loadINI(char *filename); /* load the ini file */ -int saveINI(char *filename); /* save to ini file */ - -void ReadString(char *SectionName,char *FieldName,char *FieldValue); /* read FieldValue of the FieldName */ -void WriteString(char *SectionName,char *FieldName,char *FieldValue); /* write FieldValue to the FieldName */ - -#ifdef __cplusplus -} -#endif - - -#endif /* _INI_INCLUDE */