home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 92
/
af092a.adf
/
af92.lzx
/
ARexx_Code
/
file_tree_sort.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1984-02-16
|
2KB
|
129 lines
/* ---------------------------------------------- */
/* file_sort.rexx - sorts the words in a text file into order */
ROOT=1; tree.=0; word.=''; total_count=0
/* ---------------------------------------------- */
/* first step is to read all lines from the file and
place words into the word. compound variable set... */
say "enter source filename and path?"; pull source_name
say "enter destination filename and path?"; pull dest_name
if Open(s,source_name,'r') then
do
if Open(d,dest_name,'w') then
do
do while ~EOF(s)
text=Readln(s)
count=Words(text)
if count>0 then
do
do i=1 to count
j=total_count+i
word.j=Word(text,i)
end
total_count=total_count+count
end
end
/* then we just do the same tree operations as before... */
tree.ROOT
do i=2 to total_count
call BuildTree(i,ROOT)
end
call PrintTree(ROOT)
/* and then close files before exiting... */
Close(d)
say 'Function complete!'
end
else say 'Sorry - cannot open destination file!'
Close(s)
end
else say 'Sorry - cannot open source file!'
exit
/* ---------------------------------------------- */
BuildTree: Procedure expose tree. word.
parse arg i, node
if Upper(word.i)<=Upper(word.node) then
do
if tree.node.left=0 then tree.node.left=i
else call BuildTree(i,tree.node.left)
end
else do
if tree.node.right=0 then tree.node.right=i
else call BuildTree(i,tree.node.right)
end
return
/* ---------------------------------------------- */
PrintTree: Procedure expose d tree. word.
parse arg node
if node ~=0 then
do
call PrintTree(tree.node.left)
call Writeln(d,word.node)
call PrintTree(tree.node.right)
end
return
/* ---------------------------------------------- */