home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 10
/
aminetcdnumber101996.iso
/
Aminet
/
util
/
rexx
/
AGGrep.lha
/
AGgrep.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-09-21
|
5KB
|
176 lines
/* AGgrep.rexx
**
** A too cool program that will run grep and convert the output to an
** AmigaGuide format document which will bring up the document in
** your text editor the items are clicked on
**
** Brian Gragg 9/20/95
*/
/* defines and such */
version_string = "$VER: TTXGrep 9/20/95 V1.0 © 1995 Brian Gragg"
/* GREP CALL */
GREPCALL = "sc:c/grep"
/* GREP HELP CALL */
GREPHELP = "sc:c/grep ?"
/* MACRO TO CALL YOUR EDITOR, ARGUMENT WILL BE FILE|LINENUM */
EDITMACRO = "rexx:TTXEditAtLine.rexx"
/* AMIGAGUIDE CALL */
AMIGAGUIDE = "sys:utilities/amigaguide PUBSCREEN TURBOTEXT"
grepfile = "t:grep." || Pragma("i")
agfile = "t:ttxgrep." || Pragma("i")
CR = d2c(10)
TAB = d2c(9)
/* setup the output file - we need this first so we can show errors in it */
IF Open(agfp,agfile,'w') = 0 THEN DO
SAY "Couldn't create amigaguide file ("||agfile||")"
EXIT 20
END
FullCommand = GREPCALL ARG(1)
WriteLn(agfp,'@DATABASE "TTX Grep"')
WriteLn(agfp,'@REMARK created by 'SubStr(version_string,7))
WriteLn(agfp,'')
WriteLn(agfp,'@NODE Main "'FullCommand'"')
WriteLn(agfp,'')
IF ARG()=0 THEN DO
ErrorText= "USAGE: rx ttxgrep grep-OPTIONS" || CR || version_string || CR || CR
ADDRESS COMMAND GREPHELP '>t:AGGrepError'
CALL HandleError(ErrorText,"T:AGGrepError")
END
SIGNAL ON FAILURE
ADDRESS COMMAND GREPCALL '>'grepfile ARG(1)
SIGNAL OFF FAILURE
IF Open(grepfp,grepfile,'r') = 0 THEN DO
CALL HandleError("Couldn't open grep output file ("||grepfile||")","")
END
/*************************************************************************
** Format of Grep output
** =====================
**
** pc0:TABLEMOV.C: <- FILENAME
** 296:// FUNCTION: MoveTableAbs <- Line # and Line output
** 305:int MoveTableAbs(X... ..
** 416: if (MoveTableAbs(... ..
** 450: MoveTableAbs(layo... ..
** 697: if (MoveTableAbs(... ..
** pc0:USERINT.C: <- FILENAME
** 848: if (M... <- Line # and Line output
** pc0:TABLEMOV.H: <- FILENAME
** 46:int MoveTableAbs(XY... <- Line # and Line output
**
****************************************************************************/
line = ReadLn(grepfp)
IF EOF(grepfp) THEN DO
CALL Close(grepfp)
CALL HandleError("Grep Failure:"CR" "FullCommand||CR||CR"Response"CR" No Matches Found")
END
DO WHILE ~EOF(grepfp)
/* START BY LOOKING FOR FILENAMES */
currentfile = Strip(Left(line,Length(Word(line,1))-1),"B")
CALL Pragma('W','n') /* turn off dos requesters */
IF Exists(currentfile) THEN DO
IF Index(currentfile,":")=0 THEN DO
dir = Pragma('D')
IF Right(dir,1)~=":" THEN
dir = dir || "/"
currentfile = dir || currentfile
END
WriteLn(agfp,'@{" 'currentfile' " RX "'EDITMACRO currentfile'|1" }')
END
ELSE DO
currentfile = ""
WriteLn(agfp,line)
line = ReadLn(grepfp)
END
CALL Pragma('W','w') /* turn dos requesters back on */
DO WHILE (~EOF(grepfp) & currentfile~="")
/* NOW LOOK FOR LINES WITHIN THE FILE */
line = ReadLn(grepfp)
IF Left(line,2) ~= " " THEN
BREAK
PARSE VAR line number ":" line
number = Strip(number,'B',' '||TAB)
line = Strip(line,'B',' '||TAB)
line = Translate(line,,TAB) /* convert all tabs to a space */
/* IF ANY '@' Show UP, WE NEED TO ESCAPE THEM FOR AMIGAGUIDE */
newline=""
cnt = 1
DO UNTIL cnt=0
cnt = Index(line,"@",cnt)
IF cnt~=0 THEN DO
PARSE VAR line first "@" line
newline = newline || first || "\@"
END
END
line = newline || line
IF number ~= "" THEN
WriteLn(agfp,' @{" Line: 'number' " RX "'EDITMACRO currentfile'|'number'"} 'line)
END
END
WriteLn(agfp,'@ENDNODE')
Close(grepfp)
Close(agfp)
ADDRESS COMMAND AMIGAGUIDE agfile
Delete(grepfile)
Delete(agfile)
EXIT
FAILURE:
ERROR:
errRC = RC
CALL Close(grepfp)
CALL HandleError("Grep Failure:"|| CR || " " || FullCommand ,grepfile)
EXIT
/***************************************************/
HandleError: PROCEDURE EXPOSE agfp grepfile agfile grephelp
ErrorText = arg(1)
ErrorFile = arg(2)
WriteLn(agfp,'-=-=-=-=-=-=-=-=-= E R R O R =-=-=-=-=-=-=-=-=-')
WriteLn(agfp,ErrorText)
WriteLn(agfp,' ')
IF (ErrorFile~="" & Exists(ErrorFile)) THEN DO
WriteLn(agfp,"Response:")
ADDRESS COMMAND GREPHELP '>>'ErrorFile
Open('errorfp',ErrorFile,'r')
DO WHILE ~EOF('errorfp')
WriteLn(agfp," " || ReadLn('errorfp'))
END
Close('errorfp')
END
WriteLn(agfp,"")
WriteLn(agfp,"Current Path:")
WriteLn(agfp," "||Pragma("D"))
WriteLn(agfp,'@ENDNODE')
Close(agfp)
ADDRESS COMMAND AMIGAGUIDE agfile
IF Exists(grepfile) THEN Delete(grepfile)
Delete(agfile)
EXIT 20
RETURN