author | Claus Gittinger <cg@exept.de> |
Thu, 07 May 1998 20:02:53 +0200 | |
changeset 3422 | 09c13ab58bb2 |
parent 3173 | 664f2ffa7493 |
child 3808 | 5a7866138026 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
177 | 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 |
||
1344
32a51164b237
No longer a subclass of UnboundedExternalStream, now subclass of ExternalStream.
Stefan Vogel <sv@exept.de>
parents:
1295
diff
changeset
|
13 |
ExternalStream subclass:#NonPositionableExternalStream |
1295 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'StdInStream StdOutStream StdErrorStream' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Streams-External' |
|
1 | 18 |
! |
19 |
||
613 | 20 |
!NonPositionableExternalStream primitiveDefinitions! |
21 |
%{ |
|
2896 | 22 |
#ifdef __openVMS__ |
23 |
# undef __new |
|
24 |
#endif |
|
25 |
||
613 | 26 |
#include <stdio.h> |
27 |
#define _STDIO_H_INCLUDED_ |
|
28 |
%} |
|
29 |
||
30 |
! ! |
|
31 |
||
88 | 32 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
33 |
||
34 |
copyright |
|
35 |
" |
|
36 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
177 | 37 |
All Rights Reserved |
88 | 38 |
|
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
documentation |
|
49 |
" |
|
50 |
This class provides common protocol for all non-positionable, |
|
51 |
external streams. Concrete subclasses are terminal streams, pipe streams, |
|
52 |
PrinterStreams, Sockets etc. |
|
53 |
||
54 |
There are three special instances of this class, representing stdin, |
|
55 |
stdout and stderr of the smalltalk/X process (see Unix manuals, if you |
|
177 | 56 |
dont know what those are used for). These special streams are bound to |
57 |
to globals Stdin, Stdout and Stderr at early initialization time |
|
58 |
(see Smalltalk>>initializeStandardStreams). |
|
159 | 59 |
|
60 |
The name of this class is a historical leftover - it should be called |
|
61 |
'TTYStream' or similar. |
|
1295 | 62 |
|
63 |
[author:] |
|
64 |
Claus Gittinger |
|
88 | 65 |
" |
216 | 66 |
! ! |
67 |
||
1 | 68 |
!NonPositionableExternalStream class methodsFor:'instance creation'! |
69 |
||
613 | 70 |
forStderr |
2965 | 71 |
"{ Pragma: +optSpace }" |
72 |
||
613 | 73 |
"return a NonPositionableExternalStream object for writing to |
74 |
Unixes standard error output file descriptor" |
|
75 |
||
76 |
StdErrorStream isNil ifTrue:[ |
|
77 |
StdErrorStream := self basicNew initializeForStderr |
|
78 |
]. |
|
79 |
^ StdErrorStream |
|
80 |
! |
|
81 |
||
1 | 82 |
forStdin |
2965 | 83 |
"{ Pragma: +optSpace }" |
84 |
||
44 | 85 |
"return a NonPositionableExternalStream object for reading from |
86 |
Unixes standard input file descriptor" |
|
87 |
||
88 | 88 |
StdInStream isNil ifTrue:[ |
177 | 89 |
StdInStream := self basicNew initializeForStdin |
88 | 90 |
]. |
91 |
^ StdInStream |
|
1 | 92 |
! |
93 |
||
94 |
forStdout |
|
2965 | 95 |
"{ Pragma: +optSpace }" |
96 |
||
44 | 97 |
"return a NonPositionableExternalStream object for writing to |
98 |
Unixes standard output file descriptor" |
|
99 |
||
88 | 100 |
StdOutStream isNil ifTrue:[ |
177 | 101 |
StdOutStream := self basicNew initializeForStdout |
88 | 102 |
]. |
103 |
^ StdOutStream |
|
613 | 104 |
! ! |
105 |
||
106 |
!NonPositionableExternalStream methodsFor:'error handling'! |
|
107 |
||
108 |
positionError |
|
2965 | 109 |
"{ Pragma: +optSpace }" |
110 |
||
613 | 111 |
"notify that this stream has no concept of a position" |
112 |
||
113 |
^ PositionErrorSignal raiseRequestWith:self in:thisContext sender |
|
114 |
! ! |
|
115 |
||
116 |
!NonPositionableExternalStream methodsFor:'positioning'! |
|
117 |
||
118 |
position |
|
2965 | 119 |
"{ Pragma: +optSpace }" |
120 |
||
613 | 121 |
"catch position - there is none here" |
122 |
||
123 |
^ self positionError |
|
1 | 124 |
! |
125 |
||
613 | 126 |
position:aPosition |
2965 | 127 |
"{ Pragma: +optSpace }" |
128 |
||
613 | 129 |
"catch position - there is none here" |
130 |
||
131 |
^ self positionError |
|
132 |
! |
|
44 | 133 |
|
613 | 134 |
skip:numberToSkip |
135 |
"skip count objects, return the receiver" |
|
136 |
||
137 |
"dont know how to unread ..." |
|
138 |
numberToSkip < 0 ifTrue:[ |
|
139 |
^ self error:'stream is not positionable' |
|
88 | 140 |
]. |
613 | 141 |
numberToSkip timesRepeat:self next |
3173
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
142 |
! |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
143 |
|
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
144 |
skipThroughAll:aCollection |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
145 |
"skip for and through the sequence given by the argument, aCollection; |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
146 |
return nil if not found, the receiver otherwise. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
147 |
On a successful match, the next read will return elements after aCollection; |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
148 |
if no match was found, the receiver will be positioned at the end. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
149 |
Redefined to be the same as Stream>>#skipThroughAll, to undo |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
150 |
the redefinition from PositionableStream" |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
151 |
|
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
152 |
|buffer l first idx| |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
153 |
|
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
154 |
l := aCollection size. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
155 |
first := aCollection at:1. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
156 |
[self atEnd] whileFalse:[ |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
157 |
buffer isNil ifTrue:[ |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
158 |
buffer := self nextAvailable:l. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
159 |
]. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
160 |
buffer = aCollection ifTrue:[ |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
161 |
^ self |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
162 |
]. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
163 |
idx := buffer indexOf:first startingAt:2. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
164 |
idx == 0 ifTrue:[ |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
165 |
buffer := nil |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
166 |
] ifFalse:[ |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
167 |
buffer := (buffer copyFrom:idx) , (self nextAvailable:(idx - 1)) |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
168 |
] |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
169 |
]. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
170 |
^ nil |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
171 |
|
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
172 |
" |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
173 |
|s| |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
174 |
s := ReadStream on:'12345678901234567890'. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
175 |
s skipThroughAll:'901'. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
176 |
s upToEnd |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
177 |
" |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
178 |
" |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
179 |
|s| |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
180 |
s := ReadStream on:'12345678901234567890'. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
181 |
s skipThroughAll:'1234'. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
182 |
s upToEnd |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
183 |
" |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
184 |
" |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
185 |
|s| |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
186 |
s := ReadStream on:'12345678901234567890'. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
187 |
s skipThroughAll:'999'. |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
188 |
s atEnd |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
189 |
" |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
190 |
|
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
191 |
"Modified: / 11.1.1997 / 19:09:06 / cg" |
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
192 |
"Created: / 15.1.1998 / 23:33:37 / stefan" |
1 | 193 |
! ! |
194 |
||
177 | 195 |
!NonPositionableExternalStream methodsFor:'printing & storing'! |
196 |
||
197 |
printOn:aStream |
|
2965 | 198 |
"{ Pragma: +optSpace }" |
199 |
||
213 | 200 |
"append a printed representation of the receiver on aStream" |
177 | 201 |
|
2965 | 202 |
|myName| |
203 |
||
177 | 204 |
self == Stdin ifTrue:[ |
2965 | 205 |
myName := 'Stdin'. |
206 |
] ifFalse:[ |
|
207 |
self == Stdout ifTrue:[ |
|
208 |
myName := 'Stdout'. |
|
209 |
] ifFalse:[ |
|
210 |
self == Stderr ifTrue:[ |
|
211 |
myName := 'Stderr'. |
|
212 |
] |
|
213 |
] |
|
177 | 214 |
]. |
2965 | 215 |
|
216 |
myName notNil ifTrue:[ |
|
217 |
aStream nextPutAll:myName. |
|
177 | 218 |
^ self |
219 |
]. |
|
220 |
super printOn:aStream |
|
221 |
! |
|
222 |
||
223 |
storeOn:aStream |
|
2965 | 224 |
"{ Pragma: +optSpace }" |
225 |
||
213 | 226 |
"append a printed representation of the receiver on aStream, from |
227 |
which the receiver can be reconstructed." |
|
177 | 228 |
|
229 |
((self == Stdin) |
|
230 |
or:[self == Stdout |
|
231 |
or:[self == Stderr]]) ifTrue:[ |
|
232 |
^ self printOn:aStream |
|
233 |
]. |
|
234 |
super storeOn:aStream |
|
235 |
! ! |
|
236 |
||
613 | 237 |
!NonPositionableExternalStream methodsFor:'private'! |
360 | 238 |
|
613 | 239 |
initializeForStderr |
2965 | 240 |
"{ Pragma: +optSpace }" |
241 |
||
613 | 242 |
"setup for writing to stderr" |
269 | 243 |
|
613 | 244 |
mode := #readwrite. |
245 |
buffered := false. |
|
246 |
%{ |
|
247 |
OBJ fp; |
|
269 | 248 |
|
1133 | 249 |
__INST(filePointer) = fp = __MKOBJ(stderr); __STORE(self, fp); |
613 | 250 |
%} |
251 |
! |
|
1 | 252 |
|
253 |
initializeForStdin |
|
2965 | 254 |
"{ Pragma: +optSpace }" |
255 |
||
44 | 256 |
"setup for reading stdin" |
257 |
||
1 | 258 |
mode := #readonly. |
10 | 259 |
buffered := true. |
1 | 260 |
%{ |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
261 |
OBJ fp; |
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
262 |
|
1133 | 263 |
__INST(filePointer) = fp = __MKOBJ(stdin); __STORE(self, fp); |
1 | 264 |
%} |
265 |
! |
|
266 |
||
267 |
initializeForStdout |
|
2965 | 268 |
"{ Pragma: +optSpace }" |
269 |
||
44 | 270 |
"setup for writing to stdout" |
271 |
||
1 | 272 |
mode := #readwrite. |
10 | 273 |
buffered := false. |
1 | 274 |
%{ |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
275 |
OBJ fp; |
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
276 |
|
1133 | 277 |
__INST(filePointer) = fp = __MKOBJ(stdout); __STORE(self, fp); |
1 | 278 |
%} |
279 |
! |
|
280 |
||
281 |
reOpen |
|
2965 | 282 |
"{ Pragma: +optSpace }" |
283 |
||
44 | 284 |
"reopen the stream after an image restart. |
285 |
If I am one of the standard streams, reopen is easy" |
|
1 | 286 |
|
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
287 |
(self == StdInStream) ifTrue:[ |
177 | 288 |
^ self initializeForStdin |
1 | 289 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
290 |
(self == StdOutStream) ifTrue:[ |
177 | 291 |
^ self initializeForStdout |
1 | 292 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
293 |
(self == StdErrorStream) ifTrue:[ |
177 | 294 |
^ self initializeForStderr |
1 | 295 |
]. |
296 |
^ super reOpen |
|
297 |
! ! |
|
613 | 298 |
|
299 |
!NonPositionableExternalStream methodsFor:'queries'! |
|
300 |
||
301 |
isPositionable |
|
302 |
"return true, if the stream supports positioning (this one is not)" |
|
303 |
||
304 |
^ false |
|
305 |
! ! |
|
306 |
||
1295 | 307 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
308 |
||
309 |
version |
|
3173
664f2ffa7493
Redefine #skipThroughAll: to not use #position.
Stefan Vogel <sv@exept.de>
parents:
2965
diff
changeset
|
310 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/NPExtStr.st,v 1.31 1998-01-15 23:30:40 stefan Exp $' |
1295 | 311 |
! ! |