home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13h.zip / PMPRINTF.RXX < prev    next >
Text File  |  1999-07-21  |  5KB  |  189 lines

  1. /* The "SRE-http audit" pmprintf front end
  2. This is the SRE-http substitute for pmprintf.
  3. It will write to the pmprintf window and/or a srehttp.log file.
  4. Lazy writing is supported.
  5. */
  6.  
  7. /****************** User Changeable Variables */
  8.  
  9. /* Frequency of writing results, in seconds. 
  10.    If 0, theN write results as recieved 
  11. */
  12. lazy_write=1.3
  13.  
  14. /* an optional preface to write before each pmprintf entry (useful
  15. if you have several programs using pmprintf */
  16.  
  17. preface=':'
  18. /************* END of user changable parameters  */
  19.  
  20. parse upper arg usequeue , USESEM , max_semwait,linelen,typeout,outfile
  21.  
  22. /*call pmprintf(' SRE-http PMPRINTF Thread: queue='||usequeue)
  23. call pmprintf(' SRE-http PMPRINTF Thread: semaphore='||usesem)
  24. call pmprintf(' SRE-http PMPRINTF thread: thread id='||mytid)*/
  25.  
  26. mytid=dostid()
  27. time0=xtime('r')   /* reset elapsed time clock */
  28.  
  29.  
  30. call pmprintf(' SRE-http Pmprintf: thread  and queue ='||mytid', 'usequeue)
  31.  
  32.  
  33. if  usequeue="" | USESEM="" then do
  34.    call pmprintf('SRE-http Pmprintf ERROR: initialization ERROR: '||usequeue)
  35.    exit
  36. end
  37.  
  38. /* Initialization now done == start waiting for requests for requests. */
  39.  
  40.  
  41. signal on error name iserror
  42. signal on syntax name iserror
  43.  
  44.  
  45. maxwait=lazy_write
  46. if lazy_write=0 then maxwait=0.5
  47. store_lines.0=0
  48. bakme:
  49.  a=rxqueue('s',usequeue)
  50.  aq=queued()
  51.  
  52.  if aq=0 then do
  53.     WOW=EVENTSEM_WAIT(USESEM,maxwait*1000)
  54.     if wow=640 then do
  55.         arf=write_lines(outfile)
  56.         if arf=1 then store_lines.0=0
  57.         time0=xtime('r')
  58.         signal bakme
  59.     end
  60.     IF WOW<>0 THEN do         /* FATAL ERROR */
  61.         call pmprintf(' Fatal semaphore error in PMPRINTF thread ')
  62.         EXIT
  63.     end
  64.  end
  65.  wow=EVENTSEM_RESET(usesem)
  66.  if aq=-1 then do
  67.    if queued()=0 then do
  68.       arf=write_lines(outfile)
  69.       if arf=1 then store_lines.0=0
  70.       time0=xtime('r')
  71.       signal bakme
  72.    end
  73.  end
  74.  
  75. parse pull aline0
  76. parse var aline0 nofile ',' aline
  77. im=store_lines.0+1
  78. store_lines.im=aline
  79. store_lines.im.!nofile=nofile
  80. store_lines.im.!nopmprintf=0
  81.  
  82. store_lines.0=im
  83. if xtime('e') > lazy_write then do
  84.   arf=write_lines(outfile)
  85.   if arf=1 then store_lines.0=0
  86.   time0=xtime('r')
  87. end
  88.  
  89.  
  90. signal bakme            /* do it again */
  91.  
  92.  
  93. iserror:                /* jump here on an error */
  94. signal off error ; signal off syntax
  95. call pmprintf_sref(' Error in daemon ('usequeue'), exiting: 'sigl','rc)
  96. a=rxqueue('d',usequeue)
  97. if a<>0 then call pmprintf(" ERROR= "a " shutting down "usequeue)
  98. a=eventsem_close(usesem)
  99. if a<>0 then call pmprintf(" ERROR= "a " shutting down "usesem)
  100. exit
  101.  
  102.  
  103. /****************/
  104. /* OPEN A file (if not locked, and if currently exists), and write alines.  to it*/
  105. write_lines:procedure expose store_lines. linelen typeout preface
  106.  
  107. parse arg iff
  108.  
  109. if typeout<>3 then do   /* write to pmprintf */
  110.   do mm=1 to store_lines.0
  111.     if store_lines.mm.!nopmprintf=1 then iterate /* already been written */
  112.     aline=decodekeyval(STORE_LINES.MM)  /* convert potentially rexxlib fatal %27, etc. codes */
  113.     aline=preface||aline
  114.     if length(aline)>linelen then aline=left(aline,linelen)
  115.     call pmprintf(aline)
  116.     store_lines.mm.!nopmprintf=1
  117.   END
  118. end
  119.  
  120. if typeout=1 then return 1  /* no writing to srehttp.log (tHE IFF FILE) */
  121.  
  122. foo=sref_open_read(iff,20,'both')
  123. if foo=-1 then do
  124.    call lineout iff,' -- SRE-http Log: '||date('n')||' '||xtime('n')
  125.    call lineout iff
  126.    foo=sref_open_read(iff,20,'both')
  127. end
  128. if foo<0 then return 0          /* 0 signals no success */
  129. ilen=chars(iff)
  130. foo=charin(iff,ilen,1)
  131. if c2d(foo)=26 then ilen=ilen-1
  132. foo=stream(iff,'c','seek '||ilen+1)
  133. do mm=1 to store_lines.0
  134.     if store_lines.mm.!nofile=1 then iterate
  135.     call lineout iff,store_lines.mm
  136. end
  137. foo=stream(iff,'c','close')
  138.  
  139. return 1
  140.  
  141.  
  142. /* procedure from TEST-CGI.CMD by  Frankie Fan <kfan@netcom.com>  7/11/94 */
  143. DecodeKeyVal: procedure
  144.   parse arg Code
  145.   Text=''
  146.   Code=translate(Code, ' ', '+')
  147.   rest='%'
  148.   do while (rest\='')
  149.      Parse var Code T '%' rest
  150.      Text=Text || T
  151.      if (rest\='' ) then
  152.       do
  153.         ch = left( rest,2)
  154.         if verify(ch,'01234567890ABCDEF')=0 then
  155.            c=X2C(ch)
  156.         else
  157.            c=ch
  158.         Text=Text || c
  159.         Code=substr( rest, 3)
  160.       end
  161.   end
  162.   return Text
  163.  
  164.  
  165. /*****************/
  166. /* catch a time() error, and return 0 if it occurs */
  167.  
  168. xtime:procedure
  169. parse arg is1 
  170.  
  171. atime=0
  172. signal off error  ;signal off syntax ;
  173. signal on error name xtime1 ; signal on syntax name xtime1 ;
  174. btime=time(strip(is1))
  175. atime=1
  176.  
  177. xtime1:
  178.  
  179. signal off error ;signal off syntax  ;
  180. signal on error name iserror
  181. signal on syntax name iserror
  182. if atime=0 then do
  183.  call pmprintf("SRE-http PMPRINTF: Caution,  TIME('"is1"') error : "btime)
  184.  btime=0
  185. end
  186.   
  187. return btime
  188.  
  189.