MiniIns.st
author Claus Gittinger <cg@exept.de>
Tue, 19 Aug 1997 22:40:49 +0200
changeset 2868 772c890f907c
parent 2775 acdd73312418
permissions -rw-r--r--
alpha64

"
 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 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.
"
!

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

    [author:]
        Claus Gittinger
"
! !

!MiniInspector class methodsFor:'instance creation'!

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

!MiniInspector methodsFor:'private'!

commandLoop
    |cmd done valid|

    'Inspector:' printCR.
    ' ' printCR.
    done := false.
    [done] whileFalse:[
        valid := false.
        cmd := self getCommand.
        cmd isNil ifTrue:[   "/ EOF -> quit
            cmd := $q
        ].
        (cmd >= $0 and:[cmd <= $9]) ifTrue:[
            valid := true.
            self inspectInstvar:(cmd asciiValue - $0 asciiValue) of:inspectedObject
        ].
        (cmd == $i) ifTrue:[
            valid := true.
            self printInstVarsOf:inspectedObject
        ].
        (cmd == $p) ifTrue:[
            valid := true.
            inspectedObject printCR
        ].
        (cmd == $q) ifTrue:[valid := true. done := true ].
        valid ifFalse: [
            'valid commands:
   (i)nstvars
   (p)rint
   (0-9) inspect instvar
   (q)uit'       errorPrintCR
        ]
    ].
    ^ cmd

    "Modified: 24.7.1997 / 10:00:24 / cg"
!

enter
    self commandLoop.
    ^ nil
!

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

initializeFor:anObject
    inspectedObject := anObject.
    ^self
!

inspectInstvar:which of:anObject
    which > (anObject class instSize) ifTrue:[
        which > (anObject basicSize) ifTrue:[
            'invalid instvar' printCR
        ] ifFalse:[
            (anObject basicAt:which) inspect
        ]
    ] ifFalse: [
        (anObject instVarAt:which) inspect
    ]

    "Modified: 20.5.1996 / 10:27:40 / cg"
!

printInstVarsOf:anObject
    |n "{ Class: SmallInteger }" |

    n := anObject class instSize.
    'number of instvars: ' print. n printCR.
    1 to:n do:[:i |
        '  ' print. i print. ': ' print.
        (anObject instVarAt:i) printCR
    ].
    n := anObject basicSize.
    'number of indexed instvars: ' print. n printCR.
    n > 10 ifTrue:[n := 10].
    1 to:n do:[:i |
        ' [' print. i print. ']: ' print.
        (anObject basicAt:i) printCR
    ].

    "Modified: 20.5.1996 / 10:27:45 / cg"
! !

!MiniInspector class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/Attic/MiniIns.st,v 1.19 1997-07-24 11:38:43 cg Exp $'
! !