RESERVE 20000 c$=SPACE$(128) BMOVE BASEPAGE+129,VARPTR(c$),127 c$="\megamax\fileview\*.c case" WHILE ASC(RIGHT$(c$))<=32 c$=LEFT$(c$,LEN(c$)-1) WEND @findword(1) filename$=MID$(c$,pos1%,pos2%-pos1%) @findword(pos2%) search$=MID$(c$,pos1%,pos2%-pos1%) IF pos2%<=LEN(c$) @findword(pos2%) opt$=MID$(c$,pos1%,pos2%-pos1%) IF opt$<>"-p" PRINT "usage: grep filespec searchstring [-x]" @the_end ELSE WHILE GEMDOS(17)=0 PRINT "Grep: printer not ready .. Abort Retry Ignore?" REPEAT k$=UPPER$(INKEY$) UNTIL k$="A" OR k$="R" OR k$="I" EXIT IF k$="A" OR k$="I" WEND IF k$="A" @the_end ENDIF prt%=1 ENDIF ELSE prt%=0 ENDIF ' dta%=HIMEM+4000 VOID GEMDOS(&H1A,L:dta%) @grep(filename$,search$,prt%) @the_end ' PROCEDURE grep(filename$,search$,prflag%) LOCAL n$,a$,x%,path$,lc%,sclin% PRINT "Welcome to Digital Insanity's SimpleGrep" PRINT x%=INSTR(filename$,"\") WHILE x%<>0 path$=LEFT$(filename$,x%) INC x% IF x%>LEN(filename$) PRINT "Grep: incorrect filename specification." @the_end ENDIF x%=INSTR(filename$,"\",x%) WEND filename$=filename$+CHR$(0) empty$=SPACE$(13) BMOVE VARPTR(empty$),dta%+30,13 IF GEMDOS(&H4E,L:VARPTR(filename$),0)=0 REPEAT n$=STRING$(14,0) BMOVE dta%+30,VARPTR(n$),13 BMOVE VARPTR(empty$),dta%+30,13 OPEN "i",#1,path$+n$ lc%=1 WHILE NOT (EOF(#1)) IF ASC(INKEY$)=27 CLOSE #1 @the_end ENDIF LINE INPUT #1,a$ IF INSTR(a$,search$)<>0 IF prflag%=0 PRINT n$;" line ";lc%;":";a$ INC sclin% ADD sclin%,((LEN(a$)-62)/80)+1 IF sclin%>23 PRINT "-- more --"; VOID INP(2) PRINT sclin%=0 ENDIF ELSE LPRINT n$;" line ";lc%;":";a$ ENDIF ENDIF INC lc% WEND CLOSE #1 UNTIL GEMDOS(&H4F)<>0 ELSE PRINT "Grep: ";filename$;" not found." ENDIF RETURN ' PROCEDURE the_end PRINT PRINT "Program end...Press a key...."; VOID INP(2) END RETURN ' PROCEDURE findword(p%) pos1%=p% WHILE MID$(c$,pos1%,1)=" " AND pos1%<=LEN(c$) INC pos1% WEND pos2%=pos1% WHILE MID$(c$,pos2%,1)<>" " AND pos2%<=LEN(c$) INC pos2% WEND RETURN