PositionableStream.st
author Claus Gittinger <cg@exept.de>
Sat, 09 Dec 1995 15:57:29 +0100
changeset 718 6f8222ff2ff0
parent 701 a309e3ef7faf
child 759 908363ce8a32
permissions -rw-r--r--
extra entry to store a chunk without appending a chunk-separator
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    13
PeekableStream subclass:#PositionableStream
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    14
	 instanceVariableNames:'collection position readLimit writeLimit'
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    15
	 classVariableNames:'ErrorDuringFileInSignal ChunkSeparator'
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    16
	 poolDictionaries:''
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    17
	 category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    20
!PositionableStream class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    21
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    25
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
!
10
claus
parents: 5
diff changeset
    35
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
    Instances of PositionableStream allow positioning the read pointer.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
    The PositionableStream class also adds methods for source-chunk reading
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    and writing, and for filing-in/out of source code.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    This is an abstract class.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    44
10
claus
parents: 5
diff changeset
    45
!PositionableStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    46
10
claus
parents: 5
diff changeset
    47
initialize
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
    48
    "setup the signal used to handle errors during fileIn"
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
    49
10
claus
parents: 5
diff changeset
    50
    ErrorDuringFileInSignal isNil ifTrue:[
302
1f76060d58a4 *** empty log message ***
claus
parents: 283
diff changeset
    51
	ErrorDuringFileInSignal := ErrorSignal newSignalMayProceed:true.
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    52
	ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    53
	ErrorDuringFileInSignal notifierString:'error during fileIn'.
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
    54
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
    55
	ChunkSeparator := $!!
10
claus
parents: 5
diff changeset
    56
    ]
claus
parents: 5
diff changeset
    57
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    58
a27a279701f8 Initial revision
claus
parents:
diff changeset
    59
!PositionableStream class methodsFor:'instance creation'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    60
a27a279701f8 Initial revision
claus
parents:
diff changeset
    61
on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
    "return a new PositionableStream streaming on aCollection"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    63
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
    ^ (self basicNew) on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
on:aCollection from:first to:last
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
    "return a new PositionableStream streaming on aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
     from first to last"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
369
claus
parents: 362
diff changeset
    71
    ^ (self basicNew) on:aCollection from:first to:last
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    72
!
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    73
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    74
with:aCollection
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    75
    "return a new PositionableStream streaming on aCollection,
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    76
     the stream is positioned to the end of the collection."
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    77
362
claus
parents: 360
diff changeset
    78
    ^ (self basicNew) with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
!PositionableStream class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    83
chunkSeparator
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
    "return the chunk-separation character"
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    85
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    86
    ^ ChunkSeparator
360
claus
parents: 329
diff changeset
    87
! !
claus
parents: 329
diff changeset
    88
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
!PositionableStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    90
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
contents
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
    "return the entire contents of the stream"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
    ^ collection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
peek
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
    "look ahead for and return the next element"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    99
a27a279701f8 Initial revision
claus
parents:
diff changeset
   100
    |peekObject|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   101
a27a279701f8 Initial revision
claus
parents:
diff changeset
   102
    peekObject := self next.
10
claus
parents: 5
diff changeset
   103
    self backStep.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   104
    ^ peekObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   106
a27a279701f8 Initial revision
claus
parents:
diff changeset
   107
peekFor:something
10
claus
parents: 5
diff changeset
   108
    "return true and move past if next == something; 
claus
parents: 5
diff changeset
   109
     otherwise stay and let position unchanged"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   110
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
    self next == something ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   112
	^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
    ].
10
claus
parents: 5
diff changeset
   114
    self backStep.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   115
    ^ false
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   117
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
readLimit:aNumber
369
claus
parents: 362
diff changeset
   119
    "set the read-limit; thats the position at which EOF is returned"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   120
a27a279701f8 Initial revision
claus
parents:
diff changeset
   121
    readLimit := aNumber
369
claus
parents: 362
diff changeset
   122
!
claus
parents: 362
diff changeset
   123
claus
parents: 362
diff changeset
   124
writeLimit:aNumber
claus
parents: 362
diff changeset
   125
    "set the writeLimit; thats the position after which writing is prohibited"
claus
parents: 362
diff changeset
   126
claus
parents: 362
diff changeset
   127
    writeLimit := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   130
!PositionableStream methodsFor:'chunk input/output'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
a27a279701f8 Initial revision
claus
parents:
diff changeset
   132
nextChunk
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
    "return the next chunk, i.e. all characters up to the next
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   134
     exclamation mark. Within the chunk, exclamation marks have to be doubled,
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   135
     they are undoubled here.
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   136
     Except for primitive code, in which doubling is not needed (allowed).
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   137
     This exception was added to make it easier to edit primitive code with 
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   138
     external editors. However, this means, that other Smalltalks cannot always 
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   139
     read chunks containing primitive code 
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   140
     - but that doesnt really matter, since C-primitives are an ST/X feature anyway."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   141
