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