[BACK]Return to cmd.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/cmd.c, Revision 1.15

1.15    ! jfb         1: /*     $OpenBSD: cmd.c,v 1.14 2005/04/18 21:06:46 jfb 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.11      joris      75:                return (CVS_EX_DATA);
1.1       joris      76:
1.12      joris      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);
1.15    ! jfb        81:        if (root == NULL && (root = cvsroot_get(".")) == NULL)
        !            82:                return (CVS_EX_BADROOT);
1.1       joris      83:
                     84:        if (root->cr_method != CVS_METHOD_LOCAL) {
                     85:                if (cvs_connect(root) < 0)
1.11      joris      86:                        return (CVS_EX_PROTO);
1.1       joris      87:
                     88:                if (c->cmd_flags & CVS_CMD_SENDARGS1) {
                     89:                        for (i = 0; i < argc; i++) {
                     90:                                if (cvs_sendarg(root, argv[i], 0) < 0)
1.11      joris      91:                                        return (CVS_EX_PROTO);
1.1       joris      92:                        }
                     93:                }
                     94:
1.4       joris      95:                if (c->cmd_sendflags != NULL) {
1.10      joris      96:                        if ((ret = c->cmd_sendflags(root)) != 0)
1.4       joris      97:                                return (ret);
                     98:                }
1.1       joris      99:
                    100:                if (c->cmd_flags & CVS_CMD_NEEDLOG) {
                    101:                        if (cvs_logmsg_send(root, cvs_msg) < 0)
1.11      joris     102:                                return (CVS_EX_PROTO);
1.1       joris     103:                }
                    104:        }
1.6       joris     105:
                    106:        /* if we are the version command, don't bother going
                    107:         * any further now, we did everything we had to.
                    108:         */
                    109:        if (cmd->cmd_op == CVS_OP_VERSION)
                    110:                return (0);
1.1       joris     111:
                    112:        if (c->cmd_examine != NULL)
                    113:                cvs_file_examine(cvs_files, c->cmd_examine, NULL);
                    114:
                    115:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    116:                if (c->cmd_flags & CVS_CMD_SENDDIR) {
                    117:                        if (cvs_senddir(root, cvs_files) < 0)
1.11      joris     118:                                return (CVS_EX_PROTO);
1.1       joris     119:                }
                    120:
                    121:                if (c->cmd_flags & CVS_CMD_SENDARGS2) {
                    122:                        for (i = 0; i < argc; i++) {
                    123:                                if (cvs_sendarg(root, argv[i], 0) < 0)
1.11      joris     124:                                        return (CVS_EX_PROTO);
1.1       joris     125:                        }
                    126:                }
                    127:
                    128:                if (cvs_sendreq(root, c->cmd_req,
                    129:                    (cmd->cmd_op == CVS_OP_INIT) ? root->cr_dir : NULL) < 0)
1.11      joris     130:                        return (CVS_EX_PROTO);
1.1       joris     131:        }
                    132:
                    133:        return (0);
                    134: }