From 5e3d1130948bd179a493fa6824e64338cea47939 Mon Sep 17 00:00:00 2001 From: Daveo Date: Sat, 31 Mar 2001 16:20:24 +0000 Subject: [PATCH] --- Utils/Libs/DaveLib/IniClass.h | 325 ++++++++++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 Utils/Libs/DaveLib/IniClass.h diff --git a/Utils/Libs/DaveLib/IniClass.h b/Utils/Libs/DaveLib/IniClass.h new file mode 100644 index 000000000..16b37f7dc --- /dev/null +++ b/Utils/Libs/DaveLib/IniClass.h @@ -0,0 +1,325 @@ +/***********************/ +/*** Daves Ini Class ***/ +/***********************/ + +#pragma warning( disable : 4786 ) + +#ifndef __DAVES_INI_CLASS__ +#define __DAVES_INI_CLASS__ +#include + +/******************************************************************************/ +#define CIni_Max_Data_Size 128 + +/******************************************************************************/ +struct sIniEntry +{ + char Key[CIni_Max_Data_Size+1]; + char Data[CIni_Max_Data_Size+1]; +}; + +struct sIniGroup +{ + char Name[CIni_Max_Data_Size+1+2]; + std::vector Entry; +}; + +/******************************************************************************/ +class CIni +{ +public: + CIni (char *IniFile) {Import(IniFile);} + CIni () {} + + int GetGroupCount() {return(IniGroup.size());} + char *GetGroupName(int i) {return(IniGroup[i].Name);} + +/*----------------------------------------------------------------------------*/ +// returns 1 of fail, 0 on success!! (Who thought that up!) +int MyStrCmp(const char *Str0,const char *Str1) +{ + if (strlen(Str0)!=strlen(Str1)) return(1); + for (int Loop=0;Loop='a' && C0<='z') C0+='A'-'a'; + if (C1>='a' && C1<='z') C1+='A'-'a'; + if (C0!=C1) return(1); + } + return(0); +} + +/*----------------------------------------------------------------------------*/ +void SkipLine(char **InPtr) +{ +char *Ptr=*InPtr; + + while (*Ptr!='\n' && *Ptr) Ptr++; + *InPtr=Ptr; +} +/*----------------------------------------------------------------------------*/ +void LoadAndImport(const char *Filename) +{ +FILE *File; +int Size; +char *Script; + File=fopen(Filename,"rt"); + if (!File) return; + fseek(File,0,SEEK_END); + Size=ftell(File); + fseek(File,0,SEEK_SET); + Script=(char*)malloc(Size+1); + memset(Script,0,Size+1); + // Load It + fread(Script,Size,1,File); + fclose(File); + Import(Script); + free(Script); +} + +/*----------------------------------------------------------------------------*/ +void Import(char *IniFile) +{ +char GroupEntry[CIni_Max_Data_Size+1+2]; +char KeyEntry[CIni_Max_Data_Size+1+2]; + + GroupEntry[0]=0; + ParseFindEntry(&IniFile); + while (*IniFile) + { + if (IsComment(IniFile)) + { + SkipLine(&IniFile); + } + else + { + if (ParseGetEntry(&IniFile,KeyEntry)) + { // Group + strcpy(GroupEntry,KeyEntry); // Update Group buffer + StripGroupName(GroupEntry); + UpdateGroup(GroupEntry); + } + else + { // Data + UpdateKey(GroupEntry,KeyEntry); + } + } + ParseFindEntry(&IniFile); + } +} + +/*----------------------------------------------------------------------------*/ +void Export(char *OutFile) +{ + *OutFile=0; // Clear Output + for (int Group=0;Group IniGroup; +}; +#endif \ No newline at end of file