2 * Translator from Modelica 2.x to flat Modelica
4 * Copyright (C) 2005 - 2007 Imagine S.A.
5 * For more information or commercial use please contact us at www.amesim.com
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 let evaluate x = Lazy.force x
25 let rec parse_stored_libraries lib_paths =
26 List.fold_left parse_library [] lib_paths
28 and parse_command cmd =
29 let token_fun = Lexer.token
30 and lexbuf = Lexing.from_string cmd in
31 Parser.parse Parser.CommandLine token_fun lexbuf
33 and parse_library lib_syns lib_path =
35 let file_names = modelica_file_names_of lib_path in
36 lib_syns @ (List.fold_left parse_file [] file_names)
39 ExceptHandler.handle exn;
42 and parse_file lib_syns file_name =
43 let ic = open_in_bin file_name in
45 let token_fun = Lexer.token
46 and lexbuf = Lexing.from_channel ic in
47 let src = Parser.LibraryFile file_name in
48 let lib_syn = Parser.parse src token_fun lexbuf in
54 ExceptHandler.handle exn;
57 and modelica_file_names_of lib_path =
58 let rec modelica_file_names_of' acc lib_path =
59 let base_name = basename lib_path
60 and dir_name = dirname lib_path in
61 let lib_path = Filename.concat dir_name base_name in
62 match is_directory lib_path with
64 let names = Array.to_list (Sys.readdir lib_path) in
66 List.map (function s -> Filename.concat lib_path s) names in
67 List.fold_left modelica_file_names_of' acc lib_paths
68 | false when Filename.check_suffix lib_path ".mo" -> lib_path :: acc
70 modelica_file_names_of' [] lib_path
72 and basename lib_path =
73 match Filename.basename lib_path with
74 | "." -> basename (Filename.dirname lib_path)
77 and dirname lib_path =
78 match Filename.basename lib_path with
79 | "." -> dirname (Filename.dirname lib_path)
80 | _ -> Filename.dirname lib_path
82 and is_directory dirname =
84 Sys.is_directory dirname