Annotation of src/usr.bin/cvs/checkout.c, Revision 1.15
1.15 ! xsa 1: /* $OpenBSD: checkout.c,v 1.14 2005/03/30 17:43:04 joris Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.11 tedu 4: * All rights reserved.
1.1 jfb 5: *
1.11 tedu 6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
1.1 jfb 9: *
1.11 tedu 10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
1.1 jfb 12: * 2. The name of the author may not be used to endorse or promote products
1.11 tedu 13: * derived from this software without specific prior written permission.
1.1 jfb 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
1.11 tedu 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1 jfb 25: */
26:
27: #include <sys/types.h>
28:
29: #include <errno.h>
30: #include <stdio.h>
31: #include <stdlib.h>
32: #include <unistd.h>
33: #include <string.h>
34: #include <sysexits.h>
35:
36: #include "cvs.h"
37: #include "log.h"
1.6 jfb 38: #include "file.h"
1.5 jfb 39: #include "proto.h"
1.1 jfb 40:
41:
1.13 jfb 42: #define CVS_LISTMOD 1
43: #define CVS_STATMOD 2
44:
1.14 joris 45: int cvs_checkout_options(char *, int, char **, int *);
46: int cvs_checkout_sendflags(struct cvsroot *);
47:
48: struct cvs_cmd_info cvs_checkout = {
49: cvs_checkout_options,
50: cvs_checkout_sendflags,
51: NULL, NULL, NULL,
52: 0,
53: CVS_REQ_CO,
54: CVS_CMD_SENDDIR | CVS_CMD_SENDARGS1 | CVS_CMD_SENDARGS2
55: };
56:
57: static char *date, *rev, *koptstr, *tgtdir, *rcsid;
58: static int statmod = 0;
59: static int kflag = RCS_KWEXP_DEFAULT;
1.1 jfb 60:
61: int
1.14 joris 62: cvs_checkout_options(char *opt, int argc, char **argv, int *arg)
1.1 jfb 63: {
1.14 joris 64: int ch;
65:
66: date = rev = koptstr = tgtdir = rcsid = NULL;
1.13 jfb 67: kflag = RCS_KWEXP_DEFAULT;
68:
1.14 joris 69: while ((ch = getopt(argc, argv, opt)) != -1) {
1.1 jfb 70: switch (ch) {
1.13 jfb 71: case 'A':
72: break;
1.10 jfb 73: case 'c':
1.13 jfb 74: statmod = CVS_LISTMOD;
75: break;
76: case 'D':
77: date = optarg;
78: break;
79: case 'd':
80: tgtdir = optarg;
81: break;
82: case 'f':
83: break;
84: case 'j':
85: break;
86: case 'k':
87: koptstr = optarg;
88: kflag = rcs_kflag_get(koptstr);
89: if (RCS_KWEXP_INVAL(kflag)) {
90: cvs_log(LP_ERR,
91: "invalid RCS keyword expansion mode");
92: rcs_kflag_usage();
93: return (EX_USAGE);
94: }
95: break;
96: case 'r':
97: rev = optarg;
98: break;
99: case 's':
100: statmod = CVS_STATMOD;
101: break;
102: case 't':
103: rcsid = optarg;
1.10 jfb 104: break;
1.1 jfb 105: default:
106: return (EX_USAGE);
107: }
108: }
109:
110: argc -= optind;
111: argv += optind;
112:
1.13 jfb 113: if (!statmod && (argc == 0)) {
1.1 jfb 114: cvs_log(LP_ERR,
115: "must specify at least one module or directory");
116: return (EX_USAGE);
117: }
118:
1.13 jfb 119: if (statmod && (argc > 0)) {
120: cvs_log(LP_ERR, "-c and -s must not get any arguments");
121: return (EX_USAGE);
122: }
123:
1.14 joris 124: *arg = optind;
125: return (0);
126: }
1.9 jfb 127:
1.14 joris 128: int
129: cvs_checkout_sendflags(struct cvsroot *root)
130: {
131: if (cvs_senddir(root, cvs_files) < 0)
1.15 ! xsa 132: return (-1);
1.14 joris 133: if (cvs_sendreq(root, CVS_REQ_XPANDMOD, NULL) < 0)
134: cvs_log(LP_ERR, "failed to expand module");
135:
136: /* XXX not too sure why we have to send this arg */
137: if (cvs_sendarg(root, "-N", 0) < 0)
1.15 ! xsa 138: return (-1);
1.14 joris 139:
140: if ((statmod == CVS_LISTMOD) &&
141: (cvs_sendarg(root, "-c", 0) < 0))
1.15 ! xsa 142: return (-1);
1.14 joris 143:
144: if ((statmod == CVS_STATMOD) &&
145: (cvs_sendarg(root, "-s", 0) < 0))
1.15 ! xsa 146: return (-1);
1.1 jfb 147:
148: return (0);
149: }