Disk J (May 1991) : addicon.rexx / AddIcon.rexx

/**********************************************************************/
/*                            AddIcon.rexx                            */
/**********************************************************************/
/*   A utility to attach a pre-created icon to a file.  To use, you   */
/*   must first create a subdirectory in DEVS: called ICONS, then     */
/*   place your favorite icons in the devs:Icons directory with names */
/*                   such as TEXT, TOOL, GAME, etc.                   */
/**********************************************************************/
/**** variables 
            dummy = a scratch variable for who-cares function retuns
            FileName = command argument.  File to add Icon to
            IconType = command argument.  Icon to add to file
            tmpfile  = file handler for temp list file
            instr    = input when reading list file
            tabstr   = variable tabs for nicer column output
****/
options results

/* CONSOLE EFFECTS */
BOLD_C   = '9B 31 6D'x
RED_C    = '9B 33 37 6D'x       
RESET_C  = '9B 30 6D'x
TAB      = '09'x
LF       = '0A'x

/* MESSAGES */
TITLE    = BOLD_C || 'AddIcon 1.0 By Nicholas J. Fiorello Jr.' || RESET_C
USAGE    = RED_C  || 'Usage:' RESET_C 'AddIcon <FileName> [IconType]'

ICONPATH = 'DEVS:ICONS/'                               /* Path to Icons */
DEFICON  = 'TEXT'                                  /* Default Icon type */

arg FileName IconType                             /* get some arguments */

IconType = strip(IconType,'L')                  /* remove leading space */

if length(FileName) == 0 then do                 /* a no ARGS situation */
    say TITLE || LF || USAGE
    exit
    end

if FileName == '?' then do                                 /* AddIcon ? */
    say center(TITLE, 75)   
    say center(RED_C || 'Available Icons' || RESET_C, 75, )
    say
    ""list ICONPATH '>T:Icn.tmp NOHEAD QUICK' 
    if open('tmpfile','T:Icn.tmp', 'read') then
        do while ~eof('tmpfile')
            instr = readln('tmpfile')
            if length(instr) > 0 then do
                upper instr
                if length(instr) >= 8 then         /* only tab once for */
                    tabstr = TAB                      /* long filenames */
                else
                    tabstr = TAB || TAB
                dummy = writech('STDOUT', instr || tabstr)
            end
        end
    say                                            /* dont say anything */
    dummy = close('tmpfile')
    ""delete 'T:Icn.tmp'
    exit
    end

if ~exists(FileName) then do                      /* Error finding file */
    say RED_C 'Error:' RESET_C 'File Not Found'
    exit
    end

if length(IconType) == 0 then                            /* Use Default */
    IconType = DEFICON

if ~exists(ICONPATH||IconType) then do               /* Can't find icon */
    say RED_C 'Error:' RESET_C 'No Icon of that Type'
    exit
    end

""Copy ICONPATH||IconType FileName||'.info'            /* all ok, do it */