home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rexxlb.zip
/
SAMPLES
/
TREED2.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-02-02
|
10KB
|
366 lines
/*****************************************************************************/
/* */
/* TREED2 displays the directory structure of a disk in a window. It starts */
/* at the root directory of the current disk, or at the directory name given */
/* as the first argument. It is derived from TREED.CMD, but a slightly */
/* different tree format is used. */
/* */
/* Requires Personal REXX or REXXLIB (cursor, dosdir, inkey, parsefn, */
/* doschdir, dosdrive, doscd, dosenv, scrread, scrput, scrsize, pcvideomode */
/* functions) and RXWINDOW functions. */
/* */
/* Command format: TREED2 <directory> */
/* */
/*****************************************************************************/
/* process parameter, if any, and check it names existing directory */
badarg = validate_directory(arg(1))
if badarg then do
say "'"arg(1)"'" 'is not the name of a directory.'
exit 1
end
call rxfuncadd 'w_register', 'rxwin30', 'rxwindow'
call w_register
/* processing */
call initialize
curpos = cursor()
call read_tree
call display
/* termination */
parse var curpos row col
call cursor row, col
exit
/* subroutine to read in entire tree */
read_tree: procedure expose base name. location. total. line. count fullname.
name.0 = base
location.0 = 1
line. = ''
count = 1
line.1 = base
fullname.1 = base
call tree strip(base,'t','\'), 1 /* call tree routine to do the real work */
return
/* subroutine to recursively trace through directory tree structure */
tree: procedure expose name. location. total. line. count fullname.
arg directory, depth
n = 0
name = dosdir(directory'\*.*','n','d','d')
do while name \= ''
if name \= '.' & name \= '..' then do
n = n + 1
dir.n = name
end
name = dosdir(,'n','d','d')
end
call sortdir n
total.depth = n
do loc = 1 to n
name.depth = dir.loc
location.depth = loc
call output
call tree directory'\'dir.loc, depth+1
end
return
/* routine to output a line of the output diagram */
output:
line = ''
do i = 1 to depth-1
if location.i < total.i then
line = line || left(d2c(179),3)
else
line = line || copies(' ',3)
end
if location.depth = total.depth then
join = d2c(192) /* bottom corner */
else
join = d2c(195) /* vertical with spur */
line = line || left(join,3,d2c(196)) || name.depth
count = count + 1
line.count = line
fullname.count = directory'\'name.depth
return
/* display the results in a window */
display:
height = scr_height - 6
width = 40
w = w_open(2,3,height+2,width,normal)
call w_border w,,,,,border
call showhelp
namew = w_open(scr_height-1,1,2,80,normal)
top = 1
curline = 2
old_top = 0
newdir = 1
do forever
if top \= old_top then
call show
old_top = top
current = top + curline - 2
call w_put namew, 1, 1, 'Select: 'fullname.current, 80
if newdir then
call w_put namew, 2, 1, 'Current directory: 'dosdrive()':'doscd(), 80
newdir = 0
key = inkey()
select
when key = pf2 then do
call command
newdir = 1
end
when key = pf3 then
leave
when key = pf4 then do
call changedir
newdir = 1
end
when key = pf5 then do
call newtree
if irc \= 0 then
iterate
top = 1
curline = 2
old_top = 0
end
when key = down then do
if current = count then
iterate
if curline <= height then do
call w_attr w, curline, 3, width-4, normal
curline = curline + 1
current = top + curline - 2
call highlight line.current, curline
end
else
top = top + 1
end
when key = up then do
if current = 1 then
iterate
if curline > 2 then do
call w_attr w, curline, 3, width-4, normal
curline = curline - 1
current = top + curline - 2
call highlight line.current, curline
end
else
top = top - 1
end
when key = pgdn then do
if count >= top + height
then top = top + height
if top + curline - 2 > count then
curline = count - top + 2
end
when key = pgup then do
if top - height > 0
then top = top - height
else
top = 1
end
when key = ctrlpgup then do
top = 1
end
when key = ctrlpgdn then do
if count - height + 1 > 0
then top = count - height + 1
end
otherwise nop
end
end
call w_close w
call w_close namew
call w_close helpw
return
/* get a new tree name and switch to it */
newtree:
irc = 0
dw = w_open(4,5,5,50,normal)
call w_border dw,,,,,border
call w_put dw, 2, 3, 'Enter name of new directory:'
answer = ''
do forever
answer = w_get(dw, 3, 3, 46, answer,,,'f')
key = _activation_key
select
when key = esc then do
irc = 1
leave
end
when key = enter then do
if validate_directory(answer) \= 0 then do
msg = "Directory not found."
call w_put dw, 4, 3, msg, 46
iterate
end
call read_tree
leave
end
otherwise nop
end
end
call w_close dw
return irc
/* show a portion of the tree */
show:
call w_hide w, 'n'
do i = 0 to height-1
j = top + i
call w_put w, i+2, 3, line.j, width-4
if i+2 = curline then
call highlight line.j, i+2
end
call w_unhide w
return
/* highlight the directory name */
highlight:
line = arg(1)
row = arg(2)
col = lastpos(d2c(196),line) + 3
call w_attr w, row, col, length(line) - col + 3, reverse
return
/* display the help window */
showhelp:
helpw = w_open(2,50,help_lines+2,28,normal)
call w_border helpw,,,,,border
do i = 1 to help_lines
call w_put helpw, i+1, 3, help_line.i
end
return
/* call command.com */
command:
call w_hide w
call w_hide namew
call w_hide helpw
parse var curpos row col
call cursor row, col
say
say '┌───────────────────────────────────────────────────────────────────────┐'
say '│ Shelling to OS/2... │'
say '│ Type "EXIT" to return control to TREED2 │'
say '└───────────────────────────────────────────────────────────────────────┘'
address command dosenv('comspec')
curpos = cursor()
call w_unhide w
call w_unhide namew
call w_unhide helpw
return
/* change directory */
changedir: procedure expose fullname. current
parse value parsefn(fullname.current) with drive path . .
if drive \= '-' then
call dosdrive drive
if path \= '\' then
path = strip(path,'t','\')
call doschdir path
return
/* preserve screen contents */
save_screen:
saved_screen = scrread(1,1,scr_height*scr_width,'b')
return
/* restore screen contents */
restore_screen:
call scrput 1, 1, saved_screen, 'b'
return
/* validate a putative directory name */
validate_directory: procedure expose base
base = upper(arg(1))
if base = '' then
base = dosdrive()':\'
parse value parsefn(base) with drive path fn ft
if fn \= '-' | ft \= '-' then
badarg = 1
else do
if drive = '-' then
drive = dosdrive()
if path = '-' then
path = '\'
else do
if left(path,1) \= '\' then do
if doscd(drive) \= '\' then
path = doscd(drive)'\'path
else
path = '\'path
end
end
if path \= '\' then
path = strip(path,'t','\')
base = drive':'path
if right(base,2) \= ':\' & dosdir(base,,'d','d') = '' then
badarg = 1
else
badarg = 0
end
return badarg
/* sort a list of subdirectories into alphabetical order */
sortdir: procedure expose dir.
top = arg(1)
do i = 1 to top - 1
low = i
do j = i + 1 to top
if dir.j < dir.low then low = j
end
temp = dir.i
dir.i = dir.low
dir.low = temp
end
return
/* initialize variables */
initialize:
esc = '1b'x
enter = '0d'x
ansiclear = esc'[2J'
up = '0048'x
down = '0050'x
pgup = '0049'x
pgdn = '0051'x
ctrlpgup = '0084'x
ctrlpgdn = '0076'x
pf1 = '003b'x
pf2 = '003c'x
pf3 = '003d'x
pf4 = '003e'x
pf5 = '003f'x
pf6 = '0040'x
pf7 = '0041'x
pf8 = '0042'x
pf9 = '0043'x
pf10 = '0044'x
parse value scrsize() with scr_height scr_width .
parse value pcvideomode() with irc colors . .
if irc = 1 & colors < 4 then do
reverse = 112
normal = 7
border = 15
end
else do
reverse = 112
normal = 31
border = 30
end
help_line.1 = "F2 - OS/2 Command line"
help_line.2 = "F3 - Exit"
help_line.3 = "F4 - Change directory"
help_line.4 = "F5 - New tree"
/* help_line.n = "F5 - Your new option..." */
help_lines = 4 /* must be kept in synch */
return