PositionableStream.st
changeset 7092 630807cd320f
parent 7054 685d359f9847
child 7114 acc13967229e
equal deleted inserted replaced
7091:b399f3d19084 7092:630807cd320f
    67 initialize
    67 initialize
    68     "setup the signal used to handle errors during fileIn"
    68     "setup the signal used to handle errors during fileIn"
    69 
    69 
    70     ZeroPosition := 1.
    70     ZeroPosition := 1.
    71     ErrorDuringFileInSignal isNil ifTrue:[
    71     ErrorDuringFileInSignal isNil ifTrue:[
    72 	ErrorDuringFileInSignal := ErrorSignal newSignalMayProceed:true.
    72         ErrorDuringFileInSignal := Error newSignalMayProceed:true.
    73 	ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal.
    73         ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal.
    74 	ErrorDuringFileInSignal notifierString:'error during fileIn'.
    74         ErrorDuringFileInSignal notifierString:'error during fileIn'.
    75 
    75 
    76 "/        InvalidPositionErrorSignal := PositionErrorSignal newSignalMayProceed:true.
    76 "/        InvalidPositionErrorSignal := PositionErrorSignal newSignalMayProceed:true.
    77 "/        InvalidPositionErrorSignal nameClass:self message:#invalidPositionErrorSignal.
    77 "/        InvalidPositionErrorSignal nameClass:self message:#invalidPositionErrorSignal.
    78 	InvalidPositionErrorSignal := PositionOutOfBoundsError.
    78         InvalidPositionErrorSignal := PositionOutOfBoundsError.
    79 	InvalidPositionErrorSignal notifierString:'position out of bounds: '.
    79         InvalidPositionErrorSignal notifierString:'position out of bounds: '.
    80 
    80 
    81 	CurrentFileInDirectoryQuerySignal := QuerySignal new.
    81         CurrentFileInDirectoryQuerySignal := QuerySignal new.
    82 	CurrentFileInDirectoryQuerySignal nameClass:self message:#currentFileInDirectoryQuerySignal.
    82         CurrentFileInDirectoryQuerySignal nameClass:self message:#currentFileInDirectoryQuerySignal.
    83 	CurrentFileInDirectoryQuerySignal notifierString:'query for current directory when filing in'.
    83         CurrentFileInDirectoryQuerySignal notifierString:'query for current directory when filing in'.
    84 	CurrentFileInDirectoryQuerySignal handlerBlock:[:ex | ex proceedWith:Filename currentDirectory].
    84         CurrentFileInDirectoryQuerySignal handlerBlock:[:ex | ex proceedWith:Filename currentDirectory].
    85     ]
    85     ]
    86 ! !
    86 ! !
    87 
    87 
    88 !PositionableStream class methodsFor:'instance creation'!
    88 !PositionableStream class methodsFor:'instance creation'!
    89 
    89 
   539      dontAskSignals askSomeoneForPackage redef outerContext|
   539      dontAskSignals askSomeoneForPackage redef outerContext|
   540 
   540 
   541     self skipSeparators.
   541     self skipSeparators.
   542     lastValue := self peek.
   542     lastValue := self peek.
   543     lastValue == $< ifTrue:[
   543     lastValue == $< ifTrue:[
   544 	"/ assume, its an xml file
   544         "/ assume, its an xml file
   545 	^ self fileInXMLNotifying:someone passChunk:passChunk.
   545         ^ self fileInXMLNotifying:someone passChunk:passChunk.
   546     ].
   546     ].
   547     lastValue == $# ifTrue:[
   547     lastValue == $# ifTrue:[
   548 	"assume unix interpreter name:
   548         "assume unix interpreter name:
   549 	 '#!!stx -e' or something like this"
   549          '#!!stx -e' or something like this"
   550 	self nextPeek == $!! ifTrue:[
   550         self nextPeek == $!! ifTrue:[
   551 	    "skip the unix command line"
   551             "skip the unix command line"
   552 	    self nextLine
   552             self nextLine
   553 	] ifFalse:[
   553         ] ifFalse:[
   554 	     self error:'Invalid chunk start'
   554              self error:'Invalid chunk start'
   555 	]
   555         ]
   556     ].
   556     ].
   557 
   557 
   558     Smalltalk::Compiler isNil ifTrue:[
   558     Smalltalk::Compiler isNil ifTrue:[
   559 	self isFileStream ifTrue:[
   559         self isFileStream ifTrue:[
   560 	    Transcript show:('[' , self pathName , '] ').
   560             Transcript show:('[' , self pathName , '] ').
   561 	].
   561         ].
   562 	Transcript showCR:'cannot fileIn (no compiler).'.
   562         Transcript showCR:'cannot fileIn (no compiler).'.
   563 	^ nil.
   563         ^ nil.
   564     ].
   564     ].
   565 
   565 
   566     "/ support for V'Age applications
   566     "/ support for V'Age applications
   567     defaultApplicationQuerySignal := Class defaultApplicationQuerySignal.
   567     defaultApplicationQuerySignal := Class defaultApplicationQuerySignal.
   568     changeDefaultApplicationNotificationSignal := Class changeDefaultApplicationNotificationSignal.
   568     changeDefaultApplicationNotificationSignal := Class changeDefaultApplicationNotificationSignal.
   571     packageQuerySignal := Class packageQuerySignal.
   571     packageQuerySignal := Class packageQuerySignal.
   572     nameSpaceQuerySignal := Class nameSpaceQuerySignal.
   572     nameSpaceQuerySignal := Class nameSpaceQuerySignal.
   573     usedNameSpaceQuerySignal := Class usedNameSpaceQuerySignal.
   573     usedNameSpaceQuerySignal := Class usedNameSpaceQuerySignal.
   574 
   574 
   575     (someone respondsTo:#packageToInstall) ifFalse:[
   575     (someone respondsTo:#packageToInstall) ifFalse:[
   576 	pkg := packageQuerySignal query.
   576         pkg := packageQuerySignal query.
   577 	askSomeoneForPackage := false.
   577         askSomeoneForPackage := false.
   578     ] ifTrue:[
   578     ] ifTrue:[
   579 	pkg := someone packageToInstall.
   579         pkg := someone packageToInstall.
   580 	askSomeoneForPackage := true.
   580         askSomeoneForPackage := true.
   581     ].
   581     ].
   582     (someone respondsTo:#currentNameSpace) ifFalse:[
   582     (someone respondsTo:#currentNameSpace) ifFalse:[
   583 	spc := nameSpaceQuerySignal query.
   583         spc := nameSpaceQuerySignal query.
   584     ] ifTrue:[
   584     ] ifTrue:[
   585 	spc := someone currentNameSpace
   585         spc := someone currentNameSpace
   586     ].
   586     ].
   587     (someone respondsTo:#usedNameSpaces) ifFalse:[
   587     (someone respondsTo:#usedNameSpaces) ifFalse:[
   588 	spaces := usedNameSpaceQuerySignal query.
   588         spaces := usedNameSpaceQuerySignal query.
   589     ] ifTrue:[
   589     ] ifTrue:[
   590 	spaces := someone usedNameSpaces
   590         spaces := someone usedNameSpaces
   591     ].
   591     ].
   592     (someone respondsTo:#defaultApplication) ifFalse:[
   592     (someone respondsTo:#defaultApplication) ifFalse:[
   593 	defaultApplication := defaultApplicationQuerySignal query.
   593         defaultApplication := defaultApplicationQuerySignal query.
   594     ] ifTrue:[
   594     ] ifTrue:[
   595 	defaultApplication := someone defaultApplication
   595         defaultApplication := someone defaultApplication
   596     ].
   596     ].
   597 
   597 
   598     confirmationQuerySignal := Metaclass confirmationQuerySignal.
   598     confirmationQuerySignal := Metaclass confirmationQuerySignal.
   599 
   599 
   600     passedSignals := IdentitySet new.
   600     passedSignals := IdentitySet new.
   607 
   607 
   608     handledSignals add:packageQuerySignal.
   608     handledSignals add:packageQuerySignal.
   609     handledSignals add:usedNameSpaceQuerySignal.
   609     handledSignals add:usedNameSpaceQuerySignal.
   610     handledSignals add:nameSpaceQuerySignal.
   610     handledSignals add:nameSpaceQuerySignal.
   611 
   611 
   612     handledSignals add:(Object errorSignal).
   612     handledSignals add:Error.
   613     passedSignals add:(Object errorSignal).
   613     passedSignals add:Error.
   614 
   614 
   615     handledSignals add:(Class methodRedefinitionSignal).
   615     handledSignals add:(Class methodRedefinitionSignal).
   616     passedSignals add:(Class methodRedefinitionSignal).
   616     passedSignals add:(Class methodRedefinitionSignal).
   617     handledSignals add:(Class classRedefinitionSignal).
   617     handledSignals add:(Class classRedefinitionSignal).
   618     passedSignals add:(Class classRedefinitionSignal).
   618     passedSignals add:(Class classRedefinitionSignal).
   620     passedSignals add:confirmationQuerySignal.
   620     passedSignals add:confirmationQuerySignal.
   621 
   621 
   622     outerContext := thisContext.
   622     outerContext := thisContext.
   623 
   623 
   624     handledSignals handle:[:ex |
   624     handledSignals handle:[:ex |
   625 	|sig action what sender msg param oldPackage newPackage proceedValue
   625         |sig action what sender msg param oldPackage newPackage proceedValue
   626 	 canContinueForAll|
   626          canContinueForAll|
   627 
   627 
   628 	sig := ex signal.
   628         sig := ex signal.
   629 "/sig == packageQuerySignal ifTrue:[
   629 "/sig == packageQuerySignal ifTrue:[
   630 "/self halt.
   630 "/self halt.
   631 "/].
   631 "/].
   632 	(passedSignals includes:sig) ifTrue:[
   632         (passedSignals includes:sig) ifTrue:[
   633 	    (sig isHandledIn:outerContext) ifTrue:[
   633             (sig isHandledIn:outerContext) ifTrue:[
   634 		ex reject
   634                 ex reject
   635 	    ]
   635             ]
   636 	].
   636         ].
   637         
   637         
   638 	sig == changeDefaultApplicationNotificationSignal ifTrue:[
   638         sig == changeDefaultApplicationNotificationSignal ifTrue:[
   639 	    "/ invoked via #becomeDefault to set the defaultApp and the package.
   639             "/ invoked via #becomeDefault to set the defaultApp and the package.
   640 	    "/ (only when filing in V'Age code)
   640             "/ (only when filing in V'Age code)
   641 	    defaultApplication := ex parameter.
   641             defaultApplication := ex parameter.
   642 	    pkg := defaultApplication name asSymbol.
   642             pkg := defaultApplication name asSymbol.
   643 	    ex proceedWith:nil
   643             ex proceedWith:nil
   644 	].
   644         ].
   645 	sig == defaultApplicationQuerySignal ifTrue:[
   645         sig == defaultApplicationQuerySignal ifTrue:[
   646 	    "/ query for the application to add classes & methods into
   646             "/ query for the application to add classes & methods into
   647 	    "/ (only when filing in V'Age code)
   647             "/ (only when filing in V'Age code)
   648 	    ex proceedWith:defaultApplication
   648             ex proceedWith:defaultApplication
   649 	].
   649         ].
   650 	sig == packageQuerySignal ifTrue:[
   650         sig == packageQuerySignal ifTrue:[
   651 	    "/ query for the package to use for classes & methods
   651             "/ query for the package to use for classes & methods
   652 	    askSomeoneForPackage ifTrue:[
   652             askSomeoneForPackage ifTrue:[
   653 		ex proceedWith:someone packageToInstall
   653                 ex proceedWith:someone packageToInstall
   654 	    ] ifFalse:[
   654             ] ifFalse:[
   655 		ex proceedWith:pkg
   655                 ex proceedWith:pkg
   656 	    ]
   656             ]
   657 	].
   657         ].
   658 	sig == usedNameSpaceQuerySignal ifTrue:[
   658         sig == usedNameSpaceQuerySignal ifTrue:[
   659 	    "/ query for the namespaces searched when encountering globals
   659             "/ query for the namespaces searched when encountering globals
   660 	    ex proceedWith:spaces
   660             ex proceedWith:spaces
   661 	].
   661         ].
   662 	sig == nameSpaceQuerySignal ifTrue:[
   662         sig == nameSpaceQuerySignal ifTrue:[
   663 	    "/ query for the namespace to install new classes in
   663             "/ query for the namespace to install new classes in
   664 	    ex proceedWith:spc
   664             ex proceedWith:spc
   665 	].
   665         ].
   666 	sig == confirmationQuerySignal ifTrue:[
   666         sig == confirmationQuerySignal ifTrue:[
   667 	    ex proceedWith:false "/ no dialogs popping up
   667             ex proceedWith:false "/ no dialogs popping up
   668 	].
   668         ].
   669 
   669 
   670 	sig == Stream endOfStreamSignal ifTrue:[
   670         sig == Stream endOfStreamSignal ifTrue:[
   671 	    ex reject
   671             ex reject
   672 	].
   672         ].
   673 
   673 
   674 	sig == Signal noHandlerSignal ifTrue:[
   674         sig == Signal noHandlerSignal ifTrue:[
   675 	    ex parameter rejected ifTrue:[
   675             ex parameter rejected ifTrue:[
   676 		ex reject
   676                 ex reject
   677 	    ].
   677             ].
   678 	].
   678         ].
   679 
   679 
   680 	(dontAskSignals notNil and:[dontAskSignals includesKey:sig]) ifTrue:[
   680         (dontAskSignals notNil and:[dontAskSignals includesKey:sig]) ifTrue:[
   681 	    ex proceedWith:(dontAskSignals at:sig)
   681             ex proceedWith:(dontAskSignals at:sig)
   682 	].
   682         ].
   683 
   683 
   684 	canContinueForAll := false.
   684         canContinueForAll := false.
   685 	redef := false.
   685         redef := false.
   686 
   686 
   687 	"/ for your convenience ...
   687         "/ for your convenience ...
   688 	(sig == Class methodRedefinitionSignal) ifTrue:[
   688         (sig == Class methodRedefinitionSignal) ifTrue:[
   689 	    param := ex parameter. "/ an association: oldMethod -> newMethod
   689             param := ex parameter. "/ an association: oldMethod -> newMethod
   690 	    oldPackage := param key package.
   690             oldPackage := param key package.
   691 	    newPackage := param value package.
   691             newPackage := param value package.
   692 	    msg := 'trying to overwrite method:\\    ' , param key whoString , '\\in package ''' 
   692             msg := 'trying to overwrite method:\\    ' , param key whoString , '\\in package ''' 
   693 		   , oldPackage , ''' with method from package ''' , newPackage , ''''.
   693                    , oldPackage , ''' with method from package ''' , newPackage , ''''.
   694 	    canContinueForAll := true.
   694             canContinueForAll := true.
   695 	] ifFalse:[
   695         ] ifFalse:[
   696 	    (sig == Class classRedefinitionSignal) ifTrue:[
   696             (sig == Class classRedefinitionSignal) ifTrue:[
   697 		param := ex parameter. "/ an association: oldClass -> newClass
   697                 param := ex parameter. "/ an association: oldClass -> newClass
   698                 
   698                 
   699 		oldPackage := param key package.
   699                 oldPackage := param key package.
   700 		newPackage := param value package.
   700                 newPackage := param value package.
   701 		msg := 'trying to redefine class: ' , param key name allBold , '\\in package ''' 
   701                 msg := 'trying to redefine class: ' , param key name allBold , '\\in package ''' 
   702 		       , oldPackage , ''' with new definition from package ''' , newPackage , ''''.
   702                        , oldPackage , ''' with new definition from package ''' , newPackage , ''''.
   703 		canContinueForAll := true.
   703                 canContinueForAll := true.
   704 		redef := true.
   704                 redef := true.
   705 	    ] ifFalse:[
   705             ] ifFalse:[
   706 		msg := 'error in fileIn: %1'
   706                 msg := 'error in fileIn: %1'
   707 	    ]
   707             ]
   708 	].
   708         ].
   709 
   709 
   710 	what := ex errorString.
   710         what := ex errorString.
   711 	what isNil ifTrue:[
   711         what isNil ifTrue:[
   712 	    what := ex signal notifierString.
   712             what := ex signal notifierString.
   713 	].
   713         ].
   714 
   714 
   715 	"/ handle the case where no GUI has been built in,
   715         "/ handle the case where no GUI has been built in,
   716 	"/ just abort the fileIn with a notification
   716         "/ just abort the fileIn with a notification
   717 
   717 
   718 	Display isNil ifTrue:[
   718         Display isNil ifTrue:[
   719 	    sender := ex suspendedContext sender.
   719             sender := ex suspendedContext sender.
   720 	    self notify:(what , 
   720             self notify:(what , 
   721 			 ' in ' , sender receiver class name ,
   721                          ' in ' , sender receiver class name ,
   722 			 '>>>' , sender selector).
   722                          '>>>' , sender selector).
   723 	    ex return
   723             ex return
   724 	].
   724         ].
   725 
   725 
   726 	msg := msg bindWith:what.
   726         msg := msg bindWith:what.
   727 
   727 
   728 	sig == HaltInterrupt ifTrue:[
   728         sig == HaltInterrupt ifTrue:[
   729 	    sender := ex suspendedContext.
   729             sender := ex suspendedContext.
   730 	    msg := msg , ('\\in ' , sender receiver class name , '>>>' , sender selector) withCRs
   730             msg := msg , ('\\in ' , sender receiver class name , '>>>' , sender selector) withCRs
   731 	].
   731         ].
   732 
   732 
   733 	"/ otherwise ask what should be done now and either
   733         "/ otherwise ask what should be done now and either
   734 	"/ continue or abort the fileIn
   734         "/ continue or abort the fileIn
   735 	redef ifTrue:[
   735         redef ifTrue:[
   736 	    action := OptionBox 
   736             action := OptionBox 
   737 			  request:(msg withCRs) 
   737                           request:(msg withCRs) 
   738 			  label:'Class redefinition in fileIn'
   738                           label:'Class redefinition in fileIn'
   739 			  form:(WarningBox iconBitmap)
   739                           form:(WarningBox iconBitmap)
   740 "/ cg: now always keep the old packageID
   740 "/ cg: now always keep the old packageID
   741 "/                          buttonLabels:#('cancel' 'skip' 'debug' 'keep' 'keep all' 'continue' 'continue all')
   741 "/                          buttonLabels:#('cancel' 'skip' 'debug' 'keep' 'keep all' 'continue' 'continue all')
   742 "/                          values:#(#abort #skip #debug #keep #keepAll #continue #continueForAll)
   742 "/                          values:#(#abort #skip #debug #keep #keepAll #continue #continueForAll)
   743 			  buttonLabels:#('Cancel' 'Skip' 'Debug' 'Continue' 'Continue All')
   743                           buttonLabels:#('Cancel' 'Skip' 'Debug' 'Continue' 'Continue All')
   744 			  values:#(#abort #skip #debug #keep #keepAll)
   744                           values:#(#abort #skip #debug #keep #keepAll)
   745 			  default:#continue
   745                           default:#continue
   746 			  onCancel:#abort.
   746                           onCancel:#abort.
   747 	] ifFalse:[
   747         ] ifFalse:[
   748 	    action := self askForDebug:msg withCRs canContinueForAll:canContinueForAll.
   748             action := self askForDebug:msg withCRs canContinueForAll:canContinueForAll.
   749 	].
   749         ].
   750 	action == #continueForAll ifTrue:[
   750         action == #continueForAll ifTrue:[
   751 	    dontAskSignals isNil ifTrue:[
   751             dontAskSignals isNil ifTrue:[
   752 		dontAskSignals := IdentityDictionary new.
   752                 dontAskSignals := IdentityDictionary new.
   753 	    ].
   753             ].
   754 	    dontAskSignals at:sig put:#continue.
   754             dontAskSignals at:sig put:#continue.
   755 	    action := proceedValue := #continue.
   755             action := proceedValue := #continue.
   756 	] ifFalse:[
   756         ] ifFalse:[
   757 	    action == #keepForAll ifTrue:[
   757             action == #keepForAll ifTrue:[
   758 		dontAskSignals isNil ifTrue:[
   758                 dontAskSignals isNil ifTrue:[
   759 		    dontAskSignals := IdentityDictionary new.
   759                     dontAskSignals := IdentityDictionary new.
   760 		].
   760                 ].
   761 		dontAskSignals at:sig put:#keep.
   761                 dontAskSignals at:sig put:#keep.
   762 		action := #continue.
   762                 action := #continue.
   763 		proceedValue := #keep.
   763                 proceedValue := #keep.
   764 	    ] ifFalse:[
   764             ] ifFalse:[
   765 		action == #keep ifTrue:[
   765                 action == #keep ifTrue:[
   766 		    action := #continue.
   766                     action := #continue.
   767 		    proceedValue := #keep.
   767                     proceedValue := #keep.
   768 		].
   768                 ].
   769 	    ].
   769             ].
   770 	].
   770         ].
   771 
   771 
   772 	action == #continue ifTrue:[
   772         action == #continue ifTrue:[
   773 	    ex proceedWith:(proceedValue ? #continue)
   773             ex proceedWith:(proceedValue ? #continue)
   774 	].
   774         ].
   775 	action == #abort ifTrue:[
   775         action == #abort ifTrue:[
   776 	    AbortSignal raise.
   776             AbortSignal raise.
   777 	    ex return
   777             ex return
   778 	].
   778         ].
   779 	action == #cancelAll ifTrue:[
   779         action == #cancelAll ifTrue:[
   780 	    AbortAllSignal raise.
   780             AbortAllSignal raise.
   781 	    ex return
   781             ex return
   782 	].
   782         ].
   783 	action == #skip ifTrue:[
   783         action == #skip ifTrue:[
   784 	    ex proceedWith:nil
   784             ex proceedWith:nil
   785 	].
   785         ].
   786 	action == #debug ifTrue:[
   786         action == #debug ifTrue:[
   787 	    Debugger enter:ex suspendedContext 
   787             Debugger enter:ex suspendedContext 
   788 		     withMessage:ex errorString 
   788                      withMessage:ex errorString 
   789 		     mayProceed:true.
   789                      mayProceed:true.
   790 	    ex proceedWith:proceedValue
   790             ex proceedWith:proceedValue
   791 	].
   791         ].
   792 
   792 
   793 	"/ (ex signal) enterDebuggerWith:ex message:what.
   793         "/ (ex signal) enterDebuggerWith:ex message:what.
   794 	ex reject
   794         ex reject
   795     ] do:[
   795     ] do:[
   796 	[self atEnd] whileFalse:[
   796         [self atEnd] whileFalse:[
   797 	    lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk
   797             lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk
   798 	]
   798         ]
   799     ].
   799     ].
   800     ^ lastValue
   800     ^ lastValue
   801 
   801 
   802     "Modified: / 10.9.1999 / 16:54:01 / stefan"
   802     "Modified: / 10.9.1999 / 16:54:01 / stefan"
   803     "Modified: / 16.11.2001 / 16:21:28 / cg"
   803     "Modified: / 16.11.2001 / 16:21:28 / cg"
  1191 ! !
  1191 ! !
  1192 
  1192 
  1193 !PositionableStream class methodsFor:'documentation'!
  1193 !PositionableStream class methodsFor:'documentation'!
  1194 
  1194 
  1195 version
  1195 version
  1196     ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.123 2003-02-25 11:46:48 cg Exp $'
  1196     ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.124 2003-03-02 20:38:24 stefan Exp $'
  1197 ! !
  1197 ! !
  1198 
  1198 
  1199 PositionableStream initialize!
  1199 PositionableStream initialize!