Annotation of src/usr.bin/cvs/cmd.c, Revision 1.10
1.10 ! joris 1: /* $OpenBSD: cmd.c,v 1.9 2005/04/11 18:02:58 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:
37: #include "cvs.h"
38: #include "log.h"
39: #include "rcs.h"
40: #include "proto.h"
41:
42: /*
43: * start the execution of a command.
44: */
45: int
46: cvs_startcmd(struct cvs_cmd *cmd, int argc, char **argv)
47: {
48: int i;
49: int ret;
50: struct cvsroot *root;
51: struct cvs_cmd_info *c = cmd->cmd_info;
1.5 joris 52:
53: /* if the command requested is the server one, just call the
54: * cvs_server() function to handle it, and return after it.
55: */
56: if (cmd->cmd_op == CVS_OP_SERVER) {
57: ret = cvs_server(argc, argv);
58: return (ret);
59: }
1.1 joris 60:
1.3 joris 61: if (c->cmd_options != NULL) {
1.8 joris 62: if ((ret = c->cmd_options(cmd->cmd_opts, argc, argv, &i)) != 0)
1.3 joris 63: return (ret);
64:
65: argc -= i;
66: argv += i;
67: }
1.1 joris 68:
69: if ((c->cmd_flags & CVS_CMD_ALLOWSPEC) && argc != 0)
70: cvs_files = cvs_file_getspec(argv, argc, 0);
71: else
72: cvs_files = cvs_file_get(".", c->file_flags);
73:
74: if (cvs_files == NULL)
1.7 xsa 75: return (-1);
1.1 joris 76:
1.7 xsa 77: if ((c->cmd_helper != NULL) && ((ret = c->cmd_helper()) < 0))
1.1 joris 78: return (ret);
79:
80: root = CVS_DIR_ROOT(cvs_files);
81: if (root == NULL && (root = cvsroot_get(".")) == NULL) {
82: cvs_log(LP_ERR,
83: "No CVSROOT specified! Please use the `-d' option");
84: cvs_log(LP_ERR,
85: "or set the CVSROOT enviroment variable.");
1.8 joris 86: return (1);
1.1 joris 87: }
88:
89: if (root->cr_method != CVS_METHOD_LOCAL) {
90: if (cvs_connect(root) < 0)
1.7 xsa 91: return (-1);
1.1 joris 92:
93: if (c->cmd_flags & CVS_CMD_SENDARGS1) {
94: for (i = 0; i < argc; i++) {
95: if (cvs_sendarg(root, argv[i], 0) < 0)
1.7 xsa 96: return (-1);
1.1 joris 97: }
98: }
99:
1.4 joris 100: if (c->cmd_sendflags != NULL) {
1.10 ! joris 101: if ((ret = c->cmd_sendflags(root)) != 0)
1.4 joris 102: return (ret);
103: }
1.1 joris 104:
105: if (c->cmd_flags & CVS_CMD_NEEDLOG) {
106: if (cvs_logmsg_send(root, cvs_msg) < 0)
1.7 xsa 107: return (-1);
1.1 joris 108: }
109: }
1.6 joris 110:
111: /* if we are the version command, don't bother going
112: * any further now, we did everything we had to.
113: */
114: if (cmd->cmd_op == CVS_OP_VERSION)
115: return (0);
1.1 joris 116:
117: if (c->cmd_examine != NULL)
118: cvs_file_examine(cvs_files, c->cmd_examine, NULL);
119:
120: if (root->cr_method != CVS_METHOD_LOCAL) {
121: if (c->cmd_flags & CVS_CMD_SENDDIR) {
122: if (cvs_senddir(root, cvs_files) < 0)
1.7 xsa 123: return (-1);
1.1 joris 124: }
125:
126: if (c->cmd_flags & CVS_CMD_SENDARGS2) {
127: for (i = 0; i < argc; i++) {
128: if (cvs_sendarg(root, argv[i], 0) < 0)
1.7 xsa 129: return (-1);
1.1 joris 130: }
131: }
132:
133: if (cvs_sendreq(root, c->cmd_req,
134: (cmd->cmd_op == CVS_OP_INIT) ? root->cr_dir : NULL) < 0)
1.7 xsa 135: return (-1);
1.1 joris 136: }
137:
138: return (0);
139: }