/*Subprocedure to compare the lines in a selected set of text files*/



/*Begin reading in each selected file-line by-line*/
M = 0
ReadFileLine. = ""
ReadFilePath. = ""
ReadFileName. = ""
ReadFileTree. = ""
ScanLineResults. = ""
ScanFilePathResults. = ""
ScanFileNameResults. = ""
ScanSysFileTreeResults. = ""
FileType. = ""
DO J = 1 TO OtherServicesFilePath.0 BY 1
	/*Begin reading in the lines in each file*/
	CALL ON ERROR NAME BINARY	/*Go to the BINARY routine, if an error occurs, using LINEIN*/
	ScanPath = OtherServicesFilePath.J
	K = 0
	M = M + 1
	BinaryFlag = 0
	DO WHILE Lines(ScanPath)
		K = K + 1
		ReadFileLine.M.K = LINEIN(ScanPath)
	END

	SELECT
		WHEN BinaryFlag = 0 THEN DO
			ReadFilePath.M = ScanPath
			ReadFileTree.M = OtherServicesFileDirectory.J
			Remainder = ReadFilePath.M
			Data = Remainder
			DO UNTIL Remainder = ""
				PARSE VAR Data First "\" Remainder
				Data = Remainder				
			END	/*Ends "DO UNTIL Remainder = """ Section*/
			ReadFileName.M = First
			ReadFileLine.M.0 = K
			FileType.M = "ASCII"
			RC = LineOut(ScanPath)
		END	/*Ends "WHEN BinaryFlag = 0 THEN DO" Section*/

		OTHERWISE NOP
	END	/*Ends "SELECT" Section*/
END J	/*End "DO J = 1 TO OtherServicesFilePath.0 BY 1" Section*/
ReadFileLine.0 = M
/*End reading in each selected file line-by-line*/



