10 |
#include <stdexcept> |
#include <stdexcept> |
11 |
#include <time.h> |
#include <time.h> |
12 |
#include <sys/time.h> |
#include <sys/time.h> |
13 |
|
#include <sys/types.h> |
14 |
|
#include <sys/wait.h> |
15 |
|
#include <errno.h> |
16 |
#include <stdlib.h> |
#include <stdlib.h> |
17 |
|
|
18 |
#include <cstring> |
#include <cstring> |
19 |
#include "util.h" |
#include "Util.h" |
20 |
|
|
21 |
using namespace std; |
using namespace std; |
22 |
|
|
149 |
return str; |
return str; |
150 |
} |
} |
151 |
|
|
152 |
|
|
153 |
|
vector<string> str_split(string input) |
154 |
|
{ |
155 |
|
string buf; |
156 |
|
stringstream ss(input); |
157 |
|
vector<string> tokens; |
158 |
|
while (ss >> buf) |
159 |
|
tokens.push_back(buf); |
160 |
|
return tokens; |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
vector<string> str_split(string input, string delimiter) |
vector<string> str_split(string input, string delimiter) |
165 |
{ |
{ |
166 |
vector<string> retval; |
vector<string> retval; |
183 |
return retval; |
return retval; |
184 |
} |
} |
185 |
|
|
186 |
char my_toupper(char ch) |
char danish_map[3][2] = { {198,230}, {216,248}, {197,229} }; // aelig, oslash, aring |
187 |
|
|
188 |
|
unsigned char my_toupper(unsigned char ch) |
189 |
{ |
{ |
190 |
if (ch == 'æ') |
if (ch == 230) |
191 |
return 'Æ'; |
return 198; |
192 |
if (ch == 'ø') |
if (ch == 248) |
193 |
return 'Ø'; |
return 216; |
194 |
if (ch == 'å') |
if (ch == 229) |
195 |
return 'Å'; |
return 197; |
196 |
|
|
197 |
return ::toupper(ch); |
return ::toupper(ch); |
198 |
} |
} |
199 |
|
|
200 |
char my_tolower(char ch) |
unsigned char my_tolower(unsigned char ch) |
201 |
{ |
{ |
202 |
if (ch == 'Æ') |
if (ch == 198) |
203 |
return 'æ'; |
return 230; |
204 |
if (ch == 'Ø') |
if (ch == 216) |
205 |
return 'ø'; |
return 248; |
206 |
if (ch == 'Å') |
if (ch == 197) |
207 |
return 'å'; |
return 229; |
208 |
|
|
209 |
return ::tolower(ch); |
return ::tolower(ch); |
210 |
} |
} |
240 |
string rep; |
string rep; |
241 |
rep.append(1,197); |
rep.append(1,197); |
242 |
str = str_replace(str, "Å", rep); |
str = str_replace(str, "Å", rep); |
243 |
|
str = str_replace(str, "Å", rep); |
244 |
|
|
245 |
rep.at(0) = 198; |
rep.at(0) = 198; |
246 |
str = str_replace(str, "Æ", rep); |
str = str_replace(str, "Æ", rep); |
247 |
|
str = str_replace(str, "Æ", rep); |
248 |
|
|
249 |
rep.at(0) = 216; |
rep.at(0) = 216; |
250 |
str = str_replace(str, "Ø", rep); |
str = str_replace(str, "Ø", rep); |
251 |
|
str = str_replace(str, "Ø", rep); |
252 |
|
|
253 |
|
|
254 |
rep.at(0) = 229; |
rep.at(0) = 229; |
255 |
str = str_replace(str, "å", rep); |
str = str_replace(str, "å", rep); |
256 |
|
str = str_replace(str, "å", rep); |
257 |
|
|
258 |
rep.at(0) = 230; |
rep.at(0) = 230; |
259 |
str = str_replace(str, "æ", rep); |
str = str_replace(str, "æ", rep); |
260 |
|
str = str_replace(str, "æ", rep); |
261 |
|
|
262 |
rep.at(0) = 248; |
rep.at(0) = 248; |
263 |
str = str_replace(str, "ø", rep); |
str = str_replace(str, "ø", rep); |
264 |
|
str = str_replace(str, "ø", rep); |
265 |
|
|
266 |
return str; |
return str; |
267 |
} |
} |
269 |
|
|
270 |
string str_gsm2latin(string str) |
string str_gsm2latin(string str) |
271 |
{ |
{ |
272 |
for (unsigned i=0; i<str.size(); i++) { |
for (unsigned i=0; i<str.size(); i++) |
273 |
|
{ |
274 |
str.at(i) = char_def_alphabet_decode(str.at(i)); |
str.at(i) = char_def_alphabet_decode(str.at(i)); |
275 |
} |
} |
276 |
return str; |
return str; |
278 |
|
|
279 |
string str_latin2gsm(string str) |
string str_latin2gsm(string str) |
280 |
{ |
{ |
281 |
for (unsigned i=0; i<str.size(); i++) { |
for (unsigned i=0; i<str.size(); i++) |
282 |
|
{ |
283 |
str.at(i) = char_def_alphabet_encode(str.at(i)); |
str.at(i) = char_def_alphabet_encode(str.at(i)); |
284 |
} |
} |
285 |
return str; |
return str; |
286 |
} |
} |
287 |
|
|
288 |
|
/* deprecated, use HttpClient instead |
289 |
string readUrl(string url, string tempfile) |
string readUrl(string url, string tempfile) |
290 |
{ |
{ |
291 |
char buf[128000]; |
char buf[128000]; |
320 |
unlink(tempfile.c_str()); |
unlink(tempfile.c_str()); |
321 |
|
|
322 |
return document; |
return document; |
323 |
} |
}*/ |
324 |
|
|
325 |
|
|
326 |
|
|
423 |
return (pclose(p)); |
return (pclose(p)); |
424 |
} |
} |
425 |
|
|
426 |
|
int my_system2 (const char *command) |
427 |
|
{ |
428 |
|
int pid, status; |
429 |
|
|
430 |
|
if (command == 0) |
431 |
|
return 1; |
432 |
|
// printf("forking ...\n"); |
433 |
|
pid = fork(); |
434 |
|
if (pid == -1) |
435 |
|
return -1; |
436 |
|
if (pid == 0) |
437 |
|
{ |
438 |
|
char *argv[4]; |
439 |
|
argv[0] = (char*) "sh"; |
440 |
|
argv[1] = (char*) "-c"; |
441 |
|
argv[2] = (char *) command; |
442 |
|
argv[3] = 0; |
443 |
|
// printf("chaining ...\n"); |
444 |
|
execve("/bin/sh", argv, environ); |
445 |
|
// printf("Chaining failed!\n"); |
446 |
|
exit(127); |
447 |
|
} |
448 |
|
do |
449 |
|
{ |
450 |
|
// printf("Waiting on PID: %d\n",pid); |
451 |
|
if (waitpid(pid, &status, 0) == -1) |
452 |
|
{ |
453 |
|
// printf("erc: %d\n",errno); |
454 |
|
if (errno != EINTR) |
455 |
|
return -1; |
456 |
|
} |
457 |
|
else |
458 |
|
{ |
459 |
|
// printf("status: %d\n",status); |
460 |
|
return status; |
461 |
|
} |
462 |
|
} |
463 |
|
while (1); |
464 |
|
} |
465 |
|
|
466 |
|
|
467 |
string readfile(string filename) |
string readfile(string filename) |
468 |
{ |
{ |
469 |
string str; |
string str; |
470 |
ifstream in(filename.c_str()); |
ifstream in(filename.c_str()); |
471 |
if (in) |
if (in) |
472 |
{ |
{ |
473 |
char buffer[2048]; |
char buffer[4096]; |
474 |
in.read(buffer, 2047); |
in.read(buffer, 4095); |
475 |
buffer[ in.gcount() ] = 0; |
buffer[ in.gcount() ] = 0; |
476 |
str = string(buffer); |
str = string(buffer); |
477 |
in.close(); |
in.close(); |
478 |
} |
} |
479 |
else |
else |
480 |
{ |
{ |
481 |
string message = "Could no open "; |
string message = "Could not open "; |
482 |
message += filename; |
message += filename; |
483 |
throw std::runtime_error(message); |
throw std::runtime_error(message); |
484 |
} |
} |