buddylistgrapher

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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/graph.cpp	Mon May 28 17:41:28 2007 +0200
     1.3 @@ -0,0 +1,159 @@
     1.4 +
     1.5 +#include <iostream> 
     1.6 +#include <fstream>
     1.7 +
     1.8 +using namespace std;
     1.9 +
    1.10 +#define n 1000
    1.11 +#define l 20
    1.12 +
    1.13 +//Graph File
    1.14 +ifstream inFile;
    1.15 +
    1.16 +char names [n][l];
    1.17 +
    1.18 +void readUntil(char *untilText) {
    1.19 +    //cout << "readUntil" << endl;
    1.20 +    int i = 0;
    1.21 +    while (!inFile.eof()){
    1.22 +        char cChar = inFile.get();
    1.23 +        //cout << cChar;
    1.24 +        if (cChar == untilText[i]){
    1.25 +            i++;
    1.26 +            if (i >= strlen(untilText)) return;
    1.27 +        } else {
    1.28 +            i = 0;
    1.29 +        }
    1.30 +       // cout << i;
    1.31 +    }
    1.32 +    //cout << "endReadUntil" << endl;
    1.33 +}
    1.34 +
    1.35 +//Liest bis zum untilText, aber nicht weiter als bis zum lastText
    1.36 +//wenn lastText vor untilText kommt wird bis dahin gelesen 
    1.37 +//und false zurückgegeben
    1.38 +bool readUntil(char *untilText, char *lastText) {
    1.39 +    //cout << "readUntil" << endl;
    1.40 +    int i = 0;
    1.41 +    int ii = 0;
    1.42 +    while (!inFile.eof()){
    1.43 +        char cChar = inFile.get();
    1.44 +        //cout << cChar;
    1.45 +        if (cChar == untilText[i]){
    1.46 +            i++;
    1.47 +            if (i >= strlen(untilText)) return true;
    1.48 +        } else {
    1.49 +            i = 0;
    1.50 +        }
    1.51 +        if (cChar == lastText[ii]){
    1.52 +            ii++;
    1.53 +            if (ii >= strlen(lastText)) return false;
    1.54 +        } else {
    1.55 +            ii = 0;
    1.56 +        }
    1.57 +       // cout << i;
    1.58 +    }
    1.59 +    return false;
    1.60 +    //cout << "endReadUntil" << endl;
    1.61 +}
    1.62 +int getIndex(char * name) {
    1.63 +    for (int i = 0; i < n; i++) {
    1.64 +        for (int ii = 0; ii < l; ii++) {
    1.65 +            if (names[i][ii] != name[ii]) {
    1.66 +                break;
    1.67 +            }
    1.68 +            if (names[i][ii] == '\0') return i;
    1.69 +        }
    1.70 +    }
    1.71 +    return -1;
    1.72 +}
    1.73 +
    1.74 +void readGraph(char *file) {
    1.75 +    inFile.open(file);
    1.76 +    cout << "digraph G {" << endl;
    1.77 +    cout << "size=\"25,22\";" << endl;
    1.78 +    if (inFile) {
    1.79 +        int i = 0;
    1.80 +        while (!inFile.eof()){
    1.81 +            readUntil("Profil von: ");
    1.82 +            for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
    1.83 +                char cChar = inFile.get();
    1.84 +                if ((cChar == '\n') || (cChar == ' ')) {
    1.85 +                    names[i][ii] = '\0';
    1.86 +                    break;
    1.87 +                }
    1.88 +                names[i][ii] = cChar;
    1.89 +            }
    1.90 +    //        cout <<"#"<< names[i] <<"#"<< endl;
    1.91 +            i++;
    1.92 +        }
    1.93 +        inFile.close();        
    1.94 +    }
    1.95 +    
    1.96 +    inFile.open(file);
    1.97 +    if (inFile) {
    1.98 +        int i = 0;
    1.99 +        while (!inFile.eof()){
   1.100 +            readUntil("Profil von: ");
   1.101 +            char name [l];
   1.102 +            for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
   1.103 +                char cChar = inFile.get();
   1.104 +                if ((cChar == '\n') || (cChar == ' ')) {
   1.105 +                    name[ii] = '\0';
   1.106 +                    break;
   1.107 +                }
   1.108 +                name[ii] = cChar;
   1.109 +            }
   1.110 +            //Vertex suchen
   1.111 +            int index = getIndex(name);
   1.112 +            if (index > -1) {
   1.113 +            
   1.114 +            readUntil("Buddyliste:");
   1.115 +            
   1.116 +           //     cout <<"#buddylist von:#"<< names[index] <<"#"<< endl;
   1.117 +                  
   1.118 +                while (readUntil("Nachricht schreiben ", "Bilder")) {
   1.119 +                    char buddy [l];
   1.120 +                    //cout << endl;
   1.121 +                    for (int ii = 0; (ii < l) && !inFile.eof(); ii++) {
   1.122 +                        char cChar = inFile.get();
   1.123 +                        if ((cChar == '\n') || (cChar == ' ')) {
   1.124 +                            buddy[ii] = '\0';
   1.125 +                            break;
   1.126 +                        }
   1.127 +                        buddy[ii] = cChar;
   1.128 +                    }
   1.129 +                    //Vertex suchen
   1.130 +                    int indexB = getIndex(buddy);
   1.131 +                    if (indexB > -1) {
   1.132 +                        cout << "  \"" << names[index] << "\" -> \"" << names[indexB]
   1.133 +                                << "\";" << endl;
   1.134 +                    }
   1.135 +                    
   1.136 +                    //cout <<"#buddy#"<< buddy <<"#"<< endl;
   1.137 +                }
   1.138 +            }
   1.139 +            i++;
   1.140 +        }
   1.141 +        inFile.close();        
   1.142 +    } 
   1.143 +    cout << "}" << endl;
   1.144 +}
   1.145 +
   1.146 +
   1.147 +int main(int argc, char **argv){
   1.148 +    if (argc == 2) {
   1.149 +        if (strcmp(argv[1], "--version") == 0) {
   1.150 +          cout << "Buddylistgrapher 2.0" << endl;
   1.151 +          cout << "====================" << endl;
   1.152 +          cout << "by Julian Forster (and a little bit by Markus Schnalke)" << endl;
   1.153 +          cout << "http://progmaschine.de.vu" << endl;
   1.154 +        } else {
   1.155 +          readGraph(argv[1]); 
   1.156 +        }
   1.157 +        return 0;
   1.158 +    }
   1.159 +    cerr << "usage: " << argv[0] << " <input.txt>" << endl;
   1.160 +    return 1;
   1.161 +}
   1.162 +