/* $Id: Dir2Guide.rexx,v 1.3 1994/01/17 14:47:47 winter Exp winter $ */ /**********************************************************************/ /* * Dir2Guide.rexx * * Generates an Amigaguide document from a directory. * Useful for browsing through a collection of text files, * like Includes, news archive etc. * * Requires: WShell, ExecIO * * Usage: Dir2Guide [> ] * * Author: Stefan Winterstein (winter@cs.uni-sb.de) * Status: Public Domain * * Known bugs: * - WShell must not have echo on! * - '"' in filenames not possible (-> garbage node) * - doesn't check if files are text or binary * - accept quoted argument * * TODO: * - More informative main node (display date, set @author,...) * - Write to file, not stdout * - generate index */ /**********************************************************************/ PARSE ARG dir LF = '0A'X OPTIONS RESULTS IF (dir == "") THEN DO SAY "Usage: Dir2Guide " RETURN 20 END IF ~(EXISTS(dir)) THEN DO SAY "Cannot find '" || dir ||"'" RETURN 10 END mainnode = MakeNodeName(dir) introtext = "Browse through '"|| dir ||"'" SAY "@database" mainnode SAY SAY '@Node Main "'|| dir ||'"' SAY LF LF LF LF SAY ' @{"'|| introtext ||'" link "'||mainnode||'"}' SAY SAY "@EndNode" SAY SAY CALL ProcessDir(dir) EXIT /**********************************************************************/ /* * Output node for this dir: * - links to subdirs in this dir * - links to files in this dir * - for each dir: call ProcessDir(dir) recursively * */ ProcessDir: PROCEDURE ARG dir PARSE ARG dir IF ~(EXISTS(dir)) THEN RETURN LF = '0A'X dirindent = " " fileindent = " " nodename = MakeNodeName(dir) /* * Generate and read list of subdirs */ 'List "'||dir||'" DIRS LFORMAT=" *"%n*" *"%p%n*" " TO RAM:dirlist.unsorted' IF (FileSize("RAM:dirlist.unsorted") ~= 0) THEN DO 'Sort FROM RAM:dirlist.unsorted TO RAM:dirlist' 'ExecIO READ RAM:dirlist STEM dirlist.' END ELSE DO dirlist.0 = 0 END /* * Generate and read list of files */ 'List "'||dir||'" FILES LFORMAT=" *"%n*" *"%p%n*" " TO RAM:filelist.unsorted' IF (FileSize("RAM:filelist.unsorted") ~= 0) THEN DO 'Sort FROM RAM:filelist.unsorted TO RAM:filelist' 'ExecIO READ RAM:filelist STEM filelist.' END ELSE DO filelist.0 = 0 END 'Delete >NIL: RAM:dirlist#? RAM:filelist#?' SAY "@Node" nodename '"'||dir||'"' /* * Print out links to subdirs in this dir */ IF (dirlist.0 > 0) THEN DO DO i=1 FOR dirlist.0 PARSE VAR dirlist.i '"'subdir'"' '"'pathname'"' /* ^ ^ positional markers */ tmpnodename = MakeNodeName(pathname) SAY dirindent ||'@{"' subdir '(dir)" link "'||tmpnodename||'"}' END i SAY END /* * Print out links to files in this dir */ IF (filelist.0 > 0) THEN DO DO i=1 FOR filelist.0 PARSE VAR filelist.i '"'filename'"' '"'pathname'"' SAY fileindent ||'@{"' filename '" link "'|| pathname ||'/Main"}' END i END SAY SAY "@EndNode" SAY SAY /* * Do the recursion */ DO i=1 FOR dirlist.0 PARSE VAR dirlist.i '"'subdir'"' '"'pathname'"' CALL ProcessDir(pathname) END i RETURN /**********************************************************************/ MakeNodeName: PARSE arg str specialchars = '/:, ' RETURN COMPRESS(str, specialchars) /**********************************************************************/ FileSize: PARSE ARG filename status = statef(filename) PARSE VAR status . size . IF (size = "") THEN size = 0 RETURN size