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

Diff for /src/usr.bin/less/option.c between version 1.1.1.3 and 1.1.1.4

version 1.1.1.3, 2011/09/16 17:47:07 version 1.1.1.4, 2014/04/25 13:33:49
Line 1 
Line 1 
 /*  /*
  * Copyright (C) 1984-2011  Mark Nudelman   * Copyright (C) 1984-2012  Mark Nudelman
  *   *
  * You may distribute under the terms of either the GNU General Public   * You may distribute under the terms of either the GNU General Public
  * License or the Less License, as specified in the README file.   * License or the Less License, as specified in the README file.
  *   *
  * For more information about less, or for information on how to   * For more information, see the README file.
  * contact the author, see the README file.  
  */   */
   
   
Line 31 
Line 30 
 extern int less_is_more;  extern int less_is_more;
 extern int quit_at_eof;  extern int quit_at_eof;
 extern char *every_first_cmd;  extern char *every_first_cmd;
   extern int opt_use_backslash;
   
 /*  /*
  * Return a printable description of an option.   * Return a printable description of an option.
Line 57 
Line 57 
 {  {
         static char buf[8];          static char buf[8];
   
         sprintf(buf, "-%s", prchar(c));          snprintf(buf, sizeof(buf), "-%s", prchar(c));
         return (buf);          return (buf);
 }  }
   
Line 120 
Line 120 
                 case END_OPTION_STRING:                  case END_OPTION_STRING:
                         continue;                          continue;
                 case '-':                  case '-':
   #if GNU_OPTIONS
                         /*                          /*
                          * "--" indicates an option name instead of a letter.                           * "--" indicates an option name instead of a letter.
                          */                           */
Line 128 
Line 129 
                                 optname = ++s;                                  optname = ++s;
                                 break;                                  break;
                         }                          }
   #endif
                         /*                          /*
                          * "-+" means set these options back to their defaults.                           * "-+" means set these options back to their defaults.
                          * (They may have been set otherwise by previous                           * (They may have been set otherwise by previous
Line 147 
Line 149 
                          */                           */
                         plusoption = TRUE;                          plusoption = TRUE;
                         s = optstring(s, &str, propt('+'), NULL);                          s = optstring(s, &str, propt('+'), NULL);
                           if (s == NULL)
                                   return;
                         if (*str == '+')                          if (*str == '+')
                                 every_first_cmd = save(++str);                                  every_first_cmd = save(str+1);
                         else                          else
                                 ungetsc(str);                                  ungetsc(str);
                           free(str);
                         continue;                          continue;
                 case '0':  case '1':  case '2':  case '3':  case '4':                  case '0':  case '1':  case '2':  case '3':  case '4':
                 case '5':  case '6':  case '7':  case '8':  case '9':                  case '5':  case '6':  case '7':  case '8':  case '9':
Line 178 
Line 183 
                         printopt = propt(optc);                          printopt = propt(optc);
                         lc = ASCII_IS_LOWER(optc);                          lc = ASCII_IS_LOWER(optc);
                         o = findopt(optc);                          o = findopt(optc);
                 } else                  }
   #if GNU_OPTIONS
                   else
                 {                  {
                         printopt = optname;                          printopt = optname;
                         lc = ASCII_IS_LOWER(optname[0]);                          lc = ASCII_IS_LOWER(optname[0]);
Line 203 
Line 210 
                                         parg.p_string = printopt;                                          parg.p_string = printopt;
                                         error("The %s option should not be followed by =",                                          error("The %s option should not be followed by =",
                                                 &parg);                                                  &parg);
                                         quit(QUIT_ERROR);                                          return;
                                 }                                  }
                                 s++;                                  s++;
                         } else                          } else
Line 215 
Line 222 
                                 o = NULL;                                  o = NULL;
                         }                          }
                 }                  }
   #endif
                 if (o == NULL)                  if (o == NULL)
                 {                  {
                         parg.p_string = printopt;                          parg.p_string = printopt;
Line 224 
Line 232 
                         else                          else
                                 error("There is no %s option (\"less --help\" for help)",                                  error("There is no %s option (\"less --help\" for help)",
                                         &parg);                                          &parg);
                         quit(QUIT_ERROR);                          return;
                 }                  }
   
                 str = NULL;                  str = NULL;
Line 261 
Line 269 
                         while (*s == ' ')                          while (*s == ' ')
                                 s++;                                  s++;
                         s = optstring(s, &str, printopt, o->odesc[1]);                          s = optstring(s, &str, printopt, o->odesc[1]);
                           if (s == NULL)
                                   return;
                         break;                          break;
                 case NUMBER:                  case NUMBER:
                         if (*s == '\0')                          if (*s == '\0')
Line 276 
Line 286 
                  */                   */
                 if (o->ofunc != NULL)                  if (o->ofunc != NULL)
                         (*o->ofunc)(INIT, str);                          (*o->ofunc)(INIT, str);
                   if (str != NULL)
                           free(str);
         }          }
 }  }
   
Line 559 
Line 571 
         char *validchars;          char *validchars;
 {  {
         register char *p;          register char *p;
           register char *out;
   
         if (*s == '\0')          if (*s == '\0')
         {          {
                 nostring(printopt);                  nostring(printopt);
                 quit(QUIT_ERROR);                  return (NULL);
         }          }
         *p_str = s;          /* Alloc could be more than needed, but not worth trimming. */
           *p_str = (char *) ecalloc(strlen(s)+1, sizeof(char));
           out = *p_str;
   
         for (p = s;  *p != '\0';  p++)          for (p = s;  *p != '\0';  p++)
         {          {
                 if (*p == END_OPTION_STRING ||                  if (opt_use_backslash && *p == '\\' && p[1] != '\0')
                     (validchars != NULL && strchr(validchars, *p) == NULL))  
                 {                  {
                         switch (*p)                          /* Take next char literally. */
                         {                          ++p;
                         case END_OPTION_STRING:                  } else
                         case ' ':  case '\t':  case '-':                  {
                                 /* Replace the char with a null to terminate string. */                          if (*p == END_OPTION_STRING ||
                                 *p++ = '\0';                              (validchars != NULL && strchr(validchars, *p) == NULL))
                                   /* End of option string. */
                                 break;                                  break;
                         default:  
                                 /* Cannot replace char; make a copy of the string. */  
                                 *p_str = (char *) ecalloc(p-s+1, sizeof(char));  
                                 strncpy(*p_str, s, p-s);  
                                 (*p_str)[p-s] = '\0';  
                                 break;  
                         }  
                         break;  
                 }                  }
                   *out++ = *p;
         }          }
           *out = '\0';
         return (p);          return (p);
 }  }
   
Line 610 
Line 620 
                 parg.p_string = printopt;                  parg.p_string = printopt;
                 error("Number is required after %s", &parg);                  error("Number is required after %s", &parg);
         }          }
         quit(QUIT_ERROR);  
         /* NOTREACHED */  
         return (-1);          return (-1);
 }  }
   

Legend:
Removed from v.1.1.1.3  
changed lines
  Added in v.1.1.1.4