Commit 85f4a24e authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2003-05-31 21:38:01 by cvscast] include is relative to the current script's directory

Original author: cvscast
Date: 2003-05-31 21:38:01+00:00
parent 28985ea2
...@@ -16,6 +16,11 @@ let pop_source () = ...@@ -16,6 +16,11 @@ let pop_source () =
| [] -> assert false | [] -> assert false
| s::rem -> source_stack := rem; source := s | s::rem -> source_stack := rem; source := s
let current_dir () =
match !source with
| `File s -> Filename.dirname s
| _ -> ""
let warning_ppf = ref Format.std_formatter let warning_ppf = ref Format.std_formatter
exception Location of loc * exn exception Location of loc * exn
......
...@@ -17,6 +17,8 @@ val raise_loc_generic: loc -> string -> 'a ...@@ -17,6 +17,8 @@ val raise_loc_generic: loc -> string -> 'a
val push_source: source -> unit val push_source: source -> unit
val pop_source: unit -> unit val pop_source: unit -> unit
val current_dir : unit -> string
val warning_ppf : Format.formatter ref val warning_ppf : Format.formatter ref
type viewport = [ `Html | `Text ] type viewport = [ `Html | `Text ]
......
...@@ -132,8 +132,14 @@ EXTEND ...@@ -132,8 +132,14 @@ EXTEND
| DIRECTIVE "#env" -> [ mk loc (Directive `Env) ] | DIRECTIVE "#env" -> [ mk loc (Directive `Env) ]
| "include"; s = STRING2 -> | "include"; s = STRING2 ->
let s = get_string s in let s = get_string s in
let s =
if Filename.is_relative s
then Filename.concat (Location.current_dir ()) s
else s in
protect_op "File inclusion"; protect_op "File inclusion";
(* avoid looping; should issue an error ? *) (* avoid looping; should issue an error ? *)
(* it is possible to have looping with x/../x/../x/.. ....
Need to canonicalize filename *)
if List.mem s !include_stack then [] if List.mem s !include_stack then []
else ( else (
include_stack := s :: !include_stack; include_stack := s :: !include_stack;
...@@ -141,10 +147,11 @@ EXTEND ...@@ -141,10 +147,11 @@ EXTEND
protect_exn protect_exn
(fun () -> (fun () ->
let chan = open_in s in let chan = open_in s in
let input = Stream.of_channel chan in protect_exn
let l = Grammar.Entry.parse prog input in (fun () ->
close_in chan; let input = Stream.of_channel chan in
l) Grammar.Entry.parse prog input)
(fun () -> close_in chan))
(fun () -> (fun () ->
Location.pop_source (); Location.pop_source ();
include_stack := List.tl !include_stack) include_stack := List.tl !include_stack)
......
...@@ -89,6 +89,8 @@ debug compile %%t%% %%p%%1 ... %%pn%% {{ compilation of pattern matching }} ...@@ -89,6 +89,8 @@ debug compile %%t%% %%p%%1 ... %%pn%% {{ compilation of pattern matching }}
<li>Textual inclusion <code>include "%%other_cduce_script.cd%%"</code>; <li>Textual inclusion <code>include "%%other_cduce_script.cd%%"</code>;
note that cycle of inclusion are detected and automatically broken. note that cycle of inclusion are detected and automatically broken.
Filename are relative to the directory of the current file
(or the current directory in the toplevel).
</li> </li>
</ul> </ul>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment