/* REXX ---------------------------------------------------------------+
|                Copyright (c) 1996, SAS Institute Inc.                |
|                  Unpublished - All Rights Reserved                   |
|                      S A S / C   S A M P L E                         |
|                                                                      |
|         NAME: DUMPTREE                                               |
|     LANGUAGE: REXX EXEC                                              |
|      PURPOSE: SAS/C DEBUGGER example program                         |
|               Dumptree is a REXX EXEC that can be used to display    |
|               the nodes of the binary tree created by the program    |
|               BTREE.                                                 |
|               See SAS/C Debugger User's Guide and Reference Third    |
|               Edition, Chapter 10, pgs. 209-212 .                    |
| INPUT/OUTPUT: command line/log window                                |
|                                                                      |
|   TSO -                                                              |
|        USAGE: exec DUMPTREE 'root-id'                                |
|   CMS -                                                              |
|        USAGE: exec DUMPTREE root-id                                  |
|                                                                      |
|   MISC NOTES: This program is used in conjunction with the BTREE     |
|               program to demonstrate how to use a REXX EXEC with a   |
|               C program running under control of the SAS/C Debugger. |
+---------------------------------------------------------------------*/

trace ?r /* Use "trace o" to turn off tracing */
address 'CDEBUG'
parse arg root

if root = '' then do
   'DBLOG DUMPTREE Error: root name not specified.'
   exit 4
   end

signal on error

'TRANSFER ROOT_TYPE TYPEOF' root
'TRANSFER ROOT_PTR VALUE' root
call dump root_ptr, root_type
exit 0

error:
'DBLOG DUMPTREE Error: debugger command at line' sigl 'failed.'
exit 4

dump: procedure
parse arg root_ptr, root_type

'TRANSFER RIGHT_PTR VALUE (('root_type')'root_ptr')->right'
if right_ptr ^= '0p00000000' then
   call dump right_ptr, root_type

'TRANSFER LENGTH VALUE (('root_type')'root_ptr')->length'
'TRANSFER STRING STR (('root_type')'root_ptr')->value,' length
'DBLOG DUMPTREE:' string

'TRANSFER LEFT_PTR VALUE (('root_type')'root_ptr')->left'
if left_ptr ^= '0p00000000' then
   call dump left_ptr, root_type
return