00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "configurable.h"
00048
00049 using namespace std;
00050
00051 void Configurable::insertCVSInfo(paramkey& str, const char* file, const char* revision){
00052 string f(file);
00053 string rev(revision);
00054 int colon = f.find(':');
00055 int end = f.rfind('$');
00056 if(colon >= 0 && end >= 0 && colon+1 < end){
00057 str += f.substr(colon+1, end-colon-1);
00058 }
00059 str += "-";
00060 colon = rev.find(':');
00061 end = rev.rfind('$');
00062 if(colon >= 0 && end >= 0 && colon+1 < end){
00063 str += rev.substr(colon+1, end-colon-1);
00064 }
00065 }
00066
00067 #ifndef AVR
00068
00069 bool Configurable::storeCfg(const char* filenamestem){
00070 char name[256];
00071 FILE* f;
00072 sprintf(name, "%s.cfg",filenamestem);
00073 if(!(f = fopen(name, "w"))) return false;
00074 print(f,"");
00075 fclose(f);
00076 return true;
00077 }
00078
00079 bool Configurable::restoreCfg(const char* filenamestem){
00080 char name[256];
00081 FILE* f;
00082 sprintf(name, "%s.cfg",filenamestem);
00083 if(!(f=fopen(name, "r")))
00084 return false;
00085 parse(f);
00086 fclose(f);
00087 return true;
00088 }
00089
00090 void Configurable::print(FILE* f, const char* prefix) const {
00091 const char* pre = prefix==0 ? "": prefix;
00092 const unsigned short spacelength=20;
00093 char spacer[spacelength];
00094 memset(spacer, ' ', spacelength); spacer[spacelength-1]=0;
00095
00096 paramlist list = getParamList();
00097 fprintf(f, "%s[%s][%i]\n", pre, getName().c_str(), getId());
00098 for(paramlist::iterator i = list.begin(); i!= list.end() ; i++) {
00099 const string& k = (*i).first;
00100 fprintf(f, "%s %s=%s%f\n", pre, k.c_str(),
00101 spacer+(k.length() > spacelength ? spacelength : k.length()), (*i).second);
00102 }
00103 }
00104
00105 void Configurable::parse(FILE* f) {
00106 char* buffer = 0;
00107 size_t len=0;
00108 ssize_t read=0;
00109 while ((read = getline(&buffer, &len, f)) != -1) {
00110 char* p = strchr(buffer,'=');
00111 if(p!=0){
00112 *p=0;
00113 char* s = buffer;
00114 while (*s==' ') s++;
00115
00116 setParam(s, atof(p+1));
00117 }
00118 }
00119 if(buffer) free(buffer);
00120 }
00121
00122 #endif