4 * Copyright (C) 2005 - 2007 Imagine S.A.
\r
5 * For more information or commercial use please contact us at www.amesim.com
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program; if not, write to the Free Software
\r
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
24 "@(#)XML2Modelica - Copyright (C) 2008 LMS Imagine"
\r
32 let init = ref false
\r
34 let check_filename () =
\r
35 if Filename.check_suffix !input "xml" then ()
\r
36 else failwith "check_filename: Filename suffix must be 'xml'"
\r
38 let check_output () =
\r
39 if !output = "" then failwith "check_output: No output filename specified"
\r
42 if !output <> "" then failwith "set_output: More than one output specified";
\r
46 if !input <> "" then failwith "set_input: More than one input specified";
\r
49 let construct_output_filename () =
\r
50 if !output = "" then begin
\r
51 output := Filename.chop_suffix !input "mo"
\r
57 [("-o", Arg.String set_output,
\r
58 "<outputfile> Set output file name to <outputfile>");
\r
59 ("-init", Arg.Set init,
\r
60 "Generate flat Modelica code for initialization")]
\r
62 ("usage: XML2modelica -o <outputfile> <inputfile>")
\r
68 let ic = open_in !input in
\r
69 Printf.printf "Input file name = %s\n" !input; flush stdout;
\r
70 let lexbuf = Lexing.from_channel ic in
\r
71 Printf.printf "Parsing..."; flush stdout;
\r
72 let model = XMLParser.parse !input XMLLexer.token lexbuf in
\r
73 let filename = construct_output_filename () in
\r
74 Printf.printf "OK\nGenerating code..."; flush stdout;
\r
75 ModelicaCodeGenerator.generate_code !init filename model;
\r
76 Printf.printf " OK\nOutput file name = %s\n" !output; flush stdout;
\r
77 Printf.printf "Terminated.\n"; flush stdout;
\r