apps/editconf/strconf.cpp

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <syslog.h>
00004 #include <string>
00005 #include <map>
00006 #include <fstream>
00007 
00008 using namespace std;
00009 
00010 void load(string fn, map<string, string> &c) {
00011         int i;
00012         char *z;
00013         string s;
00014         ifstream ifile(fn.c_str());
00015         while(!ifile.eof()) {
00016                 ifile >> s;
00017                 z = const_cast<char *>(s.c_str());
00018                 for(i = 0; z[i]; i++)
00019                         if(z[i] == '=') {
00020                                 z[i] = '\0';
00021                                 c[&z[0]] = &z[i + 1];
00022                                 break;
00023                         }
00024         }
00025         ifile.close();
00026 /*
00027         for(map<string, string>::iterator it = c.begin(); it != c.end(); it++)
00028                 syslog(LOG_ALERT, "|%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str());
00029 syslog(LOG_ALERT, "//||\\\\--------------------------- %s\r\n", fn.c_str());
00030 */
00031 }
00032 
00033 void save(string fn, map<string, string> &c) {
00034         string s;
00035         ofstream of(fn.c_str());
00036 /*
00037         for(map<string, string>::iterator it = c.begin(); it != c.end(); it++)
00038                 syslog(LOG_ALERT, "|%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str());
00039 */
00040         for(map<string, string>::iterator it = c.begin(); it != c.end(); it++) {
00041                 s = (*it).first;
00042                 s += "=";
00043                 s += (*it).second;
00044                 of << s;
00045                 of << endl;
00046         }
00047         of.close();
00048 }
00049 
00050 int main() {
00051         const char *uri;
00052         const char *method;
00053         const char *query;
00054 //      map<string, string> in
00055 //      string in;
00056 //      string out;
00057         map<string, string> params;
00058         map<string, string> in;
00059         map<string, string> out;
00060 
00061         method = getenv("REQUEST_METHOD");
00062         query = getenv("QUERY_STRING");
00063         uri = getenv("REQUEST_URI");
00064 /*
00065 syslog(LOG_ALERT, "REQUEST_METHOD=|%s|\r\n", method);
00066 syslog(LOG_ALERT, "REQUEST_STRING=|%s|\r\n", query);
00067 syslog(LOG_ALERT, "REQUEST_URI=|%s|\r\n", uri);
00068 
00069 syslog(LOG_ALERT, "strconf!\r\n");
00070 */
00071         // parse GET params
00072         string p_s = query;
00073         char *p = const_cast<char *>(p_s.c_str());
00074 //syslog(LOG_ALERT, "string: |%s|\r\n", p);
00075         int i, j, k;
00076         k = 0;
00077         bool f = false, to_break = false;
00078         for(i = 0; ; i++) {
00079                 if(p[i] == '\'')
00080                         f = !f;
00081                 if((p[i] == '&' || p[i] == '\0') && !f) {
00082                         if(p[i] == '\0')
00083                                 to_break = true;
00084                         else
00085                                 p[i] = '\0';
00086                         for(j = k; p[j]; j++) {
00087                                 if(p[j] == '=') {
00088                                         p[j] = '\0';
00089                                         params[&p[k]] = &p[j + 1];
00090                                         break;
00091                                 }
00092                         }
00093                         k = i + 1;
00094                         f = false;
00095                 }
00096                 if(to_break)
00097                         break;
00098         }
00099         // load 'in' and 'out' file;
00100         load(params["in"], in);
00101         load(params["out"], out);
00103         in["init_1"] = out["init_1"];
00104         in["init_2"] = out["init_2"];
00106         if(params["init_1"] != "''")
00107                 in["init_1"] = params["init_1"];
00108         if(params["init_2"] != "''")
00109                 in["init_2"] = params["init_2"];
00110 //*/
00111         save(params["out"], in);
00112 //*/
00113 //      for(map<string, string>::iterator it = params.begin(); it != params.end(); it++) {
00114 //              syslog(LOG_ALERT, "param: |%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str());
00115 //      }
00116 
00117         return 0;
00118 }

Generated on Fri Nov 28 00:06:21 2008 for elphel by  doxygen 1.5.1