2 * RCS keyword extraction
5 static char rcsid
[]= "$Id: rcskeep.c,v 1.1 1993/03/21 09:58:08 cgd Exp $ Purdue CS";
7 /*****************************************************************************
8 * main routine: getoldkeys()
9 * Testprogram: define KEEPTEST
10 *****************************************************************************
13 /* Copyright (C) 1982, 1988, 1989 Walter Tichy
14 * All rights reserved.
16 * Redistribution and use in source and binary forms are permitted
17 * provided that the above copyright notice and this paragraph are
18 * duplicated in all such forms and that any documentation,
19 * advertising materials, and other materials related to such
20 * distribution and use acknowledge that the software was developed
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 * Report all problems and direct all questions to:
27 * rcs-bugs@cs.purdue.edu
40 /* $Log: rcskeep.c,v $
41 * Revision 4.6 89/05/01 15:12:56 narten
42 * changed copyright header to reflect current distribution rules
44 * Revision 4.5 88/11/08 12:01:05 narten
45 * changes from eggert@sm.unisys.com (Paul Eggert)
47 * Revision 4.5 88/08/09 19:13:03 eggert
48 * Remove lint and speed up by making FILE *fp local, not global.
50 * Revision 4.4 87/12/18 11:44:21 narten
51 * more lint cleanups (Guy Harris)
53 * Revision 4.3 87/10/18 10:35:50 narten
54 * Updating version numbers. Changes relative to 1.1 actually relative
57 * Revision 1.3 87/09/24 14:00:00 narten
58 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
61 * Revision 1.2 87/03/27 14:22:29 jenkins
64 * Revision 1.1 84/01/23 14:50:30 kcs
67 * Revision 4.1 83/05/10 16:26:44 wft
68 * Added new markers Id and RCSfile; extraction added.
69 * Marker matching with trymatch().
71 * Revision 3.2 82/12/24 12:08:26 wft
72 * added missing #endif.
74 * Revision 3.1 82/12/04 13:22:41 wft
81 /* Testprogram; prints out the keyword values found. */
84 extern char * checkid();
85 extern FILE * fopen();
87 extern enum markers
trymatch();
90 char prevauthor
[IDLENGTH
];
91 char prevdate
[datelength
];
93 char prevrev
[revlength
];
94 char prevsource
[NCPPN
];
95 char prevstate
[IDLENGTH
];
96 char prevlocker
[IDLENGTH
];
101 /* Function: Tries to read keyword values for author, date,
102 * revision number, RCS file, (both with and without path),
103 * state, and workfilename out of the file fname.
104 * The results are placed into
105 * prevauthor, prevdate, prevRCS, prevrev, prevsource, prevstate.
106 * Aborts immediately if it finds an error and returns false.
107 * If it returns true, it doesn't mean that any of the
108 * values were found; instead, check to see whether the corresponding arrays
109 * contain the empty string.
114 char keyword
[keylength
+2];
116 enum markers mresult
;
118 /* initialize to empty */
119 prevauthor
[0]=prevsource
[0]=prevstate
[0]=prevdate
[0]=prevrev
[0]= '\0';
121 if ( (fp
= fopen(fname
, "r") ) == NULL
) {
122 error("Can't open %s\n", fname
);
125 while( (c
=getc(fp
)) != EOF
) {
127 /* try to get keyword */
129 while( (c
=getc(fp
))!=EOF
&& (tp
< keyword
+keylength
) && (c
!='\n')
130 && (c
!=KDELIM
) && (c
!=VDELIM
))
133 if (c
==KDELIM
) {VOID
ungetc(c
,fp
);continue;}
134 if (c
!=VDELIM
) continue;
137 while ((c
=getc(fp
))==' '||c
=='\t'); /* skip blanks */
138 VOID
ungetc(c
,fp
); /* needed for getval */
140 switch (mresult
=trymatch(keyword
,true)) {
142 if (getval(fp
,prevauthor
,IDLENGTH
,true))
143 if (!checkid(prevauthor
, '\0')) goto errexit
;
146 if (!getprevdate(fp
,true)) goto errexit
;
150 if (mresult
==Header
) {
151 if (!getval(fp
,prevsource
,NCPPN
,true)) break; /*unexpanded*/
153 if (!getval(fp
,prevRCS
,NCPFN
,true)) break; /*unexpanded*/
155 if (!getval(fp
,prevrev
,revlength
,false)) goto errexit
;
156 if (!checknum(prevrev
,-1)) {
157 error("Bad revision number");
160 if (!getprevdate(fp
,false)) goto errexit
;
161 if (!getval(fp
,prevauthor
,IDLENGTH
,false)) goto errexit
;
162 if (!checkid(prevauthor
, '\0')) goto errexit
;
163 if (!getval(fp
,prevstate
,IDLENGTH
,false)) goto errexit
;
164 if (!checkid(prevstate
, '\0')) goto errexit
;
165 VOID
getval(fp
, dummy
, IDLENGTH
, true); /* optional locker*/
166 VOID
getval(fp
, prevlocker
,IDLENGTH
,true); /* optional locker*/
169 VOID
getval(fp
,prevlocker
,IDLENGTH
,true);
170 if (!checkid(prevlocker
, '\0')) goto errexit
;
173 VOID
getval(fp
,prevRCS
,NCPPN
,true);
176 VOID
getval(fp
,prevRCS
,NCPFN
,true);
179 if (getval(fp
,prevrev
,revlength
,true))
180 if (!checknum(prevrev
,-1)) {
181 error("Bad revision number");
186 VOID
getval(fp
,prevsource
,NCPPN
,true);
189 if (getval(fp
,prevstate
,IDLENGTH
,true))
190 if (!checkid(prevstate
, '\0')) goto errexit
;
195 if (getc(fp
)!=KDELIM
)
196 warn("Closing %c missing on keyword",KDELIM
);
197 if (prevauthor
[0]!='\0'&&prevrev
[0]!='\0'&&prevstate
[0]!='\0'&&
199 ((prevsource
[0]!='\0')||(prevRCS
[0]!='\0'))){
200 /* done; prevlocker is irrelevant */
209 prevauthor
[0]=prevsource
[0]=prevstate
[0]=prevdate
[0]=prevrev
[0]= '\0';
210 VOID
fclose(fp
); return false;
214 static int getval(fp
,target
,maxchars
,optional
)
216 char * target
; int maxchars
, optional
;
217 /* Function: Places a keyword value into target, but not more
218 * than maxchars characters. Prints an error if optional==false
219 * and there is no keyword. Returns true if one is found, false otherwise.
221 { register char * tp
;
228 error("Missing keyword value");
232 while (!(c
==' '||c
=='\n'||c
=='\t'||c
==KDELIM
||c
==EOF
)) {
233 if (tp
-target
>=maxchars
-1) {
234 error("keyword value too long");
243 VOID
printf("getval: %s\n",target
);
245 while(c
==' '||c
=='\t') c
=getc(fp
); /* skip trailing blanks */
252 int getprevdate(fp
,optional
)
255 /* Function: reads a date prevdate; checks format
256 * If there is not date and optional==false, an error is printed.
257 * Returns false on error, true otherwise.
262 prevday
[0]=prevtime
[0]='\0';
263 if (!getval(fp
,prevday
,9,optional
)) return optional
;
264 if (!getval(fp
,prevtime
,9,false)) return false;
266 prevday
[2]=prevday
[5]=prevday
[8]=prevtime
[2]=prevtime
[5]='.';
268 VOID
strcpy(prevdate
,prevday
);
269 VOID
strcat(prevdate
,prevtime
);
270 if (!checknum(prevdate
,5)) {
271 error("Bad date: %s",prevdate
);
278 int checknum(sp
,fields
)
279 register char * sp
; int fields
;
280 { register int dotcount
;
281 if (sp
==nil
||*sp
=='\0') return true;
284 if (*sp
=='.') dotcount
++;
285 elsif (ctab
[*sp
]!=DIGIT
) return false;
288 if (fields
>= 0 && dotcount
!=fields
) return false;
295 char * RCSfilename
, * workfilename
;
298 int argc
; char *argv
[];
302 if (getoldkeys(*argv
))
303 VOID
printf("%s: revision: %s, date: %s, author: %s, state: %s\n",
304 *argv
, prevrev
, prevdate
, prevauthor
,prevstate
);
305 VOID
printf("Source: %s, RCSfile: %s\n",prevsource
,prevRCS
);