home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
mtseek.zip
/
MTSEEK.CMD
next >
Wrap
OS/2 REXX Batch file
|
1995-10-02
|
5KB
|
158 lines
/*******************************************************************/
/* MTSEEK */
/* rexx multi-threaded program using multiple processes and queues */
/* to look through files for the occurance of some text */
/* */
/* program does following: */
/* 1. starts thread to find text in files */
/* 2. as text if found, presents list to user */
/* 3. user selects file to edit */
/* */
/* Command is: mtseek <filespec> <text> */
/* Author: S.A.C. Gould 1/95 */
/*******************************************************************/
/************************ MAIN **************************************/
main:
/* constants: */
QueueName = "MTHREADQUEUE"
UserThread = "userthrd.cmd"
ProcessThread = "procthrd.cmd"
ProcOvrSem = "\MTHREAD.SEM" /* name of file which is semaphore */
EndQueue = "ENDQUEUE"
/* Get Arguments */
parse arg filenames searchtext
if searchtext = "" then call Help
/* Initialize functions */
call rxfuncadd "sysloadfuncs", "rexxutil", "sysloadfuncs"
call sysloadfuncs
/* If queue is already created, then delete it */
rc = rxqueue('delete', QueueName)
/* Create the queue. Should check to see if name is same */
/* then set input/output to the queue */
name = rxqueue('create', QueueName)
rc = rxqueue("set", QueueName)
/* Use a semephore to note that queue is active */
call CreateSemaphore ProcOvrSem
/* Now start thread to get user input */
'@start "User Input" /c /f' UserThread QueueName
/* start thread to perform search */
'@detach' ProcessThread QueueName ProcOvrSem filenames searchtext
filenames.0 = 0 /* no files yet */
/* say greeting */
'cls'
say "************** Text Search by Multitasking ***********"
say
say " ***** Display Window *******"
say
/* Process queue until completed */
do while message <> EndQueue
do while queued() = 0 /* is there anything in the queue? */
call syssleep 1 /* don't keep constantly checking */
end /* do */
/* get messages */
do while queued() <> 0
pull message
if message = EndQueue then
signal cleanup
call ParseMessage message
end
end /* do while not end of queue*/
Cleanup:
/* now destroy the queue and delete semaphore */
call DeleteSemaphore ProcOvrSem
rc = rxqueue('delete', QueueName)
exit
/********************** PROCEDURES ****************************************/
/* Creates zero length file to represent semaphore */
CreateSemaphore: Procedure
semname = arg(1)
ok = stream(semname, 'c', 'open write')
ok = stream(semname, 'c', 'close')
return
/* Destroys semaphore by deleting file */
DeleteSemaphore: Procedure
semname = arg(1)
/* '@del' semname '> NUL' */
ok = SysFileDelete(semname)
return
/* processes the message based on the sender */
ParseMessage: Procedure,
expose filenames.
message = arg(1)
/* need to parse message into sender handle and information */
parse var message handle information
select /* check to see who sent data */
when handle = "USER" then do
call ProcessUser information
end
when handle = "FILE" then do /* add filesnames to list */
call ProcessFile information
end
otherwise
say message
end /* select */
return /* ParseMessage */
/* adds a filename to the list of files containing the text */
ProcessFile: Procedure,
expose filenames.
data = arg(1)
n = filenames.0 + 1
filenames.0 = n
parse var data filename linenum rest
filenames.n.fname = filename /* save file name */
filenames.n.lnum = linenum /* save line with first occurance of text */
say "File:"format(n,3) filename
return /* processfile */
/* selects the user selected file and starts another
process by starting the editor */
ProcessUser: Procedure,
expose filenames.
fnum = arg(1)
'@start epm.exe' filenames.fnum.fname "'"filenames.fnum.lnum"'"
return /* processfile */
Help: Procedure
say "Command: mtseek filename(s) search_text"
say "example: mtseek *.* january"
exit