fts2ftx.cpp
Go to the documentation of this file.
1/** fts2ftx.cpp Utility to convert a faudes token stream to XML format.
2
3This utility converts the std faudes token format, as generated e.g. by
4Write(), to the more rigourus XML format written by XWrite(). Regarding
5generators and alphabets, the former is considered the preferred format
6for human editable files, while the latter provides an interface to
7XML editors/processors and is the preferred format for configuration files.
8
9In particular, fts2ftx can be used to convert pre 2.16b configuration
10files to the XML format scheduled for version 3.00.
11
12Copyright (C) 2010 Thomas Moor
13
14*/
15
16#include "corefaudes.h"
17
18using namespace faudes;
19
20
21// print usage info and exit
22void usage_exit(const std::string& message="") {
23 if(message!="") {
24 std::cout << "fts2ftx: " << message << std::endl;
25 std::cout << "" << std::endl;
26 exit(-1);
27 }
28 std::cout << "fts2ftx: version" << VersionString() << std::endl;
29 std::cout << "" << std::endl;
30 std::cout << "usage: fts2ftx [-t <ftype>] [-l <label>] [-o <outfile>] <infile>" << std::endl;
31 std::cout << "where " << std::endl;
32 std::cout << " <infile>: faudes token stream to convert" << std::endl;
33 std::cout << "" << std::endl;
34 std::cout << " -t <ftype>: faudes type of infile" << std::endl;
35 std::cout << " -l <label>: section label to read (defaults to entire file)" << std::endl;
36 std::cout << " -o <outfile>: file to write (defaults to infile with .ftx suffix)" << std::endl;
37 std::cout << "" << std::endl;
38 exit(-1);
39}
40
41
42
43// development: mount emscripten/js file system
44/*
45#include <emscripten.h>
46void emjs_mount(void) {
47 // mount the current folder as a NODEFS instance inside of emscripten
48 EM_ASM(
49 FS.mkdir('/working_dir');
50 FS.mount(NODEFS, { root: '.' }, '/working_dir');
51 );
52 // tell C++ programm about the current folder
53 chdir("/working_dir");
54}
55*/
56
57
58// process file
59int main(int argc, char *argv[]) {
60
61 // invoke emscripten/js mount
62 //emjs_mount();
63
64 // parameters
65 std::string mInFile;
66 std::string mOutFile;
67 std::string mType;
68 std::string mLabel;
69 int mVerify = 0;
70
71 // primitive commad line parsing
72 for(int i=1; i<argc; i++) {
73 std::string option(argv[i]);
74 // option: -t
75 if((option=="-t") || (option=="--ftype")) {
76 i++; if(i>=argc) usage_exit();
77 mType=argv[i];
78 continue;
79 }
80 // option: -l
81 if((option=="-l") || (option=="--lable")) {
82 i++; if(i>=argc) usage_exit();
83 mLabel=argv[i];
84 continue;
85 }
86 // option: -o
87 if((option=="-o") || (option=="--outfile")) {
88 i++; if(i>=argc) usage_exit();
89 mOutFile=argv[i];
90 continue;
91 }
92 // option: -v
93 if((option=="-v") || (option=="--verify")) {
94 mVerify++;
95 continue;
96 }
97 // option: -vv
98 if(option=="-vv"){
99 mVerify+=2;
100 continue;
101 }
102 // option: -vvv
103 if(option=="-vvv"){
104 mVerify+=3;
105 continue;
106 }
107 // option: help
108 if((option=="-?") || (option=="--help")) {
109 usage_exit();
110 continue;
111 }
112 // option: unknown
113 if(option.c_str()[0]=='-') {
114 usage_exit("unknown option "+ option);
115 continue;
116 }
117 // input
118 if(mInFile!="")
119 usage_exit("more than one filname specified");
120 mInFile=option;
121 }
122
123 // very verbose: dump registry
124 if(mVerify>2) {
126 }
127
128 // fix output file name
129 std::string basename = ExtractFilename(mInFile);
130 if(basename.find_last_of(".") !=std::string::npos) {
131 basename.resize(basename.find_last_of("."));
132 }
133 if(mOutFile=="") {
134 mOutFile= basename+".ftx";
135 }
136
137 // read input file
138 Type* fobject=NewFaudesObject(mType);
139 fobject->Read(mInFile,mLabel);
140
141 // verify: report
142 if(mVerify>2) {
143 std::cout << "fts2ftx: reporting faudes object of type " << mType << " (id " << typeid(*fobject).name() << ")" << std::endl;
144 fobject->Write();
145 }
146
147 // write output: console
148 if(mOutFile=="-") {
149 fobject->XWrite();
150 }
151
152 // write output: file
153 if(mOutFile!="-") {
154 fobject->XWrite(mOutFile);
155 }
156
157 // verify: read back
158 if(mOutFile!="-")
159 if(mVerify>0) {
160 std::cout << "fts2ftx: reading back ftx output" << std::endl;
161 Type* readback = fobject->New();
162 readback->Read(mOutFile);
163 if(!(*fobject==*readback))
164 std::cout << "fts2ftx: warning: objects dont match (!)" << std::endl;
165 }
166
167 // done
168 return 0;
169}
int main()
static TypeRegistry * G()
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
virtual Type * New(void) const
Definition cfl_types.cpp:54
void Write(const Type *pContext=0) const
void usage_exit(const std::string &message="")
Definition fts2ftx.cpp:22
Type * NewFaudesObject(const std::string &rTypeName)
std::string VersionString()
std::string ExtractFilename(const std::string &rFullPath)

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen