[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.4

1.4     ! joris       1: /*     $OpenBSD: cmd.c,v 1.3 2005/03/29 03:10:27 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:
1.3       joris      54:        if (c->cmd_options != NULL) {
1.4     ! joris      55:                if ((ret = c->cmd_options(cmd->cmd_opts, argc, argv, &i)))
1.3       joris      56:                        return (ret);
                     57:
                     58:                argc -= i;
                     59:                argv += i;
                     60:        }
1.1       joris      61:
                     62:        if ((c->cmd_flags & CVS_CMD_ALLOWSPEC) && argc != 0)
                     63:                cvs_files = cvs_file_getspec(argv, argc, 0);
                     64:        else
                     65:                cvs_files = cvs_file_get(".", c->file_flags);
                     66:
                     67:        if (cvs_files == NULL)
                     68:                return (EX_DATAERR);
                     69:
1.4     ! joris      70:        if ((c->cmd_helper != NULL) && ((ret = c->cmd_helper())))
1.1       joris      71:                return (ret);
                     72:
                     73:        root = CVS_DIR_ROOT(cvs_files);
                     74:        if (root == NULL && (root = cvsroot_get(".")) == NULL) {
                     75:                cvs_log(LP_ERR,
                     76:                    "No CVSROOT specified! Please use the `-d' option");
                     77:                cvs_log(LP_ERR,
                     78:                    "or set the CVSROOT enviroment variable.");
                     79:                return (EX_USAGE);
                     80:        }
                     81:
                     82:        if (root->cr_method != CVS_METHOD_LOCAL) {
                     83:                if (cvs_connect(root) < 0)
                     84:                        return (EX_PROTOCOL);
                     85:
                     86:                if (c->cmd_flags & CVS_CMD_SENDARGS1) {
                     87:                        for (i = 0; i < argc; i++) {
                     88:                                if (cvs_sendarg(root, argv[i], 0) < 0)
                     89:                                        return (EX_PROTOCOL);
                     90:                        }
                     91:                }
                     92:
1.4     ! joris      93:                if (c->cmd_sendflags != NULL) {
        !            94:                        if ((ret = c->cmd_sendflags(root)))
        !            95:                                return (ret);
        !            96:                }
1.1       joris      97:
                     98:                if (c->cmd_flags & CVS_CMD_NEEDLOG) {
                     99:                        if (cvs_logmsg_send(root, cvs_msg) < 0)
                    100:                                return (EX_PROTOCOL);
                    101:                }
                    102:        }
                    103:
                    104:        if (c->cmd_examine != NULL)
                    105:                cvs_file_examine(cvs_files, c->cmd_examine, NULL);
                    106:
                    107:        if (root->cr_method != CVS_METHOD_LOCAL) {
                    108:                if (c->cmd_flags & CVS_CMD_SENDDIR) {
                    109:                        if (cvs_senddir(root, cvs_files) < 0)
                    110:                                return (EX_PROTOCOL);
                    111:                }
                    112:
                    113:                if (c->cmd_flags & CVS_CMD_SENDARGS2) {
                    114:                        for (i = 0; i < argc; i++) {
                    115:                                if (cvs_sendarg(root, argv[i], 0) < 0)
                    116:                                        return (EX_PROTOCOL);
                    117:                        }
                    118:                }
                    119:
                    120:                if (cvs_sendreq(root, c->cmd_req,
                    121:                    (cmd->cmd_op == CVS_OP_INIT) ? root->cr_dir : NULL) < 0)
                    122:                        return (EX_PROTOCOL);
                    123:        }
                    124:
                    125:        return (0);
                    126: }