PosStream.st
changeset 159 514c749165c3
parent 93 e31220cb391f
child 180 c488255bd0be
equal deleted inserted replaced
158:be947d4e7fb2 159:514c749165c3
     1 "
     1 "
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     3               All Rights Reserved
     3 	      All Rights Reserved
     4 
     4 
     5  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
    17        category:'Streams'
    17        category:'Streams'
    18 !
    18 !
    19 
    19 
    20 PositionableStream comment:'
    20 PositionableStream comment:'
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    22               All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libbasic/Attic/PosStream.st,v 1.15 1994-08-05 00:59:23 claus Exp $
    24 $Header: /cvs/stx/stx/libbasic/Attic/PosStream.st,v 1.16 1994-10-10 00:27:25 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !PositionableStream class methodsFor:'documentation'!
    27 !PositionableStream class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    30 "
    30 "
    31  COPYRIGHT (c) 1989 by Claus Gittinger
    31  COPYRIGHT (c) 1989 by Claus Gittinger
    32               All Rights Reserved
    32 	      All Rights Reserved
    33 
    33 
    34  This software is furnished under a license and may be used
    34  This software is furnished under a license and may be used
    35  only in accordance with the terms of that license and with the
    35  only in accordance with the terms of that license and with the
    36  inclusion of the above copyright notice.   This software may not
    36  inclusion of the above copyright notice.   This software may not
    37  be provided or otherwise made available to, or used by, any
    37  be provided or otherwise made available to, or used by, any
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libbasic/Attic/PosStream.st,v 1.15 1994-08-05 00:59:23 claus Exp $
    45 $Header: /cvs/stx/stx/libbasic/Attic/PosStream.st,v 1.16 1994-10-10 00:27:25 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
    59 
    59 
    60 initialize
    60 initialize
    61     "setup the signal used to handle errors during fileIn"
    61     "setup the signal used to handle errors during fileIn"
    62 
    62 
    63     ErrorDuringFileInSignal isNil ifTrue:[
    63     ErrorDuringFileInSignal isNil ifTrue:[
    64         ErrorDuringFileInSignal := (Signal new) mayProceed:true.
    64 	Object initialize.
    65         ErrorDuringFileInSignal notifierString:'error during fileIn'.
    65 
       
    66 	ErrorDuringFileInSignal := Object errorSignal newSignalMayProceed:true.
       
    67 	ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal.
       
    68 	ErrorDuringFileInSignal notifierString:'error during fileIn'.
    66     ]
    69     ]
    67 ! !
    70 ! !
    68 
    71 
    69 !PositionableStream class methodsFor:'constants'!
    72 !PositionableStream class methodsFor:'constants'!
    70 
    73 
   148 peekFor:something
   151 peekFor:something
   149     "return true and move past if next == something; 
   152     "return true and move past if next == something; 
   150      otherwise stay and let position unchanged"
   153      otherwise stay and let position unchanged"
   151 
   154 
   152     self next == something ifTrue:[
   155     self next == something ifTrue:[
   153         ^ true
   156 	^ true
   154     ].
   157     ].
   155     self backStep.
   158     self backStep.
   156     ^ false
   159     ^ false
   157 !
   160 !
   158 
   161 
   234     index := 0.
   237     index := 0.
   235     done := false.
   238     done := false.
   236     inPrimitive := false.
   239     inPrimitive := false.
   237 
   240 
   238     [done] whileFalse:[
   241     [done] whileFalse:[
   239         ((index + 2) <= currSize) ifFalse:[
   242 	((index + 2) <= currSize) ifFalse:[
   240             newString := String new:(currSize * 2).
   243 	    newString := String new:(currSize * 2).
   241             newString replaceFrom:1 to:currSize with:theString.
   244 	    newString replaceFrom:1 to:currSize with:theString.
   242             currSize := currSize * 2.
   245 	    currSize := currSize * 2.
   243             theString := newString
   246 	    theString := newString
   244         ].
   247 	].
   245         thisChar isNil ifTrue:[
   248 	thisChar isNil ifTrue:[
   246             done := true
   249 	    done := true
   247         ] ifFalse:[
   250 	] ifFalse:[
   248             (thisChar == $% ) ifTrue:[
   251 	    (thisChar == $% ) ifTrue:[
   249                 nextChar := self peek.
   252 		nextChar := self peek.
   250                 (nextChar == ${ ) ifTrue:[
   253 		(nextChar == ${ ) ifTrue:[
   251                     inPrimitive := true.
   254 		    inPrimitive := true.
   252                     index := index + 1.
   255 		    index := index + 1.
   253                     theString at:index put:thisChar.
   256 		    theString at:index put:thisChar.
   254                     thisChar := self next
   257 		    thisChar := self next
   255                 ] ifFalse:[
   258 		] ifFalse:[
   256                     (nextChar == $} ) ifTrue:[
   259 		    (nextChar == $} ) ifTrue:[
   257                         inPrimitive := false.
   260 			inPrimitive := false.
   258                         index := index + 1.
   261 			index := index + 1.
   259                         theString at:index put:thisChar.
   262 			theString at:index put:thisChar.
   260                         thisChar := self next
   263 			thisChar := self next
   261                     ]
   264 		    ]
   262                 ]
   265 		]
   263             ] ifFalse:[
   266 	    ] ifFalse:[
   264                 inPrimitive ifFalse:[
   267 		inPrimitive ifFalse:[
   265                     (thisChar == sep) ifTrue:[
   268 		    (thisChar == sep) ifTrue:[
   266                         (self peek == sep) ifFalse:[
   269 			(self peek == sep) ifFalse:[
   267                             done := true
   270 			    done := true
   268                         ] ifTrue:[
   271 			] ifTrue:[
   269                             self next
   272 			    self next
   270                         ]
   273 			]
   271                     ]
   274 		    ]
   272                 ]
   275 		]
   273             ]
   276 	    ]
   274         ].
   277 	].
   275         done ifFalse:[
   278 	done ifFalse:[
   276             index := index + 1.
   279 	    index := index + 1.
   277             theString at:index put:thisChar.
   280 	    theString at:index put:thisChar.
   278             thisChar := self next
   281 	    thisChar := self next
   279         ]
   282 	]
   280     ].
   283     ].
   281     (index == 0) ifTrue:[^ ''].
   284     (index == 0) ifTrue:[^ ''].
   282     ^ theString copyTo:index
   285     ^ theString copyTo:index
   283 !
   286 !
   284 
   287 
   296     gotPercent := false.
   299     gotPercent := false.
   297     index := 1.
   300     index := 1.
   298     endIndex := aString size.
   301     endIndex := aString size.
   299 
   302 
   300     [index <= endIndex] whileTrue:[
   303     [index <= endIndex] whileTrue:[
   301         next := aString indexOf:$% startingAt:index ifAbsent:[endIndex + 1].
   304 	next := aString indexOf:$% startingAt:index ifAbsent:[endIndex + 1].
   302         next := next min:
   305 	next := next min:
   303                 (aString indexOf:${ startingAt:index ifAbsent:[endIndex + 1]).
   306 		(aString indexOf:${ startingAt:index ifAbsent:[endIndex + 1]).
   304         next := next min:
   307 	next := next min:
   305                 (aString indexOf:$} startingAt:index ifAbsent:[endIndex + 1]).
   308 		(aString indexOf:$} startingAt:index ifAbsent:[endIndex + 1]).
   306         next := next min:
   309 	next := next min:
   307                 (aString indexOf:sep startingAt:index ifAbsent:[endIndex + 1]).
   310 		(aString indexOf:sep startingAt:index ifAbsent:[endIndex + 1]).
   308 
   311 
   309         ((index == 1) and:[next == (endIndex + 1)]) ifTrue:[
   312 	((index == 1) and:[next == (endIndex + 1)]) ifTrue:[
   310             self nextPutAll:aString
   313 	    self nextPutAll:aString
   311         ] ifFalse:[
   314 	] ifFalse:[
   312             self nextPutAll:(aString copyFrom:index to:(next - 1))
   315 	    self nextPutAll:(aString copyFrom:index to:(next - 1))
   313         ].
   316 	].
   314 
   317 
   315         index := next.
   318 	index := next.
   316         (index <= endIndex) ifTrue:[
   319 	(index <= endIndex) ifTrue:[
   317             character := aString at:index.
   320 	    character := aString at:index.
   318             (character == $% ) ifTrue:[
   321 	    (character == $% ) ifTrue:[
   319                 gotPercent := true
   322 		gotPercent := true
   320             ] ifFalse:[
   323 	    ] ifFalse:[
   321                 (character == ${ ) ifTrue:[
   324 		(character == ${ ) ifTrue:[
   322                     gotPercent ifTrue:[
   325 		    gotPercent ifTrue:[
   323                         inPrimitive := true
   326 			inPrimitive := true
   324                     ]
   327 		    ]
   325                 ] ifFalse:[
   328 		] ifFalse:[
   326                     (character == $} ) ifTrue:[
   329 		    (character == $} ) ifTrue:[
   327                         gotPercent ifTrue:[
   330 			gotPercent ifTrue:[
   328                             inPrimitive := false
   331 			    inPrimitive := false
   329                         ]
   332 			]
   330                     ] ifFalse:[
   333 		    ] ifFalse:[
   331                         inPrimitive ifFalse:[
   334 			inPrimitive ifFalse:[
   332                             (character == sep) ifTrue:[
   335 			    (character == sep) ifTrue:[
   333                                 self nextPut:sep
   336 				self nextPut:sep
   334                             ]
   337 			    ]
   335                         ]
   338 			]
   336                     ]
   339 		    ]
   337                 ].
   340 		].
   338                 gotPercent := false
   341 		gotPercent := false
   339             ].
   342 	    ].
   340             self nextPut:character.
   343 	    self nextPut:character.
   341             index := index + 1
   344 	    index := index + 1
   342         ]
   345 	]
   343     ].
   346     ].
   344     self nextPut:sep
   347     self nextPut:sep
   345 ! !
   348 ! !
   346 
   349 
   347 !PositionableStream methodsFor:'fileIn'!
   350 !PositionableStream methodsFor:'fileIn'!
   364      return the value of the last chunk.
   367      return the value of the last chunk.
   365      Someone (which is usually some codeView) is notified of errors."
   368      Someone (which is usually some codeView) is notified of errors."
   366 
   369 
   367     |lastValue|
   370     |lastValue|
   368 
   371 
   369     SignalSet anySignal handle:[:ex |
   372     Object errorSignal handle:[:ex |
   370         |action what|
   373 	|action what|
   371 
   374 
   372         "handle the case where no GUI has been built in,
   375 	"handle the case where no GUI has been built in,
   373          just abort the fileIn with a notification"
   376 	 just abort the fileIn with a notification"
   374 
   377 
   375         Display isNil ifTrue:[
   378 	Display isNil ifTrue:[
   376             self notify:(ex signal notifierString , 
   379 	    self notify:(ex signal notifierString , 
   377                          ' in ' , ex suspendedContext sender receiver class name ,
   380 			 ' in ' , ex suspendedContext sender receiver class name ,
   378                          '>>>' , ex suspendedContext sender selector).
   381 			 '>>>' , ex suspendedContext sender selector).
   379             ex return
   382 	    ex return
   380         ].
   383 	].
   381 
   384 
   382         "otherwise ask what should be done now and either
   385 	"otherwise ask what should be done now and either
   383          continue or abort the fileIn"
   386 	 continue or abort the fileIn"
   384 
   387 
   385         what := ex errorString.
   388 	what := ex errorString.
   386         what isNil ifTrue:[
   389 	what isNil ifTrue:[
   387             what := ex signal notifierString.
   390 	    what := ex signal notifierString.
   388         ].
   391 	].
   389         action := self askForDebug:('error in fileIn: ' , what) withCRs.
   392 	action := self askForDebug:('error in fileIn: ' , what) withCRs.
   390         action == #continue ifTrue:[
   393 	action == #continue ifTrue:[
   391             ex proceed
   394 	    ex proceed
   392         ].
   395 	].
   393         action == #abort ifTrue:[
   396 	action == #abort ifTrue:[
   394             ex return
   397 	    ex return
   395         ].
   398 	].
   396         Debugger enter:ex suspendedContext
   399 	Debugger enter:ex suspendedContext
   397         "ex reject"
   400 	"ex reject"
   398     ] do:[
   401     ] do:[
   399         [self atEnd] whileFalse:[
   402 	[self atEnd] whileFalse:[
   400             lastValue := self fileInNextChunkNotifying:someone
   403 	    lastValue := self fileInNextChunkNotifying:someone
   401         ]
   404 	]
   402     ].
   405     ].
   403     ^ lastValue
   406     ^ lastValue
   404 !
   407 !
   405 
   408 
   406 fileInNextChunkNotifying:someone
   409 fileInNextChunkNotifying:someone
   407     "read next chunk, evaluate it and return the result;
   410     "read next chunk, evaluate it and return the result;
   408      someone (which is usually some codeView) is notified of errors."
   411      someone (which is usually some codeView) is notified of errors."
   409 
   412 
   410     |aString sawExcla sep|
   413     |aString sawExcla sep rslt|
   411 
   414 
   412     sep := self class chunkSeparator.
   415     sep := self class chunkSeparator.
   413     self skipSeparators.
   416     self skipSeparators.
   414     self atEnd ifFalse:[
   417     self atEnd ifFalse:[
   415         sawExcla := self peekFor:sep.
   418 	sawExcla := self peekFor:sep.
   416         aString := self nextChunk.
   419 	aString := self nextChunk.
   417         aString size ~~ 0 ifTrue:[
   420 	aString size ~~ 0 ifTrue:[
   418             sawExcla ifFalse:[
   421 	    rslt := Compiler evaluate:aString notifying:someone.
   419                 ^ Compiler evaluate:aString notifying:someone
   422 	    sawExcla ifTrue:[
   420             ].
   423 		"
   421             "
   424 		 usually, the above chunk consists of some methodsFor:-expression
   422              usually, the chunk consists of some methodsFor:-expression
   425 		 in this case, the returned value is a ClassCategoryReader,
   423              evaluate it (usually returning a ClassCategoryReader) and
   426 		 which is used to load & compile the methods ...
   424              let this reader compile the methods
   427 		"
   425             "
   428 		rslt := rslt fileInFrom:self notifying:someone
   426             ^ (Compiler evaluate:aString notifying:someone) 
   429 	    ]
   427                        fileInFrom:self notifying:someone
   430 	]
   428         ]
       
   429     ].
   431     ].
   430     ^ nil
   432     ^ rslt
   431 
   433 
   432 !
   434 !
   433 
   435 
   434 askForDebug:message
   436 askForDebug:message
   435     "launch a box asking if a debugger is wanted - used when an error
   437     "launch a box asking if a debugger is wanted - used when an error
   437 
   439 
   438     |box|
   440     |box|
   439 
   441 
   440     box := OptionBox title:message numberOfOptions:3.
   442     box := OptionBox title:message numberOfOptions:3.
   441     box actions:(Array with:[^ #abort]
   443     box actions:(Array with:[^ #abort]
   442                        with:[^ #debug]
   444 		       with:[^ #debug]
   443                        with:[^ #continue]).
   445 		       with:[^ #continue]).
   444     box buttonTitles:#('abort' 'debug' 'continue').
   446     box buttonTitles:#('abort' 'debug' 'continue').
   445     box showAtPointer.
   447     box showAtPointer.
   446     ^ #abort
   448     ^ #abort
   447 ! !
   449 ! !
   448 
   450