MiniInspector.st
author claus
Thu, 10 Aug 1995 14:32:31 +0200
changeset 379 5b5a130ccd09
parent 308 f04744ef7b5d
child 384 cc3d110ea879
permissions -rw-r--r--
revision added

"
 COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

Object subclass:#MiniInspector
       instanceVariableNames:'inspectedObject'
       classVariableNames:   ''
       poolDictionaries:''
       category:'System-Debugging-Support'
!

MiniInspector comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libbasic/MiniInspector.st,v 1.9 1995-08-10 12:29:25 claus Exp $
'!

!MiniInspector class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libbasic/MiniInspector.st,v 1.9 1995-08-10 12:29:25 claus Exp $
$Revision: 1.9 $
"
!

documentation
"
    a primitive (non graphical) inspector for use on systems without
    graphics or when the real inspector dies.
"
! !

!MiniInspector class methodsFor:'instance creation'!

openOn:anObject
    |anInspector|
    anInspector := (self new) initializeFor:anObject.
    anInspector enter
! !

!MiniInspector methodsFor:'private'!

initializeFor:anObject
    inspectedObject := anObject.
    ^self
!

enter
    self commandLoop.
    ^ nil
!

commandLoop
    |cmd done valid|

    'Inspector:' printNewline.
    ' ' printNewline.
    done := false.
    [done] whileFalse:[
	valid := false.
	cmd := self getCommand.
	(cmd == $0) ifTrue:[
	    valid := true.
	    self inspectInstvar:0 of:inspectedObject
	].
	(cmd == $1) ifTrue:[
	    valid := true.
	    self inspectInstvar:1 of:inspectedObject
	].
	(cmd == $2) ifTrue:[
	    valid := true.
	    self inspectInstvar:2 of:inspectedObject
	].
	(cmd == $3) ifTrue:[
	    valid := true.
	    self inspectInstvar:3 of:inspectedObject
	].
	(cmd == $i) ifTrue:[
	    valid := true.
	    self printInstVarsOf:inspectedObject
	].
	(cmd == $p) ifTrue:[
	    valid := true.
	    inspectedObject printNewline
	].
	(cmd == $q) ifTrue:[valid := true. done := true ].
	valid ifFalse: [
	    'valid commands:
   (i)nstvars
   (p)rint
   (1-9) inspect instvar
   (q)uit'       errorPrintNewline
	]
    ].
    ^ cmd
!

getCommand
    |cmd c|
    'inspector> ' print.
    cmd := Character fromUser.
    c := cmd.
    [ c isEndOfLineCharacter ] whileFalse: [
	c := Character fromUser
    ].
    ^ cmd
!

printInstVarsOf:anObject
    |n|
    n := anObject class instSize.
    'number of instvars: ' print. n printNewline.
    1 to:n do:[:i |
	'  ' print. i print. ': ' print.
	(anObject instVarAt:i) printNewline
    ]
!

inspectInstvar:which of:anObject
    which > (anObject class instSize) ifTrue:[
	'invalid instvar' printNewline
    ] ifFalse: [
	(anObject instVarAt:which) inspect
    ]
! !