📄 ci.c
字号:
/* Copyright (C) 1982, 1988, 1989 Walter Tichy Copyright 1990, 1991 by Paul Eggert Distributed under license by the Free Software Foundation, Inc.This file is part of RCS.RCS is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.RCS is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with RCS; see the file COPYING. If not, write tothe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.Report problems and direct all questions to: rcs-bugs@cs.purdue.edu*//* * RCS checkin operation *//******************************************************************* * check revisions into RCS files ******************************************************************* *//* $Log: ci.c,v $ * Revision 5.21 1991/11/20 17:58:07 eggert * Don't read the delta tree from a nonexistent RCS file. * * Revision 5.20 1991/10/07 17:32:46 eggert * Fix log bugs. Remove lint. * * Revision 5.19 1991/09/26 23:10:30 eggert * Plug file descriptor leak. * * Revision 5.18 1991/09/18 07:29:10 eggert * Work around a common ftruncate() bug. * * Revision 5.17 1991/09/10 22:15:46 eggert * Fix test for redirected stdin. * * Revision 5.16 1991/08/19 23:17:54 eggert * When there are no changes, revert to previous revision instead of aborting. * Add piece tables, -M, -r$. Tune. * * Revision 5.15 1991/04/21 11:58:14 eggert * Ensure that working file is newer than RCS file after ci -[lu]. * Add -x, RCSINIT, MS-DOS support. * * Revision 5.14 1991/02/28 19:18:47 eggert * Don't let a setuid ci create a new RCS file; rcs -i -a must be run first. * Fix ci -ko -l mode bug. Open work file at most once. * * Revision 5.13 1991/02/25 07:12:33 eggert * getdate -> getcurdate (SVR4 name clash) * * Revision 5.12 1990/12/31 01:00:12 eggert * Don't use uninitialized storage when handling -{N,n}. * * Revision 5.11 1990/12/04 05:18:36 eggert * Use -I for prompts and -q for diagnostics. * * Revision 5.10 1990/11/05 20:30:10 eggert * Don't remove working file when aborting due to no changes. * * Revision 5.9 1990/11/01 05:03:23 eggert * Add -I and new -t behavior. Permit arbitrary data in logs. * * Revision 5.8 1990/10/04 06:30:09 eggert * Accumulate exit status across files. * * Revision 5.7 1990/09/25 20:11:46 hammer * fixed another small typo * * Revision 5.6 1990/09/24 21:48:50 hammer * added cleanups from Paul Eggert. * * Revision 5.5 1990/09/21 06:16:38 hammer * made it handle multiple -{N,n}'s. Also, made it treat re-directed stdin * the same as the terminal * * Revision 5.4 1990/09/20 02:38:51 eggert * ci -k now checks dates more thoroughly. * * Revision 5.3 1990/09/11 02:41:07 eggert * Fix revision bug with `ci -k file1 file2'. * * Revision 5.2 1990/09/04 08:02:10 eggert * Permit adjacent revisions with identical time stamps (possible on fast hosts). * Improve incomplete line handling. Standardize yes-or-no procedure. * * Revision 5.1 1990/08/29 07:13:44 eggert * Expand locker value like co. Clean old log messages too. * * Revision 5.0 1990/08/22 08:10:00 eggert * Don't require a final newline. * Make lock and temp files faster and safer. * Remove compile-time limits; use malloc instead. * Permit dates past 1999/12/31. Switch to GMT. * Add setuid support. Don't pass +args to diff. Check diff's output. * Ansify and Posixate. Add -k, -V. Remove snooping. Tune. * Check diff's output. * * Revision 4.9 89/05/01 15:10:54 narten * changed copyright header to reflect current distribution rules * * Revision 4.8 88/11/08 13:38:23 narten * changes from root@seismo.CSS.GOV (Super User) * -d with no arguments uses the mod time of the file it is checking in * * Revision 4.7 88/08/09 19:12:07 eggert * Make sure workfile is a regular file; use its mode if RCSfile doesn't have one. * Use execv(), not system(); allow cc -R; remove lint. * isatty(fileno(stdin)) -> ttystdin() * * Revision 4.6 87/12/18 11:34:41 narten * lint cleanups (from Guy Harris) * * Revision 4.5 87/10/18 10:18:48 narten * Updating version numbers. Changes relative to revision 1.1 are actually * relative to 4.3 * * Revision 1.3 87/09/24 13:57:19 narten * Sources now pass through lint (if you ignore printf/sprintf/fprintf * warnings) * * Revision 1.2 87/03/27 14:21:33 jenkins * Port to suns * * Revision 4.3 83/12/15 12:28:54 wft * ci -u and ci -l now set mode of working file properly. * * Revision 4.2 83/12/05 13:40:54 wft * Merged with 3.9.1.1: added calls to clearerr(stdin). * made rewriteflag external. * * Revision 4.1 83/05/10 17:03:06 wft * Added option -d and -w, and updated assingment of date, etc. to new delta. * Added handling of default branches. * Option -k generates std. log message; fixed undef. pointer in reading of log. * Replaced getlock() with findlock(), link--unlink with rename(), * getpwuid() with getcaller(). * Moved all revision number generation to new routine addelta(). * Removed calls to stat(); now done by pairfilenames(). * Changed most calls to catchints() with restoreints(). * Directed all interactive messages to stderr. * * Revision 3.9.1.1 83/10/19 04:21:03 lepreau * Added clearerr(stdin) to getlogmsg() for re-reading stdin. * * Revision 3.9 83/02/15 15:25:44 wft * 4.2 prerelease * * Revision 3.9 83/02/15 15:25:44 wft * Added call to fastcopy() to copy remainder of RCS file. * * Revision 3.8 83/01/14 15:34:05 wft * Added ignoring of interrupts while new RCS file is renamed; * Avoids deletion of RCS files by interrupts. * * Revision 3.7 82/12/10 16:09:20 wft * Corrected checking of return code from diff. * * Revision 3.6 82/12/08 21:34:49 wft * Using DATEFORM to prepare date of checked-in revision; * Fixed return from addbranch(). * * Revision 3.5 82/12/04 18:32:42 wft * Replaced getdelta() with gettree(), SNOOPDIR with SNOOPFILE. Updated * field lockedby in removelock(), moved getlogmsg() before calling diff. * * Revision 3.4 82/12/02 13:27:13 wft * added option -k. * * Revision 3.3 82/11/28 20:53:31 wft * Added mustcheckin() to check for redundant checkins. * Added xpandfile() to do keyword expansion for -u and -l; * -m appends linefeed to log message if necessary. * getlogmsg() suppresses prompt if stdin is not a terminal. * Replaced keeplock with lockflag, fclose() with ffclose(), * %02d with %.2d, getlogin() with getpwuid(). * * Revision 3.2 82/10/18 20:57:23 wft * An RCS file inherits its mode during the first ci from the working file, * otherwise it stays the same, except that write permission is removed. * Fixed ci -l, added ci -u (both do an implicit co after the ci). * Fixed call to getlogin(), added call to getfullRCSname(), added check * for write error. * Changed conflicting identifiers. * * Revision 3.1 82/10/13 16:04:59 wft * fixed type of variables receiving from getc() (char -> int). * added include file dbm.h for getting BYTESIZ. This is used * to check the return code from diff portably. */#include "rcsbase.h"struct Symrev { char const *ssymbol; int override; struct Symrev * nextsym;};static char const *getcurdate P((void));static int addbranch P((struct hshentry*,struct buf*));static int addelta P((void));static int addsyms P((char const*));static int fixwork P((mode_t,char const*));static int removelock P((struct hshentry*));static int xpandfile P((RILE*,char const*,struct hshentry const*,char const**));static struct cbuf getlogmsg P((void));static void cleanup P((void));static void incnum P((char const*,struct buf*));static void addassoclst P((int, char *));static FILE *exfile;static RILE *workptr; /* working file pointer */static struct buf newdelnum; /* new revision number */static struct cbuf msg;static int exitstatus;static int forceciflag; /* forces check in */static int keepflag, keepworkingfile, rcsinitflag;static struct hshentries *gendeltas; /* deltas to be generated */static struct hshentry *targetdelta; /* old delta to be generated */static struct hshentry newdelta; /* new delta to be inserted */static struct stat workstat;static struct Symrev *assoclst, *lastassoc;mainProg(ciId, "ci", "$Id: ci.c,v 5.21 1991/11/20 17:58:07 eggert Exp $"){ static char const cmdusage[] = "\nci usage: ci -{fklqru}[rev] -mmsg -{nN}name -sstate -t[textfile] -Vn file ..."; static char const default_state[] = DEFAULTSTATE; char altdate[datesize]; char olddate[datesize]; char newdatebuf[datesize], targetdatebuf[datesize]; char *a, **newargv, *textfile; char const *author, *krev, *rev, *state; char const *diffilename, *expfilename; char const *workdiffname, *newworkfilename; char const *mtime; int lockflag, lockthis, mtimeflag, removedlock; int r; int changedRCS, changework, newhead; int usestatdate; /* Use mod time of file for -d. */ mode_t newworkmode; /* mode for working file */ struct hshentry *workdelta; setrid(); author = rev = state = textfile = nil; lockflag = false; mtimeflag = false; altdate[0]= '\0'; /* empty alternate date for -d */ usestatdate=false; suffixes = X_DEFAULT; argc = getRCSINIT(argc, argv, &newargv); argv = newargv; while (a = *++argv, 0<--argc && *a++=='-') { switch (*a++) { case 'r': keepworkingfile = lockflag = false; revno: if (*a) { if (rev) warn("redefinition of revision number"); rev = a; } break; case 'l': keepworkingfile=lockflag=true; goto revno; case 'u': keepworkingfile=true; lockflag=false; goto revno; case 'I': interactiveflag = true; goto revno; case 'q': quietflag=true; goto revno; case 'f': forceciflag=true; goto revno; case 'k': keepflag=true; goto revno; case 'm': if (msg.size) redefined('m'); msg = cleanlogmsg(a, strlen(a)); if (!msg.size) warn("missing message for -m option"); break; case 'n': if (!*a) { error("missing symbolic name after -n"); break; } checksid(a); addassoclst(false, a); break; case 'N': if (!*a) { error("missing symbolic name after -N"); break; } checksid(a); addassoclst(true, a); break; case 's': if (*a) { if (state) redefined('s'); checksid(a); state = a; } else warn("missing state for -s option"); break; case 't': if (*a) { if (textfile) redefined('t'); textfile = a; } break; case 'd': if (altdate[0] || usestatdate) redefined('d'); altdate[0] = 0; if (!(usestatdate = !*a)) str2date(a, altdate); break; case 'M': mtimeflag = true; goto revno; case 'w': if (*a) { if (author) redefined('w'); checksid(a); author = a; } else warn("missing author for -w option"); break; case 'x': suffixes = a; break; case 'V': setRCSversion(*argv); break; default: faterror("unknown option: %s%s", *argv, cmdusage); }; } /* end processing of options */ if (argc<1) faterror("no input file%s", cmdusage); /* now handle all filenames */ do {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -