libutap  0.93
Uppaal Timed Automata Parser
pretty.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 <cstdio>
23 #include <cstdlib>
24 #include <unistd.h>
25 #include <string>
26 #include <strings.h>
27 
28 #include "utap/prettyprinter.h"
29 
30 using namespace std;
31 using namespace UTAP::Constants;
32 
33 static bool newSyntax = (getenv("UPPAAL_OLD_SYNTAX") == NULL);
34 
38 int main(int argc, char *argv[])
39 {
40  try
41  {
42  std::string filename;
43 
44  if (argc != 2)
45  {
46  std::cerr << "Usage: " << argv[0] << " MODEL\n\n";
47  std::cerr << "where MODEL is a UPPAAL .xml, xta, or .ta file\n";
48  return 1;
49  }
50 
51  filename = argv[1];
52 
53  UTAP::PrettyPrinter pretty(cout);
54 
55  if (strcasecmp(".xml", filename.c_str() + filename.length() - 4) == 0)
56  {
57  parseXMLFile(filename.c_str(), &pretty, newSyntax);
58  }
59  else
60  {
61  FILE *file = fopen(filename.c_str(), "r");
62  if (file == NULL)
63  {
64  char msg[256];
65  snprintf(msg, 255, "Error opening %s", filename.c_str());
66  perror(msg);
67  return 1;
68  }
69 
70  parseXTA(file, &pretty, newSyntax);
71  }
72  }
73  catch (std::exception &e)
74  {
75  std::cerr << "Caught exception: " << e.what() << std::endl;
76  return 1;
77  }
78  return 0;
79 }
int32_t parseXMLFile(const char *file, TimedAutomataSystem *system, bool newxta)
static bool newSyntax
Definition: pretty.cpp:33
int main(int argc, char *argv[])
Test for pretty printer.
Definition: pretty.cpp:38
static int32_t parseXTA(ParserBuilder *aParserBuilder, bool newxta, xta_part_t part, std::string xpath)
Definition: parser.cc:8906