Annotation of src/usr.bin/rcs/ident.c, Revision 1.9
1.9 ! xsa 1: /* $OpenBSD: ident.c,v 1.8 2005/11/30 17:51:12 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:
1.9 ! xsa 27: #include "includes.h"
1.1 joris 28:
29: #include "log.h"
30: #include "rcs.h"
31: #include "rcsprog.h"
32:
33: #define KEYDELIM '$' /* keywords delimitor */
34: #define VALDELIM ':' /* values delimitor */
35:
1.3 joris 36: static int found = 0;
1.1 joris 37:
38: static int ident_file(const char *, FILE *);
39: static int ident_line(FILE *);
40:
41: int
42: ident_main(int argc, char **argv)
43: {
44: int i, ch;
45: FILE *fp;
46:
1.5 joris 47: while ((ch = rcs_getopt(argc, argv, "qV")) != -1) {
1.1 joris 48: switch(ch) {
49: case 'q':
50: verbose = 0;
51: break;
52: case 'V':
53: printf("%s\n", rcs_version);
54: exit(0);
55: default:
56: (usage)();
57: exit(1);
58: }
59: }
60:
1.5 joris 61: argc -= rcs_optind;
62: argv += rcs_optind;
1.1 joris 63:
1.2 xsa 64: if (argc == 0)
1.1 joris 65: ident_file(NULL, stdin);
1.2 xsa 66: else {
1.1 joris 67: for (i = 0; i < argc; i++) {
68: if ((fp = fopen(argv[i], "r")) == NULL) {
69: cvs_log(LP_ERRNO, "%s", argv[i]);
70: continue;
71: }
72:
73: ident_file(argv[i], fp);
74: fclose(fp);
75: }
76: }
77:
78: return (0);
79: }
80:
81:
82: static int
83: ident_file(const char *filename, FILE *fp)
84: {
85: int c;
86:
1.7 xsa 87: if (filename != NULL)
1.1 joris 88: printf("%s:\n", filename);
1.7 xsa 89: else
90: filename = "standard output";
1.1 joris 91:
92: for (c = 0; c != EOF; (c = getc(fp))) {
93: if ((feof(fp)) || (ferror(fp)))
94: break;
95: if (c == KEYDELIM)
96: ident_line(fp);
97: }
1.7 xsa 98:
99: if ((found == 0) && (verbose == 1))
100: fprintf(stderr, "ident warning: no id keywords in %s\n",
101: filename);
102:
103: found = 0;
1.1 joris 104:
105: return (0);
106: }
107:
108: static int
109: ident_line(FILE *fp)
110: {
111: int c;
112: char *p, linebuf[1024];
113:
114: p = linebuf;
115:
116: while ((c = getc(fp)) != VALDELIM) {
117: if ((c == EOF) && (feof(fp) | ferror(fp)))
118: return (0);
119:
120: if (isalpha(c))
121: *(p++) = c;
122: else
123: return (0);
124: }
125:
1.2 xsa 126: *(p++) = VALDELIM;
1.1 joris 127:
128: while ((c = getc(fp)) != KEYDELIM) {
129: if ((c == EOF) && (feof(fp) | ferror(fp)))
130: return (0);
131:
132: if (c == '\n')
133: return (0);
134:
135: *(p++) = c;
136: }
137:
138: if (p[-1] != ' ')
139: return (0);
140:
141: /* append trailing KEYDELIM */
142: *(p++) = c;
143: *p = '\0';
144:
1.3 joris 145: found++;
1.2 xsa 146: printf(" %c%s\n", KEYDELIM, linebuf);
1.1 joris 147:
148: return (0);
149: }
150:
151: void
152: ident_usage(void)
153: {
1.8 xsa 154: fprintf(stderr, "usage: ident [-qV] [file ...]\n");
1.1 joris 155: }