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

Annotation of src/usr.bin/rdist/distopt.c, Revision 1.8

1.8     ! millert     1: /*     $OpenBSD: distopt.c,v 1.7 2003/04/05 20:31:58 deraadt Exp $     */
1.3       deraadt     2:
1.1       dm          3: /*
                      4:  * Copyright (c) 1983 Regents of the University of California.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *     This product includes software developed by the University of
                     18:  *     California, Berkeley and its contributors.
                     19:  * 4. Neither the name of the University nor the names of its contributors
                     20:  *    may be used to endorse or promote products derived from this software
                     21:  *    without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     33:  * SUCH DAMAGE.
                     34:  */
                     35:
1.8     ! millert    36: #include "defs.h"
1.1       dm         37: #ifndef lint
1.4       millert    38: #if 0
1.8     ! millert    39: static char RCSid[] __attribute__((__unused__)) =
        !            40: "$From: distopt.c,v 1.5 1999/08/04 15:57:33 christos Exp $";
1.4       millert    41: #else
1.8     ! millert    42: static char RCSid[] __attribute__((__unused__)) =
        !            43: "$OpenBSD: distopt.c,v 1.7 2003/04/05 20:31:58 deraadt Exp $";
1.4       millert    44: #endif
1.1       dm         45:
1.8     ! millert    46: static char sccsid[] __attribute__((__unused__)) =
        !            47: "@(#)distopt.c";
1.1       dm         48:
1.8     ! millert    49: static char copyright[] __attribute__((__unused__)) =
1.1       dm         50: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
                     51:  All rights reserved.\n";
                     52: #endif /* !lint */
                     53:
                     54: /*
                     55:  * Dist Option functions
                     56:  */
                     57:
                     58:
                     59: /*
                     60:  * Distfile Option Information
                     61:  */
                     62: DISTOPTINFO distoptinfo[] = {
1.8     ! millert    63:        { DO_CHKNFS,            "chknfs",       NULL,           0},
        !            64:        { DO_CHKREADONLY,       "chkreadonly",  NULL,           0},
        !            65:        { DO_CHKSYM,            "chksym",       NULL,           0},
        !            66:        { DO_DEFGROUP,          "defgroup",     defgroup,       sizeof(defgroup) },
        !            67:        { DO_DEFOWNER,          "defowner",     defowner,       sizeof(defowner) },
        !            68:        { DO_COMPARE,           "compare",      NULL,           0},
        !            69:        { DO_FOLLOW,            "follow",       NULL,           0},
        !            70:        { DO_HISTORY,           "history",      NULL,           0},
        !            71:        { DO_IGNLNKS,           "ignlnks",      NULL,           0},
        !            72:        { DO_NOCHKGROUP,        "nochkgroup",   NULL,           0},
        !            73:        { DO_NOCHKMODE,         "nochkmode",    NULL,           0},
        !            74:        { DO_NOCHKOWNER,        "nochkowner",   NULL,           0},
        !            75:        { DO_NODESCEND,         "nodescend",    NULL,           0},
        !            76:        { DO_NOEXEC,            "noexec",       NULL,           0},
        !            77:        { DO_NUMCHKGROUP,       "numchkgroup",  NULL,           0},
        !            78:        { DO_NUMCHKOWNER,       "numchkowner",  NULL,           0},
        !            79:        { DO_QUIET,             "quiet",        NULL,           0},
        !            80:        { DO_REMOVE,            "remove",       NULL,           0},
        !            81:        { DO_SAVETARGETS,       "savetargets",  NULL,           0},
        !            82:        { DO_SPARSE,            "sparse",       NULL,           0},
        !            83:        { DO_UPDATEPERM,        "updateperm",   NULL,           0},
        !            84:        { DO_VERIFY,            "verify",       NULL,           0},
        !            85:        { DO_WHOLE,             "whole",        NULL,           0},
        !            86:        { DO_YOUNGER,           "younger",      NULL,           0},
1.1       dm         87:        { 0 },
                     88: };
                     89:
                     90: /*
                     91:  * Get a Distfile Option entry named "name".
                     92:  */
1.8     ! millert    93: DISTOPTINFO *
        !            94: getdistopt(char *name, int *len)
