author | Claus Gittinger <cg@exept.de> |
Tue, 21 Jul 1998 20:27:42 +0200 | |
changeset 3672 | 49dff0652a2c |
parent 3569 | 545c52706f7e |
child 3674 | c51550d1df17 |
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 |
|
27 |
#ifdef __openVMS__ |
|
28 |
# undef __new |
|
29 |
#endif |
|
30 |
||
1 | 31 |
#include <stdio.h> |
437 | 32 |
#define _STDIO_H_INCLUDED_ |
33 |
||
2903 | 34 |
#ifndef NO_FCNTL_H |
35 |
# include <fcntl.h> |
|
36 |
# define _FCNTL_H_INCLUDED_ |
|
37 |
#endif |
|
437 | 38 |
|
10 | 39 |
#include <errno.h> |
437 | 40 |
#define _ERRNO_H_INCLUDED_ |
42 | 41 |
|
1141 | 42 |
#ifdef LINUX |
43 |
/* use inline string macros */ |
|
44 |
# define __STRINGDEFS__ |
|
45 |
# include <linuxIntern.h> |
|
46 |
#endif |
|
47 |
||
42 | 48 |
#ifdef hpux |
49 |
# define fileno(f) ((f->__fileH << 8) | (f->__fileL)) |
|
50 |
#endif |
|
216 | 51 |
|
933
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_SET |
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_SET 0 |
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_CUR |
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_CUR 1 |
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 |
#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
|
59 |
# 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
|
60 |
#endif |
2eebae059045
oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
61 |
|
2961 | 62 |
#ifdef __VMS__ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
63 |
# define CLEAR_ERRNO errno = 0; |
2961 | 64 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
65 |
# define CLEAR_ERRNO /* nothing */ |
2961 | 66 |
#endif |
67 |
||
3420 | 68 |
#ifdef LATER |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
69 |
#define __isFilePointer(x) (__Class(x) == ExternalStream__FilePointer) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
70 |
#define __CHANGECLASS(o, x) (__qClass(o) = (x), o) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
71 |
#define __MKFILEPOINTER(f) __CHANGECLASS(__MKEXTERNALADDRESS(f), ExternalStream__FilePointer) |
3420 | 72 |
#else |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
73 |
#define __MKFILEPOINTER(f) __MKEXTERNALADDRESS(f) |
3420 | 74 |
#endif |
75 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
76 |
#ifdef xxxWIN32 |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
77 |
# define NO_STDIO |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
78 |
# define __HANDLEVal(o) (HFILE)(__externalAddressVal(o)) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
79 |
# define READ(f, cp, n) _lread((f), (cp), (n)) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
80 |
# define WRITE(f, cp, n) _lwrite((f), (cp), (n)) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
81 |
# define FFLUSH(fp) /* nothing */ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
82 |
# undef STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
83 |
# define FILEPOINTER HFILE |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
84 |
# define FILENO(f) (f) |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
85 |
#else |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
86 |
# define STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
87 |
# define FILEPOINTER FILE * |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
88 |
# define READ(f, cp, n) read(f, cp, n) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
89 |
# define WRITE(f, cp, n) write(f, cp, n) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
90 |
# define FFLUSH(fp) fflush(fp) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
91 |
# define FILENO(f) fileno(f) |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
92 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
93 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
94 |
|
2596 | 95 |
#if defined(WIN32) && defined(NO_STDIO) |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
96 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
97 |
# ifdef i386 |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
98 |
# define _X86_ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
99 |
# endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
100 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
101 |
# undef INT |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
102 |
# undef Array |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
103 |
# undef Number |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
104 |
# undef Method |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
105 |
# undef Point |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
106 |
# undef Rectangle |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
107 |
# undef Block |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
108 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
109 |
/* # include <windows.h> /* */ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
110 |
# include <stdarg.h> /* */ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
111 |
# include <windef.h> /* */ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
112 |
# include <winbase.h> /* */ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
113 |
# include <wingdi.h> /* */ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
114 |
# include <winuser.h> /* */ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
115 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
116 |
# ifdef __DEF_Array |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
117 |
# define Array __DEF_Array |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
118 |
# endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
119 |
# ifdef __DEF_Number |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
120 |
# define Number __DEF_Number |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
121 |
# endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
122 |
# ifdef __DEF_Method |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
123 |
# define Method __DEF_Method |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
124 |
# endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
125 |
# ifdef __DEF_Point |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
126 |
# define Point __DEF_Point |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
127 |
# endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
128 |
# ifdef __DEF_Block |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
129 |
# define Block __DEF_Block |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
130 |
# endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
131 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
132 |
# define stat _stat |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
133 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
134 |
#endif /* WIN32 */ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
135 |
|
216 | 136 |
/* |
137 |
* stdio library requires an fseek before reading whenever a file |
|
138 |
* is open for read/write and the last operation was a write. |
|
139 |
* (also vice-versa). |
|
140 |
* All code should use the following macro before doing reads: |
|
141 |
*/ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
142 |
#ifdef STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
143 |
# 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
|
144 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
145 |
# 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
|
146 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
147 |
|
216 | 148 |
#define __READING__(f) \ |
1133 | 149 |
if ((__INST(didWrite) != false) \ |
150 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
151 |
__INST(didWrite) = false; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
152 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
216 | 153 |
} |
154 |
||
155 |
#define __WRITING__(f) \ |
|
1133 | 156 |
if ((__INST(didWrite) != true) \ |
157 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
158 |
__INST(didWrite) = true; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
159 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
216 | 160 |
} |
161 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
162 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
163 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
164 |
#define __UNGETC__(c, f, isBuffered) \ |
2963 | 165 |
__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
|
166 |
#else |
2264 | 167 |
#define __UNGETC__(c, f, isBuffered) \ |
168 |
if (isBuffered) { \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
169 |
ungetc((c), (f)); \ |
2264 | 170 |
} else { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
171 |
__INST(readAhead) = __MKSMALLINT((c)); \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
172 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
173 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
174 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
175 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
176 |
#define __READBYTE__(ret, f, buf, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
177 |
{ \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
178 |
OBJ rA = __INST(readAhead); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
179 |
if (rA != nil) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
180 |
*(buf) = __intVal(rA); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
181 |
__INST(readAhead) = nil; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
182 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
183 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
184 |
for (;;) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
185 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
186 |
(ret) = READ(f, buf, 1); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
187 |
if ((ret) >= 0 || errno != EINTR) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
188 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
189 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
190 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
191 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
192 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
193 |
#else |
2264 | 194 |
#define __READBYTE__(ret, f, buf, isBuffered) \ |
195 |
if (isBuffered) { \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
196 |
for (;;) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
197 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
198 |
(ret) = getc(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
199 |
if ((ret) >= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
200 |
*(buf) = (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
201 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
202 |
} else if (ferror(f)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
203 |
if (errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
204 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
205 |
clearerr(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
206 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
207 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
208 |
} else \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
209 |
(ret) = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
210 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
211 |
} \ |
2264 | 212 |
} else { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
213 |
OBJ rA = __INST(readAhead); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
214 |
if (rA != nil) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
215 |
*(buf) = __intVal(rA); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
216 |
__INST(readAhead) = nil; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
217 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
218 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
219 |
for (;;) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
220 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
221 |
(ret) = read(fileno(f), buf, 1); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
222 |
if ((ret) >= 0 || errno != EINTR) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
223 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
224 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
225 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
226 |
} \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
227 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
228 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
229 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
230 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
231 |
* 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
|
232 |
* (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
|
233 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
234 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
235 |
#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
|
236 |
{ \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
237 |
int __offs = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
238 |
\ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
239 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
240 |
OBJ rA = __INST(readAhead); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
241 |
if (rA != nil) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
242 |
(buf)[__offs] = __intVal(rA); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
243 |
__INST(readAhead) = nil; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
244 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
245 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
246 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
247 |
(ret) = READ(f, (buf)+__offs, (cnt)-__offs); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
248 |
if ((ret) <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
249 |
if ((ret) < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
250 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
251 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
252 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
253 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
254 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
255 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
256 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
257 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
258 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
259 |
(ret) = __offs; \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
260 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
261 |
#else |
2264 | 262 |
#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
|
263 |
(ret) = 0; \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
264 |
if (isBuffered) { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
265 |
int __offs = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
266 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
267 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
268 |
(ret) = getc(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
269 |
if ((ret) < 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
270 |
if (ferror(f)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
271 |
if (errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
272 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
273 |
clearerr(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
274 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
275 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
276 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
277 |
(ret) = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
278 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
279 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
280 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
281 |
(buf)[__offs++] = (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
282 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
283 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
284 |
(ret) = __offs; \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
285 |
} else { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
286 |
int __offs = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
287 |
int fd = fileno(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
288 |
\ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
289 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
290 |
OBJ rA = __INST(readAhead); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
291 |
if (rA != nil) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
292 |
(buf)[__offs] = __intVal(rA); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
293 |
__INST(readAhead) = nil; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
294 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
295 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
296 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
297 |
(ret) = read(fd, (buf)+__offs, (cnt)-__offs); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
298 |
if ((ret) <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
299 |
if ((ret) < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
300 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
301 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
302 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
303 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
304 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
305 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
306 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
307 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
308 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
309 |
(ret) = __offs; \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
310 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
311 |
|
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
312 |
#if defined(F_GETFL) && defined(F_SETFL) && defined(FNDELAY) |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
313 |
# define GETFLAGS(fd) \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
314 |
fcntl(fd, F_GETFL, 0); |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
315 |
|
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
316 |
# define SETFLAGS(fd, flags) \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
317 |
fcntl(fd, F_SETFL, flags) |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
318 |
|
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
319 |
# define SETNONBLOCKING(fd) \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
320 |
{ \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
321 |
int flags; \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
322 |
flags = fcntl(fd, F_GETFL, 0); \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
323 |
if (flags >= 0) { \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
324 |
fcntl(fd, F_SETFL, flags | FNDELAY); \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
325 |
} \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
326 |
} |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
327 |
#else |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
328 |
# define GETFLAGS(fd) 0 |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
329 |
# define SETFLAGS(fd, flags) /* nothing */ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
330 |
# define SETNONBLOCKING(fd) /* nothing */ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
331 |
#endif |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
332 |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
333 |
#define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
334 |
{ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
335 |
int __offs = 0; \ |
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
336 |
int oldFlags; \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
337 |
\ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
338 |
(ret) = 0; \ |
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
339 |
oldFlags = GETFLAGS(fileno(f)); \ |
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
340 |
SETNONBLOCKING(fileno(f)); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
341 |
if (isBuffered) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
342 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
343 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
344 |
(ret) = getc(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
345 |
if ((ret) < 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
346 |
if (ferror(f)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
347 |
if (errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
348 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
349 |
clearerr(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
350 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
351 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
352 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
353 |
(ret) = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
354 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
355 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
356 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
357 |
(buf)[__offs++] = (ret); \ |
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 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
360 |
(ret) = __offs; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
361 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
362 |
int fd = fileno(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
363 |
\ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
364 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
365 |
OBJ rA = __INST(readAhead); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
366 |
if (rA != nil) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
367 |
(buf)[__offs] = __intVal(rA); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
368 |
__INST(readAhead) = nil; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
369 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
370 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
371 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
372 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
373 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
374 |
(ret) = read(fd, (buf)+__offs, (cnt)-__offs); \ |
3551 | 375 |
if ((ret) < 0) { \ |
376 |
if (errno == EINTR) { \ |
|
377 |
__HANDLE_INTERRUPTS__; \ |
|
378 |
continue; \ |
|
379 |
} \ |
|
380 |
break; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
381 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
382 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
383 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
384 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
385 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
386 |
(ret) = __offs; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
387 |
} \ |
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
388 |
SETFLAGS(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
389 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
390 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
391 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
392 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
393 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
394 |
* 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
|
395 |
* (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
|
396 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
397 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
398 |
#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
|
399 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
400 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
401 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
402 |
char *buf = (char *)(obj); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
403 |
\ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
404 |
(ret) = 0; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
405 |
{ \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
406 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
407 |
OBJ rA = __INST(readAhead); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
408 |
if (rA != nil) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
409 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
410 |
__INST(readAhead) = nil; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
411 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
412 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
413 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
414 |
(ret) = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
415 |
if ((ret) <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
416 |
if ((ret) < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
417 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
418 |
/* refetch */ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
419 |
buf = (char *)(obj); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
420 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
421 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
422 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
423 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
424 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
425 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
426 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
427 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
428 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
429 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
430 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
431 |
#else |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
432 |
#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
|
433 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
434 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
435 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
436 |
char *buf = (char *)(obj); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
437 |
\ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
438 |
(ret) = 0; \ |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
439 |
if (isBuffered) { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
440 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
441 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
442 |
(ret) = getc(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
443 |
if ((ret) < 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
444 |
if (ferror(f)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
445 |
if (errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
446 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
447 |
clearerr(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
448 |
/* refetch */ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
449 |
buf = (char *)(obj); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
450 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
451 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
452 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
453 |
(ret) = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
454 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
455 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
456 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
457 |
(buf)[__ooffs+__offs] = (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
458 |
__offs++; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
459 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
460 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
461 |
(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
|
462 |
} else { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
463 |
int fd = fileno(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
464 |
\ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
465 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
466 |
OBJ rA = __INST(readAhead); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
467 |
if (rA != nil) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
468 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
469 |
__INST(readAhead) = nil; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
470 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
471 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
472 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
473 |
(ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
474 |
if ((ret) <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
475 |
if ((ret) < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
476 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
477 |
/* refetch */ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
478 |
buf = (char *)(obj); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
479 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
480 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
481 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
482 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
483 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
484 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
485 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
486 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
487 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
488 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
489 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
490 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
491 |
#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
|
492 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
493 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
494 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
495 |
char *buf = (char *)(obj); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
496 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
497 |
(ret) = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
498 |
if (isBuffered) { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
499 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
500 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
501 |
(ret) = getc(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
502 |
if ((ret) < 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
503 |
if (ferror(f)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
504 |
if (errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
505 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
506 |
clearerr(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
507 |
/* refetch */ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
508 |
buf = (char *)(obj); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
509 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
510 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
511 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
512 |
(ret) = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
513 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
514 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
515 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
516 |
(buf)[__ooffs+__offs] = (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
517 |
__offs++; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
518 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
519 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
520 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
521 |
} else { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
522 |
int fd = fileno(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
523 |
\ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
524 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
525 |
OBJ rA = __INST(readAhead); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
526 |
if (rA != nil) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
527 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
528 |
__INST(readAhead) = nil; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
529 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
530 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
531 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
532 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
533 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
534 |
(ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
535 |
if ((ret) < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
536 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
537 |
/* refetch */ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
538 |
buf = (char *)(obj); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
539 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
540 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
541 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
542 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
543 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
544 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
545 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
546 |
} \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
547 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
548 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
549 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
550 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
551 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
552 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
553 |
#define __WRITEBYTE__(ret, f, buf, isBuffered) \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
554 |
for (;;) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
555 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
556 |
(ret) = WRITE(f, buf, 1); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
557 |
if ((ret) >= 0 || errno != EINTR) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
558 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
559 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
560 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
561 |
#else |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
562 |
#define __WRITEBYTE__(ret, f, buf, isBuffered) \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
563 |
if (isBuffered) { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
564 |
for (;;) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
565 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
566 |
ret = putc(*(buf), f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
567 |
if ((ret) >= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
568 |
(ret) = 1; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
569 |
} else if (ferror(f)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
570 |
if (errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
571 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
572 |
clearerr(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
573 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
574 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
575 |
} else \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
576 |
(ret) = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
577 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
578 |
} \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
579 |
} else { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
580 |
for (;;) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
581 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
582 |
(ret) = write(fileno(f), buf, 1); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
583 |
if ((ret) >= 0 || errno != EINTR) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
584 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
585 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
586 |
} \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
587 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
588 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
589 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
590 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
591 |
* 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
|
592 |
* (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
|
593 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
594 |
#ifdef NO_STDIO |
2961 | 595 |
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered) \ |
596 |
(ret) = 0; \ |
|
597 |
{ \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
598 |
int __offs = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
599 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
600 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
601 |
ret = WRITE(f, (buf)+__offs, (cnt)-__offs); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
602 |
if (ret <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
603 |
if (ret < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
604 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
605 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
606 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
607 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
608 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
609 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
610 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
611 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
612 |
(ret) = __offs; \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
613 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
614 |
#else |
2961 | 615 |
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered) \ |
616 |
(ret) = 0; \ |
|
617 |
if (isBuffered) { \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
618 |
int __offs = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
619 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
620 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
621 |
ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
622 |
if ((ret) <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
623 |
if (ferror(f)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
624 |
if (errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
625 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
626 |
clearerr(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
627 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
628 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
629 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
630 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
631 |
(ret) = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
632 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
633 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
634 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
635 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
636 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
637 |
(ret) = __offs; \ |
2961 | 638 |
} else { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
639 |
int __offs = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
640 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
641 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
642 |
ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);\ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
643 |
if (ret <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
644 |
if (ret < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
645 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
646 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
647 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
648 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
649 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
650 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
651 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
652 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
653 |
(ret) = __offs; \ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
654 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
655 |
#endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
656 |
|
223 | 657 |
/* |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
658 |
* 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
|
659 |
* (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
|
660 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
661 |
#ifdef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
662 |
#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
|
663 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
664 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
665 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
666 |
char *buf = (char *)(obj); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
667 |
\ |
2961 | 668 |
(ret) = 0; \ |
669 |
{ \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
670 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
671 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
672 |
ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
673 |
if (ret <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
674 |
if (ret < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
675 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
676 |
/* refetch */ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
677 |
buf = (char *)(obj); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
678 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
679 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
680 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
681 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
682 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
683 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
684 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
685 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
686 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
687 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
688 |
#else |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
689 |
#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
|
690 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
691 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
692 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
693 |
char *buf = (char *)(obj); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
694 |
\ |
2961 | 695 |
(ret) = 0; \ |
696 |
if (isBuffered) { \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
697 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
698 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
699 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
700 |
if ((ret) <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
701 |
if (ferror(f)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
702 |
if (errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
703 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
704 |
/* refetch */ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
705 |
buf = (char *)(obj); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
706 |
clearerr(f); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
707 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
708 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
709 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
710 |
} else { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
711 |
(ret) = 0; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
712 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
713 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
714 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
715 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
716 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
717 |
(ret) = __offs; \ |
2961 | 718 |
} else { \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
719 |
while (__offs < (cnt)) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
720 |
CLEAR_ERRNO; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
721 |
ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
722 |
if (ret <= 0) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
723 |
if (ret < 0 && errno == EINTR) { \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
724 |
__HANDLE_INTERRUPTS__; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
725 |
/* refetch */ \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
726 |
buf = (char *)(obj); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
727 |
continue; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
728 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
729 |
break; \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
730 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
731 |
__offs += (ret); \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
732 |
} \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
733 |
if (__offs > 0) \ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
734 |
(ret) = __offs; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
735 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
736 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
737 |
#endif |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
738 |
|
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
739 |
/* |
223 | 740 |
* on some systems errno is a macro ... check for it here |
741 |
*/ |
|
742 |
#ifndef errno |
|
743 |
extern errno; |
|
744 |
#endif |
|
745 |
||
1 | 746 |
%} |
188 | 747 |
! ! |
1 | 748 |
|
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
749 |
!ExternalStream class methodsFor:'documentation'! |
22 | 750 |
|
88 | 751 |
copyright |
752 |
" |
|
753 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
2264 | 754 |
All Rights Reserved |
88 | 755 |
|
756 |
This software is furnished under a license and may be used |
|
757 |
only in accordance with the terms of that license and with the |
|
758 |
inclusion of the above copyright notice. This software may not |
|
759 |
be provided or otherwise made available to, or used by, any |
|
760 |
other person. No title to or ownership of the software is |
|
761 |
hereby transferred. |
|
762 |
" |
|
763 |
! |
|
764 |
||
22 | 765 |
documentation |
766 |
" |
|
68 | 767 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
768 |
represent some file or communicationChannel of the underlying OperatingSystem. |
|
769 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 770 |
|
159 | 771 |
ExternalStreams can be in two modes: text- (the default) and binary-mode. |
68 | 772 |
In text-mode, the elements read/written are characters; |
773 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
|
774 |
in the range 0..255. |
|
22 | 775 |
|
68 | 776 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
777 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
778 |
is sent (in both modes). |
|
22 | 779 |
|
77 | 780 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 781 |
or just forgotten - in this case, the garbage collector will eventually collect the |
77 | 782 |
object AND a close will be performed automatically (but you will NOT know when this |
783 |
happens - so it is recommended, that you close your files when no longer needed). |
|
159 | 784 |
Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to |
77 | 785 |
some crash) the data will not be in the file, if unclosed. |
786 |
All streams understand the close message, so it never hurts to use it (it is defined as |
|
787 |
a noop in one of the superclasses). |
|
22 | 788 |
|
68 | 789 |
Most of the methods found here redefine inherited methods for better performance, |
790 |
since I/O from/to files should be fast. |
|
22 | 791 |
|
68 | 792 |
Recovering a snapshot: |
1295 | 793 |
not all streams can be restored to the state they had before - see the implementation of |
794 |
reOpen in subclasses for more information. |
|
795 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
796 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
797 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
798 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
799 |
if the contents changed in the meantime. |
|
800 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
801 |
||
802 |
[Instance variables:] |
|
803 |
||
2264 | 804 |
filePointer <Integer> the unix FILE*; somehow mapped to an integer |
805 |
(notice: not the fd) |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
806 |
on Windows: the fileHandle |
2264 | 807 |
mode <Symbol> #readwrite, #readonly or #writeonly |
808 |
buffered <Boolean> true, if buffered (i.e. collects characters - does |
|
809 |
not output immediately) |
|
810 |
binary <Boolean> true if in binary mode (reads bytes instead of chars) |
|
2920 | 811 |
eolMode <Symbol> one of nil, #cr or #crlf. |
812 |
determines how lines should be terminated. |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
813 |
nil -> newLine (as in Unix); |
2920 | 814 |
#crlf -> with cr-lf (as in MSDOS) |
815 |
#cr -> with cr (as in VMS) |
|
2264 | 816 |
hitEOF <Boolean> true, if EOF was reached |
817 |
||
818 |
lastErrorNumber <Integer> the value of errno (only valid right after the error - |
|
819 |
updated with next i/o operation) |
|
1295 | 820 |
|
821 |
[Class variables:] |
|
2264 | 822 |
Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s) |
823 |
||
824 |
StreamErrorSignal <Signal> parent of all stream errors (see Stream class) |
|
825 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
|
826 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
|
827 |
InvalidModeSignal <Signal> raised on text I/O with binary-stream |
|
828 |
or binary I/O with text-stream |
|
829 |
OpenErrorSignal <Signal> raised if open fails |
|
830 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
|
159 | 831 |
|
832 |
Additional notes: |
|
833 |
This class is implemented using the underlying stdio-c library package, which |
|
834 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
835 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
836 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
837 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
838 |
a complete rewrite for UnboundedStream ... |
|
325 | 839 |
|
188 | 840 |
Also, depending on the system, the stdio library behaves infriendly when signals |
841 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
842 |
is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns |
|
1295 | 843 |
an error and errno is set to EINTR. |
844 |
Thats what the ugly code around all getc-calls is for ... |
|
845 |
Since things get more and more ugly - we will rewrite ExternalStream |
|
846 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 847 |
|
848 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
849 |
this was bad design in the stdio lib (right from the very beginning), since its much |
|
850 |
harder to deal with this in the presence of lightweight processes, where errno gets |
|
851 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
852 |
to return errno as a negative number ...). |
|
853 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
854 |
and saves/restores the errno setting when switching to another thread. |
|
855 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
856 |
does not depend on those, but instead uses a portable private package). |
|
857 |
||
216 | 858 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
859 |
fseek whenever we are about to read after write and vice versa. |
|
860 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
861 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 862 |
|
863 |
[author:] |
|
2264 | 864 |
Claus Gittinger |
865 |
Stefan Vogel (many, many fixes ...) |
|
1295 | 866 |
|
867 |
[see also:] |
|
2264 | 868 |
FileStream Socket PipeStream |
869 |
Filename OperatingSystem |
|
22 | 870 |
" |
3255 | 871 |
! |
872 |
||
873 |
examples |
|
874 |
" |
|
875 |
open a file, read the contents and display it in a textView: |
|
876 |
||
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
877 |
|topView scrollPane textView fileStream text| |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
878 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
879 |
topView := StandardSystemView new. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
880 |
topView label:'contents of Makefile'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
881 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
882 |
scrollPane := HVScrollableView in:topView. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
883 |
scrollPane origin:0.0@0.0 corner:1.0@1.0. |
3255 | 884 |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
885 |
textView := EditTextView new. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
886 |
scrollPane scrolledView:textView. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
887 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
888 |
fileStream := 'Makefile' asFilename readStream. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
889 |
text := fileStream upToEnd. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
890 |
fileStream close. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
891 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
892 |
textView contents:text. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
893 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
894 |
topView open. |
3255 | 895 |
|
896 |
||
897 |
||
898 |
Notice, all of the above can also be done (simply) as: |
|
899 |
||
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
900 |
EditTextView openOn:'Makefile' |
3255 | 901 |
" |
22 | 902 |
! ! |
903 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
904 |
!ExternalStream class methodsFor:'initialization'! |
1 | 905 |
|
2920 | 906 |
initDefaultEOLMode |
907 |
OperatingSystem isUNIXlike ifTrue:[ |
|
908 |
"/ unix EOL conventions |
|
909 |
DefaultEOLMode := #nl |
|
910 |
] ifFalse:[ |
|
911 |
OperatingSystem isVMSlike ifTrue:[ |
|
912 |
"/ vms EOL conventions |
|
913 |
DefaultEOLMode := #cr |
|
914 |
] ifFalse:[ |
|
915 |
"/ msdos EOL conventions |
|
916 |
DefaultEOLMode := #crlf |
|
917 |
] |
|
918 |
] |
|
919 |
! |
|
920 |
||
921 |
initModeStrings |
|
922 |
"initialize modeStrings which are passed down to the underlying |
|
923 |
fopen/fdopen functions." |
|
924 |
||
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
925 |
OperatingSystem isMSDOSlike ifTrue:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
926 |
ReadMode := 'rb'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
927 |
ReadWriteMode := 'rb+'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
928 |
WriteMode := 'wb'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
929 |
AppendMode := 'ab+'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
930 |
CreateReadWriteMode := 'wb+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
931 |
] ifFalse:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
932 |
ReadMode := 'r'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
933 |
ReadWriteMode := 'r+'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
934 |
WriteMode := 'w'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
935 |
AppendMode := 'a+'. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
936 |
CreateReadWriteMode := 'w+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
937 |
] |
2920 | 938 |
! |
939 |
||
1 | 940 |
initialize |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
941 |
OpenErrorSignal isNil ifTrue:[ |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
942 |
OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
943 |
OpenErrorSignal nameClass:self message:#openErrorSignal. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
944 |
OpenErrorSignal notifierString:'open error'. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
945 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
946 |
InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
947 |
InvalidReadSignal nameClass:self message:#invalidReadSignal. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
948 |
InvalidReadSignal notifierString:'read error'. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
949 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
950 |
InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
951 |
InvalidWriteSignal nameClass:self message:#invalidWriteSignal. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
952 |
InvalidWriteSignal notifierString:'write error'. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
953 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
954 |
InvalidModeSignal := StreamErrorSignal newSignalMayProceed:false. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
955 |
InvalidModeSignal nameClass:self message:#invalidModeSignal. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
956 |
InvalidModeSignal notifierString:'binary/text mode mismatch'. |
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 |
InvalidOperationSignal := StreamErrorSignal newSignalMayProceed:false. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
959 |
InvalidOperationSignal nameClass:self message:#invalidOperationSignal. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
960 |
InvalidOperationSignal notifierString:'unsupported file operation'. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
961 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
962 |
StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
963 |
StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
964 |
StreamNotOpenSignal notifierString:'stream is not open'. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
965 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
966 |
StreamIOErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
967 |
StreamIOErrorSignal nameClass:self message:#streamIOErrorSignal. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
968 |
StreamIOErrorSignal notifierString:'I/O error'. |
159 | 969 |
]. |
970 |
||
31 | 971 |
Lobby isNil ifTrue:[ |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
972 |
Lobby := Registry new. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
973 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
974 |
"want to get informed when returning from snapshot" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
975 |
ObjectMemory addDependent:self |
2920 | 976 |
]. |
977 |
self initDefaultEOLMode. |
|
978 |
self initModeStrings. |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
979 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
980 |
"Modified: / 21.5.1998 / 16:33:53 / cg" |
1 | 981 |
! |
982 |
||
983 |
reOpenFiles |
|
984 |
"reopen all files (if possible) after a snapShot load" |
|
985 |
||
301 | 986 |
Lobby do:[:aFileStream | |
2264 | 987 |
aFileStream reOpen |
2920 | 988 |
]. |
1 | 989 |
! |
990 |
||
1469 | 991 |
update:something with:aParameter from:changedObject |
1 | 992 |
"have to reopen files when returning from snapshot" |
993 |
||
994 |
something == #returnFromSnapshot ifTrue:[ |
|
2920 | 995 |
self reOpenFiles. |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
996 |
self initDefaultEOLMode |
1 | 997 |
] |
1469 | 998 |
|
999 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 1000 |
! ! |
1001 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1002 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 1003 |
|
2920 | 1004 |
forFileDescriptor:aFileDescriptor mode:modeString |
1005 |
"given a fileDescriptor, create an ExternalStream object |
|
1006 |
to operate on this fd. |
|
1007 |
The mode-argument is passed to the fdopen call. |
|
1008 |
This may be used to wrap fd's as returned by user |
|
1009 |
primitive code, or to wrap pipe-fds into externalStreams." |
|
1010 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1011 |
|newStream| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1012 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1013 |
newStream := self basicNew. |
2920 | 1014 |
newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF. |
3535 | 1015 |
^ newStream connectTo:aFileDescriptor withMode:modeString |
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 forFileDescriptor:15 mode:'r'. |
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:05:00 / 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:17:07 / 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 |
forReadWriteToFileDescriptor:aFileDescriptor |
2920 | 1031 |
"given a fileDescriptor, create an ExternalStream object |
1032 |
to read/write from/to 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:ReadWriteMode) readwrite |
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 forReadWriteToFileDescriptor: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 |
"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
|
1048 |
"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
|
1049 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1050 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1051 |
forReadingFromFileDescriptor:aFileDescriptor |
2920 | 1052 |
"given a fileDescriptor, create an ExternalStream object |
1053 |
to read from this fd. This may be used to wrap fd's |
|
1054 |
as returned by user primitive code, or to wrap pipe- |
|
1055 |
filedescriptors into externalStreams." |
|
1056 |
||
3535 | 1057 |
^ (self forFileDescriptor:aFileDescriptor mode:ReadMode) readonly |
2920 | 1058 |
|
1059 |
" |
|
1060 |
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
|
1061 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1062 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1063 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1064 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1065 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1066 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1067 |
|
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 |
|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
|
1070 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1071 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1072 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1073 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1074 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1075 |
writeFd := pipe at:2. |
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 |
'connect Smalltalk streams ...'. |
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 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1080 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
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 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1083 |
[ |
3535 | 1084 |
1 to:10 do:[:i | |
1085 |
Transcript showCR:rs nextLine |
|
1086 |
]. |
|
1087 |
rs close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1088 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1089 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1090 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1091 |
[ |
3535 | 1092 |
1 to:10 do:[:i | |
1093 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
1094 |
]. |
|
1095 |
ws close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1096 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1097 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1098 |
" |
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 |
"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
|
1101 |
"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
|
1102 |
! |
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 |
forWritingToFileDescriptor:aFileDescriptor |
2920 | 1105 |
"given a fileDescriptor, create an ExternalStream object |
1106 |
to write to this fd. This may be used to wrap fd's |
|
1107 |
as returned by user primitive code, or to wrap pipe- |
|
1108 |
filedescriptors into externalStreams." |
|
1109 |
||
3535 | 1110 |
^ (self forFileDescriptor:aFileDescriptor mode:WriteMode) writeonly |
2920 | 1111 |
|
1112 |
" |
|
1113 |
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
|
1114 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1115 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1116 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1117 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1118 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1119 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1120 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1121 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1122 |
"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
|
1123 |
"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
|
1124 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1125 |
|
3535 | 1126 |
makePTYPair |
1127 |
"return an array with two streams - the first one is the master, |
|
1128 |
the second the slave of a ptym/ptys pair. |
|
1129 |
This is much like a bidirectional pipe, but allows signals & |
|
1130 |
control chars to be passed through the connection. |
|
1131 |
This is needed to execute a shell in a view. |
|
1132 |
This is the higher level equivalent of OperatingSystem>>makePTYPair |
|
1133 |
(which returns an array of file-descriptors)." |
|
1134 |
||
1135 |
|ptyPair m s| |
|
1136 |
||
1137 |
ptyPair := OperatingSystem makePTYPair. |
|
1138 |
ptyPair notNil ifTrue:[ |
|
1139 |
m := self forReadWriteToFileDescriptor:(ptyPair at:1). |
|
1140 |
s := self forReadWriteToFileDescriptor:(ptyPair at:2). |
|
3536 | 1141 |
ptyPair at:1 put:m. |
1142 |
ptyPair at:2 put:s. |
|
1143 |
^ ptyPair |
|
3535 | 1144 |
]. |
1145 |
^ nil |
|
1146 |
||
1147 |
" |
|
1148 |
ExternalStream makePTYPair. |
|
1149 |
" |
|
1150 |
||
1151 |
"Modified: 29.2.1996 / 18:28:36 / cg" |
|
1152 |
! |
|
1153 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1154 |
makePipe |
2920 | 1155 |
"return an array with two streams - the first one for reading, |
1156 |
the second for writing. |
|
1157 |
This is the higher level equivalent of OperatingSystem>>makePipe |
|
1158 |
(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
|
1159 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1160 |
|pipe rs ws| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1161 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1162 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1163 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1164 |
pipe notNil ifTrue:[ |
2264 | 1165 |
rs := self forReadingFromFileDescriptor:(pipe at:1). |
1166 |
ws := self forWritingToFileDescriptor:(pipe at:2). |
|
1167 |
^ 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
|
1168 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1169 |
^ nil |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1170 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1171 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1172 |
|pipe rs ws| |
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 |
pipe := ExternalStream makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1175 |
rs := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1176 |
ws := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1177 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1178 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1179 |
[ |
2264 | 1180 |
1 to:10 do:[:i | |
1181 |
Transcript showCR:rs nextLine |
|
1182 |
]. |
|
1183 |
rs close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1184 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1185 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1186 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1187 |
[ |
2264 | 1188 |
1 to:10 do:[:i | |
1189 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
|
1190 |
]. |
|
1191 |
ws close. |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1192 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1193 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1194 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1195 |
"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
|
1196 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1197 |
|
612 | 1198 |
new |
1199 |
|newStream| |
|
1200 |
||
1201 |
newStream := self basicNew. |
|
2920 | 1202 |
newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF. |
612 | 1203 |
^ newStream |
1204 |
! ! |
|
1205 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1206 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 1207 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1208 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1209 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1210 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1211 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1212 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1213 |
"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
|
1214 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1215 |
|
612 | 1216 |
invalidModeSignal |
1217 |
"return the signal raised when doing text-I/O with a binary stream |
|
1218 |
or binary-I/O with a text stream" |
|
1219 |
||
1220 |
^ InvalidModeSignal |
|
159 | 1221 |
! |
1222 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1223 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1224 |
"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
|
1225 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1226 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1227 |
^ InvalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1228 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1229 |
|
159 | 1230 |
invalidReadSignal |
1231 |
"return the signal raised when reading from writeonly streams" |
|
1232 |
||
1233 |
^ InvalidReadSignal |
|
1234 |
! |
|
1235 |
||
1236 |
invalidWriteSignal |
|
1237 |
"return the signal raised when writing to readonly streams" |
|
1238 |
||
1239 |
^ InvalidWriteSignal |
|
1240 |
! |
|
1241 |
||
612 | 1242 |
openErrorSignal |
1243 |
"return the signal raised when a file open failed" |
|
1244 |
||
1245 |
^ OpenErrorSignal |
|
1246 |
! |
|
1247 |
||
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1248 |
streamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1249 |
"return the signal raised when an I/O error occurs. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1250 |
(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
|
1251 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1252 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1253 |
^ StreamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1254 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1255 |
"Created: / 21.5.1998 / 16:32:55 / cg" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1256 |
! |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1257 |
|
159 | 1258 |
streamNotOpenSignal |
1259 |
"return the signal raised on I/O with closed streams" |
|
1260 |
||
1261 |
^ StreamNotOpenSignal |
|
2 | 1262 |
! ! |
1263 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1264 |
!ExternalStream class methodsFor:'error handling'! |
92 | 1265 |
|
1266 |
lastErrorNumber |
|
159 | 1267 |
"return the errno of the last error" |
92 | 1268 |
|
1269 |
^ LastErrorNumber |
|
159 | 1270 |
|
1271 |
" |
|
1272 |
ExternalStream lastErrorNumber |
|
1273 |
" |
|
92 | 1274 |
! |
1275 |
||
1276 |
lastErrorString |
|
1277 |
"return a message string describing the last error" |
|
1278 |
||
1279 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
1280 |
||
1281 |
" |
|
1282 |
ExternalStream lastErrorString |
|
1283 |
" |
|
1284 |
! ! |
|
1285 |
||
3044 | 1286 |
!ExternalStream methodsFor:'Squeak compatibility'! |
1287 |
||
1288 |
readOnly |
|
1289 |
"Squeak compatibility: make the stream readOnly" |
|
1290 |
||
1291 |
mode := #readonly |
|
1292 |
||
1293 |
"Modified: 20.10.1997 / 19:23:04 / cg" |
|
1294 |
"Created: 20.10.1997 / 19:23:19 / cg" |
|
1295 |
! ! |
|
1296 |
||
1 | 1297 |
!ExternalStream methodsFor:'accessing'! |
1298 |
||
612 | 1299 |
binary |
1300 |
"switch to binary mode - default is text" |
|
1301 |
||
1302 |
binary := true |
|
1 | 1303 |
! |
1304 |
||
1305 |
buffered:aBoolean |
|
10 | 1306 |
"turn buffering on or off - default is on" |
1 | 1307 |
|
10 | 1308 |
buffered := aBoolean |
1 | 1309 |
! |
1310 |
||
1311 |
contents |
|
2 | 1312 |
"return the contents of the file from the current position up-to |
1313 |
the end. If the stream is in binary mode, a ByteArray containing |
|
1314 |
the byte values is returned. |
|
1315 |
In text-mode, a collection of strings, each representing one line, |
|
1316 |
is returned." |
|
1317 |
||
1318 |
|text l chunks sizes chunk byteCount cnt bytes offset| |
|
1319 |
||
1320 |
binary ifTrue:[ |
|
2264 | 1321 |
"adding to a ByteArray produces quadratic time-space |
1322 |
behavior - therefore we allocate chunks, and concatenate them |
|
1323 |
at the end." |
|
1324 |
||
1325 |
chunks := OrderedCollection new. |
|
1326 |
sizes := OrderedCollection new. |
|
1327 |
byteCount := 0. |
|
1328 |
[self atEnd] whileFalse:[ |
|
1329 |
chunk := ByteArray uninitializedNew:4096. |
|
1330 |
cnt := self nextBytes:(chunk size) into:chunk. |
|
1331 |
cnt notNil ifTrue:[ |
|
1332 |
chunks add:chunk. |
|
1333 |
sizes add:cnt. |
|
1334 |
byteCount := byteCount + cnt |
|
1335 |
] |
|
1336 |
]. |
|
1337 |
||
1338 |
"now, create one big ByteArray" |
|
1339 |
bytes := ByteArray uninitializedNew:byteCount. |
|
1340 |
offset := 1. |
|
1341 |
1 to:chunks size do:[:index | |
|
1342 |
chunk := chunks at:index. |
|
1343 |
cnt := sizes at:index. |
|
1344 |
bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk. |
|
1345 |
offset := offset + cnt |
|
1346 |
]. |
|
1347 |
^ bytes |
|
2 | 1348 |
]. |
1 | 1349 |
|
244 | 1350 |
text := StringCollection new. |
1 | 1351 |
[self atEnd] whileFalse:[ |
2264 | 1352 |
l := self nextLine. |
1353 |
l isNil ifTrue:[ |
|
1354 |
^ text |
|
1355 |
]. |
|
1356 |
text add:l |
|
1 | 1357 |
]. |
1358 |
^ text |
|
1359 |
! |
|
1360 |
||
612 | 1361 |
contentsOfEntireFile |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1362 |
"ST-80 compatibility: return contents as String" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1363 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1364 |
^ self contents asString. |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1365 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1366 |
"Modified: 3.7.1996 / 13:22:16 / stefan" |
2 | 1367 |
! |
1368 |
||
612 | 1369 |
contentsSpecies |
1370 |
"return the kind of object to be returned by sub-collection builders |
|
1371 |
(such as upTo)" |
|
159 | 1372 |
|
1373 |
binary ifTrue:[ |
|
2264 | 1374 |
^ ByteArray |
159 | 1375 |
]. |
612 | 1376 |
^ String |
2 | 1377 |
! |
1378 |
||
2920 | 1379 |
eolMode:aSymbolOrNil |
1380 |
"specify how end-of-line (EOL) is to be marked. |
|
1381 |
The argument may be one of: |
|
1382 |
#crlf -> add a CR-NL, as in MSDOS |
|
1383 |
#cr -> add a CR, as in VMS |
|
1384 |
#nl -> add a NL, as in Unix |
|
1385 |
anyOther -> like #nl |
|
1386 |
" |
|
1387 |
||
1388 |
eolMode := aSymbolOrNil |
|
1389 |
! |
|
1390 |
||
612 | 1391 |
fileDescriptor |
1392 |
"return the fileDescriptor of the receiver - |
|
1393 |
notice: this one returns the underlying OSs fileDescriptor - |
|
1394 |
this may not be available on all platforms (i.e. non unix systems)." |
|
1 | 1395 |
|
1396 |
%{ /* NOCONTEXT */ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1397 |
#ifdef WIN32 |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1398 |
RETURN (nil); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1399 |
#else |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1400 |
FILEPOINTER f; |
612 | 1401 |
OBJ fp; |
1402 |
||
1133 | 1403 |
if ((fp = __INST(filePointer)) != nil) { |
2264 | 1404 |
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
|
1405 |
RETURN ( __MKINT(fileno(f)) ); |
1 | 1406 |
} |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1407 |
#endif |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1408 |
%}. |
612 | 1409 |
^ self errorNotOpen |
1410 |
! |
|
1411 |
||
1412 |
filePointer |
|
1413 |
"return the filePointer of the receiver - |
|
1414 |
notice: for portability stdio is used; this means you will get |
|
1415 |
a FILE * - not a fileDescriptor. |
|
1416 |
(what you really get is a corresponding integer). |
|
1417 |
You cannot do much with the returned value |
|
1418 |
- except passing it to a primitive, for example." |
|
1419 |
||
1420 |
^ filePointer |
|
1421 |
! |
|
1422 |
||
3016 | 1423 |
lineEndTransparent |
1424 |
eolMode := #cr |
|
1425 |
! |
|
1426 |
||
612 | 1427 |
readonly |
1428 |
"set access mode to readonly" |
|
1429 |
||
1430 |
mode := #readonly |
|
1431 |
! |
|
1432 |
||
1433 |
readwrite |
|
1434 |
"set access mode to readwrite" |
|
1435 |
||
1436 |
mode := #readwrite |
|
1437 |
! |
|
1438 |
||
1439 |
text |
|
1440 |
"switch to text mode - default is text" |
|
1441 |
||
1442 |
binary := false |
|
1443 |
! |
|
1444 |
||
1445 |
useCRLF:aBoolean |
|
2920 | 1446 |
"turn on or off CRLF sending (instead of LF only) - default is off. |
1447 |
This method is provided for backward compatibility - see #eolMode: |
|
1448 |
which offers another choice." |
|
1449 |
||
1450 |
aBoolean ifTrue:[ |
|
1451 |
eolMode := #crlf |
|
1452 |
] ifFalse:[ |
|
1453 |
eolMode := #nl |
|
1454 |
]. |
|
1 | 1455 |
! |
1456 |
||
612 | 1457 |
writeonly |
1458 |
"set access mode to writeonly" |
|
1459 |
||
1460 |
mode := #writeonly |
|
1461 |
! ! |
|
1462 |
||
1463 |
!ExternalStream methodsFor:'error handling'! |
|
1464 |
||
1465 |
argumentMustBeCharacter |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1466 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1467 |
|
612 | 1468 |
"report an error, that the argument must be a character" |
1469 |
||
1470 |
^ self error:'argument must be a character' |
|
1471 |
! |
|
1472 |
||
1473 |
argumentMustBeInteger |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1474 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1475 |
|
612 | 1476 |
"report an error, that the argument must be an integer" |
1477 |
||
1478 |
^ self error:'argument must be an integer' |
|
77 | 1479 |
! |
1480 |
||
612 | 1481 |
argumentMustBeString |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1482 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1483 |
|
612 | 1484 |
"report an error, that the argument must be a string" |
1485 |
||
1486 |
^ self error:'argument must be a string' |
|
1487 |
! |
|
1488 |
||
1489 |
errorBinary |
|
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 stream is in binary mode" |
1493 |
||
2920 | 1494 |
^ self invalidModeSignal |
2264 | 1495 |
raiseRequestWith:self |
1496 |
errorString:(self class name , ' is in binary mode') |
|
1497 |
in:thisContext sender |
|
612 | 1498 |
! |
1499 |
||
1500 |
errorNotBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1501 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1502 |
|
612 | 1503 |
"report an error, that the stream is not in binary mode" |
1504 |
||
2920 | 1505 |
^ self invalidModeSignal |
2264 | 1506 |
raiseRequestWith:self |
1507 |
errorString:(self class name , ' is not in binary mode') |
|
1508 |
in:thisContext sender |
|
1 | 1509 |
! |
1510 |
||
612 | 1511 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1512 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1513 |
|
612 | 1514 |
"report an error, that the stream is not in buffered mode" |
1515 |
||
1516 |
^ StreamErrorSignal |
|
2264 | 1517 |
raiseRequestWith:self |
1518 |
errorString:(self class name , ' is unbuffered - operation not allowed') |
|
1519 |
in:thisContext sender |
|
612 | 1520 |
! |
1521 |
||
1522 |
errorNotOpen |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1523 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1524 |
|
612 | 1525 |
"report an error, that the stream has not been opened" |
1526 |
||
3467 | 1527 |
^ StreamNotOpenSignal |
1528 |
raiseRequestWith:self |
|
1529 |
errorString:(self class name , ' not open') |
|
1530 |
in:thisContext sender |
|
1531 |
||
1532 |
"Modified: / 19.5.1998 / 22:07:52 / cg" |
|
612 | 1533 |
! |
1534 |
||
1535 |
errorOpen |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1536 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1537 |
|
612 | 1538 |
"report an error, that the stream is already opened" |
1539 |
||
2920 | 1540 |
^ self openErrorSignal |
2264 | 1541 |
raiseRequestWith:self |
1542 |
errorString:(self class name , ' is already open') |
|
1543 |
in:thisContext sender |
|
612 | 1544 |
! |
1545 |
||
1546 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1547 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1548 |
|
612 | 1549 |
"report an error, that the stream is a readOnly stream" |
1550 |
||
2920 | 1551 |
^ self invalidWriteSignal |
2264 | 1552 |
raiseRequestWith:self |
1553 |
errorString:(self class name , ' is readonly') |
|
1554 |
in:thisContext sender |
|
612 | 1555 |
! |
1556 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1557 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1558 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1559 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1560 |
"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
|
1561 |
|
2920 | 1562 |
^ self invalidOperationSignal |
2264 | 1563 |
raiseRequestWith:self |
1564 |
errorString:'unsupported operation' |
|
1565 |
in:thisContext sender |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1566 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1567 |
|
612 | 1568 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1569 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1570 |
|
612 | 1571 |
"report an error, that the stream is a writeOnly stream" |
1572 |
||
2920 | 1573 |
^ self invalidReadSignal |
2264 | 1574 |
raiseRequestWith:self |
1575 |
errorString:(self class name , ' is writeonly') |
|
1576 |
in:thisContext sender |
|
2 | 1577 |
! |
1578 |
||
612 | 1579 |
ioError |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1580 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1581 |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1582 |
"report an error, that some I/O error occured. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1583 |
(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
|
1584 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1585 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1586 |
^ StreamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1587 |
raiseRequestWith:self |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1588 |
errorString:('I/O error: ' , self lastErrorString) |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1589 |
in:thisContext sender |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1590 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1591 |
"Modified: / 21.5.1998 / 16:33:13 / cg" |
612 | 1592 |
! |
1593 |
||
1594 |
lastErrorNumber |
|
1595 |
"return the last error" |
|
1596 |
||
1597 |
^ lastErrorNumber |
|
1598 |
! |
|
1599 |
||
1600 |
lastErrorString |
|
1601 |
"return a message string describing the last error" |
|
1602 |
||
1603 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
2264 | 1604 |
^ 'I/O error' |
612 | 1605 |
]. |
1606 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 1607 |
! |
1608 |
||
612 | 1609 |
openError |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1610 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1611 |
|
612 | 1612 |
"report an error, that the open failed" |
1613 |
||
3235
cc254b307159
FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3221
diff
changeset
|
1614 |
^ self class openErrorSignal |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1615 |
raiseRequestWith:self |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1616 |
errorString:('error on open: ' , self lastErrorString) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1617 |
in:thisContext sender |
3235
cc254b307159
FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3221
diff
changeset
|
1618 |
|
cc254b307159
FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3221
diff
changeset
|
1619 |
"Modified: / 28.1.1998 / 14:37:42 / stefan" |
612 | 1620 |
! |
1621 |
||
1622 |
readError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1623 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1624 |
|
612 | 1625 |
"report an error, that some read error occured" |
1626 |
||
1627 |
^ ReadErrorSignal |
|
2264 | 1628 |
raiseRequestWith:self |
1629 |
errorString:('read error: ' , self lastErrorString) |
|
1630 |
in:thisContext sender |
|
612 | 1631 |
! |
1632 |
||
1633 |
writeError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1634 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
1635 |
|
612 | 1636 |
"report an error, that some write error occured" |
1637 |
||
1638 |
^ WriteErrorSignal |
|
2264 | 1639 |
raiseRequestWith:self |
1640 |
errorString:('write error: ' , self lastErrorString) |
|
1641 |
in:thisContext sender |
|
612 | 1642 |
! ! |
1643 |
||
1644 |
!ExternalStream methodsFor:'instance release'! |
|
1645 |
||
1646 |
closeFile |
|
1647 |
"low level close - may be redefined in subclasses" |
|
2 | 1648 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1649 |
%{ |
216 | 1650 |
OBJ fp; |
2 | 1651 |
|
1133 | 1652 |
if ((fp = __INST(filePointer)) != nil) { |
2264 | 1653 |
__INST(filePointer) = nil; |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1654 |
#if defined(WIN32) && defined(NO_STDIO) |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1655 |
CloseHandle(__HANDLEVal(fp)); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1656 |
#else |
2264 | 1657 |
__BEGIN_INTERRUPTABLE__ |
1658 |
fclose(__FILEVal(fp)); |
|
1659 |
__END_INTERRUPTABLE__ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1660 |
#endif |
10 | 1661 |
} |
1662 |
%} |
|
1663 |
! |
|
1664 |
||
612 | 1665 |
disposed |
1666 |
"some Stream has been collected - close the file if not already done" |
|
1667 |
||
1668 |
self closeFile |
|
1669 |
! |
|
1670 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1671 |
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
|
1672 |
"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
|
1673 |
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
|
1674 |
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
|
1675 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1676 |
%{ /* NOCONTEXT */ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1677 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1678 |
FILEPOINTER f; |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1679 |
OBJ fp; |
2765 | 1680 |
FILE *fdopen(); |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1681 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1682 |
if (__isSmallInteger(anInteger) && |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1683 |
__isString(openMode) && |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1684 |
(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
|
1685 |
) { |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1686 |
__PROTECT__(self); |
3420 | 1687 |
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
|
1688 |
__UNPROTECT__(self); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1689 |
__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
|
1690 |
RETURN (self); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1691 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1692 |
%}. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1693 |
^ self primitiveFailed |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1694 |
! |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1695 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1696 |
setFilePointer:something |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1697 |
"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
|
1698 |
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
|
1699 |
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
|
1700 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1701 |
filePointer := something |
1 | 1702 |
! |
1703 |
||
612 | 1704 |
shallowCopyForFinalization |
1705 |
"return a copy for finalization-registration; |
|
1706 |
since all we need at finalization time is the fileDescriptor, |
|
1707 |
a cheaper copy is possible." |
|
1708 |
||
1709 |
^ self class basicNew setFilePointer:filePointer |
|
1 | 1710 |
! |
1711 |
||
612 | 1712 |
shutDown |
1713 |
"close the stream - added for protocol compatibility with PipeStream. |
|
1714 |
see comment there" |
|
1715 |
||
1642
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
1716 |
filePointer isNil ifTrue:[^ self]. |
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
1717 |
Lobby unregister:self. |
612 | 1718 |
self closeFile |
1642
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
1719 |
|
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
1720 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
1 | 1721 |
! ! |
1722 |
||
2 | 1723 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 1724 |
|
1725 |
nextLine |
|
1726 |
"read the next line (characters up to newline). |
|
1727 |
Return a string containing those characters excluding the newline. |
|
1728 |
If the previous-to-last character is a cr, this is also removed, |
|
68 | 1729 |
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
|
1730 |
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
|
1731 |
|
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1732 |
|line| |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
1733 |
|
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
1734 |
%{ /* STACK:34000 */ |
1 | 1735 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1736 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1737 |
int len, ret; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
1738 |
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
|
1739 |
char *rslt, *nextPtr, *limit; |
22 | 1740 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
1741 |
int _buffered; |
216 | 1742 |
OBJ fp; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1743 |
int lineTooLong = 0; |
2920 | 1744 |
int cutOff = 0; |
1 | 1745 |
|
1133 | 1746 |
__INST(lastErrorNumber) = nil; |
1747 |
if (((fp = __INST(filePointer)) != nil) |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1748 |
&& (__INST(mode) != @symbol(writeonly)) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1749 |
&& (__INST(binary) != true) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1750 |
) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1751 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1752 |
buffer[0] = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1753 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1754 |
_buffered = (__INST(buffered) == true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1755 |
if (_buffered) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1756 |
__READING__(f); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1757 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1758 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1759 |
rslt = nextPtr = buffer; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1760 |
limit = buffer + sizeof(buffer) - 2; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1761 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1762 |
for (;;) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1763 |
__READBYTE__(ret, f, nextPtr, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1764 |
if (ret <= 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1765 |
if (nextPtr == buffer) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1766 |
rslt = NULL; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1767 |
if (ret == 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1768 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1769 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1770 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1771 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1772 |
goto err; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1773 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1774 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1775 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1776 |
if (*nextPtr == '\n') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1777 |
cutOff = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1778 |
*nextPtr = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1779 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1780 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1781 |
if (*nextPtr == '\r') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1782 |
char peekChar; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1783 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1784 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1785 |
* peek ahead for a newLine ... |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1786 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1787 |
__READBYTE__(ret, f, &peekChar, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1788 |
if (ret <= 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1789 |
cutOff = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1790 |
*nextPtr = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1791 |
if (ret == 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1792 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1793 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1794 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1795 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1796 |
goto err; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1797 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1798 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1799 |
if (peekChar == '\n') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1800 |
cutOff = 2; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1801 |
*nextPtr = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1802 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1803 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1804 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1805 |
__UNGETC__(peekChar, f, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1806 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1807 |
cutOff = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1808 |
*nextPtr = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1809 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1810 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1811 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1812 |
nextPtr++; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1813 |
if (nextPtr >= limit) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1814 |
*nextPtr = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1815 |
lineTooLong = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1816 |
if (@global(InfoPrinting) == true) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1817 |
fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n"); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1818 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1819 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1820 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1821 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1822 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1823 |
if (rslt != NULL) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1824 |
len = nextPtr-buffer; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1825 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1826 |
if (__INST(position) != nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1827 |
int __p; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1828 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1829 |
__p = __intVal(__INST(position)) + len + cutOff; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1830 |
__INST(position) = __MKSMALLINT(__p); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1831 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1832 |
/* remove any EOL character */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1833 |
if (len != 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1834 |
if (buffer[len-1] == '\n') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1835 |
buffer[--len] = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1836 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1837 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1838 |
buffer[--len] = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1839 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1840 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1841 |
line = __MKSTRING_L(buffer, len); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1842 |
if (! lineTooLong) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1843 |
RETURN ( line ); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1844 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1845 |
} |
1 | 1846 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1847 |
err: ; |
159 | 1848 |
%}. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1849 |
line notNil ifTrue:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1850 |
"/ the line as read is longer than 32k characters (boy - what a line) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1851 |
"/ The exception could be handled by reading more and returning the |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1852 |
"/ concatenation in your exception handler (the receiver and the partial |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1853 |
"/ line are passed as parameter) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1854 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1855 |
^ ReadErrorSignal |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1856 |
raiseRequestWith:(Array with:self with:line) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
1857 |
errorString:('line too long read error') |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1858 |
]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1859 |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
1860 |
hitEOF ifTrue:[^ self pastEnd]. |
159 | 1861 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2 | 1862 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
1 | 1863 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1864 |
^ self errorBinary |
1 | 1865 |
! |
1866 |
||
1867 |
nextPutLine:aString |
|
2920 | 1868 |
"write the characters in aString and append an end-of-Line marker |
1869 |
(LF, CR or CRLF - depending in the setting of eolMode)" |
|
1 | 1870 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
1871 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1872 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1873 |
int len, cnt, len1, _buffered; |
216 | 1874 |
OBJ pos, fp; |
537
dc4dad8a5ddd
many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1875 |
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
|
1876 |
int o_offs; |
1 | 1877 |
|
1133 | 1878 |
__INST(lastErrorNumber) = nil; |
1879 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 1880 |
&& (__INST(mode) != @symbol(readonly)) |
1881 |
&& (__INST(binary) != true) |
|
1882 |
&& __isString(aString) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1883 |
) { |
2264 | 1884 |
f = __FILEVal(fp); |
1885 |
len = __stringSize(aString); |
|
1886 |
||
1887 |
if (_buffered = (__INST(buffered) == true)) { |
|
1888 |
__WRITING__(f) |
|
1889 |
} |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1890 |
#ifdef BUGGY |
2264 | 1891 |
__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
|
1892 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1893 |
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
|
1894 |
__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
|
1895 |
#endif |
2264 | 1896 |
if (cnt == len) { |
2920 | 1897 |
OBJ mode = __INST(eolMode); |
1898 |
||
2264 | 1899 |
len1 = len; |
1900 |
||
2920 | 1901 |
if (mode == @symbol(cr)) { |
1902 |
cp = "\r"; len = 1; |
|
1903 |
} else if (mode == @symbol(crlf)) { |
|
2264 | 1904 |
cp = "\r\n"; len = 2; |
1905 |
} else { |
|
1906 |
cp = "\n"; len = 1; |
|
1907 |
} |
|
1908 |
__WRITEBYTES__(cnt, f, cp, len, _buffered); |
|
1909 |
||
1910 |
if (cnt > 0) { |
|
1911 |
pos = __INST(position); |
|
1912 |
if (pos != nil) { |
|
2920 | 1913 |
int __p; |
1914 |
||
1915 |
__p = __intVal(pos) + len1 + cnt; |
|
1916 |
__INST(position) = __MKSMALLINT(__p); |
|
2264 | 1917 |
} |
1918 |
RETURN ( self ); |
|
1919 |
} |
|
1920 |
} |
|
1921 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
1 | 1922 |
} |
159 | 1923 |
%}. |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1924 |
super nextPutLine:aString. |
1 | 1925 |
! |
1926 |
||
1927 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 1928 |
"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
|
1929 |
and append all lines to self. |
159 | 1930 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 1931 |
|
22 | 1932 |
If aStringOrNil is nil or not matched, copy preceeds to the end. |
1933 |
(this allows for example to read a Socket and transfer the data quickly |
|
1934 |
into a file - without creating zillions of temporary strings)" |
|
1 | 1935 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1936 |
|srcFilePointer readError line| |
1 | 1937 |
|
2331 | 1938 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
1939 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
1 | 1940 |
srcFilePointer := aStream filePointer. |
2331 | 1941 |
srcFilePointer isNil ifTrue:[aStream errorNotOpen. ^ self]. |
12 | 1942 |
|
1943 |
%{ /* STACK:2000 */ |
|
22 | 1944 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1945 |
#ifndef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1946 |
FILEPOINTER dst; |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1947 |
FILEPOINTER src; |
1 | 1948 |
char *matchString; |
1949 |
int matchLen = 0; |
|
12 | 1950 |
char buffer[1024]; |
1 | 1951 |
|
1133 | 1952 |
__INST(lastErrorNumber) = nil; |
249 | 1953 |
if (__isSmallInteger(srcFilePointer)) { |
2264 | 1954 |
if ((aStringOrNil == nil) || __isString(aStringOrNil)) { |
1955 |
if (aStringOrNil != nil) { |
|
1956 |
matchString = (char *) __stringVal(aStringOrNil); |
|
1957 |
matchLen = __stringSize(aStringOrNil); |
|
1958 |
} |
|
1959 |
dst = __FILEVal(__INST(filePointer)); |
|
1960 |
src = __FILEVal(srcFilePointer); |
|
1961 |
__BEGIN_INTERRUPTABLE__ |
|
1962 |
errno = 0; |
|
1963 |
||
1964 |
__WRITING__(dst) |
|
1965 |
||
1966 |
for (;;) { |
|
1967 |
if (fgets(buffer, sizeof(buffer)-1, src) == NULL) { |
|
1968 |
if (ferror(src)) { |
|
1969 |
readError = __MKSMALLINT(errno); |
|
1970 |
__END_INTERRUPTABLE__ |
|
1971 |
goto err; |
|
1972 |
} |
|
1973 |
break; |
|
1974 |
} |
|
1975 |
if (fputs(buffer, dst) == EOF) { |
|
1976 |
if (ferror(dst)) { |
|
1977 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
1978 |
__END_INTERRUPTABLE__ |
|
1979 |
goto err; |
|
1980 |
} |
|
1981 |
break; |
|
1982 |
} |
|
12 | 1983 |
#ifndef OLD |
2264 | 1984 |
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
|
1985 |
FFLUSH(dst); |
2264 | 1986 |
} |
12 | 1987 |
#endif |
2264 | 1988 |
if (matchLen) { |
1989 |
if (strncmp(matchString, buffer, matchLen) == 0) |
|
1990 |
break; |
|
1991 |
} |
|
1992 |
} |
|
1993 |
__END_INTERRUPTABLE__ |
|
1994 |
__INST(position) = nil; |
|
1995 |
RETURN (self); |
|
1996 |
} |
|
1 | 1997 |
} |
159 | 1998 |
err: ; |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1999 |
#endif /* ! NO_STDIO */ |
159 | 2000 |
%}. |
2001 |
readError ifTrue:[ |
|
2264 | 2002 |
aStream setLastErrorNumber:readError. |
2331 | 2003 |
aStream readError. |
2004 |
^ self |
|
159 | 2005 |
]. |
2331 | 2006 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
2007 |
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
|
2008 |
|
159 | 2009 |
" |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2010 |
argument error or unimplemented; try it linewise |
159 | 2011 |
" |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2012 |
[aStream atEnd] whileFalse:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2013 |
line := aStream nextLine. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2014 |
line isNil ifTrue:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2015 |
^ self. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2016 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2017 |
self nextPutLine:line. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2018 |
(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
|
2019 |
^ self |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2020 |
] |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2021 |
]. |
1 | 2022 |
! |
2023 |
||
2024 |
peekForLineStartingWith:aString |
|
2025 |
"read ahead for next line starting with aString; |
|
159 | 2026 |
return the line-string if found, or nil if EOF is encountered. |
2027 |
If matched, not advance position behond that line |
|
2028 |
i.e. nextLine will read the matched line. |
|
2029 |
If not matched, reposition to original position for firther reading." |
|
1 | 2030 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2031 |
|firstPos lastPos line| |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2032 |
|
1 | 2033 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
2034 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2 | 2035 |
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
|
2036 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 2037 |
|
2038 |
%{ /* STACK: 2000 */ |
|
2920 | 2039 |
#ifndef NO_STDIO |
2040 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2041 |
FILEPOINTER f; |
1 | 2042 |
int l; |
12 | 2043 |
char buffer[1024]; |
1 | 2044 |
char *cp; |
2045 |
char *matchString; |
|
2920 | 2046 |
int gotFirst = 0; |
2047 |
#ifdef __VMS__ |
|
2048 |
fpos_t firstpos, lastpos; |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2049 |
# define FTELL(__f__, __pos__) fgetpos(__f__, &(__pos__)) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2050 |
# define FSEEK(__f__, __pos__) fsetpos(__f__, &(__pos__)) |
2920 | 2051 |
#else |
2052 |
long firstpos, lastpos; |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2053 |
# define FTELL(__f__, __pos__) __pos__ = ftell(__f__) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2054 |
# define FSEEK(__f__, __pos__) fseek(__f__, __pos__, SEEK_SET) |
2920 | 2055 |
#endif |
2056 |
||
1133 | 2057 |
__INST(lastErrorNumber) = nil; |
54 | 2058 |
if (__isString(aString)) { |
2264 | 2059 |
matchString = (char *) __stringVal(aString); |
2060 |
l = __stringSize(aString); |
|
2061 |
||
2062 |
f = __FILEVal(__INST(filePointer)); |
|
2063 |
__READING__(f) |
|
2064 |
||
2065 |
for (;;) { |
|
2920 | 2066 |
FTELL(f, lastpos); |
2067 |
if (!gotFirst) { |
|
2068 |
firstpos = lastpos; |
|
2069 |
gotFirst = 1; |
|
2070 |
} |
|
2264 | 2071 |
|
2072 |
__BEGIN_INTERRUPTABLE__ |
|
2073 |
do { |
|
2074 |
cp = fgets(buffer, sizeof(buffer)-1, f); |
|
2075 |
} while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1)); |
|
2076 |
buffer[sizeof(buffer)-1] = '\0'; |
|
2077 |
__END_INTERRUPTABLE__ |
|
2078 |
||
2079 |
if (cp == NULL) { |
|
2080 |
if (ferror(f)) { |
|
2081 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2082 |
goto err; |
|
2083 |
} else { |
|
2920 | 2084 |
FSEEK(f, firstpos); |
2264 | 2085 |
RETURN (nil); |
2086 |
} |
|
2087 |
} |
|
2088 |
if (strncmp(cp, matchString, l) == 0) { |
|
2920 | 2089 |
FSEEK(f, lastpos); |
2264 | 2090 |
break; |
2091 |
} |
|
2092 |
} |
|
2093 |
/* remove EOL character */ |
|
2094 |
cp = buffer; |
|
2920 | 2095 |
while (*cp && (*cp != '\n') && (*cp != '\r')) cp++; |
2264 | 2096 |
*cp = '\0'; |
2097 |
RETURN ( __MKSTRING(buffer) ); |
|
1 | 2098 |
} |
159 | 2099 |
err: ; |
2920 | 2100 |
|
2101 |
# undef FTELL |
|
2102 |
# undef FSEEK |
|
2103 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2104 |
#endif |
159 | 2105 |
%}. |
2106 |
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
|
2107 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2108 |
"/ 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
|
2109 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2110 |
firstPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2111 |
[self atEnd] whileFalse:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2112 |
lastPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2113 |
line := self nextLine. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2114 |
line isNil ifTrue:[ |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2115 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2116 |
^ nil |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2117 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2118 |
(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
|
2119 |
self position:lastPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2120 |
^ line |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2121 |
] |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2122 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2123 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2124 |
^ nil |
1 | 2125 |
! |
2126 |
||
2127 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
2128 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
2129 |
return the index in aCollection if found, nil otherwise.. |
|
2130 |
If no match, do not change position; otherwise advance right before the |
|
2131 |
matched line so that nextLine will return this line." |
|
2132 |
||
2133 |
|line startPos linePos index| |
|
2134 |
||
2135 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2136 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2 | 2137 |
binary ifTrue:[^ self errorBinary]. |
2138 |
||
1 | 2139 |
startPos := self position. |
2140 |
[self atEnd] whileFalse:[ |
|
2264 | 2141 |
linePos := self position. |
2142 |
line := self nextLine. |
|
2143 |
line notNil ifTrue:[ |
|
2144 |
index := 1. |
|
2145 |
aCollectionOfStrings do:[:prefix | |
|
2146 |
(line startsWith:prefix) ifTrue:[ |
|
2147 |
self position:linePos. |
|
2148 |
^ index |
|
2149 |
]. |
|
2150 |
index := index + 1 |
|
2151 |
] |
|
2152 |
] |
|
1 | 2153 |
]. |
2154 |
self position:startPos. |
|
2155 |
^ nil |
|
2156 |
! ! |
|
2157 |
||
612 | 2158 |
!ExternalStream methodsFor:'misc functions'! |
2159 |
||
2160 |
async:aBoolean |
|
779 | 2161 |
"set/clear the async attribute - if set, the availability of data on |
612 | 2162 |
the receiver will trigger an ioInterrupt. |
779 | 2163 |
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
|
2164 |
Notice: |
2264 | 2165 |
not every OS supports this |
2166 |
- check with OS>>supportsIOInterrupts before using" |
|
92 | 2167 |
|
2168 |
|fd| |
|
2169 |
||
159 | 2170 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2171 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2172 |
OperatingSystem supportsIOInterrupts ifFalse:[ |
2264 | 2173 |
^ self errorUnsupportedOperation |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2174 |
]. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2175 |
|
92 | 2176 |
fd := self fileDescriptor. |
612 | 2177 |
aBoolean ifTrue:[ |
2264 | 2178 |
^ OperatingSystem enableIOInterruptsOn:fd |
612 | 2179 |
]. |
2180 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2181 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2182 |
"Modified: 11.1.1997 / 17:50:21 / cg" |
92 | 2183 |
! |
2184 |
||
612 | 2185 |
backStep |
2186 |
"step back one element - |
|
2187 |
redefined, since position is redefined here" |
|
2188 |
||
2189 |
self position:(self position - 1) |
|
362 | 2190 |
! |
2191 |
||
612 | 2192 |
blocking:aBoolean |
2193 |
"set/clear the blocking attribute - if set (which is the default) |
|
2194 |
a read (using next) on the receiver will block until data is available. |
|
2195 |
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
|
2196 |
nil. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2197 |
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
|
2198 |
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
|
2199 |
in advance. However, the data must then be read using #nextBytes: |
3174 | 2200 |
methods, in order to avoid other (pastEnd) exceptions." |
92 | 2201 |
|
159 | 2202 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
612 | 2203 |
^ 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
|
2204 |
|
3174 | 2205 |
"Modified: / 11.1.1997 / 17:48:01 / cg" |
2206 |
"Modified: / 15.1.1998 / 11:49:48 / stefan" |
|
612 | 2207 |
! |
2208 |
||
2209 |
close |
|
2210 |
"close the stream - tell operating system" |
|
2211 |
||
2212 |
filePointer isNil ifTrue:[^ self]. |
|
2213 |
Lobby unregister:self. |
|
2214 |
self closeFile. |
|
2215 |
filePointer := nil |
|
2216 |
! |
|
2217 |
||
2218 |
create |
|
2219 |
"create the stream |
|
2220 |
- this must be redefined in subclass" |
|
2221 |
||
2222 |
^ self subclassResponsibility |
|
2223 |
! |
|
2224 |
||
2225 |
ioctl:ioctlNumber |
|
2226 |
"to provide a simple ioctl facility - an ioctl is performed |
|
2227 |
on the underlying file; no arguments are passed." |
|
2228 |
||
2920 | 2229 |
^ self ioctl:ioctlNumber with:nil |
2230 |
! |
|
2231 |
||
2232 |
ioctl:ioctlNumber with:arg |
|
2233 |
"to provide a simple ioctl facility - an ioctl is performed |
|
2234 |
on the underlying file; the argument is passed as argument. |
|
2235 |
This is not used by ST/X, but provided for special situations |
|
2236 |
- for example, to control proprietrary I/O devices. |
|
2237 |
||
2238 |
Since the type of the argument depends on the ioctl being |
|
2239 |
performed, different arg types are allowed here. |
|
2240 |
If the argument is nil, an ioctl without argument is performed. |
|
2241 |
If the argument is an integral number, its directly passed; |
|
2242 |
if its a kind of ByteArray (ByteArray, String or Structure), |
|
2243 |
or external data (ExternalBytes or ExternalAddress), |
|
2244 |
a pointer to the data is passed. |
|
2245 |
This allows performing most ioctls |
|
2246 |
- however, it might be tricky to setup the buffer. |
|
2247 |
Be careful in what you pass - ST/X cannot validate its correctness." |
|
2248 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2249 |
%{ |
2896 | 2250 |
#if !defined(MSDOS_LIKE) |
2251 |
# 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
|
2252 |
FILEPOINTER f; |
2920 | 2253 |
int ret, ioNum; |
612 | 2254 |
OBJ fp; |
2920 | 2255 |
INT ioArg; |
612 | 2256 |
|
1133 | 2257 |
__INST(lastErrorNumber) = nil; |
2258 |
if ((fp = __INST(filePointer)) != nil) { |
|
2920 | 2259 |
if (__isSmallInteger(ioctlNumber) |
2260 |
&& (__isSmallInteger(arg) |
|
2261 |
|| (arg == nil) |
|
2262 |
|| __isBytes(arg) |
|
2263 |
|| __isExternalBytes(arg) |
|
2264 |
|| __isExternalAddress(arg))) { |
|
2265 |
f = __FILEVal(fp); |
|
2264 | 2266 |
ioNum = __intVal(ioctlNumber); |
2267 |
||
2268 |
__BEGIN_INTERRUPTABLE__ |
|
2269 |
do { |
|
2270 |
errno = 0; |
|
2920 | 2271 |
if (arg == nil) { |
2272 |
ioArg = 0; |
|
2273 |
} else if (__isSmallInteger(arg)) { |
|
2274 |
ioArg = __intVal(arg); |
|
2275 |
} else if (__isExternalBytes(arg)) { |
|
2276 |
ioArg = (INT)(__externalBytesAddress(arg)); |
|
2277 |
} else if (__isExternalAddress(arg)) { |
|
2278 |
ioArg = (INT)(__externalAddressVal(arg)); |
|
2279 |
} else { |
|
2280 |
ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element); |
|
2281 |
} |
|
2282 |
ret = ioctl(fileno(f), ioNum, ioArg); |
|
2264 | 2283 |
} while ((ret < 0) && (errno == EINTR)); |
2284 |
__END_INTERRUPTABLE__ |
|
2285 |
||
2286 |
if (ret >= 0) { |
|
2287 |
RETURN ( __MKSMALLINT(ret) ); |
|
2288 |
} |
|
2289 |
__INST(position) = nil; |
|
2290 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2291 |
} |
|
612 | 2292 |
} |
2896 | 2293 |
# endif |
791 | 2294 |
#endif |
612 | 2295 |
%}. |
2296 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
2297 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2298 |
" |
|
2920 | 2299 |
argument is not an integer |
2300 |
" |
|
2301 |
(ioctlNumber isMemberOf:SmallInteger) ifFalse:[^ self primitiveFailed]. |
|
612 | 2302 |
" |
2920 | 2303 |
the system does not support ioctl (MSDOS or VMS) |
612 | 2304 |
" |
2920 | 2305 |
^ self errorUnsupportedOperation |
612 | 2306 |
! |
2307 |
||
2308 |
open |
|
2309 |
"open the stream |
|
2310 |
- this must be redefined in subclass" |
|
2311 |
||
2312 |
^ self subclassResponsibility |
|
2313 |
! |
|
2314 |
||
2315 |
position |
|
2316 |
"return the position |
|
2317 |
- this must be redefined in subclass" |
|
2318 |
||
2319 |
^ self subclassResponsibility |
|
2320 |
! |
|
2321 |
||
2322 |
position:anInteger |
|
2323 |
"set the position |
|
2324 |
- this must be redefined in subclass" |
|
2325 |
||
2326 |
^ self subclassResponsibility |
|
2327 |
! |
|
2328 |
||
2329 |
reset |
|
2330 |
"set the read position to the beginning of the collection" |
|
2331 |
||
2332 |
self position:"0" 1 |
|
2333 |
! |
|
2334 |
||
1044
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2335 |
setToEnd |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2336 |
"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
|
2337 |
|
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2338 |
^ self subclassResponsibility |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2339 |
! |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
2340 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2341 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2342 |
"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
|
2343 |
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
|
2344 |
|
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
2345 |
%{ |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2346 |
#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
|
2347 |
FILEPOINTER f; |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2348 |
OBJ fp; |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2349 |
|
1133 | 2350 |
if (((fp = __INST(filePointer)) != nil) |
2351 |
&& (__INST(mode) != @symbol(readonly))) { |
|
2264 | 2352 |
if (__isSmallInteger(newSize)) { |
2353 |
f = __FILEVal(fp); |
|
2354 |
||
2355 |
if (__INST(buffered) == true) { |
|
2356 |
__READING__(f) |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2357 |
FFLUSH(f); |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2358 |
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
|
2359 |
} |
2264 | 2360 |
ftruncate(fileno(f), __intVal(newSize)); |
2361 |
RETURN (self); |
|
2362 |
} |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2363 |
} |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2364 |
#endif |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2365 |
%}. |
2331 | 2366 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
2367 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
2368 |
self errorUnsupportedOperation |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2369 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2370 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2371 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2372 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2373 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2374 |
s next:1000 put:$a. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2375 |
s truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2376 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2377 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2378 |
('test' asFilename fileSize) printNL |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2379 |
" |
612 | 2380 |
! ! |
2381 |
||
2382 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
2383 |
||
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2384 |
nextAvailableBytes:count into:anObject startingAt:start |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2385 |
"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
|
2386 |
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
|
2387 |
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
|
2388 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2389 |
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
|
2390 |
is raised if the connection is broken. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2391 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2392 |
Notice, that in contrast to other methods, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2393 |
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
|
2394 |
Thus allowing read of partial blocks. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2395 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2396 |
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
|
2397 |
(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
|
2398 |
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
|
2399 |
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
|
2400 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2401 |
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
|
2402 |
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
|
2403 |
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
|
2404 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2405 |
%{ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2406 |
FILEPOINTER f; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2407 |
int cnt, offs, ret, _buffered; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2408 |
int objSize, nInstVars, nInstBytes; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2409 |
char *cp; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2410 |
char *extPtr; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2411 |
OBJ pos, fp, oClass; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2412 |
int o_offs; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2413 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2414 |
__INST(lastErrorNumber) = nil; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2415 |
if (((fp = __INST(filePointer)) != nil) |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2416 |
&& (__INST(mode) != @symbol(writeonly)) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2417 |
&& __bothSmallInteger(count, start) |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2418 |
) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2419 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2420 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2421 |
cnt = __intVal(count); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2422 |
offs = __intVal(start) - 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2423 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2424 |
oClass = __Class(anObject); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2425 |
if (oClass == ExternalBytes) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2426 |
OBJ sz; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2427 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2428 |
nInstBytes = 0; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2429 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2430 |
sz = __externalBytesSize(anObject); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2431 |
if (__isSmallInteger(sz)) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2432 |
objSize = __intVal(sz); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2433 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2434 |
objSize = 0; /* unknown */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2435 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2436 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2437 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2438 |
case BYTEARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2439 |
case WORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2440 |
case LONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2441 |
case SWORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2442 |
case SLONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2443 |
case FLOATARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2444 |
case DOUBLEARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2445 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2446 |
default: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2447 |
goto bad; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2448 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2449 |
extPtr = (char *)0; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2450 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2451 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2452 |
objSize = __Size(anObject) - nInstBytes; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2453 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2454 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2455 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2456 |
_buffered = (__INST(buffered) == true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2457 |
if (_buffered) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2458 |
__READING__(f); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2459 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2460 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2461 |
if (extPtr) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2462 |
__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2463 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2464 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2465 |
* on interrupt, anObject may be moved to another location. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2466 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2467 |
* to get a new address. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2468 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2469 |
offs += nInstBytes; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2470 |
__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2471 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2472 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2473 |
pos = __INST(position); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2474 |
if (pos != nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2475 |
__INST(position) = __MKSMALLINT(__intVal(pos) + ret); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2476 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2477 |
RETURN (__MKSMALLINT(ret)); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2478 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2479 |
if (ret == 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2480 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2481 |
} else /* ret < 0 */ { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2482 |
__INST(position) = nil; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2483 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2484 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2485 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2486 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2487 |
bad: ; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2488 |
%}. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2489 |
(hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2490 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2491 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2492 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2493 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2494 |
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
|
2495 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2496 |
^ self primitiveFailed |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2497 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2498 |
|
612 | 2499 |
nextByte |
2500 |
"read the next byte and return it as an Integer; return nil on error. |
|
2501 |
This is allowed in both text and binary modes, always returning the |
|
2502 |
bytes binary value as an integer in 0..255." |
|
2503 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2504 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2505 |
FILEPOINTER f; |
612 | 2506 |
unsigned char byte; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2507 |
int ret, _buffered; |
612 | 2508 |
OBJ fp; |
2509 |
||
1133 | 2510 |
__INST(lastErrorNumber) = nil; |
2511 |
if (((fp = __INST(filePointer)) != nil) |
|
2512 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
2264 | 2513 |
f = __FILEVal(fp); |
2514 |
||
2515 |
_buffered = (__INST(buffered) == true); |
|
2516 |
if (_buffered) { |
|
2517 |
__READING__(f) |
|
2518 |
} |
|
2519 |
__READBYTE__(ret, f, &byte, _buffered); |
|
2520 |
if (ret > 0) { |
|
2521 |
if (__INST(position) != nil) |
|
2522 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); |
|
2523 |
RETURN (__MKSMALLINT(byte)); |
|
2524 |
} |
|
2525 |
||
2526 |
if (ret == 0) { |
|
2527 |
__INST(hitEOF) = true; |
|
2528 |
} else /* ret < 0 */ { |
|
2529 |
__INST(position) = nil; |
|
2530 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2531 |
} |
|
612 | 2532 |
} |
2533 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2534 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2535 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2536 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2537 |
^ self errorWriteOnly |
|
2538 |
! |
|
2539 |
||
2540 |
nextBytes:count into:anObject startingAt:start |
|
2541 |
"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
|
2542 |
bytes read or the number of bytes read, if EOF is encountered before. |
612 | 2543 |
If the receiver is some socket/pipe-like stream, an exception |
2544 |
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
|
2545 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2546 |
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
|
2547 |
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
|
2548 |
to only read whats there. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
2549 |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2550 |
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
|
2551 |
this does NOT return nil on EOF, but the actual count. |
612 | 2552 |
Thus allowing read of partial blocks. |
2553 |
||
2554 |
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
|
2555 |
(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
|
2556 |
or an externalBytes object (with known size). |
612 | 2557 |
If anObject is a string or byteArray and reused, this provides the |
2558 |
fastest possible physical I/O (since no new objects are allocated). |
|
2559 |
||
2560 |
Use with care - non object oriented I/O. |
|
2561 |
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
|
2562 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2563 |
since it does not care for byte order or float representation." |
612 | 2564 |
|
2565 |
%{ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2566 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2567 |
int cnt, offs, ret, _buffered; |
612 | 2568 |
int objSize, nInstVars, nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2569 |
char *extPtr; |
612 | 2570 |
OBJ pos, fp, oClass; |
2571 |
||
1133 | 2572 |
__INST(lastErrorNumber) = nil; |
2573 |
if (((fp = __INST(filePointer)) != nil) |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2574 |
&& (__INST(mode) != @symbol(writeonly)) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2575 |
&& __bothSmallInteger(count, start) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2576 |
) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2577 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2578 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2579 |
cnt = __intVal(count); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2580 |
offs = __intVal(start) - 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2581 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2582 |
oClass = __Class(anObject); |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2583 |
if (oClass == ExternalBytes) { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2584 |
OBJ sz; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2585 |
|
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2586 |
nInstBytes = 0; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2587 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2588 |
sz = __externalBytesSize(anObject); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2589 |
if (__isSmallInteger(sz)) { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2590 |
objSize = __intVal(sz); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2591 |
} else { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2592 |
objSize = 0; /* unknown */ |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2593 |
} |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2594 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2595 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2596 |
case BYTEARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2597 |
case WORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2598 |
case LONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2599 |
case SWORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2600 |
case SLONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2601 |
case FLOATARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2602 |
case DOUBLEARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2603 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2604 |
default: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2605 |
goto bad; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2606 |
} |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2607 |
extPtr = (char *)0; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2608 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2609 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2610 |
objSize = __Size(anObject) - nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2611 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2612 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2613 |
_buffered = (__INST(buffered) == true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2614 |
if (_buffered) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2615 |
__READING__(f); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2616 |
} |
2861 | 2617 |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2618 |
if (extPtr) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2619 |
__READBYTES__(ret, f, extPtr+offs, cnt, _buffered); |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2620 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2621 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2622 |
* on interrupt, anObject may be moved to another location. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2623 |
* 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
|
2624 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2625 |
offs += nInstBytes; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2626 |
__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
|
2627 |
} |
2861 | 2628 |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2629 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2630 |
pos = __INST(position); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2631 |
if (pos != nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2632 |
__INST(position) = __MKSMALLINT(__intVal(pos) + ret); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2633 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2634 |
RETURN (__MKSMALLINT(ret)); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2635 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2636 |
if (ret == 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2637 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2638 |
} else /* ret < 0 */ { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2639 |
__INST(position) = nil; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2640 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2641 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2642 |
} |
612 | 2643 |
} |
2644 |
bad: ; |
|
2645 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2646 |
(hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0]. |
612 | 2647 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2648 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2649 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2650 |
" |
|
2651 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
2652 |
" |
|
2653 |
^ self primitiveFailed |
|
92 | 2654 |
! |
2655 |
||
612 | 2656 |
nextLong |
2657 |
"Read four bytes (msb-first) and return the value as a 32-bit signed Integer. |
|
2658 |
The returned value may be a LargeInteger. |
|
2659 |
(msb-first for compatibility with other smalltalks)" |
|
2660 |
||
2661 |
^ self nextUnsignedLongMSB:true |
|
2662 |
! |
|
2663 |
||
2664 |
nextLongMSB:msbFlag |
|
2665 |
"Read four bytes and return the value as a 32-bit signed Integer, |
|
2666 |
which may be a LargeInteger. |
|
2667 |
If msbFlag is true, value is read with most-significant byte first, |
|
2668 |
otherwise least-significant byte comes first. |
|
2669 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
2670 |
Works in both binary and text modes." |
|
2671 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2672 |
%{ |
612 | 2673 |
OBJ fp; |
2674 |
||
1133 | 2675 |
__INST(lastErrorNumber) = nil; |
2676 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 2677 |
&& (__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
|
2678 |
) { |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2679 |
FILEPOINTER f; |
2264 | 2680 |
int ret; |
2681 |
int value; |
|
2682 |
char buffer[4]; |
|
2683 |
||
2684 |
f = __FILEVal(fp); |
|
2685 |
__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true); |
|
2686 |
||
2687 |
if (ret == 4) { |
|
2688 |
if (__INST(position) != nil) { |
|
2689 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4); |
|
2690 |
} |
|
2691 |
if (msbFlag == true) { |
|
2692 |
value = (buffer[0] & 0xFF); |
|
2693 |
value = (value << 8) | (buffer[1] & 0xFF); |
|
2694 |
value = (value << 8) | (buffer[2] & 0xFF); |
|
2695 |
value = (value << 8) | (buffer[3] & 0xFF); |
|
2696 |
} else { |
|
2697 |
value = (buffer[3] & 0xFF); |
|
2698 |
value = (value << 8) | (buffer[2] & 0xFF); |
|
2699 |
value = (value << 8) | (buffer[1] & 0xFF); |
|
2700 |
value = (value << 8) | (buffer[0] & 0xFF); |
|
2701 |
} |
|
2702 |
if ((value >= _MIN_INT) && (value <= _MAX_INT)) { |
|
2703 |
RETURN ( __MKSMALLINT(value)); |
|
2704 |
} |
|
2705 |
RETURN ( __MKLARGEINT(value) ); |
|
2706 |
} |
|
2707 |
||
2708 |
if (ret < 0) { |
|
2709 |
__INST(position) = nil; |
|
2710 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2711 |
} else /* ret == 0 */ { |
|
2712 |
__INST(hitEOF) = true; |
|
2713 |
} |
|
612 | 2714 |
} |
2715 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2716 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2717 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2718 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2719 |
^ self readError. |
|
1079 | 2720 |
|
362 | 2721 |
! |
2722 |
||
612 | 2723 |
nextShortMSB:msbFlag |
2724 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
2725 |
If msbFlag is true, value is read with most-significant byte first, |
|
2726 |
otherwise least-significant byte comes first. |
|
2727 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
2728 |
Works in both binary and text modes." |
|
2729 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2730 |
%{ |
612 | 2731 |
OBJ fp; |
2732 |
||
1133 | 2733 |
__INST(lastErrorNumber) = nil; |
2734 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 2735 |
&& (__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
|
2736 |
) { |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2737 |
FILEPOINTER f; |
2264 | 2738 |
int ret; |
2739 |
short value; |
|
2740 |
char buffer[2]; |
|
2741 |
||
2742 |
f = __FILEVal(fp); |
|
2743 |
__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true); |
|
2744 |
||
2745 |
if (ret == 2) { |
|
2746 |
if (__INST(position) != nil) { |
|
2747 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2); |
|
2748 |
} |
|
2749 |
if (msbFlag == true) { |
|
2750 |
value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF); |
|
2751 |
} else { |
|
2752 |
value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF); |
|
2753 |
} |
|
2754 |
RETURN (__MKSMALLINT(value)); |
|
2755 |
} |
|
2756 |
||
2757 |
if (ret < 0) { |
|
2758 |
__INST(position) = nil; |
|
2759 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2760 |
} else /* ret == 0 */ { |
|
2761 |
__INST(hitEOF) = true; |
|
2762 |
} |
|
612 | 2763 |
} |
2764 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2765 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2766 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2767 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2768 |
^ self readError. |
|
2769 |
! |
|
2770 |
||
2771 |
nextUnsignedLongMSB:msbFlag |
|
2772 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
|
2773 |
a LargeInteger. |
|
2774 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
2775 |
least-significant byte comes first. |
|
2776 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
2777 |
Works in both binary and text modes." |
|
2778 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2779 |
%{ |
612 | 2780 |
OBJ fp; |
2781 |
||
1133 | 2782 |
__INST(lastErrorNumber) = nil; |
2783 |
if (((fp = __INST(filePointer)) != nil) |
|
3456
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2784 |
&& (__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
|
2785 |
) { |
3456
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2786 |
FILEPOINTER f; |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2787 |
int ret; |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2788 |
unsigned INT value; |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2789 |
unsigned char buffer[4]; |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2790 |
|
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2791 |
f = __FILEVal(fp); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2792 |
__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2793 |
|
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2794 |
if (ret == 4) { |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2795 |
if (__INST(position) != nil) { |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2796 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2797 |
} |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2798 |
if (msbFlag == true) { |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2799 |
value = (buffer[0] & 0xFF); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2800 |
value = (value << 8) | (buffer[1] & 0xFF); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2801 |
value = (value << 8) | (buffer[2] & 0xFF); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2802 |
value = (value << 8) | (buffer[3] & 0xFF); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2803 |
} else { |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2804 |
value = (buffer[3] & 0xFF); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2805 |
value = (value << 8) | (buffer[2] & 0xFF); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2806 |
value = (value << 8) | (buffer[1] & 0xFF); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2807 |
value = (value << 8) | (buffer[0] & 0xFF); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2808 |
} |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2809 |
#ifdef alpha64 |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2810 |
value &= 0xFFFFFFFF; |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2811 |
#endif |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2812 |
if (value <= _MAX_INT) { |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2813 |
RETURN ( __MKSMALLINT(value)); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2814 |
} |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2815 |
RETURN ( __MKULARGEINT(value) ); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2816 |
} |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2817 |
|
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2818 |
if (ret < 0) { |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2819 |
__INST(position) = nil; |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2820 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2821 |
} else /* ret == 0 */ { |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2822 |
__INST(hitEOF) = true; |
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
2823 |
} |
612 | 2824 |
} |
2825 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2826 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2827 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2828 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2829 |
^ self readError. |
|
2830 |
! |
|
2831 |
||
2832 |
nextUnsignedShortMSB:msbFlag |
|
2833 |
"Read two bytes and return the value as a 16-bit unsigned Integer. |
|
1079 | 2834 |
If msbFlag is true, value is read with most-significant byte first, |
2835 |
otherwise least-significant byte comes first. |
|
612 | 2836 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
2837 |
Works in both binary and text modes." |
|
2838 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2839 |
%{ |
612 | 2840 |
OBJ fp; |
2841 |
||
1133 | 2842 |
__INST(lastErrorNumber) = nil; |
2843 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 2844 |
&& (__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
|
2845 |
) { |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2846 |
FILEPOINTER f; |
2264 | 2847 |
int ret; |
2848 |
unsigned int value; |
|
2849 |
char buffer[2]; |
|
2850 |
||
2851 |
f = __FILEVal(fp); |
|
2852 |
__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true); |
|
2853 |
||
2854 |
if (ret == 2) { |
|
2855 |
if (__INST(position) != nil) { |
|
2856 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2); |
|
2857 |
} |
|
2858 |
if (msbFlag == true) { |
|
2859 |
value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF); |
|
2860 |
} else { |
|
2861 |
value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF); |
|
2862 |
} |
|
2863 |
RETURN (__MKSMALLINT(value)); |
|
2864 |
} |
|
2865 |
||
2866 |
if (ret < 0) { |
|
2867 |
__INST(position) = nil; |
|
2868 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
2869 |
} else /* ret == 0 */ { |
|
2870 |
__INST(hitEOF) = true; |
|
2871 |
} |
|
612 | 2872 |
} |
2873 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
2874 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 2875 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2876 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2877 |
^ self readError. |
|
2878 |
! |
|
2879 |
||
2880 |
nextWord |
|
2881 |
"in text-mode: |
|
2264 | 2882 |
read the alphaNumeric next word (i.e. up to non letter-or-digit). |
2883 |
return a string containing those characters. |
|
612 | 2884 |
in binary-mode: |
2264 | 2885 |
read two bytes (msb-first) and return the value as a 16-bit |
2886 |
unsigned Integer (for compatibility with other smalltalks)" |
|
612 | 2887 |
|
2888 |
binary ifTrue:[ |
|
2264 | 2889 |
^ self nextUnsignedShortMSB:true |
92 | 2890 |
]. |
612 | 2891 |
^ self nextAlphaNumericWord |
2892 |
! ! |
|
2893 |
||
2894 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
2895 |
||
2896 |
nextPutByte:aByteValue |
|
2897 |
"write a byte. |
|
2898 |
Works in both binary and text modes." |
|
2899 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2900 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2901 |
FILEPOINTER f; |
612 | 2902 |
char c; |
2903 |
OBJ pos, fp; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2904 |
int cnt, _buffered; |
612 | 2905 |
|
1133 | 2906 |
__INST(lastErrorNumber) = nil; |
2907 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 2908 |
&& (__INST(mode) != @symbol(readonly)) |
2909 |
&& __isSmallInteger(aByteValue) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2910 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2911 |
) { |
2264 | 2912 |
c = __intVal(aByteValue); |
2913 |
f = __FILEVal(fp); |
|
2914 |
if (_buffered = (__INST(buffered) == true)) { |
|
2915 |
__WRITING__(f) |
|
2916 |
} |
|
2917 |
__WRITEBYTE__(cnt, f, &c, _buffered); |
|
2918 |
if (cnt == 1) { |
|
2919 |
pos = __INST(position); |
|
2920 |
if (pos != nil) |
|
2921 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
|
2922 |
RETURN (self); |
|
2923 |
} |
|
2924 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 2925 |
} |
2926 |
%}. |
|
2331 | 2927 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
2928 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
2929 |
self writeError. |
|
612 | 2930 |
! |
2931 |
||
2932 |
nextPutBytes:count from:anObject startingAt:start |
|
2933 |
"write count bytes from an object starting at index start. |
|
2934 |
return the number of bytes written - which could be 0. |
|
2935 |
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
|
2936 |
(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
|
2937 |
or an externalBytes object (with known size). |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2938 |
|
612 | 2939 |
Use with care - non object oriented i/o. |
2940 |
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
|
2941 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2942 |
since it does not care for byte order or float representation." |
612 | 2943 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2944 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2945 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2946 |
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
|
2947 |
int objSize, nInstVars, nInstBytes, _buffered; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2948 |
char *extPtr; |
612 | 2949 |
OBJ oClass, pos, fp; |
2950 |
||
1133 | 2951 |
__INST(lastErrorNumber) = nil; |
2952 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 2953 |
&& (__INST(mode) != @symbol(readonly)) |
2954 |
&& __bothSmallInteger(count, start) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2955 |
) { |
2264 | 2956 |
len = __intVal(count); |
2957 |
offs = __intVal(start) - 1; |
|
2958 |
f = __FILEVal(fp); |
|
2959 |
||
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2960 |
oClass = __Class(anObject); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2961 |
if (oClass == ExternalBytes) { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2962 |
OBJ sz; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2963 |
|
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2964 |
nInstBytes = 0; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2965 |
extPtr = (char *)__externalBytesAddress(anObject); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2966 |
sz = __externalBytesSize(anObject); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2967 |
if (__isSmallInteger(sz)) { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2968 |
objSize = __intVal(sz); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2969 |
} else { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2970 |
objSize = 0; /* unknown */ |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2971 |
} |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2972 |
} else { |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2973 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2974 |
case BYTEARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2975 |
case WORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2976 |
case LONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2977 |
case SWORDARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2978 |
case SLONGARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2979 |
case FLOATARRAY: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2980 |
case DOUBLEARRAY: |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2981 |
break; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2982 |
default: |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2983 |
goto bad; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2984 |
} |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2985 |
extPtr = (char *)0; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2986 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2987 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2988 |
objSize = __Size(anObject) - nInstBytes; |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2989 |
} |
2264 | 2990 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
2991 |
if (_buffered = (__INST(buffered) == true)) { |
|
2992 |
__WRITING__(f) |
|
2993 |
} |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2994 |
|
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2995 |
if (extPtr) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2996 |
__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered); |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
2997 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2998 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2999 |
* on interrupt, anObject may be moved to another location. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3000 |
* 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
|
3001 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3002 |
offs += nInstBytes; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3003 |
__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
|
3004 |
} |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3005 |
|
2264 | 3006 |
if (cnt >= 0) { |
3007 |
pos = __INST(position); |
|
3008 |
if (pos != nil) |
|
3009 |
__INST(position) = __MKSMALLINT(__intVal(pos) + cnt); |
|
3010 |
RETURN ( __MKSMALLINT(cnt) ); |
|
3011 |
} |
|
3012 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3013 |
} |
|
612 | 3014 |
} |
3015 |
bad: ; |
|
3016 |
%}. |
|
3017 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
3018 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3019 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
3020 |
^ self primitiveFailed |
|
3021 |
! |
|
3022 |
||
3023 |
nextPutLong:aNumber MSB:msbFlag |
|
3024 |
"Write the argument, aNumber as a long (four bytes). If msbFlag is |
|
3025 |
true, data is written most-significant byte first; otherwise least |
|
3026 |
first. |
|
3027 |
Works in both binary and text modes." |
|
3028 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3029 |
%{ |
612 | 3030 |
int num; |
3031 |
char bytes[4]; |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3032 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3033 |
int cnt, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3034 |
OBJ fp, pos; |
612 | 3035 |
|
1133 | 3036 |
__INST(lastErrorNumber) = nil; |
3037 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3038 |
&& (__INST(mode) != @symbol(readonly)) |
3039 |
&& __isSmallInteger(aNumber) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3040 |
) { |
2264 | 3041 |
num = __intVal(aNumber); |
3042 |
if (msbFlag == true) { |
|
3043 |
bytes[0] = (num >> 24) & 0xFF; |
|
3044 |
bytes[1] = (num >> 16) & 0xFF; |
|
3045 |
bytes[2] = (num >> 8) & 0xFF; |
|
3046 |
bytes[3] = num & 0xFF; |
|
3047 |
} else { |
|
3048 |
bytes[3] = (num >> 24) & 0xFF; |
|
3049 |
bytes[2] = (num >> 16) & 0xFF; |
|
3050 |
bytes[1] = (num >> 8) & 0xFF; |
|
3051 |
bytes[0] = num & 0xFF; |
|
3052 |
} |
|
3053 |
||
3054 |
f = __FILEVal(fp); |
|
3055 |
if (_buffered = (__INST(buffered) == true)) { |
|
3056 |
__WRITING__(f) |
|
3057 |
} |
|
3058 |
__WRITEBYTES__(cnt, f, bytes, 4, _buffered); |
|
3059 |
||
3060 |
if (cnt == 4) { |
|
3061 |
if ((pos = __INST(position)) != nil) { |
|
3062 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 4); |
|
3063 |
} |
|
3064 |
RETURN ( self ); |
|
3065 |
} |
|
3066 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 3067 |
} |
3068 |
%}. |
|
2331 | 3069 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
3070 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
3071 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
|
612 | 3072 |
|
3073 |
aNumber isInteger ifTrue:[ |
|
2331 | 3074 |
^ super nextPutLong:aNumber MSB:msbFlag |
92 | 3075 |
]. |
612 | 3076 |
self argumentMustBeInteger |
3077 |
! |
|
3078 |
||
3079 |
nextPutShort:aNumber MSB:msbFlag |
|
3080 |
"Write the argument, aNumber as a short (two bytes). If msbFlag is |
|
3081 |
true, data is written most-significant byte first; otherwise least |
|
3082 |
first. |
|
3083 |
Works in both binary and text modes." |
|
3084 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3085 |
%{ |
612 | 3086 |
int num; |
3087 |
char bytes[2]; |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3088 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3089 |
int cnt, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3090 |
OBJ fp, pos; |
612 | 3091 |
|
1133 | 3092 |
__INST(lastErrorNumber) = nil; |
3093 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3094 |
&& (__INST(mode) != @symbol(readonly)) |
3095 |
&& __isSmallInteger(aNumber) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3096 |
) { |
2264 | 3097 |
num = __intVal(aNumber); |
3098 |
if (msbFlag == true) { |
|
3099 |
bytes[0] = (num >> 8) & 0xFF; |
|
3100 |
bytes[1] = num & 0xFF; |
|
3101 |
} else { |
|
3102 |
bytes[1] = (num >> 8) & 0xFF; |
|
3103 |
bytes[0] = num & 0xFF; |
|
3104 |
} |
|
3105 |
||
3106 |
f = __FILEVal(fp); |
|
3107 |
if (_buffered = (__INST(buffered) == true)) { |
|
3108 |
__WRITING__(f) |
|
3109 |
} |
|
3110 |
__WRITEBYTES__(cnt, f, bytes, 2, _buffered); |
|
3111 |
||
3112 |
if (cnt == 2) { |
|
3113 |
if ((pos = __INST(position)) != nil) { |
|
3114 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 2); |
|
3115 |
} |
|
3116 |
RETURN ( self ); |
|
3117 |
} |
|
3118 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 3119 |
} |
3120 |
%}. |
|
2331 | 3121 |
lastErrorNumber notNil ifTrue:[^ self writeError. ^ self]. |
3122 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
3123 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
612 | 3124 |
self argumentMustBeInteger |
10 | 3125 |
! ! |
612 | 3126 |
|
3127 |
!ExternalStream methodsFor:'private'! |
|
3128 |
||
3129 |
clearEOF |
|
3130 |
hitEOF := false |
|
3131 |
! |
|
3132 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3133 |
connectTo:aFileDescriptor withMode:openmode |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3134 |
"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
|
3135 |
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
|
3136 |
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
|
3137 |
a Stream object. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3138 |
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
|
3139 |
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
|
3140 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3141 |
|retVal| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3142 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3143 |
filePointer notNil ifTrue:[^ self errorOpen]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3144 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3145 |
FILEPOINTER f; |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3146 |
OBJ fp; |
2765 | 3147 |
FILE *fdopen(); |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3148 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3149 |
if (__isSmallInteger(aFileDescriptor) |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3150 |
&& (__qClass(openmode)== @global(String))) { |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3151 |
f = (FILEPOINTER) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode)); |
2264 | 3152 |
if (f == NULL) { |
3153 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3154 |
__INST(position) = nil; |
|
3155 |
} else { |
|
3420 | 3156 |
__INST(filePointer) = fp = __MKFILEPOINTER(f); __STORE(self, fp); |
2264 | 3157 |
__INST(position) = __MKSMALLINT(1); |
3158 |
retVal = self; |
|
3159 |
} |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3160 |
} |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3161 |
%}. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3162 |
retVal notNil ifTrue:[ |
2264 | 3163 |
buffered := true. "default is buffered" |
3164 |
Lobby register:self |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3165 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3166 |
lastErrorNumber notNil ifTrue:[ |
2264 | 3167 |
" |
3168 |
the open failed for some reason ... |
|
3169 |
" |
|
3170 |
^ self openError |
|
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3171 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3172 |
^ retVal |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3173 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
3174 |
|
2963 | 3175 |
open:aPath withMode:mode |
3176 |
"low level open; opens the file/device and sets the filePointer instance |
|
3177 |
variable. Careful: this does not care for any other state." |
|
3178 |
||
3179 |
|ok| |
|
3180 |
||
3181 |
ok := false. |
|
3182 |
%{ |
|
3183 |
FILE *f; |
|
3184 |
OBJ fp; |
|
3185 |
||
3186 |
if (__isString(aPath)) { |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3187 |
__BEGIN_INTERRUPTABLE__ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3188 |
do { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3189 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(mode)); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3190 |
} while ((f == NULL) && (errno == EINTR)); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3191 |
__END_INTERRUPTABLE__ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3192 |
if (f == NULL) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3193 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3194 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3195 |
__INST(filePointer) = fp = __MKFILEPOINTER(f); __STORE(self, fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3196 |
ok = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3197 |
} |
2963 | 3198 |
} |
3199 |
%}. |
|
3200 |
ok ifFalse:[ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3201 |
" |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3202 |
the open failed for some reason ... |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3203 |
" |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3204 |
^ self openError |
2963 | 3205 |
]. |
3206 |
Lobby register:self. |
|
3207 |
! |
|
3208 |
||
612 | 3209 |
reOpen |
3210 |
"sent after snapin to reopen streams. |
|
3211 |
cannot reopen here since I am abstract and have no device knowledge" |
|
3212 |
||
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
3213 |
self class name errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR. |
612 | 3214 |
filePointer := nil. |
3215 |
Lobby unregister:self. |
|
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
3216 |
|
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
3217 |
"Modified: 10.1.1997 / 17:50:44 / cg" |
612 | 3218 |
! |
3219 |
||
3220 |
setLastError:aNumber |
|
3221 |
lastErrorNumber := aNumber |
|
3222 |
! ! |
|
3223 |
||
3224 |
!ExternalStream methodsFor:'queries'! |
|
3225 |
||
3226 |
isBinary |
|
3227 |
"return true, if the stream is in binary (as opposed to text-) mode. |
|
3228 |
The default when created is false." |
|
3229 |
||
3230 |
^ binary |
|
3231 |
! |
|
3232 |
||
3233 |
isExternalStream |
|
3234 |
"return true, if the receiver is some kind of externalStream; |
|
3235 |
true is returned here - the method redefined from Object." |
|
3236 |
||
3237 |
^ true |
|
3238 |
! |
|
3239 |
||
3240 |
isReadable |
|
3241 |
"return true, if this stream can be read from" |
|
3242 |
||
3243 |
^ (mode ~~ #writeonly) |
|
3244 |
! |
|
3245 |
||
3246 |
isWritable |
|
3247 |
"return true, if this stream can be written to" |
|
3248 |
||
3249 |
^ (mode ~~ #readonly) |
|
3250 |
! ! |
|
3251 |
||
3252 |
!ExternalStream methodsFor:'reading'! |
|
3253 |
||
3254 |
next |
|
3255 |
"return the next element; advance read position. |
|
3256 |
In binary mode, an integer is returned, otherwise a character. |
|
3257 |
If there are no more elements, nil is returned." |
|
1 | 3258 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3259 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3260 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3261 |
int ret, _buffered; |
612 | 3262 |
OBJ pos, fp; |
3263 |
unsigned char ch; |
|
3264 |
||
1133 | 3265 |
__INST(lastErrorNumber) = nil; |
3266 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3267 |
&& (__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
|
3268 |
) { |
2264 | 3269 |
f = __FILEVal(fp); |
3270 |
||
3271 |
_buffered = (__INST(buffered) == true); |
|
3272 |
if (_buffered) { |
|
3273 |
__READING__(f) |
|
3274 |
} |
|
3275 |
__READBYTE__(ret, f, &ch, _buffered); |
|
3276 |
||
3277 |
if (ret > 0) { |
|
3278 |
pos = __INST(position); |
|
3279 |
if (__isSmallInteger(pos)) { |
|
3280 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
|
3281 |
} else { |
|
3282 |
__INST(position) = nil; |
|
3283 |
} |
|
3284 |
if (__INST(binary) == true) { |
|
3285 |
RETURN ( __MKSMALLINT(ch) ); |
|
3286 |
} |
|
3287 |
RETURN ( __MKCHARACTER(ch) ); |
|
3288 |
} |
|
3289 |
||
3290 |
__INST(position) = nil; |
|
3291 |
if (ret < 0) { |
|
3292 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3293 |
} else /* ret == 0 */ { |
|
3294 |
__INST(hitEOF) = true; |
|
3295 |
} |
|
612 | 3296 |
} |
3297 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3298 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3299 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3300 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2331 | 3301 |
^ self errorWriteOnly |
612 | 3302 |
! |
3303 |
||
3304 |
next:count |
|
3305 |
"return the next count elements of the stream as a collection. |
|
3306 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
3307 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3308 |
|coll nRead| |
612 | 3309 |
|
3310 |
binary ifTrue:[ |
|
2264 | 3311 |
coll := ByteArray uninitializedNew:count |
612 | 3312 |
] ifFalse:[ |
2264 | 3313 |
coll := String new:count |
612 | 3314 |
]. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3315 |
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
|
3316 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3317 |
"/ for readStream protocol compatibility, |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3318 |
"/ we must raise an exception here. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3319 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3320 |
nRead < count ifTrue:[ |
2264 | 3321 |
^ self pastEnd |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3322 |
]. |
612 | 3323 |
^ coll |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3324 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3325 |
"Modified: 11.1.1997 / 17:44:17 / cg" |
612 | 3326 |
! |
3327 |
||
3328 |
peek |
|
3329 |
"return the element to be read next without advancing read position. |
|
3330 |
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
|
3331 |
If there are no more elements, nil is returned." |
612 | 3332 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3333 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3334 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3335 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3336 |
int ret, _buffered; |
216 | 3337 |
OBJ fp; |
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3338 |
OBJ ra; |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3339 |
|
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3340 |
if ((ra = __INST(readAhead)) != nil) { |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3341 |
if (__INST(binary) == true) { |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3342 |
RETURN ( ra ); |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3343 |
} |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3344 |
c = __intVal(ra); |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
3345 |
RETURN ( __MKCHARACTER(c) ); |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
3346 |
} |
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
3347 |
|
1133 | 3348 |
__INST(lastErrorNumber) = nil; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3349 |
|
1133 | 3350 |
if (((fp = __INST(filePointer)) != nil) |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3351 |
&& (__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
|
3352 |
) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3353 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3354 |
_buffered = (__INST(buffered) == true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3355 |
if (_buffered) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3356 |
__READING__(f) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3357 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3358 |
__READBYTE__(ret, f, &c, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3359 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3360 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3361 |
__UNGETC__(c, f, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3362 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3363 |
if (__INST(binary) == true) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3364 |
RETURN ( __MKSMALLINT(c) ); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3365 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3366 |
RETURN ( __MKCHARACTER(c) ); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3367 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3368 |
if (ret < 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3369 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3370 |
} else /* ret == 0 */ { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3371 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3372 |
} |
1 | 3373 |
} |
159 | 3374 |
%}. |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3375 |
hitEOF ifTrue:[^ self pastEnd]. |
216 | 3376 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
1 | 3377 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
159 | 3378 |
^ self errorWriteOnly |
1295 | 3379 |
! |
3380 |
||
3381 |
upToEnd |
|
3382 |
"return a collection of the elements up-to the end. |
|
3383 |
Return nil if the stream-end is reached before." |
|
3384 |
||
3385 |
|answerStream ch| |
|
3386 |
||
3387 |
answerStream := WriteStream on:(self contentsSpecies new). |
|
3388 |
[self atEnd] whileFalse:[ |
|
2264 | 3389 |
ch := self next. |
3390 |
ch notNil ifTrue:[ |
|
3391 |
answerStream nextPut:ch |
|
3392 |
] |
|
1295 | 3393 |
]. |
3394 |
^ answerStream contents |
|
3395 |
||
3396 |
"Created: 25.4.1996 / 14:40:31 / cg" |
|
612 | 3397 |
! ! |
3398 |
||
3399 |
!ExternalStream methodsFor:'reimplemented for speed'! |
|
159 | 3400 |
|
3401 |
nextAlphaNumericWord |
|
379 | 3402 |
"read the next word (i.e. up to non letter-or-digit) after first |
3403 |
skipping any whiteSpace. |
|
3404 |
Return a string containing those characters. |
|
3405 |
There is a limit of 1023 characters in the word - if longer, |
|
3406 |
it is truncated." |
|
159 | 3407 |
|
3408 |
%{ /* STACK: 2000 */ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3409 |
FILEPOINTER f; |
159 | 3410 |
int len; |
3411 |
char buffer[1024]; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3412 |
unsigned char ch; |
159 | 3413 |
int cnt = 0; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3414 |
int ret, _buffered; |
216 | 3415 |
OBJ fp; |
3416 |
||
1133 | 3417 |
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
|
3418 |
&& (__INST(mode) != @symbol(writeonly)) |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3419 |
) { |
2264 | 3420 |
f = __FILEVal(fp); |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3421 |
_buffered = (__INST(buffered) == true); |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3422 |
if (_buffered) { |
2264 | 3423 |
__READING__(f) |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3424 |
} |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
3425 |
|
2264 | 3426 |
/* |
3427 |
* skip whiteSpace first ... |
|
3428 |
*/ |
|
3429 |
do { |
|
3430 |
__READBYTE__(ret, f, &ch, _buffered); |
|
3431 |
if (ret > 0) |
|
3432 |
cnt++; |
|
3433 |
else |
|
3434 |
break; |
|
3435 |
} while ( |
|
379 | 3436 |
#ifndef NON_ASCII |
2264 | 3437 |
(ch < ' ') || |
379 | 3438 |
#endif |
2264 | 3439 |
(ch == ' ' ) || (ch == '\t') || (ch == '\r') |
3440 |
|| (ch == '\n') || (ch == 0x0b)); |
|
3441 |
||
3442 |
len = 0; |
|
3443 |
while (ret > 0 && |
|
3444 |
(((ch >= 'a') && (ch <= 'z')) || |
|
3445 |
((ch >= 'A') && (ch <= 'Z')) || |
|
3446 |
((ch >= '0') && (ch <= '9'))) |
|
3447 |
) { |
|
3448 |
buffer[len++] = ch; |
|
3449 |
if (len >= (sizeof(buffer)-1)) { |
|
3450 |
/* emergency */ |
|
3451 |
break; |
|
3452 |
} |
|
3453 |
__READBYTE__(ret, f, &ch, _buffered); |
|
3454 |
if (ret > 0) |
|
3455 |
cnt++; |
|
3456 |
else |
|
3457 |
break; |
|
3458 |
} |
|
3459 |
||
3460 |
if (ret <= 0) { |
|
3461 |
if (ret < 0) { |
|
3462 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3463 |
goto err; |
|
3464 |
} |
|
3465 |
else if (ret == 0) |
|
3466 |
__INST(hitEOF) = true; |
|
3467 |
} else { |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3468 |
__UNGETC__(ch, f, _buffered); |
2264 | 3469 |
cnt--; |
3470 |
} |
|
3471 |
||
3472 |
if (__INST(position) != nil) { |
|
3473 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt); |
|
3474 |
} |
|
3475 |
if (len != 0) { |
|
3476 |
buffer[len] = '\0'; |
|
3477 |
RETURN ( __MKSTRING_L(buffer, len) ); |
|
3478 |
} |
|
159 | 3479 |
} |
3480 |
err: ; |
|
3481 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3482 |
hitEOF ifTrue:[^ self pastEnd]. |
159 | 3483 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3484 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3485 |
^ self errorWriteOnly |
|
1 | 3486 |
! |
3487 |
||
3488 |
nextChunk |
|
3489 |
"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
|
3490 |
exclamation mark. Within the chunk, exclamation marks have to be doubled - |
216 | 3491 |
except within primitive code (this exception was added to make it easier |
3492 |
to edit primitive code with external editors). This means, that other |
|
3493 |
Smalltalks cannot always read chunks containing primitive code - but that |
|
3494 |
doesnt really matter, since C-primitives are an ST/X feature anyway. |
|
3495 |
Reimplemented here for more speed." |
|
3496 |
||
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3497 |
|retVal outOfMemory buffer| |
1 | 3498 |
|
159 | 3499 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
3500 |
binary ifTrue:[^ self errorBinary]. |
|
3501 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
216 | 3502 |
|
2854
3c8bf66e4e7d
give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents:
2766
diff
changeset
|
3503 |
%{ /* 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
|
3504 |
/* |
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3505 |
* 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
|
3506 |
* 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
|
3507 |
* 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
|
3508 |
* 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
|
3509 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3510 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3511 |
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
|
3512 |
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
|
3513 |
int ret; |
1823 | 3514 |
unsigned char *bufferPtr = (unsigned char *)0; |
2874
020627074c9e
oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents:
2861
diff
changeset
|
3515 |
unsigned char fastBuffer[8000]; |
1 | 3516 |
REGISTER int index; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3517 |
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
|
3518 |
int atBeginOfLine = 1, inPrimitive = 0; |
2920 | 3519 |
int haveCR = 0, haveNL = 0; |
216 | 3520 |
|
1133 | 3521 |
__INST(lastErrorNumber) = nil; |
3522 |
f = __FILEVal(__INST(filePointer)); |
|
668
73165201a9da
nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
3523 |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3524 |
_buffered = (__INST(buffered) == true); |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3525 |
if (_buffered) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3526 |
__READING__(f) |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3527 |
} |
159 | 3528 |
|
1 | 3529 |
/* |
3530 |
* skip spaces |
|
3531 |
*/ |
|
673
2c3a4a536cd1
oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
3532 |
c = '\n'; |
1 | 3533 |
while (! done) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3534 |
lastC = c; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3535 |
__READBYTE__(ret, f, &c, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3536 |
if (ret <= 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3537 |
goto err; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3538 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3539 |
nread++; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3540 |
atBeginOfLine = 0; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3541 |
switch (c) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3542 |
case '\n': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3543 |
case ' ': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3544 |
case '\t': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3545 |
case '\r': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3546 |
case '\b': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3547 |
case '\014': |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3548 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3549 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3550 |
default: |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3551 |
atBeginOfLine = (lastC == '\n'); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3552 |
done = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3553 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3554 |
} |
1 | 3555 |
} |
3556 |
||
3557 |
/* |
|
3558 |
* read chunk into a buffer |
|
3559 |
*/ |
|
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3560 |
bufferPtr = fastBuffer; fastFlag = 1; |
216 | 3561 |
currSize = sizeof(fastBuffer); |
362 | 3562 |
|
1 | 3563 |
index = 0; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3564 |
for (;;) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3565 |
__READBYTE__(ret, f, &peekC, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3566 |
if ((c == '%') && atBeginOfLine && ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3567 |
if (peekC == '{') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3568 |
inPrimitive = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3569 |
} else if (peekC == '}') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3570 |
inPrimitive = 0; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3571 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3572 |
} else if (c == '!' && !inPrimitive) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3573 |
if (ret > 0 && peekC == '!') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3574 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3575 |
* convert double-! to a single ! |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3576 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3577 |
__READBYTE__(ret, f, &peekC, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3578 |
if (ret > 0) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3579 |
nread++; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3580 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3581 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3582 |
* End of chunk, push back lookahead character |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3583 |
* and leave loop. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3584 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3585 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3586 |
__UNGETC__(peekC, f, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3587 |
} else |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3588 |
ret = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3589 |
break; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3590 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3591 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3592 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3593 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3594 |
* do we have to resize the buffer ? |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3595 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3596 |
if ((index+2) >= currSize) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3597 |
OBJ newBuffer; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3598 |
unsigned char *nbp; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3599 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3600 |
newBuffer = __MKEMPTYSTRING(currSize * 2); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3601 |
if (!fastFlag) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3602 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3603 |
* refetch - buffer could be moved by GC |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3604 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3605 |
bufferPtr = __stringVal(buffer); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3606 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3607 |
if (newBuffer == nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3608 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3609 |
* mhmh - chunk seems to be very big .... |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3610 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3611 |
outOfMemory = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3612 |
goto err; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3613 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3614 |
nbp = __stringVal(newBuffer); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3615 |
bcopy(bufferPtr, nbp, index); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3616 |
bufferPtr = nbp; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3617 |
bufferPtr[index] = '\0'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3618 |
buffer = newBuffer; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3619 |
fastFlag = 0; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3620 |
currSize = currSize * 2; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3621 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3622 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3623 |
if (!fastFlag) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3624 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3625 |
* old buffer may have moved (interrupt while reading) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3626 |
* - refetch pointer |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3627 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3628 |
bufferPtr = __stringVal(buffer); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3629 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3630 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3631 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3632 |
* filter out cr-nl; make it nl |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3633 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3634 |
if (c == '\n') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3635 |
haveNL = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3636 |
if (index > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3637 |
if (bufferPtr[index-1] == '\r') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3638 |
index--; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3639 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3640 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3641 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3642 |
if (c == '\r') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3643 |
haveCR = 1; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3644 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3645 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3646 |
bufferPtr[index++] = c; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3647 |
if (ret <= 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3648 |
if (ret == 0) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3649 |
break; /* End of chunk reached */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3650 |
goto err; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3651 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3652 |
nread++; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3653 |
atBeginOfLine = (c == '\n'); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3654 |
c = peekC; |
1 | 3655 |
} |
92 | 3656 |
|
1 | 3657 |
/* |
2920 | 3658 |
* care for CR-limited files. |
3659 |
* Replace CR's by NL's |
|
3660 |
*/ |
|
3661 |
if (!haveNL && haveCR) { |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3662 |
int i; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3663 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3664 |
for (i=index-1; i>=0; i--) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3665 |
if (bufferPtr[i] == '\r') { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3666 |
bufferPtr[i] = '\n'; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3667 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3668 |
} |
2920 | 3669 |
} |
3670 |
||
3671 |
/* |
|
1 | 3672 |
* 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
|
3673 |
* 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
|
3674 |
* 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
|
3675 |
* fast (C) buffer or from real (ST) buffer. |
1 | 3676 |
*/ |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
3677 |
if (fastFlag) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3678 |
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
|
3679 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3680 |
retVal = __MKSTRING_ST_L(buffer, index); |
216 | 3681 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3682 |
|
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
3683 |
err: ; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3684 |
if (ret <= 0) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3685 |
if (ret == 0) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3686 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3687 |
else /* ret < 0 */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3688 |
__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
|
3689 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3690 |
if (__INST(position) != nil) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3691 |
__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
|
3692 |
} |
159 | 3693 |
%}. |
370 | 3694 |
retVal isNil ifTrue:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3695 |
"/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3696 |
"/ 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
|
3697 |
"/ or if running out of malloc-memory |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3698 |
"/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3699 |
hitEOF ifTrue:[^ self pastEnd]. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3700 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3701 |
outOfMemory == true ifTrue:[ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3702 |
" |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3703 |
buffer memory allocation failed. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3704 |
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
|
3705 |
chunk. (seems to be too big of a chunk ...) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3706 |
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
|
3707 |
" |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3708 |
^ ObjectMemory allocationFailureSignal raise. |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3709 |
] |
216 | 3710 |
]. |
1 | 3711 |
^ retVal |
612 | 3712 |
! |
3713 |
||
3714 |
nextMatchFor:anObject |
|
3715 |
"skip all objects up-to and including anObject, return anObject on success, |
|
3716 |
nil if end-of-file is reached before. The next read operation will return |
|
3717 |
the element after anObject. |
|
3718 |
Only single byte characters are currently supported." |
|
3719 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3720 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3721 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3722 |
int ret, peekValue; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3723 |
char c; |
612 | 3724 |
OBJ fp; |
3725 |
||
1133 | 3726 |
__INST(lastErrorNumber) = nil; |
3727 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3728 |
&& (__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
|
3729 |
) { |
2264 | 3730 |
if ((__INST(binary) == true) && __isSmallInteger(anObject)) { |
3731 |
peekValue = __intVal(anObject) & 0xFF; |
|
3732 |
} else { |
|
3733 |
if ((__INST(binary) != true) && __isCharacter(anObject)) { |
|
3734 |
peekValue = __intVal(_characterVal(anObject)) & 0xFF; |
|
3735 |
} else { |
|
3736 |
peekValue = -1; |
|
3737 |
} |
|
3738 |
} |
|
3739 |
||
3740 |
if (peekValue >= 0) { |
|
3741 |
int _buffered; |
|
3742 |
||
3743 |
__INST(position) = nil; |
|
3744 |
f = __FILEVal(fp); |
|
3745 |
||
3746 |
if (_buffered = (__INST(buffered) == true)) { |
|
3747 |
__READING__(f) |
|
3748 |
} |
|
3749 |
||
3750 |
for (;;) { |
|
3751 |
__READBYTE__(ret, f, &c, _buffered); |
|
3752 |
if (ret <= 0) { |
|
3753 |
if (ret < 0) |
|
3754 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3755 |
else |
|
3756 |
__INST(hitEOF) = true; |
|
3757 |
break; |
|
3758 |
} |
|
3759 |
if (c == peekValue) { |
|
3760 |
RETURN (anObject); |
|
3761 |
} |
|
3762 |
} |
|
3763 |
} |
|
612 | 3764 |
} |
3765 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3766 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3767 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3768 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3769 |
^ super nextMatchFor:anObject |
|
3770 |
! |
|
3771 |
||
3772 |
peekFor:anObject |
|
3773 |
"return true and move past next element, if next == something. |
|
3774 |
Otherwise, stay and return false. False is also returned |
|
3775 |
when EOF is encountered. |
|
3776 |
The argument must be an integer if in binary, a character if in |
|
3777 |
text mode; only single byte characters are currently supported." |
|
3778 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3779 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3780 |
FILEPOINTER f; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
3781 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3782 |
int ret, peekValue, _buffered; |
612 | 3783 |
OBJ fp; |
3784 |
||
1133 | 3785 |
__INST(lastErrorNumber) = nil; |
3786 |
if (((fp = __INST(filePointer)) != nil) |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3787 |
&& (__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
|
3788 |
) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3789 |
if (__INST(binary) == true) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3790 |
if (__isSmallInteger(anObject)) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3791 |
peekValue = __intVal(anObject) & 0xFF; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3792 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3793 |
goto bad; |
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 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3796 |
if (__isCharacter(anObject)) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3797 |
peekValue = __intVal(_characterVal(anObject)) & 0xFF; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3798 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3799 |
goto bad; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3800 |
} |
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 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3803 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3804 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3805 |
_buffered = (__INST(buffered) == true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3806 |
if (_buffered) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3807 |
__READING__(f) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3808 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3809 |
__READBYTE__(ret, f, &c, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3810 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3811 |
if (c == peekValue) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3812 |
OBJ pos; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3813 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3814 |
if ((pos = __INST(position)) != nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3815 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3816 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3817 |
RETURN (true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3818 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3819 |
__UNGETC__(c, f, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3820 |
RETURN (false); |
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 (ret < 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3823 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3824 |
} else /* ret == 0 */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3825 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3826 |
} |
612 | 3827 |
bad: ; |
3828 |
%}. |
|
3829 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3830 |
hitEOF ifTrue:[self pastEnd. ^ false]. |
612 | 3831 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3832 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3833 |
^ super peekFor:anObject |
|
3834 |
! |
|
3835 |
||
3836 |
skipLine |
|
3837 |
"read the next line (characters up to newline) skip only; |
|
3838 |
return nil if EOF reached, self otherwise. |
|
3839 |
Not allowed in binary mode." |
|
3840 |
||
3841 |
%{ /* STACK:2000 */ |
|
3842 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3843 |
FILEPOINTER f; |
612 | 3844 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3845 |
int ret, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3846 |
char c; |
612 | 3847 |
|
1133 | 3848 |
__INST(lastErrorNumber) = nil; |
3849 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3850 |
&& (__INST(mode) != @symbol(writeonly)) |
3851 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3852 |
) { |
2264 | 3853 |
f = __FILEVal(fp); |
3854 |
if (_buffered = (__INST(buffered) == true)) { |
|
3855 |
__READING__(f) |
|
3856 |
} |
|
3857 |
for (;;) { |
|
3858 |
__READBYTE__(ret, f, &c, _buffered); |
|
3859 |
if (ret > 0) { |
|
3860 |
if (c == '\n') |
|
3861 |
RETURN(self) |
|
3862 |
} else |
|
3863 |
break; |
|
3864 |
} |
|
3865 |
if (ret < 0) { |
|
3866 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3867 |
} else /* ret == 0 */ { |
|
3868 |
__INST(hitEOF) = true; |
|
3869 |
} |
|
612 | 3870 |
} |
3871 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3872 |
hitEOF ifTrue:[^ self pastEnd]. |
2331 | 3873 |
lastErrorNumber notNil ifTrue:[self readError. ^ self]. |
3874 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
3875 |
binary ifTrue:[self errorBinary. ^ self]. |
|
3876 |
self errorWriteOnly |
|
612 | 3877 |
! |
3878 |
||
3879 |
skipSeparators |
|
3880 |
"skip all whitespace; next will return next non-white-space character |
|
3881 |
or nil if endOfFile reached. Not allowed in binary mode. |
|
3882 |
- reimplemented for speed" |
|
3883 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3884 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3885 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3886 |
char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3887 |
int ret, _buffered; |
612 | 3888 |
OBJ fp; |
3889 |
||
1133 | 3890 |
__INST(lastErrorNumber) = nil; |
3891 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3892 |
&& (__INST(mode) != @symbol(writeonly)) |
3893 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3894 |
) { |
2264 | 3895 |
f = __FILEVal(fp); |
3896 |
_buffered = (__INST(buffered) == true); |
|
3897 |
if (_buffered) { |
|
3898 |
__READING__(f) |
|
3899 |
} |
|
3900 |
||
3901 |
while (1) { |
|
3902 |
__READBYTE__(ret, f, &c, _buffered); |
|
3903 |
if (ret <= 0) { |
|
3904 |
if (ret < 0) { |
|
3905 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3906 |
} else /* ret == 0 */ { |
|
3907 |
__INST(hitEOF) = true; |
|
3908 |
} |
|
3909 |
break; |
|
3910 |
} |
|
3911 |
switch (c) { |
|
3912 |
case ' ': |
|
3913 |
case '\t': |
|
3914 |
case '\n': |
|
3915 |
case '\r': |
|
3916 |
case '\b': |
|
3917 |
case '\f': |
|
3918 |
break; |
|
3919 |
||
3920 |
default: |
|
3921 |
__UNGETC__(c, f, _buffered); |
|
3922 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
|
3923 |
} |
|
3924 |
} |
|
612 | 3925 |
} |
3926 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3927 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3928 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3929 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3930 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
3931 |
^ self errorBinary. |
|
3932 |
! |
|
3933 |
||
3934 |
skipSeparatorsExceptCR |
|
3935 |
"skip all whitespace but no newlines; |
|
3936 |
next will return next non-white-space character |
|
3937 |
or nil if endOfFile reached. Not allowed in binary mode. |
|
3938 |
- reimplemented for speed" |
|
3939 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3940 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3941 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3942 |
char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
3943 |
int ret, _buffered; |
612 | 3944 |
OBJ fp; |
3945 |
||
1133 | 3946 |
__INST(lastErrorNumber) = nil; |
3947 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 3948 |
&& (__INST(mode) != @symbol(writeonly)) |
3949 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3950 |
) { |
2264 | 3951 |
f = __FILEVal(fp); |
3952 |
_buffered = (__INST(buffered) == true); |
|
3953 |
if (_buffered) { |
|
3954 |
__READING__(f) |
|
3955 |
} |
|
3956 |
while (1) { |
|
3957 |
__READBYTE__(ret, f, &c, _buffered); |
|
3958 |
if (ret <= 0) { |
|
3959 |
if (ret < 0) { |
|
3960 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3961 |
} else /* ret == 0 */ { |
|
3962 |
__INST(hitEOF) = true; |
|
3963 |
} |
|
3964 |
break; |
|
3965 |
} |
|
3966 |
switch (c) { |
|
3967 |
case ' ': |
|
3968 |
case '\t': |
|
3969 |
case '\b': |
|
3970 |
case '\f': |
|
3971 |
break; |
|
3972 |
||
3973 |
default: |
|
3974 |
__UNGETC__(c, f, _buffered); |
|
3975 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
|
3976 |
} |
|
3977 |
} |
|
612 | 3978 |
} |
3979 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3980 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3981 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3982 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3983 |
(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
|
3984 |
^ self errorBinary. |
612 | 3985 |
! |
3986 |
||
3987 |
skipThrough:aCharacter |
|
3988 |
"skip all characters up-to and including aCharacter. Return the receiver if |
|
671 | 3989 |
skip was successful, otherwise (i.e. if not found) return nil. |
612 | 3990 |
The next read operation will return the character after aCharacter. |
3991 |
The argument, aCharacter must be character, or integer when in binary mode. |
|
3992 |
Only single byte characters are currently supported." |
|
3993 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3994 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3995 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3996 |
REGISTER int cSearch; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3997 |
unsigned char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3998 |
int ret, _buffered; |
612 | 3999 |
OBJ fp; |
4000 |
||
1133 | 4001 |
__INST(lastErrorNumber) = nil; |
4002 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4003 |
&& (__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
|
4004 |
) { |
2264 | 4005 |
if (__INST(binary) == true) { |
4006 |
/* searched for object must be a smallInteger */ |
|
4007 |
if (! __isSmallInteger(aCharacter)) goto badArgument; |
|
4008 |
cSearch = __intVal(aCharacter); |
|
4009 |
} else { |
|
4010 |
/* searched for object must be a character */ |
|
4011 |
if (! __isCharacter(aCharacter)) goto badArgument; |
|
4012 |
cSearch = __intVal(_characterVal(aCharacter)); |
|
4013 |
} |
|
4014 |
/* Q: should we just say: "not found" ? */ |
|
4015 |
if ((cSearch < 0) || (cSearch > 255)) goto badArgument; |
|
4016 |
||
4017 |
f = __FILEVal(fp); |
|
4018 |
if (_buffered = (__INST(buffered) == true)) { |
|
4019 |
__READING__(f) |
|
4020 |
} |
|
4021 |
||
4022 |
while (1) { |
|
4023 |
__READBYTE__(ret, f, &c, _buffered); |
|
4024 |
if (ret <= 0) { |
|
4025 |
if (ret < 0) { |
|
4026 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4027 |
} else /* ret == 0 */ { |
|
4028 |
__INST(hitEOF) = true; |
|
4029 |
} |
|
4030 |
break; |
|
4031 |
} |
|
4032 |
if (c == cSearch) { |
|
4033 |
RETURN (self); |
|
4034 |
} |
|
4035 |
} |
|
612 | 4036 |
} |
4037 |
badArgument: ; |
|
4038 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4039 |
hitEOF ifTrue:[^ self pastEnd]. |
2331 | 4040 |
lastErrorNumber notNil ifTrue:[self readError. ^ self]. |
4041 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4042 |
(mode == #writeonly) ifTrue:[self errorWriteOnly. ^ self]. |
|
612 | 4043 |
" |
4044 |
argument must be integer/character in binary mode, |
|
4045 |
character in text mode |
|
4046 |
" |
|
2331 | 4047 |
self error:'invalid argument'. |
612 | 4048 |
|
4049 |
" |
|
4050 |
|s| |
|
4051 |
s := 'Makefile' asFilename readStream. |
|
4052 |
s skipThrough:$=. |
|
4053 |
s next:10 |
|
4054 |
" |
|
4055 |
! |
|
4056 |
||
4057 |
skipToAll:aString |
|
4058 |
"skip for the sequence given by the argument, aCollection; |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4059 |
return nil if not found, self otherwise. |
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4060 |
On a successful match, the next read will return characters of aString." |
612 | 4061 |
|
4062 |
|oldPos| |
|
4063 |
||
4064 |
oldPos := self position. |
|
4065 |
(self skipThroughAll:aString) isNil ifTrue:[ |
|
2264 | 4066 |
" |
4067 |
restore position |
|
4068 |
" |
|
4069 |
self position:oldPos. |
|
4070 |
^ nil |
|
612 | 4071 |
]. |
4072 |
" |
|
4073 |
position before match-string |
|
4074 |
" |
|
4075 |
self position:(self position - aString size). |
|
4076 |
^ self |
|
4077 |
||
4078 |
" |
|
4079 |
|s| |
|
4080 |
s := 'Makefile' asFilename readStream. |
|
4081 |
s skipToAll:'are'. |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4082 |
s next:10 |
612 | 4083 |
" |
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4084 |
|
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
4085 |
"Modified: 26.6.1996 / 09:22:05 / cg" |
1 | 4086 |
! ! |
612 | 4087 |
|
4088 |
!ExternalStream methodsFor:'testing'! |
|
4089 |
||
4090 |
atEnd |
|
4091 |
"return true, if position is at end" |
|
4092 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4093 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4094 |
FILEPOINTER f; |
612 | 4095 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4096 |
char c; |
2861 | 4097 |
int ret, _buffered; |
612 | 4098 |
|
1133 | 4099 |
if (__INST(hitEOF) == true) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4100 |
RETURN (true); |
612 | 4101 |
} |
4102 |
||
1133 | 4103 |
__INST(lastErrorNumber) = nil; |
4104 |
||
4105 |
if ((fp = __INST(filePointer)) != nil) { |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4106 |
f = __FILEVal(fp); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4107 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4108 |
if (_buffered = (__INST(buffered) == true)) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4109 |
__READING__(f); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4110 |
} else { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4111 |
if (__INST(readAhead) != nil) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4112 |
RETURN (false); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4113 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4114 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4115 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4116 |
/* |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4117 |
* read ahead ... |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4118 |
*/ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4119 |
do { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4120 |
__BEGIN_INTERRUPTABLE__ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4121 |
__READBYTE__(ret, f, &c, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4122 |
__END_INTERRUPTABLE__ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4123 |
} while ((ret < 0) && (errno == EINTR)); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4124 |
|
3569 | 4125 |
#if defined(WIN32) && defined(EPIPE) |
4126 |
if (errno == EPIPE) |
|
4127 |
ret = 0; |
|
4128 |
#endif |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4129 |
if (ret > 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4130 |
__UNGETC__(c&0xff, f, _buffered); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4131 |
RETURN (false); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4132 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4133 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4134 |
if (ret == 0) { |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4135 |
__INST(hitEOF) = true; |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4136 |
RETURN (true); |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4137 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4138 |
|
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4139 |
/* ret < 0 */ |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4140 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
612 | 4141 |
} |
4142 |
%}. |
|
4143 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
|
4144 |
^ self errorNotOpen |
|
4145 |
! |
|
4146 |
||
4147 |
canReadWithoutBlocking |
|
4148 |
"return true, if any data is available for reading (i.e. |
|
4149 |
a read operation will not block the smalltalk process), false otherwise." |
|
4150 |
||
4151 |
|fd| |
|
4152 |
||
2986
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
4153 |
readAhead notNil ifTrue:[^ true]. |
612 | 4154 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
4155 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
4156 |
||
4157 |
fd := self fileDescriptor. |
|
4158 |
^ OperatingSystem readCheck:fd |
|
4159 |
||
4160 |
" |
|
4161 |
|pipe| |
|
4162 |
||
4163 |
pipe := PipeStream readingFrom:'(sleep 10; echo hello)'. |
|
4164 |
pipe canReadWithoutBlocking ifTrue:[ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4165 |
Transcript showCR:'data available' |
612 | 4166 |
] ifFalse:[ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4167 |
Transcript showCR:'no data available' |
612 | 4168 |
]. |
4169 |
pipe close |
|
4170 |
" |
|
2986
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
4171 |
|
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
4172 |
"Modified: 25.9.1997 / 13:08:45 / stefan" |
612 | 4173 |
! |
4174 |
||
4175 |
canWriteWithoutBlocking |
|
4176 |
"return true, if data can be written into the stream |
|
4177 |
(i.e. a write operation will not block the smalltalk process)." |
|
4178 |
||
4179 |
|fd| |
|
4180 |
||
4181 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
4182 |
mode == #readonly ifTrue:[^ self errorReadOnly]. |
|
4183 |
||
4184 |
fd := self fileDescriptor. |
|
4185 |
^ OperatingSystem writeCheck:fd |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4186 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4187 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4188 |
numAvailable |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4189 |
"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
|
4190 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4191 |
|fd| |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4192 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4193 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4194 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4195 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4196 |
fd := self fileDescriptor. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4197 |
^ OperatingSystem numAvailableForReadOn:fd. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4198 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4199 |
"/ self atEnd ifTrue:[^ 0]. |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4200 |
"/ self canReadWithoutBlocking ifTrue:[ |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4201 |
"/ ^ 1 |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4202 |
"/ ]. |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
4203 |
"/ ^ 0 |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4204 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
4205 |
"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
|
4206 |
"Modified: / 4.2.1998 / 17:31:11 / cg" |
612 | 4207 |
! ! |
4208 |
||
4209 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
4210 |
||
4211 |
readWait |
|
4212 |
"suspend the current process, until the receiver |
|
4213 |
becomes ready for reading. If data is already available, |
|
4214 |
return immediate. |
|
4215 |
The other threads are not affected by the wait." |
|
4216 |
||
4217 |
self readWaitWithTimeoutMs:nil |
|
4218 |
! |
|
4219 |
||
3016 | 4220 |
readWaitTimeoutMs:timeout |
4221 |
"ST-80 compatibility" |
|
4222 |
^ self readWaitWithTimeoutMs:timeout |
|
4223 |
! |
|
4224 |
||
612 | 4225 |
readWaitWithTimeout:timeout |
4226 |
"suspend the current process, until the receiver |
|
4227 |
becomes ready for reading or a timeout (in seconds) expired. |
|
4228 |
If data is already available, return immediate. |
|
4229 |
Return true if a timeout occured (i.e. false, if data is available). |
|
4230 |
The other threads are not affected by the wait." |
|
4231 |
||
4232 |
^ self readWaitWithTimeoutMs:timeout * 1000 |
|
4233 |
! |
|
4234 |
||
4235 |
readWaitWithTimeoutMs:timeout |
|
4236 |
"suspend the current process, until the receiver |
|
4237 |
becomes ready for reading or a timeout (in milliseconds) expired. |
|
4238 |
If data is already available, return immediate. |
|
4239 |
Return true if a timeout occured (i.e. false, if data is available). |
|
4240 |
The other threads are not affected by the wait." |
|
4241 |
||
4242 |
|fd inputSema hasData wasBlocked| |
|
4243 |
||
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4244 |
readAhead notNil ifTrue:[^ false]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4245 |
|
612 | 4246 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
4247 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
4248 |
||
4249 |
fd := self fileDescriptor. |
|
4250 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
|
4251 |
||
4252 |
wasBlocked := OperatingSystem blockInterrupts. |
|
4253 |
hasData := OperatingSystem readCheck:fd. |
|
4254 |
hasData ifFalse:[ |
|
2264 | 4255 |
inputSema := Semaphore new name:'readWait'. |
4256 |
[ |
|
4257 |
timeout notNil ifTrue:[ |
|
4258 |
Processor signal:inputSema afterMilliseconds:timeout |
|
4259 |
]. |
|
4260 |
Processor signal:inputSema onInput:fd. |
|
4261 |
Processor activeProcess state:#ioWait. |
|
4262 |
inputSema wait. |
|
4263 |
Processor disableSemaphore:inputSema. |
|
4264 |
hasData := OperatingSystem readCheck:fd |
|
4265 |
] valueOnUnwindDo:[ |
|
4266 |
Processor disableSemaphore:inputSema. |
|
4267 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
4268 |
] |
|
612 | 4269 |
]. |
4270 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
4271 |
^ hasData not |
|
4272 |
! |
|
4273 |
||
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4274 |
readWriteWait |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4275 |
"suspend the current process, until the receiver |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4276 |
becomes ready for writing or reading. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4277 |
Return immediate if the receiver is already ready. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4278 |
The other threads are not affected by the wait. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4279 |
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
|
4280 |
be finished." |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4281 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4282 |
self readWriteWaitWithTimeoutMs:nil |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4283 |
! |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4284 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4285 |
readWriteWaitWithTimeoutMs:timeout |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4286 |
"suspend the current process, until the receiver |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4287 |
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
|
4288 |
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
|
4289 |
Return immediate if the receiver is already ready. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4290 |
The other threads are not affected by the wait. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4291 |
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
|
4292 |
be finished." |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4293 |
|
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
4294 |
|fd sema canReadWrite wasBlocked| |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4295 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4296 |
filePointer isNil ifTrue:[ |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4297 |
^ self errorNotOpen |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4298 |
]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4299 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4300 |
fd := self fileDescriptor. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4301 |
(OperatingSystem readWriteCheck:fd) ifTrue:[^ false]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4302 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4303 |
wasBlocked := OperatingSystem blockInterrupts. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4304 |
canReadWrite := OperatingSystem readWriteCheck:fd. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4305 |
canReadWrite ifFalse:[ |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4306 |
sema := Semaphore new name:'readWriteWait'. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4307 |
[ |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4308 |
timeout notNil ifTrue:[ |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4309 |
Processor signal:sema afterMilliseconds:timeout |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4310 |
]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4311 |
Processor signal:sema onOutput:fd. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4312 |
Processor signal:sema onInput:fd. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4313 |
Processor activeProcess state:#ioWait. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4314 |
sema wait. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4315 |
Processor disableSemaphore:sema. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4316 |
canReadWrite := OperatingSystem readWriteCheck:fd |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4317 |
] valueOnUnwindDo:[ |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4318 |
Processor disableSemaphore:sema. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4319 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4320 |
] |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4321 |
]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4322 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4323 |
^ canReadWrite not |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4324 |
! |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
4325 |
|
612 | 4326 |
writeWait |
4327 |
"suspend the current process, until the receiver |
|
4328 |
becomes ready for writing. |
|
4329 |
Return immediate if the receiver is already ready. |
|
4330 |
The other threads are not affected by the wait." |
|
4331 |
||
4332 |
self writeWaitWithTimeoutMs:nil |
|
4333 |
! |
|
4334 |
||
3016 | 4335 |
writeWaitTimeoutMs:timeout |
4336 |
"ST-80 compatibility" |
|
4337 |
^ self writeWaitWithTimeoutMs:timeout |
|
4338 |
! |
|
4339 |
||
612 | 4340 |
writeWaitWithTimeout:timeout |
4341 |
"suspend the current process, until the receiver |
|
4342 |
becomes ready for writing or a timeout (in seconds) expired. |
|
4343 |
Return true if a timeout occured (i.e. false, if data is available). |
|
4344 |
Return immediate if the receiver is already ready. |
|
4345 |
The other threads are not affected by the wait." |
|
4346 |
||
4347 |
^ self writeWaitWithTimeoutMs:timeout * 1000 |
|
4348 |
! |
|
4349 |
||
4350 |
writeWaitWithTimeoutMs:timeout |
|
4351 |
"suspend the current process, until the receiver |
|
4352 |
becomes ready for writing or a timeout (in seconds) expired. |
|
4353 |
Return true if a timeout occured (i.e. false, if data is available). |
|
4354 |
Return immediate if the receiver is already ready. |
|
4355 |
The other threads are not affected by the wait." |
|
4356 |
||
4357 |
|fd outputSema canWrite wasBlocked| |
|
4358 |
||
4359 |
filePointer isNil ifTrue:[ |
|
2264 | 4360 |
^ self errorNotOpen |
612 | 4361 |
]. |
4362 |
mode == #readonly ifTrue:[ |
|
2264 | 4363 |
^ self errorReadOnly |
612 | 4364 |
]. |
4365 |
||
4366 |
fd := self fileDescriptor. |
|
4367 |
(OperatingSystem writeCheck:fd) ifTrue:[^ false]. |
|
4368 |
||
4369 |
wasBlocked := OperatingSystem blockInterrupts. |
|
4370 |
canWrite := OperatingSystem writeCheck:fd. |
|
4371 |
canWrite ifFalse:[ |
|
2264 | 4372 |
outputSema := Semaphore new name:'writeWait'. |
4373 |
[ |
|
4374 |
timeout notNil ifTrue:[ |
|
4375 |
Processor signal:outputSema afterMilliseconds:timeout |
|
4376 |
]. |
|
4377 |
Processor signal:outputSema onOutput:fd. |
|
4378 |
Processor activeProcess state:#ioWait. |
|
4379 |
outputSema wait. |
|
4380 |
Processor disableSemaphore:outputSema. |
|
4381 |
canWrite := OperatingSystem writeCheck:fd |
|
4382 |
] valueOnUnwindDo:[ |
|
4383 |
Processor disableSemaphore:outputSema. |
|
4384 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
4385 |
] |
|
612 | 4386 |
]. |
4387 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
4388 |
^ canWrite not |
|
4389 |
! ! |
|
4390 |
||
4391 |
!ExternalStream methodsFor:'writing'! |
|
4392 |
||
4393 |
cr |
|
4394 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
4395 |
reimplemented for speed" |
|
4396 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4397 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4398 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4399 |
int len, cnt, _buffered; |
612 | 4400 |
OBJ fp; |
4401 |
char *cp; |
|
4402 |
||
1133 | 4403 |
__INST(lastErrorNumber) = nil; |
4404 |
if (((fp = __INST(filePointer)) != nil) |
|
2331 | 4405 |
&& (__INST(mode) != @symbol(readonly)) |
4406 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4407 |
) { |
2331 | 4408 |
f = __FILEVal(fp); |
4409 |
||
4410 |
if (_buffered = (__INST(buffered) == true)) { |
|
4411 |
__WRITING__(f) |
|
4412 |
} |
|
2920 | 4413 |
{ |
4414 |
OBJ mode = __INST(eolMode); |
|
4415 |
||
4416 |
if (mode == @symbol(cr)) { |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4417 |
cp = "\r"; len = 1; |
2920 | 4418 |
} else if (mode == @symbol(crlf)) { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4419 |
cp = "\r\n"; len = 2; |
2920 | 4420 |
} else { |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
4421 |
cp = "\n"; len = 1; |
2920 | 4422 |
} |
2331 | 4423 |
} |
4424 |
__WRITEBYTES__(cnt, f, cp, len, _buffered); |
|
4425 |
||
4426 |
if (cnt == len) { |
|
4427 |
if (__INST(position) != nil) { |
|
4428 |
__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len); |
|
4429 |
} |
|
4430 |
RETURN ( self ); |
|
4431 |
} |
|
4432 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 4433 |
} |
4434 |
%}. |
|
2326 | 4435 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
4436 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4437 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
4438 |
self errorBinary |
|
612 | 4439 |
! |
4440 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4441 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4442 |
"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
|
4443 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4444 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4445 |
OBJ fp; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4446 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4447 |
__INST(lastErrorNumber) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4448 |
if ((fp = __INST(filePointer)) != nil) { |
2264 | 4449 |
if (__INST(mode) != @symbol(readonly)) { |
4450 |
if (__INST(buffered) == true) { |
|
4451 |
__BEGIN_INTERRUPTABLE__ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4452 |
FFLUSH( __FILEVal(fp) ); |
2264 | 4453 |
__END_INTERRUPTABLE__ |
4454 |
} |
|
4455 |
} |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4456 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4457 |
%} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4458 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4459 |
|
612 | 4460 |
nextPut:aCharacter |
4461 |
"write the argument, aCharacter - return nil if failed, self if ok. |
|
4462 |
Only single-byte characters are currently supported" |
|
4463 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4464 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4465 |
FILEPOINTER f; |
612 | 4466 |
char c; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4467 |
int cnt, _buffered; |
612 | 4468 |
OBJ pos, fp; |
4469 |
||
1133 | 4470 |
__INST(lastErrorNumber) = nil; |
4471 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4472 |
&& (__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
|
4473 |
) { |
2264 | 4474 |
if (__INST(binary) != true) { |
4475 |
if (__isCharacter(aCharacter)) { |
|
4476 |
c = __intVal(__characterVal(aCharacter)) & 0xFF; |
|
612 | 4477 |
doWrite: |
2264 | 4478 |
f = __FILEVal(fp); |
4479 |
||
4480 |
||
4481 |
if (_buffered = (__INST(buffered) == true)) { |
|
4482 |
__WRITING__(f) |
|
4483 |
} |
|
4484 |
__WRITEBYTE__(cnt, f, &c, _buffered); |
|
4485 |
||
4486 |
if (cnt == 1) { |
|
4487 |
pos = __INST(position); |
|
4488 |
if (pos != nil) { |
|
4489 |
__INST(position) = __MKSMALLINT(__intVal(pos) + 1); |
|
4490 |
} |
|
4491 |
RETURN ( self ); |
|
4492 |
} |
|
4493 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
4494 |
} |
|
4495 |
} else { |
|
4496 |
if (__isSmallInteger(aCharacter)) { |
|
4497 |
c = __intVal(aCharacter); |
|
4498 |
goto doWrite; |
|
4499 |
} |
|
4500 |
} |
|
612 | 4501 |
} |
4502 |
%}. |
|
2331 | 4503 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
4504 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4505 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
4506 |
binary ifFalse:[self argumentMustBeCharacter. ^ self]. |
|
4507 |
self argumentMustBeInteger. |
|
612 | 4508 |
! |
4509 |
||
4510 |
nextPutAll:aCollection |
|
4511 |
"write all elements of the argument, aCollection. |
|
4512 |
Reimplemented for speed when writing strings or byteArrays. |
|
4513 |
For others, falls back to general method in superclass." |
|
4514 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4515 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4516 |
FILEPOINTER f; |
612 | 4517 |
int len, cnt; |
4518 |
OBJ pos, fp; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4519 |
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
|
4520 |
int o_offs; |
612 | 4521 |
|
1133 | 4522 |
__INST(lastErrorNumber) = nil; |
4523 |
||
4524 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4525 |
&& (__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
|
4526 |
) { |
2264 | 4527 |
f = __FILEVal(fp); |
4528 |
if (_buffered = (__INST(buffered) == true)) { |
|
4529 |
__WRITING__(f) |
|
4530 |
} |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4531 |
|
2264 | 4532 |
if (__isString(aCollection) || __isSymbol(aCollection)) { |
4533 |
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
|
4534 |
#ifdef BUGGY |
2264 | 4535 |
__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
|
4536 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4537 |
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
|
4538 |
__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
|
4539 |
#endif |
2264 | 4540 |
} else { |
4541 |
if (__INST(binary) == true) { |
|
4542 |
int offs; |
|
4543 |
||
4544 |
if (__isByteArray(aCollection)) { |
|
4545 |
offs = 0; |
|
3221
21085ae8e1be
eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents:
3200
diff
changeset
|
4546 |
len = __byteArraySize(aCollection); |
2264 | 4547 |
} else if (__isBytes(aCollection)) { |
4548 |
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
|
4549 |
len = __byteArraySize(aCollection) - offs; |
2264 | 4550 |
} else |
4551 |
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
|
4552 |
#ifdef BUGGY |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4553 |
__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
|
4554 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4555 |
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
|
4556 |
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
|
4557 |
__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
|
4558 |
#endif |
2264 | 4559 |
} else |
4560 |
goto out; |
|
4561 |
} |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4562 |
|
2264 | 4563 |
if (cnt == len) { |
4564 |
pos = __INST(position); |
|
4565 |
if (pos != nil) { |
|
4566 |
__INST(position) = __MKSMALLINT(__intVal(pos) + len); |
|
4567 |
} |
|
4568 |
RETURN (self); |
|
4569 |
} |
|
4570 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 4571 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
4572 |
out: ; |
612 | 4573 |
%}. |
2331 | 4574 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
4575 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4576 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
612 | 4577 |
|
4578 |
^ super nextPutAll:aCollection |
|
4579 |
! |
|
4580 |
||
4581 |
nextPutAll:aCollection startingAt:start to:stop |
|
4582 |
"write a range of elements of the argument, aCollection. |
|
4583 |
Reimplemented for speed when writing strings or byteArrays. |
|
4584 |
For others, falls back to general method in superclass." |
|
4585 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4586 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4587 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4588 |
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
|
4589 |
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
|
4590 |
int o_offs; |
612 | 4591 |
|
1133 | 4592 |
__INST(lastErrorNumber) = nil; |
4593 |
if (((fp = __INST(filePointer)) != nil) |
|
2264 | 4594 |
&& (__INST(mode) != @symbol(readonly)) |
4595 |
&& __bothSmallInteger(start, stop) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4596 |
) { |
2264 | 4597 |
f = __FILEVal(fp); |
4598 |
if (_buffered = (__INST(buffered) == true)) { |
|
4599 |
__WRITING__(f) |
|
4600 |
} |
|
4601 |
iStart = __intVal(start); |
|
4602 |
iStop = __intVal(stop); |
|
4603 |
if ((iStart < 1) || (iStop < iStart)) { |
|
4604 |
RETURN(self); |
|
4605 |
} |
|
4606 |
if (__isString(aCollection) || __isSymbol(aCollection)) { |
|
4607 |
len = __stringSize(aCollection); |
|
4608 |
if (iStop > len) { |
|
4609 |
RETURN(self); |
|
4610 |
} |
|
4611 |
if (iStop > len) |
|
4612 |
iStop = len; |
|
4613 |
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
|
4614 |
#ifdef BUGGY |
2264 | 4615 |
__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
|
4616 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4617 |
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
|
4618 |
__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
|
4619 |
#endif |
2264 | 4620 |
} else { |
4621 |
if (__INST(binary) == true) { |
|
4622 |
int offs; |
|
4623 |
||
4624 |
if (__isByteArray(aCollection)) { |
|
4625 |
offs = 0; |
|
3221
21085ae8e1be
eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents:
3200
diff
changeset
|
4626 |
len = __byteArraySize(aCollection); |
2264 | 4627 |
} else if (__isBytes(aCollection)) { |
4628 |
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
|
4629 |
len = __byteArraySize(aCollection) - offs; |
2264 | 4630 |
} else |
4631 |
goto out; |
|
4632 |
||
4633 |
if (iStop > len) { |
|
4634 |
RETURN(self); |
|
4635 |
} |
|
4636 |
if (iStop > len) |
|
4637 |
iStop = len; |
|
4638 |
len = iStop - iStart + 1; |
|
4639 |
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
|
4640 |
#ifdef BUGGY |
2264 | 4641 |
__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
|
4642 |
#else |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
4643 |
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
|
4644 |
__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
|
4645 |
#endif |
2264 | 4646 |
} else |
4647 |
goto out; |
|
4648 |
} |
|
4649 |
if (cnt == len) { |
|
4650 |
pos = __INST(position); |
|
4651 |
if (pos != nil) { |
|
4652 |
__INST(position) = __MKSMALLINT(__intVal(pos) + len); |
|
4653 |
} |
|
4654 |
RETURN (self); |
|
4655 |
} |
|
4656 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
612 | 4657 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
4658 |
out: ; |
612 | 4659 |
%}. |
4660 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
4661 |
^ super nextPutAll:aCollection startingAt:start to:stop |
|
4662 |
! ! |
|
4663 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
4664 |
!ExternalStream class methodsFor:'documentation'! |
730 | 4665 |
|
4666 |
version |
|
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
4667 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.171 1998-07-21 18:27:42 cg Exp $' |
730 | 4668 |
! ! |
612 | 4669 |
ExternalStream initialize! |