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
7This file is part of RCS.
8
--- 49 unchanged lines hidden (view full) ---
58 * Revision 4.1 83/05/04 10:06:53 wft
59 * Initial revision.
60 *
61 */
62
63
64#include "rcsbase.h"
65
66libId(keysId, "$Id$")
67
68
69char const *const Keyword[] = {
70 /* This must be in the same order as rcsbase.h's enum markers type. */
71 0,
72 AUTHOR, DATE, HEADER, IDH,
73 LOCKER, LOG, NAME, RCSFILE, REVISION, SOURCE, STATE,
74 FREEBSD
75};
76
77/* Expand all keywords by default */
78
79static int ExpandKeyword[] = {
80 false,
81 true, true, true, true,
82 true, true, true, true, true, true, true,
83 false
84};
85
86 enum markers
87trymatch(string)
88 char const *string;
89/* function: Checks whether string starts with a keyword followed
90 * by a KDELIM or a VDELIM.
91 * If successful, returns the appropriate marker, otherwise Nomatch.
92 */
93{
94 register int j;
95 register char const *p, *s;
96 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); ) {
97 if (!ExpandKeyword[j])
98 continue;
99 /* try next keyword */
100 p = Keyword[j];
101 s = string;
102 while (*p++ == *s++) {
103 if (!*p)
104 switch (*s) {
105 case KDELIM:
106 case VDELIM:
107 return (enum markers)j;
108 default:
109 return Nomatch;
110 }
111 }
112 }
113 return(Nomatch);
114}
115
116setIncExc(arg)
117 char *arg;
118/* Sets up the ExpandKeyword table according to command-line flags */
119{
120 char *key;
121 int include = 0, j;
122
123 arg += 2;
124 switch (*arg++) {
125 case 'e':
126 include = false;
127 break;
128 case 'i':
129 include = true;
130 break;
131 default:
132 return(false);
133 }
134 if (include)
135 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); )
136 ExpandKeyword[j] = false;
137 key = strtok(arg, ",");
138 while (key) {
139 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); )
140 if (!strcmp(key, Keyword[j]))
141 ExpandKeyword[j] = include;
142 key = strtok(NULL, ",");
143 }
144 return(true);
145}
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
7This file is part of RCS.
8
--- 49 unchanged lines hidden (view full) ---
58 * Revision 4.1 83/05/04 10:06:53 wft
59 * Initial revision.
60 *
61 */
62
63
64#include "rcsbase.h"
65
66libId(keysId, "$Id$")
67
68
69char const *const Keyword[] = {
70 /* This must be in the same order as rcsbase.h's enum markers type. */
71 0,
72 AUTHOR, DATE, HEADER, IDH,
73 LOCKER, LOG, NAME, RCSFILE, REVISION, SOURCE, STATE,
74 FREEBSD
75};
76
77/* Expand all keywords by default */
78
79static int ExpandKeyword[] = {
80 false,
81 true, true, true, true,
82 true, true, true, true, true, true, true,
83 false
84};
85
86 enum markers
87trymatch(string)
88 char const *string;
89/* function: Checks whether string starts with a keyword followed
90 * by a KDELIM or a VDELIM.
91 * If successful, returns the appropriate marker, otherwise Nomatch.
92 */
93{
94 register int j;
95 register char const *p, *s;
96 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); ) {
97 if (!ExpandKeyword[j])
98 continue;
99 /* try next keyword */
100 p = Keyword[j];
101 s = string;
102 while (*p++ == *s++) {
103 if (!*p)
104 switch (*s) {
105 case KDELIM:
106 case VDELIM:
107 return (enum markers)j;
108 default:
109 return Nomatch;
110 }
111 }
112 }
113 return(Nomatch);
114}
115
116setIncExc(arg)
117 char *arg;
118/* Sets up the ExpandKeyword table according to command-line flags */
119{
120 char *key;
121 int include = 0, j;
122
123 arg += 2;
124 switch (*arg++) {
125 case 'e':
126 include = false;
127 break;
128 case 'i':
129 include = true;
130 break;
131 default:
132 return(false);
133 }
134 if (include)
135 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); )
136 ExpandKeyword[j] = false;
137 key = strtok(arg, ",");
138 while (key) {
139 for (j = sizeof(Keyword)/sizeof(*Keyword); (--j); )
140 if (!strcmp(key, Keyword[j]))
141 ExpandKeyword[j] = include;
142 key = strtok(NULL, ",");
143 }
144 return(true);
145}