author | Stefan Vogel <sv@exept.de> |
Sun, 09 May 2004 22:51:37 +0200 | |
changeset 8339 | b6c3643af40f |
parent 8283 | 8fe0314f8d5a |
child 8362 | e17d9ffb6fa8 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
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 |
||
5414 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
1 | 15 |
ReadWriteStream subclass:#ExternalStream |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
16 |
instanceVariableNames:'filePointer mode buffered binary eolMode hitEOF didWrite |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
17 |
lastErrorNumber readAhead' |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
18 |
classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
19 |
InvalidModeSignal OpenErrorSignal StreamNotOpenSignal |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
20 |
InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
21 |
WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
22 |
FileOpenTrace' |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
23 |
poolDictionaries:'' |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
24 |
category:'Streams-External' |
1 | 25 |
! |
26 |
||
216 | 27 |
!ExternalStream primitiveDefinitions! |
1 | 28 |
%{ |
2896 | 29 |
|
1 | 30 |
#include <stdio.h> |
437 | 31 |
#define _STDIO_H_INCLUDED_ |
32 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
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 |
|
4093 | 62 |
#if defined(__VMS__) || defined(sparc) |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
5101
diff
changeset
|
63 |
# define CLEAR_ERRNO __threadErrno = 0; |
2961 | 64 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
65 |
# define CLEAR_ERRNO /* nothing */ |
2961 | 66 |
#endif |
67 |
||
3420 | 68 |
#ifdef LATER |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
69 |
#define __isFilePointer(x) (__Class(x) == ExternalStream__FilePointer) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
70 |
#define __CHANGECLASS(o, x) (__qClass(o) = (x), o) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
71 |
#define __MKFILEPOINTER(f) __CHANGECLASS(__MKEXTERNALADDRESS(f), ExternalStream__FilePointer) |
3420 | 72 |
#else |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
73 |
#define __MKFILEPOINTER(f) __MKEXTERNALADDRESS(f) |
3420 | 74 |
#endif |
75 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
76 |
#ifdef WIN32 |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
77 |
# define NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
78 |
#endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
79 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
80 |
#ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
81 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
82 |
# undef __HANDLE_INTERRUPTS__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
83 |
# define __HANDLE_INTERRUPTS__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
84 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
85 |
# undef __BEGIN_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
86 |
# define __BEGIN_INTERRUPTABLE__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
87 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
88 |
# undef __END_INTERRUPTABLE__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
89 |
# define __END_INTERRUPTABLE__ /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
90 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
91 |
# ifdef i386 |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
92 |
# define _X86_ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
93 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
94 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
95 |
# undef INT |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
96 |
# undef Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
97 |
# undef Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
98 |
# undef Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
99 |
# undef Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
100 |
# undef Rectangle |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
101 |
# undef Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
102 |
# undef Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
103 |
# undef Date |
7832 | 104 |
# undef Delay |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
105 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
106 |
# define NOATOM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
107 |
# define NOGDICAPMASKS |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
108 |
# define NOMETAFILE |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
109 |
# define NOMINMAX |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
110 |
//#d efine NOOPENFILE |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
111 |
# define NOSOUND |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
112 |
# define NOWH |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
113 |
//# define NOCOMM |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
114 |
# define NOKANJI |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
115 |
# define NOCRYPT |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
116 |
//# define NOMCX |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
117 |
# define WIN32_LEAN_AND_MEAN |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
118 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
119 |
# include <windows.h> |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
120 |
# include <winsock.h> /* */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
121 |
# if !defined(__BORLANDC__) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
122 |
# define stat _stat |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
123 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
124 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
125 |
# ifdef __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
126 |
# define Array __DEF_Array |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
127 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
128 |
# ifdef __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
129 |
# define Number __DEF_Number |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
130 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
131 |
# ifdef __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
132 |
# define Method __DEF_Method |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
133 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
134 |
# ifdef __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
135 |
# define Point __DEF_Point |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
136 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
137 |
# ifdef __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
138 |
# define Block __DEF_Block |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
139 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
140 |
# ifdef __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
141 |
# define Time __DEF_Time |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
142 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
143 |
# ifdef __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
144 |
# define Date __DEF_Date |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
145 |
# endif |
7832 | 146 |
# ifdef __DEF_Delay |
147 |
# define Delay __DEF_Delay |
|
148 |
# endif |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
149 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
150 |
# define INT int |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
151 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
152 |
#else /* use STDIO */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
153 |
# define STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
154 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
155 |
# define READ(f, cp, n) read(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
156 |
# define WRITE(f, cp, n) write(f, cp, n) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
157 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
158 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
159 |
#endif /* use STDIO */ |
3681 | 160 |
|
3682 | 161 |
#ifdef DEBUGGING |
4092 | 162 |
extern char *__survStartPtr, *__survEndPtr; |
3682 | 163 |
# define DEBUGBUFFER(buf) \ |
3681 | 164 |
if (((char *)(buf) >= __survStartPtr) \ |
165 |
&& ((char *)(buf) < __survEndPtr)) { \ |
|
7832 | 166 |
__fatal0("read into survivor\n"); \ |
3681 | 167 |
} |
168 |
||
3682 | 169 |
#else |
170 |
# define DEBUGBUFFER(buf) /* nothing */ |
|
171 |
#endif |
|
172 |
||
216 | 173 |
/* |
174 |
* stdio library requires an fseek before reading whenever a file |
|
175 |
* is open for read/write and the last operation was a write. |
|
176 |
* (also vice-versa). |
|
177 |
* All code should use the following macro before doing reads: |
|
178 |
*/ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
179 |
#ifdef STDIO_NEEDS_FSEEK |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
180 |
# define OPT_FSEEK(f, pos, whence) fseek(f, pos, whence) |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
181 |
#else |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
182 |
# define OPT_FSEEK(f, pos, whence) /* nothing */ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
183 |
#endif |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
184 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
185 |
#ifdef WIN32 |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
186 |
//# define __HANDLEVal(o) (HFILE)(__externalAddressVal(o)) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
187 |
int _rtl_read(); |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
188 |
int _rtl_write(); |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
189 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
190 |
# ifdef __BORLANDC__ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
191 |
# define READ(ret,f, cp, n) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
192 |
{ int __res;\ |
7832 | 193 |
if (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&__res)==0) \ |
194 |
(ret) = __STX_API_CALL4((void*)recv,(void *)_get_osfhandle(fileno(f)), (void *)(cp), (void *)(n), (void *)0);\ |
|
195 |
else \ |
|
196 |
(ret) = __STX_C_CALL3((void*)_rtl_read,(void *)fileno(f), (void *)(cp), (void *)(n));\ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
197 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
198 |
# define WRITE(ret,f, cp, n) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
199 |
{ int __res;\ |
7832 | 200 |
if (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&__res)==0) \ |
201 |
(ret) = __STX_API_CALL4((void*)send,(void *)_get_osfhandle(fileno(f)), (void *)(cp), (void *)(n), (void *)0);\ |
|
202 |
else \ |
|
203 |
(ret) = __STX_C_CALL3((void*)_rtl_write,(void *)fileno(f), (void *)(cp), (void *)(n));\ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
204 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
205 |
# else /* MSC */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
206 |
# define READ(ret,f, cp, n) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
207 |
{ int __res;\ |
7832 | 208 |
if (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&__res)==0) \ |
209 |
(ret) = __STX_API_CALL4((void*)recv,(void *)_get_osfhandle(fileno(f)), (void *)(cp), (void *)(n), (void *)0);\ |
|
210 |
else { \ |
|
211 |
(ret) = __STX_API_CALL5((void*)ReadFile,(void *)_get_osfhandle(fileno(f)), (void *)(cp), (void *)(n),(void *)&__res,(void *)0);\ |
|
212 |
if (ret) \ |
|
213 |
ret = __res; \ |
|
214 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
215 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
216 |
# define WRITE(ret,f, cp, n) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
217 |
{ int __res;\ |
7832 | 218 |
if (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&__res)==0) \ |
219 |
(ret) = __STX_API_CALL4((void*)send,(void *)_get_osfhandle(fileno(f)), (void *)(cp), (void *)(n), (void *)0);\ |
|
220 |
else {\ |
|
221 |
(ret) = __STX_API_CALL5((void*)WriteFile,(void *)_get_osfhandle(fileno(f)), (void *)(cp), (void *)(n),(void *)&__res,(void*)0);\ |
|
222 |
if (ret) \ |
|
223 |
ret = __res; \ |
|
224 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
225 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
226 |
# endif /* MSC */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
227 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
228 |
# define FFLUSH(fp) fflush(fp) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
229 |
# undef STDIO_NEEDS_FSEEK |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
230 |
# define FILEPOINTER FILE * |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
231 |
# define FILENO(f) fileno(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
232 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
233 |
//#define __READING__(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
234 |
//#define __WRITING__(f) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
235 |
# define __READING__(f) \ |
1133 | 236 |
if ((__INST(didWrite) != false) \ |
237 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
7832 | 238 |
__INST(didWrite) = false; \ |
239 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 240 |
} |
241 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
242 |
# define __WRITING__(f) \ |
1133 | 243 |
if ((__INST(didWrite) != true) \ |
244 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
|
7832 | 245 |
__INST(didWrite) = true; \ |
246 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
216 | 247 |
} |
248 |
||
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
249 |
# define __UNGETC__(c, f, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
250 |
if (isBuffered) { \ |
7832 | 251 |
ungetc((c), (f)); \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
252 |
} else { \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
253 |
__INST(readAhead) = __MKSMALLINT((c)); \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
254 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
255 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
256 |
# define __READBYTE__(ret, f, buf, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
257 |
if (isBuffered) { \ |
7832 | 258 |
for (;;) { \ |
259 |
CLEAR_ERRNO; \ |
|
260 |
(ret) = getc(f); \ |
|
261 |
if ((ret) >= 0) { \ |
|
262 |
*(buf) = (ret); \ |
|
263 |
(ret) = 1; \ |
|
264 |
} else if (ferror(f)) { \ |
|
265 |
if (__threadErrno == EINTR) { \ |
|
266 |
clearerr(f); \ |
|
267 |
continue; \ |
|
268 |
} \ |
|
269 |
} else \ |
|
270 |
(ret) = 0; \ |
|
271 |
break; \ |
|
272 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
273 |
} else { \ |
7832 | 274 |
OBJ rA = __INST(readAhead); \ |
275 |
if (rA != nil) { \ |
|
276 |
*(buf) = (char)__intVal(rA); \ |
|
277 |
__INST(readAhead) = nil; \ |
|
278 |
(ret) = 1; \ |
|
279 |
} else { \ |
|
280 |
for (;;) { \ |
|
281 |
CLEAR_ERRNO; \ |
|
282 |
READ(ret,f, buf, 1); \ |
|
283 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
284 |
break; \ |
|
285 |
} \ |
|
286 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
287 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
288 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
289 |
/* |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
290 |
* read_bytes into a c-buffer |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
291 |
* (which may NOT move) |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
292 |
*/ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
293 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
294 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
295 |
if (isBuffered) { \ |
7832 | 296 |
int __offs = 0; \ |
297 |
while (__offs < (cnt)) { \ |
|
298 |
CLEAR_ERRNO; \ |
|
299 |
(ret) = getc(f); \ |
|
300 |
if ((ret) < 0) { \ |
|
301 |
if (ferror(f)) { \ |
|
302 |
if (__threadErrno == EINTR) { \ |
|
303 |
clearerr(f); \ |
|
304 |
continue; \ |
|
305 |
} \ |
|
306 |
} else { \ |
|
307 |
(ret) = 0; \ |
|
308 |
} \ |
|
309 |
break; \ |
|
310 |
} \ |
|
311 |
(buf)[__offs++] = (ret); \ |
|
312 |
} \ |
|
313 |
if (__offs > 0) \ |
|
314 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
315 |
} else { \ |
7832 | 316 |
int __offs = 0; \ |
317 |
\ |
|
318 |
while (__offs < (cnt)) { \ |
|
319 |
OBJ rA = __INST(readAhead); \ |
|
320 |
if (rA != nil) { \ |
|
321 |
(buf)[__offs] = __intVal(rA); \ |
|
322 |
__INST(readAhead) = nil; \ |
|
323 |
__offs++; \ |
|
324 |
} else { \ |
|
325 |
CLEAR_ERRNO; \ |
|
326 |
READ(ret, f, (buf)+__offs, (cnt)-__offs); \ |
|
327 |
if ((ret) <= 0) { \ |
|
328 |
if ((ret) < 0 && __threadErrno == EINTR) { \ |
|
329 |
continue; \ |
|
330 |
} \ |
|
331 |
break; \ |
|
332 |
} \ |
|
333 |
__offs += (ret); \ |
|
334 |
} \ |
|
335 |
} \ |
|
336 |
if (__offs > 0) \ |
|
337 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
338 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
339 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
340 |
# define GETFLAGS(fd) 0 |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
341 |
# define SETFLAGS(fd, flags) /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
342 |
# define SETNONBLOCKING(fd) /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
343 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
344 |
#define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
345 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
346 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
347 |
int oldFlags; \ |
7832 | 348 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
349 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
350 |
if (isBuffered) { \ |
7832 | 351 |
while (__offs < (cnt)) { \ |
352 |
CLEAR_ERRNO; \ |
|
353 |
(ret) = getc(f); \ |
|
354 |
if ((ret) < 0) { \ |
|
355 |
if (ferror(f)) { \ |
|
356 |
if (__threadErrno == EINTR) { \ |
|
357 |
clearerr(f); \ |
|
358 |
continue; \ |
|
359 |
} \ |
|
360 |
} else { \ |
|
361 |
(ret) = 0; \ |
|
362 |
} \ |
|
363 |
break; \ |
|
364 |
} \ |
|
365 |
(buf)[__offs++] = (ret); \ |
|
366 |
} \ |
|
367 |
if (__offs > 0) \ |
|
368 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
369 |
} else { \ |
7832 | 370 |
while (__offs < (cnt)) { \ |
371 |
OBJ rA = __INST(readAhead); \ |
|
372 |
if (rA != nil) { \ |
|
373 |
(buf)[__offs] = __intVal(rA); \ |
|
374 |
__INST(readAhead) = nil; \ |
|
375 |
__offs++; \ |
|
376 |
continue; \ |
|
377 |
} \ |
|
378 |
CLEAR_ERRNO; \ |
|
379 |
{ \ |
|
380 |
int res, __cnt; \ |
|
381 |
if (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res)==0) { \ |
|
382 |
if (res > 0) { \ |
|
383 |
if (res > ((cnt)-__offs)) \ |
|
384 |
res = (cnt)-__offs; \ |
|
385 |
READ(__cnt, f, (buf)+__offs, res); \ |
|
386 |
} else { \ |
|
387 |
__cnt = 0; \ |
|
388 |
} \ |
|
389 |
} else if (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)) { \ |
|
390 |
if (res > 0) { \ |
|
391 |
if (res > ((cnt)-__offs)) \ |
|
392 |
res = (cnt)-__offs; \ |
|
393 |
READ(__cnt ,f, (buf)+__offs, res); \ |
|
394 |
} else \ |
|
395 |
__cnt = 0; \ |
|
396 |
} else { \ |
|
397 |
READ(__cnt, f, (buf)+__offs, (cnt)-__offs); \ |
|
398 |
} \ |
|
399 |
if (__cnt < 0) { \ |
|
400 |
if (__threadErrno == EINTR) { \ |
|
401 |
continue; \ |
|
402 |
} \ |
|
403 |
break; \ |
|
404 |
} \ |
|
405 |
__offs += __cnt; \ |
|
406 |
} \ |
|
407 |
break; \ |
|
408 |
} \ |
|
409 |
if (__offs > 0) \ |
|
410 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
411 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
412 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
413 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
414 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
415 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
416 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
417 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
418 |
int __cnt; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
419 |
char *buf = (char *)(obj); \ |
7832 | 420 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
421 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
422 |
if (isBuffered) { \ |
7832 | 423 |
while (__offs < (cnt)) { \ |
424 |
CLEAR_ERRNO; \ |
|
425 |
(ret) = getc(f); \ |
|
426 |
if ((ret) < 0) { \ |
|
427 |
if (ferror(f)) { \ |
|
428 |
if (__threadErrno == EINTR) { \ |
|
429 |
clearerr(f); \ |
|
430 |
/* refetch */ \ |
|
431 |
buf = (char *)(obj); \ |
|
432 |
continue; \ |
|
433 |
} \ |
|
434 |
} else { \ |
|
435 |
(ret) = 0; \ |
|
436 |
} \ |
|
437 |
break; \ |
|
438 |
} \ |
|
439 |
(buf)[__ooffs+__offs] = (ret); \ |
|
440 |
__offs++; \ |
|
441 |
} \ |
|
442 |
if (__offs > 0) \ |
|
443 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
444 |
} else { \ |
7832 | 445 |
while (__offs < (cnt)) { \ |
446 |
char __buf[1024]; \ |
|
447 |
OBJ rA = __INST(readAhead); \ |
|
448 |
if (rA != nil) { \ |
|
449 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
450 |
__INST(readAhead) = nil; \ |
|
451 |
__offs++; \ |
|
452 |
} else { \ |
|
453 |
int l; \ |
|
454 |
CLEAR_ERRNO; \ |
|
455 |
l = (cnt)-__offs; \ |
|
456 |
if ( l > 1024) \ |
|
457 |
l = 1024; \ |
|
458 |
READ(__cnt, f, __buf, l); \ |
|
459 |
if (__cnt <= 0) { \ |
|
460 |
if (__cnt < 0 && __threadErrno == EINTR) { \ |
|
461 |
continue; \ |
|
462 |
} \ |
|
463 |
break; \ |
|
464 |
} \ |
|
465 |
} \ |
|
466 |
/* refetch */ \ |
|
467 |
buf = (volatile char *)(obj); \ |
|
468 |
memcpy((buf)+__ooffs+__offs,__buf, __cnt); \ |
|
469 |
__offs += __cnt; \ |
|
470 |
} \ |
|
471 |
if (__offs > 0) \ |
|
472 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
473 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
474 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
475 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
476 |
# define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)\ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
477 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
478 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
479 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
480 |
int __cnt; \ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
481 |
char *buf = (char *)(obj); \ |
7832 | 482 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
483 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
484 |
if (isBuffered) { \ |
7832 | 485 |
while (__offs < (cnt)) { \ |
486 |
CLEAR_ERRNO; \ |
|
487 |
(ret) = getc(f); \ |
|
488 |
if ((ret) < 0) { \ |
|
489 |
if (ferror(f)) { \ |
|
490 |
if (__threadErrno == EINTR) { \ |
|
491 |
clearerr(f); \ |
|
492 |
/* refetch */ \ |
|
493 |
buf = (char *)(obj); \ |
|
494 |
continue; \ |
|
495 |
} \ |
|
496 |
} else { \ |
|
497 |
(ret) = 0; \ |
|
498 |
} \ |
|
499 |
break; \ |
|
500 |
} \ |
|
501 |
(buf)[__ooffs+__offs] = (ret); \ |
|
502 |
__offs++; \ |
|
503 |
} \ |
|
504 |
if (__offs > 0) \ |
|
505 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
506 |
} else { \ |
7832 | 507 |
while (__offs < (cnt)) { \ |
508 |
char __buf[1024]; \ |
|
509 |
OBJ rA = __INST(readAhead); \ |
|
510 |
if (rA != nil) { \ |
|
511 |
(buf)[__ooffs+__offs] = __intVal(rA);\ |
|
512 |
__INST(readAhead) = nil; \ |
|
513 |
__offs++; \ |
|
514 |
continue; \ |
|
515 |
} \ |
|
516 |
{ \ |
|
517 |
int l; \ |
|
518 |
int res; \ |
|
519 |
CLEAR_ERRNO; \ |
|
520 |
l = (cnt)-__offs; \ |
|
521 |
if ( l > 1024) \ |
|
522 |
l = 1024; \ |
|
523 |
if (ioctlsocket((SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res)==0) { \ |
|
524 |
if (res > 0) { \ |
|
525 |
if (res > l) \ |
|
526 |
res = l; \ |
|
527 |
READ(__cnt ,f, __buf, res); \ |
|
528 |
} else { \ |
|
529 |
__cnt = 0; \ |
|
530 |
} \ |
|
531 |
} else if (PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)) { \ |
|
532 |
if (res > 0) { \ |
|
533 |
if (res > l) \ |
|
534 |
res = l; \ |
|
535 |
READ(__cnt ,f, __buf, res); \ |
|
536 |
} else \ |
|
537 |
__cnt = 0; \ |
|
538 |
} else { \ |
|
539 |
READ(__cnt, f, __buf, l); \ |
|
540 |
} \ |
|
541 |
if (__cnt < 0 && __threadErrno == EINTR) { \ |
|
542 |
continue; \ |
|
543 |
} \ |
|
544 |
} \ |
|
545 |
/* refetch */ \ |
|
546 |
buf = (volatile char *)(obj); \ |
|
547 |
memcpy((buf)+__ooffs+__offs,__buf, __cnt); \ |
|
548 |
__offs += __cnt; \ |
|
549 |
break; \ |
|
550 |
} \ |
|
551 |
if (__offs > 0) \ |
|
552 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
553 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
554 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
555 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
556 |
# define __WRITEBYTE__(ret, f, buf, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
557 |
if (isBuffered) { \ |
7832 | 558 |
for (;;) { \ |
559 |
CLEAR_ERRNO; \ |
|
560 |
ret = putc(*(buf), f); \ |
|
561 |
if ((ret) >= 0) { \ |
|
562 |
(ret) = 1; \ |
|
563 |
} else if (ferror(f)) { \ |
|
564 |
if (__threadErrno == EINTR) { \ |
|
565 |
clearerr(f); \ |
|
566 |
continue; \ |
|
567 |
} \ |
|
568 |
} else \ |
|
569 |
(ret) = 0; \ |
|
570 |
break; \ |
|
571 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
572 |
} else { \ |
7832 | 573 |
for (;;) { \ |
574 |
CLEAR_ERRNO; \ |
|
575 |
WRITE(ret,f, buf, 1); \ |
|
576 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
577 |
break; \ |
|
578 |
} \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
579 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
580 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
581 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
582 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
583 |
if (isBuffered) { \ |
7832 | 584 |
int __offs = 0; \ |
585 |
while (__offs < (cnt)) { \ |
|
586 |
CLEAR_ERRNO; \ |
|
587 |
ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
588 |
if ((ret) <= 0) { \ |
|
589 |
if (ferror(f)) { \ |
|
590 |
if (__threadErrno == EINTR) { \ |
|
591 |
clearerr(f); \ |
|
592 |
continue; \ |
|
593 |
} \ |
|
594 |
break; \ |
|
595 |
} else { \ |
|
596 |
(ret) = 0; \ |
|
597 |
} \ |
|
598 |
} \ |
|
599 |
__offs += (ret); \ |
|
600 |
} \ |
|
601 |
if (__offs > 0) \ |
|
602 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
603 |
} else { \ |
7832 | 604 |
int __offs = 0; \ |
605 |
while (__offs < (cnt)) { \ |
|
606 |
CLEAR_ERRNO; \ |
|
607 |
WRITE(ret,f, (buf)+__offs, (cnt)-__offs); \ |
|
608 |
if (ret <= 0) { \ |
|
609 |
if (ret < 0 && __threadErrno == EINTR) { \ |
|
610 |
continue; \ |
|
611 |
} \ |
|
612 |
break; \ |
|
613 |
} \ |
|
614 |
__offs += (ret); \ |
|
615 |
} \ |
|
616 |
if (__offs > 0) \ |
|
617 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
618 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
619 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
620 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
621 |
{ \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
622 |
int __ooffs = obj_offs; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
623 |
int __offs = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
624 |
char *buf = (char *)(obj); \ |
7832 | 625 |
\ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
626 |
(ret) = 0; \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
627 |
if (isBuffered) { \ |
7832 | 628 |
while (__offs < (cnt)) { \ |
629 |
CLEAR_ERRNO; \ |
|
630 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
631 |
if ((ret) <= 0) { \ |
|
632 |
if (ferror(f)) { \ |
|
633 |
if (__threadErrno == EINTR) { \ |
|
634 |
/* refetch */ \ |
|
635 |
buf = (char *)(obj); \ |
|
636 |
clearerr(f); \ |
|
637 |
continue; \ |
|
638 |
} \ |
|
639 |
break; \ |
|
640 |
} else { \ |
|
641 |
(ret) = 0; \ |
|
642 |
} \ |
|
643 |
} \ |
|
644 |
__offs += (ret); \ |
|
645 |
} \ |
|
646 |
if (__offs > 0) \ |
|
647 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
648 |
} else { \ |
7832 | 649 |
while (__offs < (cnt)) { \ |
650 |
char __buf[1024]; \ |
|
651 |
int l; \ |
|
652 |
CLEAR_ERRNO; \ |
|
653 |
l = (cnt)-__offs; \ |
|
654 |
if ( l > 1024) \ |
|
655 |
l = 1024; \ |
|
656 |
/* refetch */ \ |
|
657 |
buf = (volatile char *)(obj); \ |
|
658 |
memcpy(__buf,(buf)+__ooffs+__offs,l); \ |
|
659 |
WRITE(ret,f, __buf, l); \ |
|
660 |
if (ret <= 0) { \ |
|
661 |
if (ret < 0 && __threadErrno == EINTR) { \ |
|
662 |
continue; \ |
|
663 |
} \ |
|
664 |
break; \ |
|
665 |
} \ |
|
666 |
__offs += (ret); \ |
|
667 |
} \ |
|
668 |
if (__offs > 0) \ |
|
669 |
(ret) = __offs; \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
670 |
} \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
671 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
672 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
673 |
#else /* no WIN32 */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
674 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
675 |
# define __READING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
676 |
if ((__INST(didWrite) != false) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
677 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
7832 | 678 |
__INST(didWrite) = false; \ |
679 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
680 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
681 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
682 |
# define __WRITING__(f) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
683 |
if ((__INST(didWrite) != true) \ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
684 |
&& (__INST(mode) == @symbol(readwrite))) { \ |
7832 | 685 |
__INST(didWrite) = true; \ |
686 |
OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */ \ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
687 |
} |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
688 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
689 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
690 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
691 |
# define __UNGETC__(c, f, isBuffered) \ |
2963 | 692 |
__INST(readAhead) = __MKSMALLINT((c)); |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
693 |
# else |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
694 |
# define __UNGETC__(c, f, isBuffered) \ |
2264 | 695 |
if (isBuffered) { \ |
7832 | 696 |
ungetc((c), (f)); \ |
2264 | 697 |
} else { \ |
7832 | 698 |
__INST(readAhead) = __MKSMALLINT((c)); \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
699 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
700 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
701 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
702 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
703 |
# define __READBYTE__(ret, f, buf, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
704 |
{ \ |
7832 | 705 |
OBJ rA = __INST(readAhead); \ |
706 |
if (rA != nil) { \ |
|
707 |
*(buf) = __intVal(rA); \ |
|
708 |
DEBUGBUFFER(buf); \ |
|
709 |
__INST(readAhead) = nil; \ |
|
710 |
(ret) = 1; \ |
|
711 |
} else { \ |
|
712 |
for (;;) { \ |
|
713 |
CLEAR_ERRNO; \ |
|
714 |
(ret) = READ(f, buf, 1); \ |
|
715 |
DEBUGBUFFER(buf); \ |
|
716 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
717 |
break; \ |
|
718 |
__HANDLE_INTERRUPTS__; \ |
|
719 |
} \ |
|
720 |
} \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
721 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
722 |
# else |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
723 |
# define __READBYTE__(ret, f, buf, isBuffered) \ |
2264 | 724 |
if (isBuffered) { \ |
7832 | 725 |
for (;;) { \ |
726 |
CLEAR_ERRNO; \ |
|
727 |
(ret) = getc(f); \ |
|
728 |
if ((ret) >= 0) { \ |
|
729 |
DEBUGBUFFER(buf); \ |
|
730 |
*(buf) = (ret); \ |
|
731 |
(ret) = 1; \ |
|
732 |
} else if (ferror(f)) { \ |
|
733 |
if (__threadErrno == EINTR) { \ |
|
734 |
__HANDLE_INTERRUPTS__; \ |
|
735 |
clearerr(f); \ |
|
736 |
continue; \ |
|
737 |
} \ |
|
738 |
} else \ |
|
739 |
(ret) = 0; \ |
|
740 |
break; \ |
|
741 |
} \ |
|
2264 | 742 |
} else { \ |
7832 | 743 |
OBJ rA = __INST(readAhead); \ |
744 |
if (rA != nil) { \ |
|
745 |
*(buf) = __intVal(rA); \ |
|
746 |
DEBUGBUFFER(buf); \ |
|
747 |
__INST(readAhead) = nil; \ |
|
748 |
(ret) = 1; \ |
|
749 |
} else { \ |
|
750 |
for (;;) { \ |
|
751 |
CLEAR_ERRNO; \ |
|
752 |
(ret) = read(fileno(f), buf, 1); \ |
|
753 |
DEBUGBUFFER(buf); \ |
|
754 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
755 |
break; \ |
|
756 |
__HANDLE_INTERRUPTS__; \ |
|
757 |
} \ |
|
758 |
} \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
759 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
760 |
# endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
761 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
762 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
763 |
* 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
|
764 |
* (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
|
765 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
766 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
767 |
# define __READBYTES__(ret, f, buf, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
768 |
{ \ |
7832 | 769 |
int __offs = 0, __cnt; \ |
770 |
\ |
|
771 |
while (__offs < (cnt)) { \ |
|
772 |
OBJ rA = __INST(readAhead); \ |
|
773 |
if (rA != nil) { \ |
|
774 |
(buf)[__offs] = __intVal(rA); \ |
|
775 |
DEBUGBUFFER(buf); \ |
|
776 |
__INST(readAhead) = nil; \ |
|
777 |
__offs++; \ |
|
778 |
} else { \ |
|
779 |
CLEAR_ERRNO; \ |
|
780 |
__cnt = READ(f, (buf)+__offs, (cnt)-__offs); \ |
|
781 |
DEBUGBUFFER(buf); \ |
|
782 |
if (__cnt <= 0) { \ |
|
783 |
if (__cnt < 0 && __threadErrno == EINTR) { \ |
|
784 |
__HANDLE_INTERRUPTS__; \ |
|
785 |
continue; \ |
|
786 |
} \ |
|
787 |
break; \ |
|
788 |
} \ |
|
789 |
__offs += __cnt; \ |
|
790 |
} \ |
|
791 |
} \ |
|
792 |
if (__offs > 0) \ |
|
793 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
794 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
795 |
# else |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
796 |
# 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
|
797 |
(ret) = 0; \ |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
798 |
if (isBuffered) { \ |
7832 | 799 |
int __offs = 0; \ |
800 |
while (__offs < (cnt)) { \ |
|
801 |
CLEAR_ERRNO; \ |
|
802 |
(ret) = getc(f); \ |
|
803 |
if ((ret) < 0) { \ |
|
804 |
if (ferror(f)) { \ |
|
805 |
if (__threadErrno == EINTR) { \ |
|
806 |
__HANDLE_INTERRUPTS__; \ |
|
807 |
clearerr(f); \ |
|
808 |
continue; \ |
|
809 |
} \ |
|
810 |
} else { \ |
|
811 |
(ret) = 0; \ |
|
812 |
} \ |
|
813 |
break; \ |
|
814 |
} \ |
|
815 |
DEBUGBUFFER(buf); \ |
|
816 |
(buf)[__offs++] = (ret); \ |
|
817 |
} \ |
|
818 |
if (__offs > 0) \ |
|
819 |
(ret) = __offs; \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
820 |
} else { \ |
7832 | 821 |
int __offs = 0, __cnt; \ |
822 |
int fd = fileno(f); \ |
|
823 |
\ |
|
824 |
while (__offs < (cnt)) { \ |
|
825 |
OBJ rA = __INST(readAhead); \ |
|
826 |
if (rA != nil) { \ |
|
827 |
DEBUGBUFFER(buf); \ |
|
828 |
(buf)[__offs] = __intVal(rA); \ |
|
829 |
__INST(readAhead) = nil; \ |
|
830 |
__offs++; \ |
|
831 |
} else { \ |
|
832 |
CLEAR_ERRNO; \ |
|
833 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
834 |
DEBUGBUFFER(buf); \ |
|
835 |
if (__cnt <= 0) { \ |
|
836 |
if (__cnt < 0 && __threadErrno == EINTR) { \ |
|
837 |
__HANDLE_INTERRUPTS__; \ |
|
838 |
continue; \ |
|
839 |
} \ |
|
840 |
break; \ |
|
841 |
} \ |
|
842 |
__offs += __cnt; \ |
|
843 |
} \ |
|
844 |
} \ |
|
845 |
if (__offs > 0) \ |
|
846 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
847 |
} |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
848 |
|
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
849 |
|
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
850 |
/* |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
851 |
* FNDELAY and O_NDELAY is deprecated, O_NONBLOCK is used in POSIX, XPG, etc... |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
852 |
*/ |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
853 |
|
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
854 |
# if defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(O_NDELAY) || defined(FNDELAY)) |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
855 |
# define GETFLAGS(fd) \ |
7832 | 856 |
fcntl(fd, F_GETFL, 0); |
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
857 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
858 |
# define SETFLAGS(fd, flags) \ |
7832 | 859 |
fcntl(fd, F_SETFL, flags) |
6563
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
860 |
|
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
861 |
# if defined(O_NONBLOCK) |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
862 |
# define __STX_NONBLOCK_FLAG O_NONBLOCK |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
863 |
# else |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
864 |
# if defined(O_NDELAY) |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
865 |
# define __STX_NONBLOCK_FLAG O_NDELAY |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
866 |
# else |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
867 |
# define __STX_NONBLOCK_FLAG FNDELAY |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
868 |
# endif |
f786651428c8
Support O_NONBLOCK which is the POSIX way of FNDELAY
Stefan Vogel <sv@exept.de>
parents:
6487
diff
changeset
|
869 |
# endif |
3554
320cbfef9382
made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
870 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
871 |
# define SETNONBLOCKING(fd) \ |
7832 | 872 |
{ \ |
873 |
int flags; \ |
|
874 |
flags = fcntl(fd, F_GETFL, 0); \ |
|
875 |
if (flags >= 0) { \ |
|
876 |
fcntl(fd, F_SETFL, flags | __STX_NONBLOCK_FLAG); \ |
|
877 |
} \ |
|
878 |
} |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
879 |
# else |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
880 |
# define GETFLAGS(fd) 0 |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
881 |
# define SETFLAGS(fd, flags) /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
882 |
# define SETNONBLOCKING(fd) /* nothing */ |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
883 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
884 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
885 |
# define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered) \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
886 |
{ \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
887 |
int __offs = 0, __cnt; \ |
3681 | 888 |
int oldFlags; \ |
7832 | 889 |
\ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
890 |
(ret) = 0; \ |
3681 | 891 |
oldFlags = GETFLAGS(fileno(f)); \ |
892 |
SETNONBLOCKING(fileno(f)); \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
893 |
if (isBuffered) { \ |
7832 | 894 |
while (__offs < (cnt)) { \ |
895 |
CLEAR_ERRNO; \ |
|
896 |
(ret) = getc(f); \ |
|
897 |
if ((ret) < 0) { \ |
|
898 |
if (ferror(f)) { \ |
|
899 |
if (__threadErrno == EINTR) { \ |
|
900 |
(ret) = 0; \ |
|
901 |
clearerr(f); \ |
|
902 |
break; \ |
|
903 |
} \ |
|
904 |
} else { \ |
|
905 |
(ret) = 0; \ |
|
906 |
} \ |
|
907 |
break; \ |
|
908 |
} \ |
|
909 |
(buf)[__offs++] = (ret); \ |
|
910 |
DEBUGBUFFER(buf); \ |
|
911 |
} \ |
|
912 |
if (__offs > 0) \ |
|
913 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
914 |
} else { \ |
7832 | 915 |
int fd = fileno(f); \ |
916 |
\ |
|
917 |
while (__offs < (cnt)) { \ |
|
918 |
OBJ rA = __INST(readAhead); \ |
|
919 |
if (rA != nil) { \ |
|
920 |
(buf)[__offs] = __intVal(rA); \ |
|
921 |
DEBUGBUFFER(buf); \ |
|
922 |
__INST(readAhead) = nil; \ |
|
923 |
__offs++; \ |
|
924 |
continue; \ |
|
925 |
} \ |
|
926 |
CLEAR_ERRNO; \ |
|
927 |
__cnt = read(fd, (buf)+__offs, (cnt)-__offs); \ |
|
928 |
DEBUGBUFFER(buf); \ |
|
929 |
if (__cnt > 0) { \ |
|
930 |
__offs += __cnt; \ |
|
931 |
} \ |
|
932 |
break; \ |
|
933 |
} \ |
|
934 |
if (__offs > 0) \ |
|
935 |
(ret) = __offs; \ |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
936 |
} \ |
3681 | 937 |
SETFLAGS(fileno(f), oldFlags); \ |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
938 |
} |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
939 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
940 |
# endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
941 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
942 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
943 |
* 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
|
944 |
* (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
|
945 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
946 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
947 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
948 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
949 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
950 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
951 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
952 |
char *buf = (char *)(obj); \ |
7832 | 953 |
\ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
954 |
(ret) = 0; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
955 |
{ \ |
7832 | 956 |
while (__offs < (cnt)) { \ |
957 |
OBJ rA = __INST(readAhead); \ |
|
958 |
if (rA != nil) { \ |
|
959 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
960 |
DEBUGBUFFER(buf); \ |
|
961 |
__INST(readAhead) = nil; \ |
|
962 |
__offs++; \ |
|
963 |
} else { \ |
|
964 |
CLEAR_ERRNO; \ |
|
965 |
__cnt = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
966 |
DEBUGBUFFER(buf); \ |
|
967 |
if (__cnt <= 0) { \ |
|
968 |
if (__cnt < 0 && __threadErrno == EINTR) { \ |
|
969 |
__HANDLE_INTERRUPTS__; \ |
|
970 |
/* refetch */ \ |
|
971 |
buf = (char *)(obj); \ |
|
972 |
continue; \ |
|
973 |
} \ |
|
974 |
break; \ |
|
975 |
} \ |
|
976 |
__offs += __cnt; \ |
|
977 |
} \ |
|
978 |
} \ |
|
979 |
if (__offs > 0) \ |
|
980 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
981 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
982 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
983 |
# else |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
984 |
# define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
985 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
986 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
987 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
988 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
989 |
char *buf = (char *)(obj); \ |
7832 | 990 |
\ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
991 |
(ret) = 0; \ |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
992 |
if (isBuffered) { \ |
7832 | 993 |
while (__offs < (cnt)) { \ |
994 |
CLEAR_ERRNO; \ |
|
995 |
(ret) = getc(f); \ |
|
996 |
if ((ret) < 0) { \ |
|
997 |
if (ferror(f)) { \ |
|
998 |
if (__threadErrno == EINTR) { \ |
|
999 |
__HANDLE_INTERRUPTS__; \ |
|
1000 |
clearerr(f); \ |
|
1001 |
/* refetch */ \ |
|
1002 |
buf = (char *)(obj); \ |
|
1003 |
DEBUGBUFFER(buf); \ |
|
1004 |
continue; \ |
|
1005 |
} \ |
|
1006 |
} else { \ |
|
1007 |
(ret) = 0; \ |
|
1008 |
} \ |
|
1009 |
break; \ |
|
1010 |
} \ |
|
1011 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1012 |
DEBUGBUFFER(buf); \ |
|
1013 |
__offs++; \ |
|
1014 |
} \ |
|
1015 |
if (__offs > 0) \ |
|
1016 |
(ret) = __offs; \ |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1017 |
} else { \ |
7832 | 1018 |
int fd = fileno(f); \ |
1019 |
\ |
|
1020 |
while (__offs < (cnt)) { \ |
|
1021 |
OBJ rA = __INST(readAhead); \ |
|
1022 |
if (rA != nil) { \ |
|
1023 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1024 |
DEBUGBUFFER(buf); \ |
|
1025 |
__INST(readAhead) = nil; \ |
|
1026 |
__offs++; \ |
|
1027 |
} else { \ |
|
1028 |
CLEAR_ERRNO; \ |
|
1029 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1030 |
DEBUGBUFFER(buf); \ |
|
1031 |
if (__cnt <= 0) { \ |
|
1032 |
if (__cnt < 0 && __threadErrno == EINTR) { \ |
|
1033 |
__HANDLE_INTERRUPTS__; \ |
|
1034 |
/* refetch */ \ |
|
1035 |
buf = (char *)(obj); \ |
|
1036 |
continue; \ |
|
1037 |
} \ |
|
1038 |
break; \ |
|
1039 |
} \ |
|
1040 |
__offs += __cnt; \ |
|
1041 |
} \ |
|
1042 |
} \ |
|
1043 |
if (__offs > 0) \ |
|
1044 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1045 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1046 |
} |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1047 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1048 |
# define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1049 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1050 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1051 |
int __offs = 0; \ |
7540
7cd542f29024
Fix reading when readAheadBuffer is filled and following read fails
Stefan Vogel <sv@exept.de>
parents:
7503
diff
changeset
|
1052 |
int __cnt; \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1053 |
char *buf = (char *)(obj); \ |
7832 | 1054 |
\ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1055 |
(ret) = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1056 |
if (isBuffered) { \ |
7832 | 1057 |
while (__offs < (cnt)) { \ |
1058 |
CLEAR_ERRNO; \ |
|
1059 |
(ret) = getc(f); \ |
|
1060 |
if ((ret) < 0) { \ |
|
1061 |
if (ferror(f)) { \ |
|
1062 |
if (__threadErrno == EINTR) { \ |
|
1063 |
clearerr(f); \ |
|
1064 |
/* refetch */ \ |
|
1065 |
buf = (char *)(obj); \ |
|
1066 |
(ret) = 0; \ |
|
1067 |
break; \ |
|
1068 |
} \ |
|
1069 |
} else { \ |
|
1070 |
(ret) = 0; \ |
|
1071 |
} \ |
|
1072 |
break; \ |
|
1073 |
} \ |
|
1074 |
(buf)[__ooffs+__offs] = (ret); \ |
|
1075 |
DEBUGBUFFER(buf); \ |
|
1076 |
__offs++; \ |
|
1077 |
} \ |
|
1078 |
if (__offs > 0) \ |
|
1079 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1080 |
} else { \ |
7832 | 1081 |
int fd = fileno(f); \ |
1082 |
\ |
|
1083 |
while (__offs < (cnt)) { \ |
|
1084 |
OBJ rA = __INST(readAhead); \ |
|
1085 |
if (rA != nil) { \ |
|
1086 |
(buf)[__ooffs+__offs] = __intVal(rA); \ |
|
1087 |
DEBUGBUFFER(buf); \ |
|
1088 |
__INST(readAhead) = nil; \ |
|
1089 |
__offs++; \ |
|
1090 |
continue; \ |
|
1091 |
} \ |
|
1092 |
CLEAR_ERRNO; \ |
|
1093 |
__cnt = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1094 |
DEBUGBUFFER(buf); \ |
|
1095 |
if (__cnt > 0) { \ |
|
1096 |
__offs += __cnt; \ |
|
1097 |
} \ |
|
1098 |
break; \ |
|
1099 |
} \ |
|
1100 |
if (__offs > 0) \ |
|
1101 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1102 |
} \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1103 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1104 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1105 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1106 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1107 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1108 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1109 |
# define __WRITEBYTE__(ret, f, buf, isBuffered) \ |
7832 | 1110 |
for (;;) { \ |
1111 |
CLEAR_ERRNO; \ |
|
1112 |
(ret) = WRITE(f, buf, 1); \ |
|
1113 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
1114 |
break; \ |
|
1115 |
__HANDLE_INTERRUPTS__; \ |
|
1116 |
} |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1117 |
# else |
4968
ff01ac91efa3
Fix buffered nexPut: for Solaris/Sparc
Stefan Vogel <sv@exept.de>
parents:
4914
diff
changeset
|
1118 |
# define __WRITEBYTE__(ret, f, buf, isBuffered) \ |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1119 |
if (isBuffered) { \ |
7832 | 1120 |
for (;;) { \ |
1121 |
CLEAR_ERRNO; \ |
|
1122 |
ret = putc(*(buf), f); \ |
|
1123 |
if ((ret) >= 0) { \ |
|
1124 |
(ret) = 1; \ |
|
1125 |
} else if (ferror(f)) { \ |
|
1126 |
/* SOLARIS/SPARC (2.6) generates spurious errors with errno = 0 */ \ |
|
1127 |
if (__threadErrno == EINTR || __threadErrno == 0) { \ |
|
1128 |
__HANDLE_INTERRUPTS__; \ |
|
1129 |
clearerr(f); \ |
|
1130 |
continue; \ |
|
1131 |
} \ |
|
1132 |
} else \ |
|
1133 |
(ret) = 0; \ |
|
1134 |
break; \ |
|
1135 |
} \ |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
1136 |
} else { \ |
7832 | 1137 |
for (;;) { \ |
1138 |
CLEAR_ERRNO; \ |
|
1139 |
(ret) = write(fileno(f), buf, 1); \ |
|
1140 |
if ((ret) >= 0 || __threadErrno != EINTR) \ |
|
1141 |
break; \ |
|
1142 |
__HANDLE_INTERRUPTS__; \ |
|
1143 |
} \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1144 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1145 |
# endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1146 |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1147 |
/* |
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1148 |
* 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
|
1149 |
* (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
|
1150 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1151 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1152 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered) \ |
2961 | 1153 |
(ret) = 0; \ |
1154 |
{ \ |
|
7832 | 1155 |
int __offs = 0; \ |
1156 |
while (__offs < (cnt)) { \ |
|
1157 |
CLEAR_ERRNO; \ |
|
1158 |
ret = WRITE(f, (buf)+__offs, (cnt)-__offs); \ |
|
1159 |
if (ret <= 0) { \ |
|
1160 |
if (ret < 0 && __threadErrno == EINTR) { \ |
|
1161 |
__HANDLE_INTERRUPTS__; \ |
|
1162 |
continue; \ |
|
1163 |
} \ |
|
1164 |
break; \ |
|
1165 |
} \ |
|
1166 |
__offs += (ret); \ |
|
1167 |
} \ |
|
1168 |
if (__offs > 0) \ |
|
1169 |
(ret) = __offs; \ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1170 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1171 |
# else |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1172 |
# define __WRITEBYTES__(ret, f, buf, cnt, isBuffered) \ |
2961 | 1173 |
(ret) = 0; \ |
1174 |
if (isBuffered) { \ |
|
7832 | 1175 |
int __offs = 0; \ |
1176 |
while (__offs < (cnt)) { \ |
|
1177 |
CLEAR_ERRNO; \ |
|
1178 |
ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\ |
|
1179 |
if ((ret) <= 0) { \ |
|
1180 |
if (ferror(f)) { \ |
|
1181 |
if (__threadErrno == EINTR) { \ |
|
1182 |
__HANDLE_INTERRUPTS__; \ |
|
1183 |
clearerr(f); \ |
|
1184 |
continue; \ |
|
1185 |
} \ |
|
1186 |
break; \ |
|
1187 |
} else { \ |
|
1188 |
(ret) = 0; \ |
|
1189 |
} \ |
|
1190 |
} \ |
|
1191 |
__offs += (ret); \ |
|
1192 |
} \ |
|
1193 |
if (__offs > 0) \ |
|
1194 |
(ret) = __offs; \ |
|
2961 | 1195 |
} else { \ |
7832 | 1196 |
int __offs = 0; \ |
1197 |
while (__offs < (cnt)) { \ |
|
1198 |
CLEAR_ERRNO; \ |
|
1199 |
ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);\ |
|
1200 |
if (ret <= 0) { \ |
|
1201 |
if (ret < 0 && __threadErrno == EINTR) { \ |
|
1202 |
__HANDLE_INTERRUPTS__; \ |
|
1203 |
continue; \ |
|
1204 |
} \ |
|
1205 |
break; \ |
|
1206 |
} \ |
|
1207 |
__offs += (ret); \ |
|
1208 |
} \ |
|
1209 |
if (__offs > 0) \ |
|
1210 |
(ret) = __offs; \ |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1211 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1212 |
# endif |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1213 |
|
223 | 1214 |
/* |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1215 |
* 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
|
1216 |
* (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
|
1217 |
*/ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1218 |
# ifdef NO_STDIO |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1219 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1220 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1221 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1222 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1223 |
char *buf = (char *)(obj); \ |
7832 | 1224 |
\ |
2961 | 1225 |
(ret) = 0; \ |
1226 |
{ \ |
|
7832 | 1227 |
while (__offs < (cnt)) { \ |
1228 |
CLEAR_ERRNO; \ |
|
1229 |
ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1230 |
if (ret <= 0) { \ |
|
1231 |
if (ret < 0 && __threadErrno == EINTR) { \ |
|
1232 |
__HANDLE_INTERRUPTS__; \ |
|
1233 |
/* refetch */ \ |
|
1234 |
buf = (char *)(obj); \ |
|
1235 |
continue; \ |
|
1236 |
} \ |
|
1237 |
break; \ |
|
1238 |
} \ |
|
1239 |
__offs += (ret); \ |
|
1240 |
} \ |
|
1241 |
if (__offs > 0) \ |
|
1242 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1243 |
} \ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
1244 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1245 |
# else |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1246 |
# define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered) \ |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1247 |
{ \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1248 |
int __ooffs = obj_offs; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1249 |
int __offs = 0; \ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1250 |
char *buf = (char *)(obj); \ |
7832 | 1251 |
\ |
2961 | 1252 |
(ret) = 0; \ |
1253 |
if (isBuffered) { \ |
|
7832 | 1254 |
while (__offs < (cnt)) { \ |
1255 |
CLEAR_ERRNO; \ |
|
1256 |
ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f); \ |
|
1257 |
if ((ret) <= 0) { \ |
|
1258 |
if (ferror(f)) { \ |
|
1259 |
if (__threadErrno == EINTR) { \ |
|
1260 |
__HANDLE_INTERRUPTS__; \ |
|
1261 |
/* refetch */ \ |
|
1262 |
buf = (char *)(obj); \ |
|
1263 |
clearerr(f); \ |
|
1264 |
continue; \ |
|
1265 |
} \ |
|
1266 |
break; \ |
|
1267 |
} else { \ |
|
1268 |
(ret) = 0; \ |
|
1269 |
} \ |
|
1270 |
} \ |
|
1271 |
__offs += (ret); \ |
|
1272 |
} \ |
|
1273 |
if (__offs > 0) \ |
|
1274 |
(ret) = __offs; \ |
|
2961 | 1275 |
} else { \ |
7832 | 1276 |
while (__offs < (cnt)) { \ |
1277 |
CLEAR_ERRNO; \ |
|
1278 |
ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs); \ |
|
1279 |
if (ret <= 0) { \ |
|
1280 |
if (ret < 0 && __threadErrno == EINTR) { \ |
|
1281 |
__HANDLE_INTERRUPTS__; \ |
|
1282 |
/* refetch */ \ |
|
1283 |
buf = (char *)(obj); \ |
|
1284 |
continue; \ |
|
1285 |
} \ |
|
1286 |
break; \ |
|
1287 |
} \ |
|
1288 |
__offs += (ret); \ |
|
1289 |
} \ |
|
1290 |
if (__offs > 0) \ |
|
1291 |
(ret) = __offs; \ |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
1292 |
} \ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1293 |
} |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1294 |
# endif |
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
1295 |
#endif /* unix */ |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1296 |
|
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
1297 |
/* |
223 | 1298 |
* on some systems errno is a macro ... check for it here |
1299 |
*/ |
|
1300 |
#ifndef errno |
|
1301 |
extern errno; |
|
1302 |
#endif |
|
1303 |
||
1 | 1304 |
%} |
188 | 1305 |
! ! |
1 | 1306 |
|
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1307 |
!ExternalStream class methodsFor:'documentation'! |
22 | 1308 |
|
88 | 1309 |
copyright |
1310 |
" |
|
1311 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1312 |
All Rights Reserved |
88 | 1313 |
|
1314 |
This software is furnished under a license and may be used |
|
1315 |
only in accordance with the terms of that license and with the |
|
1316 |
inclusion of the above copyright notice. This software may not |
|
1317 |
be provided or otherwise made available to, or used by, any |
|
1318 |
other person. No title to or ownership of the software is |
|
1319 |
hereby transferred. |
|
1320 |
" |
|
1321 |
! |
|
1322 |
||
22 | 1323 |
documentation |
1324 |
" |
|
68 | 1325 |
ExternalStream defines protocol common to Streams which have a file-descriptor and |
1326 |
represent some file or communicationChannel of the underlying OperatingSystem. |
|
1327 |
ExternalStream is abstract; concrete classes are FileStream, PipeStream etc. |
|
77 | 1328 |
|
159 | 1329 |
ExternalStreams can be in two modes: text- (the default) and binary-mode. |
68 | 1330 |
In text-mode, the elements read/written are characters; |
1331 |
while in binary-mode the basic elements are bytes which read/write as SmallIntegers |
|
1332 |
in the range 0..255. |
|
22 | 1333 |
|
68 | 1334 |
Also, the stream can be either in buffered or unbuffered mode. In buffered mode, |
1335 |
data is not written until either a cr is written (in text mode) or a synchronizeOutput |
|
1336 |
is sent (in both modes). |
|
22 | 1337 |
|
77 | 1338 |
The underlying OperatingSystem streams may either be closed explicitely (sending a close) |
68 | 1339 |
or just forgotten - in this case, the garbage collector will eventually collect the |
77 | 1340 |
object AND a close will be performed automatically (but you will NOT know when this |
1341 |
happens - so it is recommended, that you close your files when no longer needed). |
|
159 | 1342 |
Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to |
77 | 1343 |
some crash) the data will not be in the file, if unclosed. |
1344 |
All streams understand the close message, so it never hurts to use it (it is defined as |
|
1345 |
a noop in one of the superclasses). |
|
22 | 1346 |
|
68 | 1347 |
Most of the methods found here redefine inherited methods for better performance, |
1348 |
since I/O from/to files should be fast. |
|
22 | 1349 |
|
68 | 1350 |
Recovering a snapshot: |
1295 | 1351 |
not all streams can be restored to the state they had before - see the implementation of |
1352 |
reOpen in subclasses for more information. |
|
1353 |
For streams sitting on some communication channel (i.e. Pipes and Sockets) you should |
|
1354 |
reestablish the stream upon image restart (make someone dependent on ObjectMemory). |
|
1355 |
FileStreams are reopened and positioned to their offset they had at snapshot time. |
|
1356 |
This may fail, if the file was removed or renamed - or lead to confusion |
|
1357 |
if the contents changed in the meantime. |
|
1358 |
Therefore, it is a good idea to reopen files and check for these things at restart time. |
|
1359 |
||
1360 |
[Instance variables:] |
|
1361 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1362 |
filePointer <Integer> the unix FILE*; somehow mapped to an integer |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1363 |
(notice: not the fd) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1364 |
on Windows: the fileHandle |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1365 |
mode <Symbol> #readwrite, #readonly or #writeonly |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1366 |
buffered <Boolean> true, if buffered (i.e. collects characters - does |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1367 |
not output immediately) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1368 |
binary <Boolean> true if in binary mode (reads bytes instead of chars) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1369 |
eolMode <Symbol> one of nil, #cr or #crlf. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1370 |
determines how lines should be terminated. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1371 |
nil -> newLine (as in Unix); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1372 |
#crlf -> with cr-lf (as in MSDOS) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1373 |
#cr -> with cr (as in VMS) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1374 |
hitEOF <Boolean> true, if EOF was reached |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1375 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1376 |
lastErrorNumber <Integer> the value of errno (only valid right after the error - |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1377 |
updated with next i/o operation) |
1295 | 1378 |
|
1379 |
[Class variables:] |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1380 |
Lobby <Registry> keeps track of used ext-streams (to free up FILE*'s) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1381 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1382 |
StreamErrorSignal <Signal> parent of all stream errors (see Stream class) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1383 |
InvalidReadSignal <Signal> raised on read from writeonly stream |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1384 |
InvalidWriteSignal <Signal> raised on write to readonly stream |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1385 |
InvalidModeSignal <Signal> raised on text I/O with binary-stream |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1386 |
or binary I/O with text-stream |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1387 |
OpenErrorSignal <Signal> raised if open fails |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1388 |
StreamNotOpenSignal <Signal> raised on I/O with non-open stream |
159 | 1389 |
|
1390 |
Additional notes: |
|
1391 |
This class is implemented using the underlying stdio-c library package, which |
|
1392 |
has both advantages and disadvantages: since it is portable (posix defined), porting |
|
1393 |
ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library |
|
1394 |
has big problems handling unbounded Streams, since the EOF handling in stdio is |
|
1395 |
not prepared for data to arrive after EOF has been reached - time will show, if we need |
|
1396 |
a complete rewrite for UnboundedStream ... |
|
325 | 1397 |
|
188 | 1398 |
Also, depending on the system, the stdio library behaves infriendly when signals |
1399 |
occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal |
|
1400 |
is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns |
|
1295 | 1401 |
an error and errno is set to EINTR. |
1402 |
Thats what the ugly code around all getc-calls is for ... |
|
1403 |
Since things get more and more ugly - we will rewrite ExternalStream |
|
1404 |
completely, to NOT use any stdio stuff (and do its buffering itself). |
|
325 | 1405 |
|
1406 |
Notice that typical stdio's use a single errno global variable to return an error code, |
|
1407 |
this was bad design in the stdio lib (right from the very beginning), since its much |
|
1408 |
harder to deal with this in the presence of lightweight processes, where errno gets |
|
1409 |
overwritten by an I/O operation done in another thread. (stdio should have been written |
|
1410 |
to return errno as a negative number ...). |
|
1411 |
To deal with this, the scheduler treats errno like a per-thread private variable, |
|
1412 |
and saves/restores the errno setting when switching to another thread. |
|
1413 |
(Notice that some thread packages do this also, but ST/X's thread implementation |
|
1414 |
does not depend on those, but instead uses a portable private package). |
|
1415 |
||
216 | 1416 |
Finally, if an stdio-stream is open for both reading and writing, we have to call |
1417 |
fseek whenever we are about to read after write and vice versa. |
|
1418 |
Two macros (__READING__ and __WRITING__) have been defined to be used before every |
|
1419 |
fread/fgetc and fwrite/putc respectively. |
|
1295 | 1420 |
|
1421 |
[author:] |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1422 |
Claus Gittinger |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1423 |
Stefan Vogel (many, many fixes ...) |
1295 | 1424 |
|
1425 |
[see also:] |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1426 |
FileStream Socket PipeStream |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1427 |
Filename OperatingSystem |
22 | 1428 |
" |
3255 | 1429 |
! |
1430 |
||
1431 |
examples |
|
1432 |
" |
|
1433 |
open a file, read the contents and display it in a textView: |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1434 |
[exBegin] |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1435 |
|topView scrollPane textView fileStream text| |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1436 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1437 |
topView := StandardSystemView new. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1438 |
topView label:'contents of Makefile'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1439 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1440 |
scrollPane := HVScrollableView in:topView. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1441 |
scrollPane origin:0.0@0.0 corner:1.0@1.0. |
3255 | 1442 |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1443 |
textView := EditTextView new. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1444 |
scrollPane scrolledView:textView. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1445 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1446 |
fileStream := 'Makefile' asFilename readStream. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1447 |
text := fileStream upToEnd. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1448 |
fileStream close. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1449 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1450 |
textView contents:text. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1451 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1452 |
topView open. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1453 |
[exEnd] |
3255 | 1454 |
|
1455 |
||
1456 |
Notice, all of the above can also be done (simply) as: |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1457 |
[exBegin] |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1458 |
EditTextView openOn:'Makefile' |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1459 |
[exEnd] |
3255 | 1460 |
" |
22 | 1461 |
! ! |
1462 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1463 |
!ExternalStream class methodsFor:'initialization'! |
1 | 1464 |
|
2920 | 1465 |
initDefaultEOLMode |
1466 |
OperatingSystem isUNIXlike ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1467 |
"/ unix EOL conventions |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1468 |
DefaultEOLMode := #nl |
2920 | 1469 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1470 |
OperatingSystem isVMSlike ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1471 |
"/ vms EOL conventions |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1472 |
DefaultEOLMode := #cr |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1473 |
] ifFalse:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1474 |
"/ msdos EOL conventions |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1475 |
DefaultEOLMode := #crlf |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1476 |
] |
2920 | 1477 |
] |
1478 |
! |
|
1479 |
||
1480 |
initModeStrings |
|
1481 |
"initialize modeStrings which are passed down to the underlying |
|
1482 |
fopen/fdopen functions." |
|
1483 |
||
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1484 |
OperatingSystem isMSDOSlike ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1485 |
ReadMode := 'rb'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1486 |
ReadWriteMode := 'rb+'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1487 |
WriteMode := 'wb'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1488 |
AppendMode := 'ab+'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1489 |
CreateReadWriteMode := 'wb+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1490 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1491 |
ReadMode := 'r'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1492 |
ReadWriteMode := 'r+'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1493 |
WriteMode := 'w'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1494 |
AppendMode := 'a+'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1495 |
CreateReadWriteMode := 'w+'. |
3132
037027ae20fd
msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1496 |
] |
2920 | 1497 |
! |
1498 |
||
1 | 1499 |
initialize |
593
19d568779cf7
moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
1500 |
OpenErrorSignal isNil ifTrue:[ |
8066
0dbcbe8989b8
OpenError is now a class based exception
Claus Gittinger <cg@exept.de>
parents:
8008
diff
changeset
|
1501 |
"/ OpenErrorSignal := OpenError. |
0dbcbe8989b8
OpenError is now a class based exception
Claus Gittinger <cg@exept.de>
parents:
8008
diff
changeset
|
1502 |
"/ OpenErrorSignal nameClass:self message:#openErrorSignal. |
8074 | 1503 |
OpenErrorSignal := OpenError. |
1504 |
OpenErrorSignal notifierString:'open error'. |
|
1505 |
||
1506 |
"/ InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false. |
|
1507 |
"/ InvalidReadSignal nameClass:self message:#invalidReadSignal. |
|
1508 |
InvalidReadSignal := InvalidReadError. |
|
1509 |
InvalidReadSignal notifierString:'read error'. |
|
1510 |
||
1511 |
"/ InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false. |
|
1512 |
"/ InvalidWriteSignal nameClass:self message:#invalidWriteSignal. |
|
1513 |
InvalidWriteSignal := InvalidWriteError. |
|
1514 |
InvalidWriteSignal notifierString:'write error'. |
|
1515 |
||
1516 |
"/ InvalidModeSignal := StreamErrorSignal newSignalMayProceed:false. |
|
1517 |
"/ InvalidModeSignal nameClass:self message:#invalidModeSignal. |
|
1518 |
InvalidModeSignal := InvalidModeError. |
|
1519 |
InvalidModeSignal notifierString:'binary/text mode mismatch'. |
|
1520 |
||
1521 |
"/ InvalidOperationSignal := StreamErrorSignal newSignalMayProceed:false. |
|
1522 |
"/ InvalidOperationSignal nameClass:self message:#invalidOperationSignal. |
|
1523 |
InvalidOperationSignal := InvalidOperationError. |
|
1524 |
InvalidOperationSignal notifierString:'unsupported file operation'. |
|
1525 |
||
1526 |
"/ StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false. |
|
1527 |
"/ StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal. |
|
1528 |
StreamNotOpenSignal := StreamNotOpenError. |
|
1529 |
StreamNotOpenSignal notifierString:'stream is not open'. |
|
1530 |
||
1531 |
"/ StreamIOErrorSignal := StreamErrorSignal newSignalMayProceed:false. |
|
1532 |
"/ StreamIOErrorSignal nameClass:self message:#streamIOErrorSignal. |
|
1533 |
StreamIOErrorSignal := StreamIOError. |
|
1534 |
StreamIOErrorSignal notifierString:'I/O error'. |
|
159 | 1535 |
]. |
1536 |
||
31 | 1537 |
Lobby isNil ifTrue:[ |
8074 | 1538 |
Lobby := Registry new. |
1539 |
||
1540 |
"want to get informed when returning from snapshot" |
|
1541 |
ObjectMemory addDependent:self |
|
2920 | 1542 |
]. |
5442 | 1543 |
DefaultEOLMode isNil ifTrue:[ |
8074 | 1544 |
self initDefaultEOLMode. |
5442 | 1545 |
]. |
1546 |
ReadMode isNil ifTrue:[ |
|
8074 | 1547 |
self initModeStrings. |
5442 | 1548 |
]. |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1549 |
"Modified: / 21.5.1998 / 16:33:53 / cg" |
1 | 1550 |
! |
1551 |
||
1552 |
reOpenFiles |
|
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1553 |
"reopen all files (if possible) after a snapShot load. |
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1554 |
This is invoked via the #earlyRestart change notification." |
1 | 1555 |
|
301 | 1556 |
Lobby do:[:aFileStream | |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1557 |
aFileStream reOpen |
2920 | 1558 |
]. |
1 | 1559 |
! |
1560 |
||
1469 | 1561 |
update:something with:aParameter from:changedObject |
1 | 1562 |
"have to reopen files when returning from snapshot" |
1563 |
||
4108
8c4a45bc70eb
perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents:
4093
diff
changeset
|
1564 |
something == #earlyRestart ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1565 |
self reOpenFiles. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1566 |
self initDefaultEOLMode |
1 | 1567 |
] |
1469 | 1568 |
|
1569 |
"Created: 15.6.1996 / 15:19:59 / cg" |
|
1 | 1570 |
! ! |
1571 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1572 |
!ExternalStream class methodsFor:'instance creation'! |
612 | 1573 |
|
2920 | 1574 |
forFileDescriptor:aFileDescriptor mode:modeString |
1575 |
"given a fileDescriptor, create an ExternalStream object |
|
1576 |
to operate on this fd. |
|
1577 |
The mode-argument is passed to the fdopen call. |
|
1578 |
This may be used to wrap fd's as returned by user |
|
1579 |
primitive code, or to wrap pipe-fds into externalStreams." |
|
1580 |
||
7002 | 1581 |
^ self forFileDescriptor:aFileDescriptor mode:modeString buffered:true |
1582 |
||
1583 |
" |
|
1584 |
the example below will probably fail (15 is a random FD): |
|
1585 |
||
1586 |
|s| |
|
1587 |
||
1588 |
s := ExternalStream forFileDescriptor:15 mode:'r'. |
|
1589 |
s next. |
|
1590 |
" |
|
1591 |
||
1592 |
"Created: 29.2.1996 / 18:05:00 / cg" |
|
1593 |
"Modified: 29.2.1996 / 18:17:07 / cg" |
|
1594 |
! |
|
1595 |
||
1596 |
forFileDescriptor:aFileDescriptor mode:modeString buffered:buffered |
|
1597 |
"given a fileDescriptor, create an ExternalStream object |
|
1598 |
to operate on this fd. |
|
1599 |
The mode-argument is passed to the fdopen call. |
|
1600 |
This may be used to wrap fd's as returned by user |
|
1601 |
primitive code, or to wrap pipe-fds into externalStreams." |
|
1602 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1603 |
|newStream| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1604 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1605 |
newStream := self basicNew. |
7002 | 1606 |
newStream text; buffered:buffered; eolMode:DefaultEOLMode; clearEOF. |
3535 | 1607 |
^ newStream connectTo:aFileDescriptor withMode:modeString |
2920 | 1608 |
|
1609 |
" |
|
1610 |
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
|
1611 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1612 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1613 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1614 |
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
|
1615 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1616 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1617 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1618 |
"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
|
1619 |
"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
|
1620 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1621 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1622 |
forReadWriteToFileDescriptor:aFileDescriptor |
2920 | 1623 |
"given a fileDescriptor, create an ExternalStream object |
1624 |
to read/write from/to this fd. This may be used to wrap fd's |
|
1625 |
as returned by user primitive code, or to wrap pipe- |
|
1626 |
filedescriptors into externalStreams." |
|
1627 |
||
3535 | 1628 |
^ (self forFileDescriptor:aFileDescriptor mode:ReadWriteMode) readwrite |
2920 | 1629 |
|
1630 |
" |
|
1631 |
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
|
1632 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1633 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1634 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1635 |
s := ExternalStream forReadWriteToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1636 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1637 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1638 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1639 |
"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
|
1640 |
"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
|
1641 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1642 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1643 |
forReadingFromFileDescriptor:aFileDescriptor |
2920 | 1644 |
"given a fileDescriptor, create an ExternalStream object |
1645 |
to read from this fd. This may be used to wrap fd's |
|
1646 |
as returned by user primitive code, or to wrap pipe- |
|
1647 |
filedescriptors into externalStreams." |
|
1648 |
||
3535 | 1649 |
^ (self forFileDescriptor:aFileDescriptor mode:ReadMode) readonly |
2920 | 1650 |
|
1651 |
" |
|
1652 |
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
|
1653 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1654 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1655 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1656 |
s := ExternalStream forReadingFromFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1657 |
s next. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1658 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1659 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1660 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1661 |
|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
|
1662 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1663 |
'create OS pipe ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1664 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1665 |
pipe := OperatingSystem makePipe. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1666 |
readFd := pipe at:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1667 |
writeFd := pipe at:2. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1668 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1669 |
'connect Smalltalk streams ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1670 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1671 |
rs := ExternalStream forReadingFromFileDescriptor:readFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1672 |
ws := ExternalStream forWritingToFileDescriptor:writeFd. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1673 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1674 |
'read ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1675 |
[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1676 |
1 to:10 do:[:i | |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1677 |
Transcript showCR:rs nextLine |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1678 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1679 |
rs close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1680 |
] forkAt:7. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1681 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1682 |
'write ...'. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1683 |
[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1684 |
1 to:10 do:[:i | |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1685 |
ws nextPutAll:'hello world '; nextPutAll:i printString; cr |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1686 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1687 |
ws close. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1688 |
] fork. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1689 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1690 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1691 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1692 |
"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
|
1693 |
"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
|
1694 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1695 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1696 |
forWritingToFileDescriptor:aFileDescriptor |
2920 | 1697 |
"given a fileDescriptor, create an ExternalStream object |
1698 |
to write to this fd. This may be used to wrap fd's |
|
1699 |
as returned by user primitive code, or to wrap pipe- |
|
1700 |
filedescriptors into externalStreams." |
|
1701 |
||
3535 | 1702 |
^ (self forFileDescriptor:aFileDescriptor mode:WriteMode) writeonly |
2920 | 1703 |
|
1704 |
" |
|
1705 |
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
|
1706 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1707 |
|s| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1708 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1709 |
s := ExternalStream forWritingToFileDescriptor:15. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1710 |
s binary. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1711 |
s nextPut:1. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1712 |
" |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1713 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1714 |
"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
|
1715 |
"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
|
1716 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
1717 |
|
612 | 1718 |
new |
1719 |
|newStream| |
|
1720 |
||
1721 |
newStream := self basicNew. |
|
2920 | 1722 |
newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF. |
612 | 1723 |
^ newStream |
1724 |
! ! |
|
1725 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1726 |
!ExternalStream class methodsFor:'Signal constants'! |
159 | 1727 |
|
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1728 |
inaccessibleSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1729 |
"ST-80 compatibility: return openErrorSignal" |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1730 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1731 |
^ self openErrorSignal |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1732 |
|
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1733 |
"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
|
1734 |
! |
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1735 |
|
612 | 1736 |
invalidModeSignal |
1737 |
"return the signal raised when doing text-I/O with a binary stream |
|
1738 |
or binary-I/O with a text stream" |
|
1739 |
||
8074 | 1740 |
^ InvalidModeError |
159 | 1741 |
! |
1742 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1743 |
invalidOperationSignal |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1744 |
"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
|
1745 |
I/O operation is attempted" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1746 |
|
8074 | 1747 |
^ InvalidOperationError |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1748 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
1749 |
|
159 | 1750 |
invalidReadSignal |
1751 |
"return the signal raised when reading from writeonly streams" |
|
1752 |
||
8074 | 1753 |
^ InvalidReadError |
159 | 1754 |
! |
1755 |
||
1756 |
invalidWriteSignal |
|
1757 |
"return the signal raised when writing to readonly streams" |
|
1758 |
||
8074 | 1759 |
^ InvalidWriteError |
159 | 1760 |
! |
1761 |
||
612 | 1762 |
openErrorSignal |
1763 |
"return the signal raised when a file open failed" |
|
1764 |
||
1765 |
^ OpenErrorSignal |
|
1766 |
! |
|
1767 |
||
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1768 |
streamIOErrorSignal |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1769 |
"return the signal raised when an I/O error occurs. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1770 |
(for example, a device-IO-error, or reading an NFS-dir, |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1771 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1772 |
|
8074 | 1773 |
^ StreamIOError |
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1774 |
|
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1775 |
"Created: / 21.5.1998 / 16:32:55 / cg" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1776 |
! |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
1777 |
|
159 | 1778 |
streamNotOpenSignal |
1779 |
"return the signal raised on I/O with closed streams" |
|
1780 |
||
8074 | 1781 |
^ StreamNotOpenError |
2 | 1782 |
! ! |
1783 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
1784 |
!ExternalStream class methodsFor:'error handling'! |
92 | 1785 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1786 |
errorReporter |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1787 |
"I know about error codes" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1788 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1789 |
^ self |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1790 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1791 |
|
92 | 1792 |
lastErrorNumber |
159 | 1793 |
"return the errno of the last error" |
92 | 1794 |
|
1795 |
^ LastErrorNumber |
|
159 | 1796 |
|
1797 |
" |
|
1798 |
ExternalStream lastErrorNumber |
|
1799 |
" |
|
92 | 1800 |
! |
1801 |
||
1802 |
lastErrorString |
|
1803 |
"return a message string describing the last error" |
|
1804 |
||
1805 |
^ OperatingSystem errorTextForNumber:LastErrorNumber |
|
1806 |
||
1807 |
" |
|
1808 |
ExternalStream lastErrorString |
|
1809 |
" |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1810 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1811 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1812 |
reportOn:anErrorSymbolOrNumber |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1813 |
"an error occured. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1814 |
Report it via an Exception" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1815 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1816 |
anErrorSymbolOrNumber isInteger ifTrue:[ |
8074 | 1817 |
StreamError |
1818 |
raiseRequestWith:anErrorSymbolOrNumber |
|
1819 |
errorString:(' - os error:' , (OperatingSystem errorTextForNumber:anErrorSymbolOrNumber)) |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1820 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1821 |
(self respondsTo:anErrorSymbolOrNumber) ifTrue:[ |
8074 | 1822 |
self perform:anErrorSymbolOrNumber |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1823 |
] ifFalse:[ |
8074 | 1824 |
StreamError |
1825 |
raiseRequestWith:anErrorSymbolOrNumber |
|
1826 |
errorString:(' - ' , anErrorSymbolOrNumber printString) |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1827 |
]. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
1828 |
^ false |
92 | 1829 |
! ! |
1830 |
||
7497
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1831 |
!ExternalStream class methodsFor:'obsolete'! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1832 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1833 |
makePTYPair |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1834 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1835 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1836 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1837 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePTYPair'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1838 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1839 |
^ NonPositionableExternalStream makePTYPair. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1840 |
! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1841 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1842 |
makePipe |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1843 |
"obsolete since 12-07-2003" |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1844 |
<resource:#obsolete> |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1845 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1846 |
self obsoleteMethodWarning:'use NonPositionableExternalStream makePipe'. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1847 |
|
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1848 |
^ NonPositionableExternalStream makePipe. |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1849 |
! ! |
cc29afd51151
Do not block when writing to pipes
Stefan Vogel <sv@exept.de>
parents:
7261
diff
changeset
|
1850 |
|
7261 | 1851 |
!ExternalStream methodsFor:'Compatibility-Dolphin'! |
6474 | 1852 |
|
1853 |
beText |
|
1854 |
self text |
|
1855 |
! ! |
|
1856 |
||
7261 | 1857 |
!ExternalStream methodsFor:'Compatibility-Squeak'! |
3044 | 1858 |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1859 |
nextInto:aByteArrayOrString |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1860 |
"read elements into the argument, whose size determines the amount |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1861 |
of bytes to read. If not enough elements could be read, return |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1862 |
a copy of the argument; otherwise, return the filled argument." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1863 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1864 |
|n nWanted| |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1865 |
|
4368 | 1866 |
nWanted := aByteArrayOrString byteSize. |
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1867 |
n := self nextAvailableBytes:nWanted into:aByteArrayOrString startingAt:1. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1868 |
n == nWanted ifTrue:[^ aByteArrayOrString]. |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1869 |
^ aByteArrayOrString copyTo:n |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1870 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1871 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1872 |
|
4368 | 1873 |
readInto:aContainer startingAt:index count:nElements |
1874 |
"same as #nextBytes:into:startingAt: for ByteArrays; |
|
1875 |
for LongArrays, nelements longs are read. |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1876 |
Squeak compatibility." |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1877 |
|
4368 | 1878 |
|elementSize n| |
1879 |
||
1880 |
elementSize := aContainer class elementByteSize. |
|
1881 |
n := self nextBytes:nElements*elementSize into:aContainer startingAt:1. |
|
1882 |
^ n // elementSize |
|
3872
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1883 |
|
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1884 |
! |
cab901645d2a
added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
3863
diff
changeset
|
1885 |
|
3044 | 1886 |
readOnly |
1887 |
"Squeak compatibility: make the stream readOnly" |
|
1888 |
||
1889 |
mode := #readonly |
|
1890 |
||
1891 |
"Modified: 20.10.1997 / 19:23:04 / cg" |
|
1892 |
"Created: 20.10.1997 / 19:23:19 / cg" |
|
1893 |
! ! |
|
1894 |
||
5187 | 1895 |
!ExternalStream methodsFor:'Signal constants'! |
1896 |
||
1897 |
invalidReadSignal |
|
1898 |
^ self class invalidReadSignal |
|
1899 |
||
1900 |
"Created: / 3.12.1998 / 15:12:06 / cg" |
|
1901 |
! |
|
1902 |
||
1903 |
invalidWriteSignal |
|
1904 |
^ self class invalidWriteSignal |
|
1905 |
||
1906 |
"Created: / 3.12.1998 / 15:12:10 / cg" |
|
1907 |
! ! |
|
1908 |
||
1 | 1909 |
!ExternalStream methodsFor:'accessing'! |
1910 |
||
612 | 1911 |
binary |
1912 |
"switch to binary mode - default is text" |
|
1913 |
||
1914 |
binary := true |
|
1 | 1915 |
! |
1916 |
||
1917 |
buffered:aBoolean |
|
10 | 1918 |
"turn buffering on or off - default is on" |
1 | 1919 |
|
10 | 1920 |
buffered := aBoolean |
1 | 1921 |
! |
1922 |
||
1923 |
contents |
|
2 | 1924 |
"return the contents of the file from the current position up-to |
1925 |
the end. If the stream is in binary mode, a ByteArray containing |
|
1926 |
the byte values is returned. |
|
1927 |
In text-mode, a collection of strings, each representing one line, |
|
1928 |
is returned." |
|
1929 |
||
1930 |
|text l chunks sizes chunk byteCount cnt bytes offset| |
|
1931 |
||
1932 |
binary ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1933 |
"adding to a ByteArray produces quadratic time-space |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1934 |
behavior - therefore we allocate chunks, and concatenate them |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1935 |
at the end." |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1936 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1937 |
chunks := OrderedCollection new. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1938 |
sizes := OrderedCollection new. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1939 |
byteCount := 0. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1940 |
[self atEnd] whileFalse:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1941 |
chunk := ByteArray uninitializedNew:4096. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1942 |
cnt := self nextBytes:(chunk size) into:chunk. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1943 |
cnt notNil ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1944 |
chunks add:chunk. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1945 |
sizes add:cnt. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1946 |
byteCount := byteCount + cnt |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1947 |
] |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1948 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1949 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1950 |
"now, create one big ByteArray" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1951 |
bytes := ByteArray uninitializedNew:byteCount. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1952 |
offset := 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1953 |
1 to:chunks size do:[:index | |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1954 |
chunk := chunks at:index. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1955 |
cnt := sizes at:index. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1956 |
bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1957 |
offset := offset + cnt |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1958 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1959 |
^ bytes |
2 | 1960 |
]. |
1 | 1961 |
|
244 | 1962 |
text := StringCollection new. |
1 | 1963 |
[self atEnd] whileFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1964 |
l := self nextLine. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1965 |
l isNil ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1966 |
^ text |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1967 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1968 |
text add:l |
1 | 1969 |
]. |
1970 |
^ text |
|
1971 |
! |
|
1972 |
||
612 | 1973 |
contentsOfEntireFile |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1974 |
"ST-80 compatibility: return contents as a String (or byteArray, if in binary mode). |
3876 | 1975 |
See also #contents, which returns the lines as stringCollection for text files." |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1976 |
|
6305 | 1977 |
binary ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1978 |
^ self contents. |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1979 |
]. |
6305 | 1980 |
^ self upToEnd |
1522
1d0b4bc2e563
ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents:
1515
diff
changeset
|
1981 |
|
3876 | 1982 |
"Modified: / 3.7.1996 / 13:22:16 / stefan" |
3938
4e7d1880336b
oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents:
3906
diff
changeset
|
1983 |
"Modified: / 27.11.1998 / 16:29:43 / cg" |
2 | 1984 |
! |
1985 |
||
612 | 1986 |
contentsSpecies |
1987 |
"return the kind of object to be returned by sub-collection builders |
|
1988 |
(such as upTo)" |
|
159 | 1989 |
|
5441 | 1990 |
binary == true ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1991 |
^ ByteArray |
159 | 1992 |
]. |
612 | 1993 |
^ String |
2 | 1994 |
! |
1995 |
||
2920 | 1996 |
eolMode:aSymbolOrNil |
1997 |
"specify how end-of-line (EOL) is to be marked. |
|
1998 |
The argument may be one of: |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
1999 |
#crlf -> add a CR-NL, as in MSDOS |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2000 |
#cr -> add a CR, as in VMS |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2001 |
#nl -> add a NL, as in Unix |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2002 |
anyOther -> like #nl |
2920 | 2003 |
" |
2004 |
||
2005 |
eolMode := aSymbolOrNil |
|
2006 |
! |
|
2007 |
||
612 | 2008 |
fileDescriptor |
2009 |
"return the fileDescriptor of the receiver - |
|
2010 |
notice: this one returns the underlying OSs fileDescriptor - |
|
2011 |
this may not be available on all platforms (i.e. non unix systems)." |
|
1 | 2012 |
|
3971 | 2013 |
%{ |
612 | 2014 |
OBJ fp; |
2015 |
||
1133 | 2016 |
if ((fp = __INST(filePointer)) != nil) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2017 |
FILEPOINTER f; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2018 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2019 |
f = __FILEVal(fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2020 |
RETURN ( __MKINT(fileno(f)) ); |
1 | 2021 |
} |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2022 |
%}. |
5852 | 2023 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2024 |
^ self fileDescriptorOfFile:filePointer |
|
2025 |
! |
|
2026 |
||
2027 |
fileDescriptorOfFile:filePointer |
|
2028 |
"for migration to rel5 only: |
|
2029 |
return the fileDescriptor of the argument filePointer - |
|
2030 |
notice: this one returns the underlying OSs fileDescriptor - |
|
2031 |
this may not be available on all platforms (i.e. non unix systems)." |
|
2032 |
||
2033 |
self primitiveFailed |
|
612 | 2034 |
! |
2035 |
||
2036 |
filePointer |
|
2037 |
"return the filePointer of the receiver - |
|
2038 |
notice: for portability stdio is used; this means you will get |
|
2039 |
a FILE * - not a fileDescriptor. |
|
2040 |
(what you really get is a corresponding integer). |
|
2041 |
You cannot do much with the returned value |
|
2042 |
- except passing it to a primitive, for example." |
|
2043 |
||
2044 |
^ filePointer |
|
2045 |
! |
|
2046 |
||
5323 | 2047 |
lineEndCRLF |
2048 |
eolMode := #crlf |
|
2049 |
! |
|
2050 |
||
3016 | 2051 |
lineEndTransparent |
2052 |
eolMode := #cr |
|
2053 |
! |
|
2054 |
||
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2055 |
pathName |
8070 | 2056 |
^ nil |
8069
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2057 |
! |
fdf460457c96
acessing: pathName added (returns nil)
Michael Beyl <mb@exept.de>
parents:
8066
diff
changeset
|
2058 |
|
612 | 2059 |
readonly |
2060 |
"set access mode to readonly" |
|
2061 |
||
2062 |
mode := #readonly |
|
2063 |
! |
|
2064 |
||
2065 |
readwrite |
|
2066 |
"set access mode to readwrite" |
|
2067 |
||
2068 |
mode := #readwrite |
|
2069 |
! |
|
2070 |
||
2071 |
text |
|
2072 |
"switch to text mode - default is text" |
|
2073 |
||
2074 |
binary := false |
|
2075 |
! |
|
2076 |
||
2077 |
useCRLF:aBoolean |
|
2920 | 2078 |
"turn on or off CRLF sending (instead of LF only) - default is off. |
2079 |
This method is provided for backward compatibility - see #eolMode: |
|
2080 |
which offers another choice." |
|
2081 |
||
2082 |
aBoolean ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2083 |
eolMode := #crlf |
2920 | 2084 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2085 |
eolMode := #nl |
2920 | 2086 |
]. |
1 | 2087 |
! |
2088 |
||
612 | 2089 |
writeonly |
2090 |
"set access mode to writeonly" |
|
2091 |
||
2092 |
mode := #writeonly |
|
2093 |
! ! |
|
2094 |
||
2095 |
!ExternalStream methodsFor:'error handling'! |
|
2096 |
||
2097 |
argumentMustBeCharacter |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2098 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2099 |
|
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
2100 |
"report an error, that the argument must be a character in 0..FF" |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
2101 |
|
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
2102 |
^ self error:'argument must be a single byte character' |
612 | 2103 |
! |
2104 |
||
2105 |
argumentMustBeInteger |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2106 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2107 |
|
612 | 2108 |
"report an error, that the argument must be an integer" |
2109 |
||
2110 |
^ self error:'argument must be an integer' |
|
77 | 2111 |
! |
2112 |
||
612 | 2113 |
argumentMustBeString |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2114 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2115 |
|
612 | 2116 |
"report an error, that the argument must be a string" |
2117 |
||
2118 |
^ self error:'argument must be a string' |
|
2119 |
! |
|
2120 |
||
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2121 |
errorAlreadyOpen |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2122 |
"{ Pragma: +optSpace }" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2123 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2124 |
"report an error, that the stream is already opened" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2125 |
|
8074 | 2126 |
^ OpenError |
2127 |
raiseRequestWith:self |
|
2128 |
errorString:(self class name , ' is already open') |
|
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2129 |
|
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2130 |
"Modified: / 8.5.1999 / 20:12:30 / cg" |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2131 |
! |
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
2132 |
|
612 | 2133 |
errorBinary |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2134 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2135 |
|
612 | 2136 |
"report an error, that the stream is in binary mode" |
2137 |
||
8074 | 2138 |
^ InvalidModeError |
2139 |
raiseWith:self |
|
2140 |
errorString:(self class name , ' is in binary mode') |
|
2141 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2142 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2143 |
"Modified: / 8.5.1999 / 20:12:43 / cg" |
612 | 2144 |
! |
2145 |
||
2146 |
errorNotBinary |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2147 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2148 |
|
612 | 2149 |
"report an error, that the stream is not in binary mode" |
2150 |
||
8074 | 2151 |
^ InvalidModeError |
2152 |
raiseWith:self |
|
2153 |
errorString:(self class name , ' is not in binary mode') |
|
2154 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2155 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2156 |
"Modified: / 8.5.1999 / 20:12:40 / cg" |
1 | 2157 |
! |
2158 |
||
612 | 2159 |
errorNotBuffered |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2160 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2161 |
|
612 | 2162 |
"report an error, that the stream is not in buffered mode" |
2163 |
||
8074 | 2164 |
^ StreamError |
2165 |
raiseRequestWith:self |
|
2166 |
errorString:(self class name , ' is unbuffered - operation not allowed') |
|
2167 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2168 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2169 |
"Modified: / 8.5.1999 / 20:12:36 / cg" |
612 | 2170 |
! |
2171 |
||
2172 |
errorNotOpen |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2173 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2174 |
|
612 | 2175 |
"report an error, that the stream has not been opened" |
2176 |
||
8074 | 2177 |
^ StreamNotOpenError |
2178 |
raiseWith:self |
|
2179 |
errorString:(self class name , ' not open') |
|
2180 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2181 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2182 |
"Modified: / 8.5.1999 / 20:12:33 / cg" |
612 | 2183 |
! |
2184 |
||
2185 |
errorReadOnly |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2186 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2187 |
|
612 | 2188 |
"report an error, that the stream is a readOnly stream" |
2189 |
||
8074 | 2190 |
^ InvalidWriteSignal |
2191 |
raiseWith:self |
|
2192 |
errorString:(self class name , ' is readonly') |
|
2193 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2194 |
|
4468 | 2195 |
"Modified: / 30.7.1999 / 17:08:19 / cg" |
612 | 2196 |
! |
2197 |
||
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2198 |
errorReporter |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2199 |
"ST-80 mimicry." |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2200 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
2201 |
^ self class |
6255
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2202 |
! |
d68343dc8288
Define #errorReporter and #reportError: (ST-80 protocol)
Stefan Vogel <sv@exept.de>
parents:
6012
diff
changeset
|
2203 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2204 |
errorUnsupportedOperation |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2205 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2206 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2207 |
"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
|
2208 |
|
8074 | 2209 |
^ InvalidOperationError |
2210 |
raiseWith:self |
|
2211 |
errorString:'unsupported operation' |
|
2212 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2213 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2214 |
"Modified: / 8.5.1999 / 20:12:24 / cg" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2215 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
2216 |
|
612 | 2217 |
errorWriteOnly |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2218 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2219 |
|
612 | 2220 |
"report an error, that the stream is a writeOnly stream" |
2221 |
||
8074 | 2222 |
^ InvalidReadError |
2223 |
raiseWith:self |
|
2224 |
errorString:(self class name , ' is writeonly') |
|
2225 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2226 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2227 |
"Modified: / 8.5.1999 / 20:12:20 / cg" |
2 | 2228 |
! |
2229 |
||
612 | 2230 |
ioError |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2231 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2232 |
|
3474
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2233 |
"report an error, that some I/O error occured. |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2234 |
(for example, a device-IO-error, or reading an NFS-dir, |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2235 |
which is no longer available and has been mounted soft)" |
1af4d150dab4
added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents:
3467
diff
changeset
|
2236 |
|
8074 | 2237 |
^ StreamIOError |
2238 |
raiseWith:self |
|
2239 |
errorString:('I/O error: ' , self lastErrorString) |
|
2240 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2241 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2242 |
"Modified: / 8.5.1999 / 20:12:16 / cg" |
612 | 2243 |
! |
2244 |
||
2245 |
lastErrorNumber |
|
2246 |
"return the last error" |
|
2247 |
||
2248 |
^ lastErrorNumber |
|
2249 |
! |
|
2250 |
||
2251 |
lastErrorString |
|
2252 |
"return a message string describing the last error" |
|
2253 |
||
2254 |
(lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2255 |
^ 'I/O error' |
612 | 2256 |
]. |
2257 |
^ OperatingSystem errorTextForNumber:lastErrorNumber |
|
2 | 2258 |
! |
2259 |
||
612 | 2260 |
openError |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2261 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2262 |
|
8007
adfabcb563e0
openError backWard compatibility.
Claus Gittinger <cg@exept.de>
parents:
7887
diff
changeset
|
2263 |
"/ for backward compatibility, use: |
adfabcb563e0
openError backWard compatibility.
Claus Gittinger <cg@exept.de>
parents:
7887
diff
changeset
|
2264 |
"/ self class openErrorSignal isHandled ifFalse:[^ nil]. |
adfabcb563e0
openError backWard compatibility.
Claus Gittinger <cg@exept.de>
parents:
7887
diff
changeset
|
2265 |
|
8008
e80739d6c312
openError backWard compatibility.
Claus Gittinger <cg@exept.de>
parents:
8007
diff
changeset
|
2266 |
"/ or even: |
e80739d6c312
openError backWard compatibility.
Claus Gittinger <cg@exept.de>
parents:
8007
diff
changeset
|
2267 |
"/ ^ nil. |
e80739d6c312
openError backWard compatibility.
Claus Gittinger <cg@exept.de>
parents:
8007
diff
changeset
|
2268 |
|
612 | 2269 |
"report an error, that the open failed" |
8070 | 2270 |
^ OpenError |
8283
8fe0314f8d5a
openErrorSignal arg: never a string
Claus Gittinger <cg@exept.de>
parents:
8209
diff
changeset
|
2271 |
raiseRequestWith:self |
8fe0314f8d5a
openErrorSignal arg: never a string
Claus Gittinger <cg@exept.de>
parents:
8209
diff
changeset
|
2272 |
errorString:('error on open: ' , self lastErrorString) |
8fe0314f8d5a
openErrorSignal arg: never a string
Claus Gittinger <cg@exept.de>
parents:
8209
diff
changeset
|
2273 |
"/ in:thisContext sender |
3235
cc254b307159
FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3221
diff
changeset
|
2274 |
|
cc254b307159
FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents:
3221
diff
changeset
|
2275 |
"Modified: / 28.1.1998 / 14:37:42 / stefan" |
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2276 |
"Modified: / 8.5.1999 / 20:12:12 / cg" |
612 | 2277 |
! |
2278 |
||
2279 |
readError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2280 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2281 |
|
612 | 2282 |
"report an error, that some read error occured" |
2283 |
||
8074 | 2284 |
^ ReadError |
2285 |
raiseRequestWith:self |
|
2286 |
errorString:('read error: ' , self lastErrorString) |
|
2287 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2288 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2289 |
"Modified: / 8.5.1999 / 20:12:00 / cg" |
612 | 2290 |
! |
2291 |
||
2292 |
writeError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2293 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
2294 |
|
612 | 2295 |
"report an error, that some write error occured" |
2296 |
||
8074 | 2297 |
^ WriteError |
2298 |
raiseRequestWith:self |
|
2299 |
errorString:('write error: ' , self lastErrorString) |
|
2300 |
"/ in:thisContext sender |
|
4161
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2301 |
|
3f2758cfeff5
raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents:
4152
diff
changeset
|
2302 |
"Modified: / 8.5.1999 / 20:12:09 / cg" |
612 | 2303 |
! ! |
2304 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2305 |
!ExternalStream methodsFor:'finalization'! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2306 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2307 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2308 |
"answer the registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2309 |
ExternalStreams have their own Registry" |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2310 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2311 |
^ Lobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2312 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2313 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2314 |
finalize |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2315 |
"some Stream has been collected - close the file if not already done" |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2316 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2317 |
self closeFile |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2318 |
! ! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6441
diff
changeset
|
2319 |
|
612 | 2320 |
!ExternalStream methodsFor:'instance release'! |
2321 |
||
2322 |
closeFile |
|
2323 |
"low level close - may be redefined in subclasses" |
|
2 | 2324 |
|
5494 | 2325 |
|fp| |
2326 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2327 |
%{ |
1133 | 2328 |
if ((fp = __INST(filePointer)) != nil) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2329 |
FILEPOINTER f; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2330 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2331 |
__INST(filePointer) = nil; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2332 |
f = __FILEVal(fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2333 |
if (@global(FileOpenTrace) == true) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2334 |
fprintf(stderr, "fclose [ExternalStream] %x\n", f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2335 |
} |
5620
c50610309c38
separated close from free (i.e. avoid using fclose);
Claus Gittinger <cg@exept.de>
parents:
5618
diff
changeset
|
2336 |
#ifdef WIN32 |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2337 |
__BEGIN_INTERRUPTABLE__ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2338 |
__STX_C_CALL1((void*)fclose, (void*)f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2339 |
__END_INTERRUPTABLE__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
2340 |
#else |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2341 |
__BEGIN_INTERRUPTABLE__ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2342 |
fclose(f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2343 |
__END_INTERRUPTABLE__ |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
2344 |
#endif |
10 | 2345 |
} |
5494 | 2346 |
RETURN (self); |
2347 |
%}. |
|
2348 |
"/ fallback for rel5 |
|
2349 |
||
2350 |
fp := filePointer. |
|
2351 |
fp notNil ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2352 |
filePointer := nil. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2353 |
self closeFile:fp |
5494 | 2354 |
] |
2355 |
! |
|
2356 |
||
2357 |
closeFile:filePointer |
|
2358 |
"for rel5 only" |
|
2359 |
||
2360 |
self primitiveFailed |
|
10 | 2361 |
! |
2362 |
||
6441
2be4aa0d2991
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6305
diff
changeset
|
2363 |
executor |
2be4aa0d2991
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6305
diff
changeset
|
2364 |
"return a copy for finalization-registration; |
2be4aa0d2991
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6305
diff
changeset
|
2365 |
since all we need at finalization time is the fileDescriptor, |
2be4aa0d2991
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6305
diff
changeset
|
2366 |
a cheaper copy is possible." |
2be4aa0d2991
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6305
diff
changeset
|
2367 |
|
2be4aa0d2991
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6305
diff
changeset
|
2368 |
^ self class basicNew setFilePointer:filePointer |
2be4aa0d2991
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6305
diff
changeset
|
2369 |
! |
2be4aa0d2991
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6305
diff
changeset
|
2370 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2371 |
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
|
2372 |
"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
|
2373 |
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
|
2374 |
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
|
2375 |
|
3681 | 2376 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2377 |
FILEPOINTER f; |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2378 |
OBJ fp; |
2765 | 2379 |
FILE *fdopen(); |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2380 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2381 |
if (__isSmallInteger(anInteger) && |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2382 |
__isString(openMode) && |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2383 |
(f = fdopen(__intVal(anInteger), __stringVal(openMode))) != 0 |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2384 |
) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2385 |
if (@global(FileOpenTrace) == true) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2386 |
fprintf(stderr, "fdopen [ExternalStream] %d -> %x\n", __intVal(anInteger), f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2387 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2388 |
__PROTECT__(self); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2389 |
fp = __MKFILEPOINTER(f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2390 |
__UNPROTECT__(self); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2391 |
__INST(filePointer) = fp; __STORE(self, fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2392 |
RETURN (self); |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2393 |
} |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2394 |
%}. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2395 |
^ self primitiveFailed |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2396 |
! |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2397 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2398 |
setFilePointer:something |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2399 |
"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
|
2400 |
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
|
2401 |
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
|
2402 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2403 |
filePointer := something |
1 | 2404 |
! |
2405 |
||
612 | 2406 |
shutDown |
2407 |
"close the stream - added for protocol compatibility with PipeStream. |
|
2408 |
see comment there" |
|
2409 |
||
3949 | 2410 |
self isOpen ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2411 |
Lobby unregister:self. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2412 |
self closeFile |
3949 | 2413 |
] |
1642
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
2414 |
|
91c6860f1c9d
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
2415 |
"Modified: 30.8.1996 / 00:39:21 / cg" |
1 | 2416 |
! ! |
2417 |
||
2 | 2418 |
!ExternalStream methodsFor:'line reading/writing'! |
1 | 2419 |
|
2420 |
nextLine |
|
2421 |
"read the next line (characters up to newline). |
|
2422 |
Return a string containing those characters excluding the newline. |
|
2423 |
If the previous-to-last character is a cr, this is also removed, |
|
68 | 2424 |
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
|
2425 |
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
|
2426 |
|
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2427 |
|line| |
971
eb70f5674303
max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents:
933
diff
changeset
|
2428 |
|
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
2429 |
%{ /* STACK:34000 */ |
1 | 2430 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2431 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2432 |
int len, ret; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
2433 |
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
|
2434 |
char *rslt, *nextPtr, *limit; |
22 | 2435 |
int fd, ch; |
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
2436 |
int _buffered; |
216 | 2437 |
OBJ fp; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2438 |
int lineTooLong = 0; |
2920 | 2439 |
int cutOff = 0; |
1 | 2440 |
|
1133 | 2441 |
__INST(lastErrorNumber) = nil; |
2442 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 2443 |
&& (__INST(mode) != @symbol(writeonly)) |
2444 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2445 |
) { |
8070 | 2446 |
f = __FILEVal(fp); |
2447 |
buffer[0] = '\0'; |
|
2448 |
||
2449 |
_buffered = (__INST(buffered) == true); |
|
2450 |
if (_buffered) { |
|
2451 |
__READING__(f); |
|
2452 |
} |
|
2453 |
||
2454 |
rslt = nextPtr = buffer; |
|
2455 |
limit = buffer + sizeof(buffer) - 2; |
|
2456 |
||
2457 |
for (;;) { |
|
2458 |
__READBYTE__(ret, f, nextPtr, _buffered); |
|
2459 |
if (ret <= 0) { |
|
2460 |
if (nextPtr == buffer) |
|
2461 |
rslt = NULL; |
|
2462 |
if (ret == 0) { |
|
2463 |
__INST(hitEOF) = true; |
|
2464 |
break; |
|
2465 |
} else { |
|
2466 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
2467 |
goto err; |
|
2468 |
} |
|
2469 |
} |
|
2470 |
||
2471 |
if (*nextPtr == '\n') { |
|
2472 |
cutOff = 1; |
|
2473 |
*nextPtr = '\0'; |
|
2474 |
break; |
|
2475 |
} |
|
2476 |
if (*nextPtr == '\r') { |
|
2477 |
char peekChar; |
|
2478 |
||
2479 |
/* |
|
2480 |
* peek ahead for a newLine ... |
|
2481 |
*/ |
|
2482 |
__READBYTE__(ret, f, &peekChar, _buffered); |
|
2483 |
if (ret <= 0) { |
|
2484 |
cutOff = 1; |
|
2485 |
*nextPtr = '\0'; |
|
2486 |
if (ret == 0) { |
|
2487 |
__INST(hitEOF) = true; |
|
2488 |
break; |
|
2489 |
} |
|
2490 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
2491 |
goto err; |
|
2492 |
} |
|
2493 |
||
2494 |
if (peekChar == '\n') { |
|
2495 |
cutOff = 2; |
|
2496 |
*nextPtr = '\0'; |
|
2497 |
break; |
|
2498 |
} |
|
2499 |
||
2500 |
__UNGETC__(peekChar, f, _buffered); |
|
2501 |
||
2502 |
cutOff = 1; |
|
2503 |
*nextPtr = '\0'; |
|
2504 |
break; |
|
2505 |
} |
|
2506 |
||
2507 |
nextPtr++; |
|
2508 |
if (nextPtr >= limit) { |
|
2509 |
*nextPtr = '\0'; |
|
2510 |
lineTooLong = 1; |
|
2511 |
if (@global(InfoPrinting) == true) { |
|
2512 |
fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n"); |
|
2513 |
} |
|
2514 |
break; |
|
2515 |
} |
|
2516 |
} |
|
2517 |
||
2518 |
if (rslt != NULL) { |
|
2519 |
len = nextPtr-buffer; |
|
2520 |
||
2521 |
if (__isSmallInteger(__INST(position))) { |
|
2522 |
INT np = __intVal(__INST(position)) + len + cutOff; |
|
2523 |
OBJ t; |
|
2524 |
||
2525 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
2526 |
} else { |
|
2527 |
__INST(position) = nil; /* i.e. do not know */ |
|
2528 |
} |
|
2529 |
/* remove any EOL character */ |
|
2530 |
if (len != 0) { |
|
2531 |
if (buffer[len-1] == '\n') { |
|
2532 |
buffer[--len] = '\0'; |
|
2533 |
} |
|
2534 |
if ((len != 0) && (buffer[len-1] == '\r')) { |
|
2535 |
buffer[--len] = '\0'; |
|
2536 |
} |
|
2537 |
} |
|
2538 |
line = __MKSTRING_L(buffer, len); |
|
2539 |
if (! lineTooLong) { |
|
2540 |
RETURN ( line ); |
|
2541 |
} |
|
2542 |
} |
|
1 | 2543 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
2544 |
err: ; |
159 | 2545 |
%}. |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2546 |
line notNil ifTrue:[ |
8070 | 2547 |
"/ the line as read is longer than 32k characters (boy - what a line) |
2548 |
"/ The exception could be handled by reading more and returning the |
|
2549 |
"/ concatenation in your exception handler (the receiver and the partial |
|
2550 |
"/ line are passed as parameter) |
|
2551 |
||
2552 |
LineTooLongErrorSignal isHandled ifTrue:[ |
|
2553 |
^ LineTooLongErrorSignal |
|
2554 |
raiseRequestWith:(Array with:self with:line) |
|
2555 |
errorString:('line too long read error') |
|
2556 |
]. |
|
2557 |
^ line , self nextLine |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2558 |
]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
2559 |
|
5431 | 2560 |
(hitEOF == true) ifTrue:[^ self pastEnd]. |
159 | 2561 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
2 | 2562 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
1 | 2563 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
5431 | 2564 |
(binary == true) ifTrue:[^ self errorBinary]. |
2565 |
^ super nextLine |
|
1 | 2566 |
! |
2567 |
||
2568 |
nextPutLine:aString |
|
2920 | 2569 |
"write the characters in aString and append an end-of-Line marker |
2570 |
(LF, CR or CRLF - depending in the setting of eolMode)" |
|
1 | 2571 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2572 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2573 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2574 |
int len, cnt, len1, _buffered; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
2575 |
OBJ fp; |
537
dc4dad8a5ddd
many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2576 |
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
|
2577 |
int o_offs; |
1 | 2578 |
|
1133 | 2579 |
__INST(lastErrorNumber) = nil; |
2580 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 2581 |
&& (__INST(mode) != @symbol(readonly)) |
2582 |
&& (__INST(binary) != true) |
|
2583 |
&& __isString(aString) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2584 |
) { |
8070 | 2585 |
f = __FILEVal(fp); |
2586 |
len = __stringSize(aString); |
|
2587 |
||
2588 |
if (_buffered = (__INST(buffered) == true)) { |
|
2589 |
__WRITING__(f) |
|
2590 |
} |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
2591 |
#ifdef BUGGY |
8070 | 2592 |
__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
|
2593 |
#else |
8070 | 2594 |
o_offs = (char *)__stringVal(aString)-(char *)aString; |
2595 |
__WRITEBYTES_OBJ__(cnt, f, aString, o_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
|
2596 |
#endif |
8070 | 2597 |
if (cnt == len) { |
2598 |
OBJ mode = __INST(eolMode); |
|
2599 |
||
2600 |
len1 = len; |
|
2601 |
||
2602 |
if (mode == @symbol(cr)) { |
|
2603 |
cp = "\r"; len = 1; |
|
2604 |
} else if (mode == @symbol(crlf)) { |
|
2605 |
cp = "\r\n"; len = 2; |
|
2606 |
} else { |
|
2607 |
cp = "\n"; len = 1; |
|
2608 |
} |
|
2609 |
__WRITEBYTES__(cnt, f, cp, len, _buffered); |
|
2610 |
||
2611 |
if (cnt > 0) { |
|
2612 |
if (__isSmallInteger(__INST(position))) { |
|
2613 |
INT np = __intVal(__INST(position)) + cnt; |
|
2614 |
OBJ t; |
|
2615 |
||
2616 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
2617 |
} else { |
|
2618 |
__INST(position) = nil; /* i.e. do not know */ |
|
2619 |
} |
|
2620 |
RETURN ( self ); |
|
2621 |
} |
|
2622 |
} |
|
2623 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
1 | 2624 |
} |
159 | 2625 |
%}. |
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
2626 |
super nextPutLine:aString. |
1 | 2627 |
! |
2628 |
||
2629 |
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil |
|
68 | 2630 |
"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
|
2631 |
and append all lines to self. |
159 | 2632 |
Can be used to copy/create large files or copy from a pipe/socket. |
68 | 2633 |
|
22 | 2634 |
If aStringOrNil is nil or not matched, copy preceeds to the end. |
2635 |
(this allows for example to read a Socket and transfer the data quickly |
|
2636 |
into a file - without creating zillions of temporary strings)" |
|
1 | 2637 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2638 |
|srcFilePointer readError line| |
1 | 2639 |
|
2331 | 2640 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
2641 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
1 | 2642 |
srcFilePointer := aStream filePointer. |
2331 | 2643 |
srcFilePointer isNil ifTrue:[aStream errorNotOpen. ^ self]. |
12 | 2644 |
|
2645 |
%{ /* STACK:2000 */ |
|
22 | 2646 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2647 |
#ifndef NO_STDIO |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2648 |
FILEPOINTER dst; |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2649 |
FILEPOINTER src; |
1 | 2650 |
char *matchString; |
2651 |
int matchLen = 0; |
|
12 | 2652 |
char buffer[1024]; |
1 | 2653 |
|
1133 | 2654 |
__INST(lastErrorNumber) = nil; |
249 | 2655 |
if (__isSmallInteger(srcFilePointer)) { |
8070 | 2656 |
if ((aStringOrNil == nil) || __isString(aStringOrNil)) { |
2657 |
if (aStringOrNil != nil) { |
|
2658 |
matchString = (char *) __stringVal(aStringOrNil); |
|
2659 |
matchLen = __stringSize(aStringOrNil); |
|
2660 |
} |
|
2661 |
dst = __FILEVal(__INST(filePointer)); |
|
2662 |
src = __FILEVal(srcFilePointer); |
|
2663 |
__BEGIN_INTERRUPTABLE__ |
|
2664 |
__threadErrno = 0; |
|
2665 |
||
2666 |
__WRITING__(dst) |
|
2667 |
||
2668 |
for (;;) { |
|
2669 |
if (fgets(buffer, sizeof(buffer)-1, src) == NULL) { |
|
2670 |
if (ferror(src)) { |
|
2671 |
readError = __MKSMALLINT(__threadErrno); |
|
2672 |
__END_INTERRUPTABLE__ |
|
2673 |
goto err; |
|
2674 |
} |
|
2675 |
break; |
|
2676 |
} |
|
2677 |
if (fputs(buffer, dst) == EOF) { |
|
2678 |
if (ferror(dst)) { |
|
2679 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
2680 |
__END_INTERRUPTABLE__ |
|
2681 |
goto err; |
|
2682 |
} |
|
2683 |
break; |
|
2684 |
} |
|
12 | 2685 |
#ifndef OLD |
8070 | 2686 |
if (__INST(buffered) == false) { |
2687 |
FFLUSH(dst); |
|
2688 |
} |
|
12 | 2689 |
#endif |
8070 | 2690 |
if (matchLen) { |
2691 |
if (strncmp(matchString, buffer, matchLen) == 0) |
|
2692 |
break; |
|
2693 |
} |
|
2694 |
} |
|
2695 |
__END_INTERRUPTABLE__ |
|
2696 |
__INST(position) = nil; /* i.e. do not know */ |
|
2697 |
RETURN (self); |
|
2698 |
} |
|
1 | 2699 |
} |
159 | 2700 |
err: ; |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2701 |
#endif /* ! NO_STDIO */ |
159 | 2702 |
%}. |
2703 |
readError ifTrue:[ |
|
8070 | 2704 |
aStream setLastErrorNumber:readError. |
2705 |
aStream readError. |
|
2706 |
^ self |
|
159 | 2707 |
]. |
2331 | 2708 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
2709 |
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
|
2710 |
|
159 | 2711 |
" |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2712 |
argument error or unimplemented; try it linewise |
159 | 2713 |
" |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2714 |
[aStream atEnd] whileFalse:[ |
8070 | 2715 |
line := aStream nextLine. |
2716 |
line isNil ifTrue:[ |
|
2717 |
^ self. |
|
2718 |
]. |
|
2719 |
self nextPutLine:line. |
|
2720 |
(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[ |
|
2721 |
^ self |
|
2722 |
] |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2723 |
]. |
1 | 2724 |
! |
2725 |
||
2726 |
peekForLineStartingWith:aString |
|
2727 |
"read ahead for next line starting with aString; |
|
159 | 2728 |
return the line-string if found, or nil if EOF is encountered. |
7118 | 2729 |
If matched, do not advance position beyond that line |
159 | 2730 |
i.e. nextLine will read the matched line. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2731 |
If not matched, reposition to original position for further reading." |
1 | 2732 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2733 |
|firstPos lastPos line| |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2734 |
|
1 | 2735 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
2736 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2 | 2737 |
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
|
2738 |
buffered ifFalse:[^ self errorNotBuffered]. |
12 | 2739 |
|
2740 |
%{ /* STACK: 2000 */ |
|
2920 | 2741 |
#ifndef NO_STDIO |
2742 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2743 |
FILEPOINTER f; |
1 | 2744 |
int l; |
12 | 2745 |
char buffer[1024]; |
1 | 2746 |
char *cp; |
2747 |
char *matchString; |
|
2920 | 2748 |
int gotFirst = 0; |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7875
diff
changeset
|
2749 |
#if defined(__VMS__) |
2920 | 2750 |
fpos_t firstpos, lastpos; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2751 |
# define FTELL(__f__, __pos__) fgetpos(__f__, &(__pos__)) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2752 |
# define FSEEK(__f__, __pos__) fsetpos(__f__, &(__pos__)) |
7883
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7875
diff
changeset
|
2753 |
#elif defined(_LFS_LARGEFILE) |
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7875
diff
changeset
|
2754 |
off_t firstpos, lastpos; |
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7875
diff
changeset
|
2755 |
# define FTELL(__f__, __pos__) __pos__ = ftello(__f__) |
1039acd0624b
Large file support (off_t with 64 bits) for UNIX
Stefan Vogel <sv@exept.de>
parents:
7875
diff
changeset
|
2756 |
# define FSEEK(__f__, __pos__) fseeko(__f__, __pos__, SEEK_SET) |
2920 | 2757 |
#else |
2758 |
long firstpos, lastpos; |
|
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2759 |
# define FTELL(__f__, __pos__) __pos__ = ftell(__f__) |
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
2760 |
# define FSEEK(__f__, __pos__) fseek(__f__, __pos__, SEEK_SET) |
2920 | 2761 |
#endif |
2762 |
||
1133 | 2763 |
__INST(lastErrorNumber) = nil; |
54 | 2764 |
if (__isString(aString)) { |
8070 | 2765 |
matchString = (char *) __stringVal(aString); |
2766 |
l = __stringSize(aString); |
|
2767 |
||
2768 |
f = __FILEVal(__INST(filePointer)); |
|
2769 |
__READING__(f) |
|
2770 |
||
2771 |
for (;;) { |
|
2772 |
FTELL(f, lastpos); |
|
2773 |
if (!gotFirst) { |
|
2774 |
firstpos = lastpos; |
|
2775 |
gotFirst = 1; |
|
2776 |
} |
|
2777 |
||
2778 |
__BEGIN_INTERRUPTABLE__ |
|
2779 |
do { |
|
2780 |
cp = fgets(buffer, sizeof(buffer)-1, f); |
|
2781 |
} while ((cp == NULL) && ferror(f) && (__threadErrno == EINTR) && (clearerr(f), 1)); |
|
2782 |
buffer[sizeof(buffer)-1] = '\0'; |
|
2783 |
__END_INTERRUPTABLE__ |
|
2784 |
||
2785 |
if (cp == NULL) { |
|
2786 |
if (ferror(f)) { |
|
2787 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
2788 |
goto err; |
|
2789 |
} else { |
|
2790 |
FSEEK(f, firstpos); |
|
2791 |
RETURN (nil); |
|
2792 |
} |
|
2793 |
} |
|
2794 |
if (strncmp(cp, matchString, l) == 0) { |
|
2795 |
FSEEK(f, lastpos); |
|
2796 |
break; |
|
2797 |
} |
|
2798 |
} |
|
2799 |
/* remove EOL character */ |
|
2800 |
cp = buffer; |
|
2801 |
while (*cp && (*cp != '\n') && (*cp != '\r')) cp++; |
|
2802 |
*cp = '\0'; |
|
2803 |
__INST(position) = nil; /* i.e. do not know */ |
|
2804 |
RETURN ( __MKSTRING(buffer) ); |
|
1 | 2805 |
} |
159 | 2806 |
err: ; |
2920 | 2807 |
|
2808 |
# undef FTELL |
|
2809 |
# undef FSEEK |
|
2810 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2811 |
#endif |
159 | 2812 |
%}. |
2813 |
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
|
2814 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2815 |
"/ 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
|
2816 |
|
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2817 |
firstPos := self position. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2818 |
[self atEnd] whileFalse:[ |
8070 | 2819 |
lastPos := self position. |
2820 |
line := self nextLine. |
|
2821 |
line isNil ifTrue:[ |
|
2822 |
self position:firstPos. |
|
2823 |
^ nil |
|
2824 |
]. |
|
2825 |
(line startsWith:aString) ifTrue:[ |
|
2826 |
self position:lastPos. |
|
2827 |
^ line |
|
2828 |
] |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2829 |
]. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2830 |
self position:firstPos. |
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
2831 |
^ nil |
1 | 2832 |
! |
2833 |
||
2834 |
peekForLineStartingWithAny:aCollectionOfStrings |
|
2835 |
"read ahead for next line starting with any of aCollectionOfStrings; |
|
2836 |
return the index in aCollection if found, nil otherwise.. |
|
2837 |
If no match, do not change position; otherwise advance right before the |
|
2838 |
matched line so that nextLine will return this line." |
|
2839 |
||
2840 |
|line startPos linePos index| |
|
2841 |
||
2842 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
2843 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
2 | 2844 |
binary ifTrue:[^ self errorBinary]. |
2845 |
||
1 | 2846 |
startPos := self position. |
2847 |
[self atEnd] whileFalse:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2848 |
linePos := self position. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2849 |
line := self nextLine. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2850 |
line notNil ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2851 |
index := 1. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2852 |
aCollectionOfStrings do:[:prefix | |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2853 |
(line startsWith:prefix) ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2854 |
self position:linePos. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2855 |
^ index |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2856 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2857 |
index := index + 1 |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2858 |
] |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2859 |
] |
1 | 2860 |
]. |
2861 |
self position:startPos. |
|
2862 |
^ nil |
|
2863 |
! ! |
|
2864 |
||
612 | 2865 |
!ExternalStream methodsFor:'misc functions'! |
2866 |
||
2867 |
async:aBoolean |
|
779 | 2868 |
"set/clear the async attribute - if set, the availability of data on |
612 | 2869 |
the receiver will trigger an ioInterrupt. |
779 | 2870 |
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
|
2871 |
Notice: |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2872 |
not every OS supports this |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2873 |
- check with OS>>supportsIOInterrupts before using" |
92 | 2874 |
|
2875 |
|fd| |
|
2876 |
||
159 | 2877 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2878 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2879 |
OperatingSystem supportsIOInterrupts ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2880 |
^ self errorUnsupportedOperation |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2881 |
]. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2882 |
|
92 | 2883 |
fd := self fileDescriptor. |
612 | 2884 |
aBoolean ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2885 |
^ OperatingSystem enableIOInterruptsOn:fd |
612 | 2886 |
]. |
2887 |
^ OperatingSystem disableIOInterruptsOn:fd |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2888 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2889 |
"Modified: 11.1.1997 / 17:50:21 / cg" |
92 | 2890 |
! |
2891 |
||
612 | 2892 |
blocking:aBoolean |
2893 |
"set/clear the blocking attribute - if set (which is the default) |
|
2894 |
a read (using next) on the receiver will block until data is available. |
|
2895 |
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
|
2896 |
nil. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
2897 |
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
|
2898 |
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
|
2899 |
in advance. However, the data must then be read using #nextBytes: |
3174 | 2900 |
methods, in order to avoid other (pastEnd) exceptions." |
92 | 2901 |
|
159 | 2902 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
7499
53b7a86e1f0b
ExternalStream>>blocking: returns previous blocking status
Stefan Vogel <sv@exept.de>
parents:
7497
diff
changeset
|
2903 |
^ 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
|
2904 |
|
3174 | 2905 |
"Modified: / 11.1.1997 / 17:48:01 / cg" |
2906 |
"Modified: / 15.1.1998 / 11:49:48 / stefan" |
|
612 | 2907 |
! |
2908 |
||
2909 |
close |
|
2910 |
"close the stream - tell operating system" |
|
2911 |
||
3949 | 2912 |
self isOpen ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2913 |
Lobby unregister:self. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
2914 |
self closeFile. |
3949 | 2915 |
] |
612 | 2916 |
! |
2917 |
||
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2918 |
copyToEndInto:outStream |
7017
03f1bd57c001
no one cares about the signal in copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
7013
diff
changeset
|
2919 |
"copy the data into another stream." |
03f1bd57c001
no one cares about the signal in copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
7013
diff
changeset
|
2920 |
|
7700
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2921 |
|bufferSize pos n nWritten| |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2922 |
|
8339 | 2923 |
"the sendfile() system call currently (2004-05-07) handles only descriptors that |
2924 |
that support mmap-like operations as from-fd" |
|
2925 |
||
7700
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2926 |
self isFileStream ifTrue:[ |
8339 | 2927 |
outStream isExternalStream ifTrue:[ |
2928 |
pos := self position0Based. |
|
2929 |
n := self size - pos. |
|
2930 |
nWritten := OperatingSystem |
|
2931 |
copyFromFd:(self fileDescriptor) |
|
2932 |
toFd:(outStream fileDescriptor) |
|
2933 |
startIndex:pos |
|
2934 |
count:n. |
|
2935 |
nWritten = n ifTrue:[ |
|
2936 |
^ self |
|
2937 |
]. |
|
2938 |
nWritten > 0 ifTrue:[ |
|
2939 |
self position0Based:pos+nWritten. |
|
2940 |
]. |
|
2941 |
] |
|
7700
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2942 |
]. |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2943 |
|
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2944 |
OperatingSystem isMSDOSlike ifTrue:[ |
8339 | 2945 |
"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ? |
2946 |
bufferSize := 1 * 1024. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2947 |
] ifFalse:[ |
8339 | 2948 |
bufferSize := 8 * 1024. |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2949 |
]. |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2950 |
|
7017
03f1bd57c001
no one cares about the signal in copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
7013
diff
changeset
|
2951 |
^ self copyToEndInto:outStream bufferSize:bufferSize |
7700
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2952 |
|
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2953 |
" |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2954 |
|in out| |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2955 |
|
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2956 |
in := 'Makefile' asFilename readStream. |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2957 |
out := Stdout. |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2958 |
in copyToEndInto:out. |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2959 |
in close. |
767e11efc326
use sendfile if supported by OS
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
2960 |
" |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2961 |
! |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
2962 |
|
612 | 2963 |
create |
2964 |
"create the stream |
|
2965 |
- this must be redefined in subclass" |
|
2966 |
||
2967 |
^ self subclassResponsibility |
|
2968 |
! |
|
2969 |
||
2970 |
ioctl:ioctlNumber |
|
2971 |
"to provide a simple ioctl facility - an ioctl is performed |
|
2972 |
on the underlying file; no arguments are passed." |
|
2973 |
||
2920 | 2974 |
^ self ioctl:ioctlNumber with:nil |
2975 |
! |
|
2976 |
||
2977 |
ioctl:ioctlNumber with:arg |
|
2978 |
"to provide a simple ioctl facility - an ioctl is performed |
|
2979 |
on the underlying file; the argument is passed as argument. |
|
2980 |
This is not used by ST/X, but provided for special situations |
|
2981 |
- for example, to control proprietrary I/O devices. |
|
2982 |
||
2983 |
Since the type of the argument depends on the ioctl being |
|
2984 |
performed, different arg types are allowed here. |
|
2985 |
If the argument is nil, an ioctl without argument is performed. |
|
2986 |
If the argument is an integral number, its directly passed; |
|
2987 |
if its a kind of ByteArray (ByteArray, String or Structure), |
|
2988 |
or external data (ExternalBytes or ExternalAddress), |
|
2989 |
a pointer to the data is passed. |
|
2990 |
This allows performing most ioctls |
|
2991 |
- however, it might be tricky to setup the buffer. |
|
2992 |
Be careful in what you pass - ST/X cannot validate its correctness." |
|
2993 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
2994 |
%{ |
2896 | 2995 |
#if !defined(MSDOS_LIKE) |
2996 |
# 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
|
2997 |
FILEPOINTER f; |
2920 | 2998 |
int ret, ioNum; |
612 | 2999 |
OBJ fp; |
2920 | 3000 |
INT ioArg; |
612 | 3001 |
|
1133 | 3002 |
__INST(lastErrorNumber) = nil; |
3003 |
if ((fp = __INST(filePointer)) != nil) { |
|
8070 | 3004 |
if (__isSmallInteger(ioctlNumber) |
3005 |
&& (__isSmallInteger(arg) |
|
3006 |
|| (arg == nil) |
|
3007 |
|| __isBytes(arg) |
|
3008 |
|| __isExternalBytesLike(arg) |
|
3009 |
|| __isExternalAddress(arg))) { |
|
3010 |
f = __FILEVal(fp); |
|
3011 |
ioNum = __intVal(ioctlNumber); |
|
3012 |
||
3013 |
__BEGIN_INTERRUPTABLE__ |
|
3014 |
do { |
|
3015 |
__threadErrno = 0; |
|
3016 |
if (arg == nil) { |
|
3017 |
ioArg = 0; |
|
3018 |
} else if (__isSmallInteger(arg)) { |
|
3019 |
ioArg = __intVal(arg); |
|
3020 |
} else if (__isExternalBytesLike(arg)) { |
|
3021 |
ioArg = (INT)(__externalBytesAddress(arg)); |
|
3022 |
} else if (__isExternalAddress(arg)) { |
|
3023 |
ioArg = (INT)(__externalAddressVal(arg)); |
|
3024 |
} else { |
|
3025 |
ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element); |
|
3026 |
} |
|
3027 |
ret = ioctl(fileno(f), ioNum, ioArg); |
|
3028 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
|
3029 |
__END_INTERRUPTABLE__ |
|
3030 |
||
3031 |
if (ret >= 0) { |
|
3032 |
RETURN ( __MKSMALLINT(ret) ); |
|
3033 |
} |
|
3034 |
__INST(position) = nil; /* i.e. do not know */ |
|
3035 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3036 |
} |
|
612 | 3037 |
} |
2896 | 3038 |
# endif |
791 | 3039 |
#endif |
612 | 3040 |
%}. |
3041 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
3042 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3043 |
" |
|
2920 | 3044 |
argument is not an integer |
3045 |
" |
|
3046 |
(ioctlNumber isMemberOf:SmallInteger) ifFalse:[^ self primitiveFailed]. |
|
612 | 3047 |
" |
2920 | 3048 |
the system does not support ioctl (MSDOS or VMS) |
612 | 3049 |
" |
2920 | 3050 |
^ self errorUnsupportedOperation |
612 | 3051 |
! |
3052 |
||
3053 |
open |
|
3054 |
"open the stream |
|
3055 |
- this must be redefined in subclass" |
|
3056 |
||
3057 |
^ self subclassResponsibility |
|
3058 |
! |
|
3059 |
||
3060 |
reset |
|
3061 |
"set the read position to the beginning of the collection" |
|
3062 |
||
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
3063 |
self position:ZeroPosition |
612 | 3064 |
! |
3065 |
||
1044
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
3066 |
setToEnd |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
3067 |
"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
|
3068 |
|
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
3069 |
^ self subclassResponsibility |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
3070 |
! |
c2fb3818e097
ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents:
971
diff
changeset
|
3071 |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3072 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3073 |
"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
|
3074 |
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
|
3075 |
|
1068
92fdcccf12a3
alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents:
1067
diff
changeset
|
3076 |
%{ |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3077 |
#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
|
3078 |
FILEPOINTER f; |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3079 |
OBJ fp; |
7887
c5df7cf8d667
LargeFile support for truncateTo:
Stefan Vogel <sv@exept.de>
parents:
7883
diff
changeset
|
3080 |
off_t truncateSize; |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3081 |
|
1133 | 3082 |
if (((fp = __INST(filePointer)) != nil) |
8070 | 3083 |
&& (__INST(mode) != @symbol(readonly))) { |
3084 |
if (__isSmallInteger(newSize)) { |
|
3085 |
truncateSize = __intVal(newSize); |
|
3086 |
if (truncateSize < 0) { |
|
3087 |
goto getOutOfHere; |
|
3088 |
} |
|
3089 |
} else { |
|
3090 |
truncateSize = __signedLongIntVal(newSize); |
|
3091 |
if (truncateSize < 0) { |
|
3092 |
goto getOutOfHere; |
|
3093 |
} |
|
3094 |
if (truncateSize == 0) { |
|
3095 |
if (sizeof(truncateSize) == 8) { |
|
3096 |
if (__signedLong64IntVal(newSize, &truncateSize) == 0 || truncateSize < 0) { |
|
3097 |
goto getOutOfHere; |
|
3098 |
} |
|
3099 |
} else { |
|
3100 |
goto getOutOfHere; |
|
3101 |
} |
|
3102 |
} |
|
3103 |
} |
|
3104 |
||
3105 |
f = __FILEVal(fp); |
|
3106 |
||
3107 |
if (__INST(buffered) == true) { |
|
3108 |
__READING__(f) |
|
3109 |
FFLUSH(f); |
|
3110 |
OPT_FSEEK(f, 0L, SEEK_END); /* needed in stdio */ |
|
3111 |
} |
|
3112 |
ftruncate(fileno(f), truncateSize); |
|
3113 |
RETURN (self); |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3114 |
} |
8070 | 3115 |
getOutOfHere: ; |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3116 |
#endif |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3117 |
%}. |
2331 | 3118 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
3119 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
7887
c5df7cf8d667
LargeFile support for truncateTo:
Stefan Vogel <sv@exept.de>
parents:
7883
diff
changeset
|
3120 |
newSize < 0 ifTrue:[ |
8070 | 3121 |
self error:'wrong arg'. |
7887
c5df7cf8d667
LargeFile support for truncateTo:
Stefan Vogel <sv@exept.de>
parents:
7883
diff
changeset
|
3122 |
]. |
2331 | 3123 |
self errorUnsupportedOperation |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3124 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3125 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3126 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3127 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3128 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3129 |
s next:1000 put:$a. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3130 |
s truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3131 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3132 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3133 |
('test' asFilename fileSize) printNL |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
872
diff
changeset
|
3134 |
" |
612 | 3135 |
! ! |
3136 |
||
3137 |
!ExternalStream methodsFor:'non homogenous reading'! |
|
3138 |
||
3674 | 3139 |
nextAvailable:count |
3140 |
"return the next count elements of the stream as aCollection. |
|
3141 |
If the stream reaches the end before count elements have been read, |
|
3142 |
return what is available. (i.e. a shorter collection). |
|
3143 |
The type of collection is specified in #contentsSpecies." |
|
3144 |
||
3956
51f1a9a4d63f
changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents:
3949
diff
changeset
|
3145 |
|buffer n| |
3674 | 3146 |
|
3147 |
binary ifTrue:[ |
|
7832 | 3148 |
buffer := ByteArray uninitializedNew:count |
3674 | 3149 |
] ifFalse:[ |
7832 | 3150 |
buffer := String uninitializedNew:count |
3674 | 3151 |
]. |
3152 |
n := self nextAvailableBytes:count into:buffer startingAt:1. |
|
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3153 |
n == 0 ifTrue:[ |
7832 | 3154 |
binary ifTrue:[ |
3155 |
^ #[] |
|
3156 |
]. |
|
3157 |
^ '' |
|
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3158 |
]. |
3674 | 3159 |
|
3160 |
n ~~ count ifTrue:[ |
|
7832 | 3161 |
^ buffer copyTo:n |
3674 | 3162 |
]. |
3163 |
^ buffer. |
|
3164 |
||
3165 |
" |
|
3166 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:3 |
|
3167 |
(ReadStream on:#(1 2 3 4 5)) nextAvailable:10 |
|
3168 |
(ReadStream on:'hello') nextAvailable:3 |
|
3169 |
(ReadStream on:'hello') nextAvailable:10 |
|
3170 |
" |
|
3171 |
||
3172 |
"Modified: / 16.6.1998 / 15:52:41 / cg" |
|
3173 |
! |
|
3174 |
||
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3175 |
nextAvailableBytes:count into:anObject startingAt:start |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3176 |
"read the next count bytes into an object and return the number of |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3177 |
bytes read or the number of bytes read, if EOF is encountered before, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3178 |
or no more bytes are available for reading (from the pipe/socket). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3179 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3180 |
If the receiver is some socket/pipe-like stream, an exception |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3181 |
is raised if the connection is broken. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3182 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3183 |
Notice, that in contrast to other methods, |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3184 |
this does NOT return nil on EOF, but the actual count. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3185 |
Thus allowing read of partial blocks. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3186 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3187 |
The object must have non-pointer indexed instvars |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3188 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3189 |
If anObject is a string or byteArray and reused, this provides the |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3190 |
fastest possible physical I/O (since no new objects are allocated). |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3191 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3192 |
Use with care - non object oriented I/O. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3193 |
Warning: in general, you cannot use this method to pass data from other |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3194 |
architectures since it does not care for byte order or float representation." |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3195 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3196 |
%{ |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3197 |
FILEPOINTER f; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3198 |
int cnt, offs, ret, _buffered; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3199 |
int objSize, nInstVars, nInstBytes; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3200 |
char *cp; |
3445
2639c1e3fd0b
nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents:
3432
diff
changeset
|
3201 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3202 |
OBJ fp; |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3203 |
int o_offs; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3204 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3205 |
__INST(lastErrorNumber) = nil; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3206 |
if (((fp = __INST(filePointer)) != nil) |
8070 | 3207 |
&& (__INST(mode) != @symbol(writeonly)) |
3208 |
&& __bothSmallInteger(count, start) |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3209 |
) { |
8070 | 3210 |
f = __FILEVal(fp); |
3211 |
||
3212 |
cnt = __intVal(count); |
|
3213 |
offs = __intVal(start) - 1; |
|
3214 |
||
3215 |
if (__isExternalBytesLike(anObject)) { |
|
3216 |
OBJ sz; |
|
3217 |
||
3218 |
nInstBytes = 0; |
|
3219 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3220 |
sz = __externalBytesSize(anObject); |
|
3221 |
if (__isSmallInteger(sz)) { |
|
3222 |
objSize = __intVal(sz); |
|
3223 |
} else { |
|
3224 |
objSize = 0; /* unknown */ |
|
3225 |
} |
|
3226 |
} else { |
|
3227 |
OBJ oClass; |
|
3228 |
||
3229 |
oClass = __Class(anObject); |
|
3230 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3231 |
case BYTEARRAY: |
|
3232 |
case WORDARRAY: |
|
3233 |
case LONGARRAY: |
|
3234 |
case SWORDARRAY: |
|
3235 |
case SLONGARRAY: |
|
3236 |
case FLOATARRAY: |
|
3237 |
case DOUBLEARRAY: |
|
3238 |
break; |
|
3239 |
default: |
|
3240 |
goto bad; |
|
3241 |
} |
|
3242 |
extPtr = (char *)0; |
|
3243 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3244 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3245 |
objSize = __Size(anObject) - nInstBytes; |
|
3246 |
} |
|
3247 |
||
3248 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3249 |
_buffered = (__INST(buffered) == true); |
|
3250 |
if (_buffered) { |
|
3251 |
__READING__(f); |
|
3252 |
} |
|
3253 |
||
3254 |
if (extPtr) { |
|
3255 |
__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered); |
|
3256 |
} else { |
|
3257 |
/* |
|
3258 |
* on interrupt, anObject may be moved to another location. |
|
3259 |
* So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__, |
|
3260 |
* to get a new address. |
|
3261 |
*/ |
|
3262 |
offs += nInstBytes; |
|
3263 |
__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered); |
|
3264 |
} |
|
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3265 |
#ifdef PRE_22_jan_2000 |
8070 | 3266 |
if (ret > 0) |
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3267 |
#else |
8070 | 3268 |
/* 0 is NOT an EOF condition here ... */ |
3269 |
if (ret >= 0) |
|
5202
e8130049b18f
#nextAvailableBytes:into:startingAt: may NOT set EOF flag,
Claus Gittinger <cg@exept.de>
parents:
5187
diff
changeset
|
3270 |
#endif |
8070 | 3271 |
{ |
3272 |
if (__isSmallInteger(__INST(position))) { |
|
3273 |
INT np = __intVal(__INST(position)) + ret; |
|
3274 |
OBJ t; |
|
3275 |
||
3276 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3277 |
} else { |
|
3278 |
__INST(position) = nil; /* i.e. do not know */ |
|
3279 |
} |
|
3280 |
RETURN (__MKSMALLINT(ret)); |
|
3281 |
} |
|
3282 |
if (ret == 0) { |
|
3283 |
__INST(hitEOF) = true; |
|
3284 |
} else /* ret < 0 */ { |
|
3285 |
__INST(position) = nil; |
|
3286 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3287 |
} |
|
3288 |
} |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3289 |
} |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3290 |
bad: ; |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3291 |
%}. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3292 |
(hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3293 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3294 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3295 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3296 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3297 |
count not integer or arg not bit-like (String, ByteArray etc) |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3298 |
" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3299 |
^ self primitiveFailed |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3300 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3301 |
|
612 | 3302 |
nextByte |
3303 |
"read the next byte and return it as an Integer; return nil on error. |
|
3304 |
This is allowed in both text and binary modes, always returning the |
|
3305 |
bytes binary value as an integer in 0..255." |
|
3306 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3307 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3308 |
FILEPOINTER f; |
612 | 3309 |
unsigned char byte; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3310 |
int ret, _buffered; |
612 | 3311 |
OBJ fp; |
3312 |
||
1133 | 3313 |
__INST(lastErrorNumber) = nil; |
3314 |
if (((fp = __INST(filePointer)) != nil) |
|
3315 |
&& (__INST(mode) != @symbol(writeonly))) { |
|
8070 | 3316 |
f = __FILEVal(fp); |
3317 |
||
3318 |
_buffered = (__INST(buffered) == true); |
|
3319 |
if (_buffered) { |
|
3320 |
__READING__(f) |
|
3321 |
} |
|
3322 |
__READBYTE__(ret, f, &byte, _buffered); |
|
3323 |
if (ret > 0) { |
|
3324 |
if (__isSmallInteger(__INST(position))) { |
|
3325 |
INT np = __intVal(__INST(position)) + 1; |
|
3326 |
OBJ t; |
|
3327 |
||
3328 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3329 |
} else { |
|
3330 |
__INST(position) = nil; /* i.e. do not know */ |
|
3331 |
} |
|
3332 |
RETURN (__MKSMALLINT(byte)); |
|
3333 |
} |
|
3334 |
||
3335 |
if (ret == 0) { |
|
3336 |
__INST(hitEOF) = true; |
|
3337 |
} else /* ret < 0 */ { |
|
3338 |
__INST(position) = nil; |
|
3339 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3340 |
} |
|
612 | 3341 |
} |
3342 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3343 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3344 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3345 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3346 |
^ self errorWriteOnly |
|
3347 |
! |
|
3348 |
||
3349 |
nextBytes:count into:anObject startingAt:start |
|
3350 |
"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
|
3351 |
bytes read or the number of bytes read, if EOF is encountered before. |
612 | 3352 |
If the receiver is some socket/pipe-like stream, an exception |
3353 |
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
|
3354 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3355 |
Warning: if used with a pipe/socket, this blocks until the requested number |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3356 |
of bytes have been read. See #nextAvailableBytes:into:startingAt: |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3357 |
to only read whats there. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
3358 |
|
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
3359 |
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
|
3360 |
this does NOT return nil on EOF, but the actual count. |
612 | 3361 |
Thus allowing read of partial blocks. |
3362 |
||
3363 |
The object must have non-pointer indexed instvars |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3364 |
(i.e. it must be a ByteArray, String, Float- or DoubleArray), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3365 |
or an externalBytes object (with known size). |
612 | 3366 |
If anObject is a string or byteArray and reused, this provides the |
3367 |
fastest possible physical I/O (since no new objects are allocated). |
|
3368 |
||
3369 |
Use with care - non object oriented I/O. |
|
3370 |
Warning: in general, you cannot use this method to pass data from other |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3371 |
architectures (unless you prepared the buffer with care), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3372 |
since it does not care for byte order or float representation." |
612 | 3373 |
|
3374 |
%{ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3375 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3376 |
int cnt, offs, ret, _buffered; |
612 | 3377 |
int objSize, nInstVars, nInstBytes; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3378 |
char *extPtr; |
7195
755c46f9b774
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
7118
diff
changeset
|
3379 |
OBJ fp; |
612 | 3380 |
|
1133 | 3381 |
__INST(lastErrorNumber) = nil; |
3382 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 3383 |
&& (__INST(mode) != @symbol(writeonly)) |
3384 |
&& __bothSmallInteger(count, start) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3385 |
) { |
8070 | 3386 |
f = __FILEVal(fp); |
3387 |
||
3388 |
cnt = __intVal(count); |
|
3389 |
offs = __intVal(start) - 1; |
|
3390 |
||
3391 |
if (__isExternalBytesLike(anObject)) { |
|
3392 |
OBJ sz; |
|
3393 |
||
3394 |
nInstBytes = 0; |
|
3395 |
extPtr = (char *)(__externalBytesAddress(anObject)); |
|
3396 |
sz = __externalBytesSize(anObject); |
|
3397 |
if (__isSmallInteger(sz)) { |
|
3398 |
objSize = __intVal(sz); |
|
3399 |
} else { |
|
3400 |
objSize = 0; /* unknown */ |
|
3401 |
} |
|
3402 |
} else { |
|
3403 |
OBJ oClass; |
|
3404 |
||
3405 |
oClass = __Class(anObject); |
|
3406 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3407 |
case BYTEARRAY: |
|
3408 |
case WORDARRAY: |
|
3409 |
case LONGARRAY: |
|
3410 |
case SWORDARRAY: |
|
3411 |
case SLONGARRAY: |
|
3412 |
case FLOATARRAY: |
|
3413 |
case DOUBLEARRAY: |
|
3414 |
break; |
|
3415 |
default: |
|
3416 |
goto bad; |
|
3417 |
} |
|
3418 |
extPtr = (char *)0; |
|
3419 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3420 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3421 |
objSize = __Size(anObject) - nInstBytes; |
|
3422 |
} |
|
3423 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3424 |
_buffered = (__INST(buffered) == true); |
|
3425 |
if (_buffered) { |
|
3426 |
__READING__(f); |
|
3427 |
} |
|
3428 |
||
3429 |
if (extPtr) { |
|
3430 |
__READBYTES__(ret, f, extPtr+offs, cnt, _buffered); |
|
3431 |
} else { |
|
3432 |
/* |
|
3433 |
* on interrupt, anObject may be moved to another location. |
|
3434 |
* So we pass anObject, and the offset to the __READBYTES_OBJ__ macro. |
|
3435 |
*/ |
|
3436 |
offs += nInstBytes; |
|
3437 |
__READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered); |
|
3438 |
} |
|
3439 |
||
3440 |
if (ret > 0) { |
|
3441 |
if (__isSmallInteger(__INST(position))) { |
|
3442 |
INT np = __intVal(__INST(position)) + ret; |
|
3443 |
OBJ t; |
|
3444 |
||
3445 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3446 |
} else { |
|
3447 |
__INST(position) = nil; /* i.e. do not know */ |
|
3448 |
} |
|
3449 |
RETURN (__MKSMALLINT(ret)); |
|
3450 |
} |
|
3451 |
if (ret == 0) { |
|
3452 |
__INST(hitEOF) = true; |
|
3453 |
} else /* ret < 0 */ { |
|
3454 |
__INST(position) = nil; |
|
3455 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3456 |
} |
|
3457 |
} |
|
612 | 3458 |
} |
3459 |
bad: ; |
|
3460 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3461 |
(hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0]. |
612 | 3462 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
3463 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3464 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
3465 |
" |
|
3466 |
count not integer or arg not bit-like (String, ByteArray etc) |
|
3467 |
" |
|
3468 |
^ self primitiveFailed |
|
92 | 3469 |
! |
3470 |
||
612 | 3471 |
nextLong |
3472 |
"Read four bytes (msb-first) and return the value as a 32-bit signed Integer. |
|
3473 |
The returned value may be a LargeInteger. |
|
3474 |
(msb-first for compatibility with other smalltalks)" |
|
3475 |
||
3476 |
^ self nextUnsignedLongMSB:true |
|
3477 |
! |
|
3478 |
||
3479 |
nextLongMSB:msbFlag |
|
3480 |
"Read four bytes and return the value as a 32-bit signed Integer, |
|
3481 |
which may be a LargeInteger. |
|
3482 |
If msbFlag is true, value is read with most-significant byte first, |
|
3483 |
otherwise least-significant byte comes first. |
|
3484 |
A nil is returned, if EOF is hit before all 4 bytes have been read. |
|
3485 |
Works in both binary and text modes." |
|
3486 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3487 |
%{ |
612 | 3488 |
OBJ fp; |
3489 |
||
1133 | 3490 |
__INST(lastErrorNumber) = nil; |
3491 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 3492 |
&& (__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
|
3493 |
) { |
8070 | 3494 |
FILEPOINTER f; |
3495 |
int ret, _buffered; |
|
3496 |
int value; |
|
3497 |
union { |
|
3498 |
unsigned char buffer[4]; |
|
3499 |
int intVal; |
|
3500 |
} u; |
|
3501 |
||
3502 |
f = __FILEVal(fp); |
|
3503 |
_buffered = (__INST(buffered) == true); |
|
3504 |
if (_buffered) { |
|
3505 |
__READING__(f) |
|
3506 |
} |
|
3507 |
__READBYTES__(ret, f, u.buffer, 4, _buffered); |
|
3508 |
||
3509 |
if (ret == 4) { |
|
3510 |
if (__isSmallInteger(__INST(position))) { |
|
3511 |
INT np = __intVal(__INST(position)) + 4; |
|
3512 |
OBJ t; |
|
3513 |
||
3514 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3515 |
} else { |
|
3516 |
__INST(position) = nil; /* i.e. do not know */ |
|
3517 |
} |
|
3518 |
if (msbFlag == true) { |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3519 |
#if defined(__MSBFIRST) |
8070 | 3520 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3521 |
#else |
8070 | 3522 |
value = (u.buffer[0] & 0xFF); |
3523 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
3524 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
3525 |
value = (value << 8) | (u.buffer[3] & 0xFF); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3526 |
#endif |
8070 | 3527 |
} else { |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3528 |
#if defined(__LSBFIRST) |
8070 | 3529 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3530 |
#else |
8070 | 3531 |
value = (u.buffer[3] & 0xFF); |
3532 |
value = (value << 8) | (u.buffer[2] & 0xFF); |
|
3533 |
value = (value << 8) | (u.buffer[1] & 0xFF); |
|
3534 |
value = (value << 8) | (u.buffer[0] & 0xFF); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3535 |
#endif |
8070 | 3536 |
} |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3537 |
#ifdef alpha64 |
8070 | 3538 |
RETURN ( __MKSMALLINT(value)); |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3539 |
#else |
8070 | 3540 |
if ((value >= _MIN_INT) && (value <= _MAX_INT)) { |
3541 |
RETURN ( __MKSMALLINT(value)); |
|
3542 |
} |
|
3543 |
RETURN ( __MKLARGEINT(value) ); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3544 |
#endif |
8070 | 3545 |
} |
3546 |
||
3547 |
if (ret < 0) { |
|
3548 |
__INST(position) = nil; |
|
3549 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3550 |
} else /* ret == 0 */ { |
|
3551 |
__INST(hitEOF) = true; |
|
3552 |
} |
|
612 | 3553 |
} |
3554 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3555 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3556 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
3557 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
3558 |
^ self readError. |
|
362 | 3559 |
! |
3560 |
||
612 | 3561 |
nextShortMSB:msbFlag |
3562 |
"Read two bytes and return the value as a 16-bit signed Integer. |
|
3563 |
If msbFlag is true, value is read with most-significant byte first, |
|
3564 |
otherwise least-significant byte comes first. |
|
3565 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
|
3566 |
Works in both binary and text modes." |
|
3567 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3568 |
%{ |
612 | 3569 |
OBJ fp; |
3570 |
||
1133 | 3571 |
__INST(lastErrorNumber) = nil; |
3572 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 3573 |
&& (__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
|
3574 |
) { |
8070 | 3575 |
FILEPOINTER f; |
3576 |
int ret, _buffered; |
|
3577 |
short value; |
|
3578 |
union { |
|
3579 |
unsigned char buffer[2]; |
|
3580 |
short shortVal; |
|
3581 |
} u; |
|
3582 |
||
3583 |
f = __FILEVal(fp); |
|
3584 |
_buffered = (__INST(buffered) == true); |
|
3585 |
if (_buffered) { |
|
3586 |
__READING__(f) |
|
3587 |
} |
|
3588 |
__READBYTES__(ret, f, u.buffer, 2, _buffered); |
|
3589 |
||
3590 |
if (ret == 2) { |
|
3591 |
if (__isSmallInteger(__INST(position))) { |
|
3592 |
INT np = __intVal(__INST(position)) + 2; |
|
3593 |
OBJ t; |
|
3594 |
||
3595 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3596 |
} else { |
|
3597 |
__INST(position) = nil; /* i.e. do not know */ |
|
3598 |
} |
|
3599 |
if (msbFlag == true) { |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3600 |
#if defined(__MSBFIRST) |
8070 | 3601 |
value = u.shortVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3602 |
#else |
8070 | 3603 |
value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF); |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3604 |
#endif |
8070 | 3605 |
} else { |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3606 |
#if defined(__LSBFIRST) |
8070 | 3607 |
value = u.shortVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3608 |
#else |
8070 | 3609 |
value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF); |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3610 |
#endif |
8070 | 3611 |
} |
3612 |
RETURN (__MKSMALLINT(value)); |
|
3613 |
} |
|
3614 |
||
3615 |
if (ret < 0) { |
|
3616 |
__INST(position) = nil; /* i.e. do not know */ |
|
3617 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3618 |
} else /* ret == 0 */ { |
|
3619 |
__INST(hitEOF) = true; |
|
3620 |
} |
|
612 | 3621 |
} |
3622 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3623 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3624 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
3625 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
3626 |
^ self readError. |
|
3627 |
! |
|
3628 |
||
3629 |
nextUnsignedLongMSB:msbFlag |
|
3630 |
"Read four bytes and return the value as a 32-bit unsigned Integer, which may be |
|
3631 |
a LargeInteger. |
|
3632 |
If msbFlag is true, value is read with most-significant byte first, otherwise |
|
3633 |
least-significant byte comes first. |
|
3634 |
A nil is returned, if endOfFile occurs before all 4 bytes have been read. |
|
3635 |
Works in both binary and text modes." |
|
3636 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3637 |
%{ |
612 | 3638 |
OBJ fp; |
3639 |
||
1133 | 3640 |
__INST(lastErrorNumber) = nil; |
3641 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 3642 |
&& (__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
|
3643 |
) { |
8070 | 3644 |
FILEPOINTER f; |
3645 |
int ret, _buffered; |
|
3646 |
unsigned INT value; |
|
3647 |
union { |
|
3648 |
unsigned char buffer[4]; |
|
3649 |
unsigned int intVal; |
|
3650 |
} u; |
|
3651 |
||
3652 |
f = __FILEVal(fp); |
|
3653 |
_buffered = (__INST(buffered) == true); |
|
3654 |
if (_buffered) { |
|
3655 |
__READING__(f) |
|
3656 |
} |
|
3657 |
__READBYTES__(ret, f, u.buffer, 4, _buffered); |
|
3658 |
||
3659 |
if (ret == 4) { |
|
3660 |
if (__isSmallInteger(__INST(position))) { |
|
3661 |
INT np = __intVal(__INST(position)) + 4; |
|
3662 |
OBJ t; |
|
3663 |
||
3664 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3665 |
} else { |
|
3666 |
__INST(position) = nil; /* i.e. do not know */ |
|
3667 |
} |
|
3668 |
if (msbFlag == true) { |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3669 |
#if defined(__MSBFIRST) |
8070 | 3670 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3671 |
#else |
8070 | 3672 |
value = u.buffer[0]; |
3673 |
value = (value << 8) | u.buffer[1]; |
|
3674 |
value = (value << 8) | u.buffer[2]; |
|
3675 |
value = (value << 8) | u.buffer[3]; |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3676 |
#endif |
8070 | 3677 |
} else { |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3678 |
#if defined(__LSBFIRST) |
8070 | 3679 |
value = u.intVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3680 |
#else |
8070 | 3681 |
value = u.buffer[3]; |
3682 |
value = (value << 8) | u.buffer[2]; |
|
3683 |
value = (value << 8) | u.buffer[1]; |
|
3684 |
value = (value << 8) | u.buffer[0]; |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3685 |
#endif |
8070 | 3686 |
} |
3456
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
3687 |
#ifdef alpha64 |
8070 | 3688 |
value &= 0xFFFFFFFF; |
3689 |
RETURN (__MKSMALLINT(value)); |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3690 |
#else |
8070 | 3691 |
if (value <= _MAX_INT) { |
3692 |
RETURN (__MKSMALLINT(value)); |
|
3693 |
} |
|
3694 |
RETURN (__MKULARGEINT(value) ); |
|
3456
0cdf451360b9
oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents:
3445
diff
changeset
|
3695 |
#endif |
8070 | 3696 |
} |
3697 |
||
3698 |
if (ret < 0) { |
|
3699 |
__INST(position) = nil; /* i.e. do not know */ |
|
3700 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3701 |
} else /* ret == 0 */ { |
|
3702 |
__INST(hitEOF) = true; |
|
3703 |
} |
|
612 | 3704 |
} |
3705 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3706 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3707 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
3708 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
3709 |
^ self readError. |
|
3710 |
! |
|
3711 |
||
3712 |
nextUnsignedShortMSB:msbFlag |
|
3713 |
"Read two bytes and return the value as a 16-bit unsigned Integer. |
|
1079 | 3714 |
If msbFlag is true, value is read with most-significant byte first, |
3715 |
otherwise least-significant byte comes first. |
|
612 | 3716 |
A nil is returned if EOF is reached (also when EOF is hit after the first byte). |
3717 |
Works in both binary and text modes." |
|
3718 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3719 |
%{ |
612 | 3720 |
OBJ fp; |
3721 |
||
1133 | 3722 |
__INST(lastErrorNumber) = nil; |
3723 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 3724 |
&& (__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
|
3725 |
) { |
8070 | 3726 |
FILEPOINTER f; |
3727 |
int ret, _buffered; |
|
3728 |
unsigned int value; |
|
3729 |
union { |
|
3730 |
unsigned char buffer[2]; |
|
3731 |
unsigned short shortVal; |
|
3732 |
} u; |
|
3733 |
||
3734 |
f = __FILEVal(fp); |
|
3735 |
_buffered = (__INST(buffered) == true); |
|
3736 |
if (_buffered) { |
|
3737 |
__READING__(f) |
|
3738 |
} |
|
3739 |
__READBYTES__(ret, f, u.buffer, 2, _buffered); |
|
3740 |
||
3741 |
if (ret == 2) { |
|
3742 |
if (__isSmallInteger(__INST(position))) { |
|
3743 |
INT np = __intVal(__INST(position)) + 2; |
|
3744 |
OBJ t; |
|
3745 |
||
3746 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3747 |
} else { |
|
3748 |
__INST(position) = nil; /* i.e. do not know */ |
|
3749 |
} |
|
3750 |
if (msbFlag == true) { |
|
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3751 |
#if defined(__MSBFIRST) |
8070 | 3752 |
value = u.shortVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3753 |
#else |
8070 | 3754 |
value = (u.buffer[0] << 8) | u.buffer[1]; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3755 |
#endif |
8070 | 3756 |
} else { |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3757 |
#if defined(__LSBFIRST) |
8070 | 3758 |
value = u.shortVal; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3759 |
#else |
8070 | 3760 |
value = (u.buffer[1] << 8) | u.buffer[0]; |
4383
7a5abc09fb39
slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents:
4368
diff
changeset
|
3761 |
#endif |
8070 | 3762 |
} |
3763 |
RETURN (__MKSMALLINT(value)); |
|
3764 |
} |
|
3765 |
||
3766 |
if (ret < 0) { |
|
3767 |
__INST(position) = nil; /* i.e. do not know */ |
|
3768 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3769 |
} else /* ret == 0 */ { |
|
3770 |
__INST(hitEOF) = true; |
|
3771 |
} |
|
612 | 3772 |
} |
3773 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
3774 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 3775 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
3776 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
3777 |
^ self readError. |
|
3778 |
! |
|
3779 |
||
3780 |
nextWord |
|
3781 |
"in text-mode: |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
3782 |
read the alphaNumeric next word (i.e. up to non letter-or-digit). |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
3783 |
return a string containing those characters. |
612 | 3784 |
in binary-mode: |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
3785 |
read two bytes (msb-first) and return the value as a 16-bit |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
3786 |
unsigned Integer (for compatibility with other smalltalks)" |
612 | 3787 |
|
3788 |
binary ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
3789 |
^ self nextUnsignedShortMSB:true |
92 | 3790 |
]. |
612 | 3791 |
^ self nextAlphaNumericWord |
3792 |
! ! |
|
3793 |
||
3794 |
!ExternalStream methodsFor:'non homogenous writing'! |
|
3795 |
||
3796 |
nextPutByte:aByteValue |
|
3797 |
"write a byte. |
|
3798 |
Works in both binary and text modes." |
|
3799 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3800 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3801 |
FILEPOINTER f; |
612 | 3802 |
char c; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
3803 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3804 |
int cnt, _buffered; |
612 | 3805 |
|
1133 | 3806 |
__INST(lastErrorNumber) = nil; |
3807 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 3808 |
&& (__INST(mode) != @symbol(readonly)) |
3809 |
&& __isSmallInteger(aByteValue) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3810 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3811 |
) { |
8070 | 3812 |
c = __intVal(aByteValue); |
3813 |
f = __FILEVal(fp); |
|
3814 |
if (_buffered = (__INST(buffered) == true)) { |
|
3815 |
__WRITING__(f) |
|
3816 |
} |
|
3817 |
__WRITEBYTE__(cnt, f, &c, _buffered); |
|
3818 |
if (cnt == 1) { |
|
3819 |
if (__isSmallInteger(__INST(position))) { |
|
3820 |
INT np = __intVal(__INST(position)) + 1; |
|
3821 |
OBJ t; |
|
3822 |
||
3823 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3824 |
} else { |
|
3825 |
__INST(position) = nil; /* i.e. do not know */ |
|
3826 |
} |
|
3827 |
RETURN (self); |
|
3828 |
} |
|
3829 |
if (cnt < 0) { |
|
3830 |
__INST(position) = nil; /* i.e. do not know */ |
|
3831 |
} |
|
3832 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
612 | 3833 |
} |
3834 |
%}. |
|
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
3835 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
3836 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
2331 | 3837 |
self writeError. |
612 | 3838 |
! |
3839 |
||
3840 |
nextPutBytes:count from:anObject startingAt:start |
|
3841 |
"write count bytes from an object starting at index start. |
|
3842 |
return the number of bytes written - which could be 0. |
|
3843 |
The object must have non-pointer indexed instvars |
|
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3844 |
(i.e. be a ByteArray, String, Float- or DoubleArray), |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3845 |
or an externalBytes object (with known size). |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3846 |
|
612 | 3847 |
Use with care - non object oriented i/o. |
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7678
diff
changeset
|
3848 |
Warning: |
8070 | 3849 |
in general, you cannot use this method to pass non-byte data to other |
3850 |
architectures (unless you prepared the buffer with care), |
|
3851 |
since it does not care for byte order or float representation." |
|
612 | 3852 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3853 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3854 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3855 |
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
|
3856 |
int objSize, nInstVars, nInstBytes, _buffered; |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
3857 |
char *extPtr; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
3858 |
OBJ fp; |
612 | 3859 |
|
1133 | 3860 |
__INST(lastErrorNumber) = nil; |
3861 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 3862 |
&& (__INST(mode) != @symbol(readonly)) |
3863 |
&& __bothSmallInteger(count, start) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3864 |
) { |
8070 | 3865 |
len = __intVal(count); |
3866 |
offs = __intVal(start) - 1; |
|
3867 |
f = __FILEVal(fp); |
|
3868 |
||
3869 |
if (__isExternalBytesLike(anObject)) { |
|
3870 |
OBJ sz; |
|
3871 |
||
3872 |
nInstBytes = 0; |
|
3873 |
extPtr = (char *)__externalBytesAddress(anObject); |
|
3874 |
sz = __externalBytesSize(anObject); |
|
3875 |
if (__isSmallInteger(sz)) { |
|
3876 |
objSize = __intVal(sz); |
|
3877 |
} else { |
|
3878 |
objSize = 0; /* unknown */ |
|
3879 |
} |
|
3880 |
} else { |
|
3881 |
OBJ oClass; |
|
3882 |
||
3883 |
oClass = __Class(anObject); |
|
3884 |
switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
3885 |
case BYTEARRAY: |
|
3886 |
case WORDARRAY: |
|
3887 |
case LONGARRAY: |
|
3888 |
case SWORDARRAY: |
|
3889 |
case SLONGARRAY: |
|
3890 |
case FLOATARRAY: |
|
3891 |
case DOUBLEARRAY: |
|
3892 |
break; |
|
3893 |
default: |
|
3894 |
goto bad; |
|
3895 |
} |
|
3896 |
extPtr = (char *)0; |
|
3897 |
nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
|
3898 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3899 |
objSize = __Size(anObject) - nInstBytes; |
|
3900 |
} |
|
3901 |
if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) { |
|
3902 |
if (_buffered = (__INST(buffered) == true)) { |
|
3903 |
__WRITING__(f) |
|
3904 |
} |
|
3905 |
||
3906 |
if (extPtr) { |
|
3907 |
__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered); |
|
3908 |
} else { |
|
3909 |
/* |
|
3910 |
* on interrupt, anObject may be moved to another location. |
|
3911 |
* So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro. |
|
3912 |
*/ |
|
3913 |
offs += nInstBytes; |
|
3914 |
__WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered); |
|
3915 |
} |
|
3916 |
||
3917 |
if (cnt >= 0) { |
|
3918 |
if (__isSmallInteger(__INST(position))) { |
|
3919 |
INT np = __intVal(__INST(position)) + cnt; |
|
3920 |
OBJ t; |
|
3921 |
||
3922 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
3923 |
} else { |
|
3924 |
__INST(position) = nil; /* i.e. do not know */ |
|
3925 |
} |
|
3926 |
RETURN ( __MKSMALLINT(cnt) ); |
|
3927 |
} |
|
3928 |
if ((__threadErrno == EWOULDBLOCK) || ((__threadErrno == EAGAIN))) { |
|
3929 |
RETURN ( __MKSMALLINT(0) ); |
|
3930 |
} |
|
3931 |
__INST(position) = nil; /* i.e. do not know */ |
|
3932 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
3933 |
} |
|
612 | 3934 |
} |
3935 |
bad: ; |
|
3936 |
%}. |
|
3937 |
lastErrorNumber notNil ifTrue:[^ self writeError]. |
|
3938 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
3939 |
(mode == #readonly) ifTrue:[^ self errorReadOnly]. |
|
3940 |
^ self primitiveFailed |
|
3941 |
! |
|
3942 |
||
3943 |
nextPutLong:aNumber MSB:msbFlag |
|
3944 |
"Write the argument, aNumber as a long (four bytes). If msbFlag is |
|
3945 |
true, data is written most-significant byte first; otherwise least |
|
3946 |
first. |
|
3947 |
Works in both binary and text modes." |
|
3948 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
3949 |
%{ |
612 | 3950 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3951 |
union { |
8070 | 3952 |
char bytes[4]; |
3953 |
int intVal; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3954 |
} u; |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
3955 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
3956 |
int cnt, _buffered; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3957 |
OBJ fp; |
612 | 3958 |
|
1133 | 3959 |
__INST(lastErrorNumber) = nil; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3960 |
if (__isSmallInteger(aNumber)) { |
8070 | 3961 |
num = __intVal(aNumber); |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3962 |
} else { |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3963 |
#ifdef alpha64 |
8070 | 3964 |
goto badArg; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3965 |
#else |
8070 | 3966 |
num = __longIntVal(aNumber); |
3967 |
if (num == 0) { |
|
3968 |
num = __signedLongIntVal(aNumber); |
|
3969 |
if (num == 0) { |
|
3970 |
/* bad arg or out-of-range integer |
|
3971 |
* (handled by the fallBack code) |
|
3972 |
*/ |
|
3973 |
goto badArg; |
|
3974 |
} |
|
3975 |
} |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3976 |
#endif |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3977 |
} |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3978 |
|
1133 | 3979 |
if (((fp = __INST(filePointer)) != nil) |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3980 |
&& (__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
|
3981 |
) { |
8070 | 3982 |
if (msbFlag == true) { |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3983 |
#if defined(__MSBFIRST) |
8070 | 3984 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3985 |
#else |
8070 | 3986 |
u.bytes[0] = (num >> 24) & 0xFF; |
3987 |
u.bytes[1] = (num >> 16) & 0xFF; |
|
3988 |
u.bytes[2] = (num >> 8) & 0xFF; |
|
3989 |
u.bytes[3] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3990 |
#endif |
8070 | 3991 |
} else { |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3992 |
#if defined(__LSBFIRST) |
8070 | 3993 |
u.intVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3994 |
#else |
8070 | 3995 |
u.bytes[3] = (num >> 24) & 0xFF; |
3996 |
u.bytes[2] = (num >> 16) & 0xFF; |
|
3997 |
u.bytes[1] = (num >> 8) & 0xFF; |
|
3998 |
u.bytes[0] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
3999 |
#endif |
8070 | 4000 |
} |
4001 |
||
4002 |
f = __FILEVal(fp); |
|
4003 |
if (_buffered = (__INST(buffered) == true)) { |
|
4004 |
__WRITING__(f) |
|
4005 |
} |
|
4006 |
__WRITEBYTES__(cnt, f, u.bytes, 4, _buffered); |
|
4007 |
||
4008 |
if (cnt == 4) { |
|
4009 |
if (__isSmallInteger(__INST(position))) { |
|
4010 |
INT np = __intVal(__INST(position)) + 4; |
|
4011 |
OBJ t; |
|
4012 |
||
4013 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
4014 |
} else { |
|
4015 |
__INST(position) = nil; /* i.e. do not know */ |
|
4016 |
} |
|
4017 |
RETURN ( self ); |
|
4018 |
} |
|
4019 |
__INST(position) = nil; /* i.e. do not know */ |
|
4020 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
612 | 4021 |
} |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4022 |
badArg: ; |
612 | 4023 |
%}. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4024 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4025 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4026 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
612 | 4027 |
|
4028 |
aNumber isInteger ifTrue:[ |
|
8070 | 4029 |
^ super nextPutLong:aNumber MSB:msbFlag |
92 | 4030 |
]. |
612 | 4031 |
self argumentMustBeInteger |
4032 |
! |
|
4033 |
||
4034 |
nextPutShort:aNumber MSB:msbFlag |
|
4035 |
"Write the argument, aNumber as a short (two bytes). If msbFlag is |
|
4036 |
true, data is written most-significant byte first; otherwise least |
|
4037 |
first. |
|
4038 |
Works in both binary and text modes." |
|
4039 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4040 |
%{ |
612 | 4041 |
int num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4042 |
union { |
8070 | 4043 |
char bytes[2]; |
4044 |
short shortVal; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4045 |
} u; |
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4046 |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4047 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4048 |
int cnt, _buffered; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4049 |
OBJ fp; |
612 | 4050 |
|
1133 | 4051 |
__INST(lastErrorNumber) = nil; |
4052 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 4053 |
&& (__INST(mode) != @symbol(readonly)) |
4054 |
&& __isSmallInteger(aNumber) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4055 |
) { |
8070 | 4056 |
num = __intVal(aNumber); |
4057 |
if (msbFlag == true) { |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4058 |
#if defined(__MSBFIRST) |
8070 | 4059 |
u.shortVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4060 |
#else |
8070 | 4061 |
u.bytes[0] = (num >> 8) & 0xFF; |
4062 |
u.bytes[1] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4063 |
#endif |
8070 | 4064 |
} else { |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4065 |
#if defined(__LSBFIRST) |
8070 | 4066 |
u.shortVal = num; |
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4067 |
#else |
8070 | 4068 |
u.bytes[1] = (num >> 8) & 0xFF; |
4069 |
u.bytes[0] = num & 0xFF; |
|
4384
f8e779b99b14
slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents:
4383
diff
changeset
|
4070 |
#endif |
8070 | 4071 |
} |
4072 |
||
4073 |
f = __FILEVal(fp); |
|
4074 |
if (_buffered = (__INST(buffered) == true)) { |
|
4075 |
__WRITING__(f) |
|
4076 |
} |
|
4077 |
__WRITEBYTES__(cnt, f, u.bytes, 2, _buffered); |
|
4078 |
||
4079 |
if (cnt == 2) { |
|
4080 |
if (__isSmallInteger(__INST(position))) { |
|
4081 |
INT np = __intVal(__INST(position)) + 2; |
|
4082 |
OBJ t; |
|
4083 |
||
4084 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
4085 |
} else { |
|
4086 |
__INST(position) = nil; /* i.e. do not know */ |
|
4087 |
} |
|
4088 |
RETURN ( self ); |
|
4089 |
} |
|
4090 |
__INST(position) = nil; /* i.e. do not know */ |
|
4091 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
612 | 4092 |
} |
4093 |
%}. |
|
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4094 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self.]. |
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4095 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
4096 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
612 | 4097 |
self argumentMustBeInteger |
10 | 4098 |
! ! |
612 | 4099 |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4100 |
!ExternalStream methodsFor:'positioning'! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4101 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4102 |
position0Based |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4103 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4104 |
! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4105 |
|
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4106 |
position0Based:index0Based |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4107 |
self subclassResponsibility |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4108 |
! ! |
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
7051
diff
changeset
|
4109 |
|
612 | 4110 |
!ExternalStream methodsFor:'private'! |
4111 |
||
4112 |
clearEOF |
|
4113 |
hitEOF := false |
|
4114 |
! |
|
4115 |
||
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4116 |
connectTo:aFileDescriptor withMode:openmode |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4117 |
"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
|
4118 |
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
|
4119 |
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
|
4120 |
a Stream object. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4121 |
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
|
4122 |
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
|
4123 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4124 |
|retVal| |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4125 |
|
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4468
diff
changeset
|
4126 |
filePointer notNil ifTrue:[^ self errorAlreadyOpen]. |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4127 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4128 |
FILEPOINTER f; |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4129 |
OBJ fp; |
2765 | 4130 |
FILE *fdopen(); |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4131 |
|
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4132 |
if (__isSmallInteger(aFileDescriptor) |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4133 |
&& (__qClass(openmode)== @global(String))) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4134 |
f = (FILEPOINTER) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4135 |
if (f == NULL) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4136 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4137 |
__INST(position) = nil; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4138 |
} else { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4139 |
if (@global(FileOpenTrace) == true) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4140 |
fprintf(stderr, "fdopen [ExternalStream] %d -> %x\n", __intVal(aFileDescriptor), f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4141 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4142 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4143 |
__INST(filePointer) = fp = __MKFILEPOINTER(f); __STORE(self, fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4144 |
__INST(position) = @global(PositionableStream:ZeroPosition); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4145 |
retVal = self; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4146 |
} |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4147 |
} |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4148 |
%}. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4149 |
retVal notNil ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4150 |
buffered := true. "default is buffered" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4151 |
Lobby register:self |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4152 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4153 |
lastErrorNumber notNil ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4154 |
" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4155 |
the open failed for some reason ... |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4156 |
" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4157 |
^ self openError |
1048
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4158 |
]. |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4159 |
^ retVal |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4160 |
! |
c535c5a73cba
added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents:
1044
diff
changeset
|
4161 |
|
2963 | 4162 |
open:aPath withMode:mode |
4163 |
"low level open; opens the file/device and sets the filePointer instance |
|
4164 |
variable. Careful: this does not care for any other state." |
|
4165 |
||
4166 |
|ok| |
|
4167 |
||
4168 |
ok := false. |
|
4169 |
%{ |
|
4170 |
FILE *f; |
|
4171 |
OBJ fp; |
|
4172 |
||
4173 |
if (__isString(aPath)) { |
|
5618
ad60afc06d7c
separated open from memory allocation (i.e. avoid fopen; do it as open+fdopen),
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
4174 |
#ifdef WIN32 |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4175 |
__BEGIN_INTERRUPTABLE__ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4176 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(mode)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4177 |
__END_INTERRUPTABLE__ |
5623
ce4c02168253
removed fopen workaround (now have a better malloc)
Claus Gittinger <cg@exept.de>
parents:
5620
diff
changeset
|
4178 |
#else /* UNIX */ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4179 |
__BEGIN_INTERRUPTABLE__ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4180 |
do { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4181 |
f = fopen((char *) __stringVal(aPath), (char *) __stringVal(mode)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4182 |
} while ((f == NULL) && (__threadErrno == EINTR)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4183 |
__END_INTERRUPTABLE__ |
5623
ce4c02168253
removed fopen workaround (now have a better malloc)
Claus Gittinger <cg@exept.de>
parents:
5620
diff
changeset
|
4184 |
#endif /* UNIX */ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4185 |
if (f == NULL) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4186 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4187 |
} else { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4188 |
if (@global(FileOpenTrace) == true) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4189 |
fprintf(stderr, "fopen %s [ExternalStream] -> %x\n", __stringVal(aPath), f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4190 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4191 |
__INST(filePointer) = fp = __MKFILEPOINTER(f); __STORE(self, fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4192 |
ok = true; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4193 |
} |
2963 | 4194 |
} |
4195 |
%}. |
|
4196 |
ok ifFalse:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4197 |
" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4198 |
the open failed for some reason ... |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4199 |
" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4200 |
^ self openError |
4456 | 4201 |
]. |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4202 |
position := ZeroPosition. |
2963 | 4203 |
Lobby register:self. |
4204 |
! |
|
4205 |
||
612 | 4206 |
reOpen |
4207 |
"sent after snapin to reopen streams. |
|
4208 |
cannot reopen here since I am abstract and have no device knowledge" |
|
4209 |
||
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
4210 |
self class name errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR. |
612 | 4211 |
filePointer := nil. |
4212 |
Lobby unregister:self. |
|
2134
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
4213 |
|
246a3bdab8b4
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2120
diff
changeset
|
4214 |
"Modified: 10.1.1997 / 17:50:44 / cg" |
612 | 4215 |
! |
4216 |
||
4217 |
setLastError:aNumber |
|
4218 |
lastErrorNumber := aNumber |
|
4219 |
! ! |
|
4220 |
||
4221 |
!ExternalStream methodsFor:'queries'! |
|
4222 |
||
4223 |
isBinary |
|
4224 |
"return true, if the stream is in binary (as opposed to text-) mode. |
|
4225 |
The default when created is false." |
|
4226 |
||
4227 |
^ binary |
|
4228 |
! |
|
4229 |
||
7804 | 4230 |
isBlocking |
4231 |
"return true, if O_NONBLOCK is NOT set in the fileDescriptor (propably UNIX specific)" |
|
4232 |
||
4233 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
4234 |
^ OperatingSystem isBlockingOn:self fileDescriptor |
|
4235 |
! |
|
4236 |
||
612 | 4237 |
isExternalStream |
4238 |
"return true, if the receiver is some kind of externalStream; |
|
4239 |
true is returned here - the method redefined from Object." |
|
4240 |
||
4241 |
^ true |
|
4242 |
! |
|
4243 |
||
3863 | 4244 |
isOpen |
4245 |
"return true, if this stream is open" |
|
4246 |
||
4247 |
^ filePointer notNil |
|
4248 |
! |
|
4249 |
||
612 | 4250 |
isReadable |
4251 |
"return true, if this stream can be read from" |
|
4252 |
||
4253 |
^ (mode ~~ #writeonly) |
|
4254 |
! |
|
4255 |
||
4256 |
isWritable |
|
4257 |
"return true, if this stream can be written to" |
|
4258 |
||
4259 |
^ (mode ~~ #readonly) |
|
4260 |
! ! |
|
4261 |
||
4262 |
!ExternalStream methodsFor:'reading'! |
|
4263 |
||
4264 |
next |
|
4265 |
"return the next element; advance read position. |
|
4266 |
In binary mode, an integer is returned, otherwise a character. |
|
4267 |
If there are no more elements, nil is returned." |
|
1 | 4268 |
|
5420 | 4269 |
|c| |
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4270 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4271 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4272 |
int ret, _buffered; |
612 | 4273 |
OBJ pos, fp; |
4274 |
unsigned char ch; |
|
4275 |
||
1133 | 4276 |
__INST(lastErrorNumber) = nil; |
4277 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 4278 |
&& (__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
|
4279 |
) { |
8070 | 4280 |
f = __FILEVal(fp); |
4281 |
||
4282 |
_buffered = (__INST(buffered) == true); |
|
4283 |
if (_buffered) { |
|
4284 |
__READING__(f) |
|
4285 |
} |
|
4286 |
__READBYTE__(ret, f, &ch, _buffered); |
|
4287 |
||
4288 |
if (ret > 0) { |
|
4289 |
pos = __INST(position); |
|
4290 |
if (__isSmallInteger(pos)) { |
|
4291 |
OBJ t; |
|
4292 |
||
4293 |
__INST(position) = t = __MKINT(__intVal(pos) + 1); __STORE(self, t); |
|
4294 |
} else { |
|
4295 |
__INST(position) = nil; /* i.e. do not know */ |
|
4296 |
} |
|
4297 |
if (__INST(binary) == true) { |
|
4298 |
RETURN ( __MKSMALLINT(ch) ); |
|
4299 |
} |
|
4300 |
RETURN ( __MKCHARACTER(ch) ); |
|
4301 |
} |
|
4302 |
||
4303 |
__INST(position) = nil; |
|
4304 |
if (ret < 0) { |
|
4305 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
4306 |
} else /* ret == 0 */ { |
|
4307 |
__INST(hitEOF) = true; |
|
4308 |
} |
|
612 | 4309 |
} |
4310 |
%}. |
|
5420 | 4311 |
hitEOF == true ifTrue:[^ self pastEnd]. |
612 | 4312 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
4313 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
5420 | 4314 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
4315 |
||
4316 |
readAhead notNil ifTrue:[ |
|
8070 | 4317 |
c := readAhead. |
4318 |
readAhead := nil. |
|
4319 |
^ c. |
|
5420 | 4320 |
]. |
4321 |
c := self nextByteFromFile:filePointer. |
|
5430 | 4322 |
c isNil ifTrue:[ |
8070 | 4323 |
^ self pastEnd. |
5430 | 4324 |
]. |
5420 | 4325 |
binary == true ifTrue:[ |
8070 | 4326 |
^ c |
5420 | 4327 |
]. |
4328 |
^ Character value:c |
|
612 | 4329 |
! |
4330 |
||
4331 |
next:count |
|
4332 |
"return the next count elements of the stream as a collection. |
|
4333 |
Redefined to return a String or ByteArray instead of the default: Array." |
|
4334 |
||
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4335 |
|coll nRead| |
612 | 4336 |
|
4337 |
binary ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4338 |
coll := ByteArray uninitializedNew:count |
612 | 4339 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4340 |
coll := String new:count |
612 | 4341 |
]. |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4342 |
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
|
4343 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4344 |
"/ for readStream protocol compatibility, |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4345 |
"/ we must raise an exception here. |
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4346 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4347 |
nRead < count ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4348 |
^ self pastEnd |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4349 |
]. |
612 | 4350 |
^ coll |
2151
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4351 |
|
5f1fd65f8c3b
next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents:
2134
diff
changeset
|
4352 |
"Modified: 11.1.1997 / 17:44:17 / cg" |
612 | 4353 |
! |
4354 |
||
4355 |
peek |
|
4356 |
"return the element to be read next without advancing read position. |
|
4357 |
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
|
4358 |
If there are no more elements, nil is returned." |
612 | 4359 |
|
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4360 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4361 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4362 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4363 |
int ret, _buffered; |
216 | 4364 |
OBJ fp; |
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
4365 |
OBJ ra; |
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
4366 |
|
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
4367 |
if ((ra = __INST(readAhead)) != nil) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4368 |
if (__INST(binary) == true) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4369 |
RETURN ( ra ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4370 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4371 |
c = __intVal(ra); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4372 |
RETURN ( __MKCHARACTER(c) ); |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
4373 |
} |
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
4374 |
|
1133 | 4375 |
__INST(lastErrorNumber) = nil; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4376 |
|
1133 | 4377 |
if (((fp = __INST(filePointer)) != nil) |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4378 |
&& (__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
|
4379 |
) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4380 |
f = __FILEVal(fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4381 |
_buffered = (__INST(buffered) == true); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4382 |
if (_buffered) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4383 |
__READING__(f) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4384 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4385 |
__READBYTE__(ret, f, &c, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4386 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4387 |
if (ret > 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4388 |
__UNGETC__(c, f, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4389 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4390 |
if (__INST(binary) == true) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4391 |
RETURN ( __MKSMALLINT(c) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4392 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4393 |
RETURN ( __MKCHARACTER(c) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4394 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4395 |
if (ret < 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4396 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4397 |
} else /* ret == 0 */ { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4398 |
__INST(hitEOF) = true; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4399 |
} |
1 | 4400 |
} |
159 | 4401 |
%}. |
5420 | 4402 |
hitEOF == true ifTrue:[^ self pastEnd]. |
216 | 4403 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
1 | 4404 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5420 | 4405 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
4406 |
||
4407 |
readAhead notNil ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4408 |
^ readAhead |
5420 | 4409 |
]. |
4410 |
self atEnd ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4411 |
^ self pastEnd |
5420 | 4412 |
]. |
4413 |
readAhead := self next. |
|
4414 |
^ readAhead |
|
1295 | 4415 |
! |
4416 |
||
4417 |
upToEnd |
|
4418 |
"return a collection of the elements up-to the end. |
|
4419 |
Return nil if the stream-end is reached before." |
|
4420 |
||
6569 | 4421 |
|answerStream buffer count| |
4422 |
||
4423 |
buffer := self contentsSpecies new:4096. |
|
1295 | 4424 |
[self atEnd] whileFalse:[ |
7832 | 4425 |
count := self nextAvailableBytes:4096 into:buffer startingAt:1. |
4426 |
count ~~ 0 ifTrue:[ |
|
4427 |
answerStream isNil ifTrue:[ |
|
4428 |
answerStream := WriteStream with:buffer. |
|
4429 |
answerStream position0Based:count. |
|
4430 |
buffer := self contentsSpecies new:4096. |
|
4431 |
] ifFalse:[ |
|
4432 |
answerStream nextPutAll:buffer startingAt:1 to:count. |
|
4433 |
]. |
|
4434 |
]. |
|
1295 | 4435 |
]. |
6758
bc933037a1dc
oops - upToEnd failed if already at the end
Claus Gittinger <cg@exept.de>
parents:
6661
diff
changeset
|
4436 |
answerStream isNil ifTrue:[^ self contentsSpecies new]. |
1295 | 4437 |
^ answerStream contents |
4438 |
||
7054
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
4439 |
" |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
4440 |
('smalltalk.rc' asFilename readStream upToEnd) |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
4441 |
= |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
4442 |
('smalltalk.rc' asFilename readStream contentsOfEntireFile) |
685d359f9847
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
7053
diff
changeset
|
4443 |
" |
612 | 4444 |
! ! |
4445 |
||
4446 |
!ExternalStream methodsFor:'reimplemented for speed'! |
|
159 | 4447 |
|
4448 |
nextAlphaNumericWord |
|
379 | 4449 |
"read the next word (i.e. up to non letter-or-digit) after first |
4450 |
skipping any whiteSpace. |
|
4451 |
Return a string containing those characters. |
|
4452 |
There is a limit of 1023 characters in the word - if longer, |
|
4453 |
it is truncated." |
|
159 | 4454 |
|
4455 |
%{ /* STACK: 2000 */ |
|
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4456 |
FILEPOINTER f; |
159 | 4457 |
int len; |
4458 |
char buffer[1024]; |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4459 |
unsigned char ch; |
159 | 4460 |
int cnt = 0; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4461 |
int ret, _buffered; |
216 | 4462 |
OBJ fp; |
4463 |
||
1133 | 4464 |
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
|
4465 |
&& (__INST(mode) != @symbol(writeonly)) |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4466 |
) { |
8070 | 4467 |
f = __FILEVal(fp); |
4468 |
_buffered = (__INST(buffered) == true); |
|
4469 |
if (_buffered) { |
|
4470 |
__READING__(f) |
|
4471 |
} |
|
4472 |
||
4473 |
/* |
|
4474 |
* skip whiteSpace first ... |
|
4475 |
*/ |
|
4476 |
do { |
|
4477 |
__READBYTE__(ret, f, &ch, _buffered); |
|
4478 |
if (ret > 0) |
|
4479 |
cnt++; |
|
4480 |
else |
|
4481 |
break; |
|
4482 |
} while ( |
|
379 | 4483 |
#ifndef NON_ASCII |
8070 | 4484 |
(ch < ' ') || |
379 | 4485 |
#endif |
8070 | 4486 |
(ch == ' ' ) || (ch == '\t') || (ch == '\r') |
4487 |
|| (ch == '\n') || (ch == 0x0b)); |
|
4488 |
||
4489 |
len = 0; |
|
4490 |
while (ret > 0 && |
|
4491 |
(((ch >= 'a') && (ch <= 'z')) || |
|
4492 |
((ch >= 'A') && (ch <= 'Z')) || |
|
4493 |
((ch >= '0') && (ch <= '9'))) |
|
4494 |
) { |
|
4495 |
buffer[len++] = ch; |
|
4496 |
if (len >= (sizeof(buffer)-1)) { |
|
4497 |
/* emergency */ |
|
4498 |
break; |
|
4499 |
} |
|
4500 |
__READBYTE__(ret, f, &ch, _buffered); |
|
4501 |
if (ret > 0) |
|
4502 |
cnt++; |
|
4503 |
else |
|
4504 |
break; |
|
4505 |
} |
|
4506 |
||
4507 |
if (ret <= 0) { |
|
4508 |
if (ret < 0) { |
|
4509 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
4510 |
goto err; |
|
4511 |
} |
|
4512 |
else if (ret == 0) |
|
4513 |
__INST(hitEOF) = true; |
|
4514 |
} else { |
|
4515 |
__UNGETC__(ch, f, _buffered); |
|
4516 |
cnt--; |
|
4517 |
} |
|
4518 |
||
4519 |
if (__isSmallInteger(__INST(position))) { |
|
4520 |
INT np = __intVal(__INST(position)) + cnt; |
|
4521 |
OBJ t; |
|
4522 |
||
4523 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
4524 |
} else { |
|
4525 |
__INST(position) = nil; /* i.e. do not know */ |
|
4526 |
} |
|
4527 |
||
4528 |
if (len != 0) { |
|
4529 |
buffer[len] = '\0'; |
|
4530 |
RETURN ( __MKSTRING_L(buffer, len) ); |
|
4531 |
} |
|
159 | 4532 |
} |
4533 |
err: ; |
|
4534 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4535 |
hitEOF ifTrue:[^ self pastEnd]. |
159 | 4536 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
4537 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
5414 | 4538 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
4539 |
||
4540 |
^ super nextAlphaNumericWord |
|
1 | 4541 |
! |
4542 |
||
4543 |
nextChunk |
|
4544 |
"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
|
4545 |
exclamation mark. Within the chunk, exclamation marks have to be doubled - |
216 | 4546 |
except within primitive code (this exception was added to make it easier |
4547 |
to edit primitive code with external editors). This means, that other |
|
4548 |
Smalltalks cannot always read chunks containing primitive code - but that |
|
4549 |
doesnt really matter, since C-primitives are an ST/X feature anyway. |
|
4550 |
Reimplemented here for more speed." |
|
4551 |
||
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
4552 |
|retVal outOfMemory buffer| |
1 | 4553 |
|
159 | 4554 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5420 | 4555 |
binary == true ifTrue:[^ self errorBinary]. |
159 | 4556 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
216 | 4557 |
|
2854
3c8bf66e4e7d
give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents:
2766
diff
changeset
|
4558 |
%{ /* 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
|
4559 |
/* |
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
4560 |
* 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
|
4561 |
* 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
|
4562 |
* 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
|
4563 |
* 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
|
4564 |
*/ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4565 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4566 |
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
|
4567 |
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
|
4568 |
int ret; |
1823 | 4569 |
unsigned char *bufferPtr = (unsigned char *)0; |
2874
020627074c9e
oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents:
2861
diff
changeset
|
4570 |
unsigned char fastBuffer[8000]; |
1 | 4571 |
REGISTER int index; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4572 |
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
|
4573 |
int atBeginOfLine = 1, inPrimitive = 0; |
2920 | 4574 |
int haveCR = 0, haveNL = 0; |
216 | 4575 |
|
1133 | 4576 |
__INST(lastErrorNumber) = nil; |
4577 |
f = __FILEVal(__INST(filePointer)); |
|
668
73165201a9da
nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
4578 |
|
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4579 |
_buffered = (__INST(buffered) == true); |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4580 |
if (_buffered) { |
8070 | 4581 |
__READING__(f) |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4582 |
} |
159 | 4583 |
|
1 | 4584 |
/* |
4585 |
* skip spaces |
|
4586 |
*/ |
|
673
2c3a4a536cd1
oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents:
671
diff
changeset
|
4587 |
c = '\n'; |
1 | 4588 |
while (! done) { |
8070 | 4589 |
lastC = c; |
4590 |
__READBYTE__(ret, f, &c, _buffered); |
|
4591 |
if (ret <= 0) { |
|
4592 |
goto err; |
|
4593 |
} |
|
4594 |
nread++; |
|
4595 |
atBeginOfLine = 0; |
|
4596 |
switch (c) { |
|
4597 |
case '\n': |
|
4598 |
case ' ': |
|
4599 |
case '\t': |
|
4600 |
case '\r': |
|
4601 |
case '\b': |
|
4602 |
case '\014': |
|
4603 |
break; |
|
4604 |
||
4605 |
default: |
|
4606 |
atBeginOfLine = (lastC == '\n'); |
|
4607 |
done = 1; |
|
4608 |
break; |
|
4609 |
} |
|
1 | 4610 |
} |
4611 |
||
4612 |
/* |
|
4613 |
* read chunk into a buffer |
|
4614 |
*/ |
|
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
4615 |
bufferPtr = fastBuffer; fastFlag = 1; |
216 | 4616 |
currSize = sizeof(fastBuffer); |
362 | 4617 |
|
1 | 4618 |
index = 0; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4619 |
for (;;) { |
8070 | 4620 |
__READBYTE__(ret, f, &peekC, _buffered); |
4621 |
if ((c == '%') && atBeginOfLine && ret > 0) { |
|
4622 |
if (peekC == '{') { |
|
4623 |
inPrimitive = 1; |
|
4624 |
} else if (peekC == '}') { |
|
4625 |
inPrimitive = 0; |
|
4626 |
} |
|
4627 |
} else if (c == '!' && !inPrimitive) { |
|
4628 |
if (ret > 0 && peekC == '!') { |
|
4629 |
/* |
|
4630 |
* convert double-! to a single ! |
|
4631 |
*/ |
|
4632 |
__READBYTE__(ret, f, &peekC, _buffered); |
|
4633 |
if (ret > 0) |
|
4634 |
nread++; |
|
4635 |
} else { |
|
4636 |
/* |
|
4637 |
* End of chunk, push back lookahead character |
|
4638 |
* and leave loop. |
|
4639 |
*/ |
|
4640 |
if (ret > 0) { |
|
4641 |
__UNGETC__(peekC, f, _buffered); |
|
4642 |
} else |
|
4643 |
ret = 1; |
|
4644 |
break; |
|
4645 |
} |
|
4646 |
} |
|
4647 |
||
4648 |
/* |
|
4649 |
* do we have to resize the buffer ? |
|
4650 |
*/ |
|
4651 |
if ((index+2) >= currSize) { |
|
4652 |
OBJ newBuffer; |
|
4653 |
unsigned char *nbp; |
|
4654 |
||
4655 |
newBuffer = __MKEMPTYSTRING(currSize * 2); |
|
4656 |
if (!fastFlag) { |
|
4657 |
/* |
|
4658 |
* refetch - buffer could be moved by GC |
|
4659 |
*/ |
|
4660 |
bufferPtr = __stringVal(buffer); |
|
4661 |
} |
|
4662 |
if (newBuffer == nil) { |
|
4663 |
/* |
|
4664 |
* mhmh - chunk seems to be very big .... |
|
4665 |
*/ |
|
4666 |
outOfMemory = true; |
|
4667 |
goto err; |
|
4668 |
} |
|
4669 |
nbp = __stringVal(newBuffer); |
|
4670 |
bcopy(bufferPtr, nbp, index); |
|
4671 |
bufferPtr = nbp; |
|
4672 |
bufferPtr[index] = '\0'; |
|
4673 |
buffer = newBuffer; |
|
4674 |
fastFlag = 0; |
|
4675 |
currSize = currSize * 2; |
|
4676 |
} |
|
4677 |
||
4678 |
if (!fastFlag) { |
|
4679 |
/* |
|
4680 |
* old buffer may have moved (interrupt while reading) |
|
4681 |
* - refetch pointer |
|
4682 |
*/ |
|
4683 |
bufferPtr = __stringVal(buffer); |
|
4684 |
} |
|
4685 |
||
4686 |
/* |
|
4687 |
* filter out cr-nl; make it nl |
|
4688 |
*/ |
|
4689 |
if (c == '\n') { |
|
4690 |
haveNL = 1; |
|
4691 |
if (index > 0) { |
|
4692 |
if (bufferPtr[index-1] == '\r') { |
|
4693 |
index--; |
|
4694 |
} |
|
4695 |
} |
|
4696 |
} else { |
|
4697 |
if (c == '\r') { |
|
4698 |
haveCR = 1; |
|
4699 |
} |
|
4700 |
} |
|
4701 |
bufferPtr[index++] = c; |
|
4702 |
if (ret <= 0) { |
|
4703 |
if (ret == 0) |
|
4704 |
break; /* End of chunk reached */ |
|
4705 |
goto err; |
|
4706 |
} |
|
4707 |
nread++; |
|
4708 |
atBeginOfLine = (c == '\n'); |
|
4709 |
c = peekC; |
|
1 | 4710 |
} |
92 | 4711 |
|
1 | 4712 |
/* |
2920 | 4713 |
* care for CR-limited files. |
4714 |
* Replace CR's by NL's |
|
4715 |
*/ |
|
4716 |
if (!haveNL && haveCR) { |
|
8070 | 4717 |
int i; |
4718 |
||
4719 |
for (i=index-1; i>=0; i--) { |
|
4720 |
if (bufferPtr[i] == '\r') { |
|
4721 |
bufferPtr[i] = '\n'; |
|
4722 |
} |
|
4723 |
} |
|
2920 | 4724 |
} |
4725 |
||
4726 |
/* |
|
1 | 4727 |
* 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
|
4728 |
* 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
|
4729 |
* 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
|
4730 |
* fast (C) buffer or from real (ST) buffer. |
1 | 4731 |
*/ |
665
429936f8e6e7
fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
4732 |
if (fastFlag) { |
8070 | 4733 |
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
|
4734 |
} else { |
8070 | 4735 |
retVal = __MKSTRING_ST_L(buffer, index); |
216 | 4736 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4737 |
|
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
4738 |
err: ; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4739 |
if (ret <= 0) { |
8070 | 4740 |
if (ret == 0) |
4741 |
__INST(hitEOF) = true; |
|
4742 |
else /* ret < 0 */ |
|
4743 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4744 |
} |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
4745 |
if (__isSmallInteger(__INST(position))) { |
8070 | 4746 |
INT np = __intVal(__INST(position)) + nread; |
4747 |
OBJ t; |
|
4748 |
||
4749 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
4750 |
} else { |
8070 | 4751 |
__INST(position) = nil; /* i.e. do not know */ |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4752 |
} |
159 | 4753 |
%}. |
370 | 4754 |
retVal isNil ifTrue:[ |
8070 | 4755 |
"/ |
4756 |
"/ arrive here with retVal==nil either on error or premature EOF |
|
4757 |
"/ or if running out of malloc-memory |
|
4758 |
"/ |
|
4759 |
hitEOF == true ifTrue:[^ self pastEnd]. |
|
4760 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
|
4761 |
outOfMemory == true ifTrue:[ |
|
4762 |
" |
|
4763 |
buffer memory allocation failed. |
|
4764 |
When we arrive here, there was no memory available for the |
|
4765 |
chunk. (seems to be too big of a chunk ...) |
|
4766 |
Bad luck - you should increase the ulimit and/or swap space on your machine. |
|
4767 |
" |
|
4768 |
^ ObjectMemory allocationFailureSignal raise. |
|
4769 |
]. |
|
4770 |
^ super nextChunk |
|
216 | 4771 |
]. |
1 | 4772 |
^ retVal |
612 | 4773 |
! |
4774 |
||
4775 |
nextMatchFor:anObject |
|
4776 |
"skip all objects up-to and including anObject, return anObject on success, |
|
4777 |
nil if end-of-file is reached before. The next read operation will return |
|
4778 |
the element after anObject. |
|
4779 |
Only single byte characters are currently supported." |
|
4780 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4781 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4782 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4783 |
int ret, peekValue; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4784 |
char c; |
612 | 4785 |
OBJ fp; |
4786 |
||
1133 | 4787 |
__INST(lastErrorNumber) = nil; |
4788 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 4789 |
&& (__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
|
4790 |
) { |
8070 | 4791 |
if ((__INST(binary) == true) && __isSmallInteger(anObject)) { |
4792 |
peekValue = __intVal(anObject) & 0xFF; |
|
4793 |
} else { |
|
4794 |
if ((__INST(binary) != true) && __isCharacter(anObject)) { |
|
4795 |
peekValue = __intVal(_characterVal(anObject)) & 0xFF; |
|
4796 |
} else { |
|
4797 |
peekValue = -1; |
|
4798 |
} |
|
4799 |
} |
|
4800 |
||
4801 |
if (peekValue >= 0) { |
|
4802 |
int _buffered; |
|
4803 |
||
4804 |
__INST(position) = nil; /* i.e. do not know */ |
|
4805 |
f = __FILEVal(fp); |
|
4806 |
||
4807 |
if (_buffered = (__INST(buffered) == true)) { |
|
4808 |
__READING__(f) |
|
4809 |
} |
|
4810 |
||
4811 |
for (;;) { |
|
4812 |
__READBYTE__(ret, f, &c, _buffered); |
|
4813 |
if (ret <= 0) { |
|
4814 |
if (ret < 0) |
|
4815 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
4816 |
else |
|
4817 |
__INST(hitEOF) = true; |
|
4818 |
break; |
|
4819 |
} |
|
4820 |
if (c == peekValue) { |
|
4821 |
RETURN (anObject); |
|
4822 |
} |
|
4823 |
} |
|
4824 |
} |
|
612 | 4825 |
} |
4826 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4827 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 4828 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
4829 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
4830 |
^ super nextMatchFor:anObject |
|
4831 |
! |
|
4832 |
||
4833 |
peekFor:anObject |
|
4834 |
"return true and move past next element, if next == something. |
|
4835 |
Otherwise, stay and return false. False is also returned |
|
4836 |
when EOF is encountered. |
|
4837 |
The argument must be an integer if in binary, a character if in |
|
4838 |
text mode; only single byte characters are currently supported." |
|
4839 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4840 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4841 |
FILEPOINTER f; |
3029
aa14768e0e6a
larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents:
3016
diff
changeset
|
4842 |
unsigned char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4843 |
int ret, peekValue, _buffered; |
612 | 4844 |
OBJ fp; |
4845 |
||
1133 | 4846 |
__INST(lastErrorNumber) = nil; |
4847 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 4848 |
&& (__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
|
4849 |
) { |
8070 | 4850 |
if (__INST(binary) == true) { |
4851 |
if (__isSmallInteger(anObject)) { |
|
4852 |
peekValue = __intVal(anObject) & 0xFF; |
|
4853 |
} else { |
|
4854 |
goto bad; |
|
4855 |
} |
|
4856 |
} else { |
|
4857 |
if (__isCharacter(anObject)) { |
|
4858 |
peekValue = __intVal(_characterVal(anObject)) & 0xFF; |
|
4859 |
} else { |
|
4860 |
goto bad; |
|
4861 |
} |
|
4862 |
} |
|
4863 |
||
4864 |
f = __FILEVal(fp); |
|
4865 |
||
4866 |
_buffered = (__INST(buffered) == true); |
|
4867 |
if (_buffered) { |
|
4868 |
__READING__(f) |
|
4869 |
} |
|
4870 |
__READBYTE__(ret, f, &c, _buffered); |
|
4871 |
if (ret > 0) { |
|
4872 |
if (c == peekValue) { |
|
4873 |
if (__isSmallInteger(__INST(position))) { |
|
4874 |
INT np = __intVal(__INST(position)) + 1; |
|
4875 |
OBJ t; |
|
4876 |
||
4877 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
4878 |
} else { |
|
4879 |
__INST(position) = nil; /* i.e. do not know */ |
|
4880 |
} |
|
4881 |
RETURN (true); |
|
4882 |
} |
|
4883 |
__UNGETC__(c, f, _buffered); |
|
4884 |
RETURN (false); |
|
4885 |
} |
|
4886 |
if (ret < 0) { |
|
4887 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
4888 |
} else /* ret == 0 */ |
|
4889 |
__INST(hitEOF) = true; |
|
4890 |
} |
|
612 | 4891 |
bad: ; |
4892 |
%}. |
|
4893 |
^ super peekFor:anObject |
|
4894 |
! |
|
4895 |
||
4896 |
skipLine |
|
4897 |
"read the next line (characters up to newline) skip only; |
|
4898 |
return nil if EOF reached, self otherwise. |
|
4899 |
Not allowed in binary mode." |
|
4900 |
||
4901 |
%{ /* STACK:2000 */ |
|
4902 |
||
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4903 |
FILEPOINTER f; |
612 | 4904 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4905 |
int ret, _buffered; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4906 |
char c; |
612 | 4907 |
|
1133 | 4908 |
__INST(lastErrorNumber) = nil; |
4909 |
if (((fp = __INST(filePointer)) != nil) |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4910 |
&& (__INST(mode) != @symbol(writeonly)) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4911 |
&& (__INST(binary) != true) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4912 |
) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4913 |
f = __FILEVal(fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4914 |
if (_buffered = (__INST(buffered) == true)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4915 |
__READING__(f) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4916 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4917 |
for (;;) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4918 |
__READBYTE__(ret, f, &c, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4919 |
if (ret > 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4920 |
if (c == '\n') |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4921 |
RETURN(self) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4922 |
} else |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4923 |
break; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4924 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4925 |
if (ret < 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4926 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4927 |
} else /* ret == 0 */ { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4928 |
__INST(hitEOF) = true; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4929 |
} |
612 | 4930 |
} |
4931 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
4932 |
hitEOF ifTrue:[^ self pastEnd]. |
2331 | 4933 |
lastErrorNumber notNil ifTrue:[self readError. ^ self]. |
4934 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
4935 |
binary ifTrue:[self errorBinary. ^ self]. |
|
4936 |
self errorWriteOnly |
|
612 | 4937 |
! |
4938 |
||
4939 |
skipSeparators |
|
4940 |
"skip all whitespace; next will return next non-white-space character |
|
4941 |
or nil if endOfFile reached. Not allowed in binary mode. |
|
4942 |
- reimplemented for speed" |
|
4943 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
4944 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
4945 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4946 |
char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
4947 |
int ret, _buffered; |
612 | 4948 |
OBJ fp; |
4949 |
||
1133 | 4950 |
__INST(lastErrorNumber) = nil; |
4951 |
if (((fp = __INST(filePointer)) != nil) |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4952 |
&& (__INST(mode) != @symbol(writeonly)) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4953 |
&& (__INST(binary) != true) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
4954 |
) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4955 |
f = __FILEVal(fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4956 |
_buffered = (__INST(buffered) == true); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4957 |
if (_buffered) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4958 |
__READING__(f) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4959 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4960 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4961 |
while (1) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4962 |
__READBYTE__(ret, f, &c, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4963 |
if (ret <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4964 |
if (ret < 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4965 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4966 |
} else /* ret == 0 */ { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4967 |
__INST(hitEOF) = true; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4968 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4969 |
break; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4970 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4971 |
switch (c) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4972 |
case ' ': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4973 |
case '\t': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4974 |
case '\n': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4975 |
case '\r': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4976 |
case '\b': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4977 |
case '\f': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4978 |
break; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4979 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4980 |
default: |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4981 |
__UNGETC__(c, f, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4982 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4983 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
4984 |
} |
612 | 4985 |
} |
4986 |
%}. |
|
5420 | 4987 |
hitEOF == true ifTrue:[^ self pastEnd]. |
612 | 4988 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
4989 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
4990 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
|
5420 | 4991 |
(binary == true) ifTrue:[^ self errorBinary]. |
4992 |
^ super skipSeparators. |
|
612 | 4993 |
! |
4994 |
||
4995 |
skipSeparatorsExceptCR |
|
4996 |
"skip all whitespace but no newlines; |
|
4997 |
next will return next non-white-space character |
|
4998 |
or nil if endOfFile reached. Not allowed in binary mode. |
|
4999 |
- reimplemented for speed" |
|
5000 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5001 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5002 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5003 |
char c; |
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5004 |
int ret, _buffered; |
612 | 5005 |
OBJ fp; |
5006 |
||
1133 | 5007 |
__INST(lastErrorNumber) = nil; |
5008 |
if (((fp = __INST(filePointer)) != nil) |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5009 |
&& (__INST(mode) != @symbol(writeonly)) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5010 |
&& (__INST(binary) != true) |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5011 |
) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5012 |
f = __FILEVal(fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5013 |
_buffered = (__INST(buffered) == true); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5014 |
if (_buffered) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5015 |
__READING__(f) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5016 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5017 |
while (1) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5018 |
__READBYTE__(ret, f, &c, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5019 |
if (ret <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5020 |
if (ret < 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5021 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5022 |
} else /* ret == 0 */ { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5023 |
__INST(hitEOF) = true; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5024 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5025 |
break; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5026 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5027 |
switch (c) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5028 |
case ' ': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5029 |
case '\t': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5030 |
case '\b': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5031 |
case '\f': |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5032 |
break; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5033 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5034 |
default: |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5035 |
__UNGETC__(c, f, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5036 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5037 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5038 |
} |
612 | 5039 |
} |
5040 |
%}. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1141
diff
changeset
|
5041 |
hitEOF ifTrue:[^ self pastEnd]. |
612 | 5042 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
5043 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
5044 |
(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
|
5045 |
^ self errorBinary. |
612 | 5046 |
! |
5047 |
||
5048 |
skipThrough:aCharacter |
|
6012
21eebe6e6997
fixed: return nil if skipThrough: hits EOF
Claus Gittinger <cg@exept.de>
parents:
5961
diff
changeset
|
5049 |
"skip all characters up-to and including aCharacter. |
21eebe6e6997
fixed: return nil if skipThrough: hits EOF
Claus Gittinger <cg@exept.de>
parents:
5961
diff
changeset
|
5050 |
Return the receiver if skip was successful, |
21eebe6e6997
fixed: return nil if skipThrough: hits EOF
Claus Gittinger <cg@exept.de>
parents:
5961
diff
changeset
|
5051 |
otherwise (i.e. if not found) return nil and leave the stream positioned at the end. |
612 | 5052 |
The next read operation will return the character after aCharacter. |
5053 |
The argument, aCharacter must be character, or integer when in binary mode. |
|
5054 |
Only single byte characters are currently supported." |
|
5055 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5056 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5057 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5058 |
REGISTER int cSearch; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5059 |
unsigned char c; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5060 |
int ret, _buffered; |
612 | 5061 |
OBJ fp; |
5062 |
||
1133 | 5063 |
__INST(lastErrorNumber) = nil; |
5064 |
if (((fp = __INST(filePointer)) != nil) |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5065 |
&& (__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
|
5066 |
) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5067 |
if (__INST(binary) == true) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5068 |
/* searched for object must be a smallInteger */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5069 |
if (! __isSmallInteger(aCharacter)) goto badArgument; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5070 |
cSearch = __intVal(aCharacter); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5071 |
} else { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5072 |
/* searched for object must be a character */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5073 |
if (! __isCharacter(aCharacter)) goto badArgument; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5074 |
cSearch = __intVal(_characterVal(aCharacter)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5075 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5076 |
/* Q: should we just say: "not found" ? */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5077 |
if ((cSearch < 0) || (cSearch > 255)) goto badArgument; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5078 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5079 |
f = __FILEVal(fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5080 |
if (_buffered = (__INST(buffered) == true)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5081 |
__READING__(f) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5082 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5083 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5084 |
while (1) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5085 |
__READBYTE__(ret, f, &c, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5086 |
if (ret <= 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5087 |
if (ret < 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5088 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5089 |
} else /* ret == 0 */ { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5090 |
__INST(hitEOF) = true; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5091 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5092 |
break; |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5093 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5094 |
if (c == cSearch) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5095 |
RETURN (self); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5096 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5097 |
} |
612 | 5098 |
} |
5099 |
badArgument: ; |
|
5100 |
%}. |
|
6012
21eebe6e6997
fixed: return nil if skipThrough: hits EOF
Claus Gittinger <cg@exept.de>
parents:
5961
diff
changeset
|
5101 |
hitEOF ifTrue:[^ nil]. |
2331 | 5102 |
lastErrorNumber notNil ifTrue:[self readError. ^ self]. |
5103 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
5104 |
(mode == #writeonly) ifTrue:[self errorWriteOnly. ^ self]. |
|
612 | 5105 |
" |
5106 |
argument must be integer/character in binary mode, |
|
5107 |
character in text mode |
|
5108 |
" |
|
2331 | 5109 |
self error:'invalid argument'. |
612 | 5110 |
|
5111 |
" |
|
5112 |
|s| |
|
5113 |
s := 'Makefile' asFilename readStream. |
|
5114 |
s skipThrough:$=. |
|
5115 |
s next:10 |
|
5116 |
" |
|
5117 |
! |
|
5118 |
||
5119 |
skipToAll:aString |
|
5120 |
"skip for the sequence given by the argument, aCollection; |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
5121 |
return nil if not found, self otherwise. |
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
5122 |
On a successful match, the next read will return characters of aString." |
612 | 5123 |
|
5124 |
|oldPos| |
|
5125 |
||
5126 |
oldPos := self position. |
|
5127 |
(self skipThroughAll:aString) isNil ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5128 |
" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5129 |
restore position |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5130 |
" |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5131 |
self position:oldPos. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5132 |
^ nil |
612 | 5133 |
]. |
5134 |
" |
|
5135 |
position before match-string |
|
5136 |
" |
|
5137 |
self position:(self position - aString size). |
|
5138 |
^ self |
|
5139 |
||
5140 |
" |
|
5141 |
|s| |
|
5142 |
s := 'Makefile' asFilename readStream. |
|
5143 |
s skipToAll:'are'. |
|
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
5144 |
s next:10 |
612 | 5145 |
" |
1490
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
5146 |
|
713852290c8b
use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents:
1478
diff
changeset
|
5147 |
"Modified: 26.6.1996 / 09:22:05 / cg" |
1 | 5148 |
! ! |
612 | 5149 |
|
5420 | 5150 |
!ExternalStream methodsFor:'rel5 protocol'! |
5151 |
||
5152 |
atEndFile:filePointer |
|
5153 |
"for migration to rel5 only" |
|
5154 |
||
5155 |
self primitiveFailed |
|
5156 |
||
5157 |
||
5158 |
! |
|
5159 |
||
5160 |
nextByteFromFile:filePointer |
|
5161 |
"for migration to rel5 only" |
|
5162 |
||
5163 |
self primitiveFailed |
|
5164 |
||
5165 |
||
5166 |
! |
|
5167 |
||
5168 |
nextPutByte:aByte toFile:filePointer |
|
5169 |
"for migration to rel5 only" |
|
5170 |
||
5171 |
self primitiveFailed |
|
5172 |
||
5173 |
||
5174 |
! ! |
|
5175 |
||
612 | 5176 |
!ExternalStream methodsFor:'testing'! |
5177 |
||
5178 |
atEnd |
|
5179 |
"return true, if position is at end" |
|
5180 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5181 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5182 |
FILEPOINTER f; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5183 |
OBJ fp, pos, lim; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5184 |
char c; |
2861 | 5185 |
int ret, _buffered; |
612 | 5186 |
|
1133 | 5187 |
if (__INST(hitEOF) == true) { |
8070 | 5188 |
RETURN (true); |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5189 |
} |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5190 |
pos = __INST(position); |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5191 |
lim = __INST(readLimit); |
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5192 |
if (lim != nil) { |
8070 | 5193 |
off_t _pos, _readLimit; |
5194 |
||
5195 |
_pos = __signedLongIntVal(pos); |
|
5196 |
_pos = _pos - __intVal( @global(PositionableStream:ZeroPosition)) + 1; |
|
5197 |
_readLimit = __signedLongIntVal(lim); |
|
5198 |
if (_pos > _readLimit) { |
|
5199 |
RETURN (true); |
|
5200 |
} |
|
612 | 5201 |
} |
5202 |
||
1133 | 5203 |
__INST(lastErrorNumber) = nil; |
5204 |
||
5205 |
if ((fp = __INST(filePointer)) != nil) { |
|
8070 | 5206 |
f = __FILEVal(fp); |
5207 |
||
5208 |
if (_buffered = (__INST(buffered) == true)) { |
|
5209 |
__READING__(f); |
|
5210 |
} else { |
|
5211 |
if (__INST(readAhead) != nil) { |
|
5212 |
RETURN (false); |
|
5213 |
} |
|
5214 |
} |
|
5215 |
||
5216 |
/* |
|
5217 |
* read ahead ... |
|
5218 |
*/ |
|
5219 |
do { |
|
5220 |
__BEGIN_INTERRUPTABLE__ |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5221 |
|
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5222 |
#ifdef WIN32 |
8070 | 5223 |
__threadErrno = 0; |
4914 | 5224 |
#endif |
8070 | 5225 |
__READBYTE__(ret, f, &c, _buffered); |
5226 |
||
5227 |
__END_INTERRUPTABLE__ |
|
5228 |
} while ((ret < 0) && (__threadErrno == EINTR)); |
|
4152
0c1780ae527f
dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents:
4108
diff
changeset
|
5229 |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5230 |
#if defined(WIN32) && defined(EPIPE) |
8070 | 5231 |
if ((ret < 0) && (__threadErrno == EPIPE)) { |
5232 |
ret = 0; |
|
5233 |
__threadErrno = 0; |
|
5234 |
} |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5235 |
#endif |
8070 | 5236 |
if (ret > 0) { |
5237 |
__UNGETC__(c&0xff, f, _buffered); |
|
5238 |
RETURN (false); |
|
5239 |
} |
|
5240 |
||
5241 |
if (ret == 0) { |
|
5242 |
__INST(hitEOF) = true; |
|
5243 |
RETURN (true); |
|
5244 |
} |
|
5245 |
||
5246 |
/* ret < 0 */ |
|
5247 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
612 | 5248 |
} |
5249 |
%}. |
|
5250 |
lastErrorNumber notNil ifTrue:[^ self readError]. |
|
5420 | 5251 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5252 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
5253 |
readAhead notNil ifTrue:[^ false]. |
|
5254 |
||
5255 |
"/ migration support |
|
5256 |
^ self |
|
8070 | 5257 |
atEndFile:filePointer |
3906
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5258 |
|
7f2d4a3b63e2
oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents:
3878
diff
changeset
|
5259 |
"Modified: / 30.10.1998 / 20:16:06 / cg" |
612 | 5260 |
! |
5261 |
||
5262 |
canReadWithoutBlocking |
|
5263 |
"return true, if any data is available for reading (i.e. |
|
5264 |
a read operation will not block the smalltalk process), false otherwise." |
|
5265 |
||
5266 |
|fd| |
|
5267 |
||
2986
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
5268 |
readAhead notNil ifTrue:[^ true]. |
612 | 5269 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5270 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
5271 |
||
5272 |
fd := self fileDescriptor. |
|
5273 |
^ OperatingSystem readCheck:fd |
|
5274 |
||
5275 |
" |
|
5276 |
|pipe| |
|
5277 |
||
5278 |
pipe := PipeStream readingFrom:'(sleep 10; echo hello)'. |
|
5279 |
pipe canReadWithoutBlocking ifTrue:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5280 |
Transcript showCR:'data available' |
612 | 5281 |
] ifFalse:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5282 |
Transcript showCR:'no data available' |
612 | 5283 |
]. |
5284 |
pipe close |
|
5285 |
" |
|
2986
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
5286 |
|
c6957cf6128f
Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents:
2963
diff
changeset
|
5287 |
"Modified: 25.9.1997 / 13:08:45 / stefan" |
612 | 5288 |
! |
5289 |
||
5290 |
canWriteWithoutBlocking |
|
5291 |
"return true, if data can be written into the stream |
|
5292 |
(i.e. a write operation will not block the smalltalk process)." |
|
5293 |
||
5294 |
|fd| |
|
5295 |
||
5296 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
|
5297 |
mode == #readonly ifTrue:[^ self errorReadOnly]. |
|
5298 |
||
5299 |
fd := self fileDescriptor. |
|
5300 |
^ OperatingSystem writeCheck:fd |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5301 |
! |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5302 |
|
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5303 |
nextError |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5304 |
"return the error by trying to read something. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5305 |
Should only be used, when we know, that a read operation |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5306 |
will return an error (otherwise a character may be lost). |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5307 |
Return an integer (error number), 0 (EOF) or nil (no error)" |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5308 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5309 |
%{ /*NOCONTEXT*/ |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5310 |
FILEPOINTER f; |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5311 |
int ret, _buffered; |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5312 |
OBJ fp; |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5313 |
unsigned char ch; |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5314 |
|
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5315 |
if (((fp = __INST(filePointer)) != nil) |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5316 |
&& (__INST(mode) != @symbol(writeonly)) |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5317 |
) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5318 |
f = __FILEVal(fp); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5319 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5320 |
_buffered = (__INST(buffered) == true); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5321 |
if (_buffered) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5322 |
__READING__(f) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5323 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5324 |
__READBYTE__(ret, f, &ch, _buffered); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5325 |
|
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5326 |
if (ret > 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5327 |
RETURN(nil) |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5328 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5329 |
if (ret < 0) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5330 |
RETURN(__MKSMALLINT(__threadErrno)); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5331 |
} else /* ret == 0 */ { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5332 |
RETURN(__MKSMALLINT(0)); /* EOF */ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5333 |
} |
6269
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5334 |
} |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5335 |
%}. |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5336 |
! |
3a888523e3a6
#errorReporter and #reportOn class-methods
Stefan Vogel <sv@exept.de>
parents:
6255
diff
changeset
|
5337 |
|
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5338 |
numAvailable |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5339 |
"return the number of bytes available for reading" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5340 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5341 |
|fd| |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5342 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5343 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5344 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5345 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5346 |
fd := self fileDescriptor. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5347 |
^ OperatingSystem numAvailableForReadOn:fd. |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5348 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5349 |
"/ self atEnd ifTrue:[^ 0]. |
3432
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
5350 |
"/ self canReadWithoutBlocking ifTrue:[ |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
5351 |
"/ ^ 1 |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
5352 |
"/ ]. |
1228d4ba9518
allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents:
3420
diff
changeset
|
5353 |
"/ ^ 0 |
3274
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5354 |
|
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5355 |
"Created: / 4.2.1998 / 16:56:01 / cg" |
92a24829f14a
added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents:
3255
diff
changeset
|
5356 |
"Modified: / 4.2.1998 / 17:31:11 / cg" |
612 | 5357 |
! ! |
5358 |
||
5359 |
!ExternalStream methodsFor:'waiting for I/O'! |
|
5360 |
||
5101 | 5361 |
canBeSelected |
5362 |
"return true, if this stream can be selected upon" |
|
5363 |
||
5364 |
^ OperatingSystem supportsSelect |
|
5365 |
! |
|
5366 |
||
612 | 5367 |
readWait |
5368 |
"suspend the current process, until the receiver |
|
5369 |
becomes ready for reading. If data is already available, |
|
5370 |
return immediate. |
|
5371 |
The other threads are not affected by the wait." |
|
5372 |
||
5373 |
self readWaitWithTimeoutMs:nil |
|
5374 |
! |
|
5375 |
||
3016 | 5376 |
readWaitTimeoutMs:timeout |
5377 |
"ST-80 compatibility" |
|
5378 |
^ self readWaitWithTimeoutMs:timeout |
|
5379 |
! |
|
5380 |
||
612 | 5381 |
readWaitWithTimeout:timeout |
5382 |
"suspend the current process, until the receiver |
|
5383 |
becomes ready for reading or a timeout (in seconds) expired. |
|
5384 |
If data is already available, return immediate. |
|
5385 |
Return true if a timeout occured (i.e. false, if data is available). |
|
5386 |
The other threads are not affected by the wait." |
|
5387 |
||
4640
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5388 |
|ms| |
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5389 |
|
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5390 |
timeout notNil ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5391 |
ms := timeout * 1000 |
4640
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5392 |
]. |
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5393 |
^ self readWaitWithTimeoutMs:ms |
612 | 5394 |
! |
5395 |
||
5396 |
readWaitWithTimeoutMs:timeout |
|
5397 |
"suspend the current process, until the receiver |
|
5398 |
becomes ready for reading or a timeout (in milliseconds) expired. |
|
5399 |
If data is already available, return immediate. |
|
5400 |
Return true if a timeout occured (i.e. false, if data is available). |
|
5401 |
The other threads are not affected by the wait." |
|
5402 |
||
5403 |
|fd inputSema hasData wasBlocked| |
|
5404 |
||
2120
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5405 |
readAhead notNil ifTrue:[^ false]. |
71c1870df7ba
implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents:
2045
diff
changeset
|
5406 |
|
612 | 5407 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
5408 |
mode == #writeonly ifTrue:[^ self errorWriteOnly]. |
|
5409 |
||
5410 |
fd := self fileDescriptor. |
|
5411 |
(OperatingSystem readCheck:fd) ifTrue:[^ false]. |
|
5412 |
||
5413 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5414 |
hasData := OperatingSystem readCheck:fd. |
|
5415 |
hasData ifFalse:[ |
|
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5416 |
inputSema := Semaphore new name:'readWait'. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5417 |
[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5418 |
timeout notNil ifTrue:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5419 |
Processor signal:inputSema afterMilliseconds:timeout |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5420 |
]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5421 |
Processor signal:inputSema onInput:fd. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5422 |
Processor activeProcess state:#ioWait. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5423 |
inputSema wait. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5424 |
Processor disableSemaphore:inputSema. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5425 |
hasData := OperatingSystem readCheck:fd |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5426 |
] ifCurtailed:[ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5427 |
Processor disableSemaphore:inputSema. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5428 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5429 |
] |
612 | 5430 |
]. |
5431 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
5432 |
^ hasData not |
|
5433 |
! |
|
5434 |
||
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5435 |
readWriteWait |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5436 |
"suspend the current process, until the receiver |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5437 |
becomes ready for writing or reading. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5438 |
Return immediate if the receiver is already ready. |
5506 | 5439 |
The other threads are not affected by the wait." |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5440 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5441 |
self readWriteWaitWithTimeoutMs:nil |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5442 |
! |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5443 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5444 |
readWriteWaitWithTimeoutMs:timeout |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5445 |
"suspend the current process, until the receiver |
7678 | 5446 |
becomes ready for reading or writing or a timeout (in milliseconds) expired. |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5447 |
Return true if a timeout occured (i.e. false, if data is available). |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5448 |
Return immediate if the receiver is already ready. |
5506 | 5449 |
The other threads are not affected by the wait." |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5450 |
|
3672
49dff0652a2c
fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents:
3569
diff
changeset
|
5451 |
|fd sema canReadWrite wasBlocked| |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5452 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5453 |
filePointer isNil ifTrue:[ |
7832 | 5454 |
^ self errorNotOpen |
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5455 |
]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5456 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5457 |
fd := self fileDescriptor. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5458 |
(OperatingSystem readWriteCheck:fd) ifTrue:[^ false]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5459 |
|
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5460 |
wasBlocked := OperatingSystem blockInterrupts. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5461 |
canReadWrite := OperatingSystem readWriteCheck:fd. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5462 |
canReadWrite ifFalse:[ |
7832 | 5463 |
sema := Semaphore new name:'readWriteWait'. |
5464 |
[ |
|
5465 |
timeout notNil ifTrue:[ |
|
5466 |
Processor signal:sema afterMilliseconds:timeout |
|
5467 |
]. |
|
5468 |
Processor signal:sema onOutput:fd. |
|
5469 |
Processor signal:sema onInput:fd. |
|
5470 |
Processor activeProcess state:#ioWait. |
|
5471 |
sema wait. |
|
5472 |
Processor disableSemaphore:sema. |
|
5473 |
canReadWrite := OperatingSystem readWriteCheck:fd |
|
5474 |
] ifCurtailed:[ |
|
5475 |
Processor disableSemaphore:sema. |
|
5476 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
5477 |
] |
|
3490
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5478 |
]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5479 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5480 |
^ canReadWrite not |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5481 |
! |
6a87c2b37fd4
added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents:
3474
diff
changeset
|
5482 |
|
612 | 5483 |
writeWait |
5484 |
"suspend the current process, until the receiver |
|
5485 |
becomes ready for writing. |
|
5486 |
Return immediate if the receiver is already ready. |
|
5487 |
The other threads are not affected by the wait." |
|
5488 |
||
5489 |
self writeWaitWithTimeoutMs:nil |
|
5490 |
! |
|
5491 |
||
3016 | 5492 |
writeWaitTimeoutMs:timeout |
5493 |
"ST-80 compatibility" |
|
5494 |
^ self writeWaitWithTimeoutMs:timeout |
|
5495 |
! |
|
5496 |
||
612 | 5497 |
writeWaitWithTimeout:timeout |
5498 |
"suspend the current process, until the receiver |
|
5499 |
becomes ready for writing or a timeout (in seconds) expired. |
|
5500 |
Return true if a timeout occured (i.e. false, if data is available). |
|
5501 |
Return immediate if the receiver is already ready. |
|
5502 |
The other threads are not affected by the wait." |
|
5503 |
||
4640
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5504 |
|ms| |
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5505 |
|
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5506 |
timeout notNil ifTrue:[ |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5507 |
ms := timeout * 1000 |
4640
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5508 |
]. |
034c028a5463
care for nil arg in readWaitWithTimeout / writeWaitWithTimeout
Claus Gittinger <cg@exept.de>
parents:
4627
diff
changeset
|
5509 |
^ self writeWaitWithTimeoutMs:ms |
612 | 5510 |
! |
5511 |
||
5512 |
writeWaitWithTimeoutMs:timeout |
|
5513 |
"suspend the current process, until the receiver |
|
7678 | 5514 |
becomes ready for writing or a timeout (in milliseconds) expired. |
612 | 5515 |
Return true if a timeout occured (i.e. false, if data is available). |
5516 |
Return immediate if the receiver is already ready. |
|
5517 |
The other threads are not affected by the wait." |
|
5518 |
||
5519 |
|fd outputSema canWrite wasBlocked| |
|
5520 |
||
5521 |
filePointer isNil ifTrue:[ |
|
7832 | 5522 |
^ self errorNotOpen |
612 | 5523 |
]. |
5524 |
mode == #readonly ifTrue:[ |
|
7832 | 5525 |
^ self errorReadOnly |
612 | 5526 |
]. |
5527 |
||
5528 |
fd := self fileDescriptor. |
|
5529 |
(OperatingSystem writeCheck:fd) ifTrue:[^ false]. |
|
5530 |
||
5531 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5532 |
canWrite := OperatingSystem writeCheck:fd. |
|
5533 |
canWrite ifFalse:[ |
|
7832 | 5534 |
outputSema := Semaphore new name:'writeWait'. |
5535 |
[ |
|
5536 |
timeout notNil ifTrue:[ |
|
5537 |
Processor signal:outputSema afterMilliseconds:timeout |
|
5538 |
]. |
|
5539 |
Processor signal:outputSema onOutput:fd. |
|
5540 |
Processor activeProcess state:#ioWait. |
|
5541 |
outputSema wait. |
|
5542 |
Processor disableSemaphore:outputSema. |
|
5543 |
canWrite := OperatingSystem writeCheck:fd |
|
5544 |
] ifCurtailed:[ |
|
5545 |
Processor disableSemaphore:outputSema. |
|
5546 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
5547 |
] |
|
612 | 5548 |
]. |
5549 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
5550 |
^ canWrite not |
|
5551 |
! ! |
|
5552 |
||
5553 |
!ExternalStream methodsFor:'writing'! |
|
5554 |
||
5555 |
cr |
|
5556 |
"append an end-of-line character (or CRLF if in crlf mode). |
|
5557 |
reimplemented for speed" |
|
5558 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5559 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5560 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5561 |
int len, cnt, _buffered; |
612 | 5562 |
OBJ fp; |
5563 |
char *cp; |
|
5564 |
||
1133 | 5565 |
__INST(lastErrorNumber) = nil; |
5566 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 5567 |
&& (__INST(mode) != @symbol(readonly)) |
5568 |
&& (__INST(binary) != true) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5569 |
) { |
8070 | 5570 |
f = __FILEVal(fp); |
5571 |
||
5572 |
if (_buffered = (__INST(buffered) == true)) { |
|
5573 |
__WRITING__(f) |
|
5574 |
} |
|
5575 |
{ |
|
5576 |
OBJ mode = __INST(eolMode); |
|
5577 |
||
5578 |
if (mode == @symbol(cr)) { |
|
5579 |
cp = "\r"; len = 1; |
|
5580 |
} else if (mode == @symbol(crlf)) { |
|
5581 |
cp = "\r\n"; len = 2; |
|
5582 |
} else { |
|
5583 |
cp = "\n"; len = 1; |
|
5584 |
} |
|
5585 |
} |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5586 |
#ifdef WIN32 |
8070 | 5587 |
if ((f == stdout) || (f == stderr)) { |
5588 |
cnt = fwrite(cp, 1, len, f); |
|
5589 |
} else |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5590 |
#endif |
8070 | 5591 |
{ |
5592 |
__WRITEBYTES__(cnt, f, cp, len, _buffered); |
|
5593 |
} |
|
5594 |
if (cnt == len) { |
|
5595 |
if (__isSmallInteger(__INST(position))) { |
|
5596 |
INT np = __intVal(__INST(position)) + len; |
|
5597 |
OBJ t; |
|
5598 |
||
5599 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
5600 |
} else { |
|
5601 |
__INST(position) = nil; /* i.e: dont know */ |
|
5602 |
} |
|
5603 |
RETURN ( self ); |
|
5604 |
} |
|
5605 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
612 | 5606 |
} |
5607 |
%}. |
|
2326 | 5608 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
5609 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
5610 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
5414 | 5611 |
(binary==true) ifTrue:[self errorBinary. ^ self]. |
5612 |
||
5613 |
(eolMode == #cr) ifTrue:[self nextPut:(Character return). ^ self]. |
|
5614 |
(eolMode ~~ #crlf) ifTrue:[self nextPut:(Character nl). ^ self]. |
|
5615 |
self nextPut:(Character return). |
|
5616 |
self nextPut:(Character nl). |
|
5617 |
^ self |
|
612 | 5618 |
! |
5619 |
||
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5620 |
flush |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5621 |
"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
|
5622 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5623 |
%{ |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5624 |
OBJ fp; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5625 |
|
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5626 |
__INST(lastErrorNumber) = nil; |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5627 |
if ((fp = __INST(filePointer)) != nil) { |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5628 |
if (__INST(mode) != @symbol(readonly)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5629 |
if (__INST(buffered) == true) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5630 |
FILEPOINTER f = __FILEVal(fp); |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5631 |
#ifdef WIN32 |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5632 |
if ((f == stdout) || (f == stderr)) { |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5633 |
fflush(f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5634 |
} else |
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5635 |
#endif |
7051
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5636 |
{ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5637 |
__BEGIN_INTERRUPTABLE__ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5638 |
FFLUSH(f); |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5639 |
__END_INTERRUPTABLE__ |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5640 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5641 |
} |
984d8271d06b
preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents:
7017
diff
changeset
|
5642 |
} |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5643 |
} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5644 |
%} |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5645 |
! |
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5646 |
|
612 | 5647 |
nextPut:aCharacter |
5648 |
"write the argument, aCharacter - return nil if failed, self if ok. |
|
5649 |
Only single-byte characters are currently supported" |
|
5650 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5651 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5652 |
FILEPOINTER f; |
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5653 |
unsigned codePoint; |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5654 |
unsigned char c; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5655 |
int cnt, _buffered; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5656 |
OBJ fp; |
612 | 5657 |
|
1133 | 5658 |
__INST(lastErrorNumber) = nil; |
5659 |
if (((fp = __INST(filePointer)) != nil) |
|
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5660 |
&& (__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
|
5661 |
) { |
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5662 |
if (__INST(binary) != true) { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5663 |
if (__isCharacter(aCharacter)) { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5664 |
codePoint = __intVal(__characterVal(aCharacter)); |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5665 |
if (codePoint <= 0xFF) { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5666 |
c = codePoint; |
612 | 5667 |
doWrite: |
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5668 |
f = __FILEVal(fp); |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5669 |
if (! f) { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5670 |
fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n"); |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5671 |
__INST(filePointer) = nil; |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5672 |
goto out; |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5673 |
} |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5674 |
|
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5675 |
if (_buffered = (__INST(buffered) == true)) { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5676 |
__WRITING__(f) |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5677 |
} |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5678 |
__WRITEBYTE__(cnt, f, &c, _buffered); |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5679 |
if (cnt == 1) { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5680 |
if (__isSmallInteger(__INST(position))) { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5681 |
INT np = __intVal(__INST(position)) + 1; |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5682 |
OBJ t; |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5683 |
|
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5684 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5685 |
} else { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5686 |
__INST(position) = nil; /* i.e. do not know */ |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5687 |
} |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5688 |
RETURN ( self ); |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5689 |
} |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5690 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5691 |
} |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5692 |
} |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5693 |
} else { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5694 |
if (__isSmallInteger(aCharacter)) { |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5695 |
c = __intVal(aCharacter); |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5696 |
goto doWrite; |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5697 |
} |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5698 |
} |
612 | 5699 |
} |
7737 | 5700 |
out: ; |
612 | 5701 |
%}. |
2331 | 5702 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
5703 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
5704 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
5417 | 5705 |
binary == true ifFalse:[ |
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5706 |
(aCharacter isCharacter not |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5707 |
or:[aCharacter codePoint > 16rFF]) ifTrue:[ |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5708 |
self argumentMustBeCharacter. |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5709 |
^ self. |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5710 |
]. |
5417 | 5711 |
] ifTrue:[ |
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5712 |
aCharacter isInteger ifFalse:[ |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5713 |
self argumentMustBeInteger. |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5714 |
^ self. |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5715 |
]. |
5417 | 5716 |
]. |
5717 |
"/ migration support |
|
5718 |
self |
|
8209
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5719 |
nextPutByte:aCharacter asInteger |
908ba4b9543e
check for written characters to be in 00..FF
Claus Gittinger <cg@exept.de>
parents:
8074
diff
changeset
|
5720 |
toFile:filePointer |
612 | 5721 |
! |
5722 |
||
5723 |
nextPutAll:aCollection |
|
5724 |
"write all elements of the argument, aCollection. |
|
5725 |
Reimplemented for speed when writing strings or byteArrays. |
|
5726 |
For others, falls back to general method in superclass." |
|
5727 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5728 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5729 |
FILEPOINTER f; |
612 | 5730 |
int len, cnt; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5731 |
OBJ fp; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5732 |
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
|
5733 |
int o_offs; |
612 | 5734 |
|
1133 | 5735 |
__INST(lastErrorNumber) = nil; |
5736 |
||
5737 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 5738 |
&& (__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
|
5739 |
) { |
8070 | 5740 |
f = __FILEVal(fp); |
5741 |
if (! f) { |
|
5742 |
fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n"); |
|
5743 |
__INST(filePointer) = nil; |
|
5744 |
goto out; |
|
5745 |
} |
|
5746 |
if (_buffered = (__INST(buffered) == true)) { |
|
5747 |
__WRITING__(f) |
|
5748 |
} |
|
5749 |
||
5750 |
if (__isString(aCollection) || __isSymbol(aCollection)) { |
|
5751 |
len = __stringSize(aCollection); |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5752 |
#ifdef WIN32 |
8070 | 5753 |
if ((f == stdout) || (f == stderr)) { |
5754 |
cnt = fwrite(__stringVal(aCollection), 1, len, f); |
|
5755 |
} else |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
5756 |
#endif |
8070 | 5757 |
{ |
5758 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
|
5759 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered); |
|
5760 |
} |
|
5761 |
} else { |
|
5762 |
if (__INST(binary) == true) { |
|
5763 |
int offs; |
|
5764 |
||
5765 |
if (__isByteArray(aCollection)) { |
|
5766 |
offs = 0; |
|
5767 |
len = __byteArraySize(aCollection); |
|
5768 |
} else if (__isBytes(aCollection)) { |
|
5769 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
5770 |
len = __byteArraySize(aCollection) - offs; |
|
5771 |
} else |
|
5772 |
goto out; |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5773 |
#ifdef WIN32 |
8070 | 5774 |
if ((f == stdout) || (f == stderr)) { |
5775 |
cnt = fwrite(__stringVal(aCollection), 1, len, f); |
|
5776 |
} else |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
5777 |
#endif |
8070 | 5778 |
{ |
5779 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection); |
|
5780 |
o_offs += offs; |
|
5781 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered); |
|
5782 |
} |
|
5783 |
} else |
|
5784 |
goto out; |
|
5785 |
} |
|
5786 |
||
5787 |
if (cnt == len) { |
|
5788 |
if (__isSmallInteger(__INST(position))) { |
|
5789 |
INT np = __intVal(__INST(position)) + len; |
|
5790 |
OBJ t; |
|
5791 |
||
5792 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
5793 |
} else { |
|
5794 |
__INST(position) = nil; /* i.e. do not know */ |
|
5795 |
} |
|
5796 |
RETURN (self); |
|
5797 |
} |
|
5798 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
612 | 5799 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
5800 |
out: ; |
612 | 5801 |
%}. |
2331 | 5802 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
5803 |
filePointer isNil ifTrue:[self errorNotOpen. ^ self]. |
|
5804 |
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self]. |
|
612 | 5805 |
|
5806 |
^ super nextPutAll:aCollection |
|
5807 |
! |
|
5808 |
||
5809 |
nextPutAll:aCollection startingAt:start to:stop |
|
5810 |
"write a range of elements of the argument, aCollection. |
|
5811 |
Reimplemented for speed when writing strings or byteArrays. |
|
5812 |
For others, falls back to general method in superclass." |
|
5813 |
||
1067
1e7959af0821
removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents:
1066
diff
changeset
|
5814 |
%{ |
2593
d678527ef34e
changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents:
2591
diff
changeset
|
5815 |
FILEPOINTER f; |
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5816 |
int offs, len, cnt, iStart, iStop, _buffered; |
7875
eb7d48b0425d
made all position-handling code 32bit save
Claus Gittinger <cg@exept.de>
parents:
7832
diff
changeset
|
5817 |
OBJ fp; |
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
5818 |
int o_offs; |
612 | 5819 |
|
1133 | 5820 |
__INST(lastErrorNumber) = nil; |
5821 |
if (((fp = __INST(filePointer)) != nil) |
|
8070 | 5822 |
&& (__INST(mode) != @symbol(readonly)) |
5823 |
&& __bothSmallInteger(start, stop) |
|
1463
ace6b72b6f4a
Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
5824 |
) { |
8070 | 5825 |
f = __FILEVal(fp); |
5826 |
if (_buffered = (__INST(buffered) == true)) { |
|
5827 |
__WRITING__(f) |
|
5828 |
} |
|
5829 |
iStart = __intVal(start); |
|
5830 |
iStop = __intVal(stop); |
|
5831 |
if ((iStart < 1) || (iStop < iStart)) { |
|
5832 |
RETURN(self); |
|
5833 |
} |
|
5834 |
if (__isString(aCollection) || __isSymbol(aCollection)) { |
|
5835 |
len = __stringSize(aCollection); |
|
5836 |
if (iStop > len) { |
|
5837 |
RETURN(self); |
|
5838 |
} |
|
5839 |
if (iStop > len) |
|
5840 |
iStop = len; |
|
5841 |
len = iStop - iStart + 1; |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5842 |
#ifdef WIN32 |
8070 | 5843 |
if ((f == stdout) || (f == stderr)) { |
5844 |
cnt = fwrite(__stringVal(aCollection)+iStart-1, 1, len, f); |
|
5845 |
} else |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
5846 |
#endif |
8070 | 5847 |
{ |
5848 |
o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection); |
|
5849 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered); |
|
5850 |
} |
|
5851 |
} else { |
|
5852 |
if (__INST(binary) == true) { |
|
5853 |
int offs; |
|
5854 |
||
5855 |
if (__isByteArray(aCollection)) { |
|
5856 |
offs = 0; |
|
5857 |
len = __byteArraySize(aCollection); |
|
5858 |
} else if (__isBytes(aCollection)) { |
|
5859 |
offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars)); |
|
5860 |
len = __byteArraySize(aCollection) - offs; |
|
5861 |
} else |
|
5862 |
goto out; |
|
5863 |
||
5864 |
if (iStop > len) { |
|
5865 |
RETURN(self); |
|
5866 |
} |
|
5867 |
if (iStop > len) |
|
5868 |
iStop = len; |
|
5869 |
len = iStop - iStart + 1; |
|
5870 |
offs += iStart - 1; |
|
4913
4964b2c71d31
remerged ExtSTream_win32 into ExtStream.
Claus Gittinger <cg@exept.de>
parents:
4640
diff
changeset
|
5871 |
#ifdef WIN32 |
8070 | 5872 |
if ((f == stdout) || (f == stderr)) { |
5873 |
cnt = fwrite(__stringVal(aCollection)+iStart-1, 1, len, f); |
|
5874 |
} else |
|
2513
a589586a3828
big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
5875 |
#endif |
8070 | 5876 |
{ |
5877 |
o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection); |
|
5878 |
__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+offs, len, _buffered); |
|
5879 |
} |
|
5880 |
} else |
|
5881 |
goto out; |
|
5882 |
} |
|
5883 |
if (cnt == len) { |
|
5884 |
if (__isSmallInteger(__INST(position))) { |
|
5885 |
INT np = __intVal(__INST(position)) + len; |
|
5886 |
OBJ t; |
|
5887 |
||
5888 |
__INST(position) = t = __MKINT(np); __STORE(self, t); |
|
5889 |
} else { |
|
5890 |
__INST(position) = nil; /* i.e. do not know */ |
|
5891 |
} |
|
5892 |
RETURN (self); |
|
5893 |
} |
|
5894 |
__INST(lastErrorNumber) = __MKSMALLINT(__threadErrno); |
|
612 | 5895 |
} |
1478
aae07192b7d1
labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
5896 |
out: ; |
612 | 5897 |
%}. |
7801
d930c353588d
writeError: care for EWOULDBLOCK in nonBlocking case.
penk
parents:
7737
diff
changeset
|
5898 |
lastErrorNumber notNil ifTrue:[self writeError. ^ self]. |
612 | 5899 |
^ super nextPutAll:aCollection startingAt:start to:stop |
5900 |
! ! |
|
5901 |
||
2045
1ad17ca6520f
fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents:
2044
diff
changeset
|
5902 |
!ExternalStream class methodsFor:'documentation'! |
730 | 5903 |
|
5904 |
version |
|
8339 | 5905 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.280 2004-05-09 20:51:37 stefan Exp $' |
730 | 5906 |
! ! |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6758
diff
changeset
|
5907 |
|
612 | 5908 |
ExternalStream initialize! |