ju@15: ju@15: /************************* ju@15: * GraphList2dot Converter ju@15: * ju@15: * Autor: Julian Forster ju@15: * www.ProgMaschine.de.vu ju@15: * Autor: Markus Schnalke ju@15: * http://prog.marmaro.de ju@15: * ju@15: *************************/ meillo@0: meillo@0: #include meillo@0: #include meillo@0: meillo@0: using namespace std; meillo@0: ju@15: #define n 1000 //Size of Namelist ju@15: #define l 20 //MaxNameLength meillo@0: ju@15: //Inputfile meillo@0: ifstream inFile; meillo@0: ju@15: //Namelist meillo@0: char names [n][l]; meillo@0: meillo@0: void readUntil(char *untilText) { meillo@0: //cout << "readUntil" << endl; meillo@0: int i = 0; meillo@0: while (!inFile.eof()){ meillo@0: char cChar = inFile.get(); meillo@0: //cout << cChar; meillo@0: if (cChar == untilText[i]){ meillo@0: i++; meillo@0: if (i >= strlen(untilText)) return; meillo@0: } else { meillo@0: i = 0; meillo@0: } meillo@0: // cout << i; meillo@0: } meillo@0: //cout << "endReadUntil" << endl; meillo@0: } meillo@0: meillo@0: //Liest bis zum untilText, aber nicht weiter als bis zum lastText meillo@0: //wenn lastText vor untilText kommt wird bis dahin gelesen meillo@0: //und false zurückgegeben meillo@0: bool readUntil(char *untilText, char *lastText) { meillo@0: //cout << "readUntil" << endl; meillo@0: int i = 0; meillo@0: int ii = 0; meillo@0: while (!inFile.eof()){ meillo@0: char cChar = inFile.get(); meillo@0: //cout << cChar; meillo@0: if (cChar == untilText[i]){ meillo@0: i++; meillo@0: if (i >= strlen(untilText)) return true; meillo@0: } else { meillo@0: i = 0; meillo@0: } meillo@0: if (cChar == lastText[ii]){ meillo@0: ii++; meillo@0: if (ii >= strlen(lastText)) return false; meillo@0: } else { meillo@0: ii = 0; meillo@0: } meillo@0: // cout << i; meillo@0: } meillo@0: return false; meillo@0: //cout << "endReadUntil" << endl; meillo@0: } meillo@0: int getIndex(char * name) { meillo@0: for (int i = 0; i < n; i++) { meillo@0: for (int ii = 0; ii < l; ii++) { meillo@0: if (names[i][ii] != name[ii]) { meillo@0: break; meillo@0: } meillo@0: if (names[i][ii] == '\0') return i; meillo@0: } meillo@0: } meillo@0: return -1; meillo@0: } meillo@0: meillo@0: void readGraph(char *file) { ju@15: if (inFile.open(file)) { ju@15: //header ju@15: cout << "digraph G {" << endl; ju@15: cout << "size=\"25,22\";" << endl; ju@15: ju@15: int i = -1; ju@15: int mode = 0; //0: start, 1: read headbuddy, 2: no whitespace 3: read buddy ju@15: while (!inFile.eof()) { ju@15: //read one line ju@15: int ii = 0; ju@15: char line [10 + l]; ju@15: while (!inFile.eof()) { ju@15: char c = inFile.get(); ju@15: if (c == '\n') { ju@15: line[ii] = '\0'; ju@15: break; ju@15: } else { ju@15: line[ii] = c; ju@15: ii++; ju@15: } ju@15: } ju@15: cout << line << endl; ju@15: } ju@15: /* ju@15: if (!line[0] == '\0') { ju@15: if (line[0] == ' ') { ju@15: ju@15: int begin = 0; ju@15: char buddy[l]; ju@15: for (begin = 1; begin < 10 + l; begin++) { ju@15: if (line[begin] != ' ') { ju@15: break; ju@15: } ju@15: } ju@15: if (line[begin] != '\0') { ju@15: for (int j = begin; j < 10 + l; j++) { ju@15: if ((line[j] == ' ') || (line[j] == '\0')) { ju@15: buddy[j-begin] = '\0'; ju@15: break; ju@15: } else { ju@15: if (j >= l - 1) { ju@15: cerr << "name too long" << line << endl; ju@15: return; ju@15: } ju@15: buddy[j-begin] = line[j]; ju@15: } ju@15: } ju@15: //Add Buddy ju@15: ju@15: ju@15: } ju@15: } else { ju@15: i++; ju@15: for (int j = 0; j < 10 + l; j++) { ju@15: if ((line[j] == ' ') || (line[j] == '\0')) { ju@15: names[i][j] = '\0'; ju@15: break; ju@15: } else { ju@15: if (j >= l - 1) { ju@15: cerr << "name too long" << line << endl; ju@15: return; ju@15: } ju@15: names[i][j] = line[j]; ju@15: } ju@15: } ju@15: ju@15: } ju@15: ju@15: } ju@15: ju@15: ju@15: }*/ ju@15: ju@15: //footer ju@15: cout << "}" << endl; ju@15: } else { ju@15: cerr << "could not open " << file << endl; ju@15: } ju@15: ju@15: /* if (inFile) { meillo@0: int i = 0; meillo@0: while (!inFile.eof()){ meillo@0: readUntil("Profil von: "); meillo@0: for (int ii = 0; (ii < l) && !inFile.eof(); ii++) { meillo@0: char cChar = inFile.get(); meillo@0: if ((cChar == '\n') || (cChar == ' ')) { meillo@0: names[i][ii] = '\0'; meillo@0: break; meillo@0: } meillo@0: names[i][ii] = cChar; meillo@0: } meillo@0: // cout <<"#"<< names[i] <<"#"<< endl; meillo@0: i++; meillo@0: } meillo@0: inFile.close(); meillo@0: } meillo@0: meillo@0: inFile.open(file); meillo@0: if (inFile) { meillo@0: int i = 0; meillo@0: while (!inFile.eof()){ meillo@0: readUntil("Profil von: "); meillo@0: char name [l]; meillo@0: for (int ii = 0; (ii < l) && !inFile.eof(); ii++) { meillo@0: char cChar = inFile.get(); meillo@0: if ((cChar == '\n') || (cChar == ' ')) { meillo@0: name[ii] = '\0'; meillo@0: break; meillo@0: } meillo@0: name[ii] = cChar; meillo@0: } meillo@0: //Vertex suchen meillo@0: int index = getIndex(name); meillo@0: if (index > -1) { meillo@0: meillo@0: readUntil("Buddyliste:"); meillo@0: meillo@0: // cout <<"#buddylist von:#"<< names[index] <<"#"<< endl; meillo@0: meillo@0: while (readUntil("Nachricht schreiben ", "Bilder")) { meillo@0: char buddy [l]; meillo@0: //cout << endl; meillo@0: for (int ii = 0; (ii < l) && !inFile.eof(); ii++) { meillo@0: char cChar = inFile.get(); meillo@0: if ((cChar == '\n') || (cChar == ' ')) { meillo@0: buddy[ii] = '\0'; meillo@0: break; meillo@0: } meillo@0: buddy[ii] = cChar; meillo@0: } meillo@0: //Vertex suchen meillo@0: int indexB = getIndex(buddy); meillo@0: if (indexB > -1) { meillo@0: cout << " \"" << names[index] << "\" -> \"" << names[indexB] meillo@0: << "\";" << endl; meillo@0: } meillo@0: meillo@0: //cout <<"#buddy#"<< buddy <<"#"<< endl; meillo@0: } meillo@0: } meillo@0: i++; meillo@0: } meillo@0: inFile.close(); meillo@0: } ju@15: cout << "}" << endl;*/ meillo@0: } meillo@0: meillo@0: meillo@0: int main(int argc, char **argv){ meillo@0: if (argc == 2) { meillo@0: if (strcmp(argv[1], "--version") == 0) { meillo@2: cout << "Buddylistgrapher (C++)" << endl; meillo@2: cout << "======================" << endl; meillo@2: cout << "version 2.0" << endl; meillo@2: cout << endl; meillo@2: cout << "by Julian Forster (http://progmaschine.de.vu)" << endl; meillo@2: cout << "and a little bit by Markus Schnalke (http://prog.marmaro.de)" << endl; meillo@1: } else if (strcmp(argv[1], "--help") == 0) { meillo@2: cout << "Buddylistgrapher" << endl; meillo@2: cout << "================" << endl; meillo@2: cout << endl; meillo@1: cout << "usage: " << argv[0] << " " << endl; meillo@1: cout << endl; meillo@1: cout << "The grapher generates output to stdout." << endl; meillo@1: cout << "This output is the input for the graphviz tools." << endl; meillo@1: cout << endl; meillo@1: cout << "You can use it like this:" << endl; meillo@1: cout << argv[0] << " input.txt | dot -Tpng > pic.png" << endl; meillo@1: cout << endl; meillo@1: cout << "ToDo:" << endl; meillo@1: cout << "The program was written for one specific kind of input data," << endl; meillo@1: cout << "so there is still some work to do to use it for general input." << endl; meillo@0: } else { meillo@0: readGraph(argv[1]); meillo@0: } meillo@0: return 0; meillo@0: } meillo@0: cerr << "usage: " << argv[0] << " " << endl; meillo@0: return 1; meillo@0: } meillo@0: