home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_07 / 1107044a < prev    next >
Text File  |  1993-04-30  |  3KB  |  121 lines

  1. /*
  2.    revdiff.c
  3.    The Revision Control System
  4.  
  5.    Dwayne Phillips
  6.    November 1991
  7. */
  8.  
  9. #include "rcs.h"
  10.  
  11. main(argc, argv)
  12.    int argc;
  13.    char *argv[];
  14. {
  15.    char   output_name[80], rcs_name[80], source_name[80],
  16.           string[80];
  17.    FILE   *output_file, *output2_file, *rcs_file, 
  18.           *source_file;
  19.    int    extra_file = 0, rev = 0, rev2 = 0;
  20.  
  21.    if((argc <  2) || (argc > 4)){
  22.       printf("\n\n\tusage: revdiff [-r#] [-r#] source-file\n");
  23.       exit(1);
  24.    }
  25.  
  26.       /* copy latest revision to a temp file
  27.          and run fc on the source file and temp file */
  28.    if(argc == 2){
  29.       strcpy(source_name, argv[1]);
  30.       rev = 0;
  31.    }
  32.           /* revdiff -r# source-file */
  33.    if(argc == 3){
  34.       if( (strncmp(argv[1], "-r", 2) == 0)){
  35.          strcpy(string, argv[1]);
  36.          strcpy(source_name, argv[2]);
  37.          rev = rev_number(string);
  38.       }
  39.       else{
  40.          printf("\n\n\tusage: revdiff [-r#] [-r#] source-file\n");
  41.          exit(1);
  42.       }
  43.    }
  44.  
  45.          /* revdiff -r#1 -r#2 source-file */
  46.    if(argc == 4){
  47.       if(  (strncmp(argv[1], "-r", 2) == 0)  &&
  48.            (strncmp(argv[2], "-r", 2) == 0)){
  49.          extra_file = 1;
  50.          strcpy(string, argv[1]);
  51.          rev  = rev_number(string);
  52.          strcpy(string, argv[2]);
  53.          rev2 = rev_number(string);
  54.          strcpy(source_name, argv[3]);
  55.       }
  56.       else{
  57.          printf("\n\n\tusage: revdiff [-r#] [-r#] source-file\n");
  58.          exit(1);
  59.       }
  60.    }
  61.  
  62.    create_rcs_file_name(source_name, rcs_name);
  63.  
  64.    if((rcs_file = fopen(rcs_name, "r")) == '\0'){
  65.       printf("\nrevdiff>> "
  66.              "cannot open the rcs file >>%s<<",
  67.              rcs_name);
  68.       exit(-1);
  69.    }
  70.  
  71.    if((output_file = fopen("((((", "w")) == '\0'){
  72.       printf("\nrevdiff>> cannot open the temp file ((((");
  73.       exit(-1);
  74.    }
  75.  
  76.    if(extra_file == 1){
  77.       if((output2_file = fopen("((((2", "w")) == '\0'){
  78.          printf("\nrevdiff>> cannot open the temp file ((((2");
  79.          exit(-1);
  80.       }
  81.    }
  82.  
  83.    if(extra_file == 0){
  84.       if(rev == 0)
  85.          copy_latest_rcs_to_source(rcs_file, output_file);
  86.       else{
  87.          go_to_correct_rev(rcs_file, rev);
  88.          copy_rcs_to_source(rcs_file, output_file);
  89.       }
  90.    }
  91.    else{
  92.       go_to_correct_rev(rcs_file, rev);
  93.       copy_rcs_to_source(rcs_file, output_file);
  94.       fseek(rcs_file, 0L, SEEK_SET);
  95.       go_to_correct_rev(rcs_file, rev2);
  96.       copy_rcs_to_source(rcs_file, output2_file);
  97.    }
  98.  
  99.    fclose(rcs_file);
  100.    fclose(output_file);
  101.    if(extra_file == 1)
  102.       fclose(output2_file);
  103.  
  104.       /* Use DOS's fc to compare files */
  105.    if(extra_file == 0){
  106.       replace_slash(source_name);
  107.       sprintf(string, "fc /L /N %s ((((", source_name);
  108.       system(string);
  109.    }
  110.    else{
  111.       sprintf(string, "fc (((( ((((2");
  112.       system(string);
  113.    }
  114.  
  115.    unlink("((((");
  116.    if(extra_file == 1)
  117.       unlink("((((2");
  118.  
  119.  
  120.