home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l076 / 1.ddi / PAGE.TRU < prev    next >
Encoding:
Text File  |  1988-09-17  |  3.6 KB  |  104 lines

  1. EXTERNAL
  2.  
  3. SUB Page (line$(),arg$)
  4.     !
  5.     !  Page
  6.     !  
  7.     !  a True BASIC(tm), Inc. product
  8.     ! 
  9.     !  ABSTRACT
  10.     !     Sends a True BASIC program to the [first]
  11.     !     printer port and prints the file with page 
  12.     !     headers; inserts a form feed at page breaks.
  13.     !
  14.     !  SYNTAX
  15.     !     DO PAGE
  16.     !     DO PAGE,String for page header
  17.     ! 
  18.     !  Copyright (c) 1988 by True BASIC, Inc.
  19.     !
  20.     CALL initialise                            ! default characteristics
  21.     CALL open_channel                          ! find file to use & get it
  22.     !
  23.     ! Print each line of the current file.  If a
  24.     ! line is longer than the page width, print it
  25.     ! in parts.
  26.     !
  27.     FOR i = 1 to Ubound(line$)                 ! loop through current file
  28.         LET qaz$ = line$(i)                    ! get next line
  29.         DO                                     ! loop in case line too long
  30.            CALL processor(qaz$[1:page_width])  ! print what fits
  31.            LET qaz$[1:page_width] = ""         ! done with this part
  32.         LOOP until Len(qaz$) = 0               ! loop till all parts printed
  33.     NEXT i
  34.     STOP                                       ! done...
  35.     SUB initialise
  36.         IF arg$ <> "" then
  37.            LET formatted_name$ = arg$    ! name specified on DO command
  38.         ELSE
  39.            LET formatted_name$ = "True BASIC(tm)"     ! supply default
  40.         END IF
  41.  
  42.         LET page_width = 60                 ! width of printing area
  43.         LET margin = 3                      ! top & bottom margins (2 minimum)
  44.         LET pagelength = 66                 ! lines on page
  45.  
  46.         LET linenum = Maxnum                ! force inital header
  47.         LET ff$ = Chr$(Ord("FF"))           ! a form feed
  48.         !
  49.         ! Create a string with date and time for use in header
  50.         !
  51.         LET datetime$ = Date$[5:6] & "/" & Date$[7:8] & "/" & Date$[3:4]
  52.         LET datetime$ = Time$[1:5] & " - "  & datetime$ & "     "
  53.     END SUB
  54.  
  55.     SUB open_channel
  56.         DO
  57.            WHEN exception in                ! protect in case of error
  58.                OPEN #99: printer            ! get out of loop if ok
  59.                SET #99: margin page_width
  60.                EXIT DO
  61.            USE
  62.                PRINT "Sorry, "; extext$     ! explain the error
  63.                STOP
  64.            END WHEN
  65.         LOOP
  66.     END SUB
  67.  
  68.     SUB processor(data_string$)
  69.         LET linenum = linenum + 1
  70.         IF linenum >= pagelength-margin then  ! end of page?
  71.            PRINT #99: ff$;                    ! form feed to start new page
  72.            LET pages = pages + 1              ! increment page count
  73.            CALL header                        ! print the header
  74.         END IF
  75.         PRINT #99: data_string$               ! print the line
  76.  
  77.         IF Pos(data_string$,ff$) <> 0 then    ! if the line had a form feed
  78.            LET pages = pages + 1              ! then...
  79.            CALL header                        ! print a header
  80.         END IF
  81.     END SUB
  82.  
  83.     SUB header
  84.         !
  85.         ! Print a header after a form feed - skip one line,
  86.         ! print header info, then skip any more lines needed to
  87.         ! fill out the top margin.
  88.         !
  89.         PRINT #99:
  90.         LET x$ = datetime$ & "Page " & Str$(pages)
  91.         LET xtab = page_width - Len(x$)            ! right justify
  92.         PRINT #99: formatted_name$; Tab(xtab); x$
  93.         !
  94.         ! Fill out top margin
  95.         !
  96.         FOR j = 1 to margin-2
  97.            PRINT #99:
  98.         NEXT j
  99.         LET linenum = margin                         ! current line
  100.     END SUB
  101.  
  102. END SUB
  103.