Annotation of src/usr.bin/cvs/checkout.c, Revision 1.18
1.18 ! joris 1: /* $OpenBSD: checkout.c,v 1.17 2005/04/11 18:02:58 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:
35: #include "cvs.h"
36: #include "log.h"
1.6 jfb 37: #include "file.h"
1.5 jfb 38: #include "proto.h"
1.1 jfb 39:
40:
1.13 jfb 41: #define CVS_LISTMOD 1
42: #define CVS_STATMOD 2
43:
1.14 joris 44: int cvs_checkout_options(char *, int, char **, int *);
45: int cvs_checkout_sendflags(struct cvsroot *);
46:
47: struct cvs_cmd_info cvs_checkout = {
48: cvs_checkout_options,
49: cvs_checkout_sendflags,
50: NULL, NULL, NULL,
51: 0,
52: CVS_REQ_CO,
53: CVS_CMD_SENDDIR | CVS_CMD_SENDARGS1 | CVS_CMD_SENDARGS2
54: };
55:
56: static char *date, *rev, *koptstr, *tgtdir, *rcsid;
57: static int statmod = 0;
58: static int kflag = RCS_KWEXP_DEFAULT;
1.1 jfb 59:
60: int
1.14 joris 61: cvs_checkout_options(char *opt, int argc, char **argv, int *arg)
1.1 jfb 62: {
1.14 joris 63: int ch;
64:
65: date = rev = koptstr = tgtdir = rcsid = NULL;
1.13 jfb 66: kflag = RCS_KWEXP_DEFAULT;
67:
1.14 joris 68: while ((ch = getopt(argc, argv, opt)) != -1) {
1.1 jfb 69: switch (ch) {
1.13 jfb 70: case 'A':
71: break;
1.10 jfb 72: case 'c':
1.13 jfb 73: statmod = CVS_LISTMOD;
74: break;
75: case 'D':
76: date = optarg;
77: break;
78: case 'd':
79: tgtdir = optarg;
80: break;
81: case 'f':
82: break;
83: case 'j':
84: break;
85: case 'k':
86: koptstr = optarg;
87: kflag = rcs_kflag_get(koptstr);
88: if (RCS_KWEXP_INVAL(kflag)) {
89: cvs_log(LP_ERR,
90: "invalid RCS keyword expansion mode");
91: rcs_kflag_usage();
1.18 ! joris 92: return (CVS_EX_USAGE);
1.13 jfb 93: }
94: break;
95: case 'r':
96: rev = optarg;
97: break;
98: case 's':
99: statmod = CVS_STATMOD;
100: break;
101: case 't':
102: rcsid = optarg;
1.10 jfb 103: break;
1.1 jfb 104: default:
1.18 ! joris 105: return (CVS_EX_USAGE);
1.1 jfb 106: }
107: }
108:
109: argc -= optind;
110: argv += optind;
111:
1.13 jfb 112: if (!statmod && (argc == 0)) {
1.1 jfb 113: cvs_log(LP_ERR,
114: "must specify at least one module or directory");
1.18 ! joris 115: return (CVS_EX_USAGE);
1.1 jfb 116: }
117:
1.13 jfb 118: if (statmod && (argc > 0)) {
119: cvs_log(LP_ERR, "-c and -s must not get any arguments");
1.18 ! joris 120: return (CVS_EX_USAGE);
1.13 jfb 121: }
122:
1.14 joris 123: *arg = optind;
124: return (0);
125: }
1.9 jfb 126:
1.14 joris 127: int
128: cvs_checkout_sendflags(struct cvsroot *root)
129: {
130: if (cvs_senddir(root, cvs_files) < 0)
1.18 ! joris 131: return (CVS_EX_PROTO);
1.14 joris 132: if (cvs_sendreq(root, CVS_REQ_XPANDMOD, NULL) < 0)
133: cvs_log(LP_ERR, "failed to expand module");
134:
135: /* XXX not too sure why we have to send this arg */
136: if (cvs_sendarg(root, "-N", 0) < 0)
1.18 ! joris 137: return (CVS_EX_PROTO);
1.14 joris 138:
139: if ((statmod == CVS_LISTMOD) &&
140: (cvs_sendarg(root, "-c", 0) < 0))
1.18 ! joris 141: return (CVS_EX_PROTO);
1.14 joris 142:
143: if ((statmod == CVS_STATMOD) &&
144: (cvs_sendarg(root, "-s", 0) < 0))
1.18 ! joris 145: return (CVS_EX_PROTO);
1.1 jfb 146:
147: return (0);
148: }