/*Subprocedure to scan selected files for a desired text string*/



/*Begin scanning each selected file for the desired text*/
M = 0
ScanLineResults. = ""
ScanFilePathResults. = ""
ScanFileNameResults. = ""
ScanSysFileTreeResults. = ""
FileType. = ""
DO J = 1 TO OtherServicesFilePath.0 BY 1
	/*Begin scanning each file for the desired text*/

	/*Begin scanning under the assumption that the file type is ASCII*/
	BinaryFlag = 0
	ScanPath = OtherServicesFilePath.J
	Start = LENGTH(ScanPath) - 3
	IF Start > 0 THEN DOSExtensionTest = SUBSTR(ScanPath,Start,1)
	IF DOSExtensionTest = "." THEN FileExtension = TRANSLATE(RIGHT(ScanPath,3))
	IF FileExtension = "HLP" | FileExtension = "INF" | FileExtension = "HTM" | FileExtension = "HTML" THEN DO
		CALL BINARY
		ITERATE	/*After returning from the BINARY routine, go to the next iteration of this do loop*/
	END	/*Ends "IF FileExtension = "HLP" | FileExtension = "INF" | FileExtension = "HTM" | FileExtension = "HTML" THEN DO" Section*/

	LineResults. = ""
	CALL ON ERROR NAME BINARY	/*Go to the BINARY routine, if an error occurs, using SYSFILESEARCH*/
	CALL ON NOTREADY NAME BINARY	/*Go to the BINARY routine, if a syntax problem occurs, using SYSFILESEARCH*/
	RC = SYSFILESEARCH(SearchString,ScanPath,LineResults,N)
	IF BinaryFlag = 1 THEN DO
		CALL OFF ERROR
		CALL OFF NOTREADY
		ITERATE	/*After returning from the BINARY routine, go to the next iteration of this do loop*/
	END	/*Ends "IF BinaryFlag = 1 THEN DO" Section*/
		
	IF LineResults.0 > 0 THEN DO
		M = M + 1
		DO K = 1 TO LineResults.0 BY 1
			ScanLineResults.M.K = LineResults.K
		END K	/*Ends "DO K = 1 TO LineResults.0 BY 1" Section*/
		ScanFilePathResults.M = ScanPath
		ScanLineResults.M.0 = LineResults.0
		ScanSysFileTreeResults.M = OtherServicesFileDirectory.J

		Remainder = ScanFilePathResults.M
		Data = Remainder
		DO UNTIL Remainder = ""
			PARSE VAR Data First "\" Remainder
			Data = Remainder				
		END	/*Ends "DO UNTIL Remainder = """ Section*/
		ScanFileNameResults.M = First
		FileType.M = "ASCII"
		ITERATE
	END	/*Ends "F LineResults.0 > 0 THEN DO" Section*/
	/*End scanning under the assumption that the file type is ASCII*/


	IF LineResults.0 > 0 THEN DO
		CALL OFF ERROR
		CALL OFF NOTREADY
		ITERATE	/*If the file, above, is read, go to the next iteration of this do loop*/
			/*Note RC = 3 means that a file openning error occurred (the file is probably binary)*/
	END	/*Ends "IF LineResults.0 > 0 THEN DO" Section*/

	ELSE DO
		CALL BINARY
		ITERATE	/*After returning from the BINARY routine, go to the next iteration of this do loop*/
	END	/*Ends "ELSE DO" Section*/


	BINARY:
	/*Begin scanning under the assumption that the file type is binary*/
	BinaryFlag = 1
	ToSpace = XRange("7F"x, "1F"x)	/*These are non printing characters*/

	P = 0
	/*Begin specifying the path and filename of the binary file to read*/
	FilePathToRead = OtherServicesFilePath.J
	Remainder = FilePathToRead
	Data = Remainder
	DO UNTIL Remainder = ""
		PARSE VAR Data First "\" Remainder
		Data = Remainder
	END	/*Ends "DO UNTIL Remainder = """ Section*/
	FileName = First
	/*End specifying the path and filename of the binary file to read*/

	/*Begin reading the file, 256 characters at a time, and creating a temporary ASCII equivalent of it*/
	ReadLine. = ""
	Start = 1
	ReadLength = MIN(CHARS(FilePathToRead),256)
	DO WHILE ReadLength > 0
		P = P + 1
		ReadLine.P = CHARIN(FilePathToRead,Start,ReadLength)
		
		ReadLine.P = TRANSLATE(ReadLine.P, "^", '0A'x)	/*Remove all lines feeds and make one continuous line*/
		ReadLine.P = TRANSLATE(ReadLine.P, Copies('00'x, ReadLength), ToSpace)	/*Translate unprintable characters to spaces so that PARSE can separate printable data from binary data*/
		ReadLine.P = TRANSLATE(TRANSLATE(ReadLine.P, 'FF'x, " "), " ", '00'x)	/*Translate spaces to "FF"x so that PARSE will not break up Titles with spaces, then translate all '00'x characters to spaces*/
		Stuff = ReadLine.P
		ReadLine.P = ""
		DO WHILE Stuff \= ""
			PARSE VAR Stuff Data Stuff
			Data = STRIP(Data, "B")
			SELECT
				WHEN ReadLine.P = "" THEN ReadLine.P = Data
				WHEN ReadLine.P \= "" THEN ReadLine.P = ReadLine.P" "Data
				OTHERWISE NOP
			END	/*Ends "SELECT" Section*/
		END	/*Ends "DO WHILE Stuff \= """ Section*/
		Start = Start + ReadLength
		ReadLength = MIN(CHARS(FilePathToRead),256)
	END
	RC = STREAM(FilePathToRead,"COMMAND","CLOSE")
	ReadLine.0 = P
	TemporaryASCIIFileToWrite = ProgramLocation"\SeekTemp\"FileName" (ASCII)"
	RC = WRITE_DATA(ReadLine, TemporaryASCIIFileToWrite)
	/*End reading the file, 256 characters at a time, and creating a temporary ASCII equivalent of it*/

	/*Begin scanning the temporary ASCII equivalent file*/
	ScanPath = TemporaryASCIIFileToWrite
	LineResults. = ""
	RC = SYSFILESEARCH(SearchString,ScanPath,LineResults,N)
	IF LineResults.0 > 0 THEN DO
		M = M + 1
		DO K = 1 TO LineResults.0 BY 1
			ScanLineResults.M.K = LineResults.K
		END K	/*Ends "DO K = 1 TO LineResults.0 BY 1" Section*/
		ScanFilePathResults.M = FilePathToRead
		ScanLineResults.M.0 = LineResults.0
		ScanSysFileTreeResults.M = OtherServicesFileDirectory.J

		Remainder = ScanFilePathResults.M
		Data = Remainder
		DO UNTIL Remainder = ""
			PARSE VAR Data First "\" Remainder
			Data = Remainder				
		END	/*Ends "DO UNTIL Remainder = """ Section*/
		ScanFileNameResults.M = First
		FileType.M = "binary"
	END	/*Ends "F LineResults.0 > 0 THEN DO" Section*/
	RC = SYSFILEDELETE(TemporaryASCIIFileToWrite)
	/*End scanning under the assumption that the file type is binary*/
	RETURN
	/*End scanning each file for the desired text*/
END J	/*End "DO J = 1 TO OtherServicesFilePath.0 BY 1" Section*/
ScanFilePathResults.0 = M
/*End scanning each selected file for the desired text*/
RETURN