author | Claus Gittinger <cg@exept.de> |
Wed, 04 Aug 1999 16:13:11 +0200 | |
changeset 4526 | a42dc8e09586 |
parent 4468 | 8c67b4f973d8 |
child 4597 | 9628a80e23ec |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
2264 | 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 |
|
2920 | 14 |
instanceVariableNames:'filePointer mode buffered binary eolMode hitEOF didWrite |
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
15 |
lastErrorNumber readAhead' |
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
16 |
classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal |
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
17 |
InvalidModeSignal OpenErrorSignal StreamNotOpenSignal |
2920 | 18 |
InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
19 |
WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal' |
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
20 |
poolDictionaries:'' |
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
21 |
category:'Streams-External' |
1 | 22 |
! |
23 |
||
216 | 24 |
!ExternalStream primitiveDefinitions! |
1 | 25 |
%{ |
2896 | 26 |
|
1 | 27 |
#include <stdio.h> |
437 | 28 |
#define _STDIO_H_INCLUDED_ |
29 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
30 |
|
2903 | 31 |
#ifndef NO_FCNTL_H |
32 |
# include <fcntl.h> |
|
33 |
# define _FCNTL_H_INCLUDED_ |
|
34 |
#endif |
|
437 | 35 |
|
10 | 36 |
#include <errno.h> |
437 | 37 |
#define _ERRNO_H_INCLUDED_ |
42 | 38 |
|
1141 | 39 |
#ifdef LINUX |
40 |
/* use inline string macros */ |
|
41 |
# define __STRINGDEFS__ |
|
42 |
# include <linuxIntern.h> |
|
43 |
#endif |
|
44 |
||
42 | 45 |
#ifdef hpux |
46 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
|
47 |
#endif |
|
216 | 48 |
|
933
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
49 |
#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
|
50 |
# 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
|
51 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
52 |
#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
|
53 |
# 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
|
54 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
55 |
#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
|
56 |
# 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
|
57 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
58 |
|
4093 | 59 |
#if defined(__VMS__) || defined(sparc) |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
60 |
# define CLEAR_ERRNO errno = 0; |
2961 | 61 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
62 |
# define CLEAR_ERRNO /* nothing */ |
2961 | 63 |
#endif |
64 |
||
3420 | 65 |
#ifdef LATER |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
66 |
#define __isFilePointer(x) (__Class(x) == ExternalStream__FilePointer) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
67 |
#define __CHANGECLASS(o, x) (__qClass(o) = (x), o) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
68 |
#define __MKFILEPOINTER(f) __CHANGECLASS(__MKEXTERNALADDRESS(f), ExternalStream__FilePointer) |
3420 | 69 |
#else |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
70 |
#define __MKFILEPOINTER(f) __MKEXTERNALADDRESS(f) |
3420 | 71 |
#endif |
72 |
||
4092 | 73 |
#define STDIO_NEEDS_FSEEK |
74 |
#define FILEPOINTER FILE * |
|
75 |
#define READ(f, cp, n) read(f, cp, n) |
|
76 |
#define WRITE(f, cp, n) write(f, cp, n) |
|
77 |
#define FFLUSH(fp) fflush(fp) |
|
78 |
#define FILENO(f) fileno(f) |
|
3681 | 79 |
|
3682 | 80 |
#ifdef DEBUGGING |
4092 | 81 |
extern char *__survStartPtr, *__survEndPtr; |
3682 | 82 |
# define DEBUGBUFFER(buf) \ |
3681 | 83 |
if (((char *)(buf) >= __survStartPtr) \ |
84 |
&& ((char *)(buf) < __survEndPtr)) { \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
85 |
__fatal0("read into survivor\n"); \ |
3681 | 86 |
} |
87 |
||
3682 | 88 |
#else |
89 |
# define DEBUGBUFFER(buf) /* nothing */ |
|
90 |
#endif |
|
91 |
||
216 | 92 |
/* |
93 |
* stdio library requires an fseek before reading whenever a file |
|
94 |
* is open for read/write and the last operation was a write. |
|
95 |
* (also vice-versa). |
|
96 |
* All code should use the following macro before doing reads: |
|
97 |
*/ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
98 |
#ifdef STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
99 |
# define OPT_FSEEK(f, pos, whence) fseek(f, pos, whence) |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
100 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
101 |
# define OPT_FSEEK(f, pos, whence) /* nothing */ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
102 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
103 |
|
216 | 104 |
#define __READING__(f) \ |
1133 | 105 |
if ((__INST(didWrite) != false) \ |
106 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
107 |
__INST(didWrite) = false; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
108 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
216 | 109 |
} |
110 |
||
111 |
#define __WRITING__(f) \ |
|
1133 | 112 |
if ((__INST(didWrite) != true) \ |
113 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
114 |
__INST(didWrite) = true; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
115 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
216 | 116 |
} |
117 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
118 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
119 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
120 |
#define __UNGETC__(c, f, isBuffered) \ |
2963 | 121 |
__INST(readAhead) = __MKSMALLINT((c)); |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
122 |
#else |
2264 | 123 |
#define __UNGETC__(c, f, isBuffered) \ |
124 |
if (isBuffered) { \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
125 |
ungetc((c), (f)); \ |
2264 | 126 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
127 |
__INST(readAhead) = __MKSMALLINT((c)); \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
128 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
129 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
130 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
131 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
132 |
#define __READBYTE__(ret, f, buf, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
133 |
{ \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
134 |
OBJ rA = __INST(readAhead); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
135 |
if (rA != nil) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
136 |
*(buf) = __intVal(rA); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
137 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
138 |
__INST(readAhead) = nil; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
139 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
140 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
141 |
for (;;) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
142 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
143 |
(ret) = READ(f, buf, 1); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
144 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
145 |
if ((ret) >= 0 || errno != EINTR) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
146 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
147 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
148 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
149 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
150 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
151 |
#else |
2264 | 152 |
#define __READBYTE__(ret, f, buf, isBuffered) \ |
153 |
if (isBuffered) { \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
154 |
for (;;) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
155 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
156 |
(ret) = getc(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
157 |
if ((ret) >= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
158 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
159 |
*(buf) = (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
160 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
161 |
} else if (ferror(f)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
162 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
163 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
164 |
clearerr(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
165 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
166 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
167 |
} else \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
168 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
169 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
170 |
} \ |
2264 | 171 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
172 |
OBJ rA = __INST(readAhead); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
173 |
if (rA != nil) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
174 |
*(buf) = __intVal(rA); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
175 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
176 |
__INST(readAhead) = nil; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
177 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
178 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
179 |
for (;;) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
180 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
181 |
(ret) = read(fileno(f), buf, 1); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
182 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
183 |
if ((ret) >= 0 || errno != EINTR) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
184 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
185 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
186 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
187 |
} \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
188 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
189 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
190 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
191 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
192 |
* read_bytes into a c-buffer |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
193 |
* (which may NOT move) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
194 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
195 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
196 |
#define __READBYTES__(ret, f, buf, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
197 |
{ \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
198 |
int __offs = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
199 |
\ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
200 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
201 |
OBJ rA = __INST(readAhead); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
202 |
if (rA != nil) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
203 |
(buf)[__offs] = __intVal(rA); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
204 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
205 |
__INST(readAhead) = nil; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
206 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
207 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
208 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
209 |
(ret) = READ(f, (buf)+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
210 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
211 |
if ((ret) <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
212 |
if ((ret) < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
213 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
214 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
215 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
216 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
217 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
218 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
219 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
220 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
221 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
222 |
(ret) = __offs; \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
223 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
224 |
#else |
2264 | 225 |
#define __READBYTES__(ret, f, buf, cnt, isBuffered) \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
226 |
(ret) = 0; \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
227 |
if (isBuffered) { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
228 |
int __offs = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
229 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
230 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
231 |
(ret) = getc(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
232 |
if ((ret) < 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
233 |
if (ferror(f)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
234 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
235 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
236 |
clearerr(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
237 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
238 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
239 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
240 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
241 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
242 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
243 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
244 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
245 |
(buf)[__offs++] = (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
246 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
247 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
248 |
(ret) = __offs; \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
249 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
250 |
int __offs = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
251 |
int fd = fileno(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
252 |
\ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
253 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
254 |
OBJ rA = __INST(readAhead); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
255 |
if (rA != nil) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
256 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
257 |
(buf)[__offs] = __intVal(rA); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
258 |
__INST(readAhead) = nil; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
259 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
260 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
261 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
262 |
(ret) = read(fd, (buf)+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
263 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
264 |
if ((ret) <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
265 |
if ((ret) < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
266 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
267 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
268 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
269 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
270 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
271 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
272 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
273 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
274 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
275 |
(ret) = __offs; \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
276 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
277 |
|
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
278 |
#if defined(F_GETFL) && defined(F_SETFL) && defined(FNDELAY) |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
279 |
# define GETFLAGS(fd) \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
280 |
fcntl(fd, F_GETFL, 0); |
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
281 |
|
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
282 |
# define SETFLAGS(fd, flags) \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
283 |
fcntl(fd, F_SETFL, flags) |
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
284 |
|
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
285 |
# define SETNONBLOCKING(fd) \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
286 |
{ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
287 |
int flags; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
288 |
flags = fcntl(fd, F_GETFL, 0); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
289 |
if (flags >= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
290 |
fcntl(fd, F_SETFL, flags | FNDELAY); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
291 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
292 |
} |
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
293 |
#else |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
294 |
# define GETFLAGS(fd) 0 |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
295 |
# define SETFLAGS(fd, flags) /* nothing */ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
296 |
# define SETNONBLOCKING(fd) /* nothing */ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
297 |
#endif |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
298 |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
299 |
#define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
300 |
{ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
301 |
int __offs = 0; \ |
3681 | 302 |
int oldFlags; \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
303 |
\ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
304 |
(ret) = 0; \ |
3681 | 305 |
oldFlags = GETFLAGS(fileno(f)); \ |
306 |
SETNONBLOCKING(fileno(f)); \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
307 |
if (isBuffered) { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
308 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
309 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
310 |
(ret) = getc(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
311 |
if ((ret) < 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
312 |
if (ferror(f)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
313 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
314 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
315 |
clearerr(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
316 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
317 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
318 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
319 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
320 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
321 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
322 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
323 |
(buf)[__offs++] = (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
324 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
325 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
326 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
327 |
(ret) = __offs; \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
328 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
329 |
int fd = fileno(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
330 |
\ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
331 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
332 |
OBJ rA = __INST(readAhead); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
333 |
if (rA != nil) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
334 |
(buf)[__offs] = __intVal(rA); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
335 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
336 |
__INST(readAhead) = nil; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
337 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
338 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
339 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
340 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
341 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
342 |
(ret) = read(fd, (buf)+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
343 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
344 |
if ((ret) < 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
345 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
346 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
347 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
348 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
349 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
350 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
351 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
352 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
353 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
354 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
355 |
(ret) = __offs; \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
356 |
} \ |
3681 | 357 |
SETFLAGS(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
358 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
359 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
360 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
361 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
362 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
363 |
* read_bytes into an object |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
364 |
* (which may be moved by GC) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
365 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
366 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
367 |
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
368 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
369 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
370 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
371 |
char *buf = (char *)(obj); \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
372 |
\ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
373 |
(ret) = 0; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
374 |
{ \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
375 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
376 |
OBJ rA = __INST(readAhead); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
377 |
if (rA != nil) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
378 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
379 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
380 |
__INST(readAhead) = nil; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
381 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
382 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
383 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
384 |
(ret) = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
385 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
386 |
if ((ret) <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
387 |
if ((ret) < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
388 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
389 |
/* refetch */ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
390 |
buf = (char *)(obj); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
391 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
392 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
393 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
394 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
395 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
396 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
397 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
398 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
399 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
400 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
401 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
402 |
#else |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
403 |
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
404 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
405 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
406 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
407 |
char *buf = (char *)(obj); \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
408 |
\ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
409 |
(ret) = 0; \ |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
410 |
if (isBuffered) { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
411 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
412 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
413 |
(ret) = getc(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
414 |
if ((ret) < 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
415 |
if (ferror(f)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
416 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
417 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
418 |
clearerr(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
419 |
/* refetch */ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
420 |
buf = (char *)(obj); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
421 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
422 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
423 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
424 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
425 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
426 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
427 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
428 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
429 |
(buf)[__ooffs+__offs] = (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
430 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
431 |
__offs++; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
432 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
433 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
434 |
(ret) = __offs; \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
435 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
436 |
int fd = fileno(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
437 |
\ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
438 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
439 |
OBJ rA = __INST(readAhead); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
440 |
if (rA != nil) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
441 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
442 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
443 |
__INST(readAhead) = nil; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
444 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
445 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
446 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
447 |
(ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
448 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
449 |
if ((ret) <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
450 |
if ((ret) < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
451 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
452 |
/* refetch */ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
453 |
buf = (char *)(obj); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
454 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
455 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
456 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
457 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
458 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
459 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
460 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
461 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
462 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
463 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
464 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
465 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
466 |
#define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
467 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
468 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
469 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
470 |
char *buf = (char *)(obj); \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
471 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
472 |
(ret) = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
473 |
if (isBuffered) { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
474 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
475 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
476 |
(ret) = getc(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
477 |
if ((ret) < 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
478 |
if (ferror(f)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
479 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
480 |
clearerr(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
481 |
/* refetch */ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
482 |
buf = (char *)(obj); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
483 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
484 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
485 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
486 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
487 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
488 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
489 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
490 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
491 |
(buf)[__ooffs+__offs] = (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
492 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
493 |
__offs++; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
494 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
495 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
496 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
497 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
498 |
int fd = fileno(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
499 |
\ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
500 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
501 |
OBJ rA = __INST(readAhead); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
502 |
if (rA != nil) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
503 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
504 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
505 |
__INST(readAhead) = nil; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
506 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
507 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
508 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
509 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
510 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
511 |
(ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
512 |
DEBUGBUFFER(buf); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
513 |
if ((ret) < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
514 |
/* refetch */ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
515 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
516 |
buf = (char *)(obj); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
517 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
518 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
519 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
520 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
521 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
522 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
523 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
524 |
} \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
525 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
526 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
527 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
528 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
529 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
530 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
531 |
#define __WRITEBYTE__(ret, f, buf, isBuffered) \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
532 |
for (;;) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
533 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
534 |
(ret) = WRITE(f, buf, 1); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
535 |
if ((ret) >= 0 || errno != EINTR) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
536 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
537 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
538 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
539 |
#else |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
540 |
#define __WRITEBYTE__(ret, f, buf, isBuffered) \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
541 |
if (isBuffered) { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
542 |
for (;;) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
543 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
544 |
ret = putc(*(buf), f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
545 |
if ((ret) >= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
546 |
(ret) = 1; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
547 |
} else if (ferror(f)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
548 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
549 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
550 |
clearerr(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
551 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
552 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
553 |
} else \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
554 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
555 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
556 |
} \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
557 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
558 |
for (;;) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
559 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
560 |
(ret) = write(fileno(f), buf, 1); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
561 |
if ((ret) >= 0 || errno != EINTR) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
562 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
563 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
564 |
} \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
565 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
566 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
567 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
568 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
569 |
* write_bytes from a c-buffer |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
570 |
* (which may NOT move) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
571 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
572 |
#ifdef NO_STDIO |
2961 | 573 |
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered) \ |
574 |
(ret) = 0; \ |
|
575 |
{ \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
576 |
int __offs = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
577 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
578 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
579 |
ret = WRITE(f, (buf)+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
580 |
if (ret <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
581 |
if (ret < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
582 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
583 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
584 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
585 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
586 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
587 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
588 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
589 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
590 |
(ret) = __offs; \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
591 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
592 |
#else |
2961 | 593 |
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered) \ |
594 |
(ret) = 0; \ |
|
595 |
if (isBuffered) { \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
596 |
int __offs = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
597 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
598 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
599 |
ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
600 |
if ((ret) <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
601 |
if (ferror(f)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
602 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
603 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
604 |
clearerr(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
605 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
606 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
607 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
608 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
609 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
610 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
611 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
612 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
613 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
614 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
615 |
(ret) = __offs; \ |
2961 | 616 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
617 |
int __offs = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
618 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
619 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
620 |
ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);\ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
621 |
if (ret <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
622 |
if (ret < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
623 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
624 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
625 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
626 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
627 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
628 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
629 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
630 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
631 |
(ret) = __offs; \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
632 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
633 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
634 |
|
223 | 635 |
/* |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
636 |
* write_bytes from an object |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
637 |
* (which may be moved around by GC) |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
638 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
639 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
640 |
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
641 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
642 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
643 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
644 |
char *buf = (char *)(obj); \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
645 |
\ |
2961 | 646 |
(ret) = 0; \ |
647 |
{ \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
648 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
649 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
650 |
ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
651 |
if (ret <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
652 |
if (ret < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
653 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
654 |
/* refetch */ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
655 |
buf = (char *)(obj); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
656 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
657 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
658 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
659 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
660 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
661 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
662 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
663 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
664 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
665 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
666 |
#else |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
667 |
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
668 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
669 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
670 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
671 |
char *buf = (char *)(obj); \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
672 |
\ |
2961 | 673 |
(ret) = 0; \ |
674 |
if (isBuffered) { \ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
675 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
676 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
677 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
678 |
if ((ret) <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
679 |
if (ferror(f)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
680 |
if (errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
681 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
682 |
/* refetch */ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
683 |
buf = (char *)(obj); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
684 |
clearerr(f); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
685 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
686 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
687 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
688 |
} else { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
689 |
(ret) = 0; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
690 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
691 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
692 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
693 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
694 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
695 |
(ret) = __offs; \ |
2961 | 696 |
} else { \ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
697 |
while (__offs < (cnt)) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
698 |
CLEAR_ERRNO; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
699 |
ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
700 |
if (ret <= 0) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
701 |
if (ret < 0 && errno == EINTR) { \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
702 |
__HANDLE_INTERRUPTS__; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
703 |
/* refetch */ \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
704 |
buf = (char *)(obj); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
705 |
continue; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
706 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
707 |
break; \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
708 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
709 |
__offs += (ret); \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
710 |
} \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
711 |
if (__offs > 0) \ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
712 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
713 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
714 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
715 |
#endif |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
716 |
|
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
717 |
/* |
223 | 718 |
* on some systems errno is a macro ... check for it here |
719 |
*/ |
|
720 |
#ifndef errno |
|
721 |
extern errno; |
|
722 |
#endif |
|
723 |
||
1 | 724 |
%} |
188 | 725 |
! ! |
1 | 726 |
|
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
727 |
!ExternalStream class methodsFor:'documentation'! |
22 | 728 |
|
88 | 729 |
copyright |
730 |
" |
|
731 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
2264 | 732 |
All Rights Reserved |
88 | 733 |
|
734 |
This software is furnished under a license and may be used |
|
735 |
only in accordance with the terms of that license and with the |
|
736 |
inclusion of the above copyright notice. This software may not |
|
737 |
be provided or otherwise made available to, or used by, any |
|
738 |
other person. No title to or ownership of the software is |
|
739 |
hereby transferred. |
|
740 |
" |
|
741 |
! |
|
742 |
||
22 | 743 |
documentation |
744 |
" |
|
68 | 745 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
746 |
represent some file or communicationChannel of the underlying OperatingSystem. |
|
747 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 748 |
|
159 | 749 |
ExternalStreams can be in two modes: text- (the default) and binary-mode. |
68 | 750 |
In text-mode, the elements read/written are characters; |
751 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
|
752 |
in the range 0..255. |
|
22 | 753 |
|
68 | 754 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
755 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
756 |
is sent (in both modes). |
|
22 | 757 |
|
77 | 758 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 759 |
or just forgotten - in this case, the garbage collector will eventually collect the |
77 | 760 |
object AND a close will be performed automatically (but you will NOT know when this |
761 |
happens - so it is recommended, that you close your files when no longer needed). |
|
159 | 762 |
Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to |
77 | 763 |
some crash) the data will not be in the file, if unclosed. |
764 |
All streams understand the close message, so it never hurts to use it (it is defined as |
|
765 |
a noop in one of the superclasses). |
|
22 | 766 |
|
68 | 767 |
Most of the methods found here redefine inherited methods for better performance, |
768 |
since I/O from/to files should be fast. |
|
22 | 769 |
|
68 | 770 |
Recovering a snapshot: |
1295 | 771 |
not all streams can be restored to the state they had before - see the implementation of |
772 |
reOpen in subclasses for more information. |
|
773 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
774 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
775 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
776 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
777 |
if the contents changed in the meantime. |
|
778 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
779 |
||
780 |
[Instance variables:] |
|
781 |
||
2264 | 782 |
filePointer <Integer> the unix FILE*; somehow mapped to an integer |
783 |
(notice: not the fd) |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
784 |
on Windows: the fileHandle |
2264 | 785 |
mode <Symbol> #readwrite, #readonly or #writeonly |
786 |
buffered <Boolean> true, if buffered (i.e. collects characters - does |
|
787 |
not output immediately) |
|
788 |
binary <Boolean> true if in binary mode (reads bytes instead of chars) |
|
2920 | 789 |
eolMode <Symbol> one of nil, #cr or #crlf. |
790 |
determines how lines should be terminated. |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
791 |
nil -> newLine (as in Unix); |
2920 | 792 |
#crlf -> with cr-lf (as in MSDOS) |
793 |
#cr -> with cr (as in VMS) |
|
2264 | 794 |
hitEOF <Boolean> true, if EOF was reached |
795 |
||
796 |
lastErrorNumber <Integer> the value of errno (only valid right after the error - |
|
797 |
updated with next i/o operation) |
|
1295 | 798 |
|
799 |
[Class variables:] |
|
2264 | 800 |
Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s) |
801 |
||
802 |
StreamErrorSignal <Signal> parent of all stream errors (see Stream class) |
|
803 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
|
804 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
|
805 |
InvalidModeSignal <Signal> raised on text I/O with binary-stream |
|
806 |
or binary I/O with text-stream |
|
807 |
OpenErrorSignal <Signal> raised if open fails |
|
808 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
|
159 | 809 |
|
810 |
Additional notes: |
|
811 |
This class is implemented using the underlying stdio-c library package, which |
|
812 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
813 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
814 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
815 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
816 |
a complete rewrite for UnboundedStream ... |
|
325 | 817 |
|
188 | 818 |
Also, depending on the system, the stdio library behaves infriendly when signals |
819 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
820 |
is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns |
|
1295 | 821 |
an error and errno is set to EINTR. |
822 |
Thats what the ugly code around all getc-calls is for ... |
|
823 |
Since things get more and more ugly - we will rewrite ExternalStream |
|
824 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 825 |
|
826 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
827 |
this was bad design in the stdio lib (right from the very beginning), since its much |
|
828 |
harder to deal with this in the presence of lightweight processes, where errno gets |
|
829 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
830 |
to return errno as a negative number ...). |
|
831 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
832 |
and saves/restores the errno setting when switching to another thread. |
|
833 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
834 |
does not depend on those, but instead uses a portable private package). |
|
835 |
||
216 | 836 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
837 |
fseek whenever we are about to read after write and vice versa. |
|
838 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
839 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 840 |
|
841 |
[author:] |
|
2264 | 842 |
Claus Gittinger |
843 |
Stefan Vogel (many, many fixes ...) |
|
1295 | 844 |
|
845 |
[see also:] |
|
2264 | 846 |
FileStream Socket PipeStream |
847 |
Filename OperatingSystem |
|
22 | 848 |
" |
3255 | 849 |
! |
850 |
||
851 |
examples |
|
852 |
" |
|
853 |
open a file, read the contents and display it in a textView: |
|
854 |
||
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
855 |
|topView scrollPane textView fileStream text| |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
856 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
857 |
topView := StandardSystemView new. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
858 |
topView label:'contents of Makefile'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
859 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
860 |
scrollPane := HVScrollableView in:topView. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
861 |
scrollPane origin:0.0@0.0 corner:1.0@1.0. |
3255 | 862 |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
863 |
textView := EditTextView new. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
864 |
scrollPane scrolledView:textView. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
865 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
866 |
fileStream := 'Makefile' asFilename readStream. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
867 |
text := fileStream upToEnd. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
868 |
fileStream close. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
869 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
870 |
textView contents:text. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
871 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
872 |
topView open. |
3255 | 873 |
|
874 |
||
875 |
||
876 |
Notice, all of the above can also be done (simply) as: |
|
877 |
||
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
878 |
EditTextView openOn:'Makefile' |
3255 | 879 |
" |
22 | 880 |
! ! |
881 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
882 |
!ExternalStream class methodsFor:'initialization'! |
1 | 883 |
|
2920 | 884 |
initDefaultEOLMode |
885 |
OperatingSystem isUNIXlike ifTrue:[ |
|
886 |
"/ unix EOL conventions |
|
887 |
DefaultEOLMode := #nl |
|
888 |
] ifFalse:[ |
|
889 |
OperatingSystem isVMSlike ifTrue:[ |
|
890 |
"/ vms EOL conventions |
|
891 |
DefaultEOLMode := #cr |
|
892 |
] ifFalse:[ |
|
893 |
"/ msdos EOL conventions |
|
894 |
DefaultEOLMode := #crlf |
|
895 |
] |
|
896 |
] |
|
897 |
! |
|
898 |
||
899 |
initModeStrings |
|
900 |
"initialize modeStrings which are passed down to the underlying |
|
901 |
fopen/fdopen functions." |
|
902 |
||
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
903 |
OperatingSystem isMSDOSlike ifTrue:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
904 |
ReadMode := 'rb'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
905 |
ReadWriteMode := 'rb+'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
906 |
WriteMode := 'wb'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
907 |
AppendMode := 'ab+'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
908 |
CreateReadWriteMode := 'wb+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
909 |
] ifFalse:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
910 |
ReadMode := 'r'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
911 |
ReadWriteMode := 'r+'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
912 |
WriteMode := 'w'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
913 |
AppendMode := 'a+'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
914 |
CreateReadWriteMode := 'w+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
915 |
] |
2920 | 916 |
! |
917 |
||
1 | 918 |
initialize |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
919 |
OpenErrorSignal isNil ifTrue:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
920 |
OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
921 |
OpenErrorSignal nameClass:self message:#openErrorSignal. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
922 |
OpenErrorSignal notifierString:'open error'. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
923 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
924 |
InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
925 |
InvalidReadSignal nameClass:self message:#invalidReadSignal. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
926 |
InvalidReadSignal notifierString:'read error'. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
927 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
928 |
InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
929 |
InvalidWriteSignal nameClass:self message:#invalidWriteSignal. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
930 |
InvalidWriteSignal notifierString:'write error'. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
931 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
932 |
InvalidModeSignal := StreamErrorSignal newSignalMayProceed:false. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
933 |
InvalidModeSignal nameClass:self message:#invalidModeSignal. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
934 |
InvalidModeSignal notifierString:'binary/text mode mismatch'. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
935 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
936 |
InvalidOperationSignal := StreamErrorSignal newSignalMayProceed:false. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
937 |
InvalidOperationSignal nameClass:self message:#invalidOperationSignal. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
938 |
InvalidOperationSignal notifierString:'unsupported file operation'. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
939 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
940 |
StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
941 |
StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
942 |
StreamNotOpenSignal notifierString:'stream is not open'. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
943 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
944 |
StreamIOErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
945 |
StreamIOErrorSignal nameClass:self message:#streamIOErrorSignal. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
946 |
StreamIOErrorSignal notifierString:'I/O error'. |
159 | 947 |
]. |
948 |
||
31 | 949 |
Lobby isNil ifTrue:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
950 |
Lobby := Registry new. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
951 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
952 |
"want to get informed when returning from snapshot" |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
953 |
ObjectMemory addDependent:self |
2920 | 954 |
]. |
955 |
self initDefaultEOLMode. |
|
956 |
self initModeStrings. |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
957 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
958 |
"Modified: / 21.5.1998 / 16:33:53 / cg" |
1 | 959 |
! |
960 |
||
961 |
reOpenFiles |
|
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
962 |
"reopen all files (if possible) after a snapShot load. |
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
963 |
This is invoked via the #earlyRestart change notification." |
1 | 964 |
|
301 | 965 |
Lobby do:[:aFileStream | |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
966 |
aFileStream reOpen |
2920 | 967 |
]. |
1 | 968 |
! |
969 |
||
1469 | 970 |
update:something with:aParameter from:changedObject |
1 | 971 |
"have to reopen files when returning from snapshot" |
972 |
||
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
973 |
something == #earlyRestart ifTrue:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
974 |
self reOpenFiles. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
975 |
self initDefaultEOLMode |
1 | 976 |
] |
1469 | 977 |
|
978 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 979 |
! ! |
980 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
981 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 982 |
|
2920 | 983 |
forFileDescriptor:aFileDescriptor mode:modeString |
984 |
"given a fileDescriptor, create an ExternalStream object |
|
985 |
to operate on this fd. |
|
986 |
The mode-argument is passed to the fdopen call. |
|
987 |
This may be used to wrap fd's as returned by user |
|
988 |
primitive code, or to wrap pipe-fds into externalStreams." |
|
989 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
990 |
|newStream| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
991 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
992 |
newStream := self basicNew. |
2920 | 993 |
newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF. |
3535 | 994 |
^ newStream connectTo:aFileDescriptor withMode:modeString |
2920 | 995 |
|
996 |
" |
|
997 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
998 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
999 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1000 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1001 |
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
|
1002 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1003 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1004 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1005 |
"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
|
1006 |
"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
|
1007 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1008 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1009 |
forReadWriteToFileDescriptor:aFileDescriptor |
2920 | 1010 |
"given a fileDescriptor, create an ExternalStream object |
1011 |
to read/write from/to this fd. This may be used to wrap fd's |
|
1012 |
as returned by user primitive code, or to wrap pipe- |
|
1013 |
filedescriptors into externalStreams." |
|
1014 |
||
3535 | 1015 |
^ (self forFileDescriptor:aFileDescriptor mode:ReadWriteMode) readwrite |
2920 | 1016 |
|
1017 |
" |
|
1018 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1019 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1020 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1021 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1022 |
s := ExternalStream forReadWriteToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1023 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1024 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1025 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1026 |
"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
|
1027 |
"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
|
1028 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1029 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1030 |
forReadingFromFileDescriptor:aFileDescriptor |
2920 | 1031 |
"given a fileDescriptor, create an ExternalStream object |
1032 |
to read from this fd. This may be used to wrap fd's |
|
1033 |
as returned by user primitive code, or to wrap pipe- |
|
1034 |
filedescriptors into externalStreams." |
|
1035 |
||
3535 | 1036 |
^ (self forFileDescriptor:aFileDescriptor mode:ReadMode) readonly |
2920 | 1037 |
|
1038 |
" |
|
1039 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1040 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1041 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1042 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1043 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1044 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1045 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1046 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1047 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1048 |
|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
|
1049 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1050 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1051 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1052 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1053 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1054 |
writeFd := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1055 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1056 |
'connect Smalltalk streams ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1057 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1058 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1059 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1060 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1061 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1062 |
[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1063 |
1 to:10 do:[:i | |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1064 |
Transcript showCR:rs nextLine |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1065 |
]. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1066 |
rs close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1067 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1068 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1069 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1070 |
[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1071 |
1 to:10 do:[:i | |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1072 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1073 |
]. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1074 |
ws close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1075 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1076 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1077 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1078 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1079 |
"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
|
1080 |
"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
|
1081 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1082 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1083 |
forWritingToFileDescriptor:aFileDescriptor |
2920 | 1084 |
"given a fileDescriptor, create an ExternalStream object |
1085 |
to write to this fd. This may be used to wrap fd's |
|
1086 |
as returned by user primitive code, or to wrap pipe- |
|
1087 |
filedescriptors into externalStreams." |
|
1088 |
||
3535 | 1089 |
^ (self forFileDescriptor:aFileDescriptor mode:WriteMode) writeonly |
2920 | 1090 |
|
1091 |
" |
|
1092 |
the example below will probably fail (15 is a random FD): |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1093 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1094 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1095 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1096 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1097 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1098 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1099 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1100 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1101 |
"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
|
1102 |
"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
|
1103 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1104 |
|
3535 | 1105 |
makePTYPair |
1106 |
"return an array with two streams - the first one is the master, |
|
1107 |
the second the slave of a ptym/ptys pair. |
|
1108 |
This is much like a bidirectional pipe, but allows signals & |
|
1109 |
control chars to be passed through the connection. |
|
1110 |
This is needed to execute a shell in a view. |
|
1111 |
This is the higher level equivalent of OperatingSystem>>makePTYPair |
|
1112 |
(which returns an array of file-descriptors)." |
|
1113 |
||
1114 |
|ptyPair m s| |
|
1115 |
||
1116 |
ptyPair := OperatingSystem makePTYPair. |
|
1117 |
ptyPair notNil ifTrue:[ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1118 |
m := self forReadWriteToFileDescriptor:(ptyPair at:1). |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1119 |
s := self forReadWriteToFileDescriptor:(ptyPair at:2). |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1120 |
ptyPair at:1 put:m. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1121 |
ptyPair at:2 put:s. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1122 |
^ ptyPair |
3535 | 1123 |
]. |
1124 |
^ nil |
|
1125 |
||
1126 |
" |
|
1127 |
ExternalStream makePTYPair. |
|
1128 |
" |
|
1129 |
||
1130 |
"Modified: 29.2.1996 / 18:28:36 / cg" |
|
1131 |
! |
|
1132 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1133 |
makePipe |
2920 | 1134 |
"return an array with two streams - the first one for reading, |
1135 |
the second for writing. |
|
1136 |
This is the higher level equivalent of OperatingSystem>>makePipe |
|
1137 |
(which returns an array of file-descriptors)." |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1138 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1139 |
|pipe rs ws| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1140 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1141 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1142 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1143 |
pipe notNil ifTrue:[ |
2264 | 1144 |
rs := self forReadingFromFileDescriptor:(pipe at:1). |
1145 |
ws := self forWritingToFileDescriptor:(pipe at:2). |
|
1146 |
^ 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
|
1147 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1148 |
^ nil |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1149 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1150 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1151 |
|pipe rs ws| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1152 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1153 |
pipe := ExternalStream makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1154 |
rs := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1155 |
ws := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1156 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1157 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1158 |
[ |
2264 | 1159 |
1 to:10 do:[:i | |
1160 |
Transcript showCR:rs nextLine |
|
1161 |
]. |
|
1162 |
rs close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1163 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1164 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1165 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1166 |
[ |
2264 | 1167 |
1 to:10 do:[:i | |
1168 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
1169 |
]. |
|
1170 |
ws close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1171 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1172 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1173 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1174 |
"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
|
1175 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1176 |
|
612 | 1177 |
new |
1178 |
|newStream| |
|
1179 |
||
1180 |
newStream := self basicNew. |
|
2920 | 1181 |
newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF. |
612 | 1182 |
^ newStream |
1183 |
! ! |
|
1184 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1185 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 1186 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1187 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1188 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1189 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1190 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1191 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1192 |
"Created: 2.7.1996 / 12:27:16 / stefan" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1193 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1194 |
|
612 | 1195 |
invalidModeSignal |
1196 |
"return the signal raised when doing text-I/O with a binary stream |
|
1197 |
or binary-I/O with a text stream" |
|
1198 |
||
1199 |
^ InvalidModeSignal |
|
159 | 1200 |
! |
1201 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1202 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1203 |
"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
|
1204 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1205 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1206 |
^ InvalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1207 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1208 |
|
159 | 1209 |
invalidReadSignal |
1210 |
"return the signal raised when reading from writeonly streams" |
|
1211 |
||
1212 |
^ InvalidReadSignal |
|
1213 |
! |
|
1214 |
||
1215 |
invalidWriteSignal |
|
1216 |
"return the signal raised when writing to readonly streams" |
|
1217 |
||
1218 |
^ InvalidWriteSignal |
|
1219 |
! |
|
1220 |
||
612 | 1221 |
openErrorSignal |
1222 |
"return the signal raised when a file open failed" |
|
1223 |
||
1224 |
^ OpenErrorSignal |
|
1225 |
! |
|
1226 |
||
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1227 |
streamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1228 |
"return the signal raised when an I/O error occurs. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1229 |
(for example, a device-IO-error, or reading an NFS-dir, |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1230 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1231 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1232 |
^ StreamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1233 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1234 |
"Created: / 21.5.1998 / 16:32:55 / cg" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1235 |
! |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1236 |
|
159 | 1237 |
streamNotOpenSignal |
1238 |
"return the signal raised on I/O with closed streams" |
|
1239 |
||
1240 |
^ StreamNotOpenSignal |
|
2 | 1241 |
! ! |
1242 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1243 |
!ExternalStream class methodsFor:'error handling'! |
92 | 1244 |
|
1245 |
lastErrorNumber |
|
159 | 1246 |
"return the errno of the last error" |
92 | 1247 |
|
1248 |
^ LastErrorNumber |
|
159 | 1249 |
|
1250 |
" |
|
1251 |
ExternalStream lastErrorNumber |
|
1252 |
" |
|
92 | 1253 |
! |
1254 |
||
1255 |
lastErrorString |
|
1256 |
"return a message string describing the last error" |
|
1257 |
||
1258 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
1259 |
||
1260 |
" |
|
1261 |
ExternalStream lastErrorString |
|
1262 |
" |
|
1263 |
! ! |
|
1264 |
||
3939
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1265 |
!ExternalStream methodsFor:'Signal constants'! |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1266 |
|
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1267 |
invalidReadSignal |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1268 |
^ self class invalidReadSignal |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1269 |
|
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1270 |
"Created: / 3.12.1998 / 15:12:06 / cg" |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1271 |
! |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1272 |
|
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1273 |
invalidWriteSignal |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1274 |
^ self class invalidWriteSignal |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1275 |
|
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1276 |
"Created: / 3.12.1998 / 15:12:10 / cg" |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1277 |
! ! |
52e4ebbde474
oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents:
3938
diff
changeset
|
1278 |
|
3044 | 1279 |
!ExternalStream methodsFor:'Squeak compatibility'! |
1280 |
||
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1281 |
nextInto:aByteArrayOrString |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1282 |
"read elements into the argument, whose size determines the amount |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1283 |
of bytes to read. If not enough elements could be read, return |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1284 |
a copy of the argument; otherwise, return the filled argument." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1285 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1286 |
|n nWanted| |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1287 |
|
4368 | 1288 |
nWanted := aByteArrayOrString byteSize. |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1289 |
n := self nextAvailableBytes:nWanted into:aByteArrayOrString startingAt:1. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1290 |
n == nWanted ifTrue:[^ aByteArrayOrString]. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1291 |
^ aByteArrayOrString copyTo:n |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1292 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1293 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1294 |
|
4368 | 1295 |
readInto:aContainer startingAt:index count:nElements |
1296 |
"same as #nextBytes:into:startingAt: for ByteArrays; |
|
1297 |
for LongArrays, nelements longs are read. |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1298 |
Squeak compatibility." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1299 |
|
4368 | 1300 |
|elementSize n| |
1301 |
||
1302 |
elementSize := aContainer class elementByteSize. |
|
1303 |
n := self nextBytes:nElements*elementSize into:aContainer startingAt:1. |
|
1304 |
^ n // elementSize |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1305 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1306 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1307 |
|
3044 | 1308 |
readOnly |
1309 |
"Squeak compatibility: make the stream readOnly" |
|
1310 |
||
1311 |
mode := #readonly |
|
1312 |
||
1313 |
"Modified: 20.10.1997 / 19:23:04 / cg" |
|
1314 |
"Created: 20.10.1997 / 19:23:19 / cg" |
|
1315 |
! ! |
|
1316 |
||
1 | 1317 |
!ExternalStream methodsFor:'accessing'! |
1318 |
||
612 | 1319 |
binary |
1320 |
"switch to binary mode - default is text" |
|
1321 |
||
1322 |
binary := true |
|
1 | 1323 |
! |
1324 |
||
1325 |
buffered:aBoolean |
|
10 | 1326 |
"turn buffering on or off - default is on" |
1 | 1327 |
|
10 | 1328 |
buffered := aBoolean |
1 | 1329 |
! |
1330 |
||
1331 |
contents |
|
2 | 1332 |
"return the contents of the file from the current position up-to |
1333 |
the end. If the stream is in binary mode, a ByteArray containing |
|
1334 |
the byte values is returned. |
|
1335 |
In text-mode, a collection of strings, each representing one line, |
|
1336 |
is returned." |
|
1337 |
||
1338 |
|text l chunks sizes chunk byteCount cnt bytes offset| |
|
1339 |
||
1340 |
binary ifTrue:[ |
|
2264 | 1341 |
"adding to a ByteArray produces quadratic time-space |
1342 |
behavior - therefore we allocate chunks, and concatenate them |
|
1343 |
at the end." |
|
1344 |
||
1345 |
chunks := OrderedCollection new. |
|
1346 |
sizes := OrderedCollection new. |
|
1347 |
byteCount := 0. |
|
1348 |
[self atEnd] whileFalse:[ |
|
1349 |
chunk := ByteArray uninitializedNew:4096. |
|
1350 |
cnt := self nextBytes:(chunk size) into:chunk. |
|
1351 |
cnt notNil ifTrue:[ |
|
1352 |
chunks add:chunk. |
|
1353 |
sizes add:cnt. |
|
1354 |
byteCount := byteCount + cnt |
|
1355 |
] |
|
1356 |
]. |
|
1357 |
||
1358 |
"now, create one big ByteArray" |
|
1359 |
bytes := ByteArray uninitializedNew:byteCount. |
|
1360 |
offset := 1. |
|
1361 |
1 to:chunks size do:[:index | |
|
1362 |
chunk := chunks at:index. |
|
1363 |
cnt := sizes at:index. |
|
1364 |
bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk. |
|
1365 |
offset := offset + cnt |
|
1366 |
]. |
|
1367 |
^ bytes |
|
2 | 1368 |
]. |
1 | 1369 |
|
244 | 1370 |
text := StringCollection new. |
1 | 1371 |
[self atEnd] whileFalse:[ |
2264 | 1372 |
l := self nextLine. |
1373 |
l isNil ifTrue:[ |
|
1374 |
^ text |
|
1375 |
]. |
|
1376 |
text add:l |
|
1 | 1377 |
]. |
1378 |
^ text |
|
1379 |
! |
|
1380 |
||
612 | 1381 |
contentsOfEntireFile |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1382 |
"ST-80 compatibility: return contents as a String (or byteArray, if in binary mode). |
3876 | 1383 |
See also #contents, which returns the lines as stringCollection for text files." |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1384 |
|
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1385 |
|data| |
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1386 |
|
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1387 |
data := self contents. |
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1388 |
binary ifFalse:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1389 |
^ data asString. |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1390 |
]. |
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1391 |
^ data |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1392 |
|
3876 | 1393 |
"Modified: / 3.7.1996 / 13:22:16 / stefan" |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1394 |
"Modified: / 27.11.1998 / 16:29:43 / cg" |
2 | 1395 |
! |
1396 |
||
612 | 1397 |
contentsSpecies |
1398 |
"return the kind of object to be returned by sub-collection builders |
|
1399 |
(such as upTo)" |
|
159 | 1400 |
|
1401 |
binary ifTrue:[ |
|
2264 | 1402 |
^ ByteArray |
159 | 1403 |
]. |
612 | 1404 |
^ String |
2 | 1405 |
! |
1406 |
||
2920 | 1407 |
eolMode:aSymbolOrNil |
1408 |
"specify how end-of-line (EOL) is to be marked. |
|
1409 |
The argument may be one of: |
|
1410 |
#crlf -> add a CR-NL, as in MSDOS |
|
1411 |
#cr -> add a CR, as in VMS |
|
1412 |
#nl -> add a NL, as in Unix |
|
1413 |
anyOther -> like #nl |
|
1414 |
" |
|
1415 |
||
1416 |
eolMode := aSymbolOrNil |
|
1417 |
! |
|
1418 |
||
612 | 1419 |
fileDescriptor |
1420 |
"return the fileDescriptor of the receiver - |
|
1421 |
notice: this one returns the underlying OSs fileDescriptor - |
|
1422 |
this may not be available on all platforms (i.e. non unix systems)." |
|
1 | 1423 |
|
3971 | 1424 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1425 |
FILEPOINTER f; |
612 | 1426 |
OBJ fp; |
1427 |
||
1133 | 1428 |
if ((fp = __INST(filePointer)) != nil) { |
2264 | 1429 |
f = __FILEVal(fp); |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1430 |
RETURN ( __MKINT(fileno(f)) ); |
1 | 1431 |
} |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1432 |
%}. |
612 | 1433 |
^ self errorNotOpen |
1434 |
! |
|
1435 |
||
1436 |
filePointer |
|
1437 |
"return the filePointer of the receiver - |
|
1438 |
notice: for portability stdio is used; this means you will get |
|
1439 |
a FILE * - not a fileDescriptor. |
|
1440 |
(what you really get is a corresponding integer). |
|
1441 |
You cannot do much with the returned value |
|
1442 |
- except passing it to a primitive, for example." |
|
1443 |
||
1444 |
^ filePointer |
|
1445 |
! |
|
1446 |
||
3016 | 1447 |
lineEndTransparent |
1448 |
eolMode := #cr |
|
1449 |
! |
|
1450 |
||
612 | 1451 |
readonly |
1452 |
"set access mode to readonly" |
|
1453 |
||
1454 |
mode := #readonly |
|
1455 |
! |
|
1456 |
||
1457 |
readwrite |
|
1458 |
"set access mode to readwrite" |
|
1459 |
||
1460 |
mode := #readwrite |
|
1461 |
! |
|
1462 |
||
1463 |
text |
|
1464 |
"switch to text mode - default is text" |
|
1465 |
||
1466 |
binary := false |
|
1467 |
! |
|
1468 |
||
1469 |
useCRLF:aBoolean |
|
2920 | 1470 |
"turn on or off CRLF sending (instead of LF only) - default is off. |
1471 |
This method is provided for backward compatibility - see #eolMode: |
|
1472 |
which offers another choice." |
|
1473 |
||
1474 |
aBoolean ifTrue:[ |
|
1475 |
eolMode := #crlf |
|
1476 |
] ifFalse:[ |
|
1477 |
eolMode := #nl |
|
1478 |
]. |
|
1 | 1479 |
! |
1480 |
||
612 | 1481 |
writeonly |
1482 |
"set access mode to writeonly" |
|
1483 |
||
1484 |
mode := #writeonly |
|
1485 |
! ! |
|
1486 |
||
1487 |
!ExternalStream methodsFor:'error handling'! |
|
1488 |
||
1489 |
argumentMustBeCharacter |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1490 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1491 |
|
612 | 1492 |
"report an error, that the argument must be a character" |
1493 |
||
1494 |
^ self error:'argument must be a character' |
|
1495 |
! |
|
1496 |
||
1497 |
argumentMustBeInteger |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1498 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1499 |
|
612 | 1500 |
"report an error, that the argument must be an integer" |
1501 |
||
1502 |
^ self error:'argument must be an integer' |
|
77 | 1503 |
! |
1504 |
||
612 | 1505 |
argumentMustBeString |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1506 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1507 |
|
612 | 1508 |
"report an error, that the argument must be a string" |
1509 |
||
1510 |
^ self error:'argument must be a string' |
|
1511 |
! |
|
1512 |
||
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1513 |
errorAlreadyOpen |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1514 |
"{ Pragma: +optSpace }" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1515 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1516 |
"report an error, that the stream is already opened" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1517 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1518 |
^ self class openErrorSignal |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1519 |
raiseRequestWith:self |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1520 |
errorString:(self class name , ' is already open') |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1521 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1522 |
"Modified: / 8.5.1999 / 20:12:30 / cg" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1523 |
! |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
1524 |
|
612 | 1525 |
errorBinary |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1526 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1527 |
|
612 | 1528 |
"report an error, that the stream is in binary mode" |
1529 |
||
2920 | 1530 |
^ self invalidModeSignal |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1531 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1532 |
errorString:(self class name , ' is in binary mode') |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1533 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1534 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1535 |
"Modified: / 8.5.1999 / 20:12:43 / cg" |
612 | 1536 |
! |
1537 |
||
1538 |
errorNotBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1539 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1540 |
|
612 | 1541 |
"report an error, that the stream is not in binary mode" |
1542 |
||
2920 | 1543 |
^ self invalidModeSignal |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1544 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1545 |
errorString:(self class name , ' is not in binary mode') |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1546 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1547 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1548 |
"Modified: / 8.5.1999 / 20:12:40 / cg" |
1 | 1549 |
! |
1550 |
||
612 | 1551 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1552 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1553 |
|
612 | 1554 |
"report an error, that the stream is not in buffered mode" |
1555 |
||
1556 |
^ StreamErrorSignal |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1557 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1558 |
errorString:(self class name , ' is unbuffered - operation not allowed') |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1559 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1560 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1561 |
"Modified: / 8.5.1999 / 20:12:36 / cg" |
612 | 1562 |
! |
1563 |
||
1564 |
errorNotOpen |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1565 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1566 |
|
612 | 1567 |
"report an error, that the stream has not been opened" |
1568 |
||
3467 | 1569 |
^ StreamNotOpenSignal |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1570 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1571 |
errorString:(self class name , ' not open') |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1572 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1573 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1574 |
"Modified: / 8.5.1999 / 20:12:33 / cg" |
612 | 1575 |
! |
1576 |
||
1577 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1578 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1579 |
|
612 | 1580 |
"report an error, that the stream is a readOnly stream" |
1581 |
||
2920 | 1582 |
^ self invalidWriteSignal |
4468 | 1583 |
raiseWith:self |
1584 |
errorString:(self class name , ' is readonly') |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1585 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1586 |
|
4468 | 1587 |
"Modified: / 30.7.1999 / 17:08:19 / cg" |
612 | 1588 |
! |
1589 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1590 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1591 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1592 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1593 |
"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
|
1594 |
|
2920 | 1595 |
^ self invalidOperationSignal |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1596 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1597 |
errorString:'unsupported operation' |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1598 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1599 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1600 |
"Modified: / 8.5.1999 / 20:12:24 / cg" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1601 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1602 |
|
612 | 1603 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1604 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1605 |
|
612 | 1606 |
"report an error, that the stream is a writeOnly stream" |
1607 |
||
2920 | 1608 |
^ self invalidReadSignal |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1609 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1610 |
errorString:(self class name , ' is writeonly') |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1611 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1612 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1613 |
"Modified: / 8.5.1999 / 20:12:20 / cg" |
2 | 1614 |
! |
1615 |
||
612 | 1616 |
ioError |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1617 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1618 |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1619 |
"report an error, that some I/O error occured. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1620 |
(for example, a device-IO-error, or reading an NFS-dir, |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1621 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1622 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1623 |
^ StreamIOErrorSignal |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1624 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1625 |
errorString:('I/O error: ' , self lastErrorString) |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1626 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1627 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1628 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
612 | 1629 |
! |
1630 |
||
1631 |
lastErrorNumber |
|
1632 |
"return the last error" |
|
1633 |
||
1634 |
^ lastErrorNumber |
|
1635 |
! |
|
1636 |
||
1637 |
lastErrorString |
|
1638 |
"return a message string describing the last error" |
|
1639 |
||
1640 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
2264 | 1641 |
^ 'I/O error' |
612 | 1642 |
]. |
1643 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 1644 |
! |
1645 |
||
612 | 1646 |
openError |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1647 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1648 |
|
612 | 1649 |
"report an error, that the open failed" |
1650 |
||
3235
cc254b307159
FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3221
diff
changeset
|
1651 |
^ self class openErrorSignal |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1652 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1653 |
errorString:('error on open: ' , self lastErrorString) |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1654 |
"/ in:thisContext sender |
3235
cc254b307159
FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3221
diff
changeset
|
1655 |
|
cc254b307159
FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3221
diff
changeset
|
1656 |
"Modified: / 28.1.1998 / 14:37:42 / stefan" |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1657 |
"Modified: / 8.5.1999 / 20:12:12 / cg" |
612 | 1658 |
! |
1659 |
||
1660 |
readError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1661 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1662 |
|
612 | 1663 |
"report an error, that some read error occured" |
1664 |
||
1665 |
^ ReadErrorSignal |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1666 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1667 |
errorString:('read error: ' , self lastErrorString) |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1668 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1669 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1670 |
"Modified: / 8.5.1999 / 20:12:00 / cg" |
612 | 1671 |
! |
1672 |
||
1673 |
writeError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1674 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1675 |
|
612 | 1676 |
"report an error, that some write error occured" |
1677 |
||
1678 |
^ WriteErrorSignal |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1679 |
raiseRequestWith:self |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1680 |
errorString:('write error: ' , self lastErrorString) |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1681 |
"/ in:thisContext sender |
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1682 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
1683 |
"Modified: / 8.5.1999 / 20:12:09 / cg" |
612 | 1684 |
! ! |
1685 |
||
1686 |
!ExternalStream methodsFor:'instance release'! |
|
1687 |
||
1688 |
closeFile |
|
1689 |
"low level close - may be redefined in subclasses" |
|
2 | 1690 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1691 |
%{ |
216 | 1692 |
OBJ fp; |
2 | 1693 |
|
1133 | 1694 |
if ((fp = __INST(filePointer)) != nil) { |
2264 | 1695 |
__INST(filePointer) = nil; |
1696 |
__BEGIN_INTERRUPTABLE__ |
|
1697 |
fclose(__FILEVal(fp)); |
|
1698 |
__END_INTERRUPTABLE__ |
|
10 | 1699 |
} |
1700 |
%} |
|
1701 |
! |
|
1702 |
||
612 | 1703 |
disposed |
1704 |
"some Stream has been collected - close the file if not already done" |
|
1705 |
||
1706 |
self closeFile |
|
1707 |
! |
|
1708 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1709 |
setFileDescriptor:anInteger mode:openMode |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1710 |
"set the filePointer based upon a given fileDescriptor - |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1711 |
notice: this one is based on the underlying OSs fileDescriptor - |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1712 |
this may not be available on all platforms (i.e. non unix systems)." |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1713 |
|
3681 | 1714 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1715 |
FILEPOINTER f; |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1716 |
OBJ fp; |
2765 | 1717 |
FILE *fdopen(); |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1718 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1719 |
if (__isSmallInteger(anInteger) && |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1720 |
__isString(openMode) && |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1721 |
(f = fdopen(__intVal(anInteger), __stringVal(openMode))) != 0 |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1722 |
) { |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1723 |
__PROTECT__(self); |
3420 | 1724 |
fp = __MKFILEPOINTER(f); |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1725 |
__UNPROTECT__(self); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1726 |
__INST(filePointer) = fp; __STORE(self, fp); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1727 |
RETURN (self); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1728 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1729 |
%}. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1730 |
^ self primitiveFailed |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1731 |
! |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1732 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1733 |
setFilePointer:something |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1734 |
"set the filePointer to the given one; |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1735 |
low level private & friend interface; may also be used to connect to some |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1736 |
externally provided file handle." |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1737 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1738 |
filePointer := something |
1 | 1739 |
! |
1740 |
||
612 | 1741 |
shallowCopyForFinalization |
1742 |
"return a copy for finalization-registration; |
|
1743 |
since all we need at finalization time is the fileDescriptor, |
|
1744 |
a cheaper copy is possible." |
|
1745 |
||
1746 |
^ self class basicNew setFilePointer:filePointer |
|
1 | 1747 |
! |
1748 |
||
612 | 1749 |
shutDown |
1750 |
"close the stream - added for protocol compatibility with PipeStream. |
|
1751 |
see comment there" |
|
1752 |
||
3949 | 1753 |
self isOpen ifTrue:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1754 |
Lobby unregister:self. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1755 |
self closeFile |
3949 | 1756 |
] |
1642
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
1757 |
|
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
1758 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
1 | 1759 |
! ! |
1760 |
||
2 | 1761 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 1762 |
|
1763 |
nextLine |
|
1764 |
"read the next line (characters up to newline). |
|
1765 |
Return a string containing those characters excluding the newline. |
|
1766 |
If the previous-to-last character is a cr, this is also removed, |
|
68 | 1767 |
so its possible to read alien (i.e. ms-dos) text as well. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1768 |
The line must be shorter than 16K characters - otherwise an error is signalled." |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1769 |
|
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1770 |
|line| |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
1771 |
|
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
1772 |
%{ /* STACK:34000 */ |
1 | 1773 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1774 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1775 |
int len, ret; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
1776 |
char buffer[32*1024]; |
521
70533ec40482
use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
1777 |
char *rslt, *nextPtr, *limit; |
22 | 1778 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
1779 |
int _buffered; |
216 | 1780 |
OBJ fp; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1781 |
int lineTooLong = 0; |
2920 | 1782 |
int cutOff = 0; |
1 | 1783 |
|
1133 | 1784 |
__INST(lastErrorNumber) = nil; |
1785 |
if (((fp = __INST(filePointer)) != nil) |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1786 |
&& (__INST(mode) != @symbol(writeonly)) |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1787 |
&& (__INST(binary) != true) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1788 |
) { |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1789 |
f = __FILEVal(fp); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1790 |
buffer[0] = '\0'; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1791 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1792 |
_buffered = (__INST(buffered) == true); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1793 |
if (_buffered) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1794 |
__READING__(f); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1795 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1796 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1797 |
rslt = nextPtr = buffer; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1798 |
limit = buffer + sizeof(buffer) - 2; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1799 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1800 |
for (;;) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1801 |
__READBYTE__(ret, f, nextPtr, _buffered); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1802 |
if (ret <= 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1803 |
if (nextPtr == buffer) |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1804 |
rslt = NULL; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1805 |
if (ret == 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1806 |
__INST(hitEOF) = true; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1807 |
break; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1808 |
} else { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1809 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1810 |
goto err; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1811 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1812 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1813 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1814 |
if (*nextPtr == '\n') { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1815 |
cutOff = 1; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1816 |
*nextPtr = '\0'; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1817 |
break; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1818 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1819 |
if (*nextPtr == '\r') { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1820 |
char peekChar; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1821 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1822 |
/* |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1823 |
* peek ahead for a newLine ... |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1824 |
*/ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1825 |
__READBYTE__(ret, f, &peekChar, _buffered); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1826 |
if (ret <= 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1827 |
cutOff = 1; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1828 |
*nextPtr = '\0'; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1829 |
if (ret == 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1830 |
__INST(hitEOF) = true; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1831 |
break; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1832 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1833 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1834 |
goto err; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1835 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1836 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1837 |
if (peekChar == '\n') { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1838 |
cutOff = 2; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1839 |
*nextPtr = '\0'; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1840 |
break; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1841 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1842 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1843 |
__UNGETC__(peekChar, f, _buffered); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1844 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1845 |
cutOff = 1; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1846 |
*nextPtr = '\0'; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1847 |
break; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1848 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1849 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1850 |
nextPtr++; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1851 |
if (nextPtr >= limit) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1852 |
*nextPtr = '\0'; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1853 |
lineTooLong = 1; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1854 |
if (@global(InfoPrinting) == true) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1855 |
fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n"); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1856 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1857 |
break; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1858 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1859 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1860 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1861 |
if (rslt != NULL) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1862 |
len = nextPtr-buffer; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1863 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1864 |
if (__INST(position) != nil) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1865 |
int __p; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1866 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1867 |
__p = __intVal(__INST(position)) + len + cutOff; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1868 |
__INST(position) = __MKSMALLINT(__p); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1869 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1870 |
/* remove any EOL character */ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1871 |
if (len != 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1872 |
if (buffer[len-1] == '\n') { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1873 |
buffer[--len] = '\0'; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1874 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1875 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1876 |
buffer[--len] = '\0'; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1877 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1878 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1879 |
line = __MKSTRING_L(buffer, len); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1880 |
if (! lineTooLong) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1881 |
RETURN ( line ); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1882 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1883 |
} |
1 | 1884 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1885 |
err: ; |
159 | 1886 |
%}. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1887 |
line notNil ifTrue:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1888 |
"/ the line as read is longer than 32k characters (boy - what a line) |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1889 |
"/ The exception could be handled by reading more and returning the |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1890 |
"/ concatenation in your exception handler (the receiver and the partial |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1891 |
"/ line are passed as parameter) |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1892 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1893 |
^ LineTooLongErrorSignal |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1894 |
raiseRequestWith:(Array with:self with:line) |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
1895 |
errorString:('line too long read error') |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1896 |
]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1897 |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1898 |
hitEOF ifTrue:[^ self pastEnd]. |
159 | 1899 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2 | 1900 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
1 | 1901 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1902 |
^ self errorBinary |
1 | 1903 |
! |
1904 |
||
1905 |
nextPutLine:aString |
|
2920 | 1906 |
"write the characters in aString and append an end-of-Line marker |
1907 |
(LF, CR or CRLF - depending in the setting of eolMode)" |
|
1 | 1908 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1909 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1910 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1911 |
int len, cnt, len1, _buffered; |
216 | 1912 |
OBJ pos, fp; |
537
dc4dad8a5ddd
many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1913 |
char *cp; |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1914 |
int o_offs; |
1 | 1915 |
|
1133 | 1916 |
__INST(lastErrorNumber) = nil; |
1917 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 1918 |
&& (__INST(mode) != @symbol(readonly)) |
1919 |
&& (__INST(binary) != true) |
|
1920 |
&& __isString(aString) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1921 |
) { |
2264 | 1922 |
f = __FILEVal(fp); |
1923 |
len = __stringSize(aString); |
|
1924 |
||
1925 |
if (_buffered = (__INST(buffered) == true)) { |
|
1926 |
__WRITING__(f) |
|
1927 |
} |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1928 |
#ifdef BUGGY |
2264 | 1929 |
__WRITEBYTES__(cnt, f, __stringVal(aString), len, _buffered); |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1930 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1931 |
o_offs = (char *)__stringVal(aString)-(char *)aString; |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1932 |
__WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1933 |
#endif |
2264 | 1934 |
if (cnt == len) { |
2920 | 1935 |
OBJ mode = __INST(eolMode); |
1936 |
||
2264 | 1937 |
len1 = len; |
1938 |
||
2920 | 1939 |
if (mode == @symbol(cr)) { |
1940 |
cp = "\r"; len = 1; |
|
1941 |
} else if (mode == @symbol(crlf)) { |
|
2264 | 1942 |
cp = "\r\n"; len = 2; |
1943 |
} else { |
|
1944 |
cp = "\n"; len = 1; |
|
1945 |
} |
|
1946 |
__WRITEBYTES__(cnt, f, cp, len, _buffered); |
|
1947 |
||
1948 |
if (cnt > 0) { |
|
1949 |
pos = __INST(position); |
|
1950 |
if (pos != nil) { |
|
2920 | 1951 |
int __p; |
1952 |
||
1953 |
__p = __intVal(pos) + len1 + cnt; |
|
1954 |
__INST(position) = __MKSMALLINT(__p); |
|
2264 | 1955 |
} |
1956 |
RETURN ( self ); |
|
1957 |
} |
|
1958 |
} |
|
1959 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
1 | 1960 |
} |
159 | 1961 |
%}. |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1962 |
super nextPutLine:aString. |
1 | 1963 |
! |
1964 |
||
1965 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 1966 |
"read from aStream up to and including a line starting with aStringOrNil |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1967 |
and append all lines to self. |
159 | 1968 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 1969 |
|
22 | 1970 |
If aStringOrNil is nil or not matched, copy preceeds to the end. |
1971 |
(this allows for example to read a Socket and transfer the data quickly |
|
1972 |
into a file - without creating zillions of temporary strings)" |
|
1 | 1973 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1974 |
|srcFilePointer readError line| |
1 | 1975 |
|
2331 | 1976 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
1977 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
1 | 1978 |
srcFilePointer := aStream filePointer. |
2331 | 1979 |
srcFilePointer isNil ifTrue:[aStream errorNotOpen. ^ self]. |
12 | 1980 |
|
1981 |
%{ /* STACK:2000 */ |
|
22 | 1982 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1983 |
#ifndef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1984 |
FILEPOINTER dst; |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1985 |
FILEPOINTER src; |
1 | 1986 |
char *matchString; |
1987 |
int matchLen = 0; |
|
12 | 1988 |
char buffer[1024]; |
1 | 1989 |
|
1133 | 1990 |
__INST(lastErrorNumber) = nil; |
249 | 1991 |
if (__isSmallInteger(srcFilePointer)) { |
2264 | 1992 |
if ((aStringOrNil == nil) || __isString(aStringOrNil)) { |
1993 |
if (aStringOrNil != nil) { |
|
1994 |
matchString = (char *) __stringVal(aStringOrNil); |
|
1995 |
matchLen = __stringSize(aStringOrNil); |
|
1996 |
} |
|
1997 |
dst = __FILEVal(__INST(filePointer)); |
|
1998 |
src = __FILEVal(srcFilePointer); |
|
1999 |
__BEGIN_INTERRUPTABLE__ |
|
2000 |
errno = 0; |
|
2001 |
||
2002 |
__WRITING__(dst) |
|
2003 |
||
2004 |
for (;;) { |
|
2005 |
if (fgets(buffer, sizeof(buffer)-1, src) == NULL) { |
|
2006 |
if (ferror(src)) { |
|
2007 |
readError = __MKSMALLINT(errno); |
|
2008 |
__END_INTERRUPTABLE__ |
|
2009 |
goto err; |
|
2010 |
} |
|
2011 |
break; |
|
2012 |
} |
|
2013 |
if (fputs(buffer, dst) == EOF) { |
|
2014 |
if (ferror(dst)) { |
|
2015 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2016 |
__END_INTERRUPTABLE__ |
|
2017 |
goto err; |
|
2018 |
} |
|
2019 |
break; |
|
2020 |
} |
|
12 | 2021 |
#ifndef OLD |
2264 | 2022 |
if (__INST(buffered) == false) { |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2023 |
FFLUSH(dst); |
2264 | 2024 |
} |
12 | 2025 |
#endif |
2264 | 2026 |
if (matchLen) { |
2027 |
if (strncmp(matchString, buffer, matchLen) == 0) |
|
2028 |
break; |
|
2029 |
} |
|
2030 |
} |
|
2031 |
__END_INTERRUPTABLE__ |
|
2032 |
__INST(position) = nil; |
|
2033 |
RETURN (self); |
|
2034 |
} |
|
1 | 2035 |
} |
159 | 2036 |
err: ; |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2037 |
#endif /* ! NO_STDIO */ |
159 | 2038 |
%}. |
2039 |
readError ifTrue:[ |
|
2264 | 2040 |
aStream setLastErrorNumber:readError. |
2331 | 2041 |
aStream readError. |
2042 |
^ self |
|
159 | 2043 |
]. |
2331 | 2044 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
2045 |
buffered ifFalse:[self errorNotBuffered. ^ self]. |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2046 |
|
159 | 2047 |
" |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2048 |
argument error or unimplemented; try it linewise |
159 | 2049 |
" |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2050 |
[aStream atEnd] whileFalse:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2051 |
line := aStream nextLine. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2052 |
line isNil ifTrue:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2053 |
^ self. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2054 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2055 |
self nextPutLine:line. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2056 |
(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2057 |
^ self |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2058 |
] |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2059 |
]. |
1 | 2060 |
! |
2061 |
||
2062 |
peekForLineStartingWith:aString |
|
2063 |
"read ahead for next line starting with aString; |
|
159 | 2064 |
return the line-string if found, or nil if EOF is encountered. |
2065 |
If matched, not advance position behond that line |
|
2066 |
i.e. nextLine will read the matched line. |
|
2067 |
If not matched, reposition to original position for firther reading." |
|
1 | 2068 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2069 |
|firstPos lastPos line| |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2070 |
|
1 | 2071 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
2072 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2 | 2073 |
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
|
2074 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 2075 |
|
2076 |
%{ /* STACK: 2000 */ |
|
2920 | 2077 |
#ifndef NO_STDIO |
2078 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2079 |
FILEPOINTER f; |
1 | 2080 |
int l; |
12 | 2081 |
char buffer[1024]; |
1 | 2082 |
char *cp; |
2083 |
char *matchString; |
|
2920 | 2084 |
int gotFirst = 0; |
2085 |
#ifdef __VMS__ |
|
2086 |
fpos_t firstpos, lastpos; |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2087 |
# define FTELL(__f__, __pos__) fgetpos(__f__, &(__pos__)) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2088 |
# define FSEEK(__f__, __pos__) fsetpos(__f__, &(__pos__)) |
2920 | 2089 |
#else |
2090 |
long firstpos, lastpos; |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2091 |
# define FTELL(__f__, __pos__) __pos__ = ftell(__f__) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2092 |
# define FSEEK(__f__, __pos__) fseek(__f__, __pos__, SEEK_SET) |
2920 | 2093 |
#endif |
2094 |
||
1133 | 2095 |
__INST(lastErrorNumber) = nil; |
54 | 2096 |
if (__isString(aString)) { |
2264 | 2097 |
matchString = (char *) __stringVal(aString); |
2098 |
l = __stringSize(aString); |
|
2099 |
||
2100 |
f = __FILEVal(__INST(filePointer)); |
|
2101 |
__READING__(f) |
|
2102 |
||
2103 |
for (;;) { |
|
2920 | 2104 |
FTELL(f, lastpos); |
2105 |
if (!gotFirst) { |
|
2106 |
firstpos = lastpos; |
|
2107 |
gotFirst = 1; |
|
2108 |
} |
|
2264 | 2109 |
|
2110 |
__BEGIN_INTERRUPTABLE__ |
|
2111 |
do { |
|
2112 |
cp = fgets(buffer, sizeof(buffer)-1, f); |
|
2113 |
} while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1)); |
|
2114 |
buffer[sizeof(buffer)-1] = '\0'; |
|
2115 |
__END_INTERRUPTABLE__ |
|
2116 |
||
2117 |
if (cp == NULL) { |
|
2118 |
if (ferror(f)) { |
|
2119 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2120 |
goto err; |
|
2121 |
} else { |
|
2920 | 2122 |
FSEEK(f, firstpos); |
2264 | 2123 |
RETURN (nil); |
2124 |
} |
|
2125 |
} |
|
2126 |
if (strncmp(cp, matchString, l) == 0) { |
|
2920 | 2127 |
FSEEK(f, lastpos); |
2264 | 2128 |
break; |
2129 |
} |
|
2130 |
} |
|
2131 |
/* remove EOL character */ |
|
2132 |
cp = buffer; |
|
2920 | 2133 |
while (*cp && (*cp != '\n') && (*cp != '\r')) cp++; |
2264 | 2134 |
*cp = '\0'; |
2135 |
RETURN ( __MKSTRING(buffer) ); |
|
1 | 2136 |
} |
159 | 2137 |
err: ; |
2920 | 2138 |
|
2139 |
# undef FTELL |
|
2140 |
# undef FSEEK |
|
2141 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2142 |
#endif |
159 | 2143 |
%}. |
2144 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2145 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2146 |
"/ try using generic code ... |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2147 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2148 |
firstPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2149 |
[self atEnd] whileFalse:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2150 |
lastPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2151 |
line := self nextLine. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2152 |
line isNil ifTrue:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2153 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2154 |
^ nil |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2155 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2156 |
(line startsWith:aString) ifTrue:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2157 |
self position:lastPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2158 |
^ line |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2159 |
] |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2160 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2161 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2162 |
^ nil |
1 | 2163 |
! |
2164 |
||
2165 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
2166 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
2167 |
return the index in aCollection if found, nil otherwise.. |
|
2168 |
If no match, do not change position; otherwise advance right before the |
|
2169 |
matched line so that nextLine will return this line." |
|
2170 |
||
2171 |
|line startPos linePos index| |
|
2172 |
||
2173 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2174 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2 | 2175 |
binary ifTrue:[^ self errorBinary]. |
2176 |
||
1 | 2177 |
startPos := self position. |
2178 |
[self atEnd] whileFalse:[ |
|
2264 | 2179 |
linePos := self position. |
2180 |
line := self nextLine. |
|
2181 |
line notNil ifTrue:[ |
|
2182 |
index := 1. |
|
2183 |
aCollectionOfStrings do:[:prefix | |
|
2184 |
(line startsWith:prefix) ifTrue:[ |
|
2185 |
self position:linePos. |
|
2186 |
^ index |
|
2187 |
]. |
|
2188 |
index := index + 1 |
|
2189 |
] |
|
2190 |
] |
|
1 | 2191 |
]. |
2192 |
self position:startPos. |
|
2193 |
^ nil |
|
2194 |
! ! |
|
2195 |
||
612 | 2196 |
!ExternalStream methodsFor:'misc functions'! |
2197 |
||
2198 |
async:aBoolean |
|
779 | 2199 |
"set/clear the async attribute - if set, the availability of data on |
612 | 2200 |
the receiver will trigger an ioInterrupt. |
779 | 2201 |
If cleared (which is the default) no special notification is made. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2202 |
Notice: |
2264 | 2203 |
not every OS supports this |
2204 |
- check with OS>>supportsIOInterrupts before using" |
|
92 | 2205 |
|
2206 |
|fd| |
|
2207 |
||
159 | 2208 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2209 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2210 |
OperatingSystem supportsIOInterrupts ifFalse:[ |
2264 | 2211 |
^ self errorUnsupportedOperation |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2212 |
]. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2213 |
|
92 | 2214 |
fd := self fileDescriptor. |
612 | 2215 |
aBoolean ifTrue:[ |
2264 | 2216 |
^ OperatingSystem enableIOInterruptsOn:fd |
612 | 2217 |
]. |
2218 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2219 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2220 |
"Modified: 11.1.1997 / 17:50:21 / cg" |
92 | 2221 |
! |
2222 |
||
612 | 2223 |
backStep |
2224 |
"step back one element - |
|
2225 |
redefined, since position is redefined here" |
|
2226 |
||
2227 |
self position:(self position - 1) |
|
362 | 2228 |
! |
2229 |
||
612 | 2230 |
blocking:aBoolean |
2231 |
"set/clear the blocking attribute - if set (which is the default) |
|
2232 |
a read (using next) on the receiver will block until data is available. |
|
2233 |
If cleared, a read operation will immediately return with a value of |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2234 |
nil. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2235 |
Turning off blocking is useful when reading from PipeStreams |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2236 |
or Sockets, and the amount of data to be read is not known |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2237 |
in advance. However, the data must then be read using #nextBytes: |
3174 | 2238 |
methods, in order to avoid other (pastEnd) exceptions." |
92 | 2239 |
|
159 | 2240 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
612 | 2241 |
^ OperatingSystem setBlocking:aBoolean on:(self fileDescriptor) |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2242 |
|
3174 | 2243 |
"Modified: / 11.1.1997 / 17:48:01 / cg" |
2244 |
"Modified: / 15.1.1998 / 11:49:48 / stefan" |
|
612 | 2245 |
! |
2246 |
||
2247 |
close |
|
2248 |
"close the stream - tell operating system" |
|
2249 |
||
3949 | 2250 |
self isOpen ifTrue:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2251 |
Lobby unregister:self. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2252 |
self closeFile. |
3949 | 2253 |
] |
612 | 2254 |
! |
2255 |
||
2256 |
create |
|
2257 |
"create the stream |
|
2258 |
- this must be redefined in subclass" |
|
2259 |
||
2260 |
^ self subclassResponsibility |
|
2261 |
! |
|
2262 |
||
2263 |
ioctl:ioctlNumber |
|
2264 |
"to provide a simple ioctl facility - an ioctl is performed |
|
2265 |
on the underlying file; no arguments are passed." |
|
2266 |
||
2920 | 2267 |
^ self ioctl:ioctlNumber with:nil |
2268 |
! |
|
2269 |
||
2270 |
ioctl:ioctlNumber with:arg |
|
2271 |
"to provide a simple ioctl facility - an ioctl is performed |
|
2272 |
on the underlying file; the argument is passed as argument. |
|
2273 |
This is not used by ST/X, but provided for special situations |
|
2274 |
- for example, to control proprietrary I/O devices. |
|
2275 |
||
2276 |
Since the type of the argument depends on the ioctl being |
|
2277 |
performed, different arg types are allowed here. |
|
2278 |
If the argument is nil, an ioctl without argument is performed. |
|
2279 |
If the argument is an integral number, its directly passed; |
|
2280 |
if its a kind of ByteArray (ByteArray, String or Structure), |
|
2281 |
or external data (ExternalBytes or ExternalAddress), |
|
2282 |
a pointer to the data is passed. |
|
2283 |
This allows performing most ioctls |
|
2284 |
- however, it might be tricky to setup the buffer. |
|
2285 |
Be careful in what you pass - ST/X cannot validate its correctness." |
|
2286 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2287 |
%{ |
2896 | 2288 |
#if !defined(MSDOS_LIKE) |
2289 |
# if !defined(__openVMS__) |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2290 |
FILEPOINTER f; |
2920 | 2291 |
int ret, ioNum; |
612 | 2292 |
OBJ fp; |
2920 | 2293 |
INT ioArg; |
612 | 2294 |
|
1133 | 2295 |
__INST(lastErrorNumber) = nil; |
2296 |
if ((fp = __INST(filePointer)) != nil) { |
|
2920 | 2297 |
if (__isSmallInteger(ioctlNumber) |
2298 |
&& (__isSmallInteger(arg) |
|
2299 |
|| (arg == nil) |
|
2300 |
|| __isBytes(arg) |
|
2301 |
|| __isExternalBytes(arg) |
|
2302 |
|| __isExternalAddress(arg))) { |
|
2303 |
f = __FILEVal(fp); |
|
2264 | 2304 |
ioNum = __intVal(ioctlNumber); |
2305 |
||
2306 |
__BEGIN_INTERRUPTABLE__ |
|
2307 |
do { |
|
2308 |
errno = 0; |
|
2920 | 2309 |
if (arg == nil) { |
2310 |
ioArg = 0; |
|
2311 |
} else if (__isSmallInteger(arg)) { |
|
2312 |
ioArg = __intVal(arg); |
|
2313 |
} else if (__isExternalBytes(arg)) { |
|
2314 |
ioArg = (INT)(__externalBytesAddress(arg)); |
|
2315 |
} else if (__isExternalAddress(arg)) { |
|
2316 |
ioArg = (INT)(__externalAddressVal(arg)); |
|
2317 |
} else { |
|
2318 |
ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element); |
|
2319 |
} |
|
2320 |
ret = ioctl(fileno(f), ioNum, ioArg); |
|
2264 | 2321 |
} while ((ret < 0) && (errno == EINTR)); |
2322 |
__END_INTERRUPTABLE__ |
|
2323 |
||
2324 |
if (ret >= 0) { |
|
2325 |
RETURN ( __MKSMALLINT(ret) ); |
|
2326 |
} |
|
2327 |
__INST(position) = nil; |
|
2328 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2329 |
} |
|
612 | 2330 |
} |
2896 | 2331 |
# endif |
791 | 2332 |
#endif |
612 | 2333 |
%}. |
2334 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
2335 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2336 |
" |
|
2920 | 2337 |
argument is not an integer |
2338 |
" |
|
2339 |
(ioctlNumber isMemberOf:SmallInteger) ifFalse:[^ self primitiveFailed]. |
|
612 | 2340 |
" |
2920 | 2341 |
the system does not support ioctl (MSDOS or VMS) |
612 | 2342 |
" |
2920 | 2343 |
^ self errorUnsupportedOperation |
612 | 2344 |
! |
2345 |
||
2346 |
open |
|
2347 |
"open the stream |
|
2348 |
- this must be redefined in subclass" |
|
2349 |
||
2350 |
^ self subclassResponsibility |
|
2351 |
! |
|
2352 |
||
2353 |
position |
|
2354 |
"return the position |
|
2355 |
- this must be redefined in subclass" |
|
2356 |
||
2357 |
^ self subclassResponsibility |
|
2358 |
! |
|
2359 |
||
2360 |
position:anInteger |
|
2361 |
"set the position |
|
2362 |
- this must be redefined in subclass" |
|
2363 |
||
2364 |
^ self subclassResponsibility |
|
2365 |
! |
|
2366 |
||
2367 |
reset |
|
2368 |
"set the read position to the beginning of the collection" |
|
2369 |
||
2370 |
self position:"0" 1 |
|
2371 |
! |
|
2372 |
||
1044
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2373 |
setToEnd |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2374 |
"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
|
2375 |
|
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2376 |
^ self subclassResponsibility |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2377 |
! |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2378 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2379 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2380 |
"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
|
2381 |
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
|
2382 |
|
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
2383 |
%{ |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2384 |
#ifdef HAS_FTRUNCATE |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2385 |
FILEPOINTER f; |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2386 |
OBJ fp; |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2387 |
|
1133 | 2388 |
if (((fp = __INST(filePointer)) != nil) |
2389 |
&& (__INST(mode) != @symbol(readonly))) { |
|
2264 | 2390 |
if (__isSmallInteger(newSize)) { |
2391 |
f = __FILEVal(fp); |
|
2392 |
||
2393 |
if (__INST(buffered) == true) { |
|
2394 |
__READING__(f) |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2395 |
FFLUSH(f); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2396 |
OPT_FSEEK(f, 0L, SEEK_END); /* needed in stdio */ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2397 |
} |
2264 | 2398 |
ftruncate(fileno(f), __intVal(newSize)); |
2399 |
RETURN (self); |
|
2400 |
} |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2401 |
} |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2402 |
#endif |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2403 |
%}. |
2331 | 2404 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
2405 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
2406 |
self errorUnsupportedOperation |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2407 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2408 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2409 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2410 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2411 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2412 |
s next:1000 put:$a. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2413 |
s truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2414 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2415 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2416 |
('test' asFilename fileSize) printNL |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2417 |
" |
612 | 2418 |
! ! |
2419 |
||
2420 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
2421 |
||
3674 | 2422 |
nextAvailable:count |
2423 |
"return the next count elements of the stream as aCollection. |
|
2424 |
If the stream reaches the end before count elements have been read, |
|
2425 |
return what is available. (i.e. a shorter collection). |
|
2426 |
The type of collection is specified in #contentsSpecies." |
|
2427 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
2428 |
|buffer n| |
3674 | 2429 |
|
2430 |
binary ifTrue:[ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2431 |
buffer := ByteArray new:count |
3674 | 2432 |
] ifFalse:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2433 |
buffer := String new:count |
3674 | 2434 |
]. |
2435 |
n := self nextAvailableBytes:count into:buffer startingAt:1. |
|
2436 |
n == 0 ifTrue:[^ nil]. |
|
2437 |
||
2438 |
n ~~ count ifTrue:[ |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2439 |
^ buffer copyTo:n |
3674 | 2440 |
]. |
2441 |
^ buffer. |
|
2442 |
||
2443 |
" |
|
2444 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
|
2445 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
2446 |
(ReadStream on:'hello') nextAvailable:3 |
|
2447 |
(ReadStream on:'hello') nextAvailable:10 |
|
2448 |
" |
|
2449 |
||
2450 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
2451 |
||
2452 |
! |
|
2453 |
||
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2454 |
nextAvailableBytes:count into:anObject startingAt:start |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2455 |
"read the next count bytes into an object and return the number of |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2456 |
bytes read or the number of bytes read, if EOF is encountered before, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2457 |
or no more bytes are available for reading (from the pipe/socket). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2458 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2459 |
If the receiver is some socket/pipe-like stream, an exception |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2460 |
is raised if the connection is broken. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2461 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2462 |
Notice, that in contrast to other methods, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2463 |
this does NOT return nil on EOF, but the actual count. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2464 |
Thus allowing read of partial blocks. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2465 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2466 |
The object must have non-pointer indexed instvars |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2467 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2468 |
If anObject is a string or byteArray and reused, this provides the |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2469 |
fastest possible physical I/O (since no new objects are allocated). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2470 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2471 |
Use with care - non object oriented I/O. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2472 |
Warning: in general, you cannot use this method to pass data from other |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2473 |
architectures since it does not care for byte order or float representation." |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2474 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2475 |
%{ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2476 |
FILEPOINTER f; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2477 |
int cnt, offs, ret, _buffered; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2478 |
int objSize, nInstVars, nInstBytes; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2479 |
char *cp; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2480 |
char *extPtr; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2481 |
OBJ pos, fp, oClass; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2482 |
int o_offs; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2483 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2484 |
__INST(lastErrorNumber) = nil; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2485 |
if (((fp = __INST(filePointer)) != nil) |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2486 |
&& (__INST(mode) != @symbol(writeonly)) |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2487 |
&& __bothSmallInteger(count, start) |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2488 |
) { |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2489 |
f = __FILEVal(fp); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2490 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2491 |
cnt = __intVal(count); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2492 |
offs = __intVal(start) - 1; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2493 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2494 |
oClass = __Class(anObject); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2495 |
if (oClass == ExternalBytes) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2496 |
OBJ sz; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2497 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2498 |
nInstBytes = 0; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2499 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2500 |
sz = __externalBytesSize(anObject); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2501 |
if (__isSmallInteger(sz)) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2502 |
objSize = __intVal(sz); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2503 |
} else { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2504 |
objSize = 0; /* unknown */ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2505 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2506 |
} else { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2507 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2508 |
case BYTEARRAY: |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2509 |
case WORDARRAY: |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2510 |
case LONGARRAY: |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2511 |
case SWORDARRAY: |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2512 |
case SLONGARRAY: |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2513 |
case FLOATARRAY: |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2514 |
case DOUBLEARRAY: |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2515 |
break; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2516 |
default: |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2517 |
goto bad; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2518 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2519 |
extPtr = (char *)0; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2520 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2521 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2522 |
objSize = __Size(anObject) - nInstBytes; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2523 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2524 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2525 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2526 |
_buffered = (__INST(buffered) == true); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2527 |
if (_buffered) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2528 |
__READING__(f); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2529 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2530 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2531 |
if (extPtr) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2532 |
__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2533 |
} else { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2534 |
/* |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2535 |
* on interrupt, anObject may be moved to another location. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2536 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2537 |
* to get a new address. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2538 |
*/ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2539 |
offs += nInstBytes; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2540 |
__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2541 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2542 |
if (ret > 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2543 |
pos = __INST(position); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2544 |
if (pos != nil) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2545 |
__INST(position) = __MKSMALLINT(__intVal(pos) + ret); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2546 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2547 |
RETURN (__MKSMALLINT(ret)); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2548 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2549 |
if (ret == 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2550 |
__INST(hitEOF) = true; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2551 |
} else /* ret < 0 */ { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2552 |
__INST(position) = nil; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2553 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2554 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
2555 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2556 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2557 |
bad: ; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2558 |
%}. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2559 |
(hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2560 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2561 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2562 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2563 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2564 |
count not integer or arg not bit-like (String, ByteArray etc) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2565 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2566 |
^ self primitiveFailed |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2567 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2568 |
|
612 | 2569 |
nextByte |
2570 |
"read the next byte and return it as an Integer; return nil on error. |
|
2571 |
This is allowed in both text and binary modes, always returning the |
|
2572 |
bytes binary value as an integer in 0..255." |
|
2573 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2574 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2575 |
FILEPOINTER f; |
612 | 2576 |
unsigned char byte; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2577 |
int ret, _buffered; |
612 | 2578 |
OBJ fp; |
2579 |
||
1133 | 2580 |
__INST(lastErrorNumber) = nil; |
2581 |
if (((fp = __INST(filePointer)) != nil) |
|
2582 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2583 |
f = __FILEVal(fp); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2584 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2585 |
_buffered = (__INST(buffered) == true); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2586 |
if (_buffered) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2587 |
__READING__(f) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2588 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2589 |
__READBYTE__(ret, f, &byte, _buffered); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2590 |
if (ret > 0) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2591 |
OBJ pos; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2592 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2593 |
if ((pos = __INST(position)) != nil) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2594 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2595 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2596 |
RETURN (__MKSMALLINT(byte)); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2597 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2598 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2599 |
if (ret == 0) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2600 |
__INST(hitEOF) = true; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2601 |
} else /* ret < 0 */ { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2602 |
__INST(position) = nil; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2603 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2604 |
} |
612 | 2605 |
} |
2606 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2607 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2608 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2609 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2610 |
^ self errorWriteOnly |
|
2611 |
! |
|
2612 |
||
2613 |
nextBytes:count into:anObject startingAt:start |
|
2614 |
"read the next count bytes into an object and return the number of |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2615 |
bytes read or the number of bytes read, if EOF is encountered before. |
612 | 2616 |
If the receiver is some socket/pipe-like stream, an exception |
2617 |
is raised if the connection is broken. |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2618 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2619 |
Warning: if used with a pipe/socket, this blocks until the requested number |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2620 |
of bytes have been read. See #nextAvailableBytes:into:startingAt: |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2621 |
to only read whats there. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2622 |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2623 |
Notice, that in contrast to other methods, |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2624 |
this does NOT return nil on EOF, but the actual count. |
612 | 2625 |
Thus allowing read of partial blocks. |
2626 |
||
2627 |
The object must have non-pointer indexed instvars |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2628 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2629 |
or an externalBytes object (with known size). |
612 | 2630 |
If anObject is a string or byteArray and reused, this provides the |
2631 |
fastest possible physical I/O (since no new objects are allocated). |
|
2632 |
||
2633 |
Use with care - non object oriented I/O. |
|
2634 |
Warning: in general, you cannot use this method to pass data from other |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2635 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2636 |
since it does not care for byte order or float representation." |
612 | 2637 |
|
2638 |
%{ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2639 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2640 |
int cnt, offs, ret, _buffered; |
612 | 2641 |
int objSize, nInstVars, nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2642 |
char *extPtr; |
612 | 2643 |
OBJ pos, fp, oClass; |
2644 |
||
1133 | 2645 |
__INST(lastErrorNumber) = nil; |
2646 |
if (((fp = __INST(filePointer)) != nil) |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2647 |
&& (__INST(mode) != @symbol(writeonly)) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2648 |
&& __bothSmallInteger(count, start) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2649 |
) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2650 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2651 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2652 |
cnt = __intVal(count); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2653 |
offs = __intVal(start) - 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2654 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2655 |
oClass = __Class(anObject); |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2656 |
if (oClass == ExternalBytes) { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2657 |
OBJ sz; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2658 |
|
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2659 |
nInstBytes = 0; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2660 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2661 |
sz = __externalBytesSize(anObject); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2662 |
if (__isSmallInteger(sz)) { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2663 |
objSize = __intVal(sz); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2664 |
} else { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2665 |
objSize = 0; /* unknown */ |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2666 |
} |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2667 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2668 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2669 |
case BYTEARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2670 |
case WORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2671 |
case LONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2672 |
case SWORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2673 |
case SLONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2674 |
case FLOATARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2675 |
case DOUBLEARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2676 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2677 |
default: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2678 |
goto bad; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2679 |
} |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2680 |
extPtr = (char *)0; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2681 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2682 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2683 |
objSize = __Size(anObject) - nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2684 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2685 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2686 |
_buffered = (__INST(buffered) == true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2687 |
if (_buffered) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2688 |
__READING__(f); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2689 |
} |
2861 | 2690 |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2691 |
if (extPtr) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2692 |
__READBYTES__(ret, f, extPtr+offs, cnt, _buffered); |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2693 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2694 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2695 |
* on interrupt, anObject may be moved to another location. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2696 |
* So we pass anObject, and the offset to the __READBYTES_OBJ__ macro. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2697 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2698 |
offs += nInstBytes; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2699 |
__READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered); |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2700 |
} |
2861 | 2701 |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2702 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2703 |
pos = __INST(position); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2704 |
if (pos != nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2705 |
__INST(position) = __MKSMALLINT(__intVal(pos) + ret); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2706 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2707 |
RETURN (__MKSMALLINT(ret)); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2708 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2709 |
if (ret == 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2710 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2711 |
} else /* ret < 0 */ { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2712 |
__INST(position) = nil; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2713 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2714 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2715 |
} |
612 | 2716 |
} |
2717 |
bad: ; |
|
2718 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2719 |
(hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0]. |
612 | 2720 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2721 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2722 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2723 |
" |
|
2724 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
2725 |
" |
|
2726 |
^ self primitiveFailed |
|
92 | 2727 |
! |
2728 |
||
612 | 2729 |
nextLong |
2730 |
"Read four bytes (msb-first) and return the value as a 32-bit signed Integer. |
|
2731 |
The returned value may be a LargeInteger. |
|
2732 |
(msb-first for compatibility with other smalltalks)" |
|
2733 |
||
2734 |
^ self nextUnsignedLongMSB:true |
|
2735 |
! |
|
2736 |
||
2737 |
nextLongMSB:msbFlag |
|
2738 |
"Read four bytes and return the value as a 32-bit signed Integer, |
|
2739 |
which may be a LargeInteger. |
|
2740 |
If msbFlag is true, value is read with most-significant byte first, |
|
2741 |
otherwise least-significant byte comes first. |
|
2742 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
2743 |
Works in both binary and text modes." |
|
2744 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2745 |
%{ |
612 | 2746 |
OBJ fp; |
2747 |
||
1133 | 2748 |
__INST(lastErrorNumber) = nil; |
2749 |
if (((fp = __INST(filePointer)) != nil) |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2750 |
&& (__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
|
2751 |
) { |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2752 |
FILEPOINTER f; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2753 |
int ret, _buffered; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2754 |
int value; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2755 |
union { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2756 |
unsigned char buffer[4]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2757 |
int intVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2758 |
} u; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2759 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2760 |
f = __FILEVal(fp); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2761 |
_buffered = (__INST(buffered) == true); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2762 |
if (_buffered) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2763 |
__READING__(f) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2764 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2765 |
__READBYTES__(ret, f, u.buffer, 4, _buffered); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2766 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2767 |
if (ret == 4) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2768 |
OBJ pos; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2769 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2770 |
if ((pos = __INST(position)) != nil) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2771 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 4); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2772 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2773 |
if (msbFlag == true) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2774 |
#if defined(__MSBFIRST) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2775 |
value = u.intVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2776 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2777 |
value = (u.buffer[0] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2778 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2779 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2780 |
value = (value << 8) | (u.buffer[3] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2781 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2782 |
} else { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2783 |
#if defined(__LSBFIRST) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2784 |
value = u.intVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2785 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2786 |
value = (u.buffer[3] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2787 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2788 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2789 |
value = (value << 8) | (u.buffer[0] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2790 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2791 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2792 |
#ifdef alpha64 |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2793 |
RETURN ( __MKSMALLINT(value)); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2794 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2795 |
if ((value >= _MIN_INT) && (value <= _MAX_INT)) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2796 |
RETURN ( __MKSMALLINT(value)); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2797 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2798 |
RETURN ( __MKLARGEINT(value) ); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2799 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2800 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2801 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2802 |
if (ret < 0) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2803 |
__INST(position) = nil; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2804 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2805 |
} else /* ret == 0 */ { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2806 |
__INST(hitEOF) = true; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2807 |
} |
612 | 2808 |
} |
2809 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2810 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2811 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2812 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2813 |
^ self readError. |
|
1079 | 2814 |
|
362 | 2815 |
! |
2816 |
||
612 | 2817 |
nextShortMSB:msbFlag |
2818 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
2819 |
If msbFlag is true, value is read with most-significant byte first, |
|
2820 |
otherwise least-significant byte comes first. |
|
2821 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
2822 |
Works in both binary and text modes." |
|
2823 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2824 |
%{ |
612 | 2825 |
OBJ fp; |
2826 |
||
1133 | 2827 |
__INST(lastErrorNumber) = nil; |
2828 |
if (((fp = __INST(filePointer)) != nil) |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2829 |
&& (__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
|
2830 |
) { |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2831 |
FILEPOINTER f; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2832 |
int ret, _buffered; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2833 |
short value; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2834 |
union { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2835 |
unsigned char buffer[2]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2836 |
short shortVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2837 |
} u; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2838 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2839 |
f = __FILEVal(fp); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2840 |
_buffered = (__INST(buffered) == true); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2841 |
if (_buffered) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2842 |
__READING__(f) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2843 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2844 |
__READBYTES__(ret, f, u.buffer, 2, _buffered); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2845 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2846 |
if (ret == 2) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2847 |
OBJ pos; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2848 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2849 |
if ((pos = __INST(position)) != nil) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2850 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 2); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2851 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2852 |
if (msbFlag == true) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2853 |
#if defined(__MSBFIRST) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2854 |
value = u.shortVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2855 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2856 |
value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2857 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2858 |
} else { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2859 |
#if defined(__LSBFIRST) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2860 |
value = u.shortVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2861 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2862 |
value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2863 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2864 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2865 |
RETURN (__MKSMALLINT(value)); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2866 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2867 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2868 |
if (ret < 0) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2869 |
__INST(position) = nil; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2870 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2871 |
} else /* ret == 0 */ { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2872 |
__INST(hitEOF) = true; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2873 |
} |
612 | 2874 |
} |
2875 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2876 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2877 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2878 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2879 |
^ self readError. |
|
2880 |
! |
|
2881 |
||
2882 |
nextUnsignedLongMSB:msbFlag |
|
2883 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
|
2884 |
a LargeInteger. |
|
2885 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
2886 |
least-significant byte comes first. |
|
2887 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
2888 |
Works in both binary and text modes." |
|
2889 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2890 |
%{ |
612 | 2891 |
OBJ fp; |
2892 |
||
1133 | 2893 |
__INST(lastErrorNumber) = nil; |
2894 |
if (((fp = __INST(filePointer)) != nil) |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2895 |
&& (__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
|
2896 |
) { |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2897 |
FILEPOINTER f; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2898 |
int ret, _buffered; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2899 |
unsigned INT value; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2900 |
union { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2901 |
unsigned char buffer[4]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2902 |
unsigned int intVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2903 |
} u; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2904 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2905 |
f = __FILEVal(fp); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2906 |
_buffered = (__INST(buffered) == true); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2907 |
if (_buffered) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2908 |
__READING__(f) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2909 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2910 |
__READBYTES__(ret, f, u.buffer, 4, _buffered); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2911 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2912 |
if (ret == 4) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2913 |
OBJ pos; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2914 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2915 |
if ((pos = __INST(position)) != nil) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2916 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 4); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2917 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2918 |
if (msbFlag == true) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2919 |
#if defined(__MSBFIRST) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2920 |
value = u.intVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2921 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2922 |
value = u.buffer[0]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2923 |
value = (value << 8) | u.buffer[1]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2924 |
value = (value << 8) | u.buffer[2]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2925 |
value = (value << 8) | u.buffer[3]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2926 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2927 |
} else { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2928 |
#if defined(__LSBFIRST) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2929 |
value = u.intVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2930 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2931 |
value = u.buffer[3]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2932 |
value = (value << 8) | u.buffer[2]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2933 |
value = (value << 8) | u.buffer[1]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2934 |
value = (value << 8) | u.buffer[0]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2935 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2936 |
} |
3456
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2937 |
#ifdef alpha64 |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2938 |
value &= 0xFFFFFFFF; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2939 |
RETURN (__MKSMALLINT(value)); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2940 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2941 |
if (value <= _MAX_INT) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2942 |
RETURN (__MKSMALLINT(value)); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2943 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2944 |
RETURN (__MKULARGEINT(value) ); |
3456
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2945 |
#endif |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2946 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2947 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2948 |
if (ret < 0) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2949 |
__INST(position) = nil; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2950 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2951 |
} else /* ret == 0 */ { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2952 |
__INST(hitEOF) = true; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2953 |
} |
612 | 2954 |
} |
2955 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2956 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2957 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2958 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2959 |
^ self readError. |
|
2960 |
! |
|
2961 |
||
2962 |
nextUnsignedShortMSB:msbFlag |
|
2963 |
"Read two bytes and return the value as a 16-bit unsigned Integer. |
|
1079 | 2964 |
If msbFlag is true, value is read with most-significant byte first, |
2965 |
otherwise least-significant byte comes first. |
|
612 | 2966 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
2967 |
Works in both binary and text modes." |
|
2968 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2969 |
%{ |
612 | 2970 |
OBJ fp; |
2971 |
||
1133 | 2972 |
__INST(lastErrorNumber) = nil; |
2973 |
if (((fp = __INST(filePointer)) != nil) |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2974 |
&& (__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
|
2975 |
) { |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2976 |
FILEPOINTER f; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2977 |
int ret, _buffered; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2978 |
unsigned int value; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2979 |
union { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2980 |
unsigned char buffer[2]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2981 |
unsigned short shortVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2982 |
} u; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2983 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2984 |
f = __FILEVal(fp); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2985 |
_buffered = (__INST(buffered) == true); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2986 |
if (_buffered) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2987 |
__READING__(f) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2988 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2989 |
__READBYTES__(ret, f, u.buffer, 2, _buffered); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2990 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2991 |
if (ret == 2) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2992 |
OBJ pos; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2993 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2994 |
if ((pos = __INST(position)) != nil) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2995 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 2); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2996 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2997 |
if (msbFlag == true) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2998 |
#if defined(__MSBFIRST) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
2999 |
value = u.shortVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3000 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3001 |
value = (u.buffer[0] << 8) | u.buffer[1]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3002 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3003 |
} else { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3004 |
#if defined(__LSBFIRST) |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3005 |
value = u.shortVal; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3006 |
#else |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3007 |
value = (u.buffer[1] << 8) | u.buffer[0]; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3008 |
#endif |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3009 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3010 |
RETURN (__MKSMALLINT(value)); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3011 |
} |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3012 |
|
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3013 |
if (ret < 0) { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3014 |
__INST(position) = nil; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3015 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3016 |
} else /* ret == 0 */ { |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3017 |
__INST(hitEOF) = true; |
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3018 |
} |
612 | 3019 |
} |
3020 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3021 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3022 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
3023 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
3024 |
^ self readError. |
|
3025 |
! |
|
3026 |
||
3027 |
nextWord |
|
3028 |
"in text-mode: |
|
2264 | 3029 |
read the alphaNumeric next word (i.e. up to non letter-or-digit). |
3030 |
return a string containing those characters. |
|
612 | 3031 |
in binary-mode: |
2264 | 3032 |
read two bytes (msb-first) and return the value as a 16-bit |
3033 |
unsigned Integer (for compatibility with other smalltalks)" |
|
612 | 3034 |
|
3035 |
binary ifTrue:[ |
|
2264 | 3036 |
^ self nextUnsignedShortMSB:true |
92 | 3037 |
]. |
612 | 3038 |
^ self nextAlphaNumericWord |
3039 |
! ! |
|
3040 |
||
3041 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
3042 |
||
3043 |
nextPutByte:aByteValue |
|
3044 |
"write a byte. |
|
3045 |
Works in both binary and text modes." |
|
3046 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3047 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3048 |
FILEPOINTER f; |
612 | 3049 |
char c; |
3050 |
OBJ pos, fp; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3051 |
int cnt, _buffered; |
612 | 3052 |
|
1133 | 3053 |
__INST(lastErrorNumber) = nil; |
3054 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3055 |
&& (__INST(mode) != @symbol(readonly)) |
3056 |
&& __isSmallInteger(aByteValue) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3057 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3058 |
) { |
2264 | 3059 |
c = __intVal(aByteValue); |
3060 |
f = __FILEVal(fp); |
|
3061 |
if (_buffered = (__INST(buffered) == true)) { |
|
3062 |
__WRITING__(f) |
|
3063 |
} |
|
3064 |
__WRITEBYTE__(cnt, f, &c, _buffered); |
|
3065 |
if (cnt == 1) { |
|
3066 |
pos = __INST(position); |
|
3067 |
if (pos != nil) |
|
3068 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
|
3069 |
RETURN (self); |
|
3070 |
} |
|
3071 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 3072 |
} |
3073 |
%}. |
|
2331 | 3074 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
3075 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
3076 |
self writeError. |
|
612 | 3077 |
! |
3078 |
||
3079 |
nextPutBytes:count from:anObject startingAt:start |
|
3080 |
"write count bytes from an object starting at index start. |
|
3081 |
return the number of bytes written - which could be 0. |
|
3082 |
The object must have non-pointer indexed instvars |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3083 |
(i.e. be a ByteArray, String, Float- or DoubleArray), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3084 |
or an externalBytes object (with known size). |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3085 |
|
612 | 3086 |
Use with care - non object oriented i/o. |
3087 |
Warning: in general, you cannot use this method to pass data to other |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3088 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3089 |
since it does not care for byte order or float representation." |
612 | 3090 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3091 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3092 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3093 |
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
|
3094 |
int objSize, nInstVars, nInstBytes, _buffered; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3095 |
char *extPtr; |
612 | 3096 |
OBJ oClass, pos, fp; |
3097 |
||
1133 | 3098 |
__INST(lastErrorNumber) = nil; |
3099 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3100 |
&& (__INST(mode) != @symbol(readonly)) |
3101 |
&& __bothSmallInteger(count, start) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3102 |
) { |
2264 | 3103 |
len = __intVal(count); |
3104 |
offs = __intVal(start) - 1; |
|
3105 |
f = __FILEVal(fp); |
|
3106 |
||
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3107 |
oClass = __Class(anObject); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3108 |
if (oClass == ExternalBytes) { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3109 |
OBJ sz; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3110 |
|
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3111 |
nInstBytes = 0; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3112 |
extPtr = (char *)__externalBytesAddress(anObject); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3113 |
sz = __externalBytesSize(anObject); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3114 |
if (__isSmallInteger(sz)) { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3115 |
objSize = __intVal(sz); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3116 |
} else { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3117 |
objSize = 0; /* unknown */ |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3118 |
} |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3119 |
} else { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3120 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3121 |
case BYTEARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3122 |
case WORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3123 |
case LONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3124 |
case SWORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3125 |
case SLONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3126 |
case FLOATARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3127 |
case DOUBLEARRAY: |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3128 |
break; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3129 |
default: |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3130 |
goto bad; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3131 |
} |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3132 |
extPtr = (char *)0; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3133 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3134 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3135 |
objSize = __Size(anObject) - nInstBytes; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3136 |
} |
2264 | 3137 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
3138 |
if (_buffered = (__INST(buffered) == true)) { |
|
3139 |
__WRITING__(f) |
|
3140 |
} |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3141 |
|
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3142 |
if (extPtr) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3143 |
__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered); |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3144 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3145 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3146 |
* on interrupt, anObject may be moved to another location. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3147 |
* So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3148 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3149 |
offs += nInstBytes; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3150 |
__WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered); |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3151 |
} |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3152 |
|
2264 | 3153 |
if (cnt >= 0) { |
3154 |
pos = __INST(position); |
|
3155 |
if (pos != nil) |
|
3156 |
__INST(position) = __MKSMALLINT(__intVal(pos) + cnt); |
|
3157 |
RETURN ( __MKSMALLINT(cnt) ); |
|
3158 |
} |
|
3159 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3160 |
} |
|
612 | 3161 |
} |
3162 |
bad: ; |
|
3163 |
%}. |
|
3164 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
3165 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3166 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
3167 |
^ self primitiveFailed |
|
3168 |
! |
|
3169 |
||
3170 |
nextPutLong:aNumber MSB:msbFlag |
|
3171 |
"Write the argument, aNumber as a long (four bytes). If msbFlag is |
|
3172 |
true, data is written most-significant byte first; otherwise least |
|
3173 |
first. |
|
3174 |
Works in both binary and text modes." |
|
3175 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3176 |
%{ |
612 | 3177 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3178 |
union { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3179 |
char bytes[4]; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3180 |
int intVal; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3181 |
} u; |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3182 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3183 |
int cnt, _buffered; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3184 |
OBJ fp; |
612 | 3185 |
|
1133 | 3186 |
__INST(lastErrorNumber) = nil; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3187 |
if (__isSmallInteger(aNumber)) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3188 |
num = __intVal(aNumber); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3189 |
} else { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3190 |
#ifdef alpha64 |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3191 |
goto badArg; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3192 |
#else |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3193 |
num = __longIntVal(aNumber); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3194 |
if (num == 0) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3195 |
num = __signedLongIntVal(aNumber); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3196 |
if (num == 0) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3197 |
/* bad arg or out-of-range integer |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3198 |
* (handled by the fallBack code) |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3199 |
*/ |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3200 |
goto badArg; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3201 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3202 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3203 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3204 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3205 |
|
1133 | 3206 |
if (((fp = __INST(filePointer)) != nil) |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3207 |
&& (__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
|
3208 |
) { |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3209 |
if (msbFlag == true) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3210 |
#if defined(__MSBFIRST) |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3211 |
u.intVal = num; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3212 |
#else |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3213 |
u.bytes[0] = (num >> 24) & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3214 |
u.bytes[1] = (num >> 16) & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3215 |
u.bytes[2] = (num >> 8) & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3216 |
u.bytes[3] = num & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3217 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3218 |
} else { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3219 |
#if defined(__LSBFIRST) |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3220 |
u.intVal = num; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3221 |
#else |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3222 |
u.bytes[3] = (num >> 24) & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3223 |
u.bytes[2] = (num >> 16) & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3224 |
u.bytes[1] = (num >> 8) & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3225 |
u.bytes[0] = num & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3226 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3227 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3228 |
|
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3229 |
f = __FILEVal(fp); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3230 |
if (_buffered = (__INST(buffered) == true)) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3231 |
__WRITING__(f) |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3232 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3233 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3234 |
|
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3235 |
if (cnt == 4) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3236 |
OBJ pos; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3237 |
|
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3238 |
if ((pos = __INST(position)) != nil) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3239 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 4); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3240 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3241 |
RETURN ( self ); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3242 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3243 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 3244 |
} |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3245 |
badArg: ; |
612 | 3246 |
%}. |
2331 | 3247 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
3248 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
3249 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
|
612 | 3250 |
|
3251 |
aNumber isInteger ifTrue:[ |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3252 |
^ super nextPutLong:aNumber MSB:msbFlag |
92 | 3253 |
]. |
612 | 3254 |
self argumentMustBeInteger |
3255 |
! |
|
3256 |
||
3257 |
nextPutShort:aNumber MSB:msbFlag |
|
3258 |
"Write the argument, aNumber as a short (two bytes). If msbFlag is |
|
3259 |
true, data is written most-significant byte first; otherwise least |
|
3260 |
first. |
|
3261 |
Works in both binary and text modes." |
|
3262 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3263 |
%{ |
612 | 3264 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3265 |
union { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3266 |
char bytes[2]; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3267 |
short shortVal; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3268 |
} u; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3269 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3270 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3271 |
int cnt, _buffered; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3272 |
OBJ fp; |
612 | 3273 |
|
1133 | 3274 |
__INST(lastErrorNumber) = nil; |
3275 |
if (((fp = __INST(filePointer)) != nil) |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3276 |
&& (__INST(mode) != @symbol(readonly)) |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3277 |
&& __isSmallInteger(aNumber) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3278 |
) { |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3279 |
num = __intVal(aNumber); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3280 |
if (msbFlag == true) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3281 |
#if defined(__MSBFIRST) |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3282 |
u.shortVal = num; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3283 |
#else |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3284 |
u.bytes[0] = (num >> 8) & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3285 |
u.bytes[1] = num & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3286 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3287 |
} else { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3288 |
#if defined(__LSBFIRST) |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3289 |
u.shortVal = num; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3290 |
#else |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3291 |
u.bytes[1] = (num >> 8) & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3292 |
u.bytes[0] = num & 0xFF; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3293 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3294 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3295 |
|
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3296 |
f = __FILEVal(fp); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3297 |
if (_buffered = (__INST(buffered) == true)) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3298 |
__WRITING__(f) |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3299 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3300 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3301 |
|
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3302 |
if (cnt == 2) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3303 |
OBJ pos; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3304 |
|
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3305 |
if ((pos = __INST(position)) != nil) { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3306 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 2); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3307 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3308 |
RETURN ( self ); |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3309 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3310 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 3311 |
} |
3312 |
%}. |
|
2331 | 3313 |
lastErrorNumber notNil ifTrue:[^ self writeError. ^ self]. |
3314 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
3315 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
612 | 3316 |
self argumentMustBeInteger |
10 | 3317 |
! ! |
612 | 3318 |
|
3319 |
!ExternalStream methodsFor:'private'! |
|
3320 |
||
3321 |
clearEOF |
|
3322 |
hitEOF := false |
|
3323 |
! |
|
3324 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3325 |
connectTo:aFileDescriptor withMode:openmode |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3326 |
"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
|
3327 |
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
|
3328 |
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
|
3329 |
a Stream object. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3330 |
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
|
3331 |
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
|
3332 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3333 |
|retVal| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3334 |
|
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3335 |
filePointer notNil ifTrue:[^ self errorAlreadyOpen]. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3336 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3337 |
FILEPOINTER f; |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3338 |
OBJ fp; |
2765 | 3339 |
FILE *fdopen(); |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3340 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3341 |
if (__isSmallInteger(aFileDescriptor) |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3342 |
&& (__qClass(openmode)== @global(String))) { |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3343 |
f = (FILEPOINTER) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode)); |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3344 |
if (f == NULL) { |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3345 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3346 |
__INST(position) = nil; |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3347 |
} else { |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3348 |
__INST(filePointer) = fp = __MKFILEPOINTER(f); __STORE(self, fp); |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3349 |
__INST(position) = __MKSMALLINT(1); |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3350 |
retVal = self; |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3351 |
} |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3352 |
} |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3353 |
%}. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3354 |
retVal notNil ifTrue:[ |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3355 |
buffered := true. "default is buffered" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3356 |
Lobby register:self |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3357 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3358 |
lastErrorNumber notNil ifTrue:[ |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3359 |
" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3360 |
the open failed for some reason ... |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3361 |
" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
3362 |
^ self openError |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3363 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3364 |
^ retVal |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3365 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3366 |
|
2963 | 3367 |
open:aPath withMode:mode |
3368 |
"low level open; opens the file/device and sets the filePointer instance |
|
3369 |
variable. Careful: this does not care for any other state." |
|
3370 |
||
3371 |
|ok| |
|
3372 |
||
3373 |
ok := false. |
|
3374 |
%{ |
|
3375 |
FILE *f; |
|
3376 |
OBJ fp; |
|
3377 |
||
3378 |
if (__isString(aPath)) { |
|
4456 | 3379 |
__BEGIN_INTERRUPTABLE__ |
3380 |
do { |
|
3381 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(mode)); |
|
3382 |
} while ((f == NULL) && (errno == EINTR)); |
|
3383 |
__END_INTERRUPTABLE__ |
|
3384 |
if (f == NULL) { |
|
3385 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3386 |
} else { |
|
3387 |
__INST(filePointer) = fp = __MKFILEPOINTER(f); __STORE(self, fp); |
|
3388 |
ok = true; |
|
3389 |
} |
|
2963 | 3390 |
} |
3391 |
%}. |
|
3392 |
ok ifFalse:[ |
|
4456 | 3393 |
" |
3394 |
the open failed for some reason ... |
|
3395 |
" |
|
3396 |
^ self openError |
|
3397 |
]. |
|
3398 |
position := 1. |
|
2963 | 3399 |
Lobby register:self. |
3400 |
! |
|
3401 |
||
612 | 3402 |
reOpen |
3403 |
"sent after snapin to reopen streams. |
|
3404 |
cannot reopen here since I am abstract and have no device knowledge" |
|
3405 |
||
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
3406 |
self class name errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR. |
612 | 3407 |
filePointer := nil. |
3408 |
Lobby unregister:self. |
|
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
3409 |
|
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
3410 |
"Modified: 10.1.1997 / 17:50:44 / cg" |
612 | 3411 |
! |
3412 |
||
3413 |
setLastError:aNumber |
|
3414 |
lastErrorNumber := aNumber |
|
3415 |
! ! |
|
3416 |
||
3417 |
!ExternalStream methodsFor:'queries'! |
|
3418 |
||
3419 |
isBinary |
|
3420 |
"return true, if the stream is in binary (as opposed to text-) mode. |
|
3421 |
The default when created is false." |
|
3422 |
||
3423 |
^ binary |
|
3424 |
! |
|
3425 |
||
3426 |
isExternalStream |
|
3427 |
"return true, if the receiver is some kind of externalStream; |
|
3428 |
true is returned here - the method redefined from Object." |
|
3429 |
||
3430 |
^ true |
|
3431 |
! |
|
3432 |
||
3863 | 3433 |
isOpen |
3434 |
"return true, if this stream is open" |
|
3435 |
||
3436 |
^ filePointer notNil |
|
3437 |
! |
|
3438 |
||
612 | 3439 |
isReadable |
3440 |
"return true, if this stream can be read from" |
|
3441 |
||
3442 |
^ (mode ~~ #writeonly) |
|
3443 |
! |
|
3444 |
||
3445 |
isWritable |
|
3446 |
"return true, if this stream can be written to" |
|
3447 |
||
3448 |
^ (mode ~~ #readonly) |
|
3449 |
! ! |
|
3450 |
||
3451 |
!ExternalStream methodsFor:'reading'! |
|
3452 |
||
3453 |
next |
|
3454 |
"return the next element; advance read position. |
|
3455 |
In binary mode, an integer is returned, otherwise a character. |
|
3456 |
If there are no more elements, nil is returned." |
|
1 | 3457 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3458 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3459 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3460 |
int ret, _buffered; |
612 | 3461 |
OBJ pos, fp; |
3462 |
unsigned char ch; |
|
3463 |
||
1133 | 3464 |
__INST(lastErrorNumber) = nil; |
3465 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3466 |
&& (__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
|
3467 |
) { |
2264 | 3468 |
f = __FILEVal(fp); |
3469 |
||
3470 |
_buffered = (__INST(buffered) == true); |
|
3471 |
if (_buffered) { |
|
3472 |
__READING__(f) |
|
3473 |
} |
|
3474 |
__READBYTE__(ret, f, &ch, _buffered); |
|
3475 |
||
3476 |
if (ret > 0) { |
|
3477 |
pos = __INST(position); |
|
3478 |
if (__isSmallInteger(pos)) { |
|
3479 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
|
3480 |
} else { |
|
3481 |
__INST(position) = nil; |
|
3482 |
} |
|
3483 |
if (__INST(binary) == true) { |
|
3484 |
RETURN ( __MKSMALLINT(ch) ); |
|
3485 |
} |
|
3486 |
RETURN ( __MKCHARACTER(ch) ); |
|
3487 |
} |
|
3488 |
||
3489 |
__INST(position) = nil; |
|
3490 |
if (ret < 0) { |
|
3491 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3492 |
} else /* ret == 0 */ { |
|
3493 |
__INST(hitEOF) = true; |
|
3494 |
} |
|
612 | 3495 |
} |
3496 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3497 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3498 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3499 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2331 | 3500 |
^ self errorWriteOnly |
612 | 3501 |
! |
3502 |
||
3503 |
next:count |
|
3504 |
"return the next count elements of the stream as a collection. |
|
3505 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
3506 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3507 |
|coll nRead| |
612 | 3508 |
|
3509 |
binary ifTrue:[ |
|
2264 | 3510 |
coll := ByteArray uninitializedNew:count |
612 | 3511 |
] ifFalse:[ |
2264 | 3512 |
coll := String new:count |
612 | 3513 |
]. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3514 |
nRead := self nextBytes:count into:coll startingAt:1. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3515 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3516 |
"/ for readStream protocol compatibility, |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3517 |
"/ we must raise an exception here. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3518 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3519 |
nRead < count ifTrue:[ |
2264 | 3520 |
^ self pastEnd |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3521 |
]. |
612 | 3522 |
^ coll |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3523 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3524 |
"Modified: 11.1.1997 / 17:44:17 / cg" |
612 | 3525 |
! |
3526 |
||
3527 |
peek |
|
3528 |
"return the element to be read next without advancing read position. |
|
3529 |
In binary mode, an integer is returned, otherwise a character. |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3530 |
If there are no more elements, nil is returned." |
612 | 3531 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3532 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3533 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3534 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3535 |
int ret, _buffered; |
216 | 3536 |
OBJ fp; |
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3537 |
OBJ ra; |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3538 |
|
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3539 |
if ((ra = __INST(readAhead)) != nil) { |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3540 |
if (__INST(binary) == true) { |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3541 |
RETURN ( ra ); |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3542 |
} |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3543 |
c = __intVal(ra); |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3544 |
RETURN ( __MKCHARACTER(c) ); |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
3545 |
} |
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
3546 |
|
1133 | 3547 |
__INST(lastErrorNumber) = nil; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3548 |
|
1133 | 3549 |
if (((fp = __INST(filePointer)) != nil) |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3550 |
&& (__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
|
3551 |
) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3552 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3553 |
_buffered = (__INST(buffered) == true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3554 |
if (_buffered) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3555 |
__READING__(f) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3556 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3557 |
__READBYTE__(ret, f, &c, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3558 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3559 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3560 |
__UNGETC__(c, f, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3561 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3562 |
if (__INST(binary) == true) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3563 |
RETURN ( __MKSMALLINT(c) ); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3564 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3565 |
RETURN ( __MKCHARACTER(c) ); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3566 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3567 |
if (ret < 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3568 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3569 |
} else /* ret == 0 */ { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3570 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3571 |
} |
1 | 3572 |
} |
159 | 3573 |
%}. |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3574 |
hitEOF ifTrue:[^ self pastEnd]. |
216 | 3575 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
1 | 3576 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
159 | 3577 |
^ self errorWriteOnly |
1295 | 3578 |
! |
3579 |
||
3580 |
upToEnd |
|
3581 |
"return a collection of the elements up-to the end. |
|
3582 |
Return nil if the stream-end is reached before." |
|
3583 |
||
3584 |
|answerStream ch| |
|
3585 |
||
3586 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
3587 |
[self atEnd] whileFalse:[ |
|
2264 | 3588 |
ch := self next. |
3589 |
ch notNil ifTrue:[ |
|
3590 |
answerStream nextPut:ch |
|
3591 |
] |
|
1295 | 3592 |
]. |
3593 |
^ answerStream contents |
|
3594 |
||
3595 |
"Created: 25.4.1996 / 14:40:31 / cg" |
|
612 | 3596 |
! ! |
3597 |
||
3598 |
!ExternalStream methodsFor:'reimplemented for speed'! |
|
159 | 3599 |
|
3600 |
nextAlphaNumericWord |
|
379 | 3601 |
"read the next word (i.e. up to non letter-or-digit) after first |
3602 |
skipping any whiteSpace. |
|
3603 |
Return a string containing those characters. |
|
3604 |
There is a limit of 1023 characters in the word - if longer, |
|
3605 |
it is truncated." |
|
159 | 3606 |
|
3607 |
%{ /* STACK: 2000 */ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3608 |
FILEPOINTER f; |
159 | 3609 |
int len; |
3610 |
char buffer[1024]; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3611 |
unsigned char ch; |
159 | 3612 |
int cnt = 0; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3613 |
int ret, _buffered; |
216 | 3614 |
OBJ fp; |
3615 |
||
1133 | 3616 |
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
|
3617 |
&& (__INST(mode) != @symbol(writeonly)) |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3618 |
) { |
2264 | 3619 |
f = __FILEVal(fp); |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3620 |
_buffered = (__INST(buffered) == true); |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3621 |
if (_buffered) { |
2264 | 3622 |
__READING__(f) |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3623 |
} |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
3624 |
|
2264 | 3625 |
/* |
3626 |
* skip whiteSpace first ... |
|
3627 |
*/ |
|
3628 |
do { |
|
3629 |
__READBYTE__(ret, f, &ch, _buffered); |
|
3630 |
if (ret > 0) |
|
3631 |
cnt++; |
|
3632 |
else |
|
3633 |
break; |
|
3634 |
} while ( |
|
379 | 3635 |
#ifndef NON_ASCII |
2264 | 3636 |
(ch < ' ') || |
379 | 3637 |
#endif |
2264 | 3638 |
(ch == ' ' ) || (ch == '\t') || (ch == '\r') |
3639 |
|| (ch == '\n') || (ch == 0x0b)); |
|
3640 |
||
3641 |
len = 0; |
|
3642 |
while (ret > 0 && |
|
3643 |
(((ch >= 'a') && (ch <= 'z')) || |
|
3644 |
((ch >= 'A') && (ch <= 'Z')) || |
|
3645 |
((ch >= '0') && (ch <= '9'))) |
|
3646 |
) { |
|
3647 |
buffer[len++] = ch; |
|
3648 |
if (len >= (sizeof(buffer)-1)) { |
|
3649 |
/* emergency */ |
|
3650 |
break; |
|
3651 |
} |
|
3652 |
__READBYTE__(ret, f, &ch, _buffered); |
|
3653 |
if (ret > 0) |
|
3654 |
cnt++; |
|
3655 |
else |
|
3656 |
break; |
|
3657 |
} |
|
3658 |
||
3659 |
if (ret <= 0) { |
|
3660 |
if (ret < 0) { |
|
3661 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3662 |
goto err; |
|
3663 |
} |
|
3664 |
else if (ret == 0) |
|
3665 |
__INST(hitEOF) = true; |
|
3666 |
} else { |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3667 |
__UNGETC__(ch, f, _buffered); |
2264 | 3668 |
cnt--; |
3669 |
} |
|
3670 |
||
3671 |
if (__INST(position) != nil) { |
|
3672 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt); |
|
3673 |
} |
|
3674 |
if (len != 0) { |
|
3675 |
buffer[len] = '\0'; |
|
3676 |
RETURN ( __MKSTRING_L(buffer, len) ); |
|
3677 |
} |
|
159 | 3678 |
} |
3679 |
err: ; |
|
3680 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3681 |
hitEOF ifTrue:[^ self pastEnd]. |
159 | 3682 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3683 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3684 |
^ self errorWriteOnly |
|
1 | 3685 |
! |
3686 |
||
3687 |
nextChunk |
|
3688 |
"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
|
3689 |
exclamation mark. Within the chunk, exclamation marks have to be doubled - |
216 | 3690 |
except within primitive code (this exception was added to make it easier |
3691 |
to edit primitive code with external editors). This means, that other |
|
3692 |
Smalltalks cannot always read chunks containing primitive code - but that |
|
3693 |
doesnt really matter, since C-primitives are an ST/X feature anyway. |
|
3694 |
Reimplemented here for more speed." |
|
3695 |
||
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3696 |
|retVal outOfMemory buffer| |
1 | 3697 |
|
159 | 3698 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
3699 |
binary ifTrue:[^ self errorBinary]. |
|
3700 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
216 | 3701 |
|
2854
3c8bf66e4e7d
give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents:
2766
diff
changeset
|
3702 |
%{ /* STACK: 12000 */ |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3703 |
/* |
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3704 |
* the main trick (and a bit of complication) here |
2874
020627074c9e
oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents:
2861
diff
changeset
|
3705 |
* is to read the first 8k 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
|
3706 |
* 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
|
3707 |
* 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
|
3708 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3709 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3710 |
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
|
3711 |
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
|
3712 |
int ret; |
1823 | 3713 |
unsigned char *bufferPtr = (unsigned char *)0; |
2874
020627074c9e
oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents:
2861
diff
changeset
|
3714 |
unsigned char fastBuffer[8000]; |
1 | 3715 |
REGISTER int index; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3716 |
int currSize, fastFlag, _buffered; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3717 |
int atBeginOfLine = 1, inPrimitive = 0; |
2920 | 3718 |
int haveCR = 0, haveNL = 0; |
216 | 3719 |
|
1133 | 3720 |
__INST(lastErrorNumber) = nil; |
3721 |
f = __FILEVal(__INST(filePointer)); |
|
668
73165201a9da
nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
3722 |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3723 |
_buffered = (__INST(buffered) == true); |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3724 |
if (_buffered) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3725 |
__READING__(f) |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3726 |
} |
159 | 3727 |
|
1 | 3728 |
/* |
3729 |
* skip spaces |
|
3730 |
*/ |
|
673
2c3a4a536cd1
oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
3731 |
c = '\n'; |
1 | 3732 |
while (! done) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3733 |
lastC = c; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3734 |
__READBYTE__(ret, f, &c, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3735 |
if (ret <= 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3736 |
goto err; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3737 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3738 |
nread++; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3739 |
atBeginOfLine = 0; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3740 |
switch (c) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3741 |
case '\n': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3742 |
case ' ': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3743 |
case '\t': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3744 |
case '\r': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3745 |
case '\b': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3746 |
case '\014': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3747 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3748 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3749 |
default: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3750 |
atBeginOfLine = (lastC == '\n'); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3751 |
done = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3752 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3753 |
} |
1 | 3754 |
} |
3755 |
||
3756 |
/* |
|
3757 |
* read chunk into a buffer |
|
3758 |
*/ |
|
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3759 |
bufferPtr = fastBuffer; fastFlag = 1; |
216 | 3760 |
currSize = sizeof(fastBuffer); |
362 | 3761 |
|
1 | 3762 |
index = 0; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3763 |
for (;;) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3764 |
__READBYTE__(ret, f, &peekC, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3765 |
if ((c == '%') && atBeginOfLine && ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3766 |
if (peekC == '{') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3767 |
inPrimitive = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3768 |
} else if (peekC == '}') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3769 |
inPrimitive = 0; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3770 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3771 |
} else if (c == '!' && !inPrimitive) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3772 |
if (ret > 0 && peekC == '!') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3773 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3774 |
* convert double-! to a single ! |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3775 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3776 |
__READBYTE__(ret, f, &peekC, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3777 |
if (ret > 0) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3778 |
nread++; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3779 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3780 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3781 |
* End of chunk, push back lookahead character |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3782 |
* and leave loop. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3783 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3784 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3785 |
__UNGETC__(peekC, f, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3786 |
} else |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3787 |
ret = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3788 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3789 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3790 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3791 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3792 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3793 |
* do we have to resize the buffer ? |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3794 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3795 |
if ((index+2) >= currSize) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3796 |
OBJ newBuffer; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3797 |
unsigned char *nbp; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3798 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3799 |
newBuffer = __MKEMPTYSTRING(currSize * 2); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3800 |
if (!fastFlag) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3801 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3802 |
* refetch - buffer could be moved by GC |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3803 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3804 |
bufferPtr = __stringVal(buffer); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3805 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3806 |
if (newBuffer == nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3807 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3808 |
* mhmh - chunk seems to be very big .... |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3809 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3810 |
outOfMemory = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3811 |
goto err; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3812 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3813 |
nbp = __stringVal(newBuffer); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3814 |
bcopy(bufferPtr, nbp, index); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3815 |
bufferPtr = nbp; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3816 |
bufferPtr[index] = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3817 |
buffer = newBuffer; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3818 |
fastFlag = 0; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3819 |
currSize = currSize * 2; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3820 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3821 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3822 |
if (!fastFlag) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3823 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3824 |
* old buffer may have moved (interrupt while reading) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3825 |
* - refetch pointer |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3826 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3827 |
bufferPtr = __stringVal(buffer); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3828 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3829 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3830 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3831 |
* filter out cr-nl; make it nl |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3832 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3833 |
if (c == '\n') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3834 |
haveNL = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3835 |
if (index > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3836 |
if (bufferPtr[index-1] == '\r') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3837 |
index--; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3838 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3839 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3840 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3841 |
if (c == '\r') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3842 |
haveCR = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3843 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3844 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3845 |
bufferPtr[index++] = c; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3846 |
if (ret <= 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3847 |
if (ret == 0) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3848 |
break; /* End of chunk reached */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3849 |
goto err; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3850 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3851 |
nread++; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3852 |
atBeginOfLine = (c == '\n'); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3853 |
c = peekC; |
1 | 3854 |
} |
92 | 3855 |
|
1 | 3856 |
/* |
2920 | 3857 |
* care for CR-limited files. |
3858 |
* Replace CR's by NL's |
|
3859 |
*/ |
|
3860 |
if (!haveNL && haveCR) { |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3861 |
int i; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3862 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3863 |
for (i=index-1; i>=0; i--) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3864 |
if (bufferPtr[i] == '\r') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3865 |
bufferPtr[i] = '\n'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3866 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3867 |
} |
2920 | 3868 |
} |
3869 |
||
3870 |
/* |
|
1 | 3871 |
* 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
|
3872 |
* 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
|
3873 |
* 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
|
3874 |
* fast (C) buffer or from real (ST) buffer. |
1 | 3875 |
*/ |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3876 |
if (fastFlag) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3877 |
retVal = __MKSTRING_L(bufferPtr, index); |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3878 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3879 |
retVal = __MKSTRING_ST_L(buffer, index); |
216 | 3880 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3881 |
|
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
3882 |
err: ; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3883 |
if (ret <= 0) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3884 |
if (ret == 0) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3885 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3886 |
else /* ret < 0 */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3887 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3888 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3889 |
if (__INST(position) != nil) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3890 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + nread); |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3891 |
} |
159 | 3892 |
%}. |
370 | 3893 |
retVal isNil ifTrue:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3894 |
"/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3895 |
"/ arrive here with retVal==nil either on error or premature EOF |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3896 |
"/ or if running out of malloc-memory |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3897 |
"/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3898 |
hitEOF ifTrue:[^ self pastEnd]. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3899 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3900 |
outOfMemory == true ifTrue:[ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3901 |
" |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3902 |
buffer memory allocation failed. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3903 |
When we arrive here, there was no memory available for the |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3904 |
chunk. (seems to be too big of a chunk ...) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3905 |
Bad luck - you should increase the ulimit and/or swap space on your machine. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3906 |
" |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3907 |
^ ObjectMemory allocationFailureSignal raise. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3908 |
] |
216 | 3909 |
]. |
1 | 3910 |
^ retVal |
612 | 3911 |
! |
3912 |
||
3913 |
nextMatchFor:anObject |
|
3914 |
"skip all objects up-to and including anObject, return anObject on success, |
|
3915 |
nil if end-of-file is reached before. The next read operation will return |
|
3916 |
the element after anObject. |
|
3917 |
Only single byte characters are currently supported." |
|
3918 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3919 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3920 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3921 |
int ret, peekValue; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3922 |
char c; |
612 | 3923 |
OBJ fp; |
3924 |
||
1133 | 3925 |
__INST(lastErrorNumber) = nil; |
3926 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3927 |
&& (__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
|
3928 |
) { |
2264 | 3929 |
if ((__INST(binary) == true) && __isSmallInteger(anObject)) { |
3930 |
peekValue = __intVal(anObject) & 0xFF; |
|
3931 |
} else { |
|
3932 |
if ((__INST(binary) != true) && __isCharacter(anObject)) { |
|
3933 |
peekValue = __intVal(_characterVal(anObject)) & 0xFF; |
|
3934 |
} else { |
|
3935 |
peekValue = -1; |
|
3936 |
} |
|
3937 |
} |
|
3938 |
||
3939 |
if (peekValue >= 0) { |
|
3940 |
int _buffered; |
|
3941 |
||
3942 |
__INST(position) = nil; |
|
3943 |
f = __FILEVal(fp); |
|
3944 |
||
3945 |
if (_buffered = (__INST(buffered) == true)) { |
|
3946 |
__READING__(f) |
|
3947 |
} |
|
3948 |
||
3949 |
for (;;) { |
|
3950 |
__READBYTE__(ret, f, &c, _buffered); |
|
3951 |
if (ret <= 0) { |
|
3952 |
if (ret < 0) |
|
3953 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3954 |
else |
|
3955 |
__INST(hitEOF) = true; |
|
3956 |
break; |
|
3957 |
} |
|
3958 |
if (c == peekValue) { |
|
3959 |
RETURN (anObject); |
|
3960 |
} |
|
3961 |
} |
|
3962 |
} |
|
612 | 3963 |
} |
3964 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3965 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3966 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3967 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3968 |
^ super nextMatchFor:anObject |
|
3969 |
! |
|
3970 |
||
3971 |
peekFor:anObject |
|
3972 |
"return true and move past next element, if next == something. |
|
3973 |
Otherwise, stay and return false. False is also returned |
|
3974 |
when EOF is encountered. |
|
3975 |
The argument must be an integer if in binary, a character if in |
|
3976 |
text mode; only single byte characters are currently supported." |
|
3977 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3978 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3979 |
FILEPOINTER f; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
3980 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3981 |
int ret, peekValue, _buffered; |
612 | 3982 |
OBJ fp; |
3983 |
||
1133 | 3984 |
__INST(lastErrorNumber) = nil; |
3985 |
if (((fp = __INST(filePointer)) != nil) |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3986 |
&& (__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
|
3987 |
) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3988 |
if (__INST(binary) == true) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3989 |
if (__isSmallInteger(anObject)) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3990 |
peekValue = __intVal(anObject) & 0xFF; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3991 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3992 |
goto bad; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3993 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3994 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3995 |
if (__isCharacter(anObject)) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3996 |
peekValue = __intVal(_characterVal(anObject)) & 0xFF; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3997 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3998 |
goto bad; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3999 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4000 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4001 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4002 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4003 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4004 |
_buffered = (__INST(buffered) == true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4005 |
if (_buffered) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4006 |
__READING__(f) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4007 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4008 |
__READBYTE__(ret, f, &c, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4009 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4010 |
if (c == peekValue) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4011 |
OBJ pos; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4012 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4013 |
if ((pos = __INST(position)) != nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4014 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4015 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4016 |
RETURN (true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4017 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4018 |
__UNGETC__(c, f, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4019 |
RETURN (false); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4020 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4021 |
if (ret < 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4022 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4023 |
} else /* ret == 0 */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4024 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4025 |
} |
612 | 4026 |
bad: ; |
4027 |
%}. |
|
4028 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4029 |
hitEOF ifTrue:[self pastEnd. ^ false]. |
612 | 4030 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
4031 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
4032 |
^ super peekFor:anObject |
|
4033 |
! |
|
4034 |
||
4035 |
skipLine |
|
4036 |
"read the next line (characters up to newline) skip only; |
|
4037 |
return nil if EOF reached, self otherwise. |
|
4038 |
Not allowed in binary mode." |
|
4039 |
||
4040 |
%{ /* STACK:2000 */ |
|
4041 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4042 |
FILEPOINTER f; |
612 | 4043 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4044 |
int ret, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4045 |
char c; |
612 | 4046 |
|
1133 | 4047 |
__INST(lastErrorNumber) = nil; |
4048 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4049 |
&& (__INST(mode) != @symbol(writeonly)) |
4050 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4051 |
) { |
2264 | 4052 |
f = __FILEVal(fp); |
4053 |
if (_buffered = (__INST(buffered) == true)) { |
|
4054 |
__READING__(f) |
|
4055 |
} |
|
4056 |
for (;;) { |
|
4057 |
__READBYTE__(ret, f, &c, _buffered); |
|
4058 |
if (ret > 0) { |
|
4059 |
if (c == '\n') |
|
4060 |
RETURN(self) |
|
4061 |
} else |
|
4062 |
break; |
|
4063 |
} |
|
4064 |
if (ret < 0) { |
|
4065 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4066 |
} else /* ret == 0 */ { |
|
4067 |
__INST(hitEOF) = true; |
|
4068 |
} |
|
612 | 4069 |
} |
4070 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4071 |
hitEOF ifTrue:[^ self pastEnd]. |
2331 | 4072 |
lastErrorNumber notNil ifTrue:[self readError. ^ self]. |
4073 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4074 |
binary ifTrue:[self errorBinary. ^ self]. |
|
4075 |
self errorWriteOnly |
|
612 | 4076 |
! |
4077 |
||
4078 |
skipSeparators |
|
4079 |
"skip all whitespace; next will return next non-white-space character |
|
4080 |
or nil if endOfFile reached. Not allowed in binary mode. |
|
4081 |
- reimplemented for speed" |
|
4082 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4083 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4084 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4085 |
char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4086 |
int ret, _buffered; |
612 | 4087 |
OBJ fp; |
4088 |
||
1133 | 4089 |
__INST(lastErrorNumber) = nil; |
4090 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4091 |
&& (__INST(mode) != @symbol(writeonly)) |
4092 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4093 |
) { |
2264 | 4094 |
f = __FILEVal(fp); |
4095 |
_buffered = (__INST(buffered) == true); |
|
4096 |
if (_buffered) { |
|
4097 |
__READING__(f) |
|
4098 |
} |
|
4099 |
||
4100 |
while (1) { |
|
4101 |
__READBYTE__(ret, f, &c, _buffered); |
|
4102 |
if (ret <= 0) { |
|
4103 |
if (ret < 0) { |
|
4104 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4105 |
} else /* ret == 0 */ { |
|
4106 |
__INST(hitEOF) = true; |
|
4107 |
} |
|
4108 |
break; |
|
4109 |
} |
|
4110 |
switch (c) { |
|
4111 |
case ' ': |
|
4112 |
case '\t': |
|
4113 |
case '\n': |
|
4114 |
case '\r': |
|
4115 |
case '\b': |
|
4116 |
case '\f': |
|
4117 |
break; |
|
4118 |
||
4119 |
default: |
|
4120 |
__UNGETC__(c, f, _buffered); |
|
4121 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
|
4122 |
} |
|
4123 |
} |
|
612 | 4124 |
} |
4125 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4126 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 4127 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
4128 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
4129 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
4130 |
^ self errorBinary. |
|
4131 |
! |
|
4132 |
||
4133 |
skipSeparatorsExceptCR |
|
4134 |
"skip all whitespace but no newlines; |
|
4135 |
next will return next non-white-space character |
|
4136 |
or nil if endOfFile reached. Not allowed in binary mode. |
|
4137 |
- reimplemented for speed" |
|
4138 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4139 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4140 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4141 |
char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4142 |
int ret, _buffered; |
612 | 4143 |
OBJ fp; |
4144 |
||
1133 | 4145 |
__INST(lastErrorNumber) = nil; |
4146 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4147 |
&& (__INST(mode) != @symbol(writeonly)) |
4148 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4149 |
) { |
2264 | 4150 |
f = __FILEVal(fp); |
4151 |
_buffered = (__INST(buffered) == true); |
|
4152 |
if (_buffered) { |
|
4153 |
__READING__(f) |
|
4154 |
} |
|
4155 |
while (1) { |
|
4156 |
__READBYTE__(ret, f, &c, _buffered); |
|
4157 |
if (ret <= 0) { |
|
4158 |
if (ret < 0) { |
|
4159 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4160 |
} else /* ret == 0 */ { |
|
4161 |
__INST(hitEOF) = true; |
|
4162 |
} |
|
4163 |
break; |
|
4164 |
} |
|
4165 |
switch (c) { |
|
4166 |
case ' ': |
|
4167 |
case '\t': |
|
4168 |
case '\b': |
|
4169 |
case '\f': |
|
4170 |
break; |
|
4171 |
||
4172 |
default: |
|
4173 |
__UNGETC__(c, f, _buffered); |
|
4174 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
|
4175 |
} |
|
4176 |
} |
|
612 | 4177 |
} |
4178 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4179 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 4180 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
4181 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
4182 |
(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
|
4183 |
^ self errorBinary. |
612 | 4184 |
! |
4185 |
||
4186 |
skipThrough:aCharacter |
|
4187 |
"skip all characters up-to and including aCharacter. Return the receiver if |
|
671 | 4188 |
skip was successful, otherwise (i.e. if not found) return nil. |
612 | 4189 |
The next read operation will return the character after aCharacter. |
4190 |
The argument, aCharacter must be character, or integer when in binary mode. |
|
4191 |
Only single byte characters are currently supported." |
|
4192 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4193 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4194 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4195 |
REGISTER int cSearch; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4196 |
unsigned char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4197 |
int ret, _buffered; |
612 | 4198 |
OBJ fp; |
4199 |
||
1133 | 4200 |
__INST(lastErrorNumber) = nil; |
4201 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4202 |
&& (__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
|
4203 |
) { |
2264 | 4204 |
if (__INST(binary) == true) { |
4205 |
/* searched for object must be a smallInteger */ |
|
4206 |
if (! __isSmallInteger(aCharacter)) goto badArgument; |
|
4207 |
cSearch = __intVal(aCharacter); |
|
4208 |
} else { |
|
4209 |
/* searched for object must be a character */ |
|
4210 |
if (! __isCharacter(aCharacter)) goto badArgument; |
|
4211 |
cSearch = __intVal(_characterVal(aCharacter)); |
|
4212 |
} |
|
4213 |
/* Q: should we just say: "not found" ? */ |
|
4214 |
if ((cSearch < 0) || (cSearch > 255)) goto badArgument; |
|
4215 |
||
4216 |
f = __FILEVal(fp); |
|
4217 |
if (_buffered = (__INST(buffered) == true)) { |
|
4218 |
__READING__(f) |
|
4219 |
} |
|
4220 |
||
4221 |
while (1) { |
|
4222 |
__READBYTE__(ret, f, &c, _buffered); |
|
4223 |
if (ret <= 0) { |
|
4224 |
if (ret < 0) { |
|
4225 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4226 |
} else /* ret == 0 */ { |
|
4227 |
__INST(hitEOF) = true; |
|
4228 |
} |
|
4229 |
break; |
|
4230 |
} |
|
4231 |
if (c == cSearch) { |
|
4232 |
RETURN (self); |
|
4233 |
} |
|
4234 |
} |
|
612 | 4235 |
} |
4236 |
badArgument: ; |
|
4237 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4238 |
hitEOF ifTrue:[^ self pastEnd]. |
2331 | 4239 |
lastErrorNumber notNil ifTrue:[self readError. ^ self]. |
4240 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4241 |
(mode == #writeonly) ifTrue:[self errorWriteOnly. ^ self]. |
|
612 | 4242 |
" |
4243 |
argument must be integer/character in binary mode, |
|
4244 |
character in text mode |
|
4245 |
" |
|
2331 | 4246 |
self error:'invalid argument'. |
612 | 4247 |
|
4248 |
" |
|
4249 |
|s| |
|
4250 |
s := 'Makefile' asFilename readStream. |
|
4251 |
s skipThrough:$=. |
|
4252 |
s next:10 |
|
4253 |
" |
|
4254 |
! |
|
4255 |
||
4256 |
skipToAll:aString |
|
4257 |
"skip for the sequence given by the argument, aCollection; |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4258 |
return nil if not found, self otherwise. |
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4259 |
On a successful match, the next read will return characters of aString." |
612 | 4260 |
|
4261 |
|oldPos| |
|
4262 |
||
4263 |
oldPos := self position. |
|
4264 |
(self skipThroughAll:aString) isNil ifTrue:[ |
|
2264 | 4265 |
" |
4266 |
restore position |
|
4267 |
" |
|
4268 |
self position:oldPos. |
|
4269 |
^ nil |
|
612 | 4270 |
]. |
4271 |
" |
|
4272 |
position before match-string |
|
4273 |
" |
|
4274 |
self position:(self position - aString size). |
|
4275 |
^ self |
|
4276 |
||
4277 |
" |
|
4278 |
|s| |
|
4279 |
s := 'Makefile' asFilename readStream. |
|
4280 |
s skipToAll:'are'. |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4281 |
s next:10 |
612 | 4282 |
" |
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4283 |
|
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4284 |
"Modified: 26.6.1996 / 09:22:05 / cg" |
1 | 4285 |
! ! |
612 | 4286 |
|
4287 |
!ExternalStream methodsFor:'testing'! |
|
4288 |
||
4289 |
atEnd |
|
4290 |
"return true, if position is at end" |
|
4291 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4292 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4293 |
FILEPOINTER f; |
612 | 4294 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4295 |
char c; |
2861 | 4296 |
int ret, _buffered; |
612 | 4297 |
|
1133 | 4298 |
if (__INST(hitEOF) == true) { |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4299 |
RETURN (true); |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
4300 |
} |
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
4301 |
if (__bothSmallInteger(__INST(position), __INST(readLimit))) { |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4302 |
if (__intVal(__INST(position)) > __intVal(__INST(readLimit))) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4303 |
RETURN (true); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4304 |
} |
612 | 4305 |
} |
4306 |
||
1133 | 4307 |
__INST(lastErrorNumber) = nil; |
4308 |
||
4309 |
if ((fp = __INST(filePointer)) != nil) { |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4310 |
f = __FILEVal(fp); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4311 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4312 |
if (_buffered = (__INST(buffered) == true)) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4313 |
__READING__(f); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4314 |
} else { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4315 |
if (__INST(readAhead) != nil) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4316 |
RETURN (false); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4317 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4318 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4319 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4320 |
/* |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4321 |
* read ahead ... |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4322 |
*/ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4323 |
do { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4324 |
__BEGIN_INTERRUPTABLE__ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4325 |
__READBYTE__(ret, f, &c, _buffered); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4326 |
__END_INTERRUPTABLE__ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4327 |
} while ((ret < 0) && (errno == EINTR)); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4328 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4329 |
if (ret > 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4330 |
__UNGETC__(c&0xff, f, _buffered); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4331 |
RETURN (false); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4332 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4333 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4334 |
if (ret == 0) { |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4335 |
__INST(hitEOF) = true; |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4336 |
RETURN (true); |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4337 |
} |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4338 |
|
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4339 |
/* ret < 0 */ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4340 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 4341 |
} |
4342 |
%}. |
|
4343 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
|
4344 |
^ self errorNotOpen |
|
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
4345 |
|
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
4346 |
"Modified: / 30.10.1998 / 20:16:06 / cg" |
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
4347 |
|
612 | 4348 |
! |
4349 |
||
4350 |
canReadWithoutBlocking |
|
4351 |
"return true, if any data is available for reading (i.e. |
|
4352 |
a read operation will not block the smalltalk process), false otherwise." |
|
4353 |
||
4354 |
|fd| |
|
4355 |
||
2986
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
4356 |
readAhead notNil ifTrue:[^ true]. |
612 | 4357 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
4358 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
4359 |
||
4360 |
fd := self fileDescriptor. |
|
4361 |
^ OperatingSystem readCheck:fd |
|
4362 |
||
4363 |
" |
|
4364 |
|pipe| |
|
4365 |
||
4366 |
pipe := PipeStream readingFrom:'(sleep 10; echo hello)'. |
|
4367 |
pipe canReadWithoutBlocking ifTrue:[ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4368 |
Transcript showCR:'data available' |
612 | 4369 |
] ifFalse:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4370 |
Transcript showCR:'no data available' |
612 | 4371 |
]. |
4372 |
pipe close |
|
4373 |
" |
|
2986
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
4374 |
|
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
4375 |
"Modified: 25.9.1997 / 13:08:45 / stefan" |
612 | 4376 |
! |
4377 |
||
4378 |
canWriteWithoutBlocking |
|
4379 |
"return true, if data can be written into the stream |
|
4380 |
(i.e. a write operation will not block the smalltalk process)." |
|
4381 |
||
4382 |
|fd| |
|
4383 |
||
4384 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
4385 |
mode == #readonly ifTrue:[^ self errorReadOnly]. |
|
4386 |
||
4387 |
fd := self fileDescriptor. |
|
4388 |
^ OperatingSystem writeCheck:fd |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4389 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4390 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4391 |
numAvailable |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4392 |
"return the number of bytes available for reading" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4393 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4394 |
|fd| |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4395 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4396 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4397 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4398 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4399 |
fd := self fileDescriptor. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4400 |
^ OperatingSystem numAvailableForReadOn:fd. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4401 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4402 |
"/ self atEnd ifTrue:[^ 0]. |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4403 |
"/ self canReadWithoutBlocking ifTrue:[ |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4404 |
"/ ^ 1 |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4405 |
"/ ]. |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4406 |
"/ ^ 0 |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4407 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4408 |
"Created: / 4.2.1998 / 16:56:01 / cg" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4409 |
"Modified: / 4.2.1998 / 17:31:11 / cg" |
612 | 4410 |
! ! |
4411 |
||
4412 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
4413 |
||
4414 |
readWait |
|
4415 |
"suspend the current process, until the receiver |
|
4416 |
becomes ready for reading. If data is already available, |
|
4417 |
return immediate. |
|
4418 |
The other threads are not affected by the wait." |
|
4419 |
||
4420 |
self readWaitWithTimeoutMs:nil |
|
4421 |
! |
|
4422 |
||
3016 | 4423 |
readWaitTimeoutMs:timeout |
4424 |
"ST-80 compatibility" |
|
4425 |
^ self readWaitWithTimeoutMs:timeout |
|
4426 |
! |
|
4427 |
||
612 | 4428 |
readWaitWithTimeout:timeout |
4429 |
"suspend the current process, until the receiver |
|
4430 |
becomes ready for reading or a timeout (in seconds) expired. |
|
4431 |
If data is already available, return immediate. |
|
4432 |
Return true if a timeout occured (i.e. false, if data is available). |
|
4433 |
The other threads are not affected by the wait." |
|
4434 |
||
4435 |
^ self readWaitWithTimeoutMs:timeout * 1000 |
|
4436 |
! |
|
4437 |
||
4438 |
readWaitWithTimeoutMs:timeout |
|
4439 |
"suspend the current process, until the receiver |
|
4440 |
becomes ready for reading or a timeout (in milliseconds) expired. |
|
4441 |
If data is already available, return immediate. |
|
4442 |
Return true if a timeout occured (i.e. false, if data is available). |
|
4443 |
The other threads are not affected by the wait." |
|
4444 |
||
4445 |
|fd inputSema hasData wasBlocked| |
|
4446 |
||
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4447 |
readAhead notNil ifTrue:[^ false]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4448 |
|
612 | 4449 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
4450 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
4451 |
||
4452 |
fd := self fileDescriptor. |
|
4453 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
|
4454 |
||
4455 |
wasBlocked := OperatingSystem blockInterrupts. |
|
4456 |
hasData := OperatingSystem readCheck:fd. |
|
4457 |
hasData ifFalse:[ |
|
2264 | 4458 |
inputSema := Semaphore new name:'readWait'. |
4459 |
[ |
|
4460 |
timeout notNil ifTrue:[ |
|
4461 |
Processor signal:inputSema afterMilliseconds:timeout |
|
4462 |
]. |
|
4463 |
Processor signal:inputSema onInput:fd. |
|
4464 |
Processor activeProcess state:#ioWait. |
|
4465 |
inputSema wait. |
|
4466 |
Processor disableSemaphore:inputSema. |
|
4467 |
hasData := OperatingSystem readCheck:fd |
|
4468 |
] valueOnUnwindDo:[ |
|
4469 |
Processor disableSemaphore:inputSema. |
|
4470 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
4471 |
] |
|
612 | 4472 |
]. |
4473 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
4474 |
^ hasData not |
|
4475 |
! |
|
4476 |
||
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4477 |
readWriteWait |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4478 |
"suspend the current process, until the receiver |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4479 |
becomes ready for writing or reading. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4480 |
Return immediate if the receiver is already ready. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4481 |
The other threads are not affected by the wait. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4482 |
This is actually only used with sockets, to wait for a connect to |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4483 |
be finished." |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4484 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4485 |
self readWriteWaitWithTimeoutMs:nil |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4486 |
! |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4487 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4488 |
readWriteWaitWithTimeoutMs:timeout |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4489 |
"suspend the current process, until the receiver |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4490 |
becomes ready for reading or writing or a timeout (in seconds) expired. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4491 |
Return true if a timeout occured (i.e. false, if data is available). |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4492 |
Return immediate if the receiver is already ready. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4493 |
The other threads are not affected by the wait. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4494 |
This is actually only used with sockets, to wait for a connect to |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4495 |
be finished." |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4496 |
|
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
4497 |
|fd sema canReadWrite wasBlocked| |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4498 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4499 |
filePointer isNil ifTrue:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4500 |
^ self errorNotOpen |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4501 |
]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4502 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4503 |
fd := self fileDescriptor. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4504 |
(OperatingSystem readWriteCheck:fd) ifTrue:[^ false]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4505 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4506 |
wasBlocked := OperatingSystem blockInterrupts. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4507 |
canReadWrite := OperatingSystem readWriteCheck:fd. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4508 |
canReadWrite ifFalse:[ |
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4509 |
sema := Semaphore new name:'readWriteWait'. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4510 |
[ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4511 |
timeout notNil ifTrue:[ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4512 |
Processor signal:sema afterMilliseconds:timeout |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4513 |
]. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4514 |
Processor signal:sema onOutput:fd. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4515 |
Processor signal:sema onInput:fd. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4516 |
Processor activeProcess state:#ioWait. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4517 |
sema wait. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4518 |
Processor disableSemaphore:sema. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4519 |
canReadWrite := OperatingSystem readWriteCheck:fd |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4520 |
] valueOnUnwindDo:[ |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4521 |
Processor disableSemaphore:sema. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4522 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
4523 |
] |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4524 |
]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4525 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4526 |
^ canReadWrite not |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4527 |
! |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4528 |
|
612 | 4529 |
writeWait |
4530 |
"suspend the current process, until the receiver |
|
4531 |
becomes ready for writing. |
|
4532 |
Return immediate if the receiver is already ready. |
|
4533 |
The other threads are not affected by the wait." |
|
4534 |
||
4535 |
self writeWaitWithTimeoutMs:nil |
|
4536 |
! |
|
4537 |
||
3016 | 4538 |
writeWaitTimeoutMs:timeout |
4539 |
"ST-80 compatibility" |
|
4540 |
^ self writeWaitWithTimeoutMs:timeout |
|
4541 |
! |
|
4542 |
||
612 | 4543 |
writeWaitWithTimeout:timeout |
4544 |
"suspend the current process, until the receiver |
|
4545 |
becomes ready for writing or a timeout (in seconds) expired. |
|
4546 |
Return true if a timeout occured (i.e. false, if data is available). |
|
4547 |
Return immediate if the receiver is already ready. |
|
4548 |
The other threads are not affected by the wait." |
|
4549 |
||
4550 |
^ self writeWaitWithTimeoutMs:timeout * 1000 |
|
4551 |
! |
|
4552 |
||
4553 |
writeWaitWithTimeoutMs:timeout |
|
4554 |
"suspend the current process, until the receiver |
|
4555 |
becomes ready for writing or a timeout (in seconds) expired. |
|
4556 |
Return true if a timeout occured (i.e. false, if data is available). |
|
4557 |
Return immediate if the receiver is already ready. |
|
4558 |
The other threads are not affected by the wait." |
|
4559 |
||
4560 |
|fd outputSema canWrite wasBlocked| |
|
4561 |
||
4562 |
filePointer isNil ifTrue:[ |
|
2264 | 4563 |
^ self errorNotOpen |
612 | 4564 |
]. |
4565 |
mode == #readonly ifTrue:[ |
|
2264 | 4566 |
^ self errorReadOnly |
612 | 4567 |
]. |
4568 |
||
4569 |
fd := self fileDescriptor. |
|
4570 |
(OperatingSystem writeCheck:fd) ifTrue:[^ false]. |
|
4571 |
||
4572 |
wasBlocked := OperatingSystem blockInterrupts. |
|
4573 |
canWrite := OperatingSystem writeCheck:fd. |
|
4574 |
canWrite ifFalse:[ |
|
2264 | 4575 |
outputSema := Semaphore new name:'writeWait'. |
4576 |
[ |
|
4577 |
timeout notNil ifTrue:[ |
|
4578 |
Processor signal:outputSema afterMilliseconds:timeout |
|
4579 |
]. |
|
4580 |
Processor signal:outputSema onOutput:fd. |
|
4581 |
Processor activeProcess state:#ioWait. |
|
4582 |
outputSema wait. |
|
4583 |
Processor disableSemaphore:outputSema. |
|
4584 |
canWrite := OperatingSystem writeCheck:fd |
|
4585 |
] valueOnUnwindDo:[ |
|
4586 |
Processor disableSemaphore:outputSema. |
|
4587 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
4588 |
] |
|
612 | 4589 |
]. |
4590 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
4591 |
^ canWrite not |
|
4592 |
! ! |
|
4593 |
||
4594 |
!ExternalStream methodsFor:'writing'! |
|
4595 |
||
4596 |
cr |
|
4597 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
4598 |
reimplemented for speed" |
|
4599 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4600 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4601 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4602 |
int len, cnt, _buffered; |
612 | 4603 |
OBJ fp; |
4604 |
char *cp; |
|
4605 |
||
1133 | 4606 |
__INST(lastErrorNumber) = nil; |
4607 |
if (((fp = __INST(filePointer)) != nil) |
|
2331 | 4608 |
&& (__INST(mode) != @symbol(readonly)) |
4609 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4610 |
) { |
2331 | 4611 |
f = __FILEVal(fp); |
4612 |
||
4613 |
if (_buffered = (__INST(buffered) == true)) { |
|
4614 |
__WRITING__(f) |
|
4615 |
} |
|
2920 | 4616 |
{ |
4617 |
OBJ mode = __INST(eolMode); |
|
4618 |
||
4619 |
if (mode == @symbol(cr)) { |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4620 |
cp = "\r"; len = 1; |
2920 | 4621 |
} else if (mode == @symbol(crlf)) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4622 |
cp = "\r\n"; len = 2; |
2920 | 4623 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4624 |
cp = "\n"; len = 1; |
2920 | 4625 |
} |
2331 | 4626 |
} |
4627 |
__WRITEBYTES__(cnt, f, cp, len, _buffered); |
|
4628 |
||
4629 |
if (cnt == len) { |
|
4630 |
if (__INST(position) != nil) { |
|
4631 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len); |
|
4632 |
} |
|
4633 |
RETURN ( self ); |
|
4634 |
} |
|
4635 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 4636 |
} |
4637 |
%}. |
|
2326 | 4638 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
4639 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4640 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
4641 |
self errorBinary |
|
612 | 4642 |
! |
4643 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4644 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4645 |
"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
|
4646 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4647 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4648 |
OBJ fp; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4649 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4650 |
__INST(lastErrorNumber) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4651 |
if ((fp = __INST(filePointer)) != nil) { |
2264 | 4652 |
if (__INST(mode) != @symbol(readonly)) { |
4653 |
if (__INST(buffered) == true) { |
|
4654 |
__BEGIN_INTERRUPTABLE__ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4655 |
FFLUSH( __FILEVal(fp) ); |
2264 | 4656 |
__END_INTERRUPTABLE__ |
4657 |
} |
|
4658 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4659 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4660 |
%} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4661 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4662 |
|
612 | 4663 |
nextPut:aCharacter |
4664 |
"write the argument, aCharacter - return nil if failed, self if ok. |
|
4665 |
Only single-byte characters are currently supported" |
|
4666 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4667 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4668 |
FILEPOINTER f; |
612 | 4669 |
char c; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4670 |
int cnt, _buffered; |
612 | 4671 |
OBJ pos, fp; |
4672 |
||
1133 | 4673 |
__INST(lastErrorNumber) = nil; |
4674 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4675 |
&& (__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
|
4676 |
) { |
2264 | 4677 |
if (__INST(binary) != true) { |
4678 |
if (__isCharacter(aCharacter)) { |
|
4679 |
c = __intVal(__characterVal(aCharacter)) & 0xFF; |
|
612 | 4680 |
doWrite: |
2264 | 4681 |
f = __FILEVal(fp); |
4682 |
||
4683 |
||
4684 |
if (_buffered = (__INST(buffered) == true)) { |
|
4685 |
__WRITING__(f) |
|
4686 |
} |
|
4687 |
__WRITEBYTE__(cnt, f, &c, _buffered); |
|
4688 |
||
4689 |
if (cnt == 1) { |
|
4690 |
pos = __INST(position); |
|
4691 |
if (pos != nil) { |
|
4692 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
|
4693 |
} |
|
4694 |
RETURN ( self ); |
|
4695 |
} |
|
4696 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4697 |
} |
|
4698 |
} else { |
|
4699 |
if (__isSmallInteger(aCharacter)) { |
|
4700 |
c = __intVal(aCharacter); |
|
4701 |
goto doWrite; |
|
4702 |
} |
|
4703 |
} |
|
612 | 4704 |
} |
4705 |
%}. |
|
2331 | 4706 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
4707 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4708 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
4709 |
binary ifFalse:[self argumentMustBeCharacter. ^ self]. |
|
4710 |
self argumentMustBeInteger. |
|
612 | 4711 |
! |
4712 |
||
4713 |
nextPutAll:aCollection |
|
4714 |
"write all elements of the argument, aCollection. |
|
4715 |
Reimplemented for speed when writing strings or byteArrays. |
|
4716 |
For others, falls back to general method in superclass." |
|
4717 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4718 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4719 |
FILEPOINTER f; |
612 | 4720 |
int len, cnt; |
4721 |
OBJ pos, fp; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4722 |
int _buffered; |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4723 |
int o_offs; |
612 | 4724 |
|
1133 | 4725 |
__INST(lastErrorNumber) = nil; |
4726 |
||
4727 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4728 |
&& (__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
|
4729 |
) { |
2264 | 4730 |
f = __FILEVal(fp); |
4731 |
if (_buffered = (__INST(buffered) == true)) { |
|
4732 |
__WRITING__(f) |
|
4733 |
} |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4734 |
|
2264 | 4735 |
if (__isString(aCollection) || __isSymbol(aCollection)) { |
4736 |
len = __stringSize(aCollection); |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4737 |
#ifdef BUGGY |
2264 | 4738 |
__WRITEBYTES__(cnt, f, __stringVal(aCollection), len, _buffered); |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4739 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4740 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4741 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4742 |
#endif |
2264 | 4743 |
} else { |
4744 |
if (__INST(binary) == true) { |
|
4745 |
int offs; |
|
4746 |
||
4747 |
if (__isByteArray(aCollection)) { |
|
4748 |
offs = 0; |
|
3221
21085ae8e1be
eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents:
3200
diff
changeset
|
4749 |
len = __byteArraySize(aCollection); |
2264 | 4750 |
} else if (__isBytes(aCollection)) { |
4751 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
3221
21085ae8e1be
eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents:
3200
diff
changeset
|
4752 |
len = __byteArraySize(aCollection) - offs; |
2264 | 4753 |
} else |
4754 |
goto out; |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4755 |
#ifdef BUGGY |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4756 |
__WRITEBYTES__(cnt, f, __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4757 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4758 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4759 |
o_offs += offs; |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4760 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4761 |
#endif |
2264 | 4762 |
} else |
4763 |
goto out; |
|
4764 |
} |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4765 |
|
2264 | 4766 |
if (cnt == len) { |
4767 |
pos = __INST(position); |
|
4768 |
if (pos != nil) { |
|
4769 |
__INST(position) = __MKSMALLINT(__intVal(pos) + len); |
|
4770 |
} |
|
4771 |
RETURN (self); |
|
4772 |
} |
|
4773 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 4774 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
4775 |
out: ; |
612 | 4776 |
%}. |
2331 | 4777 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
4778 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4779 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
612 | 4780 |
|
4781 |
^ super nextPutAll:aCollection |
|
4782 |
! |
|
4783 |
||
4784 |
nextPutAll:aCollection startingAt:start to:stop |
|
4785 |
"write a range of elements of the argument, aCollection. |
|
4786 |
Reimplemented for speed when writing strings or byteArrays. |
|
4787 |
For others, falls back to general method in superclass." |
|
4788 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4789 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4790 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4791 |
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
|
4792 |
OBJ fp, pos; |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4793 |
int o_offs; |
612 | 4794 |
|
1133 | 4795 |
__INST(lastErrorNumber) = nil; |
4796 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4797 |
&& (__INST(mode) != @symbol(readonly)) |
4798 |
&& __bothSmallInteger(start, stop) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4799 |
) { |
2264 | 4800 |
f = __FILEVal(fp); |
4801 |
if (_buffered = (__INST(buffered) == true)) { |
|
4802 |
__WRITING__(f) |
|
4803 |
} |
|
4804 |
iStart = __intVal(start); |
|
4805 |
iStop = __intVal(stop); |
|
4806 |
if ((iStart < 1) || (iStop < iStart)) { |
|
4807 |
RETURN(self); |
|
4808 |
} |
|
4809 |
if (__isString(aCollection) || __isSymbol(aCollection)) { |
|
4810 |
len = __stringSize(aCollection); |
|
4811 |
if (iStop > len) { |
|
4812 |
RETURN(self); |
|
4813 |
} |
|
4814 |
if (iStop > len) |
|
4815 |
iStop = len; |
|
4816 |
len = iStop - iStart + 1; |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4817 |
#ifdef BUGGY |
2264 | 4818 |
__WRITEBYTES__(cnt, f, __stringVal(aCollection)+iStart-1, len, _buffered); |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4819 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4820 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4821 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4822 |
#endif |
2264 | 4823 |
} else { |
4824 |
if (__INST(binary) == true) { |
|
4825 |
int offs; |
|
4826 |
||
4827 |
if (__isByteArray(aCollection)) { |
|
4828 |
offs = 0; |
|
3221
21085ae8e1be
eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents:
3200
diff
changeset
|
4829 |
len = __byteArraySize(aCollection); |
2264 | 4830 |
} else if (__isBytes(aCollection)) { |
4831 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
3221
21085ae8e1be
eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents:
3200
diff
changeset
|
4832 |
len = __byteArraySize(aCollection) - offs; |
2264 | 4833 |
} else |
4834 |
goto out; |
|
4835 |
||
4836 |
if (iStop > len) { |
|
4837 |
RETURN(self); |
|
4838 |
} |
|
4839 |
if (iStop > len) |
|
4840 |
iStop = len; |
|
4841 |
len = iStop - iStart + 1; |
|
4842 |
offs += iStart - 1; |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4843 |
#ifdef BUGGY |
2264 | 4844 |
__WRITEBYTES__(cnt, f, __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered); |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4845 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4846 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4847 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered); |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4848 |
#endif |
2264 | 4849 |
} else |
4850 |
goto out; |
|
4851 |
} |
|
4852 |
if (cnt == len) { |
|
4853 |
pos = __INST(position); |
|
4854 |
if (pos != nil) { |
|
4855 |
__INST(position) = __MKSMALLINT(__intVal(pos) + len); |
|
4856 |
} |
|
4857 |
RETURN (self); |
|
4858 |
} |
|
4859 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 4860 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
4861 |
out: ; |
612 | 4862 |
%}. |
4863 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
4864 |
^ super nextPutAll:aCollection startingAt:start to:stop |
|
4865 |
! ! |
|
4866 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
4867 |
!ExternalStream class methodsFor:'documentation'! |
730 | 4868 |
|
4869 |
version |
|
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
4870 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.196 1999-08-04 14:12:48 cg Exp $' |
730 | 4871 |
! ! |
612 | 4872 |
ExternalStream initialize! |