Import less v394

This commit is contained in:
Xin LI 2006-08-20 15:49:51 +00:00
parent ba8e3be904
commit 6dcb072b30
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/less/dist/; revision=161475
62 changed files with 4104 additions and 2806 deletions

View File

@ -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

View File

@ -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}

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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,32 +338,54 @@ 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?
*/
@ -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;
}

19
contrib/less/charset.h Normal file
View File

@ -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))

View File

@ -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.

View File

@ -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')
{
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 (cmd_col + width >= sc_width)
break;
putstr(p);
cmd_col += strlen(p);
cp = np;
putstr(pr);
cmd_col += width;
}
while (*cp != '\0')
{
char *np = cp;
int width;
char *pr = cmd_step_right(&np, &width, NULL);
if (width > 0)
break;
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 */
}

View File

@ -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 = '.';

120
contrib/less/configure vendored
View File

@ -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
@ -4219,6 +4316,8 @@ fi
@ -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.

View File

@ -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 "\\"
/*

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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 ();

View File

@ -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.

View File

@ -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);

View File

@ -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);

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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 = '"';

49
contrib/less/lessecho.man Normal file
View File

@ -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)

47
contrib/less/lessecho.nro Normal file
View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.
_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 -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:
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.
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
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)

View File

@ -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

View File

@ -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.

File diff suppressed because it is too large Load Diff

View File

@ -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.

View File

@ -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 */

View File

@ -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();

View File

@ -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.

View File

@ -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.

View File

@ -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:

View File

@ -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;

View File

@ -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.

View File

@ -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.

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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)
{
/*

View File

@ -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)
if (attrmode == AT_NORMAL)
clear_eol_bot();
else
{
case AT_STANDOUT:
so_exit();
int saved_attrmode = attrmode;
at_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();
clear_eol_bot();
bl_enter();
break;
default:
clear_eol_bot();
break;
at_enter(saved_attrmode);
}
}
/*
* Begin "standout" (bold, underline, or whatever).
*/
public void
so_enter()
at_enter(attr)
int attr;
{
attr = apply_at_specials(attr);
#if !MSDOS_COMPILER
tputs(sc_s_in, 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(so_fg_color, so_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_STANDOUT;
attrmode = attr;
}
/*
* End "standout".
*/
public void
so_exit()
at_exit()
{
#if !MSDOS_COMPILER
tputs(sc_s_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 "underline" (hopefully real underlining,
* otherwise whatever the terminal provides).
*/
public void
ul_enter()
at_switch(attr)
int attr;
{
#if !MSDOS_COMPILER
tputs(sc_u_in, 1, putchr);
#else
flush();
SETCOLORS(ul_fg_color, ul_bg_color);
#endif
attrmode = AT_UNDERLINE;
if (apply_at_specials(attr) != attrmode)
{
at_exit();
at_enter(attr);
}
}
/*
* End "underline".
*/
public void
ul_exit()
public int
is_at_equiv(attr1, attr2)
int attr1;
int attr2;
{
#if !MSDOS_COMPILER
tputs(sc_u_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);
return (attr1 == attr2);
}
/*
* Begin "bold"
*/
public void
bo_enter()
public int
apply_at_specials(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 (attr & AT_BINARY)
attr |= binattr;
if (attr & AT_HILITE)
attr |= AT_STANDOUT;
attr &= ~(AT_BINARY|AT_HILITE);
/*
* End "bold".
*/
public void
bo_exit()
{
#if !MSDOS_COMPILER
tputs(sc_b_out, 1, putchr);
#else
flush();
SETCOLORS(nm_fg_color, nm_bg_color);
#endif
attrmode = AT_NORMAL;
}
/*
* 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;
}
/*
* End "blink".
*/
public void
bl_exit()
{
#if !MSDOS_COMPILER
tputs(sc_bl_out, 1, putchr);
#else
flush();
SETCOLORS(nm_fg_color, nm_bg_color);
#endif
attrmode = AT_NORMAL;
return attr;
}
#if 0 /* No longer used */

View File

@ -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.

View File

@ -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);
@ -530,17 +537,43 @@ clr_hilite()
prep_startpos = prep_endpos = NULL_POSITION;
}
/*
* 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

View File

@ -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

View File

@ -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);

View File

@ -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
{
@ -131,6 +134,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
@ -141,5 +172,5 @@ getchr()
c = '\340';
} while (result != 1);
return (c & 0377);
return (c & 0xFF);
}

View File

@ -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";