diff graph.cpp @ 0:21d9547ef242

initial commit C++ and sh editions work similar
author meillo@marmaro.de
date Mon, 28 May 2007 17:41:28 +0200
parents
children 8d8b41f7c0bc
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graph.cpp	Mon May 28 17:41:28 2007 +0200
@@ -0,0 +1,159 @@
+
+#include <iostream> 
+#include <fstream>
+
+using namespace std;
+
+#define n 1000
+#define l 20
+
+//Graph File
+ifstream inFile;
+
+char names [n][l];
+
+void readUntil(char *untilText) {
+    //cout << "readUntil" << endl;
+    int i = 0;
+    while (!inFile.eof()){
+        char cChar = inFile.get();
+        //cout << cChar;
+        if (cChar == untilText[i]){
+            i++;
+            if (i >= strlen(untilText)) return;
+        } else {
+            i = 0;
+        }
+       // cout << i;
+    }
+    //cout << "endReadUntil" << endl;
+}
+
+//Liest bis zum untilText, aber nicht weiter als bis zum lastText
+//wenn lastText vor untilText kommt wird bis dahin gelesen 
+//und false zurückgegeben
+bool readUntil(char *untilText, char *lastText) {
+    //cout << "readUntil" << endl;
+    int i = 0;
+    int ii = 0;
+    while (!inFile.eof()){
+        char cChar = inFile.get();
+        //cout << cChar;
+        if (cChar == untilText[i]){
+            i++;
+            if (i >= strlen(untilText)) return true;
+        } else {
+            i = 0;
+        }
+        if (cChar == lastText[ii]){
+            ii++;
+            if (ii >= strlen(lastText)) return false;
+        } else {
+            ii = 0;
+        }
+       // cout << i;
+    }
+    return false;
+    //cout << "endReadUntil" << endl;
+}
+int getIndex(char * name) {
+    for (int i = 0; i < n; i++) {
+        for (int ii = 0; ii < l; ii++) {
+            if (names[i][ii] != name[ii]) {
+                break;
+            }
+            if (names[i][ii] == '\0') return i;
+        }
+    }
+    return -1;
+}
+
+void readGraph(char *file) {
+    inFile.open(file);
+    cout << "digraph G {" << endl;
+    cout << "size=\"25,22\";" << endl;
+    if (inFile) {
+        int i = 0;
+        while (!inFile.eof()){
+            readUntil("Profil von: ");
+            for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
+                char cChar = inFile.get();
+                if ((cChar == '\n') || (cChar == ' ')) {
+                    names[i][ii] = '\0';
+                    break;
+                }
+                names[i][ii] = cChar;
+            }
+    //        cout <<"#"<< names[i] <<"#"<< endl;
+            i++;
+        }
+        inFile.close();        
+    }
+    
+    inFile.open(file);
+    if (inFile) {
+        int i = 0;
+        while (!inFile.eof()){
+            readUntil("Profil von: ");
+            char name [l];
+            for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
+                char cChar = inFile.get();
+                if ((cChar == '\n') || (cChar == ' ')) {
+                    name[ii] = '\0';
+                    break;
+                }
+                name[ii] = cChar;
+            }
+            //Vertex suchen
+            int index = getIndex(name);
+            if (index > -1) {
+            
+            readUntil("Buddyliste:");
+            
+           //     cout <<"#buddylist von:#"<< names[index] <<"#"<< endl;
+                  
+                while (readUntil("Nachricht schreiben ", "Bilder")) {
+                    char buddy [l];
+                    //cout << endl;
+                    for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
+                        char cChar = inFile.get();
+                        if ((cChar == '\n') || (cChar == ' ')) {
+                            buddy[ii] = '\0';
+                            break;
+                        }
+                        buddy[ii] = cChar;
+                    }
+                    //Vertex suchen
+                    int indexB = getIndex(buddy);
+                    if (indexB > -1) {
+                        cout << "  \"" << names[index] << "\" -> \"" << names[indexB]
+                                << "\";" << endl;
+                    }
+                    
+                    //cout <<"#buddy#"<< buddy <<"#"<< endl;
+                }
+            }
+            i++;
+        }
+        inFile.close();        
+    } 
+    cout << "}" << endl;
+}
+
+
+int main(int argc, char **argv){
+    if (argc == 2) {
+        if (strcmp(argv[1], "--version") == 0) {
+          cout << "Buddylistgrapher 2.0" << endl;
+          cout << "====================" << endl;
+          cout << "by Julian Forster (and a little bit by Markus Schnalke)" << endl;
+          cout << "http://progmaschine.de.vu" << endl;
+        } else {
+          readGraph(argv[1]); 
+        }
+        return 0;
+    }
+    cerr << "usage: " << argv[0] << " <input.txt>" << endl;
+    return 1;
+}
+