PositionableStream.st
author Claus Gittinger <cg@exept.de>
Tue, 16 Jun 1998 16:23:52 +0200
changeset 3592 ac5e8c09ff42
parent 3584 099a64bc9b63
child 3597 98bd336b3c3f
permissions -rw-r--r--
checkin from browser
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
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    14
	instanceVariableNames:'collection position readLimit writeLimit'
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
    15
	classVariableNames:'InvalidPositionErrorSignal ErrorDuringFileInSignal ChunkSeparator'
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    16
	poolDictionaries:''
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
    17
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    20
!PositionableStream class methodsFor:'documentation'!
88
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.
3249
8401c3e42165 checkin to force re-checkout.
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
    41
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    This is an abstract class.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
    43
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
    44
    [author:]
1998
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
    45
	Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    48
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    49
!PositionableStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    50
10
claus
parents: 5
diff changeset
    51
initialize
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
    52
    "setup the signal used to handle errors during fileIn"
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
    53
10
claus
parents: 5
diff changeset
    54
    ErrorDuringFileInSignal isNil ifTrue:[
302
1f76060d58a4 *** empty log message ***
claus
parents: 283
diff changeset
    55
	ErrorDuringFileInSignal := ErrorSignal newSignalMayProceed:true.
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    56
	ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
    57
	ErrorDuringFileInSignal notifierString:'error during fileIn'.
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
    58
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
    59
	InvalidPositionErrorSignal := PositionErrorSignal newSignalMayProceed:true.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
    60
	InvalidPositionErrorSignal nameClass:self message:#invalidPositionErrorSignal.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
    61
	InvalidPositionErrorSignal notifierString:'invalid position'.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
    62
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
    63
	ChunkSeparator := $!!
10
claus
parents: 5
diff changeset
    64
    ]
claus
parents: 5
diff changeset
    65
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    67
!PositionableStream class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
    "return a new PositionableStream streaming on aCollection"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
    ^ (self basicNew) on:aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
on:aCollection from:first to:last
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
    "return a new PositionableStream streaming on aCollection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
     from first to last"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
369
claus
parents: 362
diff changeset
    79
    ^ (self basicNew) on:aCollection from:first to:last
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    80
!
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    81
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    82
with:aCollection
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    83
    "return a new PositionableStream streaming on aCollection,
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    84
     the stream is positioned to the end of the collection."
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
    85
362
claus
parents: 360
diff changeset
    86
    ^ (self basicNew) with:aCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    89
!PositionableStream class methodsFor:'Signal constants'!
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    90
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    91
invalidPositionErrorSignal
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    92
    "return the signal raised if positioning is attempted to an
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    93
     invalid position (i.e. before the begin of the stream or after
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    94
     the end)"
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    95
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    96
    ^ InvalidPositionErrorSignal
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    97
! !
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    98
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
    99
!PositionableStream class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   100
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   101
chunkSeparator
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
    "return the chunk-separation character"
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
   103
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
    ^ ChunkSeparator
360
claus
parents: 329
diff changeset
   105
! !
claus
parents: 329
diff changeset
   106
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   107
!PositionableStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   108
a27a279701f8 Initial revision
claus
parents:
diff changeset
   109
contents
a27a279701f8 Initial revision
claus
parents:
diff changeset
   110
    "return the entire contents of the stream"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
a27a279701f8 Initial revision
claus
parents:
diff changeset
   112
    ^ collection
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   114
a27a279701f8 Initial revision
claus
parents:
diff changeset
   115
peek
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
    "look ahead for and return the next element"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   117
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
    |peekObject|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   119
a27a279701f8 Initial revision
claus
parents:
diff changeset
   120
    peekObject := self next.
10
claus
parents: 5
diff changeset
   121
    self backStep.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   122
    ^ peekObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   123
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   124
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
peekFor:something
10
claus
parents: 5
diff changeset
   126
    "return true and move past if next == something; 
claus
parents: 5
diff changeset
   127
     otherwise stay and let position unchanged"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
    self next == something ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   130
	^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
    ].
