hoa2gen.cpp
Go to the documentation of this file.
1 /** hao2gen.cpp Utility to convert HAO files to generator files */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2025 Thomas Moor
6  Exclusive copyright is granted to Klaus Schmidt
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 
23 /*
24 
25 This program uses the library cpphaofparser to parse HAO files and forwards
26 relevant content as libFAUDES token stream. The source code is derived from
27 the example command-line tool, that comes with cpphaofparser v0.99.2.
28 
29 The cpphaofparser is authored/copyrighted by
30 
31 Joachim Klein <klein@tcs.inf.tu-dresden.de>
32 David Mueller <david.mueller@tcs.inf.tu-dresden.de>
33 
34 Original sources are redistributed with libFAUDES. We obtained our copy from
35 
36 http://automata.tools/hoa/cpphoafparser
37 
38 */
39 
40 
41 #include "libfaudes.h"
42 
43 using namespace faudes;
44 
45 
46 // mini help
47 void usage(std::string msg="") {
48  std::cerr << "hoa2gen --- convert HOA format to generators (" << VersionString() << ")" << std::endl;
49  if (msg != "") {
50  std::cerr << "error: " << msg << std::endl;
51  std::cerr << std::endl;
52  exit(1);
53  }
54  std::cerr << std::endl;
55  std::cerr << "hoa2gen uses the cpphoafparser library, see http://automata.tools/hoa" << std::endl;
56  std::cerr << std::endl;
57  std::cerr << "usage:"<< std::endl;
58  std::cerr << " hoa2gen [flags*] [-s <sym-in>] [<hoa-in> [<gen-out>]]" << std::endl;
59  std::cerr << std::endl;
60  std::cerr << "with:"<< std::endl;
61  std::cerr << " <hoa-in> main input file (defaults to std in)" << std::endl;
62  std::cerr << " <gen-out> main output file (defaults to std out)" << std::endl;
63  std::cerr << " <sym-in> symbol table file (defaults to no such)" << std::endl;
64  std::cerr << std::endl;
65  std::cerr << "valid flags:" << std::endl;
66  std::cerr << " --resolve-aliases resolve aliases" << std::endl;
67  std::cerr << " --trace trace the function calls (debug/devel)" << std::endl;
68  std::cerr << " --xmlout generate strict XML output " << std::endl;
69  std::cerr << std::endl;
70  exit(0);
71 }
72 
73 
74 // runner
75 int main(int argc, char* argv[]) {
76 
77  // options/args
78  std::string hoain;
79  std::string symin;
80  std::string genout;
81  bool resolve = false;
82  bool trace = false;
83  bool xmlout = false;
84  // primitive command line parser
85  for(int i=1; i<argc; i++) {
86  std::string option(argv[i]);
87  // option: symbol table
88  if(option=="-s") {
89  i++;
90  if(i>=argc) usage("symbol file not specified");
91  symin=argv[i];
92  continue;
93  }
94  // option: help
95  if((option=="-?") || (option=="--help")) {
96  usage();
97  continue;
98  }
99  // option: resolve aliases
100  if(option=="--resolve-aliases") {
101  resolve = true;
102  continue;
103  }
104  // option: trace
105  if(option=="--trace") {
106  trace = true;
107  continue;
108  }
109  // option: trace
110  if(option=="--xmlout") {
111  xmlout = true;
112  continue;
113  }
114  // option: unknown
115  if(option.c_str()[0]=='-') {
116  usage("unknown option "+ option);
117  continue;
118  }
119  // argument #1 main input file
120  if(hoain.empty()) {
121  hoain=argv[i];
122  continue;
123  }
124  // argument #2 main output file
125  if(genout.empty()) {
126  genout=argv[i];
127  continue;
128  }
129  // fail
130  usage("at most two arguments must be specified" );
131  }
132 
133  // have optional symboltable
134  SymbolTable mSymTab;
135  if(!symin.empty())
136  mSymTab.Read(symin);
137 
138  // have target object
139  RabinAutomaton mAut;
140 
141  // do import
142  if(hoain.empty())
143  ImportHoa(std::cin,mAut,&mSymTab,resolve,trace);
144  else
145  ImportHoa(hoain,mAut,&mSymTab,resolve,trace);
146 
147  // do output
148  if(xmlout) {
149  if(genout.empty()) mAut.XWrite();
150  else mAut.XWrite(genout);
151  } else {
152  if(genout.empty()) mAut.Write();
153  else mAut.Write(genout);
154  }
155 
156  return 1;
157 }
158 
159 
160 
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Definition: cfl_types.cpp:267
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
Definition: cfl_types.cpp:206
void Write(const Type *pContext=0) const
Definition: cfl_types.cpp:145
void ImportHoa(std::istream &rInStream, Generator &rGen, const SymbolTable *pSymTab, bool resolve, bool trace)
Definition: omg_hoa.cpp:503
int main(int argc, char *argv[])
Definition: hoa2gen.cpp:75
void usage(std::string msg="")
Definition: hoa2gen.cpp:47
std::string VersionString()
Definition: cfl_utils.cpp:141

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