waut2dot.cpp
Go to the documentation of this file.
1 /** waut2dot.cpp Utility to convert gen files to dot files */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2006 Bernd Opitz
6  Copyright (C) 2025 Thomas Moor
7  Exclusive copyright is granted to Klaus Schmidt
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #include "libfaudes.h"
24 
25 using namespace faudes;
26 
27 // mini help
28 void usage(const std::string& msg="") {
29  std::cerr << "waut2dot --- convert omega automata to DOT format (" << faudes::VersionString() << ")" << std::endl;
30  if (msg != "") {
31  std::cerr << "error: " << msg << std::endl;
32  std::cerr << std::endl;
33  exit(1);
34  }
35  std::cerr << std::endl;
36  std::cerr << "usage:" << std::endl;
37  std::cerr << " waut2dot [-?] <aut-in> [<dot-out>]" << std::endl;
38  std::cerr << std::endl;
39  std::cerr << "with:" << std::endl;
40  std::cerr << " <aut-in> main input file" << std::endl;
41  std::cerr << " <dot-out> main output file" << std::endl;
42  std::cerr << std::endl;
43  std::cerr << "note: <dot-out> defaults <aut-in> with suffix substituted to \"dot\"" << std::endl;
44  std::cerr << "note: the current implementation is restricted to Rabin automata" << std::endl;
45  std::cerr << std::endl;
46  exit(0);
47 }
48 
49 // runner
50 int main(int argc, char *argv[]) {
51 
52  // config
53  std::string autin;
54  std::string dotout;
55 
56  // primitive command line parser
57  for(int i=1; i<argc; i++) {
58  std::string option(argv[i]);
59  // option: help
60  if((option=="-?") || (option=="--help")) {
61  usage();
62  continue;
63  }
64  // option: unknown
65  if(option.c_str()[0]=='-') {
66  usage("unknown option "+ option);
67  continue;
68  }
69  // argument #1 input file
70  if(autin.empty()) {
71  autin=argv[i];
72  continue;
73  }
74  // argument #2 output file
75  if(dotout.empty()) {
76  dotout=argv[i];
77  continue;
78  }
79  // fail
80  usage("no more than two arguments must be specified" );
81  }
82 
83  // fail on no input
84  if(autin.empty())
85  usage("no input file specified");
86 
87  // fix output file name
88  if(dotout.empty()) {
89  std::string basename = autin;
90  if(basename.rfind(".gen") < basename.size())
91  basename.resize(basename.rfind(".gen"));
92  std::string dotout = basename+".dot";
93  }
94 
95  // read gen file
96  RabinAutomaton aut(autin);
97 
98  // write dot file
99  aut.DotWrite(dotout);
100 
101  return 0;
102 }
virtual void DotWrite(const std::string &rFileName) const
Definition: omg_rabinaut.h:359
std::string VersionString()
Definition: cfl_utils.cpp:141
int main(int argc, char *argv[])
Definition: waut2dot.cpp:50
void usage(const std::string &msg="")
Definition: waut2dot.cpp:28

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