Annotation of src/usr.bin/cvs/cmd.c, Revision 1.2
1.2 ! joris 1: /* $OpenBSD: cmd.c,v 1.1 2005/03/24 01:03:41 joris Exp $ */
1.1 joris 2: /*
3: * Copyright (c) 2005 Joris Vink <joris@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:
27: #include <sys/param.h>
28: #include <sys/queue.h>
29: #include <sys/time.h>
30:
31: #include <stdlib.h>
32: #include <stdio.h>
33: #include <unistd.h>
34: #include <errno.h>
35: #include <string.h>
36: #include <sysexits.h>
37:
38: #include "cvs.h"
39: #include "log.h"
40: #include "rcs.h"
41: #include "proto.h"
42:
43: /*
44: * start the execution of a command.
45: */
46: int
47: cvs_startcmd(struct cvs_cmd *cmd, int argc, char **argv)
48: {
49: int i;
50: int ret;
51: struct cvsroot *root;
52: struct cvs_cmd_info *c = cmd->cmd_info;
53:
54: if ((ret = c->cmd_options(cmd->cmd_opts, argc, argv, &i)) < 0)
55: return (ret);
56:
1.2 ! joris 57: argc -= i;
1.1 joris 58: argv += i;
59:
60: if ((c->cmd_flags & CVS_CMD_ALLOWSPEC) && argc != 0)
61: cvs_files = cvs_file_getspec(argv, argc, 0);
62: else
63: cvs_files = cvs_file_get(".", c->file_flags);
64:
65: if (cvs_files == NULL)
66: return (EX_DATAERR);
67:
68: if ((c->cmd_helper != NULL) && ((ret = c->cmd_helper()) < 0))
69: return (ret);
70:
71: root = CVS_DIR_ROOT(cvs_files);
72: if (root == NULL && (root = cvsroot_get(".")) == NULL) {
73: cvs_log(LP_ERR,
74: "No CVSROOT specified! Please use the `-d' option");
75: cvs_log(LP_ERR,
76: "or set the CVSROOT enviroment variable.");
77: return (EX_USAGE);
78: }
79:
80: if (root->cr_method != CVS_METHOD_LOCAL) {
81: if (cvs_connect(root) < 0)
82: return (EX_PROTOCOL);
83:
84: if (c->cmd_flags & CVS_CMD_SENDARGS1) {
85: for (i = 0; i < argc; i++) {
86: if (cvs_sendarg(root, argv[i], 0) < 0)
87: return (EX_PROTOCOL);
88: }
89: }
90:
91: if (c->cmd_sendflags != NULL)
92: c->cmd_sendflags(root);
93:
94: if (c->cmd_flags & CVS_CMD_NEEDLOG) {
95: if (cvs_logmsg_send(root, cvs_msg) < 0)
96: return (EX_PROTOCOL);
97: }
98: }
99:
100: if (c->cmd_examine != NULL)
101: cvs_file_examine(cvs_files, c->cmd_examine, NULL);
102:
103: if (root->cr_method != CVS_METHOD_LOCAL) {
104: if (c->cmd_flags & CVS_CMD_SENDDIR) {
105: if (cvs_senddir(root, cvs_files) < 0)
106: return (EX_PROTOCOL);
107: }
108:
109: if (c->cmd_flags & CVS_CMD_SENDARGS2) {
110: for (i = 0; i < argc; i++) {
111: if (cvs_sendarg(root, argv[i], 0) < 0)
112: return (EX_PROTOCOL);
113: }
114: }
115:
116: if (cvs_sendreq(root, c->cmd_req,
117: (cmd->cmd_op == CVS_OP_INIT) ? root->cr_dir : NULL) < 0)
118: return (EX_PROTOCOL);
119: }
120:
121: return (0);
122: }