Commit | Line | Data |
---|---|---|
ce543a9f JG |
1 | ;;; simple.scm --- The R6RS simple I/O library |
2 | ||
5dcbcfce | 3 | ;; Copyright (C) 2010, 2011, 2014 Free Software Foundation, Inc. |
ce543a9f JG |
4 | ;; |
5 | ;; This library is free software; you can redistribute it and/or | |
6 | ;; modify it under the terms of the GNU Lesser General Public | |
7 | ;; License as published by the Free Software Foundation; either | |
8 | ;; version 3 of the License, or (at your option) any later version. | |
9 | ;; | |
10 | ;; This library is distributed in the hope that it will be useful, | |
11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | ;; Lesser General Public License for more details. | |
14 | ;; | |
15 | ;; You should have received a copy of the GNU Lesser General Public | |
16 | ;; License along with this library; if not, write to the Free Software | |
17 | ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | \f | |
19 | ||
20 | (library (rnrs io simple (6)) | |
21 | (export eof-object | |
22 | eof-object? | |
23 | ||
24 | call-with-input-file | |
25 | call-with-output-file | |
26 | ||
27 | input-port? | |
28 | output-port? | |
29 | ||
30 | current-input-port | |
31 | current-output-port | |
32 | current-error-port | |
33 | ||
34 | with-input-from-file | |
35 | with-output-to-file | |
36 | ||
37 | open-input-file | |
38 | open-output-file | |
39 | ||
40 | close-input-port | |
41 | close-output-port | |
42 | ||
43 | read-char | |
44 | peek-char | |
45 | read | |
46 | write-char | |
47 | newline | |
48 | display | |
0113507e JG |
49 | write |
50 | ||
51 | &i/o make-i/o-error i/o-error? | |
52 | &i/o-read make-i/o-read-error i/o-read-error? | |
53 | &i/o-write make-i/o-write-error i/o-write-error? | |
54 | ||
55 | &i/o-invalid-position | |
56 | make-i/o-invalid-position-error | |
57 | i/o-invalid-position-error? | |
58 | i/o-error-position | |
59 | ||
60 | &i/o-filename | |
61 | make-i/o-filename-error | |
62 | i/o-filename-error? | |
63 | i/o-error-filename | |
64 | ||
65 | &i/o-file-protection | |
66 | make-i/o-file-protection-error | |
67 | i/o-file-protection-error? | |
68 | ||
69 | &i/o-file-is-read-only | |
70 | make-i/o-file-is-read-only-error | |
71 | i/o-file-is-read-only-error? | |
72 | ||
73 | &i/o-file-already-exists | |
74 | make-i/o-file-already-exists-error | |
75 | i/o-file-already-exists-error? | |
76 | ||
77 | &i/o-file-does-not-exist | |
78 | make-i/o-file-does-not-exist-error | |
79 | i/o-file-does-not-exist-error? | |
80 | ||
81 | &i/o-port | |
82 | make-i/o-port-error | |
83 | i/o-port-error? | |
84 | i/o-error-port) | |
85 | ||
a5484153 AR |
86 | (import (only (rnrs io ports) |
87 | call-with-port | |
2252321b | 88 | close-port |
a5484153 AR |
89 | open-file-input-port |
90 | open-file-output-port | |
91 | eof-object | |
2252321b AR |
92 | eof-object? |
93 | file-options | |
5dcbcfce | 94 | buffer-mode |
2252321b AR |
95 | native-transcoder |
96 | get-char | |
97 | lookahead-char | |
98 | get-datum | |
99 | put-char | |
100 | put-datum | |
101 | ||
a5484153 AR |
102 | input-port? |
103 | output-port?) | |
2252321b AR |
104 | (only (guile) |
105 | @@ | |
106 | current-input-port | |
107 | current-output-port | |
108 | current-error-port | |
109 | ||
110 | define* | |
111 | ||
112 | with-input-from-port | |
113 | with-output-to-port) | |
0113507e | 114 | (rnrs base (6)) |
50851f1d AR |
115 | (rnrs files (6)) ;for the condition types |
116 | ) | |
a5484153 | 117 | |
2252321b AR |
118 | (define display (@@ (rnrs io ports) display)) |
119 | ||
a5484153 AR |
120 | (define (call-with-input-file filename proc) |
121 | (call-with-port (open-file-input-port filename) proc)) | |
122 | ||
123 | (define (call-with-output-file filename proc) | |
124 | (call-with-port (open-file-output-port filename) proc)) | |
2252321b AR |
125 | |
126 | (define (with-input-from-file filename thunk) | |
127 | (call-with-input-file filename | |
128 | (lambda (port) (with-input-from-port port thunk)))) | |
129 | ||
130 | (define (with-output-to-file filename thunk) | |
131 | (call-with-output-file filename | |
132 | (lambda (port) (with-output-to-port port thunk)))) | |
133 | ||
134 | (define (open-input-file filename) | |
5dcbcfce MW |
135 | (open-file-input-port filename |
136 | (file-options) | |
137 | (buffer-mode block) | |
138 | (native-transcoder))) | |
2252321b AR |
139 | |
140 | (define (open-output-file filename) | |
5dcbcfce MW |
141 | (open-file-output-port filename |
142 | (file-options) | |
143 | (buffer-mode block) | |
144 | (native-transcoder))) | |
2252321b AR |
145 | |
146 | (define close-input-port close-port) | |
147 | (define close-output-port close-port) | |
148 | ||
149 | (define* (read-char #:optional (port (current-input-port))) | |
150 | (get-char port)) | |
151 | ||
152 | (define* (peek-char #:optional (port (current-input-port))) | |
153 | (lookahead-char port)) | |
154 | ||
155 | (define* (read #:optional (port (current-input-port))) | |
156 | (get-datum port)) | |
157 | ||
158 | (define* (write-char char #:optional (port (current-output-port))) | |
159 | (put-char port char)) | |
160 | ||
161 | (define* (newline #:optional (port (current-output-port))) | |
162 | (put-char port #\newline)) | |
163 | ||
164 | (define* (write object #:optional (port (current-output-port))) | |
165 | (put-datum port object)) | |
166 | ||
167 | ) |