0
|
1
|
|
2 #include <iostream>
|
|
3 #include <fstream>
|
|
4
|
|
5 using namespace std;
|
|
6
|
|
7 #define n 1000
|
|
8 #define l 20
|
|
9
|
|
10 //Graph File
|
|
11 ifstream inFile;
|
|
12
|
|
13 char names [n][l];
|
|
14
|
|
15 void readUntil(char *untilText) {
|
|
16 //cout << "readUntil" << endl;
|
|
17 int i = 0;
|
|
18 while (!inFile.eof()){
|
|
19 char cChar = inFile.get();
|
|
20 //cout << cChar;
|
|
21 if (cChar == untilText[i]){
|
|
22 i++;
|
|
23 if (i >= strlen(untilText)) return;
|
|
24 } else {
|
|
25 i = 0;
|
|
26 }
|
|
27 // cout << i;
|
|
28 }
|
|
29 //cout << "endReadUntil" << endl;
|
|
30 }
|
|
31
|
|
32 //Liest bis zum untilText, aber nicht weiter als bis zum lastText
|
|
33 //wenn lastText vor untilText kommt wird bis dahin gelesen
|
|
34 //und false zurückgegeben
|
|
35 bool readUntil(char *untilText, char *lastText) {
|
|
36 //cout << "readUntil" << endl;
|
|
37 int i = 0;
|
|
38 int ii = 0;
|
|
39 while (!inFile.eof()){
|
|
40 char cChar = inFile.get();
|
|
41 //cout << cChar;
|
|
42 if (cChar == untilText[i]){
|
|
43 i++;
|
|
44 if (i >= strlen(untilText)) return true;
|
|
45 } else {
|
|
46 i = 0;
|
|
47 }
|
|
48 if (cChar == lastText[ii]){
|
|
49 ii++;
|
|
50 if (ii >= strlen(lastText)) return false;
|
|
51 } else {
|
|
52 ii = 0;
|
|
53 }
|
|
54 // cout << i;
|
|
55 }
|
|
56 return false;
|
|
57 //cout << "endReadUntil" << endl;
|
|
58 }
|
|
59 int getIndex(char * name) {
|
|
60 for (int i = 0; i < n; i++) {
|
|
61 for (int ii = 0; ii < l; ii++) {
|
|
62 if (names[i][ii] != name[ii]) {
|
|
63 break;
|
|
64 }
|
|
65 if (names[i][ii] == '\0') return i;
|
|
66 }
|
|
67 }
|
|
68 return -1;
|
|
69 }
|
|
70
|
|
71 void readGraph(char *file) {
|
|
72 inFile.open(file);
|
|
73 cout << "digraph G {" << endl;
|
|
74 cout << "size=\"25,22\";" << endl;
|
|
75 if (inFile) {
|
|
76 int i = 0;
|
|
77 while (!inFile.eof()){
|
|
78 readUntil("Profil von: ");
|
|
79 for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
|
|
80 char cChar = inFile.get();
|
|
81 if ((cChar == '\n') || (cChar == ' ')) {
|
|
82 names[i][ii] = '\0';
|
|
83 break;
|
|
84 }
|
|
85 names[i][ii] = cChar;
|
|
86 }
|
|
87 // cout <<"#"<< names[i] <<"#"<< endl;
|
|
88 i++;
|
|
89 }
|
|
90 inFile.close();
|
|
91 }
|
|
92
|
|
93 inFile.open(file);
|
|
94 if (inFile) {
|
|
95 int i = 0;
|
|
96 while (!inFile.eof()){
|
|
97 readUntil("Profil von: ");
|
|
98 char name [l];
|
|
99 for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
|
|
100 char cChar = inFile.get();
|
|
101 if ((cChar == '\n') || (cChar == ' ')) {
|
|
102 name[ii] = '\0';
|
|
103 break;
|
|
104 }
|
|
105 name[ii] = cChar;
|
|
106 }
|
|
107 //Vertex suchen
|
|
108 int index = getIndex(name);
|
|
109 if (index > -1) {
|
|
110
|
|
111 readUntil("Buddyliste:");
|
|
112
|
|
113 // cout <<"#buddylist von:#"<< names[index] <<"#"<< endl;
|
|
114
|
|
115 while (readUntil("Nachricht schreiben ", "Bilder")) {
|
|
116 char buddy [l];
|
|
117 //cout << endl;
|
|
118 for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
|
|
119 char cChar = inFile.get();
|
|
120 if ((cChar == '\n') || (cChar == ' ')) {
|
|
121 buddy[ii] = '\0';
|
|
122 break;
|
|
123 }
|
|
124 buddy[ii] = cChar;
|
|
125 }
|
|
126 //Vertex suchen
|
|
127 int indexB = getIndex(buddy);
|
|
128 if (indexB > -1) {
|
|
129 cout << " \"" << names[index] << "\" -> \"" << names[indexB]
|
|
130 << "\";" << endl;
|
|
131 }
|
|
132
|
|
133 //cout <<"#buddy#"<< buddy <<"#"<< endl;
|
|
134 }
|
|
135 }
|
|
136 i++;
|
|
137 }
|
|
138 inFile.close();
|
|
139 }
|
|
140 cout << "}" << endl;
|
|
141 }
|
|
142
|
|
143
|
|
144 int main(int argc, char **argv){
|
|
145 if (argc == 2) {
|
|
146 if (strcmp(argv[1], "--version") == 0) {
|
|
147 cout << "Buddylistgrapher 2.0" << endl;
|
|
148 cout << "====================" << endl;
|
|
149 cout << "by Julian Forster (and a little bit by Markus Schnalke)" << endl;
|
|
150 cout << "http://progmaschine.de.vu" << endl;
|
|
151 } else {
|
|
152 readGraph(argv[1]);
|
|
153 }
|
|
154 return 0;
|
|
155 }
|
|
156 cerr << "usage: " << argv[0] << " <input.txt>" << endl;
|
|
157 return 1;
|
|
158 }
|
|
159
|