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