author | Claus Gittinger <cg@exept.de> |
Sat, 11 Jan 1997 19:16:19 +0100 | |
changeset 2153 | 244e36cbbd9b |
parent 2130 | b9e7e1cf98bd |
child 2154 | 89e96599e1e2 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 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 |
||
57 | 13 |
PeekableStream subclass:#PositionableStream |
973 | 14 |
instanceVariableNames:'collection position readLimit writeLimit' |
15 |
classVariableNames:'ErrorDuringFileInSignal ChunkSeparator' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Streams' |
|
1 | 18 |
! |
19 |
||
1897 | 20 |
!PositionableStream class methodsFor:'documentation'! |
88 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 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 |
! |
|
10 | 35 |
|
88 | 36 |
documentation |
37 |
" |
|
38 |
Instances of PositionableStream allow positioning the read pointer. |
|
39 |
The PositionableStream class also adds methods for source-chunk reading |
|
40 |
and writing, and for filing-in/out of source code. |
|
41 |
This is an abstract class. |
|
1295 | 42 |
|
43 |
[author:] |
|
1998 | 44 |
Claus Gittinger |
88 | 45 |
" |
46 |
! ! |
|
1 | 47 |
|
1897 | 48 |
!PositionableStream class methodsFor:'initialization'! |
1 | 49 |
|
10 | 50 |
initialize |
44 | 51 |
"setup the signal used to handle errors during fileIn" |
52 |
||
10 | 53 |
ErrorDuringFileInSignal isNil ifTrue:[ |
302 | 54 |
ErrorDuringFileInSignal := ErrorSignal newSignalMayProceed:true. |
159 | 55 |
ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal. |
56 |
ErrorDuringFileInSignal notifierString:'error during fileIn'. |
|
276 | 57 |
|
58 |
ChunkSeparator := $!! |
|
10 | 59 |
] |
60 |
! ! |
|
1 | 61 |
|
1897 | 62 |
!PositionableStream class methodsFor:'instance creation'! |
1 | 63 |
|
64 |
on:aCollection |
|
65 |
"return a new PositionableStream streaming on aCollection" |
|
66 |
||
67 |
^ (self basicNew) on:aCollection |
|
68 |
! |
|
69 |
||
70 |
on:aCollection from:first to:last |
|
71 |
"return a new PositionableStream streaming on aCollection |
|
72 |
from first to last" |
|
73 |
||
369 | 74 |
^ (self basicNew) on:aCollection from:first to:last |
57 | 75 |
! |
76 |
||
77 |
with:aCollection |
|
78 |
"return a new PositionableStream streaming on aCollection, |
|
79 |
the stream is positioned to the end of the collection." |
|
80 |
||
362 | 81 |
^ (self basicNew) with:aCollection |
1 | 82 |
! ! |
83 |
||
1897 | 84 |
!PositionableStream class methodsFor:'constants'! |
1 | 85 |
|
611 | 86 |
chunkSeparator |
87 |
"return the chunk-separation character" |
|
57 | 88 |
|
611 | 89 |
^ ChunkSeparator |
360 | 90 |
! ! |
91 |
||
1 | 92 |
!PositionableStream methodsFor:'accessing'! |
93 |
||
94 |
contents |
|
95 |
"return the entire contents of the stream" |
|
96 |
||
97 |
^ collection |
|
98 |
! |
|
99 |
||
100 |
peek |
|
101 |
"look ahead for and return the next element" |
|
102 |
||
103 |
|peekObject| |
|
104 |
||
105 |
peekObject := self next. |
|
10 | 106 |
self backStep. |
1 | 107 |
^ peekObject |
108 |
! |
|
109 |
||
110 |
peekFor:something |
|
10 | 111 |
"return true and move past if next == something; |
112 |
otherwise stay and let position unchanged" |
|
1 | 113 |
|
114 |
self next == something ifTrue:[ |
|
159 | 115 |
^ true |
1 | 116 |
]. |
10 | 117 |
self backStep. |
1 | 118 |
^ false |
119 |
! |
|
120 |
||
121 |
readLimit:aNumber |
|
369 | 122 |
"set the read-limit; thats the position at which EOF is returned" |
1 | 123 |
|
124 |
readLimit := aNumber |
|
369 | 125 |
! |
126 |
||
127 |
writeLimit:aNumber |
|
128 |
"set the writeLimit; thats the position after which writing is prohibited" |
|
129 |
||
130 |
writeLimit := aNumber |
|
1 | 131 |
! ! |
132 |
||
44 | 133 |
!PositionableStream methodsFor:'chunk input/output'! |
1 | 134 |
|
135 |
nextChunk |
|
136 |
"return the next chunk, i.e. all characters up to the next |
|
217 | 137 |
exclamation mark. Within the chunk, exclamation marks have to be doubled, |
138 |
they are undoubled here. |
|
139 |
Except for primitive code, in which doubling is not needed (allowed). |
|
140 |
This exception was added to make it easier to edit primitive code with |
|
141 |
external editors. However, this means, that other Smalltalks cannot always |
|
142 |
read chunks containing primitive code |
|
143 |
- but that doesnt really matter, since C-primitives are an ST/X feature anyway." |
|
1 | 144 |
|
145 |
|theString sep newString done thisChar nextChar inPrimitive |
|
146 |
index "{ Class:SmallInteger }" |
|
147 |
currSize "{ Class:SmallInteger }" | |
|
148 |
||
276 | 149 |
sep := ChunkSeparator. |
1 | 150 |
theString := String new:500. |
151 |
currSize := 500. |
|
152 |
thisChar := self skipSeparators. |
|
153 |
thisChar := self next. |
|
154 |
index := 0. |
|
155 |
done := false. |
|
156 |
inPrimitive := false. |
|
157 |
||
158 |
[done] whileFalse:[ |
|
159 | 159 |
((index + 2) <= currSize) ifFalse:[ |
160 |
newString := String new:(currSize * 2). |
|
161 |
newString replaceFrom:1 to:currSize with:theString. |
|
162 |
currSize := currSize * 2. |
|
163 |
theString := newString |
|
164 |
]. |
|
165 |
thisChar isNil ifTrue:[ |
|
166 |
done := true |
|
167 |
] ifFalse:[ |
|
168 |
(thisChar == $% ) ifTrue:[ |
|
169 |
nextChar := self peek. |
|
170 |
(nextChar == ${ ) ifTrue:[ |
|
171 |
inPrimitive := true. |
|
172 |
index := index + 1. |
|
173 |
theString at:index put:thisChar. |
|
174 |
thisChar := self next |
|
175 |
] ifFalse:[ |
|
176 |
(nextChar == $} ) ifTrue:[ |
|
177 |
inPrimitive := false. |
|
178 |
index := index + 1. |
|
179 |
theString at:index put:thisChar. |
|
180 |
thisChar := self next |
|
181 |
] |
|
182 |
] |
|
183 |
] ifFalse:[ |
|
184 |
inPrimitive ifFalse:[ |
|
185 |
(thisChar == sep) ifTrue:[ |
|
186 |
(self peek == sep) ifFalse:[ |
|
187 |
done := true |
|
188 |
] ifTrue:[ |
|
189 |
self next |
|
190 |
] |
|
191 |
] |
|
192 |
] |
|
193 |
] |
|
194 |
]. |
|
195 |
done ifFalse:[ |
|
196 |
index := index + 1. |
|
197 |
theString at:index put:thisChar. |
|
198 |
thisChar := self next |
|
199 |
] |
|
1 | 200 |
]. |
201 |
(index == 0) ifTrue:[^ '']. |
|
57 | 202 |
^ theString copyTo:index |
1 | 203 |
! |
204 |
||
205 |
nextChunkPut:aString |
|
206 |
"put aString as a chunk onto the receiver; |
|
217 | 207 |
double all exclamation marks except within primitives and append a |
276 | 208 |
single delimiting exclamation mark at the end. |
718
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
209 |
This modification of the chunk format (not doubling exclas in primitive code) |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
210 |
was done to have primitive code more readable and easier be edited in the fileBrowser |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
211 |
or other editors. |
276 | 212 |
Its no incompatibility, since inline primitives are an ST/X special |
718
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
213 |
and code containing ST/X primitives cannot be loaded into other smalltalks anyway." |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
214 |
|
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
215 |
self nextPutAllAsChunk:aString. |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
216 |
self nextPut:ChunkSeparator |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
217 |
|
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
218 |
"Modified: 9.12.1995 / 15:56:54 / cg" |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
219 |
! |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
220 |
|
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
221 |
nextPutAllAsChunk:aString |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
222 |
"put aString as a chunk onto the receiver; |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
223 |
double all exclamation marks except within primitives. |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
224 |
This modification of the chunk format (not doubling exclas in primitive code) |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
225 |
was done to have primitive code more readable and easier be edited in the fileBrowser |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
226 |
or other editors. |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
227 |
Its no incompatibility, since inline primitives are an ST/X special |
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
228 |
and code containing ST/X primitives cannot be loaded into other smalltalks anyway." |
1 | 229 |
|
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
230 |
|sep stopChars inPrimitive character |
1 | 231 |
index "{ Class:SmallInteger }" |
232 |
endIndex "{ Class:SmallInteger }" |
|
217 | 233 |
stop "{ Class:SmallInteger }" |
253 | 234 |
next "{ Class:SmallInteger }"| |
1 | 235 |
|
276 | 236 |
sep := ChunkSeparator. |
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
237 |
stopChars := '{}' copyWith:sep. |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
238 |
|
1 | 239 |
inPrimitive := false. |
240 |
index := 1. |
|
241 |
endIndex := aString size. |
|
217 | 242 |
stop := endIndex + 1. |
1 | 243 |
|
244 |
[index <= endIndex] whileTrue:[ |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
245 |
" |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
246 |
find position of next interesting character; |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
247 |
output stuff up to that one in one piece |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
248 |
" |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
249 |
next := aString indexOfAny:stopChars startingAt:index ifAbsent:stop. |
1 | 250 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
251 |
((index == 1) and:[next == stop]) ifTrue:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
252 |
self nextPutAll:aString |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
253 |
] ifFalse:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
254 |
self nextPutAll:aString startingAt:index to:(next - 1) |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
255 |
]. |
1 | 256 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
257 |
index := next. |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
258 |
(index <= endIndex) ifTrue:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
259 |
character := aString at:index. |
276 | 260 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
261 |
(character == ${ ) ifTrue:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
262 |
"/ starts a primitive |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
263 |
((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
264 |
inPrimitive := true |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
265 |
] |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
266 |
] ifFalse:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
267 |
"/ ends a primitive |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
268 |
(character == $} ) ifTrue:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
269 |
((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
270 |
inPrimitive := false |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
271 |
] |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
272 |
] ifFalse:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
273 |
"/ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
274 |
"/ exclas have to be doubled - except if within a primitive |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
275 |
"/ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
276 |
inPrimitive ifFalse:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
277 |
(character == sep) ifTrue:[ |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
278 |
self nextPut:sep |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
279 |
] |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
280 |
] |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
281 |
] |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
282 |
]. |
276 | 283 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
284 |
self nextPut:character. |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
285 |
index := index + 1 |
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
286 |
] |
1 | 287 |
]. |
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
288 |
|
718
6f8222ff2ff0
extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
289 |
"Modified: 9.12.1995 / 15:56:47 / cg" |
611 | 290 |
! |
291 |
||
292 |
nextPutChunkSeparator |
|
293 |
"append a chunk separator character" |
|
294 |
||
295 |
self nextPut:ChunkSeparator |
|
296 |
||
297 |
"Created: 13.9.1995 / 17:39:26 / claus" |
|
44 | 298 |
! ! |
299 |
||
300 |
!PositionableStream methodsFor:'fileIn'! |
|
301 |
||
611 | 302 |
askForDebug:message |
303 |
"launch a box asking if a debugger is wanted - used when an error |
|
304 |
occurs while filing in" |
|
305 |
||
306 |
Smalltalk isInitialized ifFalse:[ |
|
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
307 |
'PositionableStream [warning]: fileIn error during startup: ' errorPrint. message errorPrintCR. |
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
308 |
^ #debug |
611 | 309 |
]. |
875
2bb6fea4cb55
dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
310 |
"/ |
2bb6fea4cb55
dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
311 |
"/ are we in the startup sequence of an image restart ? |
2bb6fea4cb55
dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
312 |
"/ |
2bb6fea4cb55
dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
313 |
Processor activeProcessIsSystemProcess ifTrue:[ |
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
314 |
'PositionableStream [warning]: fileIn error during startup: ' errorPrint. message errorPrintCR. |
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
315 |
^ #continue |
875
2bb6fea4cb55
dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
316 |
]. |
2bb6fea4cb55
dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
317 |
|
611 | 318 |
^ OptionBox |
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
319 |
request:message |
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
320 |
label:'Error in fileIn' |
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
321 |
form:(WarningBox iconBitmap) |
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
322 |
buttonLabels:#('cancel' 'debug' 'continue') |
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
323 |
values:#(#abort #debug #continue) |
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
324 |
default:#continue. |
975 | 325 |
|
2130
b9e7e1cf98bd
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2005
diff
changeset
|
326 |
"Modified: 10.1.1997 / 18:00:56 / cg" |
611 | 327 |
! |
328 |
||
44 | 329 |
fileIn |
330 |
"file in from the receiver, i.e. read chunks and evaluate them - |
|
331 |
return the value of the last chunk." |
|
332 |
||
283 | 333 |
^ self fileInNotifying:(SourceFileLoader on:self) passChunk:true |
44 | 334 |
! |
335 |
||
1 | 336 |
fileInNextChunkNotifying:someone |
337 |
"read next chunk, evaluate it and return the result; |
|
276 | 338 |
someone (which is usually some codeView) is notified of errors. |
339 |
Filein is done as follows: |
|
340 |
read a chunk |
|
341 |
if it started with an excla, evaluate it, and let the resulting object |
|
342 |
fileIn more chunks. |
|
343 |
This is a nice trick, since the methodsFor: expression evaluates to |
|
344 |
a ClassCategoryReader which reads and compiles chunks for its class. |
|
345 |
However, other than methodsFor expressions are possible - you can |
|
346 |
(in theory) create readers for any syntax. |
|
347 |
" |
|
1 | 348 |
|
282 | 349 |
^ self fileInNextChunkNotifying:someone passChunk:false |
350 |
! |
|
351 |
||
352 |
fileInNextChunkNotifying:someone passChunk:passChunk |
|
353 |
"read next chunk, evaluate it and return the result; |
|
354 |
someone (which is usually some codeView) is notified of errors. |
|
355 |
Filein is done as follows: |
|
1998 | 356 |
read a chunk |
357 |
if it started with an excla, evaluate it, and let the resulting object |
|
358 |
fileIn more chunks. |
|
359 |
This is a nice trick, since the methodsFor: expression evaluates to |
|
360 |
a ClassCategoryReader which reads and compiles chunks for its class. |
|
361 |
However, other than methodsFor expressions are possible - you can |
|
362 |
(in theory) create readers for any syntax. |
|
282 | 363 |
" |
364 |
||
276 | 365 |
|aString sawExcla rslt done| |
1 | 366 |
|
367 |
self skipSeparators. |
|
368 |
self atEnd ifFalse:[ |
|
1998 | 369 |
sawExcla := self peekFor:ChunkSeparator. |
370 |
aString := self nextChunk. |
|
371 |
aString size ~~ 0 ifTrue:[ |
|
372 |
passChunk ifTrue:[ |
|
373 |
someone source:aString |
|
374 |
]. |
|
375 |
sawExcla ifFalse:[ |
|
376 |
rslt := Compiler evaluate:aString notifying:someone. |
|
377 |
] ifTrue:[ |
|
378 |
rslt := Compiler evaluate:aString notifying:someone compile:false. |
|
282 | 379 |
|
1998 | 380 |
" |
381 |
usually, the above chunk consists of some methodsFor:-expression |
|
382 |
in this case, the returned value is a ClassCategoryReader, |
|
383 |
which is used to load & compile the methods ... |
|
384 |
" |
|
385 |
rslt isNil ifTrue:[ |
|
386 |
" |
|
387 |
however, if that was nil (i.e. some error), we skip chunks |
|
388 |
up to the next empty chunk. |
|
389 |
" |
|
390 |
Transcript showCR:'skipping chunks ...'. |
|
391 |
done := false. |
|
392 |
[done] whileFalse:[ |
|
393 |
aString := self nextChunk. |
|
394 |
done := (aString size == 0) or:[aString isEmpty]. |
|
395 |
] |
|
396 |
] ifFalse:[ |
|
397 |
rslt := rslt fileInFrom:self notifying:someone passChunk:passChunk |
|
398 |
] |
|
399 |
] |
|
400 |
] |
|
1 | 401 |
]. |
159 | 402 |
^ rslt |
1420 | 403 |
|
404 |
"Modified: 18.5.1996 / 15:44:21 / cg" |
|
1 | 405 |
! |
406 |
||
611 | 407 |
fileInNotifying:someone passChunk:passChunk |
408 |
"file in from the receiver, i.e. read chunks and evaluate them - |
|
409 |
return the value of the last chunk. |
|
410 |
Someone (which is usually some codeView) is notified of errors." |
|
411 |
||
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
412 |
|lastValue queries pkg spc spaces| |
611 | 413 |
|
1902 | 414 |
queries := SignalSet with:(Class packageQuerySignal) |
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
415 |
with:(Class nameSpaceQuerySignal) |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
416 |
with:(Class usedNameSpaceQuerySignal). |
1902 | 417 |
|
418 |
queries handle:[:ex | |
|
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
419 |
ex signal == Class packageQuerySignal ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
420 |
pkg isNil ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
421 |
(someone respondsTo:#packageToInstall) ifFalse:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
422 |
pkg := Class packageQuerySignal raise. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
423 |
] ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
424 |
pkg := someone packageToInstall |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
425 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
426 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
427 |
ex proceedWith:pkg |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
428 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
429 |
ex signal == Class nameSpaceQuerySignal ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
430 |
spc isNil ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
431 |
(someone respondsTo:#currentNameSpace) ifFalse:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
432 |
spc := Class nameSpaceQuerySignal raise. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
433 |
] ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
434 |
spc := someone currentNameSpace |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
435 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
436 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
437 |
ex proceedWith:spc |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
438 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
439 |
ex signal == Class usedNameSpaceQuerySignal ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
440 |
spaces isNil ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
441 |
(someone respondsTo:#usedNameSpaces) ifFalse:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
442 |
spaces := Class usedNameSpaceQuerySignal raise. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
443 |
] ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
444 |
spaces := someone usedNameSpaces |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
445 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
446 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
447 |
ex proceedWith:spaces |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
448 |
]. |
1897 | 449 |
] do:[ |
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
450 |
" |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
451 |
catch any errors during fileIn |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
452 |
- offer debug/abort/continue choice |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
453 |
" |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
454 |
ErrorSignal handle:[:ex | |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
455 |
|action what sender msg param oldPackage newPackage| |
1929
ede0e5b91a05
show more info when a messageRedefinition exception happens
Claus Gittinger <cg@exept.de>
parents:
1902
diff
changeset
|
456 |
|
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
457 |
"/ for your convenience ... |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
458 |
ex signal == Class methodRedefinitionSignal ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
459 |
param := ex parameter. "/ an association: oldMethod -> newMethod |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
460 |
oldPackage := param key package. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
461 |
newPackage := param value package. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
462 |
msg := 'trying to overwrite method:\\ %1\\in package ''' |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
463 |
, oldPackage , ''' with method from package ''' , newPackage , '''' |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
464 |
] ifFalse:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
465 |
msg := 'error in fileIn: %1' |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
466 |
]. |
41 | 467 |
|
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
468 |
what := ex errorString. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
469 |
what isNil ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
470 |
what := ex signal notifierString. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
471 |
]. |
611 | 472 |
|
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
473 |
"handle the case where no GUI has been built in, |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
474 |
just abort the fileIn with a notification" |
611 | 475 |
|
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
476 |
Display isNil ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
477 |
sender := ex suspendedContext sender. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
478 |
self notify:(what , |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
479 |
' in ' , sender receiver class name , |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
480 |
'>>>' , sender selector). |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
481 |
ex return |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
482 |
]. |
1897 | 483 |
|
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
484 |
"otherwise ask what should be done now and either |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
485 |
continue or abort the fileIn" |
1897 | 486 |
|
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
487 |
action := self askForDebug:(msg bindWith:what) withCRs. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
488 |
action == #continue ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
489 |
ex proceed |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
490 |
]. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
491 |
action == #abort ifTrue:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
492 |
ex return |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
493 |
]. |
1897 | 494 |
"/ Debugger enter:ex suspendedContext |
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
495 |
(ex signal) enterDebuggerWith:ex message:what. |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
496 |
ex reject |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
497 |
] do:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
498 |
[self atEnd] whileFalse:[ |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
499 |
lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
500 |
] |
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
501 |
]. |
180 | 502 |
]. |
611 | 503 |
^ lastValue |
973 | 504 |
|
2005
d77ecd466b5b
handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
505 |
"Modified: 20.12.1996 / 00:00:13 / cg" |
611 | 506 |
! ! |
507 |
||
508 |
!PositionableStream methodsFor:'positioning'! |
|
509 |
||
510 |
backStep |
|
511 |
"move backward read position by one" |
|
512 |
||
513 |
position <= 0 ifTrue: [^ self positionError]. |
|
514 |
position := position - 1 |
|
515 |
! |
|
516 |
||
517 |
position |
|
518 |
"return the read position" |
|
519 |
||
520 |
^ position |
|
521 |
! |
|
522 |
||
523 |
position:index |
|
524 |
"set the read position" |
|
525 |
||
526 |
"/ FIX: allow positioning right after last element of stream |
|
527 |
"/ ((index > readLimit) or:[index < 0]) ifTrue: [^ self positionError]. |
|
528 |
||
529 |
((index > (readLimit+1)) or:[index < 0]) ifTrue: [^ self positionError]. |
|
530 |
position := index |
|
531 |
! |
|
532 |
||
533 |
reset |
|
534 |
"set the read position to the beginning of the collection" |
|
535 |
||
536 |
position := "0" 1 |
|
537 |
! |
|
538 |
||
539 |
setToEnd |
|
540 |
"set the read position to the end of the collection" |
|
541 |
||
542 |
position := readLimit |
|
543 |
! |
|
544 |
||
545 |
skip:numberToSkip |
|
546 |
"skip the next numberToSkip elements" |
|
547 |
||
548 |
self position:(position + numberToSkip) |
|
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
549 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
550 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
551 |
skipThroughAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
552 |
"skip for and through the sequence given by the argument, aCollection; |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
553 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
554 |
On a successful match, the next read will return elements after aCollection; |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
555 |
if no match was found, the receiver will be positioned at the end. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
556 |
This is redefined here, to make use of positioning." |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
557 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
558 |
|oldPos buffer l first idx| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
559 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
560 |
oldPos := self position. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
561 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
562 |
l := aCollection size. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
563 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
564 |
[self atEnd] whileFalse:[ |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
565 |
buffer := self nextAvailable:l. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
566 |
buffer = aCollection ifTrue:[ |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
567 |
^ self |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
568 |
]. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
569 |
idx := buffer indexOf:first startingAt:2. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
570 |
idx == 0 ifFalse:[ |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
571 |
self position:(self position - l + idx - 1) |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
572 |
] |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
573 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
574 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
575 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
576 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
577 |
|s| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
578 |
s := ReadStream on:'12345678901234567890'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
579 |
s skipThroughAll:'901'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
580 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
581 |
" |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
582 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
583 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
584 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
585 |
s skipThroughAll:'1234'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
586 |
s upToEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
587 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
588 |
" |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
589 |
|s| |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
590 |
s := ReadStream on:'12345678901234567890'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
591 |
s skipThroughAll:'999'. |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
592 |
s atEnd |
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
593 |
" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
594 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
595 |
"Created: 26.6.1996 / 09:35:35 / cg" |
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
596 |
"Modified: 11.1.1997 / 19:10:26 / cg" |
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
597 |
! |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
598 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
599 |
skipToAll:aCollection |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
600 |
"skip for the sequence given by the argument, aCollection; |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
601 |
return nil if not found, self otherwise. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
602 |
On a successful match, the next read will return elements of aCollection." |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
603 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
604 |
|oldPos buffer l first idx| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
605 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
606 |
oldPos := self position. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
607 |
l := aCollection size. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
608 |
first := aCollection at:1. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
609 |
[self atEnd] whileFalse:[ |
1998 | 610 |
buffer := self next:l. |
611 |
buffer = aCollection ifTrue:[ |
|
612 |
self position:(self position - l). |
|
613 |
^ self |
|
614 |
]. |
|
615 |
idx := buffer indexOf:first startingAt:2. |
|
616 |
idx == 0 ifFalse:[ |
|
617 |
self position:(self position - l + idx - 1) |
|
618 |
] |
|
1489
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
619 |
]. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
620 |
self position:oldPos. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
621 |
^ nil |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
622 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
623 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
624 |
|s| |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
625 |
s := ReadStream on:'12345678901234567890'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
626 |
s skipToAll:'901'. |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
627 |
s upToEnd |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
628 |
" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
629 |
|
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
630 |
"Modified: 26.6.1996 / 09:28:27 / cg" |
9e3b166483fb
moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
631 |
"Created: 26.6.1996 / 09:35:06 / cg" |
44 | 632 |
! ! |
611 | 633 |
|
634 |
!PositionableStream methodsFor:'private'! |
|
635 |
||
636 |
contentsSpecies |
|
637 |
"return a class of which instances will be returned, when |
|
638 |
parts of the collection are asked for. |
|
639 |
(see upTo-kind of methods in subclasses)" |
|
640 |
||
641 |
^ collection species |
|
642 |
! |
|
643 |
||
644 |
on:aCollection |
|
645 |
"setup for streaming on aCollection" |
|
646 |
||
647 |
collection := aCollection. |
|
648 |
readLimit := aCollection size. |
|
649 |
position := "0" 1 |
|
650 |
! |
|
651 |
||
652 |
on:aCollection from:first to:last |
|
653 |
"setup for streaming on aCollection from first to last" |
|
654 |
||
655 |
collection := aCollection. |
|
656 |
position := first. |
|
657 |
readLimit := last |
|
658 |
! |
|
659 |
||
660 |
positionError |
|
1998 | 661 |
"{ Pragma: +optSpace }" |
662 |
||
611 | 663 |
"report an error when positioning past the end" |
664 |
||
665 |
^ self error:'cannot position past end of collection' |
|
666 |
! |
|
667 |
||
668 |
with:aCollection |
|
669 |
"setup for streaming to the end of aCollection" |
|
670 |
||
671 |
collection := aCollection. |
|
672 |
self setToEnd |
|
673 |
! ! |
|
674 |
||
675 |
!PositionableStream methodsFor:'queries'! |
|
676 |
||
677 |
isPositionable |
|
678 |
"return true, if the stream supports positioning (this one is)" |
|
679 |
||
680 |
^ true |
|
681 |
! ! |
|
682 |
||
683 |
!PositionableStream methodsFor:'testing'! |
|
684 |
||
685 |
atEnd |
|
686 |
"return true, if the read-position is at the end" |
|
687 |
||
688 |
^ position > readLimit |
|
689 |
! |
|
690 |
||
691 |
isEmpty |
|
692 |
"return true, if the contents of the stream is empty" |
|
693 |
||
694 |
^ readLimit == 0 |
|
695 |
! ! |
|
696 |
||
1897 | 697 |
!PositionableStream class methodsFor:'documentation'! |
701 | 698 |
|
699 |
version |
|
2153
244e36cbbd9b
skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents:
2130
diff
changeset
|
700 |
^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.52 1997-01-11 18:16:19 cg Exp $' |
701 | 701 |
! ! |
611 | 702 |
PositionableStream initialize! |