xref: /dragonfly/gnu/usr.bin/rcs/lib/rcskeys.c (revision 37de577a)
1 /* RCS keyword table and match operation */
2 
3 /* Copyright 1982, 1988, 1989 Walter Tichy
4    Copyright 1990, 1991, 1992, 1993, 1995 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.
21 If not, write to the Free Software Foundation,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 Report problems and direct all questions to:
25 
26     rcs-bugs@cs.purdue.edu
27 
28 */
29 /*
30  * $FreeBSD: src/gnu/usr.bin/rcs/lib/rcskeys.c,v 1.12.2.1 2002/02/08 11:58:35 ru Exp $
31  * $DragonFly: src/gnu/usr.bin/rcs/lib/rcskeys.c,v 1.2 2003/06/17 04:25:47 dillon Exp $
32  *
33  * Revision 5.4  1995/06/16 06:19:24  eggert
34  * Update FSF address.
35  *
36  * Revision 5.3  1993/11/03 17:42:27  eggert
37  * Add Name keyword.
38  *
39  * Revision 5.2  1991/08/19  03:13:55  eggert
40  * Say `T const' instead of `const T'; it's less confusing for pointer types.
41  * (This change was made in other source files too.)
42  *
43  * Revision 5.1  1991/04/21  11:58:25  eggert
44  * Don't put , just before } in initializer.
45  *
46  * Revision 5.0  1990/08/22  08:12:54  eggert
47  * Add -k.  Ansify and Posixate.
48  *
49  * Revision 4.3  89/05/01  15:13:02  narten
50  * changed copyright header to reflect current distribution rules
51  *
52  * Revision 4.2  87/10/18  10:36:33  narten
53  * Updating version numbers. Changes relative to 1.1 actuallyt
54  * relative to 4.1
55  *
56  * Revision 1.2  87/09/24  14:00:10  narten
57  * Sources now pass through lint (if you ignore printf/sprintf/fprintf
58  * warnings)
59  *
60  * Revision 4.1  83/05/04  10:06:53  wft
61  * Initial revision.
62  *
63  */
64 
65 
66 #include "rcsbase.h"
67 
68 libId(keysId, "$DragonFly: src/gnu/usr.bin/rcs/lib/rcskeys.c,v 1.2 2003/06/17 04:25:47 dillon Exp $")
69 
70 
71 char const *Keyword[] = {
72     /* This must be in the same order as rcsbase.h's enum markers type. */
73 	0,
74 	AUTHOR, DATE, HEADER, IDH,
75 	LOCKER, LOG, NAME, RCSFILE, REVISION, SOURCE, STATE, CVSHEADER,
76 	NULL
77 };
78 
79 /* Expand all keywords by default */
80 static int ExpandKeyword[] = {
81 	false,
82 	true, true, true, true,
83 	true, true, true, true, true, true, true, true,
84 	true
85 };
86 enum markers LocalIdMode = Id;
87 
88 	enum markers
89 trymatch(string)
90 	char const *string;
91 /* function: Checks whether string starts with a keyword followed
92  * by a KDELIM or a VDELIM.
93  * If successful, returns the appropriate marker, otherwise Nomatch.
94  */
95 {
96         register int j;
97 	register char const *p, *s;
98 	for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  ) {
99 		if (!ExpandKeyword[j])
100 			continue;
101 		/* try next keyword */
102 		p = Keyword[j];
103 		if (p == NULL)
104 			continue;
105 		s = string;
106 		while (*p++ == *s++) {
107 			if (!*p)
108 			    switch (*s) {
109 				case KDELIM:
110 				case VDELIM:
111 				    return (enum markers)j;
112 				default:
113 				    return Nomatch;
114 			    }
115 		}
116         }
117         return(Nomatch);
118 }
119 
120 	void
121 setIncExc(arg)
122 	char const *arg;
123 /* Sets up the ExpandKeyword table according to command-line flags */
124 {
125 	char *key;
126 	char *copy, *next;
127 	int include = 0, j;
128 
129 	copy = strdup(arg);
130 	next = copy;
131 	switch (*next++) {
132 	    case 'e':
133 		include = false;
134 		break;
135 	    case 'i':
136 		include = true;
137 		break;
138 	    default:
139 		free(copy);
140 		return;
141 	}
142 	if (include)
143 		for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  )
144 			ExpandKeyword[j] = false;
145 	key = strtok(next, ",");
146 	while (key) {
147 		for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  ) {
148 			if (Keyword[j] == NULL)
149 				continue;
150 			if (!strcmp(key, Keyword[j]))
151 				ExpandKeyword[j] = include;
152 		}
153 		key = strtok(NULL, ",");
154 	}
155 	free(copy);
156 	return;
157 }
158 
159 	void
160 setRCSLocalId(string)
161 	char const *string;
162 /* function: sets local RCS id and RCSLOCALID envariable */
163 {
164 	static char local_id[keylength+1];
165 	char *copy, *next, *key;
166 
167 	copy = strdup(string);
168 	next = copy;
169 	key = strtok(next, "=");
170 	if (strlen(key) > keylength)
171 		faterror("LocalId is too long");
172 	VOID strcpy(local_id, key);
173 	Keyword[LocalId] = local_id;
174 
175 	/* options? */
176 	while ((key = strtok(NULL, ","))) {
177 		if (!strcmp(key, Keyword[Id]))
178 			LocalIdMode=Id;
179 		else if (!strcmp(key, Keyword[Header]))
180 			LocalIdMode=Header;
181 		else if (!strcmp(key, Keyword[CVSHeader]))
182 			LocalIdMode=CVSHeader;
183 		else
184 			error("Unknown LocalId mode");
185 	}
186 	free(copy);
187 }
188