summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/rcs/lib/rcskeep.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/rcs/lib/rcskeep.c')
-rw-r--r--gnu/usr.bin/rcs/lib/rcskeep.c186
1 files changed, 106 insertions, 80 deletions
diff --git a/gnu/usr.bin/rcs/lib/rcskeep.c b/gnu/usr.bin/rcs/lib/rcskeep.c
index 232a616360de..5723a2acb9be 100644
--- a/gnu/usr.bin/rcs/lib/rcskeep.c
+++ b/gnu/usr.bin/rcs/lib/rcskeep.c
@@ -1,14 +1,7 @@
-/*
- * RCS keyword extraction
- */
-/*****************************************************************************
- * main routine: getoldkeys()
- * Testprogram: define KEEPTEST
- *****************************************************************************
- */
+/* Extract RCS keyword string values from working files. */
-/* Copyright (C) 1982, 1988, 1989 Walter Tichy
- Copyright 1990, 1991 by Paul Eggert
+/* Copyright 1982, 1988, 1989 Walter Tichy
+ Copyright 1990, 1991, 1992, 1993, 1994, 1995 Paul Eggert
Distributed under license by the Free Software Foundation, Inc.
This file is part of RCS.
@@ -24,8 +17,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with RCS; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+along with RCS; see the file COPYING.
+If not, write to the Free Software Foundation,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Report problems and direct all questions to:
@@ -33,11 +27,24 @@ Report problems and direct all questions to:
*/
-
-
-/* $Log: rcskeep.c,v $
- * Revision 1.1.1.1 1993/06/18 04:22:13 jkh
- * Updated GNU utilities
+/*
+ * Revision 5.10 1995/06/16 06:19:24 eggert
+ * Update FSF address.
+ *
+ * Revision 5.9 1995/06/01 16:23:43 eggert
+ * (getoldkeys): Don't panic if a Name: is empty.
+ *
+ * Revision 5.8 1994/03/17 14:05:48 eggert
+ * Remove lint.
+ *
+ * Revision 5.7 1993/11/09 17:40:15 eggert
+ * Use simpler timezone parsing strategy now that we're using ISO 8601 format.
+ *
+ * Revision 5.6 1993/11/03 17:42:27 eggert
+ * Scan for Name keyword. Improve quality of diagnostics.
+ *
+ * Revision 5.5 1992/07/28 16:12:44 eggert
+ * Statement macro names now end in _.
*
* Revision 5.4 1991/08/19 03:13:55 eggert
* Tune.
@@ -89,33 +96,29 @@ Report problems and direct all questions to:
*
*/
-/*
-#define KEEPTEST
-*/
-/* Testprogram; prints out the keyword values found. */
-
#include "rcsbase.h"
-libId(keepId, "$Id: rcskeep.c,v 1.1.1.1 1993/06/18 04:22:13 jkh Exp $")
+libId(keepId, "$Id: rcskeep.c,v 1.4 1995/10/29 22:06:23 peter Exp $")
-static int checknum P((char const*,int));
-static int getval P((RILE*,struct buf*,int));
+static int badly_terminated P((void));
+static int checknum P((char const*));
static int get0val P((int,RILE*,struct buf*,int));
+static int getval P((RILE*,struct buf*,int));
static int keepdate P((RILE*));
static int keepid P((int,RILE*,struct buf*));
static int keeprev P((RILE*));
int prevkeys;
-struct buf prevauthor, prevdate, prevrev, prevstate;
+struct buf prevauthor, prevdate, prevname, prevrev, prevstate;
int
getoldkeys(fp)
register RILE *fp;
/* Function: Tries to read keyword values for author, date,
* revision number, and state out of the file fp.
- * If FNAME is nonnull, it is opened and closed instead of using FP.
+ * If fp is null, workname is opened and closed instead of using fp.
* The results are placed into
- * prevauthor, prevdate, prevrev, prevstate.
+ * prevauthor, prevdate, prevname, prevrev, prevstate.
* Aborts immediately if it finds an error and returns false.
* If it returns true, it doesn't mean that any of the
* values were found; instead, check to see whether the corresponding arrays
@@ -126,14 +129,15 @@ getoldkeys(fp)
char keyword[keylength+1];
register char * tp;
int needs_closing;
+ int prevname_found;
if (prevkeys)
return true;
needs_closing = false;
if (!fp) {
- if (!(fp = Iopen(workfilename, FOPEN_R_WORK, (struct stat*)0))) {
- eerror(workfilename);
+ if (!(fp = Iopen(workname, FOPEN_R_WORK, (struct stat*)0))) {
+ eerror(workname);
return false;
}
needs_closing = true;
@@ -142,6 +146,7 @@ getoldkeys(fp)
/* initialize to empty */
bufscpy(&prevauthor, "");
bufscpy(&prevdate, "");
+ bufscpy(&prevname, ""); prevname_found = 0;
bufscpy(&prevrev, "");
bufscpy(&prevstate, "");
@@ -152,7 +157,7 @@ getoldkeys(fp)
/* try to get keyword */
tp = keyword;
for (;;) {
- Igeteof(fp, c, goto ok;);
+ Igeteof_(fp, c, goto ok;)
switch (c) {
default:
if (keyword+keylength <= tp)
@@ -168,7 +173,7 @@ getoldkeys(fp)
} while (c==KDELIM);
if (c!=VDELIM) continue;
*tp = c;
- Igeteof(fp, c, break;);
+ Igeteof_(fp, c, break;)
switch (c) {
case ' ': case '\t': break;
default: continue;
@@ -187,7 +192,7 @@ getoldkeys(fp)
case Header:
case Id:
if (!(
- getval(fp, (struct buf*)nil, false) &&
+ getval(fp, (struct buf*)0, false) &&
keeprev(fp) &&
(c = keepdate(fp)) &&
keepid(c, fp, &prevauthor) &&
@@ -195,8 +200,8 @@ getoldkeys(fp)
))
return false;
/* Skip either ``who'' (new form) or ``Locker: who'' (old). */
- if (getval(fp, (struct buf*)nil, true) &&
- getval(fp, (struct buf*)nil, true))
+ if (getval(fp, (struct buf*)0, true) &&
+ getval(fp, (struct buf*)0, true))
c = 0;
else if (nerror)
return false;
@@ -204,13 +209,24 @@ getoldkeys(fp)
c = KDELIM;
break;
case Locker:
+ (void) getval(fp, (struct buf*)0, false);
+ c = 0;
+ break;
case Log:
case RCSfile:
case Source:
- if (!getval(fp, (struct buf*)nil, false))
+ if (!getval(fp, (struct buf*)0, false))
return false;
c = 0;
break;
+ case Name:
+ if (getval(fp, &prevname, false)) {
+ if (*prevname.string)
+ checkssym(prevname.string);
+ prevname_found = 1;
+ }
+ c = 0;
+ break;
case Revision:
if (!keeprev(fp))
return false;
@@ -225,16 +241,18 @@ getoldkeys(fp)
continue;
}
if (!c)
- Igeteof(fp, c, c=0;);
+ Igeteof_(fp, c, c=0;)
if (c != KDELIM) {
- error("closing %c missing on keyword", KDELIM);
+ workerror("closing %c missing on keyword", KDELIM);
return false;
}
- if (*prevauthor.string && *prevdate.string && *prevrev.string && *prevstate.string) {
+ if (prevname_found &&
+ *prevauthor.string && *prevdate.string &&
+ *prevrev.string && *prevstate.string
+ )
break;
- }
}
- Igeteof(fp, c, break;);
+ Igeteof_(fp, c, break;)
}
ok:
@@ -249,7 +267,7 @@ getoldkeys(fp)
static int
badly_terminated()
{
- error("badly terminated keyword value");
+ workerror("badly terminated keyword value");
return false;
}
@@ -260,12 +278,12 @@ getval(fp, target, optional)
int optional;
/* Reads a keyword value from FP into TARGET.
* Returns true if one is found, false otherwise.
- * Does not modify target if it is nil.
+ * Does not modify target if it is 0.
* Do not report an error if OPTIONAL is set and KDELIM is found instead.
*/
{
int c;
- Igeteof(fp, c, return badly_terminated(););
+ Igeteof_(fp, c, return badly_terminated();)
return get0val(c, fp, target, optional);
}
@@ -308,8 +326,6 @@ get0val(c, fp, target, optional)
VOID printf("getval: %s\n", target);
# endif
}
- if (!got1)
- error("too much white space in keyword value");
return got1;
case KDELIM:
@@ -320,7 +336,7 @@ get0val(c, fp, target, optional)
case 0:
return badly_terminated();
}
- Igeteof(fp, c, return badly_terminated(););
+ Igeteof_(fp, c, return badly_terminated();)
}
}
@@ -332,8 +348,7 @@ keepdate(fp)
* Return 0 on error, lookahead character otherwise.
*/
{
- struct buf prevday, prevtime, prevzone;
- register char const *p;
+ struct buf prevday, prevtime;
register int c;
c = 0;
@@ -341,24 +356,18 @@ keepdate(fp)
if (getval(fp,&prevday,false)) {
bufautobegin(&prevtime);
if (getval(fp,&prevtime,false)) {
- bufautobegin(&prevzone);
- bufscpy(&prevzone, "");
- Igeteof(fp, c, c=0;);
- if (c=='-' || c=='+')
- if (!get0val(c,fp,&prevzone,false))
- c = 0;
- else
- Igeteof(fp, c, c=0;);
+ Igeteof_(fp, c, c=0;)
if (c) {
- p = prevday.string;
- bufalloc(&prevdate, strlen(p) + strlen(prevtime.string) + strlen(prevzone.string) + 5);
- VOID sprintf(prevdate.string, "%s%s %s %s",
+ register char const *d = prevday.string, *t = prevtime.string;
+ bufalloc(&prevdate, strlen(d) + strlen(t) + 9);
+ VOID sprintf(prevdate.string, "%s%s %s%s",
/* Parse dates put out by old versions of RCS. */
- isdigit(p[0]) && isdigit(p[1]) && p[2]=='/' ? "19" : "",
- p, prevtime.string, prevzone.string
+ isdigit(d[0]) && isdigit(d[1]) && !isdigit(d[2])
+ ? "19" : "",
+ d, t,
+ strchr(t,'-') || strchr(t,'+') ? "" : "+0000"
);
}
- bufautoend(&prevzone);
}
bufautoend(&prevtime);
}
@@ -374,11 +383,11 @@ keepid(c, fp, b)
/* Get previous identifier from C+FP into B. */
{
if (!c)
- Igeteof(fp, c, return false;);
+ Igeteof_(fp, c, return false;)
if (!get0val(c, fp, b, false))
return false;
checksid(b->string);
- return true;
+ return !nerror;
}
static int
@@ -386,28 +395,45 @@ keeprev(fp)
RILE *fp;
/* Get previous revision from FP into prevrev. */
{
- return getval(fp,&prevrev,false) && checknum(prevrev.string,-1);
+ return getval(fp,&prevrev,false) && checknum(prevrev.string);
}
static int
-checknum(sp,fields)
- register char const *sp;
- int fields;
-{ register int dotcount;
- dotcount=0;
- while(*sp) {
- if (*sp=='.') dotcount++;
- else if (!isdigit(*sp)) return false;
- sp++;
- }
- return fields<0 ? dotcount&1 : dotcount==fields;
+checknum(s)
+ char const *s;
+{
+ register char const *sp;
+ register int dotcount = 0;
+ for (sp=s; ; sp++) {
+ switch (*sp) {
+ case 0:
+ if (dotcount & 1)
+ return true;
+ else
+ break;
+
+ case '.':
+ dotcount++;
+ continue;
+
+ default:
+ if (isdigit(*sp))
+ continue;
+ break;
+ }
+ break;
+ }
+ workerror("%s is not a revision number", s);
+ return false;
}
#ifdef KEEPTEST
+/* Print the keyword values found. */
+
char const cmdid[] ="keeptest";
int
@@ -415,10 +441,10 @@ main(argc, argv)
int argc; char *argv[];
{
while (*(++argv)) {
- workfilename = *argv;
+ workname = *argv;
getoldkeys((RILE*)0);
- VOID printf("%s: revision: %s, date: %s, author: %s, state: %s\n",
- *argv, prevrev.string, prevdate.string, prevauthor.string, prevstate.string);
+ VOID printf("%s: revision: %s, date: %s, author: %s, name: %s, state: %s\n",
+ *argv, prevrev.string, prevdate.string, prevauthor.string, prevname.string, prevstate.string);
}
exitmain(EXIT_SUCCESS);
}