gen2dot.cpp
Go to the documentation of this file.
1/** gen2dot.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 "corefaudes.h"
24
25using namespace faudes;
26
27// mini help
28void usage(const std::string& msg="") {
29 std::cerr << "gen2dot --- convert generators 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 << " gen2dot [-?] <gen-in> [<dot-out>]" << std::endl;
38 std::cerr << std::endl;
39 std::cerr << "with:" << std::endl;
40 std::cerr << " <gen-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 <gen-in> with suffix substituted to \"dot\"" << std::endl;
44 std::cerr << std::endl;
45 exit(0);
46}
47
48// runner
49int main(int argc, char *argv[]) {
50
51 // config
52 std::string genin;
53 std::string dotout;
54
55 // primitive command line parser
56 for(int i=1; i<argc; i++) {
57 std::string option(argv[i]);
58 // option: help
59 if((option=="-?") || (option=="--help")) {
60 usage();
61 continue;
62 }
63 // option: unknown
64 if(option.c_str()[0]=='-') {
65 usage("unknown option "+ option);
66 continue;
67 }
68 // argument #1 input file
69 if(genin.empty()) {
70 genin=argv[i];
71 continue;
72 }
73 // argument #2 output file
74 if(dotout.empty()) {
75 dotout=argv[i];
76 continue;
77 }
78 // fail
79 usage("no more than two arguments must be specified" );
80 }
81
82 // fail on no input
83 if(genin.empty())
84 usage("no input file specified");
85
86 // fix output file name
87 if(dotout.empty()) {
88 std::string basename = genin;
89 if(basename.rfind(".gen") < basename.size())
90 basename.resize(basename.rfind(".gen"));
91 dotout = basename+".dot";
92 }
93
94 // read gen file
95 Generator g(genin);
96
97 // write dot file
98 g.DotWrite(dotout);
99
100 return 0;
101}
int main()
virtual void DotWrite(const std::string &rFileName) const
void usage(const std::string &msg="")
Definition gen2dot.cpp:28
std::string VersionString()

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