Annotation of src/usr.bin/rdist/distopt.c, Revision 1.1
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[] =
! 36: "$Id: distopt.c,v 6.9 1994/04/26 16:59:41 mcooper Exp $";
! 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" },
! 71: { DO_VERIFY, "verify" },
! 72: { DO_WHOLE, "whole" },
! 73: { DO_YOUNGER, "younger" },
! 74: { 0 },
! 75: };
! 76:
! 77: /*
! 78: * Get a Distfile Option entry named "name".
! 79: */
! 80: extern DISTOPTINFO *getdistopt(name)
! 81: char *name;
! 82: {
! 83: register int i;
! 84:
! 85: for (i = 0; distoptinfo[i].do_name; ++i)
! 86: if (strcasecmp(name, distoptinfo[i].do_name) == 0)
! 87: return(&distoptinfo[i]);
! 88:
! 89: return((DISTOPTINFO *) NULL);
! 90: }
! 91:
! 92: /*
! 93: * Parse a dist option string. Set option flags to optptr.
! 94: * If doerrs is true, print out own error message. Returns
! 95: * 0 on success.
! 96: */
! 97: extern int parsedistopts(str, optptr, doerrs)
! 98: char *str;
! 99: opt_t *optptr;
! 100: int doerrs;
! 101: {
! 102: register char *string, *optstr;
! 103: DISTOPTINFO *distopt;
! 104: int negate;
! 105:
! 106: /* strtok() is harmful */
! 107: string = strdup(str);
! 108:
! 109: for (optstr = strtok(string, ","); optstr;
! 110: optstr = strtok((char *) NULL, ",")) {
! 111: if (strncasecmp(optstr, "no", 2) == 0)
! 112: negate = TRUE;
! 113: else
! 114: negate = FALSE;
! 115:
! 116: /*
! 117: * Try looking up option name. If that fails
! 118: * and the option starts with "no", strip "no"
! 119: * from option and retry lookup.
! 120: */
! 121: if (distopt = getdistopt(optstr)) {
! 122: FLAG_ON(*optptr, distopt->do_value);
! 123: continue;
! 124: }
! 125: if (negate && (distopt = getdistopt(optstr+2))) {
! 126: FLAG_OFF(*optptr, distopt->do_value);
! 127: continue;
! 128: }
! 129: if (doerrs)
! 130: error("Dist option \"%s\" is not valid.", optstr);
! 131: }
! 132:
! 133: if (string)
! 134: (void) free(string);
! 135:
! 136: return(nerrs);
! 137: }
! 138:
! 139: /*
! 140: * Get a list of the Distfile Option Entries.
! 141: */
! 142: extern char *getdistoptlist()
! 143: {
! 144: register int i;
! 145: static char buf[1024];
! 146:
! 147: for (i = 0, buf[0] = CNULL; distoptinfo[i].do_name; ++i) {
! 148: if (buf[0] == CNULL)
! 149: (void) strcpy(buf, distoptinfo[i].do_name);
! 150: else {
! 151: (void) strcat(buf, ",");
! 152: (void) strcat(buf, distoptinfo[i].do_name);
! 153: }
! 154: }
! 155:
! 156: return(buf);
! 157: }
! 158:
! 159: /*
! 160: * Get a list of the Distfile Option Entries for each enabled
! 161: * value in "opts".
! 162: */
! 163: extern char *getondistoptlist(opts)
! 164: opt_t opts;
! 165: {
! 166: register int i;
! 167: static char buf[1024];
! 168:
! 169: for (i = 0, buf[0] = CNULL; distoptinfo[i].do_name; ++i) {
! 170: if (!IS_ON(opts, distoptinfo[i].do_value))
! 171: continue;
! 172:
! 173: if (buf[0] == CNULL)
! 174: (void) strcpy(buf, distoptinfo[i].do_name);
! 175: else {
! 176: (void) strcat(buf, ",");
! 177: (void) strcat(buf, distoptinfo[i].do_name);
! 178: }
! 179: }
! 180:
! 181: return(buf);
! 182: }
! 183: