Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

main.cc

Go to the documentation of this file.
00001 /* ===========================================================================
00002  *        Filename:  main.cc
00003  *     Description:  Main program for the xml diff demo app
00004  * 
00005  *         Version:  $Rev: 6 $
00006  *         Changed:  $Date: 2005-05-10 15:55:44 -0700 (Di, 10 Mai 2005) $
00007  *         Licence:  GPL (read COPYING file for details)
00008  * 
00009  *          Author:  Erich Schubert (eS), erich@debian.org
00010  *                   Institut für Informatik, LMU München
00011  * ======================================================================== */
00012 #include <iostream>
00013 #include "doc.h"
00014 #include "diff.h"
00015 #include "out_xupdate.h"
00016 #include "out_marked.h"
00017 #include "out_merged.h"
00018 
00019 #include "getopt.h"
00020 
00021 using namespace SSD;
00022 
00023 //#define DEFAULT_PATH BAD_CAST ".//*|.//text()"
00024 //#define DEFAULT_PATH BAD_CAST ".//*|./text()"
00025 #define DEFAULT_PATH "./node() | ./*/*"
00026 //#define DEFAULT_PATH BAD_CAST "./*|./text()"
00027 //#define DEFAULT_PATH BAD_CAST ".//*|.//text()|following-sibling::*"
00028 //#define DEFAULT_PATH BAD_CAST "./following-sibling::*"
00029 
00030 void usage(char* progname) {
00031         cerr << "Usage: " << endl;
00032         cerr << "  " << progname <<
00033 #ifdef TRACING_ENABLED
00034                 " [-t trace.dat]" <<
00035 #endif
00036                 " [-p xpath] [-w] document1.xml document2.xml" << endl;
00037 #ifdef TRACING_ENABLED
00038         cerr << "    -t trace.dat        Dump search information for analysis" << endl;
00039 #endif
00040         cerr << "    -w                  Process whitespace" << endl;
00041         cerr << "    -m                  Use 'merged' output format" << endl;
00042         cerr << "    -a                  Use 'marked' output format" << endl;
00043         cerr << "    -u                  Use 'xupdate' output format" << endl;
00044         cerr << "    -f                  Use fast mode (approximative)" << endl;
00045         cerr << "    -p xpath            Use a different xpath statement for structure" << endl;
00046         cerr << "    -p './/node()'      Use descendant relation" << endl;
00047         cerr << "    -p './node()'       Use child relation" << endl;
00048 }
00049 
00050 int main(int argc, char** argv) {
00051         Doc             doc1;
00052         Doc             doc2;
00053 
00054         int output = 0;
00055         char* xpath = DEFAULT_PATH;
00056 
00057         int option_char;
00058         while (1) {
00059                 option_char = getopt(argc, argv, "famuwt:p:");
00060                 if (option_char < 0) break;
00061                 switch (option_char) {
00062 #ifdef TRACING_ENABLED
00063                         case 't': DiffDijkstra::setSearchTreeOutput(optarg); break;
00064 #endif
00065                         case 'p': xpath = optarg; break;
00066                         case 'w': Doc::useWhitespace = true; break;
00067                         case 'u': output = 0; break;
00068                         case 'm': output = 1; break;
00069                         case 'a': output = 2; break;
00070                         case 'f': DiffDijkstra::fastApproximativeMode = true; break;
00071                         case '?':
00072                                 usage(argv[0]);
00073                                 return(0);
00074                                 break;
00075                 }
00076         }
00077 
00078         if (argc - optind != 2) {
00079                 usage(argv[0]);
00080                 return(0);
00081         }
00082 
00083         if (!doc1.loadXML(argv[optind])) {
00084                 std::cerr << "Could not load: " << argv[1] << "." << std::endl;
00085                 return(1);
00086         }
00087         if (!doc2.loadXML(argv[optind + 1])) {
00088                 std::cerr << "Could not load: " << argv[2] << "." << std::endl;
00089                 return(1);
00090         }
00091         doc1.processXPath(xpath);
00092         doc2.processXPath(xpath);
00093 
00094         DiffDijkstra    diff(doc1,doc2);
00095 
00096         // RelCount::dumpIndex(cout); cout << endl;
00097 
00098         diff.run();
00099 
00100         if (!diff.result) throw "Did not get a result, something is wrong.\n";
00101 
00102         switch (output) {
00103         case 0:
00104                 {
00105                         XUpdateWriter   out;
00106                         out.run(doc1, doc2, diff);
00107                         out.dump();
00108                 };
00109                 break;
00110         case 1:
00111                 {
00112                         MergedWriter    out;
00113                         out.run(doc1, doc2, diff);
00114                         out.dump();
00115                 };
00116                 break;
00117         case 2:
00118                 {
00119                         MarkedWriter    out;
00120                         out.run(doc1, doc2, diff);
00121                         out.dump();
00122                 };
00123                 break;
00124         }
00125 
00126         return 0;
00127 }
00128 /* vim:set noet sw=4 ts=4: */

Generated on Thu Aug 4 17:57:12 2005 for SSDDiff by  doxygen 1.4.3-20050530