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

1.17    ! joris       1: /*     $OpenBSD: add.c,v 1.16 2005/04/03 17:32:50 xsa 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>
                     33: #include <sysexits.h>
1.10      xsa        34: #include <unistd.h>
1.1       jfb        35:
                     36: #include "cvs.h"
                     37: #include "log.h"
1.2       jfb        38: #include "proto.h"
1.1       jfb        39:
                     40:
1.3       jfb        41: extern char *__progname;
                     42:
                     43:
1.15      joris      44: int cvs_add_file(CVSFILE *, void *);
                     45: int cvs_add_options(char *, int, char **, int *);
                     46: int cvs_add_sendflags(struct cvsroot *);
                     47:
                     48: struct cvs_cmd_info cvs_add = {
                     49:        cvs_add_options,
                     50:        cvs_add_sendflags,
                     51:        cvs_add_file,
                     52:        NULL, NULL,
                     53:        0,
                     54:        CVS_REQ_ADD,
                     55:        CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2
                     56: };
1.3       jfb        57:
1.15      joris      58: static int kflag = RCS_KWEXP_DEFAULT;
                     59: static char *koptstr;
1.3       jfb        60:
1.1       jfb        61: int
1.15      joris      62: cvs_add_options(char *opt, int argc, char **argv, int *arg)
1.1       jfb        63: {
1.15      joris      64:        int ch;
1.1       jfb        65:
1.13      jfb        66:        cvs_msg = NULL;
1.1       jfb        67:
1.15      joris      68:        while ((ch = getopt(argc, argv, opt)) != -1) {
1.1       jfb        69:                switch (ch) {
                     70:                case 'k':
1.13      jfb        71:                        koptstr = optarg;
                     72:                        kflag = rcs_kflag_get(koptstr);
                     73:                        if (RCS_KWEXP_INVAL(kflag)) {
                     74:                                cvs_log(LP_ERR,
                     75:                                    "invalid RCS keyword expansion mode");
                     76:                                rcs_kflag_usage();
1.17    ! joris      77:                                return (1);
1.13      jfb        78:                        }
1.1       jfb        79:                        break;
                     80:                case 'm':
1.13      jfb        81:                        if ((cvs_msg = strdup(optarg)) == NULL) {
                     82:                                cvs_log(LP_ERRNO, "failed to copy message");
1.16      xsa        83:                                return (-1);
1.13      jfb        84:                        }
1.1       jfb        85:                        break;
                     86:                default:
1.17    ! joris      87:                        return (1);
1.1       jfb        88:                }
                     89:        }
                     90:
1.15      joris      91:        *arg = optind;
                     92:        return (0);
                     93: }
1.10      xsa        94:
1.15      joris      95: int
                     96: cvs_add_sendflags(struct cvsroot *root)
                     97: {
                     98:        char buf[16];
1.3       jfb        99:
1.15      joris     100:        if (kflag != RCS_KWEXP_DEFAULT) {
                    101:                strlcpy(buf, "-k", sizeof(buf));
                    102:                strlcat(buf, koptstr, sizeof(buf));
                    103:                if (cvs_sendarg(root, buf, 0) < 0)
1.16      xsa       104:                        return (-1);
1.10      xsa       105:        }
1.3       jfb       106:
                    107:        return (0);
                    108: }
                    109:
                    110: int
                    111: cvs_add_file(CVSFILE *cf, void *arg)
                    112: {
1.10      xsa       113:        int ret;
1.3       jfb       114:        struct cvsroot *root;
                    115:
1.10      xsa       116:        ret = 0;
                    117:        root = CVS_DIR_ROOT(cf);
                    118:
1.3       jfb       119:        if (cf->cf_type == DT_DIR) {
1.12      jfb       120:                if (root->cr_method != CVS_METHOD_LOCAL)
                    121:                        ret = cvs_senddir(root, cf);
1.3       jfb       122:
1.10      xsa       123:                return (ret);
1.1       jfb       124:        }
                    125:
1.5       krapht    126:        if (root->cr_method != CVS_METHOD_LOCAL) {
1.12      jfb       127:                if (cf->cf_cvstat == CVS_FST_UNKNOWN)
                    128:                        ret = cvs_sendreq(root, CVS_REQ_ISMODIFIED,
                    129:                            CVS_FILE_NAME(cf));
1.7       deraadt   130:        } else {
1.3       jfb       131:                cvs_log(LP_INFO, "scheduling file `%s' for addition",
1.10      xsa       132:                    CVS_FILE_NAME(cf));
1.3       jfb       133:                cvs_log(LP_INFO, "use `%s commit' to add this file permanently",
                    134:                    __progname);
1.1       jfb       135:        }
                    136:
1.10      xsa       137:        return (ret);
1.1       jfb       138: }