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

Annotation of src/usr.bin/cvs/add.c, Revision 1.19

1.19    ! joris       1: /*     $OpenBSD: add.c,v 1.18 2005/04/11 18:02:58 joris Exp $  */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.8       tedu        4:  * All rights reserved.
1.1       jfb         5:  *
1.8       tedu        6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
1.1       jfb         9:  *
1.8       tedu       10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
1.1       jfb        12:  * 2. The name of the author may not be used to endorse or promote products
1.8       tedu       13:  *    derived from this software without specific prior written permission.
1.1       jfb        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
1.8       tedu       24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1       jfb        25:  */
                     26:
                     27: #include <sys/types.h>
                     28:
                     29: #include <errno.h>
                     30: #include <stdio.h>
                     31: #include <stdlib.h>
                     32: #include <string.h>
1.10      xsa        33: #include <unistd.h>
1.1       jfb        34:
                     35: #include "cvs.h"
                     36: #include "log.h"
1.2       jfb        37: #include "proto.h"
1.1       jfb        38:
                     39:
1.3       jfb        40: extern char *__progname;
                     41:
                     42:
1.15      joris      43: int cvs_add_file(CVSFILE *, void *);
                     44: int cvs_add_options(char *, int, char **, int *);
                     45: int cvs_add_sendflags(struct cvsroot *);
                     46:
                     47: struct cvs_cmd_info cvs_add = {
                     48:        cvs_add_options,
                     49:        cvs_add_sendflags,
                     50:        cvs_add_file,
                     51:        NULL, NULL,
                     52:        0,
                     53:        CVS_REQ_ADD,
                     54:        CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
                     55: };
1.3       jfb        56:
1.15      joris      57: static int kflag = RCS_KWEXP_DEFAULT;
                     58: static char *koptstr;
1.3       jfb        59:
1.1       jfb        60: int
1.15      joris      61: cvs_add_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        62: {
1.15      joris      63:        int ch;
1.1       jfb        64:
1.13      jfb        65:        cvs_msg = NULL;
1.1       jfb        66:
1.15      joris      67:        while ((ch = getopt(argc, argv, opt)) != -1) {
1.1       jfb        68:                switch (ch) {
                     69:                case 'k':
1.13      jfb        70:                        koptstr = optarg;
                     71:                        kflag = rcs_kflag_get(koptstr);
                     72:                        if (RCS_KWEXP_INVAL(kflag)) {
                     73:                                cvs_log(LP_ERR,
                     74:                                    "invalid RCS keyword expansion mode");
                     75:                                rcs_kflag_usage();
1.19    ! joris      76:                                return (CVS_EX_USAGE);
1.13      jfb        77:                        }
1.1       jfb        78:                        break;
                     79:                case 'm':
1.13      jfb        80:                        if ((cvs_msg = strdup(optarg)) == NULL) {
                     81:                                cvs_log(LP_ERRNO, "failed to copy message");
1.19    ! joris      82:                                return (CVS_EX_DATA);
1.13      jfb        83:                        }
1.1       jfb        84:                        break;
                     85:                default:
1.19    ! joris      86:                        return (CVS_EX_USAGE);
1.1       jfb        87:                }
                     88:        }
                     89:
1.15      joris      90:        *arg = optind;
                     91:        return (0);
                     92: }
1.10      xsa        93:
1.15      joris      94: int
                     95: cvs_add_sendflags(struct cvsroot *root)
                     96: {
                     97:        char buf[16];
1.3       jfb        98:
1.15      joris      99:        if (kflag != RCS_KWEXP_DEFAULT) {
                    100:                strlcpy(buf, "-k", sizeof(buf));
                    101:                strlcat(buf, koptstr, sizeof(buf));
                    102:                if (cvs_sendarg(root, buf, 0) < 0)
1.19    ! joris     103:                        return (CVS_EX_PROTO);
1.10      xsa       104:        }
1.3       jfb       105:
                    106:        return (0);
                    107: }
                    108:
                    109: int
                    110: cvs_add_file(CVSFILE *cf, void *arg)
                    111: {
1.10      xsa       112:        int ret;
1.3       jfb       113:        struct cvsroot *root;
                    114:
1.10      xsa       115:        ret = 0;
                    116:        root = CVS_DIR_ROOT(cf);
                    117:
1.3       jfb       118:        if (cf->cf_type == DT_DIR) {
1.12      jfb       119:                if (root->cr_method != CVS_METHOD_LOCAL)
                    120:                        ret = cvs_senddir(root, cf);
1.3       jfb       121:
1.10      xsa       122:                return (ret);
1.1       jfb       123:        }
                    124:
1.5       krapht    125:        if (root->cr_method != CVS_METHOD_LOCAL) {
1.12      jfb       126:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    127:                        ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
                    128:                            CVS_FILE_NAME(cf));
1.7       deraadt   129:        } else {
1.3       jfb       130:                cvs_log(LP_INFO, "scheduling file `%s' for addition",
1.10      xsa       131:                    CVS_FILE_NAME(cf));
1.3       jfb       132:                cvs_log(LP_INFO, "use `%s commit' to add this file permanently",
                    133:                    __progname);
1.1       jfb       134:        }
                    135:
1.10      xsa       136:        return (ret);
1.1       jfb       137: }