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

Diff for /src/usr.bin/rdist/distopt.c between version 1.7 and 1.8

version 1.7, 2003/04/05 20:31:58 version 1.8, 2003/05/14 01:34:35
Line 33 
Line 33 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
   #include "defs.h"
 #ifndef lint  #ifndef lint
 #if 0  #if 0
 static char RCSid[] =  static char RCSid[] __attribute__((__unused__)) =
 "$From: distopt.c,v 6.10 1996/01/30 01:52:07 mcooper Exp $";  "$From: distopt.c,v 1.5 1999/08/04 15:57:33 christos Exp $";
 #else  #else
 static char RCSid[] =  static char RCSid[] __attribute__((__unused__)) =
 "$OpenBSD$";  "$OpenBSD$";
 #endif  #endif
   
 static char sccsid[] = "@(#)distopt.c";  static char sccsid[] __attribute__((__unused__)) =
   "@(#)distopt.c";
   
 static char copyright[] =  static char copyright[] __attribute__((__unused__)) =
 "@(#) Copyright (c) 1983 Regents of the University of California.\n\  "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  All rights reserved.\n";   All rights reserved.\n";
 #endif /* !lint */  #endif /* !lint */
Line 53 
Line 55 
  * Dist Option functions   * Dist Option functions
  */   */
   
 #include "defs.h"  
   
 /*  /*
  * Distfile Option Information   * Distfile Option Information
  */   */
 DISTOPTINFO distoptinfo[] = {  DISTOPTINFO distoptinfo[] = {
         { DO_CHKNFS,            "chknfs" },          { DO_CHKNFS,            "chknfs",       NULL,           0},
         { DO_CHKREADONLY,       "chkreadonly" },          { DO_CHKREADONLY,       "chkreadonly",  NULL,           0},
         { DO_CHKSYM,            "chksym" },          { DO_CHKSYM,            "chksym",       NULL,           0},
         { DO_COMPARE,           "compare" },          { DO_DEFGROUP,          "defgroup",     defgroup,       sizeof(defgroup) },
         { DO_FOLLOW,            "follow" },          { DO_DEFOWNER,          "defowner",     defowner,       sizeof(defowner) },
         { DO_IGNLNKS,           "ignlnks" },          { DO_COMPARE,           "compare",      NULL,           0},
         { DO_NOCHKGROUP,        "nochkgroup" },          { DO_FOLLOW,            "follow",       NULL,           0},
         { DO_NOCHKMODE,         "nochkmode" },          { DO_HISTORY,           "history",      NULL,           0},
         { DO_NOCHKOWNER,        "nochkowner" },          { DO_IGNLNKS,           "ignlnks",      NULL,           0},
         { DO_NODESCEND,         "nodescend" },          { DO_NOCHKGROUP,        "nochkgroup",   NULL,           0},
         { DO_NOEXEC,            "noexec" },          { DO_NOCHKMODE,         "nochkmode",    NULL,           0},
         { DO_NUMCHKGROUP,       "numchkgroup" },          { DO_NOCHKOWNER,        "nochkowner",   NULL,           0},
         { DO_NUMCHKOWNER,       "numchkowner" },          { DO_NODESCEND,         "nodescend",    NULL,           0},
         { DO_QUIET,             "quiet" },          { DO_NOEXEC,            "noexec",       NULL,           0},
         { DO_REMOVE,            "remove" },          { DO_NUMCHKGROUP,       "numchkgroup",  NULL,           0},
         { DO_SAVETARGETS,       "savetargets" },          { DO_NUMCHKOWNER,       "numchkowner",  NULL,           0},
         { DO_SPARSE,            "sparse" },          { DO_QUIET,             "quiet",        NULL,           0},
         { DO_VERIFY,            "verify" },          { DO_REMOVE,            "remove",       NULL,           0},
         { DO_WHOLE,             "whole" },          { DO_SAVETARGETS,       "savetargets",  NULL,           0},
         { DO_YOUNGER,           "younger" },          { DO_SPARSE,            "sparse",       NULL,           0},
           { DO_UPDATEPERM,        "updateperm",   NULL,           0},
           { DO_VERIFY,            "verify",       NULL,           0},
           { DO_WHOLE,             "whole",        NULL,           0},
           { DO_YOUNGER,           "younger",      NULL,           0},
         { 0 },          { 0 },
 };  };
   
 /*  /*
  * Get a Distfile Option entry named "name".   * Get a Distfile Option entry named "name".
  */   */
 extern DISTOPTINFO *getdistopt(name)  DISTOPTINFO *
         char *name;  getdistopt(char *name, int *len)
 {  {
         int i;          int i;
   
         for (i = 0; distoptinfo[i].do_name; ++i)          for (i = 0; distoptinfo[i].do_name; ++i)
                 if (strcasecmp(name, distoptinfo[i].do_name) == 0)                  if (strncasecmp(name, distoptinfo[i].do_name,
                                   *len = strlen(distoptinfo[i].do_name)) == 0)
                         return(&distoptinfo[i]);                          return(&distoptinfo[i]);
   
         return(NULL);          return(NULL);
Line 102 
Line 108 
  * If doerrs is true, print out own error message.  Returns   * If doerrs is true, print out own error message.  Returns
  * 0 on success.   * 0 on success.
  */   */
 extern int parsedistopts(str, optptr, doerrs)  int
         char *str;  parsedistopts(char *str, opt_t *optptr, int doerrs)
         opt_t *optptr;  
         int doerrs;  
 {  {
         char *string, *optstr;          char *string, *optstr;
         DISTOPTINFO *distopt;          DISTOPTINFO *distopt;
         int negate;          int len;
   
         /* strtok() is harmful */          /* strtok() is destructive */
         string = xstrdup(str);          string = xstrdup(str);
   
         for (optstr = strtok(string, ","); optstr;          for (optstr = strtok(string, ","); optstr;
              optstr = strtok(NULL, ",")) {               optstr = strtok(NULL, ",")) {
                 if (strncasecmp(optstr, "no", 2) == 0)                  /* Try Yes */
                         negate = TRUE;                  if ((distopt = getdistopt(optstr, &len)) != NULL) {
                 else  
                         negate = FALSE;  
   
                 /*  
                  * Try looking up option name.  If that fails  
                  * and the option starts with "no", strip "no"  
                  * from option and retry lookup.  
                  */  
                 if ((distopt = getdistopt(optstr))) {  
                         FLAG_ON(*optptr, distopt->do_value);                          FLAG_ON(*optptr, distopt->do_value);
                           if (distopt->do_arg && optstr[len] == '=')
                                   (void) strlcpy(distopt->do_arg,
                                       &optstr[len + 1], distopt->arg_size);
                         continue;                          continue;
                 }                  }
                 if (negate && (distopt = getdistopt(optstr+2))) {  
                   /* Try No */
                   if ((distopt = getdistopt(optstr+2, &len)) != NULL) {
                         FLAG_OFF(*optptr, distopt->do_value);                          FLAG_OFF(*optptr, distopt->do_value);
                         continue;                          continue;
                 }                  }
   
                 if (doerrs)                  if (doerrs)
                         error("Dist option \"%s\" is not valid.", optstr);                          error("Dist option \"%s\" is not valid.", optstr);
         }          }
Line 147 
Line 148 
 /*  /*
  * Get a list of the Distfile Option Entries.   * Get a list of the Distfile Option Entries.
  */   */
 extern char *getdistoptlist()  char *
   getdistoptlist(void)
 {  {
         int i;          int i;
         static char buf[1024];          static char buf[1024];
   
         for (i = 0, buf[0] = CNULL; distoptinfo[i].do_name; ++i) {          for (i = 0, buf[0] = CNULL; distoptinfo[i].do_name; ++i) {
                 if (buf[0] == CNULL)                  if (buf[0] == CNULL)
                         (void) strlcpy(buf, distoptinfo[i].do_name,                          (void) strlcpy(buf, distoptinfo[i].do_name, sizeof buf);
                             sizeof buf);  
                 else {                  else {
                         (void) strlcat(buf, ",", sizeof buf);                          (void) strlcat(buf, ",", sizeof buf);
                         (void) strlcat(buf, distoptinfo[i].do_name,                          (void) strlcat(buf, distoptinfo[i].do_name, sizeof buf);
                             sizeof buf);  
                 }                  }
         }          }
   
Line 170 
Line 170 
  * Get a list of the Distfile Option Entries for each enabled   * Get a list of the Distfile Option Entries for each enabled
  * value in "opts".   * value in "opts".
  */   */
 extern char *getondistoptlist(opts)  char *
         opt_t opts;  getondistoptlist(opt_t opts)
 {  {
         int i;          int i;
         static char buf[1024];          static char buf[1024];
Line 181 
Line 181 
                         continue;                          continue;
   
                 if (buf[0] == CNULL)                  if (buf[0] == CNULL)
                         (void) strlcpy(buf, distoptinfo[i].do_name,                          (void) strlcpy(buf, distoptinfo[i].do_name, sizeof buf);
                             sizeof buf);  
                 else {                  else {
                         (void) strlcat(buf, ",", sizeof buf);                          (void) strlcat(buf, ",", sizeof buf);
                         (void) strlcat(buf, distoptinfo[i].do_name,                          (void) strlcat(buf, distoptinfo[i].do_name, sizeof buf);
                             sizeof buf);                  }
                   if (distoptinfo[i].do_arg) {
                           (void) strlcat(buf, "=", sizeof buf);
                           (void) strlcat(buf, distoptinfo[i].do_arg, sizeof buf);
                 }                  }
         }          }
   

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8