1 /* Identify RCS keyword strings in files. */
3 /* Copyright 1982, 1988, 1989 Walter Tichy
4 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Paul Eggert
5 Distributed under license by the Free Software Foundation, Inc.
7 This file is part of RCS.
9 RCS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 RCS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with RCS; see the file COPYING.
21 If not, write to the Free Software Foundation,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 Report problems and direct all questions to:
26 rcs-bugs@cs.purdue.edu
31 * Revision 5.9 1995/06/16 06:19:24 eggert
34 * Revision 5.8 1995/06/01 16:23:43 eggert
35 * (exiterr, reportError): New functions, needed for DOS and OS/2 ports.
36 * (scanfile): Use them.
38 * Revision 5.7 1994/03/20 04:52:58 eggert
39 * Remove `exiting' from identExit.
41 * Revision 5.6 1993/11/09 17:40:15 eggert
44 * Revision 5.5 1993/11/03 17:42:27 eggert
45 * Test for char == EOF, not char < 0.
47 * Revision 5.4 1992/01/24 18:44:19 eggert
50 * Revision 5.3 1991/09/10 22:15:46 eggert
51 * Open files with FOPEN_R, not FOPEN_R_WORK,
52 * because they might be executables, not working files.
54 * Revision 5.2 1991/08/19 03:13:55 eggert
55 * Report read errors immediately.
57 * Revision 5.1 1991/02/25 07:12:37 eggert
58 * Don't report empty keywords. Check for I/O errors.
60 * Revision 5.0 1990/08/22 08:12:37 eggert
61 * Don't limit output to known keywords.
62 * Remove arbitrary limits and lint. Ansify and Posixate.
64 * Revision 4.5 89/05/01 15:11:54 narten
65 * changed copyright header to reflect current distribution rules
67 * Revision 4.4 87/10/23 17:09:57 narten
68 * added exit(0) so exit return code would be non random
70 * Revision 4.3 87/10/18 10:23:55 narten
71 * Updating version numbers. Changes relative to 1.1 are actually relative
74 * Revision 1.3 87/07/09 09:20:52 trinkle
75 * Added check to make sure there is at least one arg before comparing argv[1]
76 * with "-q". This necessary on machines that don't allow dereferncing null
77 * pointers (i.e. Suns).
79 * Revision 1.2 87/03/27 14:21:47 jenkins
82 * Revision 4.1 83/05/10 16:31:02 wft
83 * Added option -q and input from reading stdin.
84 * Marker matching is now done with trymatch() (independent of keywords).
86 * Revision 3.4 83/02/18 17:37:49 wft
87 * removed printing of new line after last file.
89 * Revision 3.3 82/12/04 12:48:55 wft
92 * Revision 3.2 82/11/28 18:24:17 wft
93 * removed Suffix; added ungetc to avoid skipping over trailing KDELIM.
95 * Revision 3.1 82/10/13 15:58:51 wft
96 * fixed type of variables receiving from getc() (char-->int).
101 static int match P((FILE*));
102 static int scanfile P((FILE*,char const*,int));
103 static void reportError P((char const*));
105 mainProg(identId, "ident", "$FreeBSD$")
106 /* Ident searches the named files for all occurrences
107 * of the pattern $@: text $ where @ is a keyword.
113 int status = EXIT_SUCCESS;
116 while ((a = *++argv) && *a=='-')
124 VOID printf("RCS version %s\n", RCS_version_string);
130 "ident: usage: ident -{qV} [file...]\n"
132 exitmain(EXIT_FAILURE);
138 VOID scanfile(stdin, (char*)0, quiet);
141 if (!(fp = fopen(a, FOPEN_RB))) {
143 status = EXIT_FAILURE;
145 scanfile(fp, a, quiet) != 0
146 || (argv[1] && putchar('\n') == EOF)
149 } while ((a = *++argv));
151 if (ferror(stdout) || fclose(stdout)!=0) {
152 reportError("standard output");
153 status = EXIT_FAILURE;
159 # define exiterr identExit
172 VOID fprintf(stderr, "%s error: ", cmdid);
179 scanfile(file, name, quiet)
183 /* Function: scan an open file with descriptor file for keywords.
184 * Return -1 if there's a write error; exit immediately on a read error.
190 VOID printf("%s:\n", name);
194 name = "standard input";
196 while (c != EOF || ! (feof(file)|ferror(file))) {
198 if ((c = match(file)))
206 if (ferror(file) || fclose(file) != 0) {
209 * The following is equivalent to exit(EXIT_FAILURE), but we invoke
210 * exiterr to keep lint happy. The DOS and OS/2 ports need exiterr.
217 VOID fprintf(stderr, "%s warning: no id keywords in %s\n", cmdid, name);
224 match(fp) /* group substring between two KDELIM's; then do pattern match */
232 while ((c = getc(fp)) != VDELIM) {
233 if (c == EOF && feof(fp) | ferror(fp))
236 case LETTER: case Letter: case DIGIT:
238 if (tp < line+sizeof(line)-4)
242 return c ? c : '\n'/* anything but 0 or KDELIM or EOF */;
248 if ((c = getc(fp)) != ' ')
251 while( (c = getc(fp)) != KDELIM ) {
252 if (c == EOF && feof(fp) | ferror(fp))
257 if (tp < line+sizeof(line)-2)
260 case NEWLN: case UNKN:
266 *tp++ = c; /*append trailing KDELIM*/
268 VOID printf(" %c%s\n", KDELIM, line);