home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 19 Printer / 19-Printer.zip / priserut.zip / SETUPDRV.CMD < prev   
OS/2 REXX Batch file  |  2000-11-15  |  6KB  |  165 lines

  1. /************************************************************************/
  2. /*    This PGM adds PM_SPOOLER_DRVSHARE entries to the OS2SYS.INI            */   
  3. /*    Usage: [drive:][path]SETUPDRV /options:parm1 parm2                */
  4. /*       /l   (List PM_SPOOLER_DRVSHARE entries on this work station)        */
  5. /*       /a:server_name driver_path   (Add entry)                        */
  6. /*       /f:[drive:][path]filename   (File input of server names)                */
  7. /*       /d   (Delete print_server name(s))                            */
  8. /*                                                */    
  9. /*********************START OF PGM**************************************/
  10. parse upper arg input1 key_value            /*Parse input for requests*/
  11. parse var input1 .'/'request':'key_name        /*get Request and Parm1*/
  12. if 0 < RxFuncQuery('SysLoadFuncs') THEN         /*determine if SysLoadFuncs need loaded*/
  13.      do
  14.     call  RxFuncAdd  'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  15.     call  SysLoadFuncs
  16.      end
  17. sysini_file=value('SYSTEM_INI',,'OS2ENVIRONMENT') /*get the "system" ini loc*/
  18. ini_app = 'PM_SPOOLER_DRVSHARE'
  19. enter = '0D'x
  20. crlf = '0D0A'x
  21. tab = '09'x
  22. call nls_translation                /*init messages "THIS ARE THE ONLY TRANSLATIONS"*/
  23.     select
  24.       when request = 'L' then            /*List request*/
  25.         call l_process
  26.       when request = 'F' then            /*File input request*/
  27.         call f_process
  28.       when request = 'A' then            /*Add server request*/
  29.         call a_process
  30.       when request = 'D' then            /*Delete request*/
  31.         call d_process
  32.        otherwise                    /*Signal Help screen*/
  33.         say syntax;call help
  34.     end /*select*/
  35.         signal end                    /*End program*/
  36. /*********************START OF PROCEDURES************************/
  37. l_process:                        /*List procedure*/
  38.     rc = SysIni(sysini_file,ini_app,'ALL:',ini_data) /*initialize INI buffers*/
  39.     if ini_data.0 > 0 then
  40.       do
  41.        say list1 
  42.         do i = 1 to ini_data.0
  43.                 key_value = SysIni(sysini_file,ini_app,ini_data.i)
  44.         say list2 ini_data.i tab,
  45.         list3 key_value
  46.         end i
  47.       end /*do*/
  48.     else say list4
  49.     return
  50. a_process:                        /*Add procedure*/
  51.     if (key_name <> '') & (key_value <> '') then     /*validation tests for NOT blank*/
  52.       do                        /*this may be improved*/
  53.         if SysIni(sysini_file,ini_app,key_name,key_value) <> 'ERROR' then 
  54.          do
  55.         say key_name key_value add2
  56.         call l_process
  57.          end
  58.       else say add1        
  59.       end
  60.     else call help    
  61.      return    
  62. f_process:                        /*File input procedure*/
  63.     if key_name = '' then do            /*help/return if no file name*/            
  64.       call help;return;end/*do*/
  65.     rc = SysFileTree(key_name,inp_file,'F')    /*Search for input file*/
  66.     if inp_file.0 = 0 then                /*File Not Found*/
  67.       do                    
  68.         say file1
  69.         signal end                    /*End Program*/
  70.       end 
  71.     j = 0                        /*file found,process*/
  72.     do while lines(key_name)            /*Read file in*/
  73.       in_data = linein(key_name)
  74.       if substr(in_data,1,1) <> ';' then        /*not a comment*/
  75.         do          
  76.           j = j+1                    /*bump the counter*/
  77.           line.j = in_data                /*add the line the the stem*/
  78.         end/*do*/
  79.     end/*while*/
  80.        rc = lineout(key_name)            /*Close file*/
  81.     line.0 = j                    /*Set the stem*/
  82.     do j = 1 to line.0
  83.           pos = pos(tab,line.j)                /*prime for 1st read*/
  84.        do while pos <> 0                /*this replaces TABs with ''*/
  85.          line.j = delstr(line.j,pos,1)        /*delete TAB*/
  86.          line.j = insert('',line.j,pos-1,1)        /*insert blank*/        
  87.              pos = pos(tab,line.j)            /*look for next TAB*/
  88.        end/*do*/     
  89.       parse upper var line.j key_name key_value    /*init name/value*/
  90.       key_name = strip(key_name)        /*remove blanks*/
  91.       key_value = strip(key_value)
  92.     if (key_name <> '') & (key_value <> '') then     /*validation tests for NOT blank*/
  93.       do                        /*this may be improved*/
  94.         if SysIni(sysini_file,ini_app,key_name,key_value) <> 'ERROR' then 
  95.          do                        /*create entry*/
  96.         say key_name key_value add2        /*report successful add*/
  97.          end/*do*/
  98.         else say add1                /*report not created*/        
  99.       end/*do*/
  100.     else say file2 j file3                 /*report invalid input*/     
  101.     end j         
  102.    return
  103. d_process:                        /*Delete server procedure*/
  104.      DO FOREVER            /*exit from this procedure by <ENTER> at PULL*/    
  105.     rc = SysIni(sysini_file,ini_app,'ALL:',ini_data) /*initialize INI buffers*/
  106.     if ini_data.0 = 0 then 
  107.       do
  108.          say dele3
  109.          return
  110.       end/*do*/      
  111.     say list5 
  112.        do i = 1 to ini_data.0            /*list available entries*/
  113.          say i'.' ini_data.i
  114.        end i                
  115. inp_again:
  116.     PULL input                    /*get the input*/
  117.     if input = '' then                /*<ENTER>*/
  118.      do 
  119.         say dele1                    /*Delete ended,return*/
  120.         return    
  121.       end
  122.     else if (input < 1) | (input > ini_data.0) then /*validate input*/    
  123.          do                        /*Invalid,redo*/
  124.         say dele2 ini_data.0
  125.             signal inp_again
  126.          end /*do*/
  127.     rc = SysIni(sysini_file,ini_app,ini_data.input,'DELETE:')  /*do the Delete*/
  128.     signal d_process    
  129.       END/*do forever*/    
  130. help:                            /*Screen help procedure*/
  131.     say help1
  132.     say help2
  133.     say help3
  134.     say help4
  135.     say help5  
  136.      return
  137. /******************************************************************
  138. ********     NLS TRANSLATION SECTION     *****************************
  139. ******************************************************************/ 
  140. nls_translation:
  141.     syntax =  'Invalid Option, use the following syntax;'
  142.     help1 = 'Usage: [drive:][path]SETUPDRV /options:parm1 parm2'
  143.     help2 = '   /l   (List 'ini_app' entries on this work station)'
  144.     help3 = '   /a:server_name driver_path   (Add entry)'
  145.     help4 = '   /f:[drive:][path]filename   (File input of server names)'  
  146.     help5 = '   /d   (Delete print_server name(s))'
  147.     list1 = 'Contents of the 'ini_app' are;'
  148.     list2 = 'Server name ='
  149.     list3 = 'Driver location ='
  150.     list4 = 'There are no entries in' ini_app
  151.     list5 = '  Enter the number of the server entry to be removed,',
  152.           ' <ENTER> to end Delete'    
  153.     dele1 = ' Delete request completed'
  154.     dele2 = ' Invalid selection, select a number from 1 to'
  155.     dele3 = ' There are no server entries to be deleted'
  156.     file1 = ' Input file not found, correct name/location'
  157.     file2 = ' Input for selection' 
  158.     file3 = 'invalid, Please correct'
  159.     add1 = 'ERROR, entry not created'
  160.     add2 = 'created'
  161.    return
  162. end:
  163.         call Rxfuncdrop(SysLoadFuncs)
  164.    exit
  165.