rcskeys.c revision 8858
19Sjkh/*
29Sjkh *                     RCS keyword table and match operation
39Sjkh */
49Sjkh
59Sjkh/* Copyright (C) 1982, 1988, 1989 Walter Tichy
69Sjkh   Copyright 1990, 1991 by Paul Eggert
79Sjkh   Distributed under license by the Free Software Foundation, Inc.
89Sjkh
99SjkhThis file is part of RCS.
109Sjkh
119SjkhRCS is free software; you can redistribute it and/or modify
129Sjkhit under the terms of the GNU General Public License as published by
139Sjkhthe Free Software Foundation; either version 2, or (at your option)
149Sjkhany later version.
159Sjkh
169SjkhRCS is distributed in the hope that it will be useful,
179Sjkhbut WITHOUT ANY WARRANTY; without even the implied warranty of
189SjkhMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
199SjkhGNU General Public License for more details.
209Sjkh
219SjkhYou should have received a copy of the GNU General Public License
229Sjkhalong with RCS; see the file COPYING.  If not, write to
239Sjkhthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
249Sjkh
259SjkhReport problems and direct all questions to:
269Sjkh
279Sjkh    rcs-bugs@cs.purdue.edu
289Sjkh
299Sjkh*/
309Sjkh
319Sjkh
329Sjkh
339Sjkh/* $Log: rcskeys.c,v $
348858Srgrimes * Revision 1.4  1994/06/22  00:51:42  rgrimes
358858Srgrimes * Fix serious off by one error for FreeBSD keyword, this has been driving
368858Srgrimes * me nuts as it was on by default and that is NOT what I wanted.
378858Srgrimes *
381764Srgrimes * Revision 1.3  1994/05/15  22:15:14  rgrimes
391764Srgrimes * To truely have the OLD behavior of RCS by default make the expansion
401764Srgrimes * 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
411764Srgrimes * of the pre 2.x repository. (Or at least make them useless in it).
421764Srgrimes *
431500Srgrimes * Revision 1.2  1994/05/14  07:00:23  rgrimes
441500Srgrimes * Add new option -K from David Dawes that allows you to turn on and off
451500Srgrimes * specific keyword substitution during a rcs co command.
468858Srgrimes * 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 $.
471500Srgrimes *
481494Srgrimes * Revision 1.1.1.1  1993/06/18  04:22:12  jkh
491494Srgrimes * Updated GNU utilities
501494Srgrimes *
519Sjkh * Revision 5.2  1991/08/19  03:13:55  eggert
529Sjkh * Say `T const' instead of `const T'; it's less confusing for pointer types.
539Sjkh * (This change was made in other source files too.)
549Sjkh *
559Sjkh * Revision 5.1  1991/04/21  11:58:25  eggert
569Sjkh * Don't put , just before } in initializer.
579Sjkh *
589Sjkh * Revision 5.0  1990/08/22  08:12:54  eggert
599Sjkh * Add -k.  Ansify and Posixate.
609Sjkh *
619Sjkh * Revision 4.3  89/05/01  15:13:02  narten
629Sjkh * changed copyright header to reflect current distribution rules
638858Srgrimes *
649Sjkh * Revision 4.2  87/10/18  10:36:33  narten
659Sjkh * Updating version numbers. Changes relative to 1.1 actuallyt
669Sjkh * relative to 4.1
678858Srgrimes *
689Sjkh * Revision 1.2  87/09/24  14:00:10  narten
698858Srgrimes * Sources now pass through lint (if you ignore printf/sprintf/fprintf
709Sjkh * warnings)
718858Srgrimes *
729Sjkh * Revision 4.1  83/05/04  10:06:53  wft
739Sjkh * Initial revision.
748858Srgrimes *
759Sjkh */
769Sjkh
779Sjkh
789Sjkh#include "rcsbase.h"
799Sjkh
808858SrgrimeslibId(keysId, "$Id: rcskeys.c,v 1.4 1994/06/22 00:51:42 rgrimes Exp $")
819Sjkh
829Sjkh
839Sjkhchar const *const Keyword[] = {
849Sjkh    /* This must be in the same order as rcsbase.h's enum markers type. */
859Sjkh	nil,
869Sjkh	AUTHOR, DATE, HEADER, IDH,
871500Srgrimes	LOCKER, LOG, RCSFILE, REVISION, SOURCE, STATE,
881500Srgrimes	FREEBSD
899Sjkh};
909Sjkh
919Sjkh
921494Srgrimes/* Expand all keywords by default */
939Sjkh
941494Srgrimesstatic int ExpandKeyword[] = {
951494Srgrimes	nil,
961494Srgrimes	true, true, true, true,
971764Srgrimes	true, true, true, true, true, true,
981500Srgrimes	false
991494Srgrimes};
1001494Srgrimes
1019Sjkh	enum markers
1029Sjkhtrymatch(string)
1039Sjkh	char const *string;
1049Sjkh/* function: Checks whether string starts with a keyword followed
1059Sjkh * by a KDELIM or a VDELIM.
1069Sjkh * If successful, returns the appropriate marker, otherwise Nomatch.
1079Sjkh */
1089Sjkh{
1099Sjkh        register int j;
1109Sjkh	register char const *p, *s;
1119Sjkh	for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  ) {
1121494Srgrimes		if (!ExpandKeyword[j])
1131494Srgrimes			continue;
1149Sjkh		/* try next keyword */
1159Sjkh		p = Keyword[j];
1169Sjkh		s = string;
1179Sjkh		while (*p++ == *s++) {
1189Sjkh			if (!*p)
1199Sjkh			    switch (*s) {
1209Sjkh				case KDELIM:
1219Sjkh				case VDELIM:
1229Sjkh				    return (enum markers)j;
1239Sjkh				default:
1249Sjkh				    return Nomatch;
1259Sjkh			    }
1269Sjkh		}
1279Sjkh        }
1289Sjkh        return(Nomatch);
1299Sjkh}
1309Sjkh
1311494Srgrimes
1321494SrgrimessetIncExc(arg)
1331494Srgrimes	char *arg;
1341494Srgrimes/* Sets up the ExpandKeyword table according to command-line flags */
1351494Srgrimes{
1361494Srgrimes	char *key;
1371494Srgrimes	int include = 0, j;
1381494Srgrimes
1391494Srgrimes	arg += 2;
1401494Srgrimes	switch (*arg++) {
1411494Srgrimes	    case 'e':
1421494Srgrimes		include = false;
1431494Srgrimes		break;
1441494Srgrimes	    case 'i':
1451494Srgrimes		include = true;
1461494Srgrimes		break;
1471494Srgrimes	    default:
1481494Srgrimes		return(false);
1491494Srgrimes	}
1501494Srgrimes	if (include)
1511494Srgrimes		for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  )
1521494Srgrimes			ExpandKeyword[j] = false;
1531494Srgrimes	key = strtok(arg, ",");
1541494Srgrimes	while (key) {
1551494Srgrimes		for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  )
1561494Srgrimes			if (!strcmp(key, Keyword[j]))
1571494Srgrimes				ExpandKeyword[j] = include;
1581494Srgrimes		key = strtok(NULL, ",");
1591494Srgrimes	}
1601494Srgrimes	return(true);
1611494Srgrimes}
1621494Srgrimes
163