/*

   Make Module List, D.A.S ModulePlayer REXX-script for making modulelists!

    V0.01   Based on makelist.drx. Will print everything (except realname)

    If you want something removed or something in different order, then
    you can either change it here or take examples from other makelist.drx
    scripts.

*/

OPTIONS Results
ADDRESS 'DASMP'

signal on error
signal on syntax
signal on ioerr
signal on break_c
signal on break_d

unknownauthor = 'Unknown'

indexwidth = 4
namewidth = 28
authorwidth = 25
stylewidth = 20
timewidth = 6
datewidth = 9
sizewidth = 7
chanwidth = 2
typewidth = 5
MODCOUNT
modcounter=result

say ''
say 'Make List All for D.A.S Moduleplayer, V0.01 by Pauli Porkka'
say 'You have 'modcounter' modules in your list currently loaded to D.A.S'
call writech(stdout, 'Do you want to list them all (Y/N)? ')
answer = readln(stdin)
answer = upper(answer)
if answer='Y' then do
   startlist = 0
   endlist = modcounter
   END
else DO
   call writech(stdout, 'Enter starting position (0-'modcounter')? ')
   startlist = readln(stdin)
   call writech(stdout, 'Enter ending position ('startlist+1'-'modcounter')? ')
   endlist = readln(stdin)
   END

say ''

listmode = 'ALL'

call writech(stdout, 'List to File or Screen (F/S)? ')
answer = readln(stdin)
answer = upper(answer)
if answer='F' then DO
   listfile='YES'
   call writech(stdout, 'Enter pathfilename for the list? ')
   listfilename = readln(stdin)
   END
else
   listfile='NO'

listheader1 = left("Num", indexwidth)' 'left("Module name", namewidth)' 'left("CH", chanwidth)' 'left("Type", typewidth)' 'left("Style", stylewidth)' 'left("Length", timewidth)' 'left("Size", sizewidth)
listheader2 = '-----------------------------------------------------------------------------------------------'

if listfile='YES' then DO
   call open(listfilehandle, listfilename, 'W')
   call writeln(listfilehandle, listheader1)
   call writeln(listfilehandle, listheader2)
   END
else DO
   say listheader1
   say listheader2
   END
   modulecount=0
DO modspec= startlist to endlist

   MOVETO modspec
   GETAUTHOR
   authorspec=result
   printline=0

      modulecount=modulecount+1
      MODNAME
      namespec=result
      GETSTYLE
      stylespec=result
      stylespec=strip(stylespec,L,'-')
      GETTIME
      timespec=result
      GETSIZE
      sizespec=result
      GETTYPE
      typespec=result
      GETCHANS
      chanspec=result
      moduleline = left(modulecount, indexwidth)' 'left(namespec, namewidth)' 'left(chanspec, chanwidth)' 'left(typespec, typewidth)' 'left(stylespec, stylewidth)' 'left(timespec, timewidth)' 'right(sizespec, sizewidth)

      if listfile='NO' then DO
         say moduleline
         END
      else
         call writeln(listfilehandle, moduleline)   
END 

if listfile='YES' then
   call close(listfilehandle)

EXIT

error:
syntax:
say 'Error at line 'sigl' in MakeListAll V0.1'
EXIT

break_c:
break_d:
say 'Received a BREAK signal, aborted...'
EXIT

ioerr:
say 'I/O Error at line 'sigl
EXIT
