├── .gitignore ├── COPYING ├── INSTALL ├── LICENSE ├── Makefile.aut ├── Makefile.dsb ├── Makefile.dsg ├── Makefile.dsu ├── Makefile.in ├── Makefile.o2e ├── Makefile.o9c ├── Makefile.o9u ├── Makefile.wnb ├── Makefile.wnm ├── NEWS ├── README ├── brac.c ├── ch.c ├── charset.c ├── charset.h ├── cmd.h ├── cmdbuf.c ├── command.c ├── compose.uni ├── configure ├── configure.ac ├── cvt.c ├── decode.c ├── defines.ds ├── defines.h.in ├── defines.o2 ├── defines.o9 ├── defines.wn ├── edit.c ├── filename.c ├── forwback.c ├── funcs.h ├── help.c ├── ifile.c ├── input.c ├── install.sh ├── jump.c ├── less.h ├── less.hlp ├── less.man ├── less.nro ├── lessecho.c ├── lessecho.man ├── lessecho.nro ├── lesskey.c ├── lesskey.h ├── lesskey.man ├── lesskey.nro ├── lglob.h ├── line.c ├── linenum.c ├── lsystem.c ├── main.c ├── mark.c ├── mkfuncs.awk ├── mkhelp.c ├── mkinstalldirs ├── mkutable ├── optfunc.c ├── option.c ├── option.h ├── opttbl.c ├── os.c ├── output.c ├── pattern.c ├── pattern.h ├── pckeys.h ├── position.c ├── position.h ├── prompt.c ├── regexp.c ├── regexp.h ├── screen.c ├── scrsize.c ├── search.c ├── signal.c ├── tags.c ├── ttyin.c ├── ubin.uni ├── version.c └── wide.uni /.gitignore: -------------------------------------------------------------------------------- 1 | *.obj 2 | *.exe 3 | defines.h 4 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | This file describes how to build and install less using 2 | the "configure" script. This only works on Unix systems. 3 | To install on other systems, read the README file. 4 | 5 | 6 | Basic Installation 7 | ================== 8 | 9 | These are generic installation instructions. 10 | 11 | The `configure' shell script attempts to guess correct values for 12 | various system-dependent variables used during compilation. It uses 13 | those values to create a `Makefile' in each directory of the package. 14 | It may also create one or more `.h' files containing system-dependent 15 | definitions. Finally, it creates a shell script `config.status' that 16 | you can run in the future to recreate the current configuration, a file 17 | `config.cache' that saves the results of its tests to speed up 18 | reconfiguring, and a file `config.log' containing compiler output 19 | (useful mainly for debugging `configure'). 20 | 21 | If you need to do unusual things to compile the package, please try 22 | to figure out how `configure' could check whether to do them, and mail 23 | diffs or instructions to the address given in the `README' so they can 24 | be considered for the next release. If at some point `config.cache' 25 | contains results you don't want to keep, you may remove or edit it. 26 | 27 | The file `configure.in' is used to create `configure' by a program 28 | called `autoconf'. You only need `configure.in' if you want to change 29 | it or regenerate `configure' using a newer version of `autoconf'. 30 | 31 | The simplest way to compile this package is: 32 | 33 | 1. `cd' to the directory containing the package's source code and type 34 | `./configure' to configure the package for your system. If you're 35 | using `csh' on an old version of System V, you might need to type 36 | `sh ./configure' instead to prevent `csh' from trying to execute 37 | `configure' itself. 38 | 39 | Running `configure' takes awhile. While running, it prints some 40 | messages telling which features it is checking for. 41 | 42 | 2. Type `make' to compile the package. 43 | 44 | 3. Optionally, type `make check' to run any self-tests that come with 45 | the package. 46 | 47 | 4. Type `make install' to install the programs and any data files and 48 | documentation. 49 | 50 | 5. You can remove the program binaries and object files from the 51 | source code directory by typing `make clean'. To also remove the 52 | files that `configure' created (so you can compile the package for 53 | a different kind of computer), type `make distclean'. There is 54 | also a `make maintainer-clean' target, but that is intended mainly 55 | for the package's developers. If you use it, you may have to get 56 | all sorts of other programs in order to regenerate files that came 57 | with the distribution. 58 | 59 | Compilers and Options 60 | ===================== 61 | 62 | Some systems require unusual options for compilation or linking that 63 | the `configure' script does not know about. You can give `configure' 64 | initial values for variables by setting them in the environment. Using 65 | a Bourne-compatible shell, you can do that on the command line like 66 | this: 67 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure 68 | 69 | Or on systems that have the `env' program, you can do it like this: 70 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure 71 | 72 | Compiling For Multiple Architectures 73 | ==================================== 74 | 75 | You can compile the package for more than one kind of computer at the 76 | same time, by placing the object files for each architecture in their 77 | own directory. To do this, you must use a version of `make' that 78 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 79 | directory where you want the object files and executables to go and run 80 | the `configure' script. `configure' automatically checks for the 81 | source code in the directory that `configure' is in and in `..'. 82 | 83 | If you have to use a `make' that does not supports the `VPATH' 84 | variable, you have to compile the package for one architecture at a time 85 | in the source code directory. After you have installed the package for 86 | one architecture, use `make distclean' before reconfiguring for another 87 | architecture. 88 | 89 | Installation Names 90 | ================== 91 | 92 | By default, `make install' will install the package's files in 93 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 94 | installation prefix other than `/usr/local' by giving `configure' the 95 | option `--prefix=PATH'. 96 | 97 | You can specify separate installation prefixes for 98 | architecture-specific files and architecture-independent files. If you 99 | give `configure' the option `--exec-prefix=PATH', the package will use 100 | PATH as the prefix for installing programs and libraries. 101 | Documentation and other data files will still use the regular prefix. 102 | 103 | In addition, if you use an unusual directory layout you can give 104 | options like `--bindir=PATH' to specify different values for particular 105 | kinds of files. Run `configure --help' for a list of the directories 106 | you can set and what kinds of files go in them. 107 | 108 | If the package supports it, you can cause programs to be installed 109 | with an extra prefix or suffix on their names by giving `configure' the 110 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 111 | 112 | Optional Features 113 | ================= 114 | 115 | Some packages pay attention to `--enable-FEATURE' options to 116 | `configure', where FEATURE indicates an optional part of the package. 117 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 118 | is something like `gnu-as' or `x' (for the X Window System). The 119 | `README' should mention any `--enable-' and `--with-' options that the 120 | package recognizes. 121 | 122 | For packages that use the X Window System, `configure' can usually 123 | find the X include and library files automatically, but if it doesn't, 124 | you can use the `configure' options `--x-includes=DIR' and 125 | `--x-libraries=DIR' to specify their locations. 126 | 127 | Specifying the System Type 128 | ========================== 129 | 130 | There may be some features `configure' can not figure out 131 | automatically, but needs to determine by the type of host the package 132 | will run on. Usually `configure' can figure that out, but if it prints 133 | a message saying it can not guess the host type, give it the 134 | `--host=TYPE' option. TYPE can either be a short name for the system 135 | type, such as `sun4', or a canonical name with three fields: 136 | CPU-COMPANY-SYSTEM 137 | 138 | See the file `config.sub' for the possible values of each field. If 139 | `config.sub' isn't included in this package, then this package doesn't 140 | need to know the host type. 141 | 142 | If you are building compiler tools for cross-compiling, you can also 143 | use the `--target=TYPE' option to select the type of system they will 144 | produce code for and the `--build=TYPE' option to select the type of 145 | system on which you are compiling the package. 146 | 147 | Sharing Defaults 148 | ================ 149 | 150 | If you want to set default values for `configure' scripts to share, 151 | you can create a site shell script called `config.site' that gives 152 | default values for variables like `CC', `cache_file', and `prefix'. 153 | `configure' looks for `PREFIX/share/config.site' if it exists, then 154 | `PREFIX/etc/config.site' if it exists. Or, you can set the 155 | `CONFIG_SITE' environment variable to the location of the site script. 156 | A warning: not all `configure' scripts look for a site script. 157 | 158 | Operation Controls 159 | ================== 160 | 161 | `configure' recognizes the following options to control how it 162 | operates. 163 | 164 | `--cache-file=FILE' 165 | Use and save the results of the tests in FILE instead of 166 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for 167 | debugging `configure'. 168 | 169 | `--help' 170 | Print a summary of the options to `configure', and exit. 171 | 172 | `--quiet' 173 | `--silent' 174 | `-q' 175 | Do not print messages saying which checks are being made. 176 | 177 | `--srcdir=DIR' 178 | Look for the package's source code in directory DIR. Usually 179 | `configure' can determine that directory automatically. 180 | 181 | `--version' 182 | Print the version of Autoconf used to generate the `configure' 183 | script, and exit. 184 | 185 | `configure' also accepts some other, not widely useful, options. 186 | 187 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Less License 2 | ------------ 3 | 4 | Less 5 | Copyright (C) 1984-2015 Mark Nudelman 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice in the documentation and/or other materials provided with 14 | the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 22 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | -------------------------------------------------------------------------------- /Makefile.aut: -------------------------------------------------------------------------------- 1 | # Makefile for authoring less. 2 | 3 | EMAIL = bug-less@gnu.org 4 | HOMEPAGE = http://www.greenwoodsoftware.com/less 5 | SHELL = /bin/sh 6 | RCS = rcs 7 | NROFF = nroff -man 8 | 9 | srcdir = . 10 | 11 | SRC = \ 12 | main.c screen.c brac.c ch.c charset.c cmdbuf.c \ 13 | command.c cvt.c decode.c edit.c filename.c forwback.c \ 14 | help.c ifile.c input.c jump.c line.c linenum.c \ 15 | lsystem.c mark.c optfunc.c option.c opttbl.c os.c \ 16 | output.c pattern.c position.c prompt.c search.c signal.c \ 17 | tags.c ttyin.c version.c 18 | DISTFILES_W = \ 19 | defines.ds Makefile.dsb Makefile.dsg Makefile.dsu \ 20 | defines.o2 Makefile.o2e \ 21 | defines.o9 Makefile.o9c Makefile.o9u \ 22 | defines.wn Makefile.wnm Makefile.wnb \ 23 | configure 24 | UNICODE_FILES = \ 25 | compose.uni ubin.uni wide.uni 26 | DISTFILES = \ 27 | ${SRC} regexp.c regexp.h \ 28 | COPYING INSTALL LICENSE Makefile.in Makefile.aut NEWS README \ 29 | configure.ac lesskey.c lessecho.c scrsize.c \ 30 | charset.h cmd.h funcs.h lglob.h less.h lesskey.h option.h \ 31 | pckeys.h pattern.h position.h \ 32 | install.sh defines.h.in mkinstalldirs \ 33 | less.nro less.man lesskey.nro lesskey.man lessecho.nro lessecho.man \ 34 | less.hlp \ 35 | mkfuncs.awk mkhelp.c \ 36 | mkutable $(UNICODE_FILES) \ 37 | ${DISTFILES_W} 38 | 39 | all: help.c funcs.h $(UNICODE_FILES) ${srcdir}/configure 40 | 41 | release: .FORCE 42 | ${MAKE} -f Makefile.aut tagall 43 | ${MAKE} -f Makefile.aut all 44 | ${MAKE} -f Makefile.aut clean 45 | ${MAKE} -f Makefile.aut dist 46 | 47 | .FORCE: 48 | 49 | help.c: less.hlp mkhelp 50 | -mv -f ${srcdir}/help.c ${srcdir}/help.c.old 51 | rm -rf help.c 52 | ./mkhelp < less.hlp > help.c 53 | if cmp -s help.c help.c.old; then mv -f help.c.old help.c; fi 54 | 55 | mkhelp: mkhelp.c 56 | ${CC} -o mkhelp mkhelp.c 57 | 58 | ${srcdir}/configure: ${srcdir}/configure.ac \ 59 | ${srcdir}/Makefile.in 60 | cd ${srcdir}; autoheader; autoconf 61 | 62 | funcs.h: ${SRC:%=${srcdir}/%} 63 | -mv -f ${srcdir}/funcs.h ${srcdir}/funcs.h.old 64 | awk -f ${srcdir}/mkfuncs.awk ${SRC:%=${srcdir}/%} >${srcdir}/funcs.h 65 | if cmp -s funcs.h funcs.h.old; then mv -f funcs.h.old funcs.h; fi 66 | 67 | lint: 68 | lint -I. ${CPPFLAGS} ${SRC} 69 | 70 | clean: 71 | rm -f Makefile config.status config.log config.cache defines.h stamp-h \ 72 | README NEWS \ 73 | less.nro less.man lesskey.nro lesskey.man lessecho.nro lessecho.man 74 | 75 | distclean: clean 76 | realclean: clean 77 | 78 | REPLACE_VERSION = \ 79 | @REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/\1/' -e q ${srcdir}/version.c`; \ 80 | DT=`date '+%d %h %Y'`; \ 81 | echo "Stuffing version number $$REL into $@"; \ 82 | rm -f $@; \ 83 | sed \ 84 | -e "s;@@VERSION@@;$$REL;" \ 85 | -e "s;@@DATE@@;$$DT;" \ 86 | -e "s;@@EMAIL@@;${EMAIL};" \ 87 | -e "s;@@HOMEPAGE@@;${HOMEPAGE};" >$@ 88 | 89 | ${srcdir}/README: ${srcdir}/README.VER ${srcdir}/version.c 90 | ${REPLACE_VERSION} ${srcdir}/README.VER 91 | ${srcdir}/NEWS: ${srcdir}/NEWS.VER ${srcdir}/version.c 92 | ${REPLACE_VERSION} ${srcdir}/NEWS.VER 93 | ${srcdir}/less.nro: ${srcdir}/less.nro.VER ${srcdir}/version.c 94 | ${REPLACE_VERSION} ${srcdir}/less.nro.VER 95 | ${srcdir}/lesskey.nro: ${srcdir}/lesskey.nro.VER ${srcdir}/version.c 96 | ${REPLACE_VERSION} ${srcdir}/lesskey.nro.VER 97 | ${srcdir}/lessecho.nro: ${srcdir}/lessecho.nro.VER ${srcdir}/version.c 98 | ${REPLACE_VERSION} ${srcdir}/lessecho.nro.VER 99 | ${srcdir}/less.hlp: ${srcdir}/less.hlp.VER ${srcdir}/version.c 100 | ${REPLACE_VERSION} ${srcdir}/less.hlp.VER 101 | 102 | ${srcdir}/less.man: ${srcdir}/less.nro 103 | ${NROFF} ${srcdir}/less.nro >${srcdir}/less.man 104 | ${srcdir}/lesskey.man: ${srcdir}/lesskey.nro 105 | ${NROFF} ${srcdir}/lesskey.nro >${srcdir}/lesskey.man 106 | ${srcdir}/lessecho.man: ${srcdir}/lessecho.nro 107 | ${NROFF} ${srcdir}/lessecho.nro >${srcdir}/lessecho.man 108 | 109 | compose.uni: unicode/UnicodeData.txt 110 | ./mkutable -f2 Mn Me -- unicode/UnicodeData.txt > $@ 111 | ubin.uni: unicode/UnicodeData.txt 112 | ./mkutable -f2 Cc Cf Cs Co Zl Zp -- unicode/UnicodeData.txt > $@ 113 | wide.uni: unicode/EastAsianWidth.txt 114 | ./mkutable -f1 W -- unicode/EastAsianWidth.txt > $@ 115 | 116 | distfiles: ${DISTFILES} 117 | 118 | dist: ${DISTFILES} 119 | if [ ! -d ${srcdir}/release ]; then mkdir ${srcdir}/release; fi 120 | @cd ${srcdir}; \ 121 | REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/less-\1/' -e q version.c`; \ 122 | rm -rf release/$$REL; mkdir release/$$REL; \ 123 | echo "Preparing $$REL"; \ 124 | rm -rf $$REL; mkdir $$REL; \ 125 | for file in ${DISTFILES}; do \ 126 | ./add_copyright $$file $$REL; \ 127 | done; \ 128 | cd $$REL; chmod -w *; chmod +w ${DISTFILES_W}; chmod +x configure; cd ..; \ 129 | echo "Creating release/$$REL/$$REL.tar.gz"; \ 130 | tar -cf - $$REL | gzip -c >release/$$REL/$$REL.tar.gz; \ 131 | echo "Signing release/$$REL/$$REL.tar.gz"; \ 132 | gpg --detach-sign release/$$REL/$$REL.tar.gz; \ 133 | echo "Creating release/$$REL/$$REL.zip"; \ 134 | zip -rq release/$$REL/$$REL.zip $$REL; \ 135 | rm -rf $$REL 136 | 137 | tagall: 138 | @REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/v\1/' -e q ${srcdir}/version.c`; \ 139 | echo "tagging $$REL"; \ 140 | for f in ${srcdir}/RCS/*,v; do \ 141 | REV=`co -p $$f 2>&1 | sed -e '1d' -e '3,$$d' -e 's/revision //'`; \ 142 | ${RCS} -N$$REL:$$REV $$f; \ 143 | done 144 | -------------------------------------------------------------------------------- /Makefile.dsb: -------------------------------------------------------------------------------- 1 | # Makefile for less. 2 | # MS-DOS version (Borland C/C++ 4.02) 3 | 4 | #### Start of system configuration section. #### 5 | 6 | CC = bcc 7 | LIBDIR = \bc\lib 8 | 9 | CFLAGS = -A- -mm -O2 -w- -1- -2- -a -d -Z 10 | LDFLAGS = -mm 11 | LIBS = 12 | EXT = .EXE 13 | 14 | #### End of system configuration section. #### 15 | 16 | # This rule allows us to supply the necessary -D options 17 | # in addition to whatever the user asks for. 18 | .c.obj: 19 | $(CC) -c -I. $(CPPFLAGS) $(CFLAGS) $< 20 | 21 | OBJ = \ 22 | main.obj screen.obj brac.obj ch.obj charset.obj cmdbuf.obj \ 23 | command.obj cvt.obj decode.obj edit.obj filename.obj forwback.obj \ 24 | help.obj ifile.obj input.obj jump.obj line.obj linenum.obj \ 25 | lsystem.obj mark.obj optfunc.obj option.obj opttbl.obj os.obj \ 26 | output.obj pattern.obj position.obj prompt.obj search.obj signal.obj \ 27 | tags.obj ttyin.obj version.obj 28 | 29 | all: less$(EXT) lesskey$(EXT) 30 | 31 | # This is really horrible, but the command line is too long for 32 | # MS-DOS if we try to link $(OBJ). 33 | less$(EXT): $(OBJ) 34 | ren lesskey.obj lesskey.obo 35 | $(CC) $(LDFLAGS) -e$@ *.obj $(LIBS) 36 | ren lesskey.obo lesskey.obj 37 | 38 | lesskey$(EXT): lesskey.obj version.obj 39 | $(CC) $(LDFLAGS) -e$@ lesskey.obj version.obj $(LIBS) 40 | 41 | defines.h: defines.ds 42 | -del defines.h 43 | -copy defines.ds defines.h 44 | 45 | $(OBJ): less.h defines.h 46 | 47 | clean: 48 | -del *.obj 49 | -del less.exe 50 | -del lesskey.exe 51 | 52 | -------------------------------------------------------------------------------- /Makefile.dsg: -------------------------------------------------------------------------------- 1 | # Makefile for less under DJGPP v2.0 or later. 2 | 3 | #### Start of system configuration section. #### 4 | 5 | srcdir = . 6 | VPATH = . 7 | 8 | CC = gcc 9 | INSTALL = ginstall -c 10 | INSTALL_PROGRAM = ginstall 11 | INSTALL_DATA = ginstall -m 644 12 | AWK = gawk 13 | 14 | CFLAGS = -O2 -g 15 | CFLAGS_COMPILE_ONLY = -c 16 | #LDFLAGS = -s 17 | LDFLAGS = -g 18 | O=o 19 | 20 | LIBS = 21 | prefix = /dev/env/DJDIR 22 | exec_prefix = ${prefix} 23 | 24 | bindir = ${exec_prefix}/bin 25 | sysconfdir = ${prefix}/etc 26 | mandir = ${prefix}/man 27 | manext = 1 28 | 29 | #### End of system configuration section. #### 30 | 31 | # This rule allows us to supply the necessary -D options 32 | # in addition to whatever the user asks for. 33 | .c.o: 34 | ${CC} -I. ${CFLAGS_COMPILE_ONLY} -DBINDIR=\"${bindir}\" -DSYSDIR=\"${sysconfdir}\" ${CPPFLAGS} ${CFLAGS} $< 35 | 36 | OBJ = \ 37 | main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \ 38 | command.${O} cvt.${O} decode.${O} edit.${O} filename.${O} forwback.${O} \ 39 | help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \ 40 | lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \ 41 | output.${O} pattern.${O} position.${O} prompt.${O} search.${O} signal.${O} \ 42 | tags.${O} ttyin.${O} version.${O} 43 | 44 | all: less lesskey lessecho 45 | 46 | less: ${OBJ} 47 | ${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS} 48 | 49 | lesskey: lesskey.${O} version.${O} 50 | ${CC} ${LDFLAGS} -o $@ lesskey.${O} version.${O} 51 | 52 | lessecho: lessecho.${O} version.${O} 53 | ${CC} ${LDFLAGS} -o $@ lessecho.${O} version.${O} 54 | 55 | defines.h: defines.ds 56 | command.com /c copy $< $@ 57 | 58 | ${OBJ}: ${srcdir}/less.h defines.h ${srcdir}/funcs.h 59 | 60 | install: all ${srcdir}/less.man ${srcdir}/lesskey.man 61 | ${INSTALL_PROGRAM} less.exe ${bindir}/less.exe 62 | ${INSTALL_PROGRAM} lesskey.exe ${bindir}/lesskey.exe 63 | ${INSTALL_PROGRAM} lessecho.exe ${bindir}/lessecho.exe 64 | ${INSTALL_DATA} ${srcdir}/less.man ${mandir}/man${manext}/less.${manext} 65 | ${INSTALL_DATA} ${srcdir}/lesskey.man ${mandir}/man${manext}/lesskey.${manext} 66 | 67 | info: 68 | install-info: 69 | dvi: 70 | check: 71 | installcheck: 72 | 73 | TAGS: 74 | etags *.c *.h 75 | 76 | newfuncs: 77 | command.com /c if exist funcs.h del funcs.h 78 | ${AWK} -f mkfuncs.awk ${OBJ:.${O}=.c} > funcs.h 79 | 80 | clean: 81 | command.com /c for %f in (*.${O} less lesskey lessecho *.exe) do if exist %f del %f 82 | 83 | mostlyclean: clean 84 | 85 | distclean: clean 86 | command.com /c if not exist Makefile.dsg ren Makefile Makefile.dsg 87 | command.com /c if not exist defines.ds ren defines.h defines.ds 88 | command.com /c for %f in (Makefile defines.h) do if exist %f del %f 89 | 90 | realclean: distclean 91 | command.com /c if exist TAGS del TAGS 92 | 93 | -------------------------------------------------------------------------------- /Makefile.dsu: -------------------------------------------------------------------------------- 1 | # Makefile for less. 2 | # MS-DOS version 3 | 4 | #### Start of system configuration section. #### 5 | 6 | CC = cl 7 | # Change the following directories to match your installation. 8 | LIBDIR = c:\msvc\lib 9 | INCDIR = c:\msvc\include 10 | 11 | # CFLAGS are compile-time options and LDFLAGS are link-time options. They are 12 | # customized for MSVC 1.0 (MSC 8.0). If you have a different version of the 13 | # compiler, you may need to change some of the options to their equivalents. 14 | # -Ot optimize for speed 15 | # -AL large memory model 16 | # -Za ANSI C conformance 17 | # -nologo suppress MSVC banners 18 | # -onerror:noexe no .EXE file if link errors occur 19 | CFLAGS = -Ot -AL -Za -nologo 20 | LDFLAGS = -onerror:noexe -nologo 21 | LIBS = $(LIBDIR)\llibce.lib $(LIBDIR)\graphics.lib 22 | 23 | #### End of system configuration section. #### 24 | 25 | # This rule allows us to supply the necessary -D options 26 | # in addition to whatever the user asks for. 27 | .c.obj: 28 | $(CC) -c -I. -I$(INCDIR) $(CPPFLAGS) $(CFLAGS) $< 29 | 30 | OBJ = \ 31 | main.obj screen.obj brac.obj ch.obj charset.obj cmdbuf.obj \ 32 | command.obj cvt.obj decode.obj edit.obj filename.obj forwback.obj \ 33 | help.obj ifile.obj input.obj jump.obj line.obj linenum.obj \ 34 | lsystem.obj mark.obj optfunc.obj option.obj opttbl.obj os.obj \ 35 | output.obj pattern.obj position.obj prompt.obj search.obj signal.obj \ 36 | tags.obj ttyin.obj version.obj 37 | 38 | all: less lesskey 39 | 40 | # This is really horrible, but the command line is too long for 41 | # MS-DOS if we try to link $(OBJ). 42 | less: $(OBJ) 43 | -if exist lesskey.obj del lesskey.obj 44 | $(CC) $(LDFLAGS) -o $@ *.obj $(LIBS) 45 | 46 | lesskey: lesskey.obj version.obj 47 | $(CC) $(LDFLAGS) -o $@ lesskey.obj version.obj $(LIBS) 48 | 49 | defines.h: defines.ds 50 | -del defines.h 51 | -copy defines.ds defines.h 52 | 53 | $(OBJ): less.h defines.h 54 | 55 | clean: 56 | -del *.obj 57 | -del less.exe 58 | -del lesskey.exe 59 | 60 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile for less. 2 | 3 | #### Start of system configuration section. #### 4 | 5 | srcdir = @srcdir@ 6 | VPATH = @srcdir@ 7 | 8 | CC = @CC@ 9 | INSTALL = @INSTALL@ 10 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 11 | INSTALL_DATA = @INSTALL_DATA@ 12 | 13 | CFLAGS = @CFLAGS@ 14 | CFLAGS_COMPILE_ONLY = -c 15 | LDFLAGS = @LDFLAGS@ 16 | CPPFLAGS = @CPPFLAGS@ 17 | EXEEXT = @EXEEXT@ 18 | O=o 19 | 20 | LIBS = @LIBS@ 21 | 22 | prefix = @prefix@ 23 | exec_prefix = @exec_prefix@ 24 | 25 | # Where the installed binary goes. 26 | bindir = @bindir@ 27 | binprefix = 28 | 29 | sysconfdir = @sysconfdir@ 30 | datarootdir = @datarootdir@ 31 | 32 | mandir = @mandir@ 33 | manext = 1 34 | manprefix = 35 | DESTDIR = 36 | 37 | #### End of system configuration section. #### 38 | 39 | SHELL = /bin/sh 40 | 41 | # This rule allows us to supply the necessary -D options 42 | # in addition to whatever the user asks for. 43 | .c.o: 44 | ${CC} -I. ${CFLAGS_COMPILE_ONLY} -DBINDIR=\"${bindir}\" -DSYSDIR=\"${sysconfdir}\" ${CPPFLAGS} ${CFLAGS} $< 45 | 46 | OBJ = \ 47 | main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \ 48 | command.${O} cvt.${O} decode.${O} edit.${O} filename.${O} forwback.${O} \ 49 | help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \ 50 | lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \ 51 | output.${O} pattern.${O} position.${O} prompt.${O} search.${O} signal.${O} \ 52 | tags.${O} ttyin.${O} version.${O} @REGEX_O@ 53 | 54 | all: less$(EXEEXT) lesskey$(EXEEXT) lessecho$(EXEEXT) 55 | 56 | less$(EXEEXT): ${OBJ} 57 | ${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS} 58 | 59 | lesskey$(EXEEXT): lesskey.${O} version.${O} 60 | ${CC} ${LDFLAGS} -o $@ lesskey.${O} version.${O} 61 | 62 | lessecho$(EXEEXT): lessecho.${O} version.${O} 63 | ${CC} ${LDFLAGS} -o $@ lessecho.${O} version.${O} 64 | 65 | ${OBJ}: ${srcdir}/less.h ${srcdir}/funcs.h defines.h 66 | 67 | install: all ${srcdir}/less.nro ${srcdir}/lesskey.nro ${srcdir}/lessecho.nro installdirs 68 | ${INSTALL_PROGRAM} less$(EXEEXT) ${DESTDIR}${bindir}/${binprefix}less$(EXEEXT) 69 | ${INSTALL_PROGRAM} lesskey$(EXEEXT) ${DESTDIR}${bindir}/${binprefix}lesskey$(EXEEXT) 70 | ${INSTALL_PROGRAM} lessecho$(EXEEXT) ${DESTDIR}${bindir}/${binprefix}lessecho$(EXEEXT) 71 | ${INSTALL_DATA} ${srcdir}/less.nro ${DESTDIR}${mandir}/man${manext}/${manprefix}less.${manext} 72 | ${INSTALL_DATA} ${srcdir}/lesskey.nro ${DESTDIR}${mandir}/man${manext}/${manprefix}lesskey.${manext} 73 | ${INSTALL_DATA} ${srcdir}/lessecho.nro ${DESTDIR}${mandir}/man${manext}/${manprefix}lessecho.${manext} 74 | 75 | install-strip: 76 | ${MAKE} INSTALL_PROGRAM='${INSTALL_PROGRAM} -s' install 77 | 78 | installdirs: mkinstalldirs 79 | ${srcdir}/mkinstalldirs ${DESTDIR}${bindir} ${DESTDIR}${mandir}/man${manext} 80 | 81 | uninstall: 82 | rm -f ${DESTDIR}${bindir}/${binprefix}less$(EXEEXT) 83 | rm -f ${DESTDIR}${bindir}/${binprefix}lesskey$(EXEEXT) 84 | rm -f ${DESTDIR}${bindir}/${binprefix}lessecho$(EXEEXT) 85 | rm -f ${DESTDIR}${mandir}/man${manext}/${manprefix}less.${manext} 86 | rm -f ${DESTDIR}${mandir}/man${manext}/${manprefix}lesskey.${manext} 87 | rm -f ${DESTDIR}${mandir}/man${manext}/${manprefix}lessecho.${manext} 88 | 89 | info: 90 | install-info: 91 | dvi: 92 | check: 93 | installcheck: 94 | 95 | TAGS: 96 | cd ${srcdir} && etags *.c *.h 97 | 98 | # config.status might not change defines.h 99 | # Don't rerun config.status if we just configured (so there's no stamp-h). 100 | defines.h: stamp-h 101 | stamp-h: defines.h.in config.status 102 | test ! -f stamp-h || CONFIG_FILES= CONFIG_HEADERS=defines.h ./config.status 103 | touch stamp-h 104 | Makefile: ${srcdir}/Makefile.in config.status 105 | CONFIG_FILES=Makefile CONFIG_HEADERS= ./config.status 106 | config.status: ${srcdir}/configure 107 | ./config.status --recheck 108 | 109 | ${srcdir}/configure: ${srcdir}/configure.ac 110 | cd ${srcdir}; autoheader; autoconf 111 | 112 | clean: 113 | rm -f *.${O} core less$(EXEEXT) lesskey$(EXEEXT) lessecho$(EXEEXT) 114 | 115 | mostlyclean: clean 116 | 117 | distclean: clean 118 | rm -f Makefile config.status config.log config.cache defines.h stamp-h 119 | 120 | realclean: distclean 121 | rm -f TAGS 122 | 123 | -------------------------------------------------------------------------------- /Makefile.o2e: -------------------------------------------------------------------------------- 1 | # Makefile for less. 2 | # OS/2 version, for emx+gcc compiler 3 | 4 | #### Start of system configuration section. #### 5 | 6 | CC = gcc -Zomf 7 | CFLAGS = -I. -O2 -Wall 8 | LDFLAGS = -s -Zcrtdll 9 | LIBS = -ltermcap 10 | O = obj 11 | 12 | #### End of system configuration section. #### 13 | 14 | .SUFFIXES: .c .${O} 15 | 16 | # This rule allows us to supply the necessary -D options 17 | # in addition to whatever the user asks for. 18 | .c.${O}: 19 | ${CC} -c ${CPPFLAGS} ${CFLAGS} $< 20 | 21 | OBJ = \ 22 | main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \ 23 | command.${O} cvt.${O} decode.${O} edit.${O} filename.${O} forwback.${O} \ 24 | help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \ 25 | lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \ 26 | output.${O} pattern.${O} position.${O} prompt.${O} search.${O} signal.${O} \ 27 | tags.${O} ttyin.${O} version.${O} regexp.${O} 28 | 29 | all: less.exe lesskey.exe scrsize.exe 30 | 31 | less.exe: ${OBJ} 32 | ${CC} ${OBJ} -o $@ ${LDFLAGS} ${LIBS} 33 | 34 | lesskey.exe: lesskey.${O} version.${O} 35 | ${CC} lesskey.${O} version.${O} -o $@ ${LDFLAGS} 36 | 37 | scrsize.exe: scrsize.c 38 | ${CC} ${CFLAGS} -D__ST_MT_ERRNO__ -s -Zmtd -lX11 $< 39 | 40 | ${OBJ}: defines.h less.h 41 | 42 | defines.h: defines.o2 43 | copy defines.o2 defines.h 44 | -------------------------------------------------------------------------------- /Makefile.o9c: -------------------------------------------------------------------------------- 1 | # Makefile for less. 2 | # OS-9 version for Microware C 3.2. 3 | 4 | #### Start of system configuration section. #### 5 | 6 | CC = cc 7 | CPPFLAGS = -D_OSK_MWC32 -DDEBUG=0 -DSTRCSPN 8 | CFLAGS = -k=0 -v=. 9 | CFLAGS_COMPILE_ONLY = -r 10 | LDFLAGS = -igm=8 11 | LIBS = -l=/dd/lib/termlib.l 12 | O = r 13 | 14 | 15 | #### End of system configuration section. #### 16 | 17 | .SUFFIXES: .c .${O} 18 | 19 | # This rule allows us to supply the necessary -D options 20 | # in addition to whatever the user asks for. 21 | 22 | .c.${O}: 23 | ${CC} ${CFLAGS_COMPILE_ONLY} ${CPPFLAGS} ${CFLAGS} $< 24 | 25 | OBJ = \ 26 | main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \ 27 | command.${O} cvt.${O} decode.${O} edit.${O} filename.${O} forwback.${O} \ 28 | help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \ 29 | lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \ 30 | output.${O} pattern.${O} position.${O} prompt.${O} search.${O} signal.${O} \ 31 | tags.${O} ttyin.${O} version.${O} regexp.${O} 32 | 33 | all: less lessecho lesskey 34 | 35 | less: ${OBJ} 36 | ${CC} ${OBJ} -f=$@ ${LDFLAGS} ${LIBS} 37 | 38 | lesskey: lesskey.${O} version.${O} 39 | ${CC} lesskey.${O} version.${O} -f=$@ ${LDFLAGS} 40 | 41 | lessecho: lessecho.${O} version.${O} 42 | ${CC} lessecho.${O} version.${O} -f=$@ ${LDFLAGS} 43 | 44 | ${OBJ}: defines.h less.h 45 | 46 | defines.h: defines.o9 47 | copy defines.o9 defines.h -rf 48 | -------------------------------------------------------------------------------- /Makefile.o9u: -------------------------------------------------------------------------------- 1 | # Makefile for less. 2 | # OS-9 version for Ultra C. 3 | 4 | #### Start of system configuration section. #### 5 | 6 | CC = cc 7 | CPPFLAGS = 8 | CFLAGS = -v=. 9 | CFLAGS_COMPILE_ONLY = -eas 10 | LDFLAGS = -olM=24k 11 | LIBS = -ltermlib.l -lsys_clib.l -lunix.l 12 | O = r 13 | 14 | 15 | #### End of system configuration section. #### 16 | 17 | .SUFFIXES: .c .${O} 18 | 19 | # This rule allows us to supply the necessary -D options 20 | # in addition to whatever the user asks for. 21 | .c.${O}: 22 | ${CC} ${CFLAGS_COMPILE_ONLY} ${CPPFLAGS} ${CFLAGS} $< 23 | 24 | OBJ = \ 25 | main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \ 26 | command.${O} cvt.${O} decode.${O} edit.${O} filename.${O} forwback.${O} \ 27 | help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \ 28 | lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \ 29 | output.${O} pattern.${O} position.${O} prompt.${O} search.${O} signal.${O} \ 30 | tags.${O} ttyin.${O} version.${O} regexp.${O} 31 | 32 | all: less lesskey 33 | 34 | less: ${OBJ} 35 | ${CC} ${OBJ} -f=$@ ${LDFLAGS} ${LIBS} 36 | 37 | lesskey: lesskey.${O} version.${O} 38 | ${CC} lesskey.${O} version.${O} -f=$@ ${LDFLAGS} 39 | 40 | ${OBJ}: defines.h less.h 41 | 42 | defines.h: defines.o9 43 | copy defines.o9 defines.h -rf 44 | -------------------------------------------------------------------------------- /Makefile.wnb: -------------------------------------------------------------------------------- 1 | # Makefile for less. 2 | # Windows version 3 | # Bolarnd C++ 5.5.1 free command line tools 4 | 5 | #### Start of system configuration section. #### 6 | # 7 | # Borland's make knows its own location in the 8 | # filesystem. 9 | # 10 | 11 | CC = bcc32 12 | LIBDIR = $(MAKEDIR)\..\lib 13 | 14 | CFLAGS = -O2 -w-pro -TWC -P-c -v- -d -f- -ff- -vi 15 | LDFLAGS = -Tpe -v- -ap -c -x -V4.0 -GF:AGGRESSIVE 16 | LD = ilink32 17 | LIBS = ${LIBDIR}\import32.lib ${LIBDIR}\cw32.lib 18 | 19 | #### End of system configuration section. #### 20 | 21 | # 22 | # This rule allows us to supply the necessary -D options 23 | # in addition to whatever the user asks for. 24 | # 25 | .c.obj: 26 | ${CC} -c -I. ${CPPFLAGS} ${CFLAGS} $< 27 | 28 | OBJ = \ 29 | main.obj screen.obj brac.obj ch.obj charset.obj cmdbuf.obj \ 30 | command.obj cvt.obj decode.obj edit.obj filename.obj forwback.obj \ 31 | help.obj ifile.obj input.obj jump.obj line.obj linenum.obj \ 32 | lsystem.obj mark.obj optfunc.obj option.obj opttbl.obj os.obj \ 33 | output.obj pattern.obj position.obj prompt.obj search.obj signal.obj \ 34 | tags.obj ttyin.obj version.obj regexp.obj 35 | 36 | all: less lesskey lessecho 37 | 38 | # 39 | # This is really horrible, but the command line is too long for 40 | # MS-DOS if we try to link ${OBJ}. 41 | # 42 | less: ${OBJ} 43 | ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj $**, $@,,${LIBS} 44 | 45 | lesskey: lesskey.obj version.obj 46 | ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj $**, $@,,${LIBS} 47 | 48 | lessecho: lessecho.obj version.obj 49 | ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj $**, $@,,${LIBS} 50 | 51 | defines.h: defines.wn 52 | -del defines.h 53 | -copy defines.wn defines.h 54 | 55 | ${OBJ}: less.h defines.h funcs.h cmd.h 56 | 57 | clean: 58 | -del *.obj 59 | -del *.il? 60 | -del *.tds 61 | -del defines.h 62 | 63 | spotless: clean 64 | -del less.exe 65 | -del lesskey.exe 66 | -del lessecho.exe 67 | 68 | realclean: spotless 69 | 70 | distclean: spotless 71 | 72 | -------------------------------------------------------------------------------- /Makefile.wnm: -------------------------------------------------------------------------------- 1 | # Makefile for less. 2 | # Windows 32 Visual C++ version 3 | 4 | #### Start of system configuration section. #### 5 | 6 | # Target architectire 7 | # use nmake -f Makefile.wnm ARCH=X64 to override this definition 8 | # Environment variable arch would not override it. 9 | # 10 | ARCH=I386 11 | 12 | CC = cl 13 | 14 | # Normal flags 15 | CFLAGS = /nologo /MD /W3 /EHsc /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /c 16 | LDFLAGS = /nologo /subsystem:console /incremental:no /machine:$(ARCH) 17 | 18 | # Debugging flags 19 | #CFLAGS = /nologo /MDd /W3 /EHsc /Od /Gm /Zi /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /c 20 | #LDFLAGS = /nologo /subsystem:console /incremental:yes /debug /machine:$(ARCH) 21 | 22 | LD = link 23 | LIBS = user32.lib 24 | 25 | #### End of system configuration section. #### 26 | 27 | # This rule allows us to supply the necessary -D options 28 | # in addition to whatever the user asks for. 29 | .c.obj: 30 | $(CC) $(CFLAGS) $< 31 | 32 | OBJ = \ 33 | main.obj screen.obj brac.obj ch.obj charset.obj cmdbuf.obj \ 34 | command.obj cvt.obj decode.obj edit.obj filename.obj forwback.obj \ 35 | help.obj ifile.obj input.obj jump.obj line.obj linenum.obj \ 36 | lsystem.obj mark.obj optfunc.obj option.obj opttbl.obj os.obj \ 37 | output.obj pattern.obj position.obj prompt.obj search.obj signal.obj \ 38 | tags.obj ttyin.obj version.obj regexp.obj 39 | 40 | all: less.exe lesskey.exe 41 | 42 | # This is really horrible, but the command line is too long for 43 | # MS-DOS if we try to link ${OBJ}. 44 | less.exe: $(OBJ) 45 | -del lesskey.obj 46 | $(LD) $(LDFLAGS) *.obj $(LIBS) /out:$@ 47 | 48 | lesskey.exe: lesskey.obj version.obj 49 | $(LD) $(LDFLAGS) lesskey.obj version.obj $(LIBS) /out:$@ 50 | 51 | defines.h: defines.wn 52 | -del defines.h 53 | -copy defines.wn defines.h 54 | 55 | $(OBJ): less.h defines.h funcs.h cmd.h 56 | 57 | clean: 58 | -del *.obj 59 | -del less.exe 60 | -del lesskey.exe 61 | 62 | 63 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | Less, version 481 3 | 4 | This is the distribution of less, version 481, released 31 Aug 2015. 5 | This program is part of the GNU project (http://www.gnu.org). 6 | 7 | This program is free software. You may redistribute it and/or 8 | modify it under the terms of either: 9 | 10 | 1. The GNU General Public License, as published by the Free 11 | Software Foundation; either version 3, or (at your option) any 12 | later version. A copy of this license is in the file COPYING. 13 | or 14 | 2. The Less License, in the file LICENSE. 15 | 16 | Please report any problems to bug-less@gnu.org. 17 | See http://www.greenwoodsoftware.com/less for the latest info. 18 | 19 | ========================================================================= 20 | 21 | This is the distribution of "less", a paginator similar to "more" or "pg". 22 | 23 | The formatted manual page is in less.man. 24 | The manual page nroff source is in less.nro. 25 | Major changes made since the last posted version are in NEWS. 26 | 27 | ======================================================================= 28 | INSTALLATION (Unix systems only): 29 | 30 | 1. Move the distributed source to its own directory and unpack it, 31 | if you have not already done so. 32 | 33 | 2. Type "sh configure". 34 | This will generate a Makefile and a defines.h. 35 | Warning: if you have a GNU sed, make sure it is version 2.05 or later. 36 | 37 | The file INSTALL describes the usage of the configure program in 38 | general. In addition, these options to configure are supported: 39 | 40 | --with-editor=program 41 | Specifies the default editor program used by the "v" command. 42 | The default is "vi". 43 | 44 | --with-regex=lib 45 | Specifies the regular expression library used by less for pattern 46 | matching. The default is "auto", which means the configure program 47 | finds a regular expression library automatically. Other values are: 48 | gnu Use the GNU regex library. 49 | pcre Use the PCRE library. 50 | posix Use the POSIX-compatible regcomp. 51 | regcmp Use the regcmp library. 52 | re_comp Use the re_comp library. 53 | regcomp Use the V8-compatible regcomp. 54 | regcomp-local Use Henry Spencer's V8-compatible regcomp 55 | (source is supplied with less). 56 | none No regular expressions, only simple string matching. 57 | --with-secure 58 | Builds a "secure" version of less, with some features disabled 59 | to prevent users from viewing other files, accessing shell 60 | commands, etc. 61 | 62 | 63 | 3. It is a good idea to look over the generated Makefile and defines.h 64 | and make sure they look ok. If you know of any peculiarities of 65 | your system that configure might not have detected, you may fix the 66 | Makefile now. Take particular notice of the list of "terminal" 67 | libraries in the LIBS definition in the Makefile; these may need 68 | to be edited. The terminal libraries will be some subset of 69 | -lncurses -lcurses -ltermcap -ltermlib 70 | 71 | If you wish, you may edit defines.h to remove some optional features. 72 | If you choose not to include some features in your version, you may 73 | wish to edit the manual page "less.nro" and the help page "less.hlp" 74 | to remove the descriptions of the features which you are removing. 75 | If you edit less.hlp, you should run "make -f Makefile.aut help.c". 76 | 77 | 4. Type "make" and watch the fun. 78 | 79 | 5. If the make succeeds, it will generate the programs "less", 80 | "lesskey" and "lessecho" in your current directory. Test the 81 | generated programs. 82 | 83 | 6. When satisfied that it works, if you wish to install it 84 | in a public place, type "make install". 85 | 86 | The default install destinations are: 87 | Executables (less, lesskey, lessecho) in /usr/local/bin 88 | Documentation (less.nro, lesskey.nro) in /usr/local/man/man1 89 | If you want to install any of these files elsewhere, define 90 | bindir and/or mandir to the appropriate directories. 91 | 92 | If you have any problems building or running "less", suggestions, 93 | complaints, etc., you may mail to bug-less@gnu.org. 94 | 95 | Note to hackers: comments noting possible improvements are enclosed 96 | in double curly brackets {{ like this }}. 97 | 98 | (Note that the above note was originally written at a time when 99 | "hackers" most commonly meant "enthusiastic and dedicated computer 100 | programmers", not "persons who attempt to circumvent computer security".) 101 | 102 | 103 | 104 | ======================================================================= 105 | INSTALLATION (MS-DOS systems only, 106 | with Microsoft C, Borland C, or DJGPP) 107 | 108 | 1. Move the distributed source to its own directory. 109 | Depending on your compiler, you may need to convert the source 110 | to have CR-LF rather than LF as line terminators. 111 | 112 | 2. If you are using Microsoft C, rename MAKEFILE.DSU to MAKEFILE. 113 | If you are using Borland C, rename MAKEFILE.DSB to MAKEFILE. 114 | If you are using DJGPP, rename MAKEFILE.DSG to MAKEFILE. 115 | 116 | 3. Look at MAKEFILE to make sure that the definitions for CC and LIBDIR 117 | are correct. CC should be the name of your C compiler and 118 | LIBDIR should be the directory where the C libraries reside (for 119 | Microsoft C only). If these definitions need to be changed, you can 120 | either modify the definitions directly in MAKEFILE, or set your 121 | environment variables CC and/or LIBDIR to override the definitions 122 | in MAKEFILE. 123 | 124 | 4. If you wish, you may edit DEFINES.DS to remove some optional features. 125 | If you choose not to include some features in your version, you may 126 | wish to edit the manual page LESS.MAN and the help page HELP.C 127 | to remove the descriptions of the features which you are removing. 128 | 129 | 5. Run your "make" program and watch the fun. 130 | If your "make" requires a flag to import environment variables, 131 | you should use that flag. 132 | If your compiler runs out of memory, try running "make -n >cmds.bat" 133 | and then run cmds.bat. 134 | 135 | 6. If the make succeeds, it will generate the programs "LESS.EXE" and 136 | "LESSKEY.EXE" in your current directory. Test the generated programs. 137 | 138 | 7. When satisfied that it works, you may wish to install LESS.EXE and 139 | LESSKEY.EXE in a directory which is included in your PATH. 140 | 141 | 142 | 143 | ======================================================================= 144 | INSTALLATION (Windows-95, Windows-98 and Windows-NT systems only, 145 | with Borland C or Microsoft Visual C++) 146 | 147 | 1. Move the distributed source to its own directory. 148 | 149 | 2. If you are using Borland C, rename Makefile.wnb to Makefile. 150 | If you are using Microsoft Visual C++, rename Makefile.wnm to Makefile. 151 | 152 | 3. Check the Makefile to make sure the definitions look ok. 153 | 154 | 4. If you wish, you may edit defines.wn to remove some optional features. 155 | If you choose not to include some features in your version, you may 156 | wish to edit the manual page less.man and the help page help.c 157 | to remove the descriptions of the features which you are removing. 158 | 159 | 5. Type "make" and watch the fun. 160 | 161 | 6. If the make succeeds, it will generate the programs "less.exe" and 162 | "lesskey.exe" in your current directory. Test the generated programs. 163 | 164 | 7. When satisfied that it works, if you wish to install it 165 | in a public place, type "make install". 166 | See step 6 of the Unix installation instructions for details 167 | on how to change the default installation directories. 168 | 169 | 170 | 171 | ======================================================================= 172 | INSTALLATION (OS/2 systems only, 173 | with EMX C) 174 | 175 | 1. Move the distributed source to its own directory. 176 | 177 | 2. Rename Makefile.o2e to Makefile. 178 | 179 | 3. Check the Makefile to make sure the definitions look ok. 180 | 181 | 4. If you wish, you may edit defines.o2 to remove some optional features. 182 | If you choose not to include some features in your version, you may 183 | wish to edit the manual page less.man and the help page help.c 184 | to remove the descriptions of the features which you are removing. 185 | 186 | 5. Type "make" and watch the fun. 187 | 188 | 6. If the make succeeds, it will generate the programs "less.exe" and 189 | "lesskey.exe" in your current directory. Test the generated programs. 190 | 191 | 7. Make sure you have the emx runtime installed. You need the emx DLLs 192 | emx.dll and emxlibcs.dll and also the termcap database, termcap.dat. 193 | Make sure you have termcap.dat either in the default location or 194 | somewhere in a directory listed in the PATH or INIT environment 195 | variables. 196 | 197 | 8. When satisfied that it works, you may wish to install less.exe, 198 | lesskey.exe and scrsize.exe in a directory which is included in 199 | your PATH. scrsize.exe is required only if you use a terminal 200 | emulator such as xterm or rxvt. 201 | 202 | 203 | 204 | ======================================================================= 205 | INSTALLATION (OS-9 systems only, 206 | with Microware C or Ultra C) 207 | 208 | 1. Move the distributed source to its own directory. 209 | 210 | 2. If you are using Microware C, rename Makefile.o9c to Makefile. 211 | If you are using Ultra C, rename Makefile.o9u to Makefile. 212 | 213 | 3. Check the Makefile to make sure the definitions look ok. 214 | 215 | 4. If you wish, you may edit defines.o9 to remove some optional features. 216 | If you choose not to include some features in your version, you may 217 | wish to edit the manual page less.man and the help page help.c 218 | to remove the descriptions of the features which you are removing. 219 | 220 | 5. Type "dmake" and watch the fun. 221 | The standard OS-9 "make" will probably not work. If you don't 222 | have dmake, you can get a copy from os9archive.rtsi.com. 223 | 224 | 6. If the make succeeds, it will generate the programs "less" and 225 | "lesskey" in your current directory. Test the generated programs. 226 | 227 | 7. When satisfied that it works, if you wish to install it 228 | in a public place, type "dmake install". 229 | See step 6 of the Unix installation instructions for details 230 | on how to change the default installation directories. 231 | 232 | ======================================================================= 233 | ACKNOWLEDGMENTS: 234 | Some versions of the less distribution are packaged using 235 | Info-ZIP's compression utility. 236 | Info-ZIP's software is free and can be obtained as source 237 | code or executables from various anonymous-ftp sites, 238 | including ftp.uu.net:/pub/archiving/zip. 239 | -------------------------------------------------------------------------------- /brac.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Routines to perform bracket matching functions. 13 | */ 14 | 15 | #include "less.h" 16 | #include "position.h" 17 | 18 | /* 19 | * Try to match the n-th open bracket 20 | * which appears in the top displayed line (forwdir), 21 | * or the n-th close bracket 22 | * which appears in the bottom displayed line (!forwdir). 23 | * The characters which serve as "open bracket" and 24 | * "close bracket" are given. 25 | */ 26 | public void 27 | match_brac(obrac, cbrac, forwdir, n) 28 | register int obrac; 29 | register int cbrac; 30 | int forwdir; 31 | int n; 32 | { 33 | register int c; 34 | register int nest; 35 | POSITION pos; 36 | int (*chget)(); 37 | 38 | extern int ch_forw_get(), ch_back_get(); 39 | 40 | /* 41 | * Seek to the line containing the open bracket. 42 | * This is either the top or bottom line on the screen, 43 | * depending on the type of bracket. 44 | */ 45 | pos = position((forwdir) ? TOP : BOTTOM); 46 | if (pos == NULL_POSITION || ch_seek(pos)) 47 | { 48 | if (forwdir) 49 | error("Nothing in top line", NULL_PARG); 50 | else 51 | error("Nothing in bottom line", NULL_PARG); 52 | return; 53 | } 54 | 55 | /* 56 | * Look thru the line to find the open bracket to match. 57 | */ 58 | do 59 | { 60 | if ((c = ch_forw_get()) == '\n' || c == EOI) 61 | { 62 | if (forwdir) 63 | error("No bracket in top line", NULL_PARG); 64 | else 65 | error("No bracket in bottom line", NULL_PARG); 66 | return; 67 | } 68 | } while (c != obrac || --n > 0); 69 | 70 | /* 71 | * Position the file just "after" the open bracket 72 | * (in the direction in which we will be searching). 73 | * If searching forward, we are already after the bracket. 74 | * If searching backward, skip back over the open bracket. 75 | */ 76 | if (!forwdir) 77 | (void) ch_back_get(); 78 | 79 | /* 80 | * Search the file for the matching bracket. 81 | */ 82 | chget = (forwdir) ? ch_forw_get : ch_back_get; 83 | nest = 0; 84 | while ((c = (*chget)()) != EOI) 85 | { 86 | if (c == obrac) 87 | nest++; 88 | else if (c == cbrac && --nest < 0) 89 | { 90 | /* 91 | * Found the matching bracket. 92 | * If searching backward, put it on the top line. 93 | * If searching forward, put it on the bottom line. 94 | */ 95 | jump_line_loc(ch_tell(), forwdir ? -1 : 1); 96 | return; 97 | } 98 | } 99 | error("No matching bracket", NULL_PARG); 100 | } 101 | -------------------------------------------------------------------------------- /charset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | #define IS_ASCII_OCTET(c) (((c) & 0x80) == 0) 11 | #define IS_UTF8_TRAIL(c) (((c) & 0xC0) == 0x80) 12 | #define IS_UTF8_LEAD2(c) (((c) & 0xE0) == 0xC0) 13 | #define IS_UTF8_LEAD3(c) (((c) & 0xF0) == 0xE0) 14 | #define IS_UTF8_LEAD4(c) (((c) & 0xF8) == 0xF0) 15 | #define IS_UTF8_LEAD5(c) (((c) & 0xFC) == 0xF8) 16 | #define IS_UTF8_LEAD6(c) (((c) & 0xFE) == 0xFC) 17 | #define IS_UTF8_INVALID(c) (((c) & 0xFE) == 0xFE) 18 | #define IS_UTF8_LEAD(c) (((c) & 0xC0) == 0xC0 && !IS_UTF8_INVALID(c)) 19 | -------------------------------------------------------------------------------- /cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | #define MAX_USERCMD 1000 12 | #define MAX_CMDLEN 16 13 | 14 | #define A_B_LINE 2 15 | #define A_B_SCREEN 3 16 | #define A_B_SCROLL 4 17 | #define A_B_SEARCH 5 18 | #define A_DIGIT 6 19 | #define A_DISP_OPTION 7 20 | #define A_DEBUG 8 21 | #define A_EXAMINE 9 22 | #define A_FIRSTCMD 10 23 | #define A_FREPAINT 11 24 | #define A_F_LINE 12 25 | #define A_F_SCREEN 13 26 | #define A_F_SCROLL 14 27 | #define A_F_SEARCH 15 28 | #define A_GOEND 16 29 | #define A_GOLINE 17 30 | #define A_GOMARK 18 31 | #define A_HELP 19 32 | #define A_NEXT_FILE 20 33 | #define A_PERCENT 21 34 | #define A_PREFIX 22 35 | #define A_PREV_FILE 23 36 | #define A_QUIT 24 37 | #define A_REPAINT 25 38 | #define A_SETMARK 26 39 | #define A_SHELL 27 40 | #define A_STAT 28 41 | #define A_FF_LINE 29 42 | #define A_BF_LINE 30 43 | #define A_VERSION 31 44 | #define A_VISUAL 32 45 | #define A_F_WINDOW 33 46 | #define A_B_WINDOW 34 47 | #define A_F_BRACKET 35 48 | #define A_B_BRACKET 36 49 | #define A_PIPE 37 50 | #define A_INDEX_FILE 38 51 | #define A_UNDO_SEARCH 39 52 | #define A_FF_SCREEN 40 53 | #define A_LSHIFT 41 54 | #define A_RSHIFT 42 55 | #define A_AGAIN_SEARCH 43 56 | #define A_T_AGAIN_SEARCH 44 57 | #define A_REVERSE_SEARCH 45 58 | #define A_T_REVERSE_SEARCH 46 59 | #define A_OPT_TOGGLE 47 60 | #define A_OPT_SET 48 61 | #define A_OPT_UNSET 49 62 | #define A_F_FOREVER 50 63 | #define A_GOPOS 51 64 | #define A_REMOVE_FILE 52 65 | #define A_NEXT_TAG 53 66 | #define A_PREV_TAG 54 67 | #define A_FILTER 55 68 | #define A_F_UNTIL_HILITE 56 69 | #define A_GOEND_BUF 57 70 | 71 | #define A_INVALID 100 72 | #define A_NOACTION 101 73 | #define A_UINVALID 102 74 | #define A_END_LIST 103 75 | #define A_SPECIAL_KEY 104 76 | 77 | #define A_SKIP 127 78 | 79 | #define A_EXTRA 0200 80 | 81 | 82 | /* Line editing characters */ 83 | 84 | #define EC_BACKSPACE 1 85 | #define EC_LINEKILL 2 86 | #define EC_RIGHT 3 87 | #define EC_LEFT 4 88 | #define EC_W_LEFT 5 89 | #define EC_W_RIGHT 6 90 | #define EC_INSERT 7 91 | #define EC_DELETE 8 92 | #define EC_HOME 9 93 | #define EC_END 10 94 | #define EC_W_BACKSPACE 11 95 | #define EC_W_DELETE 12 96 | #define EC_UP 13 97 | #define EC_DOWN 14 98 | #define EC_EXPAND 15 99 | #define EC_F_COMPLETE 17 100 | #define EC_B_COMPLETE 18 101 | #define EC_LITERAL 19 102 | #define EC_ABORT 20 103 | 104 | #define EC_NOACTION 101 105 | #define EC_UINVALID 102 106 | 107 | /* Flags for editchar() */ 108 | #define EC_PEEK 01 109 | #define EC_NOHISTORY 02 110 | #define EC_NOCOMPLETE 04 111 | #define EC_NORIGHTLEFT 010 112 | 113 | /* Environment variable stuff */ 114 | #define EV_OK 01 115 | 116 | /* Special keys (keys which output different strings on different terminals) */ 117 | #define SK_SPECIAL_KEY CONTROL('K') 118 | #define SK_RIGHT_ARROW 1 119 | #define SK_LEFT_ARROW 2 120 | #define SK_UP_ARROW 3 121 | #define SK_DOWN_ARROW 4 122 | #define SK_PAGE_UP 5 123 | #define SK_PAGE_DOWN 6 124 | #define SK_HOME 7 125 | #define SK_END 8 126 | #define SK_DELETE 9 127 | #define SK_INSERT 10 128 | #define SK_CTL_LEFT_ARROW 11 129 | #define SK_CTL_RIGHT_ARROW 12 130 | #define SK_CTL_DELETE 13 131 | #define SK_F1 14 132 | #define SK_BACKTAB 15 133 | #define SK_CTL_BACKSPACE 16 134 | #define SK_CONTROL_K 40 135 | -------------------------------------------------------------------------------- /compose.uni: -------------------------------------------------------------------------------- 1 | /* Generated by "./mkutable -f2 Mn Me -- unicode/UnicodeData.txt" on Mon Jul 14 16:21:21 PDT 2014 */ 2 | { 0x0300, 0x036f }, /* Mn */ 3 | { 0x0483, 0x0487 }, /* Mn */ 4 | { 0x0488, 0x0489 }, /* Me */ 5 | { 0x0591, 0x05bd }, /* Mn */ 6 | { 0x05bf, 0x05bf }, /* Mn */ 7 | { 0x05c1, 0x05c2 }, /* Mn */ 8 | { 0x05c4, 0x05c5 }, /* Mn */ 9 | { 0x05c7, 0x05c7 }, /* Mn */ 10 | { 0x0610, 0x061a }, /* Mn */ 11 | { 0x064b, 0x065f }, /* Mn */ 12 | { 0x0670, 0x0670 }, /* Mn */ 13 | { 0x06d6, 0x06dc }, /* Mn */ 14 | { 0x06df, 0x06e4 }, /* Mn */ 15 | { 0x06e7, 0x06e8 }, /* Mn */ 16 | { 0x06ea, 0x06ed }, /* Mn */ 17 | { 0x0711, 0x0711 }, /* Mn */ 18 | { 0x0730, 0x074a }, /* Mn */ 19 | { 0x07a6, 0x07b0 }, /* Mn */ 20 | { 0x07eb, 0x07f3 }, /* Mn */ 21 | { 0x0816, 0x0819 }, /* Mn */ 22 | { 0x081b, 0x0823 }, /* Mn */ 23 | { 0x0825, 0x0827 }, /* Mn */ 24 | { 0x0829, 0x082d }, /* Mn */ 25 | { 0x0859, 0x085b }, /* Mn */ 26 | { 0x08e4, 0x0902 }, /* Mn */ 27 | { 0x093a, 0x093a }, /* Mn */ 28 | { 0x093c, 0x093c }, /* Mn */ 29 | { 0x0941, 0x0948 }, /* Mn */ 30 | { 0x094d, 0x094d }, /* Mn */ 31 | { 0x0951, 0x0957 }, /* Mn */ 32 | { 0x0962, 0x0963 }, /* Mn */ 33 | { 0x0981, 0x0981 }, /* Mn */ 34 | { 0x09bc, 0x09bc }, /* Mn */ 35 | { 0x09c1, 0x09c4 }, /* Mn */ 36 | { 0x09cd, 0x09cd }, /* Mn */ 37 | { 0x09e2, 0x09e3 }, /* Mn */ 38 | { 0x0a01, 0x0a02 }, /* Mn */ 39 | { 0x0a3c, 0x0a3c }, /* Mn */ 40 | { 0x0a41, 0x0a42 }, /* Mn */ 41 | { 0x0a47, 0x0a48 }, /* Mn */ 42 | { 0x0a4b, 0x0a4d }, /* Mn */ 43 | { 0x0a51, 0x0a51 }, /* Mn */ 44 | { 0x0a70, 0x0a71 }, /* Mn */ 45 | { 0x0a75, 0x0a75 }, /* Mn */ 46 | { 0x0a81, 0x0a82 }, /* Mn */ 47 | { 0x0abc, 0x0abc }, /* Mn */ 48 | { 0x0ac1, 0x0ac5 }, /* Mn */ 49 | { 0x0ac7, 0x0ac8 }, /* Mn */ 50 | { 0x0acd, 0x0acd }, /* Mn */ 51 | { 0x0ae2, 0x0ae3 }, /* Mn */ 52 | { 0x0b01, 0x0b01 }, /* Mn */ 53 | { 0x0b3c, 0x0b3c }, /* Mn */ 54 | { 0x0b3f, 0x0b3f }, /* Mn */ 55 | { 0x0b41, 0x0b44 }, /* Mn */ 56 | { 0x0b4d, 0x0b4d }, /* Mn */ 57 | { 0x0b56, 0x0b56 }, /* Mn */ 58 | { 0x0b62, 0x0b63 }, /* Mn */ 59 | { 0x0b82, 0x0b82 }, /* Mn */ 60 | { 0x0bc0, 0x0bc0 }, /* Mn */ 61 | { 0x0bcd, 0x0bcd }, /* Mn */ 62 | { 0x0c00, 0x0c00 }, /* Mn */ 63 | { 0x0c3e, 0x0c40 }, /* Mn */ 64 | { 0x0c46, 0x0c48 }, /* Mn */ 65 | { 0x0c4a, 0x0c4d }, /* Mn */ 66 | { 0x0c55, 0x0c56 }, /* Mn */ 67 | { 0x0c62, 0x0c63 }, /* Mn */ 68 | { 0x0c81, 0x0c81 }, /* Mn */ 69 | { 0x0cbc, 0x0cbc }, /* Mn */ 70 | { 0x0cbf, 0x0cbf }, /* Mn */ 71 | { 0x0cc6, 0x0cc6 }, /* Mn */ 72 | { 0x0ccc, 0x0ccd }, /* Mn */ 73 | { 0x0ce2, 0x0ce3 }, /* Mn */ 74 | { 0x0d01, 0x0d01 }, /* Mn */ 75 | { 0x0d41, 0x0d44 }, /* Mn */ 76 | { 0x0d4d, 0x0d4d }, /* Mn */ 77 | { 0x0d62, 0x0d63 }, /* Mn */ 78 | { 0x0dca, 0x0dca }, /* Mn */ 79 | { 0x0dd2, 0x0dd4 }, /* Mn */ 80 | { 0x0dd6, 0x0dd6 }, /* Mn */ 81 | { 0x0e31, 0x0e31 }, /* Mn */ 82 | { 0x0e34, 0x0e3a }, /* Mn */ 83 | { 0x0e47, 0x0e4e }, /* Mn */ 84 | { 0x0eb1, 0x0eb1 }, /* Mn */ 85 | { 0x0eb4, 0x0eb9 }, /* Mn */ 86 | { 0x0ebb, 0x0ebc }, /* Mn */ 87 | { 0x0ec8, 0x0ecd }, /* Mn */ 88 | { 0x0f18, 0x0f19 }, /* Mn */ 89 | { 0x0f35, 0x0f35 }, /* Mn */ 90 | { 0x0f37, 0x0f37 }, /* Mn */ 91 | { 0x0f39, 0x0f39 }, /* Mn */ 92 | { 0x0f71, 0x0f7e }, /* Mn */ 93 | { 0x0f80, 0x0f84 }, /* Mn */ 94 | { 0x0f86, 0x0f87 }, /* Mn */ 95 | { 0x0f8d, 0x0f97 }, /* Mn */ 96 | { 0x0f99, 0x0fbc }, /* Mn */ 97 | { 0x0fc6, 0x0fc6 }, /* Mn */ 98 | { 0x102d, 0x1030 }, /* Mn */ 99 | { 0x1032, 0x1037 }, /* Mn */ 100 | { 0x1039, 0x103a }, /* Mn */ 101 | { 0x103d, 0x103e }, /* Mn */ 102 | { 0x1058, 0x1059 }, /* Mn */ 103 | { 0x105e, 0x1060 }, /* Mn */ 104 | { 0x1071, 0x1074 }, /* Mn */ 105 | { 0x1082, 0x1082 }, /* Mn */ 106 | { 0x1085, 0x1086 }, /* Mn */ 107 | { 0x108d, 0x108d }, /* Mn */ 108 | { 0x109d, 0x109d }, /* Mn */ 109 | { 0x135d, 0x135f }, /* Mn */ 110 | { 0x1712, 0x1714 }, /* Mn */ 111 | { 0x1732, 0x1734 }, /* Mn */ 112 | { 0x1752, 0x1753 }, /* Mn */ 113 | { 0x1772, 0x1773 }, /* Mn */ 114 | { 0x17b4, 0x17b5 }, /* Mn */ 115 | { 0x17b7, 0x17bd }, /* Mn */ 116 | { 0x17c6, 0x17c6 }, /* Mn */ 117 | { 0x17c9, 0x17d3 }, /* Mn */ 118 | { 0x17dd, 0x17dd }, /* Mn */ 119 | { 0x180b, 0x180d }, /* Mn */ 120 | { 0x18a9, 0x18a9 }, /* Mn */ 121 | { 0x1920, 0x1922 }, /* Mn */ 122 | { 0x1927, 0x1928 }, /* Mn */ 123 | { 0x1932, 0x1932 }, /* Mn */ 124 | { 0x1939, 0x193b }, /* Mn */ 125 | { 0x1a17, 0x1a18 }, /* Mn */ 126 | { 0x1a1b, 0x1a1b }, /* Mn */ 127 | { 0x1a56, 0x1a56 }, /* Mn */ 128 | { 0x1a58, 0x1a5e }, /* Mn */ 129 | { 0x1a60, 0x1a60 }, /* Mn */ 130 | { 0x1a62, 0x1a62 }, /* Mn */ 131 | { 0x1a65, 0x1a6c }, /* Mn */ 132 | { 0x1a73, 0x1a7c }, /* Mn */ 133 | { 0x1a7f, 0x1a7f }, /* Mn */ 134 | { 0x1ab0, 0x1abd }, /* Mn */ 135 | { 0x1abe, 0x1abe }, /* Me */ 136 | { 0x1b00, 0x1b03 }, /* Mn */ 137 | { 0x1b34, 0x1b34 }, /* Mn */ 138 | { 0x1b36, 0x1b3a }, /* Mn */ 139 | { 0x1b3c, 0x1b3c }, /* Mn */ 140 | { 0x1b42, 0x1b42 }, /* Mn */ 141 | { 0x1b6b, 0x1b73 }, /* Mn */ 142 | { 0x1b80, 0x1b81 }, /* Mn */ 143 | { 0x1ba2, 0x1ba5 }, /* Mn */ 144 | { 0x1ba8, 0x1ba9 }, /* Mn */ 145 | { 0x1bab, 0x1bad }, /* Mn */ 146 | { 0x1be6, 0x1be6 }, /* Mn */ 147 | { 0x1be8, 0x1be9 }, /* Mn */ 148 | { 0x1bed, 0x1bed }, /* Mn */ 149 | { 0x1bef, 0x1bf1 }, /* Mn */ 150 | { 0x1c2c, 0x1c33 }, /* Mn */ 151 | { 0x1c36, 0x1c37 }, /* Mn */ 152 | { 0x1cd0, 0x1cd2 }, /* Mn */ 153 | { 0x1cd4, 0x1ce0 }, /* Mn */ 154 | { 0x1ce2, 0x1ce8 }, /* Mn */ 155 | { 0x1ced, 0x1ced }, /* Mn */ 156 | { 0x1cf4, 0x1cf4 }, /* Mn */ 157 | { 0x1cf8, 0x1cf9 }, /* Mn */ 158 | { 0x1dc0, 0x1df5 }, /* Mn */ 159 | { 0x1dfc, 0x1dff }, /* Mn */ 160 | { 0x20d0, 0x20dc }, /* Mn */ 161 | { 0x20dd, 0x20e0 }, /* Me */ 162 | { 0x20e1, 0x20e1 }, /* Mn */ 163 | { 0x20e2, 0x20e4 }, /* Me */ 164 | { 0x20e5, 0x20f0 }, /* Mn */ 165 | { 0x2cef, 0x2cf1 }, /* Mn */ 166 | { 0x2d7f, 0x2d7f }, /* Mn */ 167 | { 0x2de0, 0x2dff }, /* Mn */ 168 | { 0x302a, 0x302d }, /* Mn */ 169 | { 0x3099, 0x309a }, /* Mn */ 170 | { 0xa66f, 0xa66f }, /* Mn */ 171 | { 0xa670, 0xa672 }, /* Me */ 172 | { 0xa674, 0xa67d }, /* Mn */ 173 | { 0xa69f, 0xa69f }, /* Mn */ 174 | { 0xa6f0, 0xa6f1 }, /* Mn */ 175 | { 0xa802, 0xa802 }, /* Mn */ 176 | { 0xa806, 0xa806 }, /* Mn */ 177 | { 0xa80b, 0xa80b }, /* Mn */ 178 | { 0xa825, 0xa826 }, /* Mn */ 179 | { 0xa8c4, 0xa8c4 }, /* Mn */ 180 | { 0xa8e0, 0xa8f1 }, /* Mn */ 181 | { 0xa926, 0xa92d }, /* Mn */ 182 | { 0xa947, 0xa951 }, /* Mn */ 183 | { 0xa980, 0xa982 }, /* Mn */ 184 | { 0xa9b3, 0xa9b3 }, /* Mn */ 185 | { 0xa9b6, 0xa9b9 }, /* Mn */ 186 | { 0xa9bc, 0xa9bc }, /* Mn */ 187 | { 0xa9e5, 0xa9e5 }, /* Mn */ 188 | { 0xaa29, 0xaa2e }, /* Mn */ 189 | { 0xaa31, 0xaa32 }, /* Mn */ 190 | { 0xaa35, 0xaa36 }, /* Mn */ 191 | { 0xaa43, 0xaa43 }, /* Mn */ 192 | { 0xaa4c, 0xaa4c }, /* Mn */ 193 | { 0xaa7c, 0xaa7c }, /* Mn */ 194 | { 0xaab0, 0xaab0 }, /* Mn */ 195 | { 0xaab2, 0xaab4 }, /* Mn */ 196 | { 0xaab7, 0xaab8 }, /* Mn */ 197 | { 0xaabe, 0xaabf }, /* Mn */ 198 | { 0xaac1, 0xaac1 }, /* Mn */ 199 | { 0xaaec, 0xaaed }, /* Mn */ 200 | { 0xaaf6, 0xaaf6 }, /* Mn */ 201 | { 0xabe5, 0xabe5 }, /* Mn */ 202 | { 0xabe8, 0xabe8 }, /* Mn */ 203 | { 0xabed, 0xabed }, /* Mn */ 204 | { 0xfb1e, 0xfb1e }, /* Mn */ 205 | { 0xfe00, 0xfe0f }, /* Mn */ 206 | { 0xfe20, 0xfe2d }, /* Mn */ 207 | { 0x101fd, 0x101fd }, /* Mn */ 208 | { 0x102e0, 0x102e0 }, /* Mn */ 209 | { 0x10376, 0x1037a }, /* Mn */ 210 | { 0x10a01, 0x10a03 }, /* Mn */ 211 | { 0x10a05, 0x10a06 }, /* Mn */ 212 | { 0x10a0c, 0x10a0f }, /* Mn */ 213 | { 0x10a38, 0x10a3a }, /* Mn */ 214 | { 0x10a3f, 0x10a3f }, /* Mn */ 215 | { 0x10ae5, 0x10ae6 }, /* Mn */ 216 | { 0x11001, 0x11001 }, /* Mn */ 217 | { 0x11038, 0x11046 }, /* Mn */ 218 | { 0x1107f, 0x11081 }, /* Mn */ 219 | { 0x110b3, 0x110b6 }, /* Mn */ 220 | { 0x110b9, 0x110ba }, /* Mn */ 221 | { 0x11100, 0x11102 }, /* Mn */ 222 | { 0x11127, 0x1112b }, /* Mn */ 223 | { 0x1112d, 0x11134 }, /* Mn */ 224 | { 0x11173, 0x11173 }, /* Mn */ 225 | { 0x11180, 0x11181 }, /* Mn */ 226 | { 0x111b6, 0x111be }, /* Mn */ 227 | { 0x1122f, 0x11231 }, /* Mn */ 228 | { 0x11234, 0x11234 }, /* Mn */ 229 | { 0x11236, 0x11237 }, /* Mn */ 230 | { 0x112df, 0x112df }, /* Mn */ 231 | { 0x112e3, 0x112ea }, /* Mn */ 232 | { 0x11301, 0x11301 }, /* Mn */ 233 | { 0x1133c, 0x1133c }, /* Mn */ 234 | { 0x11340, 0x11340 }, /* Mn */ 235 | { 0x11366, 0x1136c }, /* Mn */ 236 | { 0x11370, 0x11374 }, /* Mn */ 237 | { 0x114b3, 0x114b8 }, /* Mn */ 238 | { 0x114ba, 0x114ba }, /* Mn */ 239 | { 0x114bf, 0x114c0 }, /* Mn */ 240 | { 0x114c2, 0x114c3 }, /* Mn */ 241 | { 0x115b2, 0x115b5 }, /* Mn */ 242 | { 0x115bc, 0x115bd }, /* Mn */ 243 | { 0x115bf, 0x115c0 }, /* Mn */ 244 | { 0x11633, 0x1163a }, /* Mn */ 245 | { 0x1163d, 0x1163d }, /* Mn */ 246 | { 0x1163f, 0x11640 }, /* Mn */ 247 | { 0x116ab, 0x116ab }, /* Mn */ 248 | { 0x116ad, 0x116ad }, /* Mn */ 249 | { 0x116b0, 0x116b5 }, /* Mn */ 250 | { 0x116b7, 0x116b7 }, /* Mn */ 251 | { 0x16af0, 0x16af4 }, /* Mn */ 252 | { 0x16b30, 0x16b36 }, /* Mn */ 253 | { 0x16f8f, 0x16f92 }, /* Mn */ 254 | { 0x1bc9d, 0x1bc9e }, /* Mn */ 255 | { 0x1d167, 0x1d169 }, /* Mn */ 256 | { 0x1d17b, 0x1d182 }, /* Mn */ 257 | { 0x1d185, 0x1d18b }, /* Mn */ 258 | { 0x1d1aa, 0x1d1ad }, /* Mn */ 259 | { 0x1d242, 0x1d244 }, /* Mn */ 260 | { 0x1e8d0, 0x1e8d6 }, /* Mn */ 261 | { 0xe0100, 0xe01ef }, /* Mn */ 262 | -------------------------------------------------------------------------------- /cvt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | /* 11 | * Routines to convert text in various ways. Used by search. 12 | */ 13 | 14 | #include "less.h" 15 | #include "charset.h" 16 | 17 | extern int utf_mode; 18 | 19 | /* 20 | * Get the length of a buffer needed to convert a string. 21 | */ 22 | public int 23 | cvt_length(len, ops) 24 | int len; 25 | int ops; 26 | { 27 | if (utf_mode) 28 | /* 29 | * Just copying a string in UTF-8 mode can cause it to grow 30 | * in length. 31 | * Four output bytes for one input byte is the worst case. 32 | */ 33 | len *= 4; 34 | return (len + 1); 35 | } 36 | 37 | /* 38 | * Allocate a chpos array for use by cvt_text. 39 | */ 40 | public int * 41 | cvt_alloc_chpos(len) 42 | int len; 43 | { 44 | int i; 45 | int *chpos = (int *) ecalloc(sizeof(int), len); 46 | /* Initialize all entries to an invalid position. */ 47 | for (i = 0; i < len; i++) 48 | chpos[i] = -1; 49 | return (chpos); 50 | } 51 | 52 | /* 53 | * Convert text. Perform the transformations specified by ops. 54 | * Returns converted text in odst. The original offset of each 55 | * odst character (when it was in osrc) is returned in the chpos array. 56 | */ 57 | public void 58 | cvt_text(odst, osrc, chpos, lenp, ops) 59 | char *odst; 60 | char *osrc; 61 | int *chpos; 62 | int *lenp; 63 | int ops; 64 | { 65 | char *dst; 66 | char *edst = odst; 67 | char *src; 68 | register char *src_end; 69 | LWCHAR ch; 70 | 71 | if (lenp != NULL) 72 | src_end = osrc + *lenp; 73 | else 74 | src_end = osrc + strlen(osrc); 75 | 76 | for (src = osrc, dst = odst; src < src_end; ) 77 | { 78 | int src_pos = (int) (src - osrc); 79 | int dst_pos = (int) (dst - odst); 80 | ch = step_char(&src, +1, src_end); 81 | if ((ops & CVT_BS) && ch == '\b' && dst > odst) 82 | { 83 | /* Delete backspace and preceding char. */ 84 | do { 85 | dst--; 86 | } while (dst > odst && 87 | !IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst)); 88 | } else if ((ops & CVT_ANSI) && IS_CSI_START(ch)) 89 | { 90 | /* Skip to end of ANSI escape sequence. */ 91 | src++; /* skip the CSI start char */ 92 | while (src < src_end) 93 | if (!is_ansi_middle(*src++)) 94 | break; 95 | } else 96 | { 97 | /* Just copy the char to the destination buffer. */ 98 | if ((ops & CVT_TO_LC) && IS_UPPER(ch)) 99 | ch = TO_LOWER(ch); 100 | put_wchar(&dst, ch); 101 | /* Record the original position of the char. */ 102 | if (chpos != NULL) 103 | chpos[dst_pos] = src_pos; 104 | } 105 | if (dst > edst) 106 | edst = dst; 107 | } 108 | if ((ops & CVT_CRLF) && edst > odst && edst[-1] == '\r') 109 | edst--; 110 | *edst = '\0'; 111 | if (lenp != NULL) 112 | *lenp = (int) (edst - odst); 113 | /* FIXME: why was this here? if (chpos != NULL) chpos[dst - odst] = src - osrc; */ 114 | } 115 | -------------------------------------------------------------------------------- /defines.o2: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* OS/2 definition file for less. */ 12 | /* 13 | * This file has 2 sections: 14 | * User preferences. 15 | * Settings always true for the emx compiler for OS/2 systems. 16 | */ 17 | 18 | 19 | /* User preferences. */ 20 | 21 | /* 22 | * SECURE is 1 if you wish to disable a bunch of features in order to 23 | * be safe to run by unprivileged users. 24 | */ 25 | #define SECURE 0 26 | 27 | /* 28 | * SHELL_ESCAPE is 1 if you wish to allow shell escapes. 29 | * (This is possible only if your system supplies the system() function.) 30 | */ 31 | #define SHELL_ESCAPE (!SECURE) 32 | 33 | /* 34 | * EXAMINE is 1 if you wish to allow examining files by name from within less. 35 | */ 36 | #define EXAMINE (!SECURE) 37 | 38 | /* 39 | * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key 40 | * to complete filenames at prompts. 41 | */ 42 | #define TAB_COMPLETE_FILENAME (!SECURE) 43 | 44 | /* 45 | * CMD_HISTORY is 1 if you wish to allow keys to cycle through 46 | * previous commands at prompts. 47 | */ 48 | #define CMD_HISTORY 1 49 | 50 | /* 51 | * HILITE_SEARCH is 1 if you wish to have search targets to be 52 | * displayed in standout mode. 53 | */ 54 | #define HILITE_SEARCH 1 55 | 56 | /* 57 | * EDITOR is 1 if you wish to allow editor invocation (the "v" command). 58 | * (This is possible only if your system supplies the system() function.) 59 | * EDIT_PGM is the name of the (default) editor to be invoked. 60 | */ 61 | #define EDITOR (!SECURE) 62 | #define EDIT_PGM "vi" 63 | 64 | /* 65 | * TAGS is 1 if you wish to support tag files. 66 | */ 67 | #define TAGS (!SECURE) 68 | 69 | /* 70 | * USERFILE is 1 if you wish to allow a .less file to specify 71 | * user-defined key bindings. 72 | */ 73 | #define USERFILE (!SECURE) 74 | 75 | /* 76 | * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. 77 | * This will generally work if your system provides the "popen" function 78 | * and the "echo" shell command. 79 | */ 80 | #define GLOB (!SECURE) 81 | 82 | /* 83 | * PIPEC is 1 if you wish to have the "|" command 84 | * which allows the user to pipe data into a shell command. 85 | */ 86 | #define PIPEC (!SECURE) 87 | 88 | /* 89 | * LOGFILE is 1 if you wish to allow the -l option (to create log files). 90 | */ 91 | #define LOGFILE (!SECURE) 92 | 93 | /* 94 | * GNU_OPTIONS is 1 if you wish to support the GNU-style command 95 | * line options --help and --version. 96 | */ 97 | #define GNU_OPTIONS 1 98 | 99 | /* 100 | * ONLY_RETURN is 1 if you want RETURN to be the only input which 101 | * will continue past an error message. 102 | * Otherwise, any key will continue past an error message. 103 | */ 104 | #define ONLY_RETURN 0 105 | 106 | /* 107 | * LESSKEYFILE is the filename of the default lesskey output file 108 | * (in the HOME directory). 109 | * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. 110 | * DEF_LESSKEYINFILE is the filename of the default lesskey input 111 | * (in the HOME directory). 112 | * LESSHISTFILE is the filename of the history file 113 | * (in the HOME directory). 114 | */ 115 | #define LESSKEYFILE "less.ini" 116 | #define LESSKEYFILE_SYS "C:\\sysless.ini" 117 | #define DEF_LESSKEYINFILE "lesskey.ini" 118 | #define LESSHISTFILE "lesshst.ini" 119 | 120 | 121 | /* Settings always true for the emx compiler for OS/2 systems. */ 122 | #define OS2 1 123 | 124 | /* 125 | * Pathname separator character. 126 | */ 127 | #define PATHNAME_SEP "\\" 128 | 129 | /* 130 | * HAVE_SYS_TYPES_H is 1 if your system has . 131 | */ 132 | #define HAVE_SYS_TYPES_H 1 133 | 134 | /* 135 | * Define if you have the header file. 136 | */ 137 | #define HAVE_SGSTAT_H 0 138 | 139 | /* 140 | * HAVE_PERROR is 1 if your system has the perror() call. 141 | * (Actually, if it has sys_errlist, sys_nerr and errno.) 142 | */ 143 | #define HAVE_PERROR 1 144 | 145 | /* 146 | * HAVE_TIME is 1 if your system has the time() call. 147 | */ 148 | #define HAVE_TIME 1 149 | 150 | /* 151 | * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. 152 | */ 153 | #define HAVE_SHELL 0 154 | 155 | /* 156 | * Default shell metacharacters and meta-escape character. 157 | */ 158 | #define DEF_METACHARS "; *?\t\n'\"()<>|&" 159 | #define DEF_METAESCAPE "" 160 | 161 | /* 162 | * HAVE_DUP is 1 if your system has the dup() call. 163 | */ 164 | #define HAVE_DUP 1 165 | 166 | /* 167 | * Sizes of various buffers. 168 | */ 169 | #if 0 /* old sizes for small memory machines 170 | #define CMDBUF_SIZE 512 /* Buffer for multichar commands */ 171 | #define UNGOT_SIZE 100 /* Max chars to unget() */ 172 | #define LINEBUF_SIZE 1024 /* Max size of line in input file */ 173 | #define OUTBUF_SIZE 1024 /* Output buffer */ 174 | #define PROMPT_SIZE 200 /* Max size of prompt string */ 175 | #define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ 176 | #define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ 177 | #define TAGLINE_SIZE 512 /* Max size of line in tags file */ 178 | #define TABSTOP_MAX 32 /* Max number of custom tab stops */ 179 | #else /* more reasonable sizes for modern machines */ 180 | #define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ 181 | #define UNGOT_SIZE 200 /* Max chars to unget() */ 182 | #define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ 183 | #define OUTBUF_SIZE 1024 /* Output buffer */ 184 | #define PROMPT_SIZE 2048 /* Max size of prompt string */ 185 | #define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ 186 | #define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ 187 | #define TAGLINE_SIZE 1024 /* Max size of line in tags file */ 188 | #define TABSTOP_MAX 128 /* Max number of custom tab stops */ 189 | #endif 190 | 191 | /* Define to `long' if doesn't define. */ 192 | /* #define off_t long */ 193 | 194 | /* Define if you need to in order for stat and other things to work. */ 195 | /* #undef _POSIX_SOURCE */ 196 | 197 | /* Define as the return type of signal handlers (int or void). */ 198 | #define RETSIGTYPE void 199 | 200 | 201 | /* 202 | * Regular expression library. 203 | * Define exactly one of the following to be 1: 204 | * HAVE_POSIX_REGCOMP: POSIX regcomp() and regex.h 205 | * HAVE_RE_COMP: BSD re_comp() 206 | * HAVE_REGCMP: System V regcmp() 207 | * HAVE_V8_REGCOMP: Henry Spencer V8 regcomp() and regexp.h 208 | * NO_REGEX: pattern matching is supported, but without metacharacters. 209 | */ 210 | /* #undef HAVE_POSIX_REGCOMP */ 211 | /* #undef HAVE_RE_COMP */ 212 | /* #undef HAVE_REGCMP */ 213 | #define HAVE_V8_REGCOMP 1 214 | /* #undef NO_REGEX */ 215 | #define HAVE_REGEXEC2 1 216 | 217 | /* Define HAVE_VOID if your compiler supports the "void" type. */ 218 | #define HAVE_VOID 1 219 | 220 | /* Define HAVE_CONST if your compiler supports the "const" modifier. */ 221 | #define HAVE_CONST 1 222 | 223 | /* Define HAVE_TIME_T if your system supports the "time_t" type. */ 224 | #define HAVE_TIME_T 1 225 | 226 | /* Define HAVE_STRERROR if you have the strerror() function. */ 227 | #define HAVE_STRERROR 1 228 | 229 | /* Define HAVE_FILENO if you have the fileno() macro. */ 230 | #define HAVE_FILENO 1 231 | 232 | /* Define HAVE_ERRNO if you have the errno variable */ 233 | /* Define MUST_DEFINE_ERRNO if you have errno but it is not define 234 | * in errno.h */ 235 | #define HAVE_ERRNO 1 236 | /* #undef MUST_DEFINE_ERRNO */ 237 | 238 | /* Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable */ 239 | #define HAVE_SYS_ERRLIST 1 240 | 241 | /* Define HAVE_OSPEED if your termcap library has the ospeed variable */ 242 | #define HAVE_OSPEED 1 243 | /* Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined 244 | * in termcap.h. */ 245 | #define MUST_DEFINE_OSPEED 0 246 | 247 | /* Define HAVE_LOCALE if you have locale.h and setlocale. */ 248 | #define HAVE_LOCALE 1 249 | 250 | /* Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr */ 251 | #define HAVE_TERMIOS_FUNCS 1 252 | 253 | /* Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower */ 254 | #define HAVE_UPPER_LOWER 1 255 | 256 | /* Define if you have the _setjmp function. */ 257 | #define HAVE__SETJMP 0 258 | 259 | /* Define if you have the memcpy function. */ 260 | #define HAVE_MEMCPY 1 261 | 262 | /* Define if you have the popen function. */ 263 | #define HAVE_POPEN 1 264 | 265 | /* Define if you have the sigsetmask function. */ 266 | #define HAVE_SIGSETMASK 0 267 | 268 | /* Define if you have the sigprocmask function. */ 269 | #define HAVE_SIGPROCMASK 1 270 | 271 | /* Define if you have the sigset_t type and sigemptyset macro */ 272 | #define HAVE_SIGSET_T 1 273 | #define HAVE_SIGEMPTYSET 1 274 | 275 | /* Define if you have the stat function. */ 276 | #define HAVE_STAT 1 277 | 278 | /* Define if you have the strchr function. */ 279 | #define HAVE_STRCHR 1 280 | 281 | /* Define if you have the strstr function. */ 282 | #define HAVE_STRSTR 1 283 | 284 | /* Define if you have the system function. */ 285 | #define HAVE_SYSTEM 1 286 | 287 | /* Define if you have the snprintf function. */ 288 | #define HAVE_SNPRINTF 0 289 | 290 | /* Define if you have the header file. */ 291 | #define HAVE_CTYPE_H 1 292 | 293 | /* Define if you have the header file. */ 294 | #define HAVE_WCTYPE_H 0 295 | 296 | /* Define if you have the header file. */ 297 | #define HAVE_ERRNO_H 1 298 | 299 | /* Define if you have the header file. */ 300 | #define HAVE_FCNTL_H 1 301 | 302 | /* Define if you have the header file. */ 303 | #define HAVE_LIMITS_H 1 304 | 305 | /* Define if you have the header file. */ 306 | #define HAVE_STDIO_H 1 307 | 308 | /* Define if you have the header file. */ 309 | #define HAVE_STDLIB_H 1 310 | 311 | /* Define if you have the header file. */ 312 | #define HAVE_STRING_H 1 313 | 314 | /* Define if you have the header file. */ 315 | #define HAVE_SYS_IOCTL_H 1 316 | 317 | /* Define if you have the header file. */ 318 | #define HAVE_SYS_PTEM_H 0 319 | 320 | /* Define if you have the header file. */ 321 | #define HAVE_SYS_STREAM_H 0 322 | 323 | /* Define if you have the header file. */ 324 | #define HAVE_TERMCAP_H 1 325 | 326 | /* Define if you have the header file. */ 327 | #define HAVE_TERMIO_H 1 328 | 329 | /* Define if you have the header file. */ 330 | #define HAVE_TERMIOS_H 1 331 | 332 | /* Define if you have the header file. */ 333 | #define HAVE_TIME_H 1 334 | 335 | /* Define if you have the header file. */ 336 | #define HAVE_UNISTD_H 1 337 | 338 | /* Define if you have the header file. */ 339 | #define HAVE_VALUES_H 0 340 | -------------------------------------------------------------------------------- /defines.o9: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* OS/9 definition file for less. */ 12 | /* 13 | * This file has 2 sections: 14 | * User preferences. 15 | * Settings always true for OS-9 systems. 16 | */ 17 | 18 | /* User preferences. */ 19 | 20 | /* 21 | * SECURE is 1 if you wish to disable a bunch of features in order to 22 | * be safe to run by unprivileged users. 23 | */ 24 | #define SECURE 0 25 | 26 | /* 27 | * SHELL_ESCAPE is 1 if you wish to allow shell escapes. 28 | * (This is possible only if your system supplies the system() function.) 29 | */ 30 | #define SHELL_ESCAPE (!SECURE) 31 | 32 | /* 33 | * EXAMINE is 1 if you wish to allow examining files by name from within less. 34 | */ 35 | #define EXAMINE (!SECURE) 36 | 37 | /* 38 | * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key 39 | * to complete filenames at prompts. 40 | */ 41 | #define TAB_COMPLETE_FILENAME 1 42 | 43 | /* 44 | * CMD_HISTORY is 1 if you wish to allow keys to cycle through 45 | * previous commands at prompts. 46 | */ 47 | #define CMD_HISTORY 1 48 | 49 | /* 50 | * HILITE_SEARCH is 1 if you wish to have search targets to be 51 | * displayed in standout mode. 52 | */ 53 | #define HILITE_SEARCH 1 54 | 55 | /* 56 | * EDITOR is 1 if you wish to allow editor invocation (the "v" command). 57 | * (This is possible only if your system supplies the system() function.) 58 | * EDIT_PGM is the name of the (default) editor to be invoked. 59 | */ 60 | #define EDITOR (!SECURE) 61 | #define EDIT_PGM "umacs" 62 | 63 | /* 64 | * TAGS is 1 if you wish to support tag files. 65 | */ 66 | #define TAGS (!SECURE) 67 | 68 | /* 69 | * USERFILE is 1 if you wish to allow a .less file to specify 70 | * user-defined key bindings. 71 | */ 72 | #define USERFILE (!SECURE) 73 | 74 | /* 75 | * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. 76 | * This will generally work if your system provides the "popen" function 77 | * and the "echo" shell command. 78 | */ 79 | #define GLOB (!SECURE) 80 | 81 | /* 82 | * PIPEC is 1 if you wish to have the "|" command 83 | * which allows the user to pipe data into a shell command. 84 | */ 85 | #define PIPEC (!SECURE) 86 | 87 | /* 88 | * LOGFILE is 1 if you wish to allow the -l option (to create log files). 89 | */ 90 | #define LOGFILE (!SECURE) 91 | 92 | /* 93 | * GNU_OPTIONS is 1 if you wish to support the GNU-style command 94 | * line options --help and --version. 95 | */ 96 | #define GNU_OPTIONS 1 97 | 98 | /* 99 | * ONLY_RETURN is 1 if you want RETURN to be the only input which 100 | * will continue past an error message. 101 | * Otherwise, any key will continue past an error message. 102 | */ 103 | #define ONLY_RETURN 0 104 | 105 | /* 106 | * LESSKEYFILE is the filename of the default lesskey output file 107 | * (in the HOME directory). 108 | * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. 109 | * DEF_LESSKEYINFILE is the filename of the default lesskey input 110 | * (in the HOME directory). 111 | * LESSHISTFILE is the filename of the history file 112 | * (in the HOME directory). 113 | */ 114 | #define LESSKEYFILE ".less" 115 | #define LESSKEYFILE_SYS "/.sysless" 116 | #define DEF_LESSKEYINFILE ".lesskey" 117 | #define LESSHISTFILE ".lesshst" 118 | 119 | 120 | /* Settings always true for OS-9. */ 121 | 122 | /* This is not needed; it is defined by the compiler. */ 123 | /* #define _OSK 1 */ 124 | #define OS2 0 125 | #define MSDOS_COMPILER 0 126 | 127 | /* 128 | * Pathname separator character. 129 | */ 130 | #define PATHNAME_SEP "/" 131 | 132 | /* 133 | * HAVE_SYS_TYPES_H is 1 if your system has . 134 | */ 135 | #define HAVE_SYS_TYPES_H 0 136 | 137 | /* 138 | * Define if you have the header file. 139 | */ 140 | #define HAVE_SGSTAT_H 1 141 | 142 | /* 143 | * HAVE_PERROR is 1 if your system has the perror() call. 144 | * (Actually, if it has sys_errlist, sys_nerr and errno.) 145 | */ 146 | #if _OSK_MWC32 147 | #define HAVE_PERROR 0 148 | #else 149 | #define HAVE_PERROR 1 150 | #endif 151 | 152 | /* 153 | * HAVE_TIME is 1 if your system has the time() call. 154 | */ 155 | #define HAVE_TIME 1 156 | 157 | /* 158 | * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. 159 | */ 160 | #define HAVE_SHELL 0 161 | 162 | /* 163 | * Default shell metacharacters and meta-escape character. 164 | */ 165 | #define DEF_METACHARS "; \t\n'\"()<>|&^`#\\" 166 | #define DEF_METAESCAPE "\\" 167 | 168 | /* 169 | * HAVE_DUP is 1 if your system has the dup() call. 170 | */ 171 | #define HAVE_DUP 0 172 | 173 | /* 174 | * Sizes of various buffers. 175 | */ 176 | #if 0 /* old sizes for small memory machines 177 | #define CMDBUF_SIZE 512 /* Buffer for multichar commands */ 178 | #define UNGOT_SIZE 100 /* Max chars to unget() */ 179 | #define LINEBUF_SIZE 1024 /* Max size of line in input file */ 180 | #define OUTBUF_SIZE 1024 /* Output buffer */ 181 | #define PROMPT_SIZE 200 /* Max size of prompt string */ 182 | #define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ 183 | #define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ 184 | #define TAGLINE_SIZE 512 /* Max size of line in tags file */ 185 | #define TABSTOP_MAX 32 /* Max number of custom tab stops */ 186 | #else /* more reasonable sizes for modern machines */ 187 | #define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ 188 | #define UNGOT_SIZE 200 /* Max chars to unget() */ 189 | #define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ 190 | #define OUTBUF_SIZE 1024 /* Output buffer */ 191 | #define PROMPT_SIZE 2048 /* Max size of prompt string */ 192 | #define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ 193 | #define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ 194 | #define TAGLINE_SIZE 1024 /* Max size of line in tags file */ 195 | #define TABSTOP_MAX 128 /* Max number of custom tab stops */ 196 | #endif 197 | 198 | /* Define to `long' if doesn't define. */ 199 | #define off_t long 200 | 201 | /* Define if you need to in order for stat and other things to work. */ 202 | #define _POSIX_SOURCE 0 203 | 204 | /* Define as the return type of signal handlers (int or void). */ 205 | #if _OSK_MWC32 206 | #define RETSIGTYPE int 207 | #else 208 | #define RETSIGTYPE void 209 | #endif 210 | 211 | 212 | /* 213 | * Regular expression library. 214 | * Define exactly one of the following to be 1: 215 | * HAVE_POSIX_REGCOMP: POSIX regcomp() and regex.h 216 | * HAVE_RE_COMP: BSD re_comp() 217 | * HAVE_REGCMP: System V regcmp() 218 | * HAVE_V8_REGCOMP: Henry Spencer V8 regcomp() and regexp.h 219 | * NO_REGEX: pattern matching is supported, but without metacharacters. 220 | */ 221 | #define HAVE_POSIX_REGCOMP 0 222 | #define HAVE_RE_COMP 0 223 | #define HAVE_REGCMP 0 224 | #define HAVE_V8_REGCOMP 1 225 | #define NO_REGEX 0 226 | #define HAVE_REGEXEC2 1 227 | 228 | /* Define HAVE_VOID if your compiler supports the "void" type. */ 229 | #define HAVE_VOID 1 230 | 231 | /* Define HAVE_CONST if your compiler supports the "const" modifier. */ 232 | #define HAVE_CONST 0 233 | 234 | /* Define HAVE_TIME_T if your system supports the "time_t" type. */ 235 | #define HAVE_TIME_T 1 236 | 237 | /* Define HAVE_STRERROR if you have the strerror() function. */ 238 | #define HAVE_STRERROR 0 239 | 240 | /* Define HAVE_FILENO if you have the fileno() macro. */ 241 | #define HAVE_FILENO 1 242 | 243 | /* Define HAVE_ERRNO if you have the errno variable */ 244 | /* Define MUST_DEFINE_ERRNO if you have errno but it is not define 245 | * in errno.h */ 246 | #define HAVE_ERRNO 1 247 | #define MUST_DEFINE_ERRNO 0 248 | 249 | /* Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable */ 250 | #define HAVE_SYS_ERRLIST 0 251 | 252 | /* Define HAVE_OSPEED if your termcap library has the ospeed variable */ 253 | /* Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined 254 | * in termcap.h. */ 255 | #define HAVE_OSPEED 0 256 | #define MUST_DEFINE_OSPEED 0 257 | 258 | /* Define HAVE_LOCALE if you have locale.h and setlocale. */ 259 | #define HAVE_LOCALE 0 260 | 261 | /* Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr */ 262 | #define HAVE_TERMIOS_FUNCS 0 263 | 264 | /* Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower */ 265 | #define HAVE_UPPER_LOWER 1 266 | 267 | /* Define if you have the _setjmp function. */ 268 | #define HAVE__SETJMP 1 269 | 270 | /* Define if you have the memcpy function. */ 271 | #define HAVE_MEMCPY 1 272 | 273 | /* Define if you have the popen function. */ 274 | #define HAVE_POPEN 1 275 | 276 | /* Define if you have the sigsetmask function. */ 277 | #define HAVE_SIGSETMASK 0 278 | 279 | /* Define if you have the sigprocmask function. */ 280 | #define HAVE_SIGPROCMASK 0 281 | 282 | /* Define if you have the sigset_t type and sigemptyset macro */ 283 | #define HAVE_SIGSET_T 0 284 | #define HAVE_SIGEMPTYSET 0 285 | 286 | /* Define if you have the stat function. */ 287 | #define HAVE_STAT 0 288 | 289 | /* Define if you have the strchr function. */ 290 | #define HAVE_STRCHR 0 291 | 292 | /* Define if you have the system function. */ 293 | #define HAVE_SYSTEM 1 294 | 295 | /* Define if you have the snprintf function. */ 296 | #define HAVE_SNPRINTF 0 297 | 298 | /* Define if you have the header file. */ 299 | #define HAVE_CTYPE_H 1 300 | 301 | /* Define if you have the header file. */ 302 | #define HAVE_WCTYPE_H 0 303 | 304 | /* Define if you have the header file. */ 305 | #define HAVE_ERRNO_H 1 306 | 307 | /* Define if you have the header file. */ 308 | #define HAVE_FCNTL_H 0 309 | 310 | /* Define if you have the header file. */ 311 | #define HAVE_LIMITS_H 0 312 | 313 | /* Define if you have the header file. */ 314 | #define HAVE_STDIO_H 1 315 | 316 | /* Define if you have the header file. */ 317 | #define HAVE_STRING_H 1 318 | 319 | /* Define if you have the header file. */ 320 | #if _OSK_MWC32 321 | #define HAVE_STDLIB_H 0 322 | #else 323 | #define HAVE_STDLIB_H 1 324 | #endif 325 | 326 | /* Define if you have the header file. */ 327 | #define HAVE_SYS_IOCTL_H 0 328 | 329 | /* Define if you have the header file. */ 330 | #define HAVE_SYS_PTEM_H 0 331 | 332 | /* Define if you have the header file. */ 333 | #define HAVE_SYS_STREAM_H 0 334 | 335 | /* Define if you have the header file. */ 336 | #define HAVE_TERMCAP_H 1 337 | 338 | /* Define if you have the header file. */ 339 | #define HAVE_TERMIO_H 0 340 | 341 | /* Define if you have the header file. */ 342 | #define HAVE_TERMIOS_H 0 343 | 344 | /* Define if you have the header file. */ 345 | #define HAVE_TIME_H 1 346 | 347 | /* Define if you have the header file. */ 348 | #define HAVE_UNISTD_H 0 349 | 350 | /* Define if you have the header file. */ 351 | #define HAVE_VALUES_H 0 352 | -------------------------------------------------------------------------------- /defines.wn: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* Windows definition file for less. */ 12 | /* 13 | * This file has 2 sections: 14 | * User preferences. 15 | * Settings always true for Windows systems. 16 | */ 17 | 18 | 19 | /* User preferences. */ 20 | 21 | /* 22 | * SECURE is 1 if you wish to disable a bunch of features in order to 23 | * be safe to run by unprivileged users. 24 | */ 25 | #define SECURE 0 26 | 27 | /* 28 | * SHELL_ESCAPE is 1 if you wish to allow shell escapes. 29 | * (This is possible only if your system supplies the system() function.) 30 | */ 31 | #define SHELL_ESCAPE (!SECURE) 32 | 33 | /* 34 | * EXAMINE is 1 if you wish to allow examining files by name from within less. 35 | */ 36 | #define EXAMINE (!SECURE) 37 | 38 | /* 39 | * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key 40 | * to complete filenames at prompts. 41 | */ 42 | #define TAB_COMPLETE_FILENAME (!SECURE) 43 | 44 | /* 45 | * CMD_HISTORY is 1 if you wish to allow keys to cycle through 46 | * previous commands at prompts. 47 | */ 48 | #define CMD_HISTORY 1 49 | 50 | /* 51 | * HILITE_SEARCH is 1 if you wish to have search targets to be 52 | * displayed in standout mode. 53 | */ 54 | #define HILITE_SEARCH 1 55 | 56 | /* 57 | * EDITOR is 1 if you wish to allow editor invocation (the "v" command). 58 | * (This is possible only if your system supplies the system() function.) 59 | * EDIT_PGM is the name of the (default) editor to be invoked. 60 | */ 61 | #define EDITOR (!SECURE) 62 | #define EDIT_PGM "edit" 63 | 64 | /* 65 | * TAGS is 1 if you wish to support tag files. 66 | */ 67 | #define TAGS (!SECURE) 68 | 69 | /* 70 | * USERFILE is 1 if you wish to allow a .less file to specify 71 | * user-defined key bindings. 72 | */ 73 | #define USERFILE (!SECURE) 74 | 75 | /* 76 | * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. 77 | * This will generally work if your system provides the "popen" function 78 | * and the "echo" shell command. 79 | */ 80 | #define GLOB 0 81 | 82 | /* 83 | * PIPEC is 1 if you wish to have the "|" command 84 | * which allows the user to pipe data into a shell command. 85 | */ 86 | #define PIPEC 1 87 | 88 | /* 89 | * LOGFILE is 1 if you wish to allow the -l option (to create log files). 90 | */ 91 | #define LOGFILE (!SECURE) 92 | 93 | /* 94 | * GNU_OPTIONS is 1 if you wish to support the GNU-style command 95 | * line options --help and --version. 96 | */ 97 | #define GNU_OPTIONS 1 98 | 99 | /* 100 | * ONLY_RETURN is 1 if you want RETURN to be the only input which 101 | * will continue past an error message. 102 | * Otherwise, any key will continue past an error message. 103 | */ 104 | #define ONLY_RETURN 0 105 | 106 | /* 107 | * LESSKEYFILE is the filename of the default lesskey output file 108 | * (in the HOME directory). 109 | * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. 110 | * DEF_LESSKEYINFILE is the filename of the default lesskey input 111 | * (in the HOME directory). 112 | * LESSHISTFILE is the filename of the history file 113 | * (in the HOME directory). 114 | */ 115 | #define LESSKEYFILE "_less" 116 | #define LESSKEYFILE_SYS "c:\\_sysless" 117 | #define DEF_LESSKEYINFILE "_lesskey" 118 | #define LESSHISTFILE "_lesshst" 119 | 120 | 121 | /* Settings always true for Windows systems. */ 122 | 123 | #define MSDOS_COMPILER WIN32C 124 | 125 | /* 126 | * Pathname separator character. 127 | */ 128 | #define PATHNAME_SEP "\\" 129 | 130 | /* 131 | * HAVE_SYS_TYPES_H is 1 if your system has . 132 | */ 133 | #define HAVE_SYS_TYPES_H 1 134 | 135 | /* 136 | * Define if you have the header file. 137 | */ 138 | #define HAVE_SGSTAT_H 0 139 | 140 | /* 141 | * HAVE_PERROR is 1 if your system has the perror() call. 142 | * (Actually, if it has sys_errlist, sys_nerr and errno.) 143 | */ 144 | #define HAVE_PERROR 1 145 | 146 | /* 147 | * HAVE_TIME is 1 if your system has the time() call. 148 | */ 149 | #define HAVE_TIME 1 150 | 151 | /* 152 | * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. 153 | */ 154 | #define HAVE_SHELL 0 155 | 156 | /* 157 | * Default shell metacharacters and meta-escape character. 158 | */ 159 | #define DEF_METACHARS "; *?\t\n'\"()<>|&" 160 | #define DEF_METAESCAPE "" 161 | 162 | /* 163 | * HAVE_DUP is 1 if your system has the dup() call. 164 | */ 165 | #define HAVE_DUP 1 166 | 167 | /* 168 | * Sizes of various buffers. 169 | */ 170 | #if 0 /* old sizes for small memory machines 171 | #define CMDBUF_SIZE 512 /* Buffer for multichar commands */ 172 | #define UNGOT_SIZE 100 /* Max chars to unget() */ 173 | #define LINEBUF_SIZE 1024 /* Max size of line in input file */ 174 | #define OUTBUF_SIZE 1024 /* Output buffer */ 175 | #define PROMPT_SIZE 200 /* Max size of prompt string */ 176 | #define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ 177 | #define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ 178 | #define TAGLINE_SIZE 512 /* Max size of line in tags file */ 179 | #define TABSTOP_MAX 32 /* Max number of custom tab stops */ 180 | #else /* more reasonable sizes for modern machines */ 181 | #define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ 182 | #define UNGOT_SIZE 200 /* Max chars to unget() */ 183 | #define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ 184 | #define OUTBUF_SIZE 1024 /* Output buffer */ 185 | #define PROMPT_SIZE 2048 /* Max size of prompt string */ 186 | #define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ 187 | #define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ 188 | #define TAGLINE_SIZE 1024 /* Max size of line in tags file */ 189 | #define TABSTOP_MAX 128 /* Max number of custom tab stops */ 190 | #endif 191 | 192 | /* Define to `long' if doesn't define. */ 193 | /* #define off_t long */ 194 | 195 | /* Define if you need to in order for stat and other things to work. */ 196 | /* #undef _POSIX_SOURCE */ 197 | 198 | /* Define as the return type of signal handlers (int or void). */ 199 | #define RETSIGTYPE void 200 | 201 | 202 | /* 203 | * Regular expression library. 204 | * Define exactly one of the following to be 1: 205 | * HAVE_POSIX_REGCOMP: POSIX regcomp() and regex.h 206 | * HAVE_RE_COMP: BSD re_comp() 207 | * HAVE_REGCMP: System V regcmp() 208 | * HAVE_V8_REGCOMP: Henry Spencer V8 regcomp() and regexp.h 209 | * NO_REGEX: pattern matching is supported, but without metacharacters. 210 | */ 211 | /* #undef HAVE_POSIX_REGCOMP */ 212 | /* #undef HAVE_RE_COMP */ 213 | /* #undef HAVE_REGCMP */ 214 | #define HAVE_V8_REGCOMP 1 215 | /* #undef NO_REGEX */ 216 | #define HAVE_REGEXEC2 1 217 | 218 | /* Define HAVE_VOID if your compiler supports the "void" type. */ 219 | #define HAVE_VOID 1 220 | 221 | /* Define HAVE_CONST if your compiler supports the "const" modifier. */ 222 | #define HAVE_CONST 1 223 | 224 | /* Define HAVE_TIME_T if your system supports the "time_t" type. */ 225 | #define HAVE_TIME_T 1 226 | 227 | /* Define HAVE_STRERROR if you have the strerror() function. */ 228 | #define HAVE_STRERROR 1 229 | 230 | /* Define HAVE_FILENO if you have the fileno() macro. */ 231 | #define HAVE_FILENO 1 232 | 233 | /* Define HAVE_ERRNO if you have the errno variable */ 234 | /* Define MUST_DEFINE_ERRNO if you have errno but it is not define 235 | * in errno.h */ 236 | #define HAVE_ERRNO 1 237 | #define MUST_DEFINE_ERRNO 1 238 | 239 | /* Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable */ 240 | #define HAVE_SYS_ERRLIST 1 241 | 242 | /* Define HAVE_OSPEED if your termcap library has the ospeed variable */ 243 | #define HAVE_OSPEED 0 244 | /* Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined 245 | * in termcap.h. */ 246 | #define MUST_DEFINE_OSPEED 0 247 | 248 | /* Define HAVE_LOCALE if you have locale.h and setlocale. */ 249 | #define HAVE_LOCALE 0 250 | 251 | /* Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr */ 252 | #define HAVE_TERMIOS_FUNCS 0 253 | 254 | /* Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower */ 255 | #define HAVE_UPPER_LOWER 1 256 | 257 | /* Define if you have the _setjmp function. */ 258 | #define HAVE__SETJMP 1 259 | 260 | /* Define if you have the memcpy function. */ 261 | #define HAVE_MEMCPY 1 262 | 263 | /* Define if you have the popen function. */ 264 | #define HAVE_POPEN 1 265 | 266 | /* Define if you have the sigsetmask function. */ 267 | #define HAVE_SIGSETMASK 0 268 | 269 | /* Define if you have the sigprocmask function. */ 270 | #define HAVE_SIGPROCMASK 0 271 | 272 | /* Define if you have the sigset_t type and sigemptyset macro */ 273 | #define HAVE_SIGSET_T 0 274 | #define HAVE_SIGEMPTYSET 0 275 | 276 | /* Define if you have the stat function. */ 277 | #define HAVE_STAT 1 278 | 279 | /* Define if you have the strchr function. */ 280 | #define HAVE_STRCHR 1 281 | 282 | /* Define if you have the system function. */ 283 | #define HAVE_SYSTEM 1 284 | 285 | /* Define if you have the snprintf function. */ 286 | #define HAVE_SNPRINTF 1 287 | 288 | /* Define if you have the header file. */ 289 | #define HAVE_CTYPE_H 1 290 | 291 | /* Define if you have the header file. */ 292 | #define HAVE_WCTYPE_H 1 293 | 294 | /* Define if you have the header file. */ 295 | #define HAVE_ERRNO_H 1 296 | 297 | /* Define if you have the header file. */ 298 | #define HAVE_FCNTL_H 1 299 | 300 | /* Define HAVE_FLOAT if your compiler supports the "double" type. */ 301 | #define HAVE_FLOAT 1 302 | 303 | /* Define if you have the header file. */ 304 | #define HAVE_LIMITS_H 1 305 | 306 | /* Define if you have the header file. */ 307 | #define HAVE_STDIO_H 1 308 | 309 | /* Define if you have the header file. */ 310 | #define HAVE_STRING_H 1 311 | 312 | /* Define if you have the header file. */ 313 | #define HAVE_STDLIB_H 1 314 | 315 | /* Define if you have the header file. */ 316 | #define HAVE_SYS_IOCTL_H 0 317 | 318 | /* Define if you have the header file. */ 319 | #define HAVE_SYS_PTEM_H 0 320 | 321 | /* Define if you have the header file. */ 322 | #define HAVE_SYS_STREAM_H 0 323 | 324 | /* Define if you have the header file. */ 325 | #define HAVE_TERMCAP_H 0 326 | 327 | /* Define if you have the header file. */ 328 | #define HAVE_TERMIO_H 0 329 | 330 | /* Define if you have the header file. */ 331 | #define HAVE_TERMIOS_H 0 332 | 333 | /* Define if you have the header file. */ 334 | #define HAVE_TIME_H 1 335 | 336 | /* Define if you have the header file. */ 337 | #define HAVE_UNISTD_H 0 338 | 339 | /* Define if you have the header file. */ 340 | #ifdef _MSC_VER 341 | #define HAVE_VALUES_H 0 342 | #else 343 | #define HAVE_VALUES_H 1 344 | #endif 345 | 346 | #define popen _popen 347 | #define pclose _pclose 348 | #if !defined(_MSC_VER) || (_MSC_VER < 1900) 349 | #define snprintf _snprintf 350 | #endif 351 | 352 | #pragma warning(disable:4996) 353 | -------------------------------------------------------------------------------- /funcs.h: -------------------------------------------------------------------------------- 1 | public char * save (); 2 | public VOID_POINTER ecalloc (); 3 | public char * skipsp (); 4 | public int sprefix (); 5 | public void quit (); 6 | public void raw_mode (); 7 | public void scrsize (); 8 | public char * special_key_str (); 9 | public void get_term (); 10 | public void init (); 11 | public void deinit (); 12 | public void home (); 13 | public void add_line (); 14 | public void remove_top (); 15 | public void win32_scroll_up (); 16 | public void lower_left (); 17 | public void line_left (); 18 | public void check_winch (); 19 | public void goto_line (); 20 | public void vbell (); 21 | public void bell (); 22 | public void clear (); 23 | public void clear_eol (); 24 | public void clear_bot (); 25 | public void at_enter (); 26 | public void at_exit (); 27 | public void at_switch (); 28 | public int is_at_equiv (); 29 | public int apply_at_specials (); 30 | public void backspace (); 31 | public void putbs (); 32 | public char WIN32getch (); 33 | public void WIN32setcolors (); 34 | public void WIN32textout (); 35 | public void match_brac (); 36 | public void ch_ungetchar (); 37 | public void end_logfile (); 38 | public void sync_logfile (); 39 | public int ch_seek (); 40 | public int ch_end_seek (); 41 | public int ch_end_buffer_seek (); 42 | public int ch_beg_seek (); 43 | public POSITION ch_length (); 44 | public POSITION ch_tell (); 45 | public int ch_forw_get (); 46 | public int ch_back_get (); 47 | public void ch_setbufspace (); 48 | public void ch_flush (); 49 | public int seekable (); 50 | public void ch_set_eof (); 51 | public void ch_init (); 52 | public void ch_close (); 53 | public int ch_getflags (); 54 | public void ch_dump (); 55 | public void init_charset (); 56 | public int binary_char (); 57 | public int control_char (); 58 | public char * prchar (); 59 | public char * prutfchar (); 60 | public int utf_len (); 61 | public int is_utf8_well_formed (); 62 | public int utf_bin_count (); 63 | public LWCHAR get_wchar (); 64 | public void put_wchar (); 65 | public LWCHAR step_char (); 66 | public int is_composing_char (); 67 | public int is_ubin_char (); 68 | public int is_wide_char (); 69 | public int is_combining_char (); 70 | public void cmd_reset (); 71 | public void clear_cmd (); 72 | public void cmd_putstr (); 73 | public int len_cmdbuf (); 74 | public void set_mlist (); 75 | public void cmd_addhist (); 76 | public void cmd_accept (); 77 | public int cmd_char (); 78 | public LINENUM cmd_int (); 79 | public char * get_cmdbuf (); 80 | public char * cmd_lastpattern (); 81 | public void init_cmdhist (); 82 | public void save_cmdhist (); 83 | public int in_mca (); 84 | public void dispversion (); 85 | public int getcc (); 86 | public void ungetcc (); 87 | public void ungetsc (); 88 | public void commands (); 89 | public int cvt_length (); 90 | public int * cvt_alloc_chpos (); 91 | public void cvt_text (); 92 | public void init_cmds (); 93 | public void add_fcmd_table (); 94 | public void add_ecmd_table (); 95 | public int fcmd_decode (); 96 | public int ecmd_decode (); 97 | public char * lgetenv (); 98 | public int lesskey (); 99 | public void add_hometable (); 100 | public int editchar (); 101 | public void init_textlist (); 102 | public char * forw_textlist (); 103 | public char * back_textlist (); 104 | public int edit (); 105 | public int edit_ifile (); 106 | public int edit_list (); 107 | public int edit_first (); 108 | public int edit_last (); 109 | public int edit_next (); 110 | public int edit_prev (); 111 | public int edit_index (); 112 | public IFILE save_curr_ifile (); 113 | public void unsave_ifile (); 114 | public void reedit_ifile (); 115 | public void reopen_curr_ifile (); 116 | public int edit_stdin (); 117 | public void cat_file (); 118 | public void use_logfile (); 119 | public char * shell_unquote (); 120 | public char * get_meta_escape (); 121 | public char * shell_quote (); 122 | public char * homefile (); 123 | public char * fexpand (); 124 | public char * fcomplete (); 125 | public int bin_file (); 126 | public char * lglob (); 127 | public char * open_altfile (); 128 | public void close_altfile (); 129 | public int is_dir (); 130 | public char * bad_file (); 131 | public POSITION filesize (); 132 | public char * shell_coption (); 133 | public char * last_component (); 134 | public int eof_displayed (); 135 | public int entire_file_displayed (); 136 | public void squish_check (); 137 | public void forw (); 138 | public void back (); 139 | public void forward (); 140 | public void backward (); 141 | public int get_back_scroll (); 142 | public void del_ifile (); 143 | public IFILE next_ifile (); 144 | public IFILE prev_ifile (); 145 | public IFILE getoff_ifile (); 146 | public int nifile (); 147 | public IFILE get_ifile (); 148 | public char * get_filename (); 149 | public int get_index (); 150 | public void store_pos (); 151 | public void get_pos (); 152 | public void set_open (); 153 | public int opened (); 154 | public void hold_ifile (); 155 | public int held_ifile (); 156 | public void * get_filestate (); 157 | public void set_filestate (); 158 | public void if_dump (); 159 | public POSITION forw_line (); 160 | public POSITION back_line (); 161 | public void set_attnpos (); 162 | public void jump_forw (); 163 | public void jump_forw_buffered (); 164 | public void jump_back (); 165 | public void repaint (); 166 | public void jump_percent (); 167 | public void jump_line_loc (); 168 | public void jump_loc (); 169 | public void init_line (); 170 | public int is_ascii_char (); 171 | public void prewind (); 172 | public void plinenum (); 173 | public void pshift_all (); 174 | public int is_ansi_end (); 175 | public int is_ansi_middle (); 176 | public int pappend (); 177 | public int pflushmbc (); 178 | public void pdone (); 179 | public void set_status_col (); 180 | public int gline (); 181 | public void null_line (); 182 | public POSITION forw_raw_line (); 183 | public POSITION back_raw_line (); 184 | public void clr_linenum (); 185 | public void add_lnum (); 186 | public LINENUM find_linenum (); 187 | public POSITION find_pos (); 188 | public LINENUM currline (); 189 | public void lsystem (); 190 | public int pipe_mark (); 191 | public int pipe_data (); 192 | public void init_mark (); 193 | public int badmark (); 194 | public void setmark (); 195 | public void lastmark (); 196 | public void gomark (); 197 | public POSITION markpos (); 198 | public void unmark (); 199 | public void opt_o (); 200 | public void opt__O (); 201 | public void opt_j (); 202 | public void calc_jump_sline (); 203 | public void opt_shift (); 204 | public void calc_shift_count (); 205 | public void opt_k (); 206 | public void opt_t (); 207 | public void opt__T (); 208 | public void opt_p (); 209 | public void opt__P (); 210 | public void opt_b (); 211 | public void opt_i (); 212 | public void opt__V (); 213 | public void opt_D (); 214 | public void opt_x (); 215 | public void opt_quote (); 216 | public void opt_query (); 217 | public int get_swindow (); 218 | public char * propt (); 219 | public void scan_option (); 220 | public void toggle_option (); 221 | public int opt_has_param (); 222 | public char * opt_prompt (); 223 | public int isoptpending (); 224 | public void nopendopt (); 225 | public int getnum (); 226 | public long getfraction (); 227 | public int get_quit_at_eof (); 228 | public void init_option (); 229 | public struct loption * findopt (); 230 | public struct loption * findopt_name (); 231 | public int iread (); 232 | public void intread (); 233 | public time_type get_time (); 234 | public char * errno_message (); 235 | public int percentage (); 236 | public POSITION percent_pos (); 237 | public int os9_signal (); 238 | public void put_line (); 239 | public void flush (); 240 | public int putchr (); 241 | public void putstr (); 242 | public void get_return (); 243 | public void error (); 244 | public void ierror (); 245 | public int query (); 246 | public int compile_pattern (); 247 | public void uncompile_pattern (); 248 | public int valid_pattern (); 249 | public int is_null_pattern (); 250 | public int match_pattern (); 251 | public POSITION position (); 252 | public void add_forw_pos (); 253 | public void add_back_pos (); 254 | public void pos_clear (); 255 | public void pos_init (); 256 | public int onscreen (); 257 | public int empty_screen (); 258 | public int empty_lines (); 259 | public void get_scrpos (); 260 | public int adjsline (); 261 | public void init_prompt (); 262 | public char * pr_expand (); 263 | public char * eq_message (); 264 | public char * pr_string (); 265 | public char * wait_message (); 266 | public void init_search (); 267 | public void repaint_hilite (); 268 | public void clear_attn (); 269 | public void undo_search (); 270 | public void clr_hlist (); 271 | public void clr_hilite (); 272 | public void clr_filter (); 273 | public int is_filtered (); 274 | public POSITION next_unfiltered (); 275 | public POSITION prev_unfiltered (); 276 | public int is_hilited (); 277 | public void chg_caseless (); 278 | public void chg_hilite (); 279 | public int search (); 280 | public void prep_hilite (); 281 | public void set_filter_pattern (); 282 | public int is_filtering (); 283 | public RETSIGTYPE winch (); 284 | public RETSIGTYPE winch (); 285 | public void init_signals (); 286 | public void psignals (); 287 | public void cleantags (); 288 | public int gettagtype (); 289 | public void findtag (); 290 | public POSITION tagsearch (); 291 | public char * nexttag (); 292 | public char * prevtag (); 293 | public int ntags (); 294 | public int curr_tag (); 295 | public int edit_tagfile (); 296 | public void open_getchr (); 297 | public void close_getchr (); 298 | public int getchr (); 299 | -------------------------------------------------------------------------------- /ifile.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * An IFILE represents an input file. 13 | * 14 | * It is actually a pointer to an ifile structure, 15 | * but is opaque outside this module. 16 | * Ifile structures are kept in a linked list in the order they 17 | * appear on the command line. 18 | * Any new file which does not already appear in the list is 19 | * inserted after the current file. 20 | */ 21 | 22 | #include "less.h" 23 | 24 | extern IFILE curr_ifile; 25 | 26 | struct ifile { 27 | struct ifile *h_next; /* Links for command line list */ 28 | struct ifile *h_prev; 29 | char *h_filename; /* Name of the file */ 30 | void *h_filestate; /* File state (used in ch.c) */ 31 | int h_index; /* Index within command line list */ 32 | int h_hold; /* Hold count */ 33 | char h_opened; /* Has this ifile been opened? */ 34 | struct scrpos h_scrpos; /* Saved position within the file */ 35 | }; 36 | 37 | /* 38 | * Convert an IFILE (external representation) 39 | * to a struct file (internal representation), and vice versa. 40 | */ 41 | #define int_ifile(h) ((struct ifile *)(h)) 42 | #define ext_ifile(h) ((IFILE)(h)) 43 | 44 | /* 45 | * Anchor for linked list. 46 | */ 47 | static struct ifile anchor = { &anchor, &anchor, NULL, NULL, 0, 0, '\0', 48 | { NULL_POSITION, 0 } }; 49 | static int ifiles = 0; 50 | 51 | static void 52 | incr_index(p, incr) 53 | register struct ifile *p; 54 | int incr; 55 | { 56 | for (; p != &anchor; p = p->h_next) 57 | p->h_index += incr; 58 | } 59 | 60 | /* 61 | * Link an ifile into the ifile list. 62 | */ 63 | static void 64 | link_ifile(p, prev) 65 | struct ifile *p; 66 | struct ifile *prev; 67 | { 68 | /* 69 | * Link into list. 70 | */ 71 | if (prev == NULL) 72 | prev = &anchor; 73 | p->h_next = prev->h_next; 74 | p->h_prev = prev; 75 | prev->h_next->h_prev = p; 76 | prev->h_next = p; 77 | /* 78 | * Calculate index for the new one, 79 | * and adjust the indexes for subsequent ifiles in the list. 80 | */ 81 | p->h_index = prev->h_index + 1; 82 | incr_index(p->h_next, 1); 83 | ifiles++; 84 | } 85 | 86 | /* 87 | * Unlink an ifile from the ifile list. 88 | */ 89 | static void 90 | unlink_ifile(p) 91 | struct ifile *p; 92 | { 93 | p->h_next->h_prev = p->h_prev; 94 | p->h_prev->h_next = p->h_next; 95 | incr_index(p->h_next, -1); 96 | ifiles--; 97 | } 98 | 99 | /* 100 | * Allocate a new ifile structure and stick a filename in it. 101 | * It should go after "prev" in the list 102 | * (or at the beginning of the list if "prev" is NULL). 103 | * Return a pointer to the new ifile structure. 104 | */ 105 | static struct ifile * 106 | new_ifile(filename, prev) 107 | char *filename; 108 | struct ifile *prev; 109 | { 110 | register struct ifile *p; 111 | 112 | /* 113 | * Allocate and initialize structure. 114 | */ 115 | p = (struct ifile *) ecalloc(1, sizeof(struct ifile)); 116 | p->h_filename = save(filename); 117 | p->h_scrpos.pos = NULL_POSITION; 118 | p->h_opened = 0; 119 | p->h_hold = 0; 120 | p->h_filestate = NULL; 121 | link_ifile(p, prev); 122 | return (p); 123 | } 124 | 125 | /* 126 | * Delete an existing ifile structure. 127 | */ 128 | public void 129 | del_ifile(h) 130 | IFILE h; 131 | { 132 | register struct ifile *p; 133 | 134 | if (h == NULL_IFILE) 135 | return; 136 | /* 137 | * If the ifile we're deleting is the currently open ifile, 138 | * move off it. 139 | */ 140 | unmark(h); 141 | if (h == curr_ifile) 142 | curr_ifile = getoff_ifile(curr_ifile); 143 | p = int_ifile(h); 144 | unlink_ifile(p); 145 | free(p->h_filename); 146 | free(p); 147 | } 148 | 149 | /* 150 | * Get the ifile after a given one in the list. 151 | */ 152 | public IFILE 153 | next_ifile(h) 154 | IFILE h; 155 | { 156 | register struct ifile *p; 157 | 158 | p = (h == NULL_IFILE) ? &anchor : int_ifile(h); 159 | if (p->h_next == &anchor) 160 | return (NULL_IFILE); 161 | return (ext_ifile(p->h_next)); 162 | } 163 | 164 | /* 165 | * Get the ifile before a given one in the list. 166 | */ 167 | public IFILE 168 | prev_ifile(h) 169 | IFILE h; 170 | { 171 | register struct ifile *p; 172 | 173 | p = (h == NULL_IFILE) ? &anchor : int_ifile(h); 174 | if (p->h_prev == &anchor) 175 | return (NULL_IFILE); 176 | return (ext_ifile(p->h_prev)); 177 | } 178 | 179 | /* 180 | * Return a different ifile from the given one. 181 | */ 182 | public IFILE 183 | getoff_ifile(ifile) 184 | IFILE ifile; 185 | { 186 | IFILE newifile; 187 | 188 | if ((newifile = prev_ifile(ifile)) != NULL_IFILE) 189 | return (newifile); 190 | if ((newifile = next_ifile(ifile)) != NULL_IFILE) 191 | return (newifile); 192 | return (NULL_IFILE); 193 | } 194 | 195 | /* 196 | * Return the number of ifiles. 197 | */ 198 | public int 199 | nifile() 200 | { 201 | return (ifiles); 202 | } 203 | 204 | /* 205 | * Find an ifile structure, given a filename. 206 | */ 207 | static struct ifile * 208 | find_ifile(filename) 209 | char *filename; 210 | { 211 | register struct ifile *p; 212 | 213 | for (p = anchor.h_next; p != &anchor; p = p->h_next) 214 | if (strcmp(filename, p->h_filename) == 0) 215 | return (p); 216 | return (NULL); 217 | } 218 | 219 | /* 220 | * Get the ifile associated with a filename. 221 | * If the filename has not been seen before, 222 | * insert the new ifile after "prev" in the list. 223 | */ 224 | public IFILE 225 | get_ifile(filename, prev) 226 | char *filename; 227 | IFILE prev; 228 | { 229 | register struct ifile *p; 230 | 231 | if ((p = find_ifile(filename)) == NULL) 232 | p = new_ifile(filename, int_ifile(prev)); 233 | return (ext_ifile(p)); 234 | } 235 | 236 | /* 237 | * Get the filename associated with a ifile. 238 | */ 239 | public char * 240 | get_filename(ifile) 241 | IFILE ifile; 242 | { 243 | if (ifile == NULL) 244 | return (NULL); 245 | return (int_ifile(ifile)->h_filename); 246 | } 247 | 248 | /* 249 | * Get the index of the file associated with a ifile. 250 | */ 251 | public int 252 | get_index(ifile) 253 | IFILE ifile; 254 | { 255 | return (int_ifile(ifile)->h_index); 256 | } 257 | 258 | /* 259 | * Save the file position to be associated with a given file. 260 | */ 261 | public void 262 | store_pos(ifile, scrpos) 263 | IFILE ifile; 264 | struct scrpos *scrpos; 265 | { 266 | int_ifile(ifile)->h_scrpos = *scrpos; 267 | } 268 | 269 | /* 270 | * Recall the file position associated with a file. 271 | * If no position has been associated with the file, return NULL_POSITION. 272 | */ 273 | public void 274 | get_pos(ifile, scrpos) 275 | IFILE ifile; 276 | struct scrpos *scrpos; 277 | { 278 | *scrpos = int_ifile(ifile)->h_scrpos; 279 | } 280 | 281 | /* 282 | * Mark the ifile as "opened". 283 | */ 284 | public void 285 | set_open(ifile) 286 | IFILE ifile; 287 | { 288 | int_ifile(ifile)->h_opened = 1; 289 | } 290 | 291 | /* 292 | * Return whether the ifile has been opened previously. 293 | */ 294 | public int 295 | opened(ifile) 296 | IFILE ifile; 297 | { 298 | return (int_ifile(ifile)->h_opened); 299 | } 300 | 301 | public void 302 | hold_ifile(ifile, incr) 303 | IFILE ifile; 304 | int incr; 305 | { 306 | int_ifile(ifile)->h_hold += incr; 307 | } 308 | 309 | public int 310 | held_ifile(ifile) 311 | IFILE ifile; 312 | { 313 | return (int_ifile(ifile)->h_hold); 314 | } 315 | 316 | public void * 317 | get_filestate(ifile) 318 | IFILE ifile; 319 | { 320 | return (int_ifile(ifile)->h_filestate); 321 | } 322 | 323 | public void 324 | set_filestate(ifile, filestate) 325 | IFILE ifile; 326 | void *filestate; 327 | { 328 | int_ifile(ifile)->h_filestate = filestate; 329 | } 330 | 331 | #if 0 332 | public void 333 | if_dump() 334 | { 335 | register struct ifile *p; 336 | 337 | for (p = anchor.h_next; p != &anchor; p = p->h_next) 338 | { 339 | printf("%x: %d. <%s> pos %d,%x\n", 340 | p, p->h_index, p->h_filename, 341 | p->h_scrpos.ln, p->h_scrpos.pos); 342 | ch_dump(p->h_filestate); 343 | } 344 | } 345 | #endif 346 | -------------------------------------------------------------------------------- /input.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * High level routines dealing with getting lines of input 13 | * from the file being viewed. 14 | * 15 | * When we speak of "lines" here, we mean PRINTABLE lines; 16 | * lines processed with respect to the screen width. 17 | * We use the term "raw line" to refer to lines simply 18 | * delimited by newlines; not processed with respect to screen width. 19 | */ 20 | 21 | #include "less.h" 22 | 23 | extern int squeeze; 24 | extern int chopline; 25 | extern int hshift; 26 | extern int quit_if_one_screen; 27 | extern int sigs; 28 | extern int ignore_eoi; 29 | extern int status_col; 30 | extern POSITION start_attnpos; 31 | extern POSITION end_attnpos; 32 | #if HILITE_SEARCH 33 | extern int hilite_search; 34 | extern int size_linebuf; 35 | #endif 36 | 37 | /* 38 | * Get the next line. 39 | * A "current" position is passed and a "new" position is returned. 40 | * The current position is the position of the first character of 41 | * a line. The new position is the position of the first character 42 | * of the NEXT line. The line obtained is the line starting at curr_pos. 43 | */ 44 | public POSITION 45 | forw_line(curr_pos) 46 | POSITION curr_pos; 47 | { 48 | POSITION base_pos; 49 | POSITION new_pos; 50 | register int c; 51 | int blankline; 52 | int endline; 53 | int backchars; 54 | 55 | get_forw_line: 56 | if (curr_pos == NULL_POSITION) 57 | { 58 | null_line(); 59 | return (NULL_POSITION); 60 | } 61 | #if HILITE_SEARCH 62 | if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) 63 | { 64 | /* 65 | * If we are ignoring EOI (command F), only prepare 66 | * one line ahead, to avoid getting stuck waiting for 67 | * slow data without displaying the data we already have. 68 | * If we're not ignoring EOI, we *could* do the same, but 69 | * for efficiency we prepare several lines ahead at once. 70 | */ 71 | prep_hilite(curr_pos, curr_pos + 3*size_linebuf, 72 | ignore_eoi ? 1 : -1); 73 | curr_pos = next_unfiltered(curr_pos); 74 | } 75 | #endif 76 | if (ch_seek(curr_pos)) 77 | { 78 | null_line(); 79 | return (NULL_POSITION); 80 | } 81 | 82 | /* 83 | * Step back to the beginning of the line. 84 | */ 85 | base_pos = curr_pos; 86 | for (;;) 87 | { 88 | if (ABORT_SIGS()) 89 | { 90 | null_line(); 91 | return (NULL_POSITION); 92 | } 93 | c = ch_back_get(); 94 | if (c == EOI) 95 | break; 96 | if (c == '\n') 97 | { 98 | (void) ch_forw_get(); 99 | break; 100 | } 101 | --base_pos; 102 | } 103 | 104 | /* 105 | * Read forward again to the position we should start at. 106 | */ 107 | prewind(); 108 | plinenum(base_pos); 109 | (void) ch_seek(base_pos); 110 | new_pos = base_pos; 111 | while (new_pos < curr_pos) 112 | { 113 | if (ABORT_SIGS()) 114 | { 115 | null_line(); 116 | return (NULL_POSITION); 117 | } 118 | c = ch_forw_get(); 119 | backchars = pappend(c, new_pos); 120 | new_pos++; 121 | if (backchars > 0) 122 | { 123 | pshift_all(); 124 | new_pos -= backchars; 125 | while (--backchars >= 0) 126 | (void) ch_back_get(); 127 | } 128 | } 129 | (void) pflushmbc(); 130 | pshift_all(); 131 | 132 | /* 133 | * Read the first character to display. 134 | */ 135 | c = ch_forw_get(); 136 | if (c == EOI) 137 | { 138 | null_line(); 139 | return (NULL_POSITION); 140 | } 141 | blankline = (c == '\n' || c == '\r'); 142 | 143 | /* 144 | * Read each character in the line and append to the line buffer. 145 | */ 146 | for (;;) 147 | { 148 | if (ABORT_SIGS()) 149 | { 150 | null_line(); 151 | return (NULL_POSITION); 152 | } 153 | if (c == '\n' || c == EOI) 154 | { 155 | /* 156 | * End of the line. 157 | */ 158 | backchars = pflushmbc(); 159 | new_pos = ch_tell(); 160 | if (backchars > 0 && !chopline && hshift == 0) 161 | { 162 | new_pos -= backchars + 1; 163 | endline = FALSE; 164 | } else 165 | endline = TRUE; 166 | break; 167 | } 168 | if (c != '\r') 169 | blankline = 0; 170 | 171 | /* 172 | * Append the char to the line and get the next char. 173 | */ 174 | backchars = pappend(c, ch_tell()-1); 175 | if (backchars > 0) 176 | { 177 | /* 178 | * The char won't fit in the line; the line 179 | * is too long to print in the screen width. 180 | * End the line here. 181 | */ 182 | if (chopline || hshift > 0) 183 | { 184 | do 185 | { 186 | if (ABORT_SIGS()) 187 | { 188 | null_line(); 189 | return (NULL_POSITION); 190 | } 191 | c = ch_forw_get(); 192 | } while (c != '\n' && c != EOI); 193 | new_pos = ch_tell(); 194 | endline = TRUE; 195 | quit_if_one_screen = FALSE; 196 | } else 197 | { 198 | new_pos = ch_tell() - backchars; 199 | endline = FALSE; 200 | } 201 | break; 202 | } 203 | c = ch_forw_get(); 204 | } 205 | 206 | pdone(endline, 1); 207 | 208 | #if HILITE_SEARCH 209 | if (is_filtered(base_pos)) 210 | { 211 | /* 212 | * We don't want to display this line. 213 | * Get the next line. 214 | */ 215 | curr_pos = new_pos; 216 | goto get_forw_line; 217 | } 218 | 219 | if (status_col && is_hilited(base_pos, ch_tell()-1, 1, NULL)) 220 | set_status_col('*'); 221 | #endif 222 | 223 | if (squeeze && blankline) 224 | { 225 | /* 226 | * This line is blank. 227 | * Skip down to the last contiguous blank line 228 | * and pretend it is the one which we are returning. 229 | */ 230 | while ((c = ch_forw_get()) == '\n' || c == '\r') 231 | if (ABORT_SIGS()) 232 | { 233 | null_line(); 234 | return (NULL_POSITION); 235 | } 236 | if (c != EOI) 237 | (void) ch_back_get(); 238 | new_pos = ch_tell(); 239 | } 240 | 241 | return (new_pos); 242 | } 243 | 244 | /* 245 | * Get the previous line. 246 | * A "current" position is passed and a "new" position is returned. 247 | * The current position is the position of the first character of 248 | * a line. The new position is the position of the first character 249 | * of the PREVIOUS line. The line obtained is the one starting at new_pos. 250 | */ 251 | public POSITION 252 | back_line(curr_pos) 253 | POSITION curr_pos; 254 | { 255 | POSITION new_pos, begin_new_pos, base_pos; 256 | int c; 257 | int endline; 258 | int backchars; 259 | 260 | get_back_line: 261 | if (curr_pos == NULL_POSITION || curr_pos <= ch_zero()) 262 | { 263 | null_line(); 264 | return (NULL_POSITION); 265 | } 266 | #if HILITE_SEARCH 267 | if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) 268 | prep_hilite((curr_pos < 3*size_linebuf) ? 269 | 0 : curr_pos - 3*size_linebuf, curr_pos, -1); 270 | #endif 271 | if (ch_seek(curr_pos-1)) 272 | { 273 | null_line(); 274 | return (NULL_POSITION); 275 | } 276 | 277 | if (squeeze) 278 | { 279 | /* 280 | * Find out if the "current" line was blank. 281 | */ 282 | (void) ch_forw_get(); /* Skip the newline */ 283 | c = ch_forw_get(); /* First char of "current" line */ 284 | (void) ch_back_get(); /* Restore our position */ 285 | (void) ch_back_get(); 286 | 287 | if (c == '\n' || c == '\r') 288 | { 289 | /* 290 | * The "current" line was blank. 291 | * Skip over any preceding blank lines, 292 | * since we skipped them in forw_line(). 293 | */ 294 | while ((c = ch_back_get()) == '\n' || c == '\r') 295 | if (ABORT_SIGS()) 296 | { 297 | null_line(); 298 | return (NULL_POSITION); 299 | } 300 | if (c == EOI) 301 | { 302 | null_line(); 303 | return (NULL_POSITION); 304 | } 305 | (void) ch_forw_get(); 306 | } 307 | } 308 | 309 | /* 310 | * Scan backwards until we hit the beginning of the line. 311 | */ 312 | for (;;) 313 | { 314 | if (ABORT_SIGS()) 315 | { 316 | null_line(); 317 | return (NULL_POSITION); 318 | } 319 | c = ch_back_get(); 320 | if (c == '\n') 321 | { 322 | /* 323 | * This is the newline ending the previous line. 324 | * We have hit the beginning of the line. 325 | */ 326 | base_pos = ch_tell() + 1; 327 | break; 328 | } 329 | if (c == EOI) 330 | { 331 | /* 332 | * We have hit the beginning of the file. 333 | * This must be the first line in the file. 334 | * This must, of course, be the beginning of the line. 335 | */ 336 | base_pos = ch_tell(); 337 | break; 338 | } 339 | } 340 | 341 | /* 342 | * Now scan forwards from the beginning of this line. 343 | * We keep discarding "printable lines" (based on screen width) 344 | * until we reach the curr_pos. 345 | * 346 | * {{ This algorithm is pretty inefficient if the lines 347 | * are much longer than the screen width, 348 | * but I don't know of any better way. }} 349 | */ 350 | new_pos = base_pos; 351 | if (ch_seek(new_pos)) 352 | { 353 | null_line(); 354 | return (NULL_POSITION); 355 | } 356 | endline = FALSE; 357 | prewind(); 358 | plinenum(new_pos); 359 | loop: 360 | begin_new_pos = new_pos; 361 | (void) ch_seek(new_pos); 362 | 363 | do 364 | { 365 | c = ch_forw_get(); 366 | if (c == EOI || ABORT_SIGS()) 367 | { 368 | null_line(); 369 | return (NULL_POSITION); 370 | } 371 | new_pos++; 372 | if (c == '\n') 373 | { 374 | backchars = pflushmbc(); 375 | if (backchars > 0 && !chopline && hshift == 0) 376 | { 377 | backchars++; 378 | goto shift; 379 | } 380 | endline = TRUE; 381 | break; 382 | } 383 | backchars = pappend(c, ch_tell()-1); 384 | if (backchars > 0) 385 | { 386 | /* 387 | * Got a full printable line, but we haven't 388 | * reached our curr_pos yet. Discard the line 389 | * and start a new one. 390 | */ 391 | if (chopline || hshift > 0) 392 | { 393 | endline = TRUE; 394 | quit_if_one_screen = FALSE; 395 | break; 396 | } 397 | shift: 398 | pshift_all(); 399 | while (backchars-- > 0) 400 | { 401 | (void) ch_back_get(); 402 | new_pos--; 403 | } 404 | goto loop; 405 | } 406 | } while (new_pos < curr_pos); 407 | 408 | pdone(endline, 0); 409 | 410 | #if HILITE_SEARCH 411 | if (is_filtered(base_pos)) 412 | { 413 | /* 414 | * We don't want to display this line. 415 | * Get the previous line. 416 | */ 417 | curr_pos = begin_new_pos; 418 | goto get_back_line; 419 | } 420 | 421 | if (status_col && curr_pos > 0 && is_hilited(base_pos, curr_pos-1, 1, NULL)) 422 | set_status_col('*'); 423 | #endif 424 | 425 | return (begin_new_pos); 426 | } 427 | 428 | /* 429 | * Set attnpos. 430 | */ 431 | public void 432 | set_attnpos(pos) 433 | POSITION pos; 434 | { 435 | int c; 436 | 437 | if (pos != NULL_POSITION) 438 | { 439 | if (ch_seek(pos)) 440 | return; 441 | for (;;) 442 | { 443 | c = ch_forw_get(); 444 | if (c == EOI) 445 | break; 446 | if (c == '\n' || c == '\r') 447 | { 448 | (void) ch_back_get(); 449 | break; 450 | } 451 | pos++; 452 | } 453 | end_attnpos = pos; 454 | for (;;) 455 | { 456 | c = ch_back_get(); 457 | if (c == EOI || c == '\n' || c == '\r') 458 | break; 459 | pos--; 460 | } 461 | } 462 | start_attnpos = pos; 463 | } 464 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # install - install a program, script, or datafile 5 | # This comes from X11R5; it is not part of GNU. 6 | # 7 | # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $ 8 | # 9 | # This script is compatible with the BSD install script, but was written 10 | # from scratch. 11 | # 12 | 13 | 14 | # set DOITPROG to echo to test this script 15 | 16 | # Don't use :- since 4.3BSD and earlier shells don't like it. 17 | doit="${DOITPROG-}" 18 | 19 | 20 | # put in absolute paths if you don't have them in your path; or use env. vars. 21 | 22 | mvprog="${MVPROG-mv}" 23 | cpprog="${CPPROG-cp}" 24 | chmodprog="${CHMODPROG-chmod}" 25 | chownprog="${CHOWNPROG-chown}" 26 | chgrpprog="${CHGRPPROG-chgrp}" 27 | stripprog="${STRIPPROG-strip}" 28 | rmprog="${RMPROG-rm}" 29 | 30 | instcmd="$mvprog" 31 | chmodcmd="" 32 | chowncmd="" 33 | chgrpcmd="" 34 | stripcmd="" 35 | rmcmd="$rmprog -f" 36 | mvcmd="$mvprog" 37 | src="" 38 | dst="" 39 | 40 | while [ x"$1" != x ]; do 41 | case $1 in 42 | -c) instcmd="$cpprog" 43 | shift 44 | continue;; 45 | 46 | -m) chmodcmd="$chmodprog $2" 47 | shift 48 | shift 49 | continue;; 50 | 51 | -o) chowncmd="$chownprog $2" 52 | shift 53 | shift 54 | continue;; 55 | 56 | -g) chgrpcmd="$chgrpprog $2" 57 | shift 58 | shift 59 | continue;; 60 | 61 | -s) stripcmd="$stripprog" 62 | shift 63 | continue;; 64 | 65 | *) if [ x"$src" = x ] 66 | then 67 | src=$1 68 | else 69 | dst=$1 70 | fi 71 | shift 72 | continue;; 73 | esac 74 | done 75 | 76 | if [ x"$src" = x ] 77 | then 78 | echo "install: no input file specified" 79 | exit 1 80 | fi 81 | 82 | if [ x"$dst" = x ] 83 | then 84 | echo "install: no destination specified" 85 | exit 1 86 | fi 87 | 88 | 89 | # If destination is a directory, append the input filename; if your system 90 | # does not like double slashes in filenames, you may need to add some logic 91 | 92 | if [ -d $dst ] 93 | then 94 | dst="$dst"/`basename $src` 95 | fi 96 | 97 | # Make a temp file name in the proper directory. 98 | 99 | dstdir=`dirname $dst` 100 | dsttmp=$dstdir/_inst.$$_ 101 | 102 | # Move or copy the file name to the temp name 103 | 104 | $doit $instcmd $src $dsttmp 105 | 106 | # and set any options; do chmod last to preserve setuid bits 107 | 108 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi 109 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi 110 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi 111 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi 112 | 113 | # Now rename the file to the real destination. 114 | 115 | $doit $rmcmd $dst 116 | $doit $mvcmd $dsttmp $dst 117 | 118 | 119 | exit 0 120 | -------------------------------------------------------------------------------- /jump.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Routines which jump to a new location in the file. 13 | */ 14 | 15 | #include "less.h" 16 | #include "position.h" 17 | 18 | extern int jump_sline; 19 | extern int squished; 20 | extern int screen_trashed; 21 | extern int sc_width, sc_height; 22 | extern int show_attn; 23 | extern int top_scroll; 24 | 25 | /* 26 | * Jump to the end of the file. 27 | */ 28 | public void 29 | jump_forw() 30 | { 31 | POSITION pos; 32 | POSITION end_pos; 33 | 34 | if (ch_end_seek()) 35 | { 36 | error("Cannot seek to end of file", NULL_PARG); 37 | return; 38 | } 39 | /* 40 | * Note; lastmark will be called later by jump_loc, but it fails 41 | * because the position table has been cleared by pos_clear below. 42 | * So call it here before calling pos_clear. 43 | */ 44 | lastmark(); 45 | /* 46 | * Position the last line in the file at the last screen line. 47 | * Go back one line from the end of the file 48 | * to get to the beginning of the last line. 49 | */ 50 | pos_clear(); 51 | end_pos = ch_tell(); 52 | pos = back_line(end_pos); 53 | if (pos == NULL_POSITION) 54 | jump_loc((POSITION)0, sc_height-1); 55 | else 56 | { 57 | jump_loc(pos, sc_height-1); 58 | if (position(sc_height-1) != end_pos) 59 | repaint(); 60 | } 61 | } 62 | 63 | /* 64 | * Jump to the last buffered line in the file. 65 | */ 66 | public void 67 | jump_forw_buffered() 68 | { 69 | POSITION end; 70 | 71 | if (ch_end_buffer_seek()) 72 | { 73 | error("Cannot seek to end of buffers", NULL_PARG); 74 | return; 75 | } 76 | end = ch_tell(); 77 | if (end != NULL_POSITION && end > 0) 78 | jump_line_loc(end-1, sc_height-1); 79 | } 80 | 81 | /* 82 | * Jump to line n in the file. 83 | */ 84 | public void 85 | jump_back(linenum) 86 | LINENUM linenum; 87 | { 88 | POSITION pos; 89 | PARG parg; 90 | 91 | /* 92 | * Find the position of the specified line. 93 | * If we can seek there, just jump to it. 94 | * If we can't seek, but we're trying to go to line number 1, 95 | * use ch_beg_seek() to get as close as we can. 96 | */ 97 | pos = find_pos(linenum); 98 | if (pos != NULL_POSITION && ch_seek(pos) == 0) 99 | { 100 | if (show_attn) 101 | set_attnpos(pos); 102 | jump_loc(pos, jump_sline); 103 | } else if (linenum <= 1 && ch_beg_seek() == 0) 104 | { 105 | jump_loc(ch_tell(), jump_sline); 106 | error("Cannot seek to beginning of file", NULL_PARG); 107 | } else 108 | { 109 | parg.p_linenum = linenum; 110 | error("Cannot seek to line number %n", &parg); 111 | } 112 | } 113 | 114 | /* 115 | * Repaint the screen. 116 | */ 117 | public void 118 | repaint() 119 | { 120 | struct scrpos scrpos; 121 | /* 122 | * Start at the line currently at the top of the screen 123 | * and redisplay the screen. 124 | */ 125 | get_scrpos(&scrpos); 126 | pos_clear(); 127 | jump_loc(scrpos.pos, scrpos.ln); 128 | } 129 | 130 | /* 131 | * Jump to a specified percentage into the file. 132 | */ 133 | public void 134 | jump_percent(percent, fraction) 135 | int percent; 136 | long fraction; 137 | { 138 | POSITION pos, len; 139 | 140 | /* 141 | * Determine the position in the file 142 | * (the specified percentage of the file's length). 143 | */ 144 | if ((len = ch_length()) == NULL_POSITION) 145 | { 146 | ierror("Determining length of file", NULL_PARG); 147 | ch_end_seek(); 148 | } 149 | if ((len = ch_length()) == NULL_POSITION) 150 | { 151 | error("Don't know length of file", NULL_PARG); 152 | return; 153 | } 154 | pos = percent_pos(len, percent, fraction); 155 | if (pos >= len) 156 | pos = len-1; 157 | 158 | jump_line_loc(pos, jump_sline); 159 | } 160 | 161 | /* 162 | * Jump to a specified position in the file. 163 | * Like jump_loc, but the position need not be 164 | * the first character in a line. 165 | */ 166 | public void 167 | jump_line_loc(pos, sline) 168 | POSITION pos; 169 | int sline; 170 | { 171 | int c; 172 | 173 | if (ch_seek(pos) == 0) 174 | { 175 | /* 176 | * Back up to the beginning of the line. 177 | */ 178 | while ((c = ch_back_get()) != '\n' && c != EOI) 179 | ; 180 | if (c == '\n') 181 | (void) ch_forw_get(); 182 | pos = ch_tell(); 183 | } 184 | if (show_attn) 185 | set_attnpos(pos); 186 | jump_loc(pos, sline); 187 | } 188 | 189 | /* 190 | * Jump to a specified position in the file. 191 | * The position must be the first character in a line. 192 | * Place the target line on a specified line on the screen. 193 | */ 194 | public void 195 | jump_loc(pos, sline) 196 | POSITION pos; 197 | int sline; 198 | { 199 | register int nline; 200 | POSITION tpos; 201 | POSITION bpos; 202 | 203 | /* 204 | * Normalize sline. 205 | */ 206 | sline = adjsline(sline); 207 | 208 | if ((nline = onscreen(pos)) >= 0) 209 | { 210 | /* 211 | * The line is currently displayed. 212 | * Just scroll there. 213 | */ 214 | nline -= sline; 215 | if (nline > 0) 216 | forw(nline, position(BOTTOM_PLUS_ONE), 1, 0, 0); 217 | else 218 | back(-nline, position(TOP), 1, 0); 219 | #if HILITE_SEARCH 220 | if (show_attn) 221 | repaint_hilite(1); 222 | #endif 223 | return; 224 | } 225 | 226 | /* 227 | * Line is not on screen. 228 | * Seek to the desired location. 229 | */ 230 | if (ch_seek(pos)) 231 | { 232 | error("Cannot seek to that file position", NULL_PARG); 233 | return; 234 | } 235 | 236 | /* 237 | * See if the desired line is before or after 238 | * the currently displayed screen. 239 | */ 240 | tpos = position(TOP); 241 | bpos = position(BOTTOM_PLUS_ONE); 242 | if (tpos == NULL_POSITION || pos >= tpos) 243 | { 244 | /* 245 | * The desired line is after the current screen. 246 | * Move back in the file far enough so that we can 247 | * call forw() and put the desired line at the 248 | * sline-th line on the screen. 249 | */ 250 | for (nline = 0; nline < sline; nline++) 251 | { 252 | if (bpos != NULL_POSITION && pos <= bpos) 253 | { 254 | /* 255 | * Surprise! The desired line is 256 | * close enough to the current screen 257 | * that we can just scroll there after all. 258 | */ 259 | forw(sc_height-sline+nline-1, bpos, 1, 0, 0); 260 | #if HILITE_SEARCH 261 | if (show_attn) 262 | repaint_hilite(1); 263 | #endif 264 | return; 265 | } 266 | pos = back_line(pos); 267 | if (pos == NULL_POSITION) 268 | { 269 | /* 270 | * Oops. Ran into the beginning of the file. 271 | * Exit the loop here and rely on forw() 272 | * below to draw the required number of 273 | * blank lines at the top of the screen. 274 | */ 275 | break; 276 | } 277 | } 278 | lastmark(); 279 | squished = 0; 280 | screen_trashed = 0; 281 | forw(sc_height-1, pos, 1, 0, sline-nline); 282 | } else 283 | { 284 | /* 285 | * The desired line is before the current screen. 286 | * Move forward in the file far enough so that we 287 | * can call back() and put the desired line at the 288 | * sline-th line on the screen. 289 | */ 290 | for (nline = sline; nline < sc_height - 1; nline++) 291 | { 292 | pos = forw_line(pos); 293 | if (pos == NULL_POSITION) 294 | { 295 | /* 296 | * Ran into end of file. 297 | * This shouldn't normally happen, 298 | * but may if there is some kind of read error. 299 | */ 300 | break; 301 | } 302 | #if HILITE_SEARCH 303 | pos = next_unfiltered(pos); 304 | #endif 305 | if (pos >= tpos) 306 | { 307 | /* 308 | * Surprise! The desired line is 309 | * close enough to the current screen 310 | * that we can just scroll there after all. 311 | */ 312 | back(nline+1, tpos, 1, 0); 313 | #if HILITE_SEARCH 314 | if (show_attn) 315 | repaint_hilite(1); 316 | #endif 317 | return; 318 | } 319 | } 320 | lastmark(); 321 | if (!top_scroll) 322 | clear(); 323 | else 324 | home(); 325 | screen_trashed = 0; 326 | add_back_pos(pos); 327 | back(sc_height-1, pos, 1, 0); 328 | } 329 | } 330 | -------------------------------------------------------------------------------- /lessecho.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * lessecho [-ox] [-cx] [-pn] [-dn] [-a] file ... 13 | * Simply echos its filename arguments on standard output. 14 | * But any argument containing spaces is enclosed in quotes. 15 | * 16 | * -ox Specifies "x" to be the open quote character. 17 | * -cx Specifies "x" to be the close quote character. 18 | * -pn Specifies "n" to be the open quote character, as an integer. 19 | * -dn Specifies "n" to be the close quote character, as an integer. 20 | * -mx Specifies "x" to be a metachar. 21 | * -nn Specifies "n" to be a metachar, as an integer. 22 | * -ex Specifies "x" to be the escape char for metachars. 23 | * -fn Specifies "x" to be the escape char for metachars, as an integer. 24 | * -a Specifies that all arguments are to be quoted. 25 | * The default is that only arguments containing spaces are quoted. 26 | */ 27 | 28 | #include "less.h" 29 | 30 | static char *version = "$Revision: 1.15 $"; 31 | 32 | static int quote_all = 0; 33 | static char openquote = '"'; 34 | static char closequote = '"'; 35 | static char *meta_escape = "\\"; 36 | static char meta_escape_buf[2]; 37 | static char metachars[64] = ""; 38 | static int num_metachars = 0; 39 | 40 | static void 41 | pr_usage() 42 | { 43 | fprintf(stderr, 44 | "usage: lessecho [-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-fn] [-a] file ...\n"); 45 | } 46 | 47 | static void 48 | pr_version() 49 | { 50 | char *p; 51 | char buf[10]; 52 | char *pbuf = buf; 53 | 54 | for (p = version; *p != ' '; p++) 55 | if (*p == '\0') 56 | return; 57 | for (p++; *p != '$' && *p != ' ' && *p != '\0'; p++) 58 | *pbuf++ = *p; 59 | *pbuf = '\0'; 60 | printf("%s\n", buf); 61 | } 62 | 63 | static void 64 | pr_error(s) 65 | char *s; 66 | { 67 | fprintf(stderr, "%s\n", s); 68 | exit(1); 69 | } 70 | 71 | static long 72 | lstrtol(s, radix, pend) 73 | char *s; 74 | int radix; 75 | char **pend; 76 | { 77 | int v; 78 | int neg = 0; 79 | long n = 0; 80 | 81 | /* Skip leading white space. */ 82 | while (*s == ' ' || *s == '\t') 83 | s++; 84 | 85 | /* Check for a leading + or -. */ 86 | if (*s == '-') 87 | { 88 | neg = 1; 89 | s++; 90 | } else if (*s == '+') 91 | { 92 | s++; 93 | } 94 | 95 | /* Determine radix if caller does not specify. */ 96 | if (radix == 0) 97 | { 98 | radix = 10; 99 | if (*s == '0') 100 | { 101 | switch (*++s) 102 | { 103 | case 'x': 104 | radix = 16; 105 | s++; 106 | break; 107 | default: 108 | radix = 8; 109 | break; 110 | } 111 | } 112 | } 113 | 114 | /* Parse the digits of the number. */ 115 | for (;;) 116 | { 117 | if (*s >= '0' && *s <= '9') 118 | v = *s - '0'; 119 | else if (*s >= 'a' && *s <= 'f') 120 | v = *s - 'a' + 10; 121 | else if (*s >= 'A' && *s <= 'F') 122 | v = *s - 'A' + 10; 123 | else 124 | break; 125 | if (v >= radix) 126 | break; 127 | n = n * radix + v; 128 | s++; 129 | } 130 | 131 | if (pend != NULL) 132 | { 133 | /* Skip trailing white space. */ 134 | while (*s == ' ' || *s == '\t') 135 | s++; 136 | *pend = s; 137 | } 138 | if (neg) 139 | return (-n); 140 | return (n); 141 | } 142 | 143 | 144 | #if !HAVE_STRCHR 145 | char * 146 | strchr(s, c) 147 | char *s; 148 | int c; 149 | { 150 | for ( ; *s != '\0'; s++) 151 | if (*s == c) 152 | return (s); 153 | if (c == '\0') 154 | return (s); 155 | return (NULL); 156 | } 157 | #endif 158 | 159 | int 160 | main(argc, argv) 161 | int argc; 162 | char *argv[]; 163 | { 164 | char *arg; 165 | char *s; 166 | int no_more_options; 167 | 168 | no_more_options = 0; 169 | while (--argc > 0) 170 | { 171 | arg = *++argv; 172 | if (*arg != '-' || no_more_options) 173 | break; 174 | switch (*++arg) 175 | { 176 | case 'a': 177 | quote_all = 1; 178 | break; 179 | case 'c': 180 | closequote = *++arg; 181 | break; 182 | case 'd': 183 | closequote = lstrtol(++arg, 0, &s); 184 | if (s == arg) 185 | pr_error("Missing number after -d"); 186 | break; 187 | case 'e': 188 | if (strcmp(++arg, "-") == 0) 189 | meta_escape = ""; 190 | else 191 | meta_escape = arg; 192 | break; 193 | case 'f': 194 | meta_escape_buf[0] = lstrtol(++arg, 0, &s); 195 | meta_escape = meta_escape_buf; 196 | if (s == arg) 197 | pr_error("Missing number after -f"); 198 | break; 199 | case 'o': 200 | openquote = *++arg; 201 | break; 202 | case 'p': 203 | openquote = lstrtol(++arg, 0, &s); 204 | if (s == arg) 205 | pr_error("Missing number after -p"); 206 | break; 207 | case 'm': 208 | metachars[num_metachars++] = *++arg; 209 | metachars[num_metachars] = '\0'; 210 | break; 211 | case 'n': 212 | metachars[num_metachars++] = lstrtol(++arg, 0, &s); 213 | if (s == arg) 214 | pr_error("Missing number after -n"); 215 | metachars[num_metachars] = '\0'; 216 | break; 217 | case '?': 218 | pr_usage(); 219 | return (0); 220 | case '-': 221 | if (*++arg == '\0') 222 | { 223 | no_more_options = 1; 224 | break; 225 | } 226 | if (strcmp(arg, "version") == 0) 227 | { 228 | pr_version(); 229 | return (0); 230 | } 231 | if (strcmp(arg, "help") == 0) 232 | { 233 | pr_usage(); 234 | return (0); 235 | } 236 | pr_error("Invalid option after --"); 237 | default: 238 | pr_error("Invalid option letter"); 239 | } 240 | } 241 | 242 | while (argc-- > 0) 243 | { 244 | int has_meta = 0; 245 | arg = *argv++; 246 | for (s = arg; *s != '\0'; s++) 247 | { 248 | if (strchr(metachars, *s) != NULL) 249 | { 250 | has_meta = 1; 251 | break; 252 | } 253 | } 254 | if (quote_all || (has_meta && strlen(meta_escape) == 0)) 255 | printf("%c%s%c", openquote, arg, closequote); 256 | else 257 | { 258 | for (s = arg; *s != '\0'; s++) 259 | { 260 | if (strchr(metachars, *s) != NULL) 261 | printf("%s", meta_escape); 262 | printf("%c", *s); 263 | } 264 | } 265 | if (argc > 0) 266 | printf(" "); 267 | else 268 | printf("\n"); 269 | } 270 | return (0); 271 | } 272 | -------------------------------------------------------------------------------- /lessecho.man: -------------------------------------------------------------------------------- 1 | LESSECHO(1) General Commands Manual LESSECHO(1) 2 | 3 | 4 | 5 | NAME 6 | lessecho - expand metacharacters 7 | 8 | SYNOPSIS 9 | lessecho [-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-a] file ... 10 | 11 | DESCRIPTION 12 | lessecho is a program that simply echos its arguments on standard out- 13 | put. But any metacharacter in the output is preceded by an "escape" 14 | character, which by default is a backslash. 15 | 16 | OPTIONS 17 | A summary of options is included below. 18 | 19 | -ex Specifies "x", rather than backslash, to be the escape char for 20 | metachars. If x is "-", no escape char is used and arguments 21 | containing metachars are surrounded by quotes instead. 22 | 23 | -ox Specifies "x", rather than double-quote, to be the open quote 24 | character, which is used if the -e- option is specified. 25 | 26 | -cx Specifies "x" to be the close quote character. 27 | 28 | -pn Specifies "n" to be the open quote character, as an integer. 29 | 30 | -dn Specifies "n" to be the close quote character, as an integer. 31 | 32 | -mx Specifies "x" to be a metachar. By default, no characters are 33 | considered metachars. 34 | 35 | -nn Specifies "n" to be a metachar, as an integer. 36 | 37 | -fn Specifies "n" to be the escape char for metachars, as an inte- 38 | ger. 39 | 40 | -a Specifies that all arguments are to be quoted. The default is 41 | that only arguments containing metacharacters are quoted 42 | 43 | SEE ALSO 44 | less(1) 45 | 46 | AUTHOR 47 | This manual page was written by Thomas Schoepf , 48 | for the Debian GNU/Linux system (but may be used by others). 49 | 50 | Send bug reports or comments to bug-less@gnu.org. 51 | 52 | 53 | 54 | Version 481: 31 Aug 2015 LESSECHO(1) 55 | -------------------------------------------------------------------------------- /lessecho.nro: -------------------------------------------------------------------------------- 1 | .TH LESSECHO 1 "Version 481: 31 Aug 2015" 2 | .SH NAME 3 | lessecho \- expand metacharacters 4 | .SH SYNOPSIS 5 | .B lessecho 6 | .I "[-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-a] file ..." 7 | .SH "DESCRIPTION" 8 | .I lessecho 9 | is a program that simply echos its arguments on standard output. 10 | But any metacharacter in the output is preceded by an "escape" 11 | character, which by default is a backslash. 12 | .SH OPTIONS 13 | A summary of options is included below. 14 | .TP 15 | .B \-ex 16 | Specifies "x", rather than backslash, to be the escape char for metachars. 17 | If x is "-", no escape char is used and arguments containing metachars 18 | are surrounded by quotes instead. 19 | .TP 20 | .B \-ox 21 | Specifies "x", rather than double-quote, to be the open quote character, 22 | which is used if the -e- option is specified. 23 | .TP 24 | .B \-cx 25 | Specifies "x" to be the close quote character. 26 | .TP 27 | .B \-pn 28 | Specifies "n" to be the open quote character, as an integer. 29 | .TP 30 | .B \-dn 31 | Specifies "n" to be the close quote character, as an integer. 32 | .TP 33 | .B \-mx 34 | Specifies "x" to be a metachar. 35 | By default, no characters are considered metachars. 36 | .TP 37 | .B \-nn 38 | Specifies "n" to be a metachar, as an integer. 39 | .TP 40 | .B \-fn 41 | Specifies "n" to be the escape char for metachars, as an integer. 42 | .TP 43 | .B \-a 44 | Specifies that all arguments are to be quoted. 45 | The default is that only arguments containing metacharacters are quoted 46 | .SH "SEE ALSO" 47 | less(1) 48 | .SH AUTHOR 49 | This manual page was written by Thomas Schoepf , 50 | for the Debian GNU/Linux system (but may be used by others). 51 | .PP 52 | Send bug reports or comments to bug-less@gnu.org. 53 | -------------------------------------------------------------------------------- /lesskey.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Format of a lesskey file: 13 | * 14 | * LESSKEY_MAGIC (4 bytes) 15 | * sections... 16 | * END_LESSKEY_MAGIC (4 bytes) 17 | * 18 | * Each section is: 19 | * 20 | * section_MAGIC (1 byte) 21 | * section_length (2 bytes) 22 | * key table (section_length bytes) 23 | */ 24 | #define C0_LESSKEY_MAGIC '\0' 25 | #define C1_LESSKEY_MAGIC 'M' 26 | #define C2_LESSKEY_MAGIC '+' 27 | #define C3_LESSKEY_MAGIC 'G' 28 | 29 | #define CMD_SECTION 'c' 30 | #define EDIT_SECTION 'e' 31 | #define VAR_SECTION 'v' 32 | #define END_SECTION 'x' 33 | 34 | #define C0_END_LESSKEY_MAGIC 'E' 35 | #define C1_END_LESSKEY_MAGIC 'n' 36 | #define C2_END_LESSKEY_MAGIC 'd' 37 | 38 | /* */ 39 | #define KRADIX 64 40 | -------------------------------------------------------------------------------- /lglob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Macros to define the method of doing filename "globbing". 13 | * There are three possible mechanisms: 14 | * 1. GLOB_LIST 15 | * This defines a function that returns a list of matching filenames. 16 | * 2. GLOB_NAME 17 | * This defines a function that steps thru the list of matching 18 | * filenames, returning one name each time it is called. 19 | * 3. GLOB_STRING 20 | * This defines a function that returns the complete list of 21 | * matching filenames as a single space-separated string. 22 | */ 23 | 24 | #if OS2 25 | 26 | #define DECL_GLOB_LIST(list) char **list; char **pp; 27 | #define GLOB_LIST(filename,list) list = _fnexplode(filename) 28 | #define GLOB_LIST_FAILED(list) list == NULL 29 | #define SCAN_GLOB_LIST(list,p) pp = list; *pp != NULL; pp++ 30 | #define INIT_GLOB_LIST(list,p) p = *pp 31 | #define GLOB_LIST_DONE(list) _fnexplodefree(list) 32 | 33 | #else 34 | #if MSDOS_COMPILER==DJGPPC 35 | 36 | #define DECL_GLOB_LIST(list) glob_t list; int i; 37 | #define GLOB_LIST(filename,list) glob(filename,GLOB_NOCHECK,0,&list) 38 | #define GLOB_LIST_FAILED(list) 0 39 | #define SCAN_GLOB_LIST(list,p) i = 0; i < list.gl_pathc; i++ 40 | #define INIT_GLOB_LIST(list,p) p = list.gl_pathv[i] 41 | #define GLOB_LIST_DONE(list) globfree(&list) 42 | 43 | #else 44 | #if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC 45 | 46 | #define GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp) 47 | #define GLOB_FIRST_FAILED(handle) ((handle) != 0) 48 | #define GLOB_NEXT_NAME(handle,fndp) _dos_findnext(fndp) 49 | #define GLOB_NAME_DONE(handle) 50 | #define GLOB_NAME name 51 | #define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ 52 | struct find_t fnd; \ 53 | char drive[_MAX_DRIVE]; \ 54 | char dir[_MAX_DIR]; \ 55 | char fname[_MAX_FNAME]; \ 56 | char ext[_MAX_EXT]; \ 57 | int handle; 58 | #else 59 | #if MSDOS_COMPILER==WIN32C && defined(_MSC_VER) 60 | 61 | #define GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp) 62 | #define GLOB_FIRST_FAILED(handle) ((handle) == -1) 63 | #define GLOB_NEXT_NAME(handle,fndp) _findnext(handle, fndp) 64 | #define GLOB_NAME_DONE(handle) _findclose(handle) 65 | #define GLOB_NAME name 66 | #define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ 67 | struct _finddata_t fnd; \ 68 | char drive[_MAX_DRIVE]; \ 69 | char dir[_MAX_DIR]; \ 70 | char fname[_MAX_FNAME]; \ 71 | char ext[_MAX_EXT]; \ 72 | intptr_t handle; 73 | 74 | #else 75 | #if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER) /* Borland C for Windows */ 76 | 77 | #define GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL) 78 | #define GLOB_FIRST_FAILED(handle) ((handle) != 0) 79 | #define GLOB_NEXT_NAME(handle,fndp) findnext(fndp) 80 | #define GLOB_NAME_DONE(handle) 81 | #define GLOB_NAME ff_name 82 | #define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ 83 | struct ffblk fnd; \ 84 | char drive[MAXDRIVE]; \ 85 | char dir[MAXDIR]; \ 86 | char fname[MAXFILE]; \ 87 | char ext[MAXEXT]; \ 88 | int handle; 89 | 90 | #endif 91 | #endif 92 | #endif 93 | #endif 94 | #endif 95 | -------------------------------------------------------------------------------- /lsystem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Routines to execute other programs. 13 | * Necessarily very OS dependent. 14 | */ 15 | 16 | #include "less.h" 17 | #include 18 | #include "position.h" 19 | 20 | #if MSDOS_COMPILER 21 | #include 22 | #ifdef _MSC_VER 23 | #include 24 | #define setdisk(n) _chdrive((n)+1) 25 | #else 26 | #include 27 | #endif 28 | #endif 29 | 30 | extern int screen_trashed; 31 | extern IFILE curr_ifile; 32 | 33 | 34 | #if HAVE_SYSTEM 35 | 36 | /* 37 | * Pass the specified command to a shell to be executed. 38 | * Like plain "system()", but handles resetting terminal modes, etc. 39 | */ 40 | public void 41 | lsystem(cmd, donemsg) 42 | char *cmd; 43 | char *donemsg; 44 | { 45 | register int inp; 46 | #if HAVE_SHELL 47 | register char *shell; 48 | register char *p; 49 | #endif 50 | IFILE save_ifile; 51 | #if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C 52 | char cwd[FILENAME_MAX+1]; 53 | #endif 54 | 55 | /* 56 | * Print the command which is to be executed, 57 | * unless the command starts with a "-". 58 | */ 59 | if (cmd[0] == '-') 60 | cmd++; 61 | else 62 | { 63 | clear_bot(); 64 | putstr("!"); 65 | putstr(cmd); 66 | putstr("\n"); 67 | } 68 | 69 | #if MSDOS_COMPILER 70 | #if MSDOS_COMPILER==WIN32C 71 | if (*cmd == '\0') 72 | cmd = getenv("COMSPEC"); 73 | #else 74 | /* 75 | * Working directory is global on MSDOS. 76 | * The child might change the working directory, so we 77 | * must save and restore CWD across calls to "system", 78 | * or else we won't find our file when we return and 79 | * try to "reedit_ifile" it. 80 | */ 81 | getcwd(cwd, FILENAME_MAX); 82 | #endif 83 | #endif 84 | 85 | /* 86 | * Close the current input file. 87 | */ 88 | save_ifile = save_curr_ifile(); 89 | (void) edit_ifile(NULL_IFILE); 90 | 91 | /* 92 | * De-initialize the terminal and take out of raw mode. 93 | */ 94 | deinit(); 95 | flush(); /* Make sure the deinit chars get out */ 96 | raw_mode(0); 97 | #if MSDOS_COMPILER==WIN32C 98 | close_getchr(); 99 | #endif 100 | 101 | /* 102 | * Restore signals to their defaults. 103 | */ 104 | init_signals(0); 105 | 106 | #if HAVE_DUP 107 | /* 108 | * Force standard input to be the user's terminal 109 | * (the normal standard input), even if less's standard input 110 | * is coming from a pipe. 111 | */ 112 | inp = dup(0); 113 | close(0); 114 | #if OS2 115 | /* The __open() system call translates "/dev/tty" to "con". */ 116 | if (__open("/dev/tty", OPEN_READ) < 0) 117 | #else 118 | if (open("/dev/tty", OPEN_READ) < 0) 119 | #endif 120 | dup(inp); 121 | #endif 122 | 123 | /* 124 | * Pass the command to the system to be executed. 125 | * If we have a SHELL environment variable, use 126 | * <$SHELL -c "command"> instead of just . 127 | * If the command is empty, just invoke a shell. 128 | */ 129 | #if HAVE_SHELL 130 | p = NULL; 131 | if ((shell = lgetenv("SHELL")) != NULL && *shell != '\0') 132 | { 133 | if (*cmd == '\0') 134 | p = save(shell); 135 | else 136 | { 137 | char *esccmd = shell_quote(cmd); 138 | if (esccmd != NULL) 139 | { 140 | int len = (int) (strlen(shell) + strlen(esccmd) + 5); 141 | p = (char *) ecalloc(len, sizeof(char)); 142 | SNPRINTF3(p, len, "%s %s %s", shell, shell_coption(), esccmd); 143 | free(esccmd); 144 | } 145 | } 146 | } 147 | if (p == NULL) 148 | { 149 | if (*cmd == '\0') 150 | p = save("sh"); 151 | else 152 | p = save(cmd); 153 | } 154 | system(p); 155 | free(p); 156 | #else 157 | #if MSDOS_COMPILER==DJGPPC 158 | /* 159 | * Make stdin of the child be in cooked mode. 160 | */ 161 | setmode(0, O_TEXT); 162 | /* 163 | * We don't need to catch signals of the child (it 164 | * also makes trouble with some DPMI servers). 165 | */ 166 | __djgpp_exception_toggle(); 167 | system(cmd); 168 | __djgpp_exception_toggle(); 169 | #else 170 | system(cmd); 171 | #endif 172 | #endif 173 | 174 | #if HAVE_DUP 175 | /* 176 | * Restore standard input, reset signals, raw mode, etc. 177 | */ 178 | close(0); 179 | dup(inp); 180 | close(inp); 181 | #endif 182 | 183 | #if MSDOS_COMPILER==WIN32C 184 | open_getchr(); 185 | #endif 186 | init_signals(1); 187 | raw_mode(1); 188 | if (donemsg != NULL) 189 | { 190 | putstr(donemsg); 191 | putstr(" (press RETURN)"); 192 | get_return(); 193 | putchr('\n'); 194 | flush(); 195 | } 196 | init(); 197 | screen_trashed = 1; 198 | 199 | #if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C 200 | /* 201 | * Restore the previous directory (possibly 202 | * changed by the child program we just ran). 203 | */ 204 | chdir(cwd); 205 | #if MSDOS_COMPILER != DJGPPC 206 | /* 207 | * Some versions of chdir() don't change to the drive 208 | * which is part of CWD. (DJGPP does this in chdir.) 209 | */ 210 | if (cwd[1] == ':') 211 | { 212 | if (cwd[0] >= 'a' && cwd[0] <= 'z') 213 | setdisk(cwd[0] - 'a'); 214 | else if (cwd[0] >= 'A' && cwd[0] <= 'Z') 215 | setdisk(cwd[0] - 'A'); 216 | } 217 | #endif 218 | #endif 219 | 220 | /* 221 | * Reopen the current input file. 222 | */ 223 | reedit_ifile(save_ifile); 224 | 225 | #if defined(SIGWINCH) || defined(SIGWIND) 226 | /* 227 | * Since we were ignoring window change signals while we executed 228 | * the system command, we must assume the window changed. 229 | * Warning: this leaves a signal pending (in "sigs"), 230 | * so psignals() should be called soon after lsystem(). 231 | */ 232 | winch(0); 233 | #endif 234 | } 235 | 236 | #endif 237 | 238 | #if PIPEC 239 | 240 | /* 241 | * Pipe a section of the input file into the given shell command. 242 | * The section to be piped is the section "between" the current 243 | * position and the position marked by the given letter. 244 | * 245 | * If the mark is after the current screen, the section between 246 | * the top line displayed and the mark is piped. 247 | * If the mark is before the current screen, the section between 248 | * the mark and the bottom line displayed is piped. 249 | * If the mark is on the current screen, or if the mark is ".", 250 | * the whole current screen is piped. 251 | */ 252 | public int 253 | pipe_mark(c, cmd) 254 | int c; 255 | char *cmd; 256 | { 257 | POSITION mpos, tpos, bpos; 258 | 259 | /* 260 | * mpos = the marked position. 261 | * tpos = top of screen. 262 | * bpos = bottom of screen. 263 | */ 264 | mpos = markpos(c); 265 | if (mpos == NULL_POSITION) 266 | return (-1); 267 | tpos = position(TOP); 268 | if (tpos == NULL_POSITION) 269 | tpos = ch_zero(); 270 | bpos = position(BOTTOM); 271 | 272 | if (c == '.') 273 | return (pipe_data(cmd, tpos, bpos)); 274 | else if (mpos <= tpos) 275 | return (pipe_data(cmd, mpos, bpos)); 276 | else if (bpos == NULL_POSITION) 277 | return (pipe_data(cmd, tpos, bpos)); 278 | else 279 | return (pipe_data(cmd, tpos, mpos)); 280 | } 281 | 282 | /* 283 | * Create a pipe to the given shell command. 284 | * Feed it the file contents between the positions spos and epos. 285 | */ 286 | public int 287 | pipe_data(cmd, spos, epos) 288 | char *cmd; 289 | POSITION spos; 290 | POSITION epos; 291 | { 292 | register FILE *f; 293 | register int c; 294 | extern FILE *popen(); 295 | 296 | /* 297 | * This is structured much like lsystem(). 298 | * Since we're running a shell program, we must be careful 299 | * to perform the necessary deinitialization before running 300 | * the command, and reinitialization after it. 301 | */ 302 | if (ch_seek(spos) != 0) 303 | { 304 | error("Cannot seek to start position", NULL_PARG); 305 | return (-1); 306 | } 307 | 308 | if ((f = popen(cmd, "w")) == NULL) 309 | { 310 | error("Cannot create pipe", NULL_PARG); 311 | return (-1); 312 | } 313 | clear_bot(); 314 | putstr("!"); 315 | putstr(cmd); 316 | putstr("\n"); 317 | 318 | deinit(); 319 | flush(); 320 | raw_mode(0); 321 | init_signals(0); 322 | #if MSDOS_COMPILER==WIN32C 323 | close_getchr(); 324 | #endif 325 | #ifdef SIGPIPE 326 | LSIGNAL(SIGPIPE, SIG_IGN); 327 | #endif 328 | 329 | c = EOI; 330 | while (epos == NULL_POSITION || spos++ <= epos) 331 | { 332 | /* 333 | * Read a character from the file and give it to the pipe. 334 | */ 335 | c = ch_forw_get(); 336 | if (c == EOI) 337 | break; 338 | if (putc(c, f) == EOF) 339 | break; 340 | } 341 | 342 | /* 343 | * Finish up the last line. 344 | */ 345 | while (c != '\n' && c != EOI ) 346 | { 347 | c = ch_forw_get(); 348 | if (c == EOI) 349 | break; 350 | if (putc(c, f) == EOF) 351 | break; 352 | } 353 | 354 | pclose(f); 355 | 356 | #ifdef SIGPIPE 357 | LSIGNAL(SIGPIPE, SIG_DFL); 358 | #endif 359 | #if MSDOS_COMPILER==WIN32C 360 | open_getchr(); 361 | #endif 362 | init_signals(1); 363 | raw_mode(1); 364 | init(); 365 | screen_trashed = 1; 366 | #if defined(SIGWINCH) || defined(SIGWIND) 367 | /* {{ Probably don't need this here. }} */ 368 | winch(0); 369 | #endif 370 | return (0); 371 | } 372 | 373 | #endif 374 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Entry point, initialization, miscellaneous routines. 13 | */ 14 | 15 | #include "less.h" 16 | #if MSDOS_COMPILER==WIN32C 17 | #include 18 | #endif 19 | 20 | public char * every_first_cmd = NULL; 21 | public int new_file; 22 | public int is_tty; 23 | public IFILE curr_ifile = NULL_IFILE; 24 | public IFILE old_ifile = NULL_IFILE; 25 | public struct scrpos initial_scrpos; 26 | public int any_display = FALSE; 27 | public POSITION start_attnpos = NULL_POSITION; 28 | public POSITION end_attnpos = NULL_POSITION; 29 | public int wscroll; 30 | public char * progname; 31 | public int quitting; 32 | public int secure; 33 | public int dohelp; 34 | 35 | #if LOGFILE 36 | public int logfile = -1; 37 | public int force_logfile = FALSE; 38 | public char * namelogfile = NULL; 39 | #endif 40 | 41 | #if EDITOR 42 | public char * editor; 43 | public char * editproto; 44 | #endif 45 | 46 | #if TAGS 47 | extern char * tags; 48 | extern char * tagoption; 49 | extern int jump_sline; 50 | #endif 51 | 52 | #ifdef WIN32 53 | static char consoleTitle[256]; 54 | #endif 55 | 56 | extern int less_is_more; 57 | extern int missing_cap; 58 | extern int know_dumb; 59 | extern int pr_type; 60 | 61 | 62 | /* 63 | * Entry point. 64 | */ 65 | int 66 | main(argc, argv) 67 | int argc; 68 | char *argv[]; 69 | { 70 | IFILE ifile; 71 | char *s; 72 | 73 | #ifdef __EMX__ 74 | _response(&argc, &argv); 75 | _wildcard(&argc, &argv); 76 | #endif 77 | 78 | progname = *argv++; 79 | argc--; 80 | 81 | secure = 0; 82 | s = lgetenv("LESSSECURE"); 83 | if (s != NULL && *s != '\0') 84 | secure = 1; 85 | 86 | #ifdef WIN32 87 | if (getenv("HOME") == NULL) 88 | { 89 | /* 90 | * If there is no HOME environment variable, 91 | * try the concatenation of HOMEDRIVE + HOMEPATH. 92 | */ 93 | char *drive = getenv("HOMEDRIVE"); 94 | char *path = getenv("HOMEPATH"); 95 | if (drive != NULL && path != NULL) 96 | { 97 | char *env = (char *) ecalloc(strlen(drive) + 98 | strlen(path) + 6, sizeof(char)); 99 | strcpy(env, "HOME="); 100 | strcat(env, drive); 101 | strcat(env, path); 102 | putenv(env); 103 | } 104 | } 105 | GetConsoleTitle(consoleTitle, sizeof(consoleTitle)/sizeof(char)); 106 | #endif /* WIN32 */ 107 | 108 | /* 109 | * Process command line arguments and LESS environment arguments. 110 | * Command line arguments override environment arguments. 111 | */ 112 | is_tty = isatty(1); 113 | get_term(); 114 | init_cmds(); 115 | init_charset(); 116 | init_line(); 117 | init_cmdhist(); 118 | init_option(); 119 | init_search(); 120 | 121 | /* 122 | * If the name of the executable program is "more", 123 | * act like LESS_IS_MORE is set. 124 | */ 125 | for (s = progname + strlen(progname); s > progname; s--) 126 | { 127 | if (s[-1] == PATHNAME_SEP[0]) 128 | break; 129 | } 130 | if (strcmp(s, "more") == 0) 131 | less_is_more = 1; 132 | 133 | init_prompt(); 134 | 135 | s = lgetenv(less_is_more ? "MORE" : "LESS"); 136 | if (s != NULL) 137 | scan_option(save(s)); 138 | 139 | #define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0') 140 | while (argc > 0 && (isoptstring(*argv) || isoptpending())) 141 | { 142 | s = *argv++; 143 | argc--; 144 | if (strcmp(s, "--") == 0) 145 | break; 146 | scan_option(s); 147 | } 148 | #undef isoptstring 149 | 150 | if (isoptpending()) 151 | { 152 | /* 153 | * Last command line option was a flag requiring a 154 | * following string, but there was no following string. 155 | */ 156 | nopendopt(); 157 | quit(QUIT_OK); 158 | } 159 | 160 | #if EDITOR 161 | editor = lgetenv("VISUAL"); 162 | if (editor == NULL || *editor == '\0') 163 | { 164 | editor = lgetenv("EDITOR"); 165 | if (editor == NULL || *editor == '\0') 166 | editor = EDIT_PGM; 167 | } 168 | editproto = lgetenv("LESSEDIT"); 169 | if (editproto == NULL || *editproto == '\0') 170 | editproto = "%E ?lm+%lm. %f"; 171 | #endif 172 | 173 | /* 174 | * Call get_ifile with all the command line filenames 175 | * to "register" them with the ifile system. 176 | */ 177 | ifile = NULL_IFILE; 178 | if (dohelp) 179 | ifile = get_ifile(FAKE_HELPFILE, ifile); 180 | while (argc-- > 0) 181 | { 182 | char *filename; 183 | #if (MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC) 184 | /* 185 | * Because the "shell" doesn't expand filename patterns, 186 | * treat each argument as a filename pattern rather than 187 | * a single filename. 188 | * Expand the pattern and iterate over the expanded list. 189 | */ 190 | struct textlist tlist; 191 | char *gfilename; 192 | 193 | gfilename = lglob(*argv++); 194 | init_textlist(&tlist, gfilename); 195 | filename = NULL; 196 | while ((filename = forw_textlist(&tlist, filename)) != NULL) 197 | { 198 | (void) get_ifile(filename, ifile); 199 | ifile = prev_ifile(NULL_IFILE); 200 | } 201 | free(gfilename); 202 | #else 203 | filename = shell_quote(*argv); 204 | if (filename == NULL) 205 | filename = *argv; 206 | argv++; 207 | (void) get_ifile(filename, ifile); 208 | ifile = prev_ifile(NULL_IFILE); 209 | free(filename); 210 | #endif 211 | } 212 | /* 213 | * Set up terminal, etc. 214 | */ 215 | if (!is_tty) 216 | { 217 | /* 218 | * Output is not a tty. 219 | * Just copy the input file(s) to output. 220 | */ 221 | SET_BINARY(1); 222 | if (nifile() == 0) 223 | { 224 | if (edit_stdin() == 0) 225 | cat_file(); 226 | } else if (edit_first() == 0) 227 | { 228 | do { 229 | cat_file(); 230 | } while (edit_next(1) == 0); 231 | } 232 | quit(QUIT_OK); 233 | } 234 | 235 | if (missing_cap && !know_dumb) 236 | error("WARNING: terminal is not fully functional", NULL_PARG); 237 | init_mark(); 238 | open_getchr(); 239 | raw_mode(1); 240 | init_signals(1); 241 | 242 | /* 243 | * Select the first file to examine. 244 | */ 245 | #if TAGS 246 | if (tagoption != NULL || strcmp(tags, "-") == 0) 247 | { 248 | /* 249 | * A -t option was given. 250 | * Verify that no filenames were also given. 251 | * Edit the file selected by the "tags" search, 252 | * and search for the proper line in the file. 253 | */ 254 | if (nifile() > 0) 255 | { 256 | error("No filenames allowed with -t option", NULL_PARG); 257 | quit(QUIT_ERROR); 258 | } 259 | findtag(tagoption); 260 | if (edit_tagfile()) /* Edit file which contains the tag */ 261 | quit(QUIT_ERROR); 262 | /* 263 | * Search for the line which contains the tag. 264 | * Set up initial_scrpos so we display that line. 265 | */ 266 | initial_scrpos.pos = tagsearch(); 267 | if (initial_scrpos.pos == NULL_POSITION) 268 | quit(QUIT_ERROR); 269 | initial_scrpos.ln = jump_sline; 270 | } else 271 | #endif 272 | if (nifile() == 0) 273 | { 274 | if (edit_stdin()) /* Edit standard input */ 275 | quit(QUIT_ERROR); 276 | } else 277 | { 278 | if (edit_first()) /* Edit first valid file in cmd line */ 279 | quit(QUIT_ERROR); 280 | } 281 | 282 | init(); 283 | commands(); 284 | quit(QUIT_OK); 285 | /*NOTREACHED*/ 286 | return (0); 287 | } 288 | 289 | /* 290 | * Copy a string to a "safe" place 291 | * (that is, to a buffer allocated by calloc). 292 | */ 293 | public char * 294 | save(s) 295 | char *s; 296 | { 297 | register char *p; 298 | 299 | p = (char *) ecalloc(strlen(s)+1, sizeof(char)); 300 | strcpy(p, s); 301 | return (p); 302 | } 303 | 304 | /* 305 | * Allocate memory. 306 | * Like calloc(), but never returns an error (NULL). 307 | */ 308 | public VOID_POINTER 309 | ecalloc(count, size) 310 | int count; 311 | unsigned int size; 312 | { 313 | register VOID_POINTER p; 314 | 315 | p = (VOID_POINTER) calloc(count, size); 316 | if (p != NULL) 317 | return (p); 318 | error("Cannot allocate memory", NULL_PARG); 319 | quit(QUIT_ERROR); 320 | /*NOTREACHED*/ 321 | return (NULL); 322 | } 323 | 324 | /* 325 | * Skip leading spaces in a string. 326 | */ 327 | public char * 328 | skipsp(s) 329 | register char *s; 330 | { 331 | while (*s == ' ' || *s == '\t') 332 | s++; 333 | return (s); 334 | } 335 | 336 | /* 337 | * See how many characters of two strings are identical. 338 | * If uppercase is true, the first string must begin with an uppercase 339 | * character; the remainder of the first string may be either case. 340 | */ 341 | public int 342 | sprefix(ps, s, uppercase) 343 | char *ps; 344 | char *s; 345 | int uppercase; 346 | { 347 | register int c; 348 | register int sc; 349 | register int len = 0; 350 | 351 | for ( ; *s != '\0'; s++, ps++) 352 | { 353 | c = *ps; 354 | if (uppercase) 355 | { 356 | if (len == 0 && ASCII_IS_LOWER(c)) 357 | return (-1); 358 | if (ASCII_IS_UPPER(c)) 359 | c = ASCII_TO_LOWER(c); 360 | } 361 | sc = *s; 362 | if (len > 0 && ASCII_IS_UPPER(sc)) 363 | sc = ASCII_TO_LOWER(sc); 364 | if (c != sc) 365 | break; 366 | len++; 367 | } 368 | return (len); 369 | } 370 | 371 | /* 372 | * Exit the program. 373 | */ 374 | public void 375 | quit(status) 376 | int status; 377 | { 378 | static int save_status; 379 | 380 | /* 381 | * Put cursor at bottom left corner, clear the line, 382 | * reset the terminal modes, and exit. 383 | */ 384 | if (status < 0) 385 | status = save_status; 386 | else 387 | save_status = status; 388 | quitting = 1; 389 | edit((char*)NULL); 390 | save_cmdhist(); 391 | if (any_display && is_tty) 392 | clear_bot(); 393 | deinit(); 394 | flush(); 395 | raw_mode(0); 396 | #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC 397 | /* 398 | * If we don't close 2, we get some garbage from 399 | * 2's buffer when it flushes automatically. 400 | * I cannot track this one down RB 401 | * The same bug shows up if we use ^C^C to abort. 402 | */ 403 | close(2); 404 | #endif 405 | #ifdef WIN32 406 | SetConsoleTitle(consoleTitle); 407 | #endif 408 | close_getchr(); 409 | exit(status); 410 | } 411 | -------------------------------------------------------------------------------- /mark.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | #include "less.h" 12 | 13 | extern IFILE curr_ifile; 14 | extern int sc_height; 15 | extern int jump_sline; 16 | 17 | /* 18 | * The table of marks. 19 | * Each mark is identified by a lowercase or uppercase letter. 20 | * The final one is lmark, for the "last mark"; addressed by the apostrophe. 21 | */ 22 | #define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */ 23 | #define LASTMARK (NMARKS-1) 24 | static struct mark marks[NMARKS]; 25 | 26 | /* 27 | * Initialize the mark table to show no marks are set. 28 | */ 29 | public void 30 | init_mark() 31 | { 32 | int i; 33 | 34 | for (i = 0; i < NMARKS; i++) 35 | marks[i].m_scrpos.pos = NULL_POSITION; 36 | } 37 | 38 | /* 39 | * See if a mark letter is valid (between a and z). 40 | */ 41 | static struct mark * 42 | getumark(c) 43 | int c; 44 | { 45 | if (c >= 'a' && c <= 'z') 46 | return (&marks[c-'a']); 47 | 48 | if (c >= 'A' && c <= 'Z') 49 | return (&marks[c-'A'+26]); 50 | 51 | error("Invalid mark letter", NULL_PARG); 52 | return (NULL); 53 | } 54 | 55 | /* 56 | * Get the mark structure identified by a character. 57 | * The mark struct may come either from the mark table 58 | * or may be constructed on the fly for certain characters like ^, $. 59 | */ 60 | static struct mark * 61 | getmark(c) 62 | int c; 63 | { 64 | register struct mark *m; 65 | static struct mark sm; 66 | 67 | switch (c) 68 | { 69 | case '^': 70 | /* 71 | * Beginning of the current file. 72 | */ 73 | m = &sm; 74 | m->m_scrpos.pos = ch_zero(); 75 | m->m_scrpos.ln = 0; 76 | m->m_ifile = curr_ifile; 77 | break; 78 | case '$': 79 | /* 80 | * End of the current file. 81 | */ 82 | if (ch_end_seek()) 83 | { 84 | error("Cannot seek to end of file", NULL_PARG); 85 | return (NULL); 86 | } 87 | m = &sm; 88 | m->m_scrpos.pos = ch_tell(); 89 | m->m_scrpos.ln = sc_height-1; 90 | m->m_ifile = curr_ifile; 91 | break; 92 | case '.': 93 | /* 94 | * Current position in the current file. 95 | */ 96 | m = &sm; 97 | get_scrpos(&m->m_scrpos); 98 | m->m_ifile = curr_ifile; 99 | break; 100 | case '\'': 101 | /* 102 | * The "last mark". 103 | */ 104 | m = &marks[LASTMARK]; 105 | break; 106 | default: 107 | /* 108 | * Must be a user-defined mark. 109 | */ 110 | m = getumark(c); 111 | if (m == NULL) 112 | break; 113 | if (m->m_scrpos.pos == NULL_POSITION) 114 | { 115 | error("Mark not set", NULL_PARG); 116 | return (NULL); 117 | } 118 | break; 119 | } 120 | return (m); 121 | } 122 | 123 | /* 124 | * Is a mark letter is invalid? 125 | */ 126 | public int 127 | badmark(c) 128 | int c; 129 | { 130 | return (getmark(c) == NULL); 131 | } 132 | 133 | /* 134 | * Set a user-defined mark. 135 | */ 136 | public void 137 | setmark(c) 138 | int c; 139 | { 140 | register struct mark *m; 141 | struct scrpos scrpos; 142 | 143 | m = getumark(c); 144 | if (m == NULL) 145 | return; 146 | get_scrpos(&scrpos); 147 | m->m_scrpos = scrpos; 148 | m->m_ifile = curr_ifile; 149 | } 150 | 151 | /* 152 | * Set lmark (the mark named by the apostrophe). 153 | */ 154 | public void 155 | lastmark() 156 | { 157 | struct scrpos scrpos; 158 | 159 | if (ch_getflags() & CH_HELPFILE) 160 | return; 161 | get_scrpos(&scrpos); 162 | if (scrpos.pos == NULL_POSITION) 163 | return; 164 | marks[LASTMARK].m_scrpos = scrpos; 165 | marks[LASTMARK].m_ifile = curr_ifile; 166 | } 167 | 168 | /* 169 | * Go to a mark. 170 | */ 171 | public void 172 | gomark(c) 173 | int c; 174 | { 175 | register struct mark *m; 176 | struct scrpos scrpos; 177 | 178 | m = getmark(c); 179 | if (m == NULL) 180 | return; 181 | 182 | /* 183 | * If we're trying to go to the lastmark and 184 | * it has not been set to anything yet, 185 | * set it to the beginning of the current file. 186 | */ 187 | if (m == &marks[LASTMARK] && m->m_scrpos.pos == NULL_POSITION) 188 | { 189 | m->m_ifile = curr_ifile; 190 | m->m_scrpos.pos = ch_zero(); 191 | m->m_scrpos.ln = jump_sline; 192 | } 193 | 194 | /* 195 | * If we're using lmark, we must save the screen position now, 196 | * because if we call edit_ifile() below, lmark will change. 197 | * (We save the screen position even if we're not using lmark.) 198 | */ 199 | scrpos = m->m_scrpos; 200 | if (m->m_ifile != curr_ifile) 201 | { 202 | /* 203 | * Not in the current file; edit the correct file. 204 | */ 205 | if (edit_ifile(m->m_ifile)) 206 | return; 207 | } 208 | 209 | jump_loc(scrpos.pos, scrpos.ln); 210 | } 211 | 212 | /* 213 | * Return the position associated with a given mark letter. 214 | * 215 | * We don't return which screen line the position 216 | * is associated with, but this doesn't matter much, 217 | * because it's always the first non-blank line on the screen. 218 | */ 219 | public POSITION 220 | markpos(c) 221 | int c; 222 | { 223 | register struct mark *m; 224 | 225 | m = getmark(c); 226 | if (m == NULL) 227 | return (NULL_POSITION); 228 | 229 | if (m->m_ifile != curr_ifile) 230 | { 231 | error("Mark not in current file", NULL_PARG); 232 | return (NULL_POSITION); 233 | } 234 | return (m->m_scrpos.pos); 235 | } 236 | 237 | /* 238 | * Clear the marks associated with a specified ifile. 239 | */ 240 | public void 241 | unmark(ifile) 242 | IFILE ifile; 243 | { 244 | int i; 245 | 246 | for (i = 0; i < NMARKS; i++) 247 | if (marks[i].m_ifile == ifile) 248 | marks[i].m_scrpos.pos = NULL_POSITION; 249 | } 250 | -------------------------------------------------------------------------------- /mkfuncs.awk: -------------------------------------------------------------------------------- 1 | BEGIN { FS="("; state = 0 } 2 | 3 | /^ public/ { ftype = $0; state = 1 } 4 | 5 | { if (state == 1) 6 | state = 2 7 | else if (state == 2) 8 | { print ftype,$1,"();"; state = 0 } 9 | } 10 | -------------------------------------------------------------------------------- /mkhelp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Silly little program to generate the help.c source file 13 | * from the less.hlp text file. 14 | * help.c just contains a char array whose contents are 15 | * the contents of less.hlp. 16 | */ 17 | 18 | #include 19 | 20 | int 21 | main(argc, argv) 22 | int argc; 23 | char *argv[]; 24 | { 25 | int ch; 26 | int prevch; 27 | 28 | printf("/* This file was generated by mkhelp from less.hlp */\n"); 29 | printf("#include \"less.h\"\n"); 30 | printf("constant char helpdata[] = {\n"); 31 | ch = 0; 32 | while (prevch = ch, (ch = getchar()) != EOF) 33 | { 34 | switch (ch) 35 | { 36 | case '\'': 37 | printf("'\\'',"); 38 | break; 39 | case '\\': 40 | printf("'\\\\',"); 41 | break; 42 | case '\b': 43 | printf("'\\b',"); 44 | break; 45 | case '\t': 46 | printf("'\\t',"); 47 | break; 48 | case '\n': 49 | if (prevch != '\r') 50 | printf("'\\n',\n"); 51 | break; 52 | case '\r': 53 | if (prevch != '\n') 54 | printf("'\\n',\n"); 55 | break; 56 | default: 57 | if (ch >= ' ' && ch < 0x7f) 58 | printf("'%c',", ch); 59 | else 60 | printf("0x%02x,", ch); 61 | break; 62 | } 63 | } 64 | /* Add an extra null char to avoid having a trailing comma. */ 65 | printf(" 0 };\n"); 66 | printf("constant int size_helpdata = sizeof(helpdata) - 1;\n"); 67 | return (0); 68 | } 69 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Last modified: 1994-03-25 6 | # Public domain 7 | 8 | errstatus=0 9 | 10 | for file in ${1+"$@"} ; do 11 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 12 | shift 13 | 14 | pathcomp= 15 | for d in ${1+"$@"} ; do 16 | pathcomp="$pathcomp$d" 17 | case "$pathcomp" in 18 | -* ) pathcomp=./$pathcomp ;; 19 | esac 20 | 21 | if test ! -d "$pathcomp"; then 22 | echo "mkdir $pathcomp" 1>&2 23 | mkdir "$pathcomp" || errstatus=$? 24 | fi 25 | 26 | pathcomp="$pathcomp/" 27 | done 28 | done 29 | 30 | exit $errstatus 31 | 32 | # mkinstalldirs ends here 33 | -------------------------------------------------------------------------------- /mkutable: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | use strict; 3 | 4 | my $USAGE = <<__EOF__; 5 | usage: mkutable [-n] [-f#] type... [--] [<] UnicodeData.txt 6 | -n = take non-matching types 7 | -f = zero-based type field (default 2) 8 | __EOF__ 9 | 10 | use vars qw( $opt_f $opt_n ); 11 | use Getopt::Std; 12 | my $type_field = 2; 13 | 14 | exit (main() ? 1 : 0); 15 | 16 | sub main { 17 | my $date = `date`; 18 | chomp $date; 19 | my $args = join ' ', @ARGV; 20 | my $header = "/* Generated by \"$0 $args\" on $date */\n"; 21 | 22 | die $USAGE if not getopts('f:n'); 23 | $type_field = $opt_f if $opt_f; 24 | my %types; 25 | my $arg; 26 | while ($arg = shift @ARGV) { 27 | last if $arg eq '--'; 28 | $types{$arg} = 1; 29 | } 30 | my %out = ( 'types' => \%types ); 31 | my $last_code = 0; 32 | 33 | print $header; 34 | while (<>) { 35 | chomp; 36 | s/#.*//; 37 | my @fields = split /;/; 38 | next if not @fields; 39 | my $code = hex $fields[0]; 40 | my $type = $fields[$type_field]; 41 | $type =~ s/\s//g; 42 | while (++$last_code < $code) { 43 | output(\%out, $last_code, '?'); 44 | } 45 | output(\%out, $code, $type); 46 | } 47 | output(\%out, $last_code+1, '?'); 48 | } 49 | 50 | sub output { 51 | my ($out, $code, $type) = @_; 52 | my $match = ${${$out}{types}}{$type}; 53 | my $type_change = (not $$out{start_type} or $type ne $$out{start_type}); 54 | $match = not $match if $opt_n; 55 | if ($match and (not $$out{in_run} or $type_change)) { 56 | end_run($out, $code-1); 57 | start_run($out, $code, $type); 58 | } elsif (not $match and $$out{in_run}) { 59 | end_run($out, $code-1); 60 | } 61 | } 62 | 63 | sub start_run { 64 | my ($out, $code, $type) = @_; 65 | $$out{start_code} = $code; 66 | $$out{start_type} = $type; 67 | $$out{in_run} = 1; 68 | } 69 | 70 | sub end_run { 71 | my ($out, $code) = @_; 72 | return if not $$out{in_run}; 73 | printf "\t{ 0x%04x, 0x%04x }, /* %s */\n", $$out{start_code}, $code, $$out{start_type}; 74 | $$out{in_run} = 0; 75 | } 76 | -------------------------------------------------------------------------------- /option.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | #define END_OPTION_STRING ('$') 12 | 13 | /* 14 | * Types of options. 15 | */ 16 | #define BOOL 01 /* Boolean option: 0 or 1 */ 17 | #define TRIPLE 02 /* Triple-valued option: 0, 1 or 2 */ 18 | #define NUMBER 04 /* Numeric option */ 19 | #define STRING 010 /* String-valued option */ 20 | #define NOVAR 020 /* No associated variable */ 21 | #define REPAINT 040 /* Repaint screen after toggling option */ 22 | #define NO_TOGGLE 0100 /* Option cannot be toggled with "-" cmd */ 23 | #define HL_REPAINT 0200 /* Repaint hilites after toggling option */ 24 | #define NO_QUERY 0400 /* Option cannot be queried with "_" cmd */ 25 | #define INIT_HANDLER 01000 /* Call option handler function at startup */ 26 | 27 | #define OTYPE (BOOL|TRIPLE|NUMBER|STRING|NOVAR) 28 | 29 | #define OLETTER_NONE '\1' /* Invalid option letter */ 30 | 31 | /* 32 | * Argument to a handling function tells what type of activity: 33 | */ 34 | #define INIT 0 /* Initialization (from command line) */ 35 | #define QUERY 1 /* Query (from _ or - command) */ 36 | #define TOGGLE 2 /* Change value (from - command) */ 37 | 38 | /* Flag to toggle_option to specify how to "toggle" */ 39 | #define OPT_NO_TOGGLE 0 40 | #define OPT_TOGGLE 1 41 | #define OPT_UNSET 2 42 | #define OPT_SET 3 43 | #define OPT_NO_PROMPT 0100 44 | 45 | /* Error code from findopt_name */ 46 | #define OPT_AMBIG 1 47 | 48 | struct optname 49 | { 50 | char *oname; /* Long (GNU-style) option name */ 51 | struct optname *onext; /* List of synonymous option names */ 52 | }; 53 | 54 | #define OPTNAME_MAX 32 /* Max length of long option name */ 55 | 56 | struct loption 57 | { 58 | char oletter; /* The controlling letter (a-z) */ 59 | struct optname *onames; /* Long (GNU-style) option name */ 60 | int otype; /* Type of the option */ 61 | int odefault; /* Default value */ 62 | int *ovar; /* Pointer to the associated variable */ 63 | void (*ofunc)(); /* Pointer to special handling function */ 64 | char *odesc[3]; /* Description of each value */ 65 | }; 66 | 67 | -------------------------------------------------------------------------------- /os.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Operating system dependent routines. 13 | * 14 | * Most of the stuff in here is based on Unix, but an attempt 15 | * has been made to make things work on other operating systems. 16 | * This will sometimes result in a loss of functionality, unless 17 | * someone rewrites code specifically for the new operating system. 18 | * 19 | * The makefile provides defines to decide whether various 20 | * Unix features are present. 21 | */ 22 | 23 | #include "less.h" 24 | #include 25 | #include 26 | #if HAVE_TIME_H 27 | #include 28 | #endif 29 | #if HAVE_ERRNO_H 30 | #include 31 | #endif 32 | #if HAVE_VALUES_H 33 | #include 34 | #endif 35 | 36 | /* 37 | * BSD setjmp() saves (and longjmp() restores) the signal mask. 38 | * This costs a system call or two per setjmp(), so if possible we clear the 39 | * signal mask with sigsetmask(), and use _setjmp()/_longjmp() instead. 40 | * On other systems, setjmp() doesn't affect the signal mask and so 41 | * _setjmp() does not exist; we just use setjmp(). 42 | */ 43 | #if HAVE__SETJMP && HAVE_SIGSETMASK 44 | #define SET_JUMP _setjmp 45 | #define LONG_JUMP _longjmp 46 | #else 47 | #define SET_JUMP setjmp 48 | #define LONG_JUMP longjmp 49 | #endif 50 | 51 | public int reading; 52 | 53 | static jmp_buf read_label; 54 | 55 | extern int sigs; 56 | 57 | /* 58 | * Like read() system call, but is deliberately interruptible. 59 | * A call to intread() from a signal handler will interrupt 60 | * any pending iread(). 61 | */ 62 | public int 63 | iread(fd, buf, len) 64 | int fd; 65 | char *buf; 66 | unsigned int len; 67 | { 68 | register int n; 69 | 70 | start: 71 | #if MSDOS_COMPILER==WIN32C 72 | if (ABORT_SIGS()) 73 | return (READ_INTR); 74 | #else 75 | #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC 76 | if (kbhit()) 77 | { 78 | int c; 79 | 80 | c = getch(); 81 | if (c == '\003') 82 | return (READ_INTR); 83 | ungetch(c); 84 | } 85 | #endif 86 | #endif 87 | if (SET_JUMP(read_label)) 88 | { 89 | /* 90 | * We jumped here from intread. 91 | */ 92 | reading = 0; 93 | #if HAVE_SIGPROCMASK 94 | { 95 | sigset_t mask; 96 | sigemptyset(&mask); 97 | sigprocmask(SIG_SETMASK, &mask, NULL); 98 | } 99 | #else 100 | #if HAVE_SIGSETMASK 101 | sigsetmask(0); 102 | #else 103 | #ifdef _OSK 104 | sigmask(~0); 105 | #endif 106 | #endif 107 | #endif 108 | return (READ_INTR); 109 | } 110 | 111 | flush(); 112 | reading = 1; 113 | #if MSDOS_COMPILER==DJGPPC 114 | if (isatty(fd)) 115 | { 116 | /* 117 | * Don't try reading from a TTY until a character is 118 | * available, because that makes some background programs 119 | * believe DOS is busy in a way that prevents those 120 | * programs from working while "less" waits. 121 | */ 122 | fd_set readfds; 123 | 124 | FD_ZERO(&readfds); 125 | FD_SET(fd, &readfds); 126 | if (select(fd+1, &readfds, 0, 0, 0) == -1) 127 | return (-1); 128 | } 129 | #endif 130 | n = read(fd, buf, len); 131 | #if 1 132 | /* 133 | * This is a kludge to workaround a problem on some systems 134 | * where terminating a remote tty connection causes read() to 135 | * start returning 0 forever, instead of -1. 136 | */ 137 | { 138 | extern int ignore_eoi; 139 | if (!ignore_eoi) 140 | { 141 | static int consecutive_nulls = 0; 142 | if (n == 0) 143 | consecutive_nulls++; 144 | else 145 | consecutive_nulls = 0; 146 | if (consecutive_nulls > 20) 147 | quit(QUIT_ERROR); 148 | } 149 | } 150 | #endif 151 | reading = 0; 152 | if (n < 0) 153 | { 154 | #if HAVE_ERRNO 155 | /* 156 | * Certain values of errno indicate we should just retry the read. 157 | */ 158 | #if MUST_DEFINE_ERRNO 159 | extern int errno; 160 | #endif 161 | #ifdef EINTR 162 | if (errno == EINTR) 163 | goto start; 164 | #endif 165 | #ifdef EAGAIN 166 | if (errno == EAGAIN) 167 | goto start; 168 | #endif 169 | #endif 170 | return (-1); 171 | } 172 | return (n); 173 | } 174 | 175 | /* 176 | * Interrupt a pending iread(). 177 | */ 178 | public void 179 | intread() 180 | { 181 | LONG_JUMP(read_label, 1); 182 | } 183 | 184 | /* 185 | * Return the current time. 186 | */ 187 | #if HAVE_TIME 188 | public time_type 189 | get_time() 190 | { 191 | time_type t; 192 | 193 | time(&t); 194 | return (t); 195 | } 196 | #endif 197 | 198 | 199 | #if !HAVE_STRERROR 200 | /* 201 | * Local version of strerror, if not available from the system. 202 | */ 203 | static char * 204 | strerror(err) 205 | int err; 206 | { 207 | #if HAVE_SYS_ERRLIST 208 | static char buf[16]; 209 | extern char *sys_errlist[]; 210 | extern int sys_nerr; 211 | 212 | if (err < sys_nerr) 213 | return sys_errlist[err]; 214 | sprintf(buf, "Error %d", err); 215 | return buf; 216 | #else 217 | return ("cannot open"); 218 | #endif 219 | } 220 | #endif 221 | 222 | /* 223 | * errno_message: Return an error message based on the value of "errno". 224 | */ 225 | public char * 226 | errno_message(filename) 227 | char *filename; 228 | { 229 | register char *p; 230 | register char *m; 231 | int len; 232 | #if HAVE_ERRNO 233 | #if MUST_DEFINE_ERRNO 234 | extern int errno; 235 | #endif 236 | p = strerror(errno); 237 | #else 238 | p = "cannot open"; 239 | #endif 240 | len = (int) (strlen(filename) + strlen(p) + 3); 241 | m = (char *) ecalloc(len, sizeof(char)); 242 | SNPRINTF2(m, len, "%s: %s", filename, p); 243 | return (m); 244 | } 245 | 246 | /* #define HAVE_FLOAT 0 */ 247 | 248 | static POSITION 249 | muldiv(val, num, den) 250 | POSITION val, num, den; 251 | { 252 | #if HAVE_FLOAT 253 | double v = (((double) val) * num) / den; 254 | return ((POSITION) (v + 0.5)); 255 | #else 256 | POSITION v = ((POSITION) val) * num; 257 | 258 | if (v / num == val) 259 | /* No overflow */ 260 | return (POSITION) (v / den); 261 | else 262 | /* Above calculation overflows; 263 | * use a method that is less precise but won't overflow. */ 264 | return (POSITION) (val / (den / num)); 265 | #endif 266 | } 267 | 268 | /* 269 | * Return the ratio of two POSITIONS, as a percentage. 270 | * {{ Assumes a POSITION is a long int. }} 271 | */ 272 | public int 273 | percentage(num, den) 274 | POSITION num, den; 275 | { 276 | return (int) muldiv(num, (POSITION) 100, den); 277 | } 278 | 279 | /* 280 | * Return the specified percentage of a POSITION. 281 | */ 282 | public POSITION 283 | percent_pos(pos, percent, fraction) 284 | POSITION pos; 285 | int percent; 286 | long fraction; 287 | { 288 | /* Change percent (parts per 100) to perden (parts per NUM_FRAC_DENOM). */ 289 | POSITION perden = (percent * (NUM_FRAC_DENOM / 100)) + (fraction / 100); 290 | 291 | if (perden == 0) 292 | return (0); 293 | return (POSITION) muldiv(pos, perden, (POSITION) NUM_FRAC_DENOM); 294 | } 295 | 296 | #if !HAVE_STRCHR 297 | /* 298 | * strchr is used by regexp.c. 299 | */ 300 | char * 301 | strchr(s, c) 302 | char *s; 303 | int c; 304 | { 305 | for ( ; *s != '\0'; s++) 306 | if (*s == c) 307 | return (s); 308 | if (c == '\0') 309 | return (s); 310 | return (NULL); 311 | } 312 | #endif 313 | 314 | #if !HAVE_MEMCPY 315 | VOID_POINTER 316 | memcpy(dst, src, len) 317 | VOID_POINTER dst; 318 | VOID_POINTER src; 319 | int len; 320 | { 321 | char *dstp = (char *) dst; 322 | char *srcp = (char *) src; 323 | int i; 324 | 325 | for (i = 0; i < len; i++) 326 | dstp[i] = srcp[i]; 327 | return (dst); 328 | } 329 | #endif 330 | 331 | #ifdef _OSK_MWC32 332 | 333 | /* 334 | * This implements an ANSI-style intercept setup for Microware C 3.2 335 | */ 336 | public int 337 | os9_signal(type, handler) 338 | int type; 339 | RETSIGTYPE (*handler)(); 340 | { 341 | intercept(handler); 342 | } 343 | 344 | #include 345 | 346 | int 347 | isatty(f) 348 | int f; 349 | { 350 | struct sgbuf sgbuf; 351 | 352 | if (_gs_opt(f, &sgbuf) < 0) 353 | return -1; 354 | return (sgbuf.sg_class == 0); 355 | } 356 | 357 | #endif 358 | -------------------------------------------------------------------------------- /pattern.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | /* 11 | * Routines to do pattern matching. 12 | */ 13 | 14 | #include "less.h" 15 | #include "pattern.h" 16 | 17 | extern int caseless; 18 | 19 | /* 20 | * Compile a search pattern, for future use by match_pattern. 21 | */ 22 | static int 23 | compile_pattern2(pattern, search_type, comp_pattern, show_error) 24 | char *pattern; 25 | int search_type; 26 | void **comp_pattern; 27 | int show_error; 28 | { 29 | if (search_type & SRCH_NO_REGEX) 30 | return (0); 31 | { 32 | #if HAVE_GNU_REGEX 33 | struct re_pattern_buffer *comp = (struct re_pattern_buffer *) 34 | ecalloc(1, sizeof(struct re_pattern_buffer)); 35 | struct re_pattern_buffer **pcomp = 36 | (struct re_pattern_buffer **) comp_pattern; 37 | re_set_syntax(RE_SYNTAX_POSIX_EXTENDED); 38 | if (re_compile_pattern(pattern, strlen(pattern), comp)) 39 | { 40 | free(comp); 41 | if (show_error) 42 | error("Invalid pattern", NULL_PARG); 43 | return (-1); 44 | } 45 | if (*pcomp != NULL) 46 | regfree(*pcomp); 47 | *pcomp = comp; 48 | #endif 49 | #if HAVE_POSIX_REGCOMP 50 | regex_t *comp = (regex_t *) ecalloc(1, sizeof(regex_t)); 51 | regex_t **pcomp = (regex_t **) comp_pattern; 52 | if (regcomp(comp, pattern, REGCOMP_FLAG)) 53 | { 54 | free(comp); 55 | if (show_error) 56 | error("Invalid pattern", NULL_PARG); 57 | return (-1); 58 | } 59 | if (*pcomp != NULL) 60 | regfree(*pcomp); 61 | *pcomp = comp; 62 | #endif 63 | #if HAVE_PCRE 64 | pcre *comp; 65 | pcre **pcomp = (pcre **) comp_pattern; 66 | constant char *errstring; 67 | int erroffset; 68 | PARG parg; 69 | comp = pcre_compile(pattern, 0, 70 | &errstring, &erroffset, NULL); 71 | if (comp == NULL) 72 | { 73 | parg.p_string = (char *) errstring; 74 | if (show_error) 75 | error("%s", &parg); 76 | return (-1); 77 | } 78 | *pcomp = comp; 79 | #endif 80 | #if HAVE_RE_COMP 81 | PARG parg; 82 | int *pcomp = (int *) comp_pattern; 83 | if ((parg.p_string = re_comp(pattern)) != NULL) 84 | { 85 | if (show_error) 86 | error("%s", &parg); 87 | return (-1); 88 | } 89 | *pcomp = 1; 90 | #endif 91 | #if HAVE_REGCMP 92 | char *comp; 93 | char **pcomp = (char **) comp_pattern; 94 | if ((comp = regcmp(pattern, 0)) == NULL) 95 | { 96 | if (show_error) 97 | error("Invalid pattern", NULL_PARG); 98 | return (-1); 99 | } 100 | if (pcomp != NULL) 101 | free(*pcomp); 102 | *pcomp = comp; 103 | #endif 104 | #if HAVE_V8_REGCOMP 105 | struct regexp *comp; 106 | struct regexp **pcomp = (struct regexp **) comp_pattern; 107 | reg_show_error = show_error; 108 | comp = regcomp(pattern); 109 | reg_show_error = 1; 110 | if (comp == NULL) 111 | { 112 | /* 113 | * regcomp has already printed an error message 114 | * via regerror(). 115 | */ 116 | return (-1); 117 | } 118 | if (*pcomp != NULL) 119 | free(*pcomp); 120 | *pcomp = comp; 121 | #endif 122 | } 123 | return (0); 124 | } 125 | 126 | /* 127 | * Like compile_pattern2, but convert the pattern to lowercase if necessary. 128 | */ 129 | public int 130 | compile_pattern(pattern, search_type, comp_pattern) 131 | char *pattern; 132 | int search_type; 133 | void **comp_pattern; 134 | { 135 | char *cvt_pattern; 136 | int result; 137 | 138 | if (caseless != OPT_ONPLUS) 139 | cvt_pattern = pattern; 140 | else 141 | { 142 | cvt_pattern = (char*) ecalloc(1, cvt_length(strlen(pattern), CVT_TO_LC)); 143 | cvt_text(cvt_pattern, pattern, (int *)NULL, (int *)NULL, CVT_TO_LC); 144 | } 145 | result = compile_pattern2(cvt_pattern, search_type, comp_pattern, 1); 146 | if (cvt_pattern != pattern) 147 | free(cvt_pattern); 148 | return (result); 149 | } 150 | 151 | /* 152 | * Forget that we have a compiled pattern. 153 | */ 154 | public void 155 | uncompile_pattern(pattern) 156 | void **pattern; 157 | { 158 | #if HAVE_GNU_REGEX 159 | struct re_pattern_buffer **pcomp = (struct re_pattern_buffer **) pattern; 160 | if (*pcomp != NULL) 161 | regfree(*pcomp); 162 | *pcomp = NULL; 163 | #endif 164 | #if HAVE_POSIX_REGCOMP 165 | regex_t **pcomp = (regex_t **) pattern; 166 | if (*pcomp != NULL) 167 | regfree(*pcomp); 168 | *pcomp = NULL; 169 | #endif 170 | #if HAVE_PCRE 171 | pcre **pcomp = (pcre **) pattern; 172 | if (*pcomp != NULL) 173 | pcre_free(*pcomp); 174 | *pcomp = NULL; 175 | #endif 176 | #if HAVE_RE_COMP 177 | int *pcomp = (int *) pattern; 178 | *pcomp = 0; 179 | #endif 180 | #if HAVE_REGCMP 181 | char **pcomp = (char **) pattern; 182 | if (*pcomp != NULL) 183 | free(*pcomp); 184 | *pcomp = NULL; 185 | #endif 186 | #if HAVE_V8_REGCOMP 187 | struct regexp **pcomp = (struct regexp **) pattern; 188 | if (*pcomp != NULL) 189 | free(*pcomp); 190 | *pcomp = NULL; 191 | #endif 192 | } 193 | 194 | /* 195 | * Can a pattern be successfully compiled? 196 | */ 197 | public int 198 | valid_pattern(pattern) 199 | char *pattern; 200 | { 201 | void *comp_pattern; 202 | int result; 203 | 204 | CLEAR_PATTERN(comp_pattern); 205 | result = compile_pattern2(pattern, 0, &comp_pattern, 0); 206 | if (result != 0) 207 | return (0); 208 | uncompile_pattern(&comp_pattern); 209 | return (1); 210 | } 211 | 212 | /* 213 | * Is a compiled pattern null? 214 | */ 215 | public int 216 | is_null_pattern(pattern) 217 | void *pattern; 218 | { 219 | #if HAVE_GNU_REGEX 220 | return (pattern == NULL); 221 | #endif 222 | #if HAVE_POSIX_REGCOMP 223 | return (pattern == NULL); 224 | #endif 225 | #if HAVE_PCRE 226 | return (pattern == NULL); 227 | #endif 228 | #if HAVE_RE_COMP 229 | return (pattern == 0); 230 | #endif 231 | #if HAVE_REGCMP 232 | return (pattern == NULL); 233 | #endif 234 | #if HAVE_V8_REGCOMP 235 | return (pattern == NULL); 236 | #endif 237 | #if NO_REGEX 238 | return (pattern == NULL); 239 | #endif 240 | } 241 | 242 | /* 243 | * Simple pattern matching function. 244 | * It supports no metacharacters like *, etc. 245 | */ 246 | static int 247 | match(pattern, pattern_len, buf, buf_len, pfound, pend) 248 | char *pattern; 249 | int pattern_len; 250 | char *buf; 251 | int buf_len; 252 | char **pfound, **pend; 253 | { 254 | register char *pp, *lp; 255 | register char *pattern_end = pattern + pattern_len; 256 | register char *buf_end = buf + buf_len; 257 | 258 | for ( ; buf < buf_end; buf++) 259 | { 260 | for (pp = pattern, lp = buf; ; pp++, lp++) 261 | { 262 | char cp = *pp; 263 | char cl = *lp; 264 | if (caseless == OPT_ONPLUS && ASCII_IS_UPPER(cp)) 265 | cp = ASCII_TO_LOWER(cp); 266 | if (cp != cl) 267 | break; 268 | if (pp == pattern_end || lp == buf_end) 269 | break; 270 | } 271 | if (pp == pattern_end) 272 | { 273 | if (pfound != NULL) 274 | *pfound = buf; 275 | if (pend != NULL) 276 | *pend = lp; 277 | return (1); 278 | } 279 | } 280 | return (0); 281 | } 282 | 283 | /* 284 | * Perform a pattern match with the previously compiled pattern. 285 | * Set sp and ep to the start and end of the matched string. 286 | */ 287 | public int 288 | match_pattern(pattern, tpattern, line, line_len, sp, ep, notbol, search_type) 289 | void *pattern; 290 | char *tpattern; 291 | char *line; 292 | int line_len; 293 | char **sp; 294 | char **ep; 295 | int notbol; 296 | int search_type; 297 | { 298 | int matched; 299 | #if HAVE_GNU_REGEX 300 | struct re_pattern_buffer *spattern = (struct re_pattern_buffer *) pattern; 301 | #endif 302 | #if HAVE_POSIX_REGCOMP 303 | regex_t *spattern = (regex_t *) pattern; 304 | #endif 305 | #if HAVE_PCRE 306 | pcre *spattern = (pcre *) pattern; 307 | #endif 308 | #if HAVE_RE_COMP 309 | int spattern = (int) pattern; 310 | #endif 311 | #if HAVE_REGCMP 312 | char *spattern = (char *) pattern; 313 | #endif 314 | #if HAVE_V8_REGCOMP 315 | struct regexp *spattern = (struct regexp *) pattern; 316 | #endif 317 | 318 | *sp = *ep = NULL; 319 | #if NO_REGEX 320 | search_type |= SRCH_NO_REGEX; 321 | #endif 322 | if (search_type & SRCH_NO_REGEX) 323 | matched = match(tpattern, strlen(tpattern), line, line_len, sp, ep); 324 | else 325 | { 326 | #if HAVE_GNU_REGEX 327 | { 328 | struct re_registers search_regs; 329 | spattern->not_bol = notbol; 330 | spattern->regs_allocated = REGS_UNALLOCATED; 331 | matched = re_search(spattern, line, line_len, 0, line_len, &search_regs) >= 0; 332 | if (matched) 333 | { 334 | *sp = line + search_regs.start[0]; 335 | *ep = line + search_regs.end[0]; 336 | } 337 | } 338 | #endif 339 | #if HAVE_POSIX_REGCOMP 340 | { 341 | regmatch_t rm; 342 | int flags = (notbol) ? REG_NOTBOL : 0; 343 | #ifdef REG_STARTEND 344 | flags |= REG_STARTEND; 345 | rm.rm_so = 0; 346 | rm.rm_eo = line_len; 347 | #endif 348 | matched = !regexec(spattern, line, 1, &rm, flags); 349 | if (matched) 350 | { 351 | #ifndef __WATCOMC__ 352 | *sp = line + rm.rm_so; 353 | *ep = line + rm.rm_eo; 354 | #else 355 | *sp = rm.rm_sp; 356 | *ep = rm.rm_ep; 357 | #endif 358 | } 359 | } 360 | #endif 361 | #if HAVE_PCRE 362 | { 363 | int flags = (notbol) ? PCRE_NOTBOL : 0; 364 | int ovector[3]; 365 | matched = pcre_exec(spattern, NULL, line, line_len, 366 | 0, flags, ovector, 3) >= 0; 367 | if (matched) 368 | { 369 | *sp = line + ovector[0]; 370 | *ep = line + ovector[1]; 371 | } 372 | } 373 | #endif 374 | #if HAVE_RE_COMP 375 | matched = (re_exec(line) == 1); 376 | /* 377 | * re_exec doesn't seem to provide a way to get the matched string. 378 | */ 379 | *sp = *ep = NULL; 380 | #endif 381 | #if HAVE_REGCMP 382 | *ep = regex(spattern, line); 383 | matched = (*ep != NULL); 384 | if (matched) 385 | *sp = __loc1; 386 | #endif 387 | #if HAVE_V8_REGCOMP 388 | #if HAVE_REGEXEC2 389 | matched = regexec2(spattern, line, notbol); 390 | #else 391 | matched = regexec(spattern, line); 392 | #endif 393 | if (matched) 394 | { 395 | *sp = spattern->startp[0]; 396 | *ep = spattern->endp[0]; 397 | } 398 | #endif 399 | } 400 | matched = (!(search_type & SRCH_NO_MATCH) && matched) || 401 | ((search_type & SRCH_NO_MATCH) && !matched); 402 | return (matched); 403 | } 404 | 405 | -------------------------------------------------------------------------------- /pattern.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | #if HAVE_GNU_REGEX 11 | #define __USE_GNU 1 12 | #include 13 | #define DEFINE_PATTERN(name) struct re_pattern_buffer *name 14 | #define CLEAR_PATTERN(name) name = NULL 15 | #endif 16 | 17 | #if HAVE_POSIX_REGCOMP 18 | #include 19 | #ifdef REG_EXTENDED 20 | #define REGCOMP_FLAG REG_EXTENDED 21 | #else 22 | #define REGCOMP_FLAG 0 23 | #endif 24 | #define DEFINE_PATTERN(name) regex_t *name 25 | #define CLEAR_PATTERN(name) name = NULL 26 | #endif 27 | 28 | #if HAVE_PCRE 29 | #include 30 | #define DEFINE_PATTERN(name) pcre *name 31 | #define CLEAR_PATTERN(name) name = NULL 32 | #endif 33 | 34 | #if HAVE_RE_COMP 35 | char *re_comp(); 36 | int re_exec(); 37 | #define DEFINE_PATTERN(name) int name 38 | #define CLEAR_PATTERN(name) name = 0 39 | #endif 40 | 41 | #if HAVE_REGCMP 42 | char *regcmp(); 43 | char *regex(); 44 | extern char *__loc1; 45 | #define DEFINE_PATTERN(name) char *name 46 | #define CLEAR_PATTERN(name) name = NULL 47 | #endif 48 | 49 | #if HAVE_V8_REGCOMP 50 | #include "regexp.h" 51 | extern int reg_show_error; 52 | #define DEFINE_PATTERN(name) struct regexp *name 53 | #define CLEAR_PATTERN(name) name = NULL 54 | #endif 55 | 56 | #if NO_REGEX 57 | #define DEFINE_PATTERN(name) 58 | #define CLEAR_PATTERN(name) 59 | #endif 60 | -------------------------------------------------------------------------------- /pckeys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Definitions of keys on the PC. 13 | * Special (non-ASCII) keys on the PC send a two-byte sequence, 14 | * where the first byte is 0 and the second is as defined below. 15 | */ 16 | #define PCK_SHIFT_TAB '\017' 17 | #define PCK_ALT_E '\022' 18 | #define PCK_CAPS_LOCK '\072' 19 | #define PCK_F1 '\073' 20 | #define PCK_NUM_LOCK '\105' 21 | #define PCK_HOME '\107' 22 | #define PCK_UP '\110' 23 | #define PCK_PAGEUP '\111' 24 | #define PCK_LEFT '\113' 25 | #define PCK_RIGHT '\115' 26 | #define PCK_END '\117' 27 | #define PCK_DOWN '\120' 28 | #define PCK_PAGEDOWN '\121' 29 | #define PCK_INSERT '\122' 30 | #define PCK_DELETE '\123' 31 | #define PCK_CTL_LEFT '\163' 32 | #define PCK_CTL_RIGHT '\164' 33 | #define PCK_CTL_DELETE '\223' 34 | -------------------------------------------------------------------------------- /position.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Routines dealing with the "position" table. 13 | * This is a table which tells the position (in the input file) of the 14 | * first char on each currently displayed line. 15 | * 16 | * {{ The position table is scrolled by moving all the entries. 17 | * Would be better to have a circular table 18 | * and just change a couple of pointers. }} 19 | */ 20 | 21 | #include "less.h" 22 | #include "position.h" 23 | 24 | static POSITION *table = NULL; /* The position table */ 25 | static int table_size; 26 | 27 | extern int sc_width, sc_height; 28 | 29 | /* 30 | * Return the starting file position of a line displayed on the screen. 31 | * The line may be specified as a line number relative to the top 32 | * of the screen, but is usually one of these special cases: 33 | * the top (first) line on the screen 34 | * the second line on the screen 35 | * the bottom line on the screen 36 | * the line after the bottom line on the screen 37 | */ 38 | public POSITION 39 | position(where) 40 | int where; 41 | { 42 | switch (where) 43 | { 44 | case BOTTOM: 45 | where = sc_height - 2; 46 | break; 47 | case BOTTOM_PLUS_ONE: 48 | where = sc_height - 1; 49 | break; 50 | case MIDDLE: 51 | where = (sc_height - 1) / 2; 52 | } 53 | return (table[where]); 54 | } 55 | 56 | /* 57 | * Add a new file position to the bottom of the position table. 58 | */ 59 | public void 60 | add_forw_pos(pos) 61 | POSITION pos; 62 | { 63 | register int i; 64 | 65 | /* 66 | * Scroll the position table up. 67 | */ 68 | for (i = 1; i < sc_height; i++) 69 | table[i-1] = table[i]; 70 | table[sc_height - 1] = pos; 71 | } 72 | 73 | /* 74 | * Add a new file position to the top of the position table. 75 | */ 76 | public void 77 | add_back_pos(pos) 78 | POSITION pos; 79 | { 80 | register int i; 81 | 82 | /* 83 | * Scroll the position table down. 84 | */ 85 | for (i = sc_height - 1; i > 0; i--) 86 | table[i] = table[i-1]; 87 | table[0] = pos; 88 | } 89 | 90 | /* 91 | * Initialize the position table, done whenever we clear the screen. 92 | */ 93 | public void 94 | pos_clear() 95 | { 96 | register int i; 97 | 98 | for (i = 0; i < sc_height; i++) 99 | table[i] = NULL_POSITION; 100 | } 101 | 102 | /* 103 | * Allocate or reallocate the position table. 104 | */ 105 | public void 106 | pos_init() 107 | { 108 | struct scrpos scrpos; 109 | 110 | if (sc_height <= table_size) 111 | return; 112 | /* 113 | * If we already have a table, remember the first line in it 114 | * before we free it, so we can copy that line to the new table. 115 | */ 116 | if (table != NULL) 117 | { 118 | get_scrpos(&scrpos); 119 | free((char*)table); 120 | } else 121 | scrpos.pos = NULL_POSITION; 122 | table = (POSITION *) ecalloc(sc_height, sizeof(POSITION)); 123 | table_size = sc_height; 124 | pos_clear(); 125 | if (scrpos.pos != NULL_POSITION) 126 | table[scrpos.ln-1] = scrpos.pos; 127 | } 128 | 129 | /* 130 | * See if the byte at a specified position is currently on the screen. 131 | * Check the position table to see if the position falls within its range. 132 | * Return the position table entry if found, -1 if not. 133 | */ 134 | public int 135 | onscreen(pos) 136 | POSITION pos; 137 | { 138 | register int i; 139 | 140 | if (pos < table[0]) 141 | return (-1); 142 | for (i = 1; i < sc_height; i++) 143 | if (pos < table[i]) 144 | return (i-1); 145 | return (-1); 146 | } 147 | 148 | /* 149 | * See if the entire screen is empty. 150 | */ 151 | public int 152 | empty_screen() 153 | { 154 | return (empty_lines(0, sc_height-1)); 155 | } 156 | 157 | public int 158 | empty_lines(s, e) 159 | int s; 160 | int e; 161 | { 162 | register int i; 163 | 164 | for (i = s; i <= e; i++) 165 | if (table[i] != NULL_POSITION && table[i] != 0) 166 | return (0); 167 | return (1); 168 | } 169 | 170 | /* 171 | * Get the current screen position. 172 | * The screen position consists of both a file position and 173 | * a screen line number where the file position is placed on the screen. 174 | * Normally the screen line number is 0, but if we are positioned 175 | * such that the top few lines are empty, we may have to set 176 | * the screen line to a number > 0. 177 | */ 178 | public void 179 | get_scrpos(scrpos) 180 | struct scrpos *scrpos; 181 | { 182 | register int i; 183 | 184 | /* 185 | * Find the first line on the screen which has something on it, 186 | * and return the screen line number and the file position. 187 | */ 188 | for (i = 0; i < sc_height; i++) 189 | if (table[i] != NULL_POSITION) 190 | { 191 | scrpos->ln = i+1; 192 | scrpos->pos = table[i]; 193 | return; 194 | } 195 | /* 196 | * The screen is empty. 197 | */ 198 | scrpos->pos = NULL_POSITION; 199 | } 200 | 201 | /* 202 | * Adjust a screen line number to be a simple positive integer 203 | * in the range { 0 .. sc_height-2 }. 204 | * (The bottom line, sc_height-1, is reserved for prompts, etc.) 205 | * The given "sline" may be in the range { 1 .. sc_height-1 } 206 | * to refer to lines relative to the top of the screen (starting from 1), 207 | * or it may be in { -1 .. -(sc_height-1) } to refer to lines 208 | * relative to the bottom of the screen. 209 | */ 210 | public int 211 | adjsline(sline) 212 | int sline; 213 | { 214 | /* 215 | * Negative screen line number means 216 | * relative to the bottom of the screen. 217 | */ 218 | if (sline < 0) 219 | sline += sc_height; 220 | /* 221 | * Can't be less than 1 or greater than sc_height-1. 222 | */ 223 | if (sline <= 0) 224 | sline = 1; 225 | if (sline >= sc_height) 226 | sline = sc_height - 1; 227 | /* 228 | * Return zero-based line number, not one-based. 229 | */ 230 | return (sline-1); 231 | } 232 | -------------------------------------------------------------------------------- /position.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Include file for interfacing to position.c modules. 13 | */ 14 | #define TOP (0) 15 | #define TOP_PLUS_ONE (1) 16 | #define BOTTOM (-1) 17 | #define BOTTOM_PLUS_ONE (-2) 18 | #define MIDDLE (-3) 19 | -------------------------------------------------------------------------------- /regexp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Definitions etc. for regexp(3) routines. 3 | * 4 | * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], 5 | * not the System V one. 6 | */ 7 | 8 | #ifndef _REGEXP 9 | #define _REGEXP 1 10 | 11 | #define NSUBEXP 10 12 | typedef struct regexp { 13 | char *startp[NSUBEXP]; 14 | char *endp[NSUBEXP]; 15 | char regstart; /* Internal use only. */ 16 | char reganch; /* Internal use only. */ 17 | char *regmust; /* Internal use only. */ 18 | int regmlen; /* Internal use only. */ 19 | char program[1]; /* Unwarranted chumminess with compiler. */ 20 | } regexp; 21 | 22 | #if defined(__STDC__) || defined(__cplusplus) 23 | # define _ANSI_ARGS_(x) x 24 | #else 25 | # define _ANSI_ARGS_(x) () 26 | #endif 27 | 28 | extern regexp *regcomp _ANSI_ARGS_((char *exp)); 29 | extern int regexec _ANSI_ARGS_((regexp *prog, char *string)); 30 | extern int regexec2 _ANSI_ARGS_((regexp *prog, char *string, int notbol)); 31 | extern void regsub _ANSI_ARGS_((regexp *prog, char *source, char *dest)); 32 | extern void regerror _ANSI_ARGS_((char *msg)); 33 | 34 | #endif /* REGEXP */ 35 | -------------------------------------------------------------------------------- /scrsize.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | /* 11 | * This program is used to determine the screen dimensions on OS/2 systems. 12 | * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp). 13 | */ 14 | 15 | /* 16 | * When I wrote this routine, I consulted some part of the source code 17 | * of the xwininfo utility by X Consortium. 18 | * 19 | * Copyright (c) 1987, X Consortium 20 | * 21 | * Permission is hereby granted, free of charge, to any person obtaining a copy 22 | * of this software and associated documentation files (the "Software"), to 23 | * deal in the Software without restriction, including without limitation the 24 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 25 | * sell copies of the Software, and to permit persons to whom the Software is 26 | * furnished to do so, subject to the following conditions: 27 | * 28 | * The above copyright notice and this permission notice shall be included in 29 | * all copies or substantial portions of the Software. 30 | * 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 34 | * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 35 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 36 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 | * 38 | * Except as contained in this notice, the name of the X Consortium shall not 39 | * be used in advertising or otherwise to promote the sale, use or other 40 | * dealings in this Software without prior written authorization from the X 41 | * Consortium. 42 | */ 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | static int get_winsize(dpy, window, p_width, p_height) 49 | Display *dpy; 50 | Window window; 51 | int *p_width; 52 | int *p_height; 53 | { 54 | XWindowAttributes win_attributes; 55 | XSizeHints hints; 56 | long longjunk; 57 | 58 | if (!XGetWindowAttributes(dpy, window, &win_attributes)) 59 | return 1; 60 | if (!XGetWMNormalHints(dpy, window, &hints, &longjunk)) 61 | return 1; 62 | if (!(hints.flags & PResizeInc)) 63 | return 1; 64 | if (hints.width_inc == 0 || hints.height_inc == 0) 65 | return 1; 66 | if (!(hints.flags & (PBaseSize|PMinSize))) 67 | return 1; 68 | if (hints.flags & PBaseSize) 69 | { 70 | win_attributes.width -= hints.base_width; 71 | win_attributes.height -= hints.base_height; 72 | } else 73 | { 74 | win_attributes.width -= hints.min_width; 75 | win_attributes.height -= hints.min_height; 76 | } 77 | *p_width = win_attributes.width / hints.width_inc; 78 | *p_height = win_attributes.height / hints.height_inc; 79 | return 0; 80 | } 81 | 82 | int main(argc, argv) 83 | int argc; 84 | char *argv[]; 85 | { 86 | char *cp; 87 | Display *dpy; 88 | int size[2]; 89 | 90 | _scrsize(size); 91 | cp = getenv("WINDOWID"); 92 | if (cp != NULL) 93 | { 94 | dpy = XOpenDisplay(NULL); 95 | if (dpy != NULL) 96 | { 97 | get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]); 98 | XCloseDisplay(dpy); 99 | } 100 | } 101 | printf("%i %i\n", size[0], size[1]); 102 | return (0); 103 | } 104 | -------------------------------------------------------------------------------- /signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Routines dealing with signals. 13 | * 14 | * A signal usually merely causes a bit to be set in the "signals" word. 15 | * At some convenient time, the mainline code checks to see if any 16 | * signals need processing by calling psignal(). 17 | * If we happen to be reading from a file [in iread()] at the time 18 | * the signal is received, we call intread to interrupt the iread. 19 | */ 20 | 21 | #include "less.h" 22 | #include 23 | 24 | /* 25 | * "sigs" contains bits indicating signals which need to be processed. 26 | */ 27 | public int sigs; 28 | 29 | extern int sc_width, sc_height; 30 | extern int screen_trashed; 31 | extern int lnloop; 32 | extern int linenums; 33 | extern int wscroll; 34 | extern int reading; 35 | extern int quit_on_intr; 36 | extern long jump_sline_fraction; 37 | 38 | /* 39 | * Interrupt signal handler. 40 | */ 41 | /* ARGSUSED*/ 42 | static RETSIGTYPE 43 | u_interrupt(type) 44 | int type; 45 | { 46 | bell(); 47 | #if OS2 48 | LSIGNAL(SIGINT, SIG_ACK); 49 | #endif 50 | LSIGNAL(SIGINT, u_interrupt); 51 | sigs |= S_INTERRUPT; 52 | #if MSDOS_COMPILER==DJGPPC 53 | /* 54 | * If a keyboard has been hit, it must be Ctrl-C 55 | * (as opposed to Ctrl-Break), so consume it. 56 | * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.) 57 | */ 58 | if (kbhit()) 59 | getkey(); 60 | #endif 61 | if (reading) 62 | intread(); /* May longjmp */ 63 | } 64 | 65 | #ifdef SIGTSTP 66 | /* 67 | * "Stop" (^Z) signal handler. 68 | */ 69 | /* ARGSUSED*/ 70 | static RETSIGTYPE 71 | stop(type) 72 | int type; 73 | { 74 | LSIGNAL(SIGTSTP, stop); 75 | sigs |= S_STOP; 76 | if (reading) 77 | intread(); 78 | } 79 | #endif 80 | 81 | #ifdef SIGWINCH 82 | /* 83 | * "Window" change handler 84 | */ 85 | /* ARGSUSED*/ 86 | public RETSIGTYPE 87 | winch(type) 88 | int type; 89 | { 90 | LSIGNAL(SIGWINCH, winch); 91 | sigs |= S_WINCH; 92 | if (reading) 93 | intread(); 94 | } 95 | #else 96 | #ifdef SIGWIND 97 | /* 98 | * "Window" change handler 99 | */ 100 | /* ARGSUSED*/ 101 | public RETSIGTYPE 102 | winch(type) 103 | int type; 104 | { 105 | LSIGNAL(SIGWIND, winch); 106 | sigs |= S_WINCH; 107 | if (reading) 108 | intread(); 109 | } 110 | #endif 111 | #endif 112 | 113 | #if MSDOS_COMPILER==WIN32C 114 | /* 115 | * Handle CTRL-C and CTRL-BREAK keys. 116 | */ 117 | #include "windows.h" 118 | 119 | static BOOL WINAPI 120 | wbreak_handler(dwCtrlType) 121 | DWORD dwCtrlType; 122 | { 123 | switch (dwCtrlType) 124 | { 125 | case CTRL_C_EVENT: 126 | case CTRL_BREAK_EVENT: 127 | sigs |= S_INTERRUPT; 128 | return (TRUE); 129 | default: 130 | break; 131 | } 132 | return (FALSE); 133 | } 134 | #endif 135 | 136 | /* 137 | * Set up the signal handlers. 138 | */ 139 | public void 140 | init_signals(on) 141 | int on; 142 | { 143 | if (on) 144 | { 145 | /* 146 | * Set signal handlers. 147 | */ 148 | (void) LSIGNAL(SIGINT, u_interrupt); 149 | #if MSDOS_COMPILER==WIN32C 150 | SetConsoleCtrlHandler(wbreak_handler, TRUE); 151 | #endif 152 | #ifdef SIGTSTP 153 | (void) LSIGNAL(SIGTSTP, stop); 154 | #endif 155 | #ifdef SIGWINCH 156 | (void) LSIGNAL(SIGWINCH, winch); 157 | #endif 158 | #ifdef SIGWIND 159 | (void) LSIGNAL(SIGWIND, winch); 160 | #endif 161 | #ifdef SIGQUIT 162 | (void) LSIGNAL(SIGQUIT, SIG_IGN); 163 | #endif 164 | } else 165 | { 166 | /* 167 | * Restore signals to defaults. 168 | */ 169 | (void) LSIGNAL(SIGINT, SIG_DFL); 170 | #if MSDOS_COMPILER==WIN32C 171 | SetConsoleCtrlHandler(wbreak_handler, FALSE); 172 | #endif 173 | #ifdef SIGTSTP 174 | (void) LSIGNAL(SIGTSTP, SIG_DFL); 175 | #endif 176 | #ifdef SIGWINCH 177 | (void) LSIGNAL(SIGWINCH, SIG_IGN); 178 | #endif 179 | #ifdef SIGWIND 180 | (void) LSIGNAL(SIGWIND, SIG_IGN); 181 | #endif 182 | #ifdef SIGQUIT 183 | (void) LSIGNAL(SIGQUIT, SIG_DFL); 184 | #endif 185 | } 186 | } 187 | 188 | /* 189 | * Process any signals we have received. 190 | * A received signal cause a bit to be set in "sigs". 191 | */ 192 | public void 193 | psignals() 194 | { 195 | register int tsignals; 196 | 197 | if ((tsignals = sigs) == 0) 198 | return; 199 | sigs = 0; 200 | 201 | #ifdef SIGTSTP 202 | if (tsignals & S_STOP) 203 | { 204 | /* 205 | * Clean up the terminal. 206 | */ 207 | #ifdef SIGTTOU 208 | LSIGNAL(SIGTTOU, SIG_IGN); 209 | #endif 210 | clear_bot(); 211 | deinit(); 212 | flush(); 213 | raw_mode(0); 214 | #ifdef SIGTTOU 215 | LSIGNAL(SIGTTOU, SIG_DFL); 216 | #endif 217 | LSIGNAL(SIGTSTP, SIG_DFL); 218 | kill(getpid(), SIGTSTP); 219 | /* 220 | * ... Bye bye. ... 221 | * Hopefully we'll be back later and resume here... 222 | * Reset the terminal and arrange to repaint the 223 | * screen when we get back to the main command loop. 224 | */ 225 | LSIGNAL(SIGTSTP, stop); 226 | raw_mode(1); 227 | init(); 228 | screen_trashed = 1; 229 | tsignals |= S_WINCH; 230 | } 231 | #endif 232 | #ifdef S_WINCH 233 | if (tsignals & S_WINCH) 234 | { 235 | int old_width, old_height; 236 | /* 237 | * Re-execute scrsize() to read the new window size. 238 | */ 239 | old_width = sc_width; 240 | old_height = sc_height; 241 | get_term(); 242 | if (sc_width != old_width || sc_height != old_height) 243 | { 244 | wscroll = (sc_height + 1) / 2; 245 | calc_jump_sline(); 246 | calc_shift_count(); 247 | screen_trashed = 1; 248 | } 249 | } 250 | #endif 251 | if (tsignals & S_INTERRUPT) 252 | { 253 | if (quit_on_intr) 254 | quit(QUIT_INTERRUPT); 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /ttyin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1984-2015 Mark Nudelman 3 | * 4 | * You may distribute under the terms of either the GNU General Public 5 | * License or the Less License, as specified in the README file. 6 | * 7 | * For more information, see the README file. 8 | */ 9 | 10 | 11 | /* 12 | * Routines dealing with getting input from the keyboard (i.e. from the user). 13 | */ 14 | 15 | #include "less.h" 16 | #if OS2 17 | #include "cmd.h" 18 | #include "pckeys.h" 19 | #endif 20 | #if MSDOS_COMPILER==WIN32C 21 | #include "windows.h" 22 | extern char WIN32getch(); 23 | static DWORD console_mode; 24 | #endif 25 | 26 | public int tty; 27 | extern int sigs; 28 | extern int utf_mode; 29 | 30 | /* 31 | * Open keyboard for input. 32 | */ 33 | public void 34 | open_getchr() 35 | { 36 | #if MSDOS_COMPILER==WIN32C 37 | /* Need this to let child processes inherit our console handle */ 38 | SECURITY_ATTRIBUTES sa; 39 | memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES)); 40 | sa.nLength = sizeof(SECURITY_ATTRIBUTES); 41 | sa.bInheritHandle = TRUE; 42 | tty = (int) CreateFile("CONIN$", GENERIC_READ, 43 | FILE_SHARE_READ, &sa, 44 | OPEN_EXISTING, 0L, NULL); 45 | GetConsoleMode((HANDLE)tty, &console_mode); 46 | /* Make sure we get Ctrl+C events. */ 47 | SetConsoleMode((HANDLE)tty, ENABLE_PROCESSED_INPUT); 48 | #else 49 | #if MSDOS_COMPILER 50 | extern int fd0; 51 | /* 52 | * Open a new handle to CON: in binary mode 53 | * for unbuffered keyboard read. 54 | */ 55 | fd0 = dup(0); 56 | close(0); 57 | tty = open("CON", OPEN_READ); 58 | #if MSDOS_COMPILER==DJGPPC 59 | /* 60 | * Setting stdin to binary causes Ctrl-C to not 61 | * raise SIGINT. We must undo that side-effect. 62 | */ 63 | (void) __djgpp_set_ctrl_c(1); 64 | #endif 65 | #else 66 | /* 67 | * Try /dev/tty. 68 | * If that doesn't work, use file descriptor 2, 69 | * which in Unix is usually attached to the screen, 70 | * but also usually lets you read from the keyboard. 71 | */ 72 | #if OS2 73 | /* The __open() system call translates "/dev/tty" to "con". */ 74 | tty = __open("/dev/tty", OPEN_READ); 75 | #else 76 | tty = open("/dev/tty", OPEN_READ); 77 | #endif 78 | if (tty < 0) 79 | tty = 2; 80 | #endif 81 | #endif 82 | } 83 | 84 | /* 85 | * Close the keyboard. 86 | */ 87 | public void 88 | close_getchr() 89 | { 90 | #if MSDOS_COMPILER==WIN32C 91 | SetConsoleMode((HANDLE)tty, console_mode); 92 | CloseHandle((HANDLE)tty); 93 | #endif 94 | } 95 | 96 | /* 97 | * Get a character from the keyboard. 98 | */ 99 | public int 100 | getchr() 101 | { 102 | char c; 103 | int result; 104 | 105 | do 106 | { 107 | #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC 108 | /* 109 | * In raw read, we don't see ^C so look here for it. 110 | */ 111 | flush(); 112 | #if MSDOS_COMPILER==WIN32C 113 | if (ABORT_SIGS()) 114 | return (READ_INTR); 115 | c = WIN32getch(tty); 116 | #else 117 | c = getch(); 118 | #endif 119 | result = 1; 120 | if (c == '\003') 121 | return (READ_INTR); 122 | #else 123 | result = iread(tty, &c, sizeof(char)); 124 | if (result == READ_INTR) 125 | return (READ_INTR); 126 | if (result < 0) 127 | { 128 | /* 129 | * Don't call error() here, 130 | * because error calls getchr! 131 | */ 132 | quit(QUIT_ERROR); 133 | } 134 | #endif 135 | #if 0 /* allow entering arbitrary hex chars for testing */ 136 | /* ctrl-A followed by two hex chars makes a byte */ 137 | { 138 | int hex_in = 0; 139 | int hex_value = 0; 140 | if (c == CONTROL('A')) 141 | { 142 | hex_in = 2; 143 | result = 0; 144 | continue; 145 | } 146 | if (hex_in > 0) 147 | { 148 | int v; 149 | if (c >= '0' && c <= '9') 150 | v = c - '0'; 151 | else if (c >= 'a' && c <= 'f') 152 | v = c - 'a' + 10; 153 | else if (c >= 'A' && c <= 'F') 154 | v = c - 'A' + 10; 155 | else 156 | hex_in = 0; 157 | hex_value = (hex_value << 4) | v; 158 | if (--hex_in > 0) 159 | { 160 | result = 0; 161 | continue; 162 | } 163 | c = hex_value; 164 | } 165 | } 166 | #endif 167 | /* 168 | * Various parts of the program cannot handle 169 | * an input character of '\0'. 170 | * If a '\0' was actually typed, convert it to '\340' here. 171 | */ 172 | if (c == '\0') 173 | c = '\340'; 174 | } while (result != 1); 175 | 176 | return (c & 0xFF); 177 | } 178 | -------------------------------------------------------------------------------- /ubin.uni: -------------------------------------------------------------------------------- 1 | /* Generated by "./mkutable -f2 Cc Cf Cs Co Zl Zp -- unicode/UnicodeData.txt" on Mon Jul 14 16:21:22 PDT 2014 */ 2 | { 0x0000, 0x001f }, /* Cc */ 3 | { 0x007f, 0x009f }, /* Cc */ 4 | { 0x00ad, 0x00ad }, /* Cf */ 5 | { 0x0600, 0x0605 }, /* Cf */ 6 | { 0x061c, 0x061c }, /* Cf */ 7 | { 0x06dd, 0x06dd }, /* Cf */ 8 | { 0x070f, 0x070f }, /* Cf */ 9 | { 0x180e, 0x180e }, /* Cf */ 10 | { 0x200b, 0x200f }, /* Cf */ 11 | { 0x2028, 0x2028 }, /* Zl */ 12 | { 0x2029, 0x2029 }, /* Zp */ 13 | { 0x202a, 0x202e }, /* Cf */ 14 | { 0x2060, 0x2064 }, /* Cf */ 15 | { 0x2066, 0x206f }, /* Cf */ 16 | { 0xd800, 0xd800 }, /* Cs */ 17 | { 0xdb7f, 0xdb80 }, /* Cs */ 18 | { 0xdbff, 0xdc00 }, /* Cs */ 19 | { 0xdfff, 0xdfff }, /* Cs */ 20 | { 0xe000, 0xe000 }, /* Co */ 21 | { 0xf8ff, 0xf8ff }, /* Co */ 22 | { 0xfeff, 0xfeff }, /* Cf */ 23 | { 0xfff9, 0xfffb }, /* Cf */ 24 | { 0x110bd, 0x110bd }, /* Cf */ 25 | { 0x1bca0, 0x1bca3 }, /* Cf */ 26 | { 0x1d173, 0x1d17a }, /* Cf */ 27 | { 0xe0001, 0xe0001 }, /* Cf */ 28 | { 0xe0020, 0xe007f }, /* Cf */ 29 | { 0xf0000, 0xf0000 }, /* Co */ 30 | { 0xffffd, 0xffffd }, /* Co */ 31 | { 0x100000, 0x100000 }, /* Co */ 32 | { 0x10fffd, 0x10fffd }, /* Co */ 33 | -------------------------------------------------------------------------------- /wide.uni: -------------------------------------------------------------------------------- 1 | /* Generated by "./mkutable -f1 W -- unicode/EastAsianWidth.txt" on Mon Jul 14 16:21:23 PDT 2014 */ 2 | { 0x1100, 0x1100 }, /* W */ 3 | { 0x2329, 0x232a }, /* W */ 4 | { 0x2e80, 0x2e80 }, /* W */ 5 | { 0x2e9b, 0x2e9b }, /* W */ 6 | { 0x2f00, 0x2f00 }, /* W */ 7 | { 0x2ff0, 0x2ff0 }, /* W */ 8 | { 0x3001, 0x3001 }, /* W */ 9 | { 0x3004, 0x3012 }, /* W */ 10 | { 0x3014, 0x301e }, /* W */ 11 | { 0x3020, 0x3021 }, /* W */ 12 | { 0x302a, 0x302a }, /* W */ 13 | { 0x302e, 0x302e }, /* W */ 14 | { 0x3030, 0x3031 }, /* W */ 15 | { 0x3036, 0x3036 }, /* W */ 16 | { 0x3038, 0x3038 }, /* W */ 17 | { 0x303b, 0x303e }, /* W */ 18 | { 0x3041, 0x3041 }, /* W */ 19 | { 0x3099, 0x3099 }, /* W */ 20 | { 0x309b, 0x309b }, /* W */ 21 | { 0x309d, 0x309d }, /* W */ 22 | { 0x309f, 0x30a1 }, /* W */ 23 | { 0x30fb, 0x30fc }, /* W */ 24 | { 0x30ff, 0x30ff }, /* W */ 25 | { 0x3105, 0x3105 }, /* W */ 26 | { 0x3131, 0x3131 }, /* W */ 27 | { 0x3190, 0x3190 }, /* W */ 28 | { 0x3192, 0x3192 }, /* W */ 29 | { 0x3196, 0x3196 }, /* W */ 30 | { 0x31a0, 0x31a0 }, /* W */ 31 | { 0x31c0, 0x31c0 }, /* W */ 32 | { 0x31f0, 0x31f0 }, /* W */ 33 | { 0x3200, 0x3200 }, /* W */ 34 | { 0x3220, 0x3220 }, /* W */ 35 | { 0x322a, 0x322a }, /* W */ 36 | { 0x3250, 0x3251 }, /* W */ 37 | { 0x3260, 0x3260 }, /* W */ 38 | { 0x3280, 0x3280 }, /* W */ 39 | { 0x328a, 0x328a }, /* W */ 40 | { 0x32b1, 0x32b1 }, /* W */ 41 | { 0x32c0, 0x32c0 }, /* W */ 42 | { 0x3300, 0x3300 }, /* W */ 43 | { 0x3400, 0x3400 }, /* W */ 44 | { 0x4db6, 0x4db6 }, /* W */ 45 | { 0x4e00, 0x4e00 }, /* W */ 46 | { 0x9fcd, 0x9fcd }, /* W */ 47 | { 0xa000, 0xa000 }, /* W */ 48 | { 0xa015, 0xa016 }, /* W */ 49 | { 0xa490, 0xa490 }, /* W */ 50 | { 0xa960, 0xa960 }, /* W */ 51 | { 0xac00, 0xac00 }, /* W */ 52 | { 0xf900, 0xf900 }, /* W */ 53 | { 0xfa6e, 0xfa6e }, /* W */ 54 | { 0xfa70, 0xfa70 }, /* W */ 55 | { 0xfada, 0xfada }, /* W */ 56 | { 0xfe10, 0xfe10 }, /* W */ 57 | { 0xfe17, 0xfe19 }, /* W */ 58 | { 0xfe30, 0xfe31 }, /* W */ 59 | { 0xfe33, 0xfe33 }, /* W */ 60 | { 0xfe35, 0xfe45 }, /* W */ 61 | { 0xfe47, 0xfe49 }, /* W */ 62 | { 0xfe4d, 0xfe4d }, /* W */ 63 | { 0xfe50, 0xfe50 }, /* W */ 64 | { 0xfe54, 0xfe54 }, /* W */ 65 | { 0xfe58, 0xfe5f }, /* W */ 66 | { 0xfe62, 0xfe64 }, /* W */ 67 | { 0xfe68, 0xfe6a }, /* W */ 68 | { 0x1b000, 0x1b000 }, /* W */ 69 | { 0x1f200, 0x1f200 }, /* W */ 70 | { 0x1f210, 0x1f210 }, /* W */ 71 | { 0x1f240, 0x1f240 }, /* W */ 72 | { 0x1f250, 0x1f250 }, /* W */ 73 | { 0x20000, 0x20000 }, /* W */ 74 | { 0x2a6d7, 0x2a6d7 }, /* W */ 75 | { 0x2a700, 0x2a700 }, /* W */ 76 | { 0x2b735, 0x2b735 }, /* W */ 77 | { 0x2b740, 0x2b740 }, /* W */ 78 | { 0x2b81e, 0x2b81e }, /* W */ 79 | { 0x2f800, 0x2f800 }, /* W */ 80 | { 0x2fa1e, 0x2fa1e }, /* W */ 81 | { 0x30000, 0x30000 }, /* W */ 82 | --------------------------------------------------------------------------------