add config::printconfig and others to print the configfile
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@323
This commit is contained in:
parent
982ec01bc5
commit
09e339c9b8
2 changed files with 64 additions and 5 deletions
|
@ -56,7 +56,8 @@ class Property {
|
|||
public:
|
||||
Property(const char* _propname):propname(_propname) { }
|
||||
virtual void SetValue(char* input)=0;
|
||||
Value GetValue() { return __value; }
|
||||
virtual void GetValuestring(char* str)=0;
|
||||
Value GetValue() { return __value;}
|
||||
std::string propname;
|
||||
Value __value;
|
||||
virtual ~Property(){ }
|
||||
|
@ -68,6 +69,7 @@ public:
|
|||
__value._int=_value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str);
|
||||
~Prop_int(){ }
|
||||
};
|
||||
|
||||
|
@ -77,6 +79,7 @@ public:
|
|||
__value._bool=_value;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str);
|
||||
~Prop_bool(){ }
|
||||
};
|
||||
|
||||
|
@ -89,6 +92,7 @@ public:
|
|||
delete __value._string;
|
||||
}
|
||||
void SetValue(char* input);
|
||||
void GetValuestring(char* str);
|
||||
};
|
||||
class Prop_hex:public Property {
|
||||
public:
|
||||
|
@ -97,6 +101,7 @@ public:
|
|||
}
|
||||
void SetValue(char* input);
|
||||
~Prop_hex(){ }
|
||||
void GetValuestring(char* str);
|
||||
};
|
||||
|
||||
class Section {
|
||||
|
@ -108,6 +113,7 @@ public:
|
|||
void ExecuteInit() { initfunction(this);}
|
||||
|
||||
virtual void HandleInputline(char *gegevens){}
|
||||
virtual void Print(FILE* outfile) { /*At this moment empty */ }
|
||||
|
||||
std::string sectionname;
|
||||
};
|
||||
|
@ -128,7 +134,8 @@ class Section_prop:public Section {
|
|||
bool Get_bool(const char* _propname);
|
||||
int Get_hex(const char* _propname);
|
||||
void HandleInputline(char *gegevens);
|
||||
|
||||
void Print(FILE* outfile);
|
||||
|
||||
std::list<Property*> properties;
|
||||
typedef std::list<Property*>::iterator it;
|
||||
};
|
||||
|
@ -137,7 +144,7 @@ class Section_line: public Section{
|
|||
public:
|
||||
Section_line(const char* _sectionname,void (*_initfunction)(Section*)):Section(_sectionname,_initfunction){}
|
||||
void HandleInputline(char* gegevens);
|
||||
|
||||
void Print(FILE* outfile);
|
||||
std::string data;
|
||||
};
|
||||
|
||||
|
@ -157,7 +164,7 @@ public:
|
|||
void Init();
|
||||
void ShutDown();
|
||||
void StartUp();
|
||||
|
||||
void PrintConfig(const char* configfilename);
|
||||
void ParseConfigFile(const char* configfilename);
|
||||
|
||||
std::list<Section*> sectionlist;
|
||||
|
|
|
@ -51,6 +51,22 @@ void Prop_hex::SetValue(char* input){
|
|||
if(!sscanf(input,"%X",&(__value._hex))) __value._hex=0;
|
||||
}
|
||||
|
||||
void Prop_int::GetValuestring(char* str){
|
||||
sprintf(str,"%d",__value._int);
|
||||
}
|
||||
|
||||
void Prop_string::GetValuestring(char* str){
|
||||
sprintf(str,"%s",__value._string->c_str());
|
||||
}
|
||||
|
||||
void Prop_bool::GetValuestring(char* str){
|
||||
sprintf(str,"%s",__value._bool?"true":"false");
|
||||
}
|
||||
|
||||
void Prop_hex::GetValuestring(char* str){
|
||||
sprintf(str,"%X",__value._hex);
|
||||
}
|
||||
|
||||
void Section_prop::Add_int(const char* _propname, int _value) {
|
||||
Property* test=new Prop_int(_propname,_value);
|
||||
properties.push_back(test);
|
||||
|
@ -116,13 +132,49 @@ void Section_prop::HandleInputline(char *gegevens){
|
|||
}
|
||||
}
|
||||
}
|
||||
#define HELPLENGTH 300
|
||||
void Section_prop::Print(FILE* outfile){
|
||||
char* val=new char[HELPLENGTH];
|
||||
fprintf(outfile,"[%s]\n",sectionname.c_str());
|
||||
snprintf(val,HELPLENGTH,"%s_CONFIGFILE_HELP",sectionname.c_str());
|
||||
|
||||
fprintf(outfile,"%% %s",MSG_Get(val));//entries in langfile end with \n
|
||||
for(it tel=properties.begin();tel!=properties.end();tel++){
|
||||
(*tel)->GetValuestring(val);
|
||||
fprintf(outfile,"%s=%s\n",(*tel)->propname.c_str(),val);
|
||||
}
|
||||
fprintf(outfile,"\n");
|
||||
delete val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Section_line::HandleInputline(char* gegevens){
|
||||
data+=gegevens;
|
||||
data+="\n";
|
||||
}
|
||||
|
||||
void Section_line::Print(FILE* outfile)
|
||||
{
|
||||
fprintf(outfile,"[%s]\n",sectionname.c_str());
|
||||
char* val=new char[HELPLENGTH];
|
||||
snprintf(val,HELPLENGTH,"%s_CONFIGFILE_HELP",sectionname.c_str());
|
||||
fprintf(outfile,"%% %s",MSG_Get(val));//entries in langfile end with \n
|
||||
fprintf(outfile,"%s",data.c_str());
|
||||
fprintf(outfile,"\n");
|
||||
delete val;
|
||||
}
|
||||
|
||||
void Config::PrintConfig(const char* configfilename){
|
||||
FILE* outfile=fopen(configfilename,"w+b");
|
||||
if(outfile==NULL) return;
|
||||
for (it tel=sectionlist.begin(); tel!=sectionlist.end(); tel++){
|
||||
(*tel)->Print(outfile);
|
||||
}
|
||||
fclose(outfile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Section* Config::AddSection(const char* _name,void (*_initfunction)(Section*)){
|
||||
Section* blah = new Section(_name,_initfunction);
|
||||
sectionlist.push_back(blah);
|
||||
|
|
Loading…
Add table
Reference in a new issue