1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
/* $OpenBSD: rcsprog.c,v 1.3 2005/04/06 18:51:29 joris Exp $ */
/*
* Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <err.h>
#include <pwd.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sysexits.h>
#include "log.h"
#include "rcs.h"
#include "strtab.h"
extern char *__progname;
const char rcs_version[] = "OpenCVS RCS version 3.6";
void rcs_usage (void);
int rcs_main (int, char **);
struct rcs_prog {
char *prog_name;
int (*prog_hdlr)(int, char **);
} programs[] = {
{ "rcs", rcs_main },
{ "ci", NULL },
{ "co", NULL },
{ "rcsclean", NULL },
{ "rcsdiff", NULL },
};
int
main(int argc, char **argv)
{
u_int i;
int ret;
ret = -1;
cvs_strtab_init();
for (i = 0; i < (sizeof(programs)/sizeof(programs[0])); i++)
if (strcmp(__progname, programs[i].prog_name) == 0)
ret = programs[i].prog_hdlr(argc, argv);
cvs_strtab_cleanup();
return (ret);
}
void
rcs_usage(void)
{
fprintf(stderr,
"Usage: %s [-hiLMUV] [-a users] [-b [rev]] [-c string] "
"[-e users] [-k opt] file ...\n"
"\t-a users\tAdd the login names in the comma-separated <users>\n"
"\t-b rev\t\tSet the head revision to <rev>\n"
"\t-c string\tSet the comment leader to <string>\n"
"\t-e users\tRemove the login names in the comma-separated <users>\n"
"\t-h\t\tPrint the program's usage and exit\n"
"\t-i\t\tCreate a new empty RCS file\n"
"\t-k opt\t\tSet the keyword expansion mode to <opt>\n"
"\t-L\t\tEnable strict locking on the specified files\n"
"\t-M\t\tDisable mail warning about lock breaks\n"
"\t-U\t\tDisable strict locking on the specified files\n"
"\t-V\t\tPrint the program's version string and exit\n",
__progname);
}
/*
* rcs_main()
*
* Handler for the `rcs' program.
* Returns 0 on success, or >0 on error.
*/
int
rcs_main(int argc, char **argv)
{
int i, ch, flags, kflag, lkmode;
char *oldfile, *alist, *comment, *elist, *unp, *sp;
mode_t fmode;
RCSFILE *file;
kflag = lkmode = -1;
fmode = 0;
flags = RCS_READ;
oldfile = alist = comment = elist = NULL;
cvs_log_init(LD_STD, 0);
while ((ch = getopt(argc, argv, "A:a:b::c:e::hik:LMUV")) != -1) {
switch (ch) {
case 'A':
oldfile = optarg;
break;
case 'a':
alist = optarg;
break;
case 'c':
comment = optarg;
break;
case 'e':
elist = optarg;
break;
case 'h':
rcs_usage();
exit(0);
case 'i':
flags |= (RCS_WRITE | RCS_CREATE);
break;
case 'k':
kflag = rcs_kflag_get(optarg);
if (RCS_KWEXP_INVAL(kflag)) {
cvs_log(LP_ERR,
"invalid keyword substitution mode `%s'",
optarg);
exit(1);
}
break;
case 'L':
if (lkmode == RCS_LOCK_LOOSE)
cvs_log(LP_WARN, "-U overriden by -L");
lkmode = RCS_LOCK_STRICT;
break;
case 'M':
/* ignore for the moment */
break;
case 'U':
if (lkmode == RCS_LOCK_STRICT)
cvs_log(LP_WARN, "-L overriden by -U");
lkmode = RCS_LOCK_LOOSE;
break;
case 'V':
printf("%s\n", rcs_version);
exit(0);
default:
rcs_usage();
exit(1);
}
}
argc -= optind;
argv += optind;
if (argc == 0) {
cvs_log(LP_ERR, "no input file");
exit(1);
}
for (i = 0; i < argc; i++) {
printf("RCS file: %s\n", argv[0]);
file = rcs_open(argv[0], flags, fmode);
if (file == NULL) {
return (1);
}
/* entries to add to the access list */
if (alist != NULL) {
unp = alist;
do {
sp = strchr(unp, ',');
if (sp != NULL)
*(sp++) = '\0';
rcs_access_add(file, unp);
unp = sp;
} while (sp != NULL);
}
if (comment != NULL)
rcs_comment_set(file, comment);
if (kflag != -1)
rcs_kwexp_set(file, kflag);
if (lkmode != -1)
rcs_lock_setmode(file, lkmode);
rcs_close(file);
printf("done\n");
}
return (0);
}
|