From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 10-MAR-1994 08:52:46.98
To:	EVERHART
CC:	
Subj:	RE: tree program

Date: Thu, 3 Mar 94 07:14:24 PST
From: The difference between the impossible and possible lies in a person's determination - Tommy Lasorda <BFEELEY@fa.intel.com>
Message-Id: <9403031514.utk26964@FA.intel.com>
X-To: HERMES::"JPL%UVMVAX.BITNET@mitvma.mit.edu"
Subject: RE: tree program
To: info-vax@sri.com, JPL@UVMVAX.BITNET

-> Anybody have a tree program they'd like to share?
-> 
-> Ideally, I'd like something like this, but will take anything I can get.
-> 
-> top (total size, includes everything in directory)
->   +- sub_dir_1 (size)
->      +- sub_dir_1a (size)
->      +- sub_dir_1b (size)
->      +- sub_dir_1c (size)
->   +- sub_dir_2 (size)
->   +- sub_dir_3 (size)
-> 
-> 
-> Please send directly to me, as I'm not subscribed to this list.
-> Thanks in advance.
-> 
-> - Joe
-> 
-> email: jpl@uvmvax.uvm.edu

Joe,

This one works for me...

Bob Feeley
Intel Corp

cut here ----------------------------------------------------------------------
$
$   !	DRAWTREE.COM	Draws a directory tree on a VT100
$   !
$   !	Required to be run on a VT100 if output is a terminal
$   !
$   !	Parameters:  P1 - The disk directory sepcification ( will prompt if
$   !			    missing ).  Directory may be sub-level.
$   !		     P2 - Output ( default is SYS$OUTPUT, no prompting )
$   !
$   CLR                          !Clear screen before doing anything
$   ON CONTROL_Y THEN EXIT
$   SET NOON
$
$   root = P1
$   GOTO past_prompt
$ set_directory:
$   root = "SYS$LOGIN"    !Set to my root directory
$ past_prompt:
$   IF root .EQS. "" THEN GOTO set_directory
$
$   !	test if the directory exists
$   !
$   parse_root = F$PARSE ( root + "*.*;*" )
$!   IF parse_root .EQS. "" THEN GOTO prompt_directory
$!   IF F$SEARCH ( parse_root ) .EQS. "" THEN GOTO prompt_directory
$
$   !	extract the disk and directory fields
$   !
$   disk	= F$PARSE ( parse_root, , , "DEVICE" )
$   dir_root	= F$PARSE ( parse_root, , , "DIRECTORY" )
$
$   !	test it is not a sub-directory
$   !	strip delimiters
$   !
$   dir_root = dir_root - "<" - "[" - ">" - "]"
$
$   !	set up the output file
$   !	test if output is terminal it is a VT100
$   !
$   output_file = P2
$   IF output_file .EQS. "" THEN output_file = "SYS$OUTPUT"
$   output_device = F$PARSE ( output_file, "DEVICE" )
$   IF F$GETDVI ( output_device, "DEVCLASS" ) .NE. 66 THEN GOTO device_ok
$   IF F$GETDVI ( output_device, "DEVTYPE"  ) .EQ. 96 THEN GOTO device_ok
$   IF output_file .EQS. "SYS$OUTPUT"                 THEN GOTO device_ok
$   WRITE SYS$OUTPUT "Sorry, must be run on a VT100"
$   EXIT
$
$ device_ok:
$   ON CONTROL_Y THEN GOTO abort
$   OPEN/WRITE output 'output_file'
$
$   WRITE output ")0"	! into graphics mode
$
$   !	initialize things
$   !
$   lower_chars = "abcdefghijklmnopqrstuvwxyz0123456789"
$   pad_chars	= "qqqqqqqqq"	! graphic dash
$   line_0      = ""
$   level	= 1
$   entry_1     = dir_root
$
$   ! 6/29/83 - David Harrison
$   !           Remove prefix directories so that non-root directories
$   !           can be traced.
$
$ remove_prefix:
$   tmplen = f$length(entry_1)
$   dot = f$locate(".",entry_1)
$   if dot .eq. tmplen then goto prefix_removed
$   past_dot = dot + 1
$   for_remainder = tmplen - dot
$   entry_1 := 'f$extract(past_dot,for_remainder,entry_1)
$   GOTO remove_prefix
$
$ prefix_removed:
$   GOTO call_pre_case
$ return_pre_case:
$   level_1_dir = dir_root
$   line_1	= "[1;4;7m''entry_1'[m"
$
$ push:
$   !	push down a level
$   !
$   old_level = level
$   level     = level + 1
$   parsed_spec_'level' = F$PARSE ( "*.DIR", -
				    disk, -
				     "<" + level_'old_level'_dir + ">" )
