00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef _WIN32
00024 #pragma warning(disable:4786)
00025 #endif
00026 #include <stdio.h>
00027 #include "Parse.h"
00028
00029 #include "config.h"
00030
00031 #define C slask[strlen(slask) - 1]
00032
00033
00034 config_m config;
00035 static std::string config_filename;
00036
00037
00038 static void read_config(const std::string& filename)
00039 {
00040 FILE *fil = fopen(filename.c_str(),"rt");
00041 config_filename = filename;
00042 if (fil)
00043 {
00044 char slask[1000];
00045 std::string key;
00046 std::string value;
00047 fgets(slask,1000,fil);
00048 while (!feof(fil))
00049 {
00050 while (strlen(slask) && (C == 13 || C == 10))
00051 C = 0;
00052 Parse pa(slask);
00053 pa.getword(key);
00054 pa.getrest(value);
00055 config[key] = value;
00056
00057 fgets(slask,1000,fil);
00058 }
00059 fclose(fil);
00060 }
00061 }
00062
00063
00064 void write_config()
00065 {
00066 FILE *fil = fopen(config_filename.c_str(),"wt");
00067 if (fil)
00068 {
00069 for (config_m::iterator it = config.begin(); it != config.end(); it++)
00070 {
00071 std::string key = (*it).first;
00072 std::string value = (*it).second;
00073 if (key[0] != '.')
00074 fprintf(fil,"%s %s\n",key.c_str(),value.c_str());
00075 }
00076 fclose(fil);
00077 }
00078 }
00079
00080
00081 void parse_config(int argc,char *argv[],const std::string& filename)
00082 {
00083 read_config( filename );
00084 for (int i = 1; i < argc; i++)
00085 if (argv[i][0] == '-' && i < argc - 1)
00086 {
00087 config[argv[i] + 1] = argv[i + 1];
00088 i++;
00089 }
00090 write_config();
00091 }
00092
00093