author | clasohm |
Thu, 26 May 1994 13:37:51 +0200 | |
changeset 396 | 18c9c28d0f7e |
parent 378 | 85ff48546a05 |
child 1289 | 2edd7a39d92a |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: Pure/POLY |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1991 University of Cambridge |
|
5 |
||
6 |
Compatibility file for Poly/ML (AHL release 1.88) |
|
7 |
*) |
|
8 |
||
9 |
open PolyML ExtendedIO; |
|
10 |
||
11 |
||
12 |
(*A conditional timing function: applies f to () and, if the flag is true, |
|
13 |
prints its runtime.*) |
|
14 |
||
15 |
fun cond_timeit flag f = |
|
16 |
if flag then |
|
17 |
let val before = System.processtime() |
|
18 |
val result = f() |
|
19 |
val both = real(System.processtime() - before) / 10.0 |
|
20 |
in output(std_out, "Process time (incl GC): "^ |
|
21 |
makestring both ^ " secs\n"); |
|
22 |
result |
|
23 |
end |
|
24 |
else f(); |
|
25 |
||
26 |
||
27 |
(*Save function: in Poly/ML, ignores filename and commits to present file*) |
|
28 |
||
29 |
fun xML filename banner = commit(); |
|
30 |
||
31 |
||
32 |
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML*) |
|
33 |
||
34 |
fun make_pp _ pprint (str, blk, brk, en) obj = |
|
19 | 35 |
pprint obj (str, fn ind => blk (ind, false), fn wd => brk (wd, 0), |
36 |
fn () => brk (99999, 0), en); |
|
0 | 37 |
|
38 |
||
66 | 39 |
(*** File handling ***) |
0 | 40 |
|
100
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
41 |
local |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
42 |
|
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
43 |
(*These are functions from library.ML *) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
44 |
fun take_suffix _ [] = ([], []) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
45 |
| take_suffix pred (x :: xs) = |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
46 |
(case take_suffix pred xs of |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
47 |
([], sffx) => if pred x then ([], x :: sffx) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
48 |
else ([x], sffx) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
49 |
| (prfx, sffx) => (x :: prfx, sffx)); |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
50 |
|
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
51 |
fun apr (f,y) x = f(x,y); |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
52 |
|
396
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
53 |
fun seq (proc: 'a -> unit) : 'a list -> unit = |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
54 |
let fun seqf [] = () |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
55 |
| seqf (x :: xs) = (proc x; seqf xs) |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
56 |
in seqf end; |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
57 |
|
100
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
58 |
in |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
59 |
|
58
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
60 |
(*Get a string containing the time of last modification, attributes, owner |
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
61 |
and size of file (but not the path) *) |
0 | 62 |
fun file_info "" = "" |
63 |
| file_info name = |
|
58
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
64 |
let |
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
65 |
val (is, os) = ExtendedIO.execute ("ls -l " ^ name) |
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
66 |
val (result, _) = take_suffix (apr(op<>," ")) |
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
67 |
(explode (ExtendedIO.input_line is)) |
66 | 68 |
(*Remove the part after the last " " (i.e. the path/filename) *) |
58
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
69 |
in close_in is; |
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
70 |
close_out os; |
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
71 |
implode result |
b30802dfbe80
file_info now returns a string that does not contain the path/filename
clasohm
parents:
19
diff
changeset
|
72 |
end; |
66 | 73 |
|
73
075db6ac7f2f
delete_file now has type string -> unit in both NJ and POLY,
clasohm
parents:
66
diff
changeset
|
74 |
(*Delete a file *) |
075db6ac7f2f
delete_file now has type string -> unit in both NJ and POLY,
clasohm
parents:
66
diff
changeset
|
75 |
fun delete_file name = |
100
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
76 |
let val (is, os) = ExtendedIO.execute ("rm " ^ name) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
77 |
in close_in is; |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
78 |
close_out os |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
79 |
end; |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
80 |
|
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
81 |
(*Get pathname of current working directory *) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
82 |
fun pwd () = |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
83 |
let val (is, os) = ExtendedIO.execute ("pwd") |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
84 |
val (path, _) = take_suffix (apr(op=,"\n")) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
85 |
(explode (ExtendedIO.input_line is)) (*remove newline *) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
86 |
in close_in is; |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
87 |
close_out os; |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
88 |
implode path |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
89 |
end; |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
90 |
|
378
85ff48546a05
added use_string: string -> unit to execute ML commands passed in a string
clasohm
parents:
100
diff
changeset
|
91 |
|
85ff48546a05
added use_string: string -> unit to execute ML commands passed in a string
clasohm
parents:
100
diff
changeset
|
92 |
(*** ML command execution ***) |
85ff48546a05
added use_string: string -> unit to execute ML commands passed in a string
clasohm
parents:
100
diff
changeset
|
93 |
|
396
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
94 |
val use_string = |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
95 |
let fun exec command = |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
96 |
let val firstLine = ref true; |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
97 |
|
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
98 |
fun getLine () = |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
99 |
if !firstLine |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
100 |
then (firstLine := false; command) |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
101 |
else raise Io "use_string: buffer exhausted" |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
102 |
in PolyML.compiler (getLine, fn s => output (std_out, s)) () end |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
103 |
in seq exec end; |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
104 |
|
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
105 |
end; |