Rem *******************************************************************
Rem   Program : lister.bas
Rem *******************************************************************
Rem  Copyright (c) 2001 - S. Narasimhan (narasimhan_s_@hotmail.com)
Rem  All Rights reserved.
Rem *******************************************************************
Rem The program lists a text-file/program source code neatly
Rem on Standard Output.

Rem Usage : lister  filespec  [nn]  [-{l|L}]
Rem     filespec :: The specification for the text file to be listed.
Rem     nn       :: Number of lines to be listed per page. If omitted
Rem                 taken as 58.
Rem     -l       :: Use this option if line-numbers are also to be listed.
Rem As the output of this utility is to the standard output, the same
Rem can be redirected to file/printer.

Rem Initialize
FormFeed$ = CHR$(12)
Author$ = "(c) 01-June-2001 S.Narasimhan (narasimhan_s_@hotmail.com)"
Ruler$    = string$(78, "=")
datestr$  = date$  : timestr$ = time$
Header2$  = "Date:" + datestr$ + " " + timestr$ + space$(45) + "Page:"
linumreqd = 0    ' By default line number not required
lineperpg = 58   ' Default value
pagenum   = 0
linecount = 6
linenum   = 1

Rem Parse the command line
L = LEN(COMMAND$)
If L = 0 then gosub 1000 : End
parm1end = instr(command$ ," ")
parm1$ = left$(command$, parm1end - 1)
parm2end = instr(parm1end+1,command$, " ")
if parm2end > parm1end then
   parm2$ = mid$(command$,parm1end+1,parm2end-parm1end-1)
   parm2$ = ucase$(parm2$)
   If parm2$ = "-L" then
      linumreqd = 1
   else
      lineperpg = val(parm2$)
      parm3end = instr(parm2end+1,command$, " ")
      if parm3end > parm2end then
        parm3$ = mid$(command$,parm2end+1,parm3end-parm2end-1)
        parm3$ = ucase$(parm3$)
        if parm3$ = "-L" then linumreqd = 1
      end if
   end if
end if
Header1$  = "File:" + parm1$

Rem Print Header
gosub 1500
open "I", #1, parm1$
while not eof(1)
   line input #1, lin$
   gosub 2000
wend
close 1
end

Rem Subroutine to display the usage for the program
1000 :
print "Usage : lister  filespec  [nn]  [-{l|L}]"
print "    filespec :: The specification for the text file to be listed."
print "    nn       :: Number of lines to be listed per page. If omitted"
print "                taken as 58."
print "    -l       :: Use this option if line-numbers are also to be listed."
print
print "As the output of this utility is to the standard output, the same"
print "can be redirected to file/printer."
return

Rem Subroutine to skip a page and print the header on top of page 
Rem and adjust pagenum, linecount accordingly.
1500:
print FormFeed$
pagenum = pagenum + 1
print using "&"; Ruler$
print using "&"; Header1$
print using "&####"; Header2$; pagenum
print using "&"; Ruler$
linecount = 6
Return

Rem Subroutine to print a line (lin$) to standard output
Rem and adjust the variables - linenum, linecount
Rem It also checks that linecount does not exceed 'lineperpg'
Rem The moment 'linecount' exceeds 'lineperpg', the subroutine
Rem to print Header is executed
2000:
If linumreqd then
   print using "####:&"; linenum; lin$
else
   print using "&"; lin$
end if
linenum = linenum + 1
linecount = linecount + 1
If linecount > lineperpg then
   gosub 1500
end if
Return