/*Begin comparing the lines of each file, two (2) files at a time*/
R = 0
StopValue = (ReadFileLine.0 - 1)
DO J = 1 TO StopValue BY 1
	SELECT
		WHEN FileType.J = "ASCII" THEN DO
			StartValue = J + 1
			DO K = StartValue TO ReadFileLine.0 BY 1
				R = R + 1
				S = 0
				IF FileType.K = "binary" THEN ITERATE
				Question = "FALSE"	/*Question = "FALSE", when there are no line-by-line comparison differences in the forward comparison of two (2) files*/
				Question1 = "FALSE"	/*Question1 = "FALSE", when there are no line-by-line comparison differences in this now forward comparison of the two (2) files*/
				DO L = 1 TO ReadFileLine.J.0 BY 1
					Question2 = "FALSE"	/*Question2 = "FALSE", when the line to compare do not commpare, or equal, any line in the compare to file*/
					LineToCompare = TRANSLATE(ReadFileLine.J.L)
					M = 0
					DO UNTIL M = ReadFileLine.K.0 | Question2 = "TRUE"
						M = M + 1
						IF LineToCompare = TRANSLATE(ReadFileLine.K.M) THEN Question2 = "TRUE"
					END	/*Ends "DO UNTIL M = ReadFileLine.K.0 | Question2 = "TRUE"" Section*/

					SELECT
						WHEN Question2 = "TRUE" THEN NOP

						WHEN Question2 = "FALSE" & Question1 = "FALSE" THEN DO
							Question = "TRUE"
							Question1 = "TRUE"
							S = S + 1
							ScanFilePathResults.R = '"'ReadFileName.J'" and "'ReadFileName.K'"'
							ScanLineResults.R.S = '*** The following line(s) in "'ReadFileName.J'" do not compare to any line in "'ReadFileName.K'" (excludes capitalization differences) ***'
							S = S + 1
							CALL SPACEIT
							ScanLineResults.R.S = "L"L":"RequiredSpace||ReadFileLine.J.L
						END	/*Ends "WHEN Question2 = "FALSE" & Question1 = "FALSE" THEN DO" Section*/

						WHEN Question2 = "FALSE" & Question1 = "TRUE" THEN DO
							S = S + 1
							CALL SPACEIT
							ScanLineResults.R.S = "L"L":"RequiredSpace||ReadFileLine.J.L
						END	/*Ends "WHEN Question2 = "FALSE" & Question1 = "TRUE" THEN DO" Section*/

						OTHERWISE NOP
					END	/*Ends "SELECT" Section*/
				END L	/*Ends "DO L = 1 TO ReadFileLine.J.0 BY 1" Section*/


				Question1 = "FALSE"	/*Question1 = "FALSE", when there are no line-by-line comparison differences in this now reverse comparison the two (2) files*/
				DO L = 1 TO ReadFileLine.K.0 BY 1
					Question2 = "FALSE"	/*Question2 = "FALSE", when the line to compare does not commpare, or equal, any line in the compare to file*/
					LineToCompare = TRANSLATE(ReadFileLine.K.L)
					M = 0
					DO UNTIL M = ReadFileLine.J.0 | Question2 = "TRUE"
						M = M + 1
						IF LineToCompare = TRANSLATE(ReadFileLine.J.M) THEN Question2 = "TRUE"
					END	/*Ends "DO UNTIL M = ReadFileLine.K.0 | Question2 = "TRUE"" Section*/

					SELECT
						WHEN Question2 = "TRUE" THEN NOP

						WHEN Question2 = "FALSE" & Question1 = "FALSE" THEN DO
							Question1 = "TRUE"
							SELECT
								WHEN Question = "FALSE" THEN
								ScanFilePathResults.R = '"'ReadFileName.J'" and "'ReadFileName.K'"'

								OTHERWISE DO
									S = S + 1
									ScanLineResults.R.S = "     "
								END	/*Ends "OTHERWISE DO" Section*/
							END	/*Ends "SELECT" Section*/
							S = S + 1
							ScanLineResults.R.S = '*** The following line(s) in "'ReadFileName.K'" do not compare to any line in "'ReadFileName.J'" (excludes capitalization differences) ***'
							S = S + 1
							CALL SPACEIT
							ScanLineResults.R.S = "L"L":"RequiredSpace||ReadFileLine.K.L
						END	/*Ends "WHEN Question2 = "FALSE" & Question1 = "FALSE" THEN DO" Section*/

						WHEN Question2 = "FALSE" & Question1 = "TRUE" THEN DO
							S = S + 1
							CALL SPACEIT
							ScanLineResults.R.S = "L"L":"RequiredSpace||ReadFileLine.K.L
						END	/*Ends "WHEN Question2 = "FALSE" & Question1 = "TRUE" THEN DO" Section*/

						OTHERWISE NOP
					END	/*Ends "SELECT" Section*/
				END L	/*Ends "DO L = 1 TO ReadFileLine.K.0 BY 1" Section*/
				ScanLineResults.R.0 = S
				IF ScanLineResults.R.0 = 0 THEN DO
					ScanFilePathResults.R = '"'ReadFileName.J'" and "'ReadFileName.K'"'
					S = S + 1
					ScanLineResults.R.S = 'There are no differences between "'ReadFileName.J'" and "'ReadFileName.K'"'
					ScanLineResults.R.0 = S
				END
			END K	/*Ends "DO K = StartValue TO ReadFileLine.0 BY 1" Section*/
		END	/*Ends "WHEN FileType.M = "ASCII" THEN DO" Section*/

		WHEN FileType.J = "binary" THEN DO
			ScanFilePathResults.R = '"'ReadFileName.J'" and nothing else'
			S = S + 1
			ScanLineResults.R.S = 'Sorry! "'ReadFileName.J'" appears to be a binary file.'
		END	/*Ends "WHEN FileType.M = "binary" THEN DO" Section*/

		OTHERWISE NOP
	END	/*Ends "SELECT" Section*/
END J	/*Ends "DO J = 1 TO StopValue BY 1" Section*/
ScanLineResults.0 = R
ScanFilePathResults.0 = R
RETURN









/*Begin the error trap coding for binary files*/
BINARY:
BinaryFlag = 1
FileType.M = "binary"
RETURN
/*End the error trap coding for binary files*/









/*Begin setting the RequiredSpace variable*/
SPACEIT:
NumberOfDigits = LENGTH(L)
SELECT
	WHEN NumberOfDigits = 1 THEN RequiredSpace = "      "
	WHEN NumberOfDigits = 2 THEN RequiredSpace = "     "
	WHEN NumberOfDigits = 3 THEN RequiredSpace = "    "
	WHEN NumberOfDigits = 4 THEN RequiredSpace = "   "
	WHEN NumberOfDigits = 5 THEN RequiredSpace = "  "
	WHEN NumberOfDigits = 6 THEN RequiredSpace = " "
	OTHERWISE NOP
END	/*Ends "SELECT" Section*/
RETURN
/*End setting the RequiredSpace variable*/
