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