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