home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 216.lha / Magus! / MPrintIt.rexx < prev    next >
OS/2 REXX Batch file  |  1996-02-15  |  7KB  |  239 lines

  1. /*---------------------------- Start REXX Source ----------------------------*/
  2.  
  3. /*     MPrintIt.rexx           Revised 27-FEB-89
  4.  
  5.     Magus! Print Spooler
  6.            v1.00               Associated files: Magus!.rexx
  7.                                                  Magus!Cntl.rexx
  8.             by                                   Magus!Util.rexx
  9.         Dan Schenck                              MPrint.rexx
  10.          Tulsa, OK
  11.  
  12.       GEnie: D.SCHENCK
  13.        (918) 492-0523
  14.                          */
  15.  
  16. /*  Requires rexxarplib.library v2.1 */
  17.  
  18. parse arg head_pointer cc
  19. schar = '\f'
  20. rchar = '0C'X
  21. call look4spec_char
  22. schar = '\n'
  23. rchar = '0A'X
  24. call look4spec_char
  25. rtn = Setenv('printit_pgm','ACTIVE')
  26.  
  27. do forever
  28.   rtn = Setenv('current_print',head_pointer)
  29.   rtn = Setenv('%_read',0)
  30.   do while(Getenv('prnt_spooler') = 'GETTINGCLIP')
  31.     call delay(25)
  32.   end
  33.   rtn = Setenv('prnt_spooler','GETTINGCLIP')
  34.   instring = Getenv(head_pointer)
  35.   rtn = Setenv('prnt_spooler','NA')
  36.   parse VAR instring fwrd_pointer ' ' file2print ' ' orig_file ' ' copies ' ' lpp ' ' p_no ' ' date ' ' time ' ' file
  37.   call printit
  38.   do while(Getenv('prnt_spooler') = 'GETTINGCLIP')
  39.     call delay(25)
  40.   end
  41.   rtn = Setenv('prnt_spooler','GETTINGCLIP')
  42.   instring = Getenv(head_pointer)
  43.   parse VAR instring fwrd_pointer ' ' rest
  44.   rtn = Setenv(head_pointer,'null')
  45.   if fwrd_pointer = 'null' then
  46.     do
  47.       rtn = Setenv('printit_pgm','NA')
  48.       rtn = Setenv('current_print','null')
  49.       rtn = Setenv('spool_tail','null')
  50.       rtn = Setenv('prnt_spooler','NA')
  51.       address "MAGUSPORT" "DONE"
  52.       exit
  53.     end
  54.   rtn = Setenv('prnt_spooler','NA')
  55.   head_pointer = fwrd_pointer
  56. end
  57.  
  58. printit: procedure expose file2print orig_file cc copies lpp p_no date time file
  59.  
  60.   address command
  61.   interrupt = 'NOTE---> PRINT PROCESS INTERRUPTED'
  62.   if ~exists(file2print) then
  63.     do
  64.       say '"' || file2print || '" Does Not Exist"'
  65.       return
  66.     end
  67.   total_bytes = copies * word(statef(file2print),2)
  68.   bytes_read = 0
  69.   if lpp ~= 'null' then
  70.     do
  71.       count_lines = 1
  72.       if (p_no ~= 'null') & (substr(p_no,1,1) = 'b') then lpp = lpp - 2
  73.       else nop
  74.     end
  75.   else count_lines = 0
  76.   dt_string = ""
  77.   file_string = ""
  78.   if upper(date) = 'ON' then dt_string = 'Date: ' || date() || '     '
  79.   if upper(time) = 'ON' then dt_string = dt_string || 'Time: ' || time()
  80.   if upper(file) = 'ON' then file_string = 'File: ' || orig_file
  81.   do i = 1 to copies
  82.     call time('Reset')
  83.     total_lines = 0
  84.     count = 0
  85.     page = -1
  86.     do while(~open('out','PRT:','Write'))
  87.       call delay(300)
  88.     end
  89.     if count_lines then
  90.       do
  91.         call new_page
  92.         call page_minder(cc)
  93.         if dt_string ~= "" then call page_minder(dt_string)
  94.         else nop
  95.         if file_string ~= "" then call page_minder(file_string)
  96.         else nop
  97.         call page_minder(' ')
  98.       end
  99.     else
  100.       do
  101.         call writeln('out',cc)
  102.         if dt_string ~= "" then call writeln('out',dt_string)
  103.         if file_string ~= "" then call writeln('out',file_string)
  104.         call writeln('out',' ')
  105.       end
  106.     prntfile = 'pfile'
  107.     call open(prntfile,file2print,'Read')
  108.     total_rcds = 0
  109.     rec_chk = 10
  110.     do while(~eof(prntfile))
  111.       if Getenv('printit_pgm') = 'ABORT' then
  112.         do
  113.           call close(prntfile)
  114.           if count_lines then call page_minder(interrupt)
  115.           else call writeln('out',interrupt)
  116.           call close('out')
  117.           if (index(upper(file2print),"$$M!SPOOL/$$") > 0) then
  118.             'delete' file2print || " Quiet"
  119.           rtn = Setenv('printit_pgm','ACTIVE')
  120.           return
  121.         end
  122.       instring = readln(prntfile)
  123.       bytes_read = bytes_read + length(instring)
  124.       total_rcds = total_rcds + 1
  125.       if total_rcds = rec_chk then
  126.         do
  127.           rec_chk = rec_chk + 10
  128.           rtn = Setenv('%_read',(bytes_read/total_bytes*100))
  129.         end
  130.       if count_lines then
  131.         do
  132.           if right(instring,1) = '0C'X then
  133.             do
  134.               if count >= lpp then call new_page
  135.               else nop
  136.               call writeln('out',left(instring,length(instring)-1))
  137.               total_lines = total_lines + 1
  138.               call new_page
  139.             end
  140.           else
  141.             do
  142.               if count >= lpp then call new_page
  143.               else nop
  144.               call writeln('out',instring)
  145.               count = count + 1
  146.               total_lines = total_lines + 1
  147.             end
  148.         end
  149.       else call writeln('out',instring)
  150.     end
  151.     if count_lines then
  152.       do
  153.         call page_minder('0A'X || 'Total records in file = ' || total_rcds || '   Total lines printed = ' || total_lines+2 || '   Seconds to print = ' || time('E'))
  154.         if (count > 0) & (substr(p_no,1,1) = 'b') then call new_page
  155.       end
  156.     else call writeln('out','Total records in file = ' || total_rcds || '   Seconds to print = ' || time('E'))
  157.     call close(prntfile)
  158.     call close('out')
  159.     if (index(upper(file2print),"$$M!SPOOL/$$") > 0) then
  160.       'delete' file2print || " Quiet"
  161.   end
  162.   return
  163.  
  164. look4spec_char: procedure expose cc schar rchar
  165.  
  166.   spec_char = index(cc,schar)
  167.   do while(spec_char > 0)
  168.     if (spec_char + 2) > length(cc) then cc_rest = ""
  169.     else cc_rest = substr(cc,spec_char+2)
  170.     if spec_char = 1 then cc = ""
  171.     else cc = substr(cc,1,spec_char-1)
  172.     cc = cc || rchar || cc_rest
  173.     spec_char = index(cc,schar)
  174.   end
  175.   return
  176.  
  177. page_minder: procedure expose count lpp total_lines p_no page
  178.  
  179.   parse arg instring
  180.  
  181.   if right(instring,1) = '0C'X then
  182.     do
  183.       if count >= lpp then call new_page
  184.       call writeln('out',left(instring,length(instring)-1))
  185.       total_lines = total_lines + 1
  186.       call new_page
  187.       return
  188.     end
  189.   if count >= lpp then call new_page
  190.   call writeln('out',instring)
  191.   count = count + 1
  192.   total_lines = total_lines + 1
  193.   return
  194.  
  195. new_page: procedure expose count p_no page total_lines
  196.  
  197.   ff = '0C'X
  198.   if p_no ~= 'null' then
  199.     do
  200.       page = page + 1
  201.       t_or_b = substr(p_no,1,1)
  202.       if page = 0 then
  203.         if t_or_b = 'b' then
  204.           do
  205.             call writech('out',ff)
  206.             return
  207.           end
  208.         else page = 1
  209.       else nop
  210.       total_lines = total_lines + 2
  211.       if t_or_b = 't' then call writech('out',ff)
  212.       else call writeln('out',' ')
  213.       where = substr(p_no,2,1)
  214.       page_text = 'Page ' || page
  215.       select
  216.         when where = 'l' then call writeln('out',page_text)
  217.         when where = 'c' then call writeln('out',center(page_text,80))
  218.         when where = 'r' then call writeln('out',copies(' ',80-length(page_text)) || page_text)
  219.       end
  220.       if t_or_b = 't' then
  221.         do
  222.           count = 2
  223.           call writeln('out',' ')
  224.         end
  225.       else
  226.         do
  227.           count = 0
  228.           call writech('out',ff)
  229.         end
  230.     end
  231.   else
  232.    do
  233.      call writech('out',ff)
  234.      count = 0
  235.    end
  236.   return
  237.       
  238. /*----------------------------- End REXX Source -----------------------------*/
  239.