=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/option.c,v retrieving revision 1.1.1.3 retrieving revision 1.1.1.4 diff -c -r1.1.1.3 -r1.1.1.4 *** src/usr.bin/less/option.c 2011/09/16 17:47:07 1.1.1.3 --- src/usr.bin/less/option.c 2014/04/25 13:33:49 1.1.1.4 *************** *** 1,11 **** /* ! * Copyright (C) 1984-2011 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. * ! * For more information about less, or for information on how to ! * contact the author, see the README file. */ --- 1,10 ---- /* ! * Copyright (C) 1984-2012 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. * ! * For more information, see the README file. */ *************** *** 31,36 **** --- 30,36 ---- extern int less_is_more; extern int quit_at_eof; extern char *every_first_cmd; + extern int opt_use_backslash; /* * Return a printable description of an option. *************** *** 57,63 **** { static char buf[8]; ! sprintf(buf, "-%s", prchar(c)); return (buf); } --- 57,63 ---- { static char buf[8]; ! snprintf(buf, sizeof(buf), "-%s", prchar(c)); return (buf); } *************** *** 120,125 **** --- 120,126 ---- case END_OPTION_STRING: continue; case '-': + #if GNU_OPTIONS /* * "--" indicates an option name instead of a letter. */ *************** *** 128,133 **** --- 129,135 ---- optname = ++s; break; } + #endif /* * "-+" means set these options back to their defaults. * (They may have been set otherwise by previous *************** *** 147,156 **** */ plusoption = TRUE; s = optstring(s, &str, propt('+'), NULL); if (*str == '+') ! every_first_cmd = save(++str); else ungetsc(str); continue; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': --- 149,161 ---- */ plusoption = TRUE; s = optstring(s, &str, propt('+'), NULL); + if (s == NULL) + return; if (*str == '+') ! every_first_cmd = save(str+1); else ungetsc(str); + free(str); continue; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': *************** *** 178,184 **** printopt = propt(optc); lc = ASCII_IS_LOWER(optc); o = findopt(optc); ! } else { printopt = optname; lc = ASCII_IS_LOWER(optname[0]); --- 183,191 ---- printopt = propt(optc); lc = ASCII_IS_LOWER(optc); o = findopt(optc); ! } ! #if GNU_OPTIONS ! else { printopt = optname; lc = ASCII_IS_LOWER(optname[0]); *************** *** 203,209 **** parg.p_string = printopt; error("The %s option should not be followed by =", &parg); ! quit(QUIT_ERROR); } s++; } else --- 210,216 ---- parg.p_string = printopt; error("The %s option should not be followed by =", &parg); ! return; } s++; } else *************** *** 215,220 **** --- 222,228 ---- o = NULL; } } + #endif if (o == NULL) { parg.p_string = printopt; *************** *** 224,230 **** else error("There is no %s option (\"less --help\" for help)", &parg); ! quit(QUIT_ERROR); } str = NULL; --- 232,238 ---- else error("There is no %s option (\"less --help\" for help)", &parg); ! return; } str = NULL; *************** *** 261,266 **** --- 269,276 ---- while (*s == ' ') s++; s = optstring(s, &str, printopt, o->odesc[1]); + if (s == NULL) + return; break; case NUMBER: if (*s == '\0') *************** *** 276,281 **** --- 286,293 ---- */ if (o->ofunc != NULL) (*o->ofunc)(INIT, str); + if (str != NULL) + free(str); } } *************** *** 559,593 **** char *validchars; { register char *p; if (*s == '\0') { nostring(printopt); ! quit(QUIT_ERROR); } ! *p_str = s; for (p = s; *p != '\0'; p++) { ! if (*p == END_OPTION_STRING || ! (validchars != NULL && strchr(validchars, *p) == NULL)) { ! switch (*p) ! { ! case END_OPTION_STRING: ! case ' ': case '\t': case '-': ! /* Replace the char with a null to terminate string. */ ! *p++ = '\0'; 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; } } return (p); } --- 571,603 ---- char *validchars; { register char *p; + register char *out; if (*s == '\0') { nostring(printopt); ! return (NULL); } ! /* 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++) { ! if (opt_use_backslash && *p == '\\' && p[1] != '\0') { ! /* Take next char literally. */ ! ++p; ! } else ! { ! if (*p == END_OPTION_STRING || ! (validchars != NULL && strchr(validchars, *p) == NULL)) ! /* End of option string. */ break; } + *out++ = *p; } + *out = '\0'; return (p); } *************** *** 610,617 **** parg.p_string = printopt; error("Number is required after %s", &parg); } - quit(QUIT_ERROR); - /* NOTREACHED */ return (-1); } --- 620,625 ----