]> git.stg.codes - stg.git/blob - projects/convertor/settings_impl.cpp
Fix compilation issues for convertor
[stg.git] / projects / convertor / settings_impl.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Date: 27.10.2002
19  */
20
21 /*
22  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23  */
24
25 /*
26 $Revision: 1.6 $
27 $Date: 2009/06/22 16:26:54 $
28 */
29
30 #include "dotconfpp.h"
31 #include "module_settings.h"
32 #include "settings_impl.h"
33 #include "common.h"
34
35 int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params)
36 {
37 if (!node)
38     return 0;
39
40 PARAM_VALUE pv;
41
42 pv.param = node->getName();
43
44 if (node->getValue(1))
45     {
46     strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'.";
47     printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
48     return -1;
49     }
50
51 const char * value = node->getValue(0);
52
53 if (!value)
54     {
55     strError = "Module name expected.";
56     printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
57     return -1;
58     }
59
60 const DOTCONFDocumentNode * childNode = node->getChildNode();
61 while (childNode)
62     {
63     pv.param = childNode->getName();
64     int i = 0;
65     while ((value = childNode->getValue(i)) != NULL)
66         {
67         pv.value.push_back(value);
68         ++i;
69         }
70     params->push_back(pv);
71     pv.value.clear();
72     childNode = childNode->getNextNode();
73     }
74
75 return 0;
76 }
77 //-----------------------------------------------------------------------------
78 int SETTINGS_IMPL::ReadSettings()
79 {
80 const char * requiredOptions[] = {
81     "ModulesPath",
82     "SourceStoreModule",
83     "DestStoreModule",
84     NULL
85     };
86 int sourceStoreModulesCount = 0;
87 int destStoreModulesCount = 0;
88
89 DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE);
90 conf.setRequiredOptionNames(requiredOptions);
91
92 if(conf.setContent(confFile.c_str()) != 0)
93     {
94     strError = "Cannot read file " + confFile + ".";
95     printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
96     return -1;
97     }
98
99 const DOTCONFDocumentNode * node = conf.getFirstNode();
100
101 while (node)
102     {
103     if (strcasecmp(node->getName(), "ModulesPath") == 0)
104         {
105         modulesPath = node->getValue(0);
106         }
107
108     if (strcasecmp(node->getName(), "SourceStoreModule") == 0)
109         {
110         if (node->getValue(1))
111             {
112             strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
113             printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
114             return -1;
115             }
116
117         if (sourceStoreModulesCount)
118             {
119             strError = "Should be only one source StoreModule.";
120             printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
121             return -1;
122             }
123         ++sourceStoreModulesCount;
124
125         sourceStoreModuleSettings.moduleName = node->getValue(0);
126         ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams);
127         }
128
129     if (strcasecmp(node->getName(), "DestStoreModule") == 0)
130         {
131         if (node->getValue(1))
132             {
133             strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
134             printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
135             return -1;
136             }
137
138         if (destStoreModulesCount)
139             {
140             strError = "Should be only one dest StoreModule.";
141             printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
142             return -1;
143             }
144         ++destStoreModulesCount;
145
146         destStoreModuleSettings.moduleName = node->getValue(0);
147         ParseModuleSettings(node, &destStoreModuleSettings.moduleParams);
148         }
149
150     node = node->getNextNode();
151     }
152
153 return 0;
154 }
155 //-----------------------------------------------------------------------------