a27a279701f8 Initial revision
claus
parents:
diff changeset
   142
    |theString sep newString done thisChar nextChar inPrimitive
a27a279701f8 Initial revision
claus
parents:
diff changeset
   143
     index    "{ Class:SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
     currSize "{ Class:SmallInteger }" |
a27a279701f8 Initial revision
claus
parents:
diff changeset
   145
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   146
    sep := ChunkSeparator.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   147
    theString := String new:500.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   148
    currSize := 500.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   149
    thisChar := self skipSeparators.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   150
    thisChar := self next.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   151
    index := 0.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
    done := false.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
    inPrimitive := false.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
    [done] whileFalse:[
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   156
	((index + 2) <= currSize) ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   157
	    newString := String new:(currSize * 2).
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   158
	    newString replaceFrom:1 to:currSize with:theString.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   159
	    currSize := currSize * 2.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   160
	    theString := newString
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   161
	].
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   162
	thisChar isNil ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   163
	    done := true
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   164
	] ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   165
	    (thisChar == $% ) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   166
		nextChar := self peek.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   167
		(nextChar == ${ ) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   168
		    inPrimitive := true.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   169
		    index := index + 1.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   170
		    theString at:index put:thisChar.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   171
		    thisChar := self next
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   172
		] ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   173
		    (nextChar == $} ) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   174
			inPrimitive := false.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   175
			index := index + 1.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   176
			theString at:index put:thisChar.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   177
			thisChar := self next
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   178
		    ]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   179
		]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   180
	    ] ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   181
		inPrimitive ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   182
		    (thisChar == sep) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   183
			(self peek == sep) ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   184
			    done := true
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   185
			] ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   186
			    self next
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   187
			]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   188
		    ]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   189
		]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   190
	    ]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   191
	].
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   192
	done ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   193
	    index := index + 1.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   194
	    theString at:index put:thisChar.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   195
	    thisChar := self next
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   196
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   197
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   198
    (index == 0) ifTrue:[^ ''].
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
   199
    ^ theString copyTo:index
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   200
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   201
a27a279701f8 Initial revision
claus
parents:
diff changeset
   202
nextChunkPut:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   203
    "put aString as a chunk onto the receiver;
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   204
     double all exclamation marks except within primitives and append a 
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   205
     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
   206
     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
   207
     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
   208
     or other editors.
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   209
     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
   210
     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
   211
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   212
    self nextPutAllAsChunk:aString.
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   213
    self nextPut:ChunkSeparator
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
    "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
   216
!
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
nextPutAllAsChunk:aString
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   219
    "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
   220
     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
   221
     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
   222
     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
   223
     or other editors.
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   224
     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
   225
     and code containing ST/X primitives cannot be loaded into other smalltalks anyway."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   226
517
c8fae50c2cc5 fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents: 432
diff changeset
   227
    |sep stopChars inPrimitive character
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   228
     index    "{ Class:SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   229
     endIndex "{ Class:SmallInteger }"
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   230
     stop     "{ Class:SmallInteger }"
253
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   231
     next     "{ Class:SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   233
    sep := ChunkSeparator.
517
c8fae50c2cc5 fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents: 432
diff changeset
   234
    stopChars := '{}' copyWith:sep.
c8fae50c2cc5 fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents: 432
diff changeset
   235
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
    inPrimitive := false.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   237
    index := 1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   238
    endIndex := aString size.
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   239
    stop := endIndex + 1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   240
a27a279701f8 Initial revision
claus
parents:
diff changeset
   241
    [index <= endIndex] whileTrue:[
718
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   242
        "
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   243
         find position of next interresting character; 
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   244
         output stuff up to that one in one piece
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   245
        "
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   246
        next := aString indexOfAny:stopChars startingAt:index ifAbsent:stop.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   247
718
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   248
        ((index == 1) and:[next == stop]) ifTrue:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   249
            self nextPutAll:aString
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   250
        ] ifFalse:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   251
            self nextPutAll:aString startingAt:index to:(next - 1)
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   252
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   253
718
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   254
        index := next.
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   255
        (index <= endIndex) ifTrue:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   256
            character := aString at:index.
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   257
718
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   258
            (character == ${ ) ifTrue:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   259
                "/ starts a primitive
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   260
                ((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   261
                    inPrimitive := true
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   262
                ]
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   263
            ] ifFalse:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   264
                "/ ends a primitive
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   265
                (character == $} ) ifTrue:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   266
                    ((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   267
                        inPrimitive := false
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   268
                    ]
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   269
                ] ifFalse:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   270
                    "/
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   271
                    "/ exclas have to be doubled - except if within a primitive
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   272
                    "/
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   273
                    inPrimitive ifFalse:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   274
                        (character == sep) ifTrue:[
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   275
                            self nextPut:sep
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   276
                        ]
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   277
                    ]
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   278
                ]
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   279
            ].
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   280
718
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   281
            self nextPut:character.
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   282
            index := index + 1
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   283
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
    ].
