1 /* Copyright (C) 1982, 1988, 1989 Walter Tichy
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms are permitted
5 * provided that the above copyright notice and this paragraph are
6 * duplicated in all such forms and that any documentation,
7 * advertising materials, and other materials related to such
8 * distribution and use acknowledge that the software was developed
9 * by Walter Tichy.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
11 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Report all problems and direct all questions to:
15 * rcs-bugs@cs.purdue.edu
16 *
17
18
19
20
21
22
23
24 */
25
26 /*
27 * RCS identification operation
28 */
29 #ifndef lint
30 static char rcsid[]=
31 "$Header: /usr/src/local/bin/rcs/src/RCS/ident.c,v 4.5 89/05/01 15:11:54 narten Exp $Purdue CS";
32 #endif
33
34 /* $Log: ident.c,v $
35 * Revision 4.5 89/05/01 15:11:54 narten
36 * changed copyright header to reflect current distribution rules
37 *
38 * Revision 4.4 87/10/23 17:09:57 narten
39 * added exit(0) so exit return code would be non random
40 *
41 * Revision 4.3 87/10/18 10:23:55 narten
42 * Updating version numbers. Changes relative to 1.1 are actually relative
43 * to 4.1
44 *
45 * Revision 1.3 87/07/09 09:20:52 trinkle
46 * Added check to make sure there is at least one arg before comparing argv[1]
47 * with "-q". This necessary on machines that don't allow dereferncing null
48 * pointers (i.e. Suns).
49 *
50 * Revision 1.2 87/03/27 14:21:47 jenkins
51 * Port to suns
52 *
53 * Revision 1.1 84/01/23 14:50:03 kcs
54 * Initial revision
55 *
56 * Revision 4.1 83/05/10 16:31:02 wft
57 * Added option -q and input from reading stdin.
58 * Marker matching is now done with trymatch() (independent of keywords).
59 *
60 * Revision 3.4 83/02/18 17:37:49 wft
61 * removed printing of new line after last file.
62 *
63 * Revision 3.3 82/12/04 12:48:55 wft
64 * Added LOCKER.
65 *
66 * Revision 3.2 82/11/28 18:24:17 wft
67 * removed Suffix; added ungetc to avoid skipping over trailing KDELIM.
68 *
69 * Revision 3.1 82/10/13 15:58:51 wft
70 * fixed type of variables receiving from getc() (char-->int).
71 */
72
73 #include "rcsbase.h"
74 #ifdef _FSTDIO
75 #undef putc
76 #define putc __sputc
77 #else
78 #define fflsbuf _flsbuf
79 #endif
80 /* redefinition of putc not needed */
81 #ifndef lint
82 static char rcsbaseid[] = RCSBASE;
83 #endif
84
85 extern enum markers trymatch();
86
87 int quietflag;
88
main(argc,argv)89 main(argc, argv)
90 int argc; char *argv[];
91 /* Ident searches the named files for all occurrences
92 * of the pattern $keyword:...$, where the keywords are
93 * Author, Date, Header, Id, Log, RCSfile, Revision, Source, and State.
94 */
95
96 {
97 FILE *fp, *fopen();
98
99 quietflag = false;
100 if (argc > 1 && strcmp("-q",argv[1])==0) {
101 quietflag = true;
102 argc--; argv++;
103 }
104
105 if (argc<2) {
106 if ((scanfile(stdin) == 0) && !quietflag)
107 VOID fprintf(stderr, "ident warning: no id keywords in input\n");
108 exit(0);
109 }
110
111 while ( --argc > 0 ) {
112 if ( (fp = fopen(*++argv, "r") ) == NULL ) {
113 VOID fprintf(stderr, "ident error: can't open %s\n", *argv);
114 continue;
115 } else {
116 VOID printf( "%s:\n", *argv); /* print file name */
117 if ((scanfile(fp) == 0) && !quietflag)
118 VOID fprintf(stderr, "ident warning: no id keywords in %s\n", *argv);
119 if (argc>1) putchar('\n');
120 VOID fclose(fp);
121 }
122 }
123 exit(0);
124 }
125
126
scanfile(file)127 int scanfile(file)
128 FILE * file;
129 /* Function: scan an open file with descriptor file for keywords.
130 * Returns the number of matches.
131 */
132 {
133 register int matchcount;
134 register int c;
135
136
137 matchcount = 0;
138 while( (c=getc(file)) != EOF) {
139 if ( (char)c==KDELIM)
140 matchcount += match(file);
141 }
142 return matchcount;
143 }
144
145
146
match(fp)147 match(fp) /* group substring between two KDELIM's; then do pattern match */
148 FILE *fp;
149 {
150 char line[keyvallength];
151 register int c;
152 register char * tp;
153
154 tp = line;
155 while( (c = getc(fp)) != KDELIM ) {
156 *tp++ = c;
157 if ( c==EOF || c=='\n' || tp>= line+keyvallength-2)
158 return(0);
159 }
160 *tp++ = c; /*append trailing KDELIM*/
161 *tp = '\0';
162 if (trymatch(line,true)!=Nomatch) {
163 VOID fprintf(stdout," $%s\n",line);
164 return(1);
165 } else {
166 /* no match; put trailing KDELIM back into input */
167 VOID ungetc(c,fp );
168 return(0);
169 }
170 }
171