aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2006-08-20 15:49:51 +0000
committerXin LI <delphij@FreeBSD.org>2006-08-20 15:49:51 +0000
commit6dcb072b3021f88118ab758d851d01be270f36b2 (patch)
tree66e8cb2705abe3d167ba3a94a60d37c894690ff2
parentba8e3be904c2f0df1a141a80573f97e3fe4930e7 (diff)
downloadsrc-6dcb072b3021f88118ab758d851d01be270f36b2.tar.gz
src-6dcb072b3021f88118ab758d851d01be270f36b2.zip
Import less v394
Notes
Notes: svn path=/vendor/less/dist/; revision=161475
-rw-r--r--contrib/less/LICENSE2
-rw-r--r--contrib/less/Makefile.aut12
-rw-r--r--contrib/less/Makefile.in3
-rw-r--r--contrib/less/Makefile.wnb35
-rw-r--r--contrib/less/NEWS59
-rw-r--r--contrib/less/README11
-rw-r--r--contrib/less/brac.c2
-rw-r--r--contrib/less/ch.c2
-rw-r--r--contrib/less/charset.c785
-rw-r--r--contrib/less/charset.h19
-rw-r--r--contrib/less/cmd.h2
-rw-r--r--contrib/less/cmdbuf.c543
-rw-r--r--contrib/less/command.c51
-rwxr-xr-xcontrib/less/configure120
-rw-r--r--contrib/less/configure.ac34
-rw-r--r--contrib/less/decode.c6
-rw-r--r--contrib/less/defines.ds8
-rw-r--r--contrib/less/defines.h.in17
-rw-r--r--contrib/less/defines.o28
-rw-r--r--contrib/less/defines.o98
-rw-r--r--contrib/less/defines.wn8
-rw-r--r--contrib/less/edit.c16
-rw-r--r--contrib/less/filename.c54
-rw-r--r--contrib/less/forwback.c13
-rw-r--r--contrib/less/funcs.h28
-rw-r--r--contrib/less/ifile.c2
-rw-r--r--contrib/less/input.c93
-rw-r--r--contrib/less/jump.c8
-rw-r--r--contrib/less/less.h95
-rw-r--r--contrib/less/less.man2470
-rw-r--r--contrib/less/less.nro354
-rw-r--r--contrib/less/lessecho.c4
-rw-r--r--contrib/less/lessecho.man49
-rw-r--r--contrib/less/lessecho.nro47
-rw-r--r--contrib/less/lesskey.c2
-rw-r--r--contrib/less/lesskey.h2
-rw-r--r--contrib/less/lesskey.man302
-rw-r--r--contrib/less/lesskey.nro4
-rw-r--r--contrib/less/lglob.h2
-rw-r--r--contrib/less/line.c869
-rw-r--r--contrib/less/linenum.c2
-rw-r--r--contrib/less/lsystem.c148
-rw-r--r--contrib/less/main.c14
-rw-r--r--contrib/less/mark.c2
-rw-r--r--contrib/less/mkhelp.c2
-rw-r--r--contrib/less/optfunc.c25
-rw-r--r--contrib/less/option.c10
-rw-r--r--contrib/less/option.h2
-rw-r--r--contrib/less/opttbl.c26
-rw-r--r--contrib/less/os.c8
-rw-r--r--contrib/less/output.c70
-rw-r--r--contrib/less/pckeys.h2
-rw-r--r--contrib/less/position.c2
-rw-r--r--contrib/less/position.h2
-rw-r--r--contrib/less/prompt.c30
-rw-r--r--contrib/less/screen.c229
-rw-r--r--contrib/less/scrsize.c2
-rw-r--r--contrib/less/search.c130
-rw-r--r--contrib/less/signal.c5
-rw-r--r--contrib/less/tags.c39
-rw-r--r--contrib/less/ttyin.c35
-rw-r--r--contrib/less/version.c28
62 files changed, 4130 insertions, 2832 deletions
diff --git a/contrib/less/LICENSE b/contrib/less/LICENSE
index dd154f6771d7..7e4887bcd768 100644
--- a/contrib/less/LICENSE
+++ b/contrib/less/LICENSE
@@ -2,7 +2,7 @@
------------
Less
-Copyright (C) 1984-2002 Mark Nudelman
+Copyright (C) 1984-2005 Mark Nudelman
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
diff --git a/contrib/less/Makefile.aut b/contrib/less/Makefile.aut
index f105d6902f0d..b2497c03ef69 100644
--- a/contrib/less/Makefile.aut
+++ b/contrib/less/Makefile.aut
@@ -24,9 +24,10 @@ DISTFILES = \
${SRC} regexp.c regexp.h \
COPYING INSTALL LICENSE Makefile.in Makefile.aut NEWS README \
configure configure.ac lesskey.c lessecho.c scrsize.c \
- cmd.h funcs.h lglob.h less.h lesskey.h option.h pckeys.h position.h \
+ charset.h cmd.h funcs.h lglob.h less.h lesskey.h option.h pckeys.h position.h \
install.sh defines.h.in mkinstalldirs \
- less.nro lesskey.nro less.man lesskey.man less.hlp \
+ less.nro less.man lesskey.nro lesskey.man lessecho.nro lessecho.man \
+ less.hlp \
mkfuncs.awk mkhelp.c \
${DISTFILES_W}
@@ -55,7 +56,8 @@ lint:
clean:
rm -f Makefile config.status config.log config.cache defines.h stamp-h \
- README NEWS less.nro lesskey.nro less.man lesskey.man
+ README NEWS \
+ less.nro less.man lesskey.nro lesskey.man lessecho.nro lessecho.man
distclean: clean
realclean: clean
@@ -78,6 +80,8 @@ ${srcdir}/less.nro: ${srcdir}/less.nro.VER ${srcdir}/version.c
${REPLACE_VERSION} ${srcdir}/less.nro.VER
${srcdir}/lesskey.nro: ${srcdir}/lesskey.nro.VER ${srcdir}/version.c
${REPLACE_VERSION} ${srcdir}/lesskey.nro.VER
+${srcdir}/lessecho.nro: ${srcdir}/lessecho.nro.VER ${srcdir}/version.c
+ ${REPLACE_VERSION} ${srcdir}/lessecho.nro.VER
${srcdir}/less.hlp: ${srcdir}/less.hlp.VER ${srcdir}/version.c
${REPLACE_VERSION} ${srcdir}/less.hlp.VER
@@ -85,6 +89,8 @@ ${srcdir}/less.man: ${srcdir}/less.nro
${NROFF} ${srcdir}/less.nro >${srcdir}/less.man
${srcdir}/lesskey.man: ${srcdir}/lesskey.nro
${NROFF} ${srcdir}/lesskey.nro >${srcdir}/lesskey.man
+${srcdir}/lessecho.man: ${srcdir}/lessecho.nro
+ ${NROFF} ${srcdir}/lessecho.nro >${srcdir}/lessecho.man
distfiles: ${DISTFILES}
diff --git a/contrib/less/Makefile.in b/contrib/less/Makefile.in
index 8e976bb43ad4..b33aa8d895b6 100644
--- a/contrib/less/Makefile.in
+++ b/contrib/less/Makefile.in
@@ -59,12 +59,13 @@ lessecho: lessecho.${O} version.${O}
${OBJ}: ${srcdir}/less.h ${srcdir}/funcs.h defines.h
-install: all ${srcdir}/less.nro ${srcdir}/lesskey.nro installdirs
+install: all ${srcdir}/less.nro ${srcdir}/lesskey.nro ${srcdir}/lessecho.nro installdirs
${INSTALL_PROGRAM} less ${bindir}/${binprefix}less
${INSTALL_PROGRAM} lesskey ${bindir}/${binprefix}lesskey
${INSTALL_PROGRAM} lessecho ${bindir}/${binprefix}lessecho
${INSTALL_DATA} ${srcdir}/less.nro ${mandir}/man${manext}/${manprefix}less.${manext}
${INSTALL_DATA} ${srcdir}/lesskey.nro ${mandir}/man${manext}/${manprefix}lesskey.${manext}
+ ${INSTALL_DATA} ${srcdir}/lessecho.nro ${mandir}/man${manext}/${manprefix}lessecho.${manext}
install-strip:
${MAKE} INSTALL_PROGRAM='${INSTALL_PROGRAM} -s' install
diff --git a/contrib/less/Makefile.wnb b/contrib/less/Makefile.wnb
index 4da10fcbe253..2d1c85b86288 100644
--- a/contrib/less/Makefile.wnb
+++ b/contrib/less/Makefile.wnb
@@ -1,20 +1,27 @@
# Makefile for less.
# Windows version
+# Bolarnd C++ 5.5.1 free command line tools
#### Start of system configuration section. ####
+#
+# Borland's make knows its own location in the
+# filesystem.
+#
CC = bcc32
-LIBDIR = d:\bc45\lib
+LIBDIR = $(MAKEDIR)\..\lib
CFLAGS = -O2 -w-pro -TWC -P-c -v- -d -f- -ff- -vi
-LDFLAGS = /Tpe /v- /ap /c /x
-LD = tlink32
+LDFLAGS = -Tpe -v- -ap -c -x -V4.0 -GF:AGGRESSIVE
+LD = ilink32
LIBS = ${LIBDIR}\import32.lib ${LIBDIR}\cw32.lib
#### End of system configuration section. ####
+#
# This rule allows us to supply the necessary -D options
# in addition to whatever the user asks for.
+#
.c.obj:
${CC} -c -I. ${CPPFLAGS} ${CFLAGS} $<
@@ -25,16 +32,20 @@ OBJ = main.obj screen.obj brac.obj ch.obj charset.obj cmdbuf.obj command.obj \
position.obj prompt.obj search.obj signal.obj tags.obj \
ttyin.obj version.obj regexp.obj
-all: less lesskey
+all: less lesskey lessecho
+#
# This is really horrible, but the command line is too long for
# MS-DOS if we try to link ${OBJ}.
+#
less: ${OBJ}
- -del lesskey.obj
- ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj *.obj, $@,,${LIBS}
+ ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj $**, $@,,${LIBS}
lesskey: lesskey.obj version.obj
- ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj lesskey.obj version.obj, $@,,${LIBS}
+ ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj $**, $@,,${LIBS}
+
+lessecho: lessecho.obj version.obj
+ ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj $**, $@,,${LIBS}
defines.h: defines.wn
-del defines.h
@@ -44,6 +55,16 @@ ${OBJ}: less.h defines.h funcs.h cmd.h
clean:
-del *.obj
+ -del *.il?
+ -del *.tds
+ -del defines.h
+
+spotless: clean
-del less.exe
-del lesskey.exe
+ -del lessecho.exe
+
+realclean: spotless
+
+distclean: spotless
diff --git a/contrib/less/NEWS b/contrib/less/NEWS
index b5f151497542..4a532f472545 100644
--- a/contrib/less/NEWS
+++ b/contrib/less/NEWS
@@ -7,12 +7,67 @@
http://www.greenwoodsoftware.com/less
You can also download the latest version of less from there.
- To report bugs, suggestions or comments, send email to
- bug-less@gnu.org or markn@greenwoodsoftware.com.
+ To report bugs, suggestions or comments, send email to bug-less@gnu.org.
======================================================================
+ Major changes between "less" versions 382 and 394
+
+* Add history file to save search and shell command history between
+ invocations of less.
+
+* Improve behavior of history list for search and shell commands.
+
+* Add -K (or --quit-on-intr) option to make less exit immediately on ctrl-C.
+
+* Improve handling of UTF-8 files and commands, including better
+ line wrapping and handling double-width chars.
+
+* Added LESSUTFBINFMT environment variable to control display of
+ non-printable characters in a UTF-8 file.
+
+* Add --with-secure option to configure, to make it easier to
+ build a secure version of less.
+
+* Show search matches in the status column even if search highlights
+ are disabled via the -G option or the ESC-u command.
+
+* Improve performance when the file contains very long lines.
+
+* Add "windows" charset.
+
+* Add man page for lessecho.
+
+* Add support for erase2 character, treated same as erase.
+
+* Use ASCII lowercase/uppercase logic when operating on the command line.
+
+* Update makefile for Borland C++ 5.5.1.
+
+* Fix bug in calculating number of pages for %D prompt.
+
+* Fix bug in handling tag file error.
+
+* Fix obscure bug if input file is deleted while viewing help.
+
+* Fix bug handling filenames which include square brackets.
+
+* Fix possible buffer overflow in "global" tag search.
+
+* Fix possible buffer overflow in usage of LESSOPEN and LESSCLOSE.
+
+* Fix buffer overflow in reverse search.
+
+======================================================================
+
+ Major changes between "less" versions 381 and 382
+
+* Removed some old copyrighted code.
+ This probably breaks OS/9 support.
+
+======================================================================
+
Major changes between "less" versions 378 and 381
* New -L option to disable LESSOPEN processing.
diff --git a/contrib/less/README b/contrib/less/README
index a2b9ca17b1ed..ce014e485f6e 100644
--- a/contrib/less/README
+++ b/contrib/less/README
@@ -1,7 +1,7 @@
- Less, version 381
+ Less, version 394
- This is the distribution of less, version 381, released 17 Jan 2003.
+ This is the distribution of less, version 394, released 03 Dec 2005.
This program is part of the GNU project (http://www.gnu.org).
This program is free software. You may redistribute it and/or
@@ -57,6 +57,10 @@ INSTALLATION (Unix systems only):
regcomp Use the V8-compatible regcomp.
regcomp-local Use Henry Spencer's V8-compatible regcomp
(source is supplied with less).
+ --with-secure
+ Builds a "secure" version of less, with some features disabled
+ to prevent users from viewing other files, accessing shell
+ commands, etc.
3. It is a good idea to look over the generated Makefile and defines.h
and make sure they look ok. If you know of any peculiarities of
@@ -67,9 +71,6 @@ INSTALLATION (Unix systems only):
-lncurses -lcurses -ltermcap -ltermlib
If you wish, you may edit defines.h to remove some optional features.
- If you wish to build a "secure" version of less (which disables all
- features which might allow a user to do unintended things to the system
- on which less is running), edit defines.h and define SECURE to 1.
If you choose not to include some features in your version, you may
wish to edit the manual page "less.nro" and the help page "less.hlp"
to remove the descriptions of the features which you are removing.
diff --git a/contrib/less/brac.c b/contrib/less/brac.c
index 43c9dacb2471..1f8c4f765620 100644
--- a/contrib/less/brac.c
+++ b/contrib/less/brac.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/ch.c b/contrib/less/ch.c
index 0446a2c2292a..ca7ccaa41c4e 100644
--- a/contrib/less/ch.c
+++ b/contrib/less/ch.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/charset.c b/contrib/less/charset.c
index 163994f56467..84eb396bdb80 100644
--- a/contrib/less/charset.c
+++ b/contrib/less/charset.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -18,8 +18,11 @@
#if HAVE_LOCALE
#include <locale.h>
#include <ctype.h>
+#include <langinfo.h>
#endif
+#include "charset.h"
+
public int utf_mode = 0;
/*
@@ -31,23 +34,76 @@ struct charset {
int *p_flag;
char *desc;
} charsets[] = {
- { "ascii", NULL, "8bcccbcc18b95.b" },
- { "dos", NULL, "8bcccbcc12bc5b223.b" },
- { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." },
- { "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" },
- { "iso8859", NULL, "8bcccbcc18b95.33b." },
- { "koi8-r", NULL, "8bcccbcc18b95.b128." },
- { "next", NULL, "8bcccbcc18b95.bb125.bb" },
- { "utf-8", &utf_mode, "8bcccbcc18b." },
+ { "ascii", NULL, "8bcccbcc18b95.b" },
+ { "utf-8", &utf_mode, "8bcccbcc18b95.b126.bb" },
+ { "iso8859", NULL, "8bcccbcc18b95.33b." },
+ { "latin3", NULL, "8bcccbcc18b95.33b5.b8.b15.b4.b12.b18.b12.b." },
+ { "arabic", NULL, "8bcccbcc18b95.33b.3b.7b2.13b.3b.b26.5b19.b" },
+ { "greek", NULL, "8bcccbcc18b95.33b4.2b4.b3.b35.b44.b" },
+ { "greek2005", NULL, "8bcccbcc18b95.33b14.b35.b44.b" },
+ { "hebrew", NULL, "8bcccbcc18b95.33b.b29.32b28.2b2.b" },
+ { "koi8-r", NULL, "8bcccbcc18b95.b." },
+ { "KOI8-T", NULL, "8bcccbcc18b95.b8.b6.b8.b.b.5b7.3b4.b4.b3.b.b.3b." },
+ { "georgianps", NULL, "8bcccbcc18b95.3b11.4b12.2b." },
+ { "tcvn", NULL, "b..b...bcccbccbbb7.8b95.b48.5b." },
+ { "TIS-620", NULL, "8bcccbcc18b95.b.4b.11b7.8b." },
+ { "next", NULL, "8bcccbcc18b95.bb125.bb" },
+ { "dos", NULL, "8bcccbcc12bc5b95.b." },
+ { "windows-1251", NULL, "8bcccbcc12bc5b95.b24.b." },
+ { "windows-1252", NULL, "8bcccbcc12bc5b95.b.b11.b.2b12.b." },
+ { "windows-1255", NULL, "8bcccbcc12bc5b95.b.b8.b.5b9.b.4b." },
+ { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." },
+ { "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" },
{ NULL, NULL, NULL }
};
+/*
+ * Support "locale charmap"/nl_langinfo(CODESET) values, as well as others.
+ */
struct cs_alias {
char *name;
char *oname;
} cs_aliases[] = {
- { "latin1", "iso8859" },
- { "latin9", "iso8859" },
+ { "UTF-8", "utf-8" },
+ { "ANSI_X3.4-1968", "ascii" },
+ { "US-ASCII", "ascii" },
+ { "latin1", "iso8859" },
+ { "ISO-8859-1", "iso8859" },
+ { "latin9", "iso8859" },
+ { "ISO-8859-15", "iso8859" },
+ { "latin2", "iso8859" },
+ { "ISO-8859-2", "iso8859" },
+ { "ISO-8859-3", "latin3" },
+ { "latin4", "iso8859" },
+ { "ISO-8859-4", "iso8859" },
+ { "cyrillic", "iso8859" },
+ { "ISO-8859-5", "iso8859" },
+ { "ISO-8859-6", "arabic" },
+ { "ISO-8859-7", "greek" },
+ { "IBM9005", "greek2005" },
+ { "ISO-8859-8", "hebrew" },
+ { "latin5", "iso8859" },
+ { "ISO-8859-9", "iso8859" },
+ { "latin6", "iso8859" },
+ { "ISO-8859-10", "iso8859" },
+ { "latin7", "iso8859" },
+ { "ISO-8859-13", "iso8859" },
+ { "latin8", "iso8859" },
+ { "ISO-8859-14", "iso8859" },
+ { "latin10", "iso8859" },
+ { "ISO-8859-16", "iso8859" },
+ { "IBM437", "dos" },
+ { "EBCDIC-US", "ebcdic" },
+ { "IBM1047", "IBM-1047" },
+ { "KOI8-R", "koi8-r" },
+ { "KOI8-U", "koi8-r" },
+ { "GEORGIAN-PS", "georgianps" },
+ { "TCVN5712-1", "tcvn" },
+ { "NEXTSTEP", "next" },
+ { "windows", "windows-1252" }, /* backward compatibility */
+ { "CP1251", "windows-1251" },
+ { "CP1252", "windows-1252" },
+ { "CP1255", "windows-1255" },
{ NULL, NULL }
};
@@ -56,6 +112,7 @@ struct cs_alias {
static char chardef[256];
static char *binfmt = NULL;
+static char *utfbinfmt = NULL;
public int binattr = AT_STANDOUT;
@@ -131,8 +188,9 @@ ichardef(s)
* The valid charset names are listed in the "charsets" array.
*/
static int
-icharset(name)
+icharset(name, no_error)
register char *name;
+ int no_error;
{
register struct charset *p;
register struct cs_alias *a;
@@ -161,9 +219,10 @@ icharset(name)
}
}
- error("invalid charset name", NULL_PARG);
- quit(QUIT_ERROR);
- /*NOTREACHED*/
+ if (!no_error) {
+ error("invalid charset name", NULL_PARG);
+ quit(QUIT_ERROR);
+ }
return (0);
}
@@ -176,7 +235,6 @@ ilocale()
{
register int c;
- setlocale(LC_ALL, "");
for (c = 0; c < (int) sizeof(chardef); c++)
{
if (isprint(c))
@@ -190,17 +248,39 @@ ilocale()
#endif
/*
- * Define the printing format for control chars.
+ * Define the printing format for control (or binary utf) chars.
*/
- public void
-setbinfmt(s)
+ static void
+setbinfmt(s, fmtvarptr, default_fmt)
char *s;
+ char **fmtvarptr;
+ char *default_fmt;
{
- if (s == NULL || *s == '\0')
- s = "*s<%X>";
+ if (s && utf_mode)
+ {
+ /* It would be too hard to account for width otherwise. */
+ char *t = s;
+ while (*t)
+ {
+ if (*t < ' ' || *t > '~')
+ {
+ s = default_fmt;
+ goto attr;
+ }
+ t++;
+ }
+ }
+
+ /* %n is evil */
+ if (s == NULL || *s == '\0' ||
+ (*s == '*' && (s[1] == '\0' || s[2] == '\0' || strchr(s + 2, 'n'))) ||
+ (*s != '*' && strchr(s, 'n')))
+ s = default_fmt;
+
/*
* Select the attributes if it starts with "*".
*/
+ attr:
if (*s == '*')
{
switch (s[1])
@@ -213,26 +293,24 @@ setbinfmt(s)
}
s += 2;
}
- binfmt = s;
+ *fmtvarptr = s;
}
/*
- * Initialize charset data structures.
+ *
*/
- public void
-init_charset()
+ static void
+set_charset()
{
- register char *s;
+ char *s;
- s = lgetenv("LESSBINFMT");
- setbinfmt(s);
-
/*
* See if environment variable LESSCHARSET is defined.
*/
s = lgetenv("LESSCHARSET");
- if (icharset(s))
+ if (icharset(s, 0))
return;
+
/*
* LESSCHARSET is not defined: try LESSCHARDEF.
*/
@@ -243,6 +321,15 @@ init_charset()
return;
}
+#if HAVE_LOCALE
+ /*
+ * Try using the codeset name as the charset name.
+ */
+ s = nl_langinfo(CODESET);
+ if (icharset(s, 1))
+ return;
+#endif
+
#if HAVE_STRSTR
/*
* Check whether LC_ALL, LC_CTYPE or LANG look like UTF-8 is used.
@@ -251,33 +338,55 @@ init_charset()
(s = lgetenv("LC_CTYPE")) != NULL ||
(s = lgetenv("LANG")) != NULL)
{
- if (strstr(s, "UTF-8") != NULL || strstr(s, "utf-8") != NULL)
- if (icharset("utf-8"))
+ if ( strstr(s, "UTF-8") != NULL || strstr(s, "utf-8") != NULL
+ || strstr(s, "UTF8") != NULL || strstr(s, "utf8") != NULL)
+ if (icharset("utf-8", 1))
return;
}
#endif
#if HAVE_LOCALE
/*
- * Use setlocale.
+ * Get character definitions from locale functions,
+ * rather than from predefined charset entry.
*/
ilocale();
-#else
#if MSDOS_COMPILER
/*
* Default to "dos".
*/
- (void) icharset("dos");
+ (void) icharset("dos", 1);
#else
/*
* Default to "latin1".
*/
- (void) icharset("latin1");
+ (void) icharset("latin1", 1);
#endif
#endif
}
/*
+ * Initialize charset data structures.
+ */
+ public void
+init_charset()
+{
+ char *s;
+
+#if HAVE_LOCALE
+ setlocale(LC_ALL, "");
+#endif
+
+ set_charset();
+
+ s = lgetenv("LESSBINFMT");
+ setbinfmt(s, &binfmt, "*s<%02X>");
+
+ s = lgetenv("LESSUTFBINFMT");
+ setbinfmt(s, &utfbinfmt, "<U+%04lX>");
+}
+
+/*
* Is a given character a "binary" character?
*/
public int
@@ -307,16 +416,17 @@ control_char(c)
prchar(c)
int c;
{
- static char buf[8];
+ /* {{ This buffer can be overrun if LESSBINFMT is a long string. }} */
+ static char buf[32];
c &= 0377;
- if (!control_char(c))
- sprintf(buf, "%c", c);
+ if ((c < 128 || !utf_mode) && !control_char(c))
+ SNPRINTF1(buf, sizeof(buf), "%c", c);
else if (c == ESC)
- sprintf(buf, "ESC");
+ strcpy(buf, "ESC");
#if IS_EBCDIC_HOST
else if (!binary_char(c) && c < 64)
- sprintf(buf, "^%c",
+ SNPRINTF1(buf, sizeof(buf), "^%c",
/*
* This array roughly inverts CONTROL() #defined in less.h,
* and should be kept in sync with CONTROL() and IBM-1047.
@@ -328,9 +438,598 @@ prchar(c)
"..V....D....TU.Z"[c]);
#else
else if (c < 128 && !control_char(c ^ 0100))
- sprintf(buf, "^%c", c ^ 0100);
+ SNPRINTF1(buf, sizeof(buf), "^%c", c ^ 0100);
#endif
else
- sprintf(buf, binfmt, c);
+ SNPRINTF1(buf, sizeof(buf), binfmt, c);
return (buf);
}
+
+/*
+ * Return the printable form of a UTF-8 character.
+ */
+ public char *
+prutfchar(ch)
+ LWCHAR ch;
+{
+ static char buf[32];
+
+ if (ch == ESC)
+ strcpy(buf, "ESC");
+ else if (ch < 128 && control_char(ch))
+ {
+ if (!control_char(ch ^ 0100))
+ SNPRINTF1(buf, sizeof(buf), "^%c", ((char) ch) ^ 0100);
+ else
+ SNPRINTF1(buf, sizeof(buf), binfmt, (char) ch);
+ } else if (is_ubin_char(ch))
+ SNPRINTF1(buf, sizeof(buf), utfbinfmt, ch);
+ else
+ {
+ int len;
+ if (ch >= 0x80000000)
+ {
+ len = 3;
+ ch = 0xFFFD;
+ } else
+ {
+ len = (ch < 0x80) ? 1
+ : (ch < 0x800) ? 2
+ : (ch < 0x10000) ? 3
+ : (ch < 0x200000) ? 4
+ : (ch < 0x4000000) ? 5
+ : 6;
+ }
+ buf[len] = '\0';
+ if (len == 1)
+ *buf = (char) ch;
+ else
+ {
+ *buf = ((1 << len) - 1) << (8 - len);
+ while (--len > 0)
+ {
+ buf[len] = (char) (0x80 | (ch & 0x3F));
+ ch >>= 6;
+ }
+ *buf |= ch;
+ }
+ }
+ return (buf);
+}
+
+/*
+ * Get the length of a UTF-8 character in bytes.
+ */
+ public int
+utf_len(ch)
+ char ch;
+{
+ if ((ch & 0x80) == 0)
+ return 1;
+ if ((ch & 0xE0) == 0xC0)
+ return 2;
+ if ((ch & 0xF0) == 0xE0)
+ return 3;
+ if ((ch & 0xF8) == 0xF0)
+ return 4;
+ if ((ch & 0xFC) == 0xF8)
+ return 5;
+ if ((ch & 0xFE) == 0xFC)
+ return 6;
+ /* Invalid UTF-8 encoding. */
+ return 1;
+}
+
+/*
+ * Is a UTF-8 character well-formed?
+ */
+ public int
+is_utf8_well_formed(s)
+ unsigned char *s;
+{
+ int i;
+ int len;
+
+ if (IS_UTF8_INVALID(s[0]))
+ return (0);
+
+ len = utf_len((char) s[0]);
+ if (len == 1)
+ return (1);
+ if (len == 2)
+ {
+ if (s[0] < 0xC2)
+ return (0);
+ } else
+ {
+ unsigned char mask;
+ mask = (~((1 << (8-len)) - 1)) & 0xFF;
+ if (s[0] == mask && (s[1] & mask) == 0x80)
+ return (0);
+ }
+
+ for (i = 1; i < len; i++)
+ if (!IS_UTF8_TRAIL(s[i]))
+ return (0);
+ return (1);
+}
+
+/*
+ * Get the value of a UTF-8 character.
+ */
+ public LWCHAR
+get_wchar(p)
+ char *p;
+{
+ switch (utf_len(p[0]))
+ {
+ case 1:
+ default:
+ return (LWCHAR)
+ (p[0] & 0xFF);
+ case 2:
+ return (LWCHAR) (
+ ((p[0] & 0x1F) << 6) |
+ (p[1] & 0x3F));
+ case 3:
+ return (LWCHAR) (
+ ((p[0] & 0x0F) << 12) |
+ ((p[1] & 0x3F) << 6) |
+ (p[2] & 0x3F));
+ case 4:
+ return (LWCHAR) (
+ ((p[0] & 0x07) << 18) |
+ ((p[1] & 0x3F) << 12) |
+ ((p[2] & 0x3F) << 6) |
+ (p[3] & 0x3F));
+ case 5:
+ return (LWCHAR) (
+ ((p[0] & 0x03) << 24) |
+ ((p[1] & 0x3F) << 18) |
+ ((p[2] & 0x3F) << 12) |
+ ((p[3] & 0x3F) << 6) |
+ (p[4] & 0x3F));
+ case 6:
+ return (LWCHAR) (
+ ((p[0] & 0x01) << 30) |
+ ((p[1] & 0x3F) << 24) |
+ ((p[2] & 0x3F) << 18) |
+ ((p[3] & 0x3F) << 12) |
+ ((p[4] & 0x3F) << 6) |
+ (p[5] & 0x3F));
+ }
+}
+
+/*
+ * Step forward or backward one character in a string.
+ */
+ public LWCHAR
+step_char(pp, dir, limit)
+ char **pp;
+ signed int dir;
+ char *limit;
+{
+ LWCHAR ch;
+ char *p = *pp;
+
+ if (!utf_mode)
+ {
+ /* It's easy if chars are one byte. */
+ if (dir > 0)
+ ch = (LWCHAR) ((p < limit) ? *p++ : 0);
+ else
+ ch = (LWCHAR) ((p > limit) ? *--p : 0);
+ } else if (dir > 0)
+ {
+ if (p + utf_len(*p) > limit)
+ ch = 0;
+ else
+ {
+ ch = get_wchar(p);
+ p++;
+ while (IS_UTF8_TRAIL(*p))
+ p++;
+ }
+ } else
+ {
+ while (p > limit && IS_UTF8_TRAIL(p[-1]))
+ p--;
+ if (p > limit)
+ ch = get_wchar(--p);
+ else
+ ch = 0;
+ }
+ *pp = p;
+ return ch;
+}
+
+/*
+ * Unicode characters data
+ */
+struct wchar_range { LWCHAR first, last; };
+
+static struct wchar_range comp_table[] = {
+ {0x300,0x357}, {0x35d,0x36f}, {0x483,0x486}, {0x488,0x489},
+ {0x591,0x5a1}, {0x5a3,0x5b9}, {0x5bb,0x5bd}, {0x5bf,0x5bf},
+ {0x5c1,0x5c2}, {0x5c4,0x5c4}, {0x610,0x615}, {0x64b,0x658},
+ {0x670,0x670}, {0x6d6,0x6dc}, {0x6de,0x6e4}, {0x6e7,0x6e8},
+ {0x6ea,0x6ed}, {0x711,0x711}, {0x730,0x74a}, {0x7a6,0x7b0},
+ {0x901,0x902}, {0x93c,0x93c}, {0x941,0x948}, {0x94d,0x94d},
+ {0x951,0x954}, {0x962,0x963}, {0x981,0x981}, {0x9bc,0x9bc},
+ {0x9c1,0x9c4}, {0x9cd,0x9cd}, {0x9e2,0x9e3}, {0xa01,0xa02},
+ {0xa3c,0xa3c}, {0xa41,0xa42}, {0xa47,0xa48}, {0xa4b,0xa4d},
+ {0xa70,0xa71}, {0xa81,0xa82}, {0xabc,0xabc}, {0xac1,0xac5},
+ {0xac7,0xac8}, {0xacd,0xacd}, {0xae2,0xae3}, {0xb01,0xb01},
+ {0xb3c,0xb3c}, {0xb3f,0xb3f}, {0xb41,0xb43}, {0xb4d,0xb4d},
+ {0xb56,0xb56}, {0xb82,0xb82}, {0xbc0,0xbc0}, {0xbcd,0xbcd},
+ {0xc3e,0xc40}, {0xc46,0xc48}, {0xc4a,0xc4d}, {0xc55,0xc56},
+ {0xcbc,0xcbc}, {0xcbf,0xcbf}, {0xcc6,0xcc6}, {0xccc,0xccd},
+ {0xd41,0xd43}, {0xd4d,0xd4d}, {0xdca,0xdca}, {0xdd2,0xdd4},
+ {0xdd6,0xdd6}, {0xe31,0xe31}, {0xe34,0xe3a}, {0xe47,0xe4e},
+ {0xeb1,0xeb1}, {0xeb4,0xeb9}, {0xebb,0xebc}, {0xec8,0xecd},
+ {0xf18,0xf19}, {0xf35,0xf35}, {0xf37,0xf37}, {0xf39,0xf39},
+ {0xf71,0xf7e}, {0xf80,0xf84}, {0xf86,0xf87}, {0xf90,0xf97},
+ {0xf99,0xfbc}, {0xfc6,0xfc6}, {0x102d,0x1030}, {0x1032,0x1032},
+ {0x1036,0x1037}, {0x1039,0x1039}, {0x1058,0x1059},
+ {0x1712,0x1714}, {0x1732,0x1734}, {0x1752,0x1753},
+ {0x1772,0x1773}, {0x17b7,0x17bd}, {0x17c6,0x17c6},
+ {0x17c9,0x17d3}, {0x17dd,0x17dd}, {0x180b,0x180d},
+ {0x18a9,0x18a9}, {0x1920,0x1922}, {0x1927,0x1928},
+ {0x1932,0x1932}, {0x1939,0x193b}, {0x20d0,0x20ea},
+ {0x302a,0x302f}, {0x3099,0x309a}, {0xfb1e,0xfb1e},
+ {0xfe00,0xfe0f}, {0xfe20,0xfe23}, {0x1d167,0x1d169},
+ {0x1d17b,0x1d182}, {0x1d185,0x1d18b}, {0x1d1aa,0x1d1ad},
+ {0xe0100,0xe01ef},
+};
+
+static struct wchar_range comb_table[] = {
+ {0x0644,0x0622}, {0x0644,0x0623}, {0x0644,0x0625}, {0x0644,0x0627},
+};
+
+/*
+ * Characters with general category values
+ * Cc: Other, Control
+ * Cf: Other, Format
+ * Cs: Other, Surrogate
+ * Co: Other, Private Use
+ * Cn: Other, Not Assigned
+ * Zl: Separator, Line
+ * Zp: Separator, Paragraph
+ */
+static struct wchar_range ubin_table[] = {
+ { 0x0000, 0x001f} /* Cc */, { 0x007f, 0x009f} /* Cc */,
+#if 0
+ { 0x00ad, 0x00ad} /* Cf */,
+#endif
+ { 0x0237, 0x024f} /* Cn */, { 0x0358, 0x035c} /* Cn */,
+ { 0x0370, 0x0373} /* Cn */, { 0x0376, 0x0379} /* Cn */,
+ { 0x037b, 0x037d} /* Cn */, { 0x037f, 0x0383} /* Cn */,
+ { 0x038b, 0x038b} /* Cn */, { 0x038d, 0x038d} /* Cn */,
+ { 0x03a2, 0x03a2} /* Cn */, { 0x03cf, 0x03cf} /* Cn */,
+ { 0x03fc, 0x03ff} /* Cn */, { 0x0487, 0x0487} /* Cn */,
+ { 0x04cf, 0x04cf} /* Cn */, { 0x04f6, 0x04f7} /* Cn */,
+ { 0x04fa, 0x04ff} /* Cn */, { 0x0510, 0x0530} /* Cn */,
+ { 0x0557, 0x0558} /* Cn */, { 0x0560, 0x0560} /* Cn */,
+ { 0x0588, 0x0588} /* Cn */, { 0x058b, 0x0590} /* Cn */,
+ { 0x05a2, 0x05a2} /* Cn */, { 0x05ba, 0x05ba} /* Cn */,
+ { 0x05c5, 0x05cf} /* Cn */, { 0x05eb, 0x05ef} /* Cn */,
+ { 0x05f5, 0x05ff} /* Cn */,
+#if 0
+ { 0x0600, 0x0603} /* Cf */,
+#endif
+ { 0x0604, 0x060b} /* Cn */, { 0x0616, 0x061a} /* Cn */,
+ { 0x061c, 0x061e} /* Cn */, { 0x0620, 0x0620} /* Cn */,
+ { 0x063b, 0x063f} /* Cn */, { 0x0659, 0x065f} /* Cn */,
+#if 0
+ { 0x06dd, 0x06dd} /* Cf */,
+#endif
+ { 0x070e, 0x070e} /* Cn */,
+#if 0
+ { 0x070f, 0x070f} /* Cf */,
+#endif
+ { 0x074b, 0x074c} /* Cn */, { 0x0750, 0x077f} /* Cn */,
+ { 0x07b2, 0x0900} /* Cn */, { 0x093a, 0x093b} /* Cn */,
+ { 0x094e, 0x094f} /* Cn */, { 0x0955, 0x0957} /* Cn */,
+ { 0x0971, 0x0980} /* Cn */, { 0x0984, 0x0984} /* Cn */,
+ { 0x098d, 0x098e} /* Cn */, { 0x0991, 0x0992} /* Cn */,
+ { 0x09a9, 0x09a9} /* Cn */, { 0x09b1, 0x09b1} /* Cn */,
+ { 0x09b3, 0x09b5} /* Cn */, { 0x09ba, 0x09bb} /* Cn */,
+ { 0x09c5, 0x09c6} /* Cn */, { 0x09c9, 0x09ca} /* Cn */,
+ { 0x09ce, 0x09d6} /* Cn */, { 0x09d8, 0x09db} /* Cn */,
+ { 0x09de, 0x09de} /* Cn */, { 0x09e4, 0x09e5} /* Cn */,
+ { 0x09fb, 0x0a00} /* Cn */, { 0x0a04, 0x0a04} /* Cn */,
+ { 0x0a0b, 0x0a0e} /* Cn */, { 0x0a11, 0x0a12} /* Cn */,
+ { 0x0a29, 0x0a29} /* Cn */, { 0x0a31, 0x0a31} /* Cn */,
+ { 0x0a34, 0x0a34} /* Cn */, { 0x0a37, 0x0a37} /* Cn */,
+ { 0x0a3a, 0x0a3b} /* Cn */, { 0x0a3d, 0x0a3d} /* Cn */,
+ { 0x0a43, 0x0a46} /* Cn */, { 0x0a49, 0x0a4a} /* Cn */,
+ { 0x0a4e, 0x0a58} /* Cn */, { 0x0a5d, 0x0a5d} /* Cn */,
+ { 0x0a5f, 0x0a65} /* Cn */, { 0x0a75, 0x0a80} /* Cn */,
+ { 0x0a84, 0x0a84} /* Cn */, { 0x0a8e, 0x0a8e} /* Cn */,
+ { 0x0a92, 0x0a92} /* Cn */, { 0x0aa9, 0x0aa9} /* Cn */,
+ { 0x0ab1, 0x0ab1} /* Cn */, { 0x0ab4, 0x0ab4} /* Cn */,
+ { 0x0aba, 0x0abb} /* Cn */, { 0x0ac6, 0x0ac6} /* Cn */,
+ { 0x0aca, 0x0aca} /* Cn */, { 0x0ace, 0x0acf} /* Cn */,
+ { 0x0ad1, 0x0adf} /* Cn */, { 0x0ae4, 0x0ae5} /* Cn */,
+ { 0x0af0, 0x0af0} /* Cn */, { 0x0af2, 0x0b00} /* Cn */,
+ { 0x0b04, 0x0b04} /* Cn */, { 0x0b0d, 0x0b0e} /* Cn */,
+ { 0x0b11, 0x0b12} /* Cn */, { 0x0b29, 0x0b29} /* Cn */,
+ { 0x0b31, 0x0b31} /* Cn */, { 0x0b34, 0x0b34} /* Cn */,
+ { 0x0b3a, 0x0b3b} /* Cn */, { 0x0b44, 0x0b46} /* Cn */,
+ { 0x0b49, 0x0b4a} /* Cn */, { 0x0b4e, 0x0b55} /* Cn */,
+ { 0x0b58, 0x0b5b} /* Cn */, { 0x0b5e, 0x0b5e} /* Cn */,
+ { 0x0b62, 0x0b65} /* Cn */, { 0x0b72, 0x0b81} /* Cn */,
+ { 0x0b84, 0x0b84} /* Cn */, { 0x0b8b, 0x0b8d} /* Cn */,
+ { 0x0b91, 0x0b91} /* Cn */, { 0x0b96, 0x0b98} /* Cn */,
+ { 0x0b9b, 0x0b9b} /* Cn */, { 0x0b9d, 0x0b9d} /* Cn */,
+ { 0x0ba0, 0x0ba2} /* Cn */, { 0x0ba5, 0x0ba7} /* Cn */,
+ { 0x0bab, 0x0bad} /* Cn */, { 0x0bb6, 0x0bb6} /* Cn */,
+ { 0x0bba, 0x0bbd} /* Cn */, { 0x0bc3, 0x0bc5} /* Cn */,
+ { 0x0bc9, 0x0bc9} /* Cn */, { 0x0bce, 0x0bd6} /* Cn */,
+ { 0x0bd8, 0x0be6} /* Cn */, { 0x0bfb, 0x0c00} /* Cn */,
+ { 0x0c04, 0x0c04} /* Cn */, { 0x0c0d, 0x0c0d} /* Cn */,
+ { 0x0c11, 0x0c11} /* Cn */, { 0x0c29, 0x0c29} /* Cn */,
+ { 0x0c34, 0x0c34} /* Cn */, { 0x0c3a, 0x0c3d} /* Cn */,
+ { 0x0c45, 0x0c45} /* Cn */, { 0x0c49, 0x0c49} /* Cn */,
+ { 0x0c4e, 0x0c54} /* Cn */, { 0x0c57, 0x0c5f} /* Cn */,
+ { 0x0c62, 0x0c65} /* Cn */, { 0x0c70, 0x0c81} /* Cn */,
+ { 0x0c84, 0x0c84} /* Cn */, { 0x0c8d, 0x0c8d} /* Cn */,
+ { 0x0c91, 0x0c91} /* Cn */, { 0x0ca9, 0x0ca9} /* Cn */,
+ { 0x0cb4, 0x0cb4} /* Cn */, { 0x0cba, 0x0cbb} /* Cn */,
+ { 0x0cc5, 0x0cc5} /* Cn */, { 0x0cc9, 0x0cc9} /* Cn */,
+ { 0x0cce, 0x0cd4} /* Cn */, { 0x0cd7, 0x0cdd} /* Cn */,
+ { 0x0cdf, 0x0cdf} /* Cn */, { 0x0ce2, 0x0ce5} /* Cn */,
+ { 0x0cf0, 0x0d01} /* Cn */, { 0x0d04, 0x0d04} /* Cn */,
+ { 0x0d0d, 0x0d0d} /* Cn */, { 0x0d11, 0x0d11} /* Cn */,
+ { 0x0d29, 0x0d29} /* Cn */, { 0x0d3a, 0x0d3d} /* Cn */,
+ { 0x0d44, 0x0d45} /* Cn */, { 0x0d49, 0x0d49} /* Cn */,
+ { 0x0d4e, 0x0d56} /* Cn */, { 0x0d58, 0x0d5f} /* Cn */,
+ { 0x0d62, 0x0d65} /* Cn */, { 0x0d70, 0x0d81} /* Cn */,
+ { 0x0d84, 0x0d84} /* Cn */, { 0x0d97, 0x0d99} /* Cn */,
+ { 0x0db2, 0x0db2} /* Cn */, { 0x0dbc, 0x0dbc} /* Cn */,
+ { 0x0dbe, 0x0dbf} /* Cn */, { 0x0dc7, 0x0dc9} /* Cn */,
+ { 0x0dcb, 0x0dce} /* Cn */, { 0x0dd5, 0x0dd5} /* Cn */,
+ { 0x0dd7, 0x0dd7} /* Cn */, { 0x0de0, 0x0df1} /* Cn */,
+ { 0x0df5, 0x0e00} /* Cn */, { 0x0e3b, 0x0e3e} /* Cn */,
+ { 0x0e5c, 0x0e80} /* Cn */, { 0x0e83, 0x0e83} /* Cn */,
+ { 0x0e85, 0x0e86} /* Cn */, { 0x0e89, 0x0e89} /* Cn */,
+ { 0x0e8b, 0x0e8c} /* Cn */, { 0x0e8e, 0x0e93} /* Cn */,
+ { 0x0e98, 0x0e98} /* Cn */, { 0x0ea0, 0x0ea0} /* Cn */,
+ { 0x0ea4, 0x0ea4} /* Cn */, { 0x0ea6, 0x0ea6} /* Cn */,
+ { 0x0ea8, 0x0ea9} /* Cn */, { 0x0eac, 0x0eac} /* Cn */,
+ { 0x0eba, 0x0eba} /* Cn */, { 0x0ebe, 0x0ebf} /* Cn */,
+ { 0x0ec5, 0x0ec5} /* Cn */, { 0x0ec7, 0x0ec7} /* Cn */,
+ { 0x0ece, 0x0ecf} /* Cn */, { 0x0eda, 0x0edb} /* Cn */,
+ { 0x0ede, 0x0eff} /* Cn */, { 0x0f48, 0x0f48} /* Cn */,
+ { 0x0f6b, 0x0f70} /* Cn */, { 0x0f8c, 0x0f8f} /* Cn */,
+ { 0x0f98, 0x0f98} /* Cn */, { 0x0fbd, 0x0fbd} /* Cn */,
+ { 0x0fcd, 0x0fce} /* Cn */, { 0x0fd0, 0x0fff} /* Cn */,
+ { 0x1022, 0x1022} /* Cn */, { 0x1028, 0x1028} /* Cn */,
+ { 0x102b, 0x102b} /* Cn */, { 0x1033, 0x1035} /* Cn */,
+ { 0x103a, 0x103f} /* Cn */, { 0x105a, 0x109f} /* Cn */,
+ { 0x10c6, 0x10cf} /* Cn */, { 0x10f9, 0x10fa} /* Cn */,
+ { 0x10fc, 0x10ff} /* Cn */, { 0x115a, 0x115e} /* Cn */,
+ { 0x11a3, 0x11a7} /* Cn */, { 0x11fa, 0x11ff} /* Cn */,
+ { 0x1207, 0x1207} /* Cn */, { 0x1247, 0x1247} /* Cn */,
+ { 0x1249, 0x1249} /* Cn */, { 0x124e, 0x124f} /* Cn */,
+ { 0x1257, 0x1257} /* Cn */, { 0x1259, 0x1259} /* Cn */,
+ { 0x125e, 0x125f} /* Cn */, { 0x1287, 0x1287} /* Cn */,
+ { 0x1289, 0x1289} /* Cn */, { 0x128e, 0x128f} /* Cn */,
+ { 0x12af, 0x12af} /* Cn */, { 0x12b1, 0x12b1} /* Cn */,
+ { 0x12b6, 0x12b7} /* Cn */, { 0x12bf, 0x12bf} /* Cn */,
+ { 0x12c1, 0x12c1} /* Cn */, { 0x12c6, 0x12c7} /* Cn */,
+ { 0x12cf, 0x12cf} /* Cn */, { 0x12d7, 0x12d7} /* Cn */,
+ { 0x12ef, 0x12ef} /* Cn */, { 0x130f, 0x130f} /* Cn */,
+ { 0x1311, 0x1311} /* Cn */, { 0x1316, 0x1317} /* Cn */,
+ { 0x131f, 0x131f} /* Cn */, { 0x1347, 0x1347} /* Cn */,
+ { 0x135b, 0x1360} /* Cn */, { 0x137d, 0x139f} /* Cn */,
+ { 0x13f5, 0x1400} /* Cn */, { 0x1677, 0x167f} /* Cn */,
+ { 0x169d, 0x169f} /* Cn */, { 0x16f1, 0x16ff} /* Cn */,
+ { 0x170d, 0x170d} /* Cn */, { 0x1715, 0x171f} /* Cn */,
+ { 0x1737, 0x173f} /* Cn */, { 0x1754, 0x175f} /* Cn */,
+ { 0x176d, 0x176d} /* Cn */, { 0x1771, 0x1771} /* Cn */,
+ { 0x1774, 0x177f} /* Cn */,
+#if 0
+ { 0x17b4, 0x17b5} /* Cf */,
+#endif
+ { 0x17de, 0x17df} /* Cn */, { 0x17ea, 0x17ef} /* Cn */,
+ { 0x17fa, 0x17ff} /* Cn */, { 0x180f, 0x180f} /* Cn */,
+ { 0x181a, 0x181f} /* Cn */, { 0x1878, 0x187f} /* Cn */,
+ { 0x18aa, 0x18ff} /* Cn */, { 0x191d, 0x191f} /* Cn */,
+ { 0x192c, 0x192f} /* Cn */, { 0x193c, 0x193f} /* Cn */,
+ { 0x1941, 0x1943} /* Cn */, { 0x196e, 0x196f} /* Cn */,
+ { 0x1975, 0x19df} /* Cn */, { 0x1a00, 0x1cff} /* Cn */,
+ { 0x1d6c, 0x1dff} /* Cn */, { 0x1e9c, 0x1e9f} /* Cn */,
+ { 0x1efa, 0x1eff} /* Cn */, { 0x1f16, 0x1f17} /* Cn */,
+ { 0x1f1e, 0x1f1f} /* Cn */, { 0x1f46, 0x1f47} /* Cn */,
+ { 0x1f4e, 0x1f4f} /* Cn */, { 0x1f58, 0x1f58} /* Cn */,
+ { 0x1f5a, 0x1f5a} /* Cn */, { 0x1f5c, 0x1f5c} /* Cn */,
+ { 0x1f5e, 0x1f5e} /* Cn */, { 0x1f7e, 0x1f7f} /* Cn */,
+ { 0x1fb5, 0x1fb5} /* Cn */, { 0x1fc5, 0x1fc5} /* Cn */,
+ { 0x1fd4, 0x1fd5} /* Cn */, { 0x1fdc, 0x1fdc} /* Cn */,
+ { 0x1ff0, 0x1ff1} /* Cn */, { 0x1ff5, 0x1ff5} /* Cn */,
+ { 0x1fff, 0x1fff} /* Cn */, { 0x200b, 0x200f} /* Cf */,
+ { 0x2028, 0x2028} /* Zl */,
+ { 0x2029, 0x2029} /* Zp */,
+ { 0x202a, 0x202e} /* Cf */,
+ { 0x2055, 0x2056} /* Cn */, { 0x2058, 0x205e} /* Cn */,
+ { 0x2060, 0x2063} /* Cf */,
+ { 0x2064, 0x2069} /* Cn */,
+ { 0x206a, 0x206f} /* Cf */,
+ { 0x2072, 0x2073} /* Cn */, { 0x208f, 0x209f} /* Cn */,
+ { 0x20b2, 0x20cf} /* Cn */, { 0x20eb, 0x20ff} /* Cn */,
+ { 0x213c, 0x213c} /* Cn */, { 0x214c, 0x2152} /* Cn */,
+ { 0x2184, 0x218f} /* Cn */, { 0x23d1, 0x23ff} /* Cn */,
+ { 0x2427, 0x243f} /* Cn */, { 0x244b, 0x245f} /* Cn */,
+ { 0x2618, 0x2618} /* Cn */, { 0x267e, 0x267f} /* Cn */,
+ { 0x2692, 0x269f} /* Cn */, { 0x26a2, 0x2700} /* Cn */,
+ { 0x2705, 0x2705} /* Cn */, { 0x270a, 0x270b} /* Cn */,
+ { 0x2728, 0x2728} /* Cn */, { 0x274c, 0x274c} /* Cn */,
+ { 0x274e, 0x274e} /* Cn */, { 0x2753, 0x2755} /* Cn */,
+ { 0x2757, 0x2757} /* Cn */, { 0x275f, 0x2760} /* Cn */,
+ { 0x2795, 0x2797} /* Cn */, { 0x27b0, 0x27b0} /* Cn */,
+ { 0x27bf, 0x27cf} /* Cn */, { 0x27ec, 0x27ef} /* Cn */,
+ { 0x2b0e, 0x2e7f} /* Cn */, { 0x2e9a, 0x2e9a} /* Cn */,
+ { 0x2ef4, 0x2eff} /* Cn */, { 0x2fd6, 0x2fef} /* Cn */,
+ { 0x2ffc, 0x2fff} /* Cn */, { 0x3040, 0x3040} /* Cn */,
+ { 0x3097, 0x3098} /* Cn */, { 0x3100, 0x3104} /* Cn */,
+ { 0x312d, 0x3130} /* Cn */, { 0x318f, 0x318f} /* Cn */,
+ { 0x31b8, 0x31ef} /* Cn */, { 0x321f, 0x321f} /* Cn */,
+ { 0x3244, 0x324f} /* Cn */, { 0x327e, 0x327e} /* Cn */,
+ { 0x32ff, 0x32ff} /* Cn */, { 0x4db6, 0x4dbf} /* Cn */,
+ { 0x9fa6, 0x9fff} /* Cn */, { 0xa48d, 0xa48f} /* Cn */,
+ { 0xa4c7, 0xabff} /* Cn */, { 0xd7a4, 0xd7ff} /* Cn */,
+ { 0xd800, 0xdfff} /* Cs */,
+ { 0xe000, 0xf8ff} /* Co */,
+ { 0xfa2e, 0xfa2f} /* Cn */, { 0xfa6b, 0xfaff} /* Cn */,
+ { 0xfb07, 0xfb12} /* Cn */, { 0xfb18, 0xfb1c} /* Cn */,
+ { 0xfb37, 0xfb37} /* Cn */, { 0xfb3d, 0xfb3d} /* Cn */,
+ { 0xfb3f, 0xfb3f} /* Cn */, { 0xfb42, 0xfb42} /* Cn */,
+ { 0xfb45, 0xfb45} /* Cn */, { 0xfbb2, 0xfbd2} /* Cn */,
+ { 0xfd40, 0xfd4f} /* Cn */, { 0xfd90, 0xfd91} /* Cn */,
+ { 0xfdc8, 0xfdef} /* Cn */, { 0xfdfe, 0xfdff} /* Cn */,
+ { 0xfe10, 0xfe1f} /* Cn */, { 0xfe24, 0xfe2f} /* Cn */,
+ { 0xfe53, 0xfe53} /* Cn */, { 0xfe67, 0xfe67} /* Cn */,
+ { 0xfe6c, 0xfe6f} /* Cn */, { 0xfe75, 0xfe75} /* Cn */,
+ { 0xfefd, 0xfefe} /* Cn */,
+ { 0xfeff, 0xfeff} /* Cf */,
+ { 0xff00, 0xff00} /* Cn */, { 0xffbf, 0xffc1} /* Cn */,
+ { 0xffc8, 0xffc9} /* Cn */, { 0xffd0, 0xffd1} /* Cn */,
+ { 0xffd8, 0xffd9} /* Cn */, { 0xffdd, 0xffdf} /* Cn */,
+ { 0xffe7, 0xffe7} /* Cn */, { 0xffef, 0xfff8} /* Cn */,
+ { 0xfff9, 0xfffb} /* Cf */,
+ { 0xfffe, 0xffff} /* Cn */, { 0x1000c, 0x1000c} /* Cn */,
+ { 0x10027, 0x10027} /* Cn */, { 0x1003b, 0x1003b} /* Cn */,
+ { 0x1003e, 0x1003e} /* Cn */, { 0x1004e, 0x1004f} /* Cn */,
+ { 0x1005e, 0x1007f} /* Cn */, { 0x100fb, 0x100ff} /* Cn */,
+ { 0x10103, 0x10106} /* Cn */, { 0x10134, 0x10136} /* Cn */,
+ { 0x10140, 0x102ff} /* Cn */, { 0x1031f, 0x1031f} /* Cn */,
+ { 0x10324, 0x1032f} /* Cn */, { 0x1034b, 0x1037f} /* Cn */,
+ { 0x1039e, 0x1039e} /* Cn */, { 0x103a0, 0x103ff} /* Cn */,
+ { 0x1049e, 0x1049f} /* Cn */, { 0x104aa, 0x107ff} /* Cn */,
+ { 0x10806, 0x10807} /* Cn */, { 0x10809, 0x10809} /* Cn */,
+ { 0x10836, 0x10836} /* Cn */, { 0x10839, 0x1083b} /* Cn */,
+ { 0x1083d, 0x1083e} /* Cn */, { 0x10840, 0x1cfff} /* Cn */,
+ { 0x1d0f6, 0x1d0ff} /* Cn */, { 0x1d127, 0x1d129} /* Cn */,
+ { 0x1d173, 0x1d17a} /* Cf */,
+ { 0x1d1de, 0x1d2ff} /* Cn */, { 0x1d357, 0x1d3ff} /* Cn */,
+ { 0x1d455, 0x1d455} /* Cn */, { 0x1d49d, 0x1d49d} /* Cn */,
+ { 0x1d4a0, 0x1d4a1} /* Cn */, { 0x1d4a3, 0x1d4a4} /* Cn */,
+ { 0x1d4a7, 0x1d4a8} /* Cn */, { 0x1d4ad, 0x1d4ad} /* Cn */,
+ { 0x1d4ba, 0x1d4ba} /* Cn */, { 0x1d4bc, 0x1d4bc} /* Cn */,
+ { 0x1d4c4, 0x1d4c4} /* Cn */, { 0x1d506, 0x1d506} /* Cn */,
+ { 0x1d50b, 0x1d50c} /* Cn */, { 0x1d515, 0x1d515} /* Cn */,
+ { 0x1d51d, 0x1d51d} /* Cn */, { 0x1d53a, 0x1d53a} /* Cn */,
+ { 0x1d53f, 0x1d53f} /* Cn */, { 0x1d545, 0x1d545} /* Cn */,
+ { 0x1d547, 0x1d549} /* Cn */, { 0x1d551, 0x1d551} /* Cn */,
+ { 0x1d6a4, 0x1d6a7} /* Cn */, { 0x1d7ca, 0x1d7cd} /* Cn */,
+ { 0x1d800, 0x1ffff} /* Cn */, { 0x2a6d7, 0x2f7ff} /* Cn */,
+ { 0x2fa1e, 0xe0000} /* Cn */,
+ { 0xe0001, 0xe0001} /* Cf */,
+ { 0xe0002, 0xe001f} /* Cn */,
+ { 0xe0020, 0xe007f} /* Cf */,
+ { 0xe0080, 0xe00ff} /* Cn */, { 0xe01f0, 0xeffff} /* Cn */,
+ { 0xf0000, 0xffffd} /* Co */,
+ { 0xffffe, 0xfffff} /* Cn */,
+ {0x100000,0x10fffd} /* Co */,
+ {0x10fffe,0x10ffff} /* Cn */,
+ {0x110000,0x7fffffff} /* ISO 10646?? */
+};
+
+/*
+ * Double width characters
+ * W: East Asian Wide
+ * F: East Asian Full-width
+ */
+static struct wchar_range wide_table[] = {
+ { 0x1100, 0x115f} /* W */, { 0x2329, 0x232a} /* W */,
+ { 0x2E80, 0x2FFB} /* W */,
+ { 0x3000, 0x3000} /* F */,
+ { 0x3001, 0x303E} /* W */, { 0x3041, 0x4DB5} /* W */,
+ { 0x4E00, 0x9FA5} /* W */, { 0xA000, 0xA4C6} /* W */,
+ { 0xAC00, 0xD7A3} /* W */, { 0xF900, 0xFA6A} /* W */,
+ { 0xFE30, 0xFE6B} /* W */,
+ { 0xFF01, 0xFF60} /* F */, { 0xFFE0, 0xFFE6} /* F */,
+ { 0x20000, 0x2FFFD} /* W */, { 0x30000, 0x3FFFD} /* W */,
+
+};
+
+ static int
+is_in_table(ch, table, tsize)
+ LWCHAR ch;
+ struct wchar_range table[];
+ int tsize;
+{
+ int hi;
+ int lo;
+
+ /* Binary search in the table. */
+ if (ch < table[0].first)
+ return 0;
+ lo = 0;
+ hi = tsize - 1;
+ while (lo <= hi)
+ {
+ int mid = (lo + hi) / 2;
+ if (ch > table[mid].last)
+ lo = mid + 1;
+ else if (ch < table[mid].first)
+ hi = mid - 1;
+ else
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Is a character a UTF-8 composing character?
+ * If a composing character follows any char, the two combine into one glyph.
+ */
+ public int
+is_composing_char(ch)
+ LWCHAR ch;
+{
+ return is_in_table(ch, comp_table, (sizeof(comp_table) / sizeof(*comp_table)));
+}
+
+/*
+ * Should this UTF-8 character be treated as binary?
+ */
+ public int
+is_ubin_char(ch)
+ LWCHAR ch;
+{
+ return is_in_table(ch, ubin_table, (sizeof(ubin_table) / sizeof(*ubin_table)));
+}
+
+/*
+ * Is this a double width UTF-8 character?
+ */
+ public int
+is_wide_char(ch)
+ LWCHAR ch;
+{
+ return is_in_table(ch, wide_table, (sizeof(wide_table) / sizeof(*wide_table)));
+}
+
+/*
+ * Is a character a UTF-8 combining character?
+ * A combining char acts like an ordinary char, but if it follows
+ * a specific char (not any char), the two combine into one glyph.
+ */
+ public int
+is_combining_char(ch1, ch2)
+ LWCHAR ch1;
+ LWCHAR ch2;
+{
+ /* The table is small; use linear search. */
+ int i;
+ for (i = 0; i < sizeof(comb_table)/sizeof(*comb_table); i++)
+ {
+ if (ch1 == comb_table[i].first &&
+ ch2 == comb_table[i].last)
+ return 1;
+ }
+ return 0;
+}
+
diff --git a/contrib/less/charset.h b/contrib/less/charset.h
new file mode 100644
index 000000000000..237a36015cf6
--- /dev/null
+++ b/contrib/less/charset.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2005 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.
+ */
+
+#define IS_ASCII_OCTET(c) (((c) & 0x80) == 0)
+#define IS_UTF8_TRAIL(c) (((c) & 0xC0) == 0x80)
+#define IS_UTF8_LEAD2(c) (((c) & 0xE0) == 0xC0)
+#define IS_UTF8_LEAD3(c) (((c) & 0xF0) == 0xE0)
+#define IS_UTF8_LEAD4(c) (((c) & 0xF8) == 0xF0)
+#define IS_UTF8_LEAD5(c) (((c) & 0xFC) == 0xF8)
+#define IS_UTF8_LEAD6(c) (((c) & 0xFE) == 0xFC)
+#define IS_UTF8_INVALID(c) (((c) & 0xFE) == 0xFE)
+#define IS_UTF8_LEAD(c) (((c) & 0xC0) == 0xC0 && !IS_UTF8_INVALID(c))
diff --git a/contrib/less/cmd.h b/contrib/less/cmd.h
index 8f300dbe0296..8e71f0384a1c 100644
--- a/contrib/less/cmd.h
+++ b/contrib/less/cmd.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/cmdbuf.c b/contrib/less/cmdbuf.c
index dbf5f2afccca..1d3e28414795 100644
--- a/contrib/less/cmdbuf.c
+++ b/contrib/less/cmdbuf.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -16,8 +16,13 @@
#include "less.h"
#include "cmd.h"
+#include "charset.h"
+#if HAVE_STAT
+#include <sys/stat.h>
+#endif
extern int sc_width;
+extern int utf_mode;
static char cmdbuf[CMDBUF_SIZE]; /* Buffer for holding a multi-char command */
static int cmd_col; /* Current column of the cursor */
@@ -48,6 +53,12 @@ public char closequote = '"';
#endif
#if CMD_HISTORY
+
+/* History file */
+#define HISTFILE_FIRST_LINE ".less-history-file:"
+#define HISTFILE_SEARCH_SECTION ".search"
+#define HISTFILE_SHELL_SECTION ".shell"
+
/*
* A mlist structure represents a command history.
*/
@@ -93,6 +104,10 @@ public void * constant ml_shell = (void *)3;
static struct mlist *curr_mlist = NULL;
static int curr_cmdflags;
+static char cmd_mbc_buf[MAX_UTF_CHAR_LEN];
+static int cmd_mbc_buf_len;
+static int cmd_mbc_buf_index;
+
/*
* Reset command buffer (to empty).
@@ -105,6 +120,7 @@ cmd_reset()
cmd_col = 0;
cmd_offset = 0;
literal = 0;
+ cmd_mbc_buf_len = 0;
}
/*
@@ -115,6 +131,7 @@ clear_cmd()
{
clear_bot();
cmd_col = prompt_col = 0;
+ cmd_mbc_buf_len = 0;
}
/*
@@ -124,9 +141,28 @@ clear_cmd()
cmd_putstr(s)
char *s;
{
- putstr(s);
- cmd_col += strlen(s);
- prompt_col += strlen(s);
+ LWCHAR prev_ch = 0;
+ LWCHAR ch;
+ char *endline = s + strlen(s);
+ while (*s != '\0')
+ {
+ char *ns = s;
+ ch = step_char(&ns, +1, endline);
+ while (s < ns)
+ putchr(*s++);
+ if (!utf_mode)
+ {
+ cmd_col++;
+ prompt_col++;
+ } else if (!is_composing_char(ch) &&
+ !is_combining_char(prev_ch, ch))
+ {
+ int width = is_wide_char(ch) ? 2 : 1;
+ cmd_col += width;
+ prompt_col += width;
+ }
+ prev_ch = ch;
+ }
}
/*
@@ -135,7 +171,113 @@ cmd_putstr(s)
public int
len_cmdbuf()
{
- return (strlen(cmdbuf));
+ char *s = cmdbuf;
+ char *endline = s + strlen(s);
+ int len = 0;
+
+ while (*s != '\0')
+ {
+ step_char(&s, +1, endline);
+ len++;
+ }
+ return (len);
+}
+
+/*
+ * Common part of cmd_step_right() and cmd_step_left().
+ */
+ static char *
+cmd_step_common(p, ch, len, pwidth, bswidth)
+ char *p;
+ LWCHAR ch;
+ int len;
+ int *pwidth;
+ int *bswidth;
+{
+ char *pr;
+
+ if (len == 1)
+ {
+ pr = prchar((int) ch);
+ if (pwidth != NULL || bswidth != NULL)
+ {
+ int len = strlen(pr);
+ if (pwidth != NULL)
+ *pwidth = len;
+ if (bswidth != NULL)
+ *bswidth = len;
+ }
+ } else
+ {
+ pr = prutfchar(ch);
+ if (pwidth != NULL || bswidth != NULL)
+ {
+ if (is_composing_char(ch))
+ {
+ if (pwidth != NULL)
+ *pwidth = 0;
+ if (bswidth != NULL)
+ *bswidth = 0;
+ } else if (is_ubin_char(ch))
+ {
+ int len = strlen(pr);
+ if (pwidth != NULL)
+ *pwidth = len;
+ if (bswidth != NULL)
+ *bswidth = len;
+ } else
+ {
+ LWCHAR prev_ch = step_char(&p, -1, cmdbuf);
+ if (is_combining_char(prev_ch, ch))
+ {
+ if (pwidth != NULL)
+ *pwidth = 0;
+ if (bswidth != NULL)
+ *bswidth = 0;
+ } else
+ {
+ if (pwidth != NULL)
+ *pwidth = is_wide_char(ch)
+ ? 2
+ : 1;
+ if (bswidth != NULL)
+ *bswidth = 1;
+ }
+ }
+ }
+ }
+
+ return (pr);
+}
+
+/*
+ * Step a pointer one character right in the command buffer.
+ */
+ static char *
+cmd_step_right(pp, pwidth, bswidth)
+ char **pp;
+ int *pwidth;
+ int *bswidth;
+{
+ char *p = *pp;
+ LWCHAR ch = step_char(pp, +1, p + strlen(p));
+
+ return cmd_step_common(p, ch, *pp - p, pwidth, bswidth);
+}
+
+/*
+ * Step a pointer one character left in the command buffer.
+ */
+ static char *
+cmd_step_left(pp, pwidth, bswidth)
+ char **pp;
+ int *pwidth;
+ int *bswidth;
+{
+ char *p = *pp;
+ LWCHAR ch = step_char(pp, -1, cmdbuf);
+
+ return cmd_step_common(*pp, ch, p - *pp, pwidth, bswidth);
}
/*
@@ -146,19 +288,30 @@ len_cmdbuf()
cmd_repaint(old_cp)
char *old_cp;
{
- char *p;
-
/*
* Repaint the line from the current position.
*/
clear_eol();
- for ( ; *cp != '\0'; cp++)
+ while (*cp != '\0')
+ {
+ char *np = cp;
+ int width;
+ char *pr = cmd_step_right(&np, &width, NULL);
+ if (cmd_col + width >= sc_width)
+ break;
+ cp = np;
+ putstr(pr);
+ cmd_col += width;
+ }
+ while (*cp != '\0')
{
- p = prchar(*cp);
- if (cmd_col + (int)strlen(p) >= sc_width)
+ char *np = cp;
+ int width;
+ char *pr = cmd_step_right(&np, &width, NULL);
+ if (width > 0)
break;
- putstr(p);
- cmd_col += strlen(p);
+ cp = np;
+ putstr(pr);
}
/*
@@ -177,8 +330,12 @@ cmd_home()
{
while (cmd_col > prompt_col)
{
- putbs();
- cmd_col--;
+ int width, bswidth;
+
+ cmd_step_left(&cp, &width, &bswidth);
+ while (bswidth-- > 0)
+ putbs();
+ cmd_col -= width;
}
cp = &cmdbuf[cmd_offset];
@@ -201,7 +358,20 @@ cmd_lshift()
s = cmdbuf + cmd_offset;
cols = 0;
while (cols < (sc_width - prompt_col) / 2 && *s != '\0')
- cols += strlen(prchar(*s++));
+ {
+ int width;
+ cmd_step_right(&s, &width, NULL);
+ cols += width;
+ }
+ while (*s != '\0')
+ {
+ int width;
+ char *ns = s;
+ cmd_step_right(&ns, &width, NULL);
+ if (width > 0)
+ break;
+ s = ns;
+ }
cmd_offset = s - cmdbuf;
save_cp = cp;
@@ -216,7 +386,6 @@ cmd_lshift()
cmd_rshift()
{
char *s;
- char *p;
char *save_cp;
int cols;
@@ -229,8 +398,9 @@ cmd_rshift()
cols = 0;
while (cols < (sc_width - prompt_col) / 2 && s > cmdbuf)
{
- p = prchar(*--s);
- cols += strlen(p);
+ int width;
+ cmd_step_left(&s, &width, NULL);
+ cols += width;
}
cmd_offset = s - cmdbuf;
@@ -245,23 +415,32 @@ cmd_rshift()
static int
cmd_right()
{
- char *p;
+ char *pr;
+ char *ncp;
+ int width;
if (*cp == '\0')
{
- /*
- * Already at the end of the line.
- */
+ /* Already at the end of the line. */
return (CC_OK);
}
- p = prchar(*cp);
- if (cmd_col + (int)strlen(p) >= sc_width)
+ ncp = cp;
+ pr = cmd_step_right(&ncp, &width, NULL);
+ if (cmd_col + width >= sc_width)
cmd_lshift();
- else if (cmd_col + (int)strlen(p) == sc_width - 1 && cp[1] != '\0')
+ else if (cmd_col + width == sc_width - 1 && cp[1] != '\0')
cmd_lshift();
- cp++;
- putstr(p);
- cmd_col += strlen(p);
+ cp = ncp;
+ cmd_col += width;
+ putstr(pr);
+ while (*cp != '\0')
+ {
+ pr = cmd_step_right(&ncp, &width, NULL);
+ if (width > 0)
+ break;
+ putstr(pr);
+ cp = ncp;
+ }
return (CC_OK);
}
@@ -271,19 +450,26 @@ cmd_right()
static int
cmd_left()
{
- char *p;
+ char *ncp;
+ int width, bswidth;
if (cp <= cmdbuf)
{
/* Already at the beginning of the line */
return (CC_OK);
}
- p = prchar(cp[-1]);
- if (cmd_col < prompt_col + (int)strlen(p))
+ ncp = cp;
+ while (ncp > cmdbuf)
+ {
+ cmd_step_left(&ncp, &width, &bswidth);
+ if (width > 0)
+ break;
+ }
+ if (cmd_col < prompt_col + width)
cmd_rshift();
- cp--;
- cmd_col -= strlen(p);
- while (*p++ != '\0')
+ cp = ncp;
+ cmd_col -= width;
+ while (bswidth-- > 0)
putbs();
return (CC_OK);
}
@@ -292,26 +478,29 @@ cmd_left()
* Insert a char into the command buffer, at the current position.
*/
static int
-cmd_ichar(c)
- int c;
+cmd_ichar(cs, clen)
+ char *cs;
+ int clen;
{
char *s;
- if (strlen(cmdbuf) >= sizeof(cmdbuf)-2)
+ if (strlen(cmdbuf) + clen >= sizeof(cmdbuf)-1)
{
- /*
- * No room in the command buffer for another char.
- */
+ /* No room in the command buffer for another char. */
bell();
return (CC_ERROR);
}
/*
- * Insert the character into the buffer.
+ * Make room for the new character (shift the tail of the buffer right).
*/
for (s = &cmdbuf[strlen(cmdbuf)]; s >= cp; s--)
- s[1] = s[0];
- *cp = c;
+ s[clen] = s[0];
+ /*
+ * Insert the character into the buffer.
+ */
+ for (s = cp; s < cp + clen; s++)
+ *s = *cs++;
/*
* Reprint the tail of the line from the inserted char.
*/
@@ -328,6 +517,7 @@ cmd_ichar(c)
cmd_erase()
{
register char *s;
+ int clen;
if (cp == cmdbuf)
{
@@ -340,12 +530,20 @@ cmd_erase()
/*
* Move cursor left (to the char being erased).
*/
+ s = cp;
cmd_left();
+ clen = s - cp;
+
/*
* Remove the char from the buffer (shift the buffer left).
*/
- for (s = cp; *s != '\0'; s++)
- s[0] = s[1];
+ for (s = cp; ; s++)
+ {
+ s[0] = s[clen];
+ if (s[0] == '\0')
+ break;
+ }
+
/*
* Repaint the buffer after the erased char.
*/
@@ -368,9 +566,7 @@ cmd_delete()
{
if (*cp == '\0')
{
- /*
- * At end of string; there is no char under the cursor.
- */
+ /* At end of string; there is no char under the cursor. */
return (CC_OK);
}
/*
@@ -441,9 +637,7 @@ cmd_kill()
{
if (cmdbuf[0] == '\0')
{
- /*
- * Buffer is already empty; abort the current command.
- */
+ /* Buffer is already empty; abort the current command. */
return (CC_QUIT);
}
cmd_offset = 0;
@@ -470,6 +664,10 @@ set_mlist(mlist, cmdflags)
{
curr_mlist = (struct mlist *) mlist;
curr_cmdflags = cmdflags;
+
+ /* Make sure the next up-arrow moves to the last string in the mlist. */
+ if (curr_mlist != NULL)
+ curr_mlist->curr_mp = curr_mlist;
}
#if CMD_HISTORY
@@ -505,12 +703,9 @@ cmd_updown(action)
s = curr_mlist->curr_mp->string;
if (s == NULL)
s = "";
- for (cp = cmdbuf; *s != '\0'; s++)
- {
- *cp = *s;
+ strcpy(cmdbuf, s);
+ for (cp = cmdbuf; *cp != '\0'; )
cmd_right();
- }
- *cp = '\0';
return (CC_OK);
}
#endif
@@ -531,17 +726,13 @@ cmd_addhist(mlist, cmd)
*/
if (strlen(cmd) == 0)
return;
+
/*
- * Don't save if a duplicate of a command which is already
- * in the history.
- * But select the one already in the history to be current.
+ * Save the command unless it's a duplicate of the
+ * last command in the history.
*/
- for (ml = mlist->next; ml != mlist; ml = ml->next)
- {
- if (strcmp(ml->string, cmd) == 0)
- break;
- }
- if (ml == mlist)
+ ml = mlist->prev;
+ if (ml == mlist || strcmp(ml->string, cmd) != 0)
{
/*
* Did not find command in history.
@@ -705,10 +896,13 @@ cmd_istr(str)
{
char *s;
int action;
+ char *endline = str + strlen(str);
- for (s = str; *s != '\0'; s++)
+ for (s = str; *s != '\0'; )
{
- action = cmd_ichar(*s);
+ char *os = s;
+ step_char(&s, +1, endline);
+ action = cmd_ichar(os, s - os);
if (action != CC_OK)
{
bell();
@@ -995,6 +1189,56 @@ cmd_char(c)
int c;
{
int action;
+ int len;
+
+ if (!utf_mode)
+ {
+ cmd_mbc_buf[0] = c;
+ len = 1;
+ } else
+ {
+ /* Perform strict validation in all possible cases. */
+ if (cmd_mbc_buf_len == 0)
+ {
+ retry:
+ cmd_mbc_buf_index = 1;
+ *cmd_mbc_buf = c;
+ if (IS_ASCII_OCTET(c))
+ cmd_mbc_buf_len = 1;
+ else if (IS_UTF8_LEAD(c))
+ {
+ cmd_mbc_buf_len = utf_len(c);
+ return (CC_OK);
+ } else
+ {
+ /* UTF8_INVALID or stray UTF8_TRAIL */
+ bell();
+ return (CC_ERROR);
+ }
+ } else if (IS_UTF8_TRAIL(c))
+ {
+ cmd_mbc_buf[cmd_mbc_buf_index++] = c;
+ if (cmd_mbc_buf_index < cmd_mbc_buf_len)
+ return (CC_OK);
+ if (!is_utf8_well_formed(cmd_mbc_buf))
+ {
+ /* complete, but not well formed (non-shortest form), sequence */
+ cmd_mbc_buf_len = 0;
+ bell();
+ return (CC_ERROR);
+ }
+ } else
+ {
+ /* Flush incomplete (truncated) sequence. */
+ cmd_mbc_buf_len = 0;
+ bell();
+ /* Handle new char. */
+ goto retry;
+ }
+
+ len = cmd_mbc_buf_len;
+ cmd_mbc_buf_len = 0;
+ }
if (literal)
{
@@ -1002,13 +1246,13 @@ cmd_char(c)
* Insert the char, even if it is a line-editing char.
*/
literal = 0;
- return (cmd_ichar(c));
+ return (cmd_ichar(cmd_mbc_buf, len));
}
/*
- * See if it is a special line-editing character.
+ * See if it is a line-editing character.
*/
- if (in_mca())
+ if (in_mca() && len == 1)
{
action = cmd_edit(c);
switch (action)
@@ -1024,7 +1268,7 @@ cmd_char(c)
/*
* Insert the char into the command buffer.
*/
- return (cmd_ichar(c));
+ return (cmd_ichar(cmd_mbc_buf, len));
}
/*
@@ -1049,3 +1293,160 @@ get_cmdbuf()
{
return (cmdbuf);
}
+
+#if CMD_HISTORY
+/*
+ * Get the name of the history file.
+ */
+ static char *
+histfile_name()
+{
+ char *home;
+ char *name;
+ int len;
+
+ /* See if filename is explicitly specified by $LESSHISTFILE. */
+ name = lgetenv("LESSHISTFILE");
+ if (name != NULL && *name != '\0')
+ {
+ if (strcmp(name, "-") == 0)
+ /* $LESSHISTFILE == "-" means don't use a history file. */
+ return (NULL);
+ return (save(name));
+ }
+
+ /* Otherwise, file is in $HOME. */
+ home = lgetenv("HOME");
+ if (home == NULL || *home == '\0')
+ {
+#if OS2
+ home = lgetenv("INIT");
+ if (home == NULL || *home == '\0')
+#endif
+ return (NULL);
+ }
+ len = strlen(home) + strlen(LESSHISTFILE) + 2;
+ name = (char *) ecalloc(len, sizeof(char));
+ SNPRINTF2(name, len, "%s/%s", home, LESSHISTFILE);
+ return (name);
+}
+#endif /* CMD_HISTORY */
+
+/*
+ * Initialize history from a .lesshist file.
+ */
+ public void
+init_cmdhist()
+{
+#if CMD_HISTORY
+ struct mlist *ml = NULL;
+ char line[CMDBUF_SIZE];
+ char *filename;
+ FILE *f;
+ char *p;
+
+ filename = histfile_name();
+ if (filename == NULL)
+ return;
+ f = fopen(filename, "r");
+ free(filename);
+ if (f == NULL)
+ return;
+ if (fgets(line, sizeof(line), f) == NULL ||
+ strncmp(line, HISTFILE_FIRST_LINE, strlen(HISTFILE_FIRST_LINE)) != 0)
+ {
+ fclose(f);
+ return;
+ }
+ while (fgets(line, sizeof(line), f) != NULL)
+ {
+ for (p = line; *p != '\0'; p++)
+ {
+ if (*p == '\n' || *p == '\r')
+ {
+ *p = '\0';
+ break;
+ }
+ }
+ if (strcmp(line, HISTFILE_SEARCH_SECTION) == 0)
+ ml = &mlist_search;
+#if SHELL_ESCAPE || PIPEC
+ else if (strcmp(line, HISTFILE_SHELL_SECTION) == 0)
+ ml = &mlist_shell;
+#endif
+ else if (*line == '"')
+ {
+ if (ml != NULL)
+ cmd_addhist(ml, line+1);
+ }
+ }
+ fclose(f);
+#endif /* CMD_HISTORY */
+}
+
+/*
+ *
+ */
+#if CMD_HISTORY
+ static void
+save_mlist(ml, f)
+ struct mlist *ml;
+ FILE *f;
+{
+ int histsize = 0;
+ int n;
+ char *s;
+
+ s = lgetenv("LESSHISTSIZE");
+ if (s != NULL)
+ histsize = atoi(s);
+ if (histsize == 0)
+ histsize = 100;
+
+ ml = ml->prev;
+ for (n = 0; n < histsize; n++)
+ {
+ if (ml->string == NULL)
+ break;
+ ml = ml->prev;
+ }
+ for (ml = ml->next; ml->string != NULL; ml = ml->next)
+ fprintf(f, "\"%s\n", ml->string);
+}
+#endif /* CMD_HISTORY */
+
+/*
+ *
+ */
+ public void
+save_cmdhist()
+{
+#if CMD_HISTORY
+ char *filename;
+ FILE *f;
+
+ filename = histfile_name();
+ if (filename == NULL)
+ return;
+ f = fopen(filename, "w");
+ free(filename);
+ if (f == NULL)
+ return;
+#if HAVE_FCHMOD
+ /* Make history file readable only by owner. */
+ fchmod(fileno(f), 0600);
+#endif
+
+ fprintf(f, "%s\n", HISTFILE_FIRST_LINE);
+
+ fprintf(f, "%s\n", HISTFILE_SEARCH_SECTION);
+ save_mlist(&mlist_search, f);
+
+#if SHELL_ESCAPE || PIPEC
+ fprintf(f, "%s\n", HISTFILE_SHELL_SECTION);
+ save_mlist(&mlist_shell, f);
+#endif
+
+ fclose(f);
+#endif /* CMD_HISTORY */
+}
diff --git a/contrib/less/command.c b/contrib/less/command.c
index 9b059eceb876..7c0d60b119cf 100644
--- a/contrib/less/command.c
+++ b/contrib/less/command.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -21,7 +21,7 @@
#include "option.h"
#include "cmd.h"
-extern int erase_char, kill_char;
+extern int erase_char, erase2_char, kill_char;
extern int sigs;
extern int quit_at_eof;
extern int quit_if_one_screen;
@@ -67,6 +67,7 @@ static char optchar;
static int optflag;
static int optgetname;
static POSITION bottompos;
+static int save_hshift;
#if PIPEC
static char pipec;
#endif
@@ -392,7 +393,9 @@ mca_char(c)
* Already have a match for the name.
* Don't accept anything but erase/kill.
*/
- if (c == erase_char || c == kill_char)
+ if (c == erase_char ||
+ c == erase2_char ||
+ c == kill_char)
return (MCA_DONE);
return (MCA_MORE);
}
@@ -403,7 +406,7 @@ mca_char(c)
if (cmd_char(c) == CC_QUIT)
return (MCA_DONE);
p = get_cmdbuf();
- lc = islower(p[0]);
+ lc = ASCII_IS_LOWER(p[0]);
o = findopt_name(&p, &oname, NULL);
if (o != NULL)
{
@@ -413,15 +416,15 @@ mca_char(c)
* display the full option name.
*/
optchar = o->oletter;
- if (!lc && islower(optchar))
- optchar = toupper(optchar);
+ if (!lc && ASCII_IS_LOWER(optchar))
+ optchar = ASCII_TO_UPPER(optchar);
cmd_reset();
mca_opt_toggle();
for (p = oname; *p != '\0'; p++)
{
c = *p;
- if (!lc && islower(c))
- c = toupper(c);
+ if (!lc && ASCII_IS_LOWER(c))
+ c = ASCII_TO_UPPER(c);
if (cmd_char(c) != CC_OK)
return (MCA_DONE);
}
@@ -430,7 +433,7 @@ mca_char(c)
}
} else
{
- if (c == erase_char || c == kill_char)
+ if (c == erase_char || c == erase2_char || c == kill_char)
break;
if (optchar != '\0')
/* We already have the option letter. */
@@ -598,7 +601,10 @@ prompt()
bottompos = position(BOTTOM_PLUS_ONE);
/*
- * If the -E flag is set and we've hit EOF on the last file, quit.
+ * If we've hit EOF on the last file, and the -E flag is set
+ * (or -F is set and this is the first prompt), then quit.
+ * {{ Relying on "first prompt" to detect a single-screen file
+ * fails if +G is used, for example. }}
*/
if ((quit_at_eof == OPT_ONPLUS || quit_if_one_screen) &&
hit_eof && !(ch_getflags() & CH_HELPFILE) &&
@@ -627,13 +633,13 @@ prompt()
*/
clear_cmd();
p = pr_string();
- if (p == NULL)
+ if (p == NULL || *p == '\0')
putchr(':');
else
{
- so_enter();
+ at_enter(AT_STANDOUT);
putstr(p);
- so_exit();
+ at_exit();
}
}
@@ -826,6 +832,9 @@ multi_search(pattern, n)
* Restore the file we were originally viewing.
*/
reedit_ifile(save_ifile);
+ } else
+ {
+ unsave_ifile(save_ifile);
}
}
@@ -1211,6 +1220,7 @@ commands()
* just means return to viewing the
* previous file.
*/
+ hshift = save_hshift;
if (edit_prev(1) == 0)
break;
}
@@ -1300,6 +1310,8 @@ commands()
if (ch_getflags() & CH_HELPFILE)
break;
cmd_exec();
+ save_hshift = hshift;
+ hshift = 0;
(void) edit(FAKE_HELPFILE);
break;
@@ -1340,9 +1352,8 @@ commands()
}
if (curr_altfilename != NULL)
{
- error("Cannot edit file processed with LESSOPEN",
+ error("WARNING: This file was viewed via LESSOPEN",
NULL_PARG);
- break;
}
start_mca(A_SHELL, "!", ml_shell, 0);
/*
@@ -1524,8 +1535,8 @@ commands()
break;
start_mca(A_SETMARK, "mark: ", (void*)NULL, 0);
c = getcc();
- if (c == erase_char || c == kill_char ||
- c == '\n' || c == '\r')
+ if (c == erase_char || c == erase2_char ||
+ c == kill_char || c == '\n' || c == '\r')
break;
setmark(c);
break;
@@ -1536,8 +1547,8 @@ commands()
*/
start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
c = getcc();
- if (c == erase_char || c == kill_char ||
- c == '\n' || c == '\r')
+ if (c == erase_char || c == erase2_char ||
+ c == kill_char || c == '\n' || c == '\r')
break;
gomark(c);
break;
@@ -1551,7 +1562,7 @@ commands()
}
start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
c = getcc();
- if (c == erase_char || c == kill_char)
+ if (c == erase_char || c == erase2_char || c == kill_char)
break;
if (c == '\n' || c == '\r')
c = '.';
diff --git a/contrib/less/configure b/contrib/less/configure
index 6264a36eb75e..b2f05b6bb6b5 100755
--- a/contrib/less/configure
+++ b/contrib/less/configure
@@ -843,6 +843,7 @@ Optional Features:
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
+ --with-secure Compile in secure mode
--with-regex={auto,pcre,posix,regcmp,re_comp,regcomp,regcomp-local} Select a regular expression library auto
--with-editor=PROGRAM use PROGRAM as the default editor vi
@@ -2860,6 +2861,61 @@ else
have_xcurses=no
fi
+echo "$as_me:$LINENO: checking for initscr in -lncursesw" >&5
+echo $ECHO_N "checking for initscr in -lncursesw... $ECHO_C" >&6
+if test "${ac_cv_lib_ncursesw_initscr+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lncursesw $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char initscr ();
+int
+main ()
+{
+initscr ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_lib_ncursesw_initscr=yes
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+ac_cv_lib_ncursesw_initscr=no
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_ncursesw_initscr" >&5
+echo "${ECHO_T}$ac_cv_lib_ncursesw_initscr" >&6
+if test $ac_cv_lib_ncursesw_initscr = yes; then
+ have_ncursesw=yes
+else
+ have_ncursesw=no
+fi
+
echo "$as_me:$LINENO: checking for initscr in -lncurses" >&5
echo $ECHO_N "checking for initscr in -lncurses... $ECHO_C" >&6
if test "${ac_cv_lib_ncurses_initscr+set}" = set; then
@@ -3319,6 +3375,47 @@ rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
fi
fi
+if test "x$TERMLIBS" = x; then
+ if test $have_ncursesw = yes; then
+ TERMLIBS="-lncursesw"
+ SAVE_LIBS=$LIBS
+ LIBS="$LIBS $TERMLIBS"
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+int
+main ()
+{
+tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ termok=yes
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+termok=no
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+ LIBS=$SAVE_LIBS
+ if test $termok = no; then TERMLIBS=""; fi
+ fi
+fi
+
# -- Try ncurses.
if test "x$TERMLIBS" = x; then
if test $have_ncurses = yes; then
@@ -4222,6 +4319,8 @@ fi
+
+
# Checks for identifiers.
echo "$as_me:$LINENO: checking for off_t" >&5
echo $ECHO_N "checking for off_t... $ECHO_C" >&6
@@ -4456,7 +4555,9 @@ _ACEOF
-for ac_func in fsync memcpy popen _setjmp sigprocmask sigsetmask stat strchr strstr system
+
+
+for ac_func in fsync memcpy popen _setjmp sigprocmask sigsetmask snprintf stat strchr strstr system fchmod
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -5057,12 +5158,29 @@ fi
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
fi
+# Compile in secure mode?
+
+# Check whether --with-secure or --without-secure was given.
+if test "${with_secure+set}" = set; then
+ withval="$with_secure"
+ cat >>confdefs.h <<\_ACEOF
+#define SECURE_COMPILE 1
+_ACEOF
+
+else
+ cat >>confdefs.h <<\_ACEOF
+#define SECURE_COMPILE 0
+_ACEOF
+
+fi;
+
# Checks for regular expression functions.
have_regex=no
have_posix_regex=unknown
echo "$as_me:$LINENO: checking for regcomp" >&5
echo $ECHO_N "checking for regcomp... $ECHO_C" >&6
+# Select a regular expression library.
WANT_REGEX=auto
# Check whether --with-regex or --without-regex was given.
diff --git a/contrib/less/configure.ac b/contrib/less/configure.ac
index d9e6ccab6ec5..7ca55c694cae 100644
--- a/contrib/less/configure.ac
+++ b/contrib/less/configure.ac
@@ -1,6 +1,6 @@
# Process this file with autoconf to produce a configure script.
-# Copyright (C) 1984-2002 Mark Nudelman
+# Copyright (C) 1984-2004 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.
@@ -24,6 +24,7 @@ AC_SYS_LARGEFILE
# Checks for general libraries.
AC_CHECK_LIB(xcurses, initscr, [have_xcurses=yes], [have_xcurses=no])
+AC_CHECK_LIB(ncursesw, initscr, [have_ncursesw=yes], [have_ncursesw=no])
AC_CHECK_LIB(ncurses, initscr, [have_ncurses=yes], [have_ncurses=no])
AC_CHECK_LIB(curses, initscr, [have_curses=yes], [have_curses=no])
AC_CHECK_LIB(termcap, tgetent, [have_termcap=yes], [have_termcap=no])
@@ -63,6 +64,19 @@ if test "x$TERMLIBS" = x; then
fi
fi
+dnl -- Try ncursesw.
+if test "x$TERMLIBS" = x; then
+ if test $have_ncursesw = yes; then
+ TERMLIBS="-lncursesw"
+ SAVE_LIBS=$LIBS
+ LIBS="$LIBS $TERMLIBS"
+ AC_TRY_LINK(, [tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);],
+ [termok=yes], [termok=no])
+ LIBS=$SAVE_LIBS
+ if test $termok = no; then TERMLIBS=""; fi
+ fi
+fi
+
# -- Try ncurses.
if test "x$TERMLIBS" = x; then
if test $have_ncurses = yes; then
@@ -196,6 +210,8 @@ AH_TEMPLATE([HAVE_SIGEMPTYSET],
[Define HAVE_SIGEMPTYSET if you have the sigemptyset macro.])
AH_TEMPLATE([EDIT_PGM],
[Define EDIT_PGM to your editor.])
+AH_TEMPLATE([SECURE_COMPILE],
+ [Define SECURE_COMPILE=1 to build a secure version of less.])
# Checks for identifiers.
AC_TYPE_OFF_T
@@ -211,7 +227,7 @@ AC_TRY_COMPILE([#include <time.h>], [time_t t = 0;],
# Checks for library functions.
AC_TYPE_SIGNAL
-AC_CHECK_FUNCS([fsync memcpy popen _setjmp sigprocmask sigsetmask stat strchr strstr system])
+AC_CHECK_FUNCS([fsync memcpy popen _setjmp sigprocmask sigsetmask snprintf stat strchr strstr system fchmod])
# Some systems have termios.h but not the corresponding functions.
AC_CHECK_FUNC(tcgetattr, AC_DEFINE(HAVE_TERMIOS_FUNCS))
@@ -297,11 +313,17 @@ AC_TRY_LINK(, [extern short ospeed; ospeed = 0;],
[AC_MSG_RESULT(no)])
fi
+# Compile in secure mode?
+AC_ARG_WITH(secure,
+ [ --with-secure Compile in secure mode],
+ AC_DEFINE(SECURE_COMPILE, 1), AC_DEFINE(SECURE_COMPILE, 0))
+
# Checks for regular expression functions.
have_regex=no
have_posix_regex=unknown
AC_MSG_CHECKING(for regcomp)
+# Select a regular expression library.
WANT_REGEX=auto
AC_ARG_WITH(regex,
[ --with-regex={auto,pcre,posix,regcmp,re_comp,regcomp,regcomp-local} Select a regular expression library [auto]],
@@ -401,8 +423,9 @@ AH_TOP([
/*
* SECURE is 1 if you wish to disable a bunch of features in order to
* be safe to run by unprivileged users.
+ * SECURE_COMPILE is set by the --with-secure configure option.
*/
-#define SECURE 0
+#define SECURE SECURE_COMPILE
/*
* SHELL_ESCAPE is 1 if you wish to allow shell escapes.
@@ -488,10 +511,13 @@ AH_TOP([
* LESSKEYFILE_SYS is the filename of the system-wide lesskey output file.
* DEF_LESSKEYINFILE is the filename of the default lesskey input
* (in the HOME directory).
+ * LESSHISTFILE is the filename of the history file
+ * (in the HOME directory).
*/
#define LESSKEYFILE ".less"
#define LESSKEYFILE_SYS SYSDIR "/sysless"
#define DEF_LESSKEYINFILE ".lesskey"
+#define LESSHISTFILE ".lesshst"
/* Settings always true on Unix. */
@@ -535,7 +561,7 @@ AH_TOP([
/*
* Default shell metacharacters and meta-escape character.
*/
-#define DEF_METACHARS "; *?\t\n'\"()<>|&^`#\\"
+#define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\"
#define DEF_METAESCAPE "\\"
/*
diff --git a/contrib/less/decode.c b/contrib/less/decode.c
index 1737327855fd..fd63e5ac353e 100644
--- a/contrib/less/decode.c
+++ b/contrib/less/decode.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -34,7 +34,7 @@
#include "cmd.h"
#include "lesskey.h"
-extern int erase_char, kill_char;
+extern int erase_char, erase2_char, kill_char;
extern int secure;
#define SK(k) \
@@ -754,7 +754,7 @@ editchar(c, flags)
* but give it the edit-commands command table
* This table is constructed to match the user's keyboard.
*/
- if (c == erase_char)
+ if (c == erase_char || c == erase2_char)
return (EC_BACKSPACE);
if (c == kill_char)
return (EC_LINEKILL);
diff --git a/contrib/less/defines.ds b/contrib/less/defines.ds
index 9445398328ab..596f2cdc5af3 100644
--- a/contrib/less/defines.ds
+++ b/contrib/less/defines.ds
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2000 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -117,10 +117,13 @@
* LESSKEYFILE_SYS is the filename of the system-wide lesskey output file.
* DEF_LESSKEYINFILE is the filename of the default lesskey input
* (in the HOME directory).
+ * LESSHISTFILE is the filename of the history file
+ * (in the HOME directory).
*/
#define LESSKEYFILE "_less"
#define LESSKEYFILE_SYS "c:\\_sysless"
#define DEF_LESSKEYINFILE "_lesskey"
+#define LESSHISTFILE "_lesshst"
/* Settings always true for MS-DOS systems. */
@@ -304,6 +307,9 @@
/* Define if you have the system function. */
#define HAVE_SYSTEM 1
+/* Define if you have the snprintf function. */
+#define HAVE_SNPRINTF 0
+
/* Define if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
diff --git a/contrib/less/defines.h.in b/contrib/less/defines.h.in
index 387e00f49f13..be5aa14e0f45 100644
--- a/contrib/less/defines.h.in
+++ b/contrib/less/defines.h.in
@@ -18,8 +18,9 @@
/*
* SECURE is 1 if you wish to disable a bunch of features in order to
* be safe to run by unprivileged users.
+ * SECURE_COMPILE is set by the --with-secure configure option.
*/
-#define SECURE 0
+#define SECURE SECURE_COMPILE
/*
* SHELL_ESCAPE is 1 if you wish to allow shell escapes.
@@ -105,10 +106,13 @@
* LESSKEYFILE_SYS is the filename of the system-wide lesskey output file.
* DEF_LESSKEYINFILE is the filename of the default lesskey input
* (in the HOME directory).
+ * LESSHISTFILE is the filename of the history file
+ * (in the HOME directory).
*/
#define LESSKEYFILE ".less"
#define LESSKEYFILE_SYS SYSDIR "/sysless"
#define DEF_LESSKEYINFILE ".lesskey"
+#define LESSHISTFILE ".lesshst"
/* Settings always true on Unix. */
@@ -152,7 +156,7 @@
/*
* Default shell metacharacters and meta-escape character.
*/
-#define DEF_METACHARS "; *?\t\n'\"()<>|&^`#\\"
+#define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\"
#define DEF_METAESCAPE "\\"
/*
@@ -191,6 +195,9 @@
/* Define to 1 if you have the <errno.h> header file. */
#undef HAVE_ERRNO_H
+/* Define to 1 if you have the `fchmod' function. */
+#undef HAVE_FCHMOD
+
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
@@ -257,6 +264,9 @@
/* Define HAVE_SIGSET_T you have the sigset_t type. */
#undef HAVE_SIGSET_T
+/* Define to 1 if you have the `snprintf' function. */
+#undef HAVE_SNPRINTF
+
/* Define to 1 if you have the `stat' function. */
#undef HAVE_STAT
@@ -370,6 +380,9 @@
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE
+/* Define SECURE_COMPILE=1 to build a secure version of less. */
+#undef SECURE_COMPILE
+
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
#undef STAT_MACROS_BROKEN
diff --git a/contrib/less/defines.o2 b/contrib/less/defines.o2
index ee1313b6cbd4..77aba44ac58d 100644
--- a/contrib/less/defines.o2
+++ b/contrib/less/defines.o2
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2000 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -110,10 +110,13 @@
* LESSKEYFILE_SYS is the filename of the system-wide lesskey output file.
* DEF_LESSKEYINFILE is the filename of the default lesskey input
* (in the HOME directory).
+ * LESSHISTFILE is the filename of the history file
+ * (in the HOME directory).
*/
#define LESSKEYFILE "less.ini"
#define LESSKEYFILE_SYS "C:\\sysless.ini"
#define DEF_LESSKEYINFILE "lesskey.ini"
+#define LESSHISTFILE "lesshst.ini"
/* Settings always true for the emx compiler for OS/2 systems. */
@@ -270,6 +273,9 @@
/* Define if you have the system function. */
#define HAVE_SYSTEM 1
+/* Define if you have the snprintf function. */
+#define HAVE_SNPRINTF 0
+
/* Define if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
diff --git a/contrib/less/defines.o9 b/contrib/less/defines.o9
index 553a005e4e65..ad20f52ef7b6 100644
--- a/contrib/less/defines.o9
+++ b/contrib/less/defines.o9
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2000 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -109,10 +109,13 @@
* LESSKEYFILE_SYS is the filename of the system-wide lesskey output file.
* DEF_LESSKEYINFILE is the filename of the default lesskey input
* (in the HOME directory).
+ * LESSHISTFILE is the filename of the history file
+ * (in the HOME directory).
*/
#define LESSKEYFILE ".less"
#define LESSKEYFILE_SYS "/.sysless"
#define DEF_LESSKEYINFILE ".lesskey"
+#define LESSHISTFILE ".lesshst"
/* Settings always true for OS-9. */
@@ -278,6 +281,9 @@
/* Define if you have the system function. */
#define HAVE_SYSTEM 1
+/* Define if you have the snprintf function. */
+#define HAVE_SNPRINTF 0
+
/* Define if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
diff --git a/contrib/less/defines.wn b/contrib/less/defines.wn
index 737af5de0784..24f5205f380b 100644
--- a/contrib/less/defines.wn
+++ b/contrib/less/defines.wn
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2000 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -110,10 +110,13 @@
* LESSKEYFILE_SYS is the filename of the system-wide lesskey output file.
* DEF_LESSKEYINFILE is the filename of the default lesskey input
* (in the HOME directory).
+ * LESSHISTFILE is the filename of the history file
+ * (in the HOME directory).
*/
#define LESSKEYFILE "_less"
#define LESSKEYFILE_SYS "c:\\_sysless"
#define DEF_LESSKEYINFILE "_lesskey"
+#define LESSHISTFILE "_lesshst"
/* Settings always true for Windows systems. */
@@ -268,6 +271,9 @@
/* Define if you have the system function. */
#define HAVE_SYSTEM 1
+/* Define if you have the snprintf function. */
+#define HAVE_SNPRINTF 0
+
/* Define if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
diff --git a/contrib/less/edit.c b/contrib/less/edit.c
index 4873c1f212d2..3d8ec9dfad44 100644
--- a/contrib/less/edit.c
+++ b/contrib/less/edit.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -322,6 +322,14 @@ edit_ifile(ifile)
/*
* Re-open the current file.
*/
+ if (was_curr_ifile == ifile)
+ {
+ /*
+ * Whoops. The "current" ifile is the one we just deleted.
+ * Just give up.
+ */
+ quit(QUIT_ERROR);
+ }
reedit_ifile(was_curr_ifile);
return (1);
} else if ((f = open(qopen_filename, OPEN_READ)) < 0)
@@ -498,7 +506,7 @@ edit_last()
/*
- * Edit the next or previous file in the command line (ifile) list.
+ * Edit the n-th next or previous file in the command line (ifile) list.
*/
static int
edit_istep(h, n, dir)
@@ -547,14 +555,14 @@ edit_inext(h, n)
IFILE h;
int n;
{
- return (edit_istep(h, n, 1));
+ return (edit_istep(h, n, +1));
}
public int
edit_next(n)
int n;
{
- return edit_istep(curr_ifile, n, 1);
+ return edit_istep(curr_ifile, n, +1);
}
static int
diff --git a/contrib/less/filename.c b/contrib/less/filename.c
index 0b56bdc13d54..8b1c4c99421c 100644
--- a/contrib/less/filename.c
+++ b/contrib/less/filename.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -195,7 +195,7 @@ shell_quote(s)
newstr = p = (char *) ecalloc(len, sizeof(char));
if (use_quotes)
{
- sprintf(newstr, "%c%s%c", openquote, s, closequote);
+ SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote);
} else
{
while (*s != '\0')
@@ -226,6 +226,7 @@ dirfile(dirname, filename)
{
char *pathname;
char *qpathname;
+ int len;
int f;
if (dirname == NULL || *dirname == '\0')
@@ -233,11 +234,11 @@ dirfile(dirname, filename)
/*
* Construct the full pathname.
*/
- pathname = (char *) calloc(strlen(dirname) + strlen(filename) + 2,
- sizeof(char));
+ len= strlen(dirname) + strlen(filename) + 2;
+ pathname = (char *) calloc(len, sizeof(char));
if (pathname == NULL)
return (NULL);
- sprintf(pathname, "%s%s%s", dirname, PATHNAME_SEP, filename);
+ SNPRINTF3(pathname, len, "%s%s%s", dirname, PATHNAME_SEP, filename);
/*
* Make sure the file exists.
*/
@@ -425,18 +426,23 @@ fcomplete(s)
*/
{
char *slash;
+ int len;
for (slash = s+strlen(s)-1; slash > s; slash--)
if (*slash == *PATHNAME_SEP || *slash == '/')
break;
- fpat = (char *) ecalloc(strlen(s)+4, sizeof(char));
+ len = strlen(s) + 4;
+ fpat = (char *) ecalloc(len, sizeof(char));
if (strchr(slash, '.') == NULL)
- sprintf(fpat, "%s*.*", s);
+ SNPRINTF1(fpat, len, "%s*.*", s);
else
- sprintf(fpat, "%s*", s);
+ SNPRINTF1(fpat, len, "%s*", s);
}
#else
- fpat = (char *) ecalloc(strlen(s)+2, sizeof(char));
- sprintf(fpat, "%s*", s);
+ {
+ int len = strlen(s) + 2;
+ fpat = (char *) ecalloc(len, sizeof(char));
+ SNPRINTF1(fpat, len, "%s*", s);
+ }
#endif
qs = lglob(fpat);
s = shell_unquote(qs);
@@ -570,9 +576,9 @@ shellcmd(cmd)
fd = popen(cmd, "r");
} else
{
- scmd = (char *) ecalloc(strlen(shell) + strlen(esccmd) + 5,
- sizeof(char));
- sprintf(scmd, "%s %s %s", shell, shell_coption(), esccmd);
+ int len = strlen(shell) + strlen(esccmd) + 5;
+ scmd = (char *) ecalloc(len, sizeof(char));
+ SNPRINTF3(scmd, len, "%s %s %s", shell, shell_coption(), esccmd);
free(esccmd);
fd = popen(scmd, "r");
free(scmd);
@@ -680,7 +686,7 @@ lglob(filename)
do {
n = strlen(drive) + strlen(dir) + strlen(fnd.GLOB_NAME) + 1;
pathname = (char *) ecalloc(n, sizeof(char));
- sprintf(pathname, "%s%s%s", drive, dir, fnd.GLOB_NAME);
+ SNPRINTF3(pathname, n, "%s%s%s", drive, dir, fnd.GLOB_NAME);
qpathname = shell_quote(pathname);
free(pathname);
if (qpathname != NULL)
@@ -725,6 +731,7 @@ lglob(filename)
char *lessecho;
char *cmd;
char *esc;
+ int len;
esc = get_meta_escape();
if (strlen(esc) == 0)
@@ -741,8 +748,9 @@ lglob(filename)
/*
* Invoke lessecho, and read its output (a globbed list of filenames).
*/
- cmd = (char *) ecalloc(strlen(lessecho) + strlen(ofilename) + (7*strlen(metachars())) + 24, sizeof(char));
- sprintf(cmd, "%s -p0x%x -d0x%x -e%s ", lessecho, openquote, closequote, esc);
+ len = strlen(lessecho) + strlen(ofilename) + (7*strlen(metachars())) + 24;
+ cmd = (char *) ecalloc(len, sizeof(char));
+ SNPRINTF4(cmd, len, "%s -p0x%x -d0x%x -e%s ", lessecho, openquote, closequote, esc);
free(esc);
for (s = metachars(); *s != '\0'; s++)
sprintf(cmd + strlen(cmd), "-n0x%x ", *s);
@@ -795,6 +803,7 @@ open_altfile(filename, pf, pfd)
#else
char *lessopen;
char *cmd;
+ int len;
FILE *fd;
#if HAVE_FILENO
int returnfd = 0;
@@ -822,9 +831,9 @@ open_altfile(filename, pf, pfd)
#endif
}
- cmd = (char *) ecalloc(strlen(lessopen) + strlen(filename) + 2,
- sizeof(char));
- sprintf(cmd, lessopen, filename);
+ len = strlen(lessopen) + strlen(filename) + 2;
+ cmd = (char *) ecalloc(len, sizeof(char));
+ SNPRINTF1(cmd, len, lessopen, filename);
fd = shellcmd(cmd);
free(cmd);
if (fd == NULL)
@@ -884,6 +893,7 @@ close_altfile(altfilename, filename, pipefd)
char *lessclose;
FILE *fd;
char *cmd;
+ int len;
if (secure)
return;
@@ -900,9 +910,9 @@ close_altfile(altfilename, filename, pipefd)
}
if ((lessclose = lgetenv("LESSCLOSE")) == NULL)
return;
- cmd = (char *) ecalloc(strlen(lessclose) + strlen(filename) +
- strlen(altfilename) + 2, sizeof(char));
- sprintf(cmd, lessclose, filename, altfilename);
+ len = strlen(lessclose) + strlen(filename) + strlen(altfilename) + 2;
+ cmd = (char *) ecalloc(len, sizeof(char));
+ SNPRINTF2(cmd, len, lessclose, filename, altfilename);
fd = shellcmd(cmd);
free(cmd);
if (fd != NULL)
diff --git a/contrib/less/forwback.c b/contrib/less/forwback.c
index 29a52bff90aa..9aef12c3f272 100644
--- a/contrib/less/forwback.c
+++ b/contrib/less/forwback.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -124,13 +124,6 @@ forw(n, pos, force, only_last, nblank)
if (!do_repaint)
{
- /*
- * Forget any current line shift we might have
- * (from the last line of the previous screenful).
- */
- extern int cshift;
- cshift = 0;
-
if (top_scroll && n >= sc_height - 1 && pos != ch_length())
{
/*
@@ -142,7 +135,7 @@ forw(n, pos, force, only_last, nblank)
pos_clear();
add_forw_pos(pos);
force = 1;
- if (top_scroll == OPT_ONPLUS || first_time)
+ if (top_scroll == OPT_ONPLUS || (first_time && top_scroll != OPT_ON))
clear();
home();
} else
@@ -240,7 +233,7 @@ forw(n, pos, force, only_last, nblank)
if (top_scroll == OPT_ON)
clear_eol();
put_line();
- if (clear_bg && final_attr != AT_NORMAL)
+ if (clear_bg && apply_at_specials(final_attr) != AT_NORMAL)
{
/*
* Writing the last character on the last line
diff --git a/contrib/less/funcs.h b/contrib/less/funcs.h
index 01b6c12a87a4..b945b855477c 100644
--- a/contrib/less/funcs.h
+++ b/contrib/less/funcs.h
@@ -21,14 +21,11 @@
public void clear ();
public void clear_eol ();
public void clear_bot ();
- public void so_enter ();
- public void so_exit ();
- public void ul_enter ();
- public void ul_exit ();
- public void bo_enter ();
- public void bo_exit ();
- public void bl_enter ();
- public void bl_exit ();
+ public void at_enter ();
+ public void at_exit ();
+ public void at_switch ();
+ public int is_at_equiv ();
+ public int apply_at_specials ();
public void backspace ();
public void putbs ();
public char WIN32getch ();
@@ -54,6 +51,15 @@
public int binary_char ();
public int control_char ();
public char * prchar ();
+ public char * prutfchar ();
+ public int utf_len ();
+ public int is_utf8_well_formed ();
+ public LWCHAR get_wchar ();
+ public LWCHAR step_char ();
+ public int is_composing_char ();
+ public int is_ubin_char ();
+ public int is_wide_char ();
+ public int is_combining_char ();
public void cmd_reset ();
public void clear_cmd ();
public void cmd_putstr ();
@@ -64,6 +70,8 @@
public int cmd_char ();
public LINENUM cmd_int ();
public char * get_cmdbuf ();
+ public void init_cmdhist ();
+ public void save_cmdhist ();
public int in_mca ();
public void dispversion ();
public int getcc ();
@@ -142,10 +150,14 @@
public void jump_line_loc ();
public void jump_loc ();
public void init_line ();
+ public int is_ascii_char ();
public void prewind ();
public void plinenum ();
+ public void pshift_all ();
public int is_ansi_end ();
+ public int is_ansi_middle ();
public int pappend ();
+ public int pflushmbc ();
public void pdone ();
public int gline ();
public void null_line ();
diff --git a/contrib/less/ifile.c b/contrib/less/ifile.c
index 694621eaf41e..1966cea11c86 100644
--- a/contrib/less/ifile.c
+++ b/contrib/less/ifile.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/input.c b/contrib/less/input.c
index a20ce051e04b..645cf23ca442 100644
--- a/contrib/less/input.c
+++ b/contrib/less/input.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -27,6 +27,7 @@ extern int hshift;
extern int quit_if_one_screen;
extern int sigs;
extern int ignore_eoi;
+extern int status_col;
extern POSITION start_attnpos;
extern POSITION end_attnpos;
#if HILITE_SEARCH
@@ -45,10 +46,12 @@ extern int size_linebuf;
forw_line(curr_pos)
POSITION curr_pos;
{
+ POSITION base_pos;
POSITION new_pos;
register int c;
int blankline;
int endline;
+ int backchars;
if (curr_pos == NULL_POSITION)
{
@@ -56,7 +59,7 @@ forw_line(curr_pos)
return (NULL_POSITION);
}
#if HILITE_SEARCH
- if (hilite_search == OPT_ONPLUS)
+ if (hilite_search == OPT_ONPLUS || status_col)
/*
* If we are ignoring EOI (command F), only prepare
* one line ahead, to avoid getting stuck waiting for
@@ -73,9 +76,48 @@ forw_line(curr_pos)
return (NULL_POSITION);
}
- prewind();
- plinenum(curr_pos);
- (void) ch_seek(curr_pos);
+ base_pos = curr_pos;
+ for (;;)
+ {
+ if (ABORT_SIGS())
+ {
+ null_line();
+ return (NULL_POSITION);
+ }
+ c = ch_back_get();
+ if (c == EOI)
+ break;
+ if (c == '\n')
+ {
+ (void) ch_forw_get();
+ break;
+ }
+ --base_pos;
+ }
+
+ prewind();
+ plinenum(base_pos);
+ (void) ch_seek(base_pos);
+ while (base_pos < curr_pos)
+ {
+ if (ABORT_SIGS())
+ {
+ null_line();
+ return (NULL_POSITION);
+ }
+ c = ch_forw_get();
+ backchars = pappend(c, base_pos);
+ base_pos++;
+ if (backchars > 0)
+ {
+ pshift_all();
+ base_pos -= backchars;
+ while (--backchars >= 0)
+ (void) ch_back_get();
+ }
+ }
+ (void) pflushmbc();
+ pshift_all();
c = ch_forw_get();
if (c == EOI)
@@ -97,15 +139,24 @@ forw_line(curr_pos)
/*
* End of the line.
*/
+ backchars = pflushmbc();
new_pos = ch_tell();
- endline = TRUE;
+ if (backchars > 0 && !chopline && hshift == 0)
+ {
+ new_pos -= backchars + 1;
+ endline = FALSE;
+ } else
+ endline = TRUE;
break;
}
+ if (c != '\r')
+ blankline = 0;
/*
* Append the char to the line and get the next char.
*/
- if (pappend(c, ch_tell()-1))
+ backchars = pappend(c, ch_tell()-1);
+ if (backchars > 0)
{
/*
* The char won't fit in the line; the line
@@ -123,7 +174,7 @@ forw_line(curr_pos)
quit_if_one_screen = FALSE;
} else
{
- new_pos = ch_tell() - 1;
+ new_pos = ch_tell() - backchars;
endline = FALSE;
}
break;
@@ -167,6 +218,7 @@ back_line(curr_pos)
POSITION new_pos, begin_new_pos;
int c;
int endline;
+ int backchars;
if (curr_pos == NULL_POSITION || curr_pos <= ch_zero())
{
@@ -174,7 +226,7 @@ back_line(curr_pos)
return (NULL_POSITION);
}
#if HILITE_SEARCH
- if (hilite_search == OPT_ONPLUS)
+ if (hilite_search == OPT_ONPLUS || status_col)
prep_hilite((curr_pos < 3*size_linebuf) ?
0 : curr_pos - 3*size_linebuf, curr_pos, -1);
#endif
@@ -263,10 +315,10 @@ back_line(curr_pos)
return (NULL_POSITION);
}
endline = FALSE;
- loop:
- begin_new_pos = new_pos;
prewind();
plinenum(new_pos);
+ loop:
+ begin_new_pos = new_pos;
(void) ch_seek(new_pos);
do
@@ -280,10 +332,17 @@ back_line(curr_pos)
new_pos++;
if (c == '\n')
{
+ backchars = pflushmbc();
+ if (backchars > 0 && !chopline && hshift == 0)
+ {
+ backchars++;
+ goto shift;
+ }
endline = TRUE;
break;
}
- if (pappend(c, ch_tell()-1))
+ backchars = pappend(c, ch_tell()-1);
+ if (backchars > 0)
{
/*
* Got a full printable line, but we haven't
@@ -296,9 +355,13 @@ back_line(curr_pos)
quit_if_one_screen = FALSE;
break;
}
- pdone(0);
- (void) ch_back_get();
- new_pos--;
+ shift:
+ pshift_all();
+ while (backchars-- > 0)
+ {
+ (void) ch_back_get();
+ new_pos--;
+ }
goto loop;
}
} while (new_pos < curr_pos);
diff --git a/contrib/less/jump.c b/contrib/less/jump.c
index b919b2549f72..38132ccf95b2 100644
--- a/contrib/less/jump.c
+++ b/contrib/less/jump.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -22,6 +22,7 @@ extern int squished;
extern int screen_trashed;
extern int sc_width, sc_height;
extern int show_attn;
+extern int top_scroll;
/*
* Jump to the end of the file.
@@ -279,7 +280,10 @@ jump_loc(pos, sline)
}
}
lastmark();
- clear();
+ if (top_scroll != OPT_ON)
+ clear();
+ else
+ home();
screen_trashed = 0;
add_back_pos(pos);
back(sc_height-1, pos, 1, 0);
diff --git a/contrib/less/less.h b/contrib/less/less.h
index 059a6dab55bf..543d2903ac6a 100644
--- a/contrib/less/less.h
+++ b/contrib/less/less.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -79,13 +79,21 @@
#if HAVE_STRING_H
#include <string.h>
#endif
+
+/* OS-specific includes */
#ifdef _OSK
#include <modes.h>
#include <strings.h>
#endif
+
+#ifdef __TANDEM
+#include <floss.h>
+#endif
+
#if MSDOS_COMPILER==WIN32C || OS2
#include <io.h>
#endif
+
#if MSDOS_COMPILER==DJGPPC
#include <io.h>
#include <sys/exceptn.h>
@@ -104,16 +112,40 @@ void free();
* Simple lowercase test which can be used during option processing
* (before options are parsed which might tell us what charset to use).
*/
-#define SIMPLE_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
-#define SIMPLE_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
-#define SIMPLE_TO_UPPER(c) ((c) - 'a' + 'A')
-#define SIMPLE_TO_LOWER(c) ((c) - 'A' + 'a')
+#define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
+#define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
+#define ASCII_TO_UPPER(c) ((c) - 'a' + 'A')
+#define ASCII_TO_LOWER(c) ((c) - 'A' + 'a')
+
+#undef IS_UPPER
+#undef IS_LOWER
+#undef TO_UPPER
+#undef TO_LOWER
+#undef IS_SPACE
+#undef IS_DIGIT
#if !HAVE_UPPER_LOWER
-#define isupper(c) SIMPLE_IS_UPPER(c)
-#define islower(c) SIMPLE_IS_LOWER(c)
-#define toupper(c) SIMPLE_TO_UPPER(c)
-#define tolower(c) SIMPLE_TO_LOWER(c)
+#define IS_UPPER(c) ASCII_IS_UPPER(c)
+#define IS_LOWER(c) ASCII_IS_LOWER(c)
+#define TO_UPPER(c) ASCII_TO_UPPER(c)
+#define TO_LOWER(c) ASCII_TO_LOWER(c)
+#else
+#define IS_UPPER(c) isupper((unsigned char) (c))
+#define IS_LOWER(c) islower((unsigned char) (c))
+#define TO_UPPER(c) toupper((unsigned char) (c))
+#define TO_LOWER(c) tolower((unsigned char) (c))
+#endif
+
+#ifdef isspace
+#define IS_SPACE(c) isspace((unsigned char)(c))
+#else
+#define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
+#endif
+
+#ifdef isdigit
+#define IS_DIGIT(c) isdigit((unsigned char)(c))
+#else
+#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
#endif
#ifndef NULL
@@ -137,6 +169,19 @@ void free();
#endif
#endif
+#if HAVE_SNPRINTF
+#define SNPRINTF1(str, size, fmt, v1) snprintf((str), (size), (fmt), (v1))
+#define SNPRINTF2(str, size, fmt, v1, v2) snprintf((str), (size), (fmt), (v1), (v2))
+#define SNPRINTF3(str, size, fmt, v1, v2, v3) snprintf((str), (size), (fmt), (v1), (v2), (v3))
+#define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) snprintf((str), (size), (fmt), (v1), (v2), (v3), (v4))
+#else
+/* Use unsafe sprintf if we don't have snprintf. */
+#define SNPRINTF1(str, size, fmt, v1) sprintf((str), (fmt), (v1))
+#define SNPRINTF2(str, size, fmt, v1, v2) sprintf((str), (fmt), (v1), (v2))
+#define SNPRINTF3(str, size, fmt, v1, v2, v3) sprintf((str), (fmt), (v1), (v2), (v3))
+#define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4))
+#endif
+
#define BAD_LSEEK ((off_t)-1)
#ifndef CHAR_BIT
@@ -153,9 +198,11 @@ void free();
/*
* Special types and constants.
*/
+typedef unsigned long LWCHAR;
typedef off_t POSITION;
typedef off_t LINENUM;
#define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */
+#define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */
#define NULL_POSITION ((POSITION)(-1))
@@ -264,14 +311,14 @@ struct textlist
#define BS_CONTROL 2 /* \b treated as control char; prints as ^H */
/* How should we search? */
-#define SRCH_FORW 000001 /* Search forward from current position */
-#define SRCH_BACK 000002 /* Search backward from current position */
-#define SRCH_NO_MOVE 000004 /* Highlight, but don't move */
-#define SRCH_FIND_ALL 000010 /* Find and highlight all matches */
-#define SRCH_NO_MATCH 000100 /* Search for non-matching lines */
-#define SRCH_PAST_EOF 000200 /* Search past end-of-file, into next file */
-#define SRCH_FIRST_FILE 000400 /* Search starting at the first file */
-#define SRCH_NO_REGEX 001000 /* Don't use regular expressions */
+#define SRCH_FORW (1 << 0) /* Search forward from current position */
+#define SRCH_BACK (1 << 1) /* Search backward from current position */
+#define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */
+#define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */
+#define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */
+#define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */
+#define SRCH_FIRST_FILE (1 << 10) /* Search starting at the first file */
+#define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */
#define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
(((t) & ~SRCH_FORW) | SRCH_BACK) : \
@@ -289,13 +336,15 @@ struct textlist
#define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */
-/* Special chars used to tell put_line() to do something special */
+/* Special char bit-flags used to tell put_line() to do something special */
#define AT_NORMAL (0)
-#define AT_UNDERLINE (1)
-#define AT_BOLD (2)
-#define AT_BLINK (3)
-#define AT_INVIS (4)
-#define AT_STANDOUT (5)
+#define AT_UNDERLINE (1 << 0)
+#define AT_BOLD (1 << 1)
+#define AT_BLINK (1 << 2)
+#define AT_STANDOUT (1 << 3)
+#define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */
+#define AT_BINARY (1 << 5) /* LESS*BINFMT representation */
+#define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */
#if '0' == 240
#define IS_EBCDIC_HOST 1
diff --git a/contrib/less/less.man b/contrib/less/less.man
index 5455849f2ba2..8548f5500244 100644
--- a/contrib/less/less.man
+++ b/contrib/less/less.man
@@ -1,9 +1,7 @@
+LESS(1) LESS(1)
-LESS(1) LESS(1)
-
-
NNAAMMEE
less - opposite of more
@@ -12,287 +10,215 @@ SSYYNNOOPPSSIISS
lleessss ----hheellpp
lleessss --VV
lleessss ----vveerrssiioonn
- lleessss [[--[[++]]aaBBccCCddeeEEffFFggGGiiIIJJLLmmMMnnNNqqQQrrRRssSSuuUUVVwwWWXX~~]]
+ lleessss [[--[[++]]aaBBccCCddeeEEffFFggGGiiIIJJKKLLmmMMnnNNqqQQrrRRssSSuuUUVVwwWWXX~~]]
[[--bb _s_p_a_c_e]] [[--hh _l_i_n_e_s]] [[--jj _l_i_n_e]] [[--kk _k_e_y_f_i_l_e]]
[[--{{ooOO}} _l_o_g_f_i_l_e]] [[--pp _p_a_t_t_e_r_n]] [[--PP _p_r_o_m_p_t]] [[--tt _t_a_g]]
[[--TT _t_a_g_s_f_i_l_e]] [[--xx _t_a_b,,......]] [[--yy _l_i_n_e_s]] [[--[[zz]] _l_i_n_e_s]]
[[--## _s_h_i_f_t]] [[++[[++]]_c_m_d]] [[----]] [[_f_i_l_e_n_a_m_e]]......
- (See the OPTIONS section for alternate option syntax with
- long option names.)
+ (See the OPTIONS section for alternate option syntax with long option
+ names.)
DDEESSCCRRIIPPTTIIOONN
- _L_e_s_s is a program similar to _m_o_r_e (1), but which allows
- backward movement in the file as well as forward movement.
- Also, _l_e_s_s does not have to read the entire input file
- before starting, so with large input files it starts up
- faster than text editors like _v_i (1). _L_e_s_s uses termcap
- (or terminfo on some systems), so it can run on a variety
- of terminals. There is even limited support for hardcopy
- terminals. (On a hardcopy terminal, lines which should be
- printed at the top of the screen are prefixed with a
- caret.)
-
- Commands are based on both _m_o_r_e and _v_i_. Commands may be
- preceded by a decimal number, called N in the descriptions
- below. The number is used by some commands, as indicated.
+ _L_e_s_s is a program similar to _m_o_r_e (1), but which allows backward move-
+ ment in the file as well as forward movement. Also, _l_e_s_s does not have
+ to read the entire input file before starting, so with large input
+ files it starts up faster than text editors like _v_i (1). _L_e_s_s uses
+ termcap (or terminfo on some systems), so it can run on a variety of
+ terminals. There is even limited support for hardcopy terminals. (On
+ a hardcopy terminal, lines which should be printed at the top of the
+ screen are prefixed with a caret.)
+
+ Commands are based on both _m_o_r_e and _v_i_. Commands may be preceded by a
+ decimal number, called N in the descriptions below. The number is used
+ by some commands, as indicated.
CCOOMMMMAANNDDSS
- In the following descriptions, ^X means control-X. ESC
- stands for the ESCAPE key; for example ESC-v means the two
- character sequence "ESCAPE", then "v".
+ In the following descriptions, ^X means control-X. ESC stands for the
+ ESCAPE key; for example ESC-v means the two character sequence
+ "ESCAPE", then "v".
- h or H Help: display a summary of these commands. If you
- forget all the other commands, remember this one.
+ h or H Help: display a summary of these commands. If you forget all
+ the other commands, remember this one.
SPACE or ^V or f or ^F
- Scroll forward N lines, default one window (see
- option -z below). If N is more than the screen
- size, only the final screenful is displayed. Warn­
- ing: some systems use ^V as a special literaliza­
- tion character.
+ Scroll forward N lines, default one window (see option -z
+ below). If N is more than the screen size, only the final
+ screenful is displayed. Warning: some systems use ^V as a spe-
+ cial literalization character.
- z Like SPACE, but if N is specified, it becomes the
- new window size.
+ z Like SPACE, but if N is specified, it becomes the new window
+ size.
ESC-SPACE
- Like SPACE, but scrolls a full screenful, even if
-
-
-
- Version 381: 17 Jan 2003 1
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- it reaches end-of-file in the process.
+ Like SPACE, but scrolls a full screenful, even if it reaches
+ end-of-file in the process.
RETURN or ^N or e or ^E or j or ^J
- Scroll forward N lines, default 1. The entire N
- lines are displayed, even if N is more than the
- screen size.
+ Scroll forward N lines, default 1. The entire N lines are dis-
+ played, even if N is more than the screen size.
d or ^D
- Scroll forward N lines, default one half of the
- screen size. If N is specified, it becomes the new
- default for subsequent d and u commands.
+ Scroll forward N lines, default one half of the screen size. If
+ N is specified, it becomes the new default for subsequent d and
+ u commands.
b or ^B or ESC-v
- Scroll backward N lines, default one window (see
- option -z below). If N is more than the screen
- size, only the final screenful is displayed.
+ Scroll backward N lines, default one window (see option -z
+ below). If N is more than the screen size, only the final
+ screenful is displayed.
- w Like ESC-v, but if N is specified, it becomes the
- new window size.
+ w Like ESC-v, but if N is specified, it becomes the new window
+ size.
y or ^Y or ^P or k or ^K
- Scroll backward N lines, default 1. The entire N
- lines are displayed, even if N is more than the
- screen size. Warning: some systems use ^Y as a
- special job control character.
+ Scroll backward N lines, default 1. The entire N lines are dis-
+ played, even if N is more than the screen size. Warning: some
+ systems use ^Y as a special job control character.
u or ^U
- Scroll backward N lines, default one half of the
- screen size. If N is specified, it becomes the new
- default for subsequent d and u commands.
+ Scroll backward N lines, default one half of the screen size.
+ If N is specified, it becomes the new default for subsequent d
+ and u commands.
ESC-) or RIGHTARROW
- Scroll horizontally right N characters, default
- half the screen width (see the -# option). If a
- number N is specified, it becomes the default for
- future RIGHTARROW and LEFTARROW commands. While
- the text is scrolled, it acts as though the -S
+ Scroll horizontally right N characters, default half the screen
+ width (see the -# option). If a number N is specified, it
+ becomes the default for future RIGHTARROW and LEFTARROW com-
+ mands. While the text is scrolled, it acts as though the -S
option (chop lines) were in effect.
ESC-( or LEFTARROW
- Scroll horizontally left N characters, default half
- the screen width (see the -# option). If a number
- N is specified, it becomes the default for future
- RIGHTARROW and LEFTARROW commands.
+ Scroll horizontally left N characters, default half the screen
+ width (see the -# option). If a number N is specified, it
+ becomes the default for future RIGHTARROW and LEFTARROW com-
+ mands.
r or ^R or ^L
Repaint the screen.
- R Repaint the screen, discarding any buffered input.
- Useful if the file is changing while it is being
- viewed.
-
- F Scroll forward, and keep trying to read when the
- end of file is reached. Normally this command
-
-
-
- Version 381: 17 Jan 2003 2
-
-
-
-
-
-LESS(1) LESS(1)
-
+ R Repaint the screen, discarding any buffered input. Useful if
+ the file is changing while it is being viewed.
- would be used when already at the end of the file.
- It is a way to monitor the tail of a file which is
- growing while it is being viewed. (The behavior is
+ F Scroll forward, and keep trying to read when the end of file is
+ reached. Normally this command would be used when already at
+ the end of the file. It is a way to monitor the tail of a file
+ which is growing while it is being viewed. (The behavior is
similar to the "tail -f" command.)
g or < or ESC-<
- Go to line N in the file, default 1 (beginning of
- file). (Warning: this may be slow if N is large.)
+ Go to line N in the file, default 1 (beginning of file). (Warn-
+ ing: this may be slow if N is large.)
G or > or ESC->
- Go to line N in the file, default the end of the
- file. (Warning: this may be slow if N is large, or
- if N is not specified and standard input, rather
- than a file, is being read.)
-
- p or % Go to a position N percent into the file. N should
- be between 0 and 100.
-
- { If a left curly bracket appears in the top line
- displayed on the screen, the { command will go to
- the matching right curly bracket. The matching
- right curly bracket is positioned on the bottom
- line of the screen. If there is more than one left
- curly bracket on the top line, a number N may be
- used to specify the N-th bracket on the line.
-
- } If a right curly bracket appears in the bottom line
- displayed on the screen, the } command will go to
- the matching left curly bracket. The matching left
- curly bracket is positioned on the top line of the
- screen. If there is more than one right curly
- bracket on the top line, a number N may be used to
- specify the N-th bracket on the line.
-
- ( Like {, but applies to parentheses rather than
- curly brackets.
-
- ) Like }, but applies to parentheses rather than
- curly brackets.
-
- [ Like {, but applies to square brackets rather than
- curly brackets.
-
- ] Like }, but applies to square brackets rather than
- curly brackets.
-
- ESC-^F Followed by two characters, acts like {, but uses
- the two characters as open and close brackets,
- respectively. For example, "ESC ^F < >" could be
- used to go forward to the > which matches the < in
- the top displayed line.
-
- ESC-^B Followed by two characters, acts like }, but uses
- the two characters as open and close brackets,
-
-
-
- Version 381: 17 Jan 2003 3
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- respectively. For example, "ESC ^B < >" could be
- used to go backward to the < which matches the > in
- the bottom displayed line.
-
- m Followed by any lowercase letter, marks the current
- position with that letter.
-
- ' (Single quote.) Followed by any lowercase letter,
- returns to the position which was previously marked
- with that letter. Followed by another single
- quote, returns to the position at which the last
- "large" movement command was executed. Followed by
- a ^ or $, jumps to the beginning or end of the file
- respectively. Marks are preserved when a new file
- is examined, so the ' command can be used to switch
- between input files.
+ Go to line N in the file, default the end of the file. (Warn-
+ ing: this may be slow if N is large, or if N is not specified
+ and standard input, rather than a file, is being read.)
+
+ p or % Go to a position N percent into the file. N should be between 0
+ and 100.
+
+ { If a left curly bracket appears in the top line displayed on the
+ screen, the { command will go to the matching right curly
+ bracket. The matching right curly bracket is positioned on the
+ bottom line of the screen. If there is more than one left curly
+ bracket on the top line, a number N may be used to specify the
+ N-th bracket on the line.
+
+ } If a right curly bracket appears in the bottom line displayed on
+ the screen, the } command will go to the matching left curly
+ bracket. The matching left curly bracket is positioned on the
+ top line of the screen. If there is more than one right curly
+ bracket on the top line, a number N may be used to specify the
+ N-th bracket on the line.
+
+ ( Like {, but applies to parentheses rather than curly brackets.
+
+ ) Like }, but applies to parentheses rather than curly brackets.
+
+ [ Like {, but applies to square brackets rather than curly brack-
+ ets.
+
+ ] Like }, but applies to square brackets rather than curly brack-
+ ets.
+
+ ESC-^F Followed by two characters, acts like {, but uses the two char-
+ acters as open and close brackets, respectively. For example,
+ "ESC ^F < >" could be used to go forward to the > which matches
+ the < in the top displayed line.
+
+ ESC-^B Followed by two characters, acts like }, but uses the two char-
+ acters as open and close brackets, respectively. For example,
+ "ESC ^B < >" could be used to go backward to the < which matches
+ the > in the bottom displayed line.
+
+ m Followed by any lowercase letter, marks the current position
+ with that letter.
+
+ ' (Single quote.) Followed by any lowercase letter, returns to
+ the position which was previously marked with that letter. Fol-
+ lowed by another single quote, returns to the position at which
+ the last "large" movement command was executed. Followed by a ^
+ or $, jumps to the beginning or end of the file respectively.
+ Marks are preserved when a new file is examined, so the ' com-
+ mand can be used to switch between input files.
^X^X Same as single quote.
/pattern
- Search forward in the file for the N-th line con­
- taining the pattern. N defaults to 1. The pattern
- is a regular expression, as recognized by _e_d_. The
- search starts at the second line displayed (but see
+ Search forward in the file for the N-th line containing the pat-
+ tern. N defaults to 1. The pattern is a regular expression, as
+ recognized by the regular expression library supplied by your
+ system. The search starts at the second line displayed (but see
the -a and -j options, which change this).
- Certain characters are special if entered at the
- beginning of the pattern; they modify the type of
- search rather than become part of the pattern:
+ Certain characters are special if entered at the beginning of
+ the pattern; they modify the type of search rather than become
+ part of the pattern:
^N or !
- Search for lines which do NOT match the pat­
- tern.
+ Search for lines which do NOT match the pattern.
^E or *
- Search multiple files. That is, if the
- search reaches the END of the current file
- without finding a match, the search contin­
- ues in the next file in the command line
+ Search multiple files. That is, if the search reaches
+ the END of the current file without finding a match, the
+ search continues in the next file in the command line
list.
^F or @
- Begin the search at the first line of the
- FIRST file in the command line list, regard­
- less of what is currently displayed on the
- screen or the settings of the -a or -j
+ Begin the search at the first line of the FIRST file in
+ the command line list, regardless of what is currently
+ displayed on the screen or the settings of the -a or -j
options.
- ^K Highlight any text which matches the pattern
- on the current screen, but don't move to the
- first match (KEEP current position).
-
- ^R Don't interpret regular expression metachar­
- acters; that is, do a simple textual
+ ^K Highlight any text which matches the pattern on the cur-
+ rent screen, but don't move to the first match (KEEP cur-
+ rent position).
-
-
- Version 381: 17 Jan 2003 4
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- comparison.
+ ^R Don't interpret regular expression metacharacters; that
+ is, do a simple textual comparison.
?pattern
- Search backward in the file for the N-th line con­
- taining the pattern. The search starts at the line
- immediately before the top line displayed.
+ Search backward in the file for the N-th line containing the
+ pattern. The search starts at the line immediately before the
+ top line displayed.
Certain characters are special as in the / command:
^N or !
- Search for lines which do NOT match the pat­
- tern.
+ Search for lines which do NOT match the pattern.
^E or *
- Search multiple files. That is, if the
- search reaches the beginning of the current
- file without finding a match, the search
- continues in the previous file in the com­
- mand line list.
+ Search multiple files. That is, if the search reaches
+ the beginning of the current file without finding a
+ match, the search continues in the previous file in the
+ command line list.
^F or @
- Begin the search at the last line of the
- last file in the command line list, regard­
- less of what is currently displayed on the
- screen or the settings of the -a or -j
+ Begin the search at the last line of the last file in the
+ command line list, regardless of what is currently dis-
+ played on the screen or the settings of the -a or -j
options.
^K As in forward searches.
@@ -305,252 +231,177 @@ LESS(1) LESS(1)
ESC-?pattern
Same as "?*".
- n Repeat previous search, for N-th line containing
- the last pattern. If the previous search was modi­
- fied by ^N, the search is made for the N-th line
- NOT containing the pattern. If the previous search
- was modified by ^E, the search continues in the
- next (or previous) file if not satisfied in the
- current file. If the previous search was modified
- by ^R, the search is done without using regular
- expressions. There is no effect if the previous
- search was modified by ^F or ^K.
-
- N Repeat previous search, but in the reverse direc­
- tion.
-
- ESC-n Repeat previous search, but crossing file bound­
- aries. The effect is as if the previous search
- were modified by *.
-
+ n Repeat previous search, for N-th line containing the last pat-
+ tern. If the previous search was modified by ^N, the search is
+ made for the N-th line NOT containing the pattern. If the pre-
+ vious search was modified by ^E, the search continues in the
+ next (or previous) file if not satisfied in the current file.
+ If the previous search was modified by ^R, the search is done
+ without using regular expressions. There is no effect if the
+ previous search was modified by ^F or ^K.
+ N Repeat previous search, but in the reverse direction.
- Version 381: 17 Jan 2003 5
+ ESC-n Repeat previous search, but crossing file boundaries. The
+ effect is as if the previous search were modified by *.
+ ESC-N Repeat previous search, but in the reverse direction and cross-
+ ing file boundaries.
-
-
-
-LESS(1) LESS(1)
-
-
- ESC-N Repeat previous search, but in the reverse direc­
- tion and crossing file boundaries.
-
- ESC-u Undo search highlighting. Turn off highlighting of
- strings matching the current search pattern. If
- highlighting is already off because of a previous
- ESC-u command, turn highlighting back on. Any
- search command will also turn highlighting back on.
- (Highlighting can also be disabled by toggling the
- -G option; in that case search commands do not turn
- highlighting back on.)
+ ESC-u Undo search highlighting. Turn off highlighting of strings
+ matching the current search pattern. If highlighting is already
+ off because of a previous ESC-u command, turn highlighting back
+ on. Any search command will also turn highlighting back on.
+ (Highlighting can also be disabled by toggling the -G option; in
+ that case search commands do not turn highlighting back on.)
:e [filename]
- Examine a new file. If the filename is missing,
- the "current" file (see the :n and :p commands
- below) from the list of files in the command line
- is re-examined. A percent sign (%) in the filename
- is replaced by the name of the current file. A
- pound sign (#) is replaced by the name of the pre­
- viously examined file. However, two consecutive
- percent signs are simply replaced with a single
- percent sign. This allows you to enter a filename
- that contains a percent sign in the name. Simi­
- larly, two consecutive pound signs are replaced
- with a single pound sign. The filename is inserted
- into the command line list of files so that it can
- be seen by subsequent :n and :p commands. If the
- filename consists of several files, they are all
- inserted into the list of files and the first one
- is examined. If the filename contains one or more
- spaces, the entire filename should be enclosed in
- double quotes (also see the -" option).
+ Examine a new file. If the filename is missing, the "current"
+ file (see the :n and :p commands below) from the list of files
+ in the command line is re-examined. A percent sign (%) in the
+ filename is replaced by the name of the current file. A pound
+ sign (#) is replaced by the name of the previously examined
+ file. However, two consecutive percent signs are simply
+ replaced with a single percent sign. This allows you to enter a
+ filename that contains a percent sign in the name. Similarly,
+ two consecutive pound signs are replaced with a single pound
+ sign. The filename is inserted into the command line list of
+ files so that it can be seen by subsequent :n and :p commands.
+ If the filename consists of several files, they are all inserted
+ into the list of files and the first one is examined. If the
+ filename contains one or more spaces, the entire filename should
+ be enclosed in double quotes (also see the -" option).
^X^V or E
- Same as :e. Warning: some systems use ^V as a spe­
- cial literalization character. On such systems,
- you may not be able to use ^V.
+ Same as :e. Warning: some systems use ^V as a special literal-
+ ization character. On such systems, you may not be able to use
+ ^V.
- :n Examine the next file (from the list of files given
- in the command line). If a number N is specified,
- the N-th next file is examined.
+ :n Examine the next file (from the list of files given in the com-
+ mand line). If a number N is specified, the N-th next file is
+ examined.
- :p Examine the previous file in the command line list.
- If a number N is specified, the N-th previous file
- is examined.
+ :p Examine the previous file in the command line list. If a number
+ N is specified, the N-th previous file is examined.
- :x Examine the first file in the command line list.
- If a number N is specified, the N-th file in the
- list is examined.
+ :x Examine the first file in the command line list. If a number N
+ is specified, the N-th file in the list is examined.
:d Remove the current file from the list of files.
- t Go to the next tag, if there were more than one
- matches for the current tag. See the -t option for
-
-
-
- Version 381: 17 Jan 2003 6
-
-
+ t Go to the next tag, if there were more than one matches for the
+ current tag. See the -t option for more details about tags.
-
-
-LESS(1) LESS(1)
-
-
- more details about tags.
-
- T Go to the previous tag, if there were more than one
- matches for the current tag.
+ T Go to the previous tag, if there were more than one matches for
+ the current tag.
= or ^G or :f
- Prints some information about the file being
- viewed, including its name and the line number and
- byte offset of the bottom line being displayed. If
- possible, it also prints the length of the file,
- the number of lines in the file and the percent of
- the file above the last displayed line.
-
- - Followed by one of the command line option letters
- (see OPTIONS below), this will change the setting
- of that option and print a message describing the
- new setting. If a ^P (CONTROL-P) is entered imme­
- diately after the dash, the setting of the option
- is changed but no message is printed. If the
- option letter has a numeric value (such as -b or
- -h), or a string value (such as -P or -t), a new
- value may be entered after the option letter. If
- no new value is entered, a message describing the
- current setting is printed and nothing is changed.
-
- -- Like the - command, but takes a long option name
- (see OPTIONS below) rather than a single option
- letter. You must press RETURN after typing the
- option name. A ^P immediately after the second
- dash suppresses printing of a message describing
- the new setting, as in the - command.
-
- -+ Followed by one of the command line option letters
- this will reset the option to its default setting
- and print a message describing the new setting.
- (The "-+_X" command does the same thing as "-+_X" on
- the command line.) This does not work for string-
- valued options.
-
- --+ Like the -+ command, but takes a long option name
- rather than a single option letter.
-
- -! Followed by one of the command line option letters,
- this will reset the option to the "opposite" of its
- default setting and print a message describing the
- new setting. This does not work for numeric or
+ Prints some information about the file being viewed, including
+ its name and the line number and byte offset of the bottom line
+ being displayed. If possible, it also prints the length of the
+ file, the number of lines in the file and the percent of the
+ file above the last displayed line.
+
+ - Followed by one of the command line option letters (see OPTIONS
+ below), this will change the setting of that option and print a
+ message describing the new setting. If a ^P (CONTROL-P) is
+ entered immediately after the dash, the setting of the option is
+ changed but no message is printed. If the option letter has a
+ numeric value (such as -b or -h), or a string value (such as -P
+ or -t), a new value may be entered after the option letter. If
+ no new value is entered, a message describing the current set-
+ ting is printed and nothing is changed.
+
+ -- Like the - command, but takes a long option name (see OPTIONS
+ below) rather than a single option letter. You must press
+ RETURN after typing the option name. A ^P immediately after the
+ second dash suppresses printing of a message describing the new
+ setting, as in the - command.
+
+ -+ Followed by one of the command line option letters this will
+ reset the option to its default setting and print a message
+ describing the new setting. (The "-+_X" command does the same
+ thing as "-+_X" on the command line.) This does not work for
string-valued options.
- --! Like the -! command, but takes a long option name
- rather than a single option letter.
-
- _ (Underscore.) Followed by one of the command line
- option letters, this will print a message describ­
- ing the current setting of that option. The
-
-
-
- Version 381: 17 Jan 2003 7
-
-
+ --+ Like the -+ command, but takes a long option name rather than a
+ single option letter.
+ -! Followed by one of the command line option letters, this will
+ reset the option to the "opposite" of its default setting and
+ print a message describing the new setting. This does not work
+ for numeric or string-valued options.
+ --! Like the -! command, but takes a long option name rather than a
+ single option letter.
-LESS(1) LESS(1)
+ _ (Underscore.) Followed by one of the command line option let-
+ ters, this will print a message describing the current setting
+ of that option. The setting of the option is not changed.
+ __ (Double underscore.) Like the _ (underscore) command, but takes
+ a long option name rather than a single option letter. You must
+ press RETURN after typing the option name.
- setting of the option is not changed.
-
- __ (Double underscore.) Like the _ (underscore) com­
- mand, but takes a long option name rather than a
- single option letter. You must press RETURN after
- typing the option name.
-
- +cmd Causes the specified cmd to be executed each time a
- new file is examined. For example, +G causes _l_e_s_s
- to initially display each file starting at the end
- rather than the beginning.
+ +cmd Causes the specified cmd to be executed each time a new file is
+ examined. For example, +G causes _l_e_s_s to initially display each
+ file starting at the end rather than the beginning.
V Prints the version number of _l_e_s_s being run.
q or Q or :q or :Q or ZZ
Exits _l_e_s_s_.
- The following four commands may or may not be valid,
- depending on your particular installation.
+ The following four commands may or may not be valid, depending on your
+ particular installation.
- v Invokes an editor to edit the current file being
- viewed. The editor is taken from the environment
- variable VISUAL if defined, or EDITOR if VISUAL is
- not defined, or defaults to "vi" if neither VISUAL
- nor EDITOR is defined. See also the discussion of
+ v Invokes an editor to edit the current file being viewed. The
+ editor is taken from the environment variable VISUAL if defined,
+ or EDITOR if VISUAL is not defined, or defaults to "vi" if nei-
+ ther VISUAL nor EDITOR is defined. See also the discussion of
LESSEDIT under the section on PROMPTS below.
! shell-command
- Invokes a shell to run the shell-command given. A
- percent sign (%) in the command is replaced by the
- name of the current file. A pound sign (#) is
- replaced by the name of the previously examined
- file. "!!" repeats the last shell command. "!"
- with no shell command simply invokes a shell. On
- Unix systems, the shell is taken from the environ­
- ment variable SHELL, or defaults to "sh". On MS-
- DOS and OS/2 systems, the shell is the normal com­
- mand processor.
+ Invokes a shell to run the shell-command given. A percent sign
+ (%) in the command is replaced by the name of the current file.
+ A pound sign (#) is replaced by the name of the previously exam-
+ ined file. "!!" repeats the last shell command. "!" with no
+ shell command simply invokes a shell. On Unix systems, the
+ shell is taken from the environment variable SHELL, or defaults
+ to "sh". On MS-DOS and OS/2 systems, the shell is the normal
+ command processor.
| <m> shell-command
- <m> represents any mark letter. Pipes a section of
- the input file to the given shell command. The
- section of the file to be piped is between the
- first line on the current screen and the position
- marked by the letter. <m> may also be ^ or $ to
- indicate beginning or end of file respectively. If
- <m> is . or newline, the current screen is piped.
+ <m> represents any mark letter. Pipes a section of the input
+ file to the given shell command. The section of the file to be
+ piped is between the first line on the current screen and the
+ position marked by the letter. <m> may also be ^ or $ to indi-
+ cate beginning or end of file respectively. If <m> is . or new-
+ line, the current screen is piped.
s filename
- Save the input to a file. This only works if the
- input is a pipe, not an ordinary file.
-
-
-
-
-
- Version 381: 17 Jan 2003 8
-
-
-
-
-
-LESS(1) LESS(1)
+ Save the input to a file. This only works if the input is a
+ pipe, not an ordinary file.
OOPPTTIIOONNSS
- Command line options are described below. Most options
- may be changed while _l_e_s_s is running, via the "-" command.
-
- Most options may be given in one of two forms: either a
- dash followed by a single letter, or two dashes followed
- by a long option name. A long option name may be abbrevi­
- ated as long as the abbreviation is unambiguous. For
- example, --quit-at-eof may be abbreviated --quit, but not
- --qui, since both --quit-at-eof and --quiet begin with
- --qui. Some long option names are in uppercase, such as
- --QUIT-AT-EOF, as distinct from --quit-at-eof. Such
- option names need only have their first letter capital­
- ized; the remainder of the name may be in either case.
+ Command line options are described below. Most options may be changed
+ while _l_e_s_s is running, via the "-" command.
+
+ Most options may be given in one of two forms: either a dash followed
+ by a single letter, or two dashes followed by a long option name. A
+ long option name may be abbreviated as long as the abbreviation is
+ unambiguous. For example, --quit-at-eof may be abbreviated --quit, but
+ not --qui, since both --quit-at-eof and --quiet begin with --qui. Some
+ long option names are in uppercase, such as --QUIT-AT-EOF, as distinct
+ from --quit-at-eof. Such option names need only have their first
+ letter capitalized; the remainder of the name may be in either case.
For example, --Quit-at-eof is equivalent to --QUIT-AT-EOF.
- Options are also taken from the environment variable
- "LESS". For example, to avoid typing "less -options ..."
- each time _l_e_s_s is invoked, you might tell _c_s_h_:
+ Options are also taken from the environment variable "LESS". For exam-
+ ple, to avoid typing "less -options ..." each time _l_e_s_s is invoked, you
+ might tell _c_s_h_:
setenv LESS "-options"
@@ -558,584 +409,428 @@ OOPPTTIIOONNSS
LESS="-options"; export LESS
- On MS-DOS, you don't need the quotes, but you should
- replace any percent signs in the options string by double
- percent signs.
+ On MS-DOS, you don't need the quotes, but you should replace any per-
+ cent signs in the options string by double percent signs.
- The environment variable is parsed before the command
- line, so command line options override the LESS environ­
- ment variable. If an option appears in the LESS variable,
- it can be reset to its default value on the command line
- by beginning the command line option with "-+".
+ The environment variable is parsed before the command line, so command
+ line options override the LESS environment variable. If an option
+ appears in the LESS variable, it can be reset to its default value on
+ the command line by beginning the command line option with "-+".
- For options like -P or -D which take a following string, a
- dollar sign ($) must be used to signal the end of the
- string. For example, to set two -D options on MS-DOS, you
- must have a dollar sign between them, like this:
+ For options like -P or -D which take a following string, a dollar sign
+ ($) must be used to signal the end of the string. For example, to set
+ two -D options on MS-DOS, you must have a dollar sign between them,
+ like this:
LESS="-Dn9.1$-Ds4.1"
-? or --help
- This option displays a summary of the commands
- accepted by _l_e_s_s (the same as the h command).
- (Depending on how your shell interprets the ques­
- tion mark, it may be necessary to quote the ques­
- tion mark, thus: "-\?".)
+ This option displays a summary of the commands accepted by _l_e_s_s
+ (the same as the h command). (Depending on how your shell
+ interprets the question mark, it may be necessary to quote the
+ question mark, thus: "-\?".)
-a or --search-skip-screen
- Causes searches to start after the last line dis­
- played on the screen, thus skipping all lines
-
-
-
- Version 381: 17 Jan 2003 9
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- displayed on the screen. By default, searches
- start at the second line on the screen (or after
- the last found line; see the -j option).
+ Causes searches to start after the last line displayed on the
+ screen, thus skipping all lines displayed on the screen. By
+ default, searches start at the second line on the screen (or
+ after the last found line; see the -j option).
-b_n or --buffers=_n
- Specifies the amount of buffer space _l_e_s_s will use
- for each file, in units of kilobytes (1024 bytes).
- By default 64K of buffer space is used for each
- file (unless the file is a pipe; see the -B
- option). The -b option specifies instead that _n
- kilobytes of buffer space should be used for each
- file. If _n is -1, buffer space is unlimited; that
- is, the entire file is read into memory.
+ Specifies the amount of buffer space _l_e_s_s will use for each
+ file, in units of kilobytes (1024 bytes). By default 64K of
+ buffer space is used for each file (unless the file is a pipe;
+ see the -B option). The -b option specifies instead that _n
+ kilobytes of buffer space should be used for each file. If _n is
+ -1, buffer space is unlimited; that is, the entire file is read
+ into memory.
-B or --auto-buffers
- By default, when data is read from a pipe, buffers
- are allocated automatically as needed. If a large
- amount of data is read from the pipe, this can
- cause a large amount of memory to be allocated.
- The -B option disables this automatic allocation of
- buffers for pipes, so that only 64K (or the amount
- of space specified by the -b option) is used for
- the pipe. Warning: use of -B can result in erro­
- neous display, since only the most recently viewed
- part of the file is kept in memory; any earlier
+ By default, when data is read from a pipe, buffers are allocated
+ automatically as needed. If a large amount of data is read from
+ the pipe, this can cause a large amount of memory to be allo-
+ cated. The -B option disables this automatic allocation of
+ buffers for pipes, so that only 64K (or the amount of space
+ specified by the -b option) is used for the pipe. Warning: use
+ of -B can result in erroneous display, since only the most
+ recently viewed part of the file is kept in memory; any earlier
data is lost.
-c or --clear-screen
- Causes full screen repaints to be painted from the
- top line down. By default, full screen repaints
- are done by scrolling from the bottom of the
- screen.
+ Causes full screen repaints to be painted from the top line
+ down. By default, full screen repaints are done by scrolling
+ from the bottom of the screen.
-C or --CLEAR-SCREEN
- The -C option is like -c, but the screen is cleared
- before it is repainted.
+ The -C option is like -c, but the screen is cleared before it is
+ repainted.
-d or --dumb
- The -d option suppresses the error message normally
- displayed if the terminal is dumb; that is, lacks
- some important capability, such as the ability to
- clear the screen or scroll backward. The -d option
- does not otherwise change the behavior of _l_e_s_s on a
+ The -d option suppresses the error message normally displayed if
+ the terminal is dumb; that is, lacks some important capability,
+ such as the ability to clear the screen or scroll backward. The
+ -d option does not otherwise change the behavior of _l_e_s_s on a
dumb terminal.
-Dxx_c_o_l_o_r or --color=xx_c_o_l_o_r
- [MS-DOS only] Sets the color of the text displayed.
- xx is a single character which selects the type of
- text whose color is being set: n=normal, s=stand­
- out, d=bold, u=underlined, k=blink. _c_o_l_o_r is a
- pair of numbers separated by a period. The first
- number selects the foreground color and the second
- selects the background color of the text. A single
- number _N is the same as _N_._0.
-
-
-
- Version 381: 17 Jan 2003 10
-
-
-
-
-
-LESS(1) LESS(1)
-
+ [MS-DOS only] Sets the color of the text displayed. xx is a sin-
+ gle character which selects the type of text whose color is
+ being set: n=normal, s=standout, d=bold, u=underlined, k=blink.
+ _c_o_l_o_r is a pair of numbers separated by a period. The first
+ number selects the foreground color and the second selects the
+ background color of the text. A single number _N is the same as
+ _N_._0.
-e or --quit-at-eof
- Causes _l_e_s_s to automatically exit the second time
- it reaches end-of-file. By default, the only way
- to exit _l_e_s_s is via the "q" command.
+ Causes _l_e_s_s to automatically exit the second time it reaches
+ end-of-file. By default, the only way to exit _l_e_s_s is via the
+ "q" command.
-E or --QUIT-AT-EOF
- Causes _l_e_s_s to automatically exit the first time it
- reaches end-of-file.
+ Causes _l_e_s_s to automatically exit the first time it reaches end-
+ of-file.
-f or --force
- Forces non-regular files to be opened. (A non-reg­
- ular file is a directory or a device special file.)
- Also suppresses the warning message when a binary
- file is opened. By default, _l_e_s_s will refuse to
- open non-regular files.
+ Forces non-regular files to be opened. (A non-regular file is a
+ directory or a device special file.) Also suppresses the warn-
+ ing message when a binary file is opened. By default, _l_e_s_s will
+ refuse to open non-regular files.
-F or --quit-if-one-screen
- Causes _l_e_s_s to automatically exit if the entire
- file can be displayed on the first screen.
+ Causes _l_e_s_s to automatically exit if the entire file can be dis-
+ played on the first screen.
-g or --hilite-search
- Normally, _l_e_s_s will highlight ALL strings which
- match the last search command. The -g option
- changes this behavior to highlight only the partic­
- ular string which was found by the last search com­
- mand. This can cause _l_e_s_s to run somewhat faster
- than the default.
+ Normally, _l_e_s_s will highlight ALL strings which match the last
+ search command. The -g option changes this behavior to high-
+ light only the particular string which was found by the last
+ search command. This can cause _l_e_s_s to run somewhat faster than
+ the default.
-G or --HILITE-SEARCH
- The -G option suppresses all highlighting of
- strings found by search commands.
+ The -G option suppresses all highlighting of strings found by
+ search commands.
- -h_n or ---max-back-scroll=_n
- Specifies a maximum number of lines to scroll back­
- ward. If it is necessary to scroll backward more
- than _n lines, the screen is repainted in a forward
- direction instead. (If the terminal does not have
- the ability to scroll backward, -h0 is implied.)
+ -h_n or --max-back-scroll=_n
+ Specifies a maximum number of lines to scroll backward. If it
+ is necessary to scroll backward more than _n lines, the screen is
+ repainted in a forward direction instead. (If the terminal does
+ not have the ability to scroll backward, -h0 is implied.)
-i or --ignore-case
- Causes searches to ignore case; that is, uppercase
- and lowercase are considered identical. This
- option is ignored if any uppercase letters appear
- in the search pattern; in other words, if a pattern
- contains uppercase letters, then that search does
- not ignore case.
+ Causes searches to ignore case; that is, uppercase and lowercase
+ are considered identical. This option is ignored if any upper-
+ case letters appear in the search pattern; in other words, if a
+ pattern contains uppercase letters, then that search does not
+ ignore case.
-I or --IGNORE-CASE
- Like -i, but searches ignore case even if the pat­
- tern contains uppercase letters.
+ Like -i, but searches ignore case even if the pattern contains
+ uppercase letters.
-j_n or --jump-target=_n
- Specifies a line on the screen where the "target"
- line is to be positioned. A target line is the
-
-
-
- Version 381: 17 Jan 2003 11
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- object of a text search, tag search, jump to a line
- number, jump to a file percentage, or jump to a
- marked position. The screen line is specified by a
- number: the top line on the screen is 1, the next
- is 2, and so on. The number may be negative to
- specify a line relative to the bottom of the
- screen: the bottom line on the screen is -1, the
- second to the bottom is -2, and so on. If the -j
- option is used, searches begin at the line immedi­
- ately after the target line. For example, if "-j4"
- is used, the target line is the fourth line on the
- screen, so searches begin at the fifth line on the
- screen.
+ Specifies a line on the screen where the "target" line is to be
+ positioned. A target line is the object of a text search, tag
+ search, jump to a line number, jump to a file percentage, or
+ jump to a marked position. The screen line is specified by a
+ number: the top line on the screen is 1, the next is 2, and so
+ on. The number may be negative to specify a line relative to
+ the bottom of the screen: the bottom line on the screen is -1,
+ the second to the bottom is -2, and so on. If the -j option is
+ used, searches begin at the line immediately after the target
+ line. For example, if "-j4" is used, the target line is the
+ fourth line on the screen, so searches begin at the fifth line
+ on the screen.
-J or --status-column
- Displays a status column at the left edge of the
- screen. The status column shows the lines that
- matched the current search. The status column is
- also used if the -w or -W option is in effect.
+ Displays a status column at the left edge of the screen. The
+ status column shows the lines that matched the current search.
+ The status column is also used if the -w or -W option is in
+ effect.
-k_f_i_l_e_n_a_m_e or --lesskey-file=_f_i_l_e_n_a_m_e
- Causes _l_e_s_s to open and interpret the named file as
- a _l_e_s_s_k_e_y (1) file. Multiple -k options may be
- specified. If the LESSKEY or LESSKEY_SYSTEM envi­
- ronment variable is set, or if a lesskey file is
- found in a standard place (see KEY BINDINGS), it is
- also used as a _l_e_s_s_k_e_y file.
+ Causes _l_e_s_s to open and interpret the named file as a _l_e_s_s_k_e_y
+ (1) file. Multiple -k options may be specified. If the LESSKEY
+ or LESSKEY_SYSTEM environment variable is set, or if a lesskey
+ file is found in a standard place (see KEY BINDINGS), it is also
+ used as a _l_e_s_s_k_e_y file.
+
+ -K or --quit-on-intr
+ Causes _l_e_s_s to exit immediately when an interrupt character
+ (usually ^C) is typed. Normally, an interrupt character causes
+ _l_e_s_s to stop whatever it is doing and return to its command
+ prompt.
-L or --no-lessopen
- Ignore the LESSOPEN environment variable (see the
- INPUT PREPROCESSOR section below). This option can
- be set from within _l_e_s_s, but it will apply only to
- files opened subsequently, not to the file which is
- currently open.
+ Ignore the LESSOPEN environment variable (see the INPUT PREPRO-
+ CESSOR section below). This option can be set from within _l_e_s_s,
+ but it will apply only to files opened subsequently, not to the
+ file which is currently open.
-m or --long-prompt
- Causes _l_e_s_s to prompt verbosely (like _m_o_r_e), with
- the percent into the file. By default, _l_e_s_s
- prompts with a colon.
+ Causes _l_e_s_s to prompt verbosely (like _m_o_r_e), with the percent
+ into the file. By default, _l_e_s_s prompts with a colon.
-M or --LONG-PROMPT
- Causes _l_e_s_s to prompt even more verbosely than
- _m_o_r_e_.
+ Causes _l_e_s_s to prompt even more verbosely than _m_o_r_e_.
-n or --line-numbers
- Suppresses line numbers. The default (to use line
- numbers) may cause _l_e_s_s to run more slowly in some
- cases, especially with a very large input file.
- Suppressing line numbers with the -n option will
- avoid this problem. Using line numbers means: the
- line number will be displayed in the verbose prompt
- and in the = command, and the v command will pass
- the current line number to the editor (see also the
- discussion of LESSEDIT in PROMPTS below).
-
-
-
- Version 381: 17 Jan 2003 12
-
-
-
-
-
-LESS(1) LESS(1)
-
+ Suppresses line numbers. The default (to use line numbers) may
+ cause _l_e_s_s to run more slowly in some cases, especially with a
+ very large input file. Suppressing line numbers with the -n
+ option will avoid this problem. Using line numbers means: the
+ line number will be displayed in the verbose prompt and in the =
+ command, and the v command will pass the current line number to
+ the editor (see also the discussion of LESSEDIT in PROMPTS
+ below).
-N or --LINE-NUMBERS
- Causes a line number to be displayed at the begin­
- ning of each line in the display.
+ Causes a line number to be displayed at the beginning of each
+ line in the display.
-o_f_i_l_e_n_a_m_e or --log-file=_f_i_l_e_n_a_m_e
- Causes _l_e_s_s to copy its input to the named file as
- it is being viewed. This applies only when the
- input file is a pipe, not an ordinary file. If the
- file already exists, _l_e_s_s will ask for confirmation
- before overwriting it.
+ Causes _l_e_s_s to copy its input to the named file as it is being
+ viewed. This applies only when the input file is a pipe, not an
+ ordinary file. If the file already exists, _l_e_s_s will ask for
+ confirmation before overwriting it.
-O_f_i_l_e_n_a_m_e or --LOG-FILE=_f_i_l_e_n_a_m_e
- The -O option is like -o, but it will overwrite an
- existing file without asking for confirmation.
+ The -O option is like -o, but it will overwrite an existing file
+ without asking for confirmation.
- If no log file has been specified, the -o and -O
- options can be used from within _l_e_s_s to specify a
- log file. Without a file name, they will simply
- report the name of the log file. The "s" command
- is equivalent to specifying -o from within _l_e_s_s_.
+ If no log file has been specified, the -o and -O options can be
+ used from within _l_e_s_s to specify a log file. Without a file
+ name, they will simply report the name of the log file. The "s"
+ command is equivalent to specifying -o from within _l_e_s_s_.
-p_p_a_t_t_e_r_n or --pattern=_p_a_t_t_e_r_n
- The -p option on the command line is equivalent to
- specifying +/_p_a_t_t_e_r_n; that is, it tells _l_e_s_s to
- start at the first occurrence of _p_a_t_t_e_r_n in the
- file.
+ The -p option on the command line is equivalent to specifying
+ +/_p_a_t_t_e_r_n; that is, it tells _l_e_s_s to start at the first occur-
+ rence of _p_a_t_t_e_r_n in the file.
-P_p_r_o_m_p_t or --prompt=_p_r_o_m_p_t
- Provides a way to tailor the three prompt styles to
- your own preference. This option would normally be
- put in the LESS environment variable, rather than
- being typed in with each _l_e_s_s command. Such an
- option must either be the last option in the LESS
- variable, or be terminated by a dollar sign. -Ps
- followed by a string changes the default (short)
- prompt to that string. -Pm changes the medium (-m)
- prompt. -PM changes the long (-M) prompt. -Ph
- changes the prompt for the help screen. -P=
- changes the message printed by the = command. -Pw
- changes the message printed while waiting for data
- (in the F command). All prompt strings consist of
- a sequence of letters and special escape sequences.
- See the section on PROMPTS for more details.
+ Provides a way to tailor the three prompt styles to your own
+ preference. This option would normally be put in the LESS envi-
+ ronment variable, rather than being typed in with each _l_e_s_s com-
+ mand. Such an option must either be the last option in the LESS
+ variable, or be terminated by a dollar sign. -Ps followed by a
+ string changes the default (short) prompt to that string. -Pm
+ changes the medium (-m) prompt. -PM changes the long (-M)
+ prompt. -Ph changes the prompt for the help screen. -P=
+ changes the message printed by the = command. -Pw changes the
+ message printed while waiting for data (in the F command). All
+ prompt strings consist of a sequence of letters and special
+ escape sequences. See the section on PROMPTS for more details.
-q or --quiet or --silent
- Causes moderately "quiet" operation: the terminal
- bell is not rung if an attempt is made to scroll
- past the end of the file or before the beginning of
- the file. If the terminal has a "visual bell", it
- is used instead. The bell will be rung on certain
- other errors, such as typing an invalid character.
- The default is to ring the terminal bell in all
- such cases.
-
-
-
-
- Version 381: 17 Jan 2003 13
-
-
-
-
-
-LESS(1) LESS(1)
-
+ Causes moderately "quiet" operation: the terminal bell is not
+ rung if an attempt is made to scroll past the end of the file or
+ before the beginning of the file. If the terminal has a "visual
+ bell", it is used instead. The bell will be rung on certain
+ other errors, such as typing an invalid character. The default
+ is to ring the terminal bell in all such cases.
-Q or --QUIET or --SILENT
- Causes totally "quiet" operation: the terminal bell
- is never rung.
+ Causes totally "quiet" operation: the terminal bell is never
+ rung.
-r or --raw-control-chars
- Causes "raw" control characters to be displayed.
- The default is to display control characters using
- the caret notation; for example, a control-A (octal
- 001) is displayed as "^A". Warning: when the -r
- option is used, _l_e_s_s cannot keep track of the
- actual appearance of the screen (since this depends
- on how the screen responds to each type of control
- character). Thus, various display problems may
- result, such as long lines being split in the wrong
- place.
+ Causes "raw" control characters to be displayed. The default is
+ to display control characters using the caret notation; for
+ example, a control-A (octal 001) is displayed as "^A". Warning:
+ when the -r option is used, _l_e_s_s cannot keep track of the actual
+ appearance of the screen (since this depends on how the screen
+ responds to each type of control character). Thus, various dis-
+ play problems may result, such as long lines being split in the
+ wrong place.
-R or --RAW-CONTROL-CHARS
- Like -r, but tries to keep track of the screen
- appearance where possible. This works only if the
- input consists of normal text and possibly some
- ANSI "color" escape sequences, which are sequences
- of the form:
+ Like -r, but only ANSI "color" escape sequences are output in
+ "raw" form. Unlike -r, the screen appearance is maintained cor-
+ rectly in most cases. ANSI "color" escape sequences are
+ sequences of the form:
ESC [ ... m
- where the "..." is zero or more characters other
- than "m". For the purpose of keeping track of
- screen appearance, all control characters and all
- ANSI color escape sequences are assumed to not move
- the cursor. You can make _l_e_s_s think that charac­
- ters other than "m" can end ANSI color escape
- sequences by setting the environment variable
- LESSANSIENDCHARS to the list of characters which
- can end a color escape sequence.
+ where the "..." is zero or more color specification characters
+ For the purpose of keeping track of screen appearance, ANSI
+ color escape sequences are assumed to not move the cursor. You
+ can make _l_e_s_s think that characters other than "m" can end ANSI
+ color escape sequences by setting the environment variable
+ LESSANSIENDCHARS to the list of characters which can end a color
+ escape sequence. And you can make _l_e_s_s think that characters
+ other than the standard ones may appear between the ESC and the
+ m by setting the environment variable LESSANSIMIDCHARS to the
+ list of characters which can appear.
-s or --squeeze-blank-lines
- Causes consecutive blank lines to be squeezed into
- a single blank line. This is useful when viewing
- _n_r_o_f_f output.
+ Causes consecutive blank lines to be squeezed into a single
+ blank line. This is useful when viewing _n_r_o_f_f output.
-S or --chop-long-lines
- Causes lines longer than the screen width to be
- chopped rather than folded. That is, the portion
- of a long line that does not fit in the screen
- width is not shown. The default is to fold long
- lines; that is, display the remainder on the next
- line.
+ Causes lines longer than the screen width to be chopped rather
+ than folded. That is, the portion of a long line that does not
+ fit in the screen width is not shown. The default is to fold
+ long lines; that is, display the remainder on the next line.
-t_t_a_g or --tag=_t_a_g
- The -t option, followed immediately by a TAG, will
- edit the file containing that tag. For this to
- work, tag information must be available; for exam­
- ple, there may be a file in the current directory
- called "tags", which was previously built by _c_t_a_g_s
-
-
-
- Version 381: 17 Jan 2003 14
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- (1) or an equivalent command. If the environment
- variable LESSGLOBALTAGS is set, it is taken to be
- the name of a command compatible with _g_l_o_b_a_l (1),
- and that command is executed to find the tag. (See
- http://www.gnu.org/software/global/global.html).
- The -t option may also be specified from within
- _l_e_s_s (using the - command) as a way of examining a
- new file. The command ":t" is equivalent to speci­
- fying -t from within _l_e_s_s_.
+ The -t option, followed immediately by a TAG, will edit the file
+ containing that tag. For this to work, tag information must be
+ available; for example, there may be a file in the current
+ directory called "tags", which was previously built by _c_t_a_g_s (1)
+ or an equivalent command. If the environment variable LESSGLOB-
+ ALTAGS is set, it is taken to be the name of a command compati-
+ ble with _g_l_o_b_a_l (1), and that command is executed to find the
+ tag. (See http://www.gnu.org/software/global/global.html). The
+ -t option may also be specified from within _l_e_s_s (using the -
+ command) as a way of examining a new file. The command ":t" is
+ equivalent to specifying -t from within _l_e_s_s_.
-T_t_a_g_s_f_i_l_e or --tag-file=_t_a_g_s_f_i_l_e
Specifies a tags file to be used instead of "tags".
-u or --underline-special
- Causes backspaces and carriage returns to be
- treated as printable characters; that is, they are
- sent to the terminal when they appear in the input.
+ Causes backspaces and carriage returns to be treated as print-
+ able characters; that is, they are sent to the terminal when
+ they appear in the input.
-U or --UNDERLINE-SPECIAL
- Causes backspaces, tabs and carriage returns to be
- treated as control characters; that is, they are
- handled as specified by the -r option.
-
- By default, if neither -u nor -U is given,
- backspaces which appear adjacent to an underscore
- character are treated specially: the underlined
- text is displayed using the terminal's hardware
- underlining capability. Also, backspaces which
- appear between two identical characters are treated
- specially: the overstruck text is printed using the
- terminal's hardware boldface capability. Other
- backspaces are deleted, along with the preceding
- character. Carriage returns immediately followed
- by a newline are deleted. other carriage returns
- are handled as specified by the -r option. Text
- which is overstruck or underlined can be searched
- for if neither -u nor -U is in effect.
+ Causes backspaces, tabs and carriage returns to be treated as
+ control characters; that is, they are handled as specified by
+ the -r option.
+
+ By default, if neither -u nor -U is given, backspaces which
+ appear adjacent to an underscore character are treated spe-
+ cially: the underlined text is displayed using the terminal's
+ hardware underlining capability. Also, backspaces which appear
+ between two identical characters are treated specially: the
+ overstruck text is printed using the terminal's hardware bold-
+ face capability. Other backspaces are deleted, along with the
+ preceding character. Carriage returns immediately followed by a
+ newline are deleted. other carriage returns are handled as
+ specified by the -r option. Text which is overstruck or under-
+ lined can be searched for if neither -u nor -U is in effect.
-V or --version
Displays the version number of _l_e_s_s_.
-w or --hilite-unread
- Temporarily highlights the first "new" line after a
- forward movement of a full page. The first "new"
- line is the line immediately following the line
- previously at the bottom of the screen. Also high­
- lights the target line after a g or p command. The
- highlight is removed at the next command which
- causes movement. The entire line is highlighted,
- unless the -J option is in effect, in which case
- only the status column is highlighted.
+ Temporarily highlights the first "new" line after a forward
+ movement of a full page. The first "new" line is the line imme-
+ diately following the line previously at the bottom of the
+ screen. Also highlights the target line after a g or p command.
+ The highlight is removed at the next command which causes move-
+ ment. The entire line is highlighted, unless the -J option is
+ in effect, in which case only the status column is highlighted.
-W or --HILITE-UNREAD
- Like -w, but temporarily highlights the first new
-
-
-
- Version 381: 17 Jan 2003 15
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- line after any forward movement command larger than
- one line.
+ Like -w, but temporarily highlights the first new line after any
+ forward movement command larger than one line.
-x_n,... or --tabs=_n,...
- Sets tab stops. If only one _n is specified, tab
- stops are set at multiples of _n. If multiple val­
- ues separated by commas are specified, tab stops
- are set at those positions, and then continue with
- the same spacing as the last two. For example,
- _-_x_9_,_1_7 will set tabs at positions 9, 17, 25, 33,
- etc. The default for _n is 8.
+ Sets tab stops. If only one _n is specified, tab stops are set
+ at multiples of _n. If multiple values separated by commas are
+ specified, tab stops are set at those positions, and then con-
+ tinue with the same spacing as the last two. For example,
+ _-_x_9_,_1_7 will set tabs at positions 9, 17, 25, 33, etc. The
+ default for _n is 8.
-X or --no-init
- Disables sending the termcap initialization and
- deinitialization strings to the terminal. This is
- sometimes desirable if the deinitialization string
- does something unnecessary, like clearing the
- screen.
+ Disables sending the termcap initialization and deinitialization
+ strings to the terminal. This is sometimes desirable if the
+ deinitialization string does something unnecessary, like clear-
+ ing the screen.
--no-keypad
- Disables sending the keypad initialization and
- deinitialization strings to the terminal. This is
- sometimes useful if the keypad strings make the
- numeric keypad behave in an undesirable manner.
+ Disables sending the keypad initialization and deinitialization
+ strings to the terminal. This is sometimes useful if the keypad
+ strings make the numeric keypad behave in an undesirable manner.
-y_n or --max-forw-scroll=_n
- Specifies a maximum number of lines to scroll for­
- ward. If it is necessary to scroll forward more
- than _n lines, the screen is repainted instead. The
- -c or -C option may be used to repaint from the top
- of the screen if desired. By default, any forward
+ Specifies a maximum number of lines to scroll forward. If it is
+ necessary to scroll forward more than _n lines, the screen is
+ repainted instead. The -c or -C option may be used to repaint
+ from the top of the screen if desired. By default, any forward
movement causes scrolling.
-[z]_n or --window=_n
- Changes the default scrolling window size to _n
- lines. The default is one screenful. The z and w
- commands can also be used to change the window
- size. The "z" may be omitted for compatibility
- with _m_o_r_e_. If the number _n is negative, it indi­
- cates _n lines less than the current screen size.
- For example, if the screen is 24 lines, _-_z_-_4 sets
- the scrolling window to 20 lines. If the screen is
- resized to 40 lines, the scrolling window automati­
- cally changes to 36 lines.
+ Changes the default scrolling window size to _n lines. The
+ default is one screenful. The z and w commands can also be used
+ to change the window size. The "z" may be omitted for compati-
+ bility with _m_o_r_e_. If the number _n is negative, it indicates _n
+ lines less than the current screen size. For example, if the
+ screen is 24 lines, _-_z_-_4 sets the scrolling window to 20 lines.
+ If the screen is resized to 40 lines, the scrolling window auto-
+ matically changes to 36 lines.
-_"_c_c or --quotes=_c_c
- Changes the filename quoting character. This may
- be necessary if you are trying to name a file which
- contains both spaces and quote characters. Fol­
- lowed by a single character, this changes the quote
- character to that character. Filenames containing
- a space should then be surrounded by that character
- rather than by double quotes. Followed by two
- characters, changes the open quote to the first
-
-
-
- Version 381: 17 Jan 2003 16
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- character, and the close quote to the second char­
- acter. Filenames containing a space should then be
- preceded by the open quote character and followed
- by the close quote character. Note that even after
- the quote characters are changed, this option
- remains -" (a dash followed by a double quote).
+ Changes the filename quoting character. This may be necessary
+ if you are trying to name a file which contains both spaces and
+ quote characters. Followed by a single character, this changes
+ the quote character to that character. Filenames containing a
+ space should then be surrounded by that character rather than by
+ double quotes. Followed by two characters, changes the open
+ quote to the first character, and the close quote to the second
+ character. Filenames containing a space should then be preceded
+ by the open quote character and followed by the close quote
+ character. Note that even after the quote characters are
+ changed, this option remains -" (a dash followed by a double
+ quote).
-~ or --tilde
- Normally lines after end of file are displayed as a
- single tilde (~). This option causes lines after
- end of file to be displayed as blank lines.
+ Normally lines after end of file are displayed as a single tilde
+ (~). This option causes lines after end of file to be displayed
+ as blank lines.
-# or --shift
- Specifies the default number of positions to scroll
- horizontally in the RIGHTARROW and LEFTARROW com­
- mands. If the number specified is zero, it sets
- the default number of positions to one half of the
- screen width.
-
- -- A command line argument of "--" marks the end of
- option arguments. Any arguments following this are
- interpreted as filenames. This can be useful when
- viewing a file whose name begins with a "-" or "+".
-
- + If a command line option begins with ++, the remain­
- der of that option is taken to be an initial com­
- mand to _l_e_s_s_. For example, +G tells _l_e_s_s to start
- at the end of the file rather than the beginning,
- and +/xyz tells it to start at the first occurrence
- of "xyz" in the file. As a special case, +<number>
- acts like +<number>g; that is, it starts the dis­
- play at the specified line number (however, see the
- caveat under the "g" command above). If the option
- starts with ++, the initial command applies to
- every file being viewed, not just the first one.
- The + command described previously may also be used
- to set (or change) an initial command for every
- file.
+ Specifies the default number of positions to scroll horizontally
+ in the RIGHTARROW and LEFTARROW commands. If the number speci-
+ fied is zero, it sets the default number of positions to one
+ half of the screen width.
+
+ -- A command line argument of "--" marks the end of option argu-
+ ments. Any arguments following this are interpreted as file-
+ names. This can be useful when viewing a file whose name begins
+ with a "-" or "+".
+
+ + If a command line option begins with ++, the remainder of that
+ option is taken to be an initial command to _l_e_s_s_. For example,
+ +G tells _l_e_s_s to start at the end of the file rather than the
+ beginning, and +/xyz tells it to start at the first occurrence
+ of "xyz" in the file. As a special case, +<number> acts like
+ +<number>g; that is, it starts the display at the specified line
+ number (however, see the caveat under the "g" command above).
+ If the option starts with ++, the initial command applies to
+ every file being viewed, not just the first one. The + command
+ described previously may also be used to set (or change) an ini-
+ tial command for every file.
LLIINNEE EEDDIITTIINNGG
- When entering command line at the bottom of the screen
- (for example, a filename for the :e command, or the pat­
- tern for a search command), certain keys can be used to
- manipulate the command line. Most commands have an alter­
- nate form in [ brackets ] which can be used if a key does
- not exist on a particular keyboard. (The bracketed forms
- do not work in the MS-DOS version.) Any of these special
- keys may be entered literally by preceding it with the
- "literal" character, either ^V or ^A. A backslash itself
- may also be entered literally by entering two backslashes.
+ When entering command line at the bottom of the screen (for example, a
+ filename for the :e command, or the pattern for a search command),
+ certain keys can be used to manipulate the command line. Most commands
+ have an alternate form in [ brackets ] which can be used if a key does
+ not exist on a particular keyboard. (The bracketed forms do not work
+ in the MS-DOS version.) Any of these special keys may be entered lit-
+ erally by preceding it with the "literal" character, either ^V or ^A.
+ A backslash itself may also be entered literally by entering two back-
+ slashes.
LEFTARROW [ ESC-h ]
Move the cursor one space to the left.
-
-
- Version 381: 17 Jan 2003 17
-
-
-
-
-
-LESS(1) LESS(1)
-
-
RIGHTARROW [ ESC-l ]
Move the cursor one space to the right.
^LEFTARROW [ ESC-b or ESC-LEFTARROW ]
- (That is, CONTROL and LEFTARROW simultaneously.)
- Move the cursor one word to the left.
+ (That is, CONTROL and LEFTARROW simultaneously.) Move the cur-
+ sor one word to the left.
^RIGHTARROW [ ESC-w or ESC-RIGHTARROW ]
- (That is, CONTROL and RIGHTARROW simultaneously.)
- Move the cursor one word to the right.
+ (That is, CONTROL and RIGHTARROW simultaneously.) Move the cur-
+ sor one word to the right.
HOME [ ESC-0 ]
Move the cursor to the beginning of the line.
@@ -1144,19 +839,19 @@ LESS(1) LESS(1)
Move the cursor to the end of the line.
BACKSPACE
- Delete the character to the left of the cursor, or
- cancel the command if the command line is empty.
+ Delete the character to the left of the cursor, or cancel the
+ command if the command line is empty.
DELETE or [ ESC-x ]
Delete the character under the cursor.
^BACKSPACE [ ESC-BACKSPACE ]
- (That is, CONTROL and BACKSPACE simultaneously.)
- Delete the word to the left of the cursor.
+ (That is, CONTROL and BACKSPACE simultaneously.) Delete the
+ word to the left of the cursor.
^DELETE [ ESC-X or ESC-DELETE ]
- (That is, CONTROL and DELETE simultaneously.)
- Delete the word under the cursor.
+ (That is, CONTROL and DELETE simultaneously.) Delete the word
+ under the cursor.
UPARROW [ ESC-k ]
Retrieve the previous command line.
@@ -1164,143 +859,102 @@ LESS(1) LESS(1)
DOWNARROW [ ESC-j ]
Retrieve the next command line.
- TAB Complete the partial filename to the left of the
- cursor. If it matches more than one filename, the
- first match is entered into the command line.
- Repeated TABs will cycle thru the other matching
- filenames. If the completed filename is a direc­
- tory, a "/" is appended to the filename. (On MS-
- DOS systems, a "\" is appended.) The environment
- variable LESSSEPARATOR can be used to specify a
- different character to append to a directory name.
+ TAB Complete the partial filename to the left of the cursor. If it
+ matches more than one filename, the first match is entered into
+ the command line. Repeated TABs will cycle thru the other
+ matching filenames. If the completed filename is a directory, a
+ "/" is appended to the filename. (On MS-DOS systems, a "\" is
+ appended.) The environment variable LESSSEPARATOR can be used
+ to specify a different character to append to a directory name.
BACKTAB [ ESC-TAB ]
- Like, TAB, but cycles in the reverse direction thru
- the matching filenames.
-
- ^L Complete the partial filename to the left of the
- cursor. If it matches more than one filename, all
+ Like, TAB, but cycles in the reverse direction thru the matching
+ filenames.
-
-
- Version 381: 17 Jan 2003 18
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- matches are entered into the command line (if they
- fit).
+ ^L Complete the partial filename to the left of the cursor. If it
+ matches more than one filename, all matches are entered into the
+ command line (if they fit).
^U (Unix and OS/2) or ESC (MS-DOS)
- Delete the entire command line, or cancel the com­
- mand if the command line is empty. If you have
- changed your line-kill character in Unix to some­
- thing other than ^U, that character is used instead
- of ^U.
+ Delete the entire command line, or cancel the command if the
+ command line is empty. If you have changed your line-kill char-
+ acter in Unix to something other than ^U, that character is used
+ instead of ^U.
KKEEYY BBIINNDDIINNGGSS
- You may define your own _l_e_s_s commands by using the program
- _l_e_s_s_k_e_y (1) to create a lesskey file. This file specifies
- a set of command keys and an action associated with each
- key. You may also use _l_e_s_s_k_e_y to change the line-editing
- keys (see LINE EDITING), and to set environment variables.
- If the environment variable LESSKEY is set, _l_e_s_s uses that
- as the name of the lesskey file. Otherwise, _l_e_s_s looks in
- a standard place for the lesskey file: On Unix systems,
- _l_e_s_s looks for a lesskey file called "$HOME/.less". On
- MS-DOS and Windows systems, _l_e_s_s looks for a lesskey file
- called "$HOME/_less", and if it is not found there, then
- looks for a lesskey file called "_less" in any directory
- specified in the PATH environment variable. On OS/2 sys­
- tems, _l_e_s_s looks for a lesskey file called
- "$HOME/less.ini", and if it is not found, then looks for a
- lesskey file called "less.ini" in any directory specified
- in the INIT environment variable, and if it not found
- there, then looks for a lesskey file called "less.ini" in
- any directory specified in the PATH environment variable.
- See the _l_e_s_s_k_e_y manual page for more details.
-
- A system-wide lesskey file may also be set up to provide
- key bindings. If a key is defined in both a local lesskey
- file and in the system-wide file, key bindings in the
- local file take precedence over those in the system-wide
- file. If the environment variable LESSKEY_SYSTEM is set,
- _l_e_s_s uses that as the name of the system-wide lesskey
- file. Otherwise, _l_e_s_s looks in a standard place for the
- system-wide lesskey file: On Unix systems, the system-wide
- lesskey file is /usr/local/etc/sysless. (However, if _l_e_s_s
- was built with a different sysconf directory than
- /usr/local/etc, that directory is where the sysless file
- is found.) On MS-DOS and Windows systems, the system-wide
- lesskey file is c:\_sysless. On OS/2 systems, the system-
- wide lesskey file is c:\sysless.ini.
-
-
-IINNPPUUTT PPRREEPPRROOCCEESSSSOORR
- You may define an "input preprocessor" for _l_e_s_s_. Before
- _l_e_s_s opens a file, it first gives your input preprocessor
- a chance to modify the way the contents of the file are
- displayed. An input preprocessor is simply an executable
-
-
-
- Version 381: 17 Jan 2003 19
-
-
-
-
-
-LESS(1) LESS(1)
+ You may define your own _l_e_s_s commands by using the program _l_e_s_s_k_e_y (1)
+ to create a lesskey file. This file specifies a set of command keys
+ and an action associated with each key. You may also use _l_e_s_s_k_e_y to
+ change the line-editing keys (see LINE EDITING), and to set environment
+ variables. If the environment variable LESSKEY is set, _l_e_s_s uses that
+ as the name of the lesskey file. Otherwise, _l_e_s_s looks in a standard
+ place for the lesskey file: On Unix systems, _l_e_s_s looks for a lesskey
+ file called "$HOME/.less". On MS-DOS and Windows systems, _l_e_s_s looks
+ for a lesskey file called "$HOME/_less", and if it is not found there,
+ then looks for a lesskey file called "_less" in any directory specified
+ in the PATH environment variable. On OS/2 systems, _l_e_s_s looks for a
+ lesskey file called "$HOME/less.ini", and if it is not found, then
+ looks for a lesskey file called "less.ini" in any directory specified
+ in the INIT environment variable, and if it not found there, then looks
+ for a lesskey file called "less.ini" in any directory specified in the
+ PATH environment variable. See the _l_e_s_s_k_e_y manual page for more
+ details.
+ A system-wide lesskey file may also be set up to provide key bindings.
+ If a key is defined in both a local lesskey file and in the system-wide
+ file, key bindings in the local file take precedence over those in the
+ system-wide file. If the environment variable LESSKEY_SYSTEM is set,
+ _l_e_s_s uses that as the name of the system-wide lesskey file. Otherwise,
+ _l_e_s_s looks in a standard place for the system-wide lesskey file: On
+ Unix systems, the system-wide lesskey file is /usr/local/etc/sysless.
+ (However, if _l_e_s_s was built with a different sysconf directory than
+ /usr/local/etc, that directory is where the sysless file is found.) On
+ MS-DOS and Windows systems, the system-wide lesskey file is c:\_sys-
+ less. On OS/2 systems, the system-wide lesskey file is c:\sysless.ini.
- program (or shell script), which writes the contents of
- the file to a different file, called the replacement file.
- The contents of the replacement file are then displayed in
- place of the contents of the original file. However, it
- will appear to the user as if the original file is opened;
- that is, _l_e_s_s will display the original filename as the
- name of the current file.
- An input preprocessor receives one command line argument,
- the original filename, as entered by the user. It should
- create the replacement file, and when finished, print the
- name of the replacement file to its standard output. If
- the input preprocessor does not output a replacement file­
- name, _l_e_s_s uses the original file, as normal. The input
- preprocessor is not called when viewing standard input.
- To set up an input preprocessor, set the LESSOPEN environ­
- ment variable to a command line which will invoke your
- input preprocessor. This command line should include one
- occurrence of the string "%s", which will be replaced by
- the filename when the input preprocessor command is
+IINNPPUUTT PPRREEPPRROOCCEESSSSOORR
+ You may define an "input preprocessor" for _l_e_s_s_. Before _l_e_s_s opens a
+ file, it first gives your input preprocessor a chance to modify the way
+ the contents of the file are displayed. An input preprocessor is sim-
+ ply an executable program (or shell script), which writes the contents
+ of the file to a different file, called the replacement file. The con-
+ tents of the replacement file are then displayed in place of the con-
+ tents of the original file. However, it will appear to the user as if
+ the original file is opened; that is, _l_e_s_s will display the original
+ filename as the name of the current file.
+
+ An input preprocessor receives one command line argument, the original
+ filename, as entered by the user. It should create the replacement
+ file, and when finished, print the name of the replacement file to its
+ standard output. If the input preprocessor does not output a replace-
+ ment filename, _l_e_s_s uses the original file, as normal. The input pre-
+ processor is not called when viewing standard input. To set up an
+ input preprocessor, set the LESSOPEN environment variable to a command
+ line which will invoke your input preprocessor. This command line
+ should include one occurrence of the string "%s", which will be
+ replaced by the filename when the input preprocessor command is
invoked.
- When _l_e_s_s closes a file opened in such a way, it will call
- another program, called the input postprocessor, which may
- perform any desired clean-up action (such as deleting the
- replacement file created by LESSOPEN). This program
- receives two command line arguments, the original filename
- as entered by the user, and the name of the replacement
- file. To set up an input postprocessor, set the LESSCLOSE
- environment variable to a command line which will invoke
- your input postprocessor. It may include two occurrences
- of the string "%s"; the first is replaced with the origi­
- nal name of the file and the second with the name of the
- replacement file, which was output by LESSOPEN.
-
- For example, on many Unix systems, these two scripts will
- allow you to keep files in compressed format, but still
- let _l_e_s_s view them directly:
+ When _l_e_s_s closes a file opened in such a way, it will call another pro-
+ gram, called the input postprocessor, which may perform any desired
+ clean-up action (such as deleting the replacement file created by
+ LESSOPEN). This program receives two command line arguments, the orig-
+ inal filename as entered by the user, and the name of the replacement
+ file. To set up an input postprocessor, set the LESSCLOSE environment
+ variable to a command line which will invoke your input postprocessor.
+ It may include two occurrences of the string "%s"; the first is
+ replaced with the original name of the file and the second with the
+ name of the replacement file, which was output by LESSOPEN.
+
+ For example, on many Unix systems, these two scripts will allow you to
+ keep files in compressed format, but still let _l_e_s_s view them directly:
lessopen.sh:
#! /bin/sh
case "$1" in
- *.Z) uncompress -c $1 >/tmp/less.$$ 2>/dev/null
+ *.Z) uncompress -
if [ -s /tmp/less.$$ ]; then
echo /tmp/less.$$
else
@@ -1313,40 +967,26 @@ LESS(1) LESS(1)
#! /bin/sh
rm $2
-
-
- Version 381: 17 Jan 2003 20
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- To use these scripts, put them both where they can be exe­
- cuted and set LESSOPEN="lessopen.sh %s", and
- LESSCLOSE="lessclose.sh %s %s". More complex LESSOPEN and
- LESSCLOSE scripts may be written to accept other types of
- compressed files, and so on.
-
- It is also possible to set up an input preprocessor to
- pipe the file data directly to _l_e_s_s_, rather than putting
- the data into a replacement file. This avoids the need to
- decompress the entire file before starting to view it. An
- input preprocessor that works this way is called an input
- pipe. An input pipe, instead of writing the name of a
- replacement file on its standard output, writes the entire
- contents of the replacement file on its standard output.
- If the input pipe does not write any characters on its
- standard output, then there is no replacement file and
- _l_e_s_s uses the original file, as normal. To use an input
- pipe, make the first character in the LESSOPEN environment
- variable a vertical bar (|) to signify that the input pre­
- processor is an input pipe.
-
- For example, on many Unix systems, this script will work
- like the previous example scripts:
+ To use these scripts, put them both where they can be executed and set
+ LESSOPEN="lessopen.sh %s", and LESSCLOSE="lessclose.sh %s %s". More
+ complex LESSOPEN and LESSCLOSE scripts may be written to accept other
+ types of compressed files, and so on.
+
+ It is also possible to set up an input preprocessor to pipe the file
+ data directly to _l_e_s_s_, rather than putting the data into a replacement
+ file. This avoids the need to decompress the entire file before start-
+ ing to view it. An input preprocessor that works this way is called an
+ input pipe. An input pipe, instead of writing the name of a replace-
+ ment file on its standard output, writes the entire contents of the
+ replacement file on its standard output. If the input pipe does not
+ write any characters on its standard output, then there is no replace-
+ ment file and _l_e_s_s uses the original file, as normal. To use an input
+ pipe, make the first character in the LESSOPEN environment variable a
+ vertical bar (|) to signify that the input preprocessor is an input
+ pipe.
+
+ For example, on many Unix systems, this script will work like the pre-
+ vious example scripts:
lesspipe.sh:
#! /bin/sh
@@ -1355,12 +995,11 @@ LESS(1) LESS(1)
;;
esac
- To use this script, put it where it can be executed and
- set LESSOPEN="|lesspipe.sh %s". When an input pipe is
- used, a LESSCLOSE postprocessor can be used, but it is
- usually not necessary since there is no replacement file
- to clean up. In this case, the replacement file name
- passed to the LESSCLOSE postprocessor is "-".
+ To use this script, put it where it can be executed and set
+ LESSOPEN="|lesspipe.sh %s". When an input pipe is used, a LESSCLOSE
+ postprocessor can be used, but it is usually not necessary since there
+ is no replacement file to clean up. In this case, the replacement file
+ name passed to the LESSCLOSE postprocessor is "-".
NNAATTIIOONNAALL CCHHAARRAACCTTEERR SSEETTSS
@@ -1370,39 +1009,26 @@ NNAATTIIOONNAALL CCHHAARRAACCTTEERR SSEETTSS
can be displayed directly to the screen.
control characters
- should not be displayed directly, but are expected
- to be found in ordinary text files (such as
- backspace and tab).
+ should not be displayed directly, but are expected to be found
+ in ordinary text files (such as backspace and tab).
binary characters
- should not be displayed directly and are not
- expected to be found in text files.
+ should not be displayed directly and are not expected to be
+ found in text files.
+ A "character set" is simply a description of which characters are to be
+ considered normal, control, and binary. The LESSCHARSET environment
+ variable may be used to select a character set. Possible values for
+ LESSCHARSET are:
-
-
- Version 381: 17 Jan 2003 21
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- A "character set" is simply a description of which charac­
- ters are to be considered normal, control, and binary.
- The LESSCHARSET environment variable may be used to select
- a character set. Possible values for LESSCHARSET are:
-
- ascii BS, TAB, NL, CR, and formfeed are control charac­
- ters, all chars with values between 32 and 126 are
- normal, and all others are binary.
+ ascii BS, TAB, NL, CR, and formfeed are control characters, all chars
+ with values between 32 and 126 are normal, and all others are
+ binary.
iso8859
- Selects an ISO 8859 character set. This is the
- same as ASCII, except characters between 160 and
- 255 are treated as normal characters.
+ Selects an ISO 8859 character set. This is the same as ASCII,
+ except characters between 160 and 255 are treated as normal
+ characters.
latin1 Same as iso8859.
@@ -1413,48 +1039,36 @@ LESS(1) LESS(1)
ebcdic Selects an EBCDIC character set.
IBM-1047
- Selects an EBCDIC character set used by OS/390 Unix
- Services. This is the EBCDIC analogue of latin1.
- You get similar results by setting either LESS­
- CHARSET=IBM-1047 or LC_CTYPE=en_US in your environ­
- ment.
+ Selects an EBCDIC character set used by OS/390 Unix Services.
+ This is the EBCDIC analogue of latin1. You get similar results
+ by setting either LESSCHARSET=IBM-1047 or LC_CTYPE=en_US in your
+ environment.
koi8-r Selects a Russian character set.
- next Selects a character set appropriate for NeXT com­
- puters.
+ next Selects a character set appropriate for NeXT computers.
- utf-8 Selects the UTF-8 encoding of the ISO 10646 charac­
- ter set.
+ utf-8 Selects the UTF-8 encoding of the ISO 10646 character set.
- In special cases, it may be desired to tailor _l_e_s_s to use
- a character set other than the ones definable by LESS­
- CHARSET. In this case, the environment variable LESS­
- CHARDEF can be used to define a character set. It should
- be set to a string where each character in the string rep­
- resents one character in the character set. The character
- "." is used for a normal character, "c" for control, and
- "b" for binary. A decimal number may be used for repeti­
- tion. For example, "bccc4b." would mean character 0 is
- binary, 1, 2 and 3 are control, 4, 5, 6 and 7 are binary,
- and 8 is normal. All characters after the last are taken
- to be the same as the last, so characters 9 through 255
- would be normal. (This is an example, and does not neces­
- sarily represent any real character set.)
+ windows
+ Selects a character set appropriate for Microsoft Windows (cp
+ 1251).
- This table shows the value of LESSCHARDEF which is equiva­
- lent to each of the possible values for LESSCHARSET:
-
-
-
- Version 381: 17 Jan 2003 22
-
-
-
-
-
-LESS(1) LESS(1)
+ In special cases, it may be desired to tailor _l_e_s_s to use a character
+ set other than the ones definable by LESSCHARSET. In this case, the
+ environment variable LESSCHARDEF can be used to define a character set.
+ It should be set to a string where each character in the string repre-
+ sents one character in the character set. The character "." is used
+ for a normal character, "c" for control, and "b" for binary. A decimal
+ number may be used for repetition. For example, "bccc4b." would mean
+ character 0 is binary, 1, 2 and 3 are control, 4, 5, 6 and 7 are
+ binary, and 8 is normal. All characters after the last are taken to be
+ the same as the last, so characters 9 through 255 would be normal.
+ (This is an example, and does not necessarily represent any real char-
+ acter set.)
+ This table shows the value of LESSCHARDEF which is equivalent to each
+ of the possible values for LESSCHARSET:
ascii 8bcccbcc18b95.b
dos 8bcccbcc12bc5b95.b.
@@ -1467,237 +1081,188 @@ LESS(1) LESS(1)
latin1 8bcccbcc18b95.33b.
next 8bcccbcc18b95.bb125.bb
- If neither LESSCHARSET nor LESSCHARDEF is set, but the
- string "UTF-8" is found in the LC_ALL, LC_TYPE or LANG
- environment variables, then the default character set is
- utf-8.
-
- If that string is not found, but your system supports the
- _s_e_t_l_o_c_a_l_e interface, _l_e_s_s will use setlocale to determine
- the character set. setlocale is controlled by setting the
- LANG or LC_CTYPE environment variables.
-
- Finally, if the _s_e_t_l_o_c_a_l_e interface is also not available,
- the default character set is latin1.
-
- Control and binary characters are displayed in standout
- (reverse video). Each such character is displayed in
- caret notation if possible (e.g. ^A for control-A). Caret
- notation is used only if inverting the 0100 bit results in
- a normal printable character. Otherwise, the character is
- displayed as a hex number in angle brackets. This format
- can be changed by setting the LESSBINFMT environment vari­
- able. LESSBINFMT may begin with a "*" and one character
- to select the display attribute: "*k" is blinking, "*d" is
- bold, "*u" is underlined, "*s" is standout, and "*n" is
- normal. If LESSBINFMT does not begin with a "*", normal
- attribute is assumed. The remainder of LESSBINFMT is a
- string which may include one printf-style escape sequence
- (a % followed by x, X, o, d, etc.). For example, if LESS­
- BINFMT is "*u[%x]", binary characters are displayed in
- underlined hexadecimal surrounded by brackets. The
- default if no LESSBINFMT is specified is "*s<%X>".
+ If neither LESSCHARSET nor LESSCHARDEF is set, but any of the strings
+ "UTF-8", "UTF8", "utf-8" or "utf8" is found in the LC_ALL, LC_TYPE or
+ LANG environment variables, then the default character set is utf-8.
+
+ If that string is not found, but your system supports the _s_e_t_l_o_c_a_l_e
+ interface, _l_e_s_s will use setlocale to determine the character set.
+ setlocale is controlled by setting the LANG or LC_CTYPE environment
+ variables.
+
+ Finally, if the _s_e_t_l_o_c_a_l_e interface is also not available, the default
+ character set is latin1.
+
+ Control and binary characters are displayed in standout (reverse
+ video). Each such character is displayed in caret notation if possible
+ (e.g. ^A for control-A). Caret notation is used only if inverting the
+ 0100 bit results in a normal printable character. Otherwise, the char-
+ acter is displayed as a hex number in angle brackets. This format can
+ be changed by setting the LESSBINFMT environment variable. LESSBINFMT
+ may begin with a "*" and one character to select the display attribute:
+ "*k" is blinking, "*d" is bold, "*u" is underlined, "*s" is standout,
+ and "*n" is normal. If LESSBINFMT does not begin with a "*", normal
+ attribute is assumed. The remainder of LESSBINFMT is a string which
+ may include one printf-style escape sequence (a % followed by x, X, o,
+ d, etc.). For example, if LESSBINFMT is "*u[%x]", binary characters
+ are displayed in underlined hexadecimal surrounded by brackets. The
+ default if no LESSBINFMT is specified is "*s<%X>". The default if no
+ LESSBINFMT is specified is "*s<%02X>". Warning: the result of expand-
+ ing the character via LESSBINFMT must be less than 31 characters.
+
+ When the character set is utf-8, the LESSUTFBINFMT environment variable
+ acts similarly to LESSBINFMT but it applies to Unicode code points that
+ were successfully decoded but are unsuitable for display (e.g., unas-
+ signed code points). Its default value is "<U+%04lX>". Note that
+ LESSUTFBINFMT and LESSBINFMT share their display attribute setting
+ ("*x") so specifying one will affect both; LESSUTFBINFMT is read after
+ LESSBINFMT so its setting, if any, will have priority. Problematic
+ octets in a UTF-8 file (octets of a truncated sequence, octets of a
+ complete but non-shortest form sequence, illegal octets, and stray
+ trailing octets) are displayed individually using LESSBINFMT so as to
+ facilitate diagnostic of how the UTF-8 file is ill-formed.
PPRROOMMPPTTSS
- The -P option allows you to tailor the prompt to your
- preference. The string given to the -P option replaces
- the specified prompt string. Certain characters in the
- string are interpreted specially. The prompt mechanism is
- rather complicated to provide flexibility, but the ordi­
- nary user need not understand the details of constructing
- personalized prompt strings.
-
- A percent sign followed by a single character is expanded
- according to what the following character is:
-
-
-
- Version 381: 17 Jan 2003 23
-
-
-
-
-
-LESS(1) LESS(1)
-
-
- %b_X Replaced by the byte offset into the current input
- file. The b is followed by a single character
- (shown as _X above) which specifies the line whose
- byte offset is to be used. If the character is a
- "t", the byte offset of the top line in the display
- is used, an "m" means use the middle line, a "b"
- means use the bottom line, a "B" means use the line
- just after the bottom line, and a "j" means use the
- "target" line, as specified by the -j option.
+ The -P option allows you to tailor the prompt to your preference. The
+ string given to the -P option replaces the specified prompt string.
+ Certain characters in the string are interpreted specially. The prompt
+ mechanism is rather complicated to provide flexibility, but the ordi-
+ nary user need not understand the details of constructing personalized
+ prompt strings.
+
+ A percent sign followed by a single character is expanded according to
+ what the following character is:
+
+ %b_X Replaced by the byte offset into the current input file. The b
+ is followed by a single character (shown as _X above) which spec-
+ ifies the line whose byte offset is to be used. If the charac-
+ ter is a "t", the byte offset of the top line in the display is
+ used, an "m" means use the middle line, a "b" means use the bot-
+ tom line, a "B" means use the line just after the bottom line,
+ and a "j" means use the "target" line, as specified by the -j
+ option.
%B Replaced by the size of the current input file.
- %c Replaced by the column number of the text appearing
- in the first column of the screen.
+ %c Replaced by the column number of the text appearing in the first
+ column of the screen.
- %d_X Replaced by the page number of a line in the input
- file. The line to be used is determined by the _X,
- as with the %b option.
+ %d_X Replaced by the page number of a line in the input file. The
+ line to be used is determined by the _X, as with the %b option.
- %D Replaced by the number of pages in the input file,
- or equivalently, the page number of the last line
- in the input file.
+ %D Replaced by the number of pages in the input file, or equiva-
+ lently, the page number of the last line in the input file.
- %E Replaced by the name of the editor (from the VISUAL
- environment variable, or the EDITOR environment
- variable if VISUAL is not defined). See the dis­
- cussion of the LESSEDIT feature below.
+ %E Replaced by the name of the editor (from the VISUAL environment
+ variable, or the EDITOR environment variable if VISUAL is not
+ defined). See the discussion of the LESSEDIT feature below.
%f Replaced by the name of the current input file.
- %i Replaced by the index of the current file in the
- list of input files.
+ %i Replaced by the index of the current file in the list of input
+ files.
- %l_X Replaced by the line number of a line in the input
- file. The line to be used is determined by the _X,
- as with the %b option.
+ %l_X Replaced by the line number of a line in the input file. The
+ line to be used is determined by the _X, as with the %b option.
- %L Replaced by the line number of the last line in the
- input file.
+ %L Replaced by the line number of the last line in the input file.
%m Replaced by the total number of input files.
- %p_X Replaced by the percent into the current input
- file, based on byte offsets. The line used is
- determined by the _X as with the %b option.
+ %p_X Replaced by the percent into the current input file, based on
+ byte offsets. The line used is determined by the _X as with the
+ %b option.
- %P_X Replaced by the percent into the current input
- file, based on line numbers. The line used is
- determined by the _X as with the %b option.
+ %P_X Replaced by the percent into the current input file, based on
+ line numbers. The line used is determined by the _X as with the
+ %b option.
%s Same as %B.
- %t Causes any trailing spaces to be removed. Usually
- used at the end of the string, but may appear
-
-
-
- Version 381: 17 Jan 2003 24
+ %t Causes any trailing spaces to be removed. Usually used at the
+ end of the string, but may appear anywhere.
+ %x Replaced by the name of the next input file in the list.
+ If any item is unknown (for example, the file size if input is a pipe),
+ a question mark is printed instead.
+ The format of the prompt string can be changed depending on certain
+ conditions. A question mark followed by a single character acts like
+ an "IF": depending on the following character, a condition is evalu-
+ ated. If the condition is true, any characters following the question
+ mark and condition character, up to a period, are included in the
+ prompt. If the condition is false, such characters are not included.
+ A colon appearing between the question mark and the period can be used
+ to establish an "ELSE": any characters between the colon and the period
+ are included in the string if and only if the IF condition is false.
+ Condition characters (which follow a question mark) may be:
+ ?a True if any characters have been included in the prompt so far.
-LESS(1) LESS(1)
-
-
- anywhere.
-
- %x Replaced by the name of the next input file in the
- list.
-
- If any item is unknown (for example, the file size if
- input is a pipe), a question mark is printed instead.
-
- The format of the prompt string can be changed depending
- on certain conditions. A question mark followed by a sin­
- gle character acts like an "IF": depending on the follow­
- ing character, a condition is evaluated. If the condition
- is true, any characters following the question mark and
- condition character, up to a period, are included in the
- prompt. If the condition is false, such characters are
- not included. A colon appearing between the question mark
- and the period can be used to establish an "ELSE": any
- characters between the colon and the period are included
- in the string if and only if the IF condition is false.
- Condition characters (which follow a question mark) may
- be:
-
- ?a True if any characters have been included in the
- prompt so far.
-
- ?b_X True if the byte offset of the specified line is
- known.
+ ?b_X True if the byte offset of the specified line is known.
?B True if the size of current input file is known.
- ?c True if the text is horizontally shifted (%c is not
- zero).
+ ?c True if the text is horizontally shifted (%c is not zero).
- ?d_X True if the page number of the specified line is
- known.
+ ?d_X True if the page number of the specified line is known.
?e True if at end-of-file.
- ?f True if there is an input filename (that is, if
- input is not a pipe).
+ ?f True if there is an input filename (that is, if input is not a
+ pipe).
- ?l_X True if the line number of the specified line is
- known.
+ ?l_X True if the line number of the specified line is known.
- ?L True if the line number of the last line in the
- file is known.
+ ?L True if the line number of the last line in the file is known.
?m True if there is more than one input file.
- ?n True if this is the first prompt in a new input
- file.
-
- ?p_X True if the percent into the current input file,
- based on byte offsets, of the specified line is
-
-
-
- Version 381: 17 Jan 2003 25
+ ?n True if this is the first prompt in a new input file.
+ ?p_X True if the percent into the current input file, based on byte
+ offsets, of the specified line is known.
-
-
-
-LESS(1) LESS(1)
-
-
- known.
-
- ?P_X True if the percent into the current input file,
- based on line numbers, of the specified line is
- known.
+ ?P_X True if the percent into the current input file, based on line
+ numbers, of the specified line is known.
?s Same as "?B".
- ?x True if there is a next input file (that is, if the
- current input file is not the last one).
+ ?x True if there is a next input file (that is, if the current
+ input file is not the last one).
- Any characters other than the special ones (question mark,
- colon, period, percent, and backslash) become literally
- part of the prompt. Any of the special characters may be
- included in the prompt literally by preceding it with a
- backslash.
+ Any characters other than the special ones (question mark, colon,
+ period, percent, and backslash) become literally part of the prompt.
+ Any of the special characters may be included in the prompt literally
+ by preceding it with a backslash.
Some examples:
?f%f:Standard input.
- This prompt prints the filename, if known; otherwise the
- string "Standard input".
+ This prompt prints the filename, if known; otherwise the string "Stan-
+ dard input".
?f%f .?ltLine %lt:?pt%pt\%:?btByte %bt:-...
- This prompt would print the filename, if known. The file­
- name is followed by the line number, if known, otherwise
- the percent if known, otherwise the byte offset if known.
- Otherwise, a dash is printed. Notice how each question
- mark has a matching period, and how the % after the %pt is
- included literally by escaping it with a backslash.
+ This prompt would print the filename, if known. The filename is fol-
+ lowed by the line number, if known, otherwise the percent if known,
+ otherwise the byte offset if known. Otherwise, a dash is printed.
+ Notice how each question mark has a matching period, and how the %
+ after the %pt is included literally by escaping it with a backslash.
?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\: %x..%t
- This prints the filename if this is the first prompt in a
- file, followed by the "file N of N" message if there is
- more than one input file. Then, if we are at end-of-file,
- the string "(END)" is printed followed by the name of the
- next file, if there is one. Finally, any trailing spaces
- are truncated. This is the default prompt. For refer­
- ence, here are the defaults for the other two prompts (-m
- and -M respectively). Each is broken into two lines here
- for readability only.
+ This prints the filename if this is the first prompt in a file, fol-
+ lowed by the "file N of N" message if there is more than one input
+ file. Then, if we are at end-of-file, the string "(END)" is printed
+ followed by the name of the next file, if there is one. Finally, any
+ trailing spaces are truncated. This is the default prompt. For refer-
+ ence, here are the defaults for the other two prompts (-m and -M
+ respectively). Each is broken into two lines here for readability
+ only.
?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\: %x.:
?pB%pB\%:byte %bB?s/%s...%t
@@ -1708,40 +1273,25 @@ LESS(1) LESS(1)
And here is the default message produced by the = command:
?f%f .?m(file %i of %m) .?ltlines %lt-%lb?L/%L. .
-
-
-
- Version 381: 17 Jan 2003 26
-
-
-
-
-
-LESS(1) LESS(1)
-
-
byte %bB?s/%s. ?e(END) :?pB%pB\%..%t
- The prompt expansion features are also used for another
- purpose: if an environment variable LESSEDIT is defined,
- it is used as the command to be executed when the v com­
- mand is invoked. The LESSEDIT string is expanded in the
- same way as the prompt strings. The default value for
+ The prompt expansion features are also used for another purpose: if an
+ environment variable LESSEDIT is defined, it is used as the command to
+ be executed when the v command is invoked. The LESSEDIT string is
+ expanded in the same way as the prompt strings. The default value for
LESSEDIT is:
%E ?lm+%lm. %f
- Note that this expands to the editor name, followed by a +
- and the line number, followed by the file name. If your
- editor does not accept the "+linenumber" syntax, or has
- other differences in invocation syntax, the LESSEDIT vari­
- able can be changed to modify this default.
+ Note that this expands to the editor name, followed by a + and the line
+ number, followed by the file name. If your editor does not accept the
+ "+linenumber" syntax, or has other differences in invocation syntax,
+ the LESSEDIT variable can be changed to modify this default.
SSEECCUURRIITTYY
- When the environment variable LESSSECURE is set to 1, _l_e_s_s
- runs in a "secure" mode. This means these features are
- disabled:
+ When the environment variable LESSSECURE is set to 1, _l_e_s_s runs in a
+ "secure" mode. This means these features are disabled:
! the shell command
@@ -1761,53 +1311,36 @@ SSEECCUURRIITTYY
filename completion (TAB, ^L)
- Less can also be compiled to be permanently in "secure"
- mode.
+ Less can also be compiled to be permanently in "secure" mode.
EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
- Environment variables may be specified either in the sys­
- tem environment as usual, or in a _l_e_s_s_k_e_y (1) file. If
- environment variables are defined in more than one place,
- variables defined in a local lesskey file take precedence
- over variables defined in the system environment, which
- take precedence over variables defined in the system-wide
- lesskey file.
-
-
-
-
- Version 381: 17 Jan 2003 27
-
-
-
-
-
-LESS(1) LESS(1)
-
+ Environment variables may be specified either in the system environment
+ as usual, or in a _l_e_s_s_k_e_y (1) file. If environment variables are
+ defined in more than one place, variables defined in a local lesskey
+ file take precedence over variables defined in the system environment,
+ which take precedence over variables defined in the system-wide lesskey
+ file.
COLUMNS
- Sets the number of columns on the screen. Takes
- precedence over the number of columns specified by
- the TERM variable. (But if you have a windowing
- system which supports TIOCGWINSZ or WIOCGETD, the
- window system's idea of the screen size takes
- precedence over the LINES and COLUMNS environment
- variables.)
+ Sets the number of columns on the screen. Takes precedence over
+ the number of columns specified by the TERM variable. (But if
+ you have a windowing system which supports TIOCGWINSZ or
+ WIOCGETD, the window system's idea of the screen size takes
+ precedence over the LINES and COLUMNS environment variables.)
EDITOR The name of the editor (used for the v command).
- HOME Name of the user's home directory (used to find a
- lesskey file on Unix and OS/2 systems).
+ HOME Name of the user's home directory (used to find a lesskey file
+ on Unix and OS/2 systems).
HOMEDRIVE, HOMEPATH
- Concatenation of the HOMEDRIVE and HOMEPATH envi­
- ronment variables is the name of the user's home
- directory if the HOME variable is not set (only in
- the Windows version).
+ Concatenation of the HOMEDRIVE and HOMEPATH environment vari-
+ ables is the name of the user's home directory if the HOME vari-
+ able is not set (only in the Windows version).
- INIT Name of the user's init directory (used to find a
- lesskey file on OS/2 systems).
+ INIT Name of the user's init directory (used to find a lesskey file
+ on OS/2 systems).
LANG Language for determining the character set.
@@ -1817,12 +1350,16 @@ LESS(1) LESS(1)
LESS Options which are passed to _l_e_s_s automatically.
LESSANSIENDCHARS
- Characters which are assumed to end an ANSI color
- escape sequence (default "m").
+ Characters which may end an ANSI color escape sequence (default
+ "m").
+
+ LESSANSIMIDCHARS
+ Characters which may appear between the ESC character and the
+ end character in an ANSI color escape sequence (default
+ "0123456789;[?!"'#%()*+ ".
LESSBINFMT
- Format for displaying non-printable, non-control
- characters.
+ Format for displaying non-printable, non-control characters.
LESSCHARDEF
Defines a character set.
@@ -1831,36 +1368,32 @@ LESS(1) LESS(1)
Selects a predefined character set.
LESSCLOSE
- Command line to invoke the (optional) input-post­
- processor.
+ Command line to invoke the (optional) input-postprocessor.
LESSECHO
- Name of the lessecho program (default "lessecho").
- The lessecho program is needed to expand metachar­
- acters, such as * and ?, in filenames on Unix sys­
- tems.
-
-
-
-
- Version 381: 17 Jan 2003 28
-
-
-
-
-
-LESS(1) LESS(1)
-
+ Name of the lessecho program (default "lessecho"). The lessecho
+ program is needed to expand metacharacters, such as * and ?, in
+ filenames on Unix systems.
LESSEDIT
- Editor prototype string (used for the v command).
- See discussion under PROMPTS.
+ Editor prototype string (used for the v command). See discus-
+ sion under PROMPTS.
LESSGLOBALTAGS
- Name of the command used by the -t option to find
- global tags. Normally should be set to "global" if
- your system has the _g_l_o_b_a_l (1) command. If not
- set, global tags are not used.
+ Name of the command used by the -t option to find global tags.
+ Normally should be set to "global" if your system has the _g_l_o_b_a_l
+ (1) command. If not set, global tags are not used.
+
+ LESSHISTFILE
+ Name of the history file used to remember search commands and
+ shell commands between invocations of _l_e_s_s_. If set to "-", a
+ history file is not used. The default is "$HOME/.lesshst" on
+ Unix systems, "$HOME/_lesshst" on DOS and Windows systems, or
+ "$HOME/lesshst.ini" or "$INIT/lesshst.ini" on OS/2 systems.
+
+ LESSHISTSIZE
+ The maximum number of commands to save in the history file. The
+ default is 100.
LESSKEY
Name of the default lesskey(1) file.
@@ -1869,54 +1402,41 @@ LESS(1) LESS(1)
Name of the default system-wide lesskey(1) file.
LESSMETACHARS
- List of characters which are considered "metachar­
- acters" by the shell.
+ List of characters which are considered "metacharacters" by the
+ shell.
LESSMETAESCAPE
- Prefix which less will add before each metacharac­
- ter in a command sent to the shell. If LESS­
- METAESCAPE is an empty string, commands containing
- metacharacters will not be passed to the shell.
+ Prefix which less will add before each metacharacter in a com-
+ mand sent to the shell. If LESSMETAESCAPE is an empty string,
+ commands containing metacharacters will not be passed to the
+ shell.
LESSOPEN
- Command line to invoke the (optional) input-prepro­
- cessor.
+ Command line to invoke the (optional) input-preprocessor.
LESSSECURE
- Runs less in "secure" mode. See discussion under
- SECURITY.
+ Runs less in "secure" mode. See discussion under SECURITY.
LESSSEPARATOR
- String to be appended to a directory name in file­
- name completion.
-
- LINES Sets the number of lines on the screen. Takes
- precedence over the number of lines specified by
- the TERM variable. (But if you have a windowing
- system which supports TIOCGWINSZ or WIOCGETD, the
- window system's idea of the screen size takes
- precedence over the LINES and COLUMNS environment
- variables.)
-
- PATH User's search path (used to find a lesskey file on
- MS-DOS and OS/2 systems).
-
- SHELL The shell used to execute the ! command, as well as
- to expand filenames.
-
- TERM The type of terminal on which _l_e_s_s is being run.
-
-
-
-
- Version 381: 17 Jan 2003 29
-
+ String to be appended to a directory name in filename comple-
+ tion.
+ LESSUTFBINFMT
+ Format for displaying non-printable Unicode code points.
+ LINES Sets the number of lines on the screen. Takes precedence over
+ the number of lines specified by the TERM variable. (But if you
+ have a windowing system which supports TIOCGWINSZ or WIOCGETD,
+ the window system's idea of the screen size takes precedence
+ over the LINES and COLUMNS environment variables.)
+ PATH User's search path (used to find a lesskey file on MS-DOS and
+ OS/2 systems).
-LESS(1) LESS(1)
+ SHELL The shell used to execute the ! command, as well as to expand
+ filenames.
+ TERM The type of terminal on which _l_e_s_s is being run.
VISUAL The name of the editor (used for the v command).
@@ -1926,121 +1446,67 @@ SSEEEE AALLSSOO
WWAARRNNIINNGGSS
- The = command and prompts (unless changed by -P) report
- the line numbers of the lines at the top and bottom of the
- screen, but the byte and percent of the line after the one
- at the bottom of the screen.
-
- If the :e command is used to name more than one file, and
- one of the named files has been viewed previously, the new
- files may be entered into the list in an unexpected order.
-
- On certain older terminals (the so-called "magic cookie"
- terminals), search highlighting will cause an erroneous
- display. On such terminals, search highlighting is dis­
- abled by default to avoid possible problems.
-
- In certain cases, when search highlighting is enabled and
- a search pattern begins with a ^, more text than the
- matching string may be highlighted. (This problem does
- not occur when less is compiled to use the POSIX regular
- expression package.)
-
- When viewing text containing ANSI color escape sequences
- using the -R option, searching will not find text contain­
- ing an embedded escape sequence. Also, search highlight­
- ing may change the color of some of the text which follows
- the highlighted text.
-
- On some systems, _s_e_t_l_o_c_a_l_e claims that ASCII characters 0
- thru 31 are control characters rather than binary charac­
- ters. This causes _l_e_s_s to treat some binary files as
- ordinary, non-binary files. To workaround this problem,
- set the environment variable LESSCHARSET to "ascii" (or
+ The = command and prompts (unless changed by -P) report the line num-
+ bers of the lines at the top and bottom of the screen, but the byte and
+ percent of the line after the one at the bottom of the screen.
+
+ If the :e command is used to name more than one file, and one of the
+ named files has been viewed previously, the new files may be entered
+ into the list in an unexpected order.
+
+ On certain older terminals (the so-called "magic cookie" terminals),
+ search highlighting will cause an erroneous display. On such termi-
+ nals, search highlighting is disabled by default to avoid possible
+ problems.
+
+ In certain cases, when search highlighting is enabled and a search pat-
+ tern begins with a ^, more text than the matching string may be high-
+ lighted. (This problem does not occur when less is compiled to use the
+ POSIX regular expression package.)
+
+ When viewing text containing ANSI color escape sequences using the -R
+ option, searching will not find text containing an embedded escape
+ sequence. Also, search highlighting may change the color of some of
+ the text which follows the highlighted text.
+
+ On some systems, _s_e_t_l_o_c_a_l_e claims that ASCII characters 0 thru 31 are
+ control characters rather than binary characters. This causes _l_e_s_s to
+ treat some binary files as ordinary, non-binary files. To workaround
+ this problem, set the environment variable LESSCHARSET to "ascii" (or
whatever character set is appropriate).
- See http://www.greenwoodsoftware.com/less for the latest
- list of known bugs in this version of less.
-
-
-CCOOPPYYRRIIGGHHTT
- Copyright (C) 2002 Mark Nudelman
-
- less is part of the GNU project and is free software. You
- can redistribute it and/or modify it under the terms of
- either (1) the GNU General Public License as published by
- the Free Software Foundation; or (2) the Less License.
- See the file README in the less distribution for more
- details regarding redistribution. You should have
+ This manual is too long.
+ See http://www.greenwoodsoftware.com/less for the list of known bugs in
+ all versions of less.
- Version 381: 17 Jan 2003 30
-
-
-
-
-
-LESS(1) LESS(1)
-
+CCOOPPYYRRIIGGHHTT
+ Copyright (C) 1984-2005 Mark Nudelman
- received a copy of the GNU General Public License along
- with the source for less; see the file COPYING. If not,
- write to the Free Software Foundation, 59 Temple Place,
- Suite 330, Boston, MA 02111-1307, USA. You should also
- have received a copy of the Less License; see the file
- LICENSE.
+ less is part of the GNU project and is free software. You can redis-
+ tribute it and/or modify it under the terms of either (1) the GNU Gen-
+ eral Public License as published by the Free Software Foundation; or
+ (2) the Less License. See the file README in the less distribution for
+ more details regarding redistribution. You should have received a copy
+ of the GNU General Public License along with the source for less; see
+ the file COPYING. If not, write to the Free Software Foundation, 59
+ Temple Place, Suite 330, Boston, MA 02111-1307, USA. You should also
+ have received a copy of the Less License; see the file LICENSE.
- less is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied war­
- ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR­
- POSE. See the GNU General Public License for more
- details.
+ less is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FIT-
+ NESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
AAUUTTHHOORR
Mark Nudelman <markn@greenwoodsoftware.com>
- Send bug reports or comments to the above address or to
- bug-less@gnu.org.
- For more information, see the less homepage at
- http://www.greenwoodsoftware.com/less.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Send bug reports or comments to the above address or to bug-
+ less@gnu.org.
+ For more information, see the less homepage at http://www.greenwood-
+ software.com/less.
- Version 381: 17 Jan 2003 31
+ Version 394: 03 Dec 2005 LESS(1)
diff --git a/contrib/less/less.nro b/contrib/less/less.nro
index 34d0ad0ba399..f08717428c22 100644
--- a/contrib/less/less.nro
+++ b/contrib/less/less.nro
@@ -1,24 +1,24 @@
-.TH LESS 1 "Version 381: 17 Jan 2003"
+.TH LESS 1 "Version 394: 03 Dec 2005"
.SH NAME
less \- opposite of more
.SH SYNOPSIS
-.B "less -?"
+.B "less \-?"
.br
-.B "less --help"
+.B "less \-\-help"
.br
-.B "less -V"
+.B "less \-V"
.br
-.B "less --version"
+.B "less \-\-version"
.br
-.B "less [-[+]aBcCdeEfFgGiIJLmMnNqQrRsSuUVwWX~]"
+.B "less [\-[+]aBcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]"
.br
-.B " [-b \fIspace\fP] [-h \fIlines\fP] [-j \fIline\fP] [-k \fIkeyfile\fP]"
+.B " [\-b \fIspace\fP] [\-h \fIlines\fP] [\-j \fIline\fP] [\-k \fIkeyfile\fP]"
.br
-.B " [-{oO} \fIlogfile\fP] [-p \fIpattern\fP] [-P \fIprompt\fP] [-t \fItag\fP]"
+.B " [\-{oO} \fIlogfile\fP] [\-p \fIpattern\fP] [\-P \fIprompt\fP] [\-t \fItag\fP]"
.br
-.B " [-T \fItagsfile\fP] [-x \fItab\fP,...] [-y \fIlines\fP] [-[z] \fIlines\fP]"
+.B " [\-T \fItagsfile\fP] [\-x \fItab\fP,...] [\-y \fIlines\fP] [\-[z] \fIlines\fP]"
.br
-.B " [-# \fIshift\fP] [+[+]\fIcmd\fP] [--] [\fIfilename\fP]..."
+.B " [\-# \fIshift\fP] [+[+]\fIcmd\fP] [\-\-] [\fIfilename\fP]..."
.br
(See the OPTIONS section for alternate option syntax with long option names.)
@@ -57,7 +57,7 @@ two character sequence "ESCAPE", then "v".
Help: display a summary of these commands.
If you forget all the other commands, remember this one.
.IP "SPACE or ^V or f or ^F"
-Scroll forward N lines, default one window (see option -z below).
+Scroll forward N lines, default one window (see option \-z below).
If N is more than the screen size, only the final screenful is displayed.
Warning: some systems use ^V as a special literalization character.
.IP "z"
@@ -73,7 +73,7 @@ Scroll forward N lines, default one half of the screen size.
If N is specified, it becomes the new default for
subsequent d and u commands.
.IP "b or ^B or ESC-v"
-Scroll backward N lines, default one window (see option -z below).
+Scroll backward N lines, default one window (see option \-z below).
If N is more than the screen size, only the final screenful is displayed.
.IP "w"
Like ESC-v, but if N is specified, it becomes the new window size.
@@ -87,14 +87,14 @@ If N is specified, it becomes the new default for
subsequent d and u commands.
.IP "ESC-) or RIGHTARROW"
Scroll horizontally right N characters, default half the screen width
-(see the -# option).
+(see the \-# option).
If a number N is specified, it becomes the default for future RIGHTARROW
and LEFTARROW commands.
-While the text is scrolled, it acts as though the -S option
+While the text is scrolled, it acts as though the \-S option
(chop lines) were in effect.
.IP "ESC-( or LEFTARROW"
Scroll horizontally left N characters, default half the screen width
-(see the -# option).
+(see the \-# option).
If a number N is specified, it becomes the default for future RIGHTARROW
and LEFTARROW commands.
.IP "r or ^R or ^L"
@@ -108,7 +108,7 @@ end of file is reached.
Normally this command would be used when already at the end of the file.
It is a way to monitor the tail of a file which is growing
while it is being viewed.
-(The behavior is similar to the "tail -f" command.)
+(The behavior is similar to the "tail \-f" command.)
.IP "g or < or ESC-<"
Go to line N in the file, default 1 (beginning of file).
(Warning: this may be slow if N is large.)
@@ -175,9 +175,9 @@ Same as single quote.
Search forward in the file for the N-th line containing the pattern.
N defaults to 1.
The pattern is a regular expression, as recognized by
-.I ed.
+the regular expression library supplied by your system.
The search starts at the second line displayed
-(but see the -a and -j options, which change this).
+(but see the \-a and \-j options, which change this).
.sp
Certain characters are special
if entered at the beginning of the pattern;
@@ -194,7 +194,7 @@ the search continues in the next file in the command line list.
Begin the search at the first line of the FIRST file
in the command line list,
regardless of what is currently displayed on the screen
-or the settings of the -a or -j options.
+or the settings of the \-a or \-j options.
.IP "^K"
Highlight any text which matches the pattern on the current screen,
but don't move to the first match (KEEP current position).
@@ -219,7 +219,7 @@ the search continues in the previous file in the command line list.
Begin the search at the last line of the last file
in the command line list,
regardless of what is currently displayed on the screen
-or the settings of the -a or -j options.
+or the settings of the \-a or \-j options.
.IP "^K"
As in forward searches.
.IP "^R"
@@ -252,7 +252,7 @@ Turn off highlighting of strings matching the current search pattern.
If highlighting is already off because of a previous ESC-u command,
turn highlighting back on.
Any search command will also turn highlighting back on.
-(Highlighting can also be disabled by toggling the -G option;
+(Highlighting can also be disabled by toggling the \-G option;
in that case search commands do not turn highlighting back on.)
.IP ":e [filename]"
Examine a new file.
@@ -272,7 +272,7 @@ If the filename consists of several files, they are all inserted into
the list of files and the first one is examined.
If the filename contains one or more spaces,
the entire filename should be enclosed in double quotes
-(also see the -" option).
+(also see the \-" option).
.IP "^X^V or E"
Same as :e.
Warning: some systems use ^V as a special literalization character.
@@ -306,8 +306,8 @@ this will change the setting of that option
and print a message describing the new setting.
If a ^P (CONTROL-P) is entered immediately after the dash,
the setting of the option is changed but no message is printed.
-If the option letter has a numeric value (such as -b or -h),
-or a string value (such as -P or -t),
+If the option letter has a numeric value (such as \-b or \-h),
+or a string value (such as \-P or \-t),
a new value may be entered after the option letter.
If no new value is entered, a message describing
the current setting is printed and nothing is changed.
@@ -401,17 +401,17 @@ either a dash followed by a single letter,
or two dashes followed by a long option name.
A long option name may be abbreviated as long as
the abbreviation is unambiguous.
-For example, --quit-at-eof may be abbreviated --quit, but not
---qui, since both --quit-at-eof and --quiet begin with --qui.
-Some long option names are in uppercase, such as --QUIT-AT-EOF, as
-distinct from --quit-at-eof.
+For example, \-\-quit-at-eof may be abbreviated \-\-quit, but not
+--qui, since both \-\-quit-at-eof and \-\-quiet begin with \-\-qui.
+Some long option names are in uppercase, such as \-\-QUIT-AT-EOF, as
+distinct from \-\-quit-at-eof.
Such option names need only have their first letter capitalized;
the remainder of the name may be in either case.
-For example, --Quit-at-eof is equivalent to --QUIT-AT-EOF.
+For example, \-\-Quit-at-eof is equivalent to \-\-QUIT-AT-EOF.
.PP
Options are also taken from the environment variable "LESS".
For example,
-to avoid typing "less -options ..." each time
+to avoid typing "less \-options ..." each time
.I less
is invoked, you might tell
.I csh:
@@ -432,62 +432,62 @@ If an option appears in the LESS variable, it can be reset
to its default value on the command line by beginning the command
line option with "\-+".
.sp
-For options like -P or -D which take a following string,
+For options like \-P or \-D which take a following string,
a dollar sign ($) must be used to signal the end of the string.
-For example, to set two -D options on MS-DOS, you must have
+For example, to set two \-D options on MS-DOS, you must have
a dollar sign between them, like this:
.sp
LESS="-Dn9.1$-Ds4.1"
.sp
-.IP "-? or --help"
+.IP "\-? or \-\-help"
This option displays a summary of the commands accepted by
.I less
(the same as the h command).
(Depending on how your shell interprets the question mark,
-it may be necessary to quote the question mark, thus: "-\e?".)
-.IP "-a or --search-skip-screen"
+it may be necessary to quote the question mark, thus: "\-\e?".)
+.IP "\-a or \-\-search-skip-screen"
Causes searches to start after the last line
displayed on the screen,
thus skipping all lines displayed on the screen.
By default, searches start at the second line on the screen
-(or after the last found line; see the -j option).
-.IP "-b\fIn\fP or --buffers=\fIn\fP"
+(or after the last found line; see the \-j option).
+.IP "\-b\fIn\fP or \-\-buffers=\fIn\fP"
Specifies the amount of buffer space
.I less
will use for each file, in units of kilobytes (1024 bytes).
By default 64K of buffer space is used for each file
-(unless the file is a pipe; see the -B option).
-The -b option specifies instead that \fIn\fP kilobytes of
+(unless the file is a pipe; see the \-B option).
+The \-b option specifies instead that \fIn\fP kilobytes of
buffer space should be used for each file.
-If \fIn\fP is -1, buffer space is unlimited; that is,
+If \fIn\fP is \-1, buffer space is unlimited; that is,
the entire file is read into memory.
-.IP "-B or --auto-buffers"
+.IP "\-B or \-\-auto-buffers"
By default, when data is read from a pipe,
buffers are allocated automatically as needed.
If a large amount of data is read from the pipe, this can cause
a large amount of memory to be allocated.
-The -B option disables this automatic allocation of buffers for pipes,
+The \-B option disables this automatic allocation of buffers for pipes,
so that only 64K
-(or the amount of space specified by the -b option)
+(or the amount of space specified by the \-b option)
is used for the pipe.
-Warning: use of -B can result in erroneous display, since only the
+Warning: use of \-B can result in erroneous display, since only the
most recently viewed part of the file is kept in memory;
any earlier data is lost.
-.IP "-c or --clear-screen"
+.IP "\-c or \-\-clear-screen"
Causes full screen repaints to be painted from the top line down.
By default,
full screen repaints are done by scrolling from the bottom of the screen.
-.IP "-C or --CLEAR-SCREEN"
-The -C option is like -c, but the screen is cleared before it is repainted.
-.IP "-d or --dumb"
-The -d option suppresses the error message
+.IP "\-C or \-\-CLEAR-SCREEN"
+The \-C option is like \-c, but the screen is cleared before it is repainted.
+.IP "\-d or \-\-dumb"
+The \-d option suppresses the error message
normally displayed if the terminal is dumb;
that is, lacks some important capability,
such as the ability to clear the screen or scroll backward.
-The -d option does not otherwise change the behavior of
+The \-d option does not otherwise change the behavior of
.I less
on a dumb terminal.
-.IP "-D\fBx\fP\fIcolor\fP or --color=\fBx\fP\fIcolor\fP"
+.IP "\-D\fBx\fP\fIcolor\fP or \-\-color=\fBx\fP\fIcolor\fP"
[MS-DOS only]
Sets the color of the text displayed.
\fBx\fP is a single character which selects the type of text whose color is
@@ -496,7 +496,7 @@ being set: n=normal, s=standout, d=bold, u=underlined, k=blink.
The first number selects the foreground color and the second selects
the background color of the text.
A single number \fIN\fP is the same as \fIN.0\fP.
-.IP "-e or --quit-at-eof"
+.IP "\-e or \-\-quit-at-eof"
Causes
.I less
to automatically exit
@@ -504,50 +504,50 @@ the second time it reaches end-of-file.
By default, the only way to exit
.I less
is via the "q" command.
-.IP "-E or --QUIT-AT-EOF"
+.IP "\-E or \-\-QUIT-AT-EOF"
Causes
.I less
to automatically exit the first time it reaches end-of-file.
-.IP "-f or --force"
+.IP "\-f or \-\-force"
Forces non-regular files to be opened.
(A non-regular file is a directory or a device special file.)
Also suppresses the warning message when a binary file is opened.
By default,
.I less
will refuse to open non-regular files.
-.IP "-F or --quit-if-one-screen"
+.IP "\-F or \-\-quit-if-one-screen"
Causes
.I less
to automatically exit
if the entire file can be displayed on the first screen.
-.IP "-g or --hilite-search"
+.IP "\-g or \-\-hilite-search"
Normally,
.I less
will highlight ALL strings which match the last search command.
-The -g option changes this behavior to highlight only the particular string
+The \-g option changes this behavior to highlight only the particular string
which was found by the last search command.
This can cause
.I less
to run somewhat faster than the default.
-.IP "-G or --HILITE-SEARCH"
-The -G option suppresses all highlighting of strings found by search commands.
-.IP "-h\fIn\fP or ---max-back-scroll=\fIn\fP"
+.IP "\-G or \-\-HILITE-SEARCH"
+The \-G option suppresses all highlighting of strings found by search commands.
+.IP "\-h\fIn\fP or \-\-max-back-scroll=\fIn\fP"
Specifies a maximum number of lines to scroll backward.
If it is necessary to scroll backward more than \fIn\fP lines,
the screen is repainted in a forward direction instead.
(If the terminal does not have the ability to scroll
-backward, -h0 is implied.)
-.IP "-i or --ignore-case"
+backward, \-h0 is implied.)
+.IP "\-i or \-\-ignore-case"
Causes searches to ignore case; that is,
uppercase and lowercase are considered identical.
This option is ignored if any uppercase letters
appear in the search pattern;
in other words,
if a pattern contains uppercase letters, then that search does not ignore case.
-.IP "-I or --IGNORE-CASE"
-Like -i, but searches ignore case even if
+.IP "\-I or \-\-IGNORE-CASE"
+Like \-i, but searches ignore case even if
the pattern contains uppercase letters.
-.IP "-j\fIn\fP or --jump-target=\fIn\fP"
+.IP "\-j\fIn\fP or \-\-jump-target=\fIn\fP"
Specifies a line on the screen where the "target" line
is to be positioned.
A target line is the object of a text search,
@@ -556,36 +556,43 @@ jump to a file percentage, or jump to a marked position.
The screen line is specified by a number: the top line on the screen
is 1, the next is 2, and so on.
The number may be negative to specify a line relative to the bottom
-of the screen: the bottom line on the screen is -1, the second
-to the bottom is -2, and so on.
-If the -j option is used, searches begin at the line immediately
+of the screen: the bottom line on the screen is \-1, the second
+to the bottom is \-2, and so on.
+If the \-j option is used, searches begin at the line immediately
after the target line.
-For example, if "-j4" is used, the target line is the
+For example, if "\-j4" is used, the target line is the
fourth line on the screen, so searches begin at the fifth line
on the screen.
-.IP "-J or --status-column"
+.IP "\-J or \-\-status-column"
Displays a status column at the left edge of the screen.
The status column shows the lines that matched the current search.
-The status column is also used if the -w or -W option is in effect.
-.IP "-k\fIfilename\fP or --lesskey-file=\fIfilename\fP"
+The status column is also used if the \-w or \-W option is in effect.
+.IP "\-k\fIfilename\fP or \-\-lesskey-file=\fIfilename\fP"
Causes
.I less
to open and interpret the named file as a
.I lesskey
(1) file.
-Multiple -k options may be specified.
+Multiple \-k options may be specified.
If the LESSKEY or LESSKEY_SYSTEM environment variable is set, or
if a lesskey file is found in a standard place (see KEY BINDINGS),
it is also used as a
.I lesskey
file.
-.IP "-L or --no-lessopen"
+.IP "\-K or \-\-quit-on-intr"
+Causes
+.I less
+to exit immediately when an interrupt character (usually ^C) is typed.
+Normally, an interrupt character causes
+.I less
+to stop whatever it is doing and return to its command prompt.
+.IP "\-L or \-\-no-lessopen"
Ignore the LESSOPEN environment variable
(see the INPUT PREPROCESSOR section below).
This option can be set from within \fIless\fP,
but it will apply only to files opened subsequently, not to the
file which is currently open.
-.IP "-m or --long-prompt"
+.IP "\-m or \-\-long-prompt"
Causes
.I less
to prompt verbosely (like \fImore\fP),
@@ -593,25 +600,25 @@ with the percent into the file.
By default,
.I less
prompts with a colon.
-.IP "-M or --LONG-PROMPT"
+.IP "\-M or \-\-LONG-PROMPT"
Causes
.I less
to prompt even more verbosely than
.I more.
-.IP "-n or --line-numbers"
+.IP "\-n or \-\-line-numbers"
Suppresses line numbers.
The default (to use line numbers) may cause
.I less
to run more slowly in some cases, especially with a very large input file.
-Suppressing line numbers with the -n option will avoid this problem.
+Suppressing line numbers with the \-n option will avoid this problem.
Using line numbers means: the line number will be displayed in the verbose
prompt and in the = command,
and the v command will pass the current line number to the editor
(see also the discussion of LESSEDIT in PROMPTS below).
-.IP "-N or --LINE-NUMBERS"
+.IP "\-N or \-\-LINE-NUMBERS"
Causes a line number to be displayed at the beginning of
each line in the display.
-.IP "-o\fIfilename\fP or --log-file=\fIfilename\fP"
+.IP "\-o\fIfilename\fP or \-\-log-file=\fIfilename\fP"
Causes
.I less
to copy its input to the named file as it is being viewed.
@@ -620,24 +627,24 @@ not an ordinary file.
If the file already exists,
.I less
will ask for confirmation before overwriting it.
-.IP "-O\fIfilename\fP or --LOG-FILE=\fIfilename\fP"
-The -O option is like -o, but it will overwrite an existing
+.IP "\-O\fIfilename\fP or \-\-LOG-FILE=\fIfilename\fP"
+The \-O option is like \-o, but it will overwrite an existing
file without asking for confirmation.
.sp
If no log file has been specified,
-the -o and -O options can be used from within
+the \-o and \-O options can be used from within
.I less
to specify a log file.
Without a file name, they will simply report the name of the log file.
-The "s" command is equivalent to specifying -o from within
+The "s" command is equivalent to specifying \-o from within
.I less.
-.IP "-p\fIpattern\fP or --pattern=\fIpattern\fP"
-The -p option on the command line is equivalent to
+.IP "\-p\fIpattern\fP or \-\-pattern=\fIpattern\fP"
+The \-p option on the command line is equivalent to
specifying +/\fIpattern\fP;
that is, it tells
.I less
to start at the first occurrence of \fIpattern\fP in the file.
-.IP "-P\fIprompt\fP or --prompt=\fIprompt\fP"
+.IP "\-P\fIprompt\fP or \-\-prompt=\fIprompt\fP"
Provides a way to tailor the three prompt
styles to your own preference.
This option would normally be put in the LESS environment
@@ -648,15 +655,15 @@ Such an option must either be the last option in the LESS variable,
or be terminated by a dollar sign.
-Ps followed by a string changes the default (short) prompt
to that string.
--Pm changes the medium (-m) prompt.
--PM changes the long (-M) prompt.
+-Pm changes the medium (\-m) prompt.
+-PM changes the long (\-M) prompt.
-Ph changes the prompt for the help screen.
-P= changes the message printed by the = command.
-Pw changes the message printed while waiting for data (in the F command).
All prompt strings consist of a sequence of
letters and special escape sequences.
See the section on PROMPTS for more details.
-.IP "-q or --quiet or --silent"
+.IP "\-q or \-\-quiet or \-\-silent"
Causes moderately "quiet" operation:
the terminal bell is not rung
if an attempt is made to scroll past the end of the file
@@ -665,50 +672,54 @@ If the terminal has a "visual bell", it is used instead.
The bell will be rung on certain other errors,
such as typing an invalid character.
The default is to ring the terminal bell in all such cases.
-.IP "-Q or --QUIET or --SILENT"
+.IP "\-Q or \-\-QUIET or \-\-SILENT"
Causes totally "quiet" operation:
the terminal bell is never rung.
-.IP "-r or --raw-control-chars"
+.IP "\-r or \-\-raw-control-chars"
Causes "raw" control characters to be displayed.
The default is to display control characters using the caret notation;
for example, a control-A (octal 001) is displayed as "^A".
-Warning: when the -r option is used,
+Warning: when the \-r option is used,
.I less
cannot keep track of the actual appearance of the screen
(since this depends on how the screen responds to
each type of control character).
Thus, various display problems may result,
such as long lines being split in the wrong place.
-.IP "-R or --RAW-CONTROL-CHARS"
-Like -r, but tries to keep track of the screen appearance where possible.
-This works only if the input consists of normal text and possibly some
-ANSI "color" escape sequences, which are sequences of the form:
+.IP "\-R or \-\-RAW-CONTROL-CHARS"
+Like \-r, but only ANSI "color" escape sequences are output in "raw" form.
+Unlike \-r, the screen appearance is maintained correctly in most cases.
+ANSI "color" escape sequences are sequences of the form:
.sp
ESC [ ... m
.sp
-where the "..." is zero or more characters other than "m".
+where the "..." is zero or more color specification characters
For the purpose of keeping track of screen appearance,
-all control characters and all ANSI color escape sequences are
-assumed to not move the cursor.
+ANSI color escape sequences are assumed to not move the cursor.
You can make
.I less
think that characters other than "m" can end ANSI color escape sequences
by setting the environment variable LESSANSIENDCHARS to the list of
characters which can end a color escape sequence.
-.IP "-s or --squeeze-blank-lines"
+And you can make
+.I less
+think that characters other than the standard ones may appear between
+the ESC and the m by setting the environment variable LESSANSIMIDCHARS
+to the list of characters which can appear.
+.IP "\-s or \-\-squeeze-blank-lines"
Causes consecutive blank lines to be squeezed into a single blank line.
This is useful when viewing
.I nroff
output.
-.IP "-S or --chop-long-lines"
+.IP "\-S or \-\-chop-long-lines"
Causes lines longer than the screen width to be
chopped rather than folded.
That is, the portion of a long line that does not fit in
the screen width is not shown.
The default is to fold long lines; that is, display the remainder
on the next line.
-.IP "-t\fItag\fP or --tag=\fItag\fP"
-The -t option, followed immediately by a TAG,
+.IP "\-t\fItag\fP or \-\-tag=\fItag\fP"
+The \-t option, followed immediately by a TAG,
will edit the file containing that tag.
For this to work, tag information must be available;
for example, there may be a file in the current directory called "tags",
@@ -720,22 +731,22 @@ the name of a command compatible with
.I global
(1), and that command is executed to find the tag.
(See http://www.gnu.org/software/global/global.html).
-The -t option may also be specified from within
+The \-t option may also be specified from within
.I less
(using the \- command) as a way of examining a new file.
-The command ":t" is equivalent to specifying -t from within
+The command ":t" is equivalent to specifying \-t from within
.I less.
-.IP "-T\fItagsfile\fP or --tag-file=\fItagsfile\fP"
+.IP "\-T\fItagsfile\fP or \-\-tag-file=\fItagsfile\fP"
Specifies a tags file to be used instead of "tags".
-.IP "-u or --underline-special"
+.IP "\-u or \-\-underline-special"
Causes backspaces and carriage returns to be treated as printable characters;
that is, they are sent to the terminal when they appear in the input.
-.IP "-U or --UNDERLINE-SPECIAL"
+.IP "\-U or \-\-UNDERLINE-SPECIAL"
Causes backspaces, tabs and carriage returns to be
treated as control characters;
-that is, they are handled as specified by the -r option.
+that is, they are handled as specified by the \-r option.
.sp
-By default, if neither -u nor -U is given,
+By default, if neither \-u nor \-U is given,
backspaces which appear adjacent to an underscore character
are treated specially:
the underlined text is displayed
@@ -746,25 +757,25 @@ the overstruck text is printed
using the terminal's hardware boldface capability.
Other backspaces are deleted, along with the preceding character.
Carriage returns immediately followed by a newline are deleted.
-other carriage returns are handled as specified by the -r option.
+other carriage returns are handled as specified by the \-r option.
Text which is overstruck or underlined can be searched for
-if neither -u nor -U is in effect.
-.IP "-V or --version"
+if neither \-u nor \-U is in effect.
+.IP "\-V or \-\-version"
Displays the version number of
.I less.
-.IP "-w or --hilite-unread"
+.IP "\-w or \-\-hilite-unread"
Temporarily highlights the first "new" line after a forward movement
of a full page.
The first "new" line is the line immediately following the line previously
at the bottom of the screen.
Also highlights the target line after a g or p command.
The highlight is removed at the next command which causes movement.
-The entire line is highlighted, unless the -J option is in effect,
+The entire line is highlighted, unless the \-J option is in effect,
in which case only the status column is highlighted.
-.IP "-W or --HILITE-UNREAD"
-Like -w, but temporarily highlights the first new line after any
+.IP "\-W or \-\-HILITE-UNREAD"
+Like \-w, but temporarily highlights the first new line after any
forward movement command larger than one line.
-.IP "-x\fIn\fP,... or --tabs=\fIn\fP,..."
+.IP "\-x\fIn\fP,... or \-\-tabs=\fIn\fP,..."
Sets tab stops.
If only one \fIn\fP is specified, tab stops are set at multiples of \fIn\fP.
If multiple values separated by commas are specified, tab stops
@@ -772,24 +783,24 @@ are set at those positions, and then continue with the same spacing as the
last two.
For example, \fI-x9,17\fP will set tabs at positions 9, 17, 25, 33, etc.
The default for \fIn\fP is 8.
-.IP "-X or --no-init"
+.IP "\-X or \-\-no-init"
Disables sending the termcap initialization and deinitialization strings
to the terminal.
This is sometimes desirable if the deinitialization string does
something unnecessary, like clearing the screen.
-.IP "--no-keypad"
+.IP "\-\-no-keypad"
Disables sending the keypad initialization and deinitialization strings
to the terminal.
This is sometimes useful if the keypad strings make the numeric
keypad behave in an undesirable manner.
-.IP "-y\fIn\fP or --max-forw-scroll=\fIn\fP"
+.IP "\-y\fIn\fP or \-\-max-forw-scroll=\fIn\fP"
Specifies a maximum number of lines to scroll forward.
If it is necessary to scroll forward more than \fIn\fP lines,
the screen is repainted instead.
-The -c or -C option may be used to repaint from the top of
+The \-c or \-C option may be used to repaint from the top of
the screen if desired.
By default, any forward movement causes scrolling.
-.IP "-[z]\fIn\fP or --window=\fIn\fP"
+.IP "\-[z]\fIn\fP or \-\-window=\fIn\fP"
Changes the default scrolling window size to \fIn\fP lines.
The default is one screenful.
The z and w commands can also be used to change the window size.
@@ -800,10 +811,10 @@ If the number
is negative, it indicates
.I n
lines less than the current screen size.
-For example, if the screen is 24 lines, \fI-z-4\fP sets the
+For example, if the screen is 24 lines, \fI\-z-4\fP sets the
scrolling window to 20 lines. If the screen is resized to 40 lines,
the scrolling window automatically changes to 36 lines.
-.IP "-\fI\(dqcc\fP\ or\ --quotes=\fIcc\fP"
+.IP "\-\fI\(dqcc\fP\ or\ \-\-quotes=\fIcc\fP"
Changes the filename quoting character.
This may be necessary if you are trying to name a file
which contains both spaces and quote characters.
@@ -816,19 +827,19 @@ and the close quote to the second character.
Filenames containing a space should then be preceded by the open quote
character and followed by the close quote character.
Note that even after the quote characters are changed, this option
-remains -" (a dash followed by a double quote).
-.IP "-~ or --tilde"
+remains \-" (a dash followed by a double quote).
+.IP "\-~ or \-\-tilde"
Normally lines after end of file are displayed as a single tilde (~).
This option causes lines after end of file to be displayed as blank lines.
-.IP "-# or --shift"
+.IP "\-# or \-\-shift"
Specifies the default number of positions to scroll horizontally
in the RIGHTARROW and LEFTARROW commands.
If the number specified is zero, it sets the default number of
positions to one half of the screen width.
-.IP --
-A command line argument of "--" marks the end of option arguments.
+.IP \-\-
+A command line argument of "\-\-" marks the end of option arguments.
Any arguments following this are interpreted as filenames.
-This can be useful when viewing a file whose name begins with a "-" or "+".
+This can be useful when viewing a file whose name begins with a "\-" or "+".
.IP +
If a command line option begins with \fB+\fP,
the remainder of that option is taken to be an initial command to
@@ -1019,15 +1030,15 @@ lessopen.sh:
.br
case "$1" in
.br
- *.Z) uncompress -c $1 >/tmp/less.$$ 2>/dev/null
+ *.Z) uncompress -\c $1 >/tmp/less.$$ 2>/dev/null
.br
- if [ -s /tmp/less.$$ ]; then
+ if [ \-s /tmp/less.$$ ]; then
.br
echo /tmp/less.$$
.br
else
.br
- rm -f /tmp/less.$$
+ rm \-f /tmp/less.$$
.br
fi
.br
@@ -1074,7 +1085,7 @@ lesspipe.sh:
.br
case "$1" in
.br
- *.Z) uncompress -c $1 2>/dev/null
+ *.Z) uncompress \-c $1 2>/dev/null
.br
;;
.br
@@ -1087,7 +1098,7 @@ When an input pipe is used, a LESSCLOSE postprocessor can be used,
but it is usually not necessary since there is no replacement file
to clean up.
In this case, the replacement file name passed to the LESSCLOSE
-postprocessor is "-".
+postprocessor is "\-".
.SH "NATIONAL CHARACTER SETS"
There are three types of characters in the input file:
@@ -1131,6 +1142,8 @@ Selects a Russian character set.
Selects a character set appropriate for NeXT computers.
.IP utf-8
Selects the UTF-8 encoding of the ISO 10646 character set.
+.IP windows
+Selects a character set appropriate for Microsoft Windows (cp 1251).
.PP
In special cases, it may be desired to tailor
.I less
@@ -1173,7 +1186,8 @@ to each of the possible values for LESSCHARSET:
next\ \ 8bcccbcc18b95.bb125.bb
.PP
If neither LESSCHARSET nor LESSCHARDEF is set,
-but the string "UTF-8" is found in the LC_ALL, LC_TYPE or LANG
+but any of the strings "UTF-8", "UTF8", "utf-8" or "utf8"
+is found in the LC_ALL, LC_TYPE or LANG
environment variables, then the default character set is utf-8.
.PP
If that string is not found, but your system supports the
@@ -1205,10 +1219,28 @@ printf-style escape sequence (a % followed by x, X, o, d, etc.).
For example, if LESSBINFMT is "*u[%x]", binary characters
are displayed in underlined hexadecimal surrounded by brackets.
The default if no LESSBINFMT is specified is "*s<%X>".
+The default if no LESSBINFMT is specified is "*s<%02X>".
+Warning: the result of expanding the character via LESSBINFMT must
+be less than 31 characters.
+.PP
+When the character set is utf-8, the LESSUTFBINFMT environment variable
+acts similarly to LESSBINFMT but it applies to Unicode code points
+that were successfully decoded but are unsuitable for display (e.g.,
+unassigned code points).
+Its default value is "<U+%04lX>".
+Note that LESSUTFBINFMT and LESSBINFMT share their display attribute
+setting ("*x") so specifying one will affect both;
+LESSUTFBINFMT is read after LESSBINFMT so its setting, if any,
+will have priority.
+Problematic octets in a UTF-8 file (octets of a truncated sequence,
+octets of a complete but non-shortest form sequence, illegal octets,
+and stray trailing octets)
+are displayed individually using LESSBINFMT so as to facilitate diagnostic
+of how the UTF-8 file is ill-formed.
.SH "PROMPTS"
-The -P option allows you to tailor the prompt to your preference.
-The string given to the -P option replaces the specified prompt string.
+The \-P option allows you to tailor the prompt to your preference.
+The string given to the \-P option replaces the specified prompt string.
Certain characters in the string are interpreted specially.
The prompt mechanism is rather complicated to provide flexibility,
but the ordinary user need not understand the details of constructing
@@ -1225,7 +1257,7 @@ display is used,
an "m" means use the middle line,
a "b" means use the bottom line,
a "B" means use the line just after the bottom line,
-and a "j" means use the "target" line, as specified by the -j option.
+and a "j" means use the "target" line, as specified by the \-j option.
.IP "%B"
Replaced by the size of the current input file.
.IP "%c"
@@ -1350,7 +1382,7 @@ followed by the name of the next file, if there is one.
Finally, any trailing spaces are truncated.
This is the default prompt.
For reference, here are the defaults for
-the other two prompts (-m and -M respectively).
+the other two prompts (\-m and \-M respectively).
Each is broken into two lines here for readability only.
.nf
.sp
@@ -1398,11 +1430,11 @@ the pipe command
the examine command.
.IP "v"
the editing command
-.IP "s -o"
+.IP "s \-o"
log files
-.IP "-k"
+.IP "\-k"
use of lesskey files
-.IP "-t"
+.IP "\-t"
use of tags files
.IP " "
metacharacters in filenames, such as *
@@ -1447,8 +1479,12 @@ Options which are passed to
.I less
automatically.
.IP LESSANSIENDCHARS
-Characters which are assumed to end an ANSI color escape sequence
+Characters which may end an ANSI color escape sequence
(default "m").
+.IP LESSANSIMIDCHARS
+Characters which may appear between the ESC character and the
+end character in an ANSI color escape sequence
+(default "0123456789;[?!"'#%()*+\ ".
.IP LESSBINFMT
Format for displaying non-printable, non-control characters.
.IP LESSCHARDEF
@@ -1465,10 +1501,21 @@ in filenames on Unix systems.
Editor prototype string (used for the v command).
See discussion under PROMPTS.
.IP LESSGLOBALTAGS
-Name of the command used by the -t option to find global tags.
+Name of the command used by the \-t option to find global tags.
Normally should be set to "global" if your system has the
.I global
(1) command. If not set, global tags are not used.
+.IP LESSHISTFILE
+Name of the history file used to remember search commands and
+shell commands between invocations of
+.I less.
+If set to "\-", a history file is not used.
+The default is "$HOME/.lesshst" on Unix systems, "$HOME/_lesshst" on
+DOS and Windows systems, or "$HOME/lesshst.ini" or "$INIT/lesshst.ini"
+on OS/2 systems.
+.IP LESSHISTSIZE
+The maximum number of commands to save in the history file.
+The default is 100.
.IP LESSKEY
Name of the default lesskey(1) file.
.IP LESSKEY_SYSTEM
@@ -1487,6 +1534,8 @@ Runs less in "secure" mode.
See discussion under SECURITY.
.IP LESSSEPARATOR
String to be appended to a directory name in filename completion.
+.IP LESSUTFBINFMT
+Format for displaying non-printable Unicode code points.
.IP LINES
Sets the number of lines on the screen.
Takes precedence over the number of lines specified by the TERM variable.
@@ -1509,7 +1558,7 @@ The name of the editor (used for the v command).
lesskey(1)
.SH WARNINGS
-The = command and prompts (unless changed by -P)
+The = command and prompts (unless changed by \-P)
report the line numbers of the lines at the top and bottom of the screen,
but the byte and percent of the line after the one at the bottom of the screen.
.PP
@@ -1528,7 +1577,7 @@ more text than the matching string may be highlighted.
(This problem does not occur when less is compiled to use the POSIX
regular expression package.)
.PP
-When viewing text containing ANSI color escape sequences using the -R option,
+When viewing text containing ANSI color escape sequences using the \-R option,
searching will not find text containing an embedded escape sequence.
Also, search highlighting may change the color of some of the text
which follows the highlighted text.
@@ -1543,11 +1592,12 @@ to treat some binary files as ordinary, non-binary files.
To workaround this problem, set the environment variable
LESSCHARSET to "ascii" (or whatever character set is appropriate).
.PP
-See http://www.greenwoodsoftware.com/less for the latest list of known bugs in this
-version of less.
+This manual is too long.
+.PP
+See http://www.greenwoodsoftware.com/less for the list of known bugs in all versions of less.
.SH COPYRIGHT
-Copyright (C) 2002 Mark Nudelman
+Copyright (C) 1984-2005 Mark Nudelman
.PP
less is part of the GNU project and is free software.
You can redistribute it and/or modify it
diff --git a/contrib/less/lessecho.c b/contrib/less/lessecho.c
index 6fa41ef4ba05..89a44ecb6ae8 100644
--- a/contrib/less/lessecho.c
+++ b/contrib/less/lessecho.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -28,7 +28,7 @@
#include "less.h"
-static char *version = "$Revision: 1.9 $";
+static char *version = "$Revision: 1.10 $";
static int quote_all = 0;
static char openquote = '"';
diff --git a/contrib/less/lessecho.man b/contrib/less/lessecho.man
new file mode 100644
index 000000000000..79b743da5af7
--- /dev/null
+++ b/contrib/less/lessecho.man
@@ -0,0 +1,49 @@
+LESSECHO(1) LESSECHO(1)
+
+
+
+NNAAMMEE
+ lessecho - expand metacharacters
+
+SSYYNNOOPPSSIISS
+ lleesssseecchhoo _[_-_o_x_] _[_-_c_x_] _[_-_p_n_] _[_-_d_n_] _[_-_m_x_] _[_-_n_n_] _[_-_e_x_] _[_-_a_] _f_i_l_e _._._.
+
+DDEESSCCRRIIPPTTIIOONN
+ _l_e_s_s_e_c_h_o is a program that simply echos its arguments on standard out-
+ put. But any argument containing spaces is enclosed in quotes.
+
+OOPPTTIIOONNSS
+ A summary of options is included below.
+
+ --ooxx Specifies "x" to be the open quote character.
+
+ --ccxx Specifies "x" to be the close quote character.
+
+ --ppnn Specifies "n" to be the open quote character, as an integer.
+
+ --ddnn Specifies "n" to be the close quote character, as an integer.
+
+ --mmxx Specifies "x" to be a metachar.
+
+ --nnnn Specifies "n" to be a metachar, as an integer.
+
+ --eexx Specifies "x" to be the escape char for metachars.
+
+ --ffnn Specifies "n" to be the escape char for metachars, as an inte-
+ ger.
+
+ --aa Specifies that all arguments are to be quoted. The default is
+ that only arguments containing spaces are quoted.
+
+SSEEEE AALLSSOO
+ less(1)
+
+AAUUTTHHOORR
+ This manual page was written by Thomas Schoepf <schoepf@debian.org>,
+ for the Debian GNU/Linux system (but may be used by others).
+
+ Send bug reports or comments to bug-less@gnu.org.
+
+
+
+ Version 394: 03 Dec 2005 LESSECHO(1)
diff --git a/contrib/less/lessecho.nro b/contrib/less/lessecho.nro
new file mode 100644
index 000000000000..1feb074f2070
--- /dev/null
+++ b/contrib/less/lessecho.nro
@@ -0,0 +1,47 @@
+.TH LESSECHO 1 "Version 394: 03 Dec 2005"
+.SH NAME
+lessecho \- expand metacharacters
+.SH SYNOPSIS
+.B lessecho
+.I "[-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-a] file ..."
+.SH "DESCRIPTION"
+.I lessecho
+is a program that simply echos its arguments on standard output.
+But any argument containing spaces is enclosed in quotes.
+.SH OPTIONS
+A summary of options is included below.
+.TP
+.B \-ox
+Specifies "x" to be the open quote character.
+.TP
+.B \-cx
+Specifies "x" to be the close quote character.
+.TP
+.B \-pn
+Specifies "n" to be the open quote character, as an integer.
+.TP
+.B \-dn
+Specifies "n" to be the close quote character, as an integer.
+.TP
+.B \-mx
+Specifies "x" to be a metachar.
+.TP
+.B \-nn
+Specifies "n" to be a metachar, as an integer.
+.TP
+.B \-ex
+Specifies "x" to be the escape char for metachars.
+.TP
+.B \-fn
+Specifies "n" to be the escape char for metachars, as an integer.
+.TP
+.B \-a
+Specifies that all arguments are to be quoted.
+The default is that only arguments containing spaces are quoted.
+.SH "SEE ALSO"
+less(1)
+.SH AUTHOR
+This manual page was written by Thomas Schoepf <schoepf@debian.org>,
+for the Debian GNU/Linux system (but may be used by others).
+.PP
+Send bug reports or comments to bug-less@gnu.org.
diff --git a/contrib/less/lesskey.c b/contrib/less/lesskey.c
index 25d01e765693..4d211b026078 100644
--- a/contrib/less/lesskey.c
+++ b/contrib/less/lesskey.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/lesskey.h b/contrib/less/lesskey.h
index dc33c5844629..1734d2663283 100644
--- a/contrib/less/lesskey.h
+++ b/contrib/less/lesskey.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/lesskey.man b/contrib/less/lesskey.man
index addefe9a79c2..4730df47ab98 100644
--- a/contrib/less/lesskey.man
+++ b/contrib/less/lesskey.man
@@ -1,9 +1,7 @@
+LESSKEY(1) LESSKEY(1)
-LESSKEY(1) LESSKEY(1)
-
-
NNAAMMEE
lesskey - specify key bindings for less
@@ -14,33 +12,29 @@ SSYYNNOOPPSSIISS
lleesssskkeeyy ----vveerrssiioonn
DDEESSCCRRIIPPTTIIOONN
- _L_e_s_s_k_e_y is used to specify a set of key bindings to be
- used by _l_e_s_s_. The input file is a text file which
- describes the key bindings, If the input file is "-",
- standard input is read. If no input file is specified, a
- standard filename is used as the name of the input file,
- which depends on the system being used: On Unix systems,
- $HOME/.lesskey is used; on MS-DOS systems, $HOME/_lesskey
- is used; and on OS/2 systems $HOME/lesskey.ini is used, or
- $INIT/lesskey.ini if $HOME is undefined. The output file
- is a binary file which is used by _l_e_s_s_. If no output file
- is specified, and the environment variable LESSKEY is set,
- the value of LESSKEY is used as the name of the output
- file. Otherwise, a standard filename is used as the name
- of the output file, which depends on the system being
- used: On Unix and OS-9 systems, $HOME/.less is used; on
- MS-DOS systems, $HOME/_less is used; and on OS/2 systems,
- $HOME/less.ini is used, or $INIT/less.ini if $HOME is
- undefined. If the output file already exists, _l_e_s_s_k_e_y
- will overwrite it.
-
- The -V or --version option causes _l_e_s_s_k_e_y to print its
- version number and immediately exit. If -V or --version
- is present, other options and arguments are ignored.
-
- The input file consists of one or more _s_e_c_t_i_o_n_s_. Each
- section starts with a line that identifies the type of
- section. Possible sections are:
+ _L_e_s_s_k_e_y is used to specify a set of key bindings to be used by _l_e_s_s_.
+ The input file is a text file which describes the key bindings, If the
+ input file is "-", standard input is read. If no input file is speci-
+ fied, a standard filename is used as the name of the input file, which
+ depends on the system being used: On Unix systems, $HOME/.lesskey is
+ used; on MS-DOS systems, $HOME/_lesskey is used; and on OS/2 systems
+ $HOME/lesskey.ini is used, or $INIT/lesskey.ini if $HOME is undefined.
+ The output file is a binary file which is used by _l_e_s_s_. If no output
+ file is specified, and the environment variable LESSKEY is set, the
+ value of LESSKEY is used as the name of the output file. Otherwise, a
+ standard filename is used as the name of the output file, which depends
+ on the system being used: On Unix and OS-9 systems, $HOME/.less is
+ used; on MS-DOS systems, $HOME/_less is used; and on OS/2 systems,
+ $HOME/less.ini is used, or $INIT/less.ini if $HOME is undefined. If
+ the output file already exists, _l_e_s_s_k_e_y will overwrite it.
+
+ The -V or --version option causes _l_e_s_s_k_e_y to print its version number
+ and immediately exit. If -V or --version is present, other options and
+ arguments are ignored.
+
+ The input file consists of one or more _s_e_c_t_i_o_n_s_. Each section starts
+ with a line that identifies the type of section. Possible sections
+ are:
#command
Defines new command keys.
@@ -50,8 +44,8 @@ DDEESSCCRRIIPPTTIIOONN
#env Defines environment variables.
- Blank lines and lines which start with a pound sign (#)
- are ignored, except for the special section header lines.
+ Blank lines and lines which start with a pound sign (#) are ignored,
+ except for the special section header lines.
CCOOMMMMAANNDD SSEECCTTIIOONN
@@ -59,33 +53,19 @@ CCOOMMMMAANNDD SSEECCTTIIOONN
#command
-
-
- Version 381: 17 Jan 2003 1
-
-
-
-
-
-LESSKEY(1) LESSKEY(1)
-
-
- If the command section is the first section in the file,
- this line may be omitted. The command section consists of
- lines of the form:
+ If the command section is the first section in the file, this line may
+ be omitted. The command section consists of lines of the form:
_s_t_r_i_n_g <whitespace> _a_c_t_i_o_n [extra-string] <newline>
- Whitespace is any sequence of one or more spaces and/or
- tabs. The _s_t_r_i_n_g is the command key(s) which invoke the
- action. The _s_t_r_i_n_g may be a single command key, or a
- sequence of up to 15 keys. The _a_c_t_i_o_n is the name of the
- less action, from the list below. The characters in the
- _s_t_r_i_n_g may appear literally, or be prefixed by a caret to
- indicate a control key. A backslash followed by one to
- three octal digits may be used to specify a character by
- its octal value. A backslash followed by certain charac­
- ters specifies input characters as follows:
+ Whitespace is any sequence of one or more spaces and/or tabs. The
+ _s_t_r_i_n_g is the command key(s) which invoke the action. The _s_t_r_i_n_g may
+ be a single command key, or a sequence of up to 15 keys. The _a_c_t_i_o_n is
+ the name of the less action, from the list below. The characters in
+ the _s_t_r_i_n_g may appear literally, or be prefixed by a caret to indicate
+ a control key. A backslash followed by one to three octal digits may
+ be used to specify a character by its octal value. A backslash fol-
+ lowed by certain characters specifies input characters as follows:
\b BACKSPACE
@@ -115,37 +95,22 @@ LESSKEY(1) LESSKEY(1)
\kx DELETE
- A backslash followed by any other character indicates that
- character is to be taken literally. Characters which must
- be preceded by backslash include caret, space, tab and the
- backslash itself.
-
- An action may be followed by an "extra" string. When such
- a command is entered while running _l_e_s_s_, the action is
- performed, and then the extra string is parsed, just as if
- it were typed in to _l_e_s_s_. This feature can be used in
-
-
-
- Version 381: 17 Jan 2003 2
-
-
-
+ A backslash followed by any other character indicates that character is
+ to be taken literally. Characters which must be preceded by backslash
+ include caret, space, tab and the backslash itself.
-
-LESSKEY(1) LESSKEY(1)
-
-
- certain cases to extend the functionality of a command.
- For example, see the "{" and ":t" commands in the example
- below. The extra string has a special meaning for the
- "quit" action: when _l_e_s_s quits, first character of the
- extra string is used as its exit status.
+ An action may be followed by an "extra" string. When such a command is
+ entered while running _l_e_s_s_, the action is performed, and then the extra
+ string is parsed, just as if it were typed in to _l_e_s_s_. This feature
+ can be used in certain cases to extend the functionality of a command.
+ For example, see the "{" and ":t" commands in the example below. The
+ extra string has a special meaning for the "quit" action: when _l_e_s_s
+ quits, first character of the extra string is used as its exit status.
EEXXAAMMPPLLEE
- The following input file describes the set of default com­
- mand keys used by less:
+ The following input file describes the set of default command keys used
+ by less:
#command
\r forw-line
@@ -190,18 +155,6 @@ EEXXAAMMPPLLEE
< goto-line
\e< goto-line
p percent
-
-
-
- Version 381: 17 Jan 2003 3
-
-
-
-
-
-LESSKEY(1) LESSKEY(1)
-
-
% percent
\e[ left-scroll
\e] right-scroll
@@ -256,18 +209,6 @@ LESSKEY(1) LESSKEY(1)
0 digit
1 digit
2 digit
-
-
-
- Version 381: 17 Jan 2003 4
-
-
-
-
-
-LESSKEY(1) LESSKEY(1)
-
-
3 digit
4 digit
5 digit
@@ -283,27 +224,23 @@ LESSKEY(1) LESSKEY(1)
PPRREECCEEDDEENNCCEE
- Commands specified by _l_e_s_s_k_e_y take precedence over the
- default commands. A default command key may be disabled
- by including it in the input file with the action
- "invalid". Alternatively, a key may be defined to do
- nothing by using the action "noaction". "noaction" is
- similar to "invalid", but _l_e_s_s will give an error beep for
- an "invalid" command, but not for a "noaction" command.
- In addition, ALL default commands may be disabled by
- adding this control line to the input file:
+ Commands specified by _l_e_s_s_k_e_y take precedence over the default com-
+ mands. A default command key may be disabled by including it in the
+ input file with the action "invalid". Alternatively, a key may be
+ defined to do nothing by using the action "noaction". "noaction" is
+ similar to "invalid", but _l_e_s_s will give an error beep for an "invalid"
+ command, but not for a "noaction" command. In addition, ALL default
+ commands may be disabled by adding this control line to the input file:
#stop
- This will cause all default commands to be ignored. The
- #stop line should be the last line in that section of the
- file.
+ This will cause all default commands to be ignored. The #stop line
+ should be the last line in that section of the file.
- Be aware that #stop can be dangerous. Since all default
- commands are disabled, you must provide sufficient com­
- mands before the #stop line to enable all necessary
- actions. For example, failure to provide a "quit" command
- can lead to frustration.
+ Be aware that #stop can be dangerous. Since all default commands are
+ disabled, you must provide sufficient commands before the #stop line to
+ enable all necessary actions. For example, failure to provide a "quit"
+ command can lead to frustration.
LLIINNEE EEDDIITTIINNGG SSEECCTTIIOONN
@@ -311,28 +248,15 @@ LLIINNEE EEDDIITTIINNGG SSEECCTTIIOONN
#line-edit
- This section specifies new key bindings for the line edit­
- ing commands, in a manner similar to the way key bindings
- for ordinary commands are specified in the #command sec­
- tion. The line-editing section consists of a list of keys
- and actions, one per line as in the example below.
+ This section specifies new key bindings for the line editing commands,
+ in a manner similar to the way key bindings for ordinary commands are
+ specified in the #command section. The line-editing section consists
+ of a list of keys and actions, one per line as in the example below.
EEXXAAMMPPLLEE
- The following input file describes the set of default
- line-editing keys used by less:
-
-
-
-
- Version 381: 17 Jan 2003 5
-
-
-
-
-
-LESSKEY(1) LESSKEY(1)
-
+ The following input file describes the set of default line-editing keys
+ used by less:
#line-edit
\t forw-complete
@@ -370,35 +294,21 @@ LLEESSSS EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
#env
- Following this line is a list of environment variable
- assignments. Each line consists of an environment vari­
- able name, an equals sign (=) and the value to be assigned
- to the environment variable. White space before and after
- the equals sign is ignored. Variables assigned in this
- way are visible only to _l_e_s_s_. If a variable is specified
- in the system environment and also in a lesskey file, the
- value in the lesskey file takes precedence. Although the
- lesskey file can be used to override variables set in the
- environment, the main purpose of assigning variables in
- the lesskey file is simply to have all _l_e_s_s configuration
+ Following this line is a list of environment variable assignments.
+ Each line consists of an environment variable name, an equals sign (=)
+ and the value to be assigned to the environment variable. White space
+ before and after the equals sign is ignored. Variables assigned in
+ this way are visible only to _l_e_s_s_. If a variable is specified in the
+ system environment and also in a lesskey file, the value in the lesskey
+ file takes precedence. Although the lesskey file can be used to over-
+ ride variables set in the environment, the main purpose of assigning
+ variables in the lesskey file is simply to have all _l_e_s_s configuration
information stored in one file.
EEXXAAMMPPLLEE
- The following input file sets the -i option whenever _l_e_s_s
- is run, and specifies the character set to be "latin1":
-
-
-
-
- Version 381: 17 Jan 2003 6
-
-
-
-
-
-LESSKEY(1) LESSKEY(1)
-
+ The following input file sets the -i option whenever _l_e_s_s is run, and
+ specifies the character set to be "latin1":
#env
LESS = -i
@@ -411,52 +321,40 @@ SSEEEE AALLSSOO
WWAARRNNIINNGGSS
- It is not possible to specify special keys, such as upar­
- row, in a keyboard-independent manner. The only way to
- specify such keys is to specify the escape sequence which
- a particular keyboard sends when such a key is pressed.
+ It is not possible to specify special keys, such as uparrow, in a key-
+ board-independent manner. The only way to specify such keys is to
+ specify the escape sequence which a particular keyboard sends when such
+ a key is pressed.
- On MS-DOS and OS/2 systems, certain keys send a sequence
- of characters which start with a NUL character (0). This
- NUL character should be represented as \340 in a lesskey
- file.
+ On MS-DOS and OS/2 systems, certain keys send a sequence of characters
+ which start with a NUL character (0). This NUL character should be
+ represented as \340 in a lesskey file.
CCOOPPYYRRIIGGHHTT
- Copyright (C) 2000 Mark Nudelman
+ Copyright (C) 2004 Mark Nudelman
- lesskey is part of the GNU project and is free software;
- you can redistribute it and/or modify it under the terms
- of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option)
- any later version.
+ lesskey is part of the GNU project and is free software; you can redis-
+ tribute it and/or modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either version 2,
+ or (at your option) any later version.
- lesskey is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied war­
- ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR­
- POSE. See the GNU General Public License for more
- details.
+ lesskey is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
- You should have received a copy of the GNU General Public
- License along with lesskey; see the file COPYING. If not,
- write to the Free Software Foundation, 59 Temple Place,
- Suite 330, Boston, MA 02111-1307, USA.
+ You should have received a copy of the GNU General Public License along
+ with lesskey; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
AAUUTTHHOORR
Mark Nudelman <markn@greenwoodsoftware.com>
- Send bug reports or comments to the above address or to
- bug-less@gnu.org.
-
-
-
-
-
-
-
-
+ Send bug reports or comments to the above address or to bug-
+ less@gnu.org.
- Version 381: 17 Jan 2003 7
+ Version 394: 03 Dec 2005 LESSKEY(1)
diff --git a/contrib/less/lesskey.nro b/contrib/less/lesskey.nro
index 252945146323..59bad804311c 100644
--- a/contrib/less/lesskey.nro
+++ b/contrib/less/lesskey.nro
@@ -1,4 +1,4 @@
-.TH LESSKEY 1 "Version 381: 17 Jan 2003"
+.TH LESSKEY 1 "Version 394: 03 Dec 2005"
.SH NAME
lesskey \- specify key bindings for less
.SH SYNOPSIS
@@ -358,7 +358,7 @@ which start with a NUL character (0).
This NUL character should be represented as \e340 in a lesskey file.
.SH COPYRIGHT
-Copyright (C) 2000 Mark Nudelman
+Copyright (C) 2004 Mark Nudelman
.PP
lesskey is part of the GNU project and is free software;
you can redistribute it and/or modify it
diff --git a/contrib/less/lglob.h b/contrib/less/lglob.h
index f2b49cef6351..6790d4229de8 100644
--- a/contrib/less/lglob.h
+++ b/contrib/less/lglob.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/line.c b/contrib/less/line.c
index 14659f399c1f..0c4943e20904 100644
--- a/contrib/less/line.c
+++ b/contrib/less/line.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -16,14 +16,13 @@
*/
#include "less.h"
+#include "charset.h"
-#define IS_CONT(c) (((c) & 0xC0) == 0x80)
-
-public char *linebuf = NULL; /* Buffer which holds the current output line */
+static char *linebuf = NULL; /* Buffer which holds the current output line */
static char *attr = NULL; /* Extension of linebuf to hold attributes */
public int size_linebuf = 0; /* Size of line buffer (and attr buffer) */
-public int cshift; /* Current left-shift of output line buffer */
+static int cshift; /* Current left-shift of output line buffer */
public int hshift; /* Desired left-shift of output line buffer */
public int tabstops[TABSTOP_MAX] = { 0 }; /* Custom tabstops */
public int ntabstops = 1; /* Number of tabstops */
@@ -36,13 +35,17 @@ static int overstrike; /* Next char should overstrike previous char */
static int last_overstrike = AT_NORMAL;
static int is_null_line; /* There is no current line */
static int lmargin; /* Left margin */
-static int hilites; /* Number of hilites in this line */
+static int line_matches; /* Number of search matches in this line */
static char pendc;
static POSITION pendpos;
static char *end_ansi_chars;
+static char *mid_ansi_chars;
+static int attr_swidth();
+static int attr_ewidth();
static int do_append();
+extern int sigs;
extern int bs_mode;
extern int linenums;
extern int ctldisp;
@@ -59,6 +62,11 @@ extern int utf_mode;
extern POSITION start_attnpos;
extern POSITION end_attnpos;
+static char mbc_buf[MAX_UTF_CHAR_LEN];
+static int mbc_buf_len = 0;
+static int mbc_buf_index = 0;
+static POSITION mbc_pos;
+
/*
* Initialize from environment variables.
*/
@@ -68,6 +76,11 @@ init_line()
end_ansi_chars = lgetenv("LESSANSIENDCHARS");
if (end_ansi_chars == NULL || *end_ansi_chars == '\0')
end_ansi_chars = "m";
+
+ mid_ansi_chars = lgetenv("LESSANSIMIDCHARS");
+ if (mid_ansi_chars == NULL || *mid_ansi_chars == '\0')
+ mid_ansi_chars = "0123456789;[?!\"'#%()*+ ";
+
linebuf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char));
attr = (char *) ecalloc(LINEBUF_SIZE, sizeof(char));
size_linebuf = LINEBUF_SIZE;
@@ -76,12 +89,20 @@ init_line()
/*
* Expand the line buffer.
*/
- static int
+ static int
expand_linebuf()
{
- int new_size = size_linebuf + LINEBUF_SIZE;
+ /* Double the size of the line buffer. */
+ int new_size = size_linebuf * 2;
+
+ /* Just realloc to expand the buffer, if we can. */
+#if HAVE_REALLOC
+ char *new_buf = (char *) realloc(linebuf, new_size);
+ char *new_attr = (char *) realloc(attr, new_size);
+#else
char *new_buf = (char *) calloc(new_size, sizeof(char));
char *new_attr = (char *) calloc(new_size, sizeof(char));
+#endif
if (new_buf == NULL || new_attr == NULL)
{
if (new_attr != NULL)
@@ -90,10 +111,23 @@ expand_linebuf()
free(new_buf);
return 1;
}
+#if HAVE_REALLOC
+ /*
+ * We realloc'd the buffers; they already have the old contents.
+ */
+ #if 0
+ memset(new_buf + size_linebuf, 0, new_size - size_linebuf);
+ memset(new_attr + size_linebuf, 0, new_size - size_linebuf);
+ #endif
+#else
+ /*
+ * We just calloc'd the buffers; copy the old contents.
+ */
memcpy(new_buf, linebuf, size_linebuf * sizeof(char));
memcpy(new_attr, attr, size_linebuf * sizeof(char));
free(attr);
free(linebuf);
+#endif
linebuf = new_buf;
attr = new_attr;
size_linebuf = new_size;
@@ -101,6 +135,16 @@ expand_linebuf()
}
/*
+ * Is a character ASCII?
+ */
+ public int
+is_ascii_char(ch)
+ LWCHAR ch;
+{
+ return (ch <= 0x7F);
+}
+
+/*
* Rewind the line buffer.
*/
public void
@@ -108,14 +152,17 @@ prewind()
{
curr = 0;
column = 0;
+ cshift = 0;
overstrike = 0;
+ last_overstrike = AT_NORMAL;
+ mbc_buf_len = 0;
is_null_line = 0;
pendc = '\0';
lmargin = 0;
if (status_col)
lmargin += 1;
#if HILITE_SEARCH
- hilites = 0;
+ line_matches = 0;
#endif
}
@@ -150,9 +197,9 @@ plinenum(pos)
linebuf[curr] = ' ';
if (start_attnpos != NULL_POSITION &&
pos >= start_attnpos && pos < end_attnpos)
- attr[curr] = AT_STANDOUT;
+ attr[curr] = AT_NORMAL|AT_HILITE;
else
- attr[curr] = 0;
+ attr[curr] = AT_NORMAL;
curr++;
column++;
}
@@ -190,92 +237,131 @@ plinenum(pos)
}
/*
- * Determine how many characters are required to shift N columns.
+ * Shift the input line left.
+ * This means discarding N printable chars at the start of the buffer.
*/
- static int
-shift_chars(s, len)
- char *s;
- int len;
+ static void
+pshift(shift)
+ int shift;
{
- char *p = s;
+ LWCHAR prev_ch = 0;
+ unsigned char c;
+ int shifted = 0;
+ int to;
+ int from;
+ int len;
+ int width;
+ int prev_attr;
+ int next_attr;
+
+ if (shift > column - lmargin)
+ shift = column - lmargin;
+ if (shift > curr - lmargin)
+ shift = curr - lmargin;
+ to = from = lmargin;
/*
- * Each char counts for one column, except ANSI color escape
- * sequences use no columns since they don't move the cursor.
+ * We keep on going when shifted == shift
+ * to get all combining chars.
*/
- while (*p != '\0' && len > 0)
+ while (shifted <= shift && from < curr)
{
- if (*p++ != ESC)
+ c = linebuf[from];
+ if (c == ESC && ctldisp == OPT_ONPLUS)
{
- len--;
+ /* Keep cumulative effect. */
+ linebuf[to] = c;
+ attr[to++] = attr[from++];
+ while (from < curr && linebuf[from])
+ {
+ linebuf[to] = linebuf[from];
+ attr[to++] = attr[from];
+ if (!is_ansi_middle(linebuf[from++]))
+ break;
+ }
+ continue;
+ }
+
+ width = 0;
+
+ if (!IS_ASCII_OCTET(c) && utf_mode)
+ {
+ /* Assumes well-formedness validation already done. */
+ LWCHAR ch;
+
+ len = utf_len(c);
+ if (from + len > curr)
+ break;
+ ch = get_wchar(linebuf + from);
+ if (!is_composing_char(ch) && !is_combining_char(prev_ch, ch))
+ width = is_wide_char(ch) ? 2 : 1;
+ prev_ch = ch;
} else
{
- while (*p != '\0')
+ len = 1;
+ if (c == '\b')
+ /* XXX - Incorrect if several '\b' in a row. */
+ width = (utf_mode && is_wide_char(prev_ch)) ? -2 : -1;
+ else if (!control_char(c))
+ width = 1;
+ prev_ch = 0;
+ }
+
+ if (width == 2 && shift - shifted == 1) {
+ /* Should never happen when called by pshift_all(). */
+ attr[to] = attr[from];
+ /*
+ * Assume a wide_char will never be the first half of a
+ * combining_char pair, so reset prev_ch in case we're
+ * followed by a '\b'.
+ */
+ prev_ch = linebuf[to++] = ' ';
+ from += len;
+ shifted++;
+ continue;
+ }
+
+ /* Adjust width for magic cookies. */
+ prev_attr = (to > 0) ? attr[to-1] : AT_NORMAL;
+ next_attr = (from + len < curr) ? attr[from + len] : prev_attr;
+ if (!is_at_equiv(attr[from], prev_attr) &&
+ !is_at_equiv(attr[from], next_attr))
+ {
+ width += attr_swidth(attr[from]);
+ if (from + len < curr)
+ width += attr_ewidth(attr[from]);
+ if (is_at_equiv(prev_attr, next_attr))
{
- if (is_ansi_end(*p++))
- break;
+ width += attr_ewidth(prev_attr);
+ if (from + len < curr)
+ width += attr_swidth(next_attr);
}
}
- }
- return (p - s);
-}
-/*
- * Determine how many characters are required to shift N columns (UTF version).
- * {{ FIXME: what about color escape sequences in UTF mode? }}
- */
- static int
-utf_shift_chars(s, len)
- char *s;
- int len;
-{
- int ulen = 0;
-
- while (*s != '\0' && len > 0)
- {
- if (!IS_CONT(*s))
- len--;
- s++;
- ulen++;
+ if (shift - shifted < width)
+ break;
+ from += len;
+ shifted += width;
+ if (shifted < 0)
+ shifted = 0;
}
- while (IS_CONT(*s))
+ while (from < curr)
{
- s++;
- ulen++;
+ linebuf[to] = linebuf[from];
+ attr[to++] = attr[from++];
}
- return (ulen);
+ curr = to;
+ column -= shifted;
+ cshift += shifted;
}
/*
- * Shift the input line left.
- * This means discarding N printable chars at the start of the buffer.
+ *
*/
- static void
-pshift(shift)
- int shift;
+ public void
+pshift_all()
{
- int i;
- int nchars;
-
- if (shift > column - lmargin)
- shift = column - lmargin;
- if (shift > curr - lmargin)
- shift = curr - lmargin;
-
- if (utf_mode)
- nchars = utf_shift_chars(linebuf + lmargin, shift);
- else
- nchars = shift_chars(linebuf + lmargin, shift);
- if (nchars > curr)
- nchars = curr;
- for (i = 0; i < curr - nchars; i++)
- {
- linebuf[lmargin + i] = linebuf[lmargin + i + nchars];
- attr[lmargin + i] = attr[lmargin + i + nchars];
- }
- curr -= nchars;
- column -= shift;
- cshift += shift;
+ pshift(column);
}
/*
@@ -286,14 +372,20 @@ pshift(shift)
attr_swidth(a)
int a;
{
- switch (a)
- {
- case AT_BOLD: return (bo_s_width);
- case AT_UNDERLINE: return (ul_s_width);
- case AT_BLINK: return (bl_s_width);
- case AT_STANDOUT: return (so_s_width);
- }
- return (0);
+ int w = 0;
+
+ a = apply_at_specials(a);
+
+ if (a & AT_UNDERLINE)
+ w += ul_s_width;
+ if (a & AT_BOLD)
+ w += bo_s_width;
+ if (a & AT_BLINK)
+ w += bl_s_width;
+ if (a & AT_STANDOUT)
+ w += so_s_width;
+
+ return w;
}
/*
@@ -304,14 +396,20 @@ attr_swidth(a)
attr_ewidth(a)
int a;
{
- switch (a)
- {
- case AT_BOLD: return (bo_e_width);
- case AT_UNDERLINE: return (ul_e_width);
- case AT_BLINK: return (bl_e_width);
- case AT_STANDOUT: return (so_e_width);
- }
- return (0);
+ int w = 0;
+
+ a = apply_at_specials(a);
+
+ if (a & AT_UNDERLINE)
+ w += ul_e_width;
+ if (a & AT_BOLD)
+ w += bo_e_width;
+ if (a & AT_BLINK)
+ w += bl_e_width;
+ if (a & AT_STANDOUT)
+ w += so_e_width;
+
+ return w;
}
/*
@@ -321,49 +419,92 @@ attr_ewidth(a)
* attribute sequence to be inserted, so this must be taken into account.
*/
static int
-pwidth(c, a)
- int c;
+pwidth(ch, a, prev_ch)
+ LWCHAR ch;
int a;
+ LWCHAR prev_ch;
{
- register int w;
+ int w;
- if (utf_mode && IS_CONT(c))
- return (0);
-
- if (c == '\b')
+ if (ch == '\b')
/*
- * Backspace moves backwards one position.
+ * Backspace moves backwards one or two positions.
+ * XXX - Incorrect if several '\b' in a row.
*/
- return (-1);
+ return (utf_mode && is_wide_char(prev_ch)) ? -2 : -1;
- if (control_char(c))
- /*
- * Control characters do unpredicatable things,
- * so we don't even try to guess; say it doesn't move.
- * This can only happen if the -r flag is in effect.
- */
- return (0);
+ if (!utf_mode || is_ascii_char(ch))
+ {
+ if (control_char((char)ch))
+ {
+ /*
+ * Control characters do unpredictable things,
+ * so we don't even try to guess; say it doesn't move.
+ * This can only happen if the -r flag is in effect.
+ */
+ return (0);
+ }
+ } else
+ {
+ if (is_composing_char(ch) || is_combining_char(prev_ch, ch))
+ {
+ /*
+ * Composing and combining chars take up no space.
+ *
+ * Some terminals, upon failure to compose a
+ * composing character with the character(s) that
+ * precede(s) it will actually take up one column
+ * for the composing character; there isn't much
+ * we could do short of testing the (complex)
+ * composition process ourselves and printing
+ * a binary representation when it fails.
+ */
+ return (0);
+ }
+ }
/*
- * Other characters take one space,
+ * Other characters take one or two columns,
* plus the width of any attribute enter/exit sequence.
*/
w = 1;
- if (curr > 0 && attr[curr-1] != a)
+ if (is_wide_char(ch))
+ w++;
+ if (curr > 0 && !is_at_equiv(attr[curr-1], a))
w += attr_ewidth(attr[curr-1]);
- if (a && (curr == 0 || attr[curr-1] != a))
+ if ((apply_at_specials(a) != AT_NORMAL) &&
+ (curr == 0 || !is_at_equiv(attr[curr-1], a)))
w += attr_swidth(a);
return (w);
}
/*
- * Delete the previous character in the line buffer.
+ * Delete to the previous base character in the line buffer.
+ * Return 1 if one is found.
*/
- static void
+ static int
backc()
{
- curr--;
- column -= pwidth(linebuf[curr], attr[curr]);
+ LWCHAR prev_ch;
+ char *p = linebuf + curr;
+ LWCHAR ch = step_char(&p, -1, linebuf + lmargin);
+ int width;
+
+ /* This assumes that there is no '\b' in linebuf. */
+ while ( curr > lmargin
+ && column > lmargin
+ && (!(attr[curr - 1] & (AT_ANSI|AT_BINARY))))
+ {
+ curr = p - linebuf;
+ prev_ch = step_char(&p, -1, linebuf + lmargin);
+ width = pwidth(ch, attr[curr], prev_ch);
+ column -= width;
+ if (width > 0)
+ return 1;
+ ch = prev_ch;
+ }
+
+ return 0;
}
/*
@@ -372,17 +513,18 @@ backc()
static int
in_ansi_esc_seq()
{
- int i;
+ char *p;
/*
* Search backwards for either an ESC (which means we ARE in a seq);
* or an end char (which means we're NOT in a seq).
*/
- for (i = curr-1; i >= 0; i--)
+ for (p = &linebuf[curr]; p > linebuf; )
{
- if (linebuf[i] == ESC)
+ LWCHAR ch = step_char(&p, -1, linebuf);
+ if (ch == ESC)
return (1);
- if (is_ansi_end(linebuf[i]))
+ if (!is_ansi_middle(ch))
return (0);
}
return (0);
@@ -392,50 +534,107 @@ in_ansi_esc_seq()
* Is a character the end of an ANSI escape sequence?
*/
public int
-is_ansi_end(c)
- char c;
+is_ansi_end(ch)
+ LWCHAR ch;
{
- return (strchr(end_ansi_chars, c) != NULL);
+ if (!is_ascii_char(ch))
+ return (0);
+ return (strchr(end_ansi_chars, (char) ch) != NULL);
+}
+
+/*
+ *
+ */
+ public int
+is_ansi_middle(ch)
+ LWCHAR ch;
+{
+ if (!is_ascii_char(ch))
+ return (0);
+ if (is_ansi_end(ch))
+ return (0);
+ return (strchr(mid_ansi_chars, (char) ch) != NULL);
}
/*
* Append a character and attribute to the line buffer.
*/
-#define STORE_CHAR(c,a,pos) \
- do { if (store_char((c),(a),(pos))) return (1); else curr++; } while (0)
+#define STORE_CHAR(ch,a,rep,pos) \
+ do { \
+ if (store_char((ch),(a),(rep),(pos))) return (1); \
+ } while (0)
static int
-store_char(c, a, pos)
- int c;
+store_char(ch, a, rep, pos)
+ LWCHAR ch;
int a;
+ char *rep;
POSITION pos;
{
- register int w;
+ int w;
+ int replen;
+ char cs;
+
+ w = (a & (AT_UNDERLINE|AT_BOLD)); /* Pre-use w. */
+ if (w != AT_NORMAL)
+ last_overstrike = w;
- if (a != AT_NORMAL)
- last_overstrike = a;
#if HILITE_SEARCH
- if (is_hilited(pos, pos+1, 0))
{
- /*
- * This character should be highlighted.
- * Override the attribute passed in.
- */
- a = AT_STANDOUT;
- hilites++;
+ int matches;
+ if (is_hilited(pos, pos+1, 0, &matches))
+ {
+ /*
+ * This character should be highlighted.
+ * Override the attribute passed in.
+ */
+ if (a != AT_ANSI)
+ a |= AT_HILITE;
+ }
+ line_matches += matches;
}
#endif
+
if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq())
+ {
+ if (!is_ansi_end(ch) && !is_ansi_middle(ch)) {
+ /* Remove whole unrecognized sequence. */
+ do {
+ --curr;
+ } while (linebuf[curr] != ESC);
+ return 0;
+ }
+ a = AT_ANSI; /* Will force re-AT_'ing around it. */
+ w = 0;
+ }
+ else if (ctldisp == OPT_ONPLUS && ch == ESC)
+ {
+ a = AT_ANSI; /* Will force re-AT_'ing around it. */
w = 0;
+ }
else
- w = pwidth(c, a);
+ {
+ char *p = &linebuf[curr];
+ LWCHAR prev_ch = step_char(&p, -1, linebuf);
+ w = pwidth(ch, a, prev_ch);
+ }
+
if (ctldisp != OPT_ON && column + w + attr_ewidth(a) > sc_width)
/*
* Won't fit on screen.
*/
return (1);
- if (curr >= size_linebuf-2)
+ if (rep == NULL)
+ {
+ cs = (char) ch;
+ rep = &cs;
+ replen = 1;
+ } else
+ {
+ replen = utf_len(rep[0]);
+ }
+ if (curr + replen >= size_linebuf-6)
{
/*
* Won't fit in line buffer.
@@ -445,41 +644,12 @@ store_char(c, a, pos)
return (1);
}
- /*
- * Special handling for "magic cookie" terminals.
- * If an attribute enter/exit sequence has a printing width > 0,
- * and the sequence is adjacent to a space, delete the space.
- * We just mark the space as invisible, to avoid having too
- * many spaces deleted.
- * {{ Note that even if the attribute width is > 1, we
- * delete only one space. It's not worth trying to do more.
- * It's hardly worth doing this much. }}
- */
- if (curr > 0 && a != AT_NORMAL &&
- linebuf[curr-1] == ' ' && attr[curr-1] == AT_NORMAL &&
- attr_swidth(a) > 0)
+ while (replen-- > 0)
{
- /*
- * We are about to append an enter-attribute sequence
- * just after a space. Delete the space.
- */
- attr[curr-1] = AT_INVIS;
- column--;
- } else if (curr > 0 && attr[curr-1] != AT_NORMAL &&
- attr[curr-1] != AT_INVIS && c == ' ' && a == AT_NORMAL &&
- attr_ewidth(attr[curr-1]) > 0)
- {
- /*
- * We are about to append a space just after an
- * exit-attribute sequence. Delete the space.
- */
- a = AT_INVIS;
- column--;
+ linebuf[curr] = *rep++;
+ attr[curr] = a;
+ curr++;
}
- /* End of magic cookie handling. */
-
- linebuf[curr] = c;
- attr[curr] = a;
column += w;
return (0);
}
@@ -510,12 +680,57 @@ store_tab(attr, pos)
to_tab = tabstops[i+1] - to_tab;
}
+ if (column + to_tab - 1 + pwidth(' ', attr, 0) + attr_ewidth(attr) > sc_width)
+ return 1;
+
do {
- STORE_CHAR(' ', attr, pos);
+ STORE_CHAR(' ', attr, " ", pos);
} while (--to_tab > 0);
return 0;
}
+#define STORE_PRCHAR(c, pos) \
+ do { if (store_prchar((c), (pos))) return 1; } while (0)
+
+ static int
+store_prchar(c, pos)
+ char c;
+ POSITION pos;
+{
+ char *s;
+
+ /*
+ * Convert to printable representation.
+ */
+ s = prchar(c);
+
+ /*
+ * Make sure we can get the entire representation
+ * of the character on this line.
+ */
+ if (column + (int) strlen(s) - 1 +
+ pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width)
+ return 1;
+
+ for ( ; *s != 0; s++)
+ STORE_CHAR(*s, AT_BINARY, NULL, pos);
+
+ return 0;
+}
+
+ static int
+flush_mbc_buf(pos)
+ POSITION pos;
+{
+ int i;
+
+ for (i = 0; i < mbc_buf_index; i++)
+ if (store_prchar(mbc_buf[i], pos))
+ return mbc_buf_index - i;
+
+ return 0;
+}
+
/*
* Append a character to the line buffer.
* Expand tabs into spaces, handle underlining, boldfacing, etc.
@@ -523,14 +738,14 @@ store_tab(attr, pos)
*/
public int
pappend(c, pos)
- register int c;
+ char c;
POSITION pos;
{
int r;
if (pendc)
{
- if (do_append(pendc, pendpos))
+ if (do_append(pendc, NULL, pendpos))
/*
* Oops. We've probably lost the char which
* was in pendc, since caller won't back up.
@@ -541,6 +756,16 @@ pappend(c, pos)
if (c == '\r' && bs_mode == BS_SPECIAL)
{
+ if (mbc_buf_len > 0) /* utf_mode must be on. */
+ {
+ /* Flush incomplete (truncated) sequence. */
+ r = flush_mbc_buf(mbc_pos);
+ mbc_buf_index = r + 1;
+ mbc_buf_len = 0;
+ if (r)
+ return (mbc_buf_index);
+ }
+
/*
* Don't put the CR into the buffer until we see
* the next char. If the next char is a newline,
@@ -551,7 +776,50 @@ pappend(c, pos)
return (0);
}
- r = do_append(c, pos);
+ if (!utf_mode)
+ {
+ r = do_append((LWCHAR) c, NULL, pos);
+ } else
+ {
+ /* Perform strict validation in all possible cases. */
+ if (mbc_buf_len == 0)
+ {
+ retry:
+ mbc_buf_index = 1;
+ *mbc_buf = c;
+ if (IS_ASCII_OCTET(c))
+ r = do_append((LWCHAR) c, NULL, pos);
+ else if (IS_UTF8_LEAD(c))
+ {
+ mbc_buf_len = utf_len(c);
+ mbc_pos = pos;
+ return (0);
+ } else
+ /* UTF8_INVALID or stray UTF8_TRAIL */
+ r = flush_mbc_buf(pos);
+ } else if (IS_UTF8_TRAIL(c))
+ {
+ mbc_buf[mbc_buf_index++] = c;
+ if (mbc_buf_index < mbc_buf_len)
+ return (0);
+ if (is_utf8_well_formed(mbc_buf))
+ r = do_append(get_wchar(mbc_buf), mbc_buf, mbc_pos);
+ else
+ /* Complete, but not shortest form, sequence. */
+ mbc_buf_index = r = flush_mbc_buf(mbc_pos);
+ mbc_buf_len = 0;
+ } else
+ {
+ /* Flush incomplete (truncated) sequence. */
+ r = flush_mbc_buf(mbc_pos);
+ mbc_buf_index = r + 1;
+ mbc_buf_len = 0;
+ /* Handle new char. */
+ if (!r)
+ goto retry;
+ }
+ }
+
/*
* If we need to shift the line, do it.
* But wait until we get to at least the middle of the screen,
@@ -563,42 +831,48 @@ pappend(c, pos)
linebuf[curr] = '\0';
pshift(hshift - cshift);
}
+ if (r)
+ {
+ /* How many chars should caller back up? */
+ r = (!utf_mode) ? 1 : mbc_buf_index;
+ }
return (r);
}
-#define IS_UTF8_4BYTE(c) ( ((c) & 0xf8) == 0xf0 )
-#define IS_UTF8_3BYTE(c) ( ((c) & 0xf0) == 0xe0 )
-#define IS_UTF8_2BYTE(c) ( ((c) & 0xe0) == 0xc0 )
-#define IS_UTF8_TRAIL(c) ( ((c) & 0xc0) == 0x80 )
-
static int
-do_append(c, pos)
- int c;
+do_append(ch, rep, pos)
+ LWCHAR ch;
+ char *rep;
POSITION pos;
{
- register char *s;
register int a;
+ LWCHAR prev_ch;
-#define STOREC(c,a) \
- if ((c) == '\t') STORE_TAB((a),pos); else STORE_CHAR((c),(a),pos)
+ a = AT_NORMAL;
- if (c == '\b')
+ if (ch == '\b')
{
- switch (bs_mode)
- {
- case BS_NORMAL:
- STORE_CHAR(c, AT_NORMAL, pos);
- break;
- case BS_CONTROL:
+ if (bs_mode == BS_CONTROL)
goto do_control_char;
- case BS_SPECIAL:
- if (curr == 0)
- break;
- backc();
- overstrike = 1;
- break;
- }
- } else if (overstrike)
+
+ /*
+ * A better test is needed here so we don't
+ * backspace over part of the printed
+ * representation of a binary character.
+ */
+ if ( curr <= lmargin
+ || column <= lmargin
+ || (attr[curr - 1] & (AT_ANSI|AT_BINARY)))
+ STORE_PRCHAR('\b', pos);
+ else if (bs_mode == BS_NORMAL)
+ STORE_CHAR(ch, AT_NORMAL, NULL, pos);
+ else if (bs_mode == BS_SPECIAL)
+ overstrike = backc();
+
+ return 0;
+ }
+
+ if (overstrike > 0)
{
/*
* Overstrike the character at the current position
@@ -607,29 +881,11 @@ do_append(c, pos)
* bold (if an identical character is overstruck),
* or just deletion of the character in the buffer.
*/
- overstrike--;
- if (utf_mode && IS_UTF8_4BYTE(c) && curr > 2 && (char)c == linebuf[curr-3])
- {
- backc();
- backc();
- backc();
- STORE_CHAR(linebuf[curr], AT_BOLD, pos);
- overstrike = 3;
- } else if (utf_mode && (IS_UTF8_3BYTE(c) || (overstrike==2 && IS_UTF8_TRAIL(c))) && curr > 1 && (char)c == linebuf[curr-2])
- {
- backc();
- backc();
- STORE_CHAR(linebuf[curr], AT_BOLD, pos);
- overstrike = 2;
- } else if (utf_mode && curr > 0 && (IS_UTF8_2BYTE(c) || (overstrike==1 && IS_UTF8_TRAIL(c))) && (char)c == linebuf[curr-1])
- {
- backc();
- STORE_CHAR(linebuf[curr], AT_BOLD, pos);
- overstrike = 1;
- } else if (utf_mode && curr > 0 && IS_UTF8_TRAIL(c) && attr[curr-1] == AT_UNDERLINE)
- {
- STOREC(c, AT_UNDERLINE);
- } else if ((char)c == linebuf[curr])
+ overstrike = utf_mode ? -1 : 0;
+ /* To be correct, this must be a base character. */
+ prev_ch = get_wchar(linebuf + curr);
+ a = attr[curr];
+ if (ch == prev_ch)
{
/*
* Overstriking a char with itself means make it bold.
@@ -638,40 +894,37 @@ do_append(c, pos)
* it could mean make it underlined.
* Use the previous overstrike to resolve it.
*/
- if (c == '_' && last_overstrike != AT_NORMAL)
- STOREC(c, last_overstrike);
- else
- STOREC(c, AT_BOLD);
- } else if (c == '_')
- {
- if (utf_mode)
+ if (ch == '_')
{
- int i;
- for (i = 0; i < 5; i++)
- {
- if (curr <= i || !IS_CONT(linebuf[curr-i]))
- break;
- attr[curr-i-1] = AT_UNDERLINE;
- }
- }
- STOREC(linebuf[curr], AT_UNDERLINE);
- } else if (linebuf[curr] == '_')
+ if ((a & (AT_BOLD|AT_UNDERLINE)) != AT_NORMAL)
+ a |= (AT_BOLD|AT_UNDERLINE);
+ else if (last_overstrike != AT_NORMAL)
+ a |= last_overstrike;
+ else
+ a |= AT_BOLD;
+ } else
+ a |= AT_BOLD;
+ } else if (ch == '_')
{
- if (utf_mode)
- {
- if (IS_UTF8_2BYTE(c))
- overstrike = 1;
- else if (IS_UTF8_3BYTE(c))
- overstrike = 2;
- else if (IS_UTF8_4BYTE(c))
- overstrike = 3;
- }
- STOREC(c, AT_UNDERLINE);
- } else if (control_char(c))
- goto do_control_char;
+ a |= AT_UNDERLINE;
+ ch = prev_ch;
+ rep = linebuf + curr;
+ } else if (prev_ch == '_')
+ {
+ a |= AT_UNDERLINE;
+ }
+ /* Else we replace prev_ch, but we keep its attributes. */
+ } else if (overstrike < 0)
+ {
+ if ( is_composing_char(ch)
+ || is_combining_char(get_wchar(linebuf + curr), ch))
+ /* Continuation of the same overstrike. */
+ a = last_overstrike;
else
- STOREC(c, AT_NORMAL);
- } else if (c == '\t')
+ overstrike = 0;
+ }
+
+ if (ch == '\t')
{
/*
* Expand a tab into spaces.
@@ -682,43 +935,56 @@ do_append(c, pos)
goto do_control_char;
case BS_NORMAL:
case BS_SPECIAL:
- STORE_TAB(AT_NORMAL, pos);
+ STORE_TAB(a, pos);
break;
}
- } else if (control_char(c))
+ } else if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch))
{
do_control_char:
- if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && c == ESC))
+ if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && ch == ESC))
{
/*
* Output as a normal character.
*/
- STORE_CHAR(c, AT_NORMAL, pos);
+ STORE_CHAR(ch, AT_NORMAL, rep, pos);
} else
{
- /*
- * Convert to printable representation.
- */
- s = prchar(c);
- a = binattr;
+ STORE_PRCHAR((char) ch, pos);
+ }
+ } else if (utf_mode && ctldisp != OPT_ON && is_ubin_char(ch))
+ {
+ char *s;
- /*
- * Make sure we can get the entire representation
- * of the character on this line.
- */
- if (column + (int) strlen(s) +
- attr_swidth(a) + attr_ewidth(a) > sc_width)
- return (1);
+ s = prutfchar(ch);
- for ( ; *s != 0; s++)
- STORE_CHAR(*s, a, pos);
- }
- } else
+ if (column + (int) strlen(s) - 1 +
+ pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width)
+ return (1);
+
+ for ( ; *s != 0; s++)
+ STORE_CHAR(*s, AT_BINARY, NULL, pos);
+ } else
{
- STOREC(c, AT_NORMAL);
+ STORE_CHAR(ch, a, rep, pos);
}
+ return (0);
+}
- return (0);
+/*
+ *
+ */
+ public int
+pflushmbc()
+{
+ int r = 0;
+
+ if (mbc_buf_len > 0)
+ {
+ /* Flush incomplete (truncated) sequence. */
+ r = flush_mbc_buf(mbc_pos);
+ mbc_buf_len = 0;
+ }
+ return r;
}
/*
@@ -728,13 +994,15 @@ do_append(c, pos)
pdone(endline)
int endline;
{
+ (void) pflushmbc();
+
if (pendc && (pendc != '\r' || !endline))
/*
* If we had a pending character, put it in the buffer.
* But discard a pending CR if we are at end of line
* (that is, discard the CR in a CR/LF sequence).
*/
- (void) do_append(pendc, pendpos);
+ (void) do_append(pendc, NULL, pendpos);
/*
* Make sure we've shifted the line, if we need to.
@@ -742,6 +1010,17 @@ pdone(endline)
if (cshift < hshift)
pshift(hshift - cshift);
+ if (ctldisp == OPT_ONPLUS && is_ansi_end('m'))
+ {
+ /* Switch to normal attribute at end of line. */
+ char *p = "\033[m";
+ for ( ; *p != '\0'; p++)
+ {
+ linebuf[curr] = *p;
+ attr[curr++] = AT_ANSI;
+ }
+ }
+
/*
* Add a newline if necessary,
* and append a '\0' to the end of the line.
@@ -756,17 +1035,12 @@ pdone(endline)
attr[curr] = AT_NORMAL;
#if HILITE_SEARCH
- if (status_col && hilites > 0)
+ if (status_col && line_matches > 0)
{
linebuf[0] = '*';
- attr[0] = AT_STANDOUT;
+ attr[0] = AT_NORMAL|AT_HILITE;
}
#endif
- /*
- * If we are done with this line, reset the current shift.
- */
- if (endline)
- cshift = 0;
}
/*
@@ -779,21 +1053,28 @@ gline(i, ap)
register int i;
register int *ap;
{
- char *s;
-
if (is_null_line)
{
/*
* If there is no current line, we pretend the line is
* either "~" or "", depending on the "twiddle" flag.
*/
- *ap = AT_BOLD;
- s = (twiddle) ? "~\n" : "\n";
- return (s[i]);
+ if (twiddle)
+ {
+ if (i == 0)
+ {
+ *ap = AT_BOLD;
+ return '~';
+ }
+ --i;
+ }
+ /* Make sure we're back to AT_NORMAL before the '\n'. */
+ *ap = AT_NORMAL;
+ return i ? '\0' : '\n';
}
*ap = attr[i];
- return (linebuf[i] & 0377);
+ return (linebuf[i] & 0xFF);
}
/*
@@ -827,7 +1108,7 @@ forw_raw_line(curr_pos, linep)
n = 0;
for (;;)
{
- if (c == '\n' || c == EOI)
+ if (c == '\n' || c == EOI || ABORT_SIGS())
{
new_pos = ch_tell();
break;
@@ -875,7 +1156,7 @@ back_raw_line(curr_pos, linep)
for (;;)
{
c = ch_back_get();
- if (c == '\n')
+ if (c == '\n' || ABORT_SIGS())
{
/*
* This is the newline ending the previous line.
@@ -911,8 +1192,8 @@ back_raw_line(curr_pos, linep)
/*
* Shift the data to the end of the new linebuf.
*/
- for (fm = linebuf + old_size_linebuf,
- to = linebuf + size_linebuf;
+ for (fm = linebuf + old_size_linebuf - 1,
+ to = linebuf + size_linebuf - 1;
fm >= linebuf; fm--, to--)
*to = *fm;
n = size_linebuf - old_size_linebuf;
diff --git a/contrib/less/linenum.c b/contrib/less/linenum.c
index 24026fa327b0..686bfadd4c80 100644
--- a/contrib/less/linenum.c
+++ b/contrib/less/linenum.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/lsystem.c b/contrib/less/lsystem.c
index eb82eece5a45..1489351239e5 100644
--- a/contrib/less/lsystem.c
+++ b/contrib/less/lsystem.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -133,9 +133,9 @@ lsystem(cmd, donemsg)
char *esccmd = shell_quote(cmd);
if (esccmd != NULL)
{
- p = (char *) ecalloc(strlen(shell) +
- strlen(esccmd) + 5, sizeof(char));
- sprintf(p, "%s %s %s", shell, shell_coption(), esccmd);
+ int len = strlen(shell) + strlen(esccmd) + 5;
+ p = (char *) ecalloc(len, sizeof(char));
+ SNPRINTF3(p, len, "%s %s %s", shell, shell_coption(), esccmd);
free(esccmd);
}
}
@@ -367,143 +367,3 @@ pipe_data(cmd, spos, epos)
}
#endif
-
-#ifdef _OSK
-/*
- * Popen, and Pclose, for OS-9.
- *
- * Based on code copyright (c) 1988 by Wolfgang Ocker, Puchheim,
- * Ulli Dessauer, Germering and
- * Reimer Mellin, Muenchen
- * (W-Germany)
- *
- * These functions can be copied and distributed freely for any
- * non-commercial purposes. It can only be incorporated into
- * commercial software with the written permission of the authors.
- *
- * TOP-specific code stripped out and adapted for less by M.Gregorie, 1996
- *
- * address: Wolfgang Ocker
- * Lochhauserstrasse 35a
- * D-8039 Puchheim
- * West Germany
- *
- * e-mail: weo@altger.UUCP, ud@altger.UUCP, ram@altger.UUCP
- * pyramid!tmpmbx!recco!weo
- * pyramid!tmpmbx!nitmar!ud
- * pyramid!tmpmbx!ramsys!ram
- *
- * Martin Gregorie
- * 10 Sadlers Mead
- * Harlow
- * Essex, CM18 6HG
- * U.K.
- *
- * gregorie@logica.com
- */
-#include <strings.h>
-#include <errno.h>
-extern char **environ;
-extern char *getenv();
-extern int os9forkc();
-static int pids[_NFILE] = { 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0 };
-/*
- * p o p e n
- */
-FILE *popen(name, mode)
- char *name;
- char *mode;
-{
- int fd, fd2, fdsav, pid;
- static char *argv[] = {NULL, NULL, NULL };
- static char cmd[200];
- static char cmd_path[200];
- char *cp;
- char *shell;
- FILE *r;
- if ((shell = getenv("SHELL")) == NULL)
- return(NULL);
- cp = name;
- while (*cp == ' ')
- cp++;
- strcpy(cmd_path, cp);
- if (cp = index(cmd_path, ' '))
- *cp++ = '\0';
- strcpy(cmd, "ex ");
- strcat(cmd, cmd_path);
- if (cp)
- {
- strcat(cmd, " ");
- strcat(cmd, cp);
- }
- argv[0] = shell;
- argv[1] = cmd;
- /*
- mode is "r" (stdout) or "w" (stdin)
- */
- switch(mode[0])
- {
- case 'w': fd = 0;
- break;
- case 'r': fd = 1;
- break;
- default: return(NULL);
- }
- if (fd == 1)
- fflush(stdout);
- fdsav = dup(fd);
- close(fd);
-
- creat("/pipe", S_IWRITE+S_IREAD);
- pid = os9exec(os9forkc, argv[0], argv, environ, 0, 0, 3);
- fd2 = dup(fd);
- close(fd);
- dup(fdsav);
- close(fdsav);
- if (pid > 0)
- {
- pids[fd2] = pid;
- r = fdopen(fd2, mode);
- }
- else
- {
- close(fd2);
- r = NULL;
- }
- return(r);
-}
-
-/*
- * p c l o s e
- */
-int pclose(fp)
- FILE *fp;
-{
- unsigned int status;
- int pid;
- int fd,
- i;
- fd = fileno(fp);
- if (pids[fd] == 0)
- return(-1);
- fflush(fp);
- fclose(fp);
- while ((pid = wait(&status)) != -1)
- if (pid == pids[fd])
- break;
- else
- for (i = 0; i < _NFILE; i++)
- if (pids[i] == pid)
- {
- pids[i] = 0;
- break;
- }
- if (pid == -1)
- status = -1;
- pids[fd] = 0;
- return(status);
-}
-#endif /* _OSK */
diff --git a/contrib/less/main.c b/contrib/less/main.c
index 1fb91a3c946e..26c8d514e7fd 100644
--- a/contrib/less/main.c
+++ b/contrib/less/main.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -114,6 +114,7 @@ main(argc, argv)
init_prompt();
init_charset();
init_line();
+ init_cmdhist();
init_option();
s = lgetenv("LESS");
if (s != NULL)
@@ -335,14 +336,14 @@ sprefix(ps, s, uppercase)
c = *ps;
if (uppercase)
{
- if (len == 0 && SIMPLE_IS_LOWER(c))
+ if (len == 0 && ASCII_IS_LOWER(c))
return (-1);
- if (SIMPLE_IS_UPPER(c))
- c = SIMPLE_TO_LOWER(c);
+ if (ASCII_IS_UPPER(c))
+ c = ASCII_TO_LOWER(c);
}
sc = *s;
- if (len > 0 && SIMPLE_IS_UPPER(sc))
- sc = SIMPLE_TO_LOWER(sc);
+ if (len > 0 && ASCII_IS_UPPER(sc))
+ sc = ASCII_TO_LOWER(sc);
if (c != sc)
break;
len++;
@@ -369,6 +370,7 @@ quit(status)
save_status = status;
quitting = 1;
edit((char*)NULL);
+ save_cmdhist();
if (any_display && is_tty)
clear_bot();
deinit();
diff --git a/contrib/less/mark.c b/contrib/less/mark.c
index 04f97885d107..8e135e7bd77b 100644
--- a/contrib/less/mark.c
+++ b/contrib/less/mark.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/mkhelp.c b/contrib/less/mkhelp.c
index d05cb49945cd..ca881b19f10a 100644
--- a/contrib/less/mkhelp.c
+++ b/contrib/less/mkhelp.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/optfunc.c b/contrib/less/optfunc.c
index 590b495450d4..3f77a4910250 100644
--- a/contrib/less/optfunc.c
+++ b/contrib/less/optfunc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -37,6 +37,7 @@ extern int sc_height;
extern int secure;
extern int dohelp;
extern int any_display;
+extern int less_is_more;
extern char openquote;
extern char closequote;
extern char *prproto[];
@@ -201,10 +202,13 @@ opt_t(type, s)
}
findtag(skipsp(s));
save_ifile = save_curr_ifile();
- if (edit_tagfile())
- break;
- if ((pos = tagsearch()) == NULL_POSITION)
+ /*
+ * Try to open the file containing the tag
+ * and search for the tag in that file.
+ */
+ if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION)
{
+ /* Failed: reopen the old file. */
reedit_ifile(save_ifile);
break;
}
@@ -259,7 +263,12 @@ opt_p(type, s)
*/
plusoption = TRUE;
ungetsc(s);
- ungetsc("/");
+ /*
+ * In "more" mode, the -p argument is a command,
+ * not a search string, so we don't need a slash.
+ */
+ if (!less_is_more);
+ ungetsc("/");
break;
}
}
@@ -367,7 +376,7 @@ opt__V(type, s)
any_display = 1;
putstr("less ");
putstr(version);
- putstr("\nCopyright (C) 2002 Mark Nudelman\n\n");
+ putstr("\nCopyright (C) 1984-2005 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");
@@ -450,8 +459,8 @@ opt_D(type, s)
}
if (type == TOGGLE)
{
- so_enter();
- so_exit();
+ at_enter(AT_STANDOUT);
+ at_exit();
}
break;
case QUERY:
diff --git a/contrib/less/option.c b/contrib/less/option.c
index 8bb4504ba672..744a9a1fd0a2 100644
--- a/contrib/less/option.c
+++ b/contrib/less/option.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -142,12 +142,12 @@ scan_option(s)
if (optname == NULL)
{
printopt = propt(optc);
- lc = SIMPLE_IS_LOWER(optc);
+ lc = ASCII_IS_LOWER(optc);
o = findopt(optc);
} else
{
printopt = optname;
- lc = SIMPLE_IS_LOWER(optname[0]);
+ lc = ASCII_IS_LOWER(optname[0]);
o = findopt_name(&optname, NULL, &err);
s = optname;
optname = NULL;
@@ -350,14 +350,14 @@ toggle_option(c, s, how_toggle)
{
case OPT_TOGGLE:
*(o->ovar) = flip_triple(*(o->ovar),
- islower(c));
+ ASCII_IS_LOWER(c));
break;
case OPT_UNSET:
*(o->ovar) = o->odefault;
break;
case OPT_SET:
*(o->ovar) = flip_triple(o->odefault,
- islower(c));
+ ASCII_IS_LOWER(c));
break;
}
break;
diff --git a/contrib/less/option.h b/contrib/less/option.h
index 8749d9359b54..7dab722b07d3 100644
--- a/contrib/less/option.h
+++ b/contrib/less/option.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/opttbl.c b/contrib/less/opttbl.c
index bdf8d05fc75e..bd9f97f3cef9 100644
--- a/contrib/less/opttbl.c
+++ b/contrib/less/opttbl.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -48,10 +48,13 @@ public int show_attn; /* Hilite first unread line */
public int shift_count; /* Number of positions to shift horizontally */
public int status_col; /* Display a status column */
public int use_lessopen; /* Use the LESSOPEN filter */
+public int quit_on_intr; /* Quit on interrupt */
#if HILITE_SEARCH
public int hilite_search; /* Highlight matched search patterns? */
#endif
+public int less_is_more = 0; /* Make compatible with POSIX more */
+
/*
* Long option names.
*/
@@ -76,6 +79,7 @@ static struct optname J__optname = { "status-column", NULL };
#if USERFILE
static struct optname k_optname = { "lesskey-file", NULL };
#endif
+static struct optname K__optname = { "quit-on-intr", NULL };
static struct optname L__optname = { "no-lessopen", NULL };
static struct optname m_optname = { "long-prompt", NULL };
static struct optname n_optname = { "line-numbers", NULL };
@@ -245,6 +249,14 @@ static struct loption option[] =
{ NULL, NULL, NULL }
},
#endif
+ { 'K', &K__optname,
+ BOOL, OPT_OFF, &quit_on_intr, NULL,
+ {
+ "Interrupt (ctrl-C) returns to prompt",
+ "Interrupt (ctrl-C) exits less",
+ NULL
+ }
+ },
{ 'l', NULL,
STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_l,
{ NULL, NULL, NULL }
@@ -428,6 +440,11 @@ static struct loption option[] =
init_option()
{
register struct loption *o;
+ char *p;
+
+ p = lgetenv("LESS_IS_MORE");
+ if (p != NULL && *p != '\0')
+ less_is_more = 1;
for (o = option; o->oletter != '\0'; o++)
{
@@ -454,7 +471,7 @@ findopt(c)
{
if (o->oletter == c)
return (o);
- if ((o->otype & TRIPLE) && toupper(o->oletter) == c)
+ if ((o->otype & TRIPLE) && ASCII_TO_UPPER(o->oletter) == c)
return (o);
}
return (NULL);
@@ -467,9 +484,9 @@ findopt(c)
is_optchar(c)
char c;
{
- if (SIMPLE_IS_UPPER(c))
+ if (ASCII_IS_UPPER(c))
return 1;
- if (SIMPLE_IS_LOWER(c))
+ if (ASCII_IS_LOWER(c))
return 1;
if (c == '-')
return 1;
@@ -498,7 +515,6 @@ findopt_name(p_optname, p_oname, p_err)
int maxlen = 0;
int ambig = 0;
int exact = 0;
- char *eq;
/*
* Check all options.
diff --git a/contrib/less/os.c b/contrib/less/os.c
index e4f4fb50bd87..01acd6c3c07b 100644
--- a/contrib/less/os.c
+++ b/contrib/less/os.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -216,6 +216,7 @@ errno_message(filename)
{
register char *p;
register char *m;
+ int len;
#if HAVE_ERRNO
#if MUST_DEFINE_ERRNO
extern int errno;
@@ -224,8 +225,9 @@ errno_message(filename)
#else
p = "cannot open";
#endif
- m = (char *) ecalloc(strlen(filename) + strlen(p) + 3, sizeof(char));
- sprintf(m, "%s: %s", filename, p);
+ len = strlen(filename) + strlen(p) + 3;
+ m = (char *) ecalloc(len, sizeof(char));
+ SNPRINTF2(m, len, "%s: %s", filename, p);
return (m);
}
diff --git a/contrib/less/output.c b/contrib/less/output.c
index 7f5acbac9b7a..b434bc9133f9 100644
--- a/contrib/less/output.c
+++ b/contrib/less/output.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -47,7 +47,6 @@ put_line()
register int c;
register int i;
int a;
- int curr_attr;
if (ABORT_SIGS())
{
@@ -58,49 +57,19 @@ put_line()
return;
}
- curr_attr = AT_NORMAL;
+ final_attr = AT_NORMAL;
for (i = 0; (c = gline(i, &a)) != '\0'; i++)
{
- if (a != curr_attr)
- {
- /*
- * Changing attributes.
- * Display the exit sequence for the old attribute
- * and the enter sequence for the new one.
- */
- switch (curr_attr)
- {
- case AT_UNDERLINE: ul_exit(); break;
- case AT_BOLD: bo_exit(); break;
- case AT_BLINK: bl_exit(); break;
- case AT_STANDOUT: so_exit(); break;
- }
- switch (a)
- {
- case AT_UNDERLINE: ul_enter(); break;
- case AT_BOLD: bo_enter(); break;
- case AT_BLINK: bl_enter(); break;
- case AT_STANDOUT: so_enter(); break;
- }
- curr_attr = a;
- }
- if (curr_attr == AT_INVIS)
- continue;
+ at_switch(a);
+ final_attr = a;
if (c == '\b')
putbs();
else
putchr(c);
}
- switch (curr_attr)
- {
- case AT_UNDERLINE: ul_exit(); break;
- case AT_BOLD: bo_exit(); break;
- case AT_BLINK: bl_exit(); break;
- case AT_STANDOUT: so_exit(); break;
- }
- final_attr = curr_attr;
+ at_exit();
}
static char obuf[OUTBUF_SIZE];
@@ -360,6 +329,25 @@ flush()
putchr(c)
int c;
{
+#if 0 /* fake UTF-8 output for testing */
+ extern int utf_mode;
+ if (utf_mode)
+ {
+ static char ubuf[MAX_UTF_CHAR_LEN];
+ static int ubuf_len = 0;
+ static int ubuf_index = 0;
+ if (ubuf_len == 0)
+ {
+ ubuf_len = utf_len(c);
+ ubuf_index = 0;
+ }
+ ubuf[ubuf_index++] = c;
+ if (ubuf_index < ubuf_len)
+ return c;
+ c = get_wchar(ubuf) & 0xFF;
+ ubuf_len = 0;
+ }
+#endif
if (need_clr)
{
need_clr = 0;
@@ -534,8 +522,9 @@ error(fmt, parg)
if (any_display && is_tty)
{
+ at_exit();
clear_bot();
- so_enter();
+ at_enter(AT_STANDOUT);
col += so_s_width;
}
@@ -548,7 +537,7 @@ error(fmt, parg)
}
putstr(return_to_continue);
- so_exit();
+ at_exit();
col += sizeof(return_to_continue) + so_e_width;
get_return();
@@ -578,11 +567,12 @@ ierror(fmt, parg)
char *fmt;
PARG *parg;
{
+ at_exit();
clear_bot();
- so_enter();
+ at_enter(AT_STANDOUT);
(void) less_printf(fmt, parg);
putstr(intr_to_abort);
- so_exit();
+ at_exit();
flush();
need_clr = 1;
}
diff --git a/contrib/less/pckeys.h b/contrib/less/pckeys.h
index 723df550f982..2425226e3a67 100644
--- a/contrib/less/pckeys.h
+++ b/contrib/less/pckeys.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/position.c b/contrib/less/position.c
index 7c10068856db..8d3b86d4b131 100644
--- a/contrib/less/position.c
+++ b/contrib/less/position.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/position.h b/contrib/less/position.h
index 29a90d91c79a..125dae5363e5 100644
--- a/contrib/less/position.h
+++ b/contrib/less/position.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/prompt.c b/contrib/less/prompt.c
index 9a2f99a4ec00..ee34b28bf393 100644
--- a/contrib/less/prompt.c
+++ b/contrib/less/prompt.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -164,7 +164,7 @@ curr_byte(where)
POSITION pos;
pos = position(where);
- while (pos == NULL_POSITION && where >= 0 && where < sc_height)
+ while (pos == NULL_POSITION && where >= 0 && where < sc_height-1)
pos = position(++where);
if (pos == NULL_POSITION)
pos = ch_length();
@@ -200,7 +200,7 @@ cond(c, where)
case 'd': /* Same as l */
return (linenums);
case 'L': /* Final line number known? */
- case 'D': /* Same as L */
+ case 'D': /* Final page number known? */
return (linenums && ch_length() != NULL_POSITION);
case 'm': /* More than one file? */
#if TAGS
@@ -254,6 +254,9 @@ protochar(c, where, iseditproto)
LINENUM last_linenum;
IFILE h;
+#undef PAGE_NUM
+#define PAGE_NUM(linenum) ((((linenum) - 1) / (sc_height - 1)) + 1)
+
switch (c)
{
case 'b': /* Current byte offset */
@@ -269,17 +272,26 @@ protochar(c, where, iseditproto)
case 'd': /* Current page number */
linenum = currline(where);
if (linenum > 0 && sc_height > 1)
- ap_linenum(((linenum - 1) / (sc_height - 1)) + 1);
+ ap_linenum(PAGE_NUM(linenum));
else
ap_quest();
break;
- case 'D': /* Last page number */
+ case 'D': /* Final page number */
+ /* Find the page number of the last byte in the file (len-1). */
len = ch_length();
- if (len == NULL_POSITION || len == ch_zero() ||
- (linenum = find_linenum(len)) <= 0)
+ if (len == NULL_POSITION)
ap_quest();
+ else if (len == 0)
+ /* An empty file has no pages. */
+ ap_linenum(0);
else
- ap_linenum(((linenum - 1) / (sc_height - 1)) + 1);
+ {
+ linenum = find_linenum(len - 1);
+ if (linenum <= 0)
+ ap_quest();
+ else
+ ap_linenum(PAGE_NUM(linenum));
+ }
break;
#if EDITOR
case 'E': /* Editor name */
@@ -518,7 +530,7 @@ pr_expand(proto, maxwidth)
}
if (mp == message)
- return (NULL);
+ return ("");
if (maxwidth > 0 && mp >= message + maxwidth)
{
/*
diff --git a/contrib/less/screen.c b/contrib/less/screen.c
index 8a8f6a3f848c..48afdbf975fd 100644
--- a/contrib/less/screen.c
+++ b/contrib/less/screen.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -38,11 +38,12 @@ extern int fd0;
#else
-#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS
-#include <termios.h>
-#if HAVE_SYS_IOCTL_H && !defined(TIOCGWINSZ)
+#if HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
+
+#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS
+#include <termios.h>
#else
#if HAVE_TERMIO_H
#include <termio.h>
@@ -52,9 +53,6 @@ extern int fd0;
#else
#include <sgtty.h>
#endif
-#if HAVE_SYS_IOCTL_H && (defined(TIOCGWINSZ) || defined(TCGETA) || defined(TIOCGETP) || defined(WIOCGETD))
-#include <sys/ioctl.h>
-#endif
#endif
#endif
@@ -189,7 +187,9 @@ static int init_done = 0;
public int auto_wrap; /* Terminal does \r\n when write past margin */
public int ignaw; /* Terminal ignores \n immediately after wrap */
-public int erase_char, kill_char; /* The user's erase and line-kill chars */
+public int erase_char; /* The user's erase char */
+public int erase2_char; /* The user's other erase char */
+public int kill_char; /* The user's line-kill char */
public int werase_char; /* The user's word-erase char */
public int sc_width, sc_height; /* Height & width of screen */
public int bo_s_width, bo_e_width; /* Printing width of boldface seq */
@@ -202,6 +202,7 @@ public int clear_bg; /* Clear fills with background color */
public int missing_cap = 0; /* Some capability is missing */
static int attrmode = AT_NORMAL;
+extern int binattr;
#if !MSDOS_COMPILER
static char *cheaper();
@@ -230,6 +231,7 @@ extern int sigs;
extern int wscroll;
extern int screen_trashed;
extern int tty;
+extern int top_scroll;
#if HILITE_SEARCH
extern int hilite_search;
#endif
@@ -257,6 +259,7 @@ raw_mode(on)
if (on == curr_on)
return;
+ erase2_char = '\b'; /* in case OS doesn't know about erase2 */
#if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS
{
struct termios s;
@@ -339,6 +342,9 @@ raw_mode(on)
}
#endif
erase_char = s.c_cc[VERASE];
+#ifdef VERASE2
+ erase2_char = s.c_cc[VERASE2];
+#endif
kill_char = s.c_cc[VKILL];
#ifdef VWERASE
werase_char = s.c_cc[VWERASE];
@@ -1201,7 +1207,7 @@ get_term()
if (below_mem && (sc_eos_clear == NULL || *sc_eos_clear == '\0'))
{
missing_cap = 1;
- sc_eol_clear = "";
+ sc_eos_clear = "";
}
sc_clear = ltgetstr("cl", &sp);
@@ -1505,6 +1511,19 @@ init()
tputs(sc_init, sc_height, putchr);
if (!no_keypad)
tputs(sc_s_keypad, sc_height, putchr);
+ if (top_scroll)
+ {
+ int i;
+
+ /*
+ * This is nice to terminals with no alternate screen,
+ * but with saved scrolled-off-the-top lines. This way,
+ * no previous line is lost, but we start with a whole
+ * screen to ourself.
+ */
+ for (i = 1; i < sc_height; i++)
+ putchr('\n');
+ }
#else
#if MSDOS_COMPILER==WIN32C
if (!no_init)
@@ -1846,12 +1865,12 @@ create_flash()
videopages = w.numvideopages;
if (videopages < 2)
{
- so_enter();
- so_exit();
+ at_enter(AT_STANDOUT);
+ at_exit();
} else
{
_setactivepage(1);
- so_enter();
+ at_enter(AT_STANDOUT);
blanks = (char *) ecalloc(w.numtextcols, sizeof(char));
for (col = 0; col < w.numtextcols; col++)
blanks[col] = ' ';
@@ -1860,7 +1879,7 @@ create_flash()
_setactivepage(0);
_setvisualpage(0);
free(blanks);
- so_exit();
+ at_exit();
}
#else
#if MSDOS_COMPILER==BORLANDC
@@ -2090,153 +2109,111 @@ clear_bot()
* cleared area with the current attribute.
*/
lower_left();
- switch (attrmode)
- {
- case AT_STANDOUT:
- so_exit();
- clear_eol_bot();
- so_enter();
- break;
- case AT_UNDERLINE:
- ul_exit();
- clear_eol_bot();
- ul_enter();
- break;
- case AT_BOLD:
- bo_exit();
- clear_eol_bot();
- bo_enter();
- break;
- case AT_BLINK:
- bl_exit();
+ if (attrmode == AT_NORMAL)
clear_eol_bot();
- bl_enter();
- break;
- default:
+ else
+ {
+ int saved_attrmode = attrmode;
+
+ at_exit();
clear_eol_bot();
- break;
+ at_enter(saved_attrmode);
}
}
-/*
- * Begin "standout" (bold, underline, or whatever).
- */
public void
-so_enter()
+at_enter(attr)
+ int attr;
{
-#if !MSDOS_COMPILER
- tputs(sc_s_in, 1, putchr);
-#else
- flush();
- SETCOLORS(so_fg_color, so_bg_color);
-#endif
- attrmode = AT_STANDOUT;
-}
+ attr = apply_at_specials(attr);
-/*
- * End "standout".
- */
- public void
-so_exit()
-{
#if !MSDOS_COMPILER
- tputs(sc_s_out, 1, putchr);
+ /* The one with the most priority is last. */
+ if (attr & AT_UNDERLINE)
+ tputs(sc_u_in, 1, putchr);
+ if (attr & AT_BOLD)
+ tputs(sc_b_in, 1, putchr);
+ if (attr & AT_BLINK)
+ tputs(sc_bl_in, 1, putchr);
+ if (attr & AT_STANDOUT)
+ tputs(sc_s_in, 1, putchr);
#else
flush();
- SETCOLORS(nm_fg_color, nm_bg_color);
+ /* The one with the most priority is first. */
+ if (attr & AT_STANDOUT)
+ {
+ SETCOLORS(so_fg_color, so_bg_color);
+ } else if (attr & AT_BLINK)
+ {
+ SETCOLORS(bl_fg_color, bl_bg_color);
+ }
+ else if (attr & AT_BOLD)
+ {
+ SETCOLORS(bo_fg_color, bo_bg_color);
+ }
+ else if (attr & AT_UNDERLINE)
+ {
+ SETCOLORS(ul_fg_color, ul_bg_color);
+ }
#endif
- attrmode = AT_NORMAL;
-}
-/*
- * Begin "underline" (hopefully real underlining,
- * otherwise whatever the terminal provides).
- */
- public void
-ul_enter()
-{
-#if !MSDOS_COMPILER
- tputs(sc_u_in, 1, putchr);
-#else
- flush();
- SETCOLORS(ul_fg_color, ul_bg_color);
-#endif
- attrmode = AT_UNDERLINE;
+ attrmode = attr;
}
-/*
- * End "underline".
- */
public void
-ul_exit()
+at_exit()
{
#if !MSDOS_COMPILER
- tputs(sc_u_out, 1, putchr);
+ /* Undo things in the reverse order we did them. */
+ if (attrmode & AT_STANDOUT)
+ tputs(sc_s_out, 1, putchr);
+ if (attrmode & AT_BLINK)
+ tputs(sc_bl_out, 1, putchr);
+ if (attrmode & AT_BOLD)
+ tputs(sc_b_out, 1, putchr);
+ if (attrmode & AT_UNDERLINE)
+ tputs(sc_u_out, 1, putchr);
#else
flush();
SETCOLORS(nm_fg_color, nm_bg_color);
#endif
+
attrmode = AT_NORMAL;
}
-/*
- * Begin "bold"
- */
public void
-bo_enter()
+at_switch(attr)
+ int attr;
{
-#if !MSDOS_COMPILER
- tputs(sc_b_in, 1, putchr);
-#else
- flush();
- SETCOLORS(bo_fg_color, bo_bg_color);
-#endif
- attrmode = AT_BOLD;
+ if (apply_at_specials(attr) != attrmode)
+ {
+ at_exit();
+ at_enter(attr);
+ }
}
-/*
- * End "bold".
- */
- public void
-bo_exit()
+ public int
+is_at_equiv(attr1, attr2)
+ int attr1;
+ int attr2;
{
-#if !MSDOS_COMPILER
- tputs(sc_b_out, 1, putchr);
-#else
- flush();
- SETCOLORS(nm_fg_color, nm_bg_color);
-#endif
- attrmode = AT_NORMAL;
-}
+ attr1 = apply_at_specials(attr1);
+ attr2 = apply_at_specials(attr2);
-/*
- * Begin "blink"
- */
- public void
-bl_enter()
-{
-#if !MSDOS_COMPILER
- tputs(sc_bl_in, 1, putchr);
-#else
- flush();
- SETCOLORS(bl_fg_color, bl_bg_color);
-#endif
- attrmode = AT_BLINK;
+ return (attr1 == attr2);
}
-/*
- * End "blink".
- */
- public void
-bl_exit()
+ public int
+apply_at_specials(attr)
+ int attr;
{
-#if !MSDOS_COMPILER
- tputs(sc_bl_out, 1, putchr);
-#else
- flush();
- SETCOLORS(nm_fg_color, nm_bg_color);
-#endif
- attrmode = AT_NORMAL;
+ if (attr & AT_BINARY)
+ attr |= binattr;
+ if (attr & AT_HILITE)
+ attr |= AT_STANDOUT;
+ attr &= ~(AT_BINARY|AT_HILITE);
+
+ return attr;
}
#if 0 /* No longer used */
diff --git a/contrib/less/scrsize.c b/contrib/less/scrsize.c
index 9af7e345cae9..2f8fb762ed0d 100644
--- a/contrib/less/scrsize.c
+++ b/contrib/less/scrsize.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
diff --git a/contrib/less/search.c b/contrib/less/search.c
index 7d0af8b284b3..e58eda71eaaa 100644
--- a/contrib/less/search.c
+++ b/contrib/less/search.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -120,9 +120,9 @@ cvt_text(odst, osrc, ops)
for (src = osrc, dst = odst; *src != '\0'; src++)
{
- if ((ops & CVT_TO_LC) && isupper((unsigned char) *src))
+ if ((ops & CVT_TO_LC) && IS_UPPER(*src))
/* Convert uppercase to lowercase. */
- *dst++ = tolower((unsigned char) *src);
+ *dst++ = TO_LOWER(*src);
else if ((ops & CVT_BS) && *src == '\b' && dst > odst)
/* Delete BS and preceding char. */
dst--;
@@ -130,7 +130,7 @@ cvt_text(odst, osrc, ops)
{
/* Skip to end of ANSI escape sequence. */
while (src[1] != '\0')
- if (is_ansi_end(*++src))
+ if (!is_ansi_middle(*++src))
break;
} else
/* Just copy. */
@@ -175,7 +175,7 @@ is_ucase(s)
register char *p;
for (p = s; *p != '\0'; p++)
- if (isupper((unsigned char) *p))
+ if (IS_UPPER(*p))
return (1);
return (0);
}
@@ -247,11 +247,18 @@ repaint_hilite(on)
if (pos == NULL_POSITION)
continue;
epos = position(slinenum+1);
+#if 0
/*
* If any character in the line is highlighted,
* repaint the line.
+ *
+ * {{ This doesn't work -- if line is drawn with highlights
+ * which should be erased (e.g. toggle -i with status column),
+ * we must redraw the line even if it has no highlights.
+ * For now, just repaint every line. }}
*/
- if (is_hilited(pos, epos, 1))
+ if (is_hilited(pos, epos, 1, NULL))
+#endif
{
(void) forw_line(pos);
goto_line(slinenum);
@@ -532,15 +539,41 @@ clr_hilite()
/*
* Should any characters in a specified range be highlighted?
+ */
+ static int
+is_hilited_range(pos, epos)
+ POSITION pos;
+ POSITION epos;
+{
+ struct hilite *hl;
+
+ /*
+ * Look at each highlight and see if any part of it falls in the range.
+ */
+ for (hl = hilite_anchor.hl_first; hl != NULL; hl = hl->hl_next)
+ {
+ if (hl->hl_endpos > pos &&
+ (epos == NULL_POSITION || epos > hl->hl_startpos))
+ return (1);
+ }
+ return (0);
+}
+
+/*
+ * Should any characters in a specified range be highlighted?
* If nohide is nonzero, don't consider hide_hilite.
*/
public int
-is_hilited(pos, epos, nohide)
+is_hilited(pos, epos, nohide, p_matches)
POSITION pos;
POSITION epos;
int nohide;
+ int *p_matches;
{
- struct hilite *hl;
+ int match;
+
+ if (p_matches != NULL)
+ *p_matches = 0;
if (!status_col &&
start_attnpos != NULL_POSITION &&
@@ -551,6 +584,16 @@ is_hilited(pos, epos, nohide)
*/
return (1);
+ match = is_hilited_range(pos, epos);
+ if (!match)
+ return (0);
+
+ if (p_matches != NULL)
+ /*
+ * Report matches, even if we're hiding highlights.
+ */
+ *p_matches = 1;
+
if (hilite_search == 0)
/*
* Not doing highlighting.
@@ -563,16 +606,7 @@ is_hilited(pos, epos, nohide)
*/
return (0);
- /*
- * Look at each highlight and see if any part of it falls in the range.
- */
- for (hl = hilite_anchor.hl_first; hl != NULL; hl = hl->hl_next)
- {
- if (hl->hl_endpos > pos &&
- (epos == NULL_POSITION || epos > hl->hl_startpos))
- return (1);
- }
- return (0);
+ return (1);
}
/*
@@ -615,6 +649,30 @@ add_hilite(anchor, hl)
ihl->hl_next = hl;
}
+ static void
+adj_hilite_ansi(cvt_ops, line, npos)
+ int cvt_ops;
+ char **line;
+ POSITION *npos;
+{
+ if (cvt_ops & CVT_ANSI)
+ while (**line == ESC)
+ {
+ /*
+ * Found an ESC. The file position moves
+ * forward past the entire ANSI escape sequence.
+ */
+ (*line)++;
+ (*npos)++;
+ while (**line != '\0')
+ {
+ (*npos)++;
+ if (!is_ansi_middle(*(*line)++))
+ break;
+ }
+ }
+}
+
/*
* Adjust hl_startpos & hl_endpos to account for backspace processing.
*/
@@ -664,38 +722,30 @@ adj_hilite(anchor, linepos, cvt_ops)
}
if (*line == '\0')
break;
- if (cvt_ops & CVT_ANSI)
- {
- while (line[0] == ESC)
- {
- /*
- * Found an ESC. The file position moves
- * forward past the entire ANSI escape sequence.
- */
- line++;
- npos++;
- while (*line != '\0')
- {
- npos++;
- if (is_ansi_end(*line++))
- break;
- }
- }
- }
+ adj_hilite_ansi(cvt_ops, &line, &npos);
opos++;
npos++;
line++;
if (cvt_ops & CVT_BS)
{
- while (line[0] == '\b' && line[1] != '\0')
+ while (*line == '\b')
{
+ npos++;
+ line++;
+ adj_hilite_ansi(cvt_ops, &line, &npos);
+ if (*line == '\0')
+ {
+ --npos;
+ --line;
+ break;
+ }
/*
* Found a backspace. The file position moves
* forward by 2 relative to the processed line
* which was searched in hilite_line.
*/
- npos += 2;
- line += 2;
+ npos++;
+ line++;
}
}
}
@@ -1041,7 +1091,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos)
* Return it.
*/
#if HILITE_SEARCH
- if (hilite_search == 1)
+ if (hilite_search == OPT_ON)
{
/*
* Clear the hilite list and add only
diff --git a/contrib/less/signal.c b/contrib/less/signal.c
index a641d99ee9de..d09747884f1a 100644
--- a/contrib/less/signal.c
+++ b/contrib/less/signal.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -33,6 +33,7 @@ extern int lnloop;
extern int linenums;
extern int wscroll;
extern int reading;
+extern int quit_on_intr;
/*
* Interrupt signal handler.
@@ -247,6 +248,8 @@ psignals()
#endif
if (tsignals & S_INTERRUPT)
{
+ if (quit_on_intr)
+ quit(QUIT_OK);
bell();
/*
* {{ You may wish to replace the bell() with
diff --git a/contrib/less/tags.c b/contrib/less/tags.c
index 409e1209e38f..5ea736428cef 100644
--- a/contrib/less/tags.c
+++ b/contrib/less/tags.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -498,7 +498,7 @@ findgtag(tag, type)
#if !HAVE_POPEN
return TAG_NOFILE;
#else
- char command[512];
+ char *command;
char *flag;
char *qtag;
char *cmd = lgetenv("LESSGLOBALTAGS");
@@ -528,10 +528,13 @@ findgtag(tag, type)
qtag = shell_quote(tag);
if (qtag == NULL)
qtag = tag;
+ command = (char *) ecalloc(strlen(cmd) + strlen(flag) +
+ strlen(qtag) + 5, sizeof(char));
sprintf(command, "%s -x%s %s", cmd, flag, qtag);
if (qtag != tag)
free(qtag);
fp = popen(command, "r");
+ free(command);
#endif
}
if (fp != NULL)
@@ -539,6 +542,7 @@ findgtag(tag, type)
while (fgets(buf, sizeof(buf), fp))
{
char *name, *file, *line;
+ int len;
if (sigs)
{
@@ -548,8 +552,9 @@ findgtag(tag, type)
#endif
return TAG_INTR;
}
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = 0;
+ len = strlen(buf);
+ if (len > 0 && buf[len-1] == '\n')
+ buf[len-1] = '\0';
else
{
int c;
@@ -695,14 +700,6 @@ gtagsearch()
* The tag, file, and line will each be NUL-terminated pointers
* into buf.
*/
-
-#ifndef isspace
-#define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f')
-#endif
-#ifndef isdigit
-#define isdigit(c) ((c) >= '0' && (c <= '9'))
-#endif
-
static int
getentry(buf, tag, file, line)
char *buf; /* standard or extended ctags -x format data */
@@ -712,12 +709,12 @@ getentry(buf, tag, file, line)
{
char *p = buf;
- for (*tag = p; *p && !isspace(*p); p++) /* tag name */
+ for (*tag = p; *p && !IS_SPACE(*p); p++) /* tag name */
;
if (*p == 0)
return (-1);
*p++ = 0;
- for ( ; *p && isspace(*p); p++) /* (skip blanks) */
+ for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */
;
if (*p == 0)
return (-1);
@@ -725,27 +722,27 @@ getentry(buf, tag, file, line)
* If the second part begin with other than digit,
* it is assumed tag type. Skip it.
*/
- if (!isdigit(*p))
+ if (!IS_DIGIT(*p))
{
- for ( ; *p && !isspace(*p); p++) /* (skip tag type) */
+ for ( ; *p && !IS_SPACE(*p); p++) /* (skip tag type) */
;
- for (; *p && isspace(*p); p++) /* (skip blanks) */
+ for (; *p && IS_SPACE(*p); p++) /* (skip blanks) */
;
}
- if (!isdigit(*p))
+ if (!IS_DIGIT(*p))
return (-1);
*line = p; /* line number */
- for (*line = p; *p && !isspace(*p); p++)
+ for (*line = p; *p && !IS_SPACE(*p); p++)
;
if (*p == 0)
return (-1);
*p++ = 0;
- for ( ; *p && isspace(*p); p++) /* (skip blanks) */
+ for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */
;
if (*p == 0)
return (-1);
*file = p; /* file name */
- for (*file = p; *p && !isspace(*p); p++)
+ for (*file = p; *p && !IS_SPACE(*p); p++)
;
if (*p == 0)
return (-1);
diff --git a/contrib/less/ttyin.c b/contrib/less/ttyin.c
index 5d99d335e9e1..ca500f9a8ee8 100644
--- a/contrib/less/ttyin.c
+++ b/contrib/less/ttyin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2004 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.
@@ -26,6 +26,7 @@ static DWORD console_mode;
public int tty;
extern int sigs;
+extern int utf_mode;
/*
* Open keyboard for input.
@@ -101,6 +102,8 @@ getchr()
{
char c;
int result;
+ int hex_in = 0;
+ int hex_value = 0;
do
{
@@ -132,6 +135,34 @@ getchr()
quit(QUIT_ERROR);
}
#endif
+#if 0 /* allow entering arbitrary hex chars for testing */
+ /* ctrl-A followed by two hex chars makes a byte */
+ if (c == CONTROL('A'))
+ {
+ hex_in = 2;
+ result = 0;
+ continue;
+ }
+ if (hex_in > 0)
+ {
+ int v;
+ if (c >= '0' && c <= '9')
+ v = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ v = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ v = c - 'A' + 10;
+ else
+ hex_in = 0;
+ hex_value = (hex_value << 4) | v;
+ if (--hex_in > 0)
+ {
+ result = 0;
+ continue;
+ }
+ c = hex_value;
+ }
+#endif
/*
* Various parts of the program cannot handle
* an input character of '\0'.
@@ -141,5 +172,5 @@ getchr()
c = '\340';
} while (result != 1);
- return (c & 0377);
+ return (c & 0xFF);
}
diff --git a/contrib/less/version.c b/contrib/less/version.c
index 46dea70afc85..64492a9e60b0 100644
--- a/contrib/less/version.c
+++ b/contrib/less/version.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2002 Mark Nudelman
+ * Copyright (C) 1984-2005 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.
@@ -644,6 +644,30 @@ v379 11/23/02 Add -L option; fix bug with ctrl-K in lesskey files;
fix minor man page problems; change to autoconf 2.54.
v380 11/24/02 Make LINENUM same as POSITION.
v381 11/28/02 Make -N use 7 columns for line number if possible.
+-----------------------------------------------------------------
+v382 2/3/04 Remove copyrighted code.
+-----------------------------------------------------------------
+v383 2/16/04 Add history file; add -K option; improve UTF-8 handling;
+ fix some signed char bugs (thanks to Christian Biere);
+ fix some upper/lower case bugs (thanks to Bjoern Jacke);
+ add erase2 char (thanks to David Lawrence);
+ add windows charset (thanks to Dimitar Zhekov).
+v384 2/20/04 Improvements in UTF-8 handling.
+v385 2/23/04 Fix UTF-8 output bug.
+-----------------------------------------------------------------
+v386 9/13/05 Improvements to UTF-8 shift & color (thanks to Charles Levert);
+ protect against invalid LESSOPEN and LESSCLOSE values.
+v387 9/14/05 Update Charles Levert's UTF-8 patch.
+v388 9/14/05 Change history behavior; change most sprintf calls to snprintf.
+v389 9/14/05 Fix copy & paste with long lines; improve performance of
+ expand_linebuf; fix crash in init_mlist;
+v390 9/15/05 Show search matches in status column even if -G is set.
+-----------------------------------------------------------------
+v391 9/17/05 Fix bugs.
+v392 10/14/05 Fix line wrapping bug.
+v393 10/19/05 Allow multiple attributes per char; fix bold+underline bug
+ (thanks again to Charles Levert).
+v394 11/8/05 Fix prompt bug; fix compile problem in Windows build.
*/
-char version[] = "381";
+char version[] = "394";