2 * Translator from Modelica 2.x to flat Modelica
\r
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
23 let evaluate x = Lazy.force x
\r
25 let rec parse_stored_libraries lib_paths =
\r
26 List.fold_left parse_library [] lib_paths
\r
28 and parse_command cmd =
\r
29 let token_fun = Lexer.token
\r
30 and lexbuf = Lexing.from_string cmd in
\r
31 Parser.parse Parser.CommandLine token_fun lexbuf
\r
33 and parse_library lib_syns lib_path =
\r
35 let file_names = modelica_file_names_of lib_path in
\r
36 lib_syns @ (List.fold_left parse_file [] file_names)
\r
39 ExceptHandler.handle exn;
\r
42 and parse_file lib_syns file_name =
\r
43 let ic = open_in_bin file_name in
\r
45 let token_fun = Lexer.token
\r
46 and lexbuf = Lexing.from_channel ic in
\r
47 let src = Parser.LibraryFile file_name in
\r
48 let lib_syn = Parser.parse src token_fun lexbuf in
\r
54 ExceptHandler.handle exn;
\r
57 and modelica_file_names_of lib_path =
\r
58 let rec modelica_file_names_of' acc lib_path =
\r
59 let base_name = basename lib_path
\r
60 and dir_name = dirname lib_path in
\r
61 let lib_path = Filename.concat dir_name base_name in
\r
62 match is_directory lib_path with
\r
64 let names = Array.to_list (Sys.readdir lib_path) in
\r
66 List.map (function s -> Filename.concat lib_path s) names in
\r
67 List.fold_left modelica_file_names_of' acc lib_paths
\r
68 | false when Filename.check_suffix lib_path ".mo" -> lib_path :: acc
\r
70 modelica_file_names_of' [] lib_path
\r
72 and basename lib_path =
\r
73 match Filename.basename lib_path with
\r
74 | "." -> basename (Filename.dirname lib_path)
\r
77 and dirname lib_path =
\r
78 match Filename.basename lib_path with
\r
79 | "." -> dirname (Filename.dirname lib_path)
\r
80 | _ -> Filename.dirname lib_path
\r
82 and is_directory dirname =
\r
84 Sys.is_directory dirname
\r