10
claus
parents: 5
diff changeset
   132
    self backStep.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
    ^ false
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
2432
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   136
peekForAll:aCollection
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   137
    "return true and advance if the next elements are the same
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   138
     as aCollection. 
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   139
     otherwise stay and let the position unchanged"
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   140
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   141
    |oldPos|
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   142
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   143
    oldPos := self position.
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   144
    (self next:(aCollection size)) = aCollection ifTrue:[
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   145
        ^ true
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   146
    ].
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   147
    self position:oldPos.
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   148
    ^ false
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   149
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   150
    "Created: 1.3.1997 / 15:11:25 / cg"
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   151
!
5338f9b60a66 added #peekForAll:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   152
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
readLimit:aNumber
369
claus
parents: 362
diff changeset
   154
    "set the read-limit; thats the position at which EOF is returned"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
a27a279701f8 Initial revision
claus
parents:
diff changeset
   156
    readLimit := aNumber
369
claus
parents: 362
diff changeset
   157
!
claus
parents: 362
diff changeset
   158
claus
parents: 362
diff changeset
   159
writeLimit:aNumber
claus
parents: 362
diff changeset
   160
    "set the writeLimit; thats the position after which writing is prohibited"
claus
parents: 362
diff changeset
   161
claus
parents: 362
diff changeset
   162
    writeLimit := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   164
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   165
!PositionableStream methodsFor:'chunk input/output'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
nextChunk
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
    "return the next chunk, i.e. all characters up to the next
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   169
     exclamation mark. Within the chunk, exclamation marks have to be doubled,
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   170
     they are undoubled here.
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   171
     Except for primitive code, in which doubling is not needed (allowed).
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   172
     This exception was added to make it easier to edit primitive code with 
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   173
     external editors. However, this means, that other Smalltalks cannot always 
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   174
     read chunks containing primitive code 
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   175
     - but that doesnt really matter, since C-primitives are an ST/X feature anyway."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
a27a279701f8 Initial revision
claus
parents:
diff changeset
   177
    |theString sep newString done thisChar nextChar inPrimitive
a27a279701f8 Initial revision
claus
parents:
diff changeset
   178
     index    "{ Class:SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   179
     currSize "{ Class:SmallInteger }" |
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   181
    sep := ChunkSeparator.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
    theString := String new:500.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   183
    currSize := 500.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
    thisChar := self skipSeparators.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   185
    thisChar := self next.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   186
    index := 0.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   187
    done := false.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   188
    inPrimitive := false.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
a27a279701f8 Initial revision
claus
parents:
diff changeset
   190
    [done] whileFalse:[
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   191
	((index + 2) <= currSize) ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   192
	    newString := String new:(currSize * 2).
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   193
	    newString replaceFrom:1 to:currSize with:theString.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   194
	    currSize := currSize * 2.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   195
	    theString := newString
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   196
	].
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   197
	thisChar isNil ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   198
	    done := true
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   199
	] ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   200
	    (thisChar == $% ) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   201
		nextChar := self peek.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   202
		(nextChar == ${ ) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   203
		    inPrimitive := true.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   204
		    index := index + 1.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   205
		    theString at:index put:thisChar.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   206
		    thisChar := self next
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   207
		] ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   208
		    (nextChar == $} ) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   209
			inPrimitive := false.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   210
			index := index + 1.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   211
			theString at:index put:thisChar.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   212
			thisChar := self next
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   213
		    ]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   214
		]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   215
	    ] ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   216
		inPrimitive ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   217
		    (thisChar == sep) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   218
			(self peek == sep) ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   219
			    done := true
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   220
			] ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   221
			    self next
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   222
			]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   223
		    ]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   224
		]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   225
	    ]
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   226
	].
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   227
	done ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   228
	    index := index + 1.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   229
	    theString at:index put:thisChar.
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   230
	    thisChar := self next
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   231
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   233
    (index == 0) ifTrue:[^ ''].
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
   234
    ^ theString copyTo:index
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   235
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
a27a279701f8 Initial revision
claus
parents:
diff changeset
   237
