rev |
line source |
ju@15
|
1
|
ju@15
|
2 /*************************
|
ju@15
|
3 * GraphList2dot Converter
|
ju@15
|
4 *
|
ju@15
|
5 * Autor: Julian Forster
|
ju@15
|
6 * www.ProgMaschine.de.vu
|
ju@15
|
7 * Autor: Markus Schnalke
|
ju@15
|
8 * http://prog.marmaro.de
|
ju@15
|
9 *
|
ju@15
|
10 *************************/
|
meillo@0
|
11
|
meillo@0
|
12 #include <iostream>
|
meillo@0
|
13 #include <fstream>
|
meillo@0
|
14
|
meillo@0
|
15 using namespace std;
|
meillo@0
|
16
|
ju@15
|
17 #define n 1000 //Size of Namelist
|
ju@15
|
18 #define l 20 //MaxNameLength
|
meillo@0
|
19
|
ju@15
|
20 //Inputfile
|
meillo@0
|
21 ifstream inFile;
|
meillo@0
|
22
|
ju@15
|
23 //Namelist
|
meillo@0
|
24 char names [n][l];
|
meillo@0
|
25
|
meillo@0
|
26 void readUntil(char *untilText) {
|
meillo@0
|
27 //cout << "readUntil" << endl;
|
meillo@0
|
28 int i = 0;
|
meillo@0
|
29 while (!inFile.eof()){
|
meillo@0
|
30 char cChar = inFile.get();
|
meillo@0
|
31 //cout << cChar;
|
meillo@0
|
32 if (cChar == untilText[i]){
|
meillo@0
|
33 i++;
|
meillo@0
|
34 if (i >= strlen(untilText)) return;
|
meillo@0
|
35 } else {
|
meillo@0
|
36 i = 0;
|
meillo@0
|
37 }
|
meillo@0
|
38 // cout << i;
|
meillo@0
|
39 }
|
meillo@0
|
40 //cout << "endReadUntil" << endl;
|
meillo@0
|
41 }
|
meillo@0
|
42
|
meillo@0
|
43 //Liest bis zum untilText, aber nicht weiter als bis zum lastText
|
meillo@0
|
44 //wenn lastText vor untilText kommt wird bis dahin gelesen
|
meillo@0
|
45 //und false zurückgegeben
|
meillo@0
|
46 bool readUntil(char *untilText, char *lastText) {
|
meillo@0
|
47 //cout << "readUntil" << endl;
|
meillo@0
|
48 int i = 0;
|
meillo@0
|
49 int ii = 0;
|
meillo@0
|
50 while (!inFile.eof()){
|
meillo@0
|
51 char cChar = inFile.get();
|
meillo@0
|
52 //cout << cChar;
|
meillo@0
|
53 if (cChar == untilText[i]){
|
meillo@0
|
54 i++;
|
meillo@0
|
55 if (i >= strlen(untilText)) return true;
|
meillo@0
|
56 } else {
|
meillo@0
|
57 i = 0;
|
meillo@0
|
58 }
|
meillo@0
|
59 if (cChar == lastText[ii]){
|
meillo@0
|
60 ii++;
|
meillo@0
|
61 if (ii >= strlen(lastText)) return false;
|
meillo@0
|
62 } else {
|
meillo@0
|
63 ii = 0;
|
meillo@0
|
64 }
|
meillo@0
|
65 // cout << i;
|
meillo@0
|
66 }
|
meillo@0
|
67 return false;
|
meillo@0
|
68 //cout << "endReadUntil" << endl;
|
meillo@0
|
69 }
|
meillo@0
|
70 int getIndex(char * name) {
|
meillo@0
|
71 for (int i = 0; i < n; i++) {
|
meillo@0
|
72 for (int ii = 0; ii < l; ii++) {
|
meillo@0
|
73 if (names[i][ii] != name[ii]) {
|
meillo@0
|
74 break;
|
meillo@0
|
75 }
|
meillo@0
|
76 if (names[i][ii] == '\0') return i;
|
meillo@0
|
77 }
|
meillo@0
|
78 }
|
meillo@0
|
79 return -1;
|
meillo@0
|
80 }
|
meillo@0
|
81
|
meillo@0
|
82 void readGraph(char *file) {
|
ju@15
|
83 if (inFile.open(file)) {
|
ju@15
|
84 //header
|
ju@15
|
85 cout << "digraph G {" << endl;
|
ju@15
|
86 cout << "size=\"25,22\";" << endl;
|
ju@15
|
87
|
ju@15
|
88 int i = -1;
|
ju@15
|
89 int mode = 0; //0: start, 1: read headbuddy, 2: no whitespace 3: read buddy
|
ju@15
|
90 while (!inFile.eof()) {
|
ju@15
|
91 //read one line
|
ju@15
|
92 int ii = 0;
|
ju@15
|
93 char line [10 + l];
|
ju@15
|
94 while (!inFile.eof()) {
|
ju@15
|
95 char c = inFile.get();
|
ju@15
|
96 if (c == '\n') {
|
ju@15
|
97 line[ii] = '\0';
|
ju@15
|
98 break;
|
ju@15
|
99 } else {
|
ju@15
|
100 line[ii] = c;
|
ju@15
|
101 ii++;
|
ju@15
|
102 }
|
ju@15
|
103 }
|
ju@15
|
104 cout << line << endl;
|
ju@15
|
105 }
|
ju@15
|
106 /*
|
ju@15
|
107 if (!line[0] == '\0') {
|
ju@15
|
108 if (line[0] == ' ') {
|
ju@15
|
109
|
ju@15
|
110 int begin = 0;
|
ju@15
|
111 char buddy[l];
|
ju@15
|
112 for (begin = 1; begin < 10 + l; begin++) {
|
ju@15
|
113 if (line[begin] != ' ') {
|
ju@15
|
114 break;
|
ju@15
|
115 }
|
ju@15
|
116 }
|
ju@15
|
117 if (line[begin] != '\0') {
|
ju@15
|
118 for (int j = begin; j < 10 + l; j++) {
|
ju@15
|
119 if ((line[j] == ' ') || (line[j] == '\0')) {
|
ju@15
|
120 buddy[j-begin] = '\0';
|
ju@15
|
121 break;
|
ju@15
|
122 } else {
|
ju@15
|
123 if (j >= l - 1) {
|
ju@15
|
124 cerr << "name too long" << line << endl;
|
ju@15
|
125 return;
|
ju@15
|
126 }
|
ju@15
|
127 buddy[j-begin] = line[j];
|
ju@15
|
128 }
|
ju@15
|
129 }
|
ju@15
|
130 //Add Buddy
|
ju@15
|
131
|
ju@15
|
132
|
ju@15
|
133 }
|
ju@15
|
134 } else {
|
ju@15
|
135 i++;
|
ju@15
|
136 for (int j = 0; j < 10 + l; j++) {
|
ju@15
|
137 if ((line[j] == ' ') || (line[j] == '\0')) {
|
ju@15
|
138 names[i][j] = '\0';
|
ju@15
|
139 break;
|
ju@15
|
140 } else {
|
ju@15
|
141 if (j >= l - 1) {
|
ju@15
|
142 cerr << "name too long" << line << endl;
|
ju@15
|
143 return;
|
ju@15
|
144 }
|
ju@15
|
145 names[i][j] = line[j];
|
ju@15
|
146 }
|
ju@15
|
147 }
|
ju@15
|
148
|
ju@15
|
149 }
|
ju@15
|
150
|
ju@15
|
151 }
|
ju@15
|
152
|
ju@15
|
153
|
ju@15
|
154 }*/
|
ju@15
|
155
|
ju@15
|
156 //footer
|
ju@15
|
157 cout << "}" << endl;
|
ju@15
|
158 } else {
|
ju@15
|
159 cerr << "could not open " << file << endl;
|
ju@15
|
160 }
|
ju@15
|
161
|
ju@15
|
162 /* if (inFile) {
|
meillo@0
|
163 int i = 0;
|
meillo@0
|
164 while (!inFile.eof()){
|
meillo@0
|
165 readUntil("Profil von: ");
|
meillo@0
|
166 for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
|
meillo@0
|
167 char cChar = inFile.get();
|
meillo@0
|
168 if ((cChar == '\n') || (cChar == ' ')) {
|
meillo@0
|
169 names[i][ii] = '\0';
|
meillo@0
|
170 break;
|
meillo@0
|
171 }
|
meillo@0
|
172 names[i][ii] = cChar;
|
meillo@0
|
173 }
|
meillo@0
|
174 // cout <<"#"<< names[i] <<"#"<< endl;
|
meillo@0
|
175 i++;
|
meillo@0
|
176 }
|
meillo@0
|
177 inFile.close();
|
meillo@0
|
178 }
|
meillo@0
|
179
|
meillo@0
|
180 inFile.open(file);
|
meillo@0
|
181 if (inFile) {
|
meillo@0
|
182 int i = 0;
|
meillo@0
|
183 while (!inFile.eof()){
|
meillo@0
|
184 readUntil("Profil von: ");
|
meillo@0
|
185 char name [l];
|
meillo@0
|
186 for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
|
meillo@0
|
187 char cChar = inFile.get();
|
meillo@0
|
188 if ((cChar == '\n') || (cChar == ' ')) {
|
meillo@0
|
189 name[ii] = '\0';
|
meillo@0
|
190 break;
|
meillo@0
|
191 }
|
meillo@0
|
192 name[ii] = cChar;
|
meillo@0
|
193 }
|
meillo@0
|
194 //Vertex suchen
|
meillo@0
|
195 int index = getIndex(name);
|
meillo@0
|
196 if (index > -1) {
|
meillo@0
|
197
|
meillo@0
|
198 readUntil("Buddyliste:");
|
meillo@0
|
199
|
meillo@0
|
200 // cout <<"#buddylist von:#"<< names[index] <<"#"<< endl;
|
meillo@0
|
201
|
meillo@0
|
202 while (readUntil("Nachricht schreiben ", "Bilder")) {
|
meillo@0
|
203 char buddy [l];
|
meillo@0
|
204 //cout << endl;
|
meillo@0
|
205 for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
|
meillo@0
|
206 char cChar = inFile.get();
|
meillo@0
|
207 if ((cChar == '\n') || (cChar == ' ')) {
|
meillo@0
|
208 buddy[ii] = '\0';
|
meillo@0
|
209 break;
|
meillo@0
|
210 }
|
meillo@0
|
211 buddy[ii] = cChar;
|
meillo@0
|
212 }
|
meillo@0
|
213 //Vertex suchen
|
meillo@0
|
214 int indexB = getIndex(buddy);
|
meillo@0
|
215 if (indexB > -1) {
|
meillo@0
|
216 cout << " \"" << names[index] << "\" -> \"" << names[indexB]
|
meillo@0
|
217 << "\";" << endl;
|
meillo@0
|
218 }
|
meillo@0
|
219
|
meillo@0
|
220 //cout <<"#buddy#"<< buddy <<"#"<< endl;
|
meillo@0
|
221 }
|
meillo@0
|
222 }
|
meillo@0
|
223 i++;
|
meillo@0
|
224 }
|
meillo@0
|
225 inFile.close();
|
meillo@0
|
226 }
|
ju@15
|
227 cout << "}" << endl;*/
|
meillo@0
|
228 }
|
meillo@0
|
229
|
meillo@0
|
230
|
meillo@0
|
231 int main(int argc, char **argv){
|
meillo@0
|
232 if (argc == 2) {
|
meillo@0
|
233 if (strcmp(argv[1], "--version") == 0) {
|
meillo@2
|
234 cout << "Buddylistgrapher (C++)" << endl;
|
meillo@2
|
235 cout << "======================" << endl;
|
meillo@2
|
236 cout << "version 2.0" << endl;
|
meillo@2
|
237 cout << endl;
|
meillo@2
|
238 cout << "by Julian Forster (http://progmaschine.de.vu)" << endl;
|
meillo@2
|
239 cout << "and a little bit by Markus Schnalke (http://prog.marmaro.de)" << endl;
|
meillo@1
|
240 } else if (strcmp(argv[1], "--help") == 0) {
|
meillo@2
|
241 cout << "Buddylistgrapher" << endl;
|
meillo@2
|
242 cout << "================" << endl;
|
meillo@2
|
243 cout << endl;
|
meillo@1
|
244 cout << "usage: " << argv[0] << " <input.txt>" << endl;
|
meillo@1
|
245 cout << endl;
|
meillo@1
|
246 cout << "The grapher generates output to stdout." << endl;
|
meillo@1
|
247 cout << "This output is the input for the graphviz tools." << endl;
|
meillo@1
|
248 cout << endl;
|
meillo@1
|
249 cout << "You can use it like this:" << endl;
|
meillo@1
|
250 cout << argv[0] << " input.txt | dot -Tpng > pic.png" << endl;
|
meillo@1
|
251 cout << endl;
|
meillo@1
|
252 cout << "ToDo:" << endl;
|
meillo@1
|
253 cout << "The program was written for one specific kind of input data," << endl;
|
meillo@1
|
254 cout << "so there is still some work to do to use it for general input." << endl;
|
meillo@0
|
255 } else {
|
meillo@0
|
256 readGraph(argv[1]);
|
meillo@0
|
257 }
|
meillo@0
|
258 return 0;
|
meillo@0
|
259 }
|
meillo@0
|
260 cerr << "usage: " << argv[0] << " <input.txt>" << endl;
|
meillo@0
|
261 return 1;
|
meillo@0
|
262 }
|
meillo@0
|
263
|