1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
10
|
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 |
|
|
13 |
ExternalStream 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
|
10
|
22 |
All Rights Reserved
|
1
|
23 |
'!
|
|
24 |
|
|
25 |
%{
|
|
26 |
#include <stdio.h>
|
|
27 |
%}
|
|
28 |
|
88
|
29 |
!NonPositionableExternalStream class methodsFor:'documentation'!
|
|
30 |
|
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
34 |
All Rights Reserved
|
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
|
47 |
$Header: /cvs/stx/stx/libbasic/NonPositionableExternalStream.st,v 1.7 1994-06-02 16:20:59 claus Exp $
|
|
48 |
"
|
|
49 |
!
|
|
50 |
|
|
51 |
documentation
|
|
52 |
"
|
|
53 |
This class provides common protocol for all non-positionable,
|
|
54 |
external streams. Concrete subclasses are terminal streams, pipe streams,
|
|
55 |
PrinterStreams, Sockets etc.
|
|
56 |
|
|
57 |
There are three special instances of this class, representing stdin,
|
|
58 |
stdout and stderr of the smalltalk/X process (see Unix manuals, if you
|
|
59 |
dont know what those are used for).
|
|
60 |
"
|
|
61 |
! !
|
|
62 |
|
1
|
63 |
!NonPositionableExternalStream class methodsFor:'instance creation'!
|
|
64 |
|
|
65 |
forStdin
|
44
|
66 |
"return a NonPositionableExternalStream object for reading from
|
|
67 |
Unixes standard input file descriptor"
|
|
68 |
|
88
|
69 |
StdInStream isNil ifTrue:[
|
|
70 |
StdInStream := self basicNew initializeForStdin
|
|
71 |
].
|
|
72 |
^ StdInStream
|
1
|
73 |
!
|
|
74 |
|
|
75 |
forStdout
|
44
|
76 |
"return a NonPositionableExternalStream object for writing to
|
|
77 |
Unixes standard output file descriptor"
|
|
78 |
|
88
|
79 |
StdOutStream isNil ifTrue:[
|
|
80 |
StdOutStream := self basicNew initializeForStdout
|
|
81 |
].
|
|
82 |
^ StdOutStream
|
1
|
83 |
!
|
|
84 |
|
|
85 |
forStderr
|
44
|
86 |
"return a NonPositionableExternalStream object for writing to
|
|
87 |
Unixes standard error output file descriptor"
|
|
88 |
|
88
|
89 |
StdErrorStream isNil ifTrue:[
|
|
90 |
StdErrorStream := self basicNew initializeForStderr
|
|
91 |
].
|
|
92 |
^ StdErrorStream
|
1
|
93 |
! !
|
|
94 |
|
|
95 |
!NonPositionableExternalStream methodsFor:'private'!
|
|
96 |
|
|
97 |
initializeForStdin
|
44
|
98 |
"setup for reading stdin"
|
|
99 |
|
1
|
100 |
mode := #readonly.
|
10
|
101 |
buffered := true.
|
1
|
102 |
%{
|
|
103 |
_INST(filePointer) = MKOBJ(stdin);
|
|
104 |
%}
|
|
105 |
!
|
|
106 |
|
|
107 |
initializeForStdout
|
44
|
108 |
"setup for writing to stdout"
|
|
109 |
|
1
|
110 |
mode := #readwrite.
|
10
|
111 |
buffered := false.
|
1
|
112 |
%{
|
|
113 |
_INST(filePointer) = MKOBJ(stdout);
|
|
114 |
%}
|
|
115 |
!
|
|
116 |
|
|
117 |
initializeForStderr
|
44
|
118 |
"setup for writing to stderr"
|
|
119 |
|
1
|
120 |
mode := #readwrite.
|
10
|
121 |
buffered := false.
|
1
|
122 |
%{
|
|
123 |
_INST(filePointer) = MKOBJ(stderr);
|
|
124 |
%}
|
|
125 |
!
|
|
126 |
|
|
127 |
reOpen
|
44
|
128 |
"reopen the stream after an image restart.
|
|
129 |
If I am one of the standard streams, reopen is easy"
|
1
|
130 |
|
88
|
131 |
(self == #StdInStream) ifTrue:[
|
10
|
132 |
^ self initializeForStdin
|
1
|
133 |
].
|
88
|
134 |
(self == #StdOutStream) ifTrue:[
|
10
|
135 |
^ self initializeForStdout
|
1
|
136 |
].
|
88
|
137 |
(self == #StdErrorStream) ifTrue:[
|
10
|
138 |
^ self initializeForStderr
|
1
|
139 |
].
|
|
140 |
^ super reOpen
|
|
141 |
! !
|
|
142 |
|
10
|
143 |
!NonPositionableExternalStream methodsFor:'redefind basic'!
|
1
|
144 |
|
10
|
145 |
size
|
|
146 |
"report an error that this stream has no concept of size"
|
1
|
147 |
|
10
|
148 |
self shouldNotImplement
|
|
149 |
!
|
1
|
150 |
|
|
151 |
position
|
10
|
152 |
"report an error that this stream has no concept of position"
|
|
153 |
|
|
154 |
self shouldNotImplement
|
1
|
155 |
!
|
|
156 |
|
|
157 |
position:anInteger
|
10
|
158 |
"report an error that this stream has no concept of position"
|
|
159 |
|
|
160 |
self shouldNotImplement
|
1
|
161 |
! !
|