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 << std::endl;
69  exit(0);
70 }
71 
72 
73 // runner
74 int main(int argc, char* argv[]) {
75 
76  // options/args
77  std::string hoain;
78  std::string symin;
79  std::string genout;
80  bool resolve = false;
81  bool trace = false;
82  // primitive command line parser
83  for(int i=1; i<argc; i++) {
84  std::string option(argv[i]);
85  // option: symbol table
86  if(option=="-s") {
87  i++;
88  if(i>=argc) usage("symbol file not specified");
89  symin=argv[i];
90  continue;
91  }
92  // option: help
93  if((option=="-?") || (option=="--help")) {
94  usage();
95  continue;
96  }
97  // option: resolve aliases
98  if(option=="--resolve-aliases") {
99  resolve = true;
100  continue;
101  }
102  // option: trace
103  if(option=="--trace") {
104  trace = true;
105  continue;
106  }
107  // option: unknown
108  if(option.c_str()[0]=='-') {
109  usage("unknown option "+ option);
110  continue;
111  }
112  // argument #1 main input file
113  if(hoain.empty()) {
114  hoain=argv[i];
115  continue;
116  }
117  // argument #2 main output file
118  if(genout.empty()) {
119  genout=argv[i];
120  continue;
121  }
122  // fail
123  usage("at most two arguments must be specified" );
124  }
125 
126  // have optional symboltable
127  SymbolTable mSymTab;
128  if(!symin.empty())
129  mSymTab.Read(symin);
130 
131  // have target object
132  RabinAutomaton mAut;
133 
134  // do import
135  if(hoain.empty())
136  ImportHoa(std::cin,mAut,&mSymTab,resolve,trace);
137  else
138  ImportHoa(hoain,mAut,&mSymTab,resolve,trace);
139 
140  // do output
141  if(genout.empty())
142  mAut.XWrite();
143  else
144  mAut.XWrite(genout);
145 
146  return 1;
147 }
148 
149 
150 
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 ImportHoa(std::istream &rInStream, RabinAutomaton &rAut, const SymbolTable *pSymTab, bool resolve, bool trace)
Definition: omg_hoa.cpp:364
int main(int argc, char *argv[])
Definition: hoa2gen.cpp:74
void usage(std::string msg="")
Definition: hoa2gen.cpp:47
std::string VersionString()
Definition: cfl_utils.cpp:141

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen