home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / PAGEIT.E < prev    next >
Text File  |  1992-09-08  |  7KB  |  221 lines

  1. /*
  2.   PAGEIT.E
  3.  
  4.   PAGEIT scans the current file and inserts page numbers and ejects
  5.   where they are needed.  PAGEIT will also insert print control for
  6.   single or double spacing if desired (of course, the page numbering
  7.   is done taking single and double spacing into consideration). Two
  8.   blank lines are inserted at the start of each new page.
  9.  
  10.   The routine will remove extra blank lines between paragraphs.  It
  11.   will recognize the page numbering so that if it is run more then
  12.   once, maybe changes were made to the file, the ejects and page
  13.   numbers will be repositioned correctly.
  14.  
  15.   SETUP:
  16.   Compile PAGEIT.E with the EPM compiler.  For example:
  17.     ETPM PAGEIT.E
  18.  
  19.   Link the .EX file in MYSTUFF.E or MYMAIN.E
  20.  
  21.   Now it is ready to use.  Edit your ASCII file, and enter the command
  22.   PAGEIT.
  23.  
  24.   Try it.  I hope you like it.
  25.   Jeff Grantz
  26. */
  27.  
  28. defc pageit=
  29.  ind = ''
  30.  TRUE  = 0
  31.  FALSE = 1
  32.  top_of_page = TRUE
  33.  pageline = '                                                             Page '
  34.  count = 0 ; blankline = 0
  35.  eject = \12  -- put eject here so the macro can be printed without breaks
  36.  psave_pos(save_pos)  -- save starting point
  37.  .col = 1 ; .line = 1
  38.  
  39.  ccmenu =         '#Single spaced.'
  40.  ccmenu = ccmenu||'#Single spaced.  Insert print control characters.'
  41.  ccmenu = ccmenu||'#Double spaced.'
  42.  ccmenu = ccmenu||'#Double spaced.  Insert print control characters.'
  43.  
  44.  cc2 = listbox('Is this document single or double spaced?',
  45.  ccmenu, '' ,0 ,0 ,5,30);
  46.  
  47.  if (cc2 = '') then
  48.     stop           -- cancel indicates stop processing
  49.  elseif (cc2 = 'Single spaced.' or
  50.          cc2 = 'Single spaced.  Insert print control characters.') then
  51.     maxlines = 60
  52.     range = 6
  53.     spacing       = \27\65\12\27\50
  54.     wrong_spacing = \27\65\24\27\50
  55.  else
  56.     maxlines = 30
  57.     range = 3
  58.     spacing       = \27\65\24\27\50
  59.     wrong_spacing = \27\65\12\27\50
  60.  endif
  61.  
  62.  if (cc2 = 'Single spaced.  Insert print control characters.' or
  63.      cc2 = 'Double spaced.  Insert print control characters.') then
  64.     getline line, 1
  65.     line = strip(line, 'B')
  66.  
  67.     if line = '' then
  68.        -- put the proper spacing into the document
  69.        insertline spacing, 1
  70.     elseif line = spacing then
  71.        -- Current control is correct, don't do anything
  72.     elseif line = wrong_spacing then
  73.        replaceline spacing, 1
  74.     else
  75.        -- Insert the line before whatever is there
  76.        insertline spacing, 1
  77.     endif
  78.     if (line = spacing or line = wrong_spacing) then
  79.        .line = 2
  80.     endif
  81.  endif
  82.  
  83. /*
  84. --   if .line < 2 then
  85. --      page = 0   -- set up to skip the leading blank lines without deleting
  86. --   else
  87. --      page = 1
  88. --   endif
  89. */
  90. page = 0
  91. -----------------------------------------------------------------------
  92.  curline = .line
  93.  do forever -- don't use for loop because the to value is evaluated once ONLY
  94.  --      for curline = .line to .last
  95.     if page = 0 then
  96.        -- Don't delete leading blank lines
  97.        for startline = curline to .last
  98.  
  99.           count = count + 1
  100.           getline line, startline
  101.           line = strip(line, 'B')
  102.  
  103.           if line <> '' then
  104.              -- were done skipping, so get out of loop
  105.              curline = startline
  106.              startline = .last
  107.              count = count - 1
  108.           endif
  109.        endfor
  110.        page = 1
  111.     endif
  112.     count = count + 1
  113.            if curline > .last then
  114.            sayerror 'CURLINE > .LINE - - ERROR!! ind='ind
  115.            if askyesno("Type ""N"" to stop",1)="N" then stop endif
  116.            endif
  117.     getline rawline, curline
  118.     line = strip(rawline, 'B')
  119.  
  120.     if line = '' then
  121.        -- Keep track of the last blank line found
  122.        if curline - 1 = blankline then
  123.           -- We have 2 blank lines in a row delete this one
  124.            ind='removed blank line'
  125.           deleteline curline
  126.           curline = curline - 1
  127.           count = count - 1
  128.        else
  129.           blankline = curline -- save location of blank line
  130.            ind='saved blank line'
  131.        endif
  132.  
  133.     elseif substr(rawline, 1, length(pageline)) = pageline then
  134.        -- This is a page line so delete it
  135.            ind='deleted pageline'
  136.        deleteline curline
  137.        curline = curline - 1
  138.        count = count - 1
  139.  
  140.     elseif line = eject then
  141.        -- Delete the old ejects
  142.            ind='deleted eject'
  143.        deleteline curline
  144.        curline = curline - 1
  145.        count = count - 1
  146.     else
  147.        -- found a real line, indicate not top of a page ant more
  148.        top_of_page = FALSE
  149.     endif
  150.  
  151.     if count > maxlines then
  152.        if page < 10 then
  153.           pagenum = ' '|| page
  154.        else
  155.           pagenum = page
  156.        endif
  157.        page = page + 1
  158.        -- DO THE EJECT!!!!!!!!!!!!!!!!!!!!!
  159.        -- Find a place to put the eject
  160.        -- Put the page numbering in
  161.        -- Then fix the count
  162.        count = 3
  163.        top_of_page = TRUE
  164.        ind='do eject'
  165.  
  166.        if curline - range > blankline then
  167.           -- put the eject here, the last blank line is to far back
  168.           insertline ' ', curline
  169.                                 -- Put a blank line in so reflow won't
  170.                                 -- take the eject in
  171.        else
  172.           -- skip down lines so pageline comes out in same place as the other ch
  173.           -- put the eject at the last blank line
  174.           -- IE front of the next paragraph
  175.           for i = blankline to curline
  176.              insertline ' ', i
  177.           endfor
  178.        endif
  179.        -- Common code------------------------------------------
  180.        if (cc2 = 'Single spaced.' or
  181.            cc2 = 'Single spaced.  Insert print control characters.') then
  182.           -- If the doc is single spaced, add a second trailer blank line
  183.           insertline ' ', curline
  184.           curline = curline + 1
  185.        endif
  186.        insertline pageline || pagenum, curline + 1
  187.        insertline eject, curline + 2
  188.        insertline ' ', curline + 3
  189.        if cc2 = 'Single spaced.' then
  190.           -- If the doc is single spaced, add a second header blank line
  191.           insertline ' ', curline + 4
  192.           curline = curline + 4
  193.        else
  194.           curline = curline + 3
  195.        endif
  196.        sayerror 'One moment while I work.  I am at line ' curline
  197.     endif
  198.  
  199.     curline = curline + 1       -- EXIT LOOP CODE  !!!!!!!!!
  200.     if curline > .last then     -- EXIT LOOP CODE  !!!!!!!!!
  201.        leave                    -- EXIT LOOP CODE  !!!!!!!!!
  202.     endif                       -- EXIT LOOP CODE  !!!!!!!!!
  203.  
  204.  enddo -- end of do forever
  205.  
  206.       if top_of_page = FALSE then
  207.           for i = count to maxlines + 1
  208.              insertline ' ', .last + 1
  209.           endfor
  210.        if page < 10 then
  211.           pagenum = ' '|| page
  212.        else
  213.           pagenum = page
  214.        endif
  215.        insertline pageline || pagenum, .last + 1  -- put page number on last pag
  216.       endif
  217.  
  218.  prestore_pos(save_pos)
  219.  sayerror 'Pagination done.'
  220.  
  221.