From: "Morpheus" Newsgroups: comp.os.msdos.djgpp Subject: Re: compiling C++ Date: Fri, 5 Nov 1999 06:00:22 -0600 Organization: University of North Texas Lines: 268 Message-ID: <7vugut$7d9@hermes.acs.unt.edu> References: <7vsnag$jhc AT hermes DOT acs DOT unt DOT edu> NNTP-Posting-Host: dfw-premium-2.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 Here's the long version of my problem with all files: *StringUtils.h* #ifndef __STRING_UTILS__ #define __STRING_UTILS__ #define MAX_CHARS = 255; void freeString(char* str); char** newStringArray(int n); void freeStringArray(char** str); char** resizeStringArray(char** str, int n); char** newStringArrayFromFile(char* file); #endif __STRING_UTILS__ *StringUtils.cpp* #include #include #include #include #include "fileUtils.h" #include "StringUtils.h" void freeString(char *str) { if(str != NULL) { delete str; str = NULL; } } char** newStringArray(int n) { char** str = new char*[n]; for(int i = 0; i < (n - 1); i++) { str[i] = ""; } str[n - 1] = NULL; return str; } void freeStringArray(char** str) { if(str != NULL) { for(int i = 0; str[i] != NULL; i++) { freeString(str[i]); } str = NULL; } } char** resizeStringArray(char** str, int n) { char** strA = newStringArray(n); for(int i = 0; i < n; i++) { strA[i] = NULL; } if(str != NULL) { for(int i = 0; i < n; i++) { if(str[i] == NULL) { break; } strA[i] = strdup(str[i]); } } freeStringArray(str); return strA; } *FileUtils.h* #ifndef __FILE_UTILS__ #define __FILE_UTILS__ int getFileNumLines(char* file); #endif __FILE_UTILS__ *FileUtils.cpp* #include #include "StringUtils.h" #include "FileUtils.h" int getFileNumLines(char* file) { ifstream in = new ifstream(file); if(!in) { return 0; } char* line = new char[MAX_CHARS + 1]; int numLines = 0; in.readLine(line, MAX_CHARS); while(in) { numLines++; in.readLine(line, MAX_CHARS); } StringUtils::freeString(line); in.close(); ~in(); return numLines; } *IniUtils.h* #ifndef __INI_FILE__ #define __INI_FILE__ class IniFile { private: char* file; char* activeSecName; char** activeSec; public: IniFile(); IniFile(char* file); void setFile(char* file); void setActiveSection(char* secName); char* getValue(char* keyword); char* getActiveSectionName(); }; #endif __INI_FILE__ *IniUtils.cpp* #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; } void IniFile::setFile(const char* file) { this.file = strdup(file); } void IniFile::setActiveSection(const char* secName) { // with code written by my instructor 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); } int main() { IniFile* ini = new IniFile("demo1.sim"); ini->setActiveSection("Configuration"); cout << ini->getValue("Author"); } Then, after compiling with: redir -eo gxx -v -O2 -Wall IniUtils.cpp -o IniUtils.exe > compile.log *compile.log* Reading specs from d:/djgpp/lib/specs gcc.exe: unrecognized option `-02' gcc version 2.95.1 19990816 (release) d:/djgpp/lib/gcc-lib/djgpp/2.951/cpp.exe -lang-c++ -v -isystem d:/djgpp/bin/include -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplus plus -Dunix -Di386 -DGO32 -DMSDOS -DDJGPP=2 -DDJGPP_MINOR=2 -D__unix__ -D__i 386__ -D__GO32__ -D__MSDOS__ -D__DJGPP__=2 -D__DJGPP_MINOR__=2 -D__unix -D__ i386 -D__GO32 -D__MSDOS -D__DJGPP=2 -D__DJGPP_MINOR=2 -D__EXCEPTIONS -Wall IniUtils.cpp d:/djgpp/tmp\ccNOUELe.ii GNU CPP version 2.95.1 19990816 (release) (80386, BSD syntax) #include "..." search starts here: #include <...> search starts here: d:/djgpp/lang/cxx d:/djgpp/include d:/djgpp/lang/cxx d:/djgpp/lib/gcc-lib/djgpp/2.951/include d:/djgpp/include End of search list. The following default directories have been omitted from the search path: $DJDIR/lib/gcc-lib/djgpp/2.951/../../../../djgpp/include End of omitted list. d:/djgpp/lib/gcc-lib/djgpp/2.951/cc1plus.exe d:/djgpp/tmp\ccNOUELe.ii -m486 -malign-jumps=2 -malign-loops=2 -malign-funct ions=2 -m486 -malign-jumps=2 -malign-loops=2 -malign-functions=2 -quiet -dum pbase IniUtils.cc -Wall -version -o d:/djgpp/tmp\ccosVjGG.s GNU C++ version 2.95.1 19990816 (release) (djgpp) compiled by GNU C version 2.95.1 19990816 (release). d:/djgpp/bin/as.exe -o d:/djgpp/tmp\ccz2CoWH.o d:/djgpp/tmp\ccosVjGG.s d:/djgpp/bin/ld.exe -o IniUtils.exe d:/djgpp/lib/crt0.o -Ld:/djgpp/lib -Ld:/djgpp/lib/gcc-lib/djgpp/2.951 -Ld:/d jgpp/bin -Ld:/djgpp/lib d:/djgpp/tmp\ccz2CoWH.o -lstdcxx -lgpp -lm -Tdjgpp.djl -lgcc -lc -lgcc PLEASE HELP me out here.