home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / mtseek.zip / PROCTHRD.CMD < prev    next >
OS/2 REXX Batch file  |  1995-10-02  |  1KB  |  50 lines

  1. /* PROCTHRD.CMD                                                       */
  2. /* This thread perform some calculation. For this example             */
  3. /* this thread finds selected files and searches text within files.   */
  4.  
  5. parse arg qname semname filenames searchtext
  6.  
  7. MainThread:
  8.   /* setting to the queue */
  9.   rc = rxqueue("set", qname)
  10.  
  11.   Call SendMessage "Searching for files...Please wait..."
  12.  
  13.   /* Get List of files commands */
  14.   ok = SysFileTree(filenames, 'files.', 'FSO')
  15.   call SendMessage "Now searching each file."
  16.  
  17.   /* search each file */
  18.   do i = 1 to files.0
  19.     if \SemaphorePresent(semname) then  /* if no semaphore present stop processing */
  20.       signal cleanup
  21.  
  22.     /* otherwise search the file for the text */
  23.     if SysFileSearch(searchtext, files.i, 'lines.', 'N') = 0,
  24.         & lines.0 > 0 then do
  25.       message = "FILE" files.i lines.1
  26.       call SendMessage message  /* report file found */
  27.       end
  28.     end /* for each file */
  29.  
  30.   call SendMessage "End of list."
  31.  
  32.   CleanUp:
  33.     /* some clean up could occur here */
  34.   exit
  35.  
  36. SendMessage: Procedure,
  37.   expose semname        
  38.   message = arg(1)
  39.  
  40.   if SemaphorePresent(semname) then
  41.     queue message
  42.    else
  43.     signal CleanUp
  44.  
  45.   return
  46.  
  47. SemaphorePresent: Procedure
  48.   return stream(arg(1), 'c', 'query exists') <> '' 
  49.  
  50.