/**************************************************************** * Module name : compare.c * * Purpose : Compares two files & reports errors * * Created : ??-??-89 * * Last edited : 24-08-89 Version 1.0 * * Copyright : G R Buckeridge * ****************************************************************/ #include stdio.h #define MAXINT 32767 main(argc,argv) int argc; char *argv[]; { FAST char argv_buffer[MAXARGS * 2 +132]; FILE *in1,*in2; int start,addr,ch1,ch2,fail,first; cpm_cmd_line (&argc,&argv,argv_buffer); /* for reading command line */ if (argc==1) { printf("\n\tThis utility compares two files and reports any differences.\n"); printf("\n\tIts command line takes the form :- \n"); printf("\n\t\tCOMPARE FILE1.TXT FILE2.TXT 0\n"); printf("\n\tThe zero as the last argument denotes the optional start address.\n"); printf("\n\tIf not included the start address is assumed to be 100 Hex.\n"); printf("\n\tCan be aborted at any time with ctrl-C.\n"); exit(0); } if (argc<3 || argc>4) { printf("\nBad command line\n"); exit(0); } in1=fopen(argv[1],"r"); in2=fopen(argv[2],"r"); if (in1 == NULL) { printf("\nCan't open file %s\n",argv[1]); exit(0); } if (in2 == NULL) { printf("\nCan't open file %s\n",argv[2]); exit(0); } if (argc==3) addr=0x100; else addr=atoi(argv[3]); start=addr; fail=FALSE; first=FALSE; for(;;++addr) { if (keyhit()==TRUE && rawin()==3) { printf("\nUser Aborted\n"); exit(0); } ch1=getc(in1); ch2=getc(in2); if(ch1==EOF && ch2==EOF) break; if(ch1==EOF) { printf("\n%s shorter than %s\n",argv[1],argv[2]); break; } if(ch2==EOF) { printf("\n%s shorter than %s\n",argv[2],argv[1]); break; } if (ch1 != ch2) { fail=TRUE; if (first==FALSE) { first=TRUE; printf("\n"); } printf("%04x = %02x - ( %02x )\n",addr,ch1,ch2); } else first=FALSE; } if (fail==FALSE) { printf("\n%s equals %s",argv[1],argv[2]); printf(" ..... [%04x-%04x]\n",start,addr); } fclose(in1); fclose(in2); } #include ?cpm.lib #include ?stdio.lib ..... [%04x-%04x]\n",start,addr); } fclose(in1);