home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l074 / 1.ddi / PAGE.TRU < prev    next >
Encoding:
Text File  |  1985-02-03  |  2.8 KB  |  87 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 [,filename for header]
  16.     ! 
  17.     !  Copyright (c) 1985 by True BASIC, Inc.
  18.  
  19.     CALL initialise               ! default characteristics
  20.     CALL open_channel             ! find file to use & get it
  21.     CALL current_file(line$)      ! do the work
  22.  
  23.     SUB initialise
  24.         IF arg$ <> "" then
  25.            LET formatted_name$ = Ucase$(arg$)    ! name specified by user
  26.         ELSE
  27.            LET formatted_name$ = "True BASIC(tm)"     ! supply default
  28.         END IF
  29.         LET pagelength = 65       ! lines on page
  30.         LET margin = 4            ! top & bottom margins
  31.         LET page_width = 80       ! width of printing area
  32.         LET count = 1e10          ! initialise counter
  33.         LET formatted_time$ = time$    ! remember current time
  34.         LET formatted_date$ = date$[5:6] & "-" & date$[7:8] & "-" & date$[1:4]
  35.     END SUB
  36.  
  37.     SUB open_channel
  38.         DO
  39.            WHEN exception in      ! protect in case of error
  40.                 OPEN #99: printer      ! get out of loop if ok
  41.                 SET #99: margin PAGE_WIDTH
  42.                 EXIT DO
  43.            USE
  44.                 PRINT "Sorry, "; extext$    ! explain the error
  45.            END WHEN
  46.         LOOP
  47.     END SUB
  48.  
  49.     SUB current_file(line$())
  50.         FOR i = 1 to Ubound(line$)     ! loop through current file
  51.             CALL processor(line$(i))   ! print each line
  52.         NEXT i
  53.     END SUB
  54. !
  55.     SUB processor(data_string$)
  56.         CALL divide(len(data_string$),page_width,q,r)
  57.         IF q = 0 then             ! increment line count
  58.            LET count = count + 1
  59.         ELSE IF r = 0 then
  60.            LET count = count + q
  61.         ELSE
  62.            LET count = count + q + 1
  63.         END IF
  64.         IF count >= pagelength-margin then
  65.            PRINT #99: chr$(12)      ! form feed at end of page
  66.            LET pages = pages + 1    ! increment page count
  67.            CALL header         ! supply the header
  68.         END IF
  69.         PRINT #99: data_string$     ! print the line
  70.         IF pos(data_string$,chr$(12)) <> 0 then       ! look for <ctrl L>
  71.            LET pages = pages + 1     ! increment page count
  72.            CALL header        ! supply the header
  73.         END IF
  74.     END SUB
  75.  
  76.     SUB header
  77.         LET heading$ = Ucase$(formatted_name$) & "  page " & str$(pages)
  78.         PRINT #99: using$("<##############################",heading$);
  79.         PRINT #99: ,formatted_time$,,formatted_date$
  80.         PRINT #99
  81.         PRINT #99
  82.         PRINT #99
  83.         LET count = margin     ! reset line count
  84.     END SUB
  85.  
  86. END SUB
  87.