13 std::string
const & prefix, uint16_t
offset){
15 std::ifstream inFile(fileName.c_str());
16 if (!inFile.is_open()){
17 std::string envBasedFileName = fileName;
19 if(getenv(
"WIBMOD_SHARE") != NULL){
20 envBasedFileName=getenv(
"WIBMOD_SHARE");
21 envBasedFileName+=
"/config/WIB1/tables/";
22 envBasedFileName+=fileName;
23 inFile.open(envBasedFileName.c_str());
25 if (!inFile.is_open()){
26 BUException::BAD_FILE e;
27 e.Append(
"File not found: ");
28 e.Append(envBasedFileName.c_str());
32 const size_t bufferSize = 1000;
33 char buffer[bufferSize + 1];
34 memset(buffer,0,bufferSize+1);
35 uint32_t lineNumber = 1;
36 while(! inFile.eof()){
37 inFile.getline(buffer,bufferSize);
45 std::string
const & prefix, uint16_t
offset){
47 std::string activeLine = line.substr(0,line.find(
'#'));
51 boost::char_separator<char> sep(
" ");
52 boost::tokenizer<boost::char_separator<char> > tokens(activeLine,sep);
53 boost::tokenizer<boost::char_separator<char> >::iterator itToken = tokens.begin();
59 for(; itToken != tokens.end(); itToken++){
65 std::string name(*itToken);
68 name = prefix+std::string(
".")+name;
71 while( (name.size() > 0) && (
'.' == name[name.size()-1])) {
73 name.erase(name.size()-1);
79 BUException::INVALID_NAME e;
80 e.Append(
"Empty name");
84 boost::to_upper(name);
87 item->
name.assign(name);
100 if(!isdigit((itToken->c_str()[0]))){
104 while(itToken != tokens.end()){
113 BUException::MAX_INCLUDE_FILE_DEPTH e;
116 e.Append(
" at prefix ");
117 e.Append(item->
name);
118 e.Append(
" is too deep\n");
129 item->
mask = strtoul(itToken->c_str(),NULL,0);
133 unsigned int v = item->
mask;
137 if (v & 0x0000FFFF) {c -= 16;}
138 if (v & 0x00FF00FF) {c -= 8;}
139 if (v & 0x0F0F0F0F) {c -= 4;}
140 if (v & 0x33333333) {c -= 2;}
141 if (v & 0x55555555) {c -= 1;}
152 if(itToken->find(
'r') != std::string::npos){
154 }
else if (itToken->find(
'R') != std::string::npos){
159 if(itToken->find(
'w') != std::string::npos){
161 }
else if (itToken->find(
'W') != std::string::npos){
166 if(itToken->find(
'a') != std::string::npos){
168 }
else if (itToken->find(
'A') != std::string::npos){
179 if(itToken->find(
'=') == std::string::npos){
181 item->
user[*itToken];
185 size_t equalSignPos = itToken->find(
'=');
187 if(itToken->find(
'"') != std::string::npos){
188 if(itToken->find(
'"') < equalSignPos){
189 BUException::BAD_TOKEN e;
190 e.Append(
"Malformed token : ");
191 e.Append(itToken->c_str());
192 e.Append(
" on line ");
193 char numberBuffer[14] =
"\0\0\0\0\0\0\0\0\0\0\0\0";
194 snprintf(numberBuffer,12,
"%zu\n",lineNumber);
195 e.Append(numberBuffer);
196 e.Append(
"Bad line: ");
197 e.Append(activeLine);
203 std::string name = itToken->substr(0,equalSignPos);
205 if(itToken->size()-1 == equalSignPos){
206 BUException::BAD_TOKEN e;
207 e.Append(
"Malformed token : ");
208 e.Append(itToken->c_str());
209 e.Append(
" on line ");
210 char numberBuffer[14] =
"\0\0\0\0\0\0\0\0\0\0\0\0";
211 snprintf(numberBuffer,12,
"%zu\n",lineNumber);
212 e.Append(numberBuffer);
216 std::string val = itToken->substr(equalSignPos+1);
219 item->
user[name] = val;
226 if(val.find(
'"') != std::string::npos){
228 val = val.substr(0,val.find(
'"'));
232 while(itToken != tokens.end()){
234 val.append(*itToken);
235 if((*itToken)[itToken->size() -1] ==
'"'){
238 val.erase(val.size()-1);
246 while(val.find(
"\\n") != std::string::npos){
247 val.replace(val.find(
"\\n"),2,std::string(
"\n"));
249 item->
user[name] = val;
254 if(itToken == tokens.end()){