Annotation of src/usr.bin/rcs/ident.c, Revision 1.3
1.3 ! joris 1: /* $OpenBSD: ident.c,v 1.2 2005/10/06 16:02:42 xsa Exp $ */
1.1 joris 2: /*
3: * Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: *
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. The name of the author may not be used to endorse or promote products
13: * derived from this software without specific prior written permission.
14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
27: #include <sys/param.h>
28:
29: #include <ctype.h>
30: #include <stdio.h>
31: #include <stdlib.h>
32: #include <string.h>
33: #include <unistd.h>
34:
35: #include "log.h"
36: #include "rcs.h"
37: #include "rcsprog.h"
38:
39: #define KEYDELIM '$' /* keywords delimitor */
40: #define VALDELIM ':' /* values delimitor */
41:
42: extern char *__progname;
1.3 ! joris 43: static int found = 0;
1.1 joris 44:
45: static int ident_file(const char *, FILE *);
46: static int ident_line(FILE *);
47:
48: int
49: ident_main(int argc, char **argv)
50: {
51: int i, ch;
52: FILE *fp;
53:
54: while ((ch = getopt(argc, argv, "qV")) != -1) {
55: switch(ch) {
56: case 'q':
57: verbose = 0;
58: break;
59: case 'V':
60: printf("%s\n", rcs_version);
61: exit(0);
62: default:
63: (usage)();
64: exit(1);
65: }
66: }
67:
68: argc -= optind;
69: argv += optind;
70:
1.2 xsa 71: if (argc == 0)
1.1 joris 72: ident_file(NULL, stdin);
1.2 xsa 73: else {
1.1 joris 74: for (i = 0; i < argc; i++) {
75: if ((fp = fopen(argv[i], "r")) == NULL) {
76: cvs_log(LP_ERRNO, "%s", argv[i]);
77: continue;
78: }
79:
80: ident_file(argv[i], fp);
81: fclose(fp);
1.3 ! joris 82:
! 83: if (found == 0)
! 84: cvs_log(LP_WARN, "no id keywords in %s", argv[i]);
! 85: found = 0;
1.1 joris 86: }
87: }
88:
89: return (0);
90: }
91:
92:
93: static int
94: ident_file(const char *filename, FILE *fp)
95: {
96: int c;
97:
98: if (fp != stdin)
99: printf("%s:\n", filename);
100:
101: for (c = 0; c != EOF; (c = getc(fp))) {
102: if ((feof(fp)) || (ferror(fp)))
103: break;
104: if (c == KEYDELIM)
105: ident_line(fp);
106: }
107:
108: return (0);
109: }
110:
111: static int
112: ident_line(FILE *fp)
113: {
114: int c;
115: char *p, linebuf[1024];
116:
117: p = linebuf;
118:
119: while ((c = getc(fp)) != VALDELIM) {
120: if ((c == EOF) && (feof(fp) | ferror(fp)))
121: return (0);
122:
123: if (isalpha(c))
124: *(p++) = c;
125: else
126: return (0);
127: }
128:
1.2 xsa 129: *(p++) = VALDELIM;
1.1 joris 130:
131: while ((c = getc(fp)) != KEYDELIM) {
132: if ((c == EOF) && (feof(fp) | ferror(fp)))
133: return (0);
134:
135: if (c == '\n')
136: return (0);
137:
138: *(p++) = c;
139: }
140:
141: if (p[-1] != ' ')
142: return (0);
143:
144: /* append trailing KEYDELIM */
145: *(p++) = c;
146: *p = '\0';
147:
1.3 ! joris 148: found++;
1.2 xsa 149: printf(" %c%s\n", KEYDELIM, linebuf);
1.1 joris 150:
151: return (0);
152: }
153:
154: void
155: ident_usage(void)
156: {
157: fprintf(stderr, "Usage: %s [-qV] file ...\n", __progname);
158: }