author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 18:20:46 +0200 | |
changeset 1290 | 15ba3221b89b |
parent 1133 | 961f2b095c22 |
child 1295 | 83f594f05c52 |
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 |
||
159 | 13 |
UnboundedExternalStream subclass:#NonPositionableExternalStream |
613 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'StdInStream StdOutStream StdErrorStream' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Streams-External' |
|
1 | 18 |
! |
19 |
||
613 | 20 |
!NonPositionableExternalStream primitiveDefinitions! |
21 |
%{ |
|
22 |
#include <stdio.h> |
|
23 |
#define _STDIO_H_INCLUDED_ |
|
24 |
%} |
|
25 |
||
26 |
! ! |
|
27 |
||
88 | 28 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
29 |
||
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
177 | 33 |
All Rights Reserved |
88 | 34 |
|
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
This class provides common protocol for all non-positionable, |
|
47 |
external streams. Concrete subclasses are terminal streams, pipe streams, |
|
48 |
PrinterStreams, Sockets etc. |
|
49 |
||
50 |
There are three special instances of this class, representing stdin, |
|
51 |
stdout and stderr of the smalltalk/X process (see Unix manuals, if you |
|
177 | 52 |
dont know what those are used for). These special streams are bound to |
53 |
to globals Stdin, Stdout and Stderr at early initialization time |
|
54 |
(see Smalltalk>>initializeStandardStreams). |
|
159 | 55 |
|
56 |
The name of this class is a historical leftover - it should be called |
|
57 |
'TTYStream' or similar. |
|
88 | 58 |
" |
613 | 59 |
! |
216 | 60 |
|
613 | 61 |
version |
1133 | 62 |
^ '$Header: /cvs/stx/stx/libbasic/NonPositionableExternalStream.st,v 1.26 1996-04-02 22:02:45 cg Exp $' |
216 | 63 |
! ! |
64 |
||
1 | 65 |
!NonPositionableExternalStream class methodsFor:'instance creation'! |
66 |
||
613 | 67 |
forStderr |
68 |
"return a NonPositionableExternalStream object for writing to |
|
69 |
Unixes standard error output file descriptor" |
|
70 |
||
71 |
StdErrorStream isNil ifTrue:[ |
|
72 |
StdErrorStream := self basicNew initializeForStderr |
|
73 |
]. |
|
74 |
^ StdErrorStream |
|
75 |
! |
|
76 |
||
1 | 77 |
forStdin |
44 | 78 |
"return a NonPositionableExternalStream object for reading from |
79 |
Unixes standard input file descriptor" |
|
80 |
||
88 | 81 |
StdInStream isNil ifTrue:[ |
177 | 82 |
StdInStream := self basicNew initializeForStdin |
88 | 83 |
]. |
84 |
^ StdInStream |
|
1 | 85 |
! |
86 |
||
87 |
forStdout |
|
44 | 88 |
"return a NonPositionableExternalStream object for writing to |
89 |
Unixes standard output file descriptor" |
|
90 |
||
88 | 91 |
StdOutStream isNil ifTrue:[ |
177 | 92 |
StdOutStream := self basicNew initializeForStdout |
88 | 93 |
]. |
94 |
^ StdOutStream |
|
613 | 95 |
! ! |
96 |
||
97 |
!NonPositionableExternalStream methodsFor:'error handling'! |
|
98 |
||
99 |
positionError |
|
100 |
"notify that this stream has no concept of a position" |
|
101 |
||
102 |
^ PositionErrorSignal raiseRequestWith:self in:thisContext sender |
|
103 |
! ! |
|
104 |
||
105 |
!NonPositionableExternalStream methodsFor:'positioning'! |
|
106 |
||
107 |
position |
|
108 |
"catch position - there is none here" |
|
109 |
||
110 |
^ self positionError |
|
1 | 111 |
! |
112 |
||
613 | 113 |
position:aPosition |
114 |
"catch position - there is none here" |
|
115 |
||
116 |
^ self positionError |
|
117 |
! |
|
44 | 118 |
|
613 | 119 |
skip:numberToSkip |
120 |
"skip count objects, return the receiver" |
|
121 |
||
122 |
"dont know how to unread ..." |
|
123 |
numberToSkip < 0 ifTrue:[ |
|
124 |
^ self error:'stream is not positionable' |
|
88 | 125 |
]. |
613 | 126 |
numberToSkip timesRepeat:self next |
1 | 127 |
! ! |
128 |
||
177 | 129 |
!NonPositionableExternalStream methodsFor:'printing & storing'! |
130 |
||
131 |
printOn:aStream |
|
213 | 132 |
"append a printed representation of the receiver on aStream" |
177 | 133 |
|
134 |
self == Stdin ifTrue:[ |
|
135 |
aStream nextPutAll:'Stdin'. |
|
136 |
^ self |
|
137 |
]. |
|
138 |
self == Stdout ifTrue:[ |
|
139 |
aStream nextPutAll:'Stdout'. |
|
140 |
^ self |
|
141 |
]. |
|
142 |
self == Stderr ifTrue:[ |
|
143 |
aStream nextPutAll:'Stderr'. |
|
144 |
^ self |
|
145 |
]. |
|
146 |
super printOn:aStream |
|
147 |
! |
|
148 |
||
149 |
storeOn:aStream |
|
213 | 150 |
"append a printed representation of the receiver on aStream, from |
151 |
which the receiver can be reconstructed." |
|
177 | 152 |
|
153 |
((self == Stdin) |
|
154 |
or:[self == Stdout |
|
155 |
or:[self == Stderr]]) ifTrue:[ |
|
156 |
^ self printOn:aStream |
|
157 |
]. |
|
158 |
super storeOn:aStream |
|
159 |
! ! |
|
160 |
||
613 | 161 |
!NonPositionableExternalStream methodsFor:'private'! |
360 | 162 |
|
613 | 163 |
initializeForStderr |
164 |
"setup for writing to stderr" |
|
269 | 165 |
|
613 | 166 |
mode := #readwrite. |
167 |
buffered := false. |
|
168 |
%{ |
|
169 |
OBJ fp; |
|
269 | 170 |
|
1133 | 171 |
__INST(filePointer) = fp = __MKOBJ(stderr); __STORE(self, fp); |
613 | 172 |
%} |
173 |
! |
|
1 | 174 |
|
175 |
initializeForStdin |
|
44 | 176 |
"setup for reading stdin" |
177 |
||
1 | 178 |
mode := #readonly. |
10 | 179 |
buffered := true. |
1 | 180 |
%{ |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
181 |
OBJ fp; |
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
182 |
|
1133 | 183 |
__INST(filePointer) = fp = __MKOBJ(stdin); __STORE(self, fp); |
1 | 184 |
%} |
185 |
! |
|
186 |
||
187 |
initializeForStdout |
|
44 | 188 |
"setup for writing to stdout" |
189 |
||
1 | 190 |
mode := #readwrite. |
10 | 191 |
buffered := false. |
1 | 192 |
%{ |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
193 |
OBJ fp; |
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
194 |
|
1133 | 195 |
__INST(filePointer) = fp = __MKOBJ(stdout); __STORE(self, fp); |
1 | 196 |
%} |
197 |
! |
|
198 |
||
199 |
reOpen |
|
44 | 200 |
"reopen the stream after an image restart. |
201 |
If I am one of the standard streams, reopen is easy" |
|
1 | 202 |
|
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
203 |
(self == StdInStream) ifTrue:[ |
177 | 204 |
^ self initializeForStdin |
1 | 205 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
206 |
(self == StdOutStream) ifTrue:[ |
177 | 207 |
^ self initializeForStdout |
1 | 208 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
209 |
(self == StdErrorStream) ifTrue:[ |
177 | 210 |
^ self initializeForStderr |
1 | 211 |
]. |
212 |
^ super reOpen |
|
213 |
! ! |
|
613 | 214 |
|
215 |
!NonPositionableExternalStream methodsFor:'queries'! |
|
216 |
||
217 |
isPositionable |
|
218 |
"return true, if the stream supports positioning (this one is not)" |
|
219 |
||
220 |
^ false |
|
221 |
! ! |
|
222 |