!       PRTOUT          Format a SuperVUE outline document for printing.
!       Author:         Irwin M. Goldstein
!       Written on:     11/87

!       NOTE:  This program is intended to be invoked through PRTOUT.DO.
!       Command format:

!               .PRTOUT svfile [ret]

!       Where "svfile" is the name of a SuperVUE file containing
!       ".section" and ".outline" commands that you want turned into
!       a printable outline.  A file "svfile.OUT" will be created.

!       The specified SuperVUE file will be read in, converting the
!       ".outline" and ".section" dot commands into a printable outline
!       using SuperVUEs numbered list commands.  PRTOUT will then invoke
!       SuperVUE on the resulting ".OUT" file allowing manual changes and
!       adjustments to be made.  To print the outline, just invoke the print
!       command from SuperVUE command mode.

       MAP1 INPUT'FILE, S, 25                  ! name of the input file

       MAP1 LBUF, S, 500                       ! line input from the file
       MAP1 LEVEL, F, 6                        ! outline/indentation level
       MAP1 TEXT, S, 100                       ! line of text for an outline entry

       INPUT LINE INPUT'FILE                   ! get the name of the file to process

       OPEN #1, INPUT'FILE + ".TXT", INPUT     ! output of SVCPY is our input
       OPEN #2, INPUT'FILE + ".OUT", OUTPUT    ! create ".OUT" for output

!       Setup the list element commands ad a suitable ruler for the outline:

       PRINT #2, ".le %"; CHR(13);
       PRINT #2, ".letype IIA0a0";CHR(13);
       PRINT #2, ".lesuffix __).).";CHR(13);
       PRINT #2, "....|....|....|....|....|....|....|....|....|....|....|....|....|....|....|.";CHR(13);

!       Loop through the input file:

ILOOP:  INPUT LINE #1, LBUF
       IF EOF(1) = 1 &
           THEN GOTO DONE

!       Ignore all but outline commands:

       IF (UCS(LBUF[1;8]) # ".OUTLINE") AND (UCS(LBUF[1;8]) # ".SECTION") &
           THEN GOTO ILOOP

!       Determine the outline level:
!         + means increment level by one,
!         - means decrement level by one,
!         @ means leave the level alone,
!         a number means set the level to that number

       IF LBUF[10;1] = "+" &
           THEN LEVEL = LEVEL + 1 &
           ELSE IF LBUF[10;1] = "-" &
               THEN LEVEL = LEVEL - 1 &
               ELSE IF LBUF[10;1] # "@" &
                   THEN LEVEL = LBUF[10;2]

!       Get the text of the outline entry:

       TEXT = LBUF[12,LEN(LBUF)]

STRIP:  IF (LEN(TEXT) > 0) AND (TEXT[1;1] = CHR(32)) &
           THEN &
               TEXT = TEXT[2,-1] : &
               GOTO STRIP                      ! remove leading blanks

!       Output the current outline entry:

       IF LEVEL = 0 &
           THEN PRINT #2, CHR(13);             ! extra line between major headings
       PRINT #2, SPACE(5*(LEVEL+1)-1);"%    ";TEXT;CHR(13);
       GOTO ILOOP

!       End of input file reached, close up files & exit:

DONE:   CLOSE #2
       CLOSE #1
       END