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