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

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