--- a/WriteStream.st Fri Jul 19 12:26:31 1996 +0200
+++ b/WriteStream.st Fri Jul 19 12:26:56 1996 +0200
@@ -182,83 +182,82 @@
!
nextPut:anObject
- "append the argument, anObject to the stream"
+ "append the argument, anObject to the stream.
+ Special tuned for appending to String, ByteArray and Array streams."
%{ /* NOCONTEXT */
REGISTER int pos;
unsigned ch;
OBJ coll;
- OBJ p, l;
+ OBJ p, l, rL;
+ int __readLimit = -1;
coll = __INST(collection);
p = __INST(position);
if (__isNonNilObject(coll) && __isSmallInteger(p)) {
+ pos = __intVal(p);
+ l = __INST(writeLimit);
- pos = __intVal(p);
- l = __INST(writeLimit);
+ if ((l == nil)
+ || (__isSmallInteger(l) && (pos <= __intVal(l)))) {
+ OBJ cls;
- if ((l == nil)
- || (__isSmallInteger(l) && (pos <= __intVal(l)))) {
- OBJ cls;
+ cls = __qClass(coll);
- cls = __qClass(coll);
+ rL = __INST(readLimit);
+ if (__isSmallInteger(rL)) {
+ __readLimit = __intVal(rL);
+ }
- if (cls == @global(String)) {
- if (__isCharacter(anObject)
- && (pos <= __stringSize(coll))) {
- ch = __intVal(_characterVal(anObject));
- if ((ch >= 0) && (ch <= 255)) {
- __StringInstPtr(coll)->s_element[pos-1] = ch;
- __INST(position) = __MKSMALLINT(pos + 1);
- if (__isSmallInteger(__INST(readLimit))
- && (pos >= __intVal(__INST(readLimit)))) {
- __INST(readLimit) = __MKSMALLINT(pos);
- }
- RETURN ( anObject );
- }
- }
- } else {
- if (cls == @global(ByteArray)) {
- if (__isSmallInteger(anObject)
- && ((ch = __intVal(anObject)) >= 0)
- && (ch <= 255)
- && (pos <= _byteArraySize(coll))) {
- __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
- __INST(position) = __MKSMALLINT(pos + 1);
- if (__isSmallInteger(__INST(readLimit))
- && (pos >= __intVal(__INST(readLimit)))) {
- __INST(readLimit) = __MKSMALLINT(pos);
- }
- RETURN ( anObject );
- }
- } else {
- if (cls == @global(Array)) {
- if (pos <= _arraySize(coll)) {
- __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
- __STORE(coll, anObject);
- __INST(position) = __MKSMALLINT(pos + 1);
- if (__isSmallInteger(__INST(readLimit))
- && (pos >= __intVal(__INST(readLimit)))) {
- __INST(readLimit) = __MKSMALLINT(pos);
- }
- RETURN ( anObject );
- }
- }
- }
- }
- }
+ if (cls == @global(String)) {
+ if (__isCharacter(anObject)
+ && (pos <= __stringSize(coll))) {
+ ch = __intVal(_characterVal(anObject));
+ if ((ch >= 0) && (ch <= 255)) {
+ __StringInstPtr(coll)->s_element[pos-1] = ch;
+ __INST(position) = __MKSMALLINT(pos + 1);
+ if ((__readLimit >= 0) && (pos >= __readLimit)) {
+ __INST(readLimit) = __MKSMALLINT(pos);
+ }
+ RETURN ( anObject );
+ }
+ }
+ } else if (cls == @global(ByteArray)) {
+ if (__isSmallInteger(anObject)
+ && ((ch = __intVal(anObject)) >= 0)
+ && (ch <= 255)
+ && (pos <= _byteArraySize(coll))) {
+ __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
+ __INST(position) = __MKSMALLINT(pos + 1);
+ if ((__readLimit >= 0) && (pos >= __readLimit)) {
+ __INST(readLimit) = __MKSMALLINT(pos);
+ }
+ RETURN ( anObject );
+ }
+ } else if (cls == @global(Array)) {
+ if (pos <= _arraySize(coll)) {
+ __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
+ __STORE(coll, anObject);
+ __INST(position) = __MKSMALLINT(pos + 1);
+ if ((__readLimit >= 0) && (pos >= __readLimit)) {
+ __INST(readLimit) = __MKSMALLINT(pos);
+ }
+ RETURN ( anObject );
+ }
+ }
+ }
}
%}.
(writeLimit isNil
or:[position <= writeLimit]) ifTrue:[
- (position > collection size) ifTrue:[self growCollection].
- collection at:position put:anObject.
- (position > readLimit) ifTrue:[readLimit := position].
- position := position + 1.
+ (position > collection size) ifTrue:[self growCollection].
+ collection at:position put:anObject.
+ (position > readLimit) ifTrue:[readLimit := position].
+ position := position + 1.
] ifFalse:[
- WriteErrorSignal raiseErrorString:'write behond writeLimit'
+ WriteErrorSignal raiseErrorString:'write behond writeLimit'
].
^anObject
!
@@ -340,5 +339,5 @@
!WriteStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.30 1996-07-12 08:31:59 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.31 1996-07-19 10:26:56 cg Exp $'
! !