Deleted Added
full compact
rcskeys.c (1500) rcskeys.c (1764)
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 $
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.3 1994/05/15 22:15:14 rgrimes
35 * To truely have the OLD behavior of RCS by default make the expansion
36 * of $FreeBSD: head/gnu/usr.bin/rcs/lib/rcskeys.c 1764 1994-06-22 00:51:42Z rgrimes $ false by default. This should keep them out
37 * of the pre 2.x repository. (Or at least make them useless in it).
38 *
34 * Revision 1.2 1994/05/14 07:00:23 rgrimes
35 * Add new option -K from David Dawes that allows you to turn on and off
36 * specific keyword substitution during a rcs co command.
39 * Revision 1.2 1994/05/14 07:00:23 rgrimes
40 * Add new option -K from David Dawes that allows you to turn on and off
41 * specific keyword substitution during a rcs co command.
37 * Add the new keyword FreeBSD that is IDENTICAL in operation to $Id$.
42 * Add the new keyword FreeBSD that is IDENTICAL in operation to $Id: rcskeys.c,v 1.3 1994/05/15 22:15:14 rgrimes Exp $.
38 *
39 * Revision 1.1.1.1 1993/06/18 04:22:12 jkh
40 * Updated GNU utilities
41 *
42 * Revision 5.2 1991/08/19 03:13:55 eggert
43 * Say `T const' instead of `const T'; it's less confusing for pointer types.
44 * (This change was made in other source files too.)
45 *
46 * Revision 5.1 1991/04/21 11:58:25 eggert
47 * Don't put , just before } in initializer.
48 *
49 * Revision 5.0 1990/08/22 08:12:54 eggert
50 * Add -k. Ansify and Posixate.
51 *
52 * Revision 4.3 89/05/01 15:13:02 narten
53 * changed copyright header to reflect current distribution rules
54 *
55 * Revision 4.2 87/10/18 10:36:33 narten
56 * Updating version numbers. Changes relative to 1.1 actuallyt
57 * relative to 4.1
58 *
59 * Revision 1.2 87/09/24 14:00:10 narten
60 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
61 * warnings)
62 *
63 * Revision 4.1 83/05/04 10:06:53 wft
64 * Initial revision.
65 *
66 */
67
68
69#include "rcsbase.h"
70
43 *
44 * Revision 1.1.1.1 1993/06/18 04:22:12 jkh
45 * Updated GNU utilities
46 *
47 * Revision 5.2 1991/08/19 03:13:55 eggert
48 * Say `T const' instead of `const T'; it's less confusing for pointer types.
49 * (This change was made in other source files too.)
50 *
51 * Revision 5.1 1991/04/21 11:58:25 eggert
52 * Don't put , just before } in initializer.
53 *
54 * Revision 5.0 1990/08/22 08:12:54 eggert
55 * Add -k. Ansify and Posixate.
56 *
57 * Revision 4.3 89/05/01 15:13:02 narten
58 * changed copyright header to reflect current distribution rules
59 *
60 * Revision 4.2 87/10/18 10:36:33 narten
61 * Updating version numbers. Changes relative to 1.1 actuallyt
62 * relative to 4.1
63 *
64 * Revision 1.2 87/09/24 14:00:10 narten
65 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
66 * warnings)
67 *
68 * Revision 4.1 83/05/04 10:06:53 wft
69 * Initial revision.
70 *
71 */
72
73
74#include "rcsbase.h"
75
71libId(keysId, "$Id: rcskeys.c,v 1.2 1994/05/14 07:00:23 rgrimes Exp $")
76libId(keysId, "$Id: rcskeys.c,v 1.3 1994/05/15 22:15:14 rgrimes Exp $")
72
73
74char const *const Keyword[] = {
75 /* This must be in the same order as rcsbase.h's enum markers type. */
76 nil,
77 AUTHOR, DATE, HEADER, IDH,
78 LOCKER, LOG, RCSFILE, REVISION, SOURCE, STATE,
79 FREEBSD
80};
81
82
83/* Expand all keywords by default */
84
85static int ExpandKeyword[] = {
86 nil,
87 true, true, true, true,
77
78
79char const *const Keyword[] = {
80 /* This must be in the same order as rcsbase.h's enum markers type. */
81 nil,
82 AUTHOR, DATE, HEADER, IDH,
83 LOCKER, LOG, RCSFILE, REVISION, SOURCE, STATE,
84 FREEBSD
85};
86
87
88/* Expand all keywords by default */
89
90static int ExpandKeyword[] = {
91 nil,
92 true, true, true, true,
88 true, true, true, true, true, true, true,
93 true, true, true, true, true, true,
89 false
90};
91
92 enum markers
93trymatch(string)
94 char const *string;
95/* function: Checks whether string starts with a keyword followed
96 * by a KDELIM or a VDELIM.
97 * If successful, returns the appropriate marker, otherwise Nomatch.
98 */
99{
100 register int j;
101 register char const *p, *s;
102 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); ) {
103 if (!ExpandKeyword[j])
104 continue;
105 /* try next keyword */
106 p = Keyword[j];
107 s = string;
108 while (*p++ == *s++) {
109 if (!*p)
110 switch (*s) {
111 case KDELIM:
112 case VDELIM:
113 return (enum markers)j;
114 default:
115 return Nomatch;
116 }
117 }
118 }
119 return(Nomatch);
120}
121
122
123setIncExc(arg)
124 char *arg;
125/* Sets up the ExpandKeyword table according to command-line flags */
126{
127 char *key;
128 int include = 0, j;
129
130 arg += 2;
131 switch (*arg++) {
132 case 'e':
133 include = false;
134 break;
135 case 'i':
136 include = true;
137 break;
138 default:
139 return(false);
140 }
141 if (include)
142 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); )
143 ExpandKeyword[j] = false;
144 key = strtok(arg, ",");
145 while (key) {
146 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); )
147 if (!strcmp(key, Keyword[j]))
148 ExpandKeyword[j] = include;
149 key = strtok(NULL, ",");
150 }
151 return(true);
152}
153
94 false
95};
96
97 enum markers
98trymatch(string)
99 char const *string;
100/* function: Checks whether string starts with a keyword followed
101 * by a KDELIM or a VDELIM.
102 * If successful, returns the appropriate marker, otherwise Nomatch.
103 */
104{
105 register int j;
106 register char const *p, *s;
107 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); ) {
108 if (!ExpandKeyword[j])
109 continue;
110 /* try next keyword */
111 p = Keyword[j];
112 s = string;
113 while (*p++ == *s++) {
114 if (!*p)
115 switch (*s) {
116 case KDELIM:
117 case VDELIM:
118 return (enum markers)j;
119 default:
120 return Nomatch;
121 }
122 }
123 }
124 return(Nomatch);
125}
126
127
128setIncExc(arg)
129 char *arg;
130/* Sets up the ExpandKeyword table according to command-line flags */
131{
132 char *key;
133 int include = 0, j;
134
135 arg += 2;
136 switch (*arg++) {
137 case 'e':
138 include = false;
139 break;
140 case 'i':
141 include = true;
142 break;
143 default:
144 return(false);
145 }
146 if (include)
147 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); )
148 ExpandKeyword[j] = false;
149 key = strtok(arg, ",");
150 while (key) {
151 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); )
152 if (!strcmp(key, Keyword[j]))
153 ExpandKeyword[j] = include;
154 key = strtok(NULL, ",");
155 }
156 return(true);
157}
158