author | wenzelm |
Tue, 19 May 1998 17:15:30 +0200 | |
changeset 4945 | d8c809afafb8 |
parent 4943 | a1b5d156ec33 |
permissions | -rw-r--r-- |
4216 | 1 |
(* Title: Pure/Thy/file.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
File system operations. |
|
6 |
*) |
|
7 |
||
8 |
signature FILE = |
|
9 |
sig |
|
4341 | 10 |
val tmp_name: string -> string |
4216 | 11 |
val exists: string -> bool |
4341 | 12 |
val info: string -> string |
4216 | 13 |
val read: string -> string |
14 |
val write: string -> string -> unit |
|
15 |
val append: string -> string -> unit |
|
16 |
val copy: string -> string -> unit |
|
4943
a1b5d156ec33
added source: string -> (string, string list) Source.source;
wenzelm
parents:
4437
diff
changeset
|
17 |
val source: string -> (string, string list) Source.source |
4216 | 18 |
end; |
19 |
||
20 |
structure File: FILE = |
|
21 |
struct |
|
22 |
||
23 |
||
4341 | 24 |
(* tmp_name *) |
25 |
||
26 |
fun tmp_name name = |
|
27 |
Path.pack (Path.evaluate (Path.unpack o getenv) |
|
28 |
(Path.append (Path.variable "ISABELLE_TMP") (Path.unpack name))); |
|
29 |
||
30 |
||
31 |
(* exists / info *) |
|
4216 | 32 |
|
33 |
fun exists name = (file_info name <> ""); |
|
4341 | 34 |
val info = file_info; |
4216 | 35 |
|
36 |
||
37 |
(* read / write files *) |
|
38 |
||
39 |
fun read name = |
|
40 |
let |
|
41 |
val instream = TextIO.openIn name; |
|
42 |
val intext = TextIO.inputAll instream; |
|
43 |
in |
|
44 |
TextIO.closeIn instream; |
|
45 |
intext |
|
46 |
end; |
|
47 |
||
48 |
fun write name txt = |
|
49 |
let val outstream = TextIO.openOut name in |
|
50 |
TextIO.output (outstream, txt); |
|
51 |
TextIO.closeOut outstream |
|
52 |
end; |
|
53 |
||
54 |
fun append name txt = |
|
55 |
let val outstream = TextIO.openAppend name in |
|
56 |
TextIO.output (outstream, txt); |
|
57 |
TextIO.closeOut outstream |
|
58 |
end; |
|
59 |
||
4341 | 60 |
fun copy infile outfile = |
4216 | 61 |
if not (exists infile) then error ("File not found: " ^ quote infile) |
62 |
else write outfile (read infile); |
|
63 |
||
4943
a1b5d156ec33
added source: string -> (string, string list) Source.source;
wenzelm
parents:
4437
diff
changeset
|
64 |
val source = Source.of_string o read; |
a1b5d156ec33
added source: string -> (string, string list) Source.source;
wenzelm
parents:
4437
diff
changeset
|
65 |
|
4216 | 66 |
|
67 |
end; |