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

  1. /*-----------------------------Start Rexx Source------------------------------*/
  2.  
  3. /*      Magus!.rexx
  4.  
  5.     Magus! Print Spooler
  6.            v1.00               Associated files: Magus!Cntl.rexx
  7.                                                  Magus!Util.rexx
  8.             by                                   MPrint.rexx
  9.         Dan Schenck                              MPrintIt.rexx
  10.          Tulsa, OK
  11.  
  12.       GEnie: D.SCHENCK
  13.        (918) 492-0523
  14.                          */
  15.  
  16. /*  Requires rexxarplib.library v2.1 */
  17.  
  18.   true = 1
  19.   false = 0
  20.   sufile = "T:$$M!Util"
  21.   title    = "  Magus!  "
  22.   sysinfo  = "Magus! Print Spooler v1.00\"
  23.   sysinfo = sysinfo || "       Written by:\       Dan Schenck\\"
  24.   sysinfo = sysinfo || "     Tulsa, Oklahoma"
  25.   syshelp = "To activate print file selector\"
  26.   syshelp = syshelp || "use pull down menu ""Print File"".\\"
  27.   syshelp = syshelp || "To change printer control settings\"
  28.   syshelp = syshelp || "select ""Active/Inactive"" gadget\"
  29.   syshelp = syshelp || "on Magus! window."
  30.   active   = "  Active  "
  31.   inactive = " Inactive "
  32.   status = inactive
  33.   config_file = "S:MAGUS!.config"
  34.   rtn = Setenv('prnt_spooler',"NA")
  35.   rtn = Setenv('spool_tail','null')
  36.   prnt_done = true
  37.   time2exit = false
  38.   count = 0
  39.  
  40. /*  Open primary Magus! window  */
  41.  
  42.   call MenuWindow1(MAGUSHOST,MAGUSPORT)
  43.  
  44.   call AddMenu(MAGUSHOST,"System  ")
  45.   call AddItem(MAGUSHOST," About Magus! ","SYSINFO")
  46.   call AddItem(MAGUSHOST," Spooler Help ","SYSHELP")
  47.   call AddMenu(MAGUSHOST,"Options")
  48.   call AddItem(MAGUSHOST," Print File       ","PRINTSEL","P")
  49.   call AddItem(MAGUSHOST," List Print Queue ","LISTQ","Q")
  50.   call AddItem(MAGUSHOST," Abort Print Job  ","ABORTJOB","A")
  51.   call AddGadget(MAGUSHOST,7,23,"CONTROL",status,"%d")
  52.   call AddGadget(MAGUSHOST,7,11,"SYSINFO",title,"%d")
  53.  
  54.   time2quit = false
  55.   time2end  = false
  56.   call ReadHost(MAGUSHOST,MAGUSPORT,"SETUP")
  57.  
  58.   do until(time2quit) /*1*/
  59.     t = waitpkt(MAGUSPORT)
  60.     i = false
  61.     do until(i) /*2*/
  62.       p = getpkt(MAGUSPORT)
  63.       if c2d(p) = 0 then break
  64.       command = getarg(p)
  65.       t = reply(p,0)
  66.       i = true
  67.       select /*3*/
  68.  
  69.         when command = "PRINT" then
  70.           do
  71.             do while(Getenv('prnt_spooler') = 'GETTINGCLIP')
  72.               call delay(25)
  73.             end
  74.             rtn = Setenv('prnt_spooler','GETTINGCLIP')
  75.             instring = Getenv('next_file2print')
  76.             rtn = Setenv('next_file2print','[READY]')
  77.             rtn = Setenv('prnt_spooler','NA')
  78.             parse VAR instring file2print '^' options
  79.             if left(statef(file2print),4) ~= "FILE" then break
  80.             orig_file = file2print
  81.             copy_dir = Getenv('copy_dir')
  82.             if copy_dir ~= "null" then
  83.               do
  84.                 count = count + 1
  85.                 copy_file = copy_dir || "/$$" || count
  86.                 address command 'copy' file2print " TO " copy_file
  87.                 file2print = copy_file
  88.               end
  89.             do while(Getenv('prnt_spooler') = 'GETTINGCLIP')
  90.               call delay(25)
  91.             end
  92.             rtn = Setenv('prnt_spooler','GETTINGCLIP')
  93.             spool_tail = Getenv('spool_tail')
  94.             if spool_tail = "null" then
  95.               do
  96.                 fwrd_pointer = 'spool_1'
  97.                 spool_tail = 1
  98.               end
  99.             else
  100.               do
  101.                 back_pointer = 'spool_' || spool_tail
  102.                 spool_tail = spool_tail + 1
  103.                 fwrd_pointer = 'spool_' || spool_tail
  104.                 file_info = Getenv(back_pointer)
  105.                 file_info = fwrd_pointer subword(file_info,2)
  106.                 rtn = Setenv(back_pointer,file_info)
  107.               end
  108.             file_info = 'null' file2print orig_file options
  109.             rtn = Setenv(fwrd_pointer,file_info)
  110.             rtn = Setenv('spool_tail',spool_tail)
  111.             rtn = Setenv('prnt_spooler','NA')
  112.             if prnt_done then 
  113.               do
  114.                 address command arun "rx rexx:mprintit" fwrd_pointer Getenv('file_separator')
  115.                 prnt_done = false
  116.                 call RemoveGadget(MAGUSHOST,"CONTROL")
  117.                 status = active
  118.                 call BackFill(MAGUSHOST)
  119.                 call RefreshGadgets(MAGUSHOST)
  120.                 call AddGadget(MAGUSHOST,7,23,"CONTROL",status,"%d")
  121.               end
  122.          end
  123.  
  124.         when command = "DONE" then
  125.           do
  126.             if time2exit then call EndAll
  127.             prnt_done = true
  128.             count = 0
  129.             call RemoveGadget(MAGUSHOST,"CONTROL")
  130.             status = inactive
  131.             call BackFill(MAGUSHOST)
  132.             call RefreshGadgets(MAGUSHOST)
  133.             call AddGadget(MAGUSHOST,7,23,"CONTROL",status,"%d")
  134.           end
  135.  
  136.         when command = "SETUP" then
  137.           do
  138.             if ~exists(config_file) then
  139.               do
  140.                 call PostMsg(50,50,"Creating MAGUS! config file.\\To alter attributes\select ""Active/Inactive"" gadget.")
  141.                 copy_dir            = "null"
  142.                 file_separator      = "\n"
  143.                 d_raw_options = "1 null null on on on"
  144.                 done = false
  145.                 call SetOptions()
  146.                 call open('out',config_file,"Write")
  147.                 call writeln('out',"MAGUS! config file")
  148.                 call writeln('out',copy_dir)
  149.                 call writeln('out',file_separator)
  150.                 call writeln('out',d_raw_options)
  151.                 call close('out')
  152.                 call Delay(100)
  153.                 call PostMsg()
  154.               end
  155.             else
  156.               do
  157.                 call open('in',config_file,"Read")
  158.                 if readln('in') ~= "MAGUS! config file" then
  159.                   do
  160.                     call close('in')
  161.                     call PostMsg(50,50,"WARNING!\\Bad config file """||config_file||""".\\Will replace with Default File.")
  162.                     address command delete config_file
  163.                     address command arun "rx" "rexx:Magus!Setup"
  164.                     call Delay(100)
  165.                     call PostMsg()
  166.                   end
  167.                 else
  168.                   do
  169.                     copy_dir       = readln('in')
  170.                     file_separator = readln('in')
  171.                     d_raw_options  = readln('in')
  172.                     call close('in')
  173.                     call SetOptions()
  174.                     if copy_dir ~= "null" & ~exists(copy_dir) then address command "makedir" copy_dir
  175.                   end
  176.               end
  177.           end
  178.  
  179.         when command = "PRINTSEL" then address command arun "rx" "rexx:Mprint"
  180.  
  181.         when command = "LISTQ" | command = "ABORTJOB" then
  182.           do
  183.             if prnt_done then
  184.               do
  185.                 call PostMsg(50,50,"WARNING!\Print program not active.")
  186.                 call Delay(150)
  187.                 call PostMsg()
  188.               end
  189.             else
  190.               do
  191.                 call open('out',sufile,"Write")
  192.                 call writeln('out',"rx rexx:Magus!Util "||command)
  193.                 call writeln('out',"endcli")
  194.                 call close('out')
  195.                 ys = ScreenRows()/2
  196.                 address command "NewShell" ">NIL: NEWCON:0/"||ys||"/"||Screencols()||"/"||ys||"/Magus!Queue from" sufile
  197.               end
  198.           end
  199.  
  200.         when command = "CLOSEWINDOW" then
  201.           do
  202.             if prnt_done then call EndAll
  203.             call PostMsg(50,50,"Waiting on print to\complete before exiting.")
  204.             call delay(150)
  205.             call PostMsg()
  206.             time2exit = true
  207.           end
  208.  
  209.         when command = "SYSINFO" then call Request(100,100,sysinfo,,"  OK  ")
  210.  
  211.         when command = "SYSHELP" then call Request( 50, 50,syshelp,,"  OK  ")
  212.  
  213.         when command = "CONTROL" then
  214.           do /*4*/
  215.             call PostMsg(50,50,"Building Control Panel")
  216.             address REXX "rexx:Magus!Cntl"
  217.           end /*4*/
  218.         otherwise say command
  219.       end /*3*/
  220.     end /*2*/          
  221.   end /*1*/
  222.   exit
  223.  
  224. EndAll:
  225.  
  226.   call CloseWindow(MAGUSHOST)
  227.   exit
  228.  
  229. /*  Setup the host and open window for primary Magus! display  */
  230.  
  231.   MenuWindow1:
  232.   arg hostcntl, hostport
  233.  
  234.   chfile = "T:$Magus1.rexx"
  235.   if ~exists(chfile) then
  236.     do
  237.       call open('out',chfile,"Write")
  238.       call writeln('out',"/* Start Rexx Source */")
  239.       call writeln('out',"x = createhost(" || hostcntl || "," || hostport || ")")
  240.       call close('out')
  241.     end
  242.   address command arun "rx" chfile
  243.   mp = openport(hostport)
  244.   address command "c:WaitForPort" hostcntl
  245.   address command "c:WaitForPort" hostport
  246.   do until(showlist("P",hostcntl) & showlist("P",hostport))
  247.     call delay(10)
  248.   end
  249.   
  250.   idcmp = 'CLOSEWINDOW+GADGETUP+MENUPICK'
  251.   flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+BACKFILL'
  252.  
  253.   call OpenWindow(hostcntl,0,0,98,37,idcmp,flags,"M")
  254.  
  255.   return 0
  256.  
  257. /* Set print options environment variables */
  258.  
  259. SetOptions:
  260.  
  261.   rtn = Setenv('copy_dir',copy_dir)
  262.   rtn = Setenv('file_separator',file_separator)
  263.   rtn = Setenv('prt_options_raw',d_raw_options)
  264.   rtn = Setenv('next_file2print',"[READY]")
  265.   rtn = Setenv('config_file',config_file)
  266.  
  267.   return
  268.  
  269. /*-----------------------------End of Rexx Source-----------------------------*/
  270.