author | Claus Gittinger <cg@exept.de> |
Fri, 03 Jan 1997 19:36:14 +0100 | |
changeset 2044 | dc50a505862f |
parent 1823 | 51ffb7231437 |
child 2045 | 1ad17ca6520f |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ReadWriteStream subclass:#ExternalStream |
|
1044
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
14 |
instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite |
820
6d934f5d6cbc
moved readErrorSignal / writeErrorSignal up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
791
diff
changeset
|
15 |
lastErrorNumber' |
1044
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
16 |
classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
17 |
InvalidModeSignal OpenErrorSignal StreamNotOpenSignal |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
18 |
InvalidOperationSignal' |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
19 |
poolDictionaries:'' |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
20 |
category:'Streams-External' |
1 | 21 |
! |
22 |
||
216 | 23 |
!ExternalStream primitiveDefinitions! |
1 | 24 |
%{ |
25 |
#include <stdio.h> |
|
437 | 26 |
#define _STDIO_H_INCLUDED_ |
27 |
||
10 | 28 |
#include <fcntl.h> |
437 | 29 |
#define _FCNTL_H_INCLUDED_ |
30 |
||
10 | 31 |
#include <errno.h> |
437 | 32 |
#define _ERRNO_H_INCLUDED_ |
42 | 33 |
|
1141 | 34 |
#ifdef LINUX |
35 |
/* use inline string macros */ |
|
36 |
# define __STRINGDEFS__ |
|
37 |
# include <linuxIntern.h> |
|
38 |
#endif |
|
39 |
||
42 | 40 |
#ifdef hpux |
41 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
|
42 |
#endif |
|
216 | 43 |
|
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
44 |
#ifndef SEEK_SET |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
45 |
# define SEEK_SET 0 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
46 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
47 |
#ifndef SEEK_CUR |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
48 |
# define SEEK_CUR 1 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
49 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
50 |
#ifndef SEEK_END |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
51 |
# define SEEK_END 2 |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
52 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
53 |
|
216 | 54 |
/* |
55 |
* stdio library requires an fseek before reading whenever a file |
|
56 |
* is open for read/write and the last operation was a write. |
|
57 |
* (also vice-versa). |
|
58 |
* All code should use the following macro before doing reads: |
|
59 |
*/ |
|
60 |
#define __READING__(f) \ |
|
1133 | 61 |
if ((__INST(didWrite) != false) \ |
62 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
2044 | 63 |
__INST(didWrite) = false; \ |
64 |
fseek(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 65 |
} |
66 |
||
67 |
#define __WRITING__(f) \ |
|
1133 | 68 |
if ((__INST(didWrite) != true) \ |
69 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
2044 | 70 |
__INST(didWrite) = true; \ |
71 |
fseek(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 72 |
} |
73 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
74 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
75 |
#define __READBYTE__(ret, f, buf, isBuffered) \ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
76 |
if (isBuffered) { \ |
2044 | 77 |
for (;;) { \ |
78 |
ret = getc(f); \ |
|
79 |
if (ret >= 0) { \ |
|
80 |
*(buf) = ret; \ |
|
81 |
ret = 1; \ |
|
82 |
} else if (ferror(f)) { \ |
|
83 |
if (errno == EINTR) { \ |
|
84 |
__HANDLE_INTERRUPTS__; \ |
|
85 |
clearerr(f); \ |
|
86 |
continue; \ |
|
87 |
} \ |
|
88 |
} else \ |
|
89 |
ret = 0; \ |
|
90 |
break; \ |
|
91 |
} \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
92 |
} else { \ |
2044 | 93 |
for (;;) { \ |
94 |
ret = read(fileno(f), buf, 1); \ |
|
95 |
if (ret >= 0 || errno != EINTR) \ |
|
96 |
break; \ |
|
97 |
__HANDLE_INTERRUPTS__; \ |
|
98 |
} \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
99 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
100 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
101 |
#define __READBYTES__(ret, f, buf, cnt, isBuffered) \ |
1464
6d533b5e5de3
Fix reads and writes with cnt==0.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
102 |
(ret) = 0; \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
103 |
if (isBuffered) { \ |
2044 | 104 |
int __offs = 0; \ |
105 |
while (__offs < (cnt)) { \ |
|
106 |
(ret) = getc(f); \ |
|
107 |
if ((ret) < 0) { \ |
|
108 |
if (ferror(f)) { \ |
|
109 |
if (errno == EINTR) { \ |
|
110 |
__HANDLE_INTERRUPTS__; \ |
|
111 |
clearerr(f); \ |
|
112 |
continue; \ |
|
113 |
} \ |
|
114 |
} else { \ |
|
115 |
(ret) = 0; \ |
|
116 |
} \ |
|
117 |
break; \ |
|
118 |
} \ |
|
119 |
(buf)[__offs++] = (ret); \ |
|
120 |
} \ |
|
121 |
if (__offs > 0) \ |
|
122 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
123 |
} else { \ |
2044 | 124 |
int __offs = 0; \ |
125 |
while (__offs < (cnt)) { \ |
|
126 |
(ret) = read(fileno(f), (buf)+__offs, (cnt)-__offs); \ |
|
127 |
if ((ret) <= 0) { \ |
|
128 |
if ((ret) < 0 && errno == EINTR) { \ |
|
129 |
__HANDLE_INTERRUPTS__; \ |
|
130 |
continue; \ |
|
131 |
} \ |
|
132 |
break; \ |
|
133 |
} \ |
|
134 |
__offs += (ret); \ |
|
135 |
} \ |
|
136 |
if (__offs > 0) \ |
|
137 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
138 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
139 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
140 |
#define __WRITEBYTE__(ret, f, buf, isBuffered) \ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
141 |
if (isBuffered) { \ |
2044 | 142 |
for (;;) { \ |
143 |
ret = putc(*(buf), f); \ |
|
144 |
if ((ret) >= 0) { \ |
|
145 |
(ret) = 1; \ |
|
146 |
} else if (ferror(f)) { \ |
|
147 |
if (errno == EINTR) { \ |
|
148 |
__HANDLE_INTERRUPTS__; \ |
|
149 |
clearerr(f); \ |
|
150 |
continue; \ |
|
151 |
} \ |
|
152 |
} else \ |
|
153 |
(ret) = 0; \ |
|
154 |
break; \ |
|
155 |
} \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
156 |
} else { \ |
2044 | 157 |
for (;;) { \ |
158 |
(ret) = write(fileno(f), buf, 1); \ |
|
159 |
if ((ret) >= 0 || errno != EINTR) \ |
|
160 |
break; \ |
|
161 |
__HANDLE_INTERRUPTS__; \ |
|
162 |
} \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
163 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
164 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
165 |
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered) \ |
1464
6d533b5e5de3
Fix reads and writes with cnt==0.
Stefan Vogel <sv@exept.de>
parents:
1463
diff
changeset
|
166 |
(ret) = 0; \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
167 |
if (isBuffered) { \ |
2044 | 168 |
int __offs = 0; \ |
169 |
while (__offs < (cnt)) { \ |
|
170 |
ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f); \ |
|
171 |
if ((ret) < 0) { \ |
|
172 |
if (ferror(f)) { \ |
|
173 |
if (errno == EINTR) { \ |
|
174 |
__HANDLE_INTERRUPTS__; \ |
|
175 |
clearerr(f); \ |
|
176 |
continue; \ |
|
177 |
} \ |
|
178 |
} else { \ |
|
179 |
(ret) = 0; \ |
|
180 |
} \ |
|
181 |
break; \ |
|
182 |
} \ |
|
183 |
__offs += (ret); \ |
|
184 |
} \ |
|
185 |
if (__offs > 0) \ |
|
186 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
187 |
} else { \ |
2044 | 188 |
int __offs = 0; \ |
189 |
while (__offs < (cnt)) { \ |
|
190 |
ret = write(fileno(f), (buf)+__offs, (cnt)-__offs); \ |
|
191 |
if (ret <= 0) { \ |
|
192 |
if (ret < 0 && errno == EINTR) { \ |
|
193 |
__HANDLE_INTERRUPTS__; \ |
|
194 |
continue; \ |
|
195 |
} \ |
|
196 |
break; \ |
|
197 |
} \ |
|
198 |
__offs += (ret); \ |
|
199 |
} \ |
|
200 |
if (__offs > 0) \ |
|
201 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
202 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
203 |
|
223 | 204 |
/* |
205 |
* on some systems errno is a macro ... check for it here |
|
206 |
*/ |
|
207 |
#ifndef errno |
|
208 |
extern errno; |
|
209 |
#endif |
|
210 |
||
1 | 211 |
%} |
188 | 212 |
! ! |
1 | 213 |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
214 |
!ExternalStream class methodsFor:'documentation'! |
22 | 215 |
|
88 | 216 |
copyright |
217 |
" |
|
218 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 219 |
All Rights Reserved |
88 | 220 |
|
221 |
This software is furnished under a license and may be used |
|
222 |
only in accordance with the terms of that license and with the |
|
223 |
inclusion of the above copyright notice. This software may not |
|
224 |
be provided or otherwise made available to, or used by, any |
|
225 |
other person. No title to or ownership of the software is |
|
226 |
hereby transferred. |
|
227 |
" |
|
228 |
! |
|
229 |
||
22 | 230 |
documentation |
231 |
" |
|
68 | 232 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
233 |
represent some file or communicationChannel of the underlying OperatingSystem. |
|
234 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 235 |
|
159 | 236 |
ExternalStreams can be in two modes: text- (the default) and binary-mode. |
68 | 237 |
In text-mode, the elements read/written are characters; |
238 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
|
239 |
in the range 0..255. |
|
22 | 240 |
|
68 | 241 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
242 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
243 |
is sent (in both modes). |
|
22 | 244 |
|
77 | 245 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 246 |
or just forgotten - in this case, the garbage collector will eventually collect the |
77 | 247 |
object AND a close will be performed automatically (but you will NOT know when this |
248 |
happens - so it is recommended, that you close your files when no longer needed). |
|
159 | 249 |
Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to |
77 | 250 |
some crash) the data will not be in the file, if unclosed. |
251 |
All streams understand the close message, so it never hurts to use it (it is defined as |
|
252 |
a noop in one of the superclasses). |
|
22 | 253 |
|
68 | 254 |
Most of the methods found here redefine inherited methods for better performance, |
255 |
since I/O from/to files should be fast. |
|
22 | 256 |
|
68 | 257 |
Recovering a snapshot: |
1295 | 258 |
not all streams can be restored to the state they had before - see the implementation of |
259 |
reOpen in subclasses for more information. |
|
260 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
261 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
262 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
263 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
264 |
if the contents changed in the meantime. |
|
265 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
266 |
||
267 |
[Instance variables:] |
|
268 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
269 |
filePointer <Integer> the unix FILE*; somehow mapped to an integer |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
270 |
(notice: not the fd) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
271 |
mode <Symbol> #readwrite, #readonly or #writeonly |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
272 |
buffered <Boolean> true, if buffered (i.e. collects characters - does |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
273 |
not output immediately) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
274 |
binary <Boolean> true if in binary mode (reads bytes instead of chars) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
275 |
useCRLF <Boolean> true, if lines should be terminated with crlf instead |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
276 |
of lf. (i.e. if file is an MSDOS-type file) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
277 |
hitEOF <Boolean> true, if EOF was reached |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
278 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
279 |
lastErrorNumber <Integer> the value of errno (only valid right after the error - |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
280 |
updated with next i/o operation) |
1295 | 281 |
|
282 |
[Class variables:] |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
283 |
Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
284 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
285 |
StreamErrorSignal <Signal> parent of all stream errors (see Stream class) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
286 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
287 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
288 |
InvalidModeSignal <Signal> raised on text I/O with binary-stream |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
289 |
or binary I/O with text-stream |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
290 |
OpenErrorSignal <Signal> raised if open fails |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
291 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
159 | 292 |
|
293 |
Additional notes: |
|
294 |
This class is implemented using the underlying stdio-c library package, which |
|
295 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
296 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
297 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
298 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
299 |
a complete rewrite for UnboundedStream ... |
|
325 | 300 |
|
188 | 301 |
Also, depending on the system, the stdio library behaves infriendly when signals |
302 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
303 |
is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns |
|
1295 | 304 |
an error and errno is set to EINTR. |
305 |
Thats what the ugly code around all getc-calls is for ... |
|
306 |
Since things get more and more ugly - we will rewrite ExternalStream |
|
307 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 308 |
|
309 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
310 |
this was bad design in the stdio lib (right from the very beginning), since its much |
|
311 |
harder to deal with this in the presence of lightweight processes, where errno gets |
|
312 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
313 |
to return errno as a negative number ...). |
|
314 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
315 |
and saves/restores the errno setting when switching to another thread. |
|
316 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
317 |
does not depend on those, but instead uses a portable private package). |
|
318 |
||
216 | 319 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
320 |
fseek whenever we are about to read after write and vice versa. |
|
321 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
322 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 323 |
|
324 |
[author:] |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
325 |
Claus Gittinger |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
326 |
Stefan Vogel (many, many fixes ...) |
1295 | 327 |
|
328 |
[see also:] |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
329 |
FileStream Socket PipeStream |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
330 |
Filename OperatingSystem |
22 | 331 |
" |
332 |
! ! |
|
333 |
||
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
334 |
!ExternalStream class methodsFor:'initialization'! |
1 | 335 |
|
336 |
initialize |
|
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
337 |
OpenErrorSignal isNil ifTrue:[ |
255 | 338 |
OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true. |
339 |
OpenErrorSignal nameClass:self message:#openErrorSignal. |
|
340 |
OpenErrorSignal notifierString:'open error'. |
|
341 |
||
159 | 342 |
InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false. |
343 |
InvalidReadSignal nameClass:self message:#invalidReadSignal. |
|
583 | 344 |
InvalidReadSignal notifierString:'read error'. |
159 | 345 |
|
346 |
InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false. |
|
347 |
InvalidWriteSignal nameClass:self message:#invalidWriteSignal. |
|
348 |
InvalidWriteSignal notifierString:'write error'. |
|
349 |
||
350 |
InvalidModeSignal := StreamErrorSignal newSignalMayProceed:false. |
|
351 |
InvalidModeSignal nameClass:self message:#invalidModeSignal. |
|
352 |
InvalidModeSignal notifierString:'binary/text mode mismatch'. |
|
353 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
354 |
InvalidOperationSignal := StreamErrorSignal newSignalMayProceed:false. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
355 |
InvalidOperationSignal nameClass:self message:#invalidOperationSignal. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
356 |
InvalidOperationSignal notifierString:'unsupported file operation'. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
357 |
|
159 | 358 |
StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false. |
359 |
StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal. |
|
360 |
StreamNotOpenSignal notifierString:'stream is not open'. |
|
361 |
]. |
|
362 |
||
31 | 363 |
Lobby isNil ifTrue:[ |
159 | 364 |
Lobby := Registry new. |
365 |
||
366 |
"want to get informed when returning from snapshot" |
|
367 |
ObjectMemory addDependent:self |
|
1 | 368 |
] |
369 |
! |
|
370 |
||
371 |
reOpenFiles |
|
372 |
"reopen all files (if possible) after a snapShot load" |
|
373 |
||
301 | 374 |
Lobby do:[:aFileStream | |
159 | 375 |
aFileStream reOpen |
1 | 376 |
] |
377 |
! |
|
378 |
||
1469 | 379 |
update:something with:aParameter from:changedObject |
1 | 380 |
"have to reopen files when returning from snapshot" |
381 |
||
382 |
something == #returnFromSnapshot ifTrue:[ |
|
2044 | 383 |
self reOpenFiles |
1 | 384 |
] |
1469 | 385 |
|
386 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 387 |
! ! |
388 |
||
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
389 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 390 |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
391 |
forFileDescriptor:aFileDescriptor mode:mode |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
392 |
|newStream| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
393 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
394 |
newStream := self basicNew. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
395 |
newStream text; buffered:true; useCRLF:false; clearEOF. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
396 |
^ newStream connectTo:aFileDescriptor withMode:mode |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
397 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
398 |
"this will probably fail (15 is a random FD): |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
399 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
400 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
401 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
402 |
s := ExternalStream forFileDescriptor:15 mode:'r'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
403 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
404 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
405 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
406 |
"Created: 29.2.1996 / 18:05:00 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
407 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
408 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
409 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
410 |
forReadWriteToFileDescriptor:aFileDescriptor |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
411 |
^ self forFileDescriptor:aFileDescriptor mode:'r+' |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
412 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
413 |
"this will probably fail (15 is a random FD): |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
414 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
415 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
416 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
417 |
s := ExternalStream forReadWriteToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
418 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
419 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
420 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
421 |
"Created: 29.2.1996 / 18:15:08 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
422 |
"Modified: 29.2.1996 / 18:16:25 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
423 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
424 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
425 |
forReadingFromFileDescriptor:aFileDescriptor |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
426 |
^ self forFileDescriptor:aFileDescriptor mode:'r' |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
427 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
428 |
"this will probably fail (15 is a random FD): |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
429 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
430 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
431 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
432 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
433 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
434 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
435 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
436 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
437 |
|pipe readFd writeFd rs ws| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
438 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
439 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
440 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
441 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
442 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
443 |
writeFd := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
444 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
445 |
'connect Smalltalk streams ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
446 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
447 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
448 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
449 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
450 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
451 |
[ |
1079 | 452 |
1 to:10 do:[:i | |
1422 | 453 |
Transcript showCR:rs nextLine |
1079 | 454 |
]. |
455 |
rs close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
456 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
457 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
458 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
459 |
[ |
1079 | 460 |
1 to:10 do:[:i | |
461 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
462 |
]. |
|
463 |
ws close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
464 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
465 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
466 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
467 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
468 |
"Created: 29.2.1996 / 18:14:24 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
469 |
"Modified: 29.2.1996 / 18:25:02 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
470 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
471 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
472 |
forWritingToFileDescriptor:aFileDescriptor |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
473 |
^ self forFileDescriptor:aFileDescriptor mode:'w' |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
474 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
475 |
"this will probably fail (15 is a random FD): |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
476 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
477 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
478 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
479 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
480 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
481 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
482 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
483 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
484 |
"Created: 29.2.1996 / 18:14:43 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
485 |
"Modified: 29.2.1996 / 18:15:54 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
486 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
487 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
488 |
makePipe |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
489 |
"return an array with two streams - the first one for reading, the second |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
490 |
for writing. This is the higher level equivalent of OperatingSystem>>makePipe." |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
491 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
492 |
|pipe rs ws| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
493 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
494 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
495 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
496 |
pipe notNil ifTrue:[ |
1079 | 497 |
rs := self forReadingFromFileDescriptor:(pipe at:1). |
498 |
ws := self forWritingToFileDescriptor:(pipe at:2). |
|
499 |
^ Array with:rs with:ws |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
500 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
501 |
^ nil |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
502 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
503 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
504 |
|pipe rs ws| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
505 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
506 |
pipe := ExternalStream makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
507 |
rs := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
508 |
ws := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
509 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
510 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
511 |
[ |
1079 | 512 |
1 to:10 do:[:i | |
1422 | 513 |
Transcript showCR:rs nextLine |
1079 | 514 |
]. |
515 |
rs close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
516 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
517 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
518 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
519 |
[ |
1079 | 520 |
1 to:10 do:[:i | |
521 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
522 |
]. |
|
523 |
ws close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
524 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
525 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
526 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
527 |
"Modified: 29.2.1996 / 18:28:36 / cg" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
528 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
529 |
|
612 | 530 |
new |
531 |
|newStream| |
|
532 |
||
533 |
newStream := self basicNew. |
|
534 |
newStream text; buffered:true; useCRLF:false; clearEOF. |
|
535 |
^ newStream |
|
536 |
! ! |
|
537 |
||
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
538 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 539 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
540 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
541 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
542 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
543 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
544 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
545 |
"Created: 2.7.1996 / 12:27:16 / stefan" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
546 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
547 |
|
612 | 548 |
invalidModeSignal |
549 |
"return the signal raised when doing text-I/O with a binary stream |
|
550 |
or binary-I/O with a text stream" |
|
551 |
||
552 |
^ InvalidModeSignal |
|
159 | 553 |
! |
554 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
555 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
556 |
"return the signal raised when an unsupported or invalid |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
557 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
558 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
559 |
^ InvalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
560 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
561 |
|
159 | 562 |
invalidReadSignal |
563 |
"return the signal raised when reading from writeonly streams" |
|
564 |
||
565 |
^ InvalidReadSignal |
|
566 |
! |
|
567 |
||
568 |
invalidWriteSignal |
|
569 |
"return the signal raised when writing to readonly streams" |
|
570 |
||
571 |
^ InvalidWriteSignal |
|
572 |
! |
|
573 |
||
612 | 574 |
openErrorSignal |
575 |
"return the signal raised when a file open failed" |
|
576 |
||
577 |
^ OpenErrorSignal |
|
578 |
! |
|
579 |
||
159 | 580 |
streamNotOpenSignal |
581 |
"return the signal raised on I/O with closed streams" |
|
582 |
||
583 |
^ StreamNotOpenSignal |
|
2 | 584 |
! ! |
585 |
||
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
586 |
!ExternalStream class methodsFor:'error handling'! |
92 | 587 |
|
588 |
lastErrorNumber |
|
159 | 589 |
"return the errno of the last error" |
92 | 590 |
|
591 |
^ LastErrorNumber |
|
159 | 592 |
|
593 |
" |
|
594 |
ExternalStream lastErrorNumber |
|
595 |
" |
|
92 | 596 |
! |
597 |
||
598 |
lastErrorString |
|
599 |
"return a message string describing the last error" |
|
600 |
||
601 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
602 |
||
603 |
" |
|
604 |
ExternalStream lastErrorString |
|
605 |
" |
|
606 |
! ! |
|
607 |
||
1 | 608 |
!ExternalStream methodsFor:'accessing'! |
609 |
||
612 | 610 |
binary |
611 |
"switch to binary mode - default is text" |
|
612 |
||
613 |
binary := true |
|
1 | 614 |
! |
615 |
||
616 |
buffered:aBoolean |
|
10 | 617 |
"turn buffering on or off - default is on" |
1 | 618 |
|
10 | 619 |
buffered := aBoolean |
1 | 620 |
! |
621 |
||
622 |
contents |
|
2 | 623 |
"return the contents of the file from the current position up-to |
624 |
the end. If the stream is in binary mode, a ByteArray containing |
|
625 |
the byte values is returned. |
|
626 |
In text-mode, a collection of strings, each representing one line, |
|
627 |
is returned." |
|
628 |
||
629 |
|text l chunks sizes chunk byteCount cnt bytes offset| |
|
630 |
||
631 |
binary ifTrue:[ |
|
159 | 632 |
"adding to a ByteArray produces quadratic time-space |
633 |
behavior - therefore we allocate chunks, and concatenate them |
|
634 |
at the end." |
|
635 |
||
636 |
chunks := OrderedCollection new. |
|
637 |
sizes := OrderedCollection new. |
|
638 |
byteCount := 0. |
|
639 |
[self atEnd] whileFalse:[ |
|
640 |
chunk := ByteArray uninitializedNew:4096. |
|
641 |
cnt := self nextBytes:(chunk size) into:chunk. |
|
642 |
cnt notNil ifTrue:[ |
|
643 |
chunks add:chunk. |
|
644 |
sizes add:cnt. |
|
645 |
byteCount := byteCount + cnt |
|
646 |
] |
|
647 |
]. |
|
648 |
||
649 |
"now, create one big ByteArray" |
|
650 |
bytes := ByteArray uninitializedNew:byteCount. |
|
651 |
offset := 1. |
|
652 |
1 to:chunks size do:[:index | |
|
653 |
chunk := chunks at:index. |
|
654 |
cnt := sizes at:index. |
|
655 |
bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk. |
|
656 |
offset := offset + cnt |
|
657 |
]. |
|
658 |
^ bytes |
|
2 | 659 |
]. |
1 | 660 |
|
244 | 661 |
text := StringCollection new. |
1 | 662 |
[self atEnd] whileFalse:[ |
159 | 663 |
l := self nextLine. |
406 | 664 |
l isNil ifTrue:[ |
665 |
^ text |
|
666 |
]. |
|
667 |
text add:l |
|
1 | 668 |
]. |
669 |
^ text |
|
670 |
! |
|
671 |
||
612 | 672 |
contentsOfEntireFile |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
673 |
"ST-80 compatibility: return contents as String" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
674 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
675 |
^ self contents asString. |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
676 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
677 |
"Modified: 3.7.1996 / 13:22:16 / stefan" |
2 | 678 |
! |
679 |
||
612 | 680 |
contentsSpecies |
681 |
"return the kind of object to be returned by sub-collection builders |
|
682 |
(such as upTo)" |
|
159 | 683 |
|
684 |
binary ifTrue:[ |
|
612 | 685 |
^ ByteArray |
159 | 686 |
]. |
612 | 687 |
^ String |
2 | 688 |
! |
689 |
||
612 | 690 |
fileDescriptor |
691 |
"return the fileDescriptor of the receiver - |
|
692 |
notice: this one returns the underlying OSs fileDescriptor - |
|
693 |
this may not be available on all platforms (i.e. non unix systems)." |
|
1 | 694 |
|
695 |
%{ /* NOCONTEXT */ |
|
696 |
||
697 |
FILE *f; |
|
612 | 698 |
OBJ fp; |
699 |
||
1133 | 700 |
if ((fp = __INST(filePointer)) != nil) { |
612 | 701 |
f = __FILEVal(fp); |
702 |
RETURN ( __MKSMALLINT(fileno(f)) ); |
|
1 | 703 |
} |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
704 |
%}. |
612 | 705 |
^ self errorNotOpen |
706 |
! |
|
707 |
||
826
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
708 |
fileDescriptor:anInteger withMode:openMode |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
709 |
"set the filePointer from the receiver based on the fileDescriptor- |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
710 |
notice: this one is based on the underlying OSs fileDescriptor - |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
711 |
this may not be available on all platforms (i.e. non unix systems)." |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
712 |
|
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
713 |
%{ /* NOCONTEXT */ |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
714 |
|
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
715 |
FILE *f; |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
716 |
OBJ fp; |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
717 |
|
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
718 |
if (__isSmallInteger(anInteger) && |
872 | 719 |
__isString(openMode) && |
720 |
(f = fdopen(__intVal(anInteger), __stringVal(openMode))) != 0 |
|
826
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
721 |
) { |
1133 | 722 |
__INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp); |
872 | 723 |
RETURN (self); |
826
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
724 |
} |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
725 |
%}. |
826
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
726 |
^ self primitiveFailed |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
727 |
! |
b271ea453f6a
New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents:
820
diff
changeset
|
728 |
|
612 | 729 |
filePointer |
730 |
"return the filePointer of the receiver - |
|
731 |
notice: for portability stdio is used; this means you will get |
|
732 |
a FILE * - not a fileDescriptor. |
|
733 |
(what you really get is a corresponding integer). |
|
734 |
You cannot do much with the returned value |
|
735 |
- except passing it to a primitive, for example." |
|
736 |
||
737 |
^ filePointer |
|
738 |
! |
|
739 |
||
740 |
readonly |
|
741 |
"set access mode to readonly" |
|
742 |
||
743 |
mode := #readonly |
|
744 |
! |
|
745 |
||
746 |
readwrite |
|
747 |
"set access mode to readwrite" |
|
748 |
||
749 |
mode := #readwrite |
|
750 |
! |
|
751 |
||
752 |
text |
|
753 |
"switch to text mode - default is text" |
|
754 |
||
755 |
binary := false |
|
756 |
! |
|
757 |
||
758 |
useCRLF:aBoolean |
|
759 |
"turn on or off CRLF sending (instead of LF only) - default is off" |
|
760 |
||
761 |
useCRLF := aBoolean |
|
1 | 762 |
! |
763 |
||
612 | 764 |
writeonly |
765 |
"set access mode to writeonly" |
|
766 |
||
767 |
mode := #writeonly |
|
768 |
! ! |
|
769 |
||
770 |
!ExternalStream methodsFor:'error handling'! |
|
771 |
||
772 |
argumentMustBeCharacter |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
773 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
774 |
|
612 | 775 |
"report an error, that the argument must be a character" |
776 |
||
777 |
^ self error:'argument must be a character' |
|
778 |
! |
|
779 |
||
780 |
argumentMustBeInteger |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
781 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
782 |
|
612 | 783 |
"report an error, that the argument must be an integer" |
784 |
||
785 |
^ self error:'argument must be an integer' |
|
77 | 786 |
! |
787 |
||
612 | 788 |
argumentMustBeString |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
789 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
790 |
|
612 | 791 |
"report an error, that the argument must be a string" |
792 |
||
793 |
^ self error:'argument must be a string' |
|
794 |
! |
|
795 |
||
796 |
errorBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
797 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
798 |
|
612 | 799 |
"report an error, that the stream is in binary mode" |
800 |
||
801 |
^ InvalidModeSignal |
|
802 |
raiseRequestWith:self |
|
803 |
errorString:(self class name , ' is in binary mode') |
|
804 |
in:thisContext sender |
|
805 |
! |
|
806 |
||
807 |
errorNotBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
808 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
809 |
|
612 | 810 |
"report an error, that the stream is not in binary mode" |
811 |
||
812 |
^ InvalidModeSignal |
|
813 |
raiseRequestWith:self |
|
814 |
errorString:(self class name , ' is not in binary mode') |
|
815 |
in:thisContext sender |
|
1 | 816 |
! |
817 |
||
612 | 818 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
819 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
820 |
|
612 | 821 |
"report an error, that the stream is not in buffered mode" |
822 |
||
823 |
^ StreamErrorSignal |
|
824 |
raiseRequestWith:self |
|
825 |
errorString:(self class name , ' is unbuffered - operation not allowed') |
|
826 |
in:thisContext sender |
|
827 |
! |
|
828 |
||
829 |
errorNotOpen |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
830 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
831 |
|
612 | 832 |
"report an error, that the stream has not been opened" |
833 |
||
834 |
^ StreamNotOpenSignal |
|
835 |
raiseRequestWith:self |
|
836 |
errorString:(self class name , ' not open') |
|
837 |
in:thisContext sender |
|
838 |
! |
|
839 |
||
840 |
errorOpen |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
841 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
842 |
|
612 | 843 |
"report an error, that the stream is already opened" |
844 |
||
845 |
^ OpenErrorSignal |
|
846 |
raiseRequestWith:self |
|
847 |
errorString:(self class name , ' is already open') |
|
848 |
in:thisContext sender |
|
849 |
! |
|
850 |
||
851 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
852 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
853 |
|
612 | 854 |
"report an error, that the stream is a readOnly stream" |
855 |
||
856 |
^ InvalidWriteSignal |
|
857 |
raiseRequestWith:self |
|
858 |
errorString:(self class name , ' is readonly') |
|
859 |
in:thisContext sender |
|
860 |
! |
|
861 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
862 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
863 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
864 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
865 |
"report an error, that some unsupported operation was attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
866 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
867 |
^ InvalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
868 |
raiseRequestWith:self |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
869 |
errorString:'unsupported operation' |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
870 |
in:thisContext sender |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
871 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
872 |
|
612 | 873 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
874 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
875 |
|
612 | 876 |
"report an error, that the stream is a writeOnly stream" |
877 |
||
878 |
^ InvalidReadSignal |
|
879 |
raiseRequestWith:self |
|
880 |
errorString:(self class name , ' is writeonly') |
|
881 |
in:thisContext sender |
|
2 | 882 |
! |
883 |
||
612 | 884 |
ioError |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
885 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
886 |
|
612 | 887 |
"report an error, that some I/O error occured" |
888 |
||
889 |
^ StreamErrorSignal |
|
890 |
raiseRequestWith:self |
|
891 |
errorString:('I/O error: ' , self lastErrorString) |
|
892 |
in:thisContext sender |
|
893 |
! |
|
894 |
||
895 |
lastErrorNumber |
|
896 |
"return the last error" |
|
897 |
||
898 |
^ lastErrorNumber |
|
899 |
! |
|
900 |
||
901 |
lastErrorString |
|
902 |
"return a message string describing the last error" |
|
903 |
||
904 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
905 |
^ 'I/O error' |
|
906 |
]. |
|
907 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 908 |
! |
909 |
||
612 | 910 |
openError |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
911 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
912 |
|
612 | 913 |
"report an error, that the open failed" |
914 |
||
915 |
^ OpenErrorSignal |
|
916 |
raiseRequestWith:self |
|
917 |
errorString:('error on open: ' , self lastErrorString) |
|
918 |
in:thisContext sender |
|
919 |
! |
|
920 |
||
921 |
readError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
922 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
923 |
|
612 | 924 |
"report an error, that some read error occured" |
925 |
||
926 |
^ ReadErrorSignal |
|
927 |
raiseRequestWith:self |
|
928 |
errorString:('read error: ' , self lastErrorString) |
|
929 |
in:thisContext sender |
|
930 |
! |
|
931 |
||
932 |
writeError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
933 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
934 |
|
612 | 935 |
"report an error, that some write error occured" |
936 |
||
937 |
^ WriteErrorSignal |
|
938 |
raiseRequestWith:self |
|
939 |
errorString:('write error: ' , self lastErrorString) |
|
940 |
in:thisContext sender |
|
941 |
! ! |
|
942 |
||
943 |
!ExternalStream methodsFor:'instance release'! |
|
944 |
||
945 |
closeFile |
|
946 |
"low level close - may be redefined in subclasses" |
|
2 | 947 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
948 |
%{ |
216 | 949 |
OBJ fp; |
2 | 950 |
|
1133 | 951 |
if ((fp = __INST(filePointer)) != nil) { |
952 |
__INST(filePointer) = nil; |
|
362 | 953 |
__BEGIN_INTERRUPTABLE__ |
612 | 954 |
fclose(__FILEVal(fp)); |
362 | 955 |
__END_INTERRUPTABLE__ |
10 | 956 |
} |
957 |
%} |
|
958 |
! |
|
959 |
||
612 | 960 |
disposed |
961 |
"some Stream has been collected - close the file if not already done" |
|
962 |
||
963 |
self closeFile |
|
964 |
! |
|
965 |
||
966 |
setFilePointer:anInteger |
|
967 |
filePointer := anInteger |
|
1 | 968 |
! |
969 |
||
612 | 970 |
shallowCopyForFinalization |
971 |
"return a copy for finalization-registration; |
|
972 |
since all we need at finalization time is the fileDescriptor, |
|
973 |
a cheaper copy is possible." |
|
974 |
||
975 |
^ self class basicNew setFilePointer:filePointer |
|
1 | 976 |
! |
977 |
||
612 | 978 |
shutDown |
979 |
"close the stream - added for protocol compatibility with PipeStream. |
|
980 |
see comment there" |
|
981 |
||
1642
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
982 |
filePointer isNil ifTrue:[^ self]. |
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
983 |
Lobby unregister:self. |
612 | 984 |
self closeFile |
1642
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
985 |
|
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
986 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
1 | 987 |
! ! |
988 |
||
2 | 989 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 990 |
|
991 |
nextLine |
|
992 |
"read the next line (characters up to newline). |
|
993 |
Return a string containing those characters excluding the newline. |
|
994 |
If the previous-to-last character is a cr, this is also removed, |
|
68 | 995 |
so its possible to read alien (i.e. ms-dos) text as well. |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
996 |
The line must be shorter than 16K characters - otherwise its truncated." |
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
997 |
|
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
998 |
%{ /* STACK:17000 */ |
1 | 999 |
|
1000 |
FILE *f; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1001 |
int len, ret; |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
1002 |
char buffer[16*1024]; |
521
70533ec40482
use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
1003 |
char *rslt, *nextPtr, *limit; |
22 | 1004 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
1005 |
int _buffered; |
216 | 1006 |
OBJ fp; |
1 | 1007 |
|
1133 | 1008 |
__INST(lastErrorNumber) = nil; |
1009 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1010 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1011 |
&& (__INST(binary) != true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1012 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1013 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1014 |
buffer[0] = 0; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1015 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1016 |
_buffered = (__INST(buffered) == true); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1017 |
if (_buffered) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1018 |
__READING__(f); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1019 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1020 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1021 |
rslt = nextPtr = buffer; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1022 |
limit = buffer + sizeof(buffer) - 2; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1023 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1024 |
for (;;) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1025 |
__READBYTE__(ret, f, nextPtr, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1026 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1027 |
if (nextPtr == buffer) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1028 |
rslt = NULL; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1029 |
if (ret == 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1030 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1031 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1032 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1033 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1034 |
goto err; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1035 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1036 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1037 |
if (*nextPtr == '\n') { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1038 |
*nextPtr = '\0'; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1039 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1040 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1041 |
nextPtr++; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1042 |
if (nextPtr >= limit) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1043 |
*nextPtr = '\0'; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1044 |
fprintf(stderr, "EXTSTREAM: line truncated in nextLine\n"); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1045 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1046 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1047 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1048 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1049 |
if (rslt != NULL) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1050 |
len = nextPtr-buffer; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1051 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1052 |
if (__INST(position) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1053 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1054 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1055 |
/* remove EOL character */ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1056 |
if (len != 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1057 |
if (buffer[len-1] == '\n') { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1058 |
buffer[--len] = '\0'; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1059 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1060 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1061 |
buffer[--len] = '\0'; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1062 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1063 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1642
diff
changeset
|
1064 |
RETURN ( __MKSTRING_L(buffer, len) ); |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1065 |
} |
1 | 1066 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1067 |
err: ; |
159 | 1068 |
%}. |
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1069 |
hitEOF ifTrue:[^ self pastEnd]. |
159 | 1070 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2 | 1071 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
1 | 1072 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
2 | 1073 |
self errorBinary |
1 | 1074 |
! |
1075 |
||
1076 |
nextPutLine:aString |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1077 |
"write the characters in aString and append a newline or CRLF if useCRLF is set" |
1 | 1078 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1079 |
%{ |
1 | 1080 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1081 |
int len, cnt, len1, _buffered; |
216 | 1082 |
OBJ pos, fp; |
537
dc4dad8a5ddd
many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1083 |
char *cp; |
1 | 1084 |
|
1133 | 1085 |
__INST(lastErrorNumber) = nil; |
1086 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1087 |
&& (__INST(mode) != @symbol(readonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1088 |
&& (__INST(binary) != true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1089 |
&& __isString(aString) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1090 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1091 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1092 |
len = __stringSize(aString); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1093 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1094 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1095 |
__WRITING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1096 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1097 |
__WRITEBYTES__(cnt, f, __stringVal(aString), len, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1098 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1099 |
if (cnt == len) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1100 |
len1 = len; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1101 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1102 |
if (__INST(useCRLF) == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1103 |
cp = "\r\n"; len = 2; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1104 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1105 |
cp = "\n"; len = 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1106 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1107 |
__WRITEBYTES__(cnt, f, cp, len, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1108 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1109 |
if (cnt > 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1110 |
pos = __INST(position); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1111 |
if (pos != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1112 |
__INST(position) = __MKSMALLINT(__intVal(pos)+len1+cnt); |
537
dc4dad8a5ddd
many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1113 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1114 |
RETURN ( self ); |
159 | 1115 |
} |
1116 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1117 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
1 | 1118 |
} |
159 | 1119 |
%}. |
1120 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
1121 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2044 | 1122 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
1123 |
binary ifTrue:[^ self errorBinary]. |
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
1124 |
|
68 | 1125 |
super nextPutAll:aString. |
1126 |
self cr. |
|
1 | 1127 |
! |
1128 |
||
1129 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 1130 |
"read from aStream up to and including a line starting with aStringOrNil |
22 | 1131 |
and append it to self. |
159 | 1132 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 1133 |
|
22 | 1134 |
If aStringOrNil is nil or not matched, copy preceeds to the end. |
1135 |
(this allows for example to read a Socket and transfer the data quickly |
|
1136 |
into a file - without creating zillions of temporary strings)" |
|
1 | 1137 |
|
159 | 1138 |
|srcFilePointer readError| |
1 | 1139 |
|
1140 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
1141 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1142 |
srcFilePointer := aStream filePointer. |
|
1143 |
srcFilePointer isNil ifTrue:[^ aStream errorNotOpen]. |
|
12 | 1144 |
|
1145 |
%{ /* STACK:2000 */ |
|
22 | 1146 |
|
1 | 1147 |
FILE *dst, *src; |
1148 |
char *matchString; |
|
1149 |
int matchLen = 0; |
|
12 | 1150 |
char buffer[1024]; |
1 | 1151 |
|
1133 | 1152 |
__INST(lastErrorNumber) = nil; |
249 | 1153 |
if (__isSmallInteger(srcFilePointer)) { |
159 | 1154 |
if ((aStringOrNil == nil) || __isString(aStringOrNil)) { |
1155 |
if (aStringOrNil != nil) { |
|
1133 | 1156 |
matchString = (char *) __stringVal(aStringOrNil); |
1157 |
matchLen = __stringSize(aStringOrNil); |
|
159 | 1158 |
} |
1133 | 1159 |
dst = __FILEVal(__INST(filePointer)); |
475
b57530aa1b0a
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
471
diff
changeset
|
1160 |
src = __FILEVal(srcFilePointer); |
362 | 1161 |
__BEGIN_INTERRUPTABLE__ |
159 | 1162 |
errno = 0; |
1163 |
||
216 | 1164 |
__WRITING__(dst) |
159 | 1165 |
|
1166 |
for (;;) { |
|
370 | 1167 |
if (fgets(buffer, sizeof(buffer)-1, src) == NULL) { |
159 | 1168 |
if (ferror(src)) { |
359 | 1169 |
readError = __MKSMALLINT(errno); |
362 | 1170 |
__END_INTERRUPTABLE__ |
159 | 1171 |
goto err; |
1172 |
} |
|
1173 |
break; |
|
1174 |
} |
|
1175 |
if (fputs(buffer, dst) == EOF) { |
|
1176 |
if (ferror(dst)) { |
|
1133 | 1177 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
362 | 1178 |
__END_INTERRUPTABLE__ |
159 | 1179 |
goto err; |
1180 |
} |
|
1181 |
break; |
|
1182 |
} |
|
12 | 1183 |
#ifndef OLD |
1133 | 1184 |
if (__INST(buffered) == false) { |
159 | 1185 |
fflush(dst); |
1186 |
} |
|
12 | 1187 |
#endif |
159 | 1188 |
if (matchLen) { |
1189 |
if (strncmp(matchString, buffer, matchLen) == 0) |
|
1190 |
break; |
|
1191 |
} |
|
1192 |
} |
|
362 | 1193 |
__END_INTERRUPTABLE__ |
1133 | 1194 |
__INST(position) = nil; |
159 | 1195 |
RETURN (self); |
1196 |
} |
|
1 | 1197 |
} |
159 | 1198 |
err: ; |
1199 |
%}. |
|
1200 |
readError ifTrue:[ |
|
1201 |
aStream setLastErrorNumber:readError. |
|
1202 |
^ aStream readError |
|
1203 |
]. |
|
1204 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
10 | 1205 |
buffered ifFalse:[^ self errorNotBuffered]. |
159 | 1206 |
" |
1207 |
argument error |
|
1208 |
" |
|
1 | 1209 |
^ self primitiveFailed |
1210 |
! |
|
1211 |
||
1212 |
peekForLineStartingWith:aString |
|
1213 |
"read ahead for next line starting with aString; |
|
159 | 1214 |
return the line-string if found, or nil if EOF is encountered. |
1215 |
If matched, not advance position behond that line |
|
1216 |
i.e. nextLine will read the matched line. |
|
1217 |
If not matched, reposition to original position for firther reading." |
|
1 | 1218 |
|
1219 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1220 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2 | 1221 |
binary ifTrue:[^ self errorBinary]. |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1222 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 1223 |
|
1224 |
%{ /* STACK: 2000 */ |
|
1 | 1225 |
FILE *f; |
1226 |
int l; |
|
12 | 1227 |
char buffer[1024]; |
1 | 1228 |
char *cp; |
1229 |
char *matchString; |
|
92 | 1230 |
int firstpos = -1, lastpos; |
1 | 1231 |
|
1133 | 1232 |
__INST(lastErrorNumber) = nil; |
54 | 1233 |
if (__isString(aString)) { |
1133 | 1234 |
matchString = (char *) __stringVal(aString); |
1235 |
l = __stringSize(aString); |
|
1236 |
||
1237 |
f = __FILEVal(__INST(filePointer)); |
|
216 | 1238 |
__READING__(f) |
159 | 1239 |
|
1240 |
for (;;) { |
|
1241 |
lastpos = ftell(f); |
|
1242 |
if (firstpos == -1) firstpos = lastpos; |
|
1243 |
||
362 | 1244 |
__BEGIN_INTERRUPTABLE__ |
159 | 1245 |
do { |
370 | 1246 |
cp = fgets(buffer, sizeof(buffer)-1, f); |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1247 |
} while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1)); |
370 | 1248 |
buffer[sizeof(buffer)-1] = '\0'; |
362 | 1249 |
__END_INTERRUPTABLE__ |
159 | 1250 |
|
1251 |
if (cp == NULL) { |
|
1252 |
if (ferror(f)) { |
|
1133 | 1253 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
159 | 1254 |
goto err; |
1255 |
} else { |
|
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1256 |
fseek(f, firstpos, SEEK_SET); |
159 | 1257 |
RETURN (nil); |
1258 |
} |
|
1259 |
} |
|
1260 |
if (strncmp(cp, matchString, l) == 0) { |
|
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1261 |
fseek(f, lastpos, SEEK_SET); |
159 | 1262 |
break; |
1263 |
} |
|
1264 |
} |
|
1265 |
/* remove EOL character */ |
|
1266 |
cp = buffer; |
|
1267 |
while (*cp && (*cp != '\n')) cp++; |
|
1268 |
*cp = '\0'; |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1642
diff
changeset
|
1269 |
RETURN ( __MKSTRING(buffer) ); |
1 | 1270 |
} |
159 | 1271 |
err: ; |
1272 |
%}. |
|
1273 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
|
1274 |
^ self argumentMustBeString |
|
1 | 1275 |
! |
1276 |
||
1277 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
1278 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
1279 |
return the index in aCollection if found, nil otherwise.. |
|
1280 |
If no match, do not change position; otherwise advance right before the |
|
1281 |
matched line so that nextLine will return this line." |
|
1282 |
||
1283 |
|line startPos linePos index| |
|
1284 |
||
1285 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1286 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2 | 1287 |
binary ifTrue:[^ self errorBinary]. |
1288 |
||
1 | 1289 |
startPos := self position. |
1290 |
[self atEnd] whileFalse:[ |
|
159 | 1291 |
linePos := self position. |
1292 |
line := self nextLine. |
|
1293 |
line notNil ifTrue:[ |
|
1294 |
index := 1. |
|
1295 |
aCollectionOfStrings do:[:prefix | |
|
1296 |
(line startsWith:prefix) ifTrue:[ |
|
1297 |
self position:linePos. |
|
1298 |
^ index |
|
1299 |
]. |
|
1300 |
index := index + 1 |
|
1301 |
] |
|
1302 |
] |
|
1 | 1303 |
]. |
1304 |
self position:startPos. |
|
1305 |
^ nil |
|
1306 |
! ! |
|
1307 |
||
612 | 1308 |
!ExternalStream methodsFor:'misc functions'! |
1309 |
||
1310 |
async:aBoolean |
|
779 | 1311 |
"set/clear the async attribute - if set, the availability of data on |
612 | 1312 |
the receiver will trigger an ioInterrupt. |
779 | 1313 |
If cleared (which is the default) no special notification is made. |
1314 |
Notice: not every OS supports this - check with OS>>supportsIOInterrupts before" |
|
92 | 1315 |
|
1316 |
|fd| |
|
1317 |
||
159 | 1318 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
92 | 1319 |
fd := self fileDescriptor. |
612 | 1320 |
aBoolean ifTrue:[ |
1321 |
^ OperatingSystem enableIOInterruptsOn:fd |
|
1322 |
]. |
|
1323 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
92 | 1324 |
! |
1325 |
||
612 | 1326 |
backStep |
1327 |
"step back one element - |
|
1328 |
redefined, since position is redefined here" |
|
1329 |
||
1330 |
self position:(self position - 1) |
|
362 | 1331 |
! |
1332 |
||
612 | 1333 |
blocking:aBoolean |
1334 |
"set/clear the blocking attribute - if set (which is the default) |
|
1335 |
a read (using next) on the receiver will block until data is available. |
|
1336 |
If cleared, a read operation will immediately return with a value of |
|
1337 |
nil." |
|
92 | 1338 |
|
159 | 1339 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
612 | 1340 |
^ OperatingSystem setBlocking:aBoolean on:(self fileDescriptor) |
1341 |
! |
|
1342 |
||
1343 |
close |
|
1344 |
"close the stream - tell operating system" |
|
1345 |
||
1346 |
filePointer isNil ifTrue:[^ self]. |
|
1347 |
Lobby unregister:self. |
|
1348 |
self closeFile. |
|
1349 |
filePointer := nil |
|
1350 |
! |
|
1351 |
||
1352 |
create |
|
1353 |
"create the stream |
|
1354 |
- this must be redefined in subclass" |
|
1355 |
||
1356 |
^ self subclassResponsibility |
|
1357 |
! |
|
1358 |
||
1359 |
ioctl:ioctlNumber |
|
1360 |
"to provide a simple ioctl facility - an ioctl is performed |
|
1361 |
on the underlying file; no arguments are passed." |
|
1362 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1363 |
%{ |
791 | 1364 |
#ifndef MSDOS_LIKE |
612 | 1365 |
FILE *f; |
1366 |
int ret, ioNum, ioArg; |
|
1367 |
OBJ fp; |
|
1368 |
||
1133 | 1369 |
__INST(lastErrorNumber) = nil; |
1370 |
if ((fp = __INST(filePointer)) != nil) { |
|
612 | 1371 |
if (__isSmallInteger(ioctlNumber)) { |
1372 |
ioNum = __intVal(ioctlNumber); |
|
1373 |
f = __FILEVal(fp); |
|
1374 |
||
1375 |
__BEGIN_INTERRUPTABLE__ |
|
1376 |
do { |
|
1304
60d726d6d526
clear errnos before read/write
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1377 |
errno = 0; |
612 | 1378 |
ret = ioctl(fileno(f), ioNum); |
1379 |
} while ((ret < 0) && (errno == EINTR)); |
|
1380 |
__END_INTERRUPTABLE__ |
|
1381 |
||
1382 |
if (ret >= 0) { |
|
1383 |
RETURN ( __MKSMALLINT(ret) ); |
|
1384 |
} |
|
1133 | 1385 |
__INST(position) = nil; |
1386 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 1387 |
} |
1388 |
} |
|
791 | 1389 |
#endif |
612 | 1390 |
%}. |
1391 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
1392 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1393 |
" |
|
1394 |
ioctl-number is not an integer |
|
791 | 1395 |
or the system does not support ioctl (MSDOS) |
612 | 1396 |
" |
1397 |
^ self primitiveFailed |
|
1398 |
! |
|
1399 |
||
1400 |
ioctl:ioctlNumber with:arg |
|
1401 |
"to provide a simple ioctl facility - an ioctl is performed |
|
1402 |
on the underlying file; the argument is passed as argument. |
|
1403 |
If the argument is a number, its directly passed; if its a |
|
1404 |
kind of ByteArray (ByteArray, String or Structure) a pointer to |
|
1405 |
the data is passed. This allows performing most ioctls - however, |
|
1406 |
it might be tricky to setup the buffer." |
|
1407 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1408 |
%{ |
791 | 1409 |
#ifndef MSDOS_LIKE |
612 | 1410 |
FILE *f; |
1411 |
int ret, ioNum; |
|
1412 |
OBJ fp; |
|
1413 |
||
1133 | 1414 |
__INST(lastErrorNumber) = nil; |
1415 |
if ((fp = __INST(filePointer)) != nil) { |
|
612 | 1416 |
if (__isSmallInteger(ioctlNumber) |
1417 |
&& (__isSmallInteger(arg) || __isBytes(arg))) { |
|
1418 |
f = __FILEVal(fp); |
|
1419 |
ioNum = __intVal(ioctlNumber); |
|
1420 |
||
1421 |
__BEGIN_INTERRUPTABLE__ |
|
1422 |
do { |
|
1304
60d726d6d526
clear errnos before read/write
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1423 |
errno = 0; |
612 | 1424 |
if (__isSmallInteger(arg)) { |
1425 |
ret = ioctl(fileno(f), ioNum, __intVal(arg)); |
|
1426 |
} else { |
|
1427 |
ret = ioctl(fileno(f), ioNum, __ByteArrayInstPtr(arg)->ba_element); |
|
1428 |
} |
|
1429 |
} while ((ret < 0) && (errno == EINTR)); |
|
1430 |
__END_INTERRUPTABLE__ |
|
1431 |
||
1432 |
if (ret >= 0) { |
|
1433 |
RETURN ( __MKSMALLINT(ret) ); |
|
1434 |
} |
|
1133 | 1435 |
__INST(position) = nil; |
1436 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 1437 |
} |
1438 |
} |
|
791 | 1439 |
#endif |
612 | 1440 |
%}. |
1441 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
1442 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1443 |
" |
|
1444 |
ioctl-number is not an integer or argument is not byteArray-like |
|
791 | 1445 |
or the system does not support ioctl (MSDOS) |
612 | 1446 |
" |
1447 |
^ self primitiveFailed |
|
1448 |
! |
|
1449 |
||
1450 |
open |
|
1451 |
"open the stream |
|
1452 |
- this must be redefined in subclass" |
|
1453 |
||
1454 |
^ self subclassResponsibility |
|
1455 |
! |
|
1456 |
||
1457 |
position |
|
1458 |
"return the position |
|
1459 |
- this must be redefined in subclass" |
|
1460 |
||
1461 |
^ self subclassResponsibility |
|
1462 |
! |
|
1463 |
||
1464 |
position:anInteger |
|
1465 |
"set the position |
|
1466 |
- this must be redefined in subclass" |
|
1467 |
||
1468 |
^ self subclassResponsibility |
|
1469 |
! |
|
1470 |
||
1471 |
reset |
|
1472 |
"set the read position to the beginning of the collection" |
|
1473 |
||
1474 |
self position:"0" 1 |
|
1475 |
! |
|
1476 |
||
1044
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
1477 |
setToEnd |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
1478 |
"redefined since it must be implemented differently" |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
1479 |
|
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
1480 |
^ self subclassResponsibility |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
1481 |
! |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
1482 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1483 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1484 |
"truncate the underlying OS file to newSize. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1485 |
Warning: this may not be implemented on all platforms." |
1066
cffbbdea7e01
care for GC while being interruptable
Claus Gittinger <cg@exept.de>
parents:
1048
diff
changeset
|
1486 |
|
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
1487 |
%{ |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1488 |
#ifdef HAS_FTRUNCATE |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1489 |
FILE *f; |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1490 |
OBJ fp; |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1491 |
|
1133 | 1492 |
if (((fp = __INST(filePointer)) != nil) |
1493 |
&& (__INST(mode) != @symbol(readonly))) { |
|
1079 | 1494 |
if (__isSmallInteger(newSize)) { |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1495 |
f = __FILEVal(fp); |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1496 |
|
1133 | 1497 |
if (__INST(buffered) == true) { |
1079 | 1498 |
__READING__(f) |
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1499 |
fflush(f); |
1079 | 1500 |
fseek(f, 0L, SEEK_END); /* needed in stdio */ |
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1501 |
} |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1502 |
ftruncate(fileno(f), __intVal(newSize)); |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1503 |
RETURN (self); |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1504 |
} |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1505 |
} |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1506 |
#endif |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1507 |
%}. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1508 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1509 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1510 |
^ self errorUnsupportedOperation |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1511 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1512 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1513 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1514 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1515 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1516 |
s next:1000 put:$a. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1517 |
s truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1518 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1519 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1520 |
('test' asFilename fileSize) printNL |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1521 |
" |
612 | 1522 |
! ! |
1523 |
||
1524 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
1525 |
||
1526 |
nextByte |
|
1527 |
"read the next byte and return it as an Integer; return nil on error. |
|
1528 |
This is allowed in both text and binary modes, always returning the |
|
1529 |
bytes binary value as an integer in 0..255." |
|
1530 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1531 |
%{ |
612 | 1532 |
FILE *f; |
1533 |
unsigned char byte; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1534 |
int ret, _buffered; |
612 | 1535 |
OBJ fp; |
1536 |
||
1133 | 1537 |
__INST(lastErrorNumber) = nil; |
1538 |
if (((fp = __INST(filePointer)) != nil) |
|
1539 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1540 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1541 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1542 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1543 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1544 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1545 |
__READBYTE__(ret, f, &byte, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1546 |
if (ret > 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1547 |
if (__INST(position) != nil) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1548 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1549 |
RETURN (__MKSMALLINT(byte)); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1550 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1551 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1552 |
if (ret == 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1553 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1554 |
} else /* ret < 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1555 |
__INST(position) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1556 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1557 |
} |
612 | 1558 |
} |
1559 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1560 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 1561 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
1562 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1563 |
^ self errorWriteOnly |
|
1564 |
! |
|
1565 |
||
1566 |
nextBytes:count into:anObject |
|
1567 |
"read the next count bytes into an object and return the number of |
|
1568 |
bytes read. On EOF, 0 is returned. |
|
1569 |
If the receiver is some socket/pipe-like stream, an exception |
|
1570 |
is raised if the connection is broken. |
|
1571 |
||
1572 |
The object must have non-pointer indexed instvars (i.e. it must be |
|
1573 |
a ByteArray, String, Float- or DoubleArray). |
|
1574 |
If anObject is a string or byteArray and reused, this provides the |
|
1575 |
fastest possible physical I/O (since no new objects are allocated). |
|
1576 |
||
1577 |
Use with care - non object oriented i/o. |
|
1578 |
Warning: in general, you cannot use this method to pass data from other |
|
1579 |
architectures since it does not care for byte order or float representation." |
|
1580 |
||
1581 |
^ self nextBytes:count into:anObject startingAt:1 |
|
10 | 1582 |
! |
1583 |
||
612 | 1584 |
nextBytes:count into:anObject startingAt:start |
1585 |
"read the next count bytes into an object and return the number of |
|
1586 |
bytes read or 0 on EOF. |
|
1587 |
If the receiver is some socket/pipe-like stream, an exception |
|
1588 |
is raised if the connection is broken. |
|
1589 |
Notice, that in contrast to other methods |
|
1590 |
here, this does NOT return nil on EOF, but the actual count. |
|
1591 |
Thus allowing read of partial blocks. |
|
1592 |
||
1593 |
The object must have non-pointer indexed instvars |
|
1594 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray). |
|
1595 |
If anObject is a string or byteArray and reused, this provides the |
|
1596 |
fastest possible physical I/O (since no new objects are allocated). |
|
1597 |
||
1598 |
Use with care - non object oriented I/O. |
|
1599 |
Warning: in general, you cannot use this method to pass data from other |
|
1600 |
architectures since it does not care for byte order or float representation." |
|
1601 |
||
1602 |
%{ |
|
1603 |
FILE *f; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1604 |
int cnt, offs, ret, _buffered; |
612 | 1605 |
int objSize, nInstVars, nInstBytes; |
1606 |
char *cp; |
|
1607 |
OBJ pos, fp, oClass; |
|
1608 |
||
1133 | 1609 |
__INST(lastErrorNumber) = nil; |
1610 |
if (((fp = __INST(filePointer)) != nil) |
|
2044 | 1611 |
&& (__INST(mode) != @symbol(writeonly)) |
1612 |
&& __bothSmallInteger(count, start) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1613 |
) { |
2044 | 1614 |
f = __FILEVal(fp); |
1615 |
||
1616 |
oClass = __Class(anObject); |
|
1617 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
1618 |
case BYTEARRAY: |
|
1619 |
case WORDARRAY: |
|
1620 |
case LONGARRAY: |
|
1621 |
case SWORDARRAY: |
|
1622 |
case SLONGARRAY: |
|
1623 |
case FLOATARRAY: |
|
1624 |
case DOUBLEARRAY: |
|
1625 |
break; |
|
1626 |
default: |
|
1627 |
goto bad; |
|
1628 |
} |
|
1629 |
cnt = __intVal(count); |
|
1630 |
offs = __intVal(start) - 1; |
|
1631 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
1632 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
1633 |
objSize = __Size(anObject) - nInstBytes; |
|
1634 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
1635 |
/* |
|
1636 |
* mhmh - since we are interruptable, anObject may move. |
|
1637 |
* therefore, fetch the cp-pointer within the loop |
|
1638 |
*/ |
|
1639 |
if (_buffered = (__INST(buffered) == true)) { |
|
1640 |
__READING__(f); |
|
1641 |
} |
|
1642 |
||
1643 |
/* |
|
1644 |
* on interrupt, anObject may be moved to another location. |
|
1645 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
|
1646 |
* to get a new address. |
|
1647 |
*/ |
|
1648 |
__READBYTES__(ret, f, (char *)__InstPtr(anObject)+nInstBytes+offs, cnt, _buffered); |
|
1649 |
if (ret > 0) { |
|
1650 |
pos = __INST(position); |
|
1651 |
if (pos != nil) { |
|
1652 |
__INST(position) = __MKSMALLINT(__intVal(pos) + ret); |
|
1653 |
} |
|
1654 |
RETURN (__MKSMALLINT(ret)); |
|
1655 |
} |
|
1656 |
if (ret == 0) { |
|
1657 |
__INST(hitEOF) = true; |
|
1658 |
} else /* ret < 0 */ { |
|
1659 |
__INST(position) = nil; |
|
1660 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
1661 |
} |
|
1662 |
} |
|
612 | 1663 |
} |
1664 |
bad: ; |
|
1665 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1666 |
(hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0]. |
612 | 1667 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
1668 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1669 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1670 |
" |
|
1671 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
1672 |
" |
|
1673 |
^ self primitiveFailed |
|
92 | 1674 |
! |
1675 |
||
612 | 1676 |
nextBytesInto:anObject |
1677 |
"read bytes into an object, regardless of binary/text mode. |
|
1678 |
The number of bytes to read is defined by the objects size. |
|
1679 |
Return the number of bytes read. On EOF, 0 is returned. |
|
1680 |
If the receiver is some socket/pipe-like stream, an exception |
|
1681 |
is raised if the connection is broken. |
|
1682 |
||
1683 |
The object to read into must have non-pointer indexed instvars |
|
1684 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray). |
|
1685 |
If anObject is a string or byteArray and reused, this provides the |
|
1686 |
fastest possible physical I/O (since no new objects are allocated). |
|
1687 |
||
1688 |
Use with care - non object oriented i/o. |
|
1689 |
Warning: in general, you cannot use this method to pass data from other |
|
1690 |
architectures since it does not care for byte order or float representation." |
|
1691 |
||
1692 |
^ self nextBytes:(anObject size) into:anObject startingAt:1 |
|
1693 |
||
1694 |
" to read 100 bytes from a stream: |
|
1695 |
||
1696 |
|b aStream| |
|
1697 |
||
1698 |
aStream := 'smalltalk.rc' asFilename readStream. |
|
1699 |
b := ByteArray new:100. |
|
1700 |
aStream nextBytesInto:b. |
|
1701 |
aStream close. |
|
1702 |
b inspect |
|
1703 |
" |
|
1704 |
||
1705 |
" |
|
1706 |
|s aStream| |
|
1707 |
aStream := 'smalltalk.rc' asFilename readStream. |
|
1708 |
s := String new:100. |
|
1709 |
aStream nextBytesInto:s. |
|
1710 |
aStream close. |
|
1711 |
s inspect |
|
1712 |
" |
|
1713 |
! |
|
1714 |
||
1715 |
nextLong |
|
1716 |
"Read four bytes (msb-first) and return the value as a 32-bit signed Integer. |
|
1717 |
The returned value may be a LargeInteger. |
|
1718 |
(msb-first for compatibility with other smalltalks)" |
|
1719 |
||
1720 |
^ self nextUnsignedLongMSB:true |
|
1721 |
! |
|
1722 |
||
1723 |
nextLongMSB:msbFlag |
|
1724 |
"Read four bytes and return the value as a 32-bit signed Integer, |
|
1725 |
which may be a LargeInteger. |
|
1726 |
If msbFlag is true, value is read with most-significant byte first, |
|
1727 |
otherwise least-significant byte comes first. |
|
1728 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
1729 |
Works in both binary and text modes." |
|
1730 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1731 |
%{ |
612 | 1732 |
OBJ fp; |
1733 |
||
1133 | 1734 |
__INST(lastErrorNumber) = nil; |
1735 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1736 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1737 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1738 |
FILE *f; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1739 |
int ret; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1740 |
int value; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1741 |
char buffer[4]; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1742 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1743 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1744 |
__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1745 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1746 |
if (ret == 4) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1747 |
if (__INST(position) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1748 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1749 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1750 |
if (msbFlag == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1751 |
value = (buffer[0] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1752 |
value = (value << 8) | (buffer[1] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1753 |
value = (value << 8) | (buffer[2] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1754 |
value = (value << 8) | (buffer[3] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1755 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1756 |
value = (buffer[3] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1757 |
value = (value << 8) | (buffer[2] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1758 |
value = (value << 8) | (buffer[1] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1759 |
value = (value << 8) | (buffer[0] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1760 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1761 |
if ((value >= _MIN_INT) && (value <= _MAX_INT)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1762 |
RETURN ( __MKSMALLINT(value)); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1763 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1764 |
RETURN ( __MKLARGEINT(value) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1765 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1766 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1767 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1768 |
__INST(position) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1769 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1770 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1771 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1772 |
} |
612 | 1773 |
} |
1774 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1775 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 1776 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
1777 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1778 |
^ self readError. |
|
1079 | 1779 |
|
362 | 1780 |
! |
1781 |
||
612 | 1782 |
nextShortMSB:msbFlag |
1783 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
1784 |
If msbFlag is true, value is read with most-significant byte first, |
|
1785 |
otherwise least-significant byte comes first. |
|
1786 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
1787 |
Works in both binary and text modes." |
|
1788 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1789 |
%{ |
612 | 1790 |
OBJ fp; |
1791 |
||
1133 | 1792 |
__INST(lastErrorNumber) = nil; |
1793 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1794 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1795 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1796 |
FILE *f; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1797 |
int ret; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1798 |
short value; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1799 |
char buffer[2]; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1800 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1801 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1802 |
__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1803 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1804 |
if (ret == 2) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1805 |
if (__INST(position) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1806 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1807 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1808 |
if (msbFlag == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1809 |
value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1810 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1811 |
value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1812 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1813 |
RETURN (__MKSMALLINT(value)); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1814 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1815 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1816 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1817 |
__INST(position) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1818 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1819 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1820 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1821 |
} |
612 | 1822 |
} |
1823 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1824 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 1825 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
1826 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1827 |
^ self readError. |
|
1828 |
! |
|
1829 |
||
1830 |
nextUnsignedLongMSB:msbFlag |
|
1831 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
|
1832 |
a LargeInteger. |
|
1833 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
1834 |
least-significant byte comes first. |
|
1835 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
1836 |
Works in both binary and text modes." |
|
1837 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1838 |
%{ |
612 | 1839 |
OBJ fp; |
1840 |
||
1133 | 1841 |
__INST(lastErrorNumber) = nil; |
1842 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1843 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1844 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1845 |
FILE *f; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1846 |
int ret; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1847 |
unsigned int value; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1848 |
char buffer[4]; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1849 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1850 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1851 |
__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1852 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1853 |
if (ret == 4) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1854 |
if (__INST(position) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1855 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1856 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1857 |
if (msbFlag == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1858 |
value = (buffer[0] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1859 |
value = (value << 8) | (buffer[1] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1860 |
value = (value << 8) | (buffer[2] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1861 |
value = (value << 8) | (buffer[3] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1862 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1863 |
value = (buffer[3] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1864 |
value = (value << 8) | (buffer[2] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1865 |
value = (value << 8) | (buffer[1] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1866 |
value = (value << 8) | (buffer[0] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1867 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1868 |
if (value <= _MAX_INT) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1869 |
RETURN ( __MKSMALLINT(value)); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1870 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1871 |
RETURN ( __MKULARGEINT(value) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1872 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1873 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1874 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1875 |
__INST(position) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1876 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1877 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1878 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1879 |
} |
612 | 1880 |
} |
1881 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1882 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 1883 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
1884 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1885 |
^ self readError. |
|
1886 |
! |
|
1887 |
||
1888 |
nextUnsignedShortMSB:msbFlag |
|
1889 |
"Read two bytes and return the value as a 16-bit unsigned Integer. |
|
1079 | 1890 |
If msbFlag is true, value is read with most-significant byte first, |
1891 |
otherwise least-significant byte comes first. |
|
612 | 1892 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
1893 |
Works in both binary and text modes." |
|
1894 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1895 |
%{ |
612 | 1896 |
OBJ fp; |
1897 |
||
1133 | 1898 |
__INST(lastErrorNumber) = nil; |
1899 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1900 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1901 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1902 |
FILE *f; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1903 |
int ret; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1904 |
unsigned int value; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1905 |
char buffer[2]; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1906 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1907 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1908 |
__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1909 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1910 |
if (ret == 2) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1911 |
if (__INST(position) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1912 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1913 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1914 |
if (msbFlag == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1915 |
value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1916 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1917 |
value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1918 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1919 |
RETURN (__MKSMALLINT(value)); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1920 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1921 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1922 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1923 |
__INST(position) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1924 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1925 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1926 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1927 |
} |
612 | 1928 |
} |
1929 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1930 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 1931 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
1932 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1933 |
^ self readError. |
|
1934 |
! |
|
1935 |
||
1936 |
nextWord |
|
1937 |
"in text-mode: |
|
1938 |
read the alphaNumeric next word (i.e. up to non letter-or-digit). |
|
1939 |
return a string containing those characters. |
|
1940 |
in binary-mode: |
|
1941 |
read two bytes (msb-first) and return the value as a 16-bit |
|
1942 |
unsigned Integer (for compatibility with other smalltalks)" |
|
1943 |
||
1944 |
binary ifTrue:[ |
|
1945 |
^ self nextUnsignedShortMSB:true |
|
92 | 1946 |
]. |
612 | 1947 |
^ self nextAlphaNumericWord |
1948 |
! ! |
|
1949 |
||
1950 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
1951 |
||
1952 |
nextPutByte:aByteValue |
|
1953 |
"write a byte. |
|
1954 |
Works in both binary and text modes." |
|
1955 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1956 |
%{ |
612 | 1957 |
FILE *f; |
1958 |
char c; |
|
1959 |
OBJ pos, fp; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1960 |
int cnt, _buffered; |
612 | 1961 |
|
1133 | 1962 |
__INST(lastErrorNumber) = nil; |
1963 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1964 |
&& (__INST(mode) != @symbol(readonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1965 |
&& __isSmallInteger(aByteValue) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1966 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1967 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1968 |
c = __intVal(aByteValue); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1969 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1970 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1971 |
__WRITING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1972 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1973 |
__WRITEBYTE__(cnt, f, &c, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1974 |
if (cnt == 1) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1975 |
pos = __INST(position); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1976 |
if (pos != nil) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1977 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1978 |
RETURN (self); |
612 | 1979 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1980 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 1981 |
} |
1982 |
%}. |
|
1983 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1984 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
1985 |
^ self writeError. |
|
1986 |
! |
|
1987 |
||
1988 |
nextPutBytes:count from:anObject |
|
1989 |
"write count bytes from an object. |
|
1990 |
Return the number of bytes written or nil on error. |
|
1991 |
The object must have non-pointer indexed instvars |
|
1992 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
|
1993 |
Use with care - non object oriented i/o. |
|
1994 |
Warning: in general, you cannot use this method to pass data to other |
|
1995 |
architectures since it does not care for byte order or float representation." |
|
1996 |
||
1997 |
^ self nextPutBytes:count from:anObject startingAt:1 |
|
1998 |
! |
|
1999 |
||
2000 |
nextPutBytes:count from:anObject startingAt:start |
|
2001 |
"write count bytes from an object starting at index start. |
|
2002 |
return the number of bytes written - which could be 0. |
|
2003 |
The object must have non-pointer indexed instvars |
|
2004 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
|
2005 |
Use with care - non object oriented i/o. |
|
2006 |
Warning: in general, you cannot use this method to pass data to other |
|
2007 |
architectures since it does not care for byte order or float representation." |
|
2008 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2009 |
%{ |
612 | 2010 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2011 |
int cnt, len, offs, ret; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2012 |
int objSize, nInstVars, nInstBytes, _buffered; |
612 | 2013 |
char *cp; |
2014 |
OBJ oClass, pos, fp; |
|
2015 |
||
1133 | 2016 |
__INST(lastErrorNumber) = nil; |
2017 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2018 |
&& (__INST(mode) != @symbol(readonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2019 |
&& __bothSmallInteger(count, start) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2020 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2021 |
oClass = __Class(anObject); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2022 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2023 |
case BYTEARRAY: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2024 |
case WORDARRAY: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2025 |
case LONGARRAY: |
1515
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1490
diff
changeset
|
2026 |
case SWORDARRAY: |
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1490
diff
changeset
|
2027 |
case SLONGARRAY: |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2028 |
case FLOATARRAY: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2029 |
case DOUBLEARRAY: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2030 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2031 |
default: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2032 |
goto bad; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2033 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2034 |
len = __intVal(count); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2035 |
offs = __intVal(start) - 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2036 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2037 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2038 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2039 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2040 |
objSize = __Size(anObject) - nInstBytes; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2041 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2042 |
offs += nInstBytes; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2043 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2044 |
__WRITING__(f) |
612 | 2045 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2046 |
__WRITEBYTES__(cnt, f, (char *)__InstPtr(anObject)+offs, len, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2047 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2048 |
if (cnt >= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2049 |
pos = __INST(position); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2050 |
if (pos != nil) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2051 |
__INST(position) = __MKSMALLINT(__intVal(pos) + cnt); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2052 |
RETURN ( __MKSMALLINT(cnt) ); |
612 | 2053 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2054 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 2055 |
} |
2056 |
} |
|
2057 |
bad: ; |
|
2058 |
%}. |
|
2059 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
2060 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2061 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
2062 |
^ self primitiveFailed |
|
2063 |
! |
|
2064 |
||
2065 |
nextPutBytesFrom:anObject |
|
2066 |
"write bytes from an object; the number of bytes is defined by |
|
2067 |
the objects size. |
|
2068 |
Return the number of bytes written or nil on error. |
|
2069 |
The object must have non-pointer indexed instvars |
|
2070 |
(i.e. be a ByteArray, String, Float- or DoubleArray). |
|
2071 |
Use with care - non object oriented i/o. |
|
2072 |
Warning: in general, you cannot use this method to pass data to other |
|
2073 |
architectures since it does not care for byte order or float representation." |
|
2074 |
||
2075 |
^ self nextPutBytes:(anObject size) from:anObject startingAt:1 |
|
2076 |
! |
|
2077 |
||
2078 |
nextPutLong:aNumber MSB:msbFlag |
|
2079 |
"Write the argument, aNumber as a long (four bytes). If msbFlag is |
|
2080 |
true, data is written most-significant byte first; otherwise least |
|
2081 |
first. |
|
2082 |
Works in both binary and text modes." |
|
2083 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2084 |
%{ |
612 | 2085 |
int num; |
2086 |
char bytes[4]; |
|
2087 |
FILE *f; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2088 |
int cnt, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2089 |
OBJ fp, pos; |
612 | 2090 |
|
1133 | 2091 |
__INST(lastErrorNumber) = nil; |
2092 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2093 |
&& (__INST(mode) != @symbol(readonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2094 |
&& __isSmallInteger(aNumber) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2095 |
) { |
612 | 2096 |
num = __intVal(aNumber); |
2097 |
if (msbFlag == true) { |
|
2098 |
bytes[0] = (num >> 24) & 0xFF; |
|
2099 |
bytes[1] = (num >> 16) & 0xFF; |
|
2100 |
bytes[2] = (num >> 8) & 0xFF; |
|
2101 |
bytes[3] = num & 0xFF; |
|
2102 |
} else { |
|
2103 |
bytes[3] = (num >> 24) & 0xFF; |
|
2104 |
bytes[2] = (num >> 16) & 0xFF; |
|
2105 |
bytes[1] = (num >> 8) & 0xFF; |
|
2106 |
bytes[0] = num & 0xFF; |
|
2107 |
} |
|
2108 |
||
2109 |
f = __FILEVal(fp); |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2110 |
if (_buffered = (__INST(buffered) == true)) { |
612 | 2111 |
__WRITING__(f) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2112 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2113 |
__WRITEBYTES__(cnt, f, bytes, 4, _buffered); |
612 | 2114 |
|
2115 |
if (cnt == 4) { |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2116 |
if ((pos = __INST(position)) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2117 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 4); |
612 | 2118 |
} |
2119 |
RETURN ( self ); |
|
2120 |
} |
|
1133 | 2121 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 2122 |
} |
2123 |
%}. |
|
2124 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2125 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
2126 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
2127 |
||
2128 |
aNumber isInteger ifTrue:[ |
|
2129 |
msbFlag ifTrue:[ |
|
2130 |
"high word first" |
|
1079 | 2131 |
(self nextPutShort:(aNumber // 16r10000) MSB:true) isNil ifTrue:[^ nil]. |
2132 |
^ self nextPutShort:(aNumber \\ 16r10000) MSB:true |
|
612 | 2133 |
]. |
2134 |
"low word first" |
|
1079 | 2135 |
(self nextPutShort:(aNumber \\ 16r10000) MSB:false) isNil ifTrue:[^ nil]. |
2136 |
^ self nextPutShort:(aNumber // 16r10000) MSB:false. |
|
92 | 2137 |
]. |
612 | 2138 |
self argumentMustBeInteger |
2139 |
! |
|
2140 |
||
2141 |
nextPutShort:aNumber MSB:msbFlag |
|
2142 |
"Write the argument, aNumber as a short (two bytes). If msbFlag is |
|
2143 |
true, data is written most-significant byte first; otherwise least |
|
2144 |
first. |
|
2145 |
Works in both binary and text modes." |
|
2146 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2147 |
%{ |
612 | 2148 |
int num; |
2149 |
char bytes[2]; |
|
2150 |
FILE *f; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2151 |
int cnt, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2152 |
OBJ fp, pos; |
612 | 2153 |
|
1133 | 2154 |
__INST(lastErrorNumber) = nil; |
2155 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2156 |
&& (__INST(mode) != @symbol(readonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2157 |
&& __isSmallInteger(aNumber) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2158 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2159 |
num = __intVal(aNumber); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2160 |
if (msbFlag == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2161 |
bytes[0] = (num >> 8) & 0xFF; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2162 |
bytes[1] = num & 0xFF; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2163 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2164 |
bytes[1] = (num >> 8) & 0xFF; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2165 |
bytes[0] = num & 0xFF; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2166 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2167 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2168 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2169 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2170 |
__WRITING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2171 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2172 |
__WRITEBYTES__(cnt, f, bytes, 2, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2173 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2174 |
if (cnt == 2) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2175 |
if ((pos = __INST(position)) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2176 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 2); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2177 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2178 |
RETURN ( self ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2179 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2180 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 2181 |
} |
2182 |
%}. |
|
2183 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
2184 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2185 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
2186 |
self argumentMustBeInteger |
|
10 | 2187 |
! ! |
612 | 2188 |
|
2189 |
!ExternalStream methodsFor:'private'! |
|
2190 |
||
2191 |
clearEOF |
|
2192 |
hitEOF := false |
|
2193 |
! |
|
2194 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2195 |
connectTo:aFileDescriptor withMode:openmode |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2196 |
"connect a fileDescriptor; openmode is the string defining the way to open. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2197 |
This can be used to connect an extrnally provided fileDescriptor (from |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2198 |
primitive code) or a pipeFileDescriptor (as returned by makePipe) to |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2199 |
a Stream object. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2200 |
The openMode ('r', 'w' etc.) must match the mode in which |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2201 |
the fileDescriptor was originally opened (otherwise i/o errors will be reported later)." |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2202 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2203 |
|retVal| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2204 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2205 |
filePointer notNil ifTrue:[^ self errorOpen]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2206 |
%{ |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2207 |
FILE *f; |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2208 |
OBJ fp; |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2209 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2210 |
if (__isSmallInteger(aFileDescriptor) |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2211 |
&& (__qClass(openmode)== @global(String))) { |
1079 | 2212 |
f = (FILE *) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode)); |
2213 |
if (f == NULL) { |
|
1133 | 2214 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2215 |
__INST(position) = nil; |
|
1079 | 2216 |
} else { |
1133 | 2217 |
__INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp); |
2218 |
__INST(position) = __MKSMALLINT(1); |
|
1079 | 2219 |
retVal = self; |
2220 |
} |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2221 |
} |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2222 |
%}. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2223 |
retVal notNil ifTrue:[ |
1079 | 2224 |
buffered := true. "default is buffered" |
2225 |
Lobby register:self |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2226 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2227 |
lastErrorNumber notNil ifTrue:[ |
1079 | 2228 |
" |
2229 |
the open failed for some reason ... |
|
2230 |
" |
|
2231 |
^ self openError |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2232 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2233 |
^ retVal |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2234 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
2235 |
|
612 | 2236 |
reOpen |
2237 |
"sent after snapin to reopen streams. |
|
2238 |
cannot reopen here since I am abstract and have no device knowledge" |
|
2239 |
||
2240 |
self class name errorPrint. ': cannot reOpen stream - stream closed' errorPrintNL. |
|
2241 |
filePointer := nil. |
|
2242 |
Lobby unregister:self. |
|
2243 |
! |
|
2244 |
||
2245 |
setLastError:aNumber |
|
2246 |
lastErrorNumber := aNumber |
|
2247 |
! ! |
|
2248 |
||
2249 |
!ExternalStream methodsFor:'queries'! |
|
2250 |
||
2251 |
isBinary |
|
2252 |
"return true, if the stream is in binary (as opposed to text-) mode. |
|
2253 |
The default when created is false." |
|
2254 |
||
2255 |
^ binary |
|
2256 |
! |
|
2257 |
||
2258 |
isExternalStream |
|
2259 |
"return true, if the receiver is some kind of externalStream; |
|
2260 |
true is returned here - the method redefined from Object." |
|
2261 |
||
2262 |
^ true |
|
2263 |
! |
|
2264 |
||
2265 |
isReadable |
|
2266 |
"return true, if this stream can be read from" |
|
2267 |
||
2268 |
^ (mode ~~ #writeonly) |
|
2269 |
! |
|
2270 |
||
2271 |
isWritable |
|
2272 |
"return true, if this stream can be written to" |
|
2273 |
||
2274 |
^ (mode ~~ #readonly) |
|
2275 |
! ! |
|
2276 |
||
2277 |
!ExternalStream methodsFor:'reading'! |
|
2278 |
||
2279 |
next |
|
2280 |
"return the next element; advance read position. |
|
2281 |
In binary mode, an integer is returned, otherwise a character. |
|
2282 |
If there are no more elements, nil is returned." |
|
1 | 2283 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2284 |
%{ |
1 | 2285 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2286 |
int ret, _buffered; |
612 | 2287 |
OBJ pos, fp; |
2288 |
unsigned char ch; |
|
2289 |
||
1133 | 2290 |
__INST(lastErrorNumber) = nil; |
2291 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2292 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2293 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2294 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2295 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2296 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2297 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2298 |
__READBYTE__(ret, f, &ch, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2299 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2300 |
if (ret > 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2301 |
pos = __INST(position); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2302 |
if (__isSmallInteger(pos)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2303 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2304 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2305 |
__INST(position) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2306 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2307 |
if (__INST(binary) == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2308 |
RETURN ( __MKSMALLINT(ch) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2309 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2310 |
RETURN ( __MKCHARACTER(ch) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2311 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2312 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2313 |
__INST(position) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2314 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2315 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2316 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2317 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2318 |
} |
612 | 2319 |
} |
2320 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2321 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2322 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2323 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2324 |
self errorWriteOnly |
|
2325 |
! |
|
2326 |
||
2327 |
next:count |
|
2328 |
"return the next count elements of the stream as a collection. |
|
2329 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
2330 |
||
2331 |
|coll| |
|
2332 |
||
2333 |
binary ifTrue:[ |
|
2334 |
coll := ByteArray uninitializedNew:count |
|
2335 |
] ifFalse:[ |
|
2336 |
coll := String new:count |
|
2337 |
]. |
|
872 | 2338 |
self nextBytes:count into:coll startingAt:1. |
612 | 2339 |
^ coll |
2340 |
! |
|
2341 |
||
2342 |
peek |
|
2343 |
"return the element to be read next without advancing read position. |
|
2344 |
In binary mode, an integer is returned, otherwise a character. |
|
2345 |
If there are no more elements, nil is returned. |
|
2346 |
Not allowed in unbuffered mode." |
|
2347 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2348 |
%{ |
612 | 2349 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2350 |
unsigned char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2351 |
int ret; |
216 | 2352 |
OBJ fp; |
92 | 2353 |
|
1133 | 2354 |
__INST(lastErrorNumber) = nil; |
2355 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2356 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2357 |
&& (__INST(buffered) == true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2358 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2359 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2360 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2361 |
__READBYTE__(ret, f, &c, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2362 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2363 |
if (ret > 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2364 |
ungetc(c, f); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2365 |
if (__INST(binary) == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2366 |
RETURN ( __MKSMALLINT(c) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2367 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2368 |
RETURN ( __MKCHARACTER(c) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2369 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2370 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2371 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2372 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2373 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2374 |
} |
1 | 2375 |
} |
159 | 2376 |
%}. |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2377 |
hitEOF ifTrue:[^ self pastEnd]. |
216 | 2378 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
1 | 2379 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
612 | 2380 |
buffered ifFalse:[^ self errorNotBuffered]. |
159 | 2381 |
^ self errorWriteOnly |
1295 | 2382 |
! |
2383 |
||
2384 |
upToEnd |
|
2385 |
"return a collection of the elements up-to the end. |
|
2386 |
Return nil if the stream-end is reached before." |
|
2387 |
||
2388 |
|answerStream ch| |
|
2389 |
||
2390 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
2391 |
[self atEnd] whileFalse:[ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2392 |
ch := self next. |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2393 |
ch notNil ifTrue:[ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2394 |
answerStream nextPut:ch |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2395 |
] |
1295 | 2396 |
]. |
2397 |
^ answerStream contents |
|
2398 |
||
2399 |
"Created: 25.4.1996 / 14:40:31 / cg" |
|
612 | 2400 |
! ! |
2401 |
||
2402 |
!ExternalStream methodsFor:'reimplemented for speed'! |
|
159 | 2403 |
|
2404 |
nextAlphaNumericWord |
|
379 | 2405 |
"read the next word (i.e. up to non letter-or-digit) after first |
2406 |
skipping any whiteSpace. |
|
2407 |
Return a string containing those characters. |
|
2408 |
There is a limit of 1023 characters in the word - if longer, |
|
2409 |
it is truncated." |
|
159 | 2410 |
|
2411 |
%{ /* STACK: 2000 */ |
|
2412 |
FILE *f; |
|
2413 |
int len; |
|
2414 |
char buffer[1024]; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2415 |
unsigned char ch; |
159 | 2416 |
int cnt = 0; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2417 |
int ret; |
216 | 2418 |
OBJ fp; |
2419 |
||
1133 | 2420 |
if (((fp = __INST(filePointer)) != nil) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2421 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2422 |
&& (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2423 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2424 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2425 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2426 |
/* |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2427 |
* skip whiteSpace first ... |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2428 |
*/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2429 |
do { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2430 |
__READBYTE__(ret, f, &ch, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2431 |
if (ret > 0) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2432 |
cnt++; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2433 |
else |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2434 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2435 |
} while ( |
379 | 2436 |
#ifndef NON_ASCII |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2437 |
(ch < ' ') || |
379 | 2438 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2439 |
(ch == ' ' ) || (ch == '\t') || (ch == '\r') |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2440 |
|| (ch == '\n') || (ch == 0x0b)); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2441 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2442 |
len = 0; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2443 |
while (ret > 0 && |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2444 |
(((ch >= 'a') && (ch <= 'z')) || |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2445 |
((ch >= 'A') && (ch <= 'Z')) || |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2446 |
((ch >= '0') && (ch <= '9'))) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2447 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2448 |
buffer[len++] = ch; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2449 |
if (len >= (sizeof(buffer)-1)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2450 |
/* emergency */ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2451 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2452 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2453 |
__READBYTE__(ret, f, &ch, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2454 |
if (ret > 0) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2455 |
cnt++; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2456 |
else |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2457 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2458 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2459 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2460 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2461 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2462 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2463 |
goto err; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2464 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2465 |
else if (ret == 0) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2466 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2467 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2468 |
ungetc(ch, f); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2469 |
cnt--; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2470 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2471 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2472 |
if (__INST(position) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2473 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2474 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2475 |
if (len != 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2476 |
buffer[len] = '\0'; |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1642
diff
changeset
|
2477 |
RETURN ( __MKSTRING_L(buffer, len) ); |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2478 |
} |
159 | 2479 |
} |
2480 |
err: ; |
|
2481 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2482 |
hitEOF ifTrue:[^ self pastEnd]. |
159 | 2483 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2484 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2485 |
buffered ifFalse:[^ self errorNotBuffered]. |
159 | 2486 |
^ self errorWriteOnly |
1 | 2487 |
! |
2488 |
||
2489 |
nextChunk |
|
2490 |
"return the next chunk, i.e. all characters up to the next |
|
668
73165201a9da
nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2491 |
exclamation mark. Within the chunk, exclamation marks have to be doubled - |
216 | 2492 |
except within primitive code (this exception was added to make it easier |
2493 |
to edit primitive code with external editors). This means, that other |
|
2494 |
Smalltalks cannot always read chunks containing primitive code - but that |
|
2495 |
doesnt really matter, since C-primitives are an ST/X feature anyway. |
|
2496 |
Reimplemented here for more speed." |
|
2497 |
||
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2498 |
|retVal outOfMemory buffer| |
1 | 2499 |
|
159 | 2500 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2501 |
binary ifTrue:[^ self errorBinary]. |
|
2502 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2503 |
"must be buffered, because we use ungetc()" |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2504 |
buffered ifFalse:[^ self errorNotBuffered]. |
216 | 2505 |
|
443 | 2506 |
%{ /* STACK: 8000 */ |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2507 |
/* |
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2508 |
* the main trick (and a bit of complication) here |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2509 |
* is to read the first 7k into a stack-buffer. |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2510 |
* Since most chunks fit into that, |
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2511 |
* this avoids creating lots of garbage for thos small chunks. |
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2512 |
*/ |
1 | 2513 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2514 |
int nread = 0, done = 0; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2515 |
unsigned char c, lastC, peekC; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2516 |
int ret; |
1823 | 2517 |
unsigned char *bufferPtr = (unsigned char *)0; |
668
73165201a9da
nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2518 |
char fastBuffer[7000]; |
1 | 2519 |
REGISTER int index; |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2520 |
int currSize, fastFlag; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2521 |
int atBeginOfLine = 1, inPrimitive = 0; |
216 | 2522 |
|
1133 | 2523 |
__INST(lastErrorNumber) = nil; |
2524 |
f = __FILEVal(__INST(filePointer)); |
|
668
73165201a9da
nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
2525 |
|
216 | 2526 |
__READING__(f) |
159 | 2527 |
|
1 | 2528 |
/* |
2529 |
* skip spaces |
|
2530 |
*/ |
|
673
2c3a4a536cd1
oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
2531 |
c = '\n'; |
1 | 2532 |
while (! done) { |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2533 |
lastC = c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2534 |
__READBYTE__(ret, f, &c, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2535 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2536 |
goto err; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2537 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2538 |
nread++; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2539 |
atBeginOfLine = 0; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2540 |
switch (c) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2541 |
case '\n': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2542 |
case ' ': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2543 |
case '\t': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2544 |
case '\r': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2545 |
case '\b': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2546 |
case '\014': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2547 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2548 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2549 |
default: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2550 |
atBeginOfLine = (lastC == '\n'); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2551 |
done = 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2552 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2553 |
} |
1 | 2554 |
} |
2555 |
||
2556 |
/* |
|
2557 |
* read chunk into a buffer |
|
2558 |
*/ |
|
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2559 |
bufferPtr = fastBuffer; fastFlag = 1; |
216 | 2560 |
currSize = sizeof(fastBuffer); |
362 | 2561 |
|
1 | 2562 |
index = 0; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2563 |
for (;;) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2564 |
__READBYTE__(ret, f, &peekC, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2565 |
if ((c == '%') && atBeginOfLine && ret > 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2566 |
if (peekC == '{') { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2567 |
inPrimitive = 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2568 |
} else if (peekC == '}') { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2569 |
inPrimitive = 0; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2570 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2571 |
} else if (c == '!' && !inPrimitive) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2572 |
if (ret > 0 && peekC == '!') { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2573 |
/* |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2574 |
* convert double-! to a single ! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2575 |
*/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2576 |
__READBYTE__(ret, f, &peekC, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2577 |
if (ret > 0) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2578 |
nread++; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2579 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2580 |
/* |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2581 |
* End of chunk, push back lookahead character |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2582 |
* and leave loop. |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2583 |
*/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2584 |
if (ret > 0) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2585 |
ungetc(peekC, f); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2586 |
else |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2587 |
ret = 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2588 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2589 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2590 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2591 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2592 |
/* |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2593 |
* do we have to resize the buffer ? |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2594 |
*/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2595 |
if ((index+2) >= currSize) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2596 |
OBJ newBuffer; |
1823 | 2597 |
unsigned char *nbp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2598 |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1642
diff
changeset
|
2599 |
newBuffer = __MKEMPTYSTRING(currSize * 2); |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2600 |
if (newBuffer == nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2601 |
/* |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2602 |
* mhmh - chunk seems to be very big .... |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2603 |
*/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2604 |
outOfMemory = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2605 |
goto err; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2606 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2607 |
nbp = __stringVal(newBuffer); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2608 |
if (!fastFlag) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2609 |
/* |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2610 |
* old buffer may have moved - refetch pointer |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2611 |
*/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2612 |
bufferPtr = __stringVal(buffer); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2613 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2614 |
bcopy(bufferPtr, nbp, index); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2615 |
bufferPtr = nbp; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2616 |
bufferPtr[index] = '\0'; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2617 |
buffer = newBuffer; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2618 |
fastFlag = 0; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2619 |
currSize = currSize * 2; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2620 |
} else if (!fastFlag) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2621 |
/* |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2622 |
* old buffer may have moved - refetch pointer |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2623 |
*/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2624 |
bufferPtr = __stringVal(buffer); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2625 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2626 |
bufferPtr[index++] = c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2627 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2628 |
if (ret == 0) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2629 |
break; /* End of chunk reached */ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2630 |
goto err; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2631 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2632 |
nread++; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2633 |
atBeginOfLine = (c == '\n'); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2634 |
c = peekC; |
1 | 2635 |
} |
92 | 2636 |
|
1 | 2637 |
/* |
2638 |
* make it a string |
|
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2639 |
* be careful here - allocating a new string may make the |
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2640 |
* existing buffer move around. Need to check if copying from |
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2641 |
* fast (C) buffer or from real (ST) buffer. |
1 | 2642 |
*/ |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2643 |
if (fastFlag) { |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1642
diff
changeset
|
2644 |
retVal = __MKSTRING_L(bufferPtr, index); |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
2645 |
} else { |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1642
diff
changeset
|
2646 |
retVal = __MKSTRING_ST_L(buffer, index); |
216 | 2647 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2648 |
|
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
2649 |
err: ; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2650 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2651 |
if (ret == 0) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2652 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2653 |
else /* ret < 0 */ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2654 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2655 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2656 |
if (__INST(position) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2657 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + nread); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2658 |
} |
159 | 2659 |
%}. |
370 | 2660 |
retVal isNil ifTrue:[ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2661 |
"/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2662 |
"/ arrive here with retVal==nil either on error or premature EOF |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2663 |
"/ or if running out of malloc-memory |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2664 |
"/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2665 |
hitEOF ifTrue:[^ self pastEnd]. |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2666 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2667 |
outOfMemory == true ifTrue:[ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2668 |
" |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2669 |
buffer memory allocation failed. |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2670 |
When we arrive here, there was no memory available for the |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2671 |
chunk. (seems to be too big of a chunk ...) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2672 |
Bad luck - you should increase the ulimit and/or swap space on your machine. |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2673 |
" |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2674 |
^ ObjectMemory allocationFailureSignal raise. |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2675 |
] |
216 | 2676 |
]. |
1 | 2677 |
^ retVal |
612 | 2678 |
! |
2679 |
||
2680 |
nextMatchFor:anObject |
|
2681 |
"skip all objects up-to and including anObject, return anObject on success, |
|
2682 |
nil if end-of-file is reached before. The next read operation will return |
|
2683 |
the element after anObject. |
|
2684 |
Only single byte characters are currently supported." |
|
2685 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2686 |
%{ |
612 | 2687 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2688 |
int ret, peekValue; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2689 |
char c; |
612 | 2690 |
OBJ fp; |
2691 |
||
1133 | 2692 |
__INST(lastErrorNumber) = nil; |
2693 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2694 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2695 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2696 |
if ((__INST(binary) == true) && __isSmallInteger(anObject)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2697 |
peekValue = __intVal(anObject) & 0xFF; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2698 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2699 |
if ((__INST(binary) != true) && __isCharacter(anObject)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2700 |
peekValue = __intVal(_characterVal(anObject)) & 0xFF; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2701 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2702 |
peekValue = -1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2703 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2704 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2705 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2706 |
if (peekValue >= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2707 |
int _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2708 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2709 |
__INST(position) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2710 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2711 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2712 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2713 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2714 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2715 |
for (;;) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2716 |
__READBYTE__(ret, f, &c, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2717 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2718 |
if (ret < 0) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2719 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2720 |
else |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2721 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2722 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2723 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2724 |
if (c == peekValue) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2725 |
RETURN (anObject); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2726 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2727 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2728 |
} |
612 | 2729 |
} |
2730 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2731 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2732 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2733 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2734 |
^ super nextMatchFor:anObject |
|
2735 |
! |
|
2736 |
||
2737 |
peekFor:anObject |
|
2738 |
"return true and move past next element, if next == something. |
|
2739 |
Otherwise, stay and return false. False is also returned |
|
2740 |
when EOF is encountered. |
|
2741 |
The argument must be an integer if in binary, a character if in |
|
2742 |
text mode; only single byte characters are currently supported." |
|
2743 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2744 |
%{ |
612 | 2745 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2746 |
char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2747 |
int ret, peekValue; |
612 | 2748 |
OBJ fp; |
2749 |
||
1133 | 2750 |
__INST(lastErrorNumber) = nil; |
2751 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2752 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2753 |
&& (__INST(buffered) == true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2754 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2755 |
if (__INST(binary) == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2756 |
if (__isSmallInteger(anObject)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2757 |
peekValue = __intVal(anObject) & 0xFF; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2758 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2759 |
goto bad; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2760 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2761 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2762 |
if (__isCharacter(anObject)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2763 |
peekValue = __intVal(_characterVal(anObject)) & 0xFF; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2764 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2765 |
goto bad; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2766 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2767 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2768 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2769 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2770 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2771 |
__READBYTE__(ret, f, &c, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2772 |
if (ret > 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2773 |
if (c == peekValue) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2774 |
OBJ pos; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2775 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2776 |
if ((pos = __INST(position)) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2777 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2778 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2779 |
RETURN (true); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2780 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2781 |
ungetc(c, f); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2782 |
RETURN (false); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2783 |
} else if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2784 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2785 |
} else /* ret == 0 */ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2786 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2787 |
} |
612 | 2788 |
bad: ; |
2789 |
%}. |
|
2790 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2791 |
hitEOF ifTrue:[self pastEnd. ^ false]. |
612 | 2792 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2793 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2794 |
buffered ifFalse:[^ self errorNotBuffered]. |
612 | 2795 |
^ super peekFor:anObject |
2796 |
! |
|
2797 |
||
2798 |
skipLine |
|
2799 |
"read the next line (characters up to newline) skip only; |
|
2800 |
return nil if EOF reached, self otherwise. |
|
2801 |
Not allowed in binary mode." |
|
2802 |
||
2803 |
%{ /* STACK:2000 */ |
|
2804 |
||
2805 |
FILE *f; |
|
2806 |
OBJ fp; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2807 |
int ret, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2808 |
char c; |
612 | 2809 |
|
1133 | 2810 |
__INST(lastErrorNumber) = nil; |
2811 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2812 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2813 |
&& (__INST(binary) != true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2814 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2815 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2816 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2817 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2818 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2819 |
for (;;) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2820 |
__READBYTE__(ret, f, &c, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2821 |
if (ret > 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2822 |
if (c == '\n') |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2823 |
RETURN(self) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2824 |
} else |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2825 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2826 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2827 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2828 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2829 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2830 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2831 |
} |
612 | 2832 |
} |
2833 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2834 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2835 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2836 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2837 |
binary ifTrue:[^ self errorBinary]. |
|
2838 |
^ self errorWriteOnly |
|
2839 |
! |
|
2840 |
||
2841 |
skipSeparators |
|
2842 |
"skip all whitespace; next will return next non-white-space character |
|
2843 |
or nil if endOfFile reached. Not allowed in binary mode. |
|
2844 |
- reimplemented for speed" |
|
2845 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2846 |
%{ |
612 | 2847 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2848 |
char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2849 |
int ret; |
612 | 2850 |
OBJ fp; |
2851 |
||
1133 | 2852 |
__INST(lastErrorNumber) = nil; |
2853 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2854 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2855 |
&& (__INST(binary) != true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2856 |
&& (__INST(buffered) == true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2857 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2858 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2859 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2860 |
while (1) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2861 |
__READBYTE__(ret, f, &c, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2862 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2863 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2864 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2865 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2866 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2867 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2868 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2869 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2870 |
switch (c) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2871 |
case ' ': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2872 |
case '\t': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2873 |
case '\n': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2874 |
case '\r': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2875 |
case '\b': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2876 |
case '\014': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2877 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2878 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2879 |
default: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2880 |
ungetc(c, f); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2881 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2882 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2883 |
} |
612 | 2884 |
} |
2885 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2886 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2887 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2888 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2889 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2890 |
buffered ifFalse:[^ self errorNotBuffered]. |
612 | 2891 |
^ self errorBinary. |
2892 |
! |
|
2893 |
||
2894 |
skipSeparatorsExceptCR |
|
2895 |
"skip all whitespace but no newlines; |
|
2896 |
next will return next non-white-space character |
|
2897 |
or nil if endOfFile reached. Not allowed in binary mode. |
|
2898 |
- reimplemented for speed" |
|
2899 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2900 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2901 |
%{ |
612 | 2902 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2903 |
char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2904 |
int ret; |
612 | 2905 |
OBJ fp; |
2906 |
||
1133 | 2907 |
__INST(lastErrorNumber) = nil; |
2908 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2909 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2910 |
&& (__INST(binary) != true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2911 |
&& (__INST(buffered) == true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2912 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2913 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2914 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2915 |
while (1) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2916 |
__READBYTE__(ret, f, &c, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2917 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2918 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2919 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2920 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2921 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2922 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2923 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2924 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2925 |
switch (c) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2926 |
case ' ': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2927 |
case '\t': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2928 |
case '\b': |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2929 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2930 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2931 |
default: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2932 |
ungetc(c, f); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2933 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2934 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2935 |
} |
612 | 2936 |
} |
2937 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2938 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2939 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2940 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2941 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2942 |
buffered ifFalse:[^ self errorNotBuffered]. |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2943 |
^ self errorBinary. |
612 | 2944 |
! |
2945 |
||
2946 |
skipThrough:aCharacter |
|
2947 |
"skip all characters up-to and including aCharacter. Return the receiver if |
|
671 | 2948 |
skip was successful, otherwise (i.e. if not found) return nil. |
612 | 2949 |
The next read operation will return the character after aCharacter. |
2950 |
The argument, aCharacter must be character, or integer when in binary mode. |
|
2951 |
Only single byte characters are currently supported." |
|
2952 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2953 |
%{ |
612 | 2954 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2955 |
REGISTER int cSearch; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2956 |
unsigned char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2957 |
int ret, _buffered; |
612 | 2958 |
OBJ fp; |
2959 |
||
1133 | 2960 |
__INST(lastErrorNumber) = nil; |
2961 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2962 |
&& (__INST(mode) != @symbol(writeonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2963 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2964 |
if (__INST(binary) == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2965 |
/* searched for object must be a smallInteger */ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2966 |
if (! __isSmallInteger(aCharacter)) goto badArgument; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2967 |
cSearch = __intVal(aCharacter); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2968 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2969 |
/* searched for object must be a character */ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2970 |
if (! __isCharacter(aCharacter)) goto badArgument; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2971 |
cSearch = __intVal(_characterVal(aCharacter)); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2972 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2973 |
/* Q: should we just say: "not found" ? */ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2974 |
if ((cSearch < 0) || (cSearch > 255)) goto badArgument; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2975 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2976 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2977 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2978 |
__READING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2979 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2980 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2981 |
while (1) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2982 |
__READBYTE__(ret, f, &c, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2983 |
if (ret <= 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2984 |
if (ret < 0) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2985 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2986 |
} else /* ret == 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2987 |
__INST(hitEOF) = true; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2988 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2989 |
break; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2990 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2991 |
if (c == cSearch) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2992 |
RETURN (self); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2993 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2994 |
} |
612 | 2995 |
} |
2996 |
badArgument: ; |
|
2997 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2998 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2999 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3000 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3001 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
3002 |
" |
|
3003 |
argument must be integer/character in binary mode, |
|
3004 |
character in text mode |
|
3005 |
" |
|
3006 |
^ self error:'invalid argument'. |
|
3007 |
||
3008 |
" |
|
3009 |
|s| |
|
3010 |
s := 'Makefile' asFilename readStream. |
|
3011 |
s skipThrough:$=. |
|
3012 |
s next:10 |
|
3013 |
" |
|
3014 |
! |
|
3015 |
||
3016 |
skipToAll:aString |
|
3017 |
"skip for the sequence given by the argument, aCollection; |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
3018 |
return nil if not found, self otherwise. |
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
3019 |
On a successful match, the next read will return characters of aString." |
612 | 3020 |
|
3021 |
|oldPos| |
|
3022 |
||
3023 |
oldPos := self position. |
|
3024 |
(self skipThroughAll:aString) isNil ifTrue:[ |
|
2044 | 3025 |
" |
3026 |
restore position |
|
3027 |
" |
|
3028 |
self position:oldPos. |
|
3029 |
^ nil |
|
612 | 3030 |
]. |
3031 |
" |
|
3032 |
position before match-string |
|
3033 |
" |
|
3034 |
self position:(self position - aString size). |
|
3035 |
^ self |
|
3036 |
||
3037 |
" |
|
3038 |
|s| |
|
3039 |
s := 'Makefile' asFilename readStream. |
|
3040 |
s skipToAll:'are'. |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
3041 |
s next:10 |
612 | 3042 |
" |
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
3043 |
|
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
3044 |
"Modified: 26.6.1996 / 09:22:05 / cg" |
1 | 3045 |
! ! |
612 | 3046 |
|
3047 |
!ExternalStream methodsFor:'testing'! |
|
3048 |
||
3049 |
atEnd |
|
3050 |
"return true, if position is at end" |
|
3051 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3052 |
%{ |
612 | 3053 |
FILE *f; |
3054 |
OBJ fp; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3055 |
char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3056 |
int ret; |
612 | 3057 |
|
1133 | 3058 |
if (__INST(hitEOF) == true) { |
612 | 3059 |
RETURN (true); |
3060 |
} |
|
1133 | 3061 |
if (__INST(buffered) == false) { |
612 | 3062 |
RETURN (false); |
3063 |
} |
|
3064 |
||
1133 | 3065 |
__INST(lastErrorNumber) = nil; |
3066 |
||
3067 |
if ((fp = __INST(filePointer)) != nil) { |
|
612 | 3068 |
f = __FILEVal(fp); |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3069 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3070 |
/* |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3071 |
* This does not work: |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3072 |
* RETURN ( feof(f) ? true : false ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3073 |
* libc tests, if EOF has already bean read, |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3074 |
* smallatalk asks, if next read will return EOF |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3075 |
*/ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3076 |
|
612 | 3077 |
__READING__(f) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3078 |
__READBYTE__(ret, f, &c, 1); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3079 |
if (ret > 0) { |
612 | 3080 |
ungetc(c, f); |
3081 |
RETURN (false); |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3082 |
} else if (ret == 0) { |
1133 | 3083 |
__INST(hitEOF) = true; |
612 | 3084 |
RETURN (true); |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3085 |
} else /* ret < 0 */ { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3086 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 3087 |
} |
3088 |
} |
|
3089 |
%}. |
|
3090 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
|
3091 |
^ self errorNotOpen |
|
3092 |
! |
|
3093 |
||
3094 |
canReadWithoutBlocking |
|
3095 |
"return true, if any data is available for reading (i.e. |
|
3096 |
a read operation will not block the smalltalk process), false otherwise." |
|
3097 |
||
3098 |
|fd| |
|
3099 |
||
3100 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3101 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
3102 |
||
3103 |
fd := self fileDescriptor. |
|
3104 |
^ OperatingSystem readCheck:fd |
|
3105 |
||
3106 |
" |
|
3107 |
|pipe| |
|
3108 |
||
3109 |
pipe := PipeStream readingFrom:'(sleep 10; echo hello)'. |
|
3110 |
pipe canReadWithoutBlocking ifTrue:[ |
|
1422 | 3111 |
Transcript showCR:'data available' |
612 | 3112 |
] ifFalse:[ |
1422 | 3113 |
Transcript showCR:'no data available' |
612 | 3114 |
]. |
3115 |
pipe close |
|
3116 |
" |
|
3117 |
! |
|
3118 |
||
3119 |
canWriteWithoutBlocking |
|
3120 |
"return true, if data can be written into the stream |
|
3121 |
(i.e. a write operation will not block the smalltalk process)." |
|
3122 |
||
3123 |
|fd| |
|
3124 |
||
3125 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3126 |
mode == #readonly ifTrue:[^ self errorReadOnly]. |
|
3127 |
||
3128 |
fd := self fileDescriptor. |
|
3129 |
^ OperatingSystem writeCheck:fd |
|
3130 |
! ! |
|
3131 |
||
3132 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
3133 |
||
3134 |
readWait |
|
3135 |
"suspend the current process, until the receiver |
|
3136 |
becomes ready for reading. If data is already available, |
|
3137 |
return immediate. |
|
3138 |
The other threads are not affected by the wait." |
|
3139 |
||
3140 |
self readWaitWithTimeoutMs:nil |
|
3141 |
! |
|
3142 |
||
3143 |
readWaitWithTimeout:timeout |
|
3144 |
"suspend the current process, until the receiver |
|
3145 |
becomes ready for reading or a timeout (in seconds) expired. |
|
3146 |
If data is already available, return immediate. |
|
3147 |
Return true if a timeout occured (i.e. false, if data is available). |
|
3148 |
The other threads are not affected by the wait." |
|
3149 |
||
3150 |
^ self readWaitWithTimeoutMs:timeout * 1000 |
|
3151 |
! |
|
3152 |
||
3153 |
readWaitWithTimeoutMs:timeout |
|
3154 |
"suspend the current process, until the receiver |
|
3155 |
becomes ready for reading or a timeout (in milliseconds) expired. |
|
3156 |
If data is already available, return immediate. |
|
3157 |
Return true if a timeout occured (i.e. false, if data is available). |
|
3158 |
The other threads are not affected by the wait." |
|
3159 |
||
3160 |
|fd inputSema hasData wasBlocked| |
|
3161 |
||
3162 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3163 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
3164 |
||
3165 |
fd := self fileDescriptor. |
|
3166 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
|
3167 |
||
3168 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3169 |
hasData := OperatingSystem readCheck:fd. |
|
3170 |
hasData ifFalse:[ |
|
3171 |
inputSema := Semaphore new. |
|
3172 |
[ |
|
3173 |
timeout notNil ifTrue:[ |
|
3174 |
Processor signal:inputSema afterMilliseconds:timeout |
|
3175 |
]. |
|
3176 |
Processor signal:inputSema onInput:fd. |
|
3177 |
Processor activeProcess state:#ioWait. |
|
3178 |
inputSema wait. |
|
3179 |
Processor disableSemaphore:inputSema. |
|
3180 |
hasData := OperatingSystem readCheck:fd |
|
3181 |
] valueOnUnwindDo:[ |
|
3182 |
Processor disableSemaphore:inputSema. |
|
3183 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3184 |
] |
|
3185 |
]. |
|
3186 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3187 |
^ hasData not |
|
3188 |
! |
|
3189 |
||
3190 |
writeWait |
|
3191 |
"suspend the current process, until the receiver |
|
3192 |
becomes ready for writing. |
|
3193 |
Return immediate if the receiver is already ready. |
|
3194 |
The other threads are not affected by the wait." |
|
3195 |
||
3196 |
self writeWaitWithTimeoutMs:nil |
|
3197 |
! |
|
3198 |
||
3199 |
writeWaitWithTimeout:timeout |
|
3200 |
"suspend the current process, until the receiver |
|
3201 |
becomes ready for writing or a timeout (in seconds) expired. |
|
3202 |
Return true if a timeout occured (i.e. false, if data is available). |
|
3203 |
Return immediate if the receiver is already ready. |
|
3204 |
The other threads are not affected by the wait." |
|
3205 |
||
3206 |
^ self writeWaitWithTimeoutMs:timeout * 1000 |
|
3207 |
! |
|
3208 |
||
3209 |
writeWaitWithTimeoutMs:timeout |
|
3210 |
"suspend the current process, until the receiver |
|
3211 |
becomes ready for writing or a timeout (in seconds) expired. |
|
3212 |
Return true if a timeout occured (i.e. false, if data is available). |
|
3213 |
Return immediate if the receiver is already ready. |
|
3214 |
The other threads are not affected by the wait." |
|
3215 |
||
3216 |
|fd outputSema canWrite wasBlocked| |
|
3217 |
||
3218 |
filePointer isNil ifTrue:[ |
|
3219 |
^ self errorNotOpen |
|
3220 |
]. |
|
3221 |
mode == #readonly ifTrue:[ |
|
3222 |
^ self errorReadOnly |
|
3223 |
]. |
|
3224 |
||
3225 |
fd := self fileDescriptor. |
|
3226 |
(OperatingSystem writeCheck:fd) ifTrue:[^ false]. |
|
3227 |
||
3228 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3229 |
canWrite := OperatingSystem writeCheck:fd. |
|
3230 |
canWrite ifFalse:[ |
|
3231 |
outputSema := Semaphore new. |
|
3232 |
[ |
|
3233 |
timeout notNil ifTrue:[ |
|
3234 |
Processor signal:outputSema afterMilliseconds:timeout |
|
3235 |
]. |
|
3236 |
Processor signal:outputSema onOutput:fd. |
|
3237 |
Processor activeProcess state:#ioWait. |
|
3238 |
outputSema wait. |
|
3239 |
Processor disableSemaphore:outputSema. |
|
3240 |
canWrite := OperatingSystem writeCheck:fd |
|
3241 |
] valueOnUnwindDo:[ |
|
3242 |
Processor disableSemaphore:outputSema. |
|
3243 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3244 |
] |
|
3245 |
]. |
|
3246 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3247 |
^ canWrite not |
|
3248 |
! ! |
|
3249 |
||
3250 |
!ExternalStream methodsFor:'writing'! |
|
3251 |
||
3252 |
cr |
|
3253 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
3254 |
reimplemented for speed" |
|
3255 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3256 |
%{ |
612 | 3257 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3258 |
int len, cnt, _buffered; |
612 | 3259 |
OBJ fp; |
3260 |
char *cp; |
|
3261 |
||
1133 | 3262 |
__INST(lastErrorNumber) = nil; |
3263 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3264 |
&& (__INST(mode) != @symbol(readonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3265 |
&& (__INST(binary) != true) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3266 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3267 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3268 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3269 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3270 |
__WRITING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3271 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3272 |
if (__INST(useCRLF) == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3273 |
cp = "\r\n"; len = 2; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3274 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3275 |
cp = "\n"; len = 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3276 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3277 |
__WRITEBYTES__(cnt, f, cp, len, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3278 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3279 |
if (cnt == len) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3280 |
if (__INST(position) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3281 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len); |
612 | 3282 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3283 |
RETURN ( self ); |
612 | 3284 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3285 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 3286 |
} |
3287 |
%}. |
|
3288 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
3289 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3290 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
3291 |
self errorBinary |
|
3292 |
! |
|
3293 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3294 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3295 |
"write all buffered data - ignored if unbuffered" |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3296 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3297 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3298 |
OBJ fp; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3299 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3300 |
__INST(lastErrorNumber) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3301 |
if ((fp = __INST(filePointer)) != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3302 |
if (__INST(mode) != @symbol(readonly)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3303 |
if (__INST(buffered) == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3304 |
__BEGIN_INTERRUPTABLE__ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3305 |
fflush( __FILEVal(fp) ); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3306 |
__END_INTERRUPTABLE__ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3307 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3308 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3309 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3310 |
%} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3311 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3312 |
|
612 | 3313 |
nextPut:aCharacter |
3314 |
"write the argument, aCharacter - return nil if failed, self if ok. |
|
3315 |
Only single-byte characters are currently supported" |
|
3316 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3317 |
%{ |
612 | 3318 |
FILE *f; |
3319 |
char c; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3320 |
int cnt, _buffered; |
612 | 3321 |
OBJ pos, fp; |
3322 |
||
1133 | 3323 |
__INST(lastErrorNumber) = nil; |
3324 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3325 |
&& (__INST(mode) != @symbol(readonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3326 |
) { |
1133 | 3327 |
if (__INST(binary) != true) { |
612 | 3328 |
if (__isCharacter(aCharacter)) { |
3329 |
c = __intVal(__characterVal(aCharacter)) & 0xFF; |
|
3330 |
doWrite: |
|
3331 |
f = __FILEVal(fp); |
|
1066
cffbbdea7e01
care for GC while being interruptable
Claus Gittinger <cg@exept.de>
parents:
1048
diff
changeset
|
3332 |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3333 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3334 |
if (_buffered = (__INST(buffered) == true)) { |
612 | 3335 |
__WRITING__(f) |
3336 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3337 |
__WRITEBYTE__(cnt, f, &c, _buffered); |
612 | 3338 |
|
3339 |
if (cnt == 1) { |
|
1133 | 3340 |
pos = __INST(position); |
612 | 3341 |
if (pos != nil) { |
1133 | 3342 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
612 | 3343 |
} |
3344 |
RETURN ( self ); |
|
3345 |
} |
|
1133 | 3346 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 3347 |
} |
3348 |
} else { |
|
3349 |
if (__isSmallInteger(aCharacter)) { |
|
3350 |
c = __intVal(aCharacter); |
|
3351 |
goto doWrite; |
|
3352 |
} |
|
3353 |
} |
|
3354 |
} |
|
3355 |
%}. |
|
3356 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
3357 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3358 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
3359 |
binary ifFalse:[^ self argumentMustBeCharacter]. |
|
3360 |
^ self argumentMustBeInteger. |
|
3361 |
! |
|
3362 |
||
3363 |
nextPutAll:aCollection |
|
3364 |
"write all elements of the argument, aCollection. |
|
3365 |
Reimplemented for speed when writing strings or byteArrays. |
|
3366 |
For others, falls back to general method in superclass." |
|
3367 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3368 |
%{ |
612 | 3369 |
FILE *f; |
3370 |
int len, cnt; |
|
3371 |
OBJ pos, fp; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3372 |
int _buffered; |
612 | 3373 |
|
1133 | 3374 |
__INST(lastErrorNumber) = nil; |
3375 |
||
3376 |
if (((fp = __INST(filePointer)) != nil) |
|
2044 | 3377 |
&& (__INST(mode) != @symbol(readonly)) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3378 |
) { |
2044 | 3379 |
f = __FILEVal(fp); |
3380 |
if (_buffered = (__INST(buffered) == true)) { |
|
3381 |
__WRITING__(f) |
|
3382 |
} |
|
3383 |
if (__isString(aCollection) || __isSymbol(aCollection)) { |
|
3384 |
len = __stringSize(aCollection); |
|
3385 |
__WRITEBYTES__(cnt, f, __stringVal(aCollection), len, _buffered); |
|
3386 |
} else { |
|
3387 |
if (__INST(binary) == true) { |
|
3388 |
int offs; |
|
3389 |
||
3390 |
if (__isByteArray(aCollection)) { |
|
3391 |
offs = 0; |
|
3392 |
len = _byteArraySize(aCollection); |
|
3393 |
} else if (__isBytes(aCollection)) { |
|
3394 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
3395 |
len = _byteArraySize(aCollection) - offs; |
|
3396 |
} else |
|
3397 |
goto out; |
|
3398 |
__WRITEBYTES__(cnt, f, __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered); |
|
3399 |
} else |
|
3400 |
goto out; |
|
3401 |
} |
|
3402 |
if (cnt == len) { |
|
3403 |
pos = __INST(position); |
|
3404 |
if (pos != nil) { |
|
3405 |
__INST(position) = __MKSMALLINT(__intVal(pos) + len); |
|
3406 |
} |
|
3407 |
RETURN (self); |
|
3408 |
} |
|
3409 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 3410 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
3411 |
out: ; |
612 | 3412 |
%}. |
3413 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
3414 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3415 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
3416 |
||
3417 |
^ super nextPutAll:aCollection |
|
3418 |
! |
|
3419 |
||
3420 |
nextPutAll:aCollection startingAt:start to:stop |
|
3421 |
"write a range of elements of the argument, aCollection. |
|
3422 |
Reimplemented for speed when writing strings or byteArrays. |
|
3423 |
For others, falls back to general method in superclass." |
|
3424 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3425 |
%{ |
612 | 3426 |
FILE *f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3427 |
int offs, len, cnt, iStart, iStop, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3428 |
OBJ fp, pos; |
612 | 3429 |
|
1133 | 3430 |
__INST(lastErrorNumber) = nil; |
3431 |
if (((fp = __INST(filePointer)) != nil) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3432 |
&& (__INST(mode) != @symbol(readonly)) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3433 |
&& __bothSmallInteger(start, stop) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3434 |
) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3435 |
f = __FILEVal(fp); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3436 |
if (_buffered = (__INST(buffered) == true)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3437 |
__WRITING__(f) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3438 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3439 |
iStart = __intVal(start); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3440 |
iStop = __intVal(stop); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3441 |
if ((iStart < 1) || (iStop < iStart)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3442 |
RETURN(self); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3443 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3444 |
if (__isString(aCollection) || __isSymbol(aCollection)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3445 |
len = __stringSize(aCollection); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3446 |
if (iStop > len) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3447 |
RETURN(self); |
612 | 3448 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3449 |
if (iStop > len) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3450 |
iStop = len; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3451 |
len = iStop - iStart + 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3452 |
__WRITEBYTES__(cnt, f, __stringVal(aCollection)+iStart-1, len, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3453 |
} else { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3454 |
if (__INST(binary) == true) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3455 |
int offs; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3456 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3457 |
if (__isByteArray(aCollection)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3458 |
offs = 0; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3459 |
len = _byteArraySize(aCollection); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3460 |
} else if (__isBytes(aCollection)) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3461 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3462 |
len = _byteArraySize(aCollection) - offs; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3463 |
} else |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3464 |
goto out; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3465 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3466 |
if (iStop > len) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3467 |
RETURN(self); |
612 | 3468 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3469 |
if (iStop > len) |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3470 |
iStop = len; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3471 |
len = iStop - iStart + 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3472 |
offs += iStart - 1; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3473 |
__WRITEBYTES__(cnt, f, __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3474 |
} else |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3475 |
goto out; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3476 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3477 |
if (cnt == len) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3478 |
pos = __INST(position); |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3479 |
if (pos != nil) { |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3480 |
__INST(position) = __MKSMALLINT(__intVal(pos) + len); |
612 | 3481 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3482 |
RETURN (self); |
612 | 3483 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3484 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 3485 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
3486 |
out: ; |
612 | 3487 |
%}. |
3488 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
3489 |
^ super nextPutAll:aCollection startingAt:start to:stop |
|
3490 |
! ! |
|
3491 |
||
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
3492 |
!ExternalStream class methodsFor:'documentation'! |
730 | 3493 |
|
3494 |
version |
|
2044 | 3495 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.113 1997-01-03 18:36:14 cg Exp $' |
730 | 3496 |
! ! |
612 | 3497 |
ExternalStream initialize! |