muSED_exe.cxx
Go to the documentation of this file.00001 #include "cxxtls/muSED.h"
00002 #include <cxxtls/file.h>
00003 #include <stdlib.h>
00004 #include <iostream>
00005 #include <fstream>
00006
00007 using namespace std;
00008 using namespace cxxtls;
00009 using namespace muSED;
00010
00011 static void readFile(string filename, list<string> &output)
00012 {
00013 ifstream f(filename.c_str());
00014
00015 string line;
00016
00017 int lines=0;
00018
00019 while(std::getline(f, line))
00020 {
00021 ++lines;
00022 output.push_back(line);
00023 }
00024
00025 if(lines == 0)
00026 {
00027 cerr << "Error: unable to read file " << filename << endl;
00028 exit(1);
00029 }
00030
00031 }
00032
00033 int main(int argc, char **argv)
00034 {
00035 cout << "muSED test program begins!\n" << endl;
00036
00037 if( argc != 3 )
00038 {
00039 cerr << "mused error: expected script name and file name on the command line" << endl;
00040 exit(1);
00041 }
00042
00043
00044 std::list<std::string> script;
00045
00046 readFile(argv[1], script);
00047
00048 int line;
00049
00050
00051 cout << "SCRIPT" << endl;
00052
00053 line=0;
00054 CXXTLS_FOREACH(std::string const &cur, script)
00055 {
00056 cout << " script data[" << ++line << "]=" << cur << endl;
00057 }
00058
00059
00060
00061 CompiledScript compiledScript(script);
00062
00063 if(!compiledScript.ok())
00064 {
00065 cout << "ERROR: SCRIPT COMPILATION FAILURE" << endl;
00066 cout << " ERROR = " << compiledScript.error() << endl;
00067 exit(1);
00068 }
00069
00070
00071 std::list<std::string> document;
00072
00073 readFile(argv[2], document);
00074
00075 cout << "INPUT DOCUMENT" << endl;
00076
00077 line=0;
00078 CXXTLS_FOREACH(std::string const &cur, document)
00079 {
00080 cout << " input data[" << ++line << "]=" << cur << endl;
00081 }
00082
00083 std::list<std::string> output;
00084
00085
00086 std::string error =apply(compiledScript, document, output);
00087
00088 if(!error.empty())
00089 {
00090 cout << "ERROR: EXECUTION FAILED! " << error << endl;
00091 exit(1);
00092 }
00093
00094 cout << "CONVERTED OUTPUT" << endl;
00095
00096
00097 line=0;
00098 CXXTLS_FOREACH(std::string const &cur, output)
00099 {
00100 cout << " output data[" << ++line << "]=" << cur << endl;
00101 }
00102
00103 cout << "muSED test program ENDS" << endl;
00104
00105 exit(0);
00106 }