home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / diff.c < prev    next >
C/C++ Source or Header  |  1992-02-23  |  4KB  |  161 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Id: diff.c,v 1.12 89/11/19 23:40:34 berliner Exp $";
  3. #endif 
  4.  
  5. /*
  6.  *    Copyright (c) 1989, Brian Berliner
  7.  *
  8.  *    You may distribute under the terms of the GNU General Public License
  9.  *    as specified in the README file that comes with the CVS 1.0 kit.
  10.  *
  11.  * Difference
  12.  *
  13.  *    Run diff against versions in the repository.  Options that
  14.  *    are specified are passed on directly to "rcsdiff".
  15.  *
  16.  *    Without any file arguments, runs diff against all the
  17.  *    currently modified files, as listed in the CVS.adm/Mod file.
  18.  */
  19.  
  20. #include "cvs.h"
  21.  
  22. diff(argc, argv)
  23.     int argc;
  24.     char *argv[];
  25. {
  26.     register int i;
  27.     char rev1[50], rev2[50], tmp[MAXPATHLEN];
  28.     char *revision;
  29.     int c, numopt, err = 0;
  30.  
  31.     if (argc == -1)
  32.     diff_usage();
  33.     Name_Repository();
  34.     /*
  35.      * Note that we catch all the valid arguments here, so that we
  36.      * can intercept the -r arguments for doing revision diffs
  37.      */
  38.     rev1[0] = rev2[0] = '\0';
  39.     optind = 1;
  40.     while ((c = getopt(argc, argv, "biwtcefhnqr:")) != -1) {
  41.     switch (c) {
  42.     case 'b':    case 'i':    case 'w':
  43.     case 't':    case 'c':    case 'e':
  44.     case 'f':    case 'h':    case 'n':
  45.     case 'q':
  46.         /* Get_Options will take care of these */
  47.         break;
  48.     case 'r':
  49.         if (rev2[0] != '\0')
  50.         error(0, "no more than two revisions can be specified");
  51.         if (rev1[0] != '\0') {
  52.         (void) strcpy(rev2, optarg);
  53.         } else {
  54.         (void) strcpy(rev1, optarg);
  55.         }
  56.         *optarg = '\0';        /* strip the -r */
  57.         break;
  58.     case '?':
  59.     default:
  60.         diff_usage();
  61.         break;
  62.     }
  63.     }
  64.     numopt = Get_Options(--argc, ++argv);
  65.     argc -= numopt;
  66.     argv += numopt;
  67.     if (argc == 0) {
  68.     if (rev2[0] != '\0')
  69.         Find_Names(&fileargc, fileargv, MOD);
  70.     else
  71.         Find_Names(&fileargc, fileargv, ALL);
  72.     argc = fileargc;
  73.     argv = fileargv;
  74.     if (rev2[0] == '\0') {
  75.         for (i = 0; i < fileargc; i++) {
  76.         (void) strcpy(User, fileargv[i]);
  77.         Locate_RCS();
  78.         if (rev1[0] != '\0') {
  79.             revision = rev1;
  80.         } else {
  81.             Version_TS(Rcs, Tag, User);
  82.             if (VN_User[0] == '\0' || VN_User[0] == '-' ||
  83.             (VN_User[0] == '0' && VN_User[1] == '\0')) {
  84.             fileargv[i][0] = '\0';
  85.             } else if (VN_Rcs[0] == '\0' || TS_User[0] == '\0' ||
  86.                    strcmp(TS_Rcs, TS_User) == 0) {
  87.             fileargv[i][0] = '\0';
  88.             } else {
  89.             revision = VN_User;
  90.             }
  91.         }
  92.         if (fileargv[i][0] != '\0') {
  93.             (void) sprintf(tmp, "%s%c%s%s", CVSADM, DIRSEP, CVSPREFIX, User);
  94.             (void) sprintf(prog, "%s -p -q -r%s %s >%s",
  95.                    RCS_CO, revision, Rcs, tmp);
  96.             if (system(prog) == 0 && xcmp(User, tmp) == 0)
  97.             fileargv[i][0] = '\0';
  98.             (void) unlink(tmp);
  99.         }
  100.         }
  101.     }
  102.     }
  103.     for (i = 0; i < argc; i++) {
  104.     if (argv[i][0] == '\0')
  105.         continue;
  106.     (void) strcpy(User, argv[i]);
  107.     Locate_RCS();
  108.     Version_TS(Rcs, Tag, User);
  109.     if (VN_User[0] == '\0') {
  110.         warn(0, "I know nothing about %s", User);
  111.         continue;
  112.     } else if (VN_User[0] == '0' && VN_User[1] == '\0') {
  113.         warn(0, "%s is a new entry, no comparison available",
  114.          User);
  115.         continue;
  116.     } else if (VN_User[0] == '-') {
  117.         warn(0, "%s was removed, no comparison available",
  118.          User);
  119.         continue;
  120.     } else {
  121.         if (VN_Rcs[0] == '\0') {
  122.         warn(0, "cannot find %s", Rcs);
  123.         continue;
  124.         } else {
  125.         if (TS_User[0] == '\0') {
  126.             warn(0, "cannot find %s", User);
  127.             continue;
  128.         }
  129.         }
  130.     }
  131.     (void) fflush(stdout);
  132.     if (i != 0) {
  133.         printf("===================================================================\n");
  134.         (void) fflush(stdout);
  135.     }
  136.     if (rev2[0] != '\0') {
  137.         (void) sprintf(prog, "%s %s -r%s -r%s %s", RCS_DIFF,
  138.                Options, rev1, rev2, Rcs);
  139.     } else if (rev1[0] != '\0') {
  140.         (void) sprintf(prog, "%s %s -r%s %s", RCS_DIFF,
  141.                Options, rev1, Rcs);
  142.     } else {
  143.         (void) sprintf(prog, "%s %s -r%s %s", RCS_DIFF,
  144.                Options, VN_User, Rcs);
  145.     }
  146. #ifndef OS2
  147.     (void) strcat(prog, " 2>&1");
  148. #endif
  149.     err += system(prog);
  150.     (void) fflush(stdout);
  151.     }
  152.     exit(err);
  153. }
  154.  
  155. diff_usage()
  156. {
  157.     (void) fprintf(stderr, "%s %s [rcsdiff-options] [files...]\n", progname,
  158.            command);
  159.     exit(1);
  160. }
  161.