nextChunkPut:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   238
    "put aString as a chunk onto the receiver;
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   239
     double all exclamation marks except within primitives and append a 
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   240
     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
   241
     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
   242
     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
   243
     or other editors.
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   244
     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
   245
     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
   246
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   247
    self nextPutAllAsChunk:aString.
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   248
    self nextPut:ChunkSeparator
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   249
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   250
    "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
   251
!
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   252
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   253
nextPutAllAsChunk:aString
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   254
    "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
   255
     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
   256
     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
   257
     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
   258
     or other editors.
6f8222ff2ff0 extra entry to store a chunk without appending a chunk-separator
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   259
     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
   260
     and code containing ST/X primitives cannot be loaded into other smalltalks anyway."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   261
517
c8fae50c2cc5 fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents: 432
diff changeset
   262
    |sep stopChars inPrimitive character
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
     index    "{ Class:SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
     endIndex "{ Class:SmallInteger }"
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   265
     stop     "{ Class:SmallInteger }"
253
30daee717a53 *** empty log message ***
claus
parents: 217
diff changeset
   266
     next     "{ Class:SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
3386
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   268
    endIndex := aString size.
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   269
    endIndex == 0 ifTrue:[^ self].
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   270
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   271
    sep := ChunkSeparator.
517
c8fae50c2cc5 fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents: 432
diff changeset
   272
    stopChars := '{}' copyWith:sep.
c8fae50c2cc5 fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents: 432
diff changeset
   273
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
    inPrimitive := false.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
    index := 1.
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
   276
    stop := endIndex + 1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
    [index <= endIndex] whileTrue:[
3386
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   279
        "
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   280
         find position of next interesting character; 
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   281
         output stuff up to that one in one piece
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   282
        "
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   283
        next := aString indexOfAny:stopChars startingAt:index ifAbsent:stop.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
3386
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   285
        ((index == 1) and:[next == stop]) ifTrue:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   286
            self nextPutAll:aString
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   287
        ] ifFalse:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   288
            self nextPutAll:aString startingAt:index to:(next - 1)
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   289
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   290
3386
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   291
        index := next.
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   292
        (index <= endIndex) ifTrue:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   293
            character := aString at:index.
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   294
3386
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   295
            (character == ${ ) ifTrue:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   296
                "/ starts a primitive
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   297
                ((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   298
                    inPrimitive := true
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   299
                ]
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   300
            ] ifFalse:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   301
                "/ ends a primitive
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   302
                (character == $} ) ifTrue:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   303
                    ((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   304
                        inPrimitive := false
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   305
                    ]
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   306
                ] ifFalse:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   307
                    "/
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   308
                    "/ exclas have to be doubled - except if within a primitive
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   309
                    "/
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   310
                    inPrimitive ifFalse:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   311
                        (character == sep) ifTrue:[
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   312
                            self nextPut:sep
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   313
                        ]
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   314
                    ]
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   315
                ]
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   316
            ].
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   317
3386
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   318
            self nextPut:character.
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   319
            index := index + 1
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   320
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   321
    ].
517
c8fae50c2cc5 fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents: 432
diff changeset
   322
3386
735c8e814726 quicker empty chunk-putting
Claus Gittinger <cg@exept.de>
parents: 3249
diff changeset
   323
    "Modified: / 21.4.1998 / 17:22:47 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   325
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
nextPutChunkSeparator
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   327
    "append a chunk separator character"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   329
    self nextPut:ChunkSeparator
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   331
    "Created: 13.9.1995 / 17:39:26 / claus"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   332
! !
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   333
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   334
!PositionableStream methodsFor:'fileIn'!
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   335
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
askForDebug:message
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
    "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
   338
     occurs while filing in"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
    Smalltalk isInitialized ifFalse:[
2130
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   341
        'PositionableStream [warning]: fileIn error during startup: ' errorPrint. message errorPrintCR.
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   342
        ^ #debug
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   343
    ].
875
2bb6fea4cb55 dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   344
    "/
2bb6fea4cb55 dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   345
    "/ 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
   346
    "/
2bb6fea4cb55 dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   347
    Processor activeProcessIsSystemProcess ifTrue:[
2130
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   348
        'PositionableStream [warning]: fileIn error during startup: ' errorPrint. message errorPrintCR.
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   349
        ^ #continue
875
2bb6fea4cb55 dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   350
    ].
2bb6fea4cb55 dont launch box when fileIn errors occur during startup
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   351
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   352
    ^ OptionBox 
2130
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   353
          request:message 
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   354
          label:'Error in fileIn'
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   355
          form:(WarningBox iconBitmap)
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   356
          buttonLabels:#('cancel' 'debug' 'continue')
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   357
          values:#(#abort #debug #continue)
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   358
          default:#continue.
975
716245c81bc0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
   359
2130
b9e7e1cf98bd newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2005
diff changeset
   360
    "Modified: 10.1.1997 / 18:00:56 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   361
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   362
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   363
fileIn
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   364
    "file in from the receiver, i.e. read chunks and evaluate them -
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   365
     return the value of the last chunk."
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   366
283
a897d331b4c1 *** empty log message ***
claus
parents: 282
diff changeset
   367
    ^ self fileInNotifying:(SourceFileLoader on:self) passChunk:true
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   368
!
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   369
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   370
fileInNextChunkNotifying:someone
a27a279701f8 Initial revision
claus
parents:
diff changeset
   371
    "read next chunk, evaluate it and return the result;
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   372
     someone (which is usually some codeView) is notified of errors.
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   373
     Filein is done as follows:
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   374
	read a chunk
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   375
	if it started with an excla, evaluate it, and let the resulting object
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   376
	fileIn more chunks.
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   377
	This is a nice trick, since the methodsFor: expression evaluates to
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   378
	a ClassCategoryReader which reads and compiles chunks for its class.
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   379
	However, other than methodsFor expressions are possible - you can
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   380
	(in theory) create readers for any syntax.
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   381
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   382
282
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   383
    ^ self fileInNextChunkNotifying:someone passChunk:false
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   384
!
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   385
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   386
fileInNextChunkNotifying:someone passChunk:passChunk
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   387
    "read next chunk, evaluate it and return the result;
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   388
     someone (which is usually some codeView) is notified of errors.
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   389
     Filein is done as follows:
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   390
        read a chunk
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   391
        if it started with an excla, evaluate it, and let the resulting object
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   392
        fileIn more chunks.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   393
        This is a nice trick, since the methodsFor: expression evaluates to
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   394
        a ClassCategoryReader which reads and compiles chunks for its class.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   395
        However, other than methodsFor expressions are possible - you can
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   396
        (in theory) create readers for any syntax.
282
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   397
    "
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   398
276
3b6d97620494 *** empty log message ***
claus
parents: 253
diff changeset
   399
    |aString sawExcla rslt done|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   400
a27a279701f8 Initial revision
claus
parents:
diff changeset
   401
    self skipSeparators.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   402
    self atEnd ifFalse:[
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   403
        sawExcla := self peekFor:ChunkSeparator.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   404
        aString := self nextChunk.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   405
        "/
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   406
        "/ handle empty chunks;
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   407
        "/ this allows for Squeak code to be filedIn
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   408
        "/
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   409
        [aString size == 0
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   410
        and:[self atEnd not]] whileTrue:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   411
            aString := self nextChunk.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   412
        ].
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   413
        aString size ~~ 0 ifTrue:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   414
            passChunk ifTrue:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   415
                someone source:aString
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   416
            ].
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   417
            sawExcla ifFalse:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   418
                rslt := Smalltalk::Compiler evaluate:aString notifying:someone.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   419
            ] ifTrue:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   420
                Smalltalk::Compiler emptySourceNotificationSignal handle:[:ex |
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   421
                    ^ nil
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   422
                ] do:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   423
                    rslt := Smalltalk::Compiler evaluate:aString notifying:someone compile:false.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   424
                ].
282
94f5c3a6230d *** empty log message ***
claus
parents: 276
diff changeset
   425
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   426
                "
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   427
                 usually, the above chunk consists of some methodsFor:-expression
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   428
                 in this case, the returned value is a ClassCategoryReader,
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   429
                 which is used to load & compile the methods ...
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   430
                "
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   431
                rslt isNil ifTrue:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   432
                    "
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   433
                     however, if that was nil (i.e. some error), we skip chunks
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   434
                     up to the next empty chunk.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   435
                    "
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   436
                    Transcript showCR:'skipping chunks ...'.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   437
                    done := false.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   438
                    [done] whileFalse:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   439
                        aString := self nextChunk.
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   440
                        done := (aString size == 0) or:[aString isEmpty].
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   441
                    ]
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   442
                ] ifFalse:[
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   443
                    rslt := rslt fileInFrom:self notifying:someone passChunk:passChunk
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   444
                ]
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   445
            ]
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   446
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   447
    ].
159
514c749165c3 *** empty log message ***
claus
parents: 93
diff changeset
   448
    ^ rslt
1420
be5f8e9574cc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   449
3032
d267a0b1b48d handle empty chunks when filing in
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   450
    "Modified: 14.10.1997 / 17:10:35 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   451
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   452
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   453
fileInNotifying:someone passChunk:passChunk
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   454
    "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
   455
     return the value of the last chunk.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   456
     Someone (which is usually some codeView) is notified of errors."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   457
2893
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   458
    |lastValue pkg spc spaces
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   459
     packageQuerySignal nameSpaceQuerySignal usedNameSpaceQuerySignal
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   460
     changeDefaultApplicationNotificationSignal
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   461
     defaultApplicationQuerySignal defaultApplication
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   462
     handledSignals|
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   463
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   464
    "/ support for V'Age applications
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   465
    defaultApplicationQuerySignal := Class defaultApplicationQuerySignal.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   466
    changeDefaultApplicationNotificationSignal := Class changeDefaultApplicationNotificationSignal.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   467
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   468
    "/ support for ST/X's namespaces & packages
2343
93152bcf4101 only fetch signals once
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   469
    packageQuerySignal := Class packageQuerySignal.
93152bcf4101 only fetch signals once
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   470
    nameSpaceQuerySignal := Class nameSpaceQuerySignal.
93152bcf4101 only fetch signals once
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   471
    usedNameSpaceQuerySignal := Class usedNameSpaceQuerySignal.
93152bcf4101 only fetch signals once
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   472
2893
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   473
    (someone respondsTo:#packageToInstall) ifFalse:[
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   474
        pkg := packageQuerySignal raise.
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   475
    ] ifTrue:[
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   476
        pkg := someone packageToInstall
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   477
    ].
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   478
    (someone respondsTo:#currentNameSpace) ifFalse:[
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   479
        spc := nameSpaceQuerySignal raise.
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   480
    ] ifTrue:[
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   481
        spc := someone currentNameSpace
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   482
    ].
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   483
    (someone respondsTo:#usedNameSpaces) ifFalse:[
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   484
        spaces := usedNameSpaceQuerySignal raise.
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   485
    ] ifTrue:[
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   486
        spaces := someone usedNameSpaces
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   487
    ].
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   488
    (someone respondsTo:#defaultApplication) ifFalse:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   489
        defaultApplication := defaultApplicationQuerySignal raise.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   490
    ] ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   491
        defaultApplication := someone defaultApplication
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   492
    ].
2893
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   493
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   494
    handledSignals := SignalSet new.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   495
    handledSignals add:changeDefaultApplicationNotificationSignal.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   496
    handledSignals add:packageQuerySignal.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   497
    handledSignals add:usedNameSpaceQuerySignal.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   498
    handledSignals add:nameSpaceQuerySignal.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   499
    handledSignals add:defaultApplicationQuerySignal.
3592
ac5e8c09ff42 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   500
    handledSignals add:(Object errorSignal).
ac5e8c09ff42 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   501
    handledSignals add:(Class methodRedefinitionSignal).
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   502
    handledSignals handle:[:ex |
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   503
        |sig action what sender msg param oldPackage newPackage|
1902
52376295aca8 namespace fixes
Claus Gittinger <cg@exept.de>
parents: 1897
diff changeset
   504
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   505
        sig := ex signal.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   506
        sig == changeDefaultApplicationNotificationSignal ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   507
            "/ invoked via #becomeDefault to set the defaultApp and the package.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   508
            "/ (only when filing in V'Age code)
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   509
            defaultApplication := ex parameter.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   510
            pkg := defaultApplication name asSymbol.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   511
            ex proceed
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   512
        ].
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   513
        sig == defaultApplicationQuerySignal ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   514
            "/ query for the application to add classes & methods into
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   515
            "/ (only when filing in V'Age code)
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   516
            ex proceedWith:defaultApplication
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   517
        ].
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   518
        sig == packageQuerySignal ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   519
            "/ query for the package to use for classes & methods
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   520
            ex proceedWith:pkg
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   521
        ].
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   522
        sig == usedNameSpaceQuerySignal ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   523
            "/ query for the namespaces searched when encountering globals
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   524
            ex proceedWith:spaces
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   525
        ].
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   526
        sig == nameSpaceQuerySignal ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   527
            "/ query for the namespace to install new classes in
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   528
            ex proceedWith:spc
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   529
        ].
3592
ac5e8c09ff42 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   530
        sig == Stream endOfStreamSignal ifTrue:[
ac5e8c09ff42 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   531
            ex reject
ac5e8c09ff42 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   532
        ].
3580
47534257f9e5 avoid two queries for rejected signals.
Claus Gittinger <cg@exept.de>
parents: 3386
diff changeset
   533
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   534
        sig == Signal noHandlerSignal ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   535
            ex parameter rejected ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   536
                ex reject
3592
ac5e8c09ff42 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   537
            ].
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   538
        ].
2893
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   539
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   540
        "/ for your convenience ...
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   541
        sig == Class methodRedefinitionSignal ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   542
            param := ex parameter. "/ an association: oldMethod -> newMethod
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   543
            oldPackage := param key package.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   544
            newPackage := param value package.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   545
            msg := 'trying to overwrite method:\\    %1\\in package ''' 
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   546
                   , oldPackage , ''' with method from package ''' , newPackage , ''''
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   547
        ] ifFalse:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   548
            msg := 'error in fileIn: %1'
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   549
        ].
2893
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   550
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   551
        what := ex errorString.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   552
        what isNil ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   553
            what := ex signal notifierString.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   554
        ].
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   555
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   556
        "/ handle the case where no GUI has been built in,
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   557
        "/ just abort the fileIn with a notification
2893
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   558
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   559
        Display isNil ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   560
            sender := ex suspendedContext sender.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   561
            self notify:(what , 
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   562
                         ' in ' , sender receiver class name ,
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   563
                         '>>>' , sender selector).
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   564
            ex return
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   565
        ].
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   566
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   567
        msg := msg bindWith:what.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   568
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   569
        sig == Object haltSignal ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   570
            sender := ex suspendedContext.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   571
            msg := msg , ('\\in ' , sender receiver class name , '>>>' , sender selector) withCRs
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   572
        ].
2893
8ba406da6b22 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2559
diff changeset
   573
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   574
        "/ otherwise ask what should be done now and either
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   575
        "/ continue or abort the fileIn
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   576
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   577
        action := self askForDebug:msg withCRs.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   578
        action == #continue ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   579
            ex proceed
2005
d77ecd466b5b handle usedNameSpaces request
Claus Gittinger <cg@exept.de>
parents: 1999
diff changeset
   580
        ].
3584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   581
        action == #abort ifTrue:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   582
            ex return
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   583
        ].
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   584
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   585
        "/ (ex signal) enterDebuggerWith:ex message:what.
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   586
        ex reject
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   587
    ] do:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   588
        [self atEnd] whileFalse:[
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   589
            lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk
099a64bc9b63 support for V'Age fileIn (application stuff)
Claus Gittinger <cg@exept.de>
parents: 3580
diff changeset
   590
        ]
180
c488255bd0be *** empty log message ***
claus
parents: 159
diff changeset
   591
    ].
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   592
    ^ lastValue
973
5bb2473bf1ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
   593
3592
ac5e8c09ff42 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   594
    "Modified: / 16.6.1998 / 16:16:46 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   595
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   596
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   597
!PositionableStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   598
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   599
backStep
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   600
    "move backward read position by one"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   601
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   602
    position <= 0 ifTrue: [^ self positionError].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   603
    position := position - 1
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   604
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   605
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   606
position
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   607
    "return the read position"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   608
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   609
    ^ position
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   610
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   612
position:index
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   613
    "set the read position"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   614
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   615
    "/ FIX: allow positioning right after last element of stream
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   616
    "/ ((index > readLimit) or:[index < 0]) ifTrue: [^ self positionError].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   617
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   618
    ((index > (readLimit+1)) or:[index < 0]) ifTrue: [^ self positionError].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   619
    position := index
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   620
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   621
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   622
reset
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   623
    "set the read position to the beginning of the collection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   624
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   625
    position := "0" 1
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   626
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   627
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   628
setToEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   629
    "set the read position to the end of the collection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   630
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   631
    position := readLimit
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   632
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   633
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   634
skip:numberToSkip
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   635
    "skip the next numberToSkip elements"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   636
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   637
    self position:(position + numberToSkip)
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   638
!
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   639
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   640
skipThroughAll:aCollection
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   641
    "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
   642
     return nil if not found, self otherwise. 
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   643
     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
   644
     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
   645
     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
   646
2154
89e96599e1e2 skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2153
diff changeset
   647
    |buffer l first idx|
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   648
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   649
    l := aCollection size.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   650
    first := aCollection at:1.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   651
    [self atEnd] whileFalse:[
2153
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   652
        buffer := self nextAvailable:l.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   653
        buffer = aCollection ifTrue:[
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   654
            ^ self
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   655
        ].
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   656
        idx := buffer indexOf:first startingAt:2.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   657
        idx == 0 ifFalse:[
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   658
            self position:(self position - l + idx - 1)
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   659
        ]
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   660
    ].
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   661
    ^ nil
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   662
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   663
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   664
     |s|
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   665
     s := ReadStream on:'12345678901234567890'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   666
     s skipThroughAll:'901'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   667
     s upToEnd  
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   668
    "
2153
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   669
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   670
     |s|
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   671
     s := ReadStream on:'12345678901234567890'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   672
     s skipThroughAll:'1234'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   673
     s upToEnd  
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   674
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   675
    "
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   676
     |s|
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   677
     s := ReadStream on:'12345678901234567890'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   678
     s skipThroughAll:'999'.
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   679
     s atEnd  
244e36cbbd9b skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   680
    "
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   681
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   682
    "Created: 26.6.1996 / 09:35:35 / cg"
2154
89e96599e1e2 skipThroughAll: does not need the old position
Claus Gittinger <cg@exept.de>
parents: 2153
diff changeset
   683
    "Modified: 11.1.1997 / 19:16:38 / cg"
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   684
!
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   685
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   686
skipToAll:aCollection
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   687
    "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
   688
     return nil if not found, self otherwise. 
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   689
     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
   690
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   691
    |oldPos buffer l first idx|
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   692
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   693
    oldPos := self position.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   694
    l := aCollection size.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   695
    first := aCollection at:1.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   696
    [self atEnd] whileFalse:[
1998
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   697
	buffer := self next:l.
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   698
	buffer = aCollection ifTrue:[
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   699
	    self position:(self position - l).
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   700
	    ^ self
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   701
	].
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   702
	idx := buffer indexOf:first startingAt:2.
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   703
	idx == 0 ifFalse:[
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   704
	    self position:(self position - l + idx - 1)
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   705
	]
1489
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   706
    ].
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   707
    self position:oldPos.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   708
    ^ nil
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   709
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   710
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   711
     |s|
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   712
     s := ReadStream on:'12345678901234567890'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   713
     s skipToAll:'901'.
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   714
     s upToEnd  
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   715
    "
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   716
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   717
    "Modified: 26.6.1996 / 09:28:27 / cg"
9e3b166483fb moved some skip methods from readStream;
Claus Gittinger <cg@exept.de>
parents: 1420
diff changeset
   718
    "Created: 26.6.1996 / 09:35:06 / cg"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   719
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   720
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   721
!PositionableStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   722
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   723
contentsSpecies
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   724
    "return a class of which instances will be returned, when
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   725
     parts of the collection are asked for. 
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   726
     (see upTo-kind of methods in subclasses)"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   727
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   728
    ^ collection species
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   729
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   730
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   731
on:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   732
    "setup for streaming on aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   733
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   734
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   735
    readLimit := aCollection size.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   736
    position := "0" 1
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   737
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   738
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   739
on:aCollection from:first to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   740
    "setup for streaming on aCollection from first to last"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   741
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   742
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   743
    position := first.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   744
    readLimit := last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   745
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   746
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   747
positionError
1998
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   748
    "{ Pragma: +optSpace }"
9749a5f87238 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1929
diff changeset
   749
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   750
    "report an error when positioning past the end
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   751
     or before the beginning."
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   752
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
   753
    ^ InvalidPositionErrorSignal raiseIn:thisContext sender
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   754
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   755
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   756
with:aCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   757
    "setup for streaming to the end of aCollection"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   758
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   759
    collection := aCollection.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   760
    self setToEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   761
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   762
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   763
!PositionableStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   764
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   765
isPositionable
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   766
    "return true, if the stream supports positioning (this one is)"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   767
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   768
    ^ true
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   769
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   770
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   771
!PositionableStream methodsFor:'reading'!
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   772
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   773
upToAll:aCollection
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   774
    "read until a subcollection consisisting of the elements in aCollection
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   775
     is encountered.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   776
     Return everything read excluding the elements in aCollection.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   777
     The position is left before the collection; i.e. the next
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   778
     read operations will return those elements.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   779
     If no such subcollection is encountered, all elements up to the end 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   780
     are read and returned.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   781
     Compare this with #throughAll: which also reads up to some objects
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   782
     but positions behind it and DOES include it in the returned
3184
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   783
     collection.
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   784
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   785
     Note: this behavior is inconsistent with the other upTo.. methods,
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   786
           which position after the found item. We implement the method
d99302322139 Ok, #upToAll: positions after the collection.
Stefan Vogel <sv@exept.de>
parents: 3170
diff changeset
   787
           this way for the sake of ST80-compatibility."
3170
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   788
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   789
    |answerStream element last rslt|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   790
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   791
    last := aCollection last.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   792
    answerStream := WriteStream on:(self contentsSpecies new).
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   793
    [self atEnd] whileFalse:[
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   794
        element := self next.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   795
        answerStream nextPut:element.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   796
        element == last ifTrue:[
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   797
            ((rslt := answerStream contents) endsWith:aCollection) ifTrue:[
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   798
                self position:(self position - aCollection size).
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   799
                ^ rslt copyWithoutLast:aCollection size
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   800
            ]
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   801
        ].
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   802
    ].
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   803
    ^ answerStream contents
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   804
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   805
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   806
     |s|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   807
     s := ReadStream on:'hello world'.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   808
     Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   809
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   810
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   811
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   812
     |s|
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   813
     s := ReadStream on:'hello world'.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   814
     Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   815
     Transcript showCR:s atEnd.
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   816
     Transcript show:'<'; show:(s upToEnd); showCR:'>'. 
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   817
    "
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   818
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   819
    "Modified: / 12.1.1998 / 22:06:42 / cg"
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   820
    "Created: / 12.1.1998 / 22:07:01 / cg"
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   821
! !
7b299d83c45a moved upToAll: to positionableStream.
Claus Gittinger <cg@exept.de>
parents: 3032
diff changeset
   822
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   823
!PositionableStream methodsFor:'testing'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   824
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   825
atEnd
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   826
    "return true, if the read-position is at the end"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   827
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   828
    ^ position > readLimit
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   829
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   830
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   831
isEmpty
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   832
    "return true, if the contents of the stream is empty"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   833
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   834
    ^ readLimit == 0
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   835
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   836
1897
22d1ce9b62a4 fixes for packageQuery
Claus Gittinger <cg@exept.de>
parents: 1489
diff changeset
   837
!PositionableStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   838
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   839
version
3592
ac5e8c09ff42 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3584
diff changeset
   840
    ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.66 1998-06-16 14:23:52 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   841
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   842
PositionableStream initialize!