Annotation of src/usr.bin/rcs/rcsprog.c, Revision 1.6
1.6 ! joris 1: /* $OpenBSD: rcsprog.c,v 1.5 2005/09/20 04:30:57 joris Exp $ */
1.1 deraadt 2: /*
3: * Copyright (c) 2005 Jean-Francois Brousseau <jfb@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.6 ! joris 27: #include <sys/param.h>
1.1 deraadt 28: #include <sys/wait.h>
29:
1.3 joris 30: #include <ctype.h>
1.1 deraadt 31: #include <err.h>
1.3 joris 32: #include <errno.h>
1.1 deraadt 33: #include <pwd.h>
1.3 joris 34: #include <signal.h>
35: #include <string.h>
1.1 deraadt 36: #include <stdio.h>
37: #include <stdlib.h>
38: #include <unistd.h>
39:
40: #include "log.h"
41: #include "rcs.h"
42: #include "strtab.h"
43:
44: extern char *__progname;
45:
46:
47: const char rcs_version[] = "OpenCVS RCS version 3.6";
48:
1.2 deraadt 49: void rcs_usage(void);
50: int rcs_main(int, char **);
51: void (*usage)(void);
1.1 deraadt 52:
53: struct rcs_prog {
54: char *prog_name;
55: int (*prog_hdlr)(int, char **);
1.2 deraadt 56: void (*prog_usage)(void);
1.1 deraadt 57: } programs[] = {
1.2 deraadt 58: { "rcs", rcs_main, rcs_usage },
59: { "ci", NULL, NULL },
60: { "co", NULL, NULL },
61: { "rcsclean", NULL, NULL },
62: { "rcsdiff", NULL, NULL },
1.1 deraadt 63: };
64:
65:
66: int
67: main(int argc, char **argv)
68: {
69: u_int i;
70: int ret;
71:
72: ret = -1;
73: cvs_strtab_init();
74:
75: for (i = 0; i < (sizeof(programs)/sizeof(programs[0])); i++)
1.2 deraadt 76: if (strcmp(__progname, programs[i].prog_name) == 0) {
77: usage = programs[i].prog_usage;
1.1 deraadt 78: ret = programs[i].prog_hdlr(argc, argv);
1.2 deraadt 79: break;
80: }
1.1 deraadt 81:
82: cvs_strtab_cleanup();
83:
84: return (ret);
85: }
86:
87:
88: void
89: rcs_usage(void)
90: {
91: fprintf(stderr,
1.2 deraadt 92: "usage: %s [-hiLMUV] [-a users] [-b [rev]] [-c string] "
93: "[-e users] [-k opt] file ...\n", __progname);
1.1 deraadt 94: }
95:
96:
97: /*
98: * rcs_main()
99: *
100: * Handler for the `rcs' program.
101: * Returns 0 on success, or >0 on error.
102: */
103: int
104: rcs_main(int argc, char **argv)
105: {
106: int i, ch, flags, kflag, lkmode;
1.6 ! joris 107: char fpath[MAXPATHLEN];
1.1 deraadt 108: char *oldfile, *alist, *comment, *elist, *unp, *sp;
109: mode_t fmode;
110: RCSFILE *file;
111:
112: kflag = lkmode = -1;
113: fmode = 0;
114: flags = RCS_RDWR;
115: oldfile = alist = comment = elist = NULL;
116:
117: cvs_log_init(LD_STD, 0);
118:
119: while ((ch = getopt(argc, argv, "A:a:b::c:e::hik:LMUV")) != -1) {
120: switch (ch) {
121: case 'A':
122: oldfile = optarg;
123: break;
124: case 'a':
125: alist = optarg;
126: break;
127: case 'c':
128: comment = optarg;
129: break;
130: case 'e':
131: elist = optarg;
132: break;
133: case 'h':
1.2 deraadt 134: (usage)();
1.1 deraadt 135: exit(0);
136: case 'i':
137: flags |= RCS_CREATE;
138: break;
139: case 'k':
140: kflag = rcs_kflag_get(optarg);
141: if (RCS_KWEXP_INVAL(kflag)) {
142: cvs_log(LP_ERR,
143: "invalid keyword substitution mode `%s'",
144: optarg);
145: exit(1);
146: }
147: break;
148: case 'L':
149: if (lkmode == RCS_LOCK_LOOSE)
150: cvs_log(LP_WARN, "-U overriden by -L");
151: lkmode = RCS_LOCK_STRICT;
152: break;
153: case 'M':
154: /* ignore for the moment */
155: break;
156: case 'U':
157: if (lkmode == RCS_LOCK_STRICT)
158: cvs_log(LP_WARN, "-L overriden by -U");
159: lkmode = RCS_LOCK_LOOSE;
160: break;
161: case 'V':
162: printf("%s\n", rcs_version);
163: exit(0);
164: default:
1.2 deraadt 165: (usage)();
1.1 deraadt 166: exit(1);
167: }
168: }
169:
170: argc -= optind;
171: argv += optind;
172: if (argc == 0) {
173: cvs_log(LP_ERR, "no input file");
1.5 joris 174: (usage)();
1.1 deraadt 175: exit(1);
176: }
177:
178: for (i = 0; i < argc; i++) {
1.6 ! joris 179: /*
! 180: * Our RCS API does not append the RCS_FILE_EXT extension
! 181: * automaticly in rcs_open(), so we add it here.
! 182: */
! 183: snprintf(fpath, sizeof(fpath), "%s%s", argv[i], RCS_FILE_EXT);
! 184:
! 185: printf("RCS file: %s\n", fpath);
! 186: file = rcs_open(fpath, flags, fmode);
! 187: if (file == NULL)
! 188: continue;
1.1 deraadt 189:
190: /* entries to add to the access list */
191: if (alist != NULL) {
192: unp = alist;
193: do {
194: sp = strchr(unp, ',');
195: if (sp != NULL)
196: *(sp++) = '\0';
197:
198: rcs_access_add(file, unp);
199:
200: unp = sp;
201: } while (sp != NULL);
202: }
203:
204: if (comment != NULL)
205: rcs_comment_set(file, comment);
206:
207: if (kflag != -1)
208: rcs_kwexp_set(file, kflag);
209:
210: if (lkmode != -1)
211: rcs_lock_setmode(file, lkmode);
212:
213: rcs_close(file);
214: printf("done\n");
215: }
216:
217: return (0);
218: }