author | Claus Gittinger <cg@exept.de> |
Mon, 22 Sep 1997 21:04:17 +0200 | |
changeset 2965 | c5d6d02b0e8c |
parent 2896 | be30640b9012 |
child 3173 | 664f2ffa7493 |
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 |
1 | 142 |
! ! |
143 |
||
177 | 144 |
!NonPositionableExternalStream methodsFor:'printing & storing'! |
145 |
||
146 |
printOn:aStream |
|
2965 | 147 |
"{ Pragma: +optSpace }" |
148 |
||
213 | 149 |
"append a printed representation of the receiver on aStream" |
177 | 150 |
|
2965 | 151 |
|myName| |
152 |
||
177 | 153 |
self == Stdin ifTrue:[ |
2965 | 154 |
myName := 'Stdin'. |
155 |
] ifFalse:[ |
|
156 |
self == Stdout ifTrue:[ |
|
157 |
myName := 'Stdout'. |
|
158 |
] ifFalse:[ |
|
159 |
self == Stderr ifTrue:[ |
|
160 |
myName := 'Stderr'. |
|
161 |
] |
|
162 |
] |
|
177 | 163 |
]. |
2965 | 164 |
|
165 |
myName notNil ifTrue:[ |
|
166 |
aStream nextPutAll:myName. |
|
177 | 167 |
^ self |
168 |
]. |
|
169 |
super printOn:aStream |
|
170 |
! |
|
171 |
||
172 |
storeOn:aStream |
|
2965 | 173 |
"{ Pragma: +optSpace }" |
174 |
||
213 | 175 |
"append a printed representation of the receiver on aStream, from |
176 |
which the receiver can be reconstructed." |
|
177 | 177 |
|
178 |
((self == Stdin) |
|
179 |
or:[self == Stdout |
|
180 |
or:[self == Stderr]]) ifTrue:[ |
|
181 |
^ self printOn:aStream |
|
182 |
]. |
|
183 |
super storeOn:aStream |
|
184 |
! ! |
|
185 |
||
613 | 186 |
!NonPositionableExternalStream methodsFor:'private'! |
360 | 187 |
|
613 | 188 |
initializeForStderr |
2965 | 189 |
"{ Pragma: +optSpace }" |
190 |
||
613 | 191 |
"setup for writing to stderr" |
269 | 192 |
|
613 | 193 |
mode := #readwrite. |
194 |
buffered := false. |
|
195 |
%{ |
|
196 |
OBJ fp; |
|
269 | 197 |
|
1133 | 198 |
__INST(filePointer) = fp = __MKOBJ(stderr); __STORE(self, fp); |
613 | 199 |
%} |
200 |
! |
|
1 | 201 |
|
202 |
initializeForStdin |
|
2965 | 203 |
"{ Pragma: +optSpace }" |
204 |
||
44 | 205 |
"setup for reading stdin" |
206 |
||
1 | 207 |
mode := #readonly. |
10 | 208 |
buffered := true. |
1 | 209 |
%{ |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
210 |
OBJ fp; |
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
211 |
|
1133 | 212 |
__INST(filePointer) = fp = __MKOBJ(stdin); __STORE(self, fp); |
1 | 213 |
%} |
214 |
! |
|
215 |
||
216 |
initializeForStdout |
|
2965 | 217 |
"{ Pragma: +optSpace }" |
218 |
||
44 | 219 |
"setup for writing to stdout" |
220 |
||
1 | 221 |
mode := #readwrite. |
10 | 222 |
buffered := false. |
1 | 223 |
%{ |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
224 |
OBJ fp; |
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
225 |
|
1133 | 226 |
__INST(filePointer) = fp = __MKOBJ(stdout); __STORE(self, fp); |
1 | 227 |
%} |
228 |
! |
|
229 |
||
230 |
reOpen |
|
2965 | 231 |
"{ Pragma: +optSpace }" |
232 |
||
44 | 233 |
"reopen the stream after an image restart. |
234 |
If I am one of the standard streams, reopen is easy" |
|
1 | 235 |
|
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
236 |
(self == StdInStream) ifTrue:[ |
177 | 237 |
^ self initializeForStdin |
1 | 238 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
239 |
(self == StdOutStream) ifTrue:[ |
177 | 240 |
^ self initializeForStdout |
1 | 241 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
242 |
(self == StdErrorStream) ifTrue:[ |
177 | 243 |
^ self initializeForStderr |
1 | 244 |
]. |
245 |
^ super reOpen |
|
246 |
! ! |
|
613 | 247 |
|
248 |
!NonPositionableExternalStream methodsFor:'queries'! |
|
249 |
||
250 |
isPositionable |
|
251 |
"return true, if the stream supports positioning (this one is not)" |
|
252 |
||
253 |
^ false |
|
254 |
! ! |
|
255 |
||
1295 | 256 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
257 |
||
258 |
version |
|
2965 | 259 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/NPExtStr.st,v 1.30 1997-09-22 19:04:17 cg Exp $' |
1295 | 260 |
! ! |