From: "Morpheus" Newsgroups: comp.os.msdos.djgpp Subject: Re: make/linking trouble Date: Sun, 7 Nov 1999 19:35:49 -0600 Organization: Zion Lines: 123 Message-ID: <8059g6$ms7@hermes.acs.unt.edu> References: <80592o$mnp AT hermes DOT acs DOT unt DOT edu> NNTP-Posting-Host: dfw-premium-45.dialup.unt.edu X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com *IniUtils.h* #ifndef __INI_FILE__ #define __INI_FILE__ class IniFile { private: char* file; char* activeSecName; char** activeSec; public: IniFile(); IniFile(char* file); ~IniFile(); void setFile(char* file); void setActiveSection(char* secName); char* getValue(char* keyword); char* getActiveSectionName(); }; #endif __INI_FILE__ *IniUtils.cpp* #include #include #include #include #include #include "StringUtils.h" IniFile::IniFile() { file = NULL; activeSecName = NULL; activeSec = NULL; } IniFile::IniFile(const char* file) { setFile(file); activeSecName = NULL; activeSec = NULL; } IniFile::~IniFile() { freeString(file); freeString(activeSecName); freeStringArray(activeSec); } void IniFile::setFile(const char* file) { this.file = strdup(file); } void IniFile::setActiveSection(const char* secName) { char* searchSection = new char[strlen(secName) + 3]; char* line = new char[MAX_CHARS + 1]; activeSec = NULL; int numLines = 0; ifstream inifile = new ifstream(file); if(!inifile) { return NULL; } sprintf (searchSection, "[%s]", secName); // look for specified section do { inifile.getline(line, MAX_CHARS); } while(!inifile.eof() && !inifile.fail() && strcasecmp(line, searchSection) != 0); while (1) { inifile.getline(line, MAX_CHARS); if (inifile.eof() || inifile.fail() || line[0] == '[') { break; } numLines++; activeSec = newStringArray(numLines + 1); // (char **) realloc (activeSec, (numLines+1) * sizeof (char *)); activeSection[numLines++] = strdup(line); // numLines++; } // add the NULL at the end of the dynamic array // activeSection = (char **)realloc(activeSection, (numLines+1) * sizeof (char *)); // activeSection[numLines] = NULL; inifile.close(); freeStringArray(searchSection); } char* IniFile::getValue(char* keyword) { char* value = NULL; if((activeSec == NULL) || (keyword == NULL)) { return NULL; } char *pName, *pValue; // look for keyword in section while(*activeSec) { pName = *activeSec; pValue = strchr(*section++, '='); if (pValue == NULL) { continue; } if (strncasecmp(pName, keyword, strlen(keyword)) == 0) { strcpy(value, pValue + 1); return value; } // checked each line, found no match; so save default return NULL; } char* IniFile::getActiveSectionName() { return strdup(activeSecName); }