fts2ftx.cppGo to the documentation of this file.00001 /** fts2ftx.cpp Utility to convert a faudes token stream to XML format. 00002 00003 This utility converts the std faudes token format, as generated e.g. by 00004 Write(), to the more rigourus XML format written by XWrite(). Regarding 00005 generators and alphabets, the former is considered the preferred format 00006 for human editable files, while the latter provides an interface to 00007 XML editors/processors and is the preferred format for configuration files. 00008 00009 In particular, fts2ftx can be used to convert pre 2.16b configuration 00010 files to the XML format scheduled for version 3.00. 00011 00012 Copyright (C) 2010 Thomas Moor 00013 00014 */ 00015 00016 00017 #include "fts2ftx.h" 00018 00019 using namespace faudes; 00020 00021 00022 // print usage info and exit 00023 void usage_exit(const std::string& message="") { 00024 if(message!="") { 00025 std::cout << "fts2ftx: " << message << std::endl; 00026 std::cout << "" << std::endl; 00027 exit(-1); 00028 } 00029 std::cout << "fts2ftx: version" << VersionString() << std::endl; 00030 std::cout << "" << std::endl; 00031 std::cout << "usage: fts2ftx [-t <ftype>] [-l <label>] [-o <outfile>] <infile>" << std::endl; 00032 std::cout << "where " << std::endl; 00033 std::cout << " <infile>: faudes token stream to convert" << std::endl; 00034 std::cout << "" << std::endl; 00035 std::cout << " -t <ftype>: faudes type of infile" << std::endl; 00036 std::cout << " -l <label>: section label to read (defaults to entire file)" << std::endl; 00037 std::cout << " -o <outfile>: file to write (defaults to infile with .ftx suffix)" << std::endl; 00038 std::cout << "" << std::endl; 00039 exit(-1); 00040 } 00041 00042 00043 00044 // process file 00045 int main(int argc, char *argv[]) { 00046 00047 00048 // parameters 00049 std::string mInFile; 00050 std::string mOutFile; 00051 std::string mType; 00052 std::string mLabel; 00053 int mVerify = 0; 00054 00055 // primitive commad line parsing 00056 for(int i=1; i<argc; i++) { 00057 std::string option(argv[i]); 00058 // option: -t 00059 if((option=="-t") || (option=="--ftype")) { 00060 i++; if(i>=argc) usage_exit(); 00061 mType=argv[i]; 00062 continue; 00063 } 00064 // option: -l 00065 if((option=="-l") || (option=="--lable")) { 00066 i++; if(i>=argc) usage_exit(); 00067 mLabel=argv[i]; 00068 continue; 00069 } 00070 // option: -o 00071 if((option=="-o") || (option=="--outfile")) { 00072 i++; if(i>=argc) usage_exit(); 00073 mOutFile=argv[i]; 00074 continue; 00075 } 00076 // option: -v 00077 if((option=="-v") || (option=="--verify")) { 00078 mVerify++; 00079 continue; 00080 } 00081 // option: -vv 00082 if(option=="-vv"){ 00083 mVerify+=2; 00084 continue; 00085 } 00086 // option: -vvv 00087 if(option=="-vvv"){ 00088 mVerify+=3; 00089 continue; 00090 } 00091 // option: help 00092 if((option=="-?") || (option=="--help")) { 00093 usage_exit(); 00094 continue; 00095 } 00096 // option: unknown 00097 if(option.c_str()[0]=='-') { 00098 usage_exit("unknown option "+ option); 00099 continue; 00100 } 00101 // input 00102 if(mInFile!="") 00103 usage_exit("more than one filname specified" ); 00104 mInFile=option; 00105 } 00106 00107 // very verbose: dump registry 00108 if(mVerify>2) { 00109 TypeRegistry::G()->Write(); 00110 } 00111 00112 // fix output file name 00113 std::string basename = ExtractFilename(mInFile); 00114 if(basename.find_last_of(".") !=std::string::npos) { 00115 basename.resize(basename.find_last_of(".")); 00116 } 00117 if(mOutFile=="") { 00118 mOutFile= basename+".ftx"; 00119 } 00120 00121 // read input file 00122 Type* fobject=NewFaudesObject(mType); 00123 fobject->Read(mInFile,mLabel); 00124 00125 // verify: report 00126 if(mVerify>2) { 00127 std::cout << "fts2ftx: reporting faudes object of type " << mType << " (id " << typeid(*fobject).name() << ")" << std::endl; 00128 fobject->Write(); 00129 } 00130 00131 // write output: console 00132 if(mOutFile=="-") { 00133 fobject->XWrite(); 00134 } 00135 00136 // write output: file 00137 if(mOutFile!="-") { 00138 fobject->XWrite(mOutFile); 00139 } 00140 00141 // verify: read back 00142 if(mOutFile!="-") 00143 if(mVerify>0) { 00144 std::cout << "fts2ftx: reading back ftx output" << std::endl; 00145 Type* readback = fobject->New(); 00146 readback->Read(mOutFile); 00147 if(!(*fobject==*readback)) 00148 std::cout << "fts2ftx: warning: objects dont match (!)" << std::endl; 00149 } 00150 00151 // done 00152 return 0; 00153 } libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |