rcskeys.c revision 11894
111894Speter/* RCS keyword table and match operation */
29Sjkh
311894Speter/* Copyright 1982, 1988, 1989 Walter Tichy
411894Speter   Copyright 1990, 1991, 1992, 1993, 1995 Paul Eggert
59Sjkh   Distributed under license by the Free Software Foundation, Inc.
69Sjkh
79SjkhThis file is part of RCS.
89Sjkh
99SjkhRCS is free software; you can redistribute it and/or modify
109Sjkhit under the terms of the GNU General Public License as published by
119Sjkhthe Free Software Foundation; either version 2, or (at your option)
129Sjkhany later version.
139Sjkh
149SjkhRCS is distributed in the hope that it will be useful,
159Sjkhbut WITHOUT ANY WARRANTY; without even the implied warranty of
169SjkhMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
179SjkhGNU General Public License for more details.
189Sjkh
199SjkhYou should have received a copy of the GNU General Public License
2011894Speteralong with RCS; see the file COPYING.
2111894SpeterIf not, write to the Free Software Foundation,
2211894Speter59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
239Sjkh
249SjkhReport problems and direct all questions to:
259Sjkh
269Sjkh    rcs-bugs@cs.purdue.edu
279Sjkh
289Sjkh*/
299Sjkh
3011894Speter/*
3111894Speter * $Log: rcskeys.c,v $
3211894Speter * Revision 5.4  1995/06/16 06:19:24  eggert
3311894Speter * Update FSF address.
348858Srgrimes *
3511894Speter * Revision 5.3  1993/11/03 17:42:27  eggert
3611894Speter * Add Name keyword.
371764Srgrimes *
389Sjkh * Revision 5.2  1991/08/19  03:13:55  eggert
399Sjkh * Say `T const' instead of `const T'; it's less confusing for pointer types.
409Sjkh * (This change was made in other source files too.)
419Sjkh *
429Sjkh * Revision 5.1  1991/04/21  11:58:25  eggert
439Sjkh * Don't put , just before } in initializer.
449Sjkh *
459Sjkh * Revision 5.0  1990/08/22  08:12:54  eggert
469Sjkh * Add -k.  Ansify and Posixate.
479Sjkh *
489Sjkh * Revision 4.3  89/05/01  15:13:02  narten
499Sjkh * changed copyright header to reflect current distribution rules
508858Srgrimes *
519Sjkh * Revision 4.2  87/10/18  10:36:33  narten
529Sjkh * Updating version numbers. Changes relative to 1.1 actuallyt
539Sjkh * relative to 4.1
548858Srgrimes *
559Sjkh * Revision 1.2  87/09/24  14:00:10  narten
568858Srgrimes * Sources now pass through lint (if you ignore printf/sprintf/fprintf
579Sjkh * warnings)
588858Srgrimes *
599Sjkh * Revision 4.1  83/05/04  10:06:53  wft
609Sjkh * Initial revision.
618858Srgrimes *
629Sjkh */
639Sjkh
649Sjkh
659Sjkh#include "rcsbase.h"
669Sjkh
6711894SpeterlibId(keysId, "$Id: rcskeys.c,v 5.4 1995/06/16 06:19:24 eggert Exp $")
689Sjkh
699Sjkh
709Sjkhchar const *const Keyword[] = {
719Sjkh    /* This must be in the same order as rcsbase.h's enum markers type. */
7211894Speter	0,
739Sjkh	AUTHOR, DATE, HEADER, IDH,
7411894Speter	LOCKER, LOG, NAME, RCSFILE, REVISION, SOURCE, STATE
759Sjkh};
769Sjkh
779Sjkh
789Sjkh
799Sjkh	enum markers
809Sjkhtrymatch(string)
819Sjkh	char const *string;
829Sjkh/* function: Checks whether string starts with a keyword followed
839Sjkh * by a KDELIM or a VDELIM.
849Sjkh * If successful, returns the appropriate marker, otherwise Nomatch.
859Sjkh */
869Sjkh{
879Sjkh        register int j;
889Sjkh	register char const *p, *s;
899Sjkh	for (j = sizeof(Keyword)/sizeof(*Keyword);  (--j);  ) {
909Sjkh		/* try next keyword */
919Sjkh		p = Keyword[j];
929Sjkh		s = string;
939Sjkh		while (*p++ == *s++) {
949Sjkh			if (!*p)
959Sjkh			    switch (*s) {
969Sjkh				case KDELIM:
979Sjkh				case VDELIM:
989Sjkh				    return (enum markers)j;
999Sjkh				default:
1009Sjkh				    return Nomatch;
1019Sjkh			    }
1029Sjkh		}
1039Sjkh        }
1049Sjkh        return(Nomatch);
1059Sjkh}
1069Sjkh
107