author | wenzelm |
Tue, 13 Jan 1998 18:03:37 +0100 | |
changeset 4567 | b0b963a01a0c |
parent 4367 | 2f0c174036dc |
child 4704 | 4fce39cc7136 |
permissions | -rw-r--r-- |
4219
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/Thy/use.ML |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
2 |
ID: $Id$ |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
3 |
Author: David von Oheimb and Markus Wenzel, TU Muenchen |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
4 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
5 |
Redefine 'use' command in order to support path variable expansion, |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
6 |
automatic suffix generation, and symbolic input filtering (if |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
7 |
required). |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
8 |
*) |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
9 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
10 |
signature USE = |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
11 |
sig |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
12 |
val use: string -> unit |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
13 |
val exit_use: string -> unit |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
14 |
val time_use: string -> unit |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
15 |
val cd: string -> unit |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
16 |
end; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
17 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
18 |
structure Use: USE = |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
19 |
struct |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
20 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
21 |
(* generate suffix *) |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
22 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
23 |
fun append_suffix name = |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
24 |
let |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
25 |
fun try [] = error ("File not found: " ^ quote name) |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
26 |
| try (sfx :: sfxs) = |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
27 |
if File.exists (name ^ sfx) then name ^ sfx |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
28 |
else try sfxs; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
29 |
in try ["", ".ML", ".sml"] end; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
30 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
31 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
32 |
(* input filtering *) |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
33 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
34 |
val use_orig = use; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
35 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
36 |
val use_filter = |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
37 |
if not needs_filtered_use then use_orig |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
38 |
else |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
39 |
fn name => |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
40 |
let |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
41 |
val txt = File.read name; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
42 |
val txt_out = implode (SymbolFont.write_charnames' (explode txt)); |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
43 |
in |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
44 |
if txt = txt_out then use_orig name |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
45 |
else |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
46 |
let |
4367 | 47 |
val tmp_name = File.tmp_name ("." ^ Path.base_name name); |
4219
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
48 |
val _ = File.write tmp_name txt_out; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
49 |
val rm = OS.FileSys.remove; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
50 |
in |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
51 |
use_orig tmp_name handle exn => (rm tmp_name; raise exn); |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
52 |
rm tmp_name |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
53 |
end |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
54 |
end; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
55 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
56 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
57 |
(* use commands *) |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
58 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
59 |
val use = use_filter o append_suffix o Path.expand getenv; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
60 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
61 |
(*use the file, but exit with error code if errors found*) |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
62 |
fun exit_use name = use name handle _ => exit 1; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
63 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
64 |
(*timed "use" function, printing filenames*) |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
65 |
fun time_use name = timeit (fn () => |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
66 |
(writeln ("\n**** Starting " ^ name ^ " ****"); use name; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
67 |
writeln ("\n**** Finished " ^ name ^ " ****"))); |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
68 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
69 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
70 |
(* redefine cd *) |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
71 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
72 |
val cd = cd o Path.expand getenv; |
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
73 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
74 |
|
276e53e5ceca
Redefine 'use' command in order to support path variable expansion,
wenzelm
parents:
diff
changeset
|
75 |
end; |