rcskeys.c revision 8858
1/*
2 *                     RCS keyword table and match operation
3 */
4
5/* Copyright (C) 1982, 1988, 1989 Walter Tichy
6   Copyright 1990, 1991 by Paul Eggert
7   Distributed under license by the Free Software Foundation, Inc.
8
9This file is part of RCS.
10
11RCS is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2, or (at your option)
14any later version.
15
16RCS is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with RCS; see the file COPYING.  If not, write to
23the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25Report problems and direct all questions to:
26
27    rcs-bugs@cs.purdue.edu
28
29*/
30
31
32
33/* $Log: rcskeys.c,v $
34 * Revision 1.4  1994/06/22  00:51:42  rgrimes
35 * Fix serious off by one error for FreeBSD keyword, this has been driving
36 * me nuts as it was on by default and that is NOT what I wanted.
37 *
38 * Revision 1.3  1994/05/15  22:15:14  rgrimes
39 * To truely have the OLD behavior of RCS by default make the expansion
40 * of $FreeBSD: head/gnu/usr.bin/rcs/lib/rcskeys.c 8858 1995-05-30 05:05:38Z rgrimes $ false by default.  This should keep them out
41 * of the pre 2.x repository. (Or at least make them useless in it).
42 *
43 * Revision 1.2  1994/05/14  07:00:23  rgrimes
44 * Add new option -K from David Dawes that allows you to turn on and off
45 * specific keyword substitution during a rcs co command.
46 * Add the new keyword FreeBSD that is IDENTICAL in operation to $Id: rcskeys.c,v 1.4 1994/06/22 00:51:42 rgrimes Exp $.
47 *
48 * Revision 1.1.1.1  1993/06/18  04:22:12  jkh
49 * Updated GNU utilities
50 *
51 * Revision 5.2  1991/08/19  03:13:55  eggert
52 * Say `T const' instead of `const T'; it's less confusing for pointer types.
53 * (This change was made in other source files too.)
54 *
55 * Revision 5.1  1991/04/21  11:58:25  eggert
56 * Don't put , just before } in initializer.
57 *
58 * Revision 5.0  1990/08/22  08:12:54  eggert
59 * Add -k.  Ansify and Posixate.
60 *
61 * Revision 4.3  89/05/01  15:13:02  narten
62 * changed copyright header to reflect current distribution rules
63 *
64 * Revision 4.2  87/10/18  10:36:33  narten
65 * Updating version numbers. Changes relative to 1.1 actuallyt
66 * relative to 4.1
67 *
68 * Revision 1.2  87/09/24  14:00:10  narten
69 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
70 * warnings)
71 *
72 * Revision 4.1  83/05/04  10:06:53  wft
73 * Initial revision.
74 *
75 */
76
77
78#include "rcsbase.h"
79
80libId(keysId, "$Id: rcskeys.c,v 1.4 1994/06/22 00:51:42 rgrimes Exp $")
81
82
83char const *const Keyword[] = {
84    /* This must be in the same order as rcsbase.h's enum markers type. */
85	nil,
86	AUTHOR, DATE, HEADER, IDH,
87	LOCKER, LOG, RCSFILE, REVISION, SOURCE, STATE,
88	FREEBSD
89};
90
91
92/* Expand all keywords by default */
93
94static int ExpandKeyword[] = {
95	nil,
96	true, true, true, true,
97	true, true, true, true, true, true,
98	false
99};
100
101	enum markers
102trymatch(string)
103	char const *string;
104/* function: Checks whether string starts with a keyword followed
105 * by a KDELIM or a VDELIM.
106 * If successful, returns the appropriate marker, otherwise Nomatch.
107 */
108{
109        register int j;
110	register char const *p, *s;
111	for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  ) {
112		if (!ExpandKeyword[j])
113			continue;
114		/* try next keyword */
115		p = Keyword[j];
116		s = string;
117		while (*p++ == *s++) {
118			if (!*p)
119			    switch (*s) {
120				case KDELIM:
121				case VDELIM:
122				    return (enum markers)j;
123				default:
124				    return Nomatch;
125			    }
126		}
127        }
128        return(Nomatch);
129}
130
131
132setIncExc(arg)
133	char *arg;
134/* Sets up the ExpandKeyword table according to command-line flags */
135{
136	char *key;
137	int include = 0, j;
138
139	arg += 2;
140	switch (*arg++) {
141	    case 'e':
142		include = false;
143		break;
144	    case 'i':
145		include = true;
146		break;
147	    default:
148		return(false);
149	}
150	if (include)
151		for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  )
152			ExpandKeyword[j] = false;
153	key = strtok(arg, ",");
154	while (key) {
155		for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  )
156			if (!strcmp(key, Keyword[j]))
157				ExpandKeyword[j] = include;
158		key = strtok(NULL, ",");
159	}
160	return(true);
161}
162
163