517
c8fae50c2cc5 fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents: 432
diff changeset
   285
718
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   286
    "Modified: 9.12.1995 / 15:56:47 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   289
nextPutChunkSeparator
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   290
    "append a chunk separator character"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   292
    self nextPut:ChunkSeparator
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
    "Created: 13.9.1995 / 17:39:26 / claus"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   295
! !
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   296
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   297
!PositionableStream methodsFor:'fileIn'!
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   298
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
askForDebug:message
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
    "launch a box asking if a debugger is wanted - used when an error
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
     occurs while filing in"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
    Smalltalk isInitialized ifFalse:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
	'error during startup: ' errorPrint. message errorPrintNL.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
	^ #debug
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
    ^ OptionBox 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
	  request:message 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   309
	  label:'Error in fileIn'
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
	  form:(WarningBox iconBitmap)
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
	  buttonLabels:#('abort' 'debug' 'continue')
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
	  values:#(#abort #debug #continue)
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
	  default:#continue.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   314
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   316
fileIn
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   317
    "file in from the receiver, i.e. read chunks and evaluate them -
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   318
     return the value of the last chunk."
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   319
283
a897d331b4c1 *** empty log message ***
claus
parents: 282
diff changeset
   320
    ^ self fileInNotifying:(SourceFileLoader on:self) passChunk:true
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   321
!
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   322
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   323
fileInNextChunkNotifying:someone
a27a279701f8 Initial revision
claus
parents:
diff changeset
   324
    "read next chunk, evaluate it and return the result;
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   325
     someone (which is usually some codeView) is notified of errors.
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   326
     Filein is done as follows:
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   327
	read a chunk
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   328
	if it started with an excla, evaluate it, and let the resulting object
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   329
	fileIn more chunks.
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   330
	This is a nice trick, since the methodsFor: expression evaluates to
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   331
	a ClassCategoryReader which reads and compiles chunks for its class.
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   332
	However, other than methodsFor expressions are possible - you can
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   333
	(in theory) create readers for any syntax.
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   334
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   335
282
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   336
    ^ self fileInNextChunkNotifying:someone passChunk:false
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   337
!
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   338
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   339
fileInNextChunkNotifying:someone passChunk:passChunk
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   340
    "read next chunk, evaluate it and return the result;
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   341
     someone (which is usually some codeView) is notified of errors.
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   342
     Filein is done as follows:
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   343
	read a chunk
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   344
	if it started with an excla, evaluate it, and let the resulting object
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   345
	fileIn more chunks.
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   346
	This is a nice trick, since the methodsFor: expression evaluates to
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   347
	a ClassCategoryReader which reads and compiles chunks for its class.
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   348
	However, other than methodsFor expressions are possible - you can
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   349
	(in theory) create readers for any syntax.
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   350
    "
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   351
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   352
    |aString sawExcla rslt done|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   353
a27a279701f8 Initial revision
claus
parents:
diff changeset
   354
    self skipSeparators.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   355
    self atEnd ifFalse:[
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   356
	sawExcla := self peekFor:ChunkSeparator.
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   357
	aString := self nextChunk.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   358
	aString size ~~ 0 ifTrue:[
282
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   359
	    passChunk ifTrue:[
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   360
		someone source:aString
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   361
	    ].
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   362
	    sawExcla ifFalse:[
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   363
		rslt := Compiler evaluate:aString notifying:someone.
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   364
	    ] ifTrue:[
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   365
		rslt := Compiler evaluate:aString notifying:someone compile:false.
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   366
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   367
		"
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   368
		 usually, the above chunk consists of some methodsFor:-expression
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   369
		 in this case, the returned value is a ClassCategoryReader,
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   370
		 which is used to load & compile the methods ...
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   371
		"
253
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   372
		rslt isNil ifTrue:[
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   373
		    "
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   374
		     however, if that was nil (i.e. some error), we skip chunks
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   375
		     up to the next empty chunk.
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   376
		    "
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   377
		    Transcript showCr:'skipping chunks ...'.
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   378
		    done := false.
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   379
		    [done] whileFalse:[
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   380
			aString := self nextChunk.
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   381
			done := (aString size == 0) or:[aString isEmpty].
253
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   382
		    ]
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   383
		] ifFalse:[
329
claus
parents: 326
diff changeset
   384
		    rslt := rslt fileInFrom:self notifying:someone  passChunk:passChunk
253
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   385
		]
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   386
	    ]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   387
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   388
    ].
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   389
    ^ rslt
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   390
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   391
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   392
fileInNotifying:someone passChunk:passChunk
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   393
    "file in from the receiver, i.e. read chunks and evaluate them -
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   394
     return the value of the last chunk.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   395
     Someone (which is usually some codeView) is notified of errors."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   396
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   397
    |lastValue|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   398
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   399
    "
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   400
     catch any errors during fileIn 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   401
     - offer debug/abort/continue choice
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   402
    "
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   403
    Object errorSignal handle:[:ex |
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   404
	|action what sender|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   405
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   406
	what := ex errorString.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   407
	what isNil ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   408
	    what := ex signal notifierString.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   409
	].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   410
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   411
	"handle the case where no GUI has been built in,
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   412
	 just abort the fileIn with a notification"
41
a14247b04d03 *** empty log message ***
claus
parents: 27
diff changeset
   413
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   414
	Display isNil ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   415
	    sender := ex suspendedContext sender.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   416
	    self notify:(what , 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   417
			 ' in ' , sender receiver class name ,
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   418
			 '>>>' , sender selector).
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   419
	    ex return
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   420
	].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   421
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   422
	"otherwise ask what should be done now and either
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   423
	 continue or abort the fileIn"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   424
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   425
	action := self askForDebug:('error in fileIn: ' , what) withCRs.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   426
	action == #continue ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   427
	    ex proceed
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   428
	].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   429
	action == #abort ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   430
	    ex return
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   431
	].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   432
"/        Debugger enter:ex suspendedContext
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   433
	(ex signal) enterDebuggerWith:ex message:what.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   434
	ex reject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   435
    ] do:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   436
	[self atEnd] whileFalse:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   437
	    lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   438
	]
180
c488255bd0be *** empty log message ***
claus
parents: 159
diff changeset
   439
    ].
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   440
    ^ lastValue
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   442
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   443
!PositionableStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   444
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   445
backStep
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   446
    "move backward read position by one"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   448
    position <= 0 ifTrue: [^ self positionError].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   449
    position := position - 1
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   450
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   451
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   452
position
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   453
    "return the read position"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   454
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   455
    ^ position
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   456
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   457
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   458
position:index
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   459
    "set the read position"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   460
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   461
    "/ FIX: allow positioning right after last element of stream
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   462
    "/ ((index > readLimit) or:[index < 0]) ifTrue: [^ self positionError].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   463
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   464
    ((index > (readLimit+1)) or:[index < 0]) ifTrue: [^ self positionError].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   465
    position := index
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   466
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   467
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   468
reset
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   469
    "set the read position to the beginning of the collection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   470
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   471
    position := "0" 1
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   472
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   473
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   474
setToEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   475
    "set the read position to the end of the collection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   476
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   477
    position := readLimit
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   478
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   479
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   480
skip:numberToSkip
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   481
    "skip the next numberToSkip elements"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   482
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   483
    self position:(position + numberToSkip)
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   484
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   485
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   486
!PositionableStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   487
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   488
contentsSpecies
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   489
    "return a class of which instances will be returned, when
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   490
     parts of the collection are asked for. 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   491
     (see upTo-kind of methods in subclasses)"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   492
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   493
    ^ collection species
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   494
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   495
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   496
on:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   497
    "setup for streaming on aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   498
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   499
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   500
    readLimit := aCollection size.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   501
    position := "0" 1
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   502
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   503
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   504
on:aCollection from:first to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   505
    "setup for streaming on aCollection from first to last"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   506
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   507
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   508
    position := first.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   509
    readLimit := last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   510
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   511
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   512
positionError
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   513
    "report an error when positioning past the end"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   514
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   515
    ^ self error:'cannot position past end of collection'
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   516
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   517
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   518
with:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   519
    "setup for streaming to the end of aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   520
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   521
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   522
    self setToEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   523
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   524
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   525
!PositionableStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   526
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   527
isPositionable
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   528
    "return true, if the stream supports positioning (this one is)"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   529
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   530
    ^ true
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   531
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   532
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   533
!PositionableStream methodsFor:'testing'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   534
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   535
atEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   536
    "return true, if the read-position is at the end"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   537
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   538
    ^ position > readLimit
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   539
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   540
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   541
isEmpty
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   542
    "return true, if the contents of the stream is empty"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   543
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   544
    ^ readLimit == 0
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   545
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   546
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   547
!PositionableStream class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   548
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   549
version
718
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   550
    ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.36 1995-12-09 14:57:29 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   551
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   552
PositionableStream initialize!