home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / FINDSESS.ZIP / FINDSESS.CMD
OS/2 REXX Batch file  |  1991-06-05  |  2KB  |  95 lines

  1. /* REXX
  2. **  Return the next available VTAM session or null if no
  3. **  available session.
  4. */
  5.   '@ECHO off'
  6. /*
  7. ** Get command line input.  Set trace if requested.       
  8. */
  9.   parse upper arg trace .
  10.  
  11.   if trace = 'TRACE' then do
  12.     trace ?r
  13.   end
  14.   
  15.   call program_initialization
  16.  
  17.   if \find_open_presentation_space() then do 
  18.     say
  19.     say 'No open sessions found.'
  20.     short_name = ''
  21.   end
  22.  
  23.   exit short_name
  24. /*
  25. ** End of Mainline
  26. */
  27.  
  28. program_initialization:
  29. /*
  30. ** Initialize variables, set boolean switches, strip leading
  31. ** and trailing blanks from input parms (if necessary) , etc.
  32. */
  33.   
  34. /*
  35. ** load REXHLAPI.DLL external function if not already loaded
  36. */
  37.   if rxfuncquery('REXHLLAPI') then do
  38.     call rxfuncadd 'REXHLLAPI','REXHLAPI', 'REXHLLAPI'
  39.   end
  40.  
  41.   true            = 1
  42.   false           = 0
  43.   session_in_use  = true
  44.   short_name      = ''
  45.   vtam_prompt     = 'SALT RIVER PROJECT NETWORK TERMINAL'
  46.  
  47.   return 
  48.  
  49.  
  50. find_open_presentation_space:
  51.  
  52.   say 
  53.   say 'Querying Sessions...'
  54.   session_info = REXHLLAPI('Query_sessions')
  55.   if length(session_info) < 13 then do
  56.     say 'No host sessions are active.'
  57.     return false
  58.   end
  59.  
  60.   say
  61.   say 'Searching for open host session...'
  62.  
  63.   say
  64.   do start_pos = 1 by 12 for (length(session_info) / 12) while session_in_use
  65.     session_type = substr(session_info,start_pos+9,1)
  66.     if session_type = 'H' then do
  67.       short_name = substr(session_info,start_pos,1)
  68.       long_name  = substr(session_info,start_pos+1,8)
  69.       call check_session
  70.     end
  71.   end
  72.   
  73.   if session_in_use then do
  74.     return false
  75.   end
  76.   else do
  77.     return true
  78.   end
  79.  
  80.  
  81. check_session:
  82.   say 'A  Checking host session' short_name '-' long_name
  83.   if REXHLLAPI('Connect_ps', short_name) = 0 then do  
  84.  
  85.     if REXHLLAPI('Search_ps', vtam_prompt, 1) <> 0 then do
  86.       say 
  87.       say 'Open session' short_name 'found.'
  88.       session_in_use = false
  89.     end
  90.  
  91.     call REXHLLAPI 'Disconnect_ps'
  92.  
  93.   end
  94.  
  95.   return