author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 19:02:53 +0200 | |
changeset 1295 | 83f594f05c52 |
parent 1133 | 961f2b095c22 |
child 1344 | 32a51164b237 |
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 |
1295 | 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. |
|
1295 | 58 |
|
59 |
[author:] |
|
60 |
Claus Gittinger |
|
88 | 61 |
" |
216 | 62 |
! ! |
63 |
||
1 | 64 |
!NonPositionableExternalStream class methodsFor:'instance creation'! |
65 |
||
613 | 66 |
forStderr |
67 |
"return a NonPositionableExternalStream object for writing to |
|
68 |
Unixes standard error output file descriptor" |
|
69 |
||
70 |
StdErrorStream isNil ifTrue:[ |
|
71 |
StdErrorStream := self basicNew initializeForStderr |
|
72 |
]. |
|
73 |
^ StdErrorStream |
|
74 |
! |
|
75 |
||
1 | 76 |
forStdin |
44 | 77 |
"return a NonPositionableExternalStream object for reading from |
78 |
Unixes standard input file descriptor" |
|
79 |
||
88 | 80 |
StdInStream isNil ifTrue:[ |
177 | 81 |
StdInStream := self basicNew initializeForStdin |
88 | 82 |
]. |
83 |
^ StdInStream |
|
1 | 84 |
! |
85 |
||
86 |
forStdout |
|
44 | 87 |
"return a NonPositionableExternalStream object for writing to |
88 |
Unixes standard output file descriptor" |
|
89 |
||
88 | 90 |
StdOutStream isNil ifTrue:[ |
177 | 91 |
StdOutStream := self basicNew initializeForStdout |
88 | 92 |
]. |
93 |
^ StdOutStream |
|
613 | 94 |
! ! |
95 |
||
96 |
!NonPositionableExternalStream methodsFor:'error handling'! |
|
97 |
||
98 |
positionError |
|
99 |
"notify that this stream has no concept of a position" |
|
100 |
||
101 |
^ PositionErrorSignal raiseRequestWith:self in:thisContext sender |
|
102 |
! ! |
|
103 |
||
104 |
!NonPositionableExternalStream methodsFor:'positioning'! |
|
105 |
||
106 |
position |
|
107 |
"catch position - there is none here" |
|
108 |
||
109 |
^ self positionError |
|
1 | 110 |
! |
111 |
||
613 | 112 |
position:aPosition |
113 |
"catch position - there is none here" |
|
114 |
||
115 |
^ self positionError |
|
116 |
! |
|
44 | 117 |
|
613 | 118 |
skip:numberToSkip |
119 |
"skip count objects, return the receiver" |
|
120 |
||
121 |
"dont know how to unread ..." |
|
122 |
numberToSkip < 0 ifTrue:[ |
|
123 |
^ self error:'stream is not positionable' |
|
88 | 124 |
]. |
613 | 125 |
numberToSkip timesRepeat:self next |
1 | 126 |
! ! |
127 |
||
177 | 128 |
!NonPositionableExternalStream methodsFor:'printing & storing'! |
129 |
||
130 |
printOn:aStream |
|
213 | 131 |
"append a printed representation of the receiver on aStream" |
177 | 132 |
|
133 |
self == Stdin ifTrue:[ |
|
134 |
aStream nextPutAll:'Stdin'. |
|
135 |
^ self |
|
136 |
]. |
|
137 |
self == Stdout ifTrue:[ |
|
138 |
aStream nextPutAll:'Stdout'. |
|
139 |
^ self |
|
140 |
]. |
|
141 |
self == Stderr ifTrue:[ |
|
142 |
aStream nextPutAll:'Stderr'. |
|
143 |
^ self |
|
144 |
]. |
|
145 |
super printOn:aStream |
|
146 |
! |
|
147 |
||
148 |
storeOn:aStream |
|
213 | 149 |
"append a printed representation of the receiver on aStream, from |
150 |
which the receiver can be reconstructed." |
|
177 | 151 |
|
152 |
((self == Stdin) |
|
153 |
or:[self == Stdout |
|
154 |
or:[self == Stderr]]) ifTrue:[ |
|
155 |
^ self printOn:aStream |
|
156 |
]. |
|
157 |
super storeOn:aStream |
|
158 |
! ! |
|
159 |
||
613 | 160 |
!NonPositionableExternalStream methodsFor:'private'! |
360 | 161 |
|
613 | 162 |
initializeForStderr |
163 |
"setup for writing to stderr" |
|
269 | 164 |
|
613 | 165 |
mode := #readwrite. |
166 |
buffered := false. |
|
167 |
%{ |
|
168 |
OBJ fp; |
|
269 | 169 |
|
1133 | 170 |
__INST(filePointer) = fp = __MKOBJ(stderr); __STORE(self, fp); |
613 | 171 |
%} |
172 |
! |
|
1 | 173 |
|
174 |
initializeForStdin |
|
44 | 175 |
"setup for reading stdin" |
176 |
||
1 | 177 |
mode := #readonly. |
10 | 178 |
buffered := true. |
1 | 179 |
%{ |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
180 |
OBJ fp; |
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
181 |
|
1133 | 182 |
__INST(filePointer) = fp = __MKOBJ(stdin); __STORE(self, fp); |
1 | 183 |
%} |
184 |
! |
|
185 |
||
186 |
initializeForStdout |
|
44 | 187 |
"setup for writing to stdout" |
188 |
||
1 | 189 |
mode := #readwrite. |
10 | 190 |
buffered := false. |
1 | 191 |
%{ |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
192 |
OBJ fp; |
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
193 |
|
1133 | 194 |
__INST(filePointer) = fp = __MKOBJ(stdout); __STORE(self, fp); |
1 | 195 |
%} |
196 |
! |
|
197 |
||
198 |
reOpen |
|
44 | 199 |
"reopen the stream after an image restart. |
200 |
If I am one of the standard streams, reopen is easy" |
|
1 | 201 |
|
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
202 |
(self == StdInStream) ifTrue:[ |
177 | 203 |
^ self initializeForStdin |
1 | 204 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
205 |
(self == StdOutStream) ifTrue:[ |
177 | 206 |
^ self initializeForStdout |
1 | 207 |
]. |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
208 |
(self == StdErrorStream) ifTrue:[ |
177 | 209 |
^ self initializeForStderr |
1 | 210 |
]. |
211 |
^ super reOpen |
|
212 |
! ! |
|
613 | 213 |
|
214 |
!NonPositionableExternalStream methodsFor:'queries'! |
|
215 |
||
216 |
isPositionable |
|
217 |
"return true, if the stream supports positioning (this one is not)" |
|
218 |
||
219 |
^ false |
|
220 |
! ! |
|
221 |
||
1295 | 222 |
!NonPositionableExternalStream class methodsFor:'documentation'! |
223 |
||
224 |
version |
|
225 |
^ '$Header: /cvs/stx/stx/libbasic/NonPositionableExternalStream.st,v 1.27 1996-04-25 17:02:24 cg Exp $' |
|
226 |
! ! |