1.1       dm         95: {
1.6       mpech      96:        int i;
1.1       dm         97:
                     98:        for (i = 0; distoptinfo[i].do_name; ++i)
1.8     ! millert    99:                if (strncasecmp(name, distoptinfo[i].do_name,
        !           100:                                *len = strlen(distoptinfo[i].do_name)) == 0)
1.1       dm        101:                        return(&distoptinfo[i]);
                    102:
1.4       millert   103:        return(NULL);
1.1       dm        104: }
                    105:
                    106: /*
                    107:  * Parse a dist option string.  Set option flags to optptr.
                    108:  * If doerrs is true, print out own error message.  Returns
                    109:  * 0 on success.
                    110:  */
1.8     ! millert   111: int
        !           112: parsedistopts(char *str, opt_t *optptr, int doerrs)
1.1       dm        113: {
1.6       mpech     114:        char *string, *optstr;
1.1       dm        115:        DISTOPTINFO *distopt;
1.8     ! millert   116:        int len;
1.1       dm        117:
1.8     ! millert   118:        /* strtok() is destructive */
1.5       millert   119:        string = xstrdup(str);
1.1       dm        120:
                    121:        for (optstr = strtok(string, ","); optstr;
1.4       millert   122:             optstr = strtok(NULL, ",")) {
1.8     ! millert   123:                /* Try Yes */
        !           124:                if ((distopt = getdistopt(optstr, &len)) != NULL) {
1.1       dm        125:                        FLAG_ON(*optptr, distopt->do_value);
1.8     ! millert   126:                        if (distopt->do_arg && optstr[len] == '=')
        !           127:                                (void) strlcpy(distopt->do_arg,
        !           128:                                    &optstr[len + 1], distopt->arg_size);
1.1       dm        129:                        continue;
                    130:                }
1.8     ! millert   131:
        !           132:                /* Try No */
        !           133:                if ((distopt = getdistopt(optstr+2, &len)) != NULL) {
1.1       dm        134:                        FLAG_OFF(*optptr, distopt->do_value);
                    135:                        continue;
                    136:                }
1.8     ! millert   137:
1.1       dm        138:                if (doerrs)
                    139:                        error("Dist option \"%s\" is not valid.", optstr);
                    140:        }
                    141:
                    142:        if (string)
                    143:                (void) free(string);
                    144:
                    145:        return(nerrs);
                    146: }
                    147:
                    148: /*
                    149:  * Get a list of the Distfile Option Entries.
                    150:  */
1.8     ! millert   151: char *
        !           152: getdistoptlist(void)
1.1       dm        153: {
1.6       mpech     154:        int i;
1.1       dm        155:        static char buf[1024];
                    156:
                    157:        for (i = 0, buf[0] = CNULL; distoptinfo[i].do_name; ++i) {
                    158:                if (buf[0] == CNULL)
1.8     ! millert   159:                        (void) strlcpy(buf, distoptinfo[i].do_name, sizeof buf);
1.1       dm        160:                else {
1.7       deraadt   161:                        (void) strlcat(buf, ",", sizeof buf);
1.8     ! millert   162:                        (void) strlcat(buf, distoptinfo[i].do_name, sizeof buf);
1.1       dm        163:                }
                    164:        }
                    165:
                    166:        return(buf);
                    167: }
                    168:
                    169: /*
                    170:  * Get a list of the Distfile Option Entries for each enabled
                    171:  * value in "opts".
                    172:  */
1.8     ! millert   173: char *
        !           174: getondistoptlist(opt_t opts)
1.1       dm        175: {
1.6       mpech     176:        int i;
1.1       dm        177:        static char buf[1024];
                    178:
                    179:        for (i = 0, buf[0] = CNULL; distoptinfo[i].do_name; ++i) {
                    180:                if (!IS_ON(opts, distoptinfo[i].do_value))
                    181:                        continue;
                    182:
                    183:                if (buf[0] == CNULL)
1.8     ! millert   184:                        (void) strlcpy(buf, distoptinfo[i].do_name, sizeof buf);
1.1       dm        185:                else {
1.7       deraadt   186:                        (void) strlcat(buf, ",", sizeof buf);
1.8     ! millert   187:                        (void) strlcat(buf, distoptinfo[i].do_name, sizeof buf);
        !           188:                }
        !           189:                if (distoptinfo[i].do_arg) {
        !           190:                        (void) strlcat(buf, "=", sizeof buf);
        !           191:                        (void) strlcat(buf, distoptinfo[i].do_arg, sizeof buf);
1.1       dm        192:                }
                    193:        }
                    194:
                    195:        return(buf);
                    196: }
                    197: