aboutsummaryrefslogtreecommitdiff
path: root/src/tests/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/main.cc')
-rw-r--r--src/tests/main.cc142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/tests/main.cc b/src/tests/main.cc
new file mode 100644
index 0000000..1ffbfcd
--- /dev/null
+++ b/src/tests/main.cc
@@ -0,0 +1,142 @@
1// main.cc
2// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#include "../StringUtil.hh"
23
24#include <iostream>
25#include <fstream>
26#include <string>
27#include <vector>
28
29using namespace std;
30
31bool loadMenu(string filename);
32bool loadMenu2(string filename);
33
34void showError(int line, int pos, string& instr) {
35
36 cerr<<"Error on line: "<<line<<endl;
37 cerr<<instr<<endl;
38 for (int c=0; c<pos; c++) {
39 if (instr[c]=='\t')
40 cerr<<'\t';
41 else
42 cerr<<" ";
43 }
44 cerr<<"^ here"<<endl;
45
46}
47
48int main(int argc, char **argv) {
49 string filename = "menu";
50 if (argc>1)
51 filename = argv[1];
52 if (loadMenu2(filename))
53 cout<<"Load successfull"<<endl;
54 else
55 cout<<"Load failed"<<endl;
56
57/*
58 string out;
59 vector<string> stringlist;
60 stringlist.push_back(" \t\t\t \t[(in \\)\t haha )] \t\t ");
61 stringlist.push_back("(in\\)) {_ _ my_ _}");
62 stringlist.push_back("(in) {_ _ my_ _}");
63 stringlist.push_back("(in){_ _ my_ _}");
64 stringlist.push_back("\t \t \t ( in ) {haha}");
65 stringlist.push_back("\t \t \t (( in \\) ) {haha}");
66 stringlist.push_back("\t \t \t (( in \\) ){hihi}");
67 stringlist.push_back("\t \t \t (( in \\) )|{hihi}");
68 for (unsigned int i=0; i<stringlist.size(); i++) {
69 int pos = StringUtil::getStringBetween(out, stringlist[i].c_str(), '(', ')');
70 int total_pos = 0;
71 if (pos<0) {
72 showError(i+1, -pos, stringlist[i]);
73 continue;
74 }
75 cerr<<"string="<<stringlist[i]<<endl;
76 cerr<<"pos="<<pos<<" ::"<<out;
77 total_pos += pos;
78 pos = StringUtil::getStringBetween(out, stringlist[i].c_str()+total_pos, '{', '}');
79 if (pos<=0) {
80 pos=-pos;
81 showError(i+1, total_pos+pos, stringlist[i]);
82 continue;
83 }
84 cerr<<"::"<<out<<"::"<<endl;
85 total_pos += pos;
86 }
87*/
88 return 0;
89}
90
91
92
93bool loadMenu2(string filename) {
94
95 if (!filename.size())
96 return false;
97
98 ifstream menufile(filename.c_str());
99
100
101 if (menufile) {
102 string instr;
103 vector<string> args;
104 int line=0;
105 while (!menufile.eof()) {
106 //read a line
107 getline(menufile, instr);
108 line++;
109 string arg;
110 int pos = StringUtil::getStringBetween(arg, instr.c_str(), '[', ']');
111 if (pos<=0) {
112 showError(line, -pos, instr);
113 continue;
114 }
115
116 cerr<<"("<<line<<"):"<<arg<<"::";
117 int total_pos = pos;
118 pos = StringUtil::getStringBetween(arg, instr.c_str()+pos, '(', ')');
119 if (pos<=0) {
120 showError(line, total_pos+(-pos), instr);
121 continue;
122 }
123 cerr<<arg<<"::";
124
125 total_pos +=pos;
126 pos = StringUtil::getStringBetween(arg, instr.c_str()+total_pos, '{', '}');
127 if (pos<=0) {
128 total_pos = total_pos+(-pos);
129 showError(line, total_pos, instr);
130 continue;
131 }
132 cerr<<arg<<":"<<endl;
133
134 }
135
136
137 } else
138 return false;
139
140 return true;
141}
142