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

  1. #ifndef lint
  2. static char rcsid[] = "$Id: build_entry.c,v 1.9 89/11/19 23:19:45 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.  * Build Entry
  12.  *
  13.  *    Builds an entry for a new file and sets up "CVS.adm/file",[pt] by
  14.  *    interrogating the user.
  15.  *
  16.  *    Returns non-zero on error.
  17.  */
  18.  
  19. #include "cvs.h"
  20.  
  21. Build_Entry(message)
  22.     char *message;
  23. {
  24.     char fname[MAXPATHLEN];
  25.     char line[MAXLINELEN];
  26.     FILE *fp, *fptty;
  27.  
  28.     /*
  29.      * There may be an old file with the same name in the Attic!
  30.      * This is, perhaps, an awkward place to check for this, but
  31.      * other places are equally awkward.
  32.      */
  33.     (void) sprintf(fname, "%s%c%s%c%s%s",
  34.                    Repository, DIRSEP, CVSATTIC, DIRSEP, User, RCSEXT);
  35.     if (isreadable(fname)) {
  36.     warn(0, "there is an old file %s already in %s%c%s", User,
  37.          Repository, DIRSEP, CVSATTIC);
  38.     return (1);
  39.     }
  40.     /*
  41.      * The options for the "add" command are store in the file CVS.adm/User,p
  42.      */
  43.     (void) mkdir(CVSEXT_OPT, 0777);
  44.     (void) sprintf(fname, "%s%c%s", CVSEXT_OPT, DIRSEP, User);
  45.     if ((fp = open_file(fname, "w+")) == NULL)
  46.     error(1, "cannot write %s", fname);
  47.     if (fprintf(fp, "%s\n", Options) == EOF)
  48.     error(1, "cannot write %s", fname);
  49.     (void) fclose(fp);
  50.     /*
  51.      * And the requested log is read directly from the user and stored
  52.      * in the file User,t.  If the "message" argument is set, then the
  53.      * user specified the -m option to add, and it is not necessary to
  54.      * query him from the terminal.
  55.      */
  56.     (void) mkdir(CVSEXT_LOG, 0777);
  57.     (void) sprintf(fname, "%s%c%s", CVSEXT_LOG, DIRSEP, User);
  58.     if ((fp = open_file(fname, "w+")) == NULL)
  59.     error(1, "cannot write %s", fname);
  60.     if (message[0] == '\0') {
  61.     printf("RCS file: %s\n", Rcs);
  62.     printf("enter description, terminated with ^D or '.':\n");
  63.     printf("NOTE: This is NOT the log message!\n");
  64.     fptty = open_file(CONSOLE, "r");
  65.     for (;;) {
  66.         printf(">> ");
  67.         (void) fflush(stdout);
  68.         if (fgets(line, sizeof(line), fptty) == NULL ||
  69.         (line[0] == '.' && line[1] == '\n'))
  70.         break;
  71.         if (fputs(line, fp) == EOF)
  72.         error(1, "cannot write to %s", fname);
  73.     }
  74.     printf("done\n");
  75.     (void) fclose(fptty);
  76.     } else {
  77.     if (fputs(message, fp) == EOF)
  78.         error(1, "cannot write to %s", fname);
  79.     }
  80.     (void) fclose(fp);
  81.     /*
  82.      * Create the entry now, since this allows the user to interrupt
  83.      * us above without needing to clean anything up (well, we could
  84.      * clean up the ,p and ,t files, but who cares).
  85.      */
  86.     (void) sprintf(line, "Initial %s", User);
  87.     Register(User, "0", line);
  88.     return (0);
  89. }
  90.