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

[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 () =
| [] -> assert false
| 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
exception Location of loc * exn
......
......@@ -17,6 +17,8 @@ val raise_loc_generic: loc -> string -> 'a
val push_source: source -> unit
val pop_source: unit -> unit
val current_dir : unit -> string
val warning_ppf : Format.formatter ref
type viewport = [ `Html | `Text ]
......
......@@ -132,8 +132,14 @@ EXTEND
| DIRECTIVE "#env" -> [ mk loc (Directive `Env) ]
| "include"; s = STRING2 ->
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";
(* 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 []
else (
include_stack := s :: !include_stack;
......@@ -141,10 +147,11 @@ EXTEND
protect_exn
(fun () ->
let chan = open_in s in
let input = Stream.of_channel chan in
let l = Grammar.Entry.parse prog input in
close_in chan;
l)
protect_exn
(fun () ->
let input = Stream.of_channel chan in
Grammar.Entry.parse prog input)
(fun () -> close_in chan))
(fun () ->
Location.pop_source ();
include_stack := List.tl !include_stack)
......
......@@ -89,6 +89,8 @@ debug compile %%t%% %%p%%1 ... %%pn%% {{ compilation of pattern matching }}
<li>Textual inclusion <code>include "%%other_cduce_script.cd%%"</code>;
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>
</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