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