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

  1. /*
  2.    checkin.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   rcs_name[80], source_name[80], string[80];
  16.    FILE   *rcs_file, *source_file, *xxx_file;
  17.    int    leave_source = 0, one = 1, result, rev;
  18.    struct stat rcs_file_status;
  19.  
  20.    if( (argc <  2) || (argc > 3)){
  21.       printf("\n\n\tusage: checkin [-l] source-file\n");
  22.       exit(1);
  23.    }
  24.  
  25.    if(argc == 2){
  26.       strcpy(source_name, argv[1]);
  27.       if((source_file = fopen(source_name, "r")) == '\0'){
  28.          printf("\ncheckin>> "
  29.                 "cannot open the source file >>%s<<",
  30.                 source_name);
  31.          exit(-1);
  32.       }
  33.    }
  34.  
  35.    if(argc == 3){
  36.       if( (strncmp("-l", argv[1], 2) == 0)){
  37.          leave_source = 1;
  38.          strcpy(source_name, argv[2]);
  39.          if((source_file = fopen(source_name, "r")) == '\0'){
  40.             printf("\ncheckin>> "
  41.                    "cannot open the source file >>%s<<",
  42.                    source_name);
  43.             exit(-1);
  44.          }
  45.       }
  46.       else{
  47.          printf("\n\n\tusage: checkin [-l] source-file\n");
  48.          exit(3);
  49.       }
  50.    }  /* ends if argc == 3 */
  51.  
  52.    create_rcs_file_name(source_name, rcs_name);
  53.  
  54.       /*  does an rcs file already exist? */
  55.  
  56.    result = stat(rcs_name, &rcs_file_status);
  57.  
  58.    if(result == -1){ /* rcs file does not yet exist */
  59.       if((rcs_file = fopen(rcs_name, "w")) == '\0'){
  60.          printf("\ncheckin>> "
  61.                 "cannot create the rcs file >>%s<<",
  62.                 rcs_name);
  63.          exit(-1);
  64.       }
  65.       else{
  66.          get_header_lines(rcs_file, one);
  67.          copy_source_to_rcs(source_file, rcs_file);
  68.          fclose(rcs_file);
  69.          fclose(source_file);
  70.          if(leave_source == 0)
  71.             unlink(source_name);
  72.       }  /* ends else we can create the rcs file */
  73.    }  /* ends if result == -1 */
  74.  
  75.    if(result == 0){ /* rcs file already exists */
  76.       if((rcs_file = fopen(rcs_name, "r")) == '\0'){
  77.          printf("\ncheckin>> "
  78.                 "cannot open the rcs file >>%s<<",
  79.                 rcs_name);
  80.          exit(-1);
  81.       }
  82.       get_latest_revision_number(rcs_file, &rev);
  83.       rev++;
  84.       fseek(rcs_file, 0L, SEEK_SET);
  85.  
  86.       if((xxx_file = fopen("RCS/((((", "w")) == '\0'){
  87.          printf("\ncheckin>> "
  88.                 "cannot create the temp file ((((");
  89.          exit(-1);
  90.       }
  91.       get_header_lines(xxx_file, rev);
  92.  
  93.       copy_source_to_rcs(source_file, xxx_file);
  94.       while( fgets(string, 80, rcs_file) != '\0')
  95.          fputs(string, xxx_file);
  96.  
  97.       fclose(xxx_file);
  98.       fclose(rcs_file);
  99.       fclose(source_file);
  100.       unlink(rcs_name);
  101.       if(leave_source == 0)
  102.          unlink(source_name);
  103.  
  104.       sprintf(string, "copy RCS/(((( %s", rcs_name);
  105.       replace_slash(string);
  106.       system(string);
  107.       unlink("RCS/((((");
  108.  
  109.    }  /* ends if result == 0 */
  110.  
  111. }  /* ends main  */
  112.  
  113. /*
  114.    copy_source_to_rcs(FILE *source_file, FILE *rcs_file)
  115. */
  116.  
  117. copy_source_to_rcs(FILE *source_file, FILE *rcs_file)
  118. {
  119.    char line[80];
  120.    while( fgets(line, 80, source_file) != '\0'){
  121.     fputs(line, rcs_file);
  122.    }
  123.    fputs(DELIMETER, rcs_file);
  124. }
  125.  
  126. /*
  127.    get_latest_revision_number(FILE *rcs_file, int *rev)
  128. */
  129.  
  130. get_latest_revision_number(FILE *rcs_file, int *rev)
  131. {
  132.    char *line;
  133.    fgets(line, 80, rcs_file);
  134.    fgets(line, 80, rcs_file);
  135.    *rev = atoi(line);
  136. }
  137.  
  138.  
  139.