From 17bf8cb01918ebc424383073f74839795dc130bf Mon Sep 17 00:00:00 2001 From: Sjoerd van der Berg Date: Wed, 18 Sep 2002 15:33:49 +0000 Subject: [PATCH] A new CommandLine class and Config Class now has a startup handler to startup once everything has been initialized Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@295 --- src/misc/setup.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/src/misc/setup.cpp b/src/misc/setup.cpp index 1e83a93a..c66e9682 100644 --- a/src/misc/setup.cpp +++ b/src/misc/setup.cpp @@ -187,5 +187,106 @@ void Config::ParseConfigFile(const char* configfilename){ } } +void Config::SetStartUp(void (*_function)(void)) { + _start_function=_function; +} +void Config::StartUp(void) { + (*_start_function)(); +} + + + + +bool CommandLine::FindExist(char * name,bool remove) { + cmd_it it; + if (!(FindEntry(name,it,false))) return false; + if (remove) cmds.erase(it); + return true; +} + +bool CommandLine::FindHex(char * name,int & value,bool remove) { + cmd_it it,it_next; + if (!(FindEntry(name,it,true))) return false; + it_next=it;it_next++; + sscanf((*it_next).c_str(),"%X",&value); + if (remove) cmds.erase(it,it_next); + return true; +} + +bool CommandLine::FindInt(char * name,int & value,bool remove) { + cmd_it it,it_next; + if (!(FindEntry(name,it,true))) return false; + it_next=it;it_next++; + value=atoi((*it_next).c_str()); + if (remove) cmds.erase(it,it_next); + return true; +} + +bool CommandLine::FindString(char * name,std::string & value,bool remove) { + cmd_it it,it_next; + if (!(FindEntry(name,it,true))) return false; + it_next=it;it_next++; + value=*it_next; + if (remove) cmds.erase(it,it_next); + return true; +} + +bool CommandLine::FindFirst(std::string & value) { + if (cmds.empty()) return false; + value=*cmds.begin(); + return true; +} + +bool CommandLine::FindEntry(char * name,cmd_it & it,bool neednext) { + for (it=cmds.begin();it!=cmds.end();it++) { + if ((*it)==name) { + cmd_it itnext=it;itnext++; + if (neednext && (itnext==cmds.end())) return false; + return true; + } + } + return false; +} + +CommandLine::CommandLine(int argc,char * argv[]) { + if (argc>0) { + file_name=argv[0]; + } + int i=1; + while (i