180 (position > readLimit) ifTrue:[readLimit := position - 1]. |
180 (position > readLimit) ifTrue:[readLimit := position - 1]. |
181 ^ anObject |
181 ^ anObject |
182 ! |
182 ! |
183 |
183 |
184 nextPut:anObject |
184 nextPut:anObject |
185 "append the argument, anObject to the stream" |
185 "append the argument, anObject to the stream. |
|
186 Special tuned for appending to String, ByteArray and Array streams." |
186 |
187 |
187 %{ /* NOCONTEXT */ |
188 %{ /* NOCONTEXT */ |
188 |
189 |
189 REGISTER int pos; |
190 REGISTER int pos; |
190 unsigned ch; |
191 unsigned ch; |
191 OBJ coll; |
192 OBJ coll; |
192 OBJ p, l; |
193 OBJ p, l, rL; |
|
194 int __readLimit = -1; |
193 |
195 |
194 coll = __INST(collection); |
196 coll = __INST(collection); |
195 p = __INST(position); |
197 p = __INST(position); |
196 |
198 |
197 if (__isNonNilObject(coll) && __isSmallInteger(p)) { |
199 if (__isNonNilObject(coll) && __isSmallInteger(p)) { |
198 |
200 pos = __intVal(p); |
199 pos = __intVal(p); |
201 l = __INST(writeLimit); |
200 l = __INST(writeLimit); |
202 |
201 |
203 if ((l == nil) |
202 if ((l == nil) |
204 || (__isSmallInteger(l) && (pos <= __intVal(l)))) { |
203 || (__isSmallInteger(l) && (pos <= __intVal(l)))) { |
205 OBJ cls; |
204 OBJ cls; |
206 |
205 |
207 cls = __qClass(coll); |
206 cls = __qClass(coll); |
208 |
207 |
209 rL = __INST(readLimit); |
208 if (cls == @global(String)) { |
210 if (__isSmallInteger(rL)) { |
209 if (__isCharacter(anObject) |
211 __readLimit = __intVal(rL); |
210 && (pos <= __stringSize(coll))) { |
212 } |
211 ch = __intVal(_characterVal(anObject)); |
213 |
212 if ((ch >= 0) && (ch <= 255)) { |
214 if (cls == @global(String)) { |
213 __StringInstPtr(coll)->s_element[pos-1] = ch; |
215 if (__isCharacter(anObject) |
214 __INST(position) = __MKSMALLINT(pos + 1); |
216 && (pos <= __stringSize(coll))) { |
215 if (__isSmallInteger(__INST(readLimit)) |
217 ch = __intVal(_characterVal(anObject)); |
216 && (pos >= __intVal(__INST(readLimit)))) { |
218 if ((ch >= 0) && (ch <= 255)) { |
217 __INST(readLimit) = __MKSMALLINT(pos); |
219 __StringInstPtr(coll)->s_element[pos-1] = ch; |
218 } |
220 __INST(position) = __MKSMALLINT(pos + 1); |
219 RETURN ( anObject ); |
221 if ((__readLimit >= 0) && (pos >= __readLimit)) { |
220 } |
222 __INST(readLimit) = __MKSMALLINT(pos); |
221 } |
223 } |
222 } else { |
224 RETURN ( anObject ); |
223 if (cls == @global(ByteArray)) { |
225 } |
224 if (__isSmallInteger(anObject) |
226 } |
225 && ((ch = __intVal(anObject)) >= 0) |
227 } else if (cls == @global(ByteArray)) { |
226 && (ch <= 255) |
228 if (__isSmallInteger(anObject) |
227 && (pos <= _byteArraySize(coll))) { |
229 && ((ch = __intVal(anObject)) >= 0) |
228 __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch; |
230 && (ch <= 255) |
229 __INST(position) = __MKSMALLINT(pos + 1); |
231 && (pos <= _byteArraySize(coll))) { |
230 if (__isSmallInteger(__INST(readLimit)) |
232 __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch; |
231 && (pos >= __intVal(__INST(readLimit)))) { |
233 __INST(position) = __MKSMALLINT(pos + 1); |
232 __INST(readLimit) = __MKSMALLINT(pos); |
234 if ((__readLimit >= 0) && (pos >= __readLimit)) { |
233 } |
235 __INST(readLimit) = __MKSMALLINT(pos); |
234 RETURN ( anObject ); |
236 } |
235 } |
237 RETURN ( anObject ); |
236 } else { |
238 } |
237 if (cls == @global(Array)) { |
239 } else if (cls == @global(Array)) { |
238 if (pos <= _arraySize(coll)) { |
240 if (pos <= _arraySize(coll)) { |
239 __ArrayInstPtr(coll)->a_element[pos-1] = anObject; |
241 __ArrayInstPtr(coll)->a_element[pos-1] = anObject; |
240 __STORE(coll, anObject); |
242 __STORE(coll, anObject); |
241 __INST(position) = __MKSMALLINT(pos + 1); |
243 __INST(position) = __MKSMALLINT(pos + 1); |
242 if (__isSmallInteger(__INST(readLimit)) |
244 if ((__readLimit >= 0) && (pos >= __readLimit)) { |
243 && (pos >= __intVal(__INST(readLimit)))) { |
245 __INST(readLimit) = __MKSMALLINT(pos); |
244 __INST(readLimit) = __MKSMALLINT(pos); |
246 } |
245 } |
247 RETURN ( anObject ); |
246 RETURN ( anObject ); |
248 } |
247 } |
249 } |
248 } |
250 } |
249 } |
|
250 } |
|
251 } |
|
252 } |
251 } |
253 %}. |
252 %}. |
254 (writeLimit isNil |
253 (writeLimit isNil |
255 or:[position <= writeLimit]) ifTrue:[ |
254 or:[position <= writeLimit]) ifTrue:[ |
256 (position > collection size) ifTrue:[self growCollection]. |
255 (position > collection size) ifTrue:[self growCollection]. |
257 collection at:position put:anObject. |
256 collection at:position put:anObject. |
258 (position > readLimit) ifTrue:[readLimit := position]. |
257 (position > readLimit) ifTrue:[readLimit := position]. |
259 position := position + 1. |
258 position := position + 1. |
260 ] ifFalse:[ |
259 ] ifFalse:[ |
261 WriteErrorSignal raiseErrorString:'write behond writeLimit' |
260 WriteErrorSignal raiseErrorString:'write behond writeLimit' |
262 ]. |
261 ]. |
263 ^anObject |
262 ^anObject |
264 ! |
263 ! |
265 |
264 |
266 nextPutAll:aCollection |
265 nextPutAll:aCollection |