=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/optfunc.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.2 diff -c -r1.1.1.1 -r1.1.1.2 *** src/usr.bin/less/optfunc.c 1996/09/21 05:39:43 1.1.1.1 --- src/usr.bin/less/optfunc.c 2003/04/13 18:21:21 1.1.1.2 *************** *** 1,27 **** /* ! * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman ! * All rights reserved. * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted provided that the following conditions ! * are met: ! * 1. Redistributions of source code must retain the above copyright ! * notice, this list of conditions and the following disclaimer. ! * 2. Redistributions in binary form must reproduce the above copyright ! * notice in the documentation and/or other materials provided with ! * the distribution. * ! * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY ! * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ! * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE ! * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ! * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT ! * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ! * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ! * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ! * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ! * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ --- 1,11 ---- /* ! * Copyright (C) 1984-2002 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. */ *************** *** 45,60 **** #include "option.h" extern int nbufs; ! extern int cbufs; extern int pr_type; - extern int nohelp; extern int plusoption; extern int swindow; extern int sc_height; extern int any_display; extern char *prproto[]; extern char *eqproto; extern IFILE curr_ifile; #if LOGFILE extern char *namelogfile; extern int force_logfile; --- 29,50 ---- #include "option.h" extern int nbufs; ! extern int bufspace; extern int pr_type; extern int plusoption; extern int swindow; extern int sc_height; + extern int secure; + extern int dohelp; extern int any_display; + extern char openquote; + extern char closequote; extern char *prproto[]; extern char *eqproto; + extern char *hproto; + extern char *wproto; extern IFILE curr_ifile; + extern char version[]; #if LOGFILE extern char *namelogfile; extern int force_logfile; *************** *** 62,72 **** #endif #if TAGS public char *tagoption = NULL; - extern char *tagfile; extern char *tags; extern int jump_sline; #endif ! #if MSOFTC extern int nm_fg_color, nm_bg_color; extern int bo_fg_color, bo_bg_color; extern int ul_fg_color, ul_bg_color; --- 52,61 ---- #endif #if TAGS public char *tagoption = NULL; extern char *tags; extern int jump_sline; #endif ! #if MSDOS_COMPILER extern int nm_fg_color, nm_bg_color; extern int bo_fg_color, bo_bg_color; extern int ul_fg_color, ul_bg_color; *************** *** 86,91 **** --- 75,85 ---- { PARG parg; + if (secure) + { + error("log file support is not available", NULL_PARG); + return; + } switch (type) { case INIT: *************** *** 103,109 **** return; } s = skipsp(s); ! namelogfile = glob(s); use_logfile(namelogfile); sync_logfile(); break; --- 97,103 ---- return; } s = skipsp(s); ! namelogfile = lglob(s); use_logfile(namelogfile); sync_logfile(); break; *************** *** 148,154 **** { case INIT: t = s; ! n = getnum(&t, 'l', &err); if (err || n <= 0) { error("Line number is required after -l", NULL_PARG); --- 142,148 ---- { case INIT: t = s; ! n = getnum(&t, "l", &err); if (err || n <= 0) { error("Line number is required after -l", NULL_PARG); *************** *** 171,177 **** switch (type) { case INIT: ! if (lesskey(s)) { parg.p_string = s; error("Cannot use lesskey file \"%s\"", &parg); --- 165,171 ---- switch (type) { case INIT: ! if (lesskey(s, 0)) { parg.p_string = s; error("Cannot use lesskey file \"%s\"", &parg); *************** *** 200,217 **** /* Do the rest in main() */ break; case TOGGLE: findtag(skipsp(s)); ! if (tagfile == NULL) break; - save_ifile = curr_ifile; - if (edit(tagfile)) - break; if ((pos = tagsearch()) == NULL_POSITION) { ! if (edit_ifile(save_ifile)) ! quit(QUIT_ERROR); break; } jump_loc(pos, jump_sline); break; } --- 194,214 ---- /* Do the rest in main() */ break; case TOGGLE: + if (secure) + { + error("tags support is not available", NULL_PARG); + break; + } findtag(skipsp(s)); ! save_ifile = save_curr_ifile(); ! if (edit_tagfile()) break; if ((pos = tagsearch()) == NULL_POSITION) { ! reedit_ifile(save_ifile); break; } + unsave_ifile(save_ifile); jump_loc(pos, jump_sline); break; } *************** *** 234,240 **** break; case TOGGLE: s = skipsp(s); ! tags = glob(s); break; case QUERY: parg.p_string = tags; --- 231,237 ---- break; case TOGGLE: s = skipsp(s); ! tags = lglob(s); break; case QUERY: parg.p_string = tags; *************** *** 287,295 **** --- 284,295 ---- */ switch (*s) { + case 's': proto = &prproto[PR_SHORT]; s++; break; case 'm': proto = &prproto[PR_MEDIUM]; s++; break; case 'M': proto = &prproto[PR_LONG]; s++; break; case '=': proto = &eqproto; s++; break; + case 'h': proto = &hproto; s++; break; + case 'w': proto = &wproto; s++; break; default: proto = &prproto[PR_SHORT]; break; } free(*proto); *************** *** 313,326 **** { switch (type) { case TOGGLE: - case QUERY: /* ! * Allocate the new number of buffers. */ ! cbufs = ch_nbuf(cbufs); break; ! case INIT: break; } } --- 313,326 ---- { switch (type) { + case INIT: case TOGGLE: /* ! * Set the new number of buffers. */ ! ch_setbufspace(bufspace); break; ! case QUERY: break; } } *************** *** 358,374 **** { case TOGGLE: case QUERY: - case INIT: dispversion(); - if (type == INIT) - quit(QUIT_OK); break; } } ! #if MSOFTC /* ! * */ static void colordesc(s, fg_color, bg_color) --- 358,385 ---- { case TOGGLE: case QUERY: dispversion(); break; + case INIT: + /* + * Force output to stdout per GNU standard for --version output. + */ + any_display = 1; + putstr("less "); + putstr(version); + putstr("\nCopyright (C) 2002 Mark Nudelman\n\n"); + putstr("less comes with NO WARRANTY, to the extent permitted by law.\n"); + putstr("For information about the terms of redistribution,\n"); + putstr("see the file named README in the less distribution.\n"); + putstr("Homepage: http://www.greenwoodsoftware.com/less\n"); + quit(QUIT_OK); + break; } } ! #if MSDOS_COMPILER /* ! * Parse an MSDOS color descriptor. */ static void colordesc(s, fg_color, bg_color) *************** *** 379,385 **** int fg, bg; int err; ! fg = getnum(&s, 'D', &err); if (err) { error("Missing fg color in -D", NULL_PARG); --- 390,396 ---- int fg, bg; int err; ! fg = getnum(&s, "D", &err); if (err) { error("Missing fg color in -D", NULL_PARG); *************** *** 390,402 **** else { s++; ! bg = getnum(&s, 'D', &err); if (err) { error("Missing fg color in -D", NULL_PARG); return; } } *fg_color = fg; *bg_color = bg; } --- 401,415 ---- else { s++; ! bg = getnum(&s, "D", &err); if (err) { error("Missing fg color in -D", NULL_PARG); return; } } + if (*s != '\0') + error("Extra characters at end of -D option", NULL_PARG); *fg_color = fg; *bg_color = bg; } *************** *** 448,453 **** --- 461,565 ---- #endif /* + * Handler for the -x option. + */ + public void + opt_x(type, s) + int type; + register char *s; + { + extern int tabstops[]; + extern int ntabstops; + extern int tabdefault; + char msg[60+(4*TABSTOP_MAX)]; + int i; + PARG p; + + switch (type) + { + case INIT: + case TOGGLE: + /* Start at 1 because tabstops[0] is always zero. */ + for (i = 1; i < TABSTOP_MAX; ) + { + int n = 0; + s = skipsp(s); + while (*s >= '0' && *s <= '9') + n = (10 * n) + (*s++ - '0'); + if (n > tabstops[i-1]) + tabstops[i++] = n; + s = skipsp(s); + if (*s++ != ',') + break; + } + if (i < 2) + return; + ntabstops = i; + tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2]; + break; + case QUERY: + strcpy(msg, "Tab stops "); + if (ntabstops > 2) + { + for (i = 1; i < ntabstops; i++) + { + if (i > 1) + strcat(msg, ","); + sprintf(msg+strlen(msg), "%d", tabstops[i]); + } + sprintf(msg+strlen(msg), " and then "); + } + sprintf(msg+strlen(msg), "every %d spaces", + tabdefault); + p.p_string = msg; + error("%s", &p); + break; + } + } + + + /* + * Handler for the -" option. + */ + public void + opt_quote(type, s) + int type; + register char *s; + { + char buf[3]; + PARG parg; + + switch (type) + { + case INIT: + case TOGGLE: + if (s[0] == '\0') + { + openquote = closequote = '\0'; + break; + } + if (s[1] != '\0' && s[2] != '\0') + { + error("-\" must be followed by 1 or 2 chars", NULL_PARG); + return; + } + openquote = s[0]; + if (s[1] == '\0') + closequote = openquote; + else + closequote = s[1]; + break; + case QUERY: + buf[0] = openquote; + buf[1] = closequote; + buf[2] = '\0'; + parg.p_string = buf; + error("quotes %s", &parg); + break; + } + } + + /* * "-?" means display a help message. * If from the command line, exit immediately. */ *************** *** 457,464 **** int type; char *s; { - if (nohelp) - return; switch (type) { case QUERY: --- 569,574 ---- *************** *** 466,485 **** error("Use \"h\" for help", NULL_PARG); break; case INIT: ! /* ! * This is "less -?". ! * It rather ungracefully grabs control, ! * does the initializations normally done in main, ! * shows the help file and exits. ! */ ! raw_mode(1); ! get_term(); ! open_getchr(); ! init(); ! any_display = TRUE; ! help(1); ! quit(QUIT_OK); ! /*NOTREACHED*/ } } --- 576,582 ---- error("Use \"h\" for help", NULL_PARG); break; case INIT: ! dohelp = 1; } }