home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / SREFPRC1 / DOVIRT.SRF < prev    next >
Text File  |  1997-06-30  |  4KB  |  120 lines

  1. /*  simplified virtual file lookup routines */
  2. /* ----------------------------------------------- */
  3. /* find virtual file name.
  4.   Do NOT perform a "remote" virtual directory lookup!
  5.    Or, if docheck=1 and no such file with that name, returns 0
  6.    Or, if corresponding virtual is a !MOVED  or http:// entry, returns 0.
  7. */
  8. /* ----------------------------------------------- */
  9. SREF_do_virtual:
  10. parse arg ddir,asel,enmadd,docheck,transaction,homedir,host_nickname
  11. if asel="" then return 0
  12. if ddir="" then ddir=sref_datadir()
  13. if enmadd="" then do
  14.    'extract serverport '
  15.    enmadd="SREF_"||serverport||"_"
  16. end
  17. if homedir="" then
  18.    homedir=get_value('HOME_DIR')
  19.  
  20. if homedir<>"" then do
  21.   foo1=pos('~',ASEL)
  22.   if foo1>0 then do           /* do home_dir for ~ substitution, with $ option */
  23.        asel=sref_home_dir(asel,homedir)
  24.   END
  25. end
  26.  
  27.  file=wait_queue2(enmadd,transaction,asel||' '||ddir)
  28.  if abbrev(upper(file),'!MOVED')=1 then do
  29.       return 0
  30.    end
  31.    if abbrev(upper(file),'HTTP://')=1 then do
  32.       return 0
  33.    end
  34.  
  35.   
  36.    if docheck=1 then do
  37.      rf=stream(file,'c','query exists')
  38.      if rf="" then do
  39.          return 0
  40.      end
  41.    end
  42.  
  43.    return file
  44.  
  45. /* ------------------------------------------------------ */
  46. /* query and wait on helper threads -- 
  47. however, if env var SUPPRESS_VIRTUAL=1, then use use ddir */
  48. /* ------------------------------------------------------*/
  49. wait_queue2:procedure expose host_nickname
  50.  
  51. parse arg enmadd,transaction,args
  52. os2e='os2environment'
  53. atid=dostid()
  54. mysem='\SEM32\'||enmadd||'t'||atid
  55. myqueue=enmadd||'t'||atid
  56. if transaction="" then
  57.    'extract transaction'
  58.  
  59. /* suppress virtual? */
  60. if value(enmadd||'SUPPRESS_VIRTUAL',,os2e)=1 then do
  61.        parse var args action ddir
  62.        t1=strip(strip(translate(ddir,'\','/')),,'\')||'\'
  63.        action=translate(action,'\','/')
  64.        action=strip(action,'l','\')
  65.        tryfile=t1||action
  66.        return tryfile
  67.   end
  68.  
  69.   doit=enmadd||'VIRTUAL'
  70.   a=rxqueue('s',doit)
  71.   push  transaction ' ' host_nickname ',' myqueue ',' mysem ',' ARGS
  72.   doit='\SEM32\'||doit
  73.   a=eventsem_reset(mysem)
  74.   a=eventsem_post(doit)
  75.  
  76. again2t:
  77.   a=eventsem_wait(mysem)
  78.  
  79.   if a<>0 then do
  80.         call pmprintf_sref(mysem' 'mytid','athread' A Fatal Semaphore failure in virtual proc: 'a)
  81.         String 'Server is temporarily busy '
  82.         exit ' '
  83.   end
  84.   a=rxqueue('s',myqueue)
  85.   parse pull aline
  86.   PARSE VAR ALINE idnum ',' aline
  87.   idnum=strip(translate(idnum,' ','000d0a'x));TRANSACTION=STRIP(TRANSACTION)
  88.   if idnum<>transaction then  do /*wierd error: got someone else's message! */
  89.       say ' Read odd id from queue 'athread ':' transaction ',' idnum 
  90.       if eventsem_query(mysem)=1 then aa=eventsem_reset(mysem)
  91.      signal again2t
  92.   end
  93.  
  94.   aline=strip(aline)
  95.   return aline
  96.  
  97.  
  98.   
  99.  
  100. /* ----------- */                                                        
  101. /* get environment value, possibly host specific */                      
  102. /* ------------ */                                                       
  103. get_value: procedure expose enmadd host_nickname                          
  104. parse arg vname,hname0
  105. if hname0=0 then 
  106.         hname=' '
  107. else                                                    
  108.     hname=strip(host_nickname)                          
  109.  
  110. vname=strip(vname) ;
  111. if hname<>' ' then do                                                    
  112.    aval=value(enmadd||vname||'.'||hname,,'os2environment')               
  113.    if aval<>' ' Then                                                     
  114.         return aval                                                      
  115. end                                                                      
  116. aval=value(enmadd||vname,,'os2environment')                              
  117. return aval                                                              
  118.  
  119.  
  120.