home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / PMPRINTF.RXX < prev    next >
Text File  |  1998-12-17  |  4KB  |  172 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.  
  28.  
  29. call pmprintf(' SRE-http Pmprintf: thread  and queue ='||mytid', 'usequeue)
  30.  
  31.  
  32. if  usequeue="" | USESEM="" then do
  33.    call pmprintf('SRE-http Pmprintf ERROR: initialization ERROR: '||usequeue)
  34.    exit
  35. end
  36.  
  37. /* Initialization now done == start waiting for requests for requests. */
  38.  
  39.  
  40. signal on error name iserror
  41. signal on syntax name iserror
  42.  
  43.  
  44. maxwait=lazy_write
  45. if lazy_write=0 then maxwait=0.5
  46. store_lines.0=0
  47. bakme:
  48.  a=rxqueue('s',usequeue)
  49.  aq=queued()
  50.  
  51.  if aq=0 then do
  52.     WOW=EVENTSEM_WAIT(USESEM,maxwait*1000)
  53.     if wow=640 then do
  54.         arf=write_lines(outfile)
  55.         if arf=1 then store_lines.0=0
  56.         time0=time('r')
  57.         signal bakme
  58.     end
  59.     IF WOW<>0 THEN do         /* FATAL ERROR */
  60.         call pmprintf(' Fatal semaphore error in PMPRINTF thread ')
  61.         EXIT
  62.     end
  63.  end
  64.  wow=EVENTSEM_RESET(usesem)
  65.  if aq=-1 then do
  66.    if queued()=0 then do
  67.       arf=write_lines(outfile)
  68.       if arf=1 then store_lines.0=0
  69.       time0=time('r')
  70.       signal bakme
  71.    end
  72.  end
  73.  
  74. parse pull aline0
  75. parse var aline0 nofile ',' aline
  76. im=store_lines.0+1
  77. store_lines.im=aline
  78. store_lines.im.!nofile=nofile
  79. store_lines.im.!nopmprintf=0
  80.  
  81. store_lines.0=im
  82. if time('e') > lazy_write then do
  83.   arf=write_lines(outfile)
  84.   if arf=1 then store_lines.0=0
  85.   time0=time('r')
  86. end
  87.  
  88.  
  89. signal bakme            /* do it again */
  90.  
  91. iserror:
  92. signal off error ; signal off syntax
  93. call pmprintf('SRE-http Pmprintf ERROR: error in PMPRINTF thread 'sigl)
  94. a=rxqueue('d',usequeue)
  95. a=rxqueue('c',usequeue)
  96. a=eventsem_close(usesem)
  97. a=eventsem_create(usesem)
  98. a=rxqueue('s',newq)
  99. push idnum  ', 0 '
  100. wow=eventsem_post(newsem)
  101. call pmprintf('SRE-http Pmprintf: done resetting PMPRINTF thread ')
  102. signal on error name iserror
  103. signal on syntax name iserror
  104. signal bakme
  105.  
  106. exit
  107.  
  108.  
  109. /****************/
  110. /* OPEN A file (if not locked, and if currently exists), and write alines.  to it*/
  111. write_lines:procedure expose store_lines. linelen typeout preface
  112.  
  113. parse arg iff
  114.  
  115. if typeout<>3 then do   /* write to pmprintf */
  116.   do mm=1 to store_lines.0
  117.     if store_lines.mm.!nopmprintf=1 then iterate /* already been written */
  118.     aline=decodekeyval(STORE_LINES.MM)  /* convert potentially rexxlib fatal %27, etc. codes */
  119.     aline=preface||aline
  120.     if length(aline)>linelen then aline=left(aline,linelen)
  121.     call pmprintf(aline)
  122.     store_lines.mm.!nopmprintf=1
  123.   END
  124. end
  125.  
  126. if typeout=1 then return 1  /* no writing to srehttp.log (tHE IFF FILE) */
  127.  
  128. foo=sref_open_read(iff,20,'both')
  129. if foo=-1 then do
  130.    call lineout iff,' -- SRE-http Log: '||date('n')||' '||time('n')
  131.    call lineout iff
  132.    foo=sref_open_read(iff,20,'both')
  133. end
  134. if foo<0 then return 0          /* 0 signals no success */
  135. ilen=chars(iff)
  136. foo=charin(iff,ilen,1)
  137. if c2d(foo)=26 then ilen=ilen-1
  138. foo=stream(iff,'c','seek '||ilen+1)
  139. do mm=1 to store_lines.0
  140.     if store_lines.mm.!nofile=1 then iterate
  141.     call lineout iff,store_lines.mm
  142. end
  143. foo=stream(iff,'c','close')
  144.  
  145. return 1
  146.  
  147.  
  148. /* procedure from TEST-CGI.CMD by  Frankie Fan <kfan@netcom.com>  7/11/94 */
  149. DecodeKeyVal: procedure
  150.   parse arg Code
  151.   Text=''
  152.   Code=translate(Code, ' ', '+')
  153.   rest='%'
  154.   do while (rest\='')
  155.      Parse var Code T '%' rest
  156.      Text=Text || T
  157.      if (rest\='' ) then
  158.       do
  159.         ch = left( rest,2)
  160.         if verify(ch,'01234567890ABCDEF')=0 then
  161.            c=X2C(ch)
  162.         else
  163.            c=ch
  164.         Text=Text || c
  165.         Code=substr( rest, 3)
  166.       end
  167.   end
  168.   return Text
  169.  
  170.  
  171.  
  172.