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
25using namespace faudes;
26
27// mini help
28void 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
50int 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 dotout = basename+".dot";
93 }
94
95 // prepare faudes object
96 Generator* pgen=nullptr;
97
98 // try to be smart and sense type
99 std::string ftype;
100 TokenReader tr(autin);
101 Token btag;
102 tr.Peek(btag);
103 if(btag.IsBegin()) {
104 ftype=btag.StringValue();
105 if(btag.ExistsAttributeString("ftype"))
106 ftype=btag.AttributeStringValue("ftype");
107 if(ftype=="RabinAutomaton") pgen=new RabinAutomaton;
108 if(ftype=="Generator") pgen=new Generator;
109 if(ftype=="System") pgen=new System;
110 }
111
112 // fallback
113 if(pgen==nullptr) pgen=new RabinAutomaton;
114
115 // read gen file
116 pgen->Read(autin);
117
118 // write dot file
119 pgen->DotWrite(dotout);
120
121 // be kind
122 delete pgen;
123
124 return 0;
125}
int main()
bool Peek(Token &token)
const std::string & StringValue(void) const
bool ExistsAttributeString(const std::string &name)
bool IsBegin(void) const
const std::string & AttributeStringValue(const std::string &name)
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
virtual void DotWrite(const std::string &rFileName) const
vGenerator Generator
TcGenerator< AttributeVoid, AttributeVoid, AttributeCFlags, AttributeVoid > System
std::string VersionString()
TrGenerator< RabinAcceptance, AttributeVoid, AttributeCFlags, AttributeVoid > RabinAutomaton
void usage(const std::string &msg="")
Definition waut2dot.cpp:28

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