'qfind DEFLNG a-z %MAXFILES = 666 FUNCTION PBMAIN() cmd$ = TRIM$(COMMAND$) searchfor$ = PARSE$(cmd$, " ", 1) quoteon$ = LEFT$(searchfor$, 1) quoteoff$ = RIGHT$(searchfor$, 1) searchfor$ = LCASE$(MID$(searchfor$, 2, LEN(searchfor$)-2)) REPLACE "_" WITH " " IN searchfor$ searchfile$ = PARSE$(cmd$, " ", 2) ignore1$ = PARSE$(cmd$, " ", 3) ignore2$ = PARSE$(cmd$, " ", 4) IF searchfor$ = "" OR searchfile$ = "" THEN STDOUT "iqFind - in-quote Find utility" STDOUT "glider@bmezine.com" STDOUT STDOUT "This software finds text strings (case insensitive) inside text files, but" STDOUT "only inside quotes or delimited strings, on a per-line basis." STDOUT STDOUT "Usage:" STDOUT " iqfind {string} filename.ext [in-file replaces]" STDOUT " {string} is the string to search for, with { and } being the quotes." STDOUT " filename.exe is the filename to search (wildcards are OK)." STDOUT " [in-file replaces] are string sequences that should be ignored (2 max)." STDOUT "For example:" STDOUT " iqfind ""hello,_world"" test.bas """"" STDOUT " ...searches test.bas for instances of 'hello, world' ('_' translates" STDOUT " into a space) inside test.bas, and uses quotes as delimiters, while" STDOUT " ignoring double quotes inside the file (since """" is used to represent" STDOUT " a quote inside a quoted string in some compilers). STDOUT "" EXIT FUNCTION END IF IF DIR$(searchfile$) = "" THEN STDOUT "Error: Could not find '" & searchfile$ & "'" STDOUT EXIT FUNCTION END IF IF INSTR(searchfile$, ANY "?*") > 0 THEN DIM filelist$(1 TO %MAXFILES) x$ = DIR$(searchfile$) numfiles = 0 DO UNTIL x$ = "" INCR numfiles filelist$(numfiles) = x$ IF numfiles = %MAXFILES THEN STDOUT "Warning: Maximum number of files reached (" & FORMAT$(numfiles, ",") & ")." STDOUT END IF x$ = DIR$ LOOP ELSE DIM filelist$(1 TO 1) numfiles = 1 filelist$(1) = searchfile$ END IF FOR t = 1 TO numfiles matches = 0 lineno = 0 searchfile$ = filelist$(t) OPEN searchfile$ FOR INPUT AS #1 STDOUT "" STDOUT "---------- " & UCASE$(searchfile$) DO UNTIL EOF(1) INCR lineno LINE INPUT #1, origline$ IF TRIM$(origline$) <> "" THEN newline$ = LCASE$(origline$) inquote = 0 tempdata$ = "" IF ignore1$ <> "" THEN REPLACE ignore1$ WITH "" IN newline$ IF ignore2$ <> "" THEN REPLACE ignore2$ WITH "" IN newline$ END IF FOR r = 1 TO LEN(newline$) thischar$ = MID$(newline$, r, 1) IF thischar$ = quoteon$ THEN inquote = 1 ELSEIF thischar$ = quoteoff$ THEN IF INSTR(tempdata$, searchfor$) > 0 THEN EXIT FOR END IF tempdata$ = "" inquote = 0 ELSE IF inquote = 1 THEN tempdata$ = tempdata$ & thischar$ END IF END IF NEXT IF inquote = 1 THEN IF INSTR(tempdata$, searchfor$) > 0 THEN INCR matches STDOUT FORMAT$(lineno, "00000") & ": " & TRIM$(origline$) END IF END IF END IF LOOP CLOSE #1 IF matches = 0 THEN STDOUT "(no matches)" END IF STDOUT NEXT END FUNCTION