Comparing BASIC Programs
P. Kenneth Morse
This compact utility for the IBM PC/PCjr and compatibles compares two BASIC programs line by line, reporting any differences between the two files.
If you program in BASIC on MS-DOS/PC-DOS machines, it's not uncommon to find that you have two or more copies of a BASIC program with similar filenames. How can you tell for certain which is the most recent copy? DOS provides a utility called COMP.COM, but this program reports differences in the files in terms of offsets to mismatched bytes—not particularly useful information for BASIC programmers.
"COMPARE.BAS" compares two BASIC programs even if they are of different lengths, reporting any lines in one program that are not duplicated in another. It generates a complete printout of lines that are not the same in both line number and content. The program is written for IBM BASICA. It should run without modification in PCjr Cartridge BASIC, GW-BASIC, or other PC-compatible BASICs.
Enter the program and save a copy before you run it. Also before running the program, make sure that the two programs you wish to compare are saved in ASCII (non-tokenized) format. To save a program in ASCII format, append ,A to the end of a normal SAVE command. For example, the command SAVE "PROGRAM", A saves the file named PROGRAM in ASCII form.
When you run the program, it prompts you to enter the filespec (drive, path, and filename) for each of the two files you wish to compare. At the same time, make sure that your printer is turned on and ready to print. If you have a second drive or a RAMdisk, you can speed up the comparison by placing the files on separate drives.
COMPARE.BAS
For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs" elsewhere in this issue.
PJ 100 ‘Copyright 1987 PL 110 ‘Compute! Publications, Inc. LC 120 ‘All Rights Reserved. BA 125 CLS CP 130 PRINT TAB (30); "Copyright 1987" BC 140 PRINT TAB (25); "Compute! Publications, Inc." GN 160 PRINT : PRINT MB 190 LINE INPUT "File name of #1 is ", FILE * $(1) AA 200 LINE INPUT "File name of #2 is ", FILE$(2) QI 210 OPEN FILE$(1) FOR INPUT AS #1 DL 220 OPEN FILE$(2) FOR INPUT AS #2 FF 230 LPRINT "File comparison : [1] = ";FILE$(1);"[ 2] = "; FILE$ (2) JC 240 LPRINT IE 250 GOSUB 400 : IF L1$ = "0" THE N 330 II 260 GOSUB 420 : IF L2$ = "0" THE N 390 MH 270 IF L1$ = L2$ THEN 250 KB 280 IF L1 = VAL(LI$) : L2 = VAL (L2$) MJ 290 ON SGN (L1 - L2) + 2 GOTO 310, 350, 370 FI 300 " Lower line number in file 1 PH 310 LPRINT "[1] " ;L1$ : GOSUB 400 : IF L1$ <> "0" THEN 270 EN 320 LPRINT "[2] "; L2$ DO 330 GOSUB 420 : IF L2$ <> "0" THEN 320 ELSE CLOSE : END FC 340 ‘Same line number in both files AF 350 LPRINT "[1] ";L1$ : LPRINT "[2] "; L2$ : GOTO 250 HF 360 ‘Lower line number in file 2 JK 370 LPRINT "[2] ";L1$ : GOSUB 420 : IF L2$ <> "0" THEN 270 CH 380 LPRINT "[1] "; L1$ OB 390 GOSUB 400 : IF L1$ <> "0" THEN 380 ELSE CLOSE : END IM 400 IF EOF(1) = 0 THEN LINE INPUT #1, L1$ ELSE L1$ = "" MA 410 RETURN QO 420 IF EOF(2) = 0 THEN LINE INPUT #2, L2$ ELSE L2$ = "0" ME 430 RETURN