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

  1. #ifndef lint
  2. static char rcsid[] = "$Id: remove.c,v 1.9 89/11/19 23:40:43 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.  * Remove a File
  12.  *
  13.  *    Removes entries from the present version.
  14.  *    The entries will be removed from the RCS repository upon the
  15.  *    next "commit".
  16.  *
  17.  *    "remove" accepts no options, only file names that are to be
  18.  *    removed.  The file must not exist in the current directory
  19.  *    for "remove" to work correctly.
  20.  */
  21.  
  22. #include "cvs.h"
  23.  
  24. _remove(argc, argv)
  25.     int argc;
  26.     char *argv[];
  27. {
  28.     register int i;
  29.     char fname[MAXPATHLEN];
  30.     int err = 0;
  31.  
  32.     if (argc == 1 || argc == -1)
  33.     remove_usage();
  34.     argc--;
  35.     argv++;
  36.     Name_Repository();
  37.     for (i = 0; i < argc; i++) {
  38.     (void) strcpy(User, argv[i]);
  39.     Version_TS(Rcs, Tag, User);
  40.     if (TS_User[0] != '\0') {
  41.         warn(0, "%s still exists", User);
  42.         err++;
  43.         continue;
  44.     }
  45.     if (VN_User[0] == '\0') {
  46.         warn(0, "there is no entry for %s", User);
  47.         err++;
  48.     } else if (VN_User[0] == '0' && VN_User[1] == '\0') {
  49.         /*
  50.          * It's a file that has been added, but not commited yet.
  51.          * So, remove the ,p and ,t file for it and scratch it from
  52.          * the entries file.
  53.          */
  54.         Scratch_Entry(User);
  55.         (void) sprintf(fname, "%s%c%s", CVSEXT_OPT, DIRSEP, User);
  56.         (void) unlink(fname);
  57.         (void) rmdir(CVSEXT_OPT);
  58.         (void) sprintf(fname, "%s%c%s", CVSEXT_LOG, DIRSEP, User);
  59.         (void) unlink(fname);
  60.         (void) rmdir(CVSEXT_LOG);
  61.     } else if (VN_User[0] == '-') {
  62.         /*
  63.          * It's already been flagged for removal, nothing more to do.
  64.          */
  65.         warn(0, "%s was already removed", User);
  66.         err++;
  67.     } else {
  68.         /*
  69.          * Re-register it with a negative version number.
  70.          */
  71.         (void) strcpy(fname, "-");
  72.         (void) strcat(fname, VN_User);
  73.         Register(User, fname, TS_Rcs);
  74.     }
  75.     }
  76.     Entries2Files();            /* and update the Files file */
  77.     exit(err);
  78. }
  79.  
  80. static
  81. remove_usage()
  82. {
  83.     (void) fprintf(stderr, "%s %s files...\n", progname, command);
  84.     exit(1);
  85. }
  86.