home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / rcs567s.zip / rcs / src / ci.c next >
Text File  |  1994-03-20  |  37KB  |  1,300 lines

  1. /* Check in revisions of RCS files from working files.  */
  2.  
  3. /* Copyright 1982, 1988, 1989 Walter Tichy
  4.    Copyright 1990, 1991, 1992, 1993, 1994 Paul Eggert
  5.    Distributed under license by the Free Software Foundation, Inc.
  6.  
  7. This file is part of RCS.
  8.  
  9. RCS is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2, or (at your option)
  12. any later version.
  13.  
  14. RCS is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with RCS; see the file COPYING.  If not, write to
  21. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Report problems and direct all questions to:
  24.  
  25.     rcs-bugs@cs.purdue.edu
  26.  
  27. */
  28.  
  29. /*
  30.  * $Log: ci.c,v $
  31.  * Revision 5.28  1994/03/20 04:52:58  eggert
  32.  * Do not generate a corrupted RCS file if the user modifies the working file
  33.  * while `ci' is running.
  34.  * Do not remove the lock when `ci -l' reverts.
  35.  * Move buffer-flushes out of critical sections, since they aren't critical.
  36.  * Use ORCSerror to clean up after a fatal error.
  37.  * Specify subprocess input via file descriptor, not file name.
  38.  *
  39.  * Revision 5.27  1993/11/09 17:40:15  eggert
  40.  * -V now prints version on stdout and exits.  Don't print usage twice.
  41.  *
  42.  * Revision 5.26  1993/11/03 17:42:27  eggert
  43.  * Add -z.  Don't subtract from RCS file timestamp even if -T.
  44.  * Scan for and use Name keyword if -k.
  45.  * Don't discard ignored phrases.  Improve quality of diagnostics.
  46.  *
  47.  * Revision 5.25  1992/07/28  16:12:44  eggert
  48.  * Add -i, -j, -V.  Check that working and RCS files are distinct.
  49.  *
  50.  * Revision 5.24  1992/02/17  23:02:06  eggert
  51.  * `-rREV' now just specifies a revision REV; only bare `-r' reverts to default.
  52.  * Add -T.
  53.  *
  54.  * Revision 5.23  1992/01/27  16:42:51  eggert
  55.  * Always unlock branchpoint if caller has a lock.
  56.  * Add support for bad_chmod_close, bad_creat0.  lint -> RCS_lint
  57.  *
  58.  * Revision 5.22  1992/01/06  02:42:34  eggert
  59.  * Invoke utime() before chmod() to keep some buggy systems happy.
  60.  *
  61.  * Revision 5.21  1991/11/20  17:58:07  eggert
  62.  * Don't read the delta tree from a nonexistent RCS file.
  63.  *
  64.  * Revision 5.20  1991/10/07  17:32:46  eggert
  65.  * Fix log bugs.  Remove lint.
  66.  *
  67.  * Revision 5.19  1991/09/26  23:10:30  eggert
  68.  * Plug file descriptor leak.
  69.  *
  70.  * Revision 5.18  1991/09/18  07:29:10  eggert
  71.  * Work around a common ftruncate() bug.
  72.  *
  73.  * Revision 5.17  1991/09/10  22:15:46  eggert
  74.  * Fix test for redirected stdin.
  75.  *
  76.  * Revision 5.16  1991/08/19  23:17:54  eggert
  77.  * When there are no changes, revert to previous revision instead of aborting.
  78.  * Add piece tables, -M, -r$.  Tune.
  79.  *
  80.  * Revision 5.15  1991/04/21  11:58:14  eggert
  81.  * Ensure that working file is newer than RCS file after ci -[lu].
  82.  * Add -x, RCSINIT, MS-DOS support.
  83.  *
  84.  * Revision 5.14  1991/02/28  19:18:47  eggert
  85.  * Don't let a setuid ci create a new RCS file; rcs -i -a must be run first.
  86.  * Fix ci -ko -l mode bug.  Open work file at most once.
  87.  *
  88.  * Revision 5.13  1991/02/25  07:12:33  eggert
  89.  * getdate -> getcurdate (SVR4 name clash)
  90.  *
  91.  * Revision 5.12  1990/12/31  01:00:12  eggert
  92.  * Don't use uninitialized storage when handling -{N,n}.
  93.  *
  94.  * Revision 5.11  1990/12/04  05:18:36  eggert
  95.  * Use -I for prompts and -q for diagnostics.
  96.  *
  97.  * Revision 5.10  1990/11/05  20:30:10  eggert
  98.  * Don't remove working file when aborting due to no changes.
  99.  *
  100.  * Revision 5.9  1990/11/01  05:03:23  eggert
  101.  * Add -I and new -t behavior.  Permit arbitrary data in logs.
  102.  *
  103.  * Revision 5.8  1990/10/04  06:30:09  eggert
  104.  * Accumulate exit status across files.
  105.  *
  106.  * Revision 5.7  1990/09/25  20:11:46  hammer
  107.  * fixed another small typo
  108.  *
  109.  * Revision 5.6  1990/09/24  21:48:50  hammer
  110.  * added cleanups from Paul Eggert.
  111.  *
  112.  * Revision 5.5  1990/09/21  06:16:38  hammer
  113.  * made it handle multiple -{N,n}'s.  Also, made it treat re-directed stdin
  114.  * the same as the terminal
  115.  *
  116.  * Revision 5.4  1990/09/20  02:38:51  eggert
  117.  * ci -k now checks dates more thoroughly.
  118.  *
  119.  * Revision 5.3  1990/09/11  02:41:07  eggert
  120.  * Fix revision bug with `ci -k file1 file2'.
  121.  *
  122.  * Revision 5.2  1990/09/04  08:02:10  eggert
  123.  * Permit adjacent revisions with identical time stamps (possible on fast hosts).
  124.  * Improve incomplete line handling.  Standardize yes-or-no procedure.
  125.  *
  126.  * Revision 5.1  1990/08/29  07:13:44  eggert
  127.  * Expand locker value like co.  Clean old log messages too.
  128.  *
  129.  * Revision 5.0  1990/08/22  08:10:00  eggert
  130.  * Don't require a final newline.
  131.  * Make lock and temp files faster and safer.
  132.  * Remove compile-time limits; use malloc instead.
  133.  * Permit dates past 1999/12/31.  Switch to GMT.
  134.  * Add setuid support.  Don't pass +args to diff.  Check diff's output.
  135.  * Ansify and Posixate.  Add -k, -V.  Remove snooping.  Tune.
  136.  * Check diff's output.
  137.  *
  138.  * Revision 4.9  89/05/01  15:10:54  narten
  139.  * changed copyright header to reflect current distribution rules
  140.  * 
  141.  * Revision 4.8  88/11/08  13:38:23  narten
  142.  * changes from root@seismo.CSS.GOV (Super User)
  143.  * -d with no arguments uses the mod time of the file it is checking in
  144.  * 
  145.  * Revision 4.7  88/08/09  19:12:07  eggert
  146.  * Make sure workfile is a regular file; use its mode if RCSfile doesn't have one.
  147.  * Use execv(), not system(); allow cc -R; remove lint.
  148.  * isatty(fileno(stdin)) -> ttystdin()
  149.  * 
  150.  * Revision 4.6  87/12/18  11:34:41  narten
  151.  * lint cleanups (from Guy Harris)
  152.  * 
  153.  * Revision 4.5  87/10/18  10:18:48  narten
  154.  * Updating version numbers. Changes relative to revision 1.1 are actually
  155.  * relative to 4.3
  156.  * 
  157.  * Revision 1.3  87/09/24  13:57:19  narten
  158.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  159.  * warnings)
  160.  * 
  161.  * Revision 1.2  87/03/27  14:21:33  jenkins
  162.  * Port to suns
  163.  * 
  164.  * Revision 4.3  83/12/15  12:28:54  wft
  165.  * ci -u and ci -l now set mode of working file properly.
  166.  * 
  167.  * Revision 4.2  83/12/05  13:40:54  wft
  168.  * Merged with 3.9.1.1: added calls to clearerr(stdin).
  169.  * made rewriteflag external.
  170.  * 
  171.  * Revision 4.1  83/05/10  17:03:06  wft
  172.  * Added option -d and -w, and updated assingment of date, etc. to new delta.
  173.  * Added handling of default branches.
  174.  * Option -k generates std. log message; fixed undef. pointer in reading of log.
  175.  * Replaced getlock() with findlock(), link--unlink with rename(),
  176.  * getpwuid() with getcaller().
  177.  * Moved all revision number generation to new routine addelta().
  178.  * Removed calls to stat(); now done by pairfilenames().
  179.  * Changed most calls to catchints() with restoreints().
  180.  * Directed all interactive messages to stderr.
  181.  * 
  182.  * Revision 3.9.1.1  83/10/19  04:21:03  lepreau
  183.  * Added clearerr(stdin) to getlogmsg() for re-reading stdin.
  184.  * 
  185.  * Revision 3.9  83/02/15  15:25:44  wft
  186.  * 4.2 prerelease
  187.  * 
  188.  * Revision 3.9  83/02/15  15:25:44  wft
  189.  * Added call to fastcopy() to copy remainder of RCS file.
  190.  *
  191.  * Revision 3.8  83/01/14  15:34:05  wft
  192.  * Added ignoring of interrupts while new RCS file is renamed;
  193.  * Avoids deletion of RCS files by interrupts.
  194.  *
  195.  * Revision 3.7  82/12/10  16:09:20  wft
  196.  * Corrected checking of return code from diff.
  197.  *
  198.  * Revision 3.6  82/12/08  21:34:49  wft
  199.  * Using DATEFORM to prepare date of checked-in revision;
  200.  * Fixed return from addbranch().
  201.  *
  202.  * Revision 3.5  82/12/04  18:32:42  wft
  203.  * Replaced getdelta() with gettree(), SNOOPDIR with SNOOPFILE. Updated
  204.  * field lockedby in removelock(), moved getlogmsg() before calling diff.
  205.  *
  206.  * Revision 3.4  82/12/02  13:27:13  wft
  207.  * added option -k.
  208.  *
  209.  * Revision 3.3  82/11/28  20:53:31  wft
  210.  * Added mustcheckin() to check for redundant checkins.
  211.  * Added xpandfile() to do keyword expansion for -u and -l;
  212.  * -m appends linefeed to log message if necessary.
  213.  * getlogmsg() suppresses prompt if stdin is not a terminal.
  214.  * Replaced keeplock with lockflag, fclose() with ffclose(),
  215.  * %02d with %.2d, getlogin() with getpwuid().
  216.  *
  217.  * Revision 3.2  82/10/18  20:57:23  wft
  218.  * An RCS file inherits its mode during the first ci from the working file,
  219.  * otherwise it stays the same, except that write permission is removed.
  220.  * Fixed ci -l, added ci -u (both do an implicit co after the ci).
  221.  * Fixed call to getlogin(), added call to getfullRCSname(), added check
  222.  * for write error.
  223.  * Changed conflicting identifiers.
  224.  *
  225.  * Revision 3.1  82/10/13  16:04:59  wft
  226.  * fixed type of variables receiving from getc() (char -> int).
  227.  * added include file dbm.h for getting BYTESIZ. This is used
  228.  * to check the return code from diff portably.
  229.  */
  230.  
  231. #include "rcsbase.h"
  232.  
  233. struct Symrev {
  234.        char const *ssymbol;
  235.        int override;
  236.        struct Symrev * nextsym;
  237. };
  238.  
  239. static char const *getcurdate P((void));
  240. static int addbranch P((struct hshentry*,struct buf*,int));
  241. static int addelta P((void));
  242. static int addsyms P((char const*));
  243. static int fixwork P((mode_t,time_t));
  244. static int removelock P((struct hshentry*));
  245. static int xpandfile P((RILE*,struct hshentry const*,char const**,int));
  246. static struct cbuf getlogmsg P((void));
  247. static void cleanup P((void));
  248. static void incnum P((char const*,struct buf*));
  249. static void addassoclst P((int,char const*));
  250.  
  251. static FILE *exfile;
  252. static RILE *workptr;            /* working file pointer        */
  253. static struct buf newdelnum;        /* new revision number        */
  254. static struct cbuf msg;
  255. static int exitstatus;
  256. static int forceciflag;            /* forces check in        */
  257. static int keepflag, keepworkingfile, rcsinitflag;
  258. static struct hshentries *gendeltas;    /* deltas to be generated    */
  259. static struct hshentry *targetdelta;    /* old delta to be generated    */
  260. static struct hshentry newdelta;    /* new delta to be inserted    */
  261. static struct stat workstat;
  262. static struct Symrev *assoclst, **nextassoc;
  263.  
  264. mainProg(ciId, "ci", "$Id: ci.c,v 5.28 1994/03/20 04:52:58 eggert Exp $")
  265. {
  266.     static char const cmdusage[] =
  267.         "\nci usage: ci -{fIklMqru}[rev] -d[date] -mmsg -{nN}name -sstate -ttext -T -Vn -wwho -xsuff -zzone file ...";
  268.     static char const default_state[] = DEFAULTSTATE;
  269.  
  270.     char altdate[datesize];
  271.     char olddate[datesize];
  272.     char newdatebuf[datesize + zonelenmax];
  273.     char targetdatebuf[datesize + zonelenmax];
  274.     char *a, **newargv, *textfile;
  275.     char const *author, *krev, *rev, *state;
  276.     char const *diffname, *expname;
  277.     char const *newworkname;
  278.     int initflag, mustread;
  279.     int lockflag, lockthis, mtimeflag, removedlock, Ttimeflag;
  280.     int r;
  281.     int changedRCS, changework, dolog, newhead;
  282.     int usestatdate; /* Use mod time of file for -d.  */
  283.     mode_t newworkmode; /* mode for working file */
  284.     time_t mtime, wtime;
  285.     struct hshentry *workdelta;
  286.  
  287.     setrid();
  288.  
  289.     author = rev = state = textfile = 0;
  290.     initflag = lockflag = mustread = false;
  291.     mtimeflag = false;
  292.     Ttimeflag = false;
  293.     altdate[0]= '\0'; /* empty alternate date for -d */
  294.     usestatdate=false;
  295.     suffixes = X_DEFAULT;
  296.     nextassoc = &assoclst;
  297.  
  298.     argc = getRCSINIT(argc, argv, &newargv);
  299.     argv = newargv;
  300.     while (a = *++argv,  0<--argc && *a++=='-') {
  301.         switch (*a++) {
  302.  
  303.                 case 'r':
  304.             if (*a)
  305.                 goto revno;
  306.             keepworkingfile = lockflag = false;
  307.             break;
  308.  
  309.         case 'l':
  310.             keepworkingfile = lockflag = true;
  311.         revno:
  312.             if (*a) {
  313.                 if (rev) warn("redefinition of revision number");
  314.                 rev = a;
  315.                         }
  316.                         break;
  317.  
  318.                 case 'u':
  319.                         keepworkingfile=true; lockflag=false;
  320.                         goto revno;
  321.  
  322.         case 'i':
  323.             initflag = true;
  324.             goto revno;
  325.  
  326.         case 'j':
  327.             mustread = true;
  328.             goto revno;
  329.  
  330.         case 'I':
  331.             interactiveflag = true;
  332.             goto revno;
  333.  
  334.                 case 'q':
  335.                         quietflag=true;
  336.                         goto revno;
  337.  
  338.                 case 'f':
  339.                         forceciflag=true;
  340.                         goto revno;
  341.  
  342.                 case 'k':
  343.                         keepflag=true;
  344.                         goto revno;
  345.  
  346.                 case 'm':
  347.             if (msg.size) redefined('m');
  348.             msg = cleanlogmsg(a, strlen(a));
  349.             if (!msg.size)
  350.                 error("missing message for -m option");
  351.                         break;
  352.  
  353.                 case 'n':
  354.             if (!*a) {
  355.                                 error("missing symbolic name after -n");
  356.                 break;
  357.                     }
  358.             checkssym(a);
  359.             addassoclst(false, a);
  360.                 break;
  361.         
  362.         case 'N':
  363.             if (!*a) {
  364.                                 error("missing symbolic name after -N");
  365.                 break;
  366.                     }
  367.             checkssym(a);
  368.             addassoclst(true, a);
  369.                 break;
  370.  
  371.                 case 's':
  372.             if (*a) {
  373.                 if (state) redefined('s');
  374.                 checksid(a);
  375.                 state = a;
  376.             } else
  377.                 error("missing state for -s option");
  378.                         break;
  379.  
  380.                 case 't':
  381.             if (*a) {
  382.                 if (textfile) redefined('t');
  383.                 textfile = a;
  384.                         }
  385.                         break;
  386.  
  387.         case 'd':
  388.             if (altdate[0] || usestatdate)
  389.                 redefined('d');
  390.             altdate[0] = '\0';
  391.             if (!(usestatdate = !*a))
  392.                 str2date(a, altdate);
  393.                         break;
  394.  
  395.         case 'M':
  396.             mtimeflag = true;
  397.             goto revno;
  398.  
  399.         case 'w':
  400.             if (*a) {
  401.                 if (author) redefined('w');
  402.                 checksid(a);
  403.                 author = a;
  404.             } else
  405.                 error("missing author for -w option");
  406.                         break;
  407.  
  408.         case 'x':
  409.             suffixes = a;
  410.             break;
  411.  
  412.         case 'V':
  413.             setRCSversion(*argv);
  414.             break;
  415.  
  416.         case 'z':
  417.             zone_set(a);
  418.             break;
  419.  
  420.         case 'T':
  421.             if (!*a) {
  422.                 Ttimeflag = true;
  423.                 break;
  424.             }
  425.             /* fall into */
  426.                 default:
  427.             error("unknown option: %s%s", *argv, cmdusage);
  428.                 };
  429.         }  /* end processing of options */
  430.  
  431.     /* Handle all pathnames.  */
  432.     if (nerror) cleanup();
  433.     else if (argc < 1) faterror("no input file%s", cmdusage);
  434.     else for (;  0 < argc;  cleanup(), ++argv, --argc) {
  435.     targetdelta = 0;
  436.     ffree();
  437.  
  438.     switch (pairnames(argc, argv, rcswriteopen, mustread, false)) {
  439.  
  440.         case -1:                /* New RCS file */
  441. #        if has_setuid && has_getuid
  442.             if (euid() != ruid()) {
  443.             workerror("setuid initial checkin prohibited; use `rcs -i -a' first");
  444.             continue;
  445.             }
  446. #        endif
  447.         rcsinitflag = true;
  448.                 break;
  449.  
  450.         case 0:                 /* Error */
  451.                 continue;
  452.  
  453.         case 1:                 /* Normal checkin with prev . RCS file */
  454.         if (initflag) {
  455.             rcserror("already exists");
  456.             continue;
  457.         }
  458.         rcsinitflag = !Head;
  459.         }
  460.  
  461.     /*
  462.      * RCSname contains the name of the RCS file, and
  463.      * workname contains the name of the working file.
  464.      * If the RCS file exists, finptr contains the file descriptor for the
  465.      * RCS file, and RCSstat is set. The admin node is initialized.
  466.          */
  467.  
  468.     diagnose("%s  <--  %s\n", RCSname, workname);
  469.  
  470.     if (!(workptr = Iopen(workname, FOPEN_R_WORK, &workstat))) {
  471.         eerror(workname);
  472.         continue;
  473.     }
  474.  
  475.     if (finptr) {
  476.         if (same_file(RCSstat, workstat, 0)) {
  477.             rcserror("RCS file is the same as working file %s.",
  478.                 workname
  479.             );
  480.             continue;
  481.         }
  482.         if (!checkaccesslist())
  483.             continue;
  484.     }
  485.  
  486.     krev = rev;
  487.         if (keepflag) {
  488.                 /* get keyword values from working file */
  489.         if (!getoldkeys(workptr)) continue;
  490.         if (!rev  &&  !*(krev = prevrev.string)) {
  491.             workerror("can't find a revision number");
  492.                         continue;
  493.                 }
  494.         if (!*prevdate.string && *altdate=='\0' && usestatdate==false)
  495.             workwarn("can't find a date");
  496.         if (!*prevauthor.string && !author)
  497.             workwarn("can't find an author");
  498.         if (!*prevstate.string && !state)
  499.             workwarn("can't find a state");
  500.         } /* end processing keepflag */
  501.  
  502.     /* Read the delta tree.  */
  503.     if (finptr)
  504.         gettree();
  505.  
  506.         /* expand symbolic revision number */
  507.     if (!fexpandsym(krev, &newdelnum, workptr))
  508.         continue;
  509.  
  510.         /* splice new delta into tree */
  511.     if ((removedlock = addelta()) < 0)
  512.         continue;
  513.  
  514.     newdelta.num = newdelnum.string;
  515.     newdelta.branches = 0;
  516.     newdelta.lockedby = 0; /* This might be changed by addlock().  */
  517.     newdelta.selector = true;
  518.     newdelta.name = 0;
  519.     clear_buf(&newdelta.ig);
  520.     clear_buf(&newdelta.igtext);
  521.     /* set author */
  522.     if (author)
  523.         newdelta.author=author;     /* set author given by -w         */
  524.     else if (keepflag && *prevauthor.string)
  525.         newdelta.author=prevauthor.string; /* preserve old author if possible*/
  526.     else    newdelta.author=getcaller();/* otherwise use caller's id      */
  527.     newdelta.state = default_state;
  528.     if (state)
  529.         newdelta.state=state;       /* set state given by -s          */
  530.     else if (keepflag && *prevstate.string)
  531.         newdelta.state=prevstate.string;   /* preserve old state if possible */
  532.     if (usestatdate) {
  533.         time2date(workstat.st_mtime, altdate);
  534.     }
  535.     if (*altdate!='\0')
  536.         newdelta.date=altdate;      /* set date given by -d           */
  537.     else if (keepflag && *prevdate.string) {
  538.         /* Preserve old date if possible.  */
  539.         str2date(prevdate.string, olddate);
  540.         newdelta.date = olddate;
  541.     } else
  542.         newdelta.date = getcurdate();  /* use current date */
  543.     /* now check validity of date -- needed because of -d and -k          */
  544.     if (targetdelta &&
  545.         cmpnum(newdelta.date,targetdelta->date) < 0) {
  546.         rcserror("Date %s precedes %s in revision %s.",
  547.             date2str(newdelta.date, newdatebuf),
  548.             date2str(targetdelta->date, targetdatebuf),
  549.             targetdelta->num
  550.         );
  551.         continue;
  552.     }
  553.  
  554.  
  555.     if (lockflag  &&  addlock(&newdelta, true) < 0) continue;
  556.  
  557.     if (keepflag && *prevname.string)
  558.         if (addsymbol(newdelta.num, prevname.string, false)  <  0)
  559.         continue;
  560.     if (!addsyms(newdelta.num))
  561.         continue;
  562.  
  563.     
  564.     putadmin();
  565.         puttree(Head,frewrite);
  566.     putdesc(false,textfile);
  567.  
  568.     changework = Expand != OLD_EXPAND;
  569.     dolog = true;
  570.     lockthis = lockflag;
  571.     workdelta = &newdelta;
  572.  
  573.         /* build rest of file */
  574.     if (rcsinitflag) {
  575.         diagnose("initial revision: %s\n", newdelta.num);
  576.                 /* get logmessage */
  577.                 newdelta.log=getlogmsg();
  578.         putdftext(&newdelta, workptr, frewrite, false);
  579.         RCSstat.st_mode = workstat.st_mode;
  580.         RCSstat.st_nlink = 0;
  581.         changedRCS = true;
  582.         } else {
  583.         diffname = maketemp(0);
  584.         newhead  =  Head == &newdelta;
  585.         if (!newhead)
  586.             foutptr = frewrite;
  587.         expname = buildrevision(
  588.             gendeltas, targetdelta, (FILE*)0, false
  589.         );
  590.         if (
  591.             !forceciflag  &&
  592.             strcmp(newdelta.state, targetdelta->state) == 0  &&
  593.             (changework = rcsfcmp(
  594.             workptr, &workstat, expname, targetdelta
  595.             )) <= 0
  596.         ) {
  597.             diagnose("file is unchanged; reverting to previous revision %s\n",
  598.             targetdelta->num
  599.             );
  600.             if (removedlock < lockflag) {
  601.             diagnose("previous revision was not locked; ignoring -l option\n");
  602.             lockthis = 0;
  603.             }
  604.             dolog = false;
  605.             if (! (changedRCS = lockflag<removedlock || assoclst))
  606.             workdelta = targetdelta;
  607.             else {
  608.             /*
  609.              * We have started to build the wrong new RCS file.
  610.              * Start over from the beginning.
  611.              */
  612.             long hwm = ftell(frewrite);
  613.             int bad_truncate;
  614.             Orewind(frewrite);
  615. #            if !has_ftruncate
  616.                 bad_truncate = 1;
  617. #            else
  618.                 /*
  619.                  * Work around a common ftruncate() bug:
  620.                  * NFS won't let you truncate a file that you
  621.                  * currently lack permissions for, even if you
  622.                  * had permissions when you opened it.
  623.                  */
  624.                 bad_truncate = ftruncate(fileno(frewrite),(off_t)0);
  625.                 if (bad_truncate  &&  errno != EACCES)
  626.                 Oerror();
  627. #            endif
  628.             Irewind(finptr);
  629.             Lexinit();
  630.             getadmin();
  631.             gettree();
  632.             if (!(workdelta = genrevs(
  633.                 targetdelta->num, (char*)0, (char*)0, (char*)0,
  634.                 &gendeltas
  635.             )))
  636.                 continue;
  637.             workdelta->log = targetdelta->log;
  638.             if (newdelta.state != default_state)
  639.                 workdelta->state = newdelta.state;
  640.             if (lockthis<removedlock && removelock(workdelta)<0)
  641.                 continue;
  642.             if (!addsyms(workdelta->num))
  643.                 continue;
  644.             if (dorewrite(true, true) != 0)
  645.                 continue;
  646.             fastcopy(finptr, frewrite);
  647.             if (bad_truncate)
  648.                 while (ftell(frewrite) < hwm)
  649.                 /* White out any earlier mistake with '\n's.  */
  650.                 /* This is unlikely.  */
  651.                 afputc('\n', frewrite);
  652.             }
  653.         } else {
  654.             int wfd = Ifileno(workptr);
  655.             struct stat checkworkstat;
  656. #            if large_memory && !has_mmap
  657.             FILE *wfile = workptr->stream;
  658.             long wfile_off = 0; /* `= 0' pacifies `gcc -Wall'.  */
  659. #            endif
  660. #            if (!large_memory || !has_mmap) && !has_fflush_input
  661.                 off_t wfd_off;
  662. #            endif
  663.  
  664.             diagnose("new revision: %s; previous revision: %s\n",
  665.             newdelta.num, targetdelta->num
  666.             );
  667.             newdelta.log = getlogmsg();
  668. #            if !large_memory
  669.             Irewind(workptr);
  670. #            if has_fflush_input
  671.                 if (fflush(workptr) != 0)
  672.                 Ierror();
  673. #            endif
  674. #            else
  675. #            if !has_mmap
  676.                 if (
  677.                     (newhead && (wfile_off=ftell(wfile)) == -1)
  678.                  ||    fseek(wfile, 0L, SEEK_SET) != 0
  679. #                 if has_fflush_input
  680.                  ||    fflush(wfile) != 0
  681. #                 endif
  682.                 )
  683.                 Ierror();
  684. #            endif
  685. #            endif
  686. #            if (!large_memory || !has_mmap) && !has_fflush_input
  687.             wfd_off = lseek(wfd, (off_t)0, SEEK_CUR);
  688.             if (wfd_off == -1
  689.                 || (wfd_off != 0
  690.                 && lseek(wfd, (off_t)0, SEEK_SET) != 0))
  691.                 Ierror();
  692. #            endif
  693.             switch (run(wfd, diffname,
  694.             DIFF DIFF_FLAGS,
  695.             newhead ? "-" : expname,
  696.             newhead ? expname : "-",
  697.             (char*)0
  698.             )) {
  699.             case DIFF_FAILURE: case DIFF_SUCCESS: break;
  700.             default: rcsfaterror("diff failed");
  701.             }
  702.             if (newhead) {
  703. #            if (!large_memory || !has_mmap) && !has_fflush_input
  704.                 if (lseek(wfd, wfd_off, SEEK_CUR) == -1)
  705.                 Ierror();
  706. #            endif
  707. #            if large_memory && !has_mmap
  708.                 if (fseek(wfile, wfile_off, SEEK_SET) != 0)
  709.                 Ierror();
  710. #            endif
  711.             Irewind(workptr);
  712.             putdftext(&newdelta, workptr, frewrite, false);
  713.             if (!putdtext(targetdelta,diffname,frewrite,true)) continue;
  714.             } else
  715.             if (!putdtext(&newdelta,diffname,frewrite,true)) continue;
  716.  
  717.             /*
  718.             * Check whether the working file changed during checkin,
  719.             * to avoid producing an inconsistent RCS file.
  720.             */
  721.             if (
  722.             fstat(wfd, &checkworkstat) != 0
  723.              ||    workstat.st_mtime != checkworkstat.st_mtime
  724.              ||    workstat.st_size != checkworkstat.st_size
  725.             ) {
  726.             workerror("file changed during checkin");
  727.             continue;
  728.             }
  729.  
  730.             changedRCS = true;
  731.                 }
  732.         }
  733.  
  734.     /* Deduce time_t of new revision if it is needed later.  */
  735.     wtime = (time_t)-1;
  736.     if (mtimeflag | Ttimeflag)
  737.         wtime = date2time(workdelta->date);
  738.  
  739.     if (donerewrite(changedRCS,
  740.         !Ttimeflag ? (time_t)-1
  741.         : finptr && wtime < RCSstat.st_mtime ? RCSstat.st_mtime
  742.         : wtime
  743.     ) != 0)
  744.         continue;
  745.  
  746.         if (!keepworkingfile) {
  747.         Izclose(&workptr);
  748.         r = un_link(workname); /* Get rid of old file */
  749.         } else {
  750.         newworkmode = WORKMODE(RCSstat.st_mode,
  751.             !   (Expand==VAL_EXPAND  ||  lockthis < StrictLocks)
  752.         );
  753.         mtime = mtimeflag ? wtime : (time_t)-1;
  754.  
  755.         /* Expand if it might change or if we can't fix mode, time.  */
  756.         if (changework  ||  (r=fixwork(newworkmode,mtime)) != 0) {
  757.             Irewind(workptr);
  758.             /* Expand keywords in file.  */
  759.             locker_expansion = lockthis;
  760.             workdelta->name = 
  761.             namedrev(
  762.                 assoclst ? assoclst->ssymbol
  763.                 : keepflag && *prevname.string ? prevname.string
  764.                 : rev,
  765.                 workdelta
  766.             );
  767.             switch (xpandfile(
  768.             workptr, workdelta, &newworkname, dolog
  769.             )) {
  770.             default:
  771.                 continue;
  772.  
  773.             case 0:
  774.                 /*
  775.                  * No expansion occurred; try to reuse working file
  776.                  * unless we already tried and failed.
  777.                  */
  778.                 if (changework)
  779.                 if ((r=fixwork(newworkmode,mtime)) == 0)
  780.                     break;
  781.                 /* fall into */
  782.             case 1:
  783.                 Izclose(&workptr);
  784.                 aflush(exfile);
  785.                 ignoreints();
  786.                 r = chnamemod(&exfile, newworkname,
  787.                     workname, 1, newworkmode, mtime
  788.                 );
  789.                 keepdirtemp(newworkname);
  790.                 restoreints();
  791.             }
  792.         }
  793.         }
  794.     if (r != 0) {
  795.         eerror(workname);
  796.         continue;
  797.     }
  798.     diagnose("done\n");
  799.  
  800.     }
  801.  
  802.     tempunlink();
  803.     exitmain(exitstatus);
  804. }       /* end of main (ci) */
  805.  
  806.     static void
  807. cleanup()
  808. {
  809.     if (nerror) exitstatus = EXIT_FAILURE;
  810.     Izclose(&finptr);
  811.     Izclose(&workptr);
  812.     Ozclose(&exfile);
  813.     Ozclose(&fcopy);
  814.     ORCSclose();
  815.     dirtempunlink();
  816. }
  817.  
  818. #if RCS_lint
  819. #    define exiterr ciExit
  820. #endif
  821.     void
  822. exiterr()
  823. {
  824.     ORCSerror();
  825.     dirtempunlink();
  826.     tempunlink();
  827.     _exit(EXIT_FAILURE);
  828. }
  829.  
  830. /*****************************************************************/
  831. /* the rest are auxiliary routines                               */
  832.  
  833.  
  834.     static int
  835. addelta()
  836. /* Function: Appends a delta to the delta tree, whose number is
  837.  * given by newdelnum.  Updates Head, newdelnum, newdelnumlength,
  838.  * and the links in newdelta.
  839.  * Return -1 on error, 1 if a lock is removed, 0 otherwise.
  840.  */
  841. {
  842.     register char *tp;
  843.     register int i;
  844.     int removedlock;
  845.     int newdnumlength;  /* actual length of new rev. num. */
  846.  
  847.     newdnumlength = countnumflds(newdelnum.string);
  848.  
  849.     if (rcsinitflag) {
  850.                 /* this covers non-existing RCS file and a file initialized with rcs -i */
  851.         if (newdnumlength==0 && Dbranch) {
  852.             bufscpy(&newdelnum, Dbranch);
  853.             newdnumlength = countnumflds(Dbranch);
  854.         }
  855.         if (newdnumlength==0) bufscpy(&newdelnum, "1.1");
  856.         else if (newdnumlength==1) bufscat(&newdelnum, ".1");
  857.         else if (newdnumlength>2) {
  858.             rcserror("Branch point doesn't exist for revision %s.",
  859.             newdelnum.string
  860.             );
  861.             return -1;
  862.                 } /* newdnumlength == 2 is OK;  */
  863.                 Head = &newdelta;
  864.         newdelta.next = 0;
  865.         return 0;
  866.         }
  867.         if (newdnumlength==0) {
  868.                 /* derive new revision number from locks */
  869.         switch (findlock(true, &targetdelta)) {
  870.  
  871.           default:
  872.             /* found two or more old locks */
  873.             return -1;
  874.  
  875.           case 1:
  876.                     /* found an old lock */
  877.                     /* check whether locked revision exists */
  878.             if (!genrevs(targetdelta->num,(char*)0,(char*)0,(char*)0,&gendeltas))
  879.             return -1;
  880.                     if (targetdelta==Head) {
  881.                         /* make new head */
  882.                         newdelta.next=Head;
  883.                         Head= &newdelta;
  884.             } else if (!targetdelta->next && countnumflds(targetdelta->num)>2) {
  885.                         /* new tip revision on side branch */
  886.                         targetdelta->next= &newdelta;
  887.             newdelta.next = 0;
  888.                     } else {
  889.                         /* middle revision; start a new branch */
  890.             bufscpy(&newdelnum, "");
  891.             return addbranch(targetdelta, &newdelnum, 1);
  892.                     }
  893.             incnum(targetdelta->num, &newdelnum);
  894.             return 1; /* successful use of existing lock */
  895.  
  896.           case 0:
  897.                     /* no existing lock; try Dbranch */
  898.                     /* update newdelnum */
  899.             if (StrictLocks || !myself(RCSstat.st_uid)) {
  900.             rcserror("no lock set by %s", getcaller());
  901.             return -1;
  902.                     }
  903.                     if (Dbranch) {
  904.             bufscpy(&newdelnum, Dbranch);
  905.                     } else {
  906.             incnum(Head->num, &newdelnum);
  907.                     }
  908.             newdnumlength = countnumflds(newdelnum.string);
  909.                     /* now fall into next statement */
  910.                 }
  911.         }
  912.         if (newdnumlength<=2) {
  913.                 /* add new head per given number */
  914.                 if(newdnumlength==1) {
  915.                     /* make a two-field number out of it*/
  916.             if (cmpnumfld(newdelnum.string,Head->num,1)==0)
  917.             incnum(Head->num, &newdelnum);
  918.             else
  919.             bufscat(&newdelnum, ".1");
  920.                 }
  921.         if (cmpnum(newdelnum.string,Head->num) <= 0) {
  922.             rcserror("revision %s too low; must be higher than %s",
  923.               newdelnum.string, Head->num
  924.             );
  925.             return -1;
  926.                 }
  927.         targetdelta = Head;
  928.         if (0 <= (removedlock = removelock(Head))) {
  929.             if (!genrevs(Head->num,(char*)0,(char*)0,(char*)0,&gendeltas))
  930.             return -1;
  931.             newdelta.next = Head;
  932.             Head = &newdelta;
  933.         }
  934.         return removedlock;
  935.         } else {
  936.                 /* put new revision on side branch */
  937.                 /*first, get branch point */
  938.         tp = newdelnum.string;
  939.         for (i = newdnumlength - ((newdnumlength&1) ^ 1);  --i;  )
  940.             while (*tp++ != '.')
  941.                 continue;
  942.         *--tp = 0; /* Kill final dot to get old delta temporarily. */
  943.         if (!(targetdelta=genrevs(newdelnum.string,(char*)0,(char*)0,(char*)0,&gendeltas)))
  944.             return -1;
  945.         if (cmpnum(targetdelta->num, newdelnum.string) != 0) {
  946.             rcserror("can't find branch point %s", newdelnum.string);
  947.             return -1;
  948.                 }
  949.         *tp = '.'; /* Restore final dot. */
  950.         return addbranch(targetdelta, &newdelnum, 0);
  951.         }
  952. }
  953.  
  954.  
  955.  
  956.     static int
  957. addbranch(branchpoint, num, removedlock)
  958.     struct hshentry *branchpoint;
  959.     struct buf *num;
  960.     int removedlock;
  961. /* adds a new branch and branch delta at branchpoint.
  962.  * If num is the null string, appends the new branch, incrementing
  963.  * the highest branch number (initially 1), and setting the level number to 1.
  964.  * the new delta and branchhead are in globals newdelta and newbranch, resp.
  965.  * the new number is placed into num.
  966.  * Return -1 on error, 1 if a lock is removed, 0 otherwise.
  967.  * If REMOVEDLOCK is 1, a lock was already removed.
  968.  */
  969. {
  970.     struct branchhead *bhead, **btrail;
  971.     struct buf branchnum;
  972.     int result;
  973.     int field, numlength;
  974.     static struct branchhead newbranch;  /* new branch to be inserted */
  975.  
  976.     numlength = countnumflds(num->string);
  977.  
  978.     if (!branchpoint->branches) {
  979.                 /* start first branch */
  980.                 branchpoint->branches = &newbranch;
  981.                 if (numlength==0) {
  982.             bufscpy(num, branchpoint->num);
  983.             bufscat(num, ".1.1");
  984.         } else if (numlength&1)
  985.             bufscat(num, ".1");
  986.         newbranch.nextbranch = 0;
  987.  
  988.     } else if (numlength==0) {
  989.                 /* append new branch to the end */
  990.                 bhead=branchpoint->branches;
  991.                 while (bhead->nextbranch) bhead=bhead->nextbranch;
  992.                 bhead->nextbranch = &newbranch;
  993.         bufautobegin(&branchnum);
  994.         getbranchno(bhead->hsh->num, &branchnum);
  995.         incnum(branchnum.string, num);
  996.         bufautoend(&branchnum);
  997.         bufscat(num, ".1");
  998.         newbranch.nextbranch = 0;
  999.         } else {
  1000.                 /* place the branch properly */
  1001.         field = numlength - ((numlength&1) ^ 1);
  1002.                 /* field of branch number */
  1003.         btrail = &branchpoint->branches;
  1004.         while (0 < (result=cmpnumfld(num->string,(*btrail)->hsh->num,field))) {
  1005.             btrail = &(*btrail)->nextbranch;
  1006.             if (!*btrail) {
  1007.                 result = -1;
  1008.                 break;
  1009.             }
  1010.                 }
  1011.         if (result < 0) {
  1012.                         /* insert/append new branchhead */
  1013.             newbranch.nextbranch = *btrail;
  1014.             *btrail = &newbranch;
  1015.             if (numlength&1) bufscat(num, ".1");
  1016.                 } else {
  1017.                         /* branch exists; append to end */
  1018.             bufautobegin(&branchnum);
  1019.             getbranchno(num->string, &branchnum);
  1020.             targetdelta = genrevs(
  1021.                 branchnum.string, (char*)0, (char*)0, (char*)0,
  1022.                 &gendeltas
  1023.             );
  1024.             bufautoend(&branchnum);
  1025.             if (!targetdelta)
  1026.                 return -1;
  1027.             if (cmpnum(num->string,targetdelta->num) <= 0) {
  1028.                 rcserror("revision %s too low; must be higher than %s",
  1029.                       num->string, targetdelta->num
  1030.                 );
  1031.                 return -1;
  1032.                         }
  1033.             if (!removedlock
  1034.                 && 0 <= (removedlock = removelock(targetdelta))
  1035.             ) {
  1036.                 if (numlength&1)
  1037.                 incnum(targetdelta->num,num);
  1038.                 targetdelta->next = &newdelta;
  1039.                 newdelta.next = 0;
  1040.             }
  1041.             return removedlock;
  1042.             /* Don't do anything to newbranch.  */
  1043.                 }
  1044.         }
  1045.         newbranch.hsh = &newdelta;
  1046.     newdelta.next = 0;
  1047.     if (branchpoint->lockedby)
  1048.         if (strcmp(branchpoint->lockedby, getcaller()) == 0)
  1049.         return removelock(branchpoint); /* This returns 1.  */
  1050.     return removedlock;
  1051. }
  1052.  
  1053.     static int
  1054. addsyms(num)
  1055.     char const *num;
  1056. {
  1057.     register struct Symrev *p;
  1058.  
  1059.     for (p = assoclst;  p;  p = p->nextsym)
  1060.         if (addsymbol(num, p->ssymbol, p->override)  <  0)
  1061.             return false;
  1062.     return true;
  1063. }
  1064.  
  1065.  
  1066.     static void
  1067. incnum(onum,nnum)
  1068.     char const *onum;
  1069.     struct buf *nnum;
  1070. /* Increment the last field of revision number onum by one and
  1071.  * place the result into nnum.
  1072.  */
  1073. {
  1074.     register char *tp, *np;
  1075.     register size_t l;
  1076.  
  1077.     l = strlen(onum);
  1078.     bufalloc(nnum, l+2);
  1079.     np = tp = nnum->string;
  1080.     VOID strcpy(np, onum);
  1081.     for (tp = np + l;  np != tp;  )
  1082.         if (isdigit(*--tp)) {
  1083.             if (*tp != '9') {
  1084.                 ++*tp;
  1085.                 return;
  1086.             }
  1087.             *tp = '0';
  1088.         } else {
  1089.             tp++;
  1090.             break;
  1091.         }
  1092.     /* We changed 999 to 000; now change it to 1000.  */
  1093.     *tp = '1';
  1094.     tp = np + l;
  1095.     *tp++ = '0';
  1096.     *tp = 0;
  1097. }
  1098.  
  1099.  
  1100.  
  1101.     static int
  1102. removelock(delta)
  1103. struct hshentry * delta;
  1104. /* function: Finds the lock held by caller on delta,
  1105.  * removes it, and returns nonzero if successful.
  1106.  * Print an error message and return -1 if there is no such lock.
  1107.  * An exception is if !StrictLocks, and caller is the owner of
  1108.  * the RCS file. If caller does not have a lock in this case,
  1109.  * return 0; return 1 if a lock is actually removed.
  1110.  */
  1111. {
  1112.     register struct lock *next, **trail;
  1113.     char const *num;
  1114.  
  1115.         num=delta->num;
  1116.     for (trail = &Locks;  (next = *trail);  trail = &next->nextlock)
  1117.         if (next->delta == delta)
  1118.         if (strcmp(getcaller(), next->login) == 0) {
  1119.             /* We found a lock on delta by caller; delete it.  */
  1120.             *trail = next->nextlock;
  1121.             delta->lockedby = 0;
  1122.             return 1;
  1123.         } else {
  1124.             rcserror("revision %s locked by %s", num, next->login);
  1125.             return -1;
  1126.                 }
  1127.     if (!StrictLocks && myself(RCSstat.st_uid))
  1128.         return 0;
  1129.     rcserror("no lock set by %s for revision %s", getcaller(), num);
  1130.     return -1;
  1131. }
  1132.  
  1133.  
  1134.  
  1135.     static char const *
  1136. getcurdate()
  1137. /* Return a pointer to the current date.  */
  1138. {
  1139.     static char buffer[datesize]; /* date buffer */
  1140.  
  1141.     if (!buffer[0])
  1142.         time2date(now(), buffer);
  1143.         return buffer;
  1144. }
  1145.  
  1146.     static int
  1147. #if has_prototypes
  1148. fixwork(mode_t newworkmode, time_t mtime)
  1149.   /* The `#if has_prototypes' is needed because mode_t might promote to int.  */
  1150. #else
  1151.   fixwork(newworkmode, mtime)
  1152.     mode_t newworkmode;
  1153.     time_t mtime;
  1154. #endif
  1155. {
  1156.     return
  1157.             1 < workstat.st_nlink
  1158.             ||    (newworkmode&S_IWUSR && !myself(workstat.st_uid))
  1159.             ||    setmtime(workname, mtime) != 0
  1160.         ?   -1
  1161.         :    workstat.st_mode == newworkmode  ?  0
  1162.         :
  1163. #        if has_fchmod
  1164.             fchmod(Ifileno(workptr), newworkmode)
  1165. #        else
  1166. #        if bad_chmod_close
  1167.             -1
  1168. #        else
  1169.             chmod(workname, newworkmode)
  1170. #        endif
  1171. #        endif
  1172.     ;
  1173. }
  1174.  
  1175.     static int
  1176. xpandfile(unexfile, delta, exname, dolog)
  1177.     RILE *unexfile;
  1178.     struct hshentry const *delta;
  1179.     char const **exname;
  1180.     int dolog;
  1181. /*
  1182.  * Read unexfile and copy it to a
  1183.  * file, performing keyword substitution with data from delta.
  1184.  * Return -1 if unsuccessful, 1 if expansion occurred, 0 otherwise.
  1185.  * If successful, stores the stream descriptor into *EXFILEP
  1186.  * and its name into *EXNAME.
  1187.  */
  1188. {
  1189.     char const *targetname;
  1190.     int e, r;
  1191.  
  1192.     targetname = makedirtemp(1);
  1193.     if (!(exfile = fopen(targetname, FOPEN_W_WORK))) {
  1194.         eerror(targetname);
  1195.         workerror("can't build working file");
  1196.         return -1;
  1197.         }
  1198.     r = 0;
  1199.     if (Expand == OLD_EXPAND)
  1200.         fastcopy(unexfile,exfile);
  1201.     else {
  1202.         for (;;) {
  1203.             e = expandline(
  1204.                 unexfile, exfile, delta, false, (FILE*)0, dolog
  1205.             );
  1206.             if (e < 0)
  1207.                 break;
  1208.             r |= e;
  1209.             if (e <= 1)
  1210.                 break;
  1211.         }
  1212.     }
  1213.     *exname = targetname;
  1214.     return r & 1;
  1215. }
  1216.  
  1217.  
  1218.  
  1219.  
  1220. /* --------------------- G E T L O G M S G --------------------------------*/
  1221.  
  1222.  
  1223.     static struct cbuf
  1224. getlogmsg()
  1225. /* Obtain and yield a log message.
  1226.  * If a log message is given with -m, yield that message.
  1227.  * If this is the initial revision, yield a standard log message.
  1228.  * Otherwise, reads a character string from the terminal.
  1229.  * Stops after reading EOF or a single '.' on a
  1230.  * line. getlogmsg prompts the first time it is called for the
  1231.  * log message; during all later calls it asks whether the previous
  1232.  * log message can be reused.
  1233.  */
  1234. {
  1235.     static char const
  1236.         emptych[] = EMPTYLOG,
  1237.         initialch[] = "Initial revision";
  1238.     static struct cbuf const
  1239.         emptylog = { emptych, sizeof(emptych)-sizeof(char) },
  1240.         initiallog = { initialch, sizeof(initialch)-sizeof(char) };
  1241.     static struct buf logbuf;
  1242.     static struct cbuf logmsg;
  1243.  
  1244.     register char *tp;
  1245.     register size_t i;
  1246.     char const *caller;
  1247.  
  1248.     if (msg.size) return msg;
  1249.  
  1250.     if (keepflag) {
  1251.         /* generate std. log message */
  1252.         caller = getcaller();
  1253.         i = sizeof(ciklog)+strlen(caller)+3;
  1254.         bufalloc(&logbuf, i + datesize + zonelenmax);
  1255.         tp = logbuf.string;
  1256.         VOID sprintf(tp, "%s%s at ", ciklog, caller);
  1257.         VOID date2str(getcurdate(), tp+i);
  1258.         logmsg.string = tp;
  1259.         logmsg.size = strlen(tp);
  1260.         return logmsg;
  1261.     }
  1262.  
  1263.     if (!targetdelta && (
  1264.         cmpnum(newdelnum.string,"1.1")==0 ||
  1265.         cmpnum(newdelnum.string,"1.0")==0
  1266.     ))
  1267.         return initiallog;
  1268.  
  1269.     if (logmsg.size) {
  1270.                 /*previous log available*/
  1271.         if (yesorno(true, "reuse log message of previous file? [yn](y): "))
  1272.         return logmsg;
  1273.         }
  1274.  
  1275.         /* now read string from stdin */
  1276.     logmsg = getsstdin("m", "log message", "", &logbuf);
  1277.  
  1278.         /* now check whether the log message is not empty */
  1279.     if (logmsg.size)
  1280.         return logmsg;
  1281.     return emptylog;
  1282. }
  1283.  
  1284. /*  Make a linked list of Symbolic names  */
  1285.  
  1286.         static void
  1287. addassoclst(flag, sp)
  1288.     int flag;
  1289.     char const *sp;
  1290. {
  1291.         struct Symrev *pt;
  1292.     
  1293.     pt = talloc(struct Symrev);
  1294.     pt->ssymbol = sp;
  1295.     pt->override = flag;
  1296.     pt->nextsym = 0;
  1297.     *nextassoc = pt;
  1298.     nextassoc = &pt->nextsym;
  1299. }
  1300.