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

  1. /*
  2.    checkout.c
  3.    The Revision Control System
  4.  
  5.    Dwayne Phillips
  6.    November1991
  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, *rcs_file, *source_file;
  18.    int    extra_file = 0, rev = 0;
  19.  
  20.    if(argc <  2   ||   argc > 4){
  21.       printf("\n\n\tusage: checkout [-r#] source-file"
  22.              " [output-file]\n");
  23.       exit(1);
  24.    }
  25.  
  26.    if(argc == 2){
  27.       strcpy(source_name, argv[1]);
  28.       rev = 0;
  29.    }
  30.  
  31.    if(argc == 3){
  32.           /* checkout -r# source-name */
  33.       if( (strncmp(argv[1], "-r", 2) == 0)){
  34.          strcpy(string, argv[1]);
  35.          strcpy(source_name, argv[2]);
  36.          rev = rev_number(string);
  37.       }
  38.  
  39.           /* checkout source-name output-name */
  40.       if( (strncmp(argv[1], "-r", 2) != 0)){
  41.          extra_file = 1;
  42.          rev        = 0;
  43.          strcpy(source_name, argv[1]);
  44.          strcpy(output_name, argv[2]);
  45.       }
  46.    }  /* ends if argc == 3 */
  47.  
  48.  
  49.       /* checkout -r# source-name output-name */
  50.    if(argc == 4){
  51.       if( (strncmp(argv[1], "-r", 2) != 0)){
  52.          printf("\n\n\tusage: checkout [-r#] source-file"
  53.                 " [output-file]\n");
  54.          exit(1);
  55.       }
  56.       else{
  57.          extra_file = 1;
  58.          rev        = rev_number(argv[1]);
  59.          strcpy(source_name, argv[2]);
  60.          strcpy(output_name, argv[3]);
  61.       }
  62.    }
  63.  
  64.    create_rcs_file_name(source_name, rcs_name);
  65.  
  66.    if((rcs_file = fopen(rcs_name, "r")) == '\0'){
  67.       printf("\ncheckout>> "
  68.              "cannot open the rcs file >>%s<<",
  69.              rcs_name);
  70.       exit(-1);
  71.    }
  72.  
  73.    if(extra_file == 1){ /* open output_name for writing */
  74.       if((output_file = fopen(output_name, "w")) == '\0'){
  75.          printf("\ncheckout>> "
  76.                 "cannot open the output file >>%s<<",
  77.                 output_name);
  78.          exit(-1);
  79.       }
  80.    }  /* ends if extra_file == 1 */
  81.  
  82.    else{ /* else open source_name for writing */
  83.       if((source_file = fopen(source_name, "w")) == '\0'){
  84.          printf("\ncheckout>> "
  85.                 "cannot open the source file >>%s<<",
  86.                 source_name);
  87.          exit(-1);
  88.       }
  89.    }  /* ends else extra_file == 0 */
  90.  
  91.    if(extra_file == 1){  /* use output file */
  92.       if(rev == 0)
  93.          copy_latest_rcs_to_source(rcs_file, output_file);
  94.       else{
  95.          go_to_correct_rev(rcs_file, rev);
  96.          copy_rcs_to_source(rcs_file, output_file);
  97.       }
  98.    }
  99.    else{  /* else use source_file */
  100.       if(rev == 0)
  101.          copy_latest_rcs_to_source(rcs_file, source_file);
  102.       else{
  103.          go_to_correct_rev(rcs_file, rev);
  104.          copy_rcs_to_source(rcs_file, source_file);
  105.       }
  106.    }
  107.  
  108.    fclose(rcs_file);
  109.    if(extra_file == 1)
  110.       fclose(output_file);
  111.    else
  112.       fclose(source_file);
  113.  
  114. }
  115.  
  116.  
  117.