1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2015, 2019 Laboratoire de Recherche et Développement
3 // de l'Epita (LRDE).
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 #include "common_hoaread.hh"
21 #include "common_setup.hh"
22 #include "argmatch.h"
23 #include "error.h"
24
25 enum
26 {
27 OPT_TRUST_HOA = 1,
28 };
29
30 static const argp_option options[] =
31 {
32 { "trust-hoa", OPT_TRUST_HOA, "BOOL", 0,
33 "If false, properties listed in HOA files are ignored, "
34 "unless they can be easily verified. If true (the default) "
35 "any supported property is trusted.", 1 },
36 { nullptr, 0, nullptr, 0, nullptr, 0 }
37 };
38
39 spot::automaton_parser_options opt_parse;
40
41 spot::twa_graph_ptr
read_automaton(const char * filename,spot::bdd_dict_ptr & dict)42 read_automaton(const char* filename, spot::bdd_dict_ptr& dict)
43 {
44 auto p = spot::parse_aut(filename, dict,
45 spot::default_environment::instance(),
46 opt_parse);
47 if (p->format_errors(std::cerr))
48 error(2, 0, "failed to read automaton from %s", filename);
49 if (p->aborted)
50 error(2, 0, "failed to read automaton from %s (--ABORT-- read)", filename);
51 return std::move(p->aut);
52 }
53
parse_bool(const char * opt,const char * arg)54 static bool parse_bool(const char* opt, const char* arg)
55 {
56 enum bool_type { bool_false, bool_true };
57 static char const *const bool_args[] =
58 {
59 "false", "no", "0",
60 "true", "yes", "1",
61 nullptr
62 };
63 static bool_type const bool_types[] =
64 {
65 bool_false, bool_false, bool_false,
66 bool_true, bool_true, bool_true,
67 };
68 ARGMATCH_VERIFY(bool_args, bool_types);
69 bool_type bt = XARGMATCH(opt, arg, bool_args, bool_types);
70 return bt == bool_true;
71 }
72
73 static int
parse_opt_hoaread(int key,char * arg,struct argp_state *)74 parse_opt_hoaread(int key, char* arg, struct argp_state*)
75 {
76 // Called from C code, so should not raise any exception.
77 BEGIN_EXCEPTION_PROTECT;
78 // This switch is alphabetically-ordered.
79 switch (key)
80 {
81 case OPT_TRUST_HOA:
82 opt_parse.trust_hoa = parse_bool("--trust-hoa", arg);
83 break;
84 default:
85 return ARGP_ERR_UNKNOWN;
86 }
87 END_EXCEPTION_PROTECT;
88 return 0;
89 }
90
91
92 const struct argp hoaread_argp = { options, parse_opt_hoaread,
93 nullptr, nullptr, nullptr,
94 nullptr, nullptr };
95