libutap  0.93
Uppaal Timed Automata Parser
syntaxcheck.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 
3 /* libutap - Uppaal Timed Automata Parser.
4  Copyright (C) 2002 Uppsala University and Aalborg University.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public License
8  as published by the Free Software Foundation; either version 2.1 of
9  the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  USA
20 */
21 
22 #include <vector>
23 #include "utap/utap.h"
24 #include <string.h>
25 
27 using std::endl;
28 using std::cout;
29 using std::cerr;
30 using std::vector;
31 
32 int main(int argc, char *argv[])
33 {
34  try
35  {
36  bool old = false;
37 
38  if (argc < 2 || argc > 3)
39  {
40  std::cerr << "Synopsis: check [-b] <filename>" << std::endl;
41  return 1;
42  }
43 
44  old = (strcmp(argv[1], "-b") == 0);
45 
46  TimedAutomataSystem system;
47  const char *name = argv[argc - 1];
48 
49  if (strlen(name) > 4 && strcasecmp(".xml", name + strlen(name) - 4) == 0)
50  {
51  parseXMLFile(name, &system, !old);
52  }
53  else
54  {
55  FILE *file = fopen(name, "r");
56  if (!file)
57  {
58  perror("check");
59  return 1;
60  }
61  parseXTA(file, &system, !old);
62  fclose(file);
63  }
64 
65  vector<UTAP::error_t>::const_iterator it;
66  const vector<UTAP::error_t> &errors = system.getErrors();
67  const vector<UTAP::error_t> &warns = system.getWarnings();
68 
69  for (it = errors.begin(); it != errors.end(); it++)
70  {
71  cerr << *it << endl;
72  }
73  for (it = warns.begin(); it != warns.end(); it++)
74  {
75  cerr << *it << endl;
76  }
77 
78  return errors.empty() && warns.empty() ? 0 : 2;
79  }
80  catch (std::exception &e)
81  {
82  cerr << e.what() << endl;
83  return 3;
84  }
85 }
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
int32_t parseXMLFile(const char *file, TimedAutomataSystem *system, bool newxta)
const std::vector< error_t > & getErrors() const
Definition: system.cpp:1420
const std::vector< error_t > & getWarnings() const
Definition: system.cpp:1426
int main(int argc, char *argv[])
Definition: syntaxcheck.cpp:32
static int32_t parseXTA(ParserBuilder *aParserBuilder, bool newxta, xta_part_t part, std::string xpath)
Definition: parser.cc:8906