home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 272_01 / tc.c < prev    next >
Text File  |  1987-08-22  |  2KB  |  73 lines

  1. /*
  2. **                TEXT COMPARE UTILITY
  3. **
  4. **   Copyright 1987, S.E. Margison
  5. **
  6. **   This short utility compares two text files and shows
  7. **   any line differences.
  8. **
  9. **   As distributed, this program requires (for compilation):
  10. **     "Steve's Datalight Library" version 1.10 or later
  11. **   which may be obtained without registration from many Bulletin
  12. **   Board Systems including:
  13. **      Compuserve IBMSW
  14. **      Cul-De-Sac (Holliston, MA.)
  15. **      HAL-PC BBS (Houston, TX.)
  16. **   and software library houses including:
  17. **      Public (Software) Library (Houston, TX.)
  18. **
  19. **   or by registration:
  20. **      $10 for Docs, Small Model Library
  21. **      $25 for Docs, S, D, L, P libraries, and complete library source
  22. **              in C and Assembler
  23. **     Steven E. Margison
  24. **     124 Sixth Street
  25. **     Downers Grove, IL, 60515
  26. **
  27. **
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <smdefs.h>
  32.  
  33. main(argc, argv)
  34. int argc;
  35. char *argv[];
  36. {
  37.    FILE *fp1, *fp2;
  38.    char buf1[MAXLINE], buf2[MAXLINE];
  39.    int lc, end1, end2;
  40.    lc = 0;
  41.    end1 = end2 = NO;
  42.  
  43.    if(argc isnot 3) error("usage: TC file1 file2");
  44.  
  45.    if((fp1 = fopen(argv[1], "r")) is NULL) cant(argv[1]);
  46.  
  47.    if((fp2 = fopen(argv[2], "r")) is NULL) {
  48.       fclose(fp1);
  49.       cant(argv[2]);
  50.       }
  51.  
  52.    for(;;) {
  53.       ++lc;
  54.       if(fgets(buf1, MAXLINE, fp1) is NULL) end1 = YES;
  55.       if(fgets(buf2, MAXLINE, fp2) is NULL) end2 = YES;
  56.       if((end1 is YES) or (end2 is YES)) break;
  57.  
  58.       if(strcmp(buf1, buf2)) {
  59.          printf("Line %d in %s\n", lc, argv[1]);
  60.          printf("%s", buf1);
  61.          printf("Line %d in %s\n", lc, argv[2]);
  62.          printf("%s", buf2);
  63.          }
  64.       }
  65.    if((end1 is YES) and (end2 is NO))
  66.       printf("EOF on %s occured first\n", argv[1]);
  67.    if((end2 is YES) and (end1 is NO))
  68.       printf("EOF on %s occured first\n", argv[2]);
  69.    fclose(fp1);
  70.    fclose(fp2);
  71.    }
  72.  
  73.