Add shift and more const correctness
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2638
This commit is contained in:
parent
a11f305138
commit
c02188b774
2 changed files with 64 additions and 53 deletions
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: setup.h,v 1.24 2006-04-10 12:06:25 qbix79 Exp $ */
|
||||
/* $Id: setup.h,v 1.25 2006-05-25 15:07:32 qbix79 Exp $ */
|
||||
|
||||
#ifndef DOSBOX_SETUP_H
|
||||
#define DOSBOX_SETUP_H
|
||||
|
@ -46,6 +46,7 @@ public:
|
|||
bool FindStringRemain(char const * const name,std::string & value);
|
||||
bool GetStringRemain(std::string & value);
|
||||
unsigned int GetCount(void);
|
||||
void Shift(unsigned int amount=1);
|
||||
private:
|
||||
typedef std::list<std::string>::iterator cmd_it;
|
||||
std::list<std::string> cmds;
|
||||
|
@ -65,8 +66,8 @@ class Property {
|
|||
public:
|
||||
Property(char const * const _propname):propname(_propname) { }
|
||||
virtual void SetValue(char* input)=0;
|
||||
virtual void GetValuestring(char* str)=0;
|
||||
Value GetValue() { return value;}
|
||||
virtual void GetValuestring(char* str) const=0;
|
||||
Value GetValue() const { return value;}
|
||||
virtual ~Property(){ }
|
||||
std::string propname;
|
||||
Value value;
|
||||
|
@ -78,7 +79,7 @@ public:
|
|||
value._int=_value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str);
|
||||
void GetValuestring(char* str) const;
|
||||
~Prop_int(){ }
|
||||
};
|
||||
class Prop_float:public Property {
|
||||
|
@ -87,7 +88,7 @@ public:
|
|||
value._float=_value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str);
|
||||
void GetValuestring(char* str) const;
|
||||
~Prop_float(){ }
|
||||
};
|
||||
|
||||
|
@ -97,7 +98,7 @@ public:
|
|||
value._bool=_value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str);
|
||||
void GetValuestring(char* str) const;
|
||||
~Prop_bool(){ }
|
||||
};
|
||||
|
||||
|
@ -110,7 +111,7 @@ public:
|
|||
delete value._string;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str);
|
||||
void GetValuestring(char* str) const;
|
||||
};
|
||||
class Prop_hex:public Property {
|
||||
public:
|
||||
|
@ -119,7 +120,7 @@ public:
|
|||
}
|
||||
void SetValue(char* input);
|
||||
~Prop_hex(){ }
|
||||
void GetValuestring(char* str);
|
||||
void GetValuestring(char* str) const;
|
||||
};
|
||||
|
||||
class Section {
|
||||
|
@ -145,11 +146,11 @@ public:
|
|||
void AddDestroyFunction(SectionFunction func,bool canchange=false) {destroyfunctions.push_front(Function_wrapper(func,canchange));}
|
||||
void ExecuteInit(bool initall=true);
|
||||
void ExecuteDestroy(bool destroyall=true);
|
||||
const char* GetName() {return sectionname.c_str();}
|
||||
const char* GetName() const {return sectionname.c_str();}
|
||||
|
||||
virtual char const * GetPropValue(char const * const _property)=0;
|
||||
virtual char const * GetPropValue(char const * const _property) const =0;
|
||||
virtual void HandleInputline(char * _line)=0;
|
||||
virtual void PrintData(FILE* outfile)=0;
|
||||
virtual void PrintData(FILE* outfile) const =0;
|
||||
virtual ~Section() { /*Children must call executedestroy ! */}
|
||||
};
|
||||
|
||||
|
@ -158,6 +159,7 @@ class Section_prop:public Section {
|
|||
private:
|
||||
std::list<Property*> properties;
|
||||
typedef std::list<Property*>::iterator it;
|
||||
typedef std::list<Property*>::const_iterator const_it;
|
||||
public:
|
||||
Section_prop(char const * const _sectionname):Section(_sectionname){}
|
||||
void Add_int(char const * const _propname, int _value=0);
|
||||
|
@ -166,14 +168,14 @@ public:
|
|||
void Add_hex(char const * const _propname, int _value=0);
|
||||
void Add_float(char const * const _propname, float _value=0.0);
|
||||
|
||||
int Get_int(char const * const _propname);
|
||||
const char* Get_string(char const * const _propname);
|
||||
bool Get_bool(char const * const _propname);
|
||||
int Get_hex(char const * const _propname);
|
||||
float Get_float(char const * const _propname);
|
||||
int Get_int(char const * const _propname) const;
|
||||
const char* Get_string(char const * const _propname) const;
|
||||
bool Get_bool(char const * const _propname) const;
|
||||
int Get_hex(char const * const _propname) const;
|
||||
float Get_float(char const * const _propname) const;
|
||||
void HandleInputline(char *gegevens);
|
||||
void PrintData(FILE* outfile);
|
||||
virtual char const * GetPropValue(char const * const _property);
|
||||
void PrintData(FILE* outfile) const;
|
||||
virtual char const * GetPropValue(char const * const _property) const;
|
||||
//ExecuteDestroy should be here else the destroy functions use destroyed properties
|
||||
virtual ~Section_prop();
|
||||
};
|
||||
|
@ -183,8 +185,8 @@ public:
|
|||
Section_line(char const * const _sectionname):Section(_sectionname){}
|
||||
~Section_line(){ExecuteDestroy(true);}
|
||||
void HandleInputline(char* gegevens);
|
||||
void PrintData(FILE* outfile);
|
||||
virtual const char* GetPropValue(char const * const _property);
|
||||
void PrintData(FILE* outfile) const;
|
||||
virtual const char* GetPropValue(char const * const _property) const;
|
||||
std::string data;
|
||||
};
|
||||
|
||||
|
@ -195,6 +197,8 @@ private:
|
|||
std::list<Section*> sectionlist;
|
||||
typedef std::list<Section*>::iterator it;
|
||||
typedef std::list<Section*>::reverse_iterator reverse_it;
|
||||
typedef std::list<Section*>::const_iterator const_it;
|
||||
typedef std::list<Section*>::const_reverse_iterator const_reverse_it;
|
||||
void (* _start_function)(void);
|
||||
public:
|
||||
Config(CommandLine * cmd):cmdline(cmd){}
|
||||
|
@ -203,14 +207,14 @@ public:
|
|||
Section_line * AddSection_line(char const * const _name,void (*_initfunction)(Section*));
|
||||
Section_prop * AddSection_prop(char const * const _name,void (*_initfunction)(Section*),bool canchange=false);
|
||||
|
||||
Section* GetSection(char const* const _sectionname);
|
||||
Section* GetSectionFromProperty(char const * const prop);
|
||||
Section* GetSection(char const* const _sectionname) const;
|
||||
Section* GetSectionFromProperty(char const * const prop) const;
|
||||
|
||||
void SetStartUp(void (*_function)(void));
|
||||
void Init();
|
||||
void ShutDown();
|
||||
void StartUp();
|
||||
void PrintConfig(char const * const configfilename);
|
||||
void PrintConfig(char const * const configfilename) const;
|
||||
bool ParseConfigFile(char const * const configfilename);
|
||||
void ParseEnv(char ** envp);
|
||||
};
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: setup.cpp,v 1.35 2006-04-10 12:06:07 qbix79 Exp $ */
|
||||
/* $Id: setup.cpp,v 1.36 2006-05-25 15:07:33 qbix79 Exp $ */
|
||||
|
||||
#include "dosbox.h"
|
||||
#include "cross.h"
|
||||
|
@ -59,23 +59,23 @@ void Prop_hex::SetValue(char* input){
|
|||
if(!sscanf(input,"%X",&(value._hex))) value._hex=0;
|
||||
}
|
||||
|
||||
void Prop_int::GetValuestring(char* str){
|
||||
void Prop_int::GetValuestring(char* str) const{
|
||||
sprintf(str,"%d",value._int);
|
||||
}
|
||||
|
||||
void Prop_string::GetValuestring(char* str){
|
||||
void Prop_string::GetValuestring(char* str) const{
|
||||
sprintf(str,"%s",value._string->c_str());
|
||||
}
|
||||
|
||||
void Prop_bool::GetValuestring(char* str){
|
||||
void Prop_bool::GetValuestring(char* str) const{
|
||||
sprintf(str,"%s",value._bool?"true":"false");
|
||||
}
|
||||
|
||||
void Prop_float::GetValuestring(char* str){
|
||||
void Prop_float::GetValuestring(char* str) const {
|
||||
sprintf(str,"%1.2f",value._float);
|
||||
}
|
||||
|
||||
void Prop_hex::GetValuestring(char* str){
|
||||
void Prop_hex::GetValuestring(char* str) const {
|
||||
sprintf(str,"%X",value._hex);
|
||||
}
|
||||
|
||||
|
@ -103,8 +103,8 @@ void Section_prop::Add_hex(const char* _propname, int _value) {
|
|||
Property* test=new Prop_hex(_propname,_value);
|
||||
properties.push_back(test);
|
||||
}
|
||||
int Section_prop::Get_int(char const * const _propname){
|
||||
for(it tel=properties.begin();tel!=properties.end();tel++){
|
||||
int Section_prop::Get_int(char const * const _propname) const {
|
||||
for(const_it tel=properties.begin();tel!=properties.end();tel++){
|
||||
if((*tel)->propname==_propname){
|
||||
return ((*tel)->GetValue())._int;
|
||||
}
|
||||
|
@ -112,16 +112,16 @@ int Section_prop::Get_int(char const * const _propname){
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool Section_prop::Get_bool(char const * const _propname){
|
||||
for(it tel=properties.begin();tel!=properties.end();tel++){
|
||||
bool Section_prop::Get_bool(char const * const _propname) const {
|
||||
for(const_it tel=properties.begin();tel!=properties.end();tel++){
|
||||
if((*tel)->propname==_propname){
|
||||
return ((*tel)->GetValue())._bool;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
float Section_prop::Get_float(char const * const _propname){
|
||||
for(it tel=properties.begin();tel!=properties.end();tel++){
|
||||
float Section_prop::Get_float(char const * const _propname) const {
|
||||
for(const_it tel=properties.begin();tel!=properties.end();tel++){
|
||||
if((*tel)->propname==_propname){
|
||||
return ((*tel)->GetValue())._float;
|
||||
}
|
||||
|
@ -129,16 +129,16 @@ float Section_prop::Get_float(char const * const _propname){
|
|||
return false;
|
||||
}
|
||||
|
||||
const char* Section_prop::Get_string(char const * const _propname){
|
||||
for(it tel=properties.begin();tel!=properties.end();tel++){
|
||||
const char* Section_prop::Get_string(char const * const _propname) const {
|
||||
for(const_it tel=properties.begin();tel!=properties.end();tel++){
|
||||
if((*tel)->propname==_propname){
|
||||
return ((*tel)->GetValue())._string->c_str();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
int Section_prop::Get_hex(char const * const _propname){
|
||||
for(it tel=properties.begin();tel!=properties.end();tel++){
|
||||
int Section_prop::Get_hex(char const * const _propname) const {
|
||||
for(const_it tel=properties.begin();tel!=properties.end();tel++){
|
||||
if((*tel)->propname==_propname){
|
||||
return ((*tel)->GetValue())._hex;
|
||||
}
|
||||
|
@ -160,18 +160,18 @@ void Section_prop::HandleInputline(char *gegevens){
|
|||
}
|
||||
|
||||
|
||||
void Section_prop::PrintData(FILE* outfile){
|
||||
void Section_prop::PrintData(FILE* outfile) const {
|
||||
char temp[1000]; /* Should be enough for the properties */
|
||||
/* Now print out the individual section entries */
|
||||
for(it tel=properties.begin();tel!=properties.end();tel++){
|
||||
for(const_it tel=properties.begin();tel!=properties.end();tel++){
|
||||
(*tel)->GetValuestring(temp);
|
||||
fprintf(outfile,"%s=%s\n",(*tel)->propname.c_str(),temp);
|
||||
}
|
||||
}
|
||||
|
||||
static char buffer[1024];
|
||||
char const * Section_prop::GetPropValue(char const * const _property) {
|
||||
for(it tel=properties.begin();tel!=properties.end();tel++){
|
||||
char const * Section_prop::GetPropValue(char const * const _property) const{
|
||||
for(const_it tel=properties.begin();tel!=properties.end();tel++){
|
||||
if(!strcasecmp((*tel)->propname.c_str(),_property)){
|
||||
(*tel)->GetValuestring(buffer);
|
||||
return buffer;
|
||||
|
@ -185,19 +185,19 @@ void Section_line::HandleInputline(char* line){
|
|||
data+="\n";
|
||||
}
|
||||
|
||||
void Section_line::PrintData(FILE* outfile) {
|
||||
void Section_line::PrintData(FILE* outfile) const {
|
||||
fprintf(outfile,"%s",data.c_str());
|
||||
}
|
||||
|
||||
char const* Section_line::GetPropValue(char const * const /* _property*/) {
|
||||
char const* Section_line::GetPropValue(char const * const /* _property*/) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Config::PrintConfig(char const * const configfilename){
|
||||
void Config::PrintConfig(char const * const configfilename) const {
|
||||
char temp[50];char helpline[256];
|
||||
FILE* outfile=fopen(configfilename,"w+t");
|
||||
if(outfile==NULL) return;
|
||||
for (it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
for (const_it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
/* Print out the Section header */
|
||||
strcpy(temp,(*tel)->GetName());
|
||||
lowcase(temp);
|
||||
|
@ -247,8 +247,8 @@ Section_line* Config::AddSection_line(char const * const _name,void (*_initfunct
|
|||
}
|
||||
|
||||
|
||||
void Config::Init(){
|
||||
for (it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
void Config::Init() {
|
||||
for (const_it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
(*tel)->ExecuteInit();
|
||||
}
|
||||
}
|
||||
|
@ -278,15 +278,15 @@ Config::~Config() {
|
|||
}
|
||||
}
|
||||
|
||||
Section* Config::GetSection(char const * const _sectionname){
|
||||
for (it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
Section* Config::GetSection(char const * const _sectionname) const{
|
||||
for (const_it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
if (!strcasecmp((*tel)->GetName(),_sectionname)) return (*tel);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Section* Config::GetSectionFromProperty(char const * const prop){
|
||||
for (it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
Section* Config::GetSectionFromProperty(char const * const prop) const{
|
||||
for (const_it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
if ((*tel)->GetPropValue(prop)) return (*tel);
|
||||
}
|
||||
return NULL;
|
||||
|
@ -506,3 +506,10 @@ CommandLine::CommandLine(char const * const name,char const * const cmdline) {
|
|||
}
|
||||
if (inword || inquote) cmds.push_back(str);
|
||||
}
|
||||
|
||||
void CommandLine::Shift(unsigned int amount) {
|
||||
while(amount--) {
|
||||
file_name = cmds.size()?(*(cmds.begin())):"";
|
||||
if(cmds.size()) cmds.erase(cmds.begin());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue