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