summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/less/INSTALL266
-rw-r--r--usr.bin/less/LICENSE27
-rw-r--r--usr.bin/less/Makefile.aut116
-rw-r--r--usr.bin/less/configure.ac563
-rw-r--r--usr.bin/less/lessecho.c272
-rw-r--r--usr.bin/less/lglob.h95
-rw-r--r--usr.bin/less/mkfuncs.awk9
-rw-r--r--usr.bin/less/mkhelp.c69
-rw-r--r--usr.bin/less/pckeys.h34
-rw-r--r--usr.bin/less/scrsize.c104
10 files changed, 1442 insertions, 113 deletions
diff --git a/usr.bin/less/INSTALL b/usr.bin/less/INSTALL
index 8a7d026f700..c2ab230e447 100644
--- a/usr.bin/less/INSTALL
+++ b/usr.bin/less/INSTALL
@@ -1,146 +1,186 @@
- This is a generic INSTALL file for utilities distributions.
-If this package does not come with, e.g., installable documentation or
-data files, please ignore the references to them below.
+ This file describes how to build and install less using
+the "configure" script. This only works on Unix systems.
+To install on other systems, read the README file.
+
+
+Basic Installation
+==================
+
+ These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
-various system-dependent variables used during compilation, and
-creates the Makefile(s) (one in each subdirectory of the source
-directory). In some packages it creates a C header file containing
-system-dependent definitions. It also creates a file `config.status'
-that you can run in the future to recreate the current configuration.
+various system-dependent variables used during compilation. It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions. Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, a file
+`config.cache' that saves the results of its tests to speed up
+reconfiguring, and a file `config.log' containing compiler output
+(useful mainly for debugging `configure').
+
+ If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release. If at some point `config.cache'
+contains results you don't want to keep, you may remove or edit it.
+
+ The file `configure.in' is used to create `configure' by a program
+called `autoconf'. You only need `configure.in' if you want to change
+it or regenerate `configure' using a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+ 1. `cd' to the directory containing the package's source code and type
+ `./configure' to configure the package for your system. If you're
+ using `csh' on an old version of System V, you might need to type
+ `sh ./configure' instead to prevent `csh' from trying to execute
+ `configure' itself.
+
+ Running `configure' takes awhile. While running, it prints some
+ messages telling which features it is checking for.
+
+ 2. Type `make' to compile the package.
-To compile this package:
+ 3. Optionally, type `make check' to run any self-tests that come with
+ the package.
-1. Configure the package for your system.
+ 4. Type `make install' to install the programs and any data files and
+ documentation.
- Normally, you just `cd' to the directory containing the package's
-source code and type `./configure'. If you're using `csh' on an old
-version of System V, you might need to type `sh configure' instead to
-prevent `csh' from trying to execute `configure' itself.
+ 5. You can remove the program binaries and object files from the
+ source code directory by typing `make clean'. To also remove the
+ files that `configure' created (so you can compile the package for
+ a different kind of computer), type `make distclean'. There is
+ also a `make maintainer-clean' target, but that is intended mainly
+ for the package's developers. If you use it, you may have to get
+ all sorts of other programs in order to regenerate files that came
+ with the distribution.
- Running `configure' takes awhile. While it is running, it
-prints some messages that tell what it is doing. If you don't want to
-see any messages, run `configure' with its standard output redirected
-to `/dev/null'; for example, `./configure >/dev/null'.
+Compilers and Options
+=====================
- To compile the package in a different directory from the one
-containing the source code, you must use a version of `make' that
+ Some systems require unusual options for compilation or linking that
+the `configure' script does not know about. You can give `configure'
+initial values for variables by setting them in the environment. Using
+a Bourne-compatible shell, you can do that on the command line like
+this:
+ CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
+
+Or on systems that have the `env' program, you can do it like this:
+ env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
+
+Compiling For Multiple Architectures
+====================================
+
+ You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
-source code in the directory that `configure' is in and in `..'. If
-for some reason `configure' is not in the source code directory that
-you are configuring, then it will report that it can't find the source
-code. In that case, run `configure' with the option `--srcdir=DIR',
-where DIR is the directory that contains the source code.
+source code in the directory that `configure' is in and in `..'.
+
+ If you have to use a `make' that does not supports the `VPATH'
+variable, you have to compile the package for one architecture at a time
+in the source code directory. After you have installed the package for
+one architecture, use `make distclean' before reconfiguring for another
+architecture.
+
+Installation Names
+==================
By default, `make install' will install the package's files in
`/usr/local/bin', `/usr/local/man', etc. You can specify an
installation prefix other than `/usr/local' by giving `configure' the
-option `--prefix=PATH'. Alternately, you can do so by consistently
-giving a value for the `prefix' variable when you run `make', e.g.,
- make prefix=/usr/gnu
- make prefix=/usr/gnu install
+option `--prefix=PATH'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
-give `configure' the option `--exec-prefix=PATH' or set the `make'
-variable `exec_prefix' to PATH, the package will use PATH as the prefix
-for installing programs and libraries. Data files and documentation
-will still use the regular prefix. Normally, all files are installed
-using the same prefix.
-
- Some packages pay attention to `--with-PACKAGE' options to
-`configure', where PACKAGE is something like `gnu-as' or `x' (for the
-X Window System). They may also pay attention to `--enable-FEATURE'
-options, where FEATURE indicates an optional part of the package. The
-README should mention any `--with-' and `--enable-' options that the
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+ In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files. Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+ If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+ Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System). The
+`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
- `configure' also recognizes the following options:
+ For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+ There may be some features `configure' can not figure out
+automatically, but needs to determine by the type of host the package
+will run on. Usually `configure' can figure that out, but if it prints
+a message saying it can not guess the host type, give it the
+`--host=TYPE' option. TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name with three fields:
+ CPU-COMPANY-SYSTEM
+
+See the file `config.sub' for the possible values of each field. If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the host type.
+
+ If you are building compiler tools for cross-compiling, you can also
+use the `--target=TYPE' option to select the type of system they will
+produce code for and the `--build=TYPE' option to select the type of
+system on which you are compiling the package.
+
+Sharing Defaults
+================
+
+ If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists. Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Operation Controls
+==================
+
+ `configure' recognizes the following options to control how it
+operates.
+
+`--cache-file=FILE'
+ Use and save the results of the tests in FILE instead of
+ `./config.cache'. Set FILE to `/dev/null' to disable caching, for
+ debugging `configure'.
`--help'
Print a summary of the options to `configure', and exit.
`--quiet'
`--silent'
+`-q'
Do not print messages saying which checks are being made.
-`--verbose'
- Print the results of the checks.
+`--srcdir=DIR'
+ Look for the package's source code in directory DIR. Usually
+ `configure' can determine that directory automatically.
`--version'
Print the version of Autoconf used to generate the `configure'
script, and exit.
-`--x-includes=DIR'
- X include files are in DIR.
-
-`--x-libraries=DIR'
- X library files are in DIR.
-
- `configure' also accepts and ignores some other options.
-
- On systems that require unusual options for compilation or linking
-that the package's `configure' script does not know about, you can give
-`configure' initial values for variables by setting them in the
-environment. In Bourne-compatible shells, you can do that on the
-command line like this:
+`configure' also accepts some other, not widely useful, options.
- CC='gcc -traditional' LIBS=-lposix ./configure
-
-On systems that have the `env' program, you can do it like this:
-
- env CC='gcc -traditional' LIBS=-lposix ./configure
-
- Here are the `make' variables that you might want to override with
-environment variables when running `configure'.
-
- For these variables, any value given in the environment overrides the
-value that `configure' would choose:
-
- - Variable: CC
- C compiler program. The default is `cc'.
-
- - Variable: INSTALL
- Program to use to install files. The default is `install' if you
- have it, `cp' otherwise.
-
- For these variables, any value given in the environment is added to
-the value that `configure' chooses:
-
- - Variable: DEFS
- Configuration options, in the form `-Dfoo -Dbar...'. Do not use
- this variable in packages that create a configuration header file.
-
- - Variable: LIBS
- Libraries to link with, in the form `-lfoo -lbar...'.
-
- If you need to do unusual things to compile the package, we encourage
-you to figure out how `configure' could check whether to do them, and
-mail diffs or instructions to the address given in the README so we
-can include them in the next release.
-
-2. Type `make' to compile the package. If you want, you can override
-the `make' variables CFLAGS and LDFLAGS like this:
-
- make CFLAGS=-O2 LDFLAGS=-s
-
-3. If the package comes with self-tests and you want to run them,
-type `make check'. If you're not sure whether there are any, try it;
-if `make' responds with something like
- make: *** No way to make target `check'. Stop.
-then the package does not come with self-tests.
-
-4. Type `make install' to install programs, data files, and
-documentation.
-
-5. You can remove the program binaries and object files from the
-source directory by typing `make clean'. To also remove the
-Makefile(s), the header file containing system-dependent definitions
-(if the package uses one), and `config.status' (all the files that
-`configure' created), type `make distclean'.
-
- The file `configure.in' is used to create `configure' by a program
-called `autoconf'. You only need it if you want to regenerate
-`configure' using a newer version of `autoconf'.
diff --git a/usr.bin/less/LICENSE b/usr.bin/less/LICENSE
new file mode 100644
index 00000000000..dd154f6771d
--- /dev/null
+++ b/usr.bin/less/LICENSE
@@ -0,0 +1,27 @@
+ Less License
+ ------------
+
+Less
+Copyright (C) 1984-2002 Mark Nudelman
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice in the documentation and/or other materials provided with
+ the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/usr.bin/less/Makefile.aut b/usr.bin/less/Makefile.aut
new file mode 100644
index 00000000000..f105d6902f0
--- /dev/null
+++ b/usr.bin/less/Makefile.aut
@@ -0,0 +1,116 @@
+# Makefile for authoring less.
+
+EMAIL = markn@greenwoodsoftware.com
+HOMEPAGE = http://www.greenwoodsoftware.com/less
+SHELL = /bin/sh
+RCS = rcs
+NROFF = nroff -man
+
+srcdir = .
+
+SRC = \
+ main.c screen.c brac.c ch.c charset.c cmdbuf.c \
+ command.c decode.c edit.c filename.c forwback.c \
+ help.c ifile.c input.c jump.c line.c linenum.c \
+ lsystem.c mark.c optfunc.c option.c opttbl.c os.c \
+ output.c position.c prompt.c search.c signal.c \
+ tags.c ttyin.c version.c
+DISTFILES_W = \
+ defines.ds Makefile.dsb Makefile.dsg Makefile.dsu \
+ defines.o2 Makefile.o2e \
+ defines.o9 Makefile.o9c Makefile.o9u \
+ defines.wn Makefile.wnm Makefile.wnb
+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 \
+ install.sh defines.h.in mkinstalldirs \
+ less.nro lesskey.nro less.man lesskey.man less.hlp \
+ mkfuncs.awk mkhelp.c \
+ ${DISTFILES_W}
+
+all: help.c funcs.h ${srcdir}/configure
+
+help.c: less.hlp mkhelp
+ -mv -f ${srcdir}/help.c ${srcdir}/help.c.old
+ rm -rf help.c
+ ./mkhelp < less.hlp > help.c
+ if cmp -s help.c help.c.old; then mv help.c.old help.c; fi
+
+mkhelp: mkhelp.c
+ ${CC} -o mkhelp mkhelp.c
+
+${srcdir}/configure: ${srcdir}/configure.ac \
+ ${srcdir}/Makefile.in
+ cd ${srcdir}; autoheader; autoconf
+
+funcs.h: ${SRC:%=${srcdir}/%}
+ -mv -f ${srcdir}/funcs.h ${srcdir}/funcs.h.old
+ awk -f ${srcdir}/mkfuncs.awk ${SRC:%=${srcdir}/%} >${srcdir}/funcs.h
+ if cmp -s funcs.h funcs.h.old; then mv funcs.h.old funcs.h; fi
+
+lint:
+ lint -I. ${CPPFLAGS} ${SRC}
+
+clean:
+ rm -f Makefile config.status config.log config.cache defines.h stamp-h \
+ README NEWS less.nro lesskey.nro less.man lesskey.man
+
+distclean: clean
+realclean: clean
+
+REPLACE_VERSION = \
+ @REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/\1/' -e q ${srcdir}/version.c`; \
+ DT=`date '+%d %h %Y'`; \
+ echo "Stuffing version number $$REL into $@"; \
+ sed \
+ -e "s;@@VERSION@@;$$REL;" \
+ -e "s;@@DATE@@;$$DT;" \
+ -e "s;@@EMAIL@@;${EMAIL};" \
+ -e "s;@@HOMEPAGE@@;${HOMEPAGE};" >$@
+
+${srcdir}/README: ${srcdir}/README.VER ${srcdir}/version.c
+ ${REPLACE_VERSION} ${srcdir}/README.VER
+${srcdir}/NEWS: ${srcdir}/NEWS.VER ${srcdir}/version.c
+ ${REPLACE_VERSION} ${srcdir}/NEWS.VER
+${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}/less.hlp: ${srcdir}/less.hlp.VER ${srcdir}/version.c
+ ${REPLACE_VERSION} ${srcdir}/less.hlp.VER
+
+${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
+
+
+distfiles: ${DISTFILES}
+
+dist: ${DISTFILES}
+ if [ ! -d ${srcdir}/release ]; then mkdir ${srcdir}/release; fi
+ @cd ${srcdir}; \
+ REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/less-\1/' -e q version.c`; \
+ rm -rf release/$$REL; mkdir release/$$REL; \
+ echo "Preparing $$REL"; \
+ rm -rf $$REL; mkdir $$REL; \
+ for file in ${DISTFILES}; do \
+ cp -p $$file $$REL; \
+ chmod -w $$REL/$$file; \
+ done; \
+ cd $$REL; chmod +w ${DISTFILES_W}; cd ..; \
+ echo "Creating release/$$REL/$$REL.tar.gz"; \
+ tar -cf - $$REL | gzip -c >release/$$REL/$$REL.tar.gz; \
+ echo "Creating release/$$REL/$$REL.zip"; \
+ zip -rq release/$$REL/$$REL.zip $$REL; \
+ rm -rf $$REL
+
+tagall:
+ @REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/v\1/' -e q ${srcdir}/version.c`; \
+ echo "tagging $$REL"; \
+ for f in ${srcdir}/RCS/*,v; do \
+ REV=`co -p $$f 2>&1 | sed -e '1d' -e '3,$$d' -e 's/revision //'`; \
+ ${RCS} -N$$REL:$$REV $$f; \
+ done
diff --git a/usr.bin/less/configure.ac b/usr.bin/less/configure.ac
new file mode 100644
index 00000000000..d9e6ccab6ec
--- /dev/null
+++ b/usr.bin/less/configure.ac
@@ -0,0 +1,563 @@
+# Process this file with autoconf to produce a configure script.
+
+# Copyright (C) 1984-2002 Mark Nudelman
+#
+# You may distribute under the terms of either the GNU General Public
+# License or the Less License, as specified in the README file.
+#
+# For more information about less, or for information on how to
+# contact the author, see the README file.
+
+# Autoconf initialization.
+AC_INIT(less, 1)
+AC_CONFIG_SRCDIR([forwback.c])
+AC_CONFIG_HEADER([defines.h])
+
+# Checks for programs.
+AC_PROG_CC
+AC_ISC_POSIX
+AC_PROG_GCC_TRADITIONAL
+AC_PROG_INSTALL
+
+# Checks for compilation model.
+AC_SYS_LARGEFILE
+
+# Checks for general libraries.
+AC_CHECK_LIB(xcurses, initscr, [have_xcurses=yes], [have_xcurses=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])
+AC_CHECK_LIB(termlib, tgetent, [have_termlib=yes], [have_termlib=no])
+# Regular expressions (regcmp) are in -lgen on Solaris 2,
+# and in -lintl on SCO Unix.
+AC_CHECK_LIB(gen, regcmp)
+AC_CHECK_LIB(intl, regcmp)
+AC_CHECK_LIB(PW, regcmp)
+
+# Checks for terminal libraries
+AC_MSG_CHECKING([for working terminal libraries])
+TERMLIBS=
+
+# Check for systems where curses is broken.
+curses_broken=0
+if test x`uname -s` = "xHP-UX" >/dev/null 2>&1; then
+if test x`uname -r` = "xB.11.00" >/dev/null 2>&1; then
+ curses_broken=1
+fi
+if test x`uname -r` = "xB.11.11" >/dev/null 2>&1; then
+ curses_broken=1
+fi
+fi
+
+if test $curses_broken = 0; then
+# -- Try xcurses.
+if test "x$TERMLIBS" = x; then
+ if test $have_xcurses = yes; then
+ TERMLIBS="-lxcurses"
+ 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
+ TERMLIBS="-lncurses"
+ 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 curses.
+if test "x$TERMLIBS" = x; then
+ if test $have_curses = yes; then
+ TERMLIBS="-lcurses"
+ 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 curses & termcap.
+if test "x$TERMLIBS" = x; then
+ if test $have_curses = yes; then
+ if test $have_termcap = yes; then
+ TERMLIBS="-lcurses -ltermcap"
+ 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
+fi
+fi
+
+# -- Try termcap.
+if test "x$TERMLIBS" = x; then
+ if test $have_termcap = yes; then
+ TERMLIBS="-ltermcap"
+ 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 termlib.
+if test "x$TERMLIBS" = x; then
+ if test $have_termlib = yes; then
+ TERMLIBS="-lcurses -ltermlib"
+ 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
+
+if test "x$TERMLIBS" = x; then
+ AC_MSG_RESULT(Cannot find terminal libraries - configure failed)
+ exit 1
+fi
+AC_MSG_RESULT(using $TERMLIBS)
+LIBS="$LIBS $TERMLIBS"
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([ctype.h errno.h fcntl.h limits.h stdio.h stdlib.h string.h termcap.h termio.h termios.h time.h unistd.h values.h sys/ioctl.h sys/stream.h sys/ptem.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_HEADER_STAT
+AC_C_CONST
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_HEADER_TIME
+
+# Autoheader templates for symbols defined later by AC_DEFINE.
+AH_TEMPLATE([HAVE_POSIX_REGCOMP],
+ [POSIX regcomp() and regex.h])
+AH_TEMPLATE([HAVE_PCRE],
+ [PCRE (Perl-compatible regular expression) library])
+AH_TEMPLATE([HAVE_RE_COMP],
+ [BSD re_comp()])
+AH_TEMPLATE([HAVE_REGCMP],
+ [System V regcmp()])
+AH_TEMPLATE([HAVE_V8_REGCOMP],
+ [Henry Spencer V8 regcomp() and regexp.h])
+AH_TEMPLATE([NO_REGEX],
+ [pattern matching is supported, but without metacharacters.])
+AH_TEMPLATE([HAVE_REGEXEC2],
+ [])
+AH_TEMPLATE([HAVE_VOID],
+ [Define HAVE_VOID if your compiler supports the "void" type.])
+AH_TEMPLATE([HAVE_CONST],
+ [Define HAVE_CONST if your compiler supports the "const" modifier.])
+AH_TEMPLATE([HAVE_TIME_T],
+ [Define HAVE_TIME_T if your system supports the "time_t" type.])
+AH_TEMPLATE([HAVE_STRERROR],
+ [Define HAVE_STRERROR if you have the strerror() function.])
+AH_TEMPLATE([HAVE_FILENO],
+ [Define HAVE_FILENO if you have the fileno() macro.])
+AH_TEMPLATE([HAVE_ERRNO],
+ [Define HAVE_ERRNO if you have the errno variable.])
+AH_TEMPLATE([MUST_DEFINE_ERRNO],
+ [Define MUST_DEFINE_ERRNO if you have errno but it is not define in errno.h.])
+AH_TEMPLATE([HAVE_SYS_ERRLIST],
+ [Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable.])
+AH_TEMPLATE([HAVE_OSPEED],
+ [Define HAVE_OSPEED if your termcap library has the ospeed variable.])
+AH_TEMPLATE([MUST_DEFINE_OSPEED],
+ [Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined in termcap.h.])
+AH_TEMPLATE([HAVE_LOCALE],
+ [Define HAVE_LOCALE if you have locale.h and setlocale.])
+AH_TEMPLATE([HAVE_TERMIOS_FUNCS],
+ [Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr.])
+AH_TEMPLATE([HAVE_UPPER_LOWER],
+ [Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower.])
+AH_TEMPLATE([HAVE_SIGSET_T],
+ [Define HAVE_SIGSET_T you have the sigset_t type.])
+AH_TEMPLATE([HAVE_SIGEMPTYSET],
+ [Define HAVE_SIGEMPTYSET if you have the sigemptyset macro.])
+AH_TEMPLATE([EDIT_PGM],
+ [Define EDIT_PGM to your editor.])
+
+# Checks for identifiers.
+AC_TYPE_OFF_T
+AC_MSG_CHECKING(for void)
+AC_TRY_COMPILE(, [void *foo = 0;],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_VOID)], [AC_MSG_RESULT(no)])
+AC_MSG_CHECKING(for const)
+AC_TRY_COMPILE(, [const int foo = 0;],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_CONST)], [AC_MSG_RESULT(no)])
+AC_MSG_CHECKING(for time_t)
+AC_TRY_COMPILE([#include <time.h>], [time_t t = 0;],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_TIME_T)], [AC_MSG_RESULT(no)])
+
+# Checks for library functions.
+AC_TYPE_SIGNAL
+AC_CHECK_FUNCS([fsync memcpy popen _setjmp sigprocmask sigsetmask stat strchr strstr system])
+
+# Some systems have termios.h but not the corresponding functions.
+AC_CHECK_FUNC(tcgetattr, AC_DEFINE(HAVE_TERMIOS_FUNCS))
+
+AC_MSG_CHECKING(for fileno)
+AC_TRY_LINK([
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif], [static int x; x = fileno(stdin);],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_FILENO)], [AC_MSG_RESULT(no)])
+
+AC_MSG_CHECKING(for strerror)
+AC_TRY_LINK([
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#if HAVE_STRING_H
+#include <string.h>
+#endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif], [static char *x; x = strerror(0);],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STRERROR)], [AC_MSG_RESULT(no)])
+
+AC_MSG_CHECKING(for sys_errlist)
+AC_TRY_LINK(, [extern char *sys_errlist[]; static char **x; x = sys_errlist;],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYS_ERRLIST)], [AC_MSG_RESULT(no)])
+
+AC_MSG_CHECKING(for sigset_t)
+AC_TRY_LINK([
+#include <signal.h>
+], [sigset_t s; s = 0;],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SIGSET_T)], [AC_MSG_RESULT(no)])
+
+AC_MSG_CHECKING(for sigemptyset)
+AC_TRY_LINK([
+#include <signal.h>
+], [sigset_t s; sigemptyset(&s);],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SIGEMPTYSET)], [AC_MSG_RESULT(no)])
+
+have_errno=no
+AC_MSG_CHECKING(for errno)
+AC_TRY_LINK([
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif], [static int x; x = errno;],
+ [AC_MSG_RESULT(yes - in errno.h); AC_DEFINE(HAVE_ERRNO) have_errno=yes])
+if test $have_errno = no; then
+AC_TRY_LINK([
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif], [extern int errno; static int x; x = errno;],
+ [AC_MSG_RESULT(yes - must define); AC_DEFINE(HAVE_ERRNO) AC_DEFINE(MUST_DEFINE_ERRNO)],
+ [AC_MSG_RESULT(no)])
+fi
+
+AC_MSG_CHECKING(for locale)
+AC_TRY_LINK([#include <locale.h>
+#include <ctype.h>], [setlocale(LC_CTYPE,""); isprint(0); iscntrl(0);],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LOCALE)], [AC_MSG_RESULT(no)])
+AC_MSG_CHECKING(for ctype functions)
+AC_TRY_LINK([
+#if HAVE_CTYPE_H
+#include <ctype.h>
+#endif], [static int x; x = isupper(x); x = tolower(x); x = toupper(x);],
+ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_UPPER_LOWER)], [AC_MSG_RESULT(no)])
+
+# Checks for external variable ospeed in the termcap library.
+have_ospeed=no
+AC_MSG_CHECKING(termcap for ospeed)
+AC_TRY_LINK([
+#include <sys/types.h>
+#if HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+#if HAVE_TERMCAP_H
+#include <termcap.h>
+#endif], [ospeed = 0;],
+[AC_MSG_RESULT(yes - in termcap.h); AC_DEFINE(HAVE_OSPEED) have_ospeed=yes])
+if test $have_ospeed = no; then
+AC_TRY_LINK(, [extern short ospeed; ospeed = 0;],
+ [AC_MSG_RESULT(yes - must define); AC_DEFINE(HAVE_OSPEED) AC_DEFINE(MUST_DEFINE_OSPEED)],
+ [AC_MSG_RESULT(no)])
+fi
+
+# Checks for regular expression functions.
+have_regex=no
+have_posix_regex=unknown
+AC_MSG_CHECKING(for regcomp)
+
+WANT_REGEX=auto
+AC_ARG_WITH(regex,
+ [ --with-regex={auto,pcre,posix,regcmp,re_comp,regcomp,regcomp-local} Select a regular expression library [auto]],
+ WANT_REGEX="$withval")
+
+if test $have_regex = no; then
+if test $WANT_REGEX = auto -o $WANT_REGEX = posix; then
+# Some versions of Solaris have a regcomp() function, but it doesn't work!
+# So we run a test program. If we're cross-compiling, do it the old way.
+AC_TRY_RUN([
+#include <sys/types.h>
+#include <regex.h>
+main() { regex_t r; regmatch_t rm; char *text = "xabcy";
+if (regcomp(&r, "abc", 0)) exit(1);
+if (regexec(&r, text, 1, &rm, 0)) exit(1);
+#ifndef __WATCOMC__
+if (rm.rm_so != 1) exit(1); /* check for correct offset */
+#else
+if (rm.rm_sp != text + 1) exit(1); /* check for correct offset */
+#endif
+exit(0); }],
+ have_posix_regex=yes, have_posix_regex=no, have_posix_regex=unknown)
+if test $have_posix_regex = yes; then
+ AC_MSG_RESULT(using POSIX regcomp)
+ AC_DEFINE(HAVE_POSIX_REGCOMP)
+ have_regex=yes
+elif test $have_posix_regex = unknown; then
+ AC_TRY_LINK([
+#include <sys/types.h>
+#include <regex.h>],
+ [regex_t *r; regfree(r);],
+ AC_MSG_RESULT(using POSIX regcomp)
+ AC_DEFINE(HAVE_POSIX_REGCOMP) have_regex=yes)
+else
+ AC_MSG_RESULT(no)
+fi
+fi
+fi
+
+if test $have_regex = no; then
+if test $WANT_REGEX = auto -o $WANT_REGEX = pcre; then
+AC_CHECK_LIB(pcre, pcre_compile,
+[AC_MSG_RESULT(using pcre); AC_DEFINE(HAVE_PCRE) LIBS="$LIBS -lpcre" have_regex=yes], [])
+fi
+fi
+
+if test $have_regex = no; then
+if test $WANT_REGEX = auto -o $WANT_REGEX = regcmp; then
+AC_CHECK_FUNC(regcmp,
+AC_MSG_RESULT(using regcmp); AC_DEFINE(HAVE_REGCMP) have_regex=yes)
+fi
+fi
+
+if test $have_regex = no; then
+if test $WANT_REGEX = auto -o $WANT_REGEX = regcomp; then
+AC_TRY_LINK([
+#include "regexp.h"], [regcomp("");],
+AC_MSG_RESULT(using V8 regcomp); AC_DEFINE(HAVE_V8_REGCOMP) have_regex=yes)
+fi
+fi
+
+if test $have_regex = no && test -f ${srcdir}/regexp.c; then
+if test $WANT_REGEX = auto -o $WANT_REGEX = regcomp-local; then
+AC_MSG_RESULT(using V8 regcomp -- local source); AC_DEFINE(HAVE_V8_REGCOMP) AC_DEFINE(HAVE_REGEXEC2) REGEX_O='regexp.$(O)' AC_SUBST(REGEX_O) have_regex=yes
+fi
+fi
+
+if test $have_regex = no; then
+if test $WANT_REGEX = auto -o $WANT_REGEX = re_comp; then
+AC_MSG_RESULT(using re_comp); AC_CHECK_FUNC(re_comp, AC_DEFINE(HAVE_RE_COMP) have_regex=yes)
+fi
+fi
+
+if test $have_regex = no; then
+AC_MSG_RESULT(cannot find regular expression library); AC_DEFINE(NO_REGEX)
+fi
+
+AC_ARG_WITH(editor,
+ [ --with-editor=PROGRAM use PROGRAM as the default editor [vi]],
+ AC_DEFINE_UNQUOTED(EDIT_PGM, "$withval"), AC_DEFINE(EDIT_PGM, "vi"))
+
+AH_TOP([
+/* Unix definition file for less. -*- C -*-
+ *
+ * This file has 3 sections:
+ * User preferences.
+ * Settings always true on Unix.
+ * Settings automatically determined by configure.
+ *
+ * * * * * * WARNING * * * * * *
+ * If you edit defines.h by hand, do "touch stamp-h" before you run make
+ * so config.status doesn't overwrite your changes.
+ */
+
+/* User preferences. */
+
+/*
+ * SECURE is 1 if you wish to disable a bunch of features in order to
+ * be safe to run by unprivileged users.
+ */
+#define SECURE 0
+
+/*
+ * SHELL_ESCAPE is 1 if you wish to allow shell escapes.
+ * (This is possible only if your system supplies the system() function.)
+ */
+#define SHELL_ESCAPE (!SECURE)
+
+/*
+ * EXAMINE is 1 if you wish to allow examining files by name from within less.
+ */
+#define EXAMINE (!SECURE)
+
+/*
+ * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key
+ * to complete filenames at prompts.
+ */
+#define TAB_COMPLETE_FILENAME (!SECURE)
+
+/*
+ * CMD_HISTORY is 1 if you wish to allow keys to cycle through
+ * previous commands at prompts.
+ */
+#define CMD_HISTORY 1
+
+/*
+ * HILITE_SEARCH is 1 if you wish to have search targets to be
+ * displayed in standout mode.
+ */
+#define HILITE_SEARCH 1
+
+/*
+ * EDITOR is 1 if you wish to allow editor invocation (the "v" command).
+ * (This is possible only if your system supplies the system() function.)
+ * EDIT_PGM is the name of the (default) editor to be invoked.
+ */
+#define EDITOR (!SECURE)
+
+/*
+ * TAGS is 1 if you wish to support tag files.
+ */
+#define TAGS (!SECURE)
+
+/*
+ * USERFILE is 1 if you wish to allow a .less file to specify
+ * user-defined key bindings.
+ */
+#define USERFILE (!SECURE)
+
+/*
+ * GLOB is 1 if you wish to have shell metacharacters expanded in filenames.
+ * This will generally work if your system provides the "popen" function
+ * and the "echo" shell command.
+ */
+#define GLOB (!SECURE)
+
+/*
+ * PIPEC is 1 if you wish to have the "|" command
+ * which allows the user to pipe data into a shell command.
+ */
+#define PIPEC (!SECURE)
+
+/*
+ * LOGFILE is 1 if you wish to allow the -l option (to create log files).
+ */
+#define LOGFILE (!SECURE)
+
+/*
+ * GNU_OPTIONS is 1 if you wish to support the GNU-style command
+ * line options --help and --version.
+ */
+#define GNU_OPTIONS 1
+
+/*
+ * ONLY_RETURN is 1 if you want RETURN to be the only input which
+ * will continue past an error message.
+ * Otherwise, any key will continue past an error message.
+ */
+#define ONLY_RETURN 0
+
+/*
+ * LESSKEYFILE is the filename of the default lesskey output file
+ * (in the HOME directory).
+ * 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).
+ */
+#define LESSKEYFILE ".less"
+#define LESSKEYFILE_SYS SYSDIR "/sysless"
+#define DEF_LESSKEYINFILE ".lesskey"
+
+
+/* Settings always true on Unix. */
+
+/*
+ * Define MSDOS_COMPILER if compiling under Microsoft C.
+ */
+#define MSDOS_COMPILER 0
+
+/*
+ * Pathname separator character.
+ */
+#define PATHNAME_SEP "/"
+
+/*
+ * HAVE_SYS_TYPES_H is 1 if your system has <sys/types.h>.
+ */
+#define HAVE_SYS_TYPES_H 1
+
+/*
+ * Define if you have the <sgstat.h> header file.
+ */
+#undef HAVE_SGSTAT_H
+
+/*
+ * HAVE_PERROR is 1 if your system has the perror() call.
+ * (Actually, if it has sys_errlist, sys_nerr and errno.)
+ */
+#define HAVE_PERROR 1
+
+/*
+ * HAVE_TIME is 1 if your system has the time() call.
+ */
+#define HAVE_TIME 1
+
+/*
+ * HAVE_SHELL is 1 if your system supports a SHELL command interpreter.
+ */
+#define HAVE_SHELL 1
+
+/*
+ * Default shell metacharacters and meta-escape character.
+ */
+#define DEF_METACHARS "; *?\t\n'\"()<>|&^`#\\"
+#define DEF_METAESCAPE "\\"
+
+/*
+ * HAVE_DUP is 1 if your system has the dup() call.
+ */
+#define HAVE_DUP 1
+
+/*
+ * Sizes of various buffers.
+ */
+#define CMDBUF_SIZE 512 /* Buffer for multichar commands */
+#define UNGOT_SIZE 100 /* Max chars to unget() */
+#define LINEBUF_SIZE 1024 /* Max size of line in input file */
+#define OUTBUF_SIZE 1024 /* Output buffer */
+#define PROMPT_SIZE 200 /* Max size of prompt string */
+#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */
+#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */
+#define TAGLINE_SIZE 512 /* Max size of line in tags file */
+#define TABSTOP_MAX 32 /* Max number of custom tab stops */
+
+/* Settings automatically determined by configure. */
+])
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/usr.bin/less/lessecho.c b/usr.bin/less/lessecho.c
new file mode 100644
index 00000000000..35685780456
--- /dev/null
+++ b/usr.bin/less/lessecho.c
@@ -0,0 +1,272 @@
+/*
+ * Copyright (C) 1984-2002 Mark Nudelman
+ *
+ * You may distribute under the terms of either the GNU General Public
+ * License or the Less License, as specified in the README file.
+ *
+ * For more information about less, or for information on how to
+ * contact the author, see the README file.
+ */
+
+
+/*
+ * lessecho [-ox] [-cx] [-pn] [-dn] [-a] file ...
+ * Simply echos its filename arguments on standard output.
+ * But any argument containing spaces is enclosed in quotes.
+ *
+ * -ox Specifies "x" to be the open quote character.
+ * -cx Specifies "x" to be the close quote character.
+ * -pn Specifies "n" to be the open quote character, as an integer.
+ * -dn Specifies "n" to be the close quote character, as an integer.
+ * -mx Specifies "x" to be a metachar.
+ * -nn Specifies "n" to be a metachar, as an integer.
+ * -ex Specifies "x" to be the escape char for metachars.
+ * -fn Specifies "x" to be the escape char for metachars, as an integer.
+ * -a Specifies that all arguments are to be quoted.
+ * The default is that only arguments containing spaces are quoted.
+ */
+
+#include "less.h"
+
+static char *version = "$Revision: 1.1 $";
+
+static int quote_all = 0;
+static char openquote = '"';
+static char closequote = '"';
+static char *meta_escape = "\\";
+static char meta_escape_buf[2];
+static char metachars[64] = "";
+static int num_metachars = 0;
+
+ static void
+pr_usage()
+{
+ fprintf(stderr,
+ "usage: lessecho [-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-fn] [-a] file ...\n");
+}
+
+ static void
+pr_version()
+{
+ char *p;
+ char buf[10];
+ char *pbuf = buf;
+
+ for (p = version; *p != ' '; p++)
+ if (*p == '\0')
+ return;
+ for (p++; *p != '$' && *p != ' ' && *p != '\0'; p++)
+ *pbuf++ = *p;
+ *pbuf = '\0';
+ printf("%s\n", buf);
+}
+
+ static void
+pr_error(s)
+ char *s;
+{
+ fprintf(stderr, "%s\n", s);
+ exit(1);
+}
+
+ static long
+lstrtol(s, radix, pend)
+ char *s;
+ int radix;
+ char **pend;
+{
+ int v;
+ int neg = 0;
+ long n = 0;
+
+ /* Skip leading white space. */
+ while (*s == ' ' || *s == '\t')
+ s++;
+
+ /* Check for a leading + or -. */
+ if (*s == '-')
+ {
+ neg = 1;
+ s++;
+ } else if (*s == '+')
+ {
+ s++;
+ }
+
+ /* Determine radix if caller does not specify. */
+ if (radix == 0)
+ {
+ radix = 10;
+ if (*s == '0')
+ {
+ switch (*++s)
+ {
+ case 'x':
+ radix = 16;
+ s++;
+ break;
+ default:
+ radix = 8;
+ break;
+ }
+ }
+ }
+
+ /* Parse the digits of the number. */
+ for (;;)
+ {
+ if (*s >= '0' && *s <= '9')
+ v = *s - '0';
+ else if (*s >= 'a' && *s <= 'f')
+ v = *s - 'a' + 10;
+ else if (*s >= 'A' && *s <= 'F')
+ v = *s - 'A' + 10;
+ else
+ break;
+ if (v >= radix)
+ break;
+ n = n * radix + v;
+ s++;
+ }
+
+ if (pend != NULL)
+ {
+ /* Skip trailing white space. */
+ while (*s == ' ' || *s == '\t')
+ s++;
+ *pend = s;
+ }
+ if (neg)
+ return (-n);
+ return (n);
+}
+
+
+#if !HAVE_STRCHR
+ char *
+strchr(s, c)
+ char *s;
+ int c;
+{
+ for ( ; *s != '\0'; s++)
+ if (*s == c)
+ return (s);
+ if (c == '\0')
+ return (s);
+ return (NULL);
+}
+#endif
+
+ int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ char *arg;
+ char *s;
+ int no_more_options;
+
+ no_more_options = 0;
+ while (--argc > 0)
+ {
+ arg = *++argv;
+ if (*arg != '-' || no_more_options)
+ break;
+ switch (*++arg)
+ {
+ case 'a':
+ quote_all = 1;
+ break;
+ case 'c':
+ closequote = *++arg;
+ break;
+ case 'd':
+ closequote = lstrtol(++arg, 0, &s);
+ if (s == arg)
+ pr_error("Missing number after -d");
+ break;
+ case 'e':
+ if (strcmp(++arg, "-") == 0)
+ meta_escape = "";
+ else
+ meta_escape = arg;
+ break;
+ case 'f':
+ meta_escape_buf[0] = lstrtol(++arg, 0, &s);
+ meta_escape = meta_escape_buf;
+ if (s == arg)
+ pr_error("Missing number after -f");
+ break;
+ case 'o':
+ openquote = *++arg;
+ break;
+ case 'p':
+ openquote = lstrtol(++arg, 0, &s);
+ if (s == arg)
+ pr_error("Missing number after -p");
+ break;
+ case 'm':
+ metachars[num_metachars++] = *++arg;
+ metachars[num_metachars] = '\0';
+ break;
+ case 'n':
+ metachars[num_metachars++] = lstrtol(++arg, 0, &s);
+ if (s == arg)
+ pr_error("Missing number after -n");
+ metachars[num_metachars] = '\0';
+ break;
+ case '?':
+ pr_usage();
+ return (0);
+ case '-':
+ if (*++arg == '\0')
+ {
+ no_more_options = 1;
+ break;
+ }
+ if (strcmp(arg, "version") == 0)
+ {
+ pr_version();
+ return (0);
+ }
+ if (strcmp(arg, "help") == 0)
+ {
+ pr_usage();
+ return (0);
+ }
+ pr_error("Invalid option after --");
+ default:
+ pr_error("Invalid option letter");
+ }
+ }
+
+ while (argc-- > 0)
+ {
+ int has_meta = 0;
+ arg = *argv++;
+ for (s = arg; *s != '\0'; s++)
+ {
+ if (strchr(metachars, *s) != NULL)
+ {
+ has_meta = 1;
+ break;
+ }
+ }
+ if (quote_all || (has_meta && strlen(meta_escape) == 0))
+ printf("%c%s%c", openquote, arg, closequote);
+ else
+ {
+ for (s = arg; *s != '\0'; s++)
+ {
+ if (strchr(metachars, *s) != NULL)
+ printf("%s", meta_escape);
+ printf("%c", *s);
+ }
+ }
+ if (argc > 0)
+ printf(" ");
+ else
+ printf("\n");
+ }
+ return (0);
+}
diff --git a/usr.bin/less/lglob.h b/usr.bin/less/lglob.h
new file mode 100644
index 00000000000..f2b49cef635
--- /dev/null
+++ b/usr.bin/less/lglob.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 1984-2002 Mark Nudelman
+ *
+ * You may distribute under the terms of either the GNU General Public
+ * License or the Less License, as specified in the README file.
+ *
+ * For more information about less, or for information on how to
+ * contact the author, see the README file.
+ */
+
+
+/*
+ * Macros to define the method of doing filename "globbing".
+ * There are three possible mechanisms:
+ * 1. GLOB_LIST
+ * This defines a function that returns a list of matching filenames.
+ * 2. GLOB_NAME
+ * This defines a function that steps thru the list of matching
+ * filenames, returning one name each time it is called.
+ * 3. GLOB_STRING
+ * This defines a function that returns the complete list of
+ * matching filenames as a single space-separated string.
+ */
+
+#if OS2
+
+#define DECL_GLOB_LIST(list) char **list; char **pp;
+#define GLOB_LIST(filename,list) list = _fnexplode(filename)
+#define GLOB_LIST_FAILED(list) list == NULL
+#define SCAN_GLOB_LIST(list,p) pp = list; *pp != NULL; pp++
+#define INIT_GLOB_LIST(list,p) p = *pp
+#define GLOB_LIST_DONE(list) _fnexplodefree(list)
+
+#else
+#if MSDOS_COMPILER==DJGPPC
+
+#define DECL_GLOB_LIST(list) glob_t list; int i;
+#define GLOB_LIST(filename,list) glob(filename,GLOB_NOCHECK,0,&list)
+#define GLOB_LIST_FAILED(list) 0
+#define SCAN_GLOB_LIST(list,p) i = 0; i < list.gl_pathc; i++
+#define INIT_GLOB_LIST(list,p) p = list.gl_pathv[i]
+#define GLOB_LIST_DONE(list) globfree(&list)
+
+#else
+#if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC
+
+#define GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp)
+#define GLOB_FIRST_FAILED(handle) ((handle) != 0)
+#define GLOB_NEXT_NAME(handle,fndp) _dos_findnext(fndp)
+#define GLOB_NAME_DONE(handle)
+#define GLOB_NAME name
+#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
+ struct find_t fnd; \
+ char drive[_MAX_DRIVE]; \
+ char dir[_MAX_DIR]; \
+ char fname[_MAX_FNAME]; \
+ char ext[_MAX_EXT]; \
+ int handle;
+#else
+#if MSDOS_COMPILER==WIN32C && defined(_MSC_VER)
+
+#define GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp)
+#define GLOB_FIRST_FAILED(handle) ((handle) == -1)
+#define GLOB_NEXT_NAME(handle,fndp) _findnext(handle, fndp)
+#define GLOB_NAME_DONE(handle) _findclose(handle)
+#define GLOB_NAME name
+#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
+ struct _finddata_t fnd; \
+ char drive[_MAX_DRIVE]; \
+ char dir[_MAX_DIR]; \
+ char fname[_MAX_FNAME]; \
+ char ext[_MAX_EXT]; \
+ long handle;
+
+#else
+#if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER) /* Borland C for Windows */
+
+#define GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL)
+#define GLOB_FIRST_FAILED(handle) ((handle) != 0)
+#define GLOB_NEXT_NAME(handle,fndp) findnext(fndp)
+#define GLOB_NAME_DONE(handle)
+#define GLOB_NAME ff_name
+#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \
+ struct ffblk fnd; \
+ char drive[MAXDRIVE]; \
+ char dir[MAXDIR]; \
+ char fname[MAXFILE]; \
+ char ext[MAXEXT]; \
+ int handle;
+
+#endif
+#endif
+#endif
+#endif
+#endif
diff --git a/usr.bin/less/mkfuncs.awk b/usr.bin/less/mkfuncs.awk
new file mode 100644
index 00000000000..dea28acebf5
--- /dev/null
+++ b/usr.bin/less/mkfuncs.awk
@@ -0,0 +1,9 @@
+BEGIN { FS="("; state = 0 }
+
+/^ public/ { ftype = $0; state = 1 }
+
+{ if (state == 1)
+ state = 2
+ else if (state == 2)
+ { print ftype,$1,"();"; state = 0 }
+}
diff --git a/usr.bin/less/mkhelp.c b/usr.bin/less/mkhelp.c
new file mode 100644
index 00000000000..d05cb49945c
--- /dev/null
+++ b/usr.bin/less/mkhelp.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 1984-2002 Mark Nudelman
+ *
+ * You may distribute under the terms of either the GNU General Public
+ * License or the Less License, as specified in the README file.
+ *
+ * For more information about less, or for information on how to
+ * contact the author, see the README file.
+ */
+
+
+/*
+ * Silly little program to generate the help.c source file
+ * from the less.hlp text file.
+ * help.c just contains a char array whose contents are
+ * the contents of less.hlp.
+ */
+
+#include <stdio.h>
+
+ int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ int ch;
+ int prevch;
+
+ printf("/* This file was generated by mkhelp from less.hlp */\n");
+ printf("#include \"less.h\"\n");
+ printf("constant char helpdata[] = {\n");
+ ch = 0;
+ while (prevch = ch, (ch = getchar()) != EOF)
+ {
+ switch (ch)
+ {
+ case '\'':
+ printf("'\\'',");
+ break;
+ case '\\':
+ printf("'\\\\',");
+ break;
+ case '\b':
+ printf("'\\b',");
+ break;
+ case '\t':
+ printf("'\\t',");
+ break;
+ case '\n':
+ if (prevch != '\r')
+ printf("'\\n',\n");
+ break;
+ case '\r':
+ if (prevch != '\n')
+ printf("'\\n',\n");
+ break;
+ default:
+ if (ch >= ' ' && ch < 0x7f)
+ printf("'%c',", ch);
+ else
+ printf("0x%02x,", ch);
+ break;
+ }
+ }
+ /* Add an extra null char to avoid having a trailing comma. */
+ printf(" 0 };\n");
+ printf("constant int size_helpdata = sizeof(helpdata) - 1;\n");
+ return (0);
+}
diff --git a/usr.bin/less/pckeys.h b/usr.bin/less/pckeys.h
new file mode 100644
index 00000000000..723df550f98
--- /dev/null
+++ b/usr.bin/less/pckeys.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 1984-2002 Mark Nudelman
+ *
+ * You may distribute under the terms of either the GNU General Public
+ * License or the Less License, as specified in the README file.
+ *
+ * For more information about less, or for information on how to
+ * contact the author, see the README file.
+ */
+
+
+/*
+ * Definitions of keys on the PC.
+ * Special (non-ASCII) keys on the PC send a two-byte sequence,
+ * where the first byte is 0 and the second is as defined below.
+ */
+#define PCK_SHIFT_TAB '\017'
+#define PCK_ALT_E '\022'
+#define PCK_CAPS_LOCK '\072'
+#define PCK_F1 '\073'
+#define PCK_NUM_LOCK '\105'
+#define PCK_HOME '\107'
+#define PCK_UP '\110'
+#define PCK_PAGEUP '\111'
+#define PCK_LEFT '\113'
+#define PCK_RIGHT '\115'
+#define PCK_END '\117'
+#define PCK_DOWN '\120'
+#define PCK_PAGEDOWN '\121'
+#define PCK_INSERT '\122'
+#define PCK_DELETE '\123'
+#define PCK_CTL_LEFT '\163'
+#define PCK_CTL_RIGHT '\164'
+#define PCK_CTL_DELETE '\223'
diff --git a/usr.bin/less/scrsize.c b/usr.bin/less/scrsize.c
new file mode 100644
index 00000000000..9af7e345cae
--- /dev/null
+++ b/usr.bin/less/scrsize.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 1984-2002 Mark Nudelman
+ *
+ * You may distribute under the terms of either the GNU General Public
+ * License or the Less License, as specified in the README file.
+ *
+ * For more information about less, or for information on how to
+ * contact the author, see the README file.
+ */
+
+/*
+ * This program is used to determine the screen dimensions on OS/2 systems.
+ * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp).
+ */
+
+/*
+ * When I wrote this routine, I consulted some part of the source code
+ * of the xwininfo utility by X Consortium.
+ *
+ * Copyright (c) 1987, X Consortium
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the X Consortium shall not
+ * be used in advertising or otherwise to promote the sale, use or other
+ * dealings in this Software without prior written authorization from the X
+ * Consortium.
+ */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static int get_winsize(dpy, window, p_width, p_height)
+ Display *dpy;
+ Window window;
+ int *p_width;
+ int *p_height;
+{
+ XWindowAttributes win_attributes;
+ XSizeHints hints;
+ long longjunk;
+
+ if (!XGetWindowAttributes(dpy, window, &win_attributes))
+ return 1;
+ if (!XGetWMNormalHints(dpy, window, &hints, &longjunk))
+ return 1;
+ if (!(hints.flags & PResizeInc))
+ return 1;
+ if (hints.width_inc == 0 || hints.height_inc == 0)
+ return 1;
+ if (!(hints.flags & (PBaseSize|PMinSize)))
+ return 1;
+ if (hints.flags & PBaseSize)
+ {
+ win_attributes.width -= hints.base_width;
+ win_attributes.height -= hints.base_height;
+ } else
+ {
+ win_attributes.width -= hints.min_width;
+ win_attributes.height -= hints.min_height;
+ }
+ *p_width = win_attributes.width / hints.width_inc;
+ *p_height = win_attributes.height / hints.height_inc;
+ return 0;
+}
+
+int main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ char *cp;
+ Display *dpy;
+ int size[2];
+
+ _scrsize(size);
+ cp = getenv("WINDOWID");
+ if (cp != NULL)
+ {
+ dpy = XOpenDisplay(NULL);
+ if (dpy != NULL)
+ {
+ get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]);
+ XCloseDisplay(dpy);
+ }
+ }
+ printf("%i %i\n", size[0], size[1]);
+ return (0);
+}