$   next_entry_'level'	= F$SEARCH ( parsed_spec_'level', level )
$
$   ! if search fails no more levels
$   !
$   IF next_entry_'level' .NES. "" THEN GOTO more_levels
$   WRITE output line_'old_level'
$   GOTO pop
$
$ more_levels:
$   !	mark this as the first entry and not the last entry
$   !
$   last_'level' = 0
$   first_'level' = 1
$
$ list_loop:
$   !	for each each sub-directory
$   !	test if this entry is the last in the list
$   !	make the entry the file name field
$   !	Capitalize and lower case entry name
$   !
$   entry_'level' = next_entry_'level'
$   next_entry_'level'	= F$SEARCH ( parsed_spec_'level', level )
$   IF next_entry_'level' .EQS. "" THEN last_'level' = 1
$   entry_'level' = F$PARSE ( entry_'level', , , "NAME" )
$ call_pre_case:
$   entry_length = F$LENGTH ( entry_'level' )
$   counter	 = 1
$ case_loop:
$   IF counter .EQ. entry_length THEN GOTO end_case
$   index = F$CVUI ( 0, 8, F$EXTRACT ( counter, 1, entry_'level' ) ) - 65
$   IF index .LT. 0 THEN index = index + 43
$   entry_'level'['counter',1] := "''F$EXTRACT ( index, 1, lower_chars )'"
$   counter = counter + 1
$   GOTO case_loop
$ end_case:
$   IF level .EQ. 1 THEN GOTO return_pre_case
$
$   !	fiqure out the attaching character
$   !		  | not first |	  first
$   !	----------+-----------+----------
$   !	 not last | right "T" | down "T"
$   !	----------+-----------+----------
$   !	   last	  | right "L" |	  dash
$   !
$					     end_pad = "t"
$   IF first_'level'			THEN end_pad = "w"
$   IF			   last_'level' THEN end_pad = "m"
$   IF first_'level' .AND. last_'level' THEN end_pad = "q"
$
$   !	append dashes, attach character and new entry to line
$   !
$   line_'level' = line_'old_level' + -
		   F$EXTRACT ( F$LENGTH ( entry_'old_level' ), -
			       9, -
			       pad_chars ) + -
		   end_pad + -
		   "[1;4;7m" + entry_'level' + "[m"
$
$   !	blank out the entry and may be add place vertical bar connector
$   !
$   entry_'old_level' = "         x"
$   IF last_'level' THEN entry_'old_level' = "          "
$
$   !	fix up the lower level output line
$   !
$   old_old_level = old_level - 1
$   line_'old_level' = line_'old_old_level' + entry_'old_level'
$
$   !	calculate the directory specification for the next level
$   !
$   level_'level'_dir = level_'old_level'_dir + "." + entry_'level'
$   GOTO push
$ pop:
$
$   ! restore parameters
$   !
$   level = old_level
$   old_level = old_level - 1
$   old_old_level = old_level - 1
$
$   IF level .EQ. 1 THEN GOTO clean_up	! initial level all done
$   first_'level' = 0			! mark end of first entry
$   entry_'old_level' = "         "	! blank out the entry
$   line_'old_level' = line_'old_old_level' + entry_'old_level'
$   IF last_'level' THEN GOTO pop	! done with this level
$   GOTO list_loop		  	! for each sub-directory loop 
$
$ abort:
$   WRITE output "[m"
$ clean_up:
$   WRITE output ""
$   CLOSE output

