home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / backres.zip / ETC.CMD < prev    next >
OS/2 REXX Batch file  |  1998-01-20  |  3KB  |  78 lines

  1. /* -------------------------------------------------- */
  2. /* Title:               etc.cmd                       */
  3. /*                                                    */
  4. /* Author:              J.Cobb                        */
  5. /*                                                    */
  6. /* Change History:      11/11/1997 - Created JAC      */
  7. /*                                                    */
  8. /* Function:            Updates the TCP/IP services   */
  9. /*                      file with the port for psnsapi*/
  10. /* -------------------------------------------------- */
  11.  
  12.  
  13. parse arg featurehandle featureid port prodsvc
  14.  
  15. /* Query the system functions */
  16. if RxFuncQuery(RexxInstDeselect) <> 0 then
  17.    if RxFuncAdd(RexxInstDeselect,WPINSTAL,RexxInstDeselect) <> 0 then Exit
  18.  
  19. if RxFuncQuery(RexxInstSelect) <> 0 then
  20.    if RxFuncAdd(RexxInstSelect,WPINSTAL,RexxInstSelect) <> 0 then Exit
  21.  
  22. found = 0
  23. etc_path = value( 'ETC',,'OS2ENVIRONMENT')                   
  24. svcfile = etc_path'\services'                                
  25. parse var port pnum '/' ptext
  26.                                                              
  27. if FileExists(svcfile) = 0 then do
  28.    rc=RexxInstDeselect(featurehandle,featureid) 
  29.    Exit
  30. end
  31.  
  32. do while lines( svcfile) > 0                              
  33.    raw_line = linein( svcfile)                            
  34.    if left( raw_line, 1) \= '#' then do                   
  35.       parse var raw_line svcname port .                   
  36.       if svcname = prodsvc then do                  
  37.          rc=RexxInstDeselect(featurehandle,featureid)
  38.          call lineout svcfile /* Close the services file */                                     
  39.          Exit
  40.       end /* do */
  41.    end                                                    
  42. end                                                       
  43. call lineout svcfile /* Close the services file */                                     
  44.  
  45. /* Now go through until we find a unique tcp address */
  46. done = 0
  47. do until done = 1
  48.    clash = 0
  49.    do while lines( svcfile) > 0                              
  50.       raw_line = linein( svcfile)                            
  51.       if left( raw_line, 1) \= '#' then do                   
  52.          parse var raw_line svcname port .                   
  53.          parse var port num '/' .
  54.          if num = pnum then do
  55.             pnum = pnum + 1
  56.             leave
  57.             clash = 1
  58.          end /* do */
  59.       end
  60.    end
  61.    if clash = 0 then done = 1
  62. end /* do */
  63.  
  64. /* If we get here then we have a unique port number */
  65. port = pnum || '/' || ptext
  66. rc=RexxInstSelect(featurehandle,featureid)
  67. rc = RexxInstSetVariable(featurehandle,'port',port)
  68. Exit
  69.  
  70. FileExists: Procedure
  71. /**********************************************************************/
  72. /* Local subroutine to check existence of a file.                     */
  73. /* input:  "arg(1)" contains the subject fileid.                      */
  74. /* output: returns  1 := file exists,  0:= file doesn't exist         */
  75. /**********************************************************************/
  76.    return ('' \= stream( arg(1), 'c', 'query exists') )
  77.  
  78.