From 578f50b570b3dc8a65a847616d271dd84c036489 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 25 Aug 2022 17:07:28 -0500 Subject: [PATCH 01/13] less v581.2 (from http://www.greenwoodsoftware.com/less) --- INSTALL | 10 +- Makefile.aut | 18 +- Makefile.wng | 132 ++++++ Makefile.wnm | 2 +- NEWS | 50 +- README | 38 +- brac.c | 2 +- ch.c | 54 +-- charset.c | 154 +++---- charset.h | 2 +- cmd.h | 20 +- cmdbuf.c | 87 ++-- command.c | 189 +++++--- configure | 4 +- configure.ac | 4 +- cvt.c | 12 +- decode.c | 367 ++++++++------- defines.ds | 2 +- defines.h.in | 12 + defines.o2 | 2 +- defines.o9 | 2 +- defines.wn | 2 +- edit.c | 33 +- filename.c | 29 +- forwback.c | 11 +- funcs.h | 35 +- help.c | 24 +- ifile.c | 39 +- input.c | 45 +- jump.c | 2 +- less.h | 419 +++++++++-------- less.hlp | 22 +- less.man | 1244 ++++++++++++++++++++++++++++---------------------- less.nro | 204 +++++++-- lessecho.c | 14 +- lessecho.man | 6 +- lessecho.nro | 8 +- lesskey.c | 163 +++---- lesskey.h | 38 +- lesskey.man | 71 +-- lesskey.nro | 25 +- lglob.h | 110 ++--- line.c | 905 ++++++++++++++++++++---------------- linenum.c | 31 +- lsystem.c | 44 +- main.c | 84 ++-- mark.c | 26 +- mkfuncs.py | 26 ++ mkhelp.py | 36 ++ optfunc.c | 309 +++++++++---- option.c | 25 +- option.h | 62 +-- opttbl.c | 154 +++++-- os.c | 94 +++- output.c | 612 +++++++++++++------------ pattern.c | 11 +- pattern.h | 18 +- pckeys.h | 38 +- position.c | 12 +- position.h | 12 +- prompt.c | 88 ++-- regexp.h | 14 +- screen.c | 796 +++++++++++++++++++++++--------- scrsize.c | 2 +- search.c | 359 +++++++++++---- signal.c | 11 +- tags.c | 77 ++-- ttyin.c | 51 ++- version.c | 30 +- 69 files changed, 4725 insertions(+), 2909 deletions(-) create mode 100644 Makefile.wng create mode 100644 mkfuncs.py create mode 100644 mkhelp.py diff --git a/INSTALL b/INSTALL index c2ab230..78ae932 100644 --- a/INSTALL +++ b/INSTALL @@ -1,6 +1,6 @@ - This file describes how to build and install less using -the "configure" script. This only works on Unix systems. -To install on other systems, read the README file. +This file contains generic instructions on how to build and +install software using autoconf. For specific instructions +on how to build "less", see the README or README.VER file. Basic Installation @@ -24,8 +24,8 @@ diffs or instructions to the address given in the `README' so they can be considered for the next release. If at some point `config.cache' contains results you don't want to keep, you may remove or edit it. - The file `configure.in' is used to create `configure' by a program -called `autoconf'. You only need `configure.in' if you want to change + The file `configure.ac' is used to create `configure' by a program +called `autoconf'. You only need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: diff --git a/Makefile.aut b/Makefile.aut index 89309b5..b6f2101 100644 --- a/Makefile.aut +++ b/Makefile.aut @@ -1,13 +1,21 @@ # Makefile for authoring less. EMAIL = bug-less@gnu.org -HOMEPAGE = http://www.greenwoodsoftware.com/less +HOMEPAGE = https://greenwoodsoftware.com/less SHELL = /bin/sh GIT = git NROFF = nroff -t -man srcdir = . +ifeq ($(USE_PYTHON),1) + MKHELP = mkhelp.py + MKFUNCS = mkfuncs.py +else + MKHELP = mkhelp.pl + MKFUNCS = mkfuncs.pl +endif + SRC = \ main.c screen.c brac.c ch.c charset.c cmdbuf.c \ command.c cvt.c decode.c edit.c filename.c forwback.c \ @@ -19,7 +27,7 @@ DISTFILES_W = \ defines.ds Makefile.dsb Makefile.dsg Makefile.dsu \ defines.o2 Makefile.o2e \ defines.o9 Makefile.o9c Makefile.o9u \ - defines.wn Makefile.wnm Makefile.wnb \ + defines.wn Makefile.wnm Makefile.wnb Makefile.wng \ configure UNICODE_FILES = \ compose.uni fmt.uni ubin.uni wide.uni @@ -33,6 +41,7 @@ DISTFILES = \ less.nro less.man lesskey.nro lesskey.man lessecho.nro lessecho.man \ less.hlp \ mkfuncs.pl mkhelp.pl \ + mkfuncs.py mkhelp.py \ mkutable $(UNICODE_FILES) \ ${DISTFILES_W} @@ -49,7 +58,7 @@ release: .FORCE help.c: less.hlp -mv -f ${srcdir}/help.c ${srcdir}/help.c.old rm -rf help.c - ${srcdir}/mkhelp.pl < less.hlp > help.c + ${srcdir}/${MKHELP} < less.hlp > help.c if cmp -s help.c help.c.old; then mv -f help.c.old help.c; fi ${srcdir}/configure ${srcdir}/defines.h.in: ${srcdir}/configure.ac ${srcdir}/Makefile.in @@ -57,7 +66,7 @@ ${srcdir}/configure ${srcdir}/defines.h.in: ${srcdir}/configure.ac ${srcdir}/Mak funcs.h: ${SRC:%=${srcdir}/%} -mv -f ${srcdir}/funcs.h ${srcdir}/funcs.h.old - perl ${srcdir}/mkfuncs.pl ${SRC:%=${srcdir}/%} >${srcdir}/funcs.h + ${srcdir}/${MKFUNCS} ${SRC:%=${srcdir}/%} >${srcdir}/funcs.h if cmp -s funcs.h funcs.h.old; then mv -f funcs.h.old funcs.h; fi lint: @@ -80,7 +89,6 @@ REPLACE_VERSION = \ sed \ -e "s;@@VERSION@@;$$REL;" \ -e "s;@@DATE@@;$$DT;" \ - -e "s;@@EMAIL@@;${EMAIL};" \ -e "s;@@HOMEPAGE@@;${HOMEPAGE};" >$@ ${srcdir}/README: ${srcdir}/README.VER ${srcdir}/version.c diff --git a/Makefile.wng b/Makefile.wng new file mode 100644 index 0000000..8568606 --- /dev/null +++ b/Makefile.wng @@ -0,0 +1,132 @@ +# Makefile for less using mingw-w64 package: +# http://mingw-w64.org/doku.php +# +# Derived from Makefile.wnm +# +# Usage: mingw32-make -f Makefile.wng [REGEX_PACKAGE={posix|gnu|regcomp-local}] +# +# The optional command line parameter "REGEX_PACKAGE" is used to specify +# a regular expression package for compilation and linking. This parameter +# can assume one of three values. +# +# REGEX_PACKAGE == regcomp-local +# This choice selects the regular expression package written by Henry +# Spencer. It is implemented by the repository file "regexp.c". +# +# REGEX_PACKAGE == posix +# This choice selects the POSIX implementation and is provided by MingW. +# This is the default choice. +# +# REGEX_PACKAGE == gnu +# This choice selects the GNU implementation and is provided by MingW. +# + +#### Start of system configuration section. #### + +CC = gcc + +# Definitions specific to mingw +# +MINGW_DEFINES = -DMINGW -DWIN32 + +# This specifies the "root" directory of the MingW installation. +# It is defined so that the compiler and linker can find the header files +# and library that provide regular expression support. +# +MINGW_ROOT_PATH = /mingw-w64/mingw64 + +# Determine the regular expression package to be used. +# +REGEX_PACKAGE ?= posix +ifeq (${REGEX_PACKAGE},regcomp-local) + MINGW_DEFINES += -DUSE_REGEXP_C +else ifeq (${REGEX_PACKAGE},posix) + MINGW_DEFINES += -DUSE_POSIX_REGCOMP +else ifeq (${REGEX_PACKAGE},gnu) + MINGW_DEFINES += -DUSE_GNU_REGEX +else + $(error REGEX_PACKAGE must be posix, gnu or regcomp-local) +endif + +MINGW_REGEX_IPATH = -I${MINGW_ROOT_PATH}/opt/include +MINGW_REGEX_LPATH = -L${MINGW_ROOT_PATH}/opt/lib +MINGW_REGEX_LIB = -lregex + +CFLAGS_MINGW = ${MINGW_DEFINES} +ifneq (${REGEX_PACKAGE},regcomp-local) +CFLAGS_MINGW += ${MINGW_REGEX_IPATH} +endif + +# MingW may use sh.exe instead of cmd.exe. +# Make sure it does not. +# +SHELL = cmd.exe + +CFLAGS = -O2 ${CFLAGS_MINGW} +ifneq (${REGEX_PACKAGE},regcomp-local) +LDFLAGS = ${MINGW_REGEX_LPATH} +LIBS = ${MINGW_REGEX_LIB} +endif + +#### End of system configuration section. #### + +# This rule allows us to supply the necessary -D options +# in addition to whatever the user asks for. +.c.o: + ${CC} -c -I. ${CFLAGS} $< + +LESS_SRC = brac.c ch.c charset.c cmdbuf.c command.c \ + cvt.c decode.c edit.c filename.c forwback.c \ + ifile.c input.c jump.c line.c linenum.c \ + lsystem.c main.c mark.c optfunc.c option.c \ + opttbl.c os.c output.c pattern.c position.c \ + prompt.c screen.c scrsize.c search.c \ + signal.c tags.c ttyin.c version.c +ifeq (${REGEX_PACKAGE},regcomp-local) +LESS_SRC += regexp.c +endif + +OBJ = \ + main.o screen.o brac.o ch.o charset.o cmdbuf.o \ + command.o cvt.o decode.o edit.o filename.o forwback.o \ + help.o ifile.o input.o jump.o line.o linenum.o \ + lsystem.o mark.o optfunc.o option.o opttbl.o os.o \ + output.o pattern.o position.o prompt.o search.o signal.o \ + tags.o ttyin.o version.o +ifeq (${REGEX_PACKAGE},regcomp-local) +OBJ += regexp.o +endif + + +all: clean less lesskey lessecho + +less: ${OBJ} + ${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS} + +lesskey: lesskey.o version.o + ${CC} ${LDFLAGS} -o $@ lesskey.o version.o + +lessecho: lessecho.o version.o + ${CC} ${LDFLAGS} -o $@ lessecho.o version.o + +defines.h: defines.wn + copy $< $@ + +funcs.h: + perl mkfuncs.pl ${LESS_SRC} > $@ + +help.c: less.hlp + perl mkhelp.pl < $< > $@ + +${OBJ}: less.h defines.h funcs.h + +TAGS: + etags *.c *.h + +clean: + -del *.o + -del *.exe + -del defines.h + -del funcs.h + -del help.c + -if exist TAGS del TAGS diff --git a/Makefile.wnm b/Makefile.wnm index 358fa9f..cc084a7 100644 --- a/Makefile.wnm +++ b/Makefile.wnm @@ -6,7 +6,7 @@ CC = cl # Normal flags -CFLAGS = /nologo /MD /W3 /EHsc /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /c +CFLAGS = /nologo /W3 /EHsc /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /c LDFLAGS = /nologo /subsystem:console /incremental:no # Debugging flags diff --git a/NEWS b/NEWS index b0644fd..bc5afd6 100644 --- a/NEWS +++ b/NEWS @@ -4,10 +4,56 @@ ====================================================================== For the latest news about less, see the "less" Web page: - http://www.greenwoodsoftware.com/less + https://greenwoodsoftware.com/less You can also download the latest version of less from there. - To report bugs, suggestions or comments, send email to bug-less@gnu.org + Report bugs, suggestions or comments at + https://github.com/gwsw/less/issues. + +====================================================================== + + Major changes between "less" versions 563 and 581.2 + +* Change ESC-u command to toggle, not disable, highlighting per man page. + +* Add ESC-U command. + +* Add ctrl-W search modifier for wrapping search. + +* F command can be interrupted by ^X. + +* Support OSC 8 hyperlinks when -R is in effect. + +* g command with no number will ignore -j and put first line at top of screen. + +* Multiple + or -p command line options are handled better. + +* Add the --incsearch option. + +* Add the --line-num-width option. + +* Add the --status-col-width option. + +* Add the --use-color and --color options. + +* Display -w highlight even if highlighted line is empty. + +* If search result is in a long line, scroll to ensure it is visible. + +* Editing the same file under different names now creates only + one entry in the file list. + +* Make visual bell more visible on some terminals. + +* Ring end-of-file bell no more than once per second. + +* Build can use either Python or Perl for Makefile.aut operations. + +* Fix crash when using the @ search modifier. + +* Fix crash in the 's' command due to duplicate free. + +* Fix realpath crash on Darwin. ====================================================================== diff --git a/README b/README index a6ee1df..b5bf899 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ - Less, version 563 + Less, version 581.2 - This is the distribution of less, version 563, released 13 Jun 2020. + This is the distribution of less, version 581.2, released 28 Apr 2021. This program is part of the GNU project (http://www.gnu.org). This program is free software. You may redistribute it and/or @@ -13,33 +13,29 @@ or 2. The Less License, in the file LICENSE. - Please report any problems to bug-less@gnu.org. - See http://www.greenwoodsoftware.com/less for the latest info. + Please report any problems at https://github.com/gwsw/less/issues. + See https://greenwoodsoftware.com/less for the latest info. Source repository is at https://github.com/gwsw/less.git. ========================================================================= -This is the distribution of "less", a paginator similar to "more" or "pg". - The formatted manual page is in less.man. The manual page nroff source is in less.nro. Major changes made since the last posted version are in NEWS. ======================================================================= -PRE-INSTALLATION (when using git) - -If you are building from a clone of a git repository, -type "make -f Makefile.aut". -If you are building from a numbered release package (a tar or zip file -with a name like less-999.tar.gz or less-999.zip), you should skip this step. - -======================================================================= -INSTALLATION (Unix systems only): +INSTALLATION (Unix & Linux systems only): 1. Move the distributed source to its own directory and unpack it, if you have not already done so. -2. Type "sh configure". +2. If you are building from a clone of a git repository, + type "make -f Makefile.aut". + If you are building from a numbered release package (a tar or + zip file with a name like less-999.tar.gz or less-999.zip downloaded + from greenwoodsoftware.com, not from github), you should skip this step. + +3. Type "sh configure". This will generate a Makefile and a defines.h. Warning: if you have a GNU sed, make sure it is version 2.05 or later. @@ -71,7 +67,7 @@ INSTALLATION (Unix systems only): commands, etc. -3. It is a good idea to look over the generated Makefile and defines.h +4. It is a good idea to look over the generated Makefile and defines.h and make sure they look ok. If you know of any peculiarities of your system that configure might not have detected, you may fix the Makefile now. Take particular notice of the list of "terminal" @@ -85,13 +81,13 @@ INSTALLATION (Unix systems only): to remove the descriptions of the features which you are removing. If you edit less.hlp, you should run "make -f Makefile.aut help.c". -4. Type "make" and watch the fun. +5. Type "make" and watch the fun. -5. If the make succeeds, it will generate the programs "less", +6. If the make succeeds, it will generate the programs "less", "lesskey" and "lessecho" in your current directory. Test the generated programs. -6. When satisfied that it works, if you wish to install it +7. When satisfied that it works, if you wish to install it in a public place, type "make install". The default install destinations are: @@ -100,8 +96,6 @@ INSTALLATION (Unix systems only): If you want to install any of these files elsewhere, define bindir and/or mandir to the appropriate directories. -If you have any problems building or running "less", suggestions, -complaints, etc., you may mail to bug-less@gnu.org. Note to hackers: comments noting possible improvements are enclosed in double curly brackets {{ like this }}. diff --git a/brac.c b/brac.c index db3a295..53ada50 100644 --- a/brac.c +++ b/brac.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. diff --git a/ch.c b/ch.c index 70fad10..bab0692 100644 --- a/ch.c +++ b/ch.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -41,7 +41,7 @@ struct bufnode { struct bufnode *hnext, *hprev; }; -#define LBUFSIZE 8192 +#define LBUFSIZE 8192 struct buf { struct bufnode node; BLOCKNUM block; @@ -54,7 +54,7 @@ struct buf { * The file state is maintained in a filestate structure. * A pointer to the filestate is kept in the ifile structure. */ -#define BUFHASH_SIZE 1024 +#define BUFHASH_SIZE 1024 struct filestate { struct bufnode buflist; struct bufnode hashtbl[BUFHASH_SIZE]; @@ -67,24 +67,24 @@ struct filestate { POSITION fsize; }; -#define ch_bufhead thisfile->buflist.next -#define ch_buftail thisfile->buflist.prev -#define ch_nbufs thisfile->nbufs -#define ch_block thisfile->block -#define ch_offset thisfile->offset -#define ch_fpos thisfile->fpos -#define ch_fsize thisfile->fsize -#define ch_flags thisfile->flags -#define ch_file thisfile->file +#define ch_bufhead thisfile->buflist.next +#define ch_buftail thisfile->buflist.prev +#define ch_nbufs thisfile->nbufs +#define ch_block thisfile->block +#define ch_offset thisfile->offset +#define ch_fpos thisfile->fpos +#define ch_fsize thisfile->fsize +#define ch_flags thisfile->flags +#define ch_file thisfile->file -#define END_OF_CHAIN (&thisfile->buflist) -#define END_OF_HCHAIN(h) (&thisfile->hashtbl[h]) -#define BUFHASH(blk) ((blk) & (BUFHASH_SIZE-1)) +#define END_OF_CHAIN (&thisfile->buflist) +#define END_OF_HCHAIN(h) (&thisfile->hashtbl[h]) +#define BUFHASH(blk) ((blk) & (BUFHASH_SIZE-1)) /* * Macros to manipulate the list of buffers in thisfile->buflist. */ -#define FOR_BUFS(bn) \ +#define FOR_BUFS(bn) \ for (bn = ch_bufhead; bn != END_OF_CHAIN; bn = bn->next) #define BUF_RM(bn) \ @@ -106,15 +106,15 @@ struct filestate { /* * Macros to manipulate the list of buffers in thisfile->hashtbl[n]. */ -#define FOR_BUFS_IN_CHAIN(h,bn) \ +#define FOR_BUFS_IN_CHAIN(h,bn) \ for (bn = thisfile->hashtbl[h].hnext; \ bn != END_OF_HCHAIN(h); bn = bn->hnext) -#define BUF_HASH_RM(bn) \ +#define BUF_HASH_RM(bn) \ (bn)->hnext->hprev = (bn)->hprev; \ (bn)->hprev->hnext = (bn)->hnext; -#define BUF_HASH_INS(bn,h) \ +#define BUF_HASH_INS(bn,h) \ (bn)->hnext = thisfile->hashtbl[h].hnext; \ (bn)->hprev = END_OF_HCHAIN(h); \ thisfile->hashtbl[h].hnext->hprev = (bn); \ @@ -240,12 +240,12 @@ ch_get(VOID_PARAM) return ('?'); if (lseek(ch_file, (off_t)pos, SEEK_SET) == BAD_LSEEK) { - error("seek error", NULL_PARG); + error("seek error", NULL_PARG); clear_eol(); return (EOI); - } - ch_fpos = pos; - } + } + ch_fpos = pos; + } /* * Read the block. @@ -311,13 +311,7 @@ ch_get(VOID_PARAM) parg.p_string = wait_message(); ierror("%s", &parg); } -#if !MSDOS_COMPILER - sleep(1); -#else -#if MSDOS_COMPILER==WIN32C - Sleep(1000); -#endif -#endif + sleep_ms(2); /* Reduce system load */ slept = TRUE; #if HAVE_STAT_INO diff --git a/charset.c b/charset.c index 4897cba..b37c8a2 100644 --- a/charset.c +++ b/charset.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -40,27 +40,27 @@ struct charset { int *p_flag; char *desc; } charsets[] = { - { "ascii", NULL, "8bcccbcc18b95.b" }, - { "utf-8", &utf_mode, "8bcccbcc18b95.b126.bb" }, - { "iso8859", NULL, "8bcccbcc18b95.33b." }, - { "latin3", NULL, "8bcccbcc18b95.33b5.b8.b15.b4.b12.b18.b12.b." }, - { "arabic", NULL, "8bcccbcc18b95.33b.3b.7b2.13b.3b.b26.5b19.b" }, - { "greek", NULL, "8bcccbcc18b95.33b4.2b4.b3.b35.b44.b" }, - { "greek2005", NULL, "8bcccbcc18b95.33b14.b35.b44.b" }, - { "hebrew", NULL, "8bcccbcc18b95.33b.b29.32b28.2b2.b" }, - { "koi8-r", NULL, "8bcccbcc18b95.b." }, - { "KOI8-T", NULL, "8bcccbcc18b95.b8.b6.b8.b.b.5b7.3b4.b4.b3.b.b.3b." }, - { "georgianps", NULL, "8bcccbcc18b95.3b11.4b12.2b." }, - { "tcvn", NULL, "b..b...bcccbccbbb7.8b95.b48.5b." }, - { "TIS-620", NULL, "8bcccbcc18b95.b.4b.11b7.8b." }, - { "next", NULL, "8bcccbcc18b95.bb125.bb" }, - { "dos", NULL, "8bcccbcc12bc5b95.b." }, - { "windows-1251", NULL, "8bcccbcc12bc5b95.b24.b." }, - { "windows-1252", NULL, "8bcccbcc12bc5b95.b.b11.b.2b12.b." }, - { "windows-1255", NULL, "8bcccbcc12bc5b95.b.b8.b.5b9.b.4b." }, - { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." }, - { "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" }, - { NULL, NULL, NULL } + { "ascii", NULL, "8bcccbcc18b95.b" }, + { "utf-8", &utf_mode, "8bcccbcc18b95.b126.bb" }, + { "iso8859", NULL, "8bcccbcc18b95.33b." }, + { "latin3", NULL, "8bcccbcc18b95.33b5.b8.b15.b4.b12.b18.b12.b." }, + { "arabic", NULL, "8bcccbcc18b95.33b.3b.7b2.13b.3b.b26.5b19.b" }, + { "greek", NULL, "8bcccbcc18b95.33b4.2b4.b3.b35.b44.b" }, + { "greek2005", NULL, "8bcccbcc18b95.33b14.b35.b44.b" }, + { "hebrew", NULL, "8bcccbcc18b95.33b.b29.32b28.2b2.b" }, + { "koi8-r", NULL, "8bcccbcc18b95.b." }, + { "KOI8-T", NULL, "8bcccbcc18b95.b8.b6.b8.b.b.5b7.3b4.b4.b3.b.b.3b." }, + { "georgianps", NULL, "8bcccbcc18b95.3b11.4b12.2b." }, + { "tcvn", NULL, "b..b...bcccbccbbb7.8b95.b48.5b." }, + { "TIS-620", NULL, "8bcccbcc18b95.b.4b.11b7.8b." }, + { "next", NULL, "8bcccbcc18b95.bb125.bb" }, + { "dos", NULL, "8bcccbcc12bc5b95.b." }, + { "windows-1251", NULL, "8bcccbcc12bc5b95.b24.b." }, + { "windows-1252", NULL, "8bcccbcc12bc5b95.b.b11.b.2b12.b." }, + { "windows-1255", NULL, "8bcccbcc12bc5b95.b.b8.b.5b9.b.4b." }, + { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." }, + { "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" }, + { NULL, NULL, NULL } }; /* @@ -70,58 +70,58 @@ struct cs_alias { char *name; char *oname; } cs_aliases[] = { - { "UTF-8", "utf-8" }, - { "utf8", "utf-8" }, - { "UTF8", "utf-8" }, - { "ANSI_X3.4-1968", "ascii" }, - { "US-ASCII", "ascii" }, - { "latin1", "iso8859" }, - { "ISO-8859-1", "iso8859" }, - { "latin9", "iso8859" }, - { "ISO-8859-15", "iso8859" }, - { "latin2", "iso8859" }, - { "ISO-8859-2", "iso8859" }, - { "ISO-8859-3", "latin3" }, - { "latin4", "iso8859" }, - { "ISO-8859-4", "iso8859" }, - { "cyrillic", "iso8859" }, - { "ISO-8859-5", "iso8859" }, - { "ISO-8859-6", "arabic" }, - { "ISO-8859-7", "greek" }, - { "IBM9005", "greek2005" }, - { "ISO-8859-8", "hebrew" }, - { "latin5", "iso8859" }, - { "ISO-8859-9", "iso8859" }, - { "latin6", "iso8859" }, - { "ISO-8859-10", "iso8859" }, - { "latin7", "iso8859" }, - { "ISO-8859-13", "iso8859" }, - { "latin8", "iso8859" }, - { "ISO-8859-14", "iso8859" }, - { "latin10", "iso8859" }, - { "ISO-8859-16", "iso8859" }, - { "IBM437", "dos" }, - { "EBCDIC-US", "ebcdic" }, - { "IBM1047", "IBM-1047" }, - { "KOI8-R", "koi8-r" }, - { "KOI8-U", "koi8-r" }, - { "GEORGIAN-PS", "georgianps" }, - { "TCVN5712-1", "tcvn" }, - { "NEXTSTEP", "next" }, - { "windows", "windows-1252" }, /* backward compatibility */ - { "CP1251", "windows-1251" }, - { "CP1252", "windows-1252" }, - { "CP1255", "windows-1255" }, + { "UTF-8", "utf-8" }, + { "utf8", "utf-8" }, + { "UTF8", "utf-8" }, + { "ANSI_X3.4-1968", "ascii" }, + { "US-ASCII", "ascii" }, + { "latin1", "iso8859" }, + { "ISO-8859-1", "iso8859" }, + { "latin9", "iso8859" }, + { "ISO-8859-15", "iso8859" }, + { "latin2", "iso8859" }, + { "ISO-8859-2", "iso8859" }, + { "ISO-8859-3", "latin3" }, + { "latin4", "iso8859" }, + { "ISO-8859-4", "iso8859" }, + { "cyrillic", "iso8859" }, + { "ISO-8859-5", "iso8859" }, + { "ISO-8859-6", "arabic" }, + { "ISO-8859-7", "greek" }, + { "IBM9005", "greek2005" }, + { "ISO-8859-8", "hebrew" }, + { "latin5", "iso8859" }, + { "ISO-8859-9", "iso8859" }, + { "latin6", "iso8859" }, + { "ISO-8859-10", "iso8859" }, + { "latin7", "iso8859" }, + { "ISO-8859-13", "iso8859" }, + { "latin8", "iso8859" }, + { "ISO-8859-14", "iso8859" }, + { "latin10", "iso8859" }, + { "ISO-8859-16", "iso8859" }, + { "IBM437", "dos" }, + { "EBCDIC-US", "ebcdic" }, + { "IBM1047", "IBM-1047" }, + { "KOI8-R", "koi8-r" }, + { "KOI8-U", "koi8-r" }, + { "GEORGIAN-PS", "georgianps" }, + { "TCVN5712-1", "tcvn" }, + { "NEXTSTEP", "next" }, + { "windows", "windows-1252" }, /* backward compatibility */ + { "CP1251", "windows-1251" }, + { "CP1252", "windows-1252" }, + { "CP1255", "windows-1255" }, { NULL, NULL } }; -#define IS_BINARY_CHAR 01 -#define IS_CONTROL_CHAR 02 +#define IS_BINARY_CHAR 01 +#define IS_CONTROL_CHAR 02 static char chardef[256]; static char *binfmt = NULL; static char *utfbinfmt = NULL; -public int binattr = AT_STANDOUT; +public int binattr = AT_STANDOUT|AT_COLOR_BIN; /* @@ -134,9 +134,9 @@ public int binattr = AT_STANDOUT; * repetition of the letter. * * Each letter is one of: - * . normal character - * b binary character - * c control character + * . normal character + * b binary character + * c control character */ static void ichardef(s) @@ -457,16 +457,16 @@ prchar(c) SNPRINTF1(buf, sizeof(buf), "^%c", /* * This array roughly inverts CONTROL() #defined in less.h, - * and should be kept in sync with CONTROL() and IBM-1047. - */ + * and should be kept in sync with CONTROL() and IBM-1047. + */ "@ABC.I.?...KLMNO" "PQRS.JH.XY.." "\\]^_" "......W[.....EFG" "..V....D....TU.Z"[c]); #else - else if (c < 128 && !control_char(c ^ 0100)) - SNPRINTF1(buf, sizeof(buf), "^%c", (int) (c ^ 0100)); + else if (c < 128 && !control_char(c ^ 0100)) + SNPRINTF1(buf, sizeof(buf), "^%c", (int) (c ^ 0100)); #endif else SNPRINTF1(buf, sizeof(buf), binfmt, c); @@ -484,7 +484,7 @@ prutfchar(ch) if (ch == ESC) strcpy(buf, "ESC"); - else if (ch < 128 && control_char(ch)) + else if (ch < 128 && control_char(ch)) { if (!control_char(ch ^ 0100)) SNPRINTF1(buf, sizeof(buf), "^%c", ((char) ch) ^ 0100); @@ -732,9 +732,9 @@ step_char(pp, dir, limit) */ #define DECLARE_RANGE_TABLE_START(name) \ - static struct wchar_range name##_array[] = { + static struct wchar_range name##_array[] = { #define DECLARE_RANGE_TABLE_END(name) \ - }; struct wchar_range_table name##_table = { name##_array, sizeof(name##_array)/sizeof(*name##_array) }; + }; struct wchar_range_table name##_table = { name##_array, sizeof(name##_array)/sizeof(*name##_array) }; DECLARE_RANGE_TABLE_START(compose) #include "compose.uni" diff --git a/charset.h b/charset.h index cc0c3af..3e7ecf7 100644 --- a/charset.h +++ b/charset.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. diff --git a/cmd.h b/cmd.h index 95a2e58..c51f0bc 100644 --- a/cmd.h +++ b/cmd.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -31,7 +31,6 @@ #define A_HELP 19 #define A_NEXT_FILE 20 #define A_PERCENT 21 -#define A_PREFIX 22 #define A_PREV_FILE 23 #define A_QUIT 24 #define A_REPAINT 25 @@ -72,19 +71,19 @@ #define A_CLRMARK 62 #define A_SETMARKBOT 63 #define A_X11MOUSE_IN 64 -#define A_X11MOUSE_IGNORE 65 #define A_F_MOUSE 66 #define A_B_MOUSE 67 /* Note "X116" refers to extended (1006) X11 mouse reporting. */ #define A_X116MOUSE_IN 68 -#define A_X116MOUSE_IGNORE 69 +#define A_CLR_SEARCH 70 +/* These values must not conflict with any A_* or EC_* value. */ #define A_INVALID 100 #define A_NOACTION 101 #define A_UINVALID 102 #define A_END_LIST 103 #define A_SPECIAL_KEY 104 - +#define A_PREFIX 105 #define A_SKIP 127 #define A_EXTRA 0200 @@ -111,15 +110,16 @@ #define EC_B_COMPLETE 18 #define EC_LITERAL 19 #define EC_ABORT 20 +#define EC_X11MOUSE 21 +#define EC_X116MOUSE 22 -#define EC_NOACTION 101 #define EC_UINVALID 102 /* Flags for editchar() */ -#define EC_PEEK 01 -#define EC_NOHISTORY 02 -#define EC_NOCOMPLETE 04 -#define EC_NORIGHTLEFT 010 +#define ECF_PEEK 01 +#define ECF_NOHISTORY 02 +#define ECF_NOCOMPLETE 04 +#define ECF_NORIGHTLEFT 010 /* Environment variable stuff */ #define EV_OK 01 diff --git a/cmdbuf.c b/cmdbuf.c index ed78ded..9cc1f3e 100644 --- a/cmdbuf.c +++ b/cmdbuf.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -26,12 +26,12 @@ extern int no_hist_dups; extern int marks_modified; static char cmdbuf[CMDBUF_SIZE]; /* Buffer for holding a multi-char command */ -static int cmd_col; /* Current column of the cursor */ -static int prompt_col; /* Column of cursor just after prompt */ -static char *cp; /* Pointer into cmdbuf */ -static int cmd_offset; /* Index into cmdbuf of first displayed char */ -static int literal; /* Next input char should not be interpreted */ -static int updown_match = -1; /* Prefix length in up/down movement */ +static int cmd_col; /* Current column of the cursor */ +static int prompt_col; /* Column of cursor just after prompt */ +static char *cp; /* Pointer into cmdbuf */ +static int cmd_offset; /* Index into cmdbuf of first displayed char */ +static int literal; /* Next input char should not be interpreted */ +static int updown_match = -1; /* Prefix length in up/down movement */ #if TAB_COMPLETE_FILENAME static int cmd_complete LESSPARAMS((int action)); @@ -223,7 +223,7 @@ cmd_step_common(p, ch, len, pwidth, bswidth) } } if (pwidth != NULL) - *pwidth = width; + *pwidth = width; if (bswidth != NULL) *bswidth = width; return (pr); @@ -259,17 +259,42 @@ cmd_step_left(pp, pwidth, bswidth) return cmd_step_common(*pp, ch, p - *pp, pwidth, bswidth); } +/* + * Put the cursor at "home" (just after the prompt), + * and set cp to the corresponding char in cmdbuf. + */ + static void +cmd_home(VOID_PARAM) +{ + while (cmd_col > prompt_col) + { + int width, bswidth; + + cmd_step_left(&cp, &width, &bswidth); + while (bswidth-- > 0) + putbs(); + cmd_col -= width; + } + + cp = &cmdbuf[cmd_offset]; +} + /* * Repaint the line from cp onwards. * Then position the cursor just after the char old_cp (a pointer into cmdbuf). */ - static void + public void cmd_repaint(old_cp) constant char *old_cp; { /* * Repaint the line from the current position. */ + if (old_cp == NULL) + { + old_cp = cp; + cmd_home(); + } clear_eol(); while (*cp != '\0') { @@ -300,26 +325,6 @@ cmd_repaint(old_cp) cmd_left(); } -/* - * Put the cursor at "home" (just after the prompt), - * and set cp to the corresponding char in cmdbuf. - */ - static void -cmd_home(VOID_PARAM) -{ - while (cmd_col > prompt_col) - { - int width, bswidth; - - cmd_step_left(&cp, &width, &bswidth); - while (bswidth-- > 0) - putbs(); - cmd_col -= width; - } - - cp = &cmdbuf[cmd_offset]; -} - /* * Shift the cmdbuf display left a half-screen. */ @@ -826,9 +831,9 @@ cmd_accept(VOID_PARAM) * Try to perform a line-edit function on the command buffer, * using a specified char as a line-editing command. * Returns: - * CC_PASS The char does not invoke a line edit function. - * CC_OK Line edit function done. - * CC_QUIT The char requests the current command to be aborted. + * CC_PASS The char does not invoke a line edit function. + * CC_OK Line edit function done. + * CC_QUIT The char requests the current command to be aborted. */ static int cmd_edit(c) @@ -838,9 +843,9 @@ cmd_edit(c) int flags; #if TAB_COMPLETE_FILENAME -#define not_in_completion() in_completion = 0 +#define not_in_completion() in_completion = 0 #else -#define not_in_completion(VOID_PARAM) +#define not_in_completion(VOID_PARAM) #endif /* @@ -852,20 +857,22 @@ cmd_edit(c) /* * No current history; don't accept history manipulation cmds. */ - flags |= EC_NOHISTORY; + flags |= ECF_NOHISTORY; #endif #if TAB_COMPLETE_FILENAME if (curr_mlist == ml_search) /* * In a search command; don't accept file-completion cmds. */ - flags |= EC_NOCOMPLETE; + flags |= ECF_NOCOMPLETE; #endif action = editchar(c, flags); switch (action) { + case A_NOACTION: + return (CC_OK); case EC_RIGHT: not_in_completion(); return (cmd_right()); @@ -934,8 +941,6 @@ cmd_edit(c) case EC_EXPAND: return (cmd_complete(action)); #endif - case EC_NOACTION: - return (CC_OK); default: not_in_completion(); return (CC_PASS); @@ -1237,9 +1242,9 @@ cmd_complete(action) * Process a single character of a multi-character command, such as * a number, or the pattern of a search command. * Returns: - * CC_OK The char was accepted. - * CC_QUIT The char requests the command to be aborted. - * CC_ERROR The char could not be accepted due to an error. + * CC_OK The char was accepted. + * CC_QUIT The char requests the command to be aborted. + * CC_ERROR The char could not be accepted due to an error. */ public int cmd_char(c) diff --git a/command.c b/command.c index f578476..cf691a7 100644 --- a/command.c +++ b/command.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -55,21 +55,22 @@ extern void *ml_shell; extern char *editor; extern char *editproto; #endif -extern int screen_trashed; /* The screen has been overwritten */ +extern int screen_trashed; /* The screen has been overwritten */ extern int shift_count; extern int oldbot; extern int forw_prompt; +extern int incr_search; #if MSDOS_COMPILER==WIN32C extern int utf_mode; #endif #if SHELL_ESCAPE -static char *shellcmd = NULL; /* For holding last shell command for "!!" */ +static char *shellcmd = NULL; /* For holding last shell command for "!!" */ #endif -static int mca; /* The multicharacter command (action) */ -static int search_type; /* The previous type of search */ -static LINENUM number; /* The number typed by the user */ -static long fraction; /* The fractional part of the number */ +static int mca; /* The multicharacter command (action) */ +static int search_type; /* The previous type of search */ +static LINENUM number; /* The number typed by the user */ +static long fraction; /* The fractional part of the number */ static struct loption *curropt; static int opt_lower; static int optflag; @@ -111,7 +112,6 @@ set_mca(action) int action; { mca = action; - deinit_mouse(); /* we don't want mouse events while entering a cmd */ clear_bot(); clear_cmd(); } @@ -125,7 +125,6 @@ clear_mca(VOID_PARAM) if (mca == 0) return; mca = 0; - init_mouse(); } /* @@ -175,6 +174,8 @@ mca_search(VOID_PARAM) cmd_putstr("Keep-pos "); if (search_type & SRCH_NO_REGEX) cmd_putstr("Regex-off "); + if (search_type & SRCH_WRAP) + cmd_putstr("Wrap "); #if HILITE_SEARCH if (search_type & SRCH_FILTER) @@ -518,9 +519,9 @@ mca_search_char(c) /* * Certain characters as the first char of * the pattern have special meaning: - * ! Toggle the NO_MATCH flag - * * Toggle the PAST_EOF flag - * @ Toggle the FIRST_FILE flag + * ! Toggle the NO_MATCH flag + * * Toggle the PAST_EOF flag + * @ Toggle the FIRST_FILE flag */ if (len_cmdbuf() > 0) return (NO_MCA); @@ -541,6 +542,10 @@ mca_search_char(c) if (mca != A_FILTER) flag = SRCH_NO_MOVE; break; + case CONTROL('W'): /* WRAP around */ + if (mca != A_FILTER) + flag = SRCH_WRAP; + break; case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */ flag = SRCH_NO_REGEX; break; @@ -552,7 +557,8 @@ mca_search_char(c) if (flag != 0) { - search_type ^= flag; + /* Toggle flag, but keep PAST_EOF and WRAP mutually exclusive. */ + search_type ^= flag | (search_type & (SRCH_PAST_EOF|SRCH_WRAP)); mca_search(); return (MCA_MORE); } @@ -590,9 +596,16 @@ mca_char(c) * Entering digits of a number. * Terminated by a non-digit. */ - if (!((c >= '0' && c <= '9') || c == '.') && - editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == A_INVALID) + if ((c >= '0' && c <= '9') || c == '.') + break; + switch (editchar(c, ECF_PEEK|ECF_NOHISTORY|ECF_NOCOMPLETE|ECF_NORIGHTLEFT)) { + case A_NOACTION: + /* + * Ignore this char and get another one. + */ + return (MCA_MORE); + case A_INVALID: /* * Not part of the number. * End the number and treat this char @@ -645,15 +658,44 @@ mca_char(c) */ return (MCA_DONE); - if ((mca == A_F_BRACKET || mca == A_B_BRACKET) && len_cmdbuf() >= 2) + switch (mca) { - /* - * Special case for the bracket-matching commands. - * Execute the command after getting exactly two - * characters from the user. - */ - exec_mca(); - return (MCA_DONE); + case A_F_BRACKET: + case A_B_BRACKET: + if (len_cmdbuf() >= 2) + { + /* + * Special case for the bracket-matching commands. + * Execute the command after getting exactly two + * characters from the user. + */ + exec_mca(); + return (MCA_DONE); + } + break; + case A_F_SEARCH: + case A_B_SEARCH: + if (incr_search) + { + /* Incremental search: do a search after every input char. */ + int st = (search_type & (SRCH_FORW|SRCH_BACK|SRCH_NO_MATCH|SRCH_NO_REGEX|SRCH_NO_MOVE|SRCH_WRAP)); + char *pattern = get_cmdbuf(); + cmd_exec(); + if (*pattern == '\0') + { + /* User has backspaced to an empty pattern. */ + undo_search(1); + } else + { + if (search(st | SRCH_INCR, pattern, 1) != 0) + /* No match, invalid pattern, etc. */ + undo_search(1); + } + /* Redraw the search prompt and search string. */ + mca_search(); + cmd_repaint(NULL); + } + break; } /* @@ -689,12 +731,6 @@ make_display(VOID_PARAM) if (empty_screen()) { if (initial_scrpos.pos == NULL_POSITION) - /* - * {{ Maybe this should be: - * jump_loc(ch_zero(), jump_sline); - * but this behavior seems rather unexpected - * on the first screen. }} - */ jump_loc(ch_zero(), 1); else jump_loc(initial_scrpos.pos, initial_scrpos.ln); @@ -787,11 +823,16 @@ prompt(VOID_PARAM) clear_cmd(); forw_prompt = 0; p = pr_string(); +#if HILITE_SEARCH if (is_filtering()) putstr("& "); +#endif if (p == NULL || *p == '\0') + { + at_enter(AT_NORMAL|AT_COLOR_PROMPT); putchr(':'); - else + at_exit(); + } else { #if MSDOS_COMPILER==WIN32C WCHAR w[MAX_PATH*2]; @@ -801,7 +842,7 @@ prompt(VOID_PARAM) 0, w, -1, a, sizeof(a), NULL, NULL); p = a; #endif - at_enter(AT_STANDOUT); + at_enter(AT_STANDOUT|AT_COLOR_PROMPT); putstr(p); at_exit(); } @@ -837,7 +878,7 @@ getcc_end_command(VOID_PARAM) return ('\n'); default: /* Some other incomplete command. Let user complete it. */ - return (getchr()); + return ((ungot == NULL) ? getchr() : 0); } } @@ -850,23 +891,26 @@ getcc_end_command(VOID_PARAM) static LWCHAR getccu(VOID_PARAM) { - LWCHAR c; - if (ungot == NULL) + LWCHAR c = 0; + while (c == 0) { - /* Normal case: no ungotten chars. - * Get char from the user. */ - c = getchr(); - } else - { - /* Ungotten chars available: - * Take the top of stack (most recent). */ - struct ungot *ug = ungot; - c = ug->ug_char; - ungot = ug->ug_next; - free(ug); - - if (c == CHAR_END_COMMAND) - c = getcc_end_command(); + if (ungot == NULL) + { + /* Normal case: no ungotten chars. + * Get char from the user. */ + c = getchr(); + } else + { + /* Ungotten chars available: + * Take the top of stack (most recent). */ + struct ungot *ug = ungot; + c = ug->ug_char; + ungot = ug->ug_next; + free(ug); + + if (c == CHAR_END_COMMAND) + c = getcc_end_command(); + } } return (c); } @@ -941,6 +985,28 @@ ungetcc(c) ungot = ug; } +/* + * "Unget" a command character. + * If any other chars are already ungotten, put this one after those. + */ + public void +ungetcc_back(c) + LWCHAR c; +{ + struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot)); + ug->ug_char = c; + ug->ug_next = NULL; + if (ungot == NULL) + ungot = ug; + else + { + struct ungot *pu; + for (pu = ungot; pu->ug_next != NULL; pu = pu->ug_next) + continue; + pu->ug_next = ug; + } +} + /* * Unget a whole string of command characters. * The next sequence of getcc()'s will return this string. @@ -949,10 +1015,8 @@ ungetcc(c) ungetsc(s) char *s; { - char *p; - - for (p = s + strlen(s) - 1; p >= s; p--) - ungetcc(*p); + while (*s != '\0') + ungetcc_back(*s++); } /* @@ -1116,6 +1180,7 @@ commands(VOID_PARAM) int action; char *cbuf; int newaction; + int save_jump_sline; int save_search_type; char *extra; char tbuf[2]; @@ -1417,11 +1482,18 @@ commands(VOID_PARAM) case A_GOLINE: /* * Go to line N, default beginning of file. + * If N <= 0, ignore jump_sline in order to avoid + * empty lines before the beginning of the file. */ + save_jump_sline = jump_sline; if (number <= 0) + { number = 1; + jump_sline = 0; + } cmd_exec(); jump_back(number); + jump_sline = save_jump_sline; break; case A_PERCENT: @@ -1487,7 +1559,7 @@ commands(VOID_PARAM) case A_VERSION: /* - * Print version number, without the "@(#)". + * Print version number. */ cmd_exec(); dispversion(); @@ -1518,10 +1590,10 @@ commands(VOID_PARAM) /* * Define abbreviation for a commonly used sequence below. */ -#define DO_SEARCH() \ - if (number <= 0) number = 1; \ - mca_search(); \ - cmd_exec(); \ +#define DO_SEARCH() \ + if (number <= 0) number = 1; \ + mca_search(); \ + cmd_exec(); \ multi_search((char *)NULL, (int) number, 0); @@ -1598,10 +1670,11 @@ commands(VOID_PARAM) break; case A_UNDO_SEARCH: + case A_CLR_SEARCH: /* * Clear search string highlighting. */ - undo_search(); + undo_search(action == A_CLR_SEARCH); break; case A_HELP: diff --git a/configure b/configure index fda7091..e3be2c0 100644 --- a/configure +++ b/configure @@ -4189,7 +4189,7 @@ if test "x$TERMLIBS" = x; then LIBS="$LIBS $TERMLIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - +#include int main () { @@ -4855,7 +4855,7 @@ cat >>confdefs.h <<_ACEOF _ACEOF -for ac_func in fsync popen _setjmp sigprocmask sigsetmask snprintf stat system fchmod realpath +for ac_func in fchmod fsync nanosleep poll popen realpath _setjmp sigprocmask sigsetmask snprintf stat system ttyname usleep do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index e9aa286..3407736 100644 --- a/configure.ac +++ b/configure.ac @@ -110,7 +110,7 @@ if test "x$TERMLIBS" = x; then TERMLIBS="-lncurses" SAVE_LIBS=$LIBS LIBS="$LIBS $TERMLIBS" - AC_TRY_LINK(, [tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);], + AC_TRY_LINK([#include ], [tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);], [termok=yes], [termok=no]) LIBS=$SAVE_LIBS if test $termok = no; then TERMLIBS=""; fi @@ -274,7 +274,7 @@ AC_TRY_COMPILE([], [int f(int a) { return a; }], # Checks for library functions. AC_TYPE_SIGNAL -AC_CHECK_FUNCS([fsync popen _setjmp sigprocmask sigsetmask snprintf stat system fchmod realpath]) +AC_CHECK_FUNCS([fchmod fsync nanosleep poll popen realpath _setjmp sigprocmask sigsetmask snprintf stat system ttyname usleep]) # AC_CHECK_FUNCS may not work for inline functions, so test these separately. AC_MSG_CHECKING(for memcpy) diff --git a/cvt.c b/cvt.c index e850a51..9cf44b8 100644 --- a/cvt.c +++ b/cvt.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -77,6 +77,7 @@ cvt_text(odst, osrc, chpos, lenp, ops) { int src_pos = (int) (src - osrc); int dst_pos = (int) (dst - odst); + struct ansi_state *pansi; ch = step_char(&src, +1, src_end); if ((ops & CVT_BS) && ch == '\b' && dst > odst) { @@ -85,13 +86,16 @@ cvt_text(odst, osrc, chpos, lenp, ops) dst--; } while (dst > odst && utf_mode && !IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst)); - } else if ((ops & CVT_ANSI) && IS_CSI_START(ch)) + } else if ((ops & CVT_ANSI) && (pansi = ansi_start(ch)) != NULL) { /* Skip to end of ANSI escape sequence. */ - src++; /* skip the CSI start char */ while (src < src_end) - if (!is_ansi_middle(*src++)) + { + if (ansi_step(pansi, ch) != ANSI_MID) break; + ch = *src++; + } + ansi_done(pansi); } else { /* Just copy the char to the destination buffer. */ diff --git a/decode.c b/decode.c index c5467ff..f3bfb7a 100644 --- a/decode.c +++ b/decode.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -14,7 +14,7 @@ * This is all table driven. * A command table is a sequence of command descriptors. * Each command descriptor is a sequence of bytes with the following format: - * ...<0> + * ...<0> * The characters c1,c2,...,cN are the command string; that is, * the characters which the user must type. * It is terminated by a null <0> byte. @@ -48,173 +48,176 @@ extern int sc_height; static unsigned char cmdtable[] = { - '\r',0, A_F_LINE, - '\n',0, A_F_LINE, - 'e',0, A_F_LINE, - 'j',0, A_F_LINE, - SK(SK_DOWN_ARROW),0, A_F_LINE, - CONTROL('E'),0, A_F_LINE, - CONTROL('N'),0, A_F_LINE, - 'k',0, A_B_LINE, - 'y',0, A_B_LINE, - CONTROL('Y'),0, A_B_LINE, - SK(SK_CONTROL_K),0, A_B_LINE, - CONTROL('P'),0, A_B_LINE, - SK(SK_UP_ARROW),0, A_B_LINE, - 'J',0, A_FF_LINE, - 'K',0, A_BF_LINE, - 'Y',0, A_BF_LINE, - 'd',0, A_F_SCROLL, - CONTROL('D'),0, A_F_SCROLL, - 'u',0, A_B_SCROLL, - CONTROL('U'),0, A_B_SCROLL, - ESC,'[','M',0, A_X11MOUSE_IN, - ESC,'[','<',0, A_X116MOUSE_IN, - ' ',0, A_F_SCREEN, - 'f',0, A_F_SCREEN, - CONTROL('F'),0, A_F_SCREEN, - CONTROL('V'),0, A_F_SCREEN, - SK(SK_PAGE_DOWN),0, A_F_SCREEN, - 'b',0, A_B_SCREEN, - CONTROL('B'),0, A_B_SCREEN, - ESC,'v',0, A_B_SCREEN, - SK(SK_PAGE_UP),0, A_B_SCREEN, - 'z',0, A_F_WINDOW, - 'w',0, A_B_WINDOW, - ESC,' ',0, A_FF_SCREEN, - 'F',0, A_F_FOREVER, - ESC,'F',0, A_F_UNTIL_HILITE, - 'R',0, A_FREPAINT, - 'r',0, A_REPAINT, - CONTROL('R'),0, A_REPAINT, - CONTROL('L'),0, A_REPAINT, - ESC,'u',0, A_UNDO_SEARCH, - 'g',0, A_GOLINE, - SK(SK_HOME),0, A_GOLINE, - '<',0, A_GOLINE, - ESC,'<',0, A_GOLINE, - 'p',0, A_PERCENT, - '%',0, A_PERCENT, - ESC,'[',0, A_LSHIFT, - ESC,']',0, A_RSHIFT, - ESC,'(',0, A_LSHIFT, - ESC,')',0, A_RSHIFT, - ESC,'{',0, A_LLSHIFT, - ESC,'}',0, A_RRSHIFT, - SK(SK_RIGHT_ARROW),0, A_RSHIFT, - SK(SK_LEFT_ARROW),0, A_LSHIFT, - SK(SK_CTL_RIGHT_ARROW),0, A_RRSHIFT, - SK(SK_CTL_LEFT_ARROW),0, A_LLSHIFT, - '{',0, A_F_BRACKET|A_EXTRA, '{','}',0, - '}',0, A_B_BRACKET|A_EXTRA, '{','}',0, - '(',0, A_F_BRACKET|A_EXTRA, '(',')',0, - ')',0, A_B_BRACKET|A_EXTRA, '(',')',0, - '[',0, A_F_BRACKET|A_EXTRA, '[',']',0, - ']',0, A_B_BRACKET|A_EXTRA, '[',']',0, - ESC,CONTROL('F'),0, A_F_BRACKET, - ESC,CONTROL('B'),0, A_B_BRACKET, - 'G',0, A_GOEND, - ESC,'G',0, A_GOEND_BUF, - ESC,'>',0, A_GOEND, - '>',0, A_GOEND, - SK(SK_END),0, A_GOEND, - 'P',0, A_GOPOS, - - '0',0, A_DIGIT, - '1',0, A_DIGIT, - '2',0, A_DIGIT, - '3',0, A_DIGIT, - '4',0, A_DIGIT, - '5',0, A_DIGIT, - '6',0, A_DIGIT, - '7',0, A_DIGIT, - '8',0, A_DIGIT, - '9',0, A_DIGIT, - '.',0, A_DIGIT, - - '=',0, A_STAT, - CONTROL('G'),0, A_STAT, - ':','f',0, A_STAT, - '/',0, A_F_SEARCH, - '?',0, A_B_SEARCH, - ESC,'/',0, A_F_SEARCH|A_EXTRA, '*',0, - ESC,'?',0, A_B_SEARCH|A_EXTRA, '*',0, - 'n',0, A_AGAIN_SEARCH, - ESC,'n',0, A_T_AGAIN_SEARCH, - 'N',0, A_REVERSE_SEARCH, - ESC,'N',0, A_T_REVERSE_SEARCH, - '&',0, A_FILTER, - 'm',0, A_SETMARK, - 'M',0, A_SETMARKBOT, - ESC,'m',0, A_CLRMARK, - '\'',0, A_GOMARK, - CONTROL('X'),CONTROL('X'),0, A_GOMARK, - 'E',0, A_EXAMINE, - ':','e',0, A_EXAMINE, - CONTROL('X'),CONTROL('V'),0, A_EXAMINE, - ':','n',0, A_NEXT_FILE, - ':','p',0, A_PREV_FILE, - 't',0, A_NEXT_TAG, - 'T',0, A_PREV_TAG, - ':','x',0, A_INDEX_FILE, - ':','d',0, A_REMOVE_FILE, - '-',0, A_OPT_TOGGLE, - ':','t',0, A_OPT_TOGGLE|A_EXTRA, 't',0, - 's',0, A_OPT_TOGGLE|A_EXTRA, 'o',0, - '_',0, A_DISP_OPTION, - '|',0, A_PIPE, - 'v',0, A_VISUAL, - '!',0, A_SHELL, - '+',0, A_FIRSTCMD, - - 'H',0, A_HELP, - 'h',0, A_HELP, - SK(SK_F1),0, A_HELP, - 'V',0, A_VERSION, - 'q',0, A_QUIT, - 'Q',0, A_QUIT, - ':','q',0, A_QUIT, - ':','Q',0, A_QUIT, - 'Z','Z',0, A_QUIT + '\r',0, A_F_LINE, + '\n',0, A_F_LINE, + 'e',0, A_F_LINE, + 'j',0, A_F_LINE, + SK(SK_DOWN_ARROW),0, A_F_LINE, + CONTROL('E'),0, A_F_LINE, + CONTROL('N'),0, A_F_LINE, + 'k',0, A_B_LINE, + 'y',0, A_B_LINE, + CONTROL('Y'),0, A_B_LINE, + SK(SK_CONTROL_K),0, A_B_LINE, + CONTROL('P'),0, A_B_LINE, + SK(SK_UP_ARROW),0, A_B_LINE, + 'J',0, A_FF_LINE, + 'K',0, A_BF_LINE, + 'Y',0, A_BF_LINE, + 'd',0, A_F_SCROLL, + CONTROL('D'),0, A_F_SCROLL, + 'u',0, A_B_SCROLL, + CONTROL('U'),0, A_B_SCROLL, + ESC,'[','M',0, A_X11MOUSE_IN, + ESC,'[','<',0, A_X116MOUSE_IN, + ' ',0, A_F_SCREEN, + 'f',0, A_F_SCREEN, + CONTROL('F'),0, A_F_SCREEN, + CONTROL('V'),0, A_F_SCREEN, + SK(SK_PAGE_DOWN),0, A_F_SCREEN, + 'b',0, A_B_SCREEN, + CONTROL('B'),0, A_B_SCREEN, + ESC,'v',0, A_B_SCREEN, + SK(SK_PAGE_UP),0, A_B_SCREEN, + 'z',0, A_F_WINDOW, + 'w',0, A_B_WINDOW, + ESC,' ',0, A_FF_SCREEN, + 'F',0, A_F_FOREVER, + ESC,'F',0, A_F_UNTIL_HILITE, + 'R',0, A_FREPAINT, + 'r',0, A_REPAINT, + CONTROL('R'),0, A_REPAINT, + CONTROL('L'),0, A_REPAINT, + ESC,'u',0, A_UNDO_SEARCH, + ESC,'U',0, A_CLR_SEARCH, + 'g',0, A_GOLINE, + SK(SK_HOME),0, A_GOLINE, + '<',0, A_GOLINE, + ESC,'<',0, A_GOLINE, + 'p',0, A_PERCENT, + '%',0, A_PERCENT, + ESC,'[',0, A_LSHIFT, + ESC,']',0, A_RSHIFT, + ESC,'(',0, A_LSHIFT, + ESC,')',0, A_RSHIFT, + ESC,'{',0, A_LLSHIFT, + ESC,'}',0, A_RRSHIFT, + SK(SK_RIGHT_ARROW),0, A_RSHIFT, + SK(SK_LEFT_ARROW),0, A_LSHIFT, + SK(SK_CTL_RIGHT_ARROW),0, A_RRSHIFT, + SK(SK_CTL_LEFT_ARROW),0, A_LLSHIFT, + '{',0, A_F_BRACKET|A_EXTRA, '{','}',0, + '}',0, A_B_BRACKET|A_EXTRA, '{','}',0, + '(',0, A_F_BRACKET|A_EXTRA, '(',')',0, + ')',0, A_B_BRACKET|A_EXTRA, '(',')',0, + '[',0, A_F_BRACKET|A_EXTRA, '[',']',0, + ']',0, A_B_BRACKET|A_EXTRA, '[',']',0, + ESC,CONTROL('F'),0, A_F_BRACKET, + ESC,CONTROL('B'),0, A_B_BRACKET, + 'G',0, A_GOEND, + ESC,'G',0, A_GOEND_BUF, + ESC,'>',0, A_GOEND, + '>',0, A_GOEND, + SK(SK_END),0, A_GOEND, + 'P',0, A_GOPOS, + + '0',0, A_DIGIT, + '1',0, A_DIGIT, + '2',0, A_DIGIT, + '3',0, A_DIGIT, + '4',0, A_DIGIT, + '5',0, A_DIGIT, + '6',0, A_DIGIT, + '7',0, A_DIGIT, + '8',0, A_DIGIT, + '9',0, A_DIGIT, + '.',0, A_DIGIT, + + '=',0, A_STAT, + CONTROL('G'),0, A_STAT, + ':','f',0, A_STAT, + '/',0, A_F_SEARCH, + '?',0, A_B_SEARCH, + ESC,'/',0, A_F_SEARCH|A_EXTRA, '*',0, + ESC,'?',0, A_B_SEARCH|A_EXTRA, '*',0, + 'n',0, A_AGAIN_SEARCH, + ESC,'n',0, A_T_AGAIN_SEARCH, + 'N',0, A_REVERSE_SEARCH, + ESC,'N',0, A_T_REVERSE_SEARCH, + '&',0, A_FILTER, + 'm',0, A_SETMARK, + 'M',0, A_SETMARKBOT, + ESC,'m',0, A_CLRMARK, + '\'',0, A_GOMARK, + CONTROL('X'),CONTROL('X'),0, A_GOMARK, + 'E',0, A_EXAMINE, + ':','e',0, A_EXAMINE, + CONTROL('X'),CONTROL('V'),0, A_EXAMINE, + ':','n',0, A_NEXT_FILE, + ':','p',0, A_PREV_FILE, + 't',0, A_NEXT_TAG, + 'T',0, A_PREV_TAG, + ':','x',0, A_INDEX_FILE, + ':','d',0, A_REMOVE_FILE, + '-',0, A_OPT_TOGGLE, + ':','t',0, A_OPT_TOGGLE|A_EXTRA, 't',0, + 's',0, A_OPT_TOGGLE|A_EXTRA, 'o',0, + '_',0, A_DISP_OPTION, + '|',0, A_PIPE, + 'v',0, A_VISUAL, + '!',0, A_SHELL, + '+',0, A_FIRSTCMD, + + 'H',0, A_HELP, + 'h',0, A_HELP, + SK(SK_F1),0, A_HELP, + 'V',0, A_VERSION, + 'q',0, A_QUIT, + 'Q',0, A_QUIT, + ':','q',0, A_QUIT, + ':','Q',0, A_QUIT, + 'Z','Z',0, A_QUIT }; static unsigned char edittable[] = { - '\t',0, EC_F_COMPLETE, /* TAB */ - '\17',0, EC_B_COMPLETE, /* BACKTAB */ - SK(SK_BACKTAB),0, EC_B_COMPLETE, /* BACKTAB */ - ESC,'\t',0, EC_B_COMPLETE, /* ESC TAB */ - CONTROL('L'),0, EC_EXPAND, /* CTRL-L */ - CONTROL('V'),0, EC_LITERAL, /* BACKSLASH */ - CONTROL('A'),0, EC_LITERAL, /* BACKSLASH */ - ESC,'l',0, EC_RIGHT, /* ESC l */ - SK(SK_RIGHT_ARROW),0, EC_RIGHT, /* RIGHTARROW */ - ESC,'h',0, EC_LEFT, /* ESC h */ - SK(SK_LEFT_ARROW),0, EC_LEFT, /* LEFTARROW */ - ESC,'b',0, EC_W_LEFT, /* ESC b */ - ESC,SK(SK_LEFT_ARROW),0, EC_W_LEFT, /* ESC LEFTARROW */ - SK(SK_CTL_LEFT_ARROW),0, EC_W_LEFT, /* CTRL-LEFTARROW */ - ESC,'w',0, EC_W_RIGHT, /* ESC w */ - ESC,SK(SK_RIGHT_ARROW),0, EC_W_RIGHT, /* ESC RIGHTARROW */ - SK(SK_CTL_RIGHT_ARROW),0, EC_W_RIGHT, /* CTRL-RIGHTARROW */ - ESC,'i',0, EC_INSERT, /* ESC i */ - SK(SK_INSERT),0, EC_INSERT, /* INSERT */ - ESC,'x',0, EC_DELETE, /* ESC x */ - SK(SK_DELETE),0, EC_DELETE, /* DELETE */ - ESC,'X',0, EC_W_DELETE, /* ESC X */ - ESC,SK(SK_DELETE),0, EC_W_DELETE, /* ESC DELETE */ - SK(SK_CTL_DELETE),0, EC_W_DELETE, /* CTRL-DELETE */ - SK(SK_CTL_BACKSPACE),0, EC_W_BACKSPACE, /* CTRL-BACKSPACE */ - ESC,'\b',0, EC_W_BACKSPACE, /* ESC BACKSPACE */ - ESC,'0',0, EC_HOME, /* ESC 0 */ - SK(SK_HOME),0, EC_HOME, /* HOME */ - ESC,'$',0, EC_END, /* ESC $ */ - SK(SK_END),0, EC_END, /* END */ - ESC,'k',0, EC_UP, /* ESC k */ - SK(SK_UP_ARROW),0, EC_UP, /* UPARROW */ - ESC,'j',0, EC_DOWN, /* ESC j */ - SK(SK_DOWN_ARROW),0, EC_DOWN, /* DOWNARROW */ - CONTROL('G'),0, EC_ABORT, /* CTRL-G */ + '\t',0, EC_F_COMPLETE, /* TAB */ + '\17',0, EC_B_COMPLETE, /* BACKTAB */ + SK(SK_BACKTAB),0, EC_B_COMPLETE, /* BACKTAB */ + ESC,'\t',0, EC_B_COMPLETE, /* ESC TAB */ + CONTROL('L'),0, EC_EXPAND, /* CTRL-L */ + CONTROL('V'),0, EC_LITERAL, /* BACKSLASH */ + CONTROL('A'),0, EC_LITERAL, /* BACKSLASH */ + ESC,'l',0, EC_RIGHT, /* ESC l */ + SK(SK_RIGHT_ARROW),0, EC_RIGHT, /* RIGHTARROW */ + ESC,'h',0, EC_LEFT, /* ESC h */ + SK(SK_LEFT_ARROW),0, EC_LEFT, /* LEFTARROW */ + ESC,'b',0, EC_W_LEFT, /* ESC b */ + ESC,SK(SK_LEFT_ARROW),0, EC_W_LEFT, /* ESC LEFTARROW */ + SK(SK_CTL_LEFT_ARROW),0, EC_W_LEFT, /* CTRL-LEFTARROW */ + ESC,'w',0, EC_W_RIGHT, /* ESC w */ + ESC,SK(SK_RIGHT_ARROW),0, EC_W_RIGHT, /* ESC RIGHTARROW */ + SK(SK_CTL_RIGHT_ARROW),0, EC_W_RIGHT, /* CTRL-RIGHTARROW */ + ESC,'i',0, EC_INSERT, /* ESC i */ + SK(SK_INSERT),0, EC_INSERT, /* INSERT */ + ESC,'x',0, EC_DELETE, /* ESC x */ + SK(SK_DELETE),0, EC_DELETE, /* DELETE */ + ESC,'X',0, EC_W_DELETE, /* ESC X */ + ESC,SK(SK_DELETE),0, EC_W_DELETE, /* ESC DELETE */ + SK(SK_CTL_DELETE),0, EC_W_DELETE, /* CTRL-DELETE */ + SK(SK_CTL_BACKSPACE),0, EC_W_BACKSPACE, /* CTRL-BACKSPACE */ + ESC,'\b',0, EC_W_BACKSPACE, /* ESC BACKSPACE */ + ESC,'0',0, EC_HOME, /* ESC 0 */ + SK(SK_HOME),0, EC_HOME, /* HOME */ + ESC,'$',0, EC_END, /* ESC $ */ + SK(SK_END),0, EC_END, /* END */ + ESC,'k',0, EC_UP, /* ESC k */ + SK(SK_UP_ARROW),0, EC_UP, /* UPARROW */ + ESC,'j',0, EC_DOWN, /* ESC j */ + SK(SK_DOWN_ARROW),0, EC_DOWN, /* DOWNARROW */ + CONTROL('G'),0, EC_ABORT, /* CTRL-G */ + ESC,'[','M',0, EC_X11MOUSE, /* X11 mouse report */ + ESC,'[','<',0, EC_X116MOUSE, /* X11 1006 mouse report */ }; /* @@ -487,11 +490,14 @@ getcc_int(pterm) * The prefix ("\e[M") has already been read. */ static int -x11mouse_action(VOID_PARAM) +x11mouse_action(skip) + int skip; { int b = getcc() - X11MOUSE_OFFSET; int x = getcc() - X11MOUSE_OFFSET-1; int y = getcc() - X11MOUSE_OFFSET-1; + if (skip) + return (A_NOACTION); switch (b) { default: return (A_NOACTION); @@ -509,7 +515,8 @@ x11mouse_action(VOID_PARAM) * The prefix ("\e[<") has already been read. */ static int -x116mouse_action(VOID_PARAM) +x116mouse_action(skip) + int skip; { char ch; int x, y; @@ -519,6 +526,8 @@ x116mouse_action(VOID_PARAM) if (x < 0 || ch != ';') return (A_NOACTION); y = getcc_int(&ch) - 1; if (y < 0) return (A_NOACTION); + if (skip) + return (A_NOACTION); switch (b) { case X11MOUSE_WHEEL_DOWN: return mouse_wheel_down(); @@ -580,9 +589,9 @@ cmd_search(cmd, table, endtable, sp) a &= ~A_EXTRA; } if (a == A_X11MOUSE_IN) - a = x11mouse_action(); + a = x11mouse_action(0); else if (a == A_X116MOUSE_IN) - a = x116mouse_action(); + a = x116mouse_action(0); return (a); } } else if (*q == '\0') @@ -924,7 +933,6 @@ editchar(c, flags) #if MSDOS_COMPILER==WIN32C if (!win32_kbhit()) #endif - return (EC_LINEKILL); } @@ -934,15 +942,20 @@ editchar(c, flags) */ nch = 0; do { - if (nch > 0) + if (nch > 0) c = getcc(); usercmd[nch] = c; usercmd[nch+1] = '\0'; nch++; action = ecmd_decode(usercmd, &s); - } while (action == A_PREFIX); - - if (flags & EC_NORIGHTLEFT) + } while (action == A_PREFIX && nch < MAX_CMDLEN); + + if (action == EC_X11MOUSE) + return (x11mouse_action(1)); + if (action == EC_X116MOUSE) + return (x116mouse_action(1)); + + if (flags & ECF_NORIGHTLEFT) { switch (action) { @@ -953,7 +966,7 @@ editchar(c, flags) } } #if CMD_HISTORY - if (flags & EC_NOHISTORY) + if (flags & ECF_NOHISTORY) { /* * The caller says there is no history list. @@ -969,7 +982,7 @@ editchar(c, flags) } #endif #if TAB_COMPLETE_FILENAME - if (flags & EC_NOCOMPLETE) + if (flags & ECF_NOCOMPLETE) { /* * The caller says we don't want any filename completion cmds. @@ -985,7 +998,7 @@ editchar(c, flags) } } #endif - if ((flags & EC_PEEK) || action == A_INVALID) + if ((flags & ECF_PEEK) || action == A_INVALID) { /* * We're just peeking, or we didn't understand the command. diff --git a/defines.ds b/defines.ds index 45512bc..fb02c89 100644 --- a/defines.ds +++ b/defines.ds @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. diff --git a/defines.h.in b/defines.h.in index 36822bc..389a24f 100644 --- a/defines.h.in +++ b/defines.h.in @@ -257,6 +257,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the `nanosleep' function. */ +#undef HAVE_NANOSLEEP + /* Define HAVE_OSPEED if your termcap library has the ospeed variable. */ #undef HAVE_OSPEED @@ -266,6 +269,9 @@ /* PCRE2 (Perl-compatible regular expression) library */ #undef HAVE_PCRE2 +/* Define to 1 if you have the `poll' function. */ +#undef HAVE_POLL + /* Define to 1 if you have the `popen' function. */ #undef HAVE_POPEN @@ -359,12 +365,18 @@ /* Define HAVE_TIME_T if your system supports the "time_t" type. */ #undef HAVE_TIME_T +/* Define to 1 if you have the `ttyname' function. */ +#undef HAVE_TTYNAME + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower. */ #undef HAVE_UPPER_LOWER +/* Define to 1 if you have the `usleep' function. */ +#undef HAVE_USLEEP + /* Henry Spencer V8 regcomp() and regexp.h */ #undef HAVE_V8_REGCOMP diff --git a/defines.o2 b/defines.o2 index 0257f5f..267ef5e 100644 --- a/defines.o2 +++ b/defines.o2 @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. diff --git a/defines.o9 b/defines.o9 index 5d36ca8..22740ef 100644 --- a/defines.o9 +++ b/defines.o9 @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. diff --git a/defines.wn b/defines.wn index 80966df..b8256e1 100644 --- a/defines.wn +++ b/defines.wn @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. diff --git a/edit.c b/edit.c index 3702b50..12631db 100644 --- a/edit.c +++ b/edit.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -20,13 +20,12 @@ public int fd0 = 0; extern int new_file; -extern int errmsgs; extern int cbufs; extern char *every_first_cmd; -extern int any_display; extern int force_open; extern int is_tty; extern int sigs; +extern int hshift; extern IFILE curr_ifile; extern IFILE old_ifile; extern struct scrpos initial_scrpos; @@ -47,7 +46,6 @@ public dev_t curr_dev; public ino_t curr_ino; #endif - /* * Textlist functions deal with a list of words separated by spaces. * init_textlist sets up a textlist structure. @@ -242,7 +240,6 @@ edit_ifile(ifile) { int f; int answer; - int no_display; int chflags; char *filename; char *open_filename; @@ -462,14 +459,12 @@ edit_ifile(ifile) #endif if (every_first_cmd != NULL) { - ungetcc(CHAR_END_COMMAND); ungetsc(every_first_cmd); + ungetcc_back(CHAR_END_COMMAND); } } - no_display = !any_display; flush(); - any_display = TRUE; if (is_tty) { @@ -485,6 +480,7 @@ edit_ifile(ifile) #if HILITE_SEARCH clr_hilite(); #endif + hshift = 0; if (strcmp(filename, FAKE_HELPFILE) && strcmp(filename, FAKE_EMPTYFILE)) { char *qfilename = shell_quote(filename); @@ -492,17 +488,6 @@ edit_ifile(ifile) free(qfilename); } - if (no_display && errmsgs > 0) - { - /* - * We displayed some messages on error output - * (file descriptor 2; see error() function). - * Before erasing the screen contents, - * display the file name and wait for a keystroke. - */ - parg.p_string = filename; - error("%s", &parg); - } } free(filename); return (0); @@ -784,6 +769,8 @@ cat_file(VOID_PARAM) #if LOGFILE +#define OVERWRITE_OPTIONS "Overwrite, Append, Don't log, or Quit?" + /* * If the user asked for a log file and our input file * is standard input, create the log file. @@ -827,7 +814,7 @@ use_logfile(filename) * Ask user what to do. */ parg.p_string = filename; - answer = query("Warning: \"%s\" exists; Overwrite, Append or Don't log? ", &parg); + answer = query("Warning: \"%s\" exists; "OVERWRITE_OPTIONS" ", &parg); } loop: @@ -855,14 +842,12 @@ use_logfile(filename) * Don't do anything. */ return; - case 'q': - quit(QUIT_OK); - /*NOTREACHED*/ default: /* * Eh? */ - answer = query("Overwrite, Append, or Don't log? (Type \"O\", \"A\", \"D\" or \"q\") ", NULL_PARG); + + answer = query(OVERWRITE_OPTIONS" (Type \"O\", \"A\", \"D\" or \"Q\") ", NULL_PARG); goto loop; } diff --git a/filename.c b/filename.c index adb5e64..177cb94 100644 --- a/filename.c +++ b/filename.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -23,7 +23,7 @@ #if MSDOS_COMPILER==DJGPPC #include #include -#define _MAX_PATH PATH_MAX +#define _MAX_PATH PATH_MAX #endif #endif #ifdef _OSK @@ -36,10 +36,10 @@ #if HAVE_STAT #include #ifndef S_ISDIR -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif #ifndef S_ISREG -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #endif #endif @@ -312,7 +312,7 @@ fexpand(s) char *e; IFILE ifile; -#define fchar_ifile(c) \ +#define fchar_ifile(c) \ ((c) == '%' ? curr_ifile : \ (c) == '#' ? old_ifile : NULL_IFILE) @@ -486,9 +486,12 @@ bin_file(f) } else { LWCHAR c = step_char(&p, +1, edata); - if (ctldisp == OPT_ONPLUS && IS_CSI_START(c)) - skip_ansi(&p, edata); - else if (binary_char(c)) + struct ansi_state *pansi; + if (ctldisp == OPT_ONPLUS && (pansi = ansi_start(c)) != NULL) + { + skip_ansi(pansi, &p, edata); + ansi_done(pansi); + } else if (binary_char(c)) bin_count++; } } @@ -648,7 +651,7 @@ lglob(filename) qfilename = shell_quote(p); if (qfilename != NULL) { - length += strlen(qfilename) + 1; + length += strlen(qfilename) + 1; free(qfilename); } } @@ -914,7 +917,7 @@ open_altfile(filename, pf, pfd) int f; /* - * The first time we open the file, read one char + * The alt file is a pipe. Read one char * to see if the pipe will produce any data. * If it does, push the char back on the pipe. */ @@ -931,18 +934,22 @@ open_altfile(filename, pf, pfd) */ int status = pclose(fd); if (returnfd > 1 && status == 0) { + /* File is empty. */ *pfd = NULL; *pf = -1; return (save(FAKE_EMPTYFILE)); } + /* No alt file. */ return (NULL); } + /* Alt pipe contains data, so use it. */ ch_ungetchar(c); *pfd = (void *) fd; *pf = f; return (save("-")); } #endif + /* The alt file is a regular file. Read its name from LESSOPEN. */ cmd = readfd(fd); pclose(fd); if (*cmd == '\0') @@ -972,7 +979,7 @@ close_altfile(altfilename, filename) return; ch_ungetchar(-1); if ((lessclose = lgetenv("LESSCLOSE")) == NULL) - return; + return; if (num_pct_s(lessclose) > 2) { error("LESSCLOSE ignored; must contain no more than 2 %%s", NULL_PARG); diff --git a/forwback.c b/forwback.c index 720054c..e72172b 100644 --- a/forwback.c +++ b/forwback.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -47,6 +47,13 @@ extern char *tagoption; static void eof_bell(VOID_PARAM) { +#if HAVE_TIME + static time_type last_eof_bell = 0; + time_type now = get_time(); + if (now == last_eof_bell) /* max once per second */ + return; + last_eof_bell = now; +#endif if (quiet == NOT_QUIET) bell(); else @@ -185,7 +192,7 @@ forw(n, pos, force, only_last, nblank) { clear(); home(); - } else if (!first_time) + } else if (!first_time && !is_filtering()) { putstr("...skipping...\n"); } diff --git a/funcs.h b/funcs.h index fb3c7bb..1293035 100644 --- a/funcs.h +++ b/funcs.h @@ -11,6 +11,7 @@ public void init_mouse LESSPARAMS ((VOID_PARAM)); public void deinit_mouse LESSPARAMS ((VOID_PARAM)); public void init LESSPARAMS ((VOID_PARAM)); public void deinit LESSPARAMS ((VOID_PARAM)); +public int interactive LESSPARAMS ((VOID_PARAM)); public void home LESSPARAMS ((VOID_PARAM)); public void add_line LESSPARAMS ((VOID_PARAM)); public void remove_top LESSPARAMS ((int n)); @@ -24,12 +25,12 @@ public void bell LESSPARAMS ((VOID_PARAM)); public void clear LESSPARAMS ((VOID_PARAM)); public void clear_eol LESSPARAMS ((VOID_PARAM)); public void clear_bot LESSPARAMS ((VOID_PARAM)); +public COLOR_TYPE parse_color LESSPARAMS ((char *str, int *p_fg, int *p_bg)); public void at_enter LESSPARAMS ((int attr)); public void at_exit LESSPARAMS ((VOID_PARAM)); public void at_switch LESSPARAMS ((int attr)); public int is_at_equiv LESSPARAMS ((int attr1, int attr2)); public int apply_at_specials LESSPARAMS ((int attr)); -public void backspace LESSPARAMS ((VOID_PARAM)); public void putbs LESSPARAMS ((VOID_PARAM)); public int win32_kbhit LESSPARAMS ((VOID_PARAM)); public char WIN32getch LESSPARAMS ((VOID_PARAM)); @@ -75,6 +76,7 @@ public void cmd_reset LESSPARAMS ((VOID_PARAM)); public void clear_cmd LESSPARAMS ((VOID_PARAM)); public void cmd_putstr LESSPARAMS ((constant char *s)); public int len_cmdbuf LESSPARAMS ((VOID_PARAM)); +public void cmd_repaint LESSPARAMS ((constant char *old_cp)); public void set_mlist LESSPARAMS ((void *mlist, int cmdflags)); public void cmd_addhist LESSPARAMS ((struct mlist *mlist, constant char *cmd, int modified)); public void cmd_accept LESSPARAMS ((VOID_PARAM)); @@ -88,6 +90,7 @@ public int in_mca LESSPARAMS ((VOID_PARAM)); public void dispversion LESSPARAMS ((VOID_PARAM)); public int getcc LESSPARAMS ((VOID_PARAM)); public void ungetcc LESSPARAMS ((LWCHAR c)); +public void ungetcc_back LESSPARAMS ((LWCHAR c)); public void ungetsc LESSPARAMS ((char *s)); public LWCHAR peekcc LESSPARAMS ((VOID_PARAM)); public void commands LESSPARAMS ((VOID_PARAM)); @@ -155,6 +158,7 @@ public IFILE getoff_ifile LESSPARAMS ((IFILE ifile)); public int nifile LESSPARAMS ((VOID_PARAM)); public IFILE get_ifile LESSPARAMS ((char *filename, IFILE prev)); public char * get_filename LESSPARAMS ((IFILE ifile)); +public char * get_real_filename LESSPARAMS ((IFILE ifile)); public int get_index LESSPARAMS ((IFILE ifile)); public void store_pos LESSPARAMS ((IFILE ifile, struct scrpos *scrpos)); public void get_pos LESSPARAMS ((IFILE ifile, struct scrpos *scrpos)); @@ -169,6 +173,7 @@ public void * get_altpipe LESSPARAMS ((IFILE ifile)); public void set_altfilename LESSPARAMS ((IFILE ifile, char *altfilename)); public char * get_altfilename LESSPARAMS ((IFILE ifile)); public void if_dump LESSPARAMS ((VOID_PARAM)); +public POSITION forw_line_seg LESSPARAMS ((POSITION curr_pos, int get_segpos)); public POSITION forw_line LESSPARAMS ((POSITION curr_pos)); public POSITION back_line LESSPARAMS ((POSITION curr_pos)); public void set_attnpos LESSPARAMS ((POSITION pos)); @@ -182,20 +187,27 @@ public void jump_loc LESSPARAMS ((POSITION pos, int sline)); public void init_line LESSPARAMS ((VOID_PARAM)); public int is_ascii_char LESSPARAMS ((LWCHAR ch)); public void prewind LESSPARAMS ((VOID_PARAM)); -public void plinenum LESSPARAMS ((POSITION pos)); +public void plinestart LESSPARAMS ((POSITION pos)); +public int line_pfx_width LESSPARAMS ((VOID_PARAM)); public void pshift_all LESSPARAMS ((VOID_PARAM)); +public int pwidth LESSPARAMS ((LWCHAR ch, int a, LWCHAR prev_ch, int prev_a)); public int is_ansi_end LESSPARAMS ((LWCHAR ch)); public int is_ansi_middle LESSPARAMS ((LWCHAR ch)); -public void skip_ansi LESSPARAMS ((char **pp, constant char *limit)); +public void skip_ansi LESSPARAMS ((struct ansi_state *pansi, char **pp, constant char *limit)); +public struct ansi_state * ansi_start LESSPARAMS ((LWCHAR ch)); +public int ansi_step LESSPARAMS ((struct ansi_state *pansi, LWCHAR ch)); +public void ansi_done LESSPARAMS ((struct ansi_state *pansi)); public int pappend LESSPARAMS ((int c, POSITION pos)); public int pflushmbc LESSPARAMS ((VOID_PARAM)); public void pdone LESSPARAMS ((int endline, int chopped, int forw)); -public void set_status_col LESSPARAMS ((int c)); +public void set_status_col LESSPARAMS ((int c, int attr)); public int gline LESSPARAMS ((int i, int *ap)); public void null_line LESSPARAMS ((VOID_PARAM)); public POSITION forw_raw_line LESSPARAMS ((POSITION curr_pos, char **linep, int *line_lenp)); public POSITION back_raw_line LESSPARAMS ((POSITION curr_pos, char **linep, int *line_lenp)); public int rrshift LESSPARAMS ((VOID_PARAM)); +public int set_color_map LESSPARAMS ((int attr, char *colorstr)); +public char * get_color_map LESSPARAMS ((int attr)); public void clr_linenum LESSPARAMS ((VOID_PARAM)); public void add_lnum LESSPARAMS ((LINENUM linenum, POSITION pos)); public LINENUM find_linenum LESSPARAMS ((POSITION pos)); @@ -237,6 +249,10 @@ public void opt_rscroll LESSPARAMS ((int type, char *s)); public void opt_query LESSPARAMS ((int type, char *s)); public void opt_mousecap LESSPARAMS ((int type, char *s)); public void opt_wheel_lines LESSPARAMS ((int type, char *s)); +public void opt_linenum_width LESSPARAMS ((int type, char *s)); +public void opt_status_col_width LESSPARAMS ((int type, char *s)); +public void opt_ttyin_name LESSPARAMS ((int type, char *s)); +public void opt_rstat LESSPARAMS ((int type, char *s)); public int get_swindow LESSPARAMS ((VOID_PARAM)); public char * propt LESSPARAMS ((int c)); public void scan_option LESSPARAMS ((char *s)); @@ -259,15 +275,18 @@ public char * errno_message LESSPARAMS ((char *filename)); public int percentage LESSPARAMS ((POSITION num, POSITION den)); public POSITION percent_pos LESSPARAMS ((POSITION pos, int percent, long fraction)); public int os9_signal LESSPARAMS ((int type, RETSIGTYPE (*handler)())); +public void sleep_ms LESSPARAMS ((int ms)); public void put_line LESSPARAMS ((VOID_PARAM)); public void flush LESSPARAMS ((VOID_PARAM)); +public void set_output LESSPARAMS ((int fd)); public int putchr LESSPARAMS ((int c)); public void putstr LESSPARAMS ((constant char *s)); +public int less_printf LESSPARAMS ((char *fmt, PARG *parg)); public void get_return LESSPARAMS ((VOID_PARAM)); public void error LESSPARAMS ((char *fmt, PARG *parg)); public void ierror LESSPARAMS ((char *fmt, PARG *parg)); public int query LESSPARAMS ((char *fmt, PARG *parg)); -public int compile_pattern LESSPARAMS ((char *pattern, int search_type, PATTERN_TYPE *comp_pattern)); +public int compile_pattern LESSPARAMS ((char *pattern, int search_type, int show_error, PATTERN_TYPE *comp_pattern)); public void uncompile_pattern LESSPARAMS ((PATTERN_TYPE *pattern)); public int valid_pattern LESSPARAMS ((char *pattern)); public int is_null_pattern LESSPARAMS ((PATTERN_TYPE pattern)); @@ -291,14 +310,14 @@ public char * wait_message LESSPARAMS ((VOID_PARAM)); public void init_search LESSPARAMS ((VOID_PARAM)); public void repaint_hilite LESSPARAMS ((int on)); public void clear_attn LESSPARAMS ((VOID_PARAM)); -public void undo_search LESSPARAMS ((VOID_PARAM)); +public void undo_search LESSPARAMS ((int clear)); public void clr_hlist LESSPARAMS ((struct hilite_tree *anchor)); public void clr_hilite LESSPARAMS ((VOID_PARAM)); public void clr_filter LESSPARAMS ((VOID_PARAM)); public int is_filtered LESSPARAMS ((POSITION pos)); public POSITION next_unfiltered LESSPARAMS ((POSITION pos)); public POSITION prev_unfiltered LESSPARAMS ((POSITION pos)); -public int is_hilited LESSPARAMS ((POSITION pos, POSITION epos, int nohide, int *p_matches)); +public int is_hilited_attr LESSPARAMS ((POSITION pos, POSITION epos, int nohide, int *p_matches)); public void chg_hilite LESSPARAMS ((VOID_PARAM)); public void chg_caseless LESSPARAMS ((VOID_PARAM)); public int search LESSPARAMS ((int search_type, char *pattern, int n)); @@ -317,7 +336,9 @@ public char * prevtag LESSPARAMS ((int n)); public int ntags LESSPARAMS ((VOID_PARAM)); public int curr_tag LESSPARAMS ((VOID_PARAM)); public int edit_tagfile LESSPARAMS ((VOID_PARAM)); +public char * tty_device LESSPARAMS ((VOID_PARAM)); public void open_getchr LESSPARAMS ((VOID_PARAM)); public void close_getchr LESSPARAMS ((VOID_PARAM)); public int default_wheel_lines LESSPARAMS ((VOID_PARAM)); +public void rstat LESSPARAMS ((char st)); public int getchr LESSPARAMS ((VOID_PARAM)); diff --git a/help.c b/help.c index cfaa578..f5b4aa1 100644 --- a/help.c +++ b/help.c @@ -1,4 +1,4 @@ -/* This file was generated by mkhelp.pl from less.hlp at 3:34 on 2020/6/14 */ +/* This file was generated by mkhelp.pl from less.hlp at 14:59 on 2021/4/28 */ #include "less.h" constant char helpdata[] = { '\n', @@ -45,7 +45,8 @@ constant char helpdata[] = { ' ',' ','E','S','C','-','n',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','R','e','p','e','a','t',' ','p','r','e','v','i','o','u','s',' ','s','e','a','r','c','h',',',' ','s','p','a','n','n','i','n','g',' ','f','i','l','e','s','.','\n', ' ',' ','E','S','C','-','N',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','R','e','p','e','a','t',' ','p','r','e','v','i','o','u','s',' ','s','e','a','r','c','h',',',' ','r','e','v','e','r','s','e',' ','d','i','r','.',' ','&',' ','s','p','a','n','n','i','n','g',' ','f','i','l','e','s','.','\n', ' ',' ','E','S','C','-','u',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','U','n','d','o',' ','(','t','o','g','g','l','e',')',' ','s','e','a','r','c','h',' ','h','i','g','h','l','i','g','h','t','i','n','g','.','\n', -' ',' ','&','_','\b','p','_','\b','a','_','\b','t','_','\b','t','_','\b','e','_','\b','r','_','\b','n',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','D','i','s','p','l','a','y',' ','o','n','l','y',' ','m','a','t','c','h','i','n','g',' ','l','i','n','e','s','\n', +' ',' ','E','S','C','-','U',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','C','l','e','a','r',' ','s','e','a','r','c','h',' ','h','i','g','h','l','i','g','h','t','i','n','g','.','\n', +' ',' ','&','_','\b','p','_','\b','a','_','\b','t','_','\b','t','_','\b','e','_','\b','r','_','\b','n',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','D','i','s','p','l','a','y',' ','o','n','l','y',' ','m','a','t','c','h','i','n','g',' ','l','i','n','e','s','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','\n', ' ',' ',' ',' ',' ',' ',' ',' ','A',' ','s','e','a','r','c','h',' ','p','a','t','t','e','r','n',' ','m','a','y',' ','b','e','g','i','n',' ','w','i','t','h',' ','o','n','e',' ','o','r',' ','m','o','r','e',' ','o','f',':','\n', ' ',' ',' ',' ',' ',' ',' ',' ','^','N',' ','o','r',' ','!',' ',' ','S','e','a','r','c','h',' ','f','o','r',' ','N','O','N','-','m','a','t','c','h','i','n','g',' ','l','i','n','e','s','.','\n', @@ -53,6 +54,7 @@ constant char helpdata[] = { ' ',' ',' ',' ',' ',' ',' ',' ','^','F',' ','o','r',' ','@',' ',' ','S','t','a','r','t',' ','s','e','a','r','c','h',' ','a','t',' ','F','I','R','S','T',' ','f','i','l','e',' ','(','f','o','r',' ','/',')',' ','o','r',' ','l','a','s','t',' ','f','i','l','e',' ','(','f','o','r',' ','?',')','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ','^','K',' ',' ',' ',' ',' ',' ',' ','H','i','g','h','l','i','g','h','t',' ','m','a','t','c','h','e','s',',',' ','b','u','t',' ','d','o','n','\'','t',' ','m','o','v','e',' ','(','K','E','E','P',' ','p','o','s','i','t','i','o','n',')','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ','^','R',' ',' ',' ',' ',' ',' ',' ','D','o','n','\'','t',' ','u','s','e',' ','R','E','G','U','L','A','R',' ','E','X','P','R','E','S','S','I','O','N','S','.','\n', +' ',' ',' ',' ',' ',' ',' ',' ','^','W',' ',' ',' ',' ',' ',' ',' ','W','R','A','P',' ','s','e','a','r','c','h',' ','i','f',' ','n','o',' ','m','a','t','c','h',' ','f','o','u','n','d','.','\n', ' ','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','\n', '\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','J','\b','J','U','\b','U','M','\b','M','P','\b','P','I','\b','I','N','\b','N','G','\b','G','\n', @@ -65,7 +67,7 @@ constant char helpdata[] = { ' ',' ','{',' ',' ','(',' ',' ','[',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','F','i','n','d',' ','c','l','o','s','e',' ','b','r','a','c','k','e','t',' ','}',' ',')',' ',']','.','\n', ' ',' ','}',' ',' ',')',' ',' ',']',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','F','i','n','d',' ','o','p','e','n',' ','b','r','a','c','k','e','t',' ','{',' ','(',' ','[','.','\n', ' ',' ','E','S','C','-','^','F',' ','_','\b','<','_','\b','c','_','\b','1','_','\b','>',' ','_','\b','<','_','\b','c','_','\b','2','_','\b','>',' ',' ','*',' ',' ','F','i','n','d',' ','c','l','o','s','e',' ','b','r','a','c','k','e','t',' ','_','\b','<','_','\b','c','_','\b','2','_','\b','>','.','\n', -' ',' ','E','S','C','-','^','B',' ','_','\b','<','_','\b','c','_','\b','1','_','\b','>',' ','_','\b','<','_','\b','c','_','\b','2','_','\b','>',' ',' ','*',' ',' ','F','i','n','d',' ','o','p','e','n',' ','b','r','a','c','k','e','t',' ','_','\b','<','_','\b','c','_','\b','1','_','\b','>',' ','\n', +' ',' ','E','S','C','-','^','B',' ','_','\b','<','_','\b','c','_','\b','1','_','\b','>',' ','_','\b','<','_','\b','c','_','\b','2','_','\b','>',' ',' ','*',' ',' ','F','i','n','d',' ','o','p','e','n',' ','b','r','a','c','k','e','t',' ','_','\b','<','_','\b','c','_','\b','1','_','\b','>','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','\n', ' ',' ',' ',' ',' ',' ',' ',' ','E','a','c','h',' ','"','f','i','n','d',' ','c','l','o','s','e',' ','b','r','a','c','k','e','t','"',' ','c','o','m','m','a','n','d',' ','g','o','e','s',' ','f','o','r','w','a','r','d',' ','t','o',' ','t','h','e',' ','c','l','o','s','e',' ','b','r','a','c','k','e','t',' ','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','m','a','t','c','h','i','n','g',' ','t','h','e',' ','(','_','\b','N','-','t','h',')',' ','o','p','e','n',' ','b','r','a','c','k','e','t',' ','i','n',' ','t','h','e',' ','t','o','p',' ','l','i','n','e','.','\n', @@ -132,8 +134,8 @@ constant char helpdata[] = { ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','R','e','p','a','i','n','t',' ','b','y',' ','c','l','e','a','r','i','n','g',' ','r','a','t','h','e','r',' ','t','h','a','n',' ','s','c','r','o','l','l','i','n','g','.','\n', ' ',' ','-','d',' ',' ','.','.','.','.','.','.','.','.',' ',' ','-','-','d','u','m','b','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','D','u','m','b',' ','t','e','r','m','i','n','a','l','.','\n', -' ',' ','-','D',' ','[','_','\b','x','_','\b','n','_','\b','.','_','\b','n',']',' ',' ','.',' ',' ','-','-','c','o','l','o','r','=','_','\b','x','_','\b','n','_','\b','.','_','\b','n','\n', -' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','s','c','r','e','e','n',' ','c','o','l','o','r','s','.',' ','(','M','S','-','D','O','S',' ','o','n','l','y',')','\n', +' ',' ','-','D',' ','x','\b','x','_','\b','c','_','\b','o','_','\b','l','_','\b','o','_','\b','r',' ',' ','.',' ',' ','-','-','c','o','l','o','r','=','x','\b','x','_','\b','c','_','\b','o','_','\b','l','_','\b','o','_','\b','r','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','s','c','r','e','e','n',' ','c','o','l','o','r','s','.','\n', ' ',' ','-','e',' ',' ','-','E',' ',' ','.','.','.','.',' ',' ','-','-','q','u','i','t','-','a','t','-','e','o','f',' ',' ','-','-','Q','U','I','T','-','A','T','-','E','O','F','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','Q','u','i','t',' ','a','t',' ','e','n','d',' ','o','f',' ','f','i','l','e','.','\n', ' ',' ','-','f',' ',' ','.','.','.','.','.','.','.','.',' ',' ','-','-','f','o','r','c','e','\n', @@ -205,9 +207,13 @@ constant char helpdata[] = { ' ',' ','-','~',' ',' ','.','.','.','.','.','.','.','.',' ',' ','-','-','t','i','l','d','e','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','D','o','n','\'','t',' ','d','i','s','p','l','a','y',' ','t','i','l','d','e','s',' ','a','f','t','e','r',' ','e','n','d',' ','o','f',' ','f','i','l','e','.','\n', ' ',' ','-','#',' ','[','_','\b','N',']',' ',' ','.','.','.','.',' ',' ','-','-','s','h','i','f','t','=','[','_','\b','N',']','\n', -' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','H','o','r','i','z','o','n','t','a','l',' ','s','c','r','o','l','l',' ','a','m','o','u','n','t',' ','(','0',' ','=',' ','o','n','e',' ','h','a','l','f',' ','s','c','r','e','e','n',' ','w','i','d','t','h',')','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','h','o','r','i','z','o','n','t','a','l',' ','s','c','r','o','l','l',' ','a','m','o','u','n','t',' ','(','0',' ','=',' ','o','n','e',' ','h','a','l','f',' ','s','c','r','e','e','n',' ','w','i','d','t','h',')','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','f','o','l','l','o','w','-','n','a','m','e','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','T','h','e',' ','F',' ','c','o','m','m','a','n','d',' ','c','h','a','n','g','e','s',' ','f','i','l','e','s',' ','i','f',' ','t','h','e',' ','i','n','p','u','t',' ','f','i','l','e',' ','i','s',' ','r','e','n','a','m','e','d','.','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','i','n','c','s','e','a','r','c','h','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','e','a','r','c','h',' ','f','i','l','e',' ','a','s',' ','e','a','c','h',' ','p','a','t','t','e','r','n',' ','c','h','a','r','a','c','t','e','r',' ','i','s',' ','t','y','p','e','d',' ','i','n','.','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','l','i','n','e','-','n','u','m','-','w','i','d','t','h','=','N','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','t','h','e',' ','w','i','d','t','h',' ','o','f',' ','t','h','e',' ','-','N',' ','l','i','n','e',' ','n','u','m','b','e','r',' ','f','i','e','l','d',' ','t','o',' ','N',' ','c','h','a','r','a','c','t','e','r','s','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','m','o','u','s','e','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','E','n','a','b','l','e',' ','m','o','u','s','e',' ','i','n','p','u','t','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','n','o','-','k','e','y','p','a','d','\n', @@ -218,8 +224,12 @@ constant char helpdata[] = { ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','t','h','e',' ','c','h','a','r','a','c','t','e','r',' ','u','s','e','d',' ','t','o',' ','m','a','r','k',' ','t','r','u','n','c','a','t','e','d',' ','l','i','n','e','s','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','s','a','v','e','-','m','a','r','k','s','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','R','e','t','a','i','n',' ','m','a','r','k','s',' ','a','c','r','o','s','s',' ','i','n','v','o','c','a','t','i','o','n','s',' ','o','f',' ','l','e','s','s','.','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','s','t','a','t','u','s','-','c','o','l','-','w','i','d','t','h','=','N','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','t','h','e',' ','w','i','d','t','h',' ','o','f',' ','t','h','e',' ','-','J',' ','s','t','a','t','u','s',' ','c','o','l','u','m','n',' ','t','o',' ','N',' ','c','h','a','r','a','c','t','e','r','s','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','u','s','e','-','b','a','c','k','s','l','a','s','h','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','u','b','s','e','q','u','e','n','t',' ','o','p','t','i','o','n','s',' ','u','s','e',' ','b','a','c','k','s','l','a','s','h',' ','a','s',' ','e','s','c','a','p','e',' ','c','h','a','r','.','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','u','s','e','-','c','o','l','o','r','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','E','n','a','b','l','e','s',' ','c','o','l','o','r','e','d',' ','t','e','x','t','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','w','h','e','e','l','-','l','i','n','e','s','=','N','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','E','a','c','h',' ','c','l','i','c','k',' ','o','f',' ','t','h','e',' ','m','o','u','s','e',' ','w','h','e','e','l',' ','m','o','v','e','s',' ','N',' ','l','i','n','e','s','.','\n', '\n', @@ -247,7 +257,5 @@ constant char helpdata[] = { ' ','T','A','B',' ','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' ','C','o','m','p','l','e','t','e',' ','f','i','l','e','n','a','m','e',' ','&',' ','c','y','c','l','e','.','\n', ' ','S','H','I','F','T','-','T','A','B',' ','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' ','E','S','C','-','T','A','B',' ',' ',' ','C','o','m','p','l','e','t','e',' ','f','i','l','e','n','a','m','e',' ','&',' ','r','e','v','e','r','s','e',' ','c','y','c','l','e','.','\n', ' ','c','t','r','l','-','L',' ','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.',' ','C','o','m','p','l','e','t','e',' ','f','i','l','e','n','a','m','e',',',' ','l','i','s','t',' ','a','l','l','.','\n', -'\n', -'\n', 0 }; constant int size_helpdata = sizeof(helpdata) - 1; diff --git a/ifile.c b/ifile.c index 6006cb1..bc47a66 100644 --- a/ifile.c +++ b/ifile.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -21,12 +21,13 @@ #include "less.h" -extern IFILE curr_ifile; +extern IFILE curr_ifile; struct ifile { struct ifile *h_next; /* Links for command line list */ struct ifile *h_prev; char *h_filename; /* Name of the file */ + char *h_rfilename; /* Canonical name of the file */ void *h_filestate; /* File state (used in ch.c) */ int h_index; /* Index within command line list */ int h_hold; /* Hold count */ @@ -40,13 +41,13 @@ struct ifile { * Convert an IFILE (external representation) * to a struct file (internal representation), and vice versa. */ -#define int_ifile(h) ((struct ifile *)(h)) -#define ext_ifile(h) ((IFILE)(h)) +#define int_ifile(h) ((struct ifile *)(h)) +#define ext_ifile(h) ((IFILE)(h)) /* * Anchor for linked list. */ -static struct ifile anchor = { &anchor, &anchor, NULL, NULL, 0, 0, '\0', +static struct ifile anchor = { &anchor, &anchor, NULL, NULL, NULL, 0, 0, '\0', { NULL_POSITION, 0 } }; static int ifiles = 0; @@ -116,10 +117,13 @@ new_ifile(filename, prev) */ p = (struct ifile *) ecalloc(1, sizeof(struct ifile)); p->h_filename = save(filename); + p->h_rfilename = lrealpath(filename); p->h_scrpos.pos = NULL_POSITION; p->h_opened = 0; p->h_hold = 0; p->h_filestate = NULL; + p->h_altfilename = NULL; + p->h_altpipe = NULL; link_ifile(p, prev); /* * {{ It's dodgy to call mark.c functions from here; @@ -150,6 +154,7 @@ del_ifile(h) curr_ifile = getoff_ifile(curr_ifile); p = int_ifile(h); unlink_ifile(p); + free(p->h_rfilename); free(p->h_filename); free(p); } @@ -221,15 +226,17 @@ find_ifile(filename) for (p = anchor.h_next; p != &anchor; p = p->h_next) { - if (strcmp(filename, p->h_filename) == 0 || - strcmp(rfilename, p->h_filename) == 0) + if (strcmp(rfilename, p->h_rfilename) == 0) { /* * If given name is shorter than the name we were * previously using for this file, adopt shorter name. */ if (strlen(filename) < strlen(p->h_filename)) - strcpy(p->h_filename, filename); + { + free(p->h_filename); + p->h_filename = save(filename); + } break; } } @@ -257,7 +264,7 @@ get_ifile(filename, prev) } /* - * Get the filename associated with a ifile. + * Get the display filename associated with a ifile. */ public char * get_filename(ifile) @@ -268,6 +275,18 @@ get_filename(ifile) return (int_ifile(ifile)->h_filename); } +/* + * Get the canonical filename associated with a ifile. + */ + public char * +get_real_filename(ifile) + IFILE ifile; +{ + if (ifile == NULL) + return (NULL); + return (int_ifile(ifile)->h_rfilename); +} + /* * Get the index of the file associated with a ifile. */ @@ -372,7 +391,7 @@ set_altfilename(ifile, altfilename) char *altfilename; { struct ifile *p = int_ifile(ifile); - if (p->h_altfilename != NULL) + if (p->h_altfilename != NULL && p->h_altfilename != altfilename) free(p->h_altfilename); p->h_altfilename = altfilename; } diff --git a/input.c b/input.c index 526fe4b..f57c9e3 100644 --- a/input.c +++ b/input.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -31,6 +31,7 @@ extern POSITION end_attnpos; #if HILITE_SEARCH extern int hilite_search; extern int size_linebuf; +extern int show_attn; #endif /* @@ -41,8 +42,9 @@ extern int size_linebuf; * of the NEXT line. The line obtained is the line starting at curr_pos. */ public POSITION -forw_line(curr_pos) +forw_line_seg(curr_pos, get_segpos) POSITION curr_pos; + int get_segpos; { POSITION base_pos; POSITION new_pos; @@ -104,8 +106,8 @@ forw_line(curr_pos) /* * Read forward again to the position we should start at. */ - prewind(); - plinenum(base_pos); + prewind(); + plinestart(base_pos); (void) ch_seek(base_pos); new_pos = base_pos; while (new_pos < curr_pos) @@ -180,8 +182,9 @@ forw_line(curr_pos) * is too long to print in the screen width. * End the line here. */ - if (chopline || hshift > 0) + if ((chopline || hshift > 0) && !get_segpos) { + /* Read to end of line. */ do { if (ABORT_SIGS()) @@ -205,6 +208,13 @@ forw_line(curr_pos) c = ch_forw_get(); } +#if HILITE_SEARCH + if (blankline && show_attn) + { + /* Add spurious space to carry possible attn hilite. */ + pappend(' ', ch_tell()-1); + } +#endif pdone(endline, chopped, 1); #if HILITE_SEARCH @@ -218,8 +228,12 @@ forw_line(curr_pos) goto get_forw_line; } - if (status_col && is_hilited(base_pos, ch_tell()-1, 1, NULL)) - set_status_col('*'); + if (status_col) + { + int attr = is_hilited_attr(base_pos, ch_tell()-1, 1, NULL); + if (attr) + set_status_col('*', attr); + } #endif if (squeeze && blankline) @@ -243,6 +257,13 @@ forw_line(curr_pos) return (new_pos); } + public POSITION +forw_line(curr_pos) + POSITION curr_pos; +{ + return forw_line_seg(curr_pos, FALSE); +} + /* * Get the previous line. * A "current" position is passed and a "new" position is returned. @@ -358,7 +379,7 @@ back_line(curr_pos) } endline = FALSE; prewind(); - plinenum(new_pos); + plinestart(new_pos); loop: begin_new_pos = new_pos; (void) ch_seek(new_pos); @@ -423,8 +444,12 @@ back_line(curr_pos) goto get_back_line; } - if (status_col && curr_pos > 0 && is_hilited(base_pos, curr_pos-1, 1, NULL)) - set_status_col('*'); + if (status_col && curr_pos > 0) + { + int attr = is_hilited_attr(base_pos, curr_pos-1, 1, NULL); + if (attr) + set_status_col('*', attr); + } #endif return (begin_new_pos); diff --git a/jump.c b/jump.c index a8ed6a5..a376486 100644 --- a/jump.c +++ b/jump.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. diff --git a/less.h b/less.h index 944df68..4751976 100644 --- a/less.h +++ b/less.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -16,10 +16,10 @@ /* * Defines for MSDOS_COMPILER. */ -#define MSOFTC 1 /* Microsoft C */ -#define BORLANDC 2 /* Borland C */ -#define WIN32C 3 /* Windows (Borland C or Microsoft C) */ -#define DJGPPC 4 /* DJGPP C */ +#define MSOFTC 1 /* Microsoft C */ +#define BORLANDC 2 /* Borland C */ +#define WIN32C 3 /* Windows (Borland C or Microsoft C) */ +#define DJGPPC 4 /* DJGPP C */ /* * Include the file of compile-time options. @@ -45,20 +45,20 @@ #define LESSPARAMS(a) () #endif #if HAVE_VOID -#define VOID_POINTER void * -#define VOID_PARAM void +#define VOID_POINTER void * +#define VOID_PARAM void #else -#define VOID_POINTER char * -#define VOID_PARAM -#define void int +#define VOID_POINTER char * +#define VOID_PARAM +#define void int #endif #if HAVE_CONST -#define constant const +#define constant const #else -#define constant +#define constant #endif -#define public /* PUBLIC FUNCTION */ +#define public /* PUBLIC FUNCTION */ /* Library function declarations */ @@ -122,10 +122,10 @@ void free(); * Simple lowercase test which can be used during option processing * (before options are parsed which might tell us what charset to use). */ -#define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') -#define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') -#define ASCII_TO_UPPER(c) ((c) - 'a' + 'A') -#define ASCII_TO_LOWER(c) ((c) - 'A' + 'a') +#define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') +#define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') +#define ASCII_TO_UPPER(c) ((c) - 'a' + 'A') +#define ASCII_TO_LOWER(c) ((c) - 'A' + 'a') #undef IS_UPPER #undef IS_LOWER @@ -135,56 +135,56 @@ void free(); #undef IS_DIGIT #if HAVE_WCTYPE -#define IS_UPPER(c) iswupper(c) -#define IS_LOWER(c) iswlower(c) -#define TO_UPPER(c) towupper(c) -#define TO_LOWER(c) towlower(c) +#define IS_UPPER(c) iswupper(c) +#define IS_LOWER(c) iswlower(c) +#define TO_UPPER(c) towupper(c) +#define TO_LOWER(c) towlower(c) #else #if HAVE_UPPER_LOWER -#define IS_UPPER(c) isupper((unsigned char) (c)) -#define IS_LOWER(c) islower((unsigned char) (c)) -#define TO_UPPER(c) toupper((unsigned char) (c)) -#define TO_LOWER(c) tolower((unsigned char) (c)) +#define IS_UPPER(c) isupper((unsigned char) (c)) +#define IS_LOWER(c) islower((unsigned char) (c)) +#define TO_UPPER(c) toupper((unsigned char) (c)) +#define TO_LOWER(c) tolower((unsigned char) (c)) #else -#define IS_UPPER(c) ASCII_IS_UPPER(c) -#define IS_LOWER(c) ASCII_IS_LOWER(c) -#define TO_UPPER(c) ASCII_TO_UPPER(c) -#define TO_LOWER(c) ASCII_TO_LOWER(c) +#define IS_UPPER(c) ASCII_IS_UPPER(c) +#define IS_LOWER(c) ASCII_IS_LOWER(c) +#define TO_UPPER(c) ASCII_TO_UPPER(c) +#define TO_LOWER(c) ASCII_TO_LOWER(c) #endif #endif #ifdef isspace -#define IS_SPACE(c) isspace((unsigned char)(c)) +#define IS_SPACE(c) isspace((unsigned char)(c)) #else -#define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f') +#define IS_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f') #endif #ifdef isdigit -#define IS_DIGIT(c) isdigit((unsigned char)(c)) +#define IS_DIGIT(c) isdigit((unsigned char)(c)) #else -#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') +#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') #endif -#define IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI)) +#define IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI)) #ifndef NULL -#define NULL 0 +#define NULL 0 #endif #ifndef TRUE -#define TRUE 1 +#define TRUE 1 #endif #ifndef FALSE -#define FALSE 0 +#define FALSE 0 #endif -#define OPT_OFF 0 -#define OPT_ON 1 -#define OPT_ONPLUS 2 +#define OPT_OFF 0 +#define OPT_ON 1 +#define OPT_ONPLUS 2 #if !HAVE_MEMCPY #ifndef memcpy -#define memcpy(to,from,len) bcopy((from),(to),(len)) +#define memcpy(to,from,len) bcopy((from),(to),(len)) #endif #endif @@ -201,7 +201,7 @@ void free(); #define SNPRINTF4(str, size, fmt, v1, v2, v3, v4) sprintf((str), (fmt), (v1), (v2), (v3), (v4)) #endif -#define BAD_LSEEK ((off_t)-1) +#define BAD_LSEEK ((off_t)-1) #ifndef SEEK_SET #define SEEK_SET 0 @@ -225,37 +225,39 @@ void free(); * Special types and constants. */ typedef unsigned long LWCHAR; -typedef off_t POSITION; -typedef off_t LINENUM; -#define MIN_LINENUM_WIDTH 7 /* Min printing width of a line number */ -#define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */ +typedef off_t POSITION; +typedef off_t LINENUM; +#define MIN_LINENUM_WIDTH 7 /* Default min printing width of a line number */ +#define MAX_LINENUM_WIDTH 16 /* Max width of a line number */ +#define MAX_STATUSCOL_WIDTH 4 /* Max width of the status column */ +#define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */ -#define NULL_POSITION ((POSITION)(-1)) +#define NULL_POSITION ((POSITION)(-1)) /* * Flags for open() */ #if MSDOS_COMPILER || OS2 -#define OPEN_READ (O_RDONLY|O_BINARY) +#define OPEN_READ (O_RDONLY|O_BINARY) #else #ifdef _OSK -#define OPEN_READ (S_IREAD) +#define OPEN_READ (S_IREAD) #else #ifdef O_RDONLY -#define OPEN_READ (O_RDONLY) +#define OPEN_READ (O_RDONLY) #else -#define OPEN_READ (0) +#define OPEN_READ (0) #endif #endif #endif #if defined(O_WRONLY) && defined(O_APPEND) -#define OPEN_APPEND (O_APPEND|O_WRONLY) +#define OPEN_APPEND (O_APPEND|O_WRONLY) #else #ifdef _OSK -#define OPEN_APPEND (S_IWRITE) +#define OPEN_APPEND (S_IWRITE) #else -#define OPEN_APPEND (1) +#define OPEN_APPEND (1) #endif #endif @@ -263,12 +265,12 @@ typedef off_t LINENUM; * Set a file descriptor to binary mode. */ #if MSDOS_COMPILER==MSOFTC -#define SET_BINARY(f) _setmode(f, _O_BINARY); +#define SET_BINARY(f) _setmode(f, _O_BINARY); #else #if MSDOS_COMPILER || OS2 -#define SET_BINARY(f) setmode(f, O_BINARY) +#define SET_BINARY(f) setmode(f, O_BINARY) #else -#define SET_BINARY(f) +#define SET_BINARY(f) #endif #endif @@ -276,18 +278,18 @@ typedef off_t LINENUM; * Does the shell treat "?" as a metacharacter? */ #if MSDOS_COMPILER || OS2 || _OSK -#define SHELL_META_QUEST 0 +#define SHELL_META_QUEST 0 #else -#define SHELL_META_QUEST 1 +#define SHELL_META_QUEST 1 #endif -#define SPACES_IN_FILENAMES 1 +#define SPACES_IN_FILENAMES 1 /* * An IFILE represents an input file. */ -#define IFILE VOID_POINTER -#define NULL_IFILE ((IFILE)NULL) +#define IFILE VOID_POINTER +#define NULL_IFILE ((IFILE)NULL) /* * The structure used to represent a "screen position". @@ -298,63 +300,65 @@ typedef off_t LINENUM; */ struct scrpos { - POSITION pos; - int ln; + POSITION pos; + int ln; }; typedef union parg { - char *p_string; - int p_int; - LINENUM p_linenum; + char *p_string; + int p_int; + LINENUM p_linenum; + char p_char; } PARG; -#define NULL_PARG ((PARG *)NULL) +#define NULL_PARG ((PARG *)NULL) struct textlist { - char *string; - char *endstring; + char *string; + char *endstring; }; struct wchar_range { - LWCHAR first, last; + LWCHAR first, last; }; struct wchar_range_table { - struct wchar_range *table; - int count; + struct wchar_range *table; + int count; }; -#define EOI (-1) +#define EOI (-1) -#define READ_INTR (-2) +#define READ_INTR (-2) /* A fraction is represented by an int n; the fraction is n/NUM_FRAC_DENOM */ -#define NUM_FRAC_DENOM 1000000 -#define NUM_LOG_FRAC_DENOM 6 +#define NUM_FRAC_DENOM 1000000 +#define NUM_LOG_FRAC_DENOM 6 /* How quiet should we be? */ -#define NOT_QUIET 0 /* Ring bell at eof and for errors */ -#define LITTLE_QUIET 1 /* Ring bell only for errors */ -#define VERY_QUIET 2 /* Never ring bell */ +#define NOT_QUIET 0 /* Ring bell at eof and for errors */ +#define LITTLE_QUIET 1 /* Ring bell only for errors */ +#define VERY_QUIET 2 /* Never ring bell */ /* How should we prompt? */ -#define PR_SHORT 0 /* Prompt with colon */ -#define PR_MEDIUM 1 /* Prompt with message */ -#define PR_LONG 2 /* Prompt with longer message */ +#define PR_SHORT 0 /* Prompt with colon */ +#define PR_MEDIUM 1 /* Prompt with message */ +#define PR_LONG 2 /* Prompt with longer message */ /* How should we handle backspaces? */ -#define BS_SPECIAL 0 /* Do special things for underlining and bold */ -#define BS_NORMAL 1 /* \b treated as normal char; actually output */ -#define BS_CONTROL 2 /* \b treated as control char; prints as ^H */ +#define BS_SPECIAL 0 /* Do special things for underlining and bold */ +#define BS_NORMAL 1 /* \b treated as normal char; actually output */ +#define BS_CONTROL 2 /* \b treated as control char; prints as ^H */ /* How should we search? */ -#define SRCH_FORW (1 << 0) /* Search forward from current position */ -#define SRCH_BACK (1 << 1) /* Search backward from current position */ +#define SRCH_FORW (1 << 0) /* Search forward from current position */ +#define SRCH_BACK (1 << 1) /* Search backward from current position */ #define SRCH_NO_MOVE (1 << 2) /* Highlight, but don't move */ +#define SRCH_INCR (1 << 3) /* Incremental search */ #define SRCH_FIND_ALL (1 << 4) /* Find and highlight all matches */ #define SRCH_NO_MATCH (1 << 8) /* Search for non-matching lines */ #define SRCH_PAST_EOF (1 << 9) /* Search past end-of-file, into next file */ @@ -362,32 +366,62 @@ struct wchar_range_table #define SRCH_NO_REGEX (1 << 12) /* Don't use regular expressions */ #define SRCH_FILTER (1 << 13) /* Search is for '&' (filter) command */ #define SRCH_AFTER_TARGET (1 << 14) /* Start search after the target line */ +#define SRCH_WRAP (1 << 15) /* Wrap-around search (continue at BOF/EOF) */ -#define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \ - (((t) & ~SRCH_FORW) | SRCH_BACK) : \ - (((t) & ~SRCH_BACK) | SRCH_FORW)) +#define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \ + (((t) & ~SRCH_FORW) | SRCH_BACK) : \ + (((t) & ~SRCH_BACK) | SRCH_FORW)) /* */ -#define NO_MCA 0 -#define MCA_DONE 1 -#define MCA_MORE 2 +#define NO_MCA 0 +#define MCA_DONE 1 +#define MCA_MORE 2 -#define CC_OK 0 /* Char was accepted & processed */ -#define CC_QUIT 1 /* Char was a request to abort current cmd */ -#define CC_ERROR 2 /* Char could not be accepted due to error */ -#define CC_PASS 3 /* Char was rejected (internal) */ +#define CC_OK 0 /* Char was accepted & processed */ +#define CC_QUIT 1 /* Char was a request to abort current cmd */ +#define CC_ERROR 2 /* Char could not be accepted due to error */ +#define CC_PASS 3 /* Char was rejected (internal) */ #define CF_QUIT_ON_ERASE 0001 /* Abort cmd if its entirely erased */ /* Special char bit-flags used to tell put_line() to do something special */ -#define AT_NORMAL (0) -#define AT_UNDERLINE (1 << 0) -#define AT_BOLD (1 << 1) -#define AT_BLINK (1 << 2) -#define AT_STANDOUT (1 << 3) -#define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */ -#define AT_BINARY (1 << 5) /* LESS*BINFMT representation */ -#define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */ +#define AT_NORMAL (0) +#define AT_UNDERLINE (1 << 0) +#define AT_BOLD (1 << 1) +#define AT_BLINK (1 << 2) +#define AT_STANDOUT (1 << 3) +#define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */ +#define AT_BINARY (1 << 5) /* LESS*BINFMT representation */ +#define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */ + +#define AT_COLOR_SHIFT 8 +#define AT_NUM_COLORS 16 +#define AT_COLOR ((AT_NUM_COLORS-1) << AT_COLOR_SHIFT) +#define AT_COLOR_ATTN (1 << AT_COLOR_SHIFT) +#define AT_COLOR_BIN (2 << AT_COLOR_SHIFT) +#define AT_COLOR_CTRL (3 << AT_COLOR_SHIFT) +#define AT_COLOR_ERROR (4 << AT_COLOR_SHIFT) +#define AT_COLOR_LINENUM (5 << AT_COLOR_SHIFT) +#define AT_COLOR_MARK (6 << AT_COLOR_SHIFT) +#define AT_COLOR_PROMPT (7 << AT_COLOR_SHIFT) +#define AT_COLOR_RSCROLL (8 << AT_COLOR_SHIFT) +#define AT_COLOR_SEARCH (9 << AT_COLOR_SHIFT) + +typedef enum { CT_NULL, CT_4BIT, CT_6BIT } COLOR_TYPE; + +typedef enum { + CV_BLUE = 1, + CV_GREEN = 2, + CV_RED = 4, + CV_BRIGHT = 8, + CV_NOCHANGE = -2, + CV_ERROR = -1 +} COLOR_VALUE; + +/* ANSI states */ +#define ANSI_MID 1 +#define ANSI_ERR 2 +#define ANSI_END 3 #if '0' == 240 #define IS_EBCDIC_HOST 1 @@ -400,76 +434,76 @@ struct wchar_range_table * into a constant. */ #define CONTROL(c) ( \ - (c)=='[' ? '\047' : \ - (c)=='a' ? '\001' : \ - (c)=='b' ? '\002' : \ - (c)=='c' ? '\003' : \ - (c)=='d' ? '\067' : \ - (c)=='e' ? '\055' : \ - (c)=='f' ? '\056' : \ - (c)=='g' ? '\057' : \ - (c)=='h' ? '\026' : \ - (c)=='i' ? '\005' : \ - (c)=='j' ? '\025' : \ - (c)=='k' ? '\013' : \ - (c)=='l' ? '\014' : \ - (c)=='m' ? '\015' : \ - (c)=='n' ? '\016' : \ - (c)=='o' ? '\017' : \ - (c)=='p' ? '\020' : \ - (c)=='q' ? '\021' : \ - (c)=='r' ? '\022' : \ - (c)=='s' ? '\023' : \ - (c)=='t' ? '\074' : \ - (c)=='u' ? '\075' : \ - (c)=='v' ? '\062' : \ - (c)=='w' ? '\046' : \ - (c)=='x' ? '\030' : \ - (c)=='y' ? '\031' : \ - (c)=='z' ? '\077' : \ - (c)=='A' ? '\001' : \ - (c)=='B' ? '\002' : \ - (c)=='C' ? '\003' : \ - (c)=='D' ? '\067' : \ - (c)=='E' ? '\055' : \ - (c)=='F' ? '\056' : \ - (c)=='G' ? '\057' : \ - (c)=='H' ? '\026' : \ - (c)=='I' ? '\005' : \ - (c)=='J' ? '\025' : \ - (c)=='K' ? '\013' : \ - (c)=='L' ? '\014' : \ - (c)=='M' ? '\015' : \ - (c)=='N' ? '\016' : \ - (c)=='O' ? '\017' : \ - (c)=='P' ? '\020' : \ - (c)=='Q' ? '\021' : \ - (c)=='R' ? '\022' : \ - (c)=='S' ? '\023' : \ - (c)=='T' ? '\074' : \ - (c)=='U' ? '\075' : \ - (c)=='V' ? '\062' : \ - (c)=='W' ? '\046' : \ - (c)=='X' ? '\030' : \ - (c)=='Y' ? '\031' : \ - (c)=='Z' ? '\077' : \ - (c)=='|' ? '\031' : \ - (c)=='\\' ? '\034' : \ - (c)=='^' ? '\036' : \ - (c)&077) + (c)=='[' ? '\047' : \ + (c)=='a' ? '\001' : \ + (c)=='b' ? '\002' : \ + (c)=='c' ? '\003' : \ + (c)=='d' ? '\067' : \ + (c)=='e' ? '\055' : \ + (c)=='f' ? '\056' : \ + (c)=='g' ? '\057' : \ + (c)=='h' ? '\026' : \ + (c)=='i' ? '\005' : \ + (c)=='j' ? '\025' : \ + (c)=='k' ? '\013' : \ + (c)=='l' ? '\014' : \ + (c)=='m' ? '\015' : \ + (c)=='n' ? '\016' : \ + (c)=='o' ? '\017' : \ + (c)=='p' ? '\020' : \ + (c)=='q' ? '\021' : \ + (c)=='r' ? '\022' : \ + (c)=='s' ? '\023' : \ + (c)=='t' ? '\074' : \ + (c)=='u' ? '\075' : \ + (c)=='v' ? '\062' : \ + (c)=='w' ? '\046' : \ + (c)=='x' ? '\030' : \ + (c)=='y' ? '\031' : \ + (c)=='z' ? '\077' : \ + (c)=='A' ? '\001' : \ + (c)=='B' ? '\002' : \ + (c)=='C' ? '\003' : \ + (c)=='D' ? '\067' : \ + (c)=='E' ? '\055' : \ + (c)=='F' ? '\056' : \ + (c)=='G' ? '\057' : \ + (c)=='H' ? '\026' : \ + (c)=='I' ? '\005' : \ + (c)=='J' ? '\025' : \ + (c)=='K' ? '\013' : \ + (c)=='L' ? '\014' : \ + (c)=='M' ? '\015' : \ + (c)=='N' ? '\016' : \ + (c)=='O' ? '\017' : \ + (c)=='P' ? '\020' : \ + (c)=='Q' ? '\021' : \ + (c)=='R' ? '\022' : \ + (c)=='S' ? '\023' : \ + (c)=='T' ? '\074' : \ + (c)=='U' ? '\075' : \ + (c)=='V' ? '\062' : \ + (c)=='W' ? '\046' : \ + (c)=='X' ? '\030' : \ + (c)=='Y' ? '\031' : \ + (c)=='Z' ? '\077' : \ + (c)=='|' ? '\031' : \ + (c)=='\\' ? '\034' : \ + (c)=='^' ? '\036' : \ + (c)&077) #else -#define CONTROL(c) ((c)&037) +#define CONTROL(c) ((c)&037) #endif /* IS_EBCDIC_HOST */ -#define ESC CONTROL('[') -#define ESCS "\33" -#define CSI ((unsigned char)'\233') -#define CHAR_END_COMMAND 0x40000000 +#define ESC CONTROL('[') +#define ESCS "\33" +#define CSI ((unsigned char)'\233') +#define CHAR_END_COMMAND 0x40000000 #if _OSK_MWC32 -#define LSIGNAL(sig,func) os9_signal(sig,func) +#define LSIGNAL(sig,func) os9_signal(sig,func) #else -#define LSIGNAL(sig,func) signal(sig,func) +#define LSIGNAL(sig,func) signal(sig,func) #endif #if HAVE_SIGPROCMASK @@ -486,41 +520,41 @@ struct wchar_range_table #endif #endif -#define S_INTERRUPT 01 -#define S_STOP 02 -#define S_WINCH 04 -#define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP)) +#define S_INTERRUPT 01 +#define S_STOP 02 +#define S_WINCH 04 +#define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP)) -#define QUIT_OK 0 -#define QUIT_ERROR 1 -#define QUIT_INTERRUPT 2 -#define QUIT_SAVED_STATUS (-1) +#define QUIT_OK 0 +#define QUIT_ERROR 1 +#define QUIT_INTERRUPT 2 +#define QUIT_SAVED_STATUS (-1) #define FOLLOW_DESC 0 #define FOLLOW_NAME 1 /* filestate flags */ -#define CH_CANSEEK 001 -#define CH_KEEPOPEN 002 -#define CH_POPENED 004 -#define CH_HELPFILE 010 -#define CH_NODATA 020 /* Special case for zero length files */ +#define CH_CANSEEK 001 +#define CH_KEEPOPEN 002 +#define CH_POPENED 004 +#define CH_HELPFILE 010 +#define CH_NODATA 020 /* Special case for zero length files */ -#define ch_zero() ((POSITION)0) +#define ch_zero() ((POSITION)0) -#define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@" -#define FAKE_EMPTYFILE "@/\\less/\\empty/\\file/\\@" +#define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@" +#define FAKE_EMPTYFILE "@/\\less/\\empty/\\file/\\@" /* Flags for cvt_text */ -#define CVT_TO_LC 01 /* Convert upper-case to lower-case */ -#define CVT_BS 02 /* Do backspace processing */ -#define CVT_CRLF 04 /* Remove CR after LF */ -#define CVT_ANSI 010 /* Remove ANSI escape sequences */ +#define CVT_TO_LC 01 /* Convert upper-case to lower-case */ +#define CVT_BS 02 /* Do backspace processing */ +#define CVT_CRLF 04 /* Remove CR after LF */ +#define CVT_ANSI 010 /* Remove ANSI escape sequences */ #if HAVE_TIME_T -#define time_type time_t +#define time_type time_t #else -#define time_type long +#define time_type long #endif /* X11 mouse reporting definitions */ @@ -535,6 +569,7 @@ struct wchar_range_table struct mlist; struct loption; struct hilite_tree; +struct ansi_state; #include "pattern.h" #include "funcs.h" diff --git a/less.hlp b/less.hlp index a8f78ad..1e1ebf4 100644 --- a/less.hlp +++ b/less.hlp @@ -42,7 +42,8 @@ ESC-n * Repeat previous search, spanning files. ESC-N * Repeat previous search, reverse dir. & spanning files. ESC-u Undo (toggle) search highlighting. - &_p_a_t_t_e_r_n * Display only matching lines + ESC-U Clear search highlighting. + &_p_a_t_t_e_r_n * Display only matching lines. --------------------------------------------------- A search pattern may begin with one or more of: ^N or ! Search for NON-matching lines. @@ -50,6 +51,7 @@ ^F or @ Start search at FIRST file (for /) or last file (for ?). ^K Highlight matches, but don't move (KEEP position). ^R Don't use REGULAR EXPRESSIONS. + ^W WRAP search if no match found. --------------------------------------------------------------------------- JJUUMMPPIINNGG @@ -62,7 +64,7 @@ { ( [ * Find close bracket } ) ]. } ) ] * Find open bracket { ( [. ESC-^F _<_c_1_> _<_c_2_> * Find close bracket _<_c_2_>. - ESC-^B _<_c_1_> _<_c_2_> * Find open bracket _<_c_1_> + ESC-^B _<_c_1_> _<_c_2_> * Find open bracket _<_c_1_>. --------------------------------------------------- Each "find close bracket" command goes forward to the close bracket matching the (_N-th) open bracket in the top line. @@ -129,8 +131,8 @@ Repaint by clearing rather than scrolling. -d ........ --dumb Dumb terminal. - -D [_x_n_._n] . --color=_x_n_._n - Set screen colors. (MS-DOS only) + -D xx_c_o_l_o_r . --color=xx_c_o_l_o_r + Set screen colors. -e -E .... --quit-at-eof --QUIT-AT-EOF Quit at end of file. -f ........ --force @@ -202,9 +204,13 @@ -~ ........ --tilde Don't display tildes after end of file. -# [_N] .... --shift=[_N] - Horizontal scroll amount (0 = one half screen width) + Set horizontal scroll amount (0 = one half screen width). --follow-name The F command changes files if the input file is renamed. + --incsearch + Search file as each pattern character is typed in. + --line-num-width=N + Set the width of the -N line number field to N characters. --mouse Enable mouse input. --no-keypad @@ -215,8 +221,12 @@ Set the character used to mark truncated lines. --save-marks Retain marks across invocations of less. + --status-col-width=N + Set the width of the -J status column to N characters. --use-backslash Subsequent options use backslash as escape char. + --use-color + Enables colored text. --wheel-lines=N Each click of the mouse wheel moves N lines. @@ -244,5 +254,3 @@ TAB ...................................... Complete filename & cycle. SHIFT-TAB ...................... ESC-TAB Complete filename & reverse cycle. ctrl-L ................................... Complete filename, list all. - - diff --git a/less.man b/less.man index 39656a2..6efe7a9 100644 --- a/less.man +++ b/less.man @@ -107,17 +107,20 @@ LESS(1) General Commands Manual LESS(1) r or ^R or ^L Repaint the screen. - R Repaint the screen, discarding any buffered input. Useful if - the file is changing while it is being viewed. - - F Scroll forward, and keep trying to read when the end of file is - reached. Normally this command would be used when already at - the end of the file. It is a way to monitor the tail of a file - which is growing while it is being viewed. (The behavior is - similar to the "tail -f" command.) - - ESC-F Like F, but as soon as a line is found which matches the last - search pattern, the terminal bell is rung and forward scrolling + R Repaint the screen, discarding any buffered input. That is, + reload the current file. Useful if the file is changing while + it is being viewed. + + F Scroll forward, and keep trying to read when the end of file is + reached. Normally this command would be used when already at + the end of the file. It is a way to monitor the tail of a file + which is growing while it is being viewed. (The behavior is + similar to the "tail -f" command.) To stop waiting for more + data, enter the interrupt character (usually ^C). On some sys- + tems you can also use ^X. + + ESC-F Like F, but as soon as a line is found which matches the last + search pattern, the terminal bell is rung and forward scrolling stops. g or < or ESC-< @@ -125,12 +128,12 @@ LESS(1) General Commands Manual LESS(1) ing: this may be slow if N is large.) G or > or ESC-> - Go to line N in the file, default the end of the file. (Warn- - ing: this may be slow if N is large, or if N is not specified + Go to line N in the file, default the end of the file. (Warn- + ing: this may be slow if N is large, or if N is not specified and standard input, rather than a file, is being read.) - ESC-G Same as G, except if no number N is specified and the input is - standard input, goes to the last line which is currently + ESC-G Same as G, except if no number N is specified and the input is + standard input, goes to the last line which is currently buffered. p or % Go to a position N percent into the file. N should be between 0 @@ -139,93 +142,98 @@ LESS(1) General Commands Manual LESS(1) P Go to the line containing byte offset N in the file. { If a left curly bracket appears in the top line displayed on the - screen, the { command will go to the matching right curly - bracket. The matching right curly bracket is positioned on the + screen, the { command will go to the matching right curly + bracket. The matching right curly bracket is positioned on the bottom line of the screen. If there is more than one left curly - bracket on the top line, a number N may be used to specify the + bracket on the top line, a number N may be used to specify the N-th bracket on the line. } If a right curly bracket appears in the bottom line displayed on - the screen, the } command will go to the matching left curly - bracket. The matching left curly bracket is positioned on the - top line of the screen. If there is more than one right curly - bracket on the top line, a number N may be used to specify the + the screen, the } command will go to the matching left curly + bracket. The matching left curly bracket is positioned on the + top line of the screen. If there is more than one right curly + bracket on the top line, a number N may be used to specify the N-th bracket on the line. ( Like {, but applies to parentheses rather than curly brackets. ) Like }, but applies to parentheses rather than curly brackets. - [ Like {, but applies to square brackets rather than curly brack- + [ Like {, but applies to square brackets rather than curly brack- ets. - ] Like }, but applies to square brackets rather than curly brack- + ] Like }, but applies to square brackets rather than curly brack- ets. - ESC-^F Followed by two characters, acts like {, but uses the two char- - acters as open and close brackets, respectively. For example, - "ESC ^F < >" could be used to go forward to the > which matches + ESC-^F Followed by two characters, acts like {, but uses the two char- + acters as open and close brackets, respectively. For example, + "ESC ^F < >" could be used to go forward to the > which matches the < in the top displayed line. - ESC-^B Followed by two characters, acts like }, but uses the two char- - acters as open and close brackets, respectively. For example, + ESC-^B Followed by two characters, acts like }, but uses the two char- + acters as open and close brackets, respectively. For example, "ESC ^B < >" could be used to go backward to the < which matches the > in the bottom displayed line. - m Followed by any lowercase or uppercase letter, marks the first - displayed line with that letter. If the status column is en- - abled via the -J option, the status column shows the marked + m Followed by any lowercase or uppercase letter, marks the first + displayed line with that letter. If the status column is en- + abled via the -J option, the status column shows the marked line. - M Acts like m, except the last displayed line is marked rather + M Acts like m, except the last displayed line is marked rather than the first displayed line. - ' (Single quote.) Followed by any lowercase or uppercase letter, - returns to the position which was previously marked with that - letter. Followed by another single quote, returns to the posi- - tion at which the last "large" movement command was executed. - Followed by a ^ or $, jumps to the beginning or end of the file - respectively. Marks are preserved when a new file is examined, + ' (Single quote.) Followed by any lowercase or uppercase letter, + returns to the position which was previously marked with that + letter. Followed by another single quote, returns to the posi- + tion at which the last "large" movement command was executed. + Followed by a ^ or $, jumps to the beginning or end of the file + respectively. Marks are preserved when a new file is examined, so the ' command can be used to switch between input files. ^X^X Same as single quote. - ESC-m Followed by any lowercase or uppercase letter, clears the mark + ESC-m Followed by any lowercase or uppercase letter, clears the mark identified by that letter. /pattern Search forward in the file for the N-th line containing the pat- tern. N defaults to 1. The pattern is a regular expression, as - recognized by the regular expression library supplied by your - system. The search starts at the first line displayed (but see + recognized by the regular expression library supplied by your + system. The search starts at the first line displayed (but see the -a and -j options, which change this). - Certain characters are special if entered at the beginning of - the pattern; they modify the type of search rather than become + Certain characters are special if entered at the beginning of + the pattern; they modify the type of search rather than become part of the pattern: ^N or ! Search for lines which do NOT match the pattern. ^E or * - Search multiple files. That is, if the search reaches - the END of the current file without finding a match, the - search continues in the next file in the command line + Search multiple files. That is, if the search reaches + the END of the current file without finding a match, the + search continues in the next file in the command line list. ^F or @ - Begin the search at the first line of the FIRST file in - the command line list, regardless of what is currently - displayed on the screen or the settings of the -a or -j + Begin the search at the first line of the FIRST file in + the command line list, regardless of what is currently + displayed on the screen or the settings of the -a or -j options. - ^K Highlight any text which matches the pattern on the cur- + ^K Highlight any text which matches the pattern on the cur- rent screen, but don't move to the first match (KEEP cur- rent position). - ^R Don't interpret regular expression metacharacters; that + ^R Don't interpret regular expression metacharacters; that is, do a simple textual comparison. + ^W WRAP around the current file. That is, if the search + reaches the end of the current file without finding a + match, the search continues from the first line of the + current file up to the line where it started. + ?pattern Search backward in the file for the N-th line containing the pattern. The search starts at the last line displayed (but see @@ -252,141 +260,152 @@ LESS(1) General Commands Manual LESS(1) ^R As in forward searches. + ^W WRAP around the current file. That is, if the search + reaches the beginning of the current file without finding + a match, the search continues from the last line of the + current file up to the line where it started. + ESC-/pattern Same as "/*". ESC-?pattern Same as "?*". - n Repeat previous search, for N-th line containing the last pat- - tern. If the previous search was modified by ^N, the search is - made for the N-th line NOT containing the pattern. If the pre- - vious search was modified by ^E, the search continues in the - next (or previous) file if not satisfied in the current file. - If the previous search was modified by ^R, the search is done - without using regular expressions. There is no effect if the + n Repeat previous search, for N-th line containing the last pat- + tern. If the previous search was modified by ^N, the search is + made for the N-th line NOT containing the pattern. If the pre- + vious search was modified by ^E, the search continues in the + next (or previous) file if not satisfied in the current file. + If the previous search was modified by ^R, the search is done + without using regular expressions. There is no effect if the previous search was modified by ^F or ^K. N Repeat previous search, but in the reverse direction. - ESC-n Repeat previous search, but crossing file boundaries. The ef- + ESC-n Repeat previous search, but crossing file boundaries. The ef- fect is as if the previous search were modified by *. - ESC-N Repeat previous search, but in the reverse direction and cross- + ESC-N Repeat previous search, but in the reverse direction and cross- ing file boundaries. - ESC-u Undo search highlighting. Turn off highlighting of strings + ESC-u Undo search highlighting. Turn off highlighting of strings matching the current search pattern. If highlighting is already - off because of a previous ESC-u command, turn highlighting back - on. Any search command will also turn highlighting back on. + off because of a previous ESC-u command, turn highlighting back + on. Any search command will also turn highlighting back on. (Highlighting can also be disabled by toggling the -G option; in that case search commands do not turn highlighting back on.) + ESC-U Like ESC-u but also clears the saved search pattern. If the + status column is enabled via the -J option, this clears all + search matches marked in the status column. + &pattern - Display only lines which match the pattern; lines which do not - match the pattern are not displayed. If pattern is empty (if - you type & immediately followed by ENTER), any filtering is - turned off, and all lines are displayed. While filtering is in - effect, an ampersand is displayed at the beginning of the + Display only lines which match the pattern; lines which do not + match the pattern are not displayed. If pattern is empty (if + you type & immediately followed by ENTER), any filtering is + turned off, and all lines are displayed. While filtering is in + effect, an ampersand is displayed at the beginning of the prompt, as a reminder that some lines in the file may be hidden. + Multiple & commands may be entered, in which case only lines + which match all of the patterns will be displayed. Certain characters are special as in the / command: ^N or ! Display only lines which do NOT match the pattern. - ^R Don't interpret regular expression metacharacters; that + ^R Don't interpret regular expression metacharacters; that is, do a simple textual comparison. :e [filename] - Examine a new file. If the filename is missing, the "current" - file (see the :n and :p commands below) from the list of files - in the command line is re-examined. A percent sign (%) in the - filename is replaced by the name of the current file. A pound - sign (#) is replaced by the name of the previously examined - file. However, two consecutive percent signs are simply re- - placed with a single percent sign. This allows you to enter a - filename that contains a percent sign in the name. Similarly, - two consecutive pound signs are replaced with a single pound - sign. The filename is inserted into the command line list of - files so that it can be seen by subsequent :n and :p commands. + Examine a new file. If the filename is missing, the "current" + file (see the :n and :p commands below) from the list of files + in the command line is re-examined. A percent sign (%) in the + filename is replaced by the name of the current file. A pound + sign (#) is replaced by the name of the previously examined + file. However, two consecutive percent signs are simply re- + placed with a single percent sign. This allows you to enter a + filename that contains a percent sign in the name. Similarly, + two consecutive pound signs are replaced with a single pound + sign. The filename is inserted into the command line list of + files so that it can be seen by subsequent :n and :p commands. If the filename consists of several files, they are all inserted - into the list of files and the first one is examined. If the + into the list of files and the first one is examined. If the filename contains one or more spaces, the entire filename should be enclosed in double quotes (also see the -" option). ^X^V or E - Same as :e. Warning: some systems use ^V as a special literal- - ization character. On such systems, you may not be able to use + Same as :e. Warning: some systems use ^V as a special literal- + ization character. On such systems, you may not be able to use ^V. - :n Examine the next file (from the list of files given in the com- - mand line). If a number N is specified, the N-th next file is + :n Examine the next file (from the list of files given in the com- + mand line). If a number N is specified, the N-th next file is examined. :p Examine the previous file in the command line list. If a number N is specified, the N-th previous file is examined. - :x Examine the first file in the command line list. If a number N + :x Examine the first file in the command line list. If a number N is specified, the N-th file in the list is examined. :d Remove the current file from the list of files. - t Go to the next tag, if there were more than one matches for the + t Go to the next tag, if there were more than one matches for the current tag. See the -t option for more details about tags. - T Go to the previous tag, if there were more than one matches for + T Go to the previous tag, if there were more than one matches for the current tag. = or ^G or :f - Prints some information about the file being viewed, including - its name and the line number and byte offset of the bottom line - being displayed. If possible, it also prints the length of the - file, the number of lines in the file and the percent of the + Prints some information about the file being viewed, including + its name and the line number and byte offset of the bottom line + being displayed. If possible, it also prints the length of the + file, the number of lines in the file and the percent of the file above the last displayed line. - - Followed by one of the command line option letters (see OPTIONS - below), this will change the setting of that option and print a - message describing the new setting. If a ^P (CONTROL-P) is en- - tered immediately after the dash, the setting of the option is - changed but no message is printed. If the option letter has a - numeric value (such as -b or -h), or a string value (such as -P - or -t), a new value may be entered after the option letter. If - no new value is entered, a message describing the current set- + - Followed by one of the command line option letters (see OPTIONS + below), this will change the setting of that option and print a + message describing the new setting. If a ^P (CONTROL-P) is en- + tered immediately after the dash, the setting of the option is + changed but no message is printed. If the option letter has a + numeric value (such as -b or -h), or a string value (such as -P + or -t), a new value may be entered after the option letter. If + no new value is entered, a message describing the current set- ting is printed and nothing is changed. - -- Like the - command, but takes a long option name (see OPTIONS + -- Like the - command, but takes a long option name (see OPTIONS below) rather than a single option letter. You must press ENTER - or RETURN after typing the option name. A ^P immediately after - the second dash suppresses printing of a message describing the + or RETURN after typing the option name. A ^P immediately after + the second dash suppresses printing of a message describing the new setting, as in the - command. -+ Followed by one of the command line option letters this will re- - set the option to its default setting and print a message de- - scribing the new setting. (The "-+X" command does the same - thing as "-+X" on the command line.) This does not work for + set the option to its default setting and print a message de- + scribing the new setting. (The "-+X" command does the same + thing as "-+X" on the command line.) This does not work for string-valued options. - --+ Like the -+ command, but takes a long option name rather than a + --+ Like the -+ command, but takes a long option name rather than a single option letter. - -! Followed by one of the command line option letters, this will - reset the option to the "opposite" of its default setting and - print a message describing the new setting. This does not work + -! Followed by one of the command line option letters, this will + reset the option to the "opposite" of its default setting and + print a message describing the new setting. This does not work for numeric or string-valued options. - --! Like the -! command, but takes a long option name rather than a + --! Like the -! command, but takes a long option name rather than a single option letter. - _ (Underscore.) Followed by one of the command line option let- - ters, this will print a message describing the current setting + _ (Underscore.) Followed by one of the command line option let- + ters, this will print a message describing the current setting of that option. The setting of the option is not changed. __ (Double underscore.) Like the _ (underscore) command, but takes a long option name rather than a single option letter. You must press ENTER or RETURN after typing the option name. - +cmd Causes the specified cmd to be executed each time a new file is + +cmd Causes the specified cmd to be executed each time a new file is examined. For example, +G causes less to initially display each file starting at the end rather than the beginning. @@ -395,51 +414,51 @@ LESS(1) General Commands Manual LESS(1) q or Q or :q or :Q or ZZ Exits less. - The following four commands may or may not be valid, depending on your + The following four commands may or may not be valid, depending on your particular installation. - v Invokes an editor to edit the current file being viewed. The + v Invokes an editor to edit the current file being viewed. The editor is taken from the environment variable VISUAL if defined, - or EDITOR if VISUAL is not defined, or defaults to "vi" if nei- - ther VISUAL nor EDITOR is defined. See also the discussion of + or EDITOR if VISUAL is not defined, or defaults to "vi" if nei- + ther VISUAL nor EDITOR is defined. See also the discussion of LESSEDIT under the section on PROMPTS below. ! shell-command - Invokes a shell to run the shell-command given. A percent sign - (%) in the command is replaced by the name of the current file. + Invokes a shell to run the shell-command given. A percent sign + (%) in the command is replaced by the name of the current file. A pound sign (#) is replaced by the name of the previously exam- - ined file. "!!" repeats the last shell command. "!" with no - shell command simply invokes a shell. On Unix systems, the - shell is taken from the environment variable SHELL, or defaults - to "sh". On MS-DOS and OS/2 systems, the shell is the normal + ined file. "!!" repeats the last shell command. "!" with no + shell command simply invokes a shell. On Unix systems, the + shell is taken from the environment variable SHELL, or defaults + to "sh". On MS-DOS and OS/2 systems, the shell is the normal command processor. | shell-command - represents any mark letter. Pipes a section of the input - file to the given shell command. The section of the file to be - piped is between the position marked by the letter and the cur- - rent screen. The entire current screen is included, regardless - of whether the marked position is before or after the current - screen. may also be ^ or $ to indicate beginning or end of - file respectively. If is . or newline, the current screen + represents any mark letter. Pipes a section of the input + file to the given shell command. The section of the file to be + piped is between the position marked by the letter and the cur- + rent screen. The entire current screen is included, regardless + of whether the marked position is before or after the current + screen. may also be ^ or $ to indicate beginning or end of + file respectively. If is . or newline, the current screen is piped. s filename - Save the input to a file. This only works if the input is a + Save the input to a file. This only works if the input is a pipe, not an ordinary file. OPTIONS - Command line options are described below. Most options may be changed + Command line options are described below. Most options may be changed while less is running, via the "-" command. - Most options may be given in one of two forms: either a dash followed - by a single letter, or two dashes followed by a long option name. A - long option name may be abbreviated as long as the abbreviation is un- - ambiguous. For example, --quit-at-eof may be abbreviated --quit, but + Most options may be given in one of two forms: either a dash followed + by a single letter, or two dashes followed by a long option name. A + long option name may be abbreviated as long as the abbreviation is un- + ambiguous. For example, --quit-at-eof may be abbreviated --quit, but not --qui, since both --quit-at-eof and --quiet begin with --qui. Some - long option names are in uppercase, such as --QUIT-AT-EOF, as distinct - from --quit-at-eof. Such option names need only have their first let- - ter capitalized; the remainder of the name may be in either case. For + long option names are in uppercase, such as --QUIT-AT-EOF, as distinct + from --quit-at-eof. Such option names need only have their first let- + ter capitalized; the remainder of the name may be in either case. For example, --Quit-at-eof is equivalent to --QUIT-AT-EOF. Options are also taken from the environment variable "LESS". For exam- @@ -452,76 +471,76 @@ LESS(1) General Commands Manual LESS(1) LESS="-options"; export LESS - On MS-DOS, you don't need the quotes, but you should replace any per- + On MS-DOS, you don't need the quotes, but you should replace any per- cent signs in the options string by double percent signs. - The environment variable is parsed before the command line, so command - line options override the LESS environment variable. If an option ap- + The environment variable is parsed before the command line, so command + line options override the LESS environment variable. If an option ap- pears in the LESS variable, it can be reset to its default value on the command line by beginning the command line option with "-+". - Some options like -k or -D require a string to follow the option let- - ter. The string for that option is considered to end when a dollar - sign ($) is found. For example, you can set two -D options on MS-DOS + Some options like -k or -D require a string to follow the option let- + ter. The string for that option is considered to end when a dollar + sign ($) is found. For example, you can set two -D options on MS-DOS like this: LESS="Dn9.1$Ds4.1" - If the --use-backslash option appears earlier in the options, then a - dollar sign or backslash may be included literally in an option string + If the --use-backslash option appears earlier in the options, then a + dollar sign or backslash may be included literally in an option string by preceding it with a backslash. If the --use-backslash option is not - in effect, then backslashes are not treated specially, and there is no + in effect, then backslashes are not treated specially, and there is no way to include a dollar sign in the option string. -? or --help - This option displays a summary of the commands accepted by less - (the same as the h command). (Depending on how your shell in- - terprets the question mark, it may be necessary to quote the + This option displays a summary of the commands accepted by less + (the same as the h command). (Depending on how your shell in- + terprets the question mark, it may be necessary to quote the question mark, thus: "-\?".) -a or --search-skip-screen - By default, forward searches start at the top of the displayed - screen and backwards searches start at the bottom of the dis- - played screen (except for repeated searches invoked by the n or - N commands, which start after or before the "target" line re- - spectively; see the -j option for more about the target line). - The -a option causes forward searches to instead start at the - bottom of the screen and backward searches to start at the top + By default, forward searches start at the top of the displayed + screen and backwards searches start at the bottom of the dis- + played screen (except for repeated searches invoked by the n or + N commands, which start after or before the "target" line re- + spectively; see the -j option for more about the target line). + The -a option causes forward searches to instead start at the + bottom of the screen and backward searches to start at the top of the screen, thus skipping all lines displayed on the screen. -A or --SEARCH-SKIP-SCREEN - Causes all forward searches (not just non-repeated searches) to - start just after the target line, and all backward searches to - start just before the target line. Thus, forward searches will + Causes all forward searches (not just non-repeated searches) to + start just after the target line, and all backward searches to + start just before the target line. Thus, forward searches will skip part of the displayed screen (from the first line up to and - including the target line). Similarly backwards searches will + including the target line). Similarly backwards searches will skip the displayed screen from the last line up to and including the target line. This was the default behavior in less versions prior to 441. -bn or --buffers=n - Specifies the amount of buffer space less will use for each - file, in units of kilobytes (1024 bytes). By default 64 KB of - buffer space is used for each file (unless the file is a pipe; - see the -B option). The -b option specifies instead that n + Specifies the amount of buffer space less will use for each + file, in units of kilobytes (1024 bytes). By default 64 KB of + buffer space is used for each file (unless the file is a pipe; + see the -B option). The -b option specifies instead that n kilobytes of buffer space should be used for each file. If n is - -1, buffer space is unlimited; that is, the entire file can be + -1, buffer space is unlimited; that is, the entire file can be read into memory. -B or --auto-buffers By default, when data is read from a pipe, buffers are allocated automatically as needed. If a large amount of data is read from - the pipe, this can cause a large amount of memory to be allo- + the pipe, this can cause a large amount of memory to be allo- cated. The -B option disables this automatic allocation of buf- fers for pipes, so that only 64 KB (or the amount of space spec- - ified by the -b option) is used for the pipe. Warning: use of + ified by the -b option) is used for the pipe. Warning: use of -B can result in erroneous display, since only the most recently - viewed part of the piped data is kept in memory; any earlier + viewed part of the piped data is kept in memory; any earlier data is lost. -c or --clear-screen - Causes full screen repaints to be painted from the top line - down. By default, full screen repaints are done by scrolling + Causes full screen repaints to be painted from the top line + down. By default, full screen repaints are done by scrolling from the bottom of the screen. -C or --CLEAR-SCREEN @@ -529,26 +548,104 @@ LESS(1) General Commands Manual LESS(1) -d or --dumb The -d option suppresses the error message normally displayed if - the terminal is dumb; that is, lacks some important capability, + the terminal is dumb; that is, lacks some important capability, such as the ability to clear the screen or scroll backward. The - -d option does not otherwise change the behavior of less on a + -d option does not otherwise change the behavior of less on a dumb terminal. -Dxcolor or --color=xcolor - [MS-DOS only] Sets the color of the text displayed. x is a sin- - gle character which selects the type of text whose color is be- - ing set: n=normal, s=standout, d=bold, u=underlined, k=blink. - color is a pair of numbers separated by a period. The first - number selects the foreground color and the second selects the - background color of the text. A single number N is the same as - N.M, where M is the normal background color. The color may - start or end with u to use underline (with the normal color, if - by itself), if the system supports it (Windows only). x may - also be a to toggle strict ANSI sequence rendering (SGR mode). + Changes the color of different parts of the displayed text. x + is a single character which selects the type of text whose color + is being set: + + B Binary characters. + + C Control characters. + + E Errors and informational messages. + + M Mark letters in the status column. + + N Line numbers enabled via the -N option. + + P Prompts. + + R The rscroll character. + + S Search results. + + W The highlight enabled via the -w option. + + d Bold text. + + k Blinking text. + + s Standout text. + + u Underlined text. + + The uppercase letters can be used only when the --use-color op- + tion is enabled. When text color is specified by both an upper- + case letter and a lowercase letter, the uppercase letter takes + precedence. For example, error messages are normally displayed + as standout text. So if both "s" and "E" are given a color, the + "E" color applies to error messages, and the "s" color applies + to other standout text. The "d" and "u" letters refer to bold + and underline text formed by overstriking with backspaces (see + the -u option), not to text using ANSI escape sequences with the + -R option. + + A lowercase letter may be followed by a + to indicate that both + the normal format change and the specified color should both be + used. For example, -Dug displays underlined text as green with- + out underlining; the green color has replaced the usual under- + line formatting. But -Du+g displays underlined text as both + green and in underlined format. + + color is either a 4-bit color string or an 8-bit color string: + + A 4-bit color string is zero, one or two characters, where the + first character specifies the foreground color and the second + specifies the background color as follows: + + b Blue + + c Cyan + + g Green + + k Black + + m Magenta + + r Red + + w White + + y Yellow + + The corresponding upper-case letter denotes a brighter shade of + the color. For example, -DNGk displays line numbers as bright + green text on a black background, and -DEbR displays error mes- + sages as blue text on a bright red background. If either char- + acter is a "-" or is omitted, the corresponding color is set to + that of normal text. + + An 8-bit color string is one or two decimal integers separated + by a dot, where the first integer specifies the foreground color + and the second specifies the background color. Each integer is + a value between 0 and 255 inclusive which selects a "CSI 38;5" + color value (see + https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) + If either integer is a "-" or is omitted, the corresponding col- + or is set to that of normal text. On MS-DOS versions of less, + 8-bit color is not supported; instead, decimal values are inter- + preted as 4-bit CHAR_INFO.Attributes values (see + https://docs.microsoft.com/en-us/windows/console/char-info-str). -e or --quit-at-eof - Causes less to automatically exit the second time it reaches - end-of-file. By default, the only way to exit less is via the + Causes less to automatically exit the second time it reaches + end-of-file. By default, the only way to exit less is via the "q" command. -E or --QUIT-AT-EOF @@ -557,7 +654,7 @@ LESS(1) General Commands Manual LESS(1) -f or --force Forces non-regular files to be opened. (A non-regular file is a - directory or a device special file.) Also suppresses the warn- + directory or a device special file.) Also suppresses the warn- ing message when a binary file is opened. By default, less will refuse to open non-regular files. Note that some operating sys- tems will not allow directories to be read, even if -f is set. @@ -567,63 +664,62 @@ LESS(1) General Commands Manual LESS(1) played on the first screen. -g or --hilite-search - Normally, less will highlight ALL strings which match the last - search command. The -g option changes this behavior to high- - light only the particular string which was found by the last + Normally, less will highlight ALL strings which match the last + search command. The -g option changes this behavior to high- + light only the particular string which was found by the last search command. This can cause less to run somewhat faster than the default. -G or --HILITE-SEARCH - The -G option suppresses all highlighting of strings found by + The -G option suppresses all highlighting of strings found by search commands. -hn or --max-back-scroll=n - Specifies a maximum number of lines to scroll backward. If it + Specifies a maximum number of lines to scroll backward. If it is necessary to scroll backward more than n lines, the screen is repainted in a forward direction instead. (If the terminal does not have the ability to scroll backward, -h0 is implied.) -i or --ignore-case Causes searches to ignore case; that is, uppercase and lowercase - are considered identical. This option is ignored if any upper- - case letters appear in the search pattern; in other words, if a - pattern contains uppercase letters, then that search does not + are considered identical. This option is ignored if any upper- + case letters appear in the search pattern; in other words, if a + pattern contains uppercase letters, then that search does not ignore case. -I or --IGNORE-CASE - Like -i, but searches ignore case even if the pattern contains + Like -i, but searches ignore case even if the pattern contains uppercase letters. -jn or --jump-target=n - Specifies a line on the screen where the "target" line is to be - positioned. The target line is the line specified by any com- - mand to search for a pattern, jump to a line number, jump to a + Specifies a line on the screen where the "target" line is to be + positioned. The target line is the line specified by any com- + mand to search for a pattern, jump to a line number, jump to a file percentage or jump to a tag. The screen line may be speci- - fied by a number: the top line on the screen is 1, the next is + fied by a number: the top line on the screen is 1, the next is 2, and so on. The number may be negative to specify a line rel- ative to the bottom of the screen: the bottom line on the screen - is -1, the second to the bottom is -2, and so on. Alternately, - the screen line may be specified as a fraction of the height of - the screen, starting with a decimal point: .5 is in the middle - of the screen, .3 is three tenths down from the first line, and - so on. If the line is specified as a fraction, the actual line - number is recalculated if the terminal window is resized, so - that the target line remains at the specified fraction of the - screen height. If any form of the -j option is used, repeated + is -1, the second to the bottom is -2, and so on. Alternately, + the screen line may be specified as a fraction of the height of + the screen, starting with a decimal point: .5 is in the middle + of the screen, .3 is three tenths down from the first line, and + so on. If the line is specified as a fraction, the actual line + number is recalculated if the terminal window is resized, so + that the target line remains at the specified fraction of the + screen height. If any form of the -j option is used, repeated forward searches (invoked with "n" or "N") begin at the line im- - mediately after the target line, and repeated backward searches + mediately after the target line, and repeated backward searches begin at the target line, unless changed by -a or -A. For exam- ple, if "-j4" is used, the target line is the fourth line on the - screen, so forward searches begin at the fifth line on the - screen. However nonrepeated searches (invoked with "/" or "?") - always begin at the start or end of the current screen respec- + screen, so forward searches begin at the fifth line on the + screen. However nonrepeated searches (invoked with "/" or "?") + always begin at the start or end of the current screen respec- tively. -J or --status-column - Displays a status column at the left edge of the screen. The - status column shows the lines that matched the current search, - and any lines that are marked (via the m or M command). The - status column is also used if the -w or -W option is in effect. + Displays a status column at the left edge of the screen. The + status column shows the lines that matched the current search, + and any lines that are marked (via the m or M command). -kfilename or --lesskey-file=filename Causes less to open and interpret the named file as a lesskey(1) @@ -727,84 +823,101 @@ LESS(1) General Commands Manual LESS(1) play problems may result, such as long lines being split in the wrong place. + USE OF THE -r OPTION IS NOT RECOMMENDED. + -R or --RAW-CONTROL-CHARS - Like -r, but only ANSI "color" escape sequences are output in - "raw" form. Unlike -r, the screen appearance is maintained cor- - rectly in most cases. ANSI "color" escape sequences are se- - quences of the form: + Like -r, but only ANSI "color" escape sequences and OSC 8 hyper- + link sequences are output in "raw" form. Unlike -r, the screen + appearance is maintained correctly, provided that there are no + escape sequences in the file other than these types of escape + sequences. Color escape sequences are only supported when the + color is changed within one line, not across lines. In other + words, the beginning of each line is assumed to be normal (non- + colored), regardless of any escape sequences in previous lines. + For the purpose of keeping track of screen appearance, these es- + cape sequences are assumed to not move the cursor. + + OSC 8 hyperlinks are sequences of the form: + + ESC ] 8 ; ... \7 + + The terminating sequence may be either a BEL character (\7) or + the two-character sequence "ESC \". + + ANSI color escape sequences are sequences of the form: ESC [ ... m - where the "..." is zero or more color specification characters - For the purpose of keeping track of screen appearance, ANSI - color escape sequences are assumed to not move the cursor. You - can make less think that characters other than "m" can end ANSI - color escape sequences by setting the environment variable + where the "..." is zero or more color specification characters. + You can make less think that characters other than "m" can end + ANSI color escape sequences by setting the environment variable LESSANSIENDCHARS to the list of characters which can end a color - escape sequence. And you can make less think that characters - other than the standard ones may appear between the ESC and the - m by setting the environment variable LESSANSIMIDCHARS to the + escape sequence. And you can make less think that characters + other than the standard ones may appear between the ESC and the + m by setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear. -s or --squeeze-blank-lines - Causes consecutive blank lines to be squeezed into a single + Causes consecutive blank lines to be squeezed into a single blank line. This is useful when viewing nroff output. -S or --chop-long-lines - Causes lines longer than the screen width to be chopped (trun- + Causes lines longer than the screen width to be chopped (trun- cated) rather than wrapped. That is, the portion of a long line that does not fit in the screen width is not displayed until you - press RIGHT-ARROW. The default is to wrap long lines; that is, + press RIGHT-ARROW. The default is to wrap long lines; that is, display the remainder on the next line. -ttag or --tag=tag The -t option, followed immediately by a TAG, will edit the file - containing that tag. For this to work, tag information must be - available; for example, there may be a file in the current di- + containing that tag. For this to work, tag information must be + available; for example, there may be a file in the current di- rectory called "tags", which was previously built by ctags(1) or an equivalent command. If the environment variable LESSGLOBALT- - AGS is set, it is taken to be the name of a command compatible - with global(1), and that command is executed to find the tag. + AGS is set, it is taken to be the name of a command compatible + with global(1), and that command is executed to find the tag. (See http://www.gnu.org/software/global/global.html). The -t - option may also be specified from within less (using the - com- - mand) as a way of examining a new file. The command ":t" is + option may also be specified from within less (using the - com- + mand) as a way of examining a new file. The command ":t" is equivalent to specifying -t from within less. -Ttagsfile or --tag-file=tagsfile Specifies a tags file to be used instead of "tags". -u or --underline-special - Causes backspaces and carriage returns to be treated as print- - able characters; that is, they are sent to the terminal when + Causes backspaces and carriage returns to be treated as print- + able characters; that is, they are sent to the terminal when they appear in the input. -U or --UNDERLINE-SPECIAL - Causes backspaces, tabs, carriage returns and "formatting char- + Causes backspaces, tabs, carriage returns and "formatting char- acters" (as defined by Unicode) to be treated as control charac- ters; that is, they are handled as specified by the -r option. - By default, if neither -u nor -U is given, backspaces which ap- - pear adjacent to an underscore character are treated specially: - the underlined text is displayed using the terminal's hardware - underlining capability. Also, backspaces which appear between - two identical characters are treated specially: the overstruck - text is printed using the terminal's hardware boldface capabil- - ity. Other backspaces are deleted, along with the preceding - character. Carriage returns immediately followed by a newline + By default, if neither -u nor -U is given, backspaces which ap- + pear adjacent to an underscore character are treated specially: + the underlined text is displayed using the terminal's hardware + underlining capability. Also, backspaces which appear between + two identical characters are treated specially: the overstruck + text is printed using the terminal's hardware boldface capabili- + ty. Other backspaces are deleted, along with the preceding + character. Carriage returns immediately followed by a newline are deleted. Other carriage returns are handled as specified by - the -r option. Text which is overstruck or underlined can be - searched for if neither -u nor -U is in effect. + the -r option. Unicode formatting characters, such as the Byte + Order Mark, are sent to the terminal. Text which is overstruck + or underlined can be searched for if neither -u nor -U is in ef- + fect. -V or --version Displays the version number of less. -w or --hilite-unread - Temporarily highlights the first "new" line after a forward + Temporarily highlights the first "new" line after a forward movement of a full page. The first "new" line is the line imme- - diately following the line previously at the bottom of the + diately following the line previously at the bottom of the screen. Also highlights the target line after a g or p command. - The highlight is removed at the next command which causes move- - ment. The entire line is highlighted, unless the -J option is + The highlight is removed at the next command which causes move- + ment. The entire line is highlighted, unless the -J option is in effect, in which case only the status column is highlighted. -W or --HILITE-UNREAD @@ -812,48 +925,48 @@ LESS(1) General Commands Manual LESS(1) forward movement command larger than one line. -xn,... or --tabs=n,... - Sets tab stops. If only one n is specified, tab stops are set - at multiples of n. If multiple values separated by commas are - specified, tab stops are set at those positions, and then con- - tinue with the same spacing as the last two. For example, - -x9,17 will set tabs at positions 9, 17, 25, 33, etc. The de- + Sets tab stops. If only one n is specified, tab stops are set + at multiples of n. If multiple values separated by commas are + specified, tab stops are set at those positions, and then con- + tinue with the same spacing as the last two. For example, + -x9,17 will set tabs at positions 9, 17, 25, 33, etc. The de- fault for n is 8. -X or --no-init Disables sending the termcap initialization and deinitialization - strings to the terminal. This is sometimes desirable if the - deinitialization string does something unnecessary, like clear- + strings to the terminal. This is sometimes desirable if the + deinitialization string does something unnecessary, like clear- ing the screen. -yn or --max-forw-scroll=n Specifies a maximum number of lines to scroll forward. If it is necessary to scroll forward more than n lines, the screen is re- - painted instead. The -c or -C option may be used to repaint - from the top of the screen if desired. By default, any forward + painted instead. The -c or -C option may be used to repaint + from the top of the screen if desired. By default, any forward movement causes scrolling. -zn or --window=n or -n - Changes the default scrolling window size to n lines. The de- - fault is one screenful. The z and w commands can also be used - to change the window size. The "z" may be omitted for compati- + Changes the default scrolling window size to n lines. The de- + fault is one screenful. The z and w commands can also be used + to change the window size. The "z" may be omitted for compati- bility with some versions of more. If the number n is negative, it indicates n lines less than the current screen size. For ex- ample, if the screen is 24 lines, -z-4 sets the scrolling window - to 20 lines. If the screen is resized to 40 lines, the + to 20 lines. If the screen is resized to 40 lines, the scrolling window automatically changes to 36 lines. -"cc or --quotes=cc - Changes the filename quoting character. This may be necessary - if you are trying to name a file which contains both spaces and - quote characters. Followed by a single character, this changes - the quote character to that character. Filenames containing a + Changes the filename quoting character. This may be necessary + if you are trying to name a file which contains both spaces and + quote characters. Followed by a single character, this changes + the quote character to that character. Filenames containing a space should then be surrounded by that character rather than by - double quotes. Followed by two characters, changes the open - quote to the first character, and the close quote to the second + double quotes. Followed by two characters, changes the open + quote to the first character, and the close quote to the second character. Filenames containing a space should then be preceded - by the open quote character and followed by the close quote - character. Note that even after the quote characters are - changed, this option remains -" (a dash followed by a double + by the open quote character and followed by the close quote + character. Note that even after the quote characters are + changed, this option remains -" (a dash followed by a double quote). -~ or --tilde @@ -863,12 +976,12 @@ LESS(1) General Commands Manual LESS(1) -# or --shift Specifies the default number of positions to scroll horizontally - in the RIGHTARROW and LEFTARROW commands. If the number speci- - fied is zero, it sets the default number of positions to one + in the RIGHTARROW and LEFTARROW commands. If the number speci- + fied is zero, it sets the default number of positions to one half of the screen width. Alternately, the number may be speci- - fied as a fraction of the width of the screen, starting with a - decimal point: .5 is half of the screen width, .3 is three - tenths of the screen width, and so on. If the number is speci- + fied as a fraction of the width of the screen, starting with a + decimal point: .5 is half of the screen width, .3 is three + tenths of the screen width, and so on. If the number is speci- fied as a fraction, the actual number of scroll positions is re- calculated if the terminal window is resized, so that the actual scroll remains at the specified fraction of the screen width. @@ -876,13 +989,22 @@ LESS(1) General Commands Manual LESS(1) --follow-name Normally, if the input file is renamed while an F command is ex- ecuting, less will continue to display the contents of the orig- - inal file despite its name change. If --follow-name is speci- - fied, during an F command less will periodically attempt to re- + inal file despite its name change. If --follow-name is speci- + fied, during an F command less will periodically attempt to re- open the file by name. If the reopen succeeds and the file is a - different file from the original (which means that a new file - has been created with the same name as the original (now re- + different file from the original (which means that a new file + has been created with the same name as the original (now re- named) file), less will display the contents of that new file. + --incsearch + Subsequent search commands will be "incremental"; that is, less + will advance to the next line containing the search pattern as + each character of the pattern is typed in. + + --line-num-width + Sets the minimum width of the line number field when the -N op- + tion is in effect. The default is 7 characters. + --mouse Enables mouse input: scrolling the mouse wheel down moves for- ward in the file, scrolling the mouse wheel up moves backwards @@ -919,45 +1041,57 @@ LESS(1) General Commands Manual LESS(1) Save marks in the history file, so marks are retained across different invocations of less. + --status-col-width + Sets the width of the status column when the -J option is in ef- + fect. The default is 2 characters. + --use-backslash - This option changes the interpretations of options which follow + This option changes the interpretations of options which follow this one. After the --use-backslash option, any backslash in an - option string is removed and the following character is taken - literally. This allows a dollar sign to be included in option + option string is removed and the following character is taken + literally. This allows a dollar sign to be included in option strings. + --use-color + Enables the colored text in various places. The -D option can + be used to change the colors. Colored text works only if the + terminal supports ANSI color escape sequences (as defined in EC- + MA-48 SGR; see + https://www.ecma-international.org/publications-and- + standards/standards/ecma-48). + --wheel-lines=n - Set the number of lines to scroll when the mouse wheel is - scrolled and the --mouse or --MOUSE option is in effect. The + Set the number of lines to scroll when the mouse wheel is + scrolled and the --mouse or --MOUSE option is in effect. The default is 1 line. - -- A command line argument of "--" marks the end of option argu- - ments. Any arguments following this are interpreted as file- + -- A command line argument of "--" marks the end of option argu- + ments. Any arguments following this are interpreted as file- names. This can be useful when viewing a file whose name begins with a "-" or "+". - + If a command line option begins with +, the remainder of that - option is taken to be an initial command to less. For example, - +G tells less to start at the end of the file rather than the - beginning, and +/xyz tells it to start at the first occurrence - of "xyz" in the file. As a special case, + acts like + + If a command line option begins with +, the remainder of that + option is taken to be an initial command to less. For example, + +G tells less to start at the end of the file rather than the + beginning, and +/xyz tells it to start at the first occurrence + of "xyz" in the file. As a special case, + acts like +g; that is, it starts the display at the specified line - number (however, see the caveat under the "g" command above). + number (however, see the caveat under the "g" command above). If the option starts with ++, the initial command applies to ev- - ery file being viewed, not just the first one. The + command + ery file being viewed, not just the first one. The + command described previously may also be used to set (or change) an ini- tial command for every file. LINE EDITING - When entering command line at the bottom of the screen (for example, a - filename for the :e command, or the pattern for a search command), cer- - tain keys can be used to manipulate the command line. Most commands - have an alternate form in [ brackets ] which can be used if a key does - not exist on a particular keyboard. (Note that the forms beginning - with ESC do not work in some MS-DOS and Windows systems because ESC is - the line erase character.) Any of these special keys may be entered - literally by preceding it with the "literal" character, either ^V or - ^A. A backslash itself may also be entered literally by entering two + When entering a command line at the bottom of the screen (for example, + a filename for the :e command, or the pattern for a search command), + certain keys can be used to manipulate the command line. Most commands + have an alternate form in [ brackets ] which can be used if a key does + not exist on a particular keyboard. (Note that the forms beginning + with ESC do not work in some MS-DOS and Windows systems because ESC is + the line erase character.) Any of these special keys may be entered + literally by preceding it with the "literal" character, either ^V or + ^A. A backslash itself may also be entered literally by entering two backslashes. LEFTARROW [ ESC-h ] @@ -967,7 +1101,7 @@ LESS(1) General Commands Manual LESS(1) Move the cursor one space to the right. ^LEFTARROW [ ESC-b or ESC-LEFTARROW ] - (That is, CONTROL and LEFTARROW simultaneously.) Move the cur- + (That is, CONTROL and LEFTARROW simultaneously.) Move the cur- sor one word to the left. ^RIGHTARROW [ ESC-w or ESC-RIGHTARROW ] @@ -981,48 +1115,48 @@ LESS(1) General Commands Manual LESS(1) Move the cursor to the end of the line. BACKSPACE - Delete the character to the left of the cursor, or cancel the + Delete the character to the left of the cursor, or cancel the command if the command line is empty. DELETE or [ ESC-x ] Delete the character under the cursor. ^BACKSPACE [ ESC-BACKSPACE ] - (That is, CONTROL and BACKSPACE simultaneously.) Delete the + (That is, CONTROL and BACKSPACE simultaneously.) Delete the word to the left of the cursor. ^DELETE [ ESC-X or ESC-DELETE ] - (That is, CONTROL and DELETE simultaneously.) Delete the word + (That is, CONTROL and DELETE simultaneously.) Delete the word under the cursor. UPARROW [ ESC-k ] - Retrieve the previous command line. If you first enter some - text and then press UPARROW, it will retrieve the previous com- + Retrieve the previous command line. If you first enter some + text and then press UPARROW, it will retrieve the previous com- mand which begins with that text. DOWNARROW [ ESC-j ] - Retrieve the next command line. If you first enter some text - and then press DOWNARROW, it will retrieve the next command + Retrieve the next command line. If you first enter some text + and then press DOWNARROW, it will retrieve the next command which begins with that text. - TAB Complete the partial filename to the left of the cursor. If it - matches more than one filename, the first match is entered into - the command line. Repeated TABs will cycle thru the other + TAB Complete the partial filename to the left of the cursor. If it + matches more than one filename, the first match is entered into + the command line. Repeated TABs will cycle thru the other matching filenames. If the completed filename is a directory, a - "/" is appended to the filename. (On MS-DOS systems, a "\" is - appended.) The environment variable LESSSEPARATOR can be used + "/" is appended to the filename. (On MS-DOS systems, a "\" is + appended.) The environment variable LESSSEPARATOR can be used to specify a different character to append to a directory name. BACKTAB [ ESC-TAB ] Like, TAB, but cycles in the reverse direction thru the matching filenames. - ^L Complete the partial filename to the left of the cursor. If it + ^L Complete the partial filename to the left of the cursor. If it matches more than one filename, all matches are entered into the command line (if they fit). ^U (Unix and OS/2) or ESC (MS-DOS) - Delete the entire command line, or cancel the command if the + Delete the entire command line, or cancel the command if the command line is empty. If you have changed your line-kill char- acter in Unix to something other than ^U, that character is used instead of ^U. @@ -1030,70 +1164,70 @@ LESS(1) General Commands Manual LESS(1) ^G Delete the entire command line and return to the main prompt. KEY BINDINGS - You may define your own less commands by using the program lesskey(1) - to create a lesskey file. This file specifies a set of command keys - and an action associated with each key. You may also use lesskey to + You may define your own less commands by using the program lesskey(1) + to create a lesskey file. This file specifies a set of command keys + and an action associated with each key. You may also use lesskey to change the line-editing keys (see LINE EDITING), and to set environment - variables. If the environment variable LESSKEY is set, less uses that - as the name of the lesskey file. Otherwise, less looks in a standard - place for the lesskey file: On Unix systems, less looks for a lesskey - file called "$HOME/.less". On MS-DOS and Windows systems, less looks - for a lesskey file called "$HOME/_less", and if it is not found there, + variables. If the environment variable LESSKEY is set, less uses that + as the name of the lesskey file. Otherwise, less looks in a standard + place for the lesskey file: On Unix systems, less looks for a lesskey + file called "$HOME/.less". On MS-DOS and Windows systems, less looks + for a lesskey file called "$HOME/_less", and if it is not found there, then looks for a lesskey file called "_less" in any directory specified - in the PATH environment variable. On OS/2 systems, less looks for a - lesskey file called "$HOME/less.ini", and if it is not found, then - looks for a lesskey file called "less.ini" in any directory specified + in the PATH environment variable. On OS/2 systems, less looks for a + lesskey file called "$HOME/less.ini", and if it is not found, then + looks for a lesskey file called "less.ini" in any directory specified in the INIT environment variable, and if it not found there, then looks - for a lesskey file called "less.ini" in any directory specified in the - PATH environment variable. See the lesskey manual page for more de- + for a lesskey file called "less.ini" in any directory specified in the + PATH environment variable. See the lesskey manual page for more de- tails. - A system-wide lesskey file may also be set up to provide key bindings. + A system-wide lesskey file may also be set up to provide key bindings. If a key is defined in both a local lesskey file and in the system-wide - file, key bindings in the local file take precedence over those in the - system-wide file. If the environment variable LESSKEY_SYSTEM is set, + file, key bindings in the local file take precedence over those in the + system-wide file. If the environment variable LESSKEY_SYSTEM is set, less uses that as the name of the system-wide lesskey file. Otherwise, - less looks in a standard place for the system-wide lesskey file: On - Unix systems, the system-wide lesskey file is /usr/local/etc/sysless. - (However, if less was built with a different sysconf directory than + less looks in a standard place for the system-wide lesskey file: On + Unix systems, the system-wide lesskey file is /usr/local/etc/sysless. + (However, if less was built with a different sysconf directory than /usr/local/etc, that directory is where the sysless file is found.) On - MS-DOS and Windows systems, the system-wide lesskey file is c:\_sys- + MS-DOS and Windows systems, the system-wide lesskey file is c:\_sys- less. On OS/2 systems, the system-wide lesskey file is c:\sysless.ini. INPUT PREPROCESSOR - You may define an "input preprocessor" for less. Before less opens a + You may define an "input preprocessor" for less. Before less opens a file, it first gives your input preprocessor a chance to modify the way - the contents of the file are displayed. An input preprocessor is sim- - ply an executable program (or shell script), which writes the contents + the contents of the file are displayed. An input preprocessor is sim- + ply an executable program (or shell script), which writes the contents of the file to a different file, called the replacement file. The con- - tents of the replacement file are then displayed in place of the con- - tents of the original file. However, it will appear to the user as if - the original file is opened; that is, less will display the original + tents of the replacement file are then displayed in place of the con- + tents of the original file. However, it will appear to the user as if + the original file is opened; that is, less will display the original filename as the name of the current file. - An input preprocessor receives one command line argument, the original - filename, as entered by the user. It should create the replacement - file, and when finished, print the name of the replacement file to its - standard output. If the input preprocessor does not output a replace- - ment filename, less uses the original file, as normal. The input pre- - processor is not called when viewing standard input. To set up an in- - put preprocessor, set the LESSOPEN environment variable to a command - line which will invoke your input preprocessor. This command line - should include one occurrence of the string "%s", which will be re- + An input preprocessor receives one command line argument, the original + filename, as entered by the user. It should create the replacement + file, and when finished, print the name of the replacement file to its + standard output. If the input preprocessor does not output a replace- + ment filename, less uses the original file, as normal. The input pre- + processor is not called when viewing standard input. To set up an in- + put preprocessor, set the LESSOPEN environment variable to a command + line which will invoke your input preprocessor. This command line + should include one occurrence of the string "%s", which will be re- placed by the filename when the input preprocessor command is invoked. When less closes a file opened in such a way, it will call another pro- - gram, called the input postprocessor, which may perform any desired - clean-up action (such as deleting the replacement file created by + gram, called the input postprocessor, which may perform any desired + clean-up action (such as deleting the replacement file created by LESSOPEN). This program receives two command line arguments, the orig- - inal filename as entered by the user, and the name of the replacement - file. To set up an input postprocessor, set the LESSCLOSE environment - variable to a command line which will invoke your input postprocessor. - It may include two occurrences of the string "%s"; the first is re- - placed with the original name of the file and the second with the name + inal filename as entered by the user, and the name of the replacement + file. To set up an input postprocessor, set the LESSCLOSE environment + variable to a command line which will invoke your input postprocessor. + It may include two occurrences of the string "%s"; the first is re- + placed with the original name of the file and the second with the name of the replacement file, which was output by LESSOPEN. - For example, on many Unix systems, these two scripts will allow you to + For example, on many Unix systems, these two scripts will allow you to keep files in compressed format, but still let less view them directly: lessopen.sh: @@ -1113,27 +1247,27 @@ LESS(1) General Commands Manual LESS(1) #! /bin/sh rm $2 - To use these scripts, put them both where they can be executed and set + To use these scripts, put them both where they can be executed and set LESSOPEN="lessopen.sh %s", and LESSCLOSE="lessclose.sh %s %s". More - complex LESSOPEN and LESSCLOSE scripts may be written to accept other + complex LESSOPEN and LESSCLOSE scripts may be written to accept other types of compressed files, and so on. - It is also possible to set up an input preprocessor to pipe the file - data directly to less, rather than putting the data into a replacement + It is also possible to set up an input preprocessor to pipe the file + data directly to less, rather than putting the data into a replacement file. This avoids the need to decompress the entire file before start- ing to view it. An input preprocessor that works this way is called an - input pipe. An input pipe, instead of writing the name of a replace- + input pipe. An input pipe, instead of writing the name of a replace- ment file on its standard output, writes the entire contents of the re- - placement file on its standard output. If the input pipe does not - write any characters on its standard output, then there is no replace- - ment file and less uses the original file, as normal. To use an input - pipe, make the first character in the LESSOPEN environment variable a - vertical bar (|) to signify that the input preprocessor is an input - pipe. As with non-pipe input preprocessors, the command string must - contain one occurrence of %s, which is replaced with the filename of + placement file on its standard output. If the input pipe does not + write any characters on its standard output, then there is no replace- + ment file and less uses the original file, as normal. To use an input + pipe, make the first character in the LESSOPEN environment variable a + vertical bar (|) to signify that the input preprocessor is an input + pipe. As with non-pipe input preprocessors, the command string must + contain one occurrence of %s, which is replaced with the filename of the input file. - For example, on many Unix systems, this script will work like the pre- + For example, on many Unix systems, this script will work like the pre- vious example scripts: lesspipe.sh: @@ -1150,29 +1284,29 @@ LESS(1) General Commands Manual LESS(1) LESSOPEN="|lesspipe.sh %s". Note that a preprocessor cannot output an empty file, since that is in- - terpreted as meaning there is no replacement, and the original file is - used. To avoid this, if LESSOPEN starts with two vertical bars, the - exit status of the script becomes meaningful. If the exit status is - zero, the output is considered to be replacement text, even if it is - empty. If the exit status is nonzero, any output is ignored and the - original file is used. For compatibility with previous versions of + terpreted as meaning there is no replacement, and the original file is + used. To avoid this, if LESSOPEN starts with two vertical bars, the + exit status of the script becomes meaningful. If the exit status is + zero, the output is considered to be replacement text, even if it is + empty. If the exit status is nonzero, any output is ignored and the + original file is used. For compatibility with previous versions of less, if LESSOPEN starts with only one vertical bar, the exit status of the preprocessor is ignored. - When an input pipe is used, a LESSCLOSE postprocessor can be used, but + When an input pipe is used, a LESSCLOSE postprocessor can be used, but it is usually not necessary since there is no replacement file to clean - up. In this case, the replacement file name passed to the LESSCLOSE + up. In this case, the replacement file name passed to the LESSCLOSE postprocessor is "-". - For compatibility with previous versions of less, the input preproces- + For compatibility with previous versions of less, the input preproces- sor or pipe is not used if less is viewing standard input. However, if - the first character of LESSOPEN is a dash (-), the input preprocessor - is used on standard input as well as other files. In this case, the - dash is not considered to be part of the preprocessor command. If + the first character of LESSOPEN is a dash (-), the input preprocessor + is used on standard input as well as other files. In this case, the + dash is not considered to be part of the preprocessor command. If standard input is being viewed, the input preprocessor is passed a file - name consisting of a single dash. Similarly, if the first two charac- - ters of LESSOPEN are vertical bar and dash (|-) or two vertical bars - and a dash (||-), the input pipe is used on standard input as well as + name consisting of a single dash. Similarly, if the first two charac- + ters of LESSOPEN are vertical bar and dash (|-) or two vertical bars + and a dash (||-), the input pipe is used on standard input as well as other files. Again, in this case the dash is not considered to be part of the input pipe command. @@ -1183,25 +1317,25 @@ LESS(1) General Commands Manual LESS(1) can be displayed directly to the screen. control characters - should not be displayed directly, but are expected to be found + should not be displayed directly, but are expected to be found in ordinary text files (such as backspace and tab). binary characters - should not be displayed directly and are not expected to be + should not be displayed directly and are not expected to be found in text files. A "character set" is simply a description of which characters are to be - considered normal, control, and binary. The LESSCHARSET environment - variable may be used to select a character set. Possible values for + considered normal, control, and binary. The LESSCHARSET environment + variable may be used to select a character set. Possible values for LESSCHARSET are: - ascii BS, TAB, NL, CR, and formfeed are control characters, all chars - with values between 32 and 126 are normal, and all others are + ascii BS, TAB, NL, CR, and formfeed are control characters, all chars + with values between 32 and 126 are normal, and all others are binary. iso8859 - Selects an ISO 8859 character set. This is the same as ASCII, - except characters between 160 and 255 are treated as normal + Selects an ISO 8859 character set. This is the same as ASCII, + except characters between 160 and 255 are treated as normal characters. latin1 Same as iso8859. @@ -1213,8 +1347,8 @@ LESS(1) General Commands Manual LESS(1) ebcdic Selects an EBCDIC character set. IBM-1047 - Selects an EBCDIC character set used by OS/390 Unix Services. - This is the EBCDIC analogue of latin1. You get similar results + Selects an EBCDIC character set used by OS/390 Unix Services. + This is the EBCDIC analogue of latin1. You get similar results by setting either LESSCHARSET=IBM-1047 or LC_CTYPE=en_US in your environment. @@ -1222,29 +1356,29 @@ LESS(1) General Commands Manual LESS(1) next Selects a character set appropriate for NeXT computers. - utf-8 Selects the UTF-8 encoding of the ISO 10646 character set. - UTF-8 is special in that it supports multi-byte characters in - the input file. It is the only character set that supports - multi-byte characters. + utf-8 Selects the UTF-8 encoding of the ISO 10646 character set. + UTF-8 is special in that it supports multi-byte characters in + the input file. It is the only character set that supports mul- + ti-byte characters. windows - Selects a character set appropriate for Microsoft Windows (cp + Selects a character set appropriate for Microsoft Windows (cp 1251). - In rare cases, it may be desired to tailor less to use a character set - other than the ones definable by LESSCHARSET. In this case, the envi- + In rare cases, it may be desired to tailor less to use a character set + other than the ones definable by LESSCHARSET. In this case, the envi- ronment variable LESSCHARDEF can be used to define a character set. It should be set to a string where each character in the string represents - one character in the character set. The character "." is used for a - normal character, "c" for control, and "b" for binary. A decimal num- - ber may be used for repetition. For example, "bccc4b." would mean - character 0 is binary, 1, 2 and 3 are control, 4, 5, 6 and 7 are bi- - nary, and 8 is normal. All characters after the last are taken to be - the same as the last, so characters 9 through 255 would be normal. - (This is an example, and does not necessarily represent any real char- - acter set.) - - This table shows the value of LESSCHARDEF which is equivalent to each + one character in the character set. The character "." is used for a + normal character, "c" for control, and "b" for binary. A decimal num- + ber may be used for repetition. For example, "bccc4b." would mean + character 0 is binary, 1, 2 and 3 are control, 4, 5, 6 and 7 are bina- + ry, and 8 is normal. All characters after the last are taken to be the + same as the last, so characters 9 through 255 would be normal. (This + is an example, and does not necessarily represent any real character + set.) + + This table shows the value of LESSCHARDEF which is equivalent to each of the possible values for LESSCHARSET: ascii 8bcccbcc18b95.b @@ -1258,65 +1392,65 @@ LESS(1) General Commands Manual LESS(1) latin1 8bcccbcc18b95.33b. next 8bcccbcc18b95.bb125.bb - If neither LESSCHARSET nor LESSCHARDEF is set, but any of the strings - "UTF-8", "UTF8", "utf-8" or "utf8" is found in the LC_ALL, LC_CTYPE or + If neither LESSCHARSET nor LESSCHARDEF is set, but any of the strings + "UTF-8", "UTF8", "utf-8" or "utf8" is found in the LC_ALL, LC_CTYPE or LANG environment variables, then the default character set is utf-8. If that string is not found, but your system supports the setlocale in- - terface, less will use setlocale to determine the character set. set- - locale is controlled by setting the LANG or LC_CTYPE environment vari- + terface, less will use setlocale to determine the character set. set- + locale is controlled by setting the LANG or LC_CTYPE environment vari- ables. - Finally, if the setlocale interface is also not available, the default + Finally, if the setlocale interface is also not available, the default character set is latin1. - Control and binary characters are displayed in standout (reverse + Control and binary characters are displayed in standout (reverse video). Each such character is displayed in caret notation if possible - (e.g. ^A for control-A). Caret notation is used only if inverting the + (e.g. ^A for control-A). Caret notation is used only if inverting the 0100 bit results in a normal printable character. Otherwise, the char- - acter is displayed as a hex number in angle brackets. This format can - be changed by setting the LESSBINFMT environment variable. LESSBINFMT + acter is displayed as a hex number in angle brackets. This format can + be changed by setting the LESSBINFMT environment variable. LESSBINFMT may begin with a "*" and one character to select the display attribute: - "*k" is blinking, "*d" is bold, "*u" is underlined, "*s" is standout, - and "*n" is normal. If LESSBINFMT does not begin with a "*", normal - attribute is assumed. The remainder of LESSBINFMT is a string which - may include one printf-style escape sequence (a % followed by x, X, o, - d, etc.). For example, if LESSBINFMT is "*u[%x]", binary characters - are displayed in underlined hexadecimal surrounded by brackets. The - default if no LESSBINFMT is specified is "*s<%02X>". Warning: the re- - sult of expanding the character via LESSBINFMT must be less than 31 + "*k" is blinking, "*d" is bold, "*u" is underlined, "*s" is standout, + and "*n" is normal. If LESSBINFMT does not begin with a "*", normal + attribute is assumed. The remainder of LESSBINFMT is a string which + may include one printf-style escape sequence (a % followed by x, X, o, + d, etc.). For example, if LESSBINFMT is "*u[%x]", binary characters + are displayed in underlined hexadecimal surrounded by brackets. The + default if no LESSBINFMT is specified is "*s<%02X>". Warning: the re- + sult of expanding the character via LESSBINFMT must be less than 31 characters. When the character set is utf-8, the LESSUTFBINFMT environment variable acts similarly to LESSBINFMT but it applies to Unicode code points that - were successfully decoded but are unsuitable for display (e.g., unas- - signed code points). Its default value is "". Note that - LESSUTFBINFMT and LESSBINFMT share their display attribute setting - ("*x") so specifying one will affect both; LESSUTFBINFMT is read after - LESSBINFMT so its setting, if any, will have priority. Problematic - octets in a UTF-8 file (octets of a truncated sequence, octets of a - complete but non-shortest form sequence, invalid octets, and stray - trailing octets) are displayed individually using LESSBINFMT so as to + were successfully decoded but are unsuitable for display (e.g., unas- + signed code points). Its default value is "". Note that + LESSUTFBINFMT and LESSBINFMT share their display attribute setting + ("*x") so specifying one will affect both; LESSUTFBINFMT is read after + LESSBINFMT so its setting, if any, will have priority. Problematic + octets in a UTF-8 file (octets of a truncated sequence, octets of a + complete but non-shortest form sequence, invalid octets, and stray + trailing octets) are displayed individually using LESSBINFMT so as to facilitate diagnostic of how the UTF-8 file is ill-formed. PROMPTS - The -P option allows you to tailor the prompt to your preference. The - string given to the -P option replaces the specified prompt string. + The -P option allows you to tailor the prompt to your preference. The + string given to the -P option replaces the specified prompt string. Certain characters in the string are interpreted specially. The prompt - mechanism is rather complicated to provide flexibility, but the ordi- - nary user need not understand the details of constructing personalized + mechanism is rather complicated to provide flexibility, but the ordi- + nary user need not understand the details of constructing personalized prompt strings. - A percent sign followed by a single character is expanded according to + A percent sign followed by a single character is expanded according to what the following character is: - %bX Replaced by the byte offset into the current input file. The b + %bX Replaced by the byte offset into the current input file. The b is followed by a single character (shown as X above) which spec- - ifies the line whose byte offset is to be used. If the charac- - ter is a "t", the byte offset of the top line in the display is + ifies the line whose byte offset is to be used. If the charac- + ter is a "t", the byte offset of the top line in the display is used, an "m" means use the middle line, a "b" means use the bot- - tom line, a "B" means use the line just after the bottom line, - and a "j" means use the "target" line, as specified by the -j + tom line, a "B" means use the line just after the bottom line, + and a "j" means use the "target" line, as specified by the -j option. %B Replaced by the size of the current input file. @@ -1324,50 +1458,50 @@ LESS(1) General Commands Manual LESS(1) %c Replaced by the column number of the text appearing in the first column of the screen. - %dX Replaced by the page number of a line in the input file. The + %dX Replaced by the page number of a line in the input file. The line to be used is determined by the X, as with the %b option. - %D Replaced by the number of pages in the input file, or equiva- + %D Replaced by the number of pages in the input file, or equiva- lently, the page number of the last line in the input file. - %E Replaced by the name of the editor (from the VISUAL environment - variable, or the EDITOR environment variable if VISUAL is not + %E Replaced by the name of the editor (from the VISUAL environment + variable, or the EDITOR environment variable if VISUAL is not defined). See the discussion of the LESSEDIT feature below. %f Replaced by the name of the current input file. - %F Replaced by the last component of the name of the current input + %F Replaced by the last component of the name of the current input file. - %g Replaced by the shell-escaped name of the current input file. - This is useful when the expanded string will be used in a shell + %g Replaced by the shell-escaped name of the current input file. + This is useful when the expanded string will be used in a shell command, such as in LESSEDIT. - %i Replaced by the index of the current file in the list of input + %i Replaced by the index of the current file in the list of input files. - %lX Replaced by the line number of a line in the input file. The + %lX Replaced by the line number of a line in the input file. The line to be used is determined by the X, as with the %b option. %L Replaced by the line number of the last line in the input file. %m Replaced by the total number of input files. - %pX Replaced by the percent into the current input file, based on - byte offsets. The line used is determined by the X as with the + %pX Replaced by the percent into the current input file, based on + byte offsets. The line used is determined by the X as with the %b option. - %PX Replaced by the percent into the current input file, based on - line numbers. The line used is determined by the X as with the + %PX Replaced by the percent into the current input file, based on + line numbers. The line used is determined by the X as with the %b option. %s Same as %B. - %t Causes any trailing spaces to be removed. Usually used at the + %t Causes any trailing spaces to be removed. Usually used at the end of the string, but may appear anywhere. - %T Normally expands to the word "file". However if viewing files - via a tags list using the -t option, it expands to the word + %T Normally expands to the word "file". However if viewing files + via a tags list using the -t option, it expands to the word "tag". %x Replaced by the name of the next input file in the list. @@ -1375,15 +1509,15 @@ LESS(1) General Commands Manual LESS(1) If any item is unknown (for example, the file size if input is a pipe), a question mark is printed instead. - The format of the prompt string can be changed depending on certain - conditions. A question mark followed by a single character acts like - an "IF": depending on the following character, a condition is evalu- - ated. If the condition is true, any characters following the question - mark and condition character, up to a period, are included in the - prompt. If the condition is false, such characters are not included. - A colon appearing between the question mark and the period can be used + The format of the prompt string can be changed depending on certain + conditions. A question mark followed by a single character acts like + an "IF": depending on the following character, a condition is evaluat- + ed. If the condition is true, any characters following the question + mark and condition character, up to a period, are included in the + prompt. If the condition is false, such characters are not included. + A colon appearing between the question mark and the period can be used to establish an "ELSE": any characters between the colon and the period - are included in the string if and only if the IF condition is false. + are included in the string if and only if the IF condition is false. Condition characters (which follow a question mark) may be: ?a True if any characters have been included in the prompt so far. @@ -1398,7 +1532,7 @@ LESS(1) General Commands Manual LESS(1) ?e True if at end-of-file. - ?f True if there is an input filename (that is, if input is not a + ?f True if there is an input filename (that is, if input is not a pipe). ?lX True if the line number of the specified line is known. @@ -1409,45 +1543,45 @@ LESS(1) General Commands Manual LESS(1) ?n True if this is the first prompt in a new input file. - ?pX True if the percent into the current input file, based on byte + ?pX True if the percent into the current input file, based on byte offsets, of the specified line is known. - ?PX True if the percent into the current input file, based on line + ?PX True if the percent into the current input file, based on line numbers, of the specified line is known. ?s Same as "?B". - ?x True if there is a next input file (that is, if the current in- + ?x True if there is a next input file (that is, if the current in- put file is not the last one). - Any characters other than the special ones (question mark, colon, pe- - riod, percent, and backslash) become literally part of the prompt. Any - of the special characters may be included in the prompt literally by + Any characters other than the special ones (question mark, colon, peri- + od, percent, and backslash) become literally part of the prompt. Any + of the special characters may be included in the prompt literally by preceding it with a backslash. Some examples: ?f%f:Standard input. - This prompt prints the filename, if known; otherwise the string "Stan- + This prompt prints the filename, if known; otherwise the string "Stan- dard input". ?f%f .?ltLine %lt:?pt%pt\%:?btByte %bt:-... - This prompt would print the filename, if known. The filename is fol- - lowed by the line number, if known, otherwise the percent if known, + This prompt would print the filename, if known. The filename is fol- + lowed by the line number, if known, otherwise the percent if known, otherwise the byte offset if known. Otherwise, a dash is printed. No- - tice how each question mark has a matching period, and how the % after + tice how each question mark has a matching period, and how the % after the %pt is included literally by escaping it with a backslash. ?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\: %x..%t"; - This prints the filename if this is the first prompt in a file, fol- - lowed by the "file N of N" message if there is more than one input - file. Then, if we are at end-of-file, the string "(END)" is printed - followed by the name of the next file, if there is one. Finally, any + This prints the filename if this is the first prompt in a file, fol- + lowed by the "file N of N" message if there is more than one input + file. Then, if we are at end-of-file, the string "(END)" is printed + followed by the name of the next file, if there is one. Finally, any trailing spaces are truncated. This is the default prompt. For refer- - ence, here are the defaults for the other two prompts (-m and -M re- + ence, here are the defaults for the other two prompts (-m and -M re- spectively). Each is broken into two lines here for readability only. ?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\: %x.: @@ -1461,22 +1595,22 @@ LESS(1) General Commands Manual LESS(1) ?f%f .?m(%T %i of %m) .?ltlines %lt-%lb?L/%L. . byte %bB?s/%s. ?e(END) :?pB%pB\%..%t - The prompt expansion features are also used for another purpose: if an - environment variable LESSEDIT is defined, it is used as the command to - be executed when the v command is invoked. The LESSEDIT string is ex- - panded in the same way as the prompt strings. The default value for + The prompt expansion features are also used for another purpose: if an + environment variable LESSEDIT is defined, it is used as the command to + be executed when the v command is invoked. The LESSEDIT string is ex- + panded in the same way as the prompt strings. The default value for LESSEDIT is: %E ?lm+%lm. %g Note that this expands to the editor name, followed by a + and the line - number, followed by the shell-escaped file name. If your editor does - not accept the "+linenumber" syntax, or has other differences in invo- - cation syntax, the LESSEDIT variable can be changed to modify this de- + number, followed by the shell-escaped file name. If your editor does + not accept the "+linenumber" syntax, or has other differences in invo- + cation syntax, the LESSEDIT variable can be changed to modify this de- fault. SECURITY - When the environment variable LESSSECURE is set to 1, less runs in a + When the environment variable LESSSECURE is set to 1, less runs in a "secure" mode. This means these features are disabled: ! the shell command @@ -1501,52 +1635,52 @@ LESS(1) General Commands Manual LESS(1) COMPATIBILITY WITH MORE If the environment variable LESS_IS_MORE is set to 1, or if the program - is invoked via a file link named "more", less behaves (mostly) in con- - formance with the POSIX "more" command specification. In this mode, + is invoked via a file link named "more", less behaves (mostly) in con- + formance with the POSIX "more" command specification. In this mode, less behaves differently in these ways: The -e option works differently. If the -e option is not set, less be- - haves as if the -e option were set. If the -e option is set, less be- + haves as if the -e option were set. If the -e option is set, less be- haves as if the -E option were set. - The -m option works differently. If the -m option is not set, the - medium prompt is used, and it is prefixed with the string "--More--". + The -m option works differently. If the -m option is not set, the + medium prompt is used, and it is prefixed with the string "--More--". If the -m option is set, the short prompt is used. - The -n option acts like the -z option. The normal behavior of the -n + The -n option acts like the -z option. The normal behavior of the -n option is unavailable in this mode. - The parameter to the -p option is taken to be a less command rather + The parameter to the -p option is taken to be a less command rather than a search pattern. - The LESS environment variable is ignored, and the MORE environment + The LESS environment variable is ignored, and the MORE environment variable is used in its place. ENVIRONMENT VARIABLES Environment variables may be specified either in the system environment - as usual, or in a lesskey(1) file. If environment variables are de- + as usual, or in a lesskey(1) file. If environment variables are de- fined in more than one place, variables defined in a local lesskey file take precedence over variables defined in the system environment, which take precedence over variables defined in the system-wide lesskey file. COLUMNS Sets the number of columns on the screen. Takes precedence over - the number of columns specified by the TERM variable. (But if + the number of columns specified by the TERM variable. (But if you have a windowing system which supports TIOCGWINSZ or - WIOCGETD, the window system's idea of the screen size takes + WIOCGETD, the window system's idea of the screen size takes precedence over the LINES and COLUMNS environment variables.) EDITOR The name of the editor (used for the v command). - HOME Name of the user's home directory (used to find a lesskey file + HOME Name of the user's home directory (used to find a lesskey file on Unix and OS/2 systems). HOMEDRIVE, HOMEPATH - Concatenation of the HOMEDRIVE and HOMEPATH environment vari- + Concatenation of the HOMEDRIVE and HOMEPATH environment vari- ables is the name of the user's home directory if the HOME vari- able is not set (only in the Windows version). - INIT Name of the user's init directory (used to find a lesskey file + INIT Name of the user's init directory (used to find a lesskey file on OS/2 systems). LANG Language for determining the character set. @@ -1557,12 +1691,12 @@ LESS(1) General Commands Manual LESS(1) LESS Options which are passed to less automatically. LESSANSIENDCHARS - Characters which may end an ANSI color escape sequence (default + Characters which may end an ANSI color escape sequence (default "m"). LESSANSIMIDCHARS - Characters which may appear between the ESC character and the - end character in an ANSI color escape sequence (default + Characters which may appear between the ESC character and the + end character in an ANSI color escape sequence (default "0123456789:;[?!"'#%()*+ ". LESSBINFMT @@ -1579,24 +1713,24 @@ LESS(1) General Commands Manual LESS(1) LESSECHO Name of the lessecho program (default "lessecho"). The lessecho - program is needed to expand metacharacters, such as * and ?, in + program is needed to expand metacharacters, such as * and ?, in filenames on Unix systems. LESSEDIT - Editor prototype string (used for the v command). See discus- + Editor prototype string (used for the v command). See discus- sion under PROMPTS. LESSGLOBALTAGS - Name of the command used by the -t option to find global tags. - Normally should be set to "global" if your system has the - global(1) command. If not set, global tags are not used. + Name of the command used by the -t option to find global tags. + Normally should be set to "global" if your system has the glob- + al(1) command. If not set, global tags are not used. LESSHISTFILE - Name of the history file used to remember search commands and - shell commands between invocations of less. If set to "-" or - "/dev/null", a history file is not used. The default is - "$HOME/.lesshst" on Unix systems, "$HOME/_lesshst" on DOS and - Windows systems, or "$HOME/lesshst.ini" or "$INIT/lesshst.ini" + Name of the history file used to remember search commands and + shell commands between invocations of less. If set to "-" or + "/dev/null", a history file is not used. The default is + "$HOME/.lesshst" on Unix systems, "$HOME/_lesshst" on DOS and + Windows systems, or "$HOME/lesshst.ini" or "$INIT/lesshst.ini" on OS/2 systems. LESSHISTSIZE @@ -1610,13 +1744,13 @@ LESS(1) General Commands Manual LESS(1) Name of the default system-wide lesskey(1) file. LESSMETACHARS - List of characters which are considered "metacharacters" by the + List of characters which are considered "metacharacters" by the shell. LESSMETAESCAPE - Prefix which less will add before each metacharacter in a com- - mand sent to the shell. If LESSMETAESCAPE is an empty string, - commands containing metacharacters will not be passed to the + Prefix which less will add before each metacharacter in a com- + mand sent to the shell. If LESSMETAESCAPE is an empty string, + commands containing metacharacters will not be passed to the shell. LESSOPEN @@ -1626,7 +1760,7 @@ LESS(1) General Commands Manual LESS(1) Runs less in "secure" mode. See discussion under SECURITY. LESSSEPARATOR - String to be appended to a directory name in filename comple- + String to be appended to a directory name in filename comple- tion. LESSUTFBINFMT @@ -1635,19 +1769,19 @@ LESS(1) General Commands Manual LESS(1) LESS_IS_MORE Emulate the more(1) command. - LINES Sets the number of lines on the screen. Takes precedence over + LINES Sets the number of lines on the screen. Takes precedence over the number of lines specified by the TERM variable. (But if you - have a windowing system which supports TIOCGWINSZ or WIOCGETD, - the window system's idea of the screen size takes precedence + have a windowing system which supports TIOCGWINSZ or WIOCGETD, + the window system's idea of the screen size takes precedence over the LINES and COLUMNS environment variables.) - MORE Options which are passed to less automatically when running in + MORE Options which are passed to less automatically when running in more compatible mode. - PATH User's search path (used to find a lesskey file on MS-DOS and + PATH User's search path (used to find a lesskey file on MS-DOS and OS/2 systems). - SHELL The shell used to execute the ! command, as well as to expand + SHELL The shell used to execute the ! command, as well as to expand filenames. TERM The type of terminal on which less is being run. @@ -1658,29 +1792,29 @@ LESS(1) General Commands Manual LESS(1) lesskey(1) COPYRIGHT - Copyright (C) 1984-2020 Mark Nudelman + Copyright (C) 1984-2021 Mark Nudelman - less is part of the GNU project and is free software. You can redis- - tribute it and/or modify it under the terms of either (1) the GNU Gen- - eral Public License as published by the Free Software Foundation; or + less is part of the GNU project and is free software. You can redis- + tribute it and/or modify it under the terms of either (1) the GNU Gen- + eral Public License as published by the Free Software Foundation; or (2) the Less License. See the file README in the less distribution for more details regarding redistribution. You should have received a copy - of the GNU General Public License along with the source for less; see - the file COPYING. If not, write to the Free Software Foundation, 59 - Temple Place, Suite 330, Boston, MA 02111-1307, USA. You should also + of the GNU General Public License along with the source for less; see + the file COPYING. If not, write to the Free Software Foundation, 59 + Temple Place, Suite 330, Boston, MA 02111-1307, USA. You should also have received a copy of the Less License; see the file LICENSE. less is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FIT- - NESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + WARRANTY; without even the implied warranty of MERCHANTABILITY or FIT- + NESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. AUTHOR Mark Nudelman Report bugs at https://github.com/gwsw/less/issues. For more information, see the less homepage at - http://www.greenwoodsoftware.com/less. + https://greenwoodsoftware.com/less. - Version 563: 13 Jun 2020 LESS(1) + Version 581.2: 28 Apr 2021 LESS(1) diff --git a/less.nro b/less.nro index 70f99ce..f148ccb 100644 --- a/less.nro +++ b/less.nro @@ -1,5 +1,5 @@ '\" t -.TH LESS 1 "Version 563: 13 Jun 2020" +.TH LESS 1 "Version 581.2: 28 Apr 2021" .SH NAME less \- opposite of more .SH SYNOPSIS @@ -109,6 +109,7 @@ Scroll horizontally left back to the first column. Repaint the screen. .IP R Repaint the screen, discarding any buffered input. +That is, reload the current file. Useful if the file is changing while it is being viewed. .IP "F" Scroll forward, and keep trying to read when the @@ -117,6 +118,8 @@ Normally this command would be used when already at the end of the file. It is a way to monitor the tail of a file which is growing while it is being viewed. (The behavior is similar to the "tail \-f" command.) +To stop waiting for more data, enter the interrupt character (usually ^C). +On some systems you can also use ^X. .IP "ESC-F" Like F, but as soon as a line is found which matches the last search pattern, the terminal bell is rung @@ -226,6 +229,11 @@ but don't move to the first match (KEEP current position). .IP "^R" Don't interpret regular expression metacharacters; that is, do a simple textual comparison. +.IP "^W" +WRAP around the current file. +That is, if the search reaches the end of the current file +without finding a match, the search continues from the first line of the +current file up to the line where it started. .RE .IP ?pattern Search backward in the file for the N-th line containing the pattern. @@ -250,6 +258,11 @@ or the settings of the \-a or \-j options. As in forward searches. .IP "^R" As in forward searches. +.IP "^W" +WRAP around the current file. +That is, if the search reaches the beginning of the current file +without finding a match, the search continues from the last line of the +current file up to the line where it started. .RE .IP "ESC-/pattern" Same as "/*". @@ -280,6 +293,10 @@ turn highlighting back on. Any search command will also turn highlighting back on. (Highlighting can also be disabled by toggling the \-G option; in that case search commands do not turn highlighting back on.) +.IP "ESC-U" +Like ESC-u but also clears the saved search pattern. +If the status column is enabled via the \-J option, +this clears all search matches marked in the status column. .IP "&pattern" Display only lines which match the pattern; lines which do not match the pattern are not displayed. @@ -288,6 +305,8 @@ any filtering is turned off, and all lines are displayed. While filtering is in effect, an ampersand is displayed at the beginning of the prompt, as a reminder that some lines in the file may be hidden. +Multiple & commands may be entered, in which case only lines +which match all of the patterns will be displayed. .sp Certain characters are special as in the / command: .RS @@ -552,20 +571,105 @@ The \-d option does not otherwise change the behavior of .I less on a dumb terminal. .IP "\-D\fBx\fP\fIcolor\fP or \-\-color=\fBx\fP\fIcolor\fP" -[MS-DOS only] -Sets the color of the text displayed. -\fBx\fP is a single character which selects the type of text whose color is -being set: n=normal, s=standout, d=bold, u=underlined, k=blink. -\fIcolor\fP is a pair of numbers separated by a period. -The first number selects the foreground color and the second selects -the background color of the text. -A single number \fIN\fP is the same as \fIN.M\fP, -where \fIM\fP is the normal background color. -The color may start or end with \fBu\fP to use underline (with the normal -color, if by itself), if the system supports it (Windows only). -\fBx\fP may also be \fBa\fP to toggle strict ANSI sequence rendering -(SGR mode). -. +Changes the color of different parts of the displayed text. +\fBx\fP is a single character which selects the type of text +whose color is being set: +.RS +.IP "B" +Binary characters. +.IP "C" +Control characters. +.IP "E" +Errors and informational messages. +.IP "M" +Mark letters in the status column. +.IP "N" +Line numbers enabled via the \-N option. +.IP "P" +Prompts. +.IP "R" +The rscroll character. +.IP "S" +Search results. +.IP "W" +The highlight enabled via the \-w option. +.IP "d" +Bold text. +.IP "k" +Blinking text. +.IP "s" +Standout text. +.IP "u" +Underlined text. +.RE + +.RS +The uppercase letters can be used only when the \-\-use-color option is enabled. +When text color is specified by both an uppercase letter and a lowercase letter, +the uppercase letter takes precedence. +For example, error messages are normally displayed as standout text. +So if both "s" and "E" are given a color, the "E" color applies +to error messages, and the "s" color applies to other standout text. +The "d" and "u" letters refer to bold and underline text formed by +overstriking with backspaces (see the \-u option), +not to text using ANSI escape sequences with the \-R option. +.PP +A lowercase letter may be followed by a + to indicate that +both the normal format change and the specified color should both be used. +For example, \-Dug displays underlined text as green without underlining; +the green color has replaced the usual underline formatting. +But \-Du+g displays underlined text as both green and in underlined format. +.PP +\fIcolor\fP is either a 4-bit color string or an 8-bit color string: +.PP +A 4-bit color string is zero, one or two characters, where +the first character specifies the foreground color and +the second specifies the background color as follows: +.IP "b" +Blue +.IP "c" +Cyan +.IP "g" +Green +.IP "k" +Black +.IP "m" +Magenta +.IP "r" +Red +.IP "w" +White +.IP "y" +Yellow +.PP +The corresponding upper-case letter denotes a brighter shade of the color. +For example, \-DNGk displays line numbers as bright green text on a black +background, and \-DEbR displays error messages as blue text on a +bright red background. +If either character is a "-" or is omitted, the corresponding color +is set to that of normal text. +.PP +An 8-bit color string is one or two decimal integers separated by a dot, +where the first integer specifies the foreground color and +the second specifies the background color. +Each integer is a value between 0 and 255 inclusive which selects +a "CSI 38;5" color value (see +.br +.nh +https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) +.hy +If either integer is a "-" or is omitted, +the corresponding color is set to that of normal text. +On MS-DOS versions of +.IR less , +8-bit color is not supported; instead, decimal values are interpreted as 4-bit +CHAR_INFO.Attributes values +(see +.br +.nh +https://docs.microsoft.com/en-us/windows/console/char-info-str). +.hy +.RE .IP "\-e or \-\-quit-at-eof" Causes .I less @@ -650,7 +754,6 @@ always begin at the start or end of the current screen respectively. Displays a status column at the left edge of the screen. The status column shows the lines that matched the current search, and any lines that are marked (via the m or M command). -The status column is also used if the \-w or \-W option is in effect. .IP "\-k\fIfilename\fP or \-\-lesskey-file=\fIfilename\fP" Causes .I less @@ -676,7 +779,8 @@ command prompt from the "F" command. .IP "\-L or \-\-no-lessopen" Ignore the LESSOPEN environment variable (see the INPUT PREPROCESSOR section below). -This option can be set from within \fIless\fP, +This option can be set from within +.IR less , but it will apply only to files opened subsequently, not to the file which is currently open. .IP "\-m or \-\-long-prompt" @@ -776,16 +880,33 @@ cannot keep track of the actual appearance of the screen each type of control character). Thus, various display problems may result, such as long lines being split in the wrong place. +.sp +USE OF THE \-r OPTION IS NOT RECOMMENDED. .IP "\-R or \-\-RAW-CONTROL-CHARS" -Like \-r, but only ANSI "color" escape sequences are output in "raw" form. -Unlike \-r, the screen appearance is maintained correctly in most cases. -ANSI "color" escape sequences are sequences of the form: +Like \-r, but only ANSI "color" escape sequences and OSC 8 hyperlink +sequences are output in "raw" form. +Unlike \-r, the screen appearance is maintained correctly, +provided that there are no escape sequences in the file +other than these types of escape sequences. +Color escape sequences are only supported when the color +is changed within one line, not across lines. +In other words, the beginning of each line is assumed to be +normal (non-colored), regardless of any escape sequences in previous lines. +For the purpose of keeping track of screen appearance, +these escape sequences are assumed to not move the cursor. +.sp +OSC 8 hyperlinks are sequences of the form: +.sp + ESC ] 8 ; \&...\& \\7 +.sp +The terminating sequence may be either a BEL character (\\7) +or the two-character sequence "ESC \\". +.sp +ANSI color escape sequences are sequences of the form: .sp ESC [ \&...\& m .sp -where the "...\&" is zero or more color specification characters -For the purpose of keeping track of screen appearance, -ANSI color escape sequences are assumed to not move the cursor. +where the "...\&" is zero or more color specification characters. You can make .I less think that characters other than "m" can end ANSI color escape sequences @@ -820,7 +941,10 @@ If the environment variable LESSGLOBALTAGS is set, it is taken to be the name of a command compatible with .IR global (1), and that command is executed to find the tag. -(See http://www.gnu.org/software/global/global.html). +(See +.nh +http://www.gnu.org/software/global/global.html). +.hy The \-t option may also be specified from within .I less (using the \- command) as a way of examining a new file. @@ -848,6 +972,8 @@ using the terminal's hardware boldface capability. Other backspaces are deleted, along with the preceding character. Carriage returns immediately followed by a newline are deleted. Other carriage returns are handled as specified by the \-r option. +Unicode formatting characters, such as the Byte Order Mark, +are sent to the terminal. Text which is overstruck or underlined can be searched for if neither \-u nor \-U is in effect. .IP "\-V or \-\-version" @@ -941,6 +1067,14 @@ If the reopen succeeds and the file is a different file from the original with the same name as the original (now renamed) file), .I less will display the contents of that new file. +.IP "\-\-incsearch" +Subsequent search commands will be "incremental"; that is, +.I less +will advance to the next line containing the search pattern +as each character of the pattern is typed in. +.IP "\-\-line-num-width" +Sets the minimum width of the line number field when the \-N option is in effect. +The default is 7 characters. .IP "\-\-mouse" Enables mouse input: scrolling the mouse wheel down moves forward in the file, @@ -973,12 +1107,26 @@ If there is no attribute indicator, standout is used. If set to "\-", truncated lines are not marked. .IP "\-\-save-marks" Save marks in the history file, so marks are retained -across different invocations of \fIless\fP. +across different invocations of +.IR less . +.IP "\-\-status-col-width" +Sets the width of the status column when the \-J option is in effect. +The default is 2 characters. .IP "\-\-use-backslash" This option changes the interpretations of options which follow this one. After the \-\-use-backslash option, any backslash in an option string is removed and the following character is taken literally. This allows a dollar sign to be included in option strings. +.IP "\-\-use-color" +Enables the colored text in various places. +The -D option can be used to change the colors. +Colored text works only if the terminal supports +ANSI color escape sequences (as defined in ECMA-48 SGR; +see +.br +.nh +https://www.ecma-international.org/publications-and-standards/standards/ecma-48). +.hy .IP "\-\-wheel-lines=\fIn\fP" Set the number of lines to scroll when the mouse wheel is scrolled and the \-\-mouse or \-\-MOUSE option is in effect. @@ -1004,7 +1152,7 @@ The + command described previously may also be used to set (or change) an initial command for every file. . .SH "LINE EDITING" -When entering command line at the bottom of the screen +When entering a command line at the bottom of the screen (for example, a filename for the :e command, or the pattern for a search command), certain keys can be used to manipulate the command line. @@ -1804,7 +1952,7 @@ The name of the editor (used for the v command). .BR lesskey (1) . .SH COPYRIGHT -Copyright (C) 1984-2020 Mark Nudelman +Copyright (C) 1984-2021 Mark Nudelman .PP less is part of the GNU project and is free software. You can redistribute it and/or modify it @@ -1833,4 +1981,4 @@ Report bugs at https://github.com/gwsw/less/issues. .br For more information, see the less homepage at .br -http://www.greenwoodsoftware.com/less. +https://greenwoodsoftware.com/less. diff --git a/lessecho.c b/lessecho.c index 6bf2e9c..bfb0f72 100644 --- a/lessecho.c +++ b/lessecho.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -13,16 +13,16 @@ * Simply echos its filename arguments on standard output. * But any argument containing spaces is enclosed in quotes. * - * -ox Specifies "x" to be the open quote character. - * -cx Specifies "x" to be the close quote character. - * -pn Specifies "n" to be the open quote character, as an integer. - * -dn Specifies "n" to be the close quote character, as an integer. + * -ox Specifies "x" to be the open quote character. + * -cx Specifies "x" to be the close quote character. + * -pn Specifies "n" to be the open quote character, as an integer. + * -dn Specifies "n" to be the close quote character, as an integer. * -mx Specifies "x" to be a metachar. * -nn Specifies "n" to be a metachar, as an integer. * -ex Specifies "x" to be the escape char for metachars. * -fn Specifies "x" to be the escape char for metachars, as an integer. - * -a Specifies that all arguments are to be quoted. - * The default is that only arguments containing spaces are quoted. + * -a Specifies that all arguments are to be quoted. + * The default is that only arguments containing spaces are quoted. */ #include "less.h" diff --git a/lessecho.man b/lessecho.man index 2a4c457..6a47aba 100644 --- a/lessecho.man +++ b/lessecho.man @@ -38,7 +38,7 @@ LESSECHO(1) General Commands Manual LESSECHO(1) ger. -a Specifies that all arguments are to be quoted. The default is - that only arguments containing metacharacters are quoted + that only arguments containing metacharacters are quoted. SEE ALSO less(1) @@ -47,8 +47,8 @@ LESSECHO(1) General Commands Manual LESSECHO(1) This manual page was written by Thomas Schoepf , for the Debian GNU/Linux system (but may be used by others). - Send bug reports or comments to bug-less@gnu.org. + Report bugs at https://github.com/gwsw/less/issues. - Version 563: 13 Jun 2020 LESSECHO(1) + Version 581.2: 28 Apr 2021 LESSECHO(1) diff --git a/lessecho.nro b/lessecho.nro index d6d367b..484efa1 100644 --- a/lessecho.nro +++ b/lessecho.nro @@ -1,4 +1,4 @@ -.TH LESSECHO 1 "Version 563: 13 Jun 2020" +.TH LESSECHO 1 "Version 581.2: 28 Apr 2021" .SH NAME lessecho \- expand metacharacters .SH SYNOPSIS @@ -19,7 +19,7 @@ are surrounded by quotes instead. .TP .B \-ox Specifies "x", rather than double-quote, to be the open quote character, -which is used if the -e- option is specified. +which is used if the \-e- option is specified. .TP .B \-cx Specifies "x" to be the close quote character. @@ -42,11 +42,11 @@ Specifies "n" to be the escape char for metachars, as an integer. .TP .B \-a Specifies that all arguments are to be quoted. -The default is that only arguments containing metacharacters are quoted +The default is that only arguments containing metacharacters are quoted. .SH "SEE ALSO" .BR less (1) .SH AUTHOR This manual page was written by Thomas Schoepf , for the Debian GNU/Linux system (but may be used by others). .PP -Send bug reports or comments to bug-less@gnu.org. +Report bugs at https://github.com/gwsw/less/issues. diff --git a/lesskey.c b/lesskey.c index 74cdcb2..de7a9bf 100644 --- a/lesskey.c +++ b/lesskey.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -9,73 +9,73 @@ /* - * lesskey [-o output] [input] + * lesskey [-o output] [input] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Make a .less file. - * If no input file is specified, standard input is used. - * If no output file is specified, $HOME/.less is used. + * Make a .less file. + * If no input file is specified, standard input is used. + * If no output file is specified, $HOME/.less is used. * - * The .less file is used to specify (to "less") user-defined - * key bindings. Basically any sequence of 1 to MAX_CMDLEN - * keystrokes may be bound to an existing less function. + * The .less file is used to specify (to "less") user-defined + * key bindings. Basically any sequence of 1 to MAX_CMDLEN + * keystrokes may be bound to an existing less function. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * The input file is an ascii file consisting of a - * sequence of lines of the form: - * string action [chars] + * The input file is an ascii file consisting of a + * sequence of lines of the form: + * string action [chars] * - * "string" is a sequence of command characters which form - * the new user-defined command. The command - * characters may be: - * 1. The actual character itself. - * 2. A character preceded by ^ to specify a - * control character (e.g. ^X means control-X). - * 3. A backslash followed by one to three octal digits - * to specify a character by its octal value. - * 4. A backslash followed by b, e, n, r or t - * to specify \b, ESC, \n, \r or \t, respectively. - * 5. Any character (other than those mentioned above) preceded - * by a \ to specify the character itself (characters which - * must be preceded by \ include ^, \, and whitespace. - * "action" is the name of a "less" action, from the table below. - * "chars" is an optional sequence of characters which is treated - * as keyboard input after the command is executed. + * "string" is a sequence of command characters which form + * the new user-defined command. The command + * characters may be: + * 1. The actual character itself. + * 2. A character preceded by ^ to specify a + * control character (e.g. ^X means control-X). + * 3. A backslash followed by one to three octal digits + * to specify a character by its octal value. + * 4. A backslash followed by b, e, n, r or t + * to specify \b, ESC, \n, \r or \t, respectively. + * 5. Any character (other than those mentioned above) preceded + * by a \ to specify the character itself (characters which + * must be preceded by \ include ^, \, and whitespace. + * "action" is the name of a "less" action, from the table below. + * "chars" is an optional sequence of characters which is treated + * as keyboard input after the command is executed. * - * Blank lines and lines which start with # are ignored, - * except for the special control lines: - * #command Signals the beginning of the command - * keys section. - * #line-edit Signals the beginning of the line-editing - * keys section. - * #env Signals the beginning of the environment - * variable section. - * #stop Stops command parsing in less; - * causes all default keys to be disabled. + * Blank lines and lines which start with # are ignored, + * except for the special control lines: + * #command Signals the beginning of the command + * keys section. + * #line-edit Signals the beginning of the line-editing + * keys section. + * #env Signals the beginning of the environment + * variable section. + * #stop Stops command parsing in less; + * causes all default keys to be disabled. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * The output file is a non-ascii file, consisting of a header, - * one or more sections, and a trailer. - * Each section begins with a section header, a section length word - * and the section data. Normally there are three sections: - * CMD_SECTION Definition of command keys. - * EDIT_SECTION Definition of editing keys. - * END_SECTION A special section header, with no - * length word or section data. + * The output file is a non-ascii file, consisting of a header, + * one or more sections, and a trailer. + * Each section begins with a section header, a section length word + * and the section data. Normally there are three sections: + * CMD_SECTION Definition of command keys. + * EDIT_SECTION Definition of editing keys. + * END_SECTION A special section header, with no + * length word or section data. * - * Section data consists of zero or more byte sequences of the form: - * string <0> - * or - * string <0> chars <0> + * Section data consists of zero or more byte sequences of the form: + * string <0> + * or + * string <0> chars <0> * - * "string" is the command string. - * "<0>" is one null byte. - * "" is one byte containing the action code (the A_xxx value). - * If action is ORed with A_EXTRA, the action byte is followed - * by the null-terminated "chars" string. + * "string" is the command string. + * "<0>" is one null byte. + * "" is one byte containing the action code (the A_xxx value). + * If action is ORed with A_EXTRA, the action byte is followed + * by the null-terminated "chars" string. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -153,6 +153,7 @@ struct cmdname cmdnames[] = { "toggle-flag", A_OPT_TOGGLE }, { "toggle-option", A_OPT_TOGGLE }, { "undo-hilite", A_UNDO_SEARCH }, + { "clear-search", A_CLR_SEARCH }, { "version", A_VERSION }, { "visual", A_VISUAL }, { NULL, 0 } @@ -160,26 +161,26 @@ struct cmdname cmdnames[] = struct cmdname editnames[] = { - { "back-complete", EC_B_COMPLETE }, - { "backspace", EC_BACKSPACE }, - { "delete", EC_DELETE }, - { "down", EC_DOWN }, - { "end", EC_END }, - { "expand", EC_EXPAND }, - { "forw-complete", EC_F_COMPLETE }, - { "home", EC_HOME }, - { "insert", EC_INSERT }, - { "invalid", EC_UINVALID }, - { "kill-line", EC_LINEKILL }, - { "abort", EC_ABORT }, - { "left", EC_LEFT }, - { "literal", EC_LITERAL }, - { "right", EC_RIGHT }, - { "up", EC_UP }, - { "word-backspace", EC_W_BACKSPACE }, - { "word-delete", EC_W_DELETE }, - { "word-left", EC_W_LEFT }, - { "word-right", EC_W_RIGHT }, + { "back-complete", EC_B_COMPLETE }, + { "backspace", EC_BACKSPACE }, + { "delete", EC_DELETE }, + { "down", EC_DOWN }, + { "end", EC_END }, + { "expand", EC_EXPAND }, + { "forw-complete", EC_F_COMPLETE }, + { "home", EC_HOME }, + { "insert", EC_INSERT }, + { "invalid", EC_UINVALID }, + { "kill-line", EC_LINEKILL }, + { "abort", EC_ABORT }, + { "left", EC_LEFT }, + { "literal", EC_LITERAL }, + { "right", EC_RIGHT }, + { "up", EC_UP }, + { "word-backspace", EC_W_BACKSPACE }, + { "word-delete", EC_W_DELETE }, + { "word-left", EC_W_LEFT }, + { "word-right", EC_W_RIGHT }, { NULL, 0 } }; @@ -206,10 +207,10 @@ char filetrailer[] = { C1_END_LESSKEY_MAGIC, C2_END_LESSKEY_MAGIC }; -char cmdsection[1] = { CMD_SECTION }; -char editsection[1] = { EDIT_SECTION }; -char varsection[1] = { VAR_SECTION }; -char endsection[1] = { END_SECTION }; +char cmdsection[1] = { CMD_SECTION }; +char editsection[1] = { EDIT_SECTION }; +char varsection[1] = { VAR_SECTION }; +char endsection[1] = { END_SECTION }; char *infile = NULL; char *outfile = NULL ; @@ -459,7 +460,7 @@ tstr(pp, xlate) *pp = p+2; buf[0] = CONTROL(p[1]); buf[1] = '\0'; - if (buf[0] == CONTROL('K')) + if (xlate && buf[0] == CONTROL('K')) return tstr_control_k; return (buf); } @@ -478,7 +479,7 @@ tstr(pp, xlate) skipsp(s) char *s; { - while (*s == ' ' || *s == '\t') + while (*s == ' ' || *s == '\t') s++; return (s); } @@ -546,7 +547,7 @@ add_cmd_str(s) control_line(s) char *s; { -#define PREFIX(str,pat) (strncmp(str,pat,strlen(pat)) == 0) +#define PREFIX(str,pat) (strncmp(str,pat,strlen(pat)) == 0) if (PREFIX(s, "#line-edit")) { diff --git a/lesskey.h b/lesskey.h index 2c4b5d6..3a8f836 100644 --- a/lesskey.h +++ b/lesskey.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -11,29 +11,29 @@ /* * Format of a lesskey file: * - * LESSKEY_MAGIC (4 bytes) - * sections... - * END_LESSKEY_MAGIC (4 bytes) + * LESSKEY_MAGIC (4 bytes) + * sections... + * END_LESSKEY_MAGIC (4 bytes) * * Each section is: * - * section_MAGIC (1 byte) - * section_length (2 bytes) - * key table (section_length bytes) + * section_MAGIC (1 byte) + * section_length (2 bytes) + * key table (section_length bytes) */ -#define C0_LESSKEY_MAGIC '\0' -#define C1_LESSKEY_MAGIC 'M' -#define C2_LESSKEY_MAGIC '+' -#define C3_LESSKEY_MAGIC 'G' +#define C0_LESSKEY_MAGIC '\0' +#define C1_LESSKEY_MAGIC 'M' +#define C2_LESSKEY_MAGIC '+' +#define C3_LESSKEY_MAGIC 'G' -#define CMD_SECTION 'c' -#define EDIT_SECTION 'e' -#define VAR_SECTION 'v' -#define END_SECTION 'x' +#define CMD_SECTION 'c' +#define EDIT_SECTION 'e' +#define VAR_SECTION 'v' +#define END_SECTION 'x' -#define C0_END_LESSKEY_MAGIC 'E' -#define C1_END_LESSKEY_MAGIC 'n' -#define C2_END_LESSKEY_MAGIC 'd' +#define C0_END_LESSKEY_MAGIC 'E' +#define C1_END_LESSKEY_MAGIC 'n' +#define C2_END_LESSKEY_MAGIC 'd' /* */ -#define KRADIX 64 +#define KRADIX 64 diff --git a/lesskey.man b/lesskey.man index 413f6aa..36a629e 100644 --- a/lesskey.man +++ b/lesskey.man @@ -16,24 +16,25 @@ LESSKEY(1) General Commands Manual LESSKEY(1) The input file is a text file which describes the key bindings. If the input file is "-", standard input is read. If no input file is speci- fied, a standard filename is used as the name of the input file, which - depends on the system being used: On Unix systems, $HOME/.lesskey is - used; on MS-DOS systems, $HOME/_lesskey is used; and on OS/2 systems - $HOME/lesskey.ini is used, or $INIT/lesskey.ini if $HOME is undefined. - The output file is a binary file which is used by less. If no output - file is specified, and the environment variable LESSKEY is set, the - value of LESSKEY is used as the name of the output file. Otherwise, a - standard filename is used as the name of the output file, which depends - on the system being used: On Unix and OS-9 systems, $HOME/.less is - used; on MS-DOS systems, $HOME/_less is used; and on OS/2 systems, - $HOME/less.ini is used, or $INIT/less.ini if $HOME is undefined. If - the output file already exists, lesskey will overwrite it. - - The -V or --version option causes lesskey to print its version number + depends on the system being used: On Unix systems, "$HOME/.lesskey" is + used; on MS-DOS systems, "$HOME/_lesskey" is used; and on OS/2 systems + "$HOME/lesskey.ini" is used, or "$INIT/lesskey.ini" if $HOME is unde- + fined. The output file is a binary file which is used by less. If no + output file is specified, and the environment variable LESSKEY is set, + the value of LESSKEY is used as the name of the output file. Other- + wise, a standard filename is used as the name of the output file, which + depends on the system being used: On Unix and OS-9 systems, + "$HOME/.less" is used; on MS-DOS systems, "$HOME/_less" is used; and on + OS/2 systems, "$HOME/less.ini" is used, or "$INIT/less.ini" if $HOME is + undefined. If the output file already exists, lesskey will overwrite + it. + + The -V or --version option causes lesskey to print its version number and immediately exit. If -V or --version is present, other options and arguments are ignored. - The input file consists of one or more sections. Each section starts - with a line that identifies the type of section. Possible sections + The input file consists of one or more sections. Each section starts + with a line that identifies the type of section. Possible sections are: #command @@ -44,7 +45,7 @@ LESSKEY(1) General Commands Manual LESSKEY(1) #env Defines environment variables. - Blank lines and lines which start with a pound sign (#) are ignored, + Blank lines and lines which start with a pound sign (#) are ignored, except for the special section header lines. COMMAND SECTION @@ -52,18 +53,18 @@ LESSKEY(1) General Commands Manual LESSKEY(1) #command - If the command section is the first section in the file, this line may + If the command section is the first section in the file, this line may be omitted. The command section consists of lines of the form: string action [extra-string] - Whitespace is any sequence of one or more spaces and/or tabs. The - string is the command key(s) which invoke the action. The string may + Whitespace is any sequence of one or more spaces and/or tabs. The + string is the command key(s) which invoke the action. The string may be a single command key, or a sequence of up to 15 keys. The action is - the name of the less action, from the list below. The characters in - the string may appear literally, or be prefixed by a caret to indicate - a control key. A backslash followed by one to three octal digits may - be used to specify a character by its octal value. A backslash fol- + the name of the less action, from the list below. The characters in + the string may appear literally, or be prefixed by a caret to indicate + a control key. A backslash followed by one to three octal digits may + be used to specify a character by its octal value. A backslash fol- lowed by certain characters specifies input characters as follows: \b BACKSPACE @@ -95,16 +96,17 @@ LESSKEY(1) General Commands Manual LESSKEY(1) \kx DELETE A backslash followed by any other character indicates that character is - to be taken literally. Characters which must be preceded by backslash + to be taken literally. Characters which must be preceded by backslash include caret, space, tab and the backslash itself. An action may be followed by an "extra" string. When such a command is entered while running less, the action is performed, and then the extra - string is parsed, just as if it were typed in to less. This feature - can be used in certain cases to extend the functionality of a command. - For example, see the "{" and ":t" commands in the example below. The - extra string has a special meaning for the "quit" action: when less - quits, first character of the extra string is used as its exit status. + string is parsed, just as if it were typed in to less. This feature + can be used in certain cases to extend the functionality of a command. + For example, see the "{" and ":t" commands in the example below. The + extra string has a special meaning for the "quit" action: when less + quits, the first character of the extra string is used as its exit sta- + tus. EXAMPLE The following input file describes the set of default command keys used @@ -127,9 +129,9 @@ LESSKEY(1) General Commands Manual LESSKEY(1) J forw-line-force K back-line-force Y back-line-force + d forw-scroll ^D forw-scroll - u back-scroll ^U back-scroll \40 forw-screen @@ -151,6 +153,7 @@ LESSKEY(1) General Commands Manual LESSKEY(1) ^R repaint ^L repaint \eu undo-hilite + \eU clear-search g goto-line \kh goto-line < goto-line @@ -192,10 +195,10 @@ LESSKEY(1) General Commands Manual LESSKEY(1) & filter m set-mark M set-mark-bottom + \em clear-mark ' goto-mark ^X^X goto-mark - E examine :e examine ^X^V examine @@ -332,7 +335,7 @@ LESSKEY(1) General Commands Manual LESSKEY(1) represented as \340 in a lesskey file. COPYRIGHT - Copyright (C) 1984-2020 Mark Nudelman + Copyright (C) 1984-2021 Mark Nudelman less is part of the GNU project and is free software. You can redis- tribute it and/or modify it under the terms of either (1) the GNU Gen- @@ -351,8 +354,8 @@ LESSKEY(1) General Commands Manual LESSKEY(1) AUTHOR Mark Nudelman - Send bug reports or comments to . + Report bugs at https://github.com/gwsw/less/issues. - Version 563: 13 Jun 2020 LESSKEY(1) + Version 581.2: 28 Apr 2021 LESSKEY(1) diff --git a/lesskey.nro b/lesskey.nro index 5b8cbe4..1f8e5b3 100644 --- a/lesskey.nro +++ b/lesskey.nro @@ -1,5 +1,5 @@ '\" t -.TH LESSKEY 1 "Version 563: 13 Jun 2020" +.TH LESSKEY 1 "Version 581.2: 28 Apr 2021" .SH NAME lesskey \- specify key bindings for less .SH SYNOPSIS @@ -18,10 +18,10 @@ The input file is a text file which describes the key bindings. If the input file is "\-", standard input is read. If no input file is specified, a standard filename is used as the name of the input file, which depends on the system being used: -On Unix systems, $HOME/.lesskey is used; -on MS-DOS systems, $HOME/_lesskey is used; -and on OS/2 systems $HOME/lesskey.ini is used, -or $INIT/lesskey.ini if $HOME is undefined. +On Unix systems, "$HOME/.lesskey" is used; +on MS-DOS systems, "$HOME/_lesskey" is used; +and on OS/2 systems "$HOME/lesskey.ini" is used, +or "$INIT/lesskey.ini" if $HOME is undefined. The output file is a binary file which is used by .IR less . If no output file is specified, @@ -29,10 +29,10 @@ and the environment variable LESSKEY is set, the value of LESSKEY is used as the name of the output file. Otherwise, a standard filename is used as the name of the output file, which depends on the system being used: -On Unix and OS-9 systems, $HOME/.less is used; -on MS-DOS systems, $HOME/_less is used; -and on OS/2 systems, $HOME/less.ini is used, -or $INIT/less.ini if $HOME is undefined. +On Unix and OS-9 systems, "$HOME/.less" is used; +on MS-DOS systems, "$HOME/_less" is used; +and on OS/2 systems, "$HOME/less.ini" is used, +or "$INIT/less.ini" if $HOME is undefined. If the output file already exists, .I lesskey will overwrite it. @@ -123,7 +123,7 @@ For example, see the "{" and ":t" commands in the example below. The extra string has a special meaning for the "quit" action: when .I less -quits, first character of the extra string is used as its exit status. +quits, the first character of the extra string is used as its exit status. . .SH EXAMPLE The following input file describes the set of @@ -171,6 +171,7 @@ r repaint ^R repaint ^L repaint \eeu undo-hilite +\eeU clear-search g goto-line \ekh goto-line < goto-line @@ -370,7 +371,7 @@ which start with a NUL character (0). This NUL character should be represented as \e340 in a lesskey file. . .SH COPYRIGHT -Copyright (C) 1984-2020 Mark Nudelman +Copyright (C) 1984-2021 Mark Nudelman .PP less is part of the GNU project and is free software. You can redistribute it and/or modify it @@ -395,4 +396,4 @@ See the GNU General Public License for more details. . Mark Nudelman .br -Send bug reports or comments to . +Report bugs at https://github.com/gwsw/less/issues. diff --git a/lglob.h b/lglob.h index e13e798..2e5e74e 100644 --- a/lglob.h +++ b/lglob.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -11,81 +11,81 @@ /* * Macros to define the method of doing filename "globbing". * There are three possible mechanisms: - * 1. GLOB_LIST - * This defines a function that returns a list of matching filenames. + * 1. GLOB_LIST + * This defines a function that returns a list of matching filenames. * 2. GLOB_NAME - * This defines a function that steps thru the list of matching - * filenames, returning one name each time it is called. + * This defines a function that steps thru the list of matching + * filenames, returning one name each time it is called. * 3. GLOB_STRING - * This defines a function that returns the complete list of - * matching filenames as a single space-separated string. + * This defines a function that returns the complete list of + * matching filenames as a single space-separated string. */ #if OS2 -#define DECL_GLOB_LIST(list) char **list; char **pp; -#define GLOB_LIST(filename,list) list = _fnexplode(filename) -#define GLOB_LIST_FAILED(list) list == NULL -#define SCAN_GLOB_LIST(list,p) pp = list; *pp != NULL; pp++ -#define INIT_GLOB_LIST(list,p) p = *pp -#define GLOB_LIST_DONE(list) _fnexplodefree(list) +#define DECL_GLOB_LIST(list) char **list; char **pp; +#define GLOB_LIST(filename,list) list = _fnexplode(filename) +#define GLOB_LIST_FAILED(list) list == NULL +#define SCAN_GLOB_LIST(list,p) pp = list; *pp != NULL; pp++ +#define INIT_GLOB_LIST(list,p) p = *pp +#define GLOB_LIST_DONE(list) _fnexplodefree(list) #else #if MSDOS_COMPILER==DJGPPC -#define DECL_GLOB_LIST(list) glob_t list; int i; -#define GLOB_LIST(filename,list) glob(filename,GLOB_NOCHECK,0,&list) -#define GLOB_LIST_FAILED(list) 0 -#define SCAN_GLOB_LIST(list,p) i = 0; i < list.gl_pathc; i++ -#define INIT_GLOB_LIST(list,p) p = list.gl_pathv[i] -#define GLOB_LIST_DONE(list) globfree(&list) +#define DECL_GLOB_LIST(list) glob_t list; int i; +#define GLOB_LIST(filename,list) glob(filename,GLOB_NOCHECK,0,&list) +#define GLOB_LIST_FAILED(list) 0 +#define SCAN_GLOB_LIST(list,p) i = 0; i < list.gl_pathc; i++ +#define INIT_GLOB_LIST(list,p) p = list.gl_pathv[i] +#define GLOB_LIST_DONE(list) globfree(&list) #else #if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==BORLANDC -#define GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp) -#define GLOB_FIRST_FAILED(handle) ((handle) != 0) -#define GLOB_NEXT_NAME(handle,fndp) _dos_findnext(fndp) -#define GLOB_NAME_DONE(handle) -#define GLOB_NAME name -#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ - struct find_t fnd; \ - char drive[_MAX_DRIVE]; \ - char dir[_MAX_DIR]; \ - char fname[_MAX_FNAME]; \ - char ext[_MAX_EXT]; \ - int handle; +#define GLOB_FIRST_NAME(filename,fndp,h) h = _dos_findfirst(filename, ~_A_VOLID, fndp) +#define GLOB_FIRST_FAILED(handle) ((handle) != 0) +#define GLOB_NEXT_NAME(handle,fndp) _dos_findnext(fndp) +#define GLOB_NAME_DONE(handle) +#define GLOB_NAME name +#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ + struct find_t fnd; \ + char drive[_MAX_DRIVE]; \ + char dir[_MAX_DIR]; \ + char fname[_MAX_FNAME]; \ + char ext[_MAX_EXT]; \ + int handle; #else #if MSDOS_COMPILER==WIN32C && (defined(_MSC_VER) || defined(MINGW)) -#define GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp) -#define GLOB_FIRST_FAILED(handle) ((handle) == -1) -#define GLOB_NEXT_NAME(handle,fndp) _findnext(handle, fndp) -#define GLOB_NAME_DONE(handle) _findclose(handle) -#define GLOB_NAME name -#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ - struct _finddata_t fnd; \ - char drive[_MAX_DRIVE]; \ - char dir[_MAX_DIR]; \ - char fname[_MAX_FNAME]; \ - char ext[_MAX_EXT]; \ - intptr_t handle; +#define GLOB_FIRST_NAME(filename,fndp,h) h = _findfirst(filename, fndp) +#define GLOB_FIRST_FAILED(handle) ((handle) == -1) +#define GLOB_NEXT_NAME(handle,fndp) _findnext(handle, fndp) +#define GLOB_NAME_DONE(handle) _findclose(handle) +#define GLOB_NAME name +#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ + struct _finddata_t fnd; \ + char drive[_MAX_DRIVE]; \ + char dir[_MAX_DIR]; \ + char fname[_MAX_FNAME]; \ + char ext[_MAX_EXT]; \ + intptr_t handle; #else #if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER) /* Borland C for Windows */ -#define GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL) -#define GLOB_FIRST_FAILED(handle) ((handle) != 0) -#define GLOB_NEXT_NAME(handle,fndp) findnext(fndp) -#define GLOB_NAME_DONE(handle) -#define GLOB_NAME ff_name -#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ - struct ffblk fnd; \ - char drive[MAXDRIVE]; \ - char dir[MAXDIR]; \ - char fname[MAXFILE]; \ - char ext[MAXEXT]; \ - int handle; +#define GLOB_FIRST_NAME(filename,fndp,h) h = findfirst(filename, fndp, ~FA_LABEL) +#define GLOB_FIRST_FAILED(handle) ((handle) != 0) +#define GLOB_NEXT_NAME(handle,fndp) findnext(fndp) +#define GLOB_NAME_DONE(handle) +#define GLOB_NAME ff_name +#define DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) \ + struct ffblk fnd; \ + char drive[MAXDRIVE]; \ + char dir[MAXDIR]; \ + char fname[MAXFILE]; \ + char ext[MAXEXT]; \ + int handle; #endif #endif diff --git a/line.c b/line.c index 4a55231..57d3cbe 100644 --- a/line.c +++ b/line.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -22,26 +22,38 @@ #include #endif -static char *linebuf = NULL; /* Buffer which holds the current output line */ -static char *attr = NULL; /* Extension of linebuf to hold attributes */ -public int size_linebuf = 0; /* Size of line buffer (and attr buffer) */ - -static int cshift; /* Current left-shift of output line buffer */ -public int hshift; /* Desired left-shift of output line buffer */ +#define MAX_PFX_WIDTH (MAX_LINENUM_WIDTH + MAX_STATUSCOL_WIDTH + 1) +static struct { + char *buf; /* Buffer which holds the current output line */ + int *attr; /* Parallel to buf, to hold attributes */ + int print; /* Index in buf of first printable char */ + int end; /* Number of chars in buf */ + char pfx[MAX_PFX_WIDTH]; /* Holds status column and line number */ + int pfx_attr[MAX_PFX_WIDTH]; + int pfx_end; /* Number of chars in pfx */ +} linebuf; + +static struct { + char *buf; + int size; + int end; +} shifted_ansi; + +public int size_linebuf = 0; /* Size of line buffer (and attr buffer) */ +static struct ansi_state *line_ansi = NULL; +static int cshift; /* Current left-shift of output line buffer */ +public int hshift; /* Desired left-shift of output line buffer */ public int tabstops[TABSTOP_MAX] = { 0 }; /* Custom tabstops */ -public int ntabstops = 1; /* Number of tabstops */ -public int tabdefault = 8; /* Default repeated tabstops */ -public POSITION highest_hilite; /* Pos of last hilite in file found so far */ +public int ntabstops = 1; /* Number of tabstops */ +public int tabdefault = 8; /* Default repeated tabstops */ +public POSITION highest_hilite; /* Pos of last hilite in file found so far */ -static int curr; /* Index into linebuf */ -static int column; /* Printable length, accounting for - backspaces, etc. */ +static int end_column; /* Printable length, accounting for backspaces, etc. */ static int right_curr; static int right_column; -static int overstrike; /* Next char should overstrike previous char */ +static int overstrike; /* Next char should overstrike previous char */ static int last_overstrike = AT_NORMAL; -static int is_null_line; /* There is no current line */ -static int lmargin; /* Left margin */ +static int is_null_line; /* There is no current line */ static LWCHAR pendc; static POSITION pendpos; static char *end_ansi_chars; @@ -58,6 +70,8 @@ extern int ctldisp; extern int twiddle; extern int binattr; extern int status_col; +extern int status_col_width; +extern int linenum_width; extern int auto_wrap, ignaw; extern int bo_s_width, bo_e_width; extern int ul_s_width, ul_e_width; @@ -69,12 +83,37 @@ extern POSITION start_attnpos; extern POSITION end_attnpos; extern char rscroll_char; extern int rscroll_attr; +extern int use_color; static char mbc_buf[MAX_UTF_CHAR_LEN]; static int mbc_buf_len = 0; static int mbc_buf_index = 0; static POSITION mbc_pos; +/* Configurable color map */ +static char color_map[AT_NUM_COLORS][12] = { + "Wm", /* AT_COLOR_ATTN */ + "kR", /* AT_COLOR_BIN */ + "kR", /* AT_COLOR_CTRL */ + "kY", /* AT_COLOR_ERROR */ + "c", /* AT_COLOR_LINENUM */ + "Wb", /* AT_COLOR_MARK */ + "kC", /* AT_COLOR_PROMPT */ + "kc", /* AT_COLOR_RSCROLL */ + "kG", /* AT_COLOR_SEARCH */ + "", /* AT_UNDERLINE */ + "", /* AT_BOLD */ + "", /* AT_BLINK */ + "", /* AT_STANDOUT */ +}; + +/* State while processing an ANSI escape sequence */ +struct ansi_state { + int hindex; /* Index into hyperlink prefix */ + int hlink; /* Processing hyperlink address? */ + int prev_esc; /* Prev char was ESC (to detect ESC-\ seq) */ +}; + /* * Initialize from environment variables. */ @@ -89,9 +128,11 @@ init_line(VOID_PARAM) if (isnullenv(mid_ansi_chars)) mid_ansi_chars = "0123456789:;[?!\"'#%()*+ "; - linebuf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); - attr = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); + linebuf.buf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); + linebuf.attr = (int *) ecalloc(LINEBUF_SIZE, sizeof(int)); size_linebuf = LINEBUF_SIZE; + shifted_ansi.buf = NULL; + shifted_ansi.size = 0; } /* @@ -105,11 +146,11 @@ expand_linebuf(VOID_PARAM) /* Just realloc to expand the buffer, if we can. */ #if HAVE_REALLOC - char *new_buf = (char *) realloc(linebuf, new_size); - char *new_attr = (char *) realloc(attr, new_size); + char *new_buf = (char *) realloc(linebuf.buf, new_size); + int *new_attr = (int *) realloc(linebuf.attr, new_size*sizeof(int)); #else char *new_buf = (char *) calloc(new_size, sizeof(char)); - char *new_attr = (char *) calloc(new_size, sizeof(char)); + int *new_attr = (int *) calloc(new_size, sizeof(int)); #endif if (new_buf == NULL || new_attr == NULL) { @@ -123,13 +164,13 @@ expand_linebuf(VOID_PARAM) /* * We just calloc'd the buffers; copy the old contents. */ - memcpy(new_buf, linebuf, size_linebuf * sizeof(char)); - memcpy(new_attr, attr, size_linebuf * sizeof(char)); - free(attr); - free(linebuf); + memcpy(new_buf, linebuf.buf, size_linebuf * sizeof(char)); + memcpy(new_attr, linebuf.attr, size_linebuf * sizeof(int)); + free(linebuf.attr); + free(linebuf.buf); #endif - linebuf = new_buf; - attr = new_attr; + linebuf.buf = new_buf; + linebuf.attr = new_attr; size_linebuf = new_size; return 0; } @@ -144,14 +185,35 @@ is_ascii_char(ch) return (ch <= 0x7F); } +/* + */ + static void +inc_end_column(w) + int w; +{ + if (end_column > right_column && w > 0) + { + right_column = end_column; + right_curr = linebuf.end; + } + end_column += w; +} + /* * Rewind the line buffer. */ public void prewind(VOID_PARAM) { - curr = 0; - column = 0; + linebuf.print = 6; /* big enough for longest UTF-8 sequence */ + linebuf.pfx_end = 0; + for (linebuf.end = 0; linebuf.end < linebuf.print; linebuf.end++) + { + linebuf.buf[linebuf.end] = '\0'; + linebuf.attr[linebuf.end] = 0; + } + + end_column = 0; right_curr = 0; right_column = 0; cshift = 0; @@ -160,42 +222,64 @@ prewind(VOID_PARAM) mbc_buf_len = 0; is_null_line = 0; pendc = '\0'; - lmargin = 0; - if (status_col) - lmargin += 2; + shifted_ansi.end = 0; } /* * Set a character in the line buffer. */ static void -set_linebuf(n, ch, a) +set_linebuf(n, ch, attr) int n; char ch; - char a; + int attr; { - linebuf[n] = ch; - attr[n] = a; + linebuf.buf[n] = ch; + linebuf.attr[n] = attr; } /* * Append a character to the line buffer. */ static void -add_linebuf(ch, a, w) +add_linebuf(ch, attr, w) char ch; - char a; + int attr; int w; { - set_linebuf(curr++, ch, a); - column += w; + set_linebuf(linebuf.end++, ch, attr); + inc_end_column(w); +} + +/* + * Set a character in the line prefix buffer. + */ + static void +set_pfx(n, ch, attr) + int n; + char ch; + int attr; +{ + linebuf.pfx[n] = ch; + linebuf.pfx_attr[n] = attr; +} + +/* + * Append a character to the line prefix buffer. + */ + static void +add_pfx(ch, attr) + char ch; + int attr; +{ + set_pfx(linebuf.pfx_end++, ch, attr); } /* - * Insert the line number (of the given position) into the line buffer. + * Insert the status column and line number into the line buffer. */ public void -plinenum(pos) +plinestart(pos) POSITION pos; { LINENUM linenum = 0; @@ -207,7 +291,7 @@ plinenum(pos) * Get the line number and put it in the current line. * {{ Note: since find_linenum calls forw_raw_line, * it may seek in the input file, requiring the caller - * of plinenum to re-seek if necessary. }} + * of plinestart to re-seek if necessary. }} * {{ Since forw_raw_line modifies linebuf, we must * do this first, before storing anything in linebuf. }} */ @@ -222,16 +306,17 @@ plinenum(pos) int a = AT_NORMAL; char c = posmark(pos); if (c != 0) - a |= AT_HILITE; + a |= AT_HILITE|AT_COLOR_MARK; else { c = ' '; if (start_attnpos != NULL_POSITION && pos >= start_attnpos && pos <= end_attnpos) - a |= AT_HILITE; + a |= AT_HILITE|AT_COLOR_ATTN; } - add_linebuf(c, a, 1); /* column 0: status */ - add_linebuf(' ', AT_NORMAL, 1); /* column 1: empty */ + add_pfx(c, a); /* column 0: status */ + while (linebuf.pfx_end < status_col_width) + add_pfx(' ', AT_NORMAL); } /* @@ -241,155 +326,67 @@ plinenum(pos) if (linenums == OPT_ONPLUS) { char buf[INT_STRLEN_BOUND(linenum) + 2]; - int pad = 0; - int n; + int len; linenumtoa(linenum, buf); - n = (int) strlen(buf); - if (n < MIN_LINENUM_WIDTH) - pad = MIN_LINENUM_WIDTH - n; - for (i = 0; i < pad; i++) - add_linebuf(' ', AT_NORMAL, 1); - for (i = 0; i < n; i++) - add_linebuf(buf[i], AT_BOLD, 1); - add_linebuf(' ', AT_NORMAL, 1); - lmargin += n + pad + 1; - } - /* - * Append enough spaces to bring us to the lmargin. - */ - while (column < lmargin) - { - add_linebuf(' ', AT_NORMAL, 1); + len = (int) strlen(buf); + for (i = 0; i < linenum_width - len; i++) + add_pfx(' ', AT_NORMAL); + for (i = 0; i < len; i++) + add_pfx(buf[i], AT_NORMAL|AT_COLOR_LINENUM); + add_pfx(' ', AT_NORMAL); } + end_column = linebuf.pfx_end; } /* - * Shift the input line left. - * This means discarding N printable chars at the start of the buffer. + * Return the width of the line prefix (status column and line number). + * {{ Actual line number can be wider than linenum_width. }} */ - static void -pshift(shift) - int shift; + public int +line_pfx_width(VOID_PARAM) { - LWCHAR prev_ch = 0; - unsigned char c; - int shifted = 0; - int to; - int from; - int len; - int width; - int prev_attr; - int next_attr; - - if (shift > column - lmargin) - shift = column - lmargin; - if (shift > curr - lmargin) - shift = curr - lmargin; - - to = from = lmargin; - /* - * We keep on going when shifted == shift - * to get all combining chars. - */ - while (shifted <= shift && from < curr) - { - c = linebuf[from]; - if (ctldisp == OPT_ONPLUS && IS_CSI_START(c)) - { - /* Keep cumulative effect. */ - linebuf[to] = c; - attr[to++] = attr[from++]; - while (from < curr && linebuf[from]) - { - linebuf[to] = linebuf[from]; - attr[to++] = attr[from]; - if (!is_ansi_middle(linebuf[from++])) - break; - } - continue; - } - - width = 0; - - if (!IS_ASCII_OCTET(c) && utf_mode) - { - /* Assumes well-formedness validation already done. */ - LWCHAR ch; - - len = utf_len(c); - if (from + len > curr) - break; - ch = get_wchar(linebuf + from); - if (!is_composing_char(ch) && !is_combining_char(prev_ch, ch)) - width = is_wide_char(ch) ? 2 : 1; - prev_ch = ch; - } else - { - len = 1; - if (c == '\b') - /* XXX - Incorrect if several '\b' in a row. */ - width = (utf_mode && is_wide_char(prev_ch)) ? -2 : -1; - else if (!control_char(c)) - width = 1; - prev_ch = 0; - } - - if (width == 2 && shift - shifted == 1) { - /* Should never happen when called by pshift_all(). */ - attr[to] = attr[from]; - /* - * Assume a wide_char will never be the first half of a - * combining_char pair, so reset prev_ch in case we're - * followed by a '\b'. - */ - prev_ch = linebuf[to++] = ' '; - from += len; - shifted++; - continue; - } - - /* Adjust width for magic cookies. */ - prev_attr = (to > 0) ? attr[to-1] : AT_NORMAL; - next_attr = (from + len < curr) ? attr[from + len] : prev_attr; - if (!is_at_equiv(attr[from], prev_attr) && - !is_at_equiv(attr[from], next_attr)) - { - width += attr_swidth(attr[from]); - if (from + len < curr) - width += attr_ewidth(attr[from]); - if (is_at_equiv(prev_attr, next_attr)) - { - width += attr_ewidth(prev_attr); - if (from + len < curr) - width += attr_swidth(next_attr); - } - } + int width = 0; + if (status_col) + width += status_col_width; + if (linenums == OPT_ONPLUS) + width += linenum_width + 1; + return width; +} - if (shift - shifted < width) - break; - from += len; - shifted += width; - if (shifted < 0) - shifted = 0; - } - while (from < curr) +/* + * Add char to the shifted_ansi buffer. + */ + static void +add_ansi(ch) + char ch; +{ + if (shifted_ansi.end == shifted_ansi.size) { - linebuf[to] = linebuf[from]; - attr[to++] = attr[from++]; + /* Expand shifted_ansi buffer. */ + int size = (shifted_ansi.size == 0) ? 8 : shifted_ansi.size * 2; + char *buf = (char *) ecalloc(size, sizeof(char)); + memcpy(buf, shifted_ansi.buf, shifted_ansi.size); + if (shifted_ansi.buf != NULL) free(shifted_ansi.buf); + shifted_ansi.buf = buf; + shifted_ansi.size = size; } - curr = to; - column -= shifted; - cshift += shifted; + shifted_ansi.buf[shifted_ansi.end++] = ch; } /* - * + * Shift line left so that the last char is just to the left + * of the first visible column. */ public void pshift_all(VOID_PARAM) { - pshift(column); + int i; + for (i = linebuf.print; i < linebuf.end; i++) + if (linebuf.attr[i] == AT_ANSI) + add_ansi(linebuf.buf[i]); + linebuf.end = linebuf.print; + end_column = linebuf.pfx_end; } /* @@ -442,24 +439,28 @@ attr_ewidth(a) /* * Return the printing width of a given character and attribute, - * if the character were added to the current position in the line buffer. + * if the character were added after prev_ch. * Adding a character with a given attribute may cause an enter or exit * attribute sequence to be inserted, so this must be taken into account. */ - static int -pwidth(ch, a, prev_ch) + public int +pwidth(ch, a, prev_ch, prev_a) LWCHAR ch; int a; LWCHAR prev_ch; + int prev_a; { int w; if (ch == '\b') + { /* * Backspace moves backwards one or two positions. - * XXX - Incorrect if several '\b' in a row. */ + if (prev_a & (AT_ANSI|AT_BINARY)) + return strlen(prchar('\b')); return (utf_mode && is_wide_char(prev_ch)) ? -2 : -1; + } if (!utf_mode || is_ascii_char(ch)) { @@ -481,7 +482,7 @@ pwidth(ch, a, prev_ch) * * Some terminals, upon failure to compose a * composing character with the character(s) that - * precede(s) it will actually take up one column + * precede(s) it will actually take up one end_column * for the composing character; there isn't much * we could do short of testing the (complex) * composition process ourselves and printing @@ -498,64 +499,42 @@ pwidth(ch, a, prev_ch) w = 1; if (is_wide_char(ch)) w++; - if (curr > 0 && !is_at_equiv(attr[curr-1], a)) - w += attr_ewidth(attr[curr-1]); - if ((apply_at_specials(a) != AT_NORMAL) && - (curr == 0 || !is_at_equiv(attr[curr-1], a))) + if (linebuf.end > 0 && !is_at_equiv(linebuf.attr[linebuf.end-1], a)) + w += attr_ewidth(linebuf.attr[linebuf.end-1]); + if (apply_at_specials(a) != AT_NORMAL && + (linebuf.end == 0 || !is_at_equiv(linebuf.attr[linebuf.end-1], a))) w += attr_swidth(a); return (w); } /* * Delete to the previous base character in the line buffer. - * Return 1 if one is found. */ static int backc(VOID_PARAM) { - LWCHAR prev_ch; - char *p = linebuf + curr; - LWCHAR ch = step_char(&p, -1, linebuf + lmargin); - int width; - - /* This assumes that there is no '\b' in linebuf. */ - while ( curr > lmargin - && column > lmargin - && (!(attr[curr - 1] & (AT_ANSI|AT_BINARY)))) - { - curr = (int) (p - linebuf); - prev_ch = step_char(&p, -1, linebuf + lmargin); - width = pwidth(ch, attr[curr], prev_ch); - column -= width; - if (width > 0) - return 1; - ch = prev_ch; - } - - return 0; -} - -/* - * Are we currently within a recognized ANSI escape sequence? - */ - static int -in_ansi_esc_seq(VOID_PARAM) -{ + LWCHAR ch; char *p; - /* - * Search backwards for either an ESC (which means we ARE in a seq); - * or an end char (which means we're NOT in a seq). - */ - for (p = &linebuf[curr]; p > linebuf; ) + if (linebuf.end == 0) + return (0); + p = &linebuf.buf[linebuf.end]; + ch = step_char(&p, -1, linebuf.buf); + /* Skip back to the next nonzero-width char. */ + while (p > linebuf.buf) { - LWCHAR ch = step_char(&p, -1, linebuf); - if (IS_CSI_START(ch)) - return (1); - if (!is_ansi_middle(ch)) - return (0); + LWCHAR prev_ch; + int width; + linebuf.end = (int) (p - linebuf.buf); + prev_ch = step_char(&p, -1, linebuf.buf); + width = pwidth(ch, linebuf.attr[linebuf.end], prev_ch, linebuf.attr[linebuf.end-1]); + end_column -= width; + /* {{ right_column? }} */ + if (width > 0) + break; + ch = prev_ch; } - return (0); + return (1); } /* @@ -589,22 +568,91 @@ is_ansi_middle(ch) * pp is initially positioned just after the CSI_START char. */ public void -skip_ansi(pp, limit) +skip_ansi(pansi, pp, limit) + struct ansi_state *pansi; char **pp; constant char *limit; { LWCHAR c; do { c = step_char(pp, +1, limit); - } while (*pp < limit && is_ansi_middle(c)); - /* Note that we discard final char, for which is_ansi_middle is false. */ + } while (*pp < limit && ansi_step(pansi, c) == ANSI_MID); + /* Note that we discard final char, for which is_ansi_end is true. */ +} + +/* + * Determine if a character starts an ANSI escape sequence. + * If so, return an ansi_state struct; otherwise return NULL. + */ + public struct ansi_state * +ansi_start(ch) + LWCHAR ch; +{ + struct ansi_state *pansi; + + if (!IS_CSI_START(ch)) + return NULL; + pansi = ecalloc(1, sizeof(struct ansi_state)); + pansi->hindex = 0; + pansi->hlink = 0; + pansi->prev_esc = 0; + return pansi; +} + +/* + * Determine whether the next char in an ANSI escape sequence + * ends the sequence. + */ + public int +ansi_step(pansi, ch) + struct ansi_state *pansi; + LWCHAR ch; +{ + if (pansi->hlink) + { + /* Hyperlink ends with \7 or ESC-backslash. */ + if (ch == '\7') + return ANSI_END; + if (pansi->prev_esc && ch == '\\') + return ANSI_END; + pansi->prev_esc = (ch == ESC); + return ANSI_MID; + } + if (pansi->hindex >= 0) + { + static char hlink_prefix[] = ESCS "]8;"; + if (ch == hlink_prefix[pansi->hindex] || + (pansi->hindex == 0 && IS_CSI_START(ch))) + { + pansi->hindex++; + if (hlink_prefix[pansi->hindex] == '\0') + pansi->hlink = 1; /* now processing hyperlink addr */ + return ANSI_MID; + } + pansi->hindex = -1; /* not a hyperlink */ + } + /* Check for SGR sequences */ + if (is_ansi_middle(ch)) + return ANSI_MID; + if (is_ansi_end(ch)) + return ANSI_END; + return ANSI_ERR; } +/* + * Free an ansi_state structure. + */ + public void +ansi_done(pansi) + struct ansi_state *pansi; +{ + free(pansi); +} /* * Append a character and attribute to the line buffer. */ -#define STORE_CHAR(ch,a,rep,pos) \ +#define STORE_CHAR(ch,a,rep,pos) \ do { \ if (store_char((ch),(a),(rep),(pos))) return (1); \ } while (0) @@ -617,17 +665,19 @@ store_char(ch, a, rep, pos) POSITION pos; { int w; + int i; int replen; char cs; - w = (a & (AT_UNDERLINE|AT_BOLD)); /* Pre-use w. */ - if (w != AT_NORMAL) - last_overstrike = w; + i = (a & (AT_UNDERLINE|AT_BOLD)); + if (i != AT_NORMAL) + last_overstrike = i; #if HILITE_SEARCH { int matches; - if (is_hilited(pos, pos+1, 0, &matches)) + int hl_attr = is_hilited_attr(pos, pos+1, 0, &matches); + if (hl_attr) { /* * This character should be highlighted. @@ -635,43 +685,24 @@ store_char(ch, a, rep, pos) */ if (a != AT_ANSI) { - if (highest_hilite != NULL_POSITION && - pos > highest_hilite) - highest_hilite = pos; - a |= AT_HILITE; + if (highest_hilite != NULL_POSITION && pos > highest_hilite) + highest_hilite = pos; + a |= hl_attr; } } } #endif - if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq()) - { - if (!is_ansi_end(ch) && !is_ansi_middle(ch)) { - /* Remove whole unrecognized sequence. */ - char *p = &linebuf[curr]; - LWCHAR bch; - do { - bch = step_char(&p, -1, linebuf); - } while (p > linebuf && !IS_CSI_START(bch)); - curr = (int) (p - linebuf); - return 0; - } - a = AT_ANSI; /* Will force re-AT_'ing around it. */ - w = 0; - } - else if (ctldisp == OPT_ONPLUS && IS_CSI_START(ch)) - { - a = AT_ANSI; /* Will force re-AT_'ing around it. */ + if (a == AT_ANSI) { w = 0; - } - else - { - char *p = &linebuf[curr]; - LWCHAR prev_ch = step_char(&p, -1, linebuf); - w = pwidth(ch, a, prev_ch); + } else { + char *p = &linebuf.buf[linebuf.end]; + LWCHAR prev_ch = (linebuf.end > 0) ? step_char(&p, -1, linebuf.buf) : 0; + int prev_a = (linebuf.end > 0) ? linebuf.attr[linebuf.end-1] : 0; + w = pwidth(ch, a, prev_ch, prev_a); } - if (ctldisp != OPT_ON && column + w + attr_ewidth(a) > sc_width) + if (ctldisp != OPT_ON && end_column - cshift + w + attr_ewidth(a) > sc_width) /* * Won't fit on screen. */ @@ -686,7 +717,7 @@ store_char(ch, a, rep, pos) { replen = utf_len(rep[0]); } - if (curr + replen >= size_linebuf-6) + if (linebuf.end + replen >= size_linebuf-6) { /* * Won't fit in line buffer. @@ -696,17 +727,42 @@ store_char(ch, a, rep, pos) return (1); } - if (column > right_column && w > 0) + if (cshift == hshift && shifted_ansi.end > 0) { - right_column = column; - right_curr = curr; + /* Copy shifted ANSI sequences to beginning of line. */ + for (i = 0; i < shifted_ansi.end; i++) + add_linebuf(shifted_ansi.buf[i], AT_ANSI, 0); + shifted_ansi.end = 0; } + /* Add the char to the buf, even if we will left-shift it next. */ + inc_end_column(w); + for (i = 0; i < replen; i++) + add_linebuf(*rep++, a, 0); - while (replen-- > 0) + if (cshift < hshift) { - add_linebuf(*rep++, a, 0); + /* We haven't left-shifted enough yet. */ + if (a == AT_ANSI) + add_ansi(ch); /* Save ANSI attributes */ + if (linebuf.end > linebuf.print) + { + /* Shift left enough to put last byte of this char at print-1. */ + memcpy(&linebuf.buf[0], &linebuf.buf[replen], linebuf.print); + memcpy(&linebuf.attr[0], &linebuf.attr[replen], linebuf.print); + linebuf.end -= replen; + cshift += w; + /* + * If the char we just left-shifted was double width, + * the 2 spaces we shifted may be too much. + * Represent the "half char" at start of line with a highlighted space. + */ + while (cshift > hshift) + { + add_linebuf(' ', rscroll_attr, 0); + cshift--; + } + } } - column += w; return (0); } @@ -714,7 +770,7 @@ store_char(ch, a, rep, pos) * Append a tab to the line buffer. * Store spaces to represent the tab. */ -#define STORE_TAB(a,pos) \ +#define STORE_TAB(a,pos) \ do { if (store_tab((a),(pos))) return (1); } while (0) static int @@ -722,23 +778,20 @@ store_tab(attr, pos) int attr; POSITION pos; { - int to_tab = column + cshift - lmargin; - int i; + int to_tab = end_column - linebuf.pfx_end; if (ntabstops < 2 || to_tab >= tabstops[ntabstops-1]) to_tab = tabdefault - ((to_tab - tabstops[ntabstops-1]) % tabdefault); else { + int i; for (i = ntabstops - 2; i >= 0; i--) if (to_tab >= tabstops[i]) break; to_tab = tabstops[i+1] - to_tab; } - if (column + to_tab - 1 + pwidth(' ', attr, 0) + attr_ewidth(attr) > sc_width) - return 1; - do { STORE_CHAR(' ', attr, " ", pos); } while (--to_tab > 0); @@ -759,18 +812,8 @@ store_prchar(c, pos) * Convert to printable representation. */ s = prchar(c); - - /* - * Make sure we can get the entire representation - * of the character on this line. - */ - if (column + (int) strlen(s) - 1 + - pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width) - return 1; - for ( ; *s != 0; s++) - STORE_CHAR(*s, AT_BINARY, NULL, pos); - + STORE_CHAR(*s, AT_BINARY|AT_COLOR_CTRL, NULL, pos); return 0; } @@ -783,7 +826,6 @@ flush_mbc_buf(pos) for (i = 0; i < mbc_buf_index; i++) if (store_prchar(mbc_buf[i], pos)) return mbc_buf_index - i; - return 0; } @@ -875,19 +917,7 @@ pappend(c, pos) /* Handle new char. */ if (!r) goto retry; - } - } - - /* - * If we need to shift the line, do it. - * But wait until we get to at least the middle of the screen, - * so shifting it doesn't affect the chars we're currently - * pappending. (Bold & underline can get messed up otherwise.) - */ - if (cshift < hshift && column > sc_width / 2) - { - linebuf[curr] = '\0'; - pshift(hshift - cshift); + } } if (r) { @@ -898,37 +928,91 @@ pappend(c, pos) } static int -do_append(ch, rep, pos) +store_control_char(ch, rep, pos) LWCHAR ch; char *rep; POSITION pos; { - int a; - LWCHAR prev_ch; - - a = AT_NORMAL; + if (ctldisp == OPT_ON) + { + /* Output the character itself. */ + STORE_CHAR(ch, AT_NORMAL, rep, pos); + } else + { + /* Output a printable representation of the character. */ + STORE_PRCHAR((char) ch, pos); + } + return (0); +} - if (ch == '\b') + static int +store_ansi(ch, rep, pos) + LWCHAR ch; + char *rep; + POSITION pos; +{ + switch (ansi_step(line_ansi, ch)) { - if (bs_mode == BS_CONTROL) - goto do_control_char; + case ANSI_MID: + STORE_CHAR(ch, AT_ANSI, rep, pos); + break; + case ANSI_END: + STORE_CHAR(ch, AT_ANSI, rep, pos); + ansi_done(line_ansi); + line_ansi = NULL; + break; + case ANSI_ERR: { + /* Remove whole unrecognized sequence. */ + char *start = (cshift < hshift) ? shifted_ansi.buf : linebuf.buf; + int *end = (cshift < hshift) ? &shifted_ansi.end : &linebuf.end; + char *p = start + *end; + LWCHAR bch; + do { + bch = step_char(&p, -1, start); + } while (p > start && !IS_CSI_START(bch)); + *end = (int) (p - start); + ansi_done(line_ansi); + line_ansi = NULL; + break; } + } + return (0); +} - /* - * A better test is needed here so we don't - * backspace over part of the printed - * representation of a binary character. - */ - if ( curr <= lmargin - || column <= lmargin - || (attr[curr - 1] & (AT_ANSI|AT_BINARY))) - STORE_PRCHAR('\b', pos); - else if (bs_mode == BS_NORMAL) - STORE_CHAR(ch, AT_NORMAL, NULL, pos); - else if (bs_mode == BS_SPECIAL) - overstrike = backc(); + static int +store_bs(ch, rep, pos) + LWCHAR ch; + char *rep; + POSITION pos; +{ + if (bs_mode == BS_CONTROL) + return store_control_char(ch, rep, pos); + if (linebuf.end > 0 && + ((linebuf.end <= linebuf.print && linebuf.buf[linebuf.end-1] == '\0') || + (linebuf.end > 0 && linebuf.attr[linebuf.end - 1] & (AT_ANSI|AT_BINARY)))) + STORE_PRCHAR('\b', pos); + else if (bs_mode == BS_NORMAL) + STORE_CHAR(ch, AT_NORMAL, NULL, pos); + else if (bs_mode == BS_SPECIAL) + overstrike = backc(); + return 0; +} - return 0; - } + static int +do_append(ch, rep, pos) + LWCHAR ch; + char *rep; + POSITION pos; +{ + int a = AT_NORMAL; + + if (ctldisp == OPT_ONPLUS && line_ansi == NULL) + line_ansi = ansi_start(ch); + + if (line_ansi != NULL) + return store_ansi(ch, rep, pos); + + if (ch == '\b') + return store_bs(ch, rep, pos); if (overstrike > 0) { @@ -937,18 +1021,19 @@ do_append(ch, rep, pos) * in the line buffer. This will cause either * underline (if a "_" is overstruck), * bold (if an identical character is overstruck), - * or just deletion of the character in the buffer. + * or just replacing the character in the buffer. */ + LWCHAR prev_ch; overstrike = utf_mode ? -1 : 0; if (utf_mode) { /* To be correct, this must be a base character. */ - prev_ch = get_wchar(linebuf + curr); + prev_ch = get_wchar(&linebuf.buf[linebuf.end]); } else { - prev_ch = (unsigned char) linebuf[curr]; + prev_ch = (unsigned char) linebuf.buf[linebuf.end]; } - a = attr[curr]; + a = linebuf.attr[linebuf.end]; if (ch == prev_ch) { /* @@ -972,7 +1057,7 @@ do_append(ch, rep, pos) { a |= AT_UNDERLINE; ch = prev_ch; - rep = linebuf + curr; + rep = &linebuf.buf[linebuf.end]; } else if (prev_ch == '_') { a |= AT_UNDERLINE; @@ -981,14 +1066,14 @@ do_append(ch, rep, pos) } else if (overstrike < 0) { if ( is_composing_char(ch) - || is_combining_char(get_wchar(linebuf + curr), ch)) + || is_combining_char(get_wchar(&linebuf.buf[linebuf.end]), ch)) /* Continuation of the same overstrike. */ a = last_overstrike; else overstrike = 0; } - if (ch == '\t') + if (ch == '\t') { /* * Expand a tab into spaces. @@ -996,42 +1081,27 @@ do_append(ch, rep, pos) switch (bs_mode) { case BS_CONTROL: - goto do_control_char; + return store_control_char(ch, rep, pos); case BS_NORMAL: case BS_SPECIAL: STORE_TAB(a, pos); break; } - } else if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch)) + return (0); + } + if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch)) { - do_control_char: - if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && IS_CSI_START(ch))) - { - /* - * Output as a normal character. - */ - STORE_CHAR(ch, AT_NORMAL, rep, pos); - } else - { - STORE_PRCHAR((char) ch, pos); - } + return store_control_char(ch, rep, pos); } else if (utf_mode && ctldisp != OPT_ON && is_ubin_char(ch)) { - char *s; - - s = prutfchar(ch); - - if (column + (int) strlen(s) - 1 + - pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width) - return (1); - + char *s = prutfchar(ch); for ( ; *s != 0; s++) STORE_CHAR(*s, AT_BINARY, NULL, pos); - } else + } else { STORE_CHAR(ch, a, rep, pos); } - return (0); + return (0); } /* @@ -1084,12 +1154,6 @@ pdone(endline, chopped, forw) */ (void) do_append(pendc, NULL, pendpos); - /* - * Make sure we've shifted the line, if we need to. - */ - if (cshift < hshift) - pshift(hshift - cshift); - if (chopped && rscroll_char) { /* @@ -1097,21 +1161,21 @@ pdone(endline, chopped, forw) * If we've already filled the rightmost screen char * (in the buffer), overwrite it. */ - if (column >= sc_width) + if (end_column >= sc_width + cshift) { /* We've already written in the rightmost char. */ - column = right_column; - curr = right_curr; + end_column = right_column; + linebuf.end = right_curr; } add_attr_normal(); - while (column < sc_width-1) + while (end_column < sc_width-1 + cshift) { /* * Space to last (rightmost) char on screen. * This may be necessary if the char we overwrote * was double-width. */ - add_linebuf(' ', AT_NORMAL, 1); + add_linebuf(' ', rscroll_attr, 1); } /* Print rscroll char. It must be single-width. */ add_linebuf(rscroll_char, rscroll_attr, 1); @@ -1133,11 +1197,11 @@ pdone(endline, chopped, forw) * the next line is blank. In that case the single newline output for * that blank line would be ignored!) */ - if (column < sc_width || !auto_wrap || (endline && ignaw) || ctldisp == OPT_ON) + if (end_column < sc_width + cshift || !auto_wrap || (endline && ignaw) || ctldisp == OPT_ON) { add_linebuf('\n', AT_NORMAL, 0); } - else if (ignaw && column >= sc_width && forw) + else if (ignaw && end_column >= sc_width + cshift && forw) { /* * Terminals with "ignaw" don't wrap until they *really* need @@ -1156,17 +1220,18 @@ pdone(endline, chopped, forw) add_linebuf(' ', AT_NORMAL, 1); add_linebuf('\b', AT_NORMAL, -1); } - set_linebuf(curr, '\0', AT_NORMAL); + set_linebuf(linebuf.end, '\0', AT_NORMAL); } /* * */ public void -set_status_col(c) +set_status_col(c, attr) int c; + int attr; { - set_linebuf(0, c, AT_NORMAL|AT_HILITE); + set_pfx(0, c, attr); } /* @@ -1199,8 +1264,14 @@ gline(i, ap) return i ? '\0' : '\n'; } - *ap = attr[i]; - return (linebuf[i] & 0xFF); + if (i < linebuf.pfx_end) + { + *ap = linebuf.pfx_attr[i]; + return linebuf.pfx[i]; + } + i += linebuf.print - linebuf.pfx_end; + *ap = linebuf.attr[i]; + return (linebuf.buf[i] & 0xFF); } /* @@ -1252,12 +1323,12 @@ forw_raw_line(curr_pos, linep, line_lenp) break; } } - linebuf[n++] = c; + linebuf.buf[n++] = c; c = ch_forw_get(); } - linebuf[n] = '\0'; + linebuf.buf[n] = '\0'; if (linep != NULL) - *linep = linebuf; + *linep = linebuf.buf; if (line_lenp != NULL) *line_lenp = n; return (new_pos); @@ -1282,7 +1353,7 @@ back_raw_line(curr_pos, linep, line_lenp) return (NULL_POSITION); n = size_linebuf; - linebuf[--n] = '\0'; + linebuf.buf[--n] = '\0'; for (;;) { c = ch_back_get(); @@ -1322,16 +1393,16 @@ back_raw_line(curr_pos, linep, line_lenp) /* * Shift the data to the end of the new linebuf. */ - for (fm = linebuf + old_size_linebuf - 1, - to = linebuf + size_linebuf - 1; - fm >= linebuf; fm--, to--) + for (fm = linebuf.buf + old_size_linebuf - 1, + to = linebuf.buf + size_linebuf - 1; + fm >= linebuf.buf; fm--, to--) *to = *fm; n = size_linebuf - old_size_linebuf; } - linebuf[--n] = c; + linebuf.buf[--n] = c; } if (linep != NULL) - *linep = &linebuf[n]; + *linep = &linebuf.buf[n]; if (line_lenp != NULL) *line_lenp = size_linebuf - 1 - n; return (new_pos); @@ -1350,16 +1421,80 @@ rrshift(VOID_PARAM) save_width = sc_width; sc_width = INT_MAX; - hshift = 0; pos = position(TOP); for (line = 0; line < sc_height && pos != NULL_POSITION; line++) { pos = forw_line(pos); - if (column > longest) - longest = column; + if (end_column > longest) + longest = end_column; } sc_width = save_width; if (longest < sc_width) return 0; return longest - sc_width; } + +/* + * Get the color_map index associated with a given attribute. + */ + static int +color_index(attr) + int attr; +{ + if (use_color) + { + switch (attr & AT_COLOR) + { + case AT_COLOR_ATTN: return 0; + case AT_COLOR_BIN: return 1; + case AT_COLOR_CTRL: return 2; + case AT_COLOR_ERROR: return 3; + case AT_COLOR_LINENUM: return 4; + case AT_COLOR_MARK: return 5; + case AT_COLOR_PROMPT: return 6; + case AT_COLOR_RSCROLL: return 7; + case AT_COLOR_SEARCH: return 8; + } + } + if (attr & AT_UNDERLINE) + return 9; + if (attr & AT_BOLD) + return 10; + if (attr & AT_BLINK) + return 11; + if (attr & AT_STANDOUT) + return 12; + return -1; +} + +/* + * Set the color string to use for a given attribute. + */ + public int +set_color_map(attr, colorstr) + int attr; + char *colorstr; +{ + int cx = color_index(attr); + if (cx < 0) + return -1; + if (strlen(colorstr)+1 > sizeof(color_map[cx])) + return -1; + if (*colorstr != '\0' && parse_color(colorstr, NULL, NULL) == CT_NULL) + return -1; + strcpy(color_map[cx], colorstr); + return 0; +} + +/* + * Get the color string to use for a given attribute. + */ + public char * +get_color_map(attr) + int attr; +{ + int cx = color_index(attr); + if (cx < 0) + return NULL; + return color_map[cx]; +} diff --git a/linenum.c b/linenum.c index 46c3154..00cac60 100644 --- a/linenum.c +++ b/linenum.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -40,11 +40,11 @@ */ struct linenum_info { - struct linenum_info *next; /* Link to next in the list */ - struct linenum_info *prev; /* Line to previous in the list */ - POSITION pos; /* File position */ - POSITION gap; /* Gap between prev and next */ - LINENUM line; /* Line number */ + struct linenum_info *next; /* Link to next in the list */ + struct linenum_info *prev; /* Line to previous in the list */ + POSITION pos; /* File position */ + POSITION gap; /* Gap between prev and next */ + LINENUM line; /* Line number */ }; /* * "gap" needs some explanation: the gap of any particular line number @@ -55,14 +55,14 @@ struct linenum_info * when we have a new one to insert and the table is full. */ -#define NPOOL 200 /* Size of line number pool */ +#define NPOOL 200 /* Size of line number pool */ -#define LONGTIME (2) /* In seconds */ +#define LONGTIME (2) /* In seconds */ -static struct linenum_info anchor; /* Anchor of the list */ -static struct linenum_info *freelist; /* Anchor of the unused entries */ -static struct linenum_info pool[NPOOL]; /* The pool itself */ -static struct linenum_info *spare; /* We always keep one spare entry */ +static struct linenum_info anchor; /* Anchor of the list */ +static struct linenum_info *freelist; /* Anchor of the unused entries */ +static struct linenum_info pool[NPOOL]; /* The pool itself */ +static struct linenum_info *spare; /* We always keep one spare entry */ extern int linenums; extern int sigs; @@ -248,6 +248,8 @@ longish(VOID_PARAM) static void abort_long(VOID_PARAM) { + if (loopcount >= 0) + return; if (linenums == OPT_ONPLUS) /* * We were displaying line numbers, so need to repaint. @@ -308,6 +310,7 @@ find_linenum(pos) #if HAVE_TIME startime = get_time(); #endif + loopcount = 0; if (p == &anchor || pos - p->prev->pos < p->pos - pos) { /* @@ -316,7 +319,6 @@ find_linenum(pos) p = p->prev; if (ch_seek(p->pos)) return (0); - loopcount = 0; for (linenum = p->line, cpos = p->pos; cpos < pos; linenum++) { /* @@ -348,7 +350,6 @@ find_linenum(pos) */ if (ch_seek(p->pos)) return (0); - loopcount = 0; for (linenum = p->line, cpos = p->pos; cpos > pos; linenum--) { /* @@ -368,7 +369,7 @@ find_linenum(pos) */ add_lnum(linenum, cpos); } - + loopcount = 0; return (linenum); } diff --git a/lsystem.c b/lsystem.c index 5e51c06..5c67526 100644 --- a/lsystem.c +++ b/lsystem.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -97,7 +97,7 @@ lsystem(cmd, donemsg) * De-initialize the terminal and take out of raw mode. */ deinit(); - flush(); /* Make sure the deinit chars get out */ + flush(); /* Make sure the deinit chars get out */ raw_mode(0); #if MSDOS_COMPILER==WIN32C close_getchr(); @@ -116,11 +116,13 @@ lsystem(cmd, donemsg) */ inp = dup(0); close(0); +#if !MSDOS_COMPILER #if OS2 /* The __open() system call translates "/dev/tty" to "con". */ - if (__open("/dev/tty", OPEN_READ) < 0) + if (__open(tty_device(), OPEN_READ) < 0) #else - if (open("/dev/tty", OPEN_READ) < 0) + if (open(tty_device(), OPEN_READ) < 0) +#endif #endif dup(inp); #endif @@ -169,7 +171,7 @@ lsystem(cmd, donemsg) * also makes trouble with some DPMI servers). */ __djgpp_exception_toggle(); - system(cmd); + system(cmd); __djgpp_exception_toggle(); #else system(cmd); @@ -274,14 +276,14 @@ pipe_mark(c, cmd) tpos = ch_zero(); bpos = position(BOTTOM); - if (c == '.') - return (pipe_data(cmd, tpos, bpos)); - else if (mpos <= tpos) - return (pipe_data(cmd, mpos, bpos)); - else if (bpos == NULL_POSITION) - return (pipe_data(cmd, tpos, bpos)); - else - return (pipe_data(cmd, tpos, mpos)); + if (c == '.') + return (pipe_data(cmd, tpos, bpos)); + else if (mpos <= tpos) + return (pipe_data(cmd, mpos, bpos)); + else if (bpos == NULL_POSITION) + return (pipe_data(cmd, tpos, bpos)); + else + return (pipe_data(cmd, tpos, mpos)); } /* @@ -346,14 +348,14 @@ pipe_data(cmd, spos, epos) /* * Finish up the last line. */ - while (c != '\n' && c != EOI ) - { - c = ch_forw_get(); - if (c == EOI) - break; - if (putc(c, f) == EOF) - break; - } + while (c != '\n' && c != EOI ) + { + c = ch_forw_get(); + if (c == EOI) + break; + if (putc(c, f) == EOF) + break; + } pclose(f); diff --git a/main.c b/main.c index 784ca5b..7248842 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -18,49 +18,49 @@ #include #endif -public char * every_first_cmd = NULL; -public int new_file; -public int is_tty; -public IFILE curr_ifile = NULL_IFILE; -public IFILE old_ifile = NULL_IFILE; +public char * every_first_cmd = NULL; +public int new_file; +public int is_tty; +public IFILE curr_ifile = NULL_IFILE; +public IFILE old_ifile = NULL_IFILE; public struct scrpos initial_scrpos; -public int any_display = FALSE; -public POSITION start_attnpos = NULL_POSITION; -public POSITION end_attnpos = NULL_POSITION; -public int wscroll; -public char * progname; -public int quitting; -public int secure; -public int dohelp; +public POSITION start_attnpos = NULL_POSITION; +public POSITION end_attnpos = NULL_POSITION; +public int wscroll; +public char * progname; +public int quitting; +public int secure; +public int dohelp; #if LOGFILE -public int logfile = -1; -public int force_logfile = FALSE; -public char * namelogfile = NULL; +public int logfile = -1; +public int force_logfile = FALSE; +public char * namelogfile = NULL; #endif #if EDITOR -public char * editor; -public char * editproto; +public char * editor; +public char * editproto; #endif #if TAGS -extern char * tags; -extern char * tagoption; -extern int jump_sline; +extern char * tags; +extern char * tagoption; +extern int jump_sline; #endif #ifdef WIN32 static char consoleTitle[256]; #endif -public int one_screen; -extern int less_is_more; -extern int missing_cap; -extern int know_dumb; -extern int pr_type; -extern int quit_if_one_screen; -extern int no_init; +public int one_screen; +extern int less_is_more; +extern int missing_cap; +extern int know_dumb; +extern int pr_type; +extern int quit_if_one_screen; +extern int no_init; +extern int errmsgs; /* @@ -82,10 +82,14 @@ main(argc, argv) progname = *argv++; argc--; +#if SECURE + secure = 1; +#else secure = 0; s = lgetenv("LESSSECURE"); if (!isnullenv(s)) secure = 1; +#endif #ifdef WIN32 if (getenv("HOME") == NULL) @@ -137,7 +141,7 @@ main(argc, argv) if (s != NULL) scan_option(save(s)); -#define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0') +#define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0') while (argc > 0 && (isoptstring(*argv) || isoptpending())) { s = *argv++; @@ -219,6 +223,7 @@ main(argc, argv) * Output is not a tty. * Just copy the input file(s) to output. */ + set_output(1); /* write to stdout */ SET_BINARY(1); if (edit_first() == 0) { @@ -282,6 +287,18 @@ main(argc, argv) } } + if (errmsgs > 0) + { + /* + * We displayed some messages on error output + * (file descriptor 2; see flush()). + * Before erasing the screen contents, wait for a keystroke. + */ + less_printf("Press RETURN to continue ", NULL_PARG); + get_return(); + putchr('\n'); + } + set_output(1); init(); commands(); quit(QUIT_OK); @@ -331,7 +348,7 @@ ecalloc(count, size) skipsp(s) char *s; { - while (*s == ' ' || *s == '\t') + while (*s == ' ' || *s == '\t') s++; return (s); } @@ -388,10 +405,13 @@ quit(status) status = save_status; else save_status = status; +#if LESSTEST + rstat('Q'); +#endif /*LESSTEST*/ quitting = 1; edit((char*)NULL); save_cmdhist(); - if (any_display && is_tty) + if (interactive()) clear_bot(); deinit(); flush(); diff --git a/mark.c b/mark.c index e86d7b3..cbb316f 100644 --- a/mark.c +++ b/mark.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -38,10 +38,10 @@ struct mark * Each mark is identified by a lowercase or uppercase letter. * The final one is lmark, for the "last mark"; addressed by the apostrophe. */ -#define NMARKS ((2*26)+2) /* a-z, A-Z, mousemark, lastmark */ -#define NUMARKS ((2*26)+1) /* user marks (not lastmark) */ -#define MOUSEMARK (NMARKS-2) -#define LASTMARK (NMARKS-1) +#define NMARKS ((2*26)+2) /* a-z, A-Z, mousemark, lastmark */ +#define NUMARKS ((2*26)+1) /* user marks (not lastmark) */ +#define MOUSEMARK (NMARKS-2) +#define LASTMARK (NMARKS-1) static struct mark marks[NMARKS]; public int marks_modified = 0; @@ -116,13 +116,17 @@ mark_get_ifile(m) getumark(c) int c; { + PARG parg; if (c >= 'a' && c <= 'z') return (&marks[c-'a']); if (c >= 'A' && c <= 'Z') return (&marks[c-'A'+26]); + if (c == '\'') + return (&marks[LASTMARK]); if (c == '#') return (&marks[MOUSEMARK]); - error("Invalid mark letter", NULL_PARG); + parg.p_char = (char) c; + error("Invalid mark letter %c", &parg); return (NULL); } @@ -259,6 +263,7 @@ lastmark(VOID_PARAM) if (scrpos.pos == NULL_POSITION) return; cmark(&marks[LASTMARK], curr_ifile, scrpos.pos, scrpos.ln); + marks_modified = 1; } /* @@ -370,7 +375,7 @@ mark_check_ifile(ifile) IFILE ifile; { int i; - char *filename = lrealpath(get_filename(ifile)); + char *filename = get_real_filename(ifile); for (i = 0; i < NMARKS; i++) { @@ -384,7 +389,6 @@ mark_check_ifile(ifile) free(mark_filename); } } - free(filename); } #if CMD_HISTORY @@ -403,7 +407,7 @@ save_marks(fout, hdr) return; fprintf(fout, "%s\n", hdr); - for (i = 0; i < NUMARKS; i++) + for (i = 0; i < NMARKS; i++) { char *filename; struct mark *m = &marks[i]; @@ -413,12 +417,10 @@ save_marks(fout, hdr) postoa(m->m_scrpos.pos, pos_str); filename = m->m_filename; if (filename == NULL) - filename = get_filename(m->m_ifile); - filename = lrealpath(filename); + filename = get_real_filename(m->m_ifile); if (strcmp(filename, "-") != 0) fprintf(fout, "m %c %d %s %s\n", m->m_letter, m->m_scrpos.ln, pos_str, filename); - free(filename); } } diff --git a/mkfuncs.py b/mkfuncs.py new file mode 100644 index 0000000..7a2da5a --- /dev/null +++ b/mkfuncs.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +import fileinput +import re + +definition = '' +state = 0 +params = 0 + +for line in fileinput.input(): + if test := re.search(r'^\tpublic\s+(.*)', line): + definition = 'public ' + test.group(1) + state = 1 + params = 0 + elif (state == 1) and (test := re.search(r'(\w+)\s*\(', line)): + definition = '{0} LESSPARAMS (('.format(test.group(1)) + state = 2 + elif state == 2: + if re.search(r'^{', line): + if not params: definition += 'VOID_PARAM' + print(f'{definition}));') + state = 0 + elif test := re.search(r'^\s*([^;]*)', line): + if (definition[-1:] != '('): definition += ', ' + definition += test.group(1) + params = 1 diff --git a/mkhelp.py b/mkhelp.py new file mode 100644 index 0000000..029f150 --- /dev/null +++ b/mkhelp.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import time +import sys + +time = time.gmtime() +print("/* This file was generated by mkhelp.py from less.hlp at "\ + "%d:%02d GMT on %d/%d/%d */\n" % + (time.tm_hour, time.tm_min, time.tm_year, time.tm_mon, time.tm_mday)) +print("#include \"less.h\"") +print("constant char helpdata[] = {") +ch = 0 +while True: + prevch = ch + ch = sys.stdin.read(1) + if ch == '': + break + if (ch == "'"): + print("'\\'',", end='') + elif (ch == "\\"): + print("'\\\\',", end='') + elif (ch == "\b"): + print ("'\\b',", end='') + elif (ch == "\t"): + print ("'\\t',", end='') + elif (ch == "\n"): + if prevch != "\r": print("'\\n',") + elif (ch == "\r"): + if prevch != "\n": print("'\\n',") + else: + if ((ord(ch) >= ord(' ')) and (ord(ch) < 0x7f)): + print(f"'{ch}',", end='') + else: + print("0x%02x," % ord(ch), end='') +print(" '\\0' };") +print("constant int size_helpdata = sizeof(helpdata) - 1;") diff --git a/optfunc.c b/optfunc.c index c04f9d4..768fe0e 100644 --- a/optfunc.c +++ b/optfunc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -19,9 +19,9 @@ * Each handling function is passed a "type" and, if it is a string * option, the string which should be "assigned" to the option. * The type may be one of: - * INIT The option is being initialized from the command line. - * TOGGLE The option is being changed from within the program. - * QUERY The setting of the option is merely being queried. + * INIT The option is being initialized from the command line. + * TOGGLE The option is being changed from within the program. + * QUERY The setting of the option is merely being queried. */ #include "less.h" @@ -36,7 +36,7 @@ extern int sc_width; extern int sc_height; extern int secure; extern int dohelp; -extern int any_display; +extern int is_tty; extern char openquote; extern char closequote; extern char *prproto[]; @@ -55,6 +55,9 @@ extern int rscroll_attr; extern int mousecap; extern int wheel_lines; extern int less_is_more; +extern int linenum_width; +extern int status_col_width; +extern int use_color; #if LOGFILE extern char *namelogfile; extern int force_logfile; @@ -65,6 +68,10 @@ public char *tagoption = NULL; extern char *tags; extern char ztags[]; #endif +#if LESSTEST +extern char *ttyin_name; +extern int rstat_file; +#endif /*LESSTEST*/ #if MSDOS_COMPILER extern int nm_fg_color, nm_bg_color; extern int bo_fg_color, bo_bg_color; @@ -395,13 +402,13 @@ opt_p(type, s) } else { plusoption = TRUE; - ungetcc(CHAR_END_COMMAND); - ungetsc(s); /* * {{ This won't work if the "/" command is * changed or invalidated by a .lesskey file. }} */ ungetsc("/"); + ungetsc(s); + ungetcc_back(CHAR_END_COMMAND); } break; } @@ -427,13 +434,13 @@ opt__P(type, s) */ switch (*s) { - case 's': proto = &prproto[PR_SHORT]; s++; break; - case 'm': proto = &prproto[PR_MEDIUM]; s++; break; - case 'M': proto = &prproto[PR_LONG]; s++; break; - case '=': proto = &eqproto; s++; break; - case 'h': proto = &hproto; s++; break; - case 'w': proto = &wproto; s++; break; - default: proto = &prproto[PR_SHORT]; break; + case 's': proto = &prproto[PR_SHORT]; s++; break; + case 'm': proto = &prproto[PR_MEDIUM]; s++; break; + case 'M': proto = &prproto[PR_LONG]; s++; break; + case '=': proto = &eqproto; s++; break; + case 'h': proto = &hproto; s++; break; + case 'w': proto = &wproto; s++; break; + default: proto = &prproto[PR_SHORT]; break; } free(*proto); *proto = save(s); @@ -504,20 +511,28 @@ opt__V(type, s) dispversion(); break; case INIT: - /* - * Force output to stdout per GNU standard for --version output. - */ - any_display = 1; + set_output(1); /* Force output to stdout per GNU standard for --version output. */ putstr("less "); putstr(version); putstr(" ("); putstr(pattern_lib_name()); putstr(" regular expressions)\n"); - putstr("Copyright (C) 1984-2020 Mark Nudelman\n\n"); + { + char constant *copyright = "Copyright (C) 1984-2021 Mark Nudelman\n\n"; + if (copyright[0] == '@') + copyright = "Copyright (C) 1984 Mark Nudelman\n\n"; + putstr(copyright); + } + if (version[strlen(version)-1] == 'x') + { + putstr("** This is an EXPERIMENTAL build of the 'less' software,\n"); + putstr("** and may not function correctly.\n"); + putstr("** Obtain release builds from the web page below.\n\n"); + } putstr("less comes with NO WARRANTY, to the extent permitted by law.\n"); putstr("For information about the terms of redistribution,\n"); putstr("see the file named README in the less distribution.\n"); - putstr("Home page: http://www.greenwoodsoftware.com/less\n"); + putstr("Home page: https://greenwoodsoftware.com/less\n"); quit(QUIT_OK); break; } @@ -527,60 +542,70 @@ opt__V(type, s) /* * Parse an MSDOS color descriptor. */ - static void + static void colordesc(s, fg_color, bg_color) char *s; int *fg_color; int *bg_color; { int fg, bg; - int err; #if MSDOS_COMPILER==WIN32C int ul = 0; - + if (*s == 'u') { ul = COMMON_LVB_UNDERSCORE; - ++s; - } -#endif - fg = getnum(&s, "D", &err); - if (err) - { -#if MSDOS_COMPILER==WIN32C - if (ul) - fg = nm_fg_color; - else -#endif - { - error("Missing fg color in -D", NULL_PARG); - return; - } - } - if (*s != '.') - bg = nm_bg_color; - else - { s++; - bg = getnum(&s, "D", &err); - if (err) + if (*s == '\0') { - error("Missing bg color in -D", NULL_PARG); + *fg_color = nm_fg_color | ul; + *bg_color = nm_bg_color; return; } } -#if MSDOS_COMPILER==WIN32C - if (*s == 'u') +#endif + if (parse_color(s, &fg, &bg) == CT_NULL) { - ul = COMMON_LVB_UNDERSCORE; - ++s; + PARG p; + p.p_string = s; + error("Invalid color string \"%s\"", &p); + } else + { + if (fg == CV_NOCHANGE) + fg = nm_fg_color; + if (bg == CV_NOCHANGE) + bg = nm_bg_color; +#if MSDOS_COMPILER==WIN32C + fg |= ul; +#endif + *fg_color = fg; + *bg_color = bg; } - fg |= ul; +} #endif - if (*s != '\0') - error("Extra characters at end of -D option", NULL_PARG); - *fg_color = fg; - *bg_color = bg; + + static int +color_from_namechar(namechar) + char namechar; +{ + switch (namechar) + { + case 'A': return AT_COLOR_ATTN; + case 'B': return AT_COLOR_BIN; + case 'C': return AT_COLOR_CTRL; + case 'E': return AT_COLOR_ERROR; + case 'M': return AT_COLOR_MARK; + case 'N': return AT_COLOR_LINENUM; + case 'P': return AT_COLOR_PROMPT; + case 'R': return AT_COLOR_RSCROLL; + case 'S': return AT_COLOR_SEARCH; + case 'n': return AT_NORMAL; + case 's': return AT_STANDOUT; + case 'd': return AT_BOLD; + case 'u': return AT_UNDERLINE; + case 'k': return AT_BLINK; + default: return -1; + } } /* @@ -593,48 +618,75 @@ opt_D(type, s) char *s; { PARG p; + int attr; switch (type) { case INIT: case TOGGLE: - switch (*s++) +#if MSDOS_COMPILER + if (*s == 'a') { - case 'n': - colordesc(s, &nm_fg_color, &nm_bg_color); - break; - case 'd': - colordesc(s, &bo_fg_color, &bo_bg_color); - break; - case 'u': - colordesc(s, &ul_fg_color, &ul_bg_color); - break; - case 'k': - colordesc(s, &bl_fg_color, &bl_bg_color); - break; - case 's': - colordesc(s, &so_fg_color, &so_bg_color); - break; - case 'a': sgr_mode = !sgr_mode; break; - default: - error("-D must be followed by n, d, u, k, s or a", NULL_PARG); - break; } - if (type == TOGGLE) +#endif + attr = color_from_namechar(s[0]); + if (attr < 0) + { + p.p_char = s[0]; + error("Invalid color specifier '%c'", &p); + return; + } + if (!use_color && (attr & AT_COLOR)) + { + error("Set --use-color before changing colors", NULL_PARG); + return; + } + s++; +#if MSDOS_COMPILER + if (!(attr & AT_COLOR)) + { + switch (attr) + { + case AT_NORMAL: + colordesc(s, &nm_fg_color, &nm_bg_color); + break; + case AT_BOLD: + colordesc(s, &bo_fg_color, &bo_bg_color); + break; + case AT_UNDERLINE: + colordesc(s, &ul_fg_color, &ul_bg_color); + break; + case AT_BLINK: + colordesc(s, &bl_fg_color, &bl_bg_color); + break; + case AT_STANDOUT: + colordesc(s, &so_fg_color, &so_bg_color); + break; + } + if (type == TOGGLE) + { + at_enter(AT_STANDOUT); + at_exit(); + } + } else +#endif + if (set_color_map(attr, s) < 0) { - at_enter(AT_STANDOUT); - at_exit(); + p.p_string = s; + error("Invalid color string \"%s\"", &p); + return; } break; +#if MSDOS_COMPILER case QUERY: p.p_string = (sgr_mode) ? "on" : "off"; error("SGR mode is %s", &p); break; +#endif } } -#endif /* * Handler for the -x option. @@ -759,7 +811,7 @@ opt_rscroll(type, s) } else { rscroll_char = *fmt ? *fmt : '>'; - rscroll_attr = attr; + rscroll_attr = attr|AT_COLOR_RSCROLL; } break; } case QUERY: { @@ -834,6 +886,103 @@ opt_wheel_lines(type, s) } } +/* + * Handler for the --line-number-width option. + */ + /*ARGSUSED*/ + public void +opt_linenum_width(type, s) + int type; + char *s; +{ + PARG parg; + + switch (type) + { + case INIT: + case TOGGLE: + if (linenum_width > MAX_LINENUM_WIDTH) + { + parg.p_int = MAX_LINENUM_WIDTH; + error("Line number width must not be larger than %d", &parg); + linenum_width = MIN_LINENUM_WIDTH; + } + break; + case QUERY: + break; + } +} + +/* + * Handler for the --status-column-width option. + */ + /*ARGSUSED*/ + public void +opt_status_col_width(type, s) + int type; + char *s; +{ + PARG parg; + + switch (type) + { + case INIT: + case TOGGLE: + if (status_col_width > MAX_STATUSCOL_WIDTH) + { + parg.p_int = MAX_STATUSCOL_WIDTH; + error("Status column width must not be larger than %d", &parg); + status_col_width = 2; + } + break; + case QUERY: + break; + } +} + +#if LESSTEST +/* + * Handler for the --tty option. + */ + /*ARGSUSED*/ + public void +opt_ttyin_name(type, s) + int type; + char *s; +{ + switch (type) + { + case INIT: + ttyin_name = s; + is_tty = 1; + break; + } +} + +/* + * Handler for the --rstat option. + */ + /*ARGSUSED*/ + public void +opt_rstat(type, s) + int type; + char *s; +{ + switch (type) + { + case INIT: + rstat_file = open(s, O_WRONLY|O_CREAT, 0664); + if (rstat_file < 0) + { + PARG parg; + parg.p_string = s; + error("Cannot create rstat file \"%s\"", &parg); + } + break; + } +} +#endif /*LESSTEST*/ + /* * Get the "screen window" size. */ diff --git a/option.c b/option.c index 9cb19bc..61247d8 100644 --- a/option.c +++ b/option.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -23,8 +23,7 @@ static struct loption *pendopt; public int plusoption = FALSE; -static char *optstring LESSPARAMS((char *s, char **p_str, char *printopt, - char *validchars)); +static char *optstring LESSPARAMS((char *s, char **p_str, char *printopt, char *validchars)); static int flip_triple LESSPARAMS((int val, int lc)); extern int screen_trashed; @@ -157,8 +156,8 @@ scan_option(s) every_first_cmd = save(str+1); } else { - ungetcc(CHAR_END_COMMAND); ungetsc(str); + ungetcc_back(CHAR_END_COMMAND); } free(str); continue; @@ -297,10 +296,10 @@ scan_option(s) * Toggle command line flags from within the program. * Used by the "-" and "_" commands. * how_toggle may be: - * OPT_NO_TOGGLE just report the current setting, without changing it. - * OPT_TOGGLE invert the current setting - * OPT_UNSET set to the default value - * OPT_SET set to the inverse of the default value + * OPT_NO_TOGGLE just report the current setting, without changing it. + * OPT_TOGGLE invert the current setting + * OPT_UNSET set to the default value + * OPT_SET set to the inverse of the default value */ public void toggle_option(o, lower, s, how_toggle) @@ -384,10 +383,10 @@ toggle_option(o, lower, s, how_toggle) case TRIPLE: /* * Triple: - * If user gave the lower case letter, then switch - * to 1 unless already 1, in which case make it 0. - * If user gave the upper case letter, then switch - * to 2 unless already 2, in which case make it 0. + * If user gave the lower case letter, then switch + * to 1 unless already 1, in which case make it 0. + * If user gave the upper case letter, then switch + * to 2 unless already 2, in which case make it 0. */ switch (how_toggle) { @@ -405,7 +404,7 @@ toggle_option(o, lower, s, how_toggle) case STRING: /* * String: don't do anything here. - * The handling function will do everything. + * The handling function will do everything. */ switch (how_toggle) { diff --git a/option.h b/option.h index c705aca..4a10d6b 100644 --- a/option.h +++ b/option.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -8,59 +8,59 @@ */ -#define END_OPTION_STRING ('$') +#define END_OPTION_STRING ('$') /* * Types of options. */ -#define BOOL 01 /* Boolean option: 0 or 1 */ -#define TRIPLE 02 /* Triple-valued option: 0, 1 or 2 */ -#define NUMBER 04 /* Numeric option */ -#define STRING 010 /* String-valued option */ -#define NOVAR 020 /* No associated variable */ -#define REPAINT 040 /* Repaint screen after toggling option */ -#define NO_TOGGLE 0100 /* Option cannot be toggled with "-" cmd */ -#define HL_REPAINT 0200 /* Repaint hilites after toggling option */ -#define NO_QUERY 0400 /* Option cannot be queried with "_" cmd */ -#define INIT_HANDLER 01000 /* Call option handler function at startup */ +#define BOOL 01 /* Boolean option: 0 or 1 */ +#define TRIPLE 02 /* Triple-valued option: 0, 1 or 2 */ +#define NUMBER 04 /* Numeric option */ +#define STRING 010 /* String-valued option */ +#define NOVAR 020 /* No associated variable */ +#define REPAINT 040 /* Repaint screen after toggling option */ +#define NO_TOGGLE 0100 /* Option cannot be toggled with "-" cmd */ +#define HL_REPAINT 0200 /* Repaint hilites after toggling option */ +#define NO_QUERY 0400 /* Option cannot be queried with "_" cmd */ +#define INIT_HANDLER 01000 /* Call option handler function at startup */ -#define OTYPE (BOOL|TRIPLE|NUMBER|STRING|NOVAR) +#define OTYPE (BOOL|TRIPLE|NUMBER|STRING|NOVAR) #define OLETTER_NONE '\1' /* Invalid option letter */ /* * Argument to a handling function tells what type of activity: */ -#define INIT 0 /* Initialization (from command line) */ -#define QUERY 1 /* Query (from _ or - command) */ -#define TOGGLE 2 /* Change value (from - command) */ +#define INIT 0 /* Initialization (from command line) */ +#define QUERY 1 /* Query (from _ or - command) */ +#define TOGGLE 2 /* Change value (from - command) */ /* Flag to toggle_option to specify how to "toggle" */ -#define OPT_NO_TOGGLE 0 -#define OPT_TOGGLE 1 -#define OPT_UNSET 2 -#define OPT_SET 3 -#define OPT_NO_PROMPT 0100 +#define OPT_NO_TOGGLE 0 +#define OPT_TOGGLE 1 +#define OPT_UNSET 2 +#define OPT_SET 3 +#define OPT_NO_PROMPT 0100 /* Error code from findopt_name */ #define OPT_AMBIG 1 struct optname { - char *oname; /* Long (GNU-style) option name */ - struct optname *onext; /* List of synonymous option names */ + char *oname; /* Long (GNU-style) option name */ + struct optname *onext; /* List of synonymous option names */ }; -#define OPTNAME_MAX 32 /* Max length of long option name */ +#define OPTNAME_MAX 32 /* Max length of long option name */ struct loption { - char oletter; /* The controlling letter (a-z) */ - struct optname *onames; /* Long (GNU-style) option name */ - int otype; /* Type of the option */ - int odefault; /* Default value */ - int *ovar; /* Pointer to the associated variable */ - void (*ofunc) LESSPARAMS ((int, char*)); /* Pointer to special handling function */ - char *odesc[3]; /* Description of each value */ + char oletter; /* The controlling letter (a-z) */ + struct optname *onames; /* Long (GNU-style) option name */ + int otype; /* Type of the option */ + int odefault; /* Default value */ + int *ovar; /* Pointer to the associated variable */ + void (*ofunc) LESSPARAMS ((int, char*)); /* Pointer to special handling function */ + char *odesc[3]; /* Description of each value */ }; diff --git a/opttbl.c b/opttbl.c index 1871f8a..3a5d283 100644 --- a/opttbl.c +++ b/opttbl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -18,52 +18,56 @@ /* * Variables controlled by command line options. */ -public int quiet; /* Should we suppress the audible bell? */ -public int how_search; /* Where should forward searches start? */ -public int top_scroll; /* Repaint screen from top? - (alternative is scroll from bottom) */ -public int pr_type; /* Type of prompt (short, medium, long) */ -public int bs_mode; /* How to process backspaces */ -public int know_dumb; /* Don't complain about dumb terminals */ -public int quit_at_eof; /* Quit after hitting end of file twice */ -public int quit_if_one_screen; /* Quit if EOF on first screen */ -public int squeeze; /* Squeeze multiple blank lines into one */ -public int tabstop; /* Tab settings */ -public int back_scroll; /* Repaint screen on backwards movement */ -public int forw_scroll; /* Repaint screen on forward movement */ -public int caseless; /* Do "caseless" searches */ -public int linenums; /* Use line numbers */ -public int autobuf; /* Automatically allocate buffers as needed */ -public int bufspace; /* Max buffer space per file (K) */ -public int ctldisp; /* Send control chars to screen untranslated */ -public int force_open; /* Open the file even if not regular file */ -public int swindow; /* Size of scrolling window */ -public int jump_sline; /* Screen line of "jump target" */ +public int quiet; /* Should we suppress the audible bell? */ +public int how_search; /* Where should forward searches start? */ +public int top_scroll; /* Repaint screen from top? + (alternative is scroll from bottom) */ +public int pr_type; /* Type of prompt (short, medium, long) */ +public int bs_mode; /* How to process backspaces */ +public int know_dumb; /* Don't complain about dumb terminals */ +public int quit_at_eof; /* Quit after hitting end of file twice */ +public int quit_if_one_screen; /* Quit if EOF on first screen */ +public int squeeze; /* Squeeze multiple blank lines into one */ +public int tabstop; /* Tab settings */ +public int back_scroll; /* Repaint screen on backwards movement */ +public int forw_scroll; /* Repaint screen on forward movement */ +public int caseless; /* Do "caseless" searches */ +public int linenums; /* Use line numbers */ +public int autobuf; /* Automatically allocate buffers as needed */ +public int bufspace; /* Max buffer space per file (K) */ +public int ctldisp; /* Send control chars to screen untranslated */ +public int force_open; /* Open the file even if not regular file */ +public int swindow; /* Size of scrolling window */ +public int jump_sline; /* Screen line of "jump target" */ public long jump_sline_fraction = -1; public long shift_count_fraction = -1; -public int chopline; /* Truncate displayed lines at screen width */ -public int no_init; /* Disable sending ti/te termcap strings */ -public int no_keypad; /* Disable sending ks/ke termcap strings */ +public int chopline; /* Truncate displayed lines at screen width */ +public int no_init; /* Disable sending ti/te termcap strings */ +public int no_keypad; /* Disable sending ks/ke termcap strings */ public int twiddle; /* Show tildes after EOF */ -public int show_attn; /* Hilite first unread line */ -public int shift_count; /* Number of positions to shift horizontally */ -public int status_col; /* Display a status column */ -public int use_lessopen; /* Use the LESSOPEN filter */ -public int quit_on_intr; /* Quit on interrupt */ -public int follow_mode; /* F cmd Follows file desc or file name? */ -public int oldbot; /* Old bottom of screen behavior {{REMOVE}} */ -public int opt_use_backslash; /* Use backslash escaping in option parsing */ -public char rscroll_char; /* Char which marks chopped lines with -S */ -public int rscroll_attr; /* Attribute of rscroll_char */ -public int no_hist_dups; /* Remove dups from history list */ -public int mousecap; /* Allow mouse for scrolling */ -public int wheel_lines; /* Number of lines to scroll on mouse wheel scroll */ -public int perma_marks; /* Save marks in history file */ +public int show_attn; /* Hilite first unread line */ +public int shift_count; /* Number of positions to shift horizontally */ +public int status_col; /* Display a status column */ +public int use_lessopen; /* Use the LESSOPEN filter */ +public int quit_on_intr; /* Quit on interrupt */ +public int follow_mode; /* F cmd Follows file desc or file name? */ +public int oldbot; /* Old bottom of screen behavior {{REMOVE}} */ +public int opt_use_backslash; /* Use backslash escaping in option parsing */ +public char rscroll_char; /* Char which marks chopped lines with -S */ +public int rscroll_attr; /* Attribute of rscroll_char */ +public int no_hist_dups; /* Remove dups from history list */ +public int mousecap; /* Allow mouse for scrolling */ +public int wheel_lines; /* Number of lines to scroll on mouse wheel scroll */ +public int perma_marks; /* Save marks in history file */ +public int linenum_width; /* Width of line numbers */ +public int status_col_width; /* Width of status column */ +public int incr_search; /* Incremental search */ +public int use_color; /* Use UI color */ #if HILITE_SEARCH -public int hilite_search; /* Highlight matched search patterns? */ +public int hilite_search; /* Highlight matched search patterns? */ #endif -public int less_is_more = 0; /* Make compatible with POSIX more */ +public int less_is_more = 0; /* Make compatible with POSIX more */ /* * Long option names. @@ -73,9 +77,7 @@ static struct optname b_optname = { "buffers", NULL }; static struct optname B__optname = { "auto-buffers", NULL }; static struct optname c_optname = { "clear-screen", NULL }; static struct optname d_optname = { "dumb", NULL }; -#if MSDOS_COMPILER static struct optname D__optname = { "color", NULL }; -#endif static struct optname e_optname = { "quit-at-eof", NULL }; static struct optname f_optname = { "force", NULL }; static struct optname F__optname = { "quit-if-one-screen", NULL }; @@ -127,7 +129,15 @@ static struct optname rscroll_optname = { "rscroll", NULL }; static struct optname nohistdups_optname = { "no-histdups", NULL }; static struct optname mousecap_optname = { "mouse", NULL }; static struct optname wheel_lines_optname = { "wheel-lines", NULL }; -static struct optname perma_marks_optname = { "save-marks", NULL }; +static struct optname perma_marks_optname = { "save-marks", NULL }; +static struct optname linenum_width_optname = { "line-num-width", NULL }; +static struct optname status_col_width_optname = { "status-col-width", NULL }; +static struct optname incr_search_optname = { "incsearch", NULL }; +static struct optname use_color_optname = { "use-color", NULL }; +#if LESSTEST +static struct optname ttyin_name_optname = { "tty", NULL }; +static struct optname rstat_optname = { "rstat", NULL }; +#endif /*LESSTEST*/ /* @@ -185,16 +195,14 @@ static struct loption option[] = NULL } }, -#if MSDOS_COMPILER { 'D', &D__optname, - STRING|REPAINT, 0, NULL, opt_D, + STRING|REPAINT|NO_QUERY, 0, NULL, opt_D, { "color desc: ", - "Dadknsu0123456789.", + NULL, NULL } }, -#endif { 'e', &e_optname, TRIPLE, OPT_OFF, &quit_at_eof, NULL, { @@ -503,6 +511,56 @@ static struct loption option[] = NULL } }, + { OLETTER_NONE, &linenum_width_optname, + NUMBER|REPAINT, MIN_LINENUM_WIDTH, &linenum_width, opt_linenum_width, + { + "Line number width: ", + "Line number width is %d chars", + NULL + } + }, + { OLETTER_NONE, &status_col_width_optname, + NUMBER|REPAINT, 2, &status_col_width, opt_status_col_width, + { + "Status column width: ", + "Status column width is %d chars", + NULL + } + }, + { OLETTER_NONE, &incr_search_optname, + BOOL, OPT_OFF, &incr_search, NULL, + { + "Incremental search is off", + "Incremental search is on", + NULL + } + }, + { OLETTER_NONE, &use_color_optname, + BOOL|REPAINT, OPT_OFF, &use_color, NULL, + { + "Don't use color", + "Use color", + NULL + } + }, +#if LESSTEST + { OLETTER_NONE, &ttyin_name_optname, + STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name, + { + NULL, + NULL, + NULL + } + }, + { OLETTER_NONE, &rstat_optname, + STRING|NO_TOGGLE, 0, NULL, opt_rstat, + { + NULL, + NULL, + NULL + } + }, +#endif /*LESSTEST*/ { '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } } }; diff --git a/os.c b/os.c index 1f33f4f..1723787 100644 --- a/os.c +++ b/os.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -23,6 +23,9 @@ #include "less.h" #include #include +#if MSDOS_COMPILER==WIN32C +#include +#endif #if HAVE_TIME_H #include #endif @@ -33,6 +36,15 @@ #include #endif +#if HAVE_POLL && !MSDOS_COMPILER && !defined(__APPLE__) +#define USE_POLL 1 +#else +#define USE_POLL 0 +#endif +#if USE_POLL +#include +#endif + /* * BSD setjmp() saves (and longjmp() restores) the signal mask. * This costs a system call or two per setjmp(), so if possible we clear the @@ -41,11 +53,11 @@ * _setjmp() does not exist; we just use setjmp(). */ #if HAVE__SETJMP && HAVE_SIGSETMASK -#define SET_JUMP _setjmp -#define LONG_JUMP _longjmp +#define SET_JUMP _setjmp +#define LONG_JUMP _longjmp #else -#define SET_JUMP setjmp -#define LONG_JUMP longjmp +#define SET_JUMP setjmp +#define LONG_JUMP longjmp #endif public int reading; @@ -53,6 +65,27 @@ public int reading; static jmp_buf read_label; extern int sigs; +extern int ignore_eoi; +#if !MSDOS_COMPILER +extern int tty; +#endif + +#if USE_POLL +/* + * Return true if one of the events has occurred on the specified file. + */ + static int +poll_events(fd, events) + int fd; + int events; +{ + struct pollfd poller = { fd, events, 0 }; + int n = poll(&poller, 1, 0); + if (n <= 0) + return 0; + return (poller.revents & events); +} +#endif /* * Like read() system call, but is deliberately interruptible. @@ -126,6 +159,29 @@ iread(fd, buf, len) if (select(fd+1, &readfds, 0, 0, 0) == -1) return (-1); } +#endif +#if USE_POLL + if (ignore_eoi && fd != tty) + { + if (poll_events(tty, POLLIN) && getchr() == CONTROL('X')) + { + sigs |= S_INTERRUPT; + return (READ_INTR); + } + if (poll_events(fd, POLLERR|POLLHUP)) + { + sigs |= S_INTERRUPT; + return (READ_INTR); + } + } +#else +#if MSDOS_COMPILER==WIN32C + if (win32_kbhit() && WIN32getch() == CONTROL('X')) + { + sigs |= S_INTERRUPT; + return (READ_INTR); + } +#endif #endif n = read(fd, buf, len); #if 1 @@ -135,7 +191,6 @@ iread(fd, buf, len) * start returning 0 forever, instead of -1. */ { - extern int ignore_eoi; if (!ignore_eoi) { static int consecutive_nulls = 0; @@ -204,18 +259,16 @@ get_time(VOID_PARAM) strerror(err) int err; { -#if HAVE_SYS_ERRLIST static char buf[16]; +#if HAVE_SYS_ERRLIST extern char *sys_errlist[]; extern int sys_nerr; if (err < sys_nerr) return sys_errlist[err]; +#endif sprintf(buf, "Error %d", err); return buf; -#else - return ("cannot open"); -#endif } #endif @@ -356,3 +409,24 @@ isatty(f) } #endif + + public void +sleep_ms(ms) + int ms; +{ +#if MSDOS_COMPILER==WIN32C + Sleep(ms); +#else +#if HAVE_NANOSLEEP + int sec = ms / 1000; + struct timespec t = { sec, (ms - sec*1000) * 1000000 }; + nanosleep(&t, NULL); +#else +#if HAVE_USLEEP + usleep(ms); +#else + sleep((ms+999) / 1000); +#endif +#endif +#endif +} diff --git a/output.c b/output.c index b3d192d..ddb6ad2 100644 --- a/output.c +++ b/output.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -20,7 +20,7 @@ #endif #endif -public int errmsgs; /* Count of messages displayed by error() */ +public int errmsgs; /* Count of messages displayed by error() */ public int need_clr; public int final_attr; public int at_prompt; @@ -29,7 +29,6 @@ extern int sigs; extern int sc_width; extern int so_s_width, so_e_width; extern int screen_trashed; -extern int any_display; extern int is_tty; extern int oldbot; @@ -42,7 +41,7 @@ extern int so_fg_color, so_bg_color; extern int bl_fg_color, bl_bg_color; extern int sgr_mode; #if MSDOS_COMPILER==WIN32C -extern int have_ul; +extern int vt_enabled; #endif #endif @@ -82,6 +81,269 @@ put_line(VOID_PARAM) static char obuf[OUTBUF_SIZE]; static char *ob = obuf; +static int outfd = 2; /* stderr */ + +#if MSDOS_COMPILER==WIN32C || MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC + static void +win_flush(VOID_PARAM) +{ + if (ctldisp != OPT_ONPLUS || (vt_enabled && sgr_mode)) + WIN32textout(obuf, ob - obuf); + else + { + /* + * Look for SGR escape sequences, and convert them + * to color commands. Replace bold, underline, + * and italic escapes into colors specified via + * the -D command-line option. + */ + char *anchor, *p, *p_next; + static int fg, fgi, bg, bgi; + static int at; + int f, b; +#if MSDOS_COMPILER==WIN32C + /* Screen colors used by 3x and 4x SGR commands. */ + static unsigned char screen_color[] = { + 0, /* BLACK */ + FOREGROUND_RED, + FOREGROUND_GREEN, + FOREGROUND_RED|FOREGROUND_GREEN, + FOREGROUND_BLUE, + FOREGROUND_BLUE|FOREGROUND_RED, + FOREGROUND_BLUE|FOREGROUND_GREEN, + FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED + }; +#else + static enum COLORS screen_color[] = { + BLACK, RED, GREEN, BROWN, + BLUE, MAGENTA, CYAN, LIGHTGRAY + }; +#endif + + if (fg == 0 && bg == 0) + { + fg = nm_fg_color & 7; + fgi = nm_fg_color & 8; + bg = nm_bg_color & 7; + bgi = nm_bg_color & 8; + } + for (anchor = p_next = obuf; + (p_next = memchr(p_next, ESC, ob - p_next)) != NULL; ) + { + p = p_next; + if (p[1] == '[') /* "ESC-[" sequence */ + { + if (p > anchor) + { + /* + * If some chars seen since + * the last escape sequence, + * write them out to the screen. + */ + WIN32textout(anchor, p-anchor); + anchor = p; + } + p += 2; /* Skip the "ESC-[" */ + if (is_ansi_end(*p)) + { + /* + * Handle null escape sequence + * "ESC[m", which restores + * the normal color. + */ + p++; + anchor = p_next = p; + fg = nm_fg_color & 7; + fgi = nm_fg_color & 8; + bg = nm_bg_color & 7; + bgi = nm_bg_color & 8; + at = 0; + WIN32setcolors(nm_fg_color, nm_bg_color); + continue; + } + p_next = p; + at &= ~32; + + /* + * Select foreground/background colors + * based on the escape sequence. + */ + while (!is_ansi_end(*p)) + { + char *q; + long code = strtol(p, &q, 10); + + if (*q == '\0') + { + /* + * Incomplete sequence. + * Leave it unprocessed + * in the buffer. + */ + int slop = (int) (q - anchor); + /* {{ strcpy args overlap! }} */ + strcpy(obuf, anchor); + ob = &obuf[slop]; + return; + } + + if (q == p || + code > 49 || code < 0 || + (!is_ansi_end(*q) && *q != ';')) + { + p_next = q; + break; + } + if (*q == ';') + { + q++; + at |= 32; + } + + switch (code) + { + default: + /* case 0: all attrs off */ + fg = nm_fg_color & 7; + bg = nm_bg_color & 7; + at &= 32; + /* + * \e[0m use normal + * intensities, but + * \e[0;...m resets them + */ + if (at & 32) + { + fgi = 0; + bgi = 0; + } else + { + fgi = nm_fg_color & 8; + bgi = nm_bg_color & 8; + } + break; + case 1: /* bold on */ + fgi = 8; + at |= 1; + break; + case 3: /* italic on */ + case 7: /* inverse on */ + at |= 2; + break; + case 4: /* underline on */ + bgi = 8; + at |= 4; + break; + case 5: /* slow blink on */ + case 6: /* fast blink on */ + bgi = 8; + at |= 8; + break; + case 8: /* concealed on */ + at |= 16; + break; + case 22: /* bold off */ + fgi = 0; + at &= ~1; + break; + case 23: /* italic off */ + case 27: /* inverse off */ + at &= ~2; + break; + case 24: /* underline off */ + bgi = 0; + at &= ~4; + break; + case 28: /* concealed off */ + at &= ~16; + break; + case 30: case 31: case 32: + case 33: case 34: case 35: + case 36: case 37: + fg = screen_color[code - 30]; + at |= 32; + break; + case 39: /* default fg */ + fg = nm_fg_color & 7; + at |= 32; + break; + case 40: case 41: case 42: + case 43: case 44: case 45: + case 46: case 47: + bg = screen_color[code - 40]; + at |= 32; + break; + case 49: /* default bg */ + bg = nm_bg_color & 7; + at |= 32; + break; + } + p = q; + } + if (!is_ansi_end(*p) || p == p_next) + break; + /* + * In SGR mode, the ANSI sequence is + * always honored; otherwise if an attr + * is used by itself ("\e[1m" versus + * "\e[1;33m", for example), set the + * color assigned to that attribute. + */ + if (sgr_mode || (at & 32)) + { + if (at & 2) + { + f = bg | bgi; + b = fg | fgi; + } else + { + f = fg | fgi; + b = bg | bgi; + } + } else + { + if (at & 1) + { + f = bo_fg_color; + b = bo_bg_color; + } else if (at & 2) + { + f = so_fg_color; + b = so_bg_color; + } else if (at & 4) + { + f = ul_fg_color; + b = ul_bg_color; + } else if (at & 8) + { + f = bl_fg_color; + b = bl_bg_color; + } else + { + f = nm_fg_color; + b = nm_bg_color; + } + } + if (at & 16) + f = b ^ 8; +#if MSDOS_COMPILER==WIN32C + f &= 0xf | COMMON_LVB_UNDERSCORE; +#else + f &= 0xf; +#endif + b &= 0xf; + WIN32setcolors(f, b); + p_next = anchor = p + 1; + } else + p_next++; + } + + /* Output what's left in the buffer. */ + WIN32textout(anchor, ob - anchor); + } + ob = obuf; +} +#endif /* * Flush buffered output. @@ -103,293 +365,44 @@ static char *ob = obuf; flush(VOID_PARAM) { int n; - int fd; n = (int) (ob - obuf); if (n == 0) return; + ob = obuf; #if MSDOS_COMPILER==MSOFTC - if (is_tty && any_display) + if (interactive()) { - *ob = '\0'; + obuf[n] = '\0'; _outtext(obuf); - ob = obuf; return; } #else #if MSDOS_COMPILER==WIN32C || MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - if (is_tty && any_display) + if (interactive()) { + ob = obuf + n; *ob = '\0'; - if (ctldisp != OPT_ONPLUS) - WIN32textout(obuf, ob - obuf); - else - { - /* - * Look for SGR escape sequences, and convert them - * to color commands. Replace bold, underline, - * and italic escapes into colors specified via - * the -D command-line option. - */ - char *anchor, *p, *p_next; - static int fg, fgi, bg, bgi; - static int at; - int f, b; -#if MSDOS_COMPILER==WIN32C - /* Screen colors used by 3x and 4x SGR commands. */ - static unsigned char screen_color[] = { - 0, /* BLACK */ - FOREGROUND_RED, - FOREGROUND_GREEN, - FOREGROUND_RED|FOREGROUND_GREEN, - FOREGROUND_BLUE, - FOREGROUND_BLUE|FOREGROUND_RED, - FOREGROUND_BLUE|FOREGROUND_GREEN, - FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED - }; -#else - static enum COLORS screen_color[] = { - BLACK, RED, GREEN, BROWN, - BLUE, MAGENTA, CYAN, LIGHTGRAY - }; -#endif - - if (fg == 0 && bg == 0) - { - fg = nm_fg_color & 7; - fgi = nm_fg_color & 8; - bg = nm_bg_color & 7; - bgi = nm_bg_color & 8; - } - for (anchor = p_next = obuf; - (p_next = memchr(p_next, ESC, ob - p_next)) != NULL; ) - { - p = p_next; - if (p[1] == '[') /* "ESC-[" sequence */ - { - if (p > anchor) - { - /* - * If some chars seen since - * the last escape sequence, - * write them out to the screen. - */ - WIN32textout(anchor, p-anchor); - anchor = p; - } - p += 2; /* Skip the "ESC-[" */ - if (is_ansi_end(*p)) - { - /* - * Handle null escape sequence - * "ESC[m", which restores - * the normal color. - */ - p++; - anchor = p_next = p; - fg = nm_fg_color & 7; - fgi = nm_fg_color & 8; - bg = nm_bg_color & 7; - bgi = nm_bg_color & 8; - at = 0; - WIN32setcolors(nm_fg_color, nm_bg_color); - continue; - } - p_next = p; - at &= ~32; - - /* - * Select foreground/background colors - * based on the escape sequence. - */ - while (!is_ansi_end(*p)) - { - char *q; - long code = strtol(p, &q, 10); - - if (*q == '\0') - { - /* - * Incomplete sequence. - * Leave it unprocessed - * in the buffer. - */ - int slop = (int) (q - anchor); - /* {{ strcpy args overlap! }} */ - strcpy(obuf, anchor); - ob = &obuf[slop]; - return; - } - - if (q == p || - code > 49 || code < 0 || - (!is_ansi_end(*q) && *q != ';')) - { - p_next = q; - break; - } - if (*q == ';') - { - q++; - at |= 32; - } - - switch (code) - { - default: - /* case 0: all attrs off */ - fg = nm_fg_color & 7; - bg = nm_bg_color & 7; - at &= 32; - /* - * \e[0m use normal - * intensities, but - * \e[0;...m resets them - */ - if (at & 32) - { - fgi = 0; - bgi = 0; - } else - { - fgi = nm_fg_color & 8; - bgi = nm_bg_color & 8; - } - break; - case 1: /* bold on */ - fgi = 8; - at |= 1; - break; - case 3: /* italic on */ - case 7: /* inverse on */ - at |= 2; - break; - case 4: /* underline on */ -#if MSDOS_COMPILER==WIN32C - if (have_ul) - bgi = COMMON_LVB_UNDERSCORE >> 4; - else -#endif - bgi = 8; - at |= 4; - break; - case 5: /* slow blink on */ - case 6: /* fast blink on */ - bgi = 8; - at |= 8; - break; - case 8: /* concealed on */ - at |= 16; - break; - case 22: /* bold off */ - fgi = 0; - at &= ~1; - break; - case 23: /* italic off */ - case 27: /* inverse off */ - at &= ~2; - break; - case 24: /* underline off */ - bgi = 0; - at &= ~4; - break; - case 28: /* concealed off */ - at &= ~16; - break; - case 30: case 31: case 32: - case 33: case 34: case 35: - case 36: case 37: - fg = screen_color[code - 30]; - at |= 32; - break; - case 39: /* default fg */ - fg = nm_fg_color & 7; - at |= 32; - break; - case 40: case 41: case 42: - case 43: case 44: case 45: - case 46: case 47: - bg = screen_color[code - 40]; - at |= 32; - break; - case 49: /* default bg */ - bg = nm_bg_color & 7; - at |= 32; - break; - } - p = q; - } - if (!is_ansi_end(*p) || p == p_next) - break; - /* - * In SGR mode, the ANSI sequence is - * always honored; otherwise if an attr - * is used by itself ("\e[1m" versus - * "\e[1;33m", for example), set the - * color assigned to that attribute. - */ - if (sgr_mode || (at & 32)) - { - if (at & 2) - { - f = bg | bgi; - b = fg | fgi; - } else - { - f = fg | fgi; - b = bg | bgi; - } - } else - { - if (at & 1) - { - f = bo_fg_color; - b = bo_bg_color; - } else if (at & 2) - { - f = so_fg_color; - b = so_bg_color; - } else if (at & 4) - { - f = ul_fg_color; - b = ul_bg_color; - } else if (at & 8) - { - f = bl_fg_color; - b = bl_bg_color; - } else - { - f = nm_fg_color; - b = nm_bg_color; - } - } - if (at & 16) - f = b ^ 8; - f &= 0xf; -#if MSDOS_COMPILER==WIN32C - b &= 0xf | (COMMON_LVB_UNDERSCORE >> 4); -#else - b &= 0xf; -#endif - WIN32setcolors(f, b); - p_next = anchor = p + 1; - } else - p_next++; - } - - /* Output what's left in the buffer. */ - WIN32textout(anchor, ob - anchor); - } - ob = obuf; + win_flush(); return; } #endif #endif - fd = (any_display) ? 1 : 2; - if (write(fd, obuf, n) != n) + + if (write(outfd, obuf, n) != n) screen_trashed = 1; - ob = obuf; +} + +/* + * Set the output file descriptor (1=stdout or 2=stderr). + */ + public void +set_output(fd) + int fd; +{ + flush(); + outfd = fd; } /* @@ -491,8 +504,8 @@ type funcname(buf, ebuf) \ char **ebuf; \ { \ type val = 0; \ - for (;;) { \ - char c = *buf++; \ + for (;; buf++) { \ + char c = *buf; \ if (c < '0' || c > '9') break; \ val = 10 * val + c - '0'; \ } \ @@ -534,8 +547,11 @@ iprint_linenum(num) /* * This function implements printf-like functionality * using a more portable argument list mechanism than printf's. + * + * {{ This paranoia about the portability of printf dates from experiences + * with systems in the 1980s and is of course no longer necessary. }} */ - static int + public int less_printf(fmt, parg) char *fmt; PARG *parg; @@ -572,6 +588,10 @@ less_printf(fmt, parg) col += iprint_linenum(parg->p_linenum); parg++; break; + case 'c': + putchr(parg->p_char); + col++; + break; case '%': putchr('%'); break; @@ -615,24 +635,20 @@ error(fmt, parg) errmsgs++; - if (any_display && is_tty) - { - if (!oldbot) - squish_check(); - at_exit(); - clear_bot(); - at_enter(AT_STANDOUT); - col += so_s_width; - } - - col += less_printf(fmt, parg); - - if (!(any_display && is_tty)) + if (!interactive()) { + less_printf(fmt, parg); putchr('\n'); return; } + if (!oldbot) + squish_check(); + at_exit(); + clear_bot(); + at_enter(AT_STANDOUT|AT_COLOR_ERROR); + col += so_s_width; + col += less_printf(fmt, parg); putstr(return_to_continue); at_exit(); col += sizeof(return_to_continue) + so_e_width; @@ -667,7 +683,7 @@ ierror(fmt, parg) { at_exit(); clear_bot(); - at_enter(AT_STANDOUT); + at_enter(AT_STANDOUT|AT_COLOR_ERROR); (void) less_printf(fmt, parg); putstr(intr_to_abort); at_exit(); @@ -687,22 +703,24 @@ query(fmt, parg) int c; int col = 0; - if (any_display && is_tty) + if (interactive()) clear_bot(); (void) less_printf(fmt, parg); c = getchr(); - if (!(any_display && is_tty)) + if (interactive()) + { + lower_left(); + if (col >= sc_width) + screen_trashed = 1; + flush(); + } else { putchr('\n'); - return (c); } - lower_left(); - if (col >= sc_width) - screen_trashed = 1; - flush(); - + if (c == 'Q') + quit(QUIT_OK); return (c); } diff --git a/pattern.c b/pattern.c index b7fc057..c2266fc 100644 --- a/pattern.c +++ b/pattern.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -145,9 +145,10 @@ compile_pattern2(pattern, search_type, comp_pattern, show_error) * Like compile_pattern2, but convert the pattern to lowercase if necessary. */ public int -compile_pattern(pattern, search_type, comp_pattern) +compile_pattern(pattern, search_type, show_error, comp_pattern) char *pattern; int search_type; + int show_error; PATTERN_TYPE *comp_pattern; { char *cvt_pattern; @@ -160,7 +161,7 @@ compile_pattern(pattern, search_type, comp_pattern) cvt_pattern = (char*) ecalloc(1, cvt_length(strlen(pattern), CVT_TO_LC)); cvt_text(cvt_pattern, pattern, (int *)NULL, (int *)NULL, CVT_TO_LC); } - result = compile_pattern2(cvt_pattern, search_type, comp_pattern, 1); + result = compile_pattern2(cvt_pattern, search_type, comp_pattern, show_error); if (cvt_pattern != pattern) free(cvt_pattern); return (result); @@ -214,6 +215,7 @@ uncompile_pattern(pattern) #endif } +#if 0 /* * Can a pattern be successfully compiled? */ @@ -224,13 +226,14 @@ valid_pattern(pattern) PATTERN_TYPE comp_pattern; int result; - CLEAR_PATTERN(comp_pattern); + SET_NULL_PATTERN(comp_pattern); result = compile_pattern2(pattern, 0, &comp_pattern, 0); if (result != 0) return (0); uncompile_pattern(&comp_pattern); return (1); } +#endif /* * Is a compiled pattern null? diff --git a/pattern.h b/pattern.h index 677f45b..6cd9d1a 100644 --- a/pattern.h +++ b/pattern.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -11,7 +11,7 @@ #define __USE_GNU 1 #include #define PATTERN_TYPE struct re_pattern_buffer * -#define CLEAR_PATTERN(name) name = NULL +#define SET_NULL_PATTERN(name) name = NULL #endif #if HAVE_POSIX_REGCOMP @@ -22,27 +22,27 @@ #define REGCOMP_FLAG 0 #endif #define PATTERN_TYPE regex_t * -#define CLEAR_PATTERN(name) name = NULL +#define SET_NULL_PATTERN(name) name = NULL #endif #if HAVE_PCRE #include #define PATTERN_TYPE pcre * -#define CLEAR_PATTERN(name) name = NULL +#define SET_NULL_PATTERN(name) name = NULL #endif #if HAVE_PCRE2 #define PCRE2_CODE_UNIT_WIDTH 8 #include #define PATTERN_TYPE pcre2_code * -#define CLEAR_PATTERN(name) name = NULL +#define SET_NULL_PATTERN(name) name = NULL #endif #if HAVE_RE_COMP char *re_comp LESSPARAMS ((char*)); int re_exec LESSPARAMS ((char*)); #define PATTERN_TYPE int -#define CLEAR_PATTERN(name) name = 0 +#define SET_NULL_PATTERN(name) name = 0 #endif #if HAVE_REGCMP @@ -50,17 +50,17 @@ char *regcmp LESSPARAMS ((char*)); char *regex LESSPARAMS ((char**, char*)); extern char *__loc1; #define PATTERN_TYPE char ** -#define CLEAR_PATTERN(name) name = NULL +#define SET_NULL_PATTERN(name) name = NULL #endif #if HAVE_V8_REGCOMP #include "regexp.h" extern int reg_show_error; #define PATTERN_TYPE struct regexp * -#define CLEAR_PATTERN(name) name = NULL +#define SET_NULL_PATTERN(name) name = NULL #endif #if NO_REGEX #define PATTERN_TYPE void * -#define CLEAR_PATTERN(name) +#define SET_NULL_PATTERN(name) #endif diff --git a/pckeys.h b/pckeys.h index e41ca9a..8b21d72 100644 --- a/pckeys.h +++ b/pckeys.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -13,21 +13,21 @@ * Special (non-ASCII) keys on the PC send a two-byte sequence, * where the first byte is 0 and the second is as defined below. */ -#define PCK_SHIFT_TAB '\017' -#define PCK_ALT_E '\022' -#define PCK_CAPS_LOCK '\072' -#define PCK_F1 '\073' -#define PCK_NUM_LOCK '\105' -#define PCK_HOME '\107' -#define PCK_UP '\110' -#define PCK_PAGEUP '\111' -#define PCK_LEFT '\113' -#define PCK_RIGHT '\115' -#define PCK_END '\117' -#define PCK_DOWN '\120' -#define PCK_PAGEDOWN '\121' -#define PCK_INSERT '\122' -#define PCK_DELETE '\123' -#define PCK_CTL_LEFT '\163' -#define PCK_CTL_RIGHT '\164' -#define PCK_CTL_DELETE '\223' +#define PCK_SHIFT_TAB '\017' +#define PCK_ALT_E '\022' +#define PCK_CAPS_LOCK '\072' +#define PCK_F1 '\073' +#define PCK_NUM_LOCK '\105' +#define PCK_HOME '\107' +#define PCK_UP '\110' +#define PCK_PAGEUP '\111' +#define PCK_LEFT '\113' +#define PCK_RIGHT '\115' +#define PCK_END '\117' +#define PCK_DOWN '\120' +#define PCK_PAGEDOWN '\121' +#define PCK_INSERT '\122' +#define PCK_DELETE '\123' +#define PCK_CTL_LEFT '\163' +#define PCK_CTL_RIGHT '\164' +#define PCK_CTL_DELETE '\223' diff --git a/position.c b/position.c index 6e37ec5..8f6edc9 100644 --- a/position.c +++ b/position.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -21,7 +21,7 @@ #include "less.h" #include "position.h" -static POSITION *table = NULL; /* The position table */ +static POSITION *table = NULL; /* The position table */ static int table_size = 0; extern int sc_width, sc_height; @@ -30,10 +30,10 @@ extern int sc_width, sc_height; * Return the starting file position of a line displayed on the screen. * The line may be specified as a line number relative to the top * of the screen, but is usually one of these special cases: - * the top (first) line on the screen - * the second line on the screen - * the bottom line on the screen - * the line after the bottom line on the screen + * the top (first) line on the screen + * the second line on the screen + * the bottom line on the screen + * the line after the bottom line on the screen */ public POSITION position(sindex) diff --git a/position.h b/position.h index 2e6c71b..4e0efc7 100644 --- a/position.h +++ b/position.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -11,8 +11,8 @@ /* * Include file for interfacing to position.c modules. */ -#define TOP (0) -#define TOP_PLUS_ONE (1) -#define BOTTOM (-1) -#define BOTTOM_PLUS_ONE (-2) -#define MIDDLE (-3) +#define TOP (0) +#define TOP_PLUS_ONE (1) +#define BOTTOM (-1) +#define BOTTOM_PLUS_ONE (-2) +#define MIDDLE (-3) diff --git a/prompt.c b/prompt.c index e587bd7..0e38c0f 100644 --- a/prompt.c +++ b/prompt.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -123,7 +123,7 @@ ap_pos(pos) /* * Append a line number to the end of the message. */ - static void + static void ap_linenum(linenum) LINENUM linenum; { @@ -187,48 +187,48 @@ cond(c, where) switch (c) { - case 'a': /* Anything in the message yet? */ + case 'a': /* Anything in the message yet? */ return (mp > message); - case 'b': /* Current byte offset known? */ + case 'b': /* Current byte offset known? */ return (curr_byte(where) != NULL_POSITION); case 'c': return (hshift != 0); - case 'e': /* At end of file? */ + case 'e': /* At end of file? */ return (eof_displayed()); - case 'f': /* Filename known? */ + case 'f': /* Filename known? */ case 'g': return (strcmp(get_filename(curr_ifile), "-") != 0); - case 'l': /* Line number known? */ - case 'd': /* Same as l */ + case 'l': /* Line number known? */ + case 'd': /* Same as l */ if (!linenums) return 0; return (currline(where) != 0); - case 'L': /* Final line number known? */ - case 'D': /* Final page number known? */ + case 'L': /* Final line number known? */ + case 'D': /* Final page number known? */ return (linenums && ch_length() != NULL_POSITION); - case 'm': /* More than one file? */ + case 'm': /* More than one file? */ #if TAGS return (ntags() ? (ntags() > 1) : (nifile() > 1)); #else return (nifile() > 1); #endif - case 'n': /* First prompt in a new file? */ + case 'n': /* First prompt in a new file? */ #if TAGS return (ntags() ? 1 : new_file); #else return (new_file); #endif - case 'p': /* Percent into file (bytes) known? */ + case 'p': /* Percent into file (bytes) known? */ return (curr_byte(where) != NULL_POSITION && ch_length() > 0); - case 'P': /* Percent into file (lines) known? */ + case 'P': /* Percent into file (lines) known? */ return (currline(where) != 0 && (len = ch_length()) > 0 && find_linenum(len) != 0); - case 's': /* Size of file known? */ + case 's': /* Size of file known? */ case 'B': return (ch_length() != NULL_POSITION); - case 'x': /* Is there a "next" file? */ + case 'x': /* Is there a "next" file? */ #if TAGS if (ntags()) return (0); @@ -264,7 +264,7 @@ protochar(c, where, iseditproto) switch (c) { - case 'b': /* Current byte offset */ + case 'b': /* Current byte offset */ pos = curr_byte(where); if (pos != NULL_POSITION) ap_pos(pos); @@ -274,14 +274,14 @@ protochar(c, where, iseditproto) case 'c': ap_int(hshift); break; - case 'd': /* Current page number */ + case 'd': /* Current page number */ linenum = currline(where); if (linenum > 0 && sc_height > 1) ap_linenum(PAGE_NUM(linenum)); else ap_quest(); break; - case 'D': /* Final page number */ + case 'D': /* Final page number */ /* Find the page number of the last byte in the file (len-1). */ len = ch_length(); if (len == NULL_POSITION) @@ -299,22 +299,22 @@ protochar(c, where, iseditproto) } break; #if EDITOR - case 'E': /* Editor name */ + case 'E': /* Editor name */ ap_str(editor); break; #endif - case 'f': /* File name */ + case 'f': /* File name */ ap_str(get_filename(curr_ifile)); break; - case 'F': /* Last component of file name */ + case 'F': /* Last component of file name */ ap_str(last_component(get_filename(curr_ifile))); break; - case 'g': /* Shell-escaped file name */ + case 'g': /* Shell-escaped file name */ s = shell_quote(get_filename(curr_ifile)); ap_str(s); free(s); break; - case 'i': /* Index into list of files */ + case 'i': /* Index into list of files */ #if TAGS if (ntags()) ap_int(curr_tag()); @@ -322,14 +322,14 @@ protochar(c, where, iseditproto) #endif ap_int(get_index(curr_ifile)); break; - case 'l': /* Current line number */ + case 'l': /* Current line number */ linenum = currline(where); if (linenum != 0) ap_linenum(linenum); else ap_quest(); break; - case 'L': /* Final line number */ + case 'L': /* Final line number */ len = ch_length(); if (len == NULL_POSITION || len == ch_zero() || (linenum = find_linenum(len)) <= 0) @@ -337,7 +337,7 @@ protochar(c, where, iseditproto) else ap_linenum(linenum-1); break; - case 'm': /* Number of files */ + case 'm': /* Number of files */ #if TAGS n = ntags(); if (n) @@ -346,7 +346,7 @@ protochar(c, where, iseditproto) #endif ap_int(nifile()); break; - case 'p': /* Percent into file (bytes) */ + case 'p': /* Percent into file (bytes) */ pos = curr_byte(where); len = ch_length(); if (pos != NULL_POSITION && len > 0) @@ -354,7 +354,7 @@ protochar(c, where, iseditproto) else ap_quest(); break; - case 'P': /* Percent into file (lines) */ + case 'P': /* Percent into file (lines) */ linenum = currline(where); if (linenum == 0 || (len = ch_length()) == NULL_POSITION || len == ch_zero() || @@ -363,7 +363,7 @@ protochar(c, where, iseditproto) else ap_int(percentage(linenum, last_linenum)); break; - case 's': /* Size of file */ + case 's': /* Size of file */ case 'B': len = ch_length(); if (len != NULL_POSITION) @@ -371,12 +371,12 @@ protochar(c, where, iseditproto) else ap_quest(); break; - case 't': /* Truncate trailing spaces in the message */ + case 't': /* Truncate trailing spaces in the message */ while (mp > message && mp[-1] == ' ') mp--; *mp = '\0'; break; - case 'T': /* Type of list */ + case 'T': /* Type of list */ #if TAGS if (ntags()) ap_str("tag"); @@ -384,7 +384,7 @@ protochar(c, where, iseditproto) #endif ap_str("file"); break; - case 'x': /* Name of next file */ + case 'x': /* Name of next file */ h = next_ifile(curr_ifile); if (h != NULL_IFILE) ap_str(get_filename(h)); @@ -469,12 +469,12 @@ wherechar(p, wp) case 'b': case 'd': case 'l': case 'p': case 'P': switch (*++p) { - case 't': *wp = TOP; break; - case 'm': *wp = MIDDLE; break; - case 'b': *wp = BOTTOM; break; - case 'B': *wp = BOTTOM_PLUS_ONE; break; + case 't': *wp = TOP; break; + case 'm': *wp = MIDDLE; break; + case 'b': *wp = BOTTOM; break; + case 'B': *wp = BOTTOM_PLUS_ONE; break; case 'j': *wp = sindex_from_sline(jump_sline); break; - default: *wp = TOP; p--; break; + default: *wp = TOP; p--; break; } } return (p); @@ -501,14 +501,14 @@ pr_expand(proto, maxwidth) { switch (*p) { - default: /* Just put the character in the message */ + default: /* Just put the character in the message */ ap_char(*p); break; - case '\\': /* Backslash escapes the next character */ + case '\\': /* Backslash escapes the next character */ p++; ap_char(*p); break; - case '?': /* Conditional (IF) */ + case '?': /* Conditional (IF) */ if ((c = *++p) == '\0') --p; else @@ -519,12 +519,12 @@ pr_expand(proto, maxwidth) p = skipcond(p); } break; - case ':': /* ELSE */ + case ':': /* ELSE */ p = skipcond(p); break; - case '.': /* ENDIF */ + case '.': /* ENDIF */ break; - case '%': /* Percent escape */ + case '%': /* Percent escape */ if ((c = *++p) == '\0') --p; else diff --git a/regexp.h b/regexp.h index bcef6d1..283ff2a 100644 --- a/regexp.h +++ b/regexp.h @@ -10,13 +10,13 @@ #define NSUBEXP 10 typedef struct regexp { - char *startp[NSUBEXP]; - char *endp[NSUBEXP]; - char regstart; /* Internal use only. */ - char reganch; /* Internal use only. */ - char *regmust; /* Internal use only. */ - int regmlen; /* Internal use only. */ - char program[1]; /* Unwarranted chumminess with compiler. */ + char *startp[NSUBEXP]; + char *endp[NSUBEXP]; + char regstart; /* Internal use only. */ + char reganch; /* Internal use only. */ + char *regmust; /* Internal use only. */ + int regmlen; /* Internal use only. */ + char program[1]; /* Unwarranted chumminess with compiler. */ } regexp; #if defined(__STDC__) || defined(__cplusplus) diff --git a/screen.c b/screen.c index c9635f4..ff6b6d7 100644 --- a/screen.c +++ b/screen.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -35,6 +35,19 @@ extern int fd0; #endif #include +#ifndef FOREGROUND_BLUE +#define FOREGROUND_BLUE 0x0001 +#endif +#ifndef FOREGROUND_GREEN +#define FOREGROUND_GREEN 0x0002 +#endif +#ifndef FOREGROUND_RED +#define FOREGROUND_RED 0x0004 +#endif +#ifndef FOREGROUND_INTENSITY +#define FOREGROUND_INTENSITY 0x0008 +#endif + #else #if HAVE_SYS_IOCTL_H @@ -85,17 +98,19 @@ extern int fd0; #endif #if OS2 -#define DEFAULT_TERM "ansi" +#define DEFAULT_TERM "ansi" static char *windowid; #else -#define DEFAULT_TERM "unknown" +#define DEFAULT_TERM "unknown" #endif #if MSDOS_COMPILER==MSOFTC static int videopages; static long msec_loops; static int flash_created = 0; -#define SETCOLORS(fg,bg) { _settextcolor(fg); _setbkcolor(bg); } +#define SET_FG_COLOR(fg) _settextcolor(fg) +#define SET_BG_COLOR(bg) _setbkcolor(bg) +#define SETCOLORS(fg,bg) { SET_FG_COLOR(fg); SET_BG_COLOR(bg); } #endif #if MSDOS_COMPILER==BORLANDC @@ -106,7 +121,9 @@ static int flash_created = 0; #define _settextposition(y,x) gotoxy(x,y) #define _clearscreen(m) clrscr() #define _outtext(s) cputs(s) -#define SETCOLORS(fg,bg) { textcolor(fg); textbackground(bg); } +#define SET_FG_COLOR(fg) textcolor(fg) +#define SET_BG_COLOR(bg) textbackground(bg) +#define SETCOLORS(fg,bg) { SET_FG_COLOR(fg); SET_BG_COLOR(bg); } extern int sc_height; #endif @@ -138,28 +155,31 @@ static void win32_deinit_term(); #define FG_COLORS (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY) #define BG_COLORS (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY) -#define MAKEATTR(fg,bg) ((WORD)((fg)|((bg)<<4))) -#define SETCOLORS(fg,bg) { curr_attr = MAKEATTR(fg,bg); \ - if (SetConsoleTextAttribute(con_out, curr_attr) == 0) \ - error("SETCOLORS failed", NULL_PARG); } +#define MAKEATTR(fg,bg) ((WORD)((fg)|((bg)<<4))) +#define APPLY_COLORS() { if (SetConsoleTextAttribute(con_out, curr_attr) == 0) \ + error("SETCOLORS failed", NULL_PARG); } +#define SET_FG_COLOR(fg) { curr_attr |= (fg); APPLY_COLORS(); } +#define SET_BG_COLOR(bg) { curr_attr |= ((bg)<<4); APPLY_COLORS(); } +#define SETCOLORS(fg,bg) { curr_attr = MAKEATTR(fg,bg); APPLY_COLORS(); } #endif #if MSDOS_COMPILER -public int nm_fg_color; /* Color of normal text */ +public int nm_fg_color; /* Color of normal text */ public int nm_bg_color; -public int bo_fg_color; /* Color of bold text */ +public int bo_fg_color; /* Color of bold text */ public int bo_bg_color; -public int ul_fg_color; /* Color of underlined text */ +public int ul_fg_color; /* Color of underlined text */ public int ul_bg_color; -public int so_fg_color; /* Color of standout text */ +public int so_fg_color; /* Color of standout text */ public int so_bg_color; -public int bl_fg_color; /* Color of blinking text */ +public int bl_fg_color; /* Color of blinking text */ public int bl_bg_color; -static int sy_fg_color; /* Color of system text (before less) */ +static int sy_fg_color; /* Color of system text (before less) */ static int sy_bg_color; -public int sgr_mode; /* Honor ANSI sequences rather than using above */ +public int sgr_mode; /* Honor ANSI sequences rather than using above */ #if MSDOS_COMPILER==WIN32C -public int have_ul; /* Is underline available? */ +static DWORD init_output_mode; /* The initial console output mode */ +public int vt_enabled = -1; /* Is virtual terminal processing available? */ #endif #else @@ -167,56 +187,61 @@ public int have_ul; /* Is underline available? */ * Strings passed to tputs() to do various terminal functions. */ static char - *sc_pad, /* Pad string */ - *sc_home, /* Cursor home */ - *sc_addline, /* Add line, scroll down following lines */ - *sc_lower_left, /* Cursor to last line, first column */ - *sc_return, /* Cursor to beginning of current line */ - *sc_move, /* General cursor positioning */ - *sc_clear, /* Clear screen */ - *sc_eol_clear, /* Clear to end of line */ - *sc_eos_clear, /* Clear to end of screen */ - *sc_s_in, /* Enter standout (highlighted) mode */ - *sc_s_out, /* Exit standout mode */ - *sc_u_in, /* Enter underline mode */ - *sc_u_out, /* Exit underline mode */ - *sc_b_in, /* Enter bold mode */ - *sc_b_out, /* Exit bold mode */ - *sc_bl_in, /* Enter blink mode */ - *sc_bl_out, /* Exit blink mode */ - *sc_visual_bell, /* Visual bell (flash screen) sequence */ - *sc_backspace, /* Backspace cursor */ - *sc_s_keypad, /* Start keypad mode */ - *sc_e_keypad, /* End keypad mode */ - *sc_s_mousecap, /* Start mouse capture mode */ - *sc_e_mousecap, /* End mouse capture mode */ - *sc_init, /* Startup terminal initialization */ - *sc_deinit; /* Exit terminal de-initialization */ + *sc_pad, /* Pad string */ + *sc_home, /* Cursor home */ + *sc_addline, /* Add line, scroll down following lines */ + *sc_lower_left, /* Cursor to last line, first column */ + *sc_return, /* Cursor to beginning of current line */ + *sc_move, /* General cursor positioning */ + *sc_clear, /* Clear screen */ + *sc_eol_clear, /* Clear to end of line */ + *sc_eos_clear, /* Clear to end of screen */ + *sc_s_in, /* Enter standout (highlighted) mode */ + *sc_s_out, /* Exit standout mode */ + *sc_u_in, /* Enter underline mode */ + *sc_u_out, /* Exit underline mode */ + *sc_b_in, /* Enter bold mode */ + *sc_b_out, /* Exit bold mode */ + *sc_bl_in, /* Enter blink mode */ + *sc_bl_out, /* Exit blink mode */ + *sc_visual_bell, /* Visual bell (flash screen) sequence */ + *sc_backspace, /* Backspace cursor */ + *sc_s_keypad, /* Start keypad mode */ + *sc_e_keypad, /* End keypad mode */ + *sc_s_mousecap, /* Start mouse capture mode */ + *sc_e_mousecap, /* End mouse capture mode */ + *sc_init, /* Startup terminal initialization */ + *sc_deinit; /* Exit terminal de-initialization */ + +static int attrcolor = -1; #endif static int init_done = 0; -public int auto_wrap; /* Terminal does \r\n when write past margin */ -public int ignaw; /* Terminal ignores \n immediately after wrap */ -public int erase_char; /* The user's erase char */ -public int erase2_char; /* The user's other erase char */ -public int kill_char; /* The user's line-kill char */ -public int werase_char; /* The user's word-erase char */ -public int sc_width, sc_height; /* Height & width of screen */ -public int bo_s_width, bo_e_width; /* Printing width of boldface seq */ -public int ul_s_width, ul_e_width; /* Printing width of underline seq */ -public int so_s_width, so_e_width; /* Printing width of standout seq */ -public int bl_s_width, bl_e_width; /* Printing width of blink seq */ -public int above_mem, below_mem; /* Memory retained above/below screen */ -public int can_goto_line; /* Can move cursor to any line */ -public int clear_bg; /* Clear fills with background color */ -public int missing_cap = 0; /* Some capability is missing */ -public char *kent = NULL; /* Keypad ENTER sequence */ +public int auto_wrap; /* Terminal does \r\n when write past margin */ +public int ignaw; /* Terminal ignores \n immediately after wrap */ +public int erase_char; /* The user's erase char */ +public int erase2_char; /* The user's other erase char */ +public int kill_char; /* The user's line-kill char */ +public int werase_char; /* The user's word-erase char */ +public int sc_width, sc_height; /* Height & width of screen */ +public int bo_s_width, bo_e_width; /* Printing width of boldface seq */ +public int ul_s_width, ul_e_width; /* Printing width of underline seq */ +public int so_s_width, so_e_width; /* Printing width of standout seq */ +public int bl_s_width, bl_e_width; /* Printing width of blink seq */ +public int above_mem, below_mem; /* Memory retained above/below screen */ +public int can_goto_line; /* Can move cursor to any line */ +public int clear_bg; /* Clear fills with background color */ +public int missing_cap = 0; /* Some capability is missing */ +public char *kent = NULL; /* Keypad ENTER sequence */ static int attrmode = AT_NORMAL; static int termcap_debug = -1; extern int binattr; extern int one_screen; +#if LESSTEST +extern char *ttyin_name; +#endif /*LESSTEST*/ #if !MSDOS_COMPILER static char *cheaper LESSPARAMS((char *t1, char *t2, char *def)); @@ -229,15 +254,15 @@ static void tmodes LESSPARAMS((char *incap, char *outcap, char **instr, * and needed by, the termcap library. */ #if MUST_DEFINE_OSPEED -extern short ospeed; /* Terminal output baud rate */ -extern char PC; /* Pad character */ +extern short ospeed; /* Terminal output baud rate */ +extern char PC; /* Pad character */ #endif #ifdef _OSK short ospeed; char PC_, *UP, *BC; #endif -extern int quiet; /* If VERY_QUIET, use visual bell for bell */ +extern int quiet; /* If VERY_QUIET, use visual bell for bell */ extern int no_back_scroll; extern int swindow; extern int no_init; @@ -249,6 +274,8 @@ extern int top_scroll; extern int quit_if_one_screen; extern int oldbot; extern int mousecap; +extern int is_tty; +extern int use_color; #if HILITE_SEARCH extern int hilite_search; #endif @@ -270,12 +297,12 @@ extern char *tgoto(); /* * Change terminal to "raw mode", or restore to "normal" mode. * "Raw mode" means - * 1. An outstanding read will complete on receipt of a single keystroke. - * 2. Input is not echoed. - * 3. On output, \n is mapped to \r\n. - * 4. \t is NOT expanded into spaces. - * 5. Signal-causing characters such as ctrl-C (interrupt), - * etc. are NOT disabled. + * 1. An outstanding read will complete on receipt of a single keystroke. + * 2. Input is not echoed. + * 3. On output, \n is mapped to \r\n. + * 4. \t is NOT expanded into spaces. + * 5. Signal-causing characters such as ctrl-C (interrupt), + * etc. are NOT disabled. * It doesn't matter whether an input \n is mapped to \r, or vice versa. */ public void @@ -285,7 +312,7 @@ raw_mode(on) static int curr_on = 0; if (on == curr_on) - return; + return; erase2_char = '\b'; /* in case OS doesn't know about erase2 */ #if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS { @@ -723,11 +750,11 @@ scrsize(VOID_PARAM) int n; #endif -#define DEF_SC_WIDTH 80 +#define DEF_SC_WIDTH 80 #if MSDOS_COMPILER -#define DEF_SC_HEIGHT 25 +#define DEF_SC_HEIGHT 25 #else -#define DEF_SC_HEIGHT 24 +#define DEF_SC_HEIGHT 24 #endif @@ -816,24 +843,24 @@ scrsize(VOID_PARAM) #endif #endif - if (sys_height > 0) - sc_height = sys_height; - else if ((s = lgetenv("LINES")) != NULL) + if ((s = lgetenv("LINES")) != NULL) sc_height = atoi(s); + else if (sys_height > 0) + sc_height = sys_height; #if !MSDOS_COMPILER else if ((n = ltgetnum("li")) > 0) - sc_height = n; + sc_height = n; #endif if (sc_height <= 0) sc_height = DEF_SC_HEIGHT; - if (sys_width > 0) - sc_width = sys_width; - else if ((s = lgetenv("COLUMNS")) != NULL) + if ((s = lgetenv("COLUMNS")) != NULL) sc_width = atoi(s); + else if (sys_width > 0) + sc_width = sys_width; #if !MSDOS_COMPILER else if ((n = ltgetnum("co")) > 0) - sc_width = n; + sc_width = n; #endif if (sc_width <= 0) sc_width = DEF_SC_WIDTH; @@ -895,22 +922,22 @@ special_key_str(key) static char tbuf[40]; char *s; #if MSDOS_COMPILER || OS2 - static char k_right[] = { '\340', PCK_RIGHT, 0 }; - static char k_left[] = { '\340', PCK_LEFT, 0 }; - static char k_ctl_right[] = { '\340', PCK_CTL_RIGHT, 0 }; - static char k_ctl_left[] = { '\340', PCK_CTL_LEFT, 0 }; - static char k_insert[] = { '\340', PCK_INSERT, 0 }; - static char k_delete[] = { '\340', PCK_DELETE, 0 }; - static char k_ctl_delete[] = { '\340', PCK_CTL_DELETE, 0 }; - static char k_ctl_backspace[] = { '\177', 0 }; - static char k_home[] = { '\340', PCK_HOME, 0 }; - static char k_end[] = { '\340', PCK_END, 0 }; - static char k_up[] = { '\340', PCK_UP, 0 }; - static char k_down[] = { '\340', PCK_DOWN, 0 }; - static char k_backtab[] = { '\340', PCK_SHIFT_TAB, 0 }; - static char k_pagedown[] = { '\340', PCK_PAGEDOWN, 0 }; - static char k_pageup[] = { '\340', PCK_PAGEUP, 0 }; - static char k_f1[] = { '\340', PCK_F1, 0 }; + static char k_right[] = { '\340', PCK_RIGHT, 0 }; + static char k_left[] = { '\340', PCK_LEFT, 0 }; + static char k_ctl_right[] = { '\340', PCK_CTL_RIGHT, 0 }; + static char k_ctl_left[] = { '\340', PCK_CTL_LEFT, 0 }; + static char k_insert[] = { '\340', PCK_INSERT, 0 }; + static char k_delete[] = { '\340', PCK_DELETE, 0 }; + static char k_ctl_delete[] = { '\340', PCK_CTL_DELETE, 0 }; + static char k_ctl_backspace[] = { '\177', 0 }; + static char k_home[] = { '\340', PCK_HOME, 0 }; + static char k_end[] = { '\340', PCK_END, 0 }; + static char k_up[] = { '\340', PCK_UP, 0 }; + static char k_down[] = { '\340', PCK_DOWN, 0 }; + static char k_backtab[] = { '\340', PCK_SHIFT_TAB, 0 }; + static char k_pagedown[] = { '\340', PCK_PAGEDOWN, 0 }; + static char k_pageup[] = { '\340', PCK_PAGEUP, 0 }; + static char k_f1[] = { '\340', PCK_F1, 0 }; #endif #if !MSDOS_COMPILER char *sp = tbuf; @@ -951,9 +978,9 @@ special_key_str(key) s = windowid ? ltgetstr("kD", &sp) : k_delete; if (s == NULL) { - tbuf[0] = '\177'; - tbuf[1] = '\0'; - s = tbuf; + tbuf[0] = '\177'; + tbuf[1] = '\0'; + s = tbuf; } break; #endif @@ -1037,9 +1064,9 @@ special_key_str(key) s = ltgetstr("kD", &sp); if (s == NULL) { - tbuf[0] = '\177'; - tbuf[1] = '\0'; - s = tbuf; + tbuf[0] = '\177'; + tbuf[1] = '\0'; + s = tbuf; } break; #endif @@ -1093,6 +1120,7 @@ get_term(VOID_PARAM) * before any file operations have been done on fd0. */ SET_BINARY(0); + GetConsoleMode(con_out, &init_output_mode); GetConsoleScreenBufferInfo(con_out, &scr); curr_attr = scr.wAttributes; sy_bg_color = (curr_attr & BG_COLORS) >> 4; /* normalize */ @@ -1497,6 +1525,34 @@ initcolor(VOID_PARAM) #if MSDOS_COMPILER==WIN32C +/* + * Enable virtual terminal processing, if available. + */ + static void +win32_init_vt_term(VOID_PARAM) +{ + DWORD output_mode; + + if (vt_enabled == 0 || (vt_enabled == 1 && con_out == con_out_ours)) + return; + + GetConsoleMode(con_out, &output_mode); + vt_enabled = SetConsoleMode(con_out, + output_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); + if (vt_enabled) + { + auto_wrap = 0; + ignaw = 1; + } +} + + static void +win32_deinit_vt_term(VOID_PARAM) +{ + if (vt_enabled == 1 && con_out == con_out_save) + SetConsoleMode(con_out, init_output_mode); +} + /* * Termcap-like init with a private win32 console. */ @@ -1513,8 +1569,6 @@ win32_init_term(VOID_PARAM) if (con_out_ours == INVALID_HANDLE_VALUE) { - DWORD output_mode; - /* * Create our own screen buffer, so that we * may restore the original when done. @@ -1525,12 +1579,6 @@ win32_init_term(VOID_PARAM) (LPSECURITY_ATTRIBUTES) NULL, CONSOLE_TEXTMODE_BUFFER, (LPVOID) NULL); - /* - * Enable underline, if available. - */ - GetConsoleMode(con_out_ours, &output_mode); - have_ul = SetConsoleMode(con_out_ours, - output_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); } size.X = scr.srWindow.Right - scr.srWindow.Left + 1; @@ -1556,6 +1604,68 @@ win32_deinit_term(VOID_PARAM) #endif +#if !MSDOS_COMPILER + static void +do_tputs(str, affcnt, f_putc) + char *str; + int affcnt; + int (*f_putc)(int); +{ +#if LESSTEST + if (ttyin_name != NULL) + putstr(str); + else +#endif /*LESSTEST*/ + tputs(str, affcnt, f_putc); +} + +/* + * Like tputs but we handle $<...> delay strings here because + * some implementations of tputs don't perform delays correctly. + */ + static void +ltputs(str, affcnt, f_putc) + char *str; + int affcnt; + int (*f_putc)(int); +{ + while (str != NULL && *str != '\0') + { +#if HAVE_STRSTR + char *obrac = strstr(str, "$<"); + if (obrac != NULL) + { + char str2[64]; + int slen = obrac - str; + if (slen < sizeof(str2)) + { + int delay; + /* Output first part of string (before "$<"). */ + memcpy(str2, str, slen); + str2[slen] = '\0'; + do_tputs(str2, affcnt, f_putc); + str += slen + 2; + /* Perform the delay. */ + delay = lstrtoi(str, &str); + if (*str == '*') + delay *= affcnt; + flush(); + sleep_ms(delay); + /* Skip past closing ">" at end of delay string. */ + str = strstr(str, ">"); + if (str != NULL) + str++; + continue; + } + } +#endif + /* Pass the rest of the string to tputs and we're done. */ + do_tputs(str, affcnt, f_putc); + break; + } +} +#endif /* MSDOS_COMPILER */ + /* * Configure the termimal so mouse clicks and wheel moves * produce input to less. @@ -1563,10 +1673,8 @@ win32_deinit_term(VOID_PARAM) public void init_mouse(VOID_PARAM) { - if (!mousecap) - return; #if !MSDOS_COMPILER - tputs(sc_s_mousecap, sc_height, putchr); + ltputs(sc_s_mousecap, sc_height, putchr); #else #if MSDOS_COMPILER==WIN32C SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT @@ -1583,10 +1691,8 @@ init_mouse(VOID_PARAM) public void deinit_mouse(VOID_PARAM) { - if (!mousecap) - return; #if !MSDOS_COMPILER - tputs(sc_e_mousecap, sc_height, putchr); + ltputs(sc_e_mousecap, sc_height, putchr); #else #if MSDOS_COMPILER==WIN32C SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_EXTENDED_FLAGS @@ -1605,11 +1711,13 @@ init(VOID_PARAM) if (!(quit_if_one_screen && one_screen)) { if (!no_init) - tputs(sc_init, sc_height, putchr); + ltputs(sc_init, sc_height, putchr); if (!no_keypad) - tputs(sc_s_keypad, sc_height, putchr); - init_mouse(); + ltputs(sc_s_keypad, sc_height, putchr); + if (mousecap) + init_mouse(); } + init_done = 1; if (top_scroll) { int i; @@ -1630,14 +1738,16 @@ init(VOID_PARAM) { if (!no_init) win32_init_term(); - init_mouse(); + if (mousecap) + init_mouse(); } + win32_init_vt_term(); #endif + init_done = 1; initcolor(); flush(); #endif - init_done = 1; } /* @@ -1651,19 +1761,22 @@ deinit(VOID_PARAM) #if !MSDOS_COMPILER if (!(quit_if_one_screen && one_screen)) { - deinit_mouse(); + if (mousecap) + deinit_mouse(); if (!no_keypad) - tputs(sc_e_keypad, sc_height, putchr); + ltputs(sc_e_keypad, sc_height, putchr); if (!no_init) - tputs(sc_deinit, sc_height, putchr); + ltputs(sc_deinit, sc_height, putchr); } #else /* Restore system colors. */ SETCOLORS(sy_fg_color, sy_bg_color); #if MSDOS_COMPILER==WIN32C + win32_deinit_vt_term(); if (!(quit_if_one_screen && one_screen)) { - deinit_mouse(); + if (mousecap) + deinit_mouse(); if (!no_init) win32_deinit_term(); } @@ -1675,14 +1788,31 @@ deinit(VOID_PARAM) init_done = 0; } +/* + * Are we interactive (ie. writing to an initialized tty)? + */ + public int +interactive(VOID_PARAM) +{ + return (is_tty && init_done); +} + + static void +assert_interactive(VOID_PARAM) +{ + if (interactive()) return; + /* abort(); */ +} + /* * Home cursor (move to upper left corner of screen). */ public void home(VOID_PARAM) { + assert_interactive(); #if !MSDOS_COMPILER - tputs(sc_home, 1, putchr); + ltputs(sc_home, 1, putchr); #else flush(); _settextposition(1,1); @@ -1696,8 +1826,9 @@ home(VOID_PARAM) public void add_line(VOID_PARAM) { + assert_interactive(); #if !MSDOS_COMPILER - tputs(sc_addline, sc_height, putchr); + ltputs(sc_addline, sc_height, putchr); #else flush(); #if MSDOS_COMPILER==MSOFTC @@ -1905,10 +2036,9 @@ win32_scroll_up(n) public void lower_left(VOID_PARAM) { - if (!init_done) - return; + assert_interactive(); #if !MSDOS_COMPILER - tputs(sc_lower_left, 1, putchr); + ltputs(sc_lower_left, 1, putchr); #else flush(); _settextposition(sc_height, 1); @@ -1921,28 +2051,31 @@ lower_left(VOID_PARAM) public void line_left(VOID_PARAM) { + assert_interactive(); #if !MSDOS_COMPILER - tputs(sc_return, 1, putchr); + ltputs(sc_return, 1, putchr); #else - int row; - flush(); -#if MSDOS_COMPILER==WIN32C { - CONSOLE_SCREEN_BUFFER_INFO scr; - GetConsoleScreenBufferInfo(con_out, &scr); - row = scr.dwCursorPosition.Y - scr.srWindow.Top + 1; - } + int row; + flush(); +#if MSDOS_COMPILER==WIN32C + { + CONSOLE_SCREEN_BUFFER_INFO scr; + GetConsoleScreenBufferInfo(con_out, &scr); + row = scr.dwCursorPosition.Y - scr.srWindow.Top + 1; + } #else #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - row = wherey(); + row = wherey(); #else - { - struct rccoord tpos = _gettextposition(); - row = tpos.row; - } + { + struct rccoord tpos = _gettextposition(); + row = tpos.row; + } #endif #endif - _settextposition(row, 1); + _settextposition(row, 1); + } #endif } @@ -1984,8 +2117,9 @@ check_winch(VOID_PARAM) goto_line(sindex) int sindex; { + assert_interactive(); #if !MSDOS_COMPILER - tputs(tgoto(sc_move, 0, sindex), 1, putchr); + ltputs(tgoto(sc_move, 0, sindex), 1, putchr); #else flush(); _settextposition(sindex+1, 1); @@ -2052,7 +2186,7 @@ vbell(VOID_PARAM) #if !MSDOS_COMPILER if (*sc_visual_bell == '\0') return; - tputs(sc_visual_bell, sc_height, putchr); + ltputs(sc_visual_bell, sc_height, putchr); #else #if MSDOS_COMPILER==DJGPPC ScreenVisualBell(); @@ -2142,8 +2276,9 @@ bell(VOID_PARAM) public void clear(VOID_PARAM) { + assert_interactive(); #if !MSDOS_COMPILER - tputs(sc_clear, sc_height, putchr); + ltputs(sc_clear, sc_height, putchr); #else flush(); #if MSDOS_COMPILER==WIN32C @@ -2161,8 +2296,9 @@ clear(VOID_PARAM) public void clear_eol(VOID_PARAM) { + /* assert_interactive();*/ #if !MSDOS_COMPILER - tputs(sc_eol_clear, 1, putchr); + ltputs(sc_eol_clear, 1, putchr); #else #if MSDOS_COMPILER==MSOFTC short top, left; @@ -2220,13 +2356,14 @@ clear_eol(VOID_PARAM) static void clear_eol_bot(VOID_PARAM) { + assert_interactive(); #if MSDOS_COMPILER clear_eol(); #else if (below_mem) - tputs(sc_eos_clear, 1, putchr); + ltputs(sc_eos_clear, 1, putchr); else - tputs(sc_eol_clear, 1, putchr); + ltputs(sc_eol_clear, 1, putchr); #endif } @@ -2259,42 +2396,305 @@ clear_bot(VOID_PARAM) } } +/* + * Color string may be "x[y]" where x and y are 4-bit color chars, + * or "N[.M]" where N and M are decimal integers> + * Any of x,y,N,M may also be "-" to mean "unchanged". + */ + +/* + * Parse a 4-bit color char. + */ + static int +parse_color4(ch) + char ch; +{ + switch (ch) + { + case 'k': return 0; + case 'r': return CV_RED; + case 'g': return CV_GREEN; + case 'y': return CV_RED|CV_GREEN; + case 'b': return CV_BLUE; + case 'm': return CV_RED|CV_BLUE; + case 'c': return CV_GREEN|CV_BLUE; + case 'w': return CV_RED|CV_GREEN|CV_BLUE; + case 'K': return 0|CV_BRIGHT; + case 'R': return CV_RED|CV_BRIGHT; + case 'G': return CV_GREEN|CV_BRIGHT; + case 'Y': return CV_RED|CV_GREEN|CV_BRIGHT; + case 'B': return CV_BLUE|CV_BRIGHT; + case 'M': return CV_RED|CV_BLUE|CV_BRIGHT; + case 'C': return CV_GREEN|CV_BLUE|CV_BRIGHT; + case 'W': return CV_RED|CV_GREEN|CV_BLUE|CV_BRIGHT; + case '-': return CV_NOCHANGE; + default: return CV_ERROR; + } +} + +/* + * Parse a color as a decimal integer. + */ + static int +parse_color6(ps) + char **ps; +{ + if (**ps == '-') + { + (*ps)++; + return CV_NOCHANGE; + } else + { + char *ops = *ps; + int color = lstrtoi(ops, ps); + if (*ps == ops) + return CV_ERROR; + return color; + } +} + +/* + * Parse a color pair and return the foreground/background values. + * Return type of color specifier: + * CV_4BIT: fg/bg values are OR of CV_{RGB} bits. + * CV_6BIT: fg/bg values are integers entered by user. + */ + public COLOR_TYPE +parse_color(str, p_fg, p_bg) + char *str; + int *p_fg; + int *p_bg; +{ + int fg; + int bg; + COLOR_TYPE type = CT_NULL; + + if (str == NULL || *str == '\0') + return CT_NULL; + if (*str == '+') + str++; /* ignore leading + */ + + fg = parse_color4(str[0]); + bg = parse_color4((strlen(str) < 2) ? '-' : str[1]); + if (fg != CV_ERROR && bg != CV_ERROR) + type = CT_4BIT; + else + { + fg = parse_color6(&str); + bg = (fg != CV_ERROR && *str++ == '.') ? parse_color6(&str) : CV_NOCHANGE; + if (fg != CV_ERROR && bg != CV_ERROR) + type = CT_6BIT; + } + if (p_fg != NULL) *p_fg = fg; + if (p_bg != NULL) *p_bg = bg; + return type; +} + +#if !MSDOS_COMPILER + + static int +sgr_color(color) + int color; +{ + switch (color) + { + case 0: return 30; + case CV_RED: return 31; + case CV_GREEN: return 32; + case CV_RED|CV_GREEN: return 33; + case CV_BLUE: return 34; + case CV_RED|CV_BLUE: return 35; + case CV_GREEN|CV_BLUE: return 36; + case CV_RED|CV_GREEN|CV_BLUE: return 37; + + case CV_BRIGHT: return 90; + case CV_RED|CV_BRIGHT: return 91; + case CV_GREEN|CV_BRIGHT: return 92; + case CV_RED|CV_GREEN|CV_BRIGHT: return 93; + case CV_BLUE|CV_BRIGHT: return 94; + case CV_RED|CV_BLUE|CV_BRIGHT: return 95; + case CV_GREEN|CV_BLUE|CV_BRIGHT: return 96; + case CV_RED|CV_GREEN|CV_BLUE|CV_BRIGHT: return 97; + + default: return color; + } +} + + static void +tput_fmt(fmt, color, f_putc) + char *fmt; + int color; + int (*f_putc)(int); +{ + char buf[16]; + if (color == attrcolor) + return; + SNPRINTF1(buf, sizeof(buf), fmt, color); + ltputs(buf, 1, f_putc); + attrcolor = color; +} + + static void +tput_color(str, f_putc) + char *str; + int (*f_putc)(int); +{ + int fg; + int bg; + + if (str != NULL && strcmp(str, "*") == 0) + { + /* Special case: reset to normal */ + tput_fmt(ESCS"[m", -1, f_putc); + return; + } + switch (parse_color(str, &fg, &bg)) + { + case CT_4BIT: + if (fg >= 0) + tput_fmt(ESCS"[%dm", sgr_color(fg), f_putc); + if (bg >= 0) + tput_fmt(ESCS"[%dm", sgr_color(bg)+10, f_putc); + break; + case CT_6BIT: + if (fg >= 0) + tput_fmt(ESCS"[38;5;%dm", fg, f_putc); + if (bg >= 0) + tput_fmt(ESCS"[48;5;%dm", bg, f_putc); + break; + default: + break; + } +} + + static void +tput_inmode(mode_str, attr, attr_bit, f_putc) + char *mode_str; + int attr; + int attr_bit; + int (*f_putc)(int); +{ + char *color_str; + if ((attr & attr_bit) == 0) + return; + color_str = get_color_map(attr_bit); + if (color_str == NULL || *color_str == '\0' || *color_str == '+') + { + ltputs(mode_str, 1, f_putc); + if (color_str == NULL || *color_str++ != '+') + return; + } + /* Color overrides mode string */ + tput_color(color_str, f_putc); +} + + static void +tput_outmode(mode_str, attr_bit, f_putc) + char *mode_str; + int attr_bit; + int (*f_putc)(int); +{ + if ((attrmode & attr_bit) == 0) + return; + ltputs(mode_str, 1, f_putc); +} + +#else /* MSDOS_COMPILER */ + +#if MSDOS_COMPILER==WIN32C + static int +WIN32put_fmt(fmt, color) + char *fmt; + int color; +{ + char buf[16]; + int len = SNPRINTF1(buf, sizeof(buf), fmt, color); + WIN32textout(buf, len); + return TRUE; +} +#endif + + static int +win_set_color(attr) + int attr; +{ + int fg; + int bg; + int out = FALSE; + char *str = get_color_map(attr); + if (str == NULL || str[0] == '\0') + return FALSE; + switch (parse_color(str, &fg, &bg)) + { + case CT_4BIT: + if (fg >= 0 && bg >= 0) + { + SETCOLORS(fg, bg); + out = TRUE; + } else if (fg >= 0) + { + SET_FG_COLOR(fg); + out = TRUE; + } else if (bg >= 0) + { + SET_BG_COLOR(bg); + out = TRUE; + } + break; +#if MSDOS_COMPILER==WIN32C + case CT_6BIT: + if (vt_enabled) + { + if (fg > 0) + out = WIN32put_fmt(ESCS"[38;5;%dm", fg); + if (bg > 0) + out = WIN32put_fmt(ESCS"[48;5;%dm", bg); + } + break; +#endif + default: + break; + } + return out; +} + +#endif /* MSDOS_COMPILER */ + public void at_enter(attr) int attr; { attr = apply_at_specials(attr); - #if !MSDOS_COMPILER /* The one with the most priority is last. */ - if (attr & AT_UNDERLINE) - tputs(sc_u_in, 1, putchr); - if (attr & AT_BOLD) - tputs(sc_b_in, 1, putchr); - if (attr & AT_BLINK) - tputs(sc_bl_in, 1, putchr); - if (attr & AT_STANDOUT) - tputs(sc_s_in, 1, putchr); + tput_inmode(sc_u_in, attr, AT_UNDERLINE, putchr); + tput_inmode(sc_b_in, attr, AT_BOLD, putchr); + tput_inmode(sc_bl_in, attr, AT_BLINK, putchr); + /* Don't use standout and color at the same time. */ + if (use_color && (attr & AT_COLOR)) + tput_color(get_color_map(attr), putchr); + else + tput_inmode(sc_s_in, attr, AT_STANDOUT, putchr); #else flush(); /* The one with the most priority is first. */ - if (attr & AT_STANDOUT) + if ((attr & AT_COLOR) && use_color) + { + win_set_color(attr); + } else if (attr & AT_STANDOUT) { SETCOLORS(so_fg_color, so_bg_color); } else if (attr & AT_BLINK) { SETCOLORS(bl_fg_color, bl_bg_color); - } - else if (attr & AT_BOLD) + } else if (attr & AT_BOLD) { SETCOLORS(bo_fg_color, bo_bg_color); - } - else if (attr & AT_UNDERLINE) + } else if (attr & AT_UNDERLINE) { SETCOLORS(ul_fg_color, ul_bg_color); } #endif - attrmode = attr; } @@ -2303,19 +2703,15 @@ at_exit(VOID_PARAM) { #if !MSDOS_COMPILER /* Undo things in the reverse order we did them. */ - if (attrmode & AT_STANDOUT) - tputs(sc_s_out, 1, putchr); - if (attrmode & AT_BLINK) - tputs(sc_bl_out, 1, putchr); - if (attrmode & AT_BOLD) - tputs(sc_b_out, 1, putchr); - if (attrmode & AT_UNDERLINE) - tputs(sc_u_out, 1, putchr); + tput_color("*", putchr); + tput_outmode(sc_s_out, AT_STANDOUT, putchr); + tput_outmode(sc_bl_out, AT_BLINK, putchr); + tput_outmode(sc_b_out, AT_BOLD, putchr); + tput_outmode(sc_u_out, AT_UNDERLINE, putchr); #else flush(); SETCOLORS(nm_fg_color, nm_bg_color); #endif - attrmode = AT_NORMAL; } @@ -2357,57 +2753,6 @@ apply_at_specials(attr) return attr; } -#if 0 /* No longer used */ -/* - * Erase the character to the left of the cursor - * and move the cursor left. - */ - public void -backspace(VOID_PARAM) -{ -#if !MSDOS_COMPILER - /* - * Erase the previous character by overstriking with a space. - */ - tputs(sc_backspace, 1, putchr); - putchr(' '); - tputs(sc_backspace, 1, putchr); -#else -#if MSDOS_COMPILER==MSOFTC - struct rccoord tpos; - - flush(); - tpos = _gettextposition(); - if (tpos.col <= 1) - return; - _settextposition(tpos.row, tpos.col-1); - _outtext(" "); - _settextposition(tpos.row, tpos.col-1); -#else -#if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - cputs("\b"); -#else -#if MSDOS_COMPILER==WIN32C - COORD cpos; - DWORD cChars; - CONSOLE_SCREEN_BUFFER_INFO scr; - - flush(); - GetConsoleScreenBufferInfo(con_out, &scr); - cpos = scr.dwCursorPosition; - if (cpos.X <= 0) - return; - cpos.X--; - SetConsoleCursorPosition(con_out, cpos); - FillConsoleOutputCharacter(con_out, (TCHAR)' ', 1, cpos, &cChars); - SetConsoleCursorPosition(con_out, cpos); -#endif -#endif -#endif -#endif -} -#endif /* 0 */ - /* * Output a plain backspace, without erasing the previous char. */ @@ -2419,7 +2764,7 @@ putbs(VOID_PARAM) else { #if !MSDOS_COMPILER - tputs(sc_backspace, 1, putchr); + ltputs(sc_backspace, 1, putchr); #else int row, col; @@ -2638,3 +2983,4 @@ WIN32textout(text, len) #endif } #endif + diff --git a/scrsize.c b/scrsize.c index 2063aa3..ee07cb8 100644 --- a/scrsize.c +++ b/scrsize.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. diff --git a/search.c b/search.c index 7650ab3..f619fbe 100644 --- a/search.c +++ b/search.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -16,8 +16,8 @@ #include "position.h" #include "charset.h" -#define MINPOS(a,b) (((a) < (b)) ? (a) : (b)) -#define MAXPOS(a,b) (((a) > (b)) ? (a) : (b)) +#define MINPOS(a,b) (((a) < (b)) ? (a) : (b)) +#define MAXPOS(a,b) (((a) > (b)) ? (a) : (b)) extern int sigs; extern int how_search; @@ -33,6 +33,10 @@ extern POSITION start_attnpos; extern POSITION end_attnpos; extern int utf_mode; extern int screen_trashed; +extern int sc_width; +extern int sc_height; +extern int chopline; +extern int hshift; #if HILITE_SEARCH extern int hilite_search; extern int size_linebuf; @@ -41,8 +45,7 @@ extern int can_goto_line; static int hide_hilite; static POSITION prep_startpos; static POSITION prep_endpos; -static int is_caseless; -static int is_ucase_pattern; +extern POSITION xxpos; /* * Structures for maintaining a set of ranges for hilites and filtered-out @@ -94,6 +97,7 @@ struct hilite_tree static struct hilite_tree hilite_anchor = HILITE_INITIALIZER(); static struct hilite_tree filter_anchor = HILITE_INITIALIZER(); +static struct pattern_info *filter_infos = NULL; #endif @@ -105,6 +109,7 @@ struct pattern_info { PATTERN_TYPE compiled; char* text; int search_type; + struct pattern_info *next; }; #if NO_REGEX @@ -114,7 +119,8 @@ struct pattern_info { #endif static struct pattern_info search_info; -static struct pattern_info filter_info; +static int is_ucase_pattern; +static int is_caseless; /* * Are there any uppercase letters in this string? @@ -135,19 +141,35 @@ is_ucase(str) return (0); } +/* + * Discard a saved pattern. + */ + static void +clear_pattern(info) + struct pattern_info *info; +{ + if (info->text != NULL) + free(info->text); + info->text = NULL; +#if !NO_REGEX + uncompile_pattern(&info->compiled); +#endif +} + /* * Compile and save a search pattern. */ static int -set_pattern(info, pattern, search_type) +set_pattern(info, pattern, search_type, show_error) struct pattern_info *info; char *pattern; int search_type; + int show_error; { #if !NO_REGEX if (pattern == NULL) - CLEAR_PATTERN(info->compiled); - else if (compile_pattern(pattern, search_type, &info->compiled) < 0) + SET_NULL_PATTERN(info->compiled); + else if (compile_pattern(pattern, search_type, show_error, &info->compiled) < 0) return -1; #endif /* Pattern compiled successfully; save the text too. */ @@ -173,21 +195,6 @@ set_pattern(info, pattern, search_type) return 0; } -/* - * Discard a saved pattern. - */ - static void -clear_pattern(info) - struct pattern_info *info; -{ - if (info->text != NULL) - free(info->text); - info->text = NULL; -#if !NO_REGEX - uncompile_pattern(&info->compiled); -#endif -} - /* * Initialize saved pattern to nothing. */ @@ -195,9 +202,10 @@ clear_pattern(info) init_pattern(info) struct pattern_info *info; { - CLEAR_PATTERN(info->compiled); + SET_NULL_PATTERN(info->compiled); info->text = NULL; info->search_type = 0; + info->next = NULL; } /* @@ -207,7 +215,6 @@ init_pattern(info) init_search(VOID_PARAM) { init_pattern(&search_info); - init_pattern(&filter_info); } /* @@ -217,18 +224,13 @@ init_search(VOID_PARAM) get_cvt_ops(VOID_PARAM) { int ops = 0; - if (is_caseless || bs_mode == BS_SPECIAL) - { - if (is_caseless) - ops |= CVT_TO_LC; - if (bs_mode == BS_SPECIAL) - ops |= CVT_BS; - if (bs_mode != BS_CONTROL) - ops |= CVT_CRLF; - } else if (bs_mode != BS_CONTROL) - { + + if (is_caseless) + ops |= CVT_TO_LC; + if (bs_mode == BS_SPECIAL) + ops |= CVT_BS; + if (bs_mode != BS_CONTROL) ops |= CVT_CRLF; - } if (ctldisp == OPT_ONPLUS) ops |= CVT_ANSI; return (ops); @@ -292,6 +294,7 @@ repaint_hilite(on) lower_left(); hide_hilite = save_hide_hilite; } +#endif /* * Clear the attn hilite. @@ -299,6 +302,7 @@ repaint_hilite(on) public void clear_attn(VOID_PARAM) { +#if HILITE_SEARCH int sindex; POSITION old_start_attnpos; POSITION old_end_attnpos; @@ -337,27 +341,30 @@ clear_attn(VOID_PARAM) } if (moved) lower_left(); -} #endif +} /* - * Hide search string highlighting. + * Toggle or clear search string highlighting. */ public void -undo_search(VOID_PARAM) +undo_search(clear) + int clear; { - if (!prev_pattern(&search_info)) + clear_pattern(&search_info); +#if HILITE_SEARCH + if (clear) + { + clr_hilite(); + } else { if (hilite_anchor.first == NULL) { error("No previous regular expression", NULL_PARG); return; } - clr_hilite(); /* Next time, hilite_anchor.first will be NULL. */ + hide_hilite = !hide_hilite; } - clear_pattern(&search_info); -#if HILITE_SEARCH - hide_hilite = !hide_hilite; repaint_hilite(1); #endif } @@ -601,7 +608,7 @@ prev_unfiltered(pos) * If nohide is nonzero, don't consider hide_hilite. */ public int -is_hilited(pos, epos, nohide, p_matches) +is_hilited_attr(pos, epos, nohide, p_matches) POSITION pos; POSITION epos; int nohide; @@ -614,12 +621,12 @@ is_hilited(pos, epos, nohide, p_matches) if (!status_col && start_attnpos != NULL_POSITION && - pos < end_attnpos && - (epos == NULL_POSITION || epos > start_attnpos)) + pos <= end_attnpos && + (epos == NULL_POSITION || epos >= start_attnpos)) /* * The attn line overlaps this range. */ - return (1); + return (AT_HILITE|AT_COLOR_ATTN); match = is_hilited_range(pos, epos); if (!match) @@ -631,7 +638,7 @@ is_hilited(pos, epos, nohide, p_matches) * hilite in status column. In this case we want to return * hilite status even if hiliting is disabled or hidden. */ - return (1); + return (AT_HILITE|AT_COLOR_SEARCH); /* * Report matches, even if we're hiding highlights. @@ -650,7 +657,7 @@ is_hilited(pos, epos, nohide, p_matches) */ return (0); - return (1); + return (AT_HILITE|AT_COLOR_SEARCH); } /* @@ -1155,11 +1162,92 @@ search_pos(search_type) return (pos); } +/* + * Check to see if the line matches the filter pattern. + * If so, add an entry to the filter list. + */ +#if HILITE_SEARCH + static int +matches_filters(pos, cline, line_len, chpos, linepos, sp, ep) + POSITION pos; + char *cline; + int line_len; + int *chpos; + POSITION linepos; + char **sp; + char **ep; +{ + struct pattern_info *filter; + + for (filter = filter_infos; filter != NULL; filter = filter->next) + { + int line_filter = match_pattern(info_compiled(filter), filter->text, + cline, line_len, sp, ep, 0, filter->search_type); + if (line_filter) + { + struct hilite hl; + hl.hl_startpos = linepos; + hl.hl_endpos = pos; + add_hilite(&filter_anchor, &hl); + free(cline); + free(chpos); + return (1); + } + } + return (0); +} +#endif + +/* + * Get the position of the first char in the screen line which + * puts tpos on screen. + */ + static POSITION +get_lastlinepos(pos, tpos, sheight) + POSITION pos; + POSITION tpos; + int sheight; +{ + int nlines; + + for (nlines = 0;; nlines++) + { + POSITION npos = forw_line(pos); + if (npos > tpos) + { + if (nlines < sheight) + return NULL_POSITION; + return pos; + } + pos = npos; + } +} + +/* + * Get the segment index of tpos in the line starting at pos. + * A segment is a string of printable chars that fills the screen width. + */ + static int +get_seg(pos, tpos) + POSITION pos; + POSITION tpos; +{ + int seg; + + for (seg = 0;; seg++) + { + POSITION npos = forw_line_seg(pos, TRUE); + if (npos > tpos) + return seg; + pos = npos; + } +} + /* * Search a subset of the file, specified by start/end position. */ static int -search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) +search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, plastlinepos) POSITION pos; POSITION endpos; int search_type; @@ -1167,6 +1255,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) int maxlines; POSITION *plinepos; POSITION *pendpos; + POSITION *plastlinepos; { char *line; char *cline; @@ -1178,9 +1267,14 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) int cvt_len; int *chpos; POSITION linepos, oldpos; + int swidth = sc_width - line_pfx_width(); + int sheight = sc_height - sindex_from_sline(jump_sline); linenum = find_linenum(pos); oldpos = pos; + /* When the search wraps around, end at starting position. */ + if ((search_type & SRCH_WRAP) && endpos == NULL_POSITION) + endpos = pos; for (;;) { /* @@ -1196,7 +1290,9 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) return (-1); } - if ((endpos != NULL_POSITION && pos >= endpos) || maxlines == 0) + if ((endpos != NULL_POSITION && !(search_type & SRCH_WRAP) && + (((search_type & SRCH_FORW) && pos >= endpos) || + ((search_type & SRCH_BACK) && pos <= endpos))) || maxlines == 0) { /* * Reached end position without a match. @@ -1235,6 +1331,35 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) /* * Reached EOF/BOF without a match. */ + if (search_type & SRCH_WRAP) + { + /* + * The search wraps around the current file, so + * try to continue at BOF/EOF. + */ + if (search_type & SRCH_FORW) + { + pos = ch_zero(); + } else + { + pos = ch_length(); + if (pos == NULL_POSITION) + { + (void) ch_end_seek(); + pos = ch_length(); + } + } + if (pos != NULL_POSITION) { + /* + * Wrap-around was successful. Clear + * the flag so we don't wrap again, and + * continue the search at new pos. + */ + search_type &= ~SRCH_WRAP; + linenum = find_linenum(pos); + continue; + } + } if (pendpos != NULL) *pendpos = oldpos; return (matches); @@ -1252,8 +1377,10 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) add_lnum(linenum, pos); oldpos = pos; +#if HILITE_SEARCH if (is_filtered(linepos)) continue; +#endif /* * If it's a caseless search, convert the line to lowercase. @@ -1267,25 +1394,14 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) #if HILITE_SEARCH /* - * Check to see if the line matches the filter pattern. - * If so, add an entry to the filter list. + * If any filters are in effect, ignore non-matching lines. */ - if (((search_type & SRCH_FIND_ALL) || + if (filter_infos != NULL && + ((search_type & SRCH_FIND_ALL) || prep_startpos == NULL_POSITION || - linepos < prep_startpos || linepos >= prep_endpos) && - prev_pattern(&filter_info)) { - int line_filter = match_pattern(info_compiled(&filter_info), filter_info.text, - cline, line_len, &sp, &ep, 0, filter_info.search_type); - if (line_filter) - { - struct hilite hl; - hl.hl_startpos = linepos; - hl.hl_endpos = pos; - add_hilite(&filter_anchor, &hl); - free(cline); - free(chpos); + linepos < prep_startpos || linepos >= prep_endpos)) { + if (matches_filters(pos, cline, line_len, chpos, linepos, &sp, &ep)) continue; - } } #endif @@ -1330,6 +1446,50 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) hilite_line(linepos, cline, line_len, chpos, sp, ep, cvt_ops); } #endif + if (chopline) + { + /* + * If necessary, shift horizontally to make sure + * search match is fully visible. + */ + if (sp != NULL && ep != NULL) + { + int start_off = sp - cline; + int end_off = ep - cline; + int save_hshift = hshift; + int sshift; + int eshift; + hshift = 0; /* make get_seg count screen lines */ + chopline = FALSE; + sshift = swidth * get_seg(linepos, linepos + chpos[start_off]); + eshift = swidth * get_seg(linepos, linepos + chpos[end_off]); + chopline = TRUE; + if (sshift >= save_hshift && eshift <= save_hshift) + { + hshift = save_hshift; + } else + { + hshift = sshift; + screen_trashed = 1; + } + } + } else if (plastlinepos != NULL) + { + /* + * If the line is so long that the highlighted match + * won't be seen when the line is displayed normally + * (starting at the first char) because it fills the whole + * screen and more, scroll forward until the last char + * of the match appears in the last line on the screen. + * lastlinepos is the position of the first char of that last line. + */ + if (ep != NULL) + { + int end_off = ep - cline; + if (end_off >= swidth * sheight / 4) /* heuristic */ + *plastlinepos = get_lastlinepos(linepos, linepos + chpos[end_off], sheight); + } + } free(cline); free(chpos); if (plinepos != NULL) @@ -1358,8 +1518,8 @@ hist_pattern(search_type) if (pattern == NULL) return (0); - if (set_pattern(&search_info, pattern, search_type) < 0) - return (0); + if (set_pattern(&search_info, pattern, search_type, 1) < 0) + return (-1); #if HILITE_SEARCH if (hilite_search == OPT_ONPLUS && !hide_hilite) @@ -1392,7 +1552,7 @@ chg_caseless(VOID_PARAM) * Regenerate the pattern using the new state. */ clear_pattern(&search_info); - hist_pattern(search_info.search_type); + (void) hist_pattern(search_info.search_type); } } @@ -1412,6 +1572,8 @@ search(search_type, pattern, n) int n; { POSITION pos; + POSITION opos; + POSITION lastlinepos = NULL_POSITION; if (pattern == NULL || *pattern == '\0') { @@ -1419,10 +1581,13 @@ search(search_type, pattern, n) * A null pattern means use the previously compiled pattern. */ search_type |= SRCH_AFTER_TARGET; - if (!prev_pattern(&search_info) && !hist_pattern(search_type)) + if (!prev_pattern(&search_info)) { - error("No previous regular expression", NULL_PARG); - return (-1); + int r = hist_pattern(search_type); + if (r == 0) + error("No previous regular expression", NULL_PARG); + if (r <= 0) + return (-1); } if ((search_type & SRCH_NO_REGEX) != (search_info.search_type & SRCH_NO_REGEX)) @@ -1455,7 +1620,8 @@ search(search_type, pattern, n) /* * Compile the pattern. */ - if (set_pattern(&search_info, pattern, search_type) < 0) + int show_error = !(search_type & SRCH_INCR); + if (set_pattern(&search_info, pattern, search_type, show_error) < 0) return (-1); #if HILITE_SEARCH if (hilite_search || status_col) @@ -1483,6 +1649,7 @@ search(search_type, pattern, n) * Figure out where to start the search. */ pos = search_pos(search_type); + opos = position(sindex_from_sline(jump_sline)); if (pos == NULL_POSITION) { /* @@ -1490,14 +1657,16 @@ search(search_type, pattern, n) */ if (search_type & SRCH_PAST_EOF) return (n); +#if HILITE_SEARCH if (hilite_search == OPT_ON || status_col) repaint_hilite(1); +#endif error("Nothing to search", NULL_PARG); return (-1); } n = search_range(pos, NULL_POSITION, search_type, n, -1, - &pos, (POSITION*)NULL); + &pos, (POSITION*)NULL, &lastlinepos); if (n != 0) { /* @@ -1518,7 +1687,10 @@ search(search_type, pattern, n) /* * Go to the matching line. */ - jump_loc(pos, jump_sline); + if (lastlinepos != NULL_POSITION) + jump_loc(lastlinepos, BOTTOM); + else if (pos != opos) + jump_loc(pos, jump_sline); } #if HILITE_SEARCH @@ -1531,7 +1703,6 @@ search(search_type, pattern, n) return (0); } - #if HILITE_SEARCH /* * Prepare hilites in a given range of the file. @@ -1560,7 +1731,7 @@ prep_hilite(spos, epos, maxlines) * Search beyond where we're asked to search, so the prep region covers * more than we need. Do one big search instead of a bunch of small ones. */ -#define SEARCH_MORE (3*size_linebuf) +#define SEARCH_MORE (3*size_linebuf) if (!prev_pattern(&search_info) && !is_filtering()) return; @@ -1665,7 +1836,7 @@ prep_hilite(spos, epos, maxlines) search_type |= (search_info.search_type & SRCH_NO_REGEX); for (;;) { - result = search_range(spos, epos, search_type, 0, maxlines, (POSITION*)NULL, &new_epos); + result = search_range(spos, epos, search_type, 0, maxlines, (POSITION*)NULL, &new_epos, (POSITION*)NULL); if (result < 0) return; if (prep_endpos == NULL_POSITION || new_epos > prep_endpos) @@ -1718,11 +1889,29 @@ set_filter_pattern(pattern, search_type) char *pattern; int search_type; { + struct pattern_info *filter; + clr_filter(); if (pattern == NULL || *pattern == '\0') - clear_pattern(&filter_info); - else - set_pattern(&filter_info, pattern, search_type); + { + /* Clear and free all filters. */ + for (filter = filter_infos; filter != NULL; ) + { + struct pattern_info *next_filter = filter->next; + clear_pattern(filter); + free(filter); + filter = next_filter; + } + filter_infos = NULL; + } else + { + /* Create a new filter and add it to the filter_infos list. */ + filter = ecalloc(1, sizeof(struct pattern_info)); + init_pattern(filter); + set_pattern(filter, pattern, search_type, 1); + filter->next = filter_infos; + filter_infos = filter; + } screen_trashed = 1; } @@ -1734,7 +1923,7 @@ is_filtering(VOID_PARAM) { if (ch_getflags() & CH_HELPFILE) return (0); - return prev_pattern(&filter_info); + return (filter_infos != NULL); } #endif diff --git a/signal.c b/signal.c index 49c843d..dd66683 100644 --- a/signal.c +++ b/signal.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -33,6 +33,7 @@ extern int linenums; extern int wscroll; extern int reading; extern int quit_on_intr; +extern int secure; extern long jump_sline_fraction; /* @@ -58,6 +59,9 @@ u_interrupt(type) */ if (kbhit()) getkey(); +#endif +#if HILITE_SEARCH + set_filter_pattern(NULL, 0); #endif if (reading) intread(); /* May longjmp */ @@ -121,6 +125,9 @@ wbreak_handler(dwCtrlType) case CTRL_C_EVENT: case CTRL_BREAK_EVENT: sigs |= S_INTERRUPT; +#if HILITE_SEARCH + set_filter_pattern(NULL, 0); +#endif return (TRUE); default: break; @@ -154,7 +161,7 @@ init_signals(on) (void) LSIGNAL(SIGINT, u_interrupt); #endif #ifdef SIGTSTP - (void) LSIGNAL(SIGTSTP, stop); + (void) LSIGNAL(SIGTSTP, secure ? SIG_IGN : stop); #endif #ifdef SIGWINCH (void) LSIGNAL(SIGWINCH, winch); diff --git a/tags.c b/tags.c index fdc82da..d449c03 100644 --- a/tags.c +++ b/tags.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -10,7 +10,7 @@ #include "less.h" -#define WHITESP(c) ((c)==' ' || (c)=='\t') +#define WHITESP(c) ((c)==' ' || (c)=='\t') #if TAGS @@ -36,12 +36,12 @@ enum tag_result { * Tag type */ enum { - T_CTAGS, /* 'tags': standard and extended format (ctags) */ - T_CTAGS_X, /* stdin: cross reference format (ctags) */ - T_GTAGS, /* 'GTAGS': function definition (global) */ - T_GRTAGS, /* 'GRTAGS': function reference (global) */ - T_GSYMS, /* 'GSYMS': other symbols (global) */ - T_GPATH /* 'GPATH': path name (global) */ + T_CTAGS, /* 'tags': standard and extended format (ctags) */ + T_CTAGS_X, /* stdin: cross reference format (ctags) */ + T_GTAGS, /* 'GTAGS': function definition (global) */ + T_GRTAGS, /* 'GRTAGS': function reference (global) */ + T_GSYMS, /* 'GSYMS': other symbols (global) */ + T_GPATH /* 'GPATH': path name (global) */ }; static enum tag_result findctag LESSPARAMS((char *tag)); @@ -50,8 +50,7 @@ static char *nextgtag(VOID_PARAM); static char *prevgtag(VOID_PARAM); static POSITION ctagsearch(VOID_PARAM); static POSITION gtagsearch(VOID_PARAM); -static int getentry LESSPARAMS((char *buf, char **tag, char **file, - char **line)); +static int getentry LESSPARAMS((char *buf, char **tag, char **file, char **line)); /* * The list of tags generated by the last findgtag() call. @@ -67,10 +66,10 @@ struct taglist { }; struct tag { struct tag *next, *prev; /* List links */ - char *tag_file; /* Source file containing the tag */ - LINENUM tag_linenum; /* Appropriate line number in source file */ - char *tag_pattern; /* Pattern used to find the tag */ - char tag_endline; /* True if the pattern includes '$' */ + char *tag_file; /* Source file containing the tag */ + LINENUM tag_linenum; /* Appropriate line number in source file */ + char *tag_pattern; /* Pattern used to find the tag */ + char tag_endline; /* True if the pattern includes '$' */ }; #define TAG_END ((struct tag *) &taglist) static struct taglist taglist = { TAG_END, TAG_END }; @@ -412,10 +411,10 @@ curtag_match(char const *line, POSITION linepos) * Search for a tag. * This is a stripped-down version of search(). * We don't use search() for several reasons: - * - We don't want to blow away any search string we may have saved. - * - The various regular-expression functions (from different systems: - * regcmp vs. re_comp) behave differently in the presence of - * parentheses (which are almost always found in a tag). + * - We don't want to blow away any search string we may have saved. + * - The various regular-expression functions (from different systems: + * regcmp vs. re_comp) behave differently in the presence of + * parentheses (which are almost always found in a tag). */ static POSITION ctagsearch(VOID_PARAM) @@ -498,8 +497,8 @@ ctagsearch(VOID_PARAM) */ static enum tag_result findgtag(tag, type) - char *tag; /* tag to load */ - int type; /* tags type */ + char *tag; /* tag to load */ + int type; /* tags type */ { char buf[256]; FILE *fp; @@ -590,7 +589,7 @@ findgtag(tag, type) } while (c != '\n' && c != EOF); } - if (getentry(buf, &name, &file, &line)) + if (getentry(buf, &name, &file, &line)) { /* * Couldn't parse this line for some reason. @@ -624,7 +623,7 @@ findgtag(tag, type) return TAG_FOUND; } -static int circular = 0; /* 1: circular tag structure */ +static int circular = 0; /* 1: circular tag structure */ /* * Return the filename required for the next gtag in the queue that was setup @@ -709,9 +708,9 @@ gtagsearch(VOID_PARAM) * |func 21 subr.c func(arg) * * The following commands write this format. - * o Traditinal Ctags with -x option - * o Global with -x option - * See + * o Traditinal Ctags with -x option + * o Global with -x option + * See * * [extended format] * @@ -720,8 +719,8 @@ gtagsearch(VOID_PARAM) * |func function 21 subr.c func(arg) * * The following commands write this format. - * o Exuberant Ctags with -x option - * See + * o Exuberant Ctags with -x option + * See * * Returns 0 on success, -1 on error. * The tag, file, and line will each be NUL-terminated pointers @@ -729,19 +728,19 @@ gtagsearch(VOID_PARAM) */ static int getentry(buf, tag, file, line) - char *buf; /* standard or extended ctags -x format data */ - char **tag; /* name of the tag we actually found */ - char **file; /* file in which to find this tag */ - char **line; /* line number of file where this tag is found */ + char *buf; /* standard or extended ctags -x format data */ + char **tag; /* name of the tag we actually found */ + char **file; /* file in which to find this tag */ + char **line; /* line number of file where this tag is found */ { char *p = buf; - for (*tag = p; *p && !IS_SPACE(*p); p++) /* tag name */ + for (*tag = p; *p && !IS_SPACE(*p); p++) /* tag name */ ; if (*p == 0) return (-1); *p++ = 0; - for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ + for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ ; if (*p == 0) return (-1); @@ -751,24 +750,24 @@ getentry(buf, tag, file, line) */ if (!IS_DIGIT(*p)) { - for ( ; *p && !IS_SPACE(*p); p++) /* (skip tag type) */ + for ( ; *p && !IS_SPACE(*p); p++) /* (skip tag type) */ ; - for (; *p && IS_SPACE(*p); p++) /* (skip blanks) */ + for (; *p && IS_SPACE(*p); p++) /* (skip blanks) */ ; } if (!IS_DIGIT(*p)) return (-1); - *line = p; /* line number */ + *line = p; /* line number */ for (*line = p; *p && !IS_SPACE(*p); p++) ; if (*p == 0) return (-1); *p++ = 0; - for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ + for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ ; if (*p == 0) return (-1); - *file = p; /* file name */ + *file = p; /* file name */ for (*file = p; *p && !IS_SPACE(*p); p++) ; if (*p == 0) @@ -780,5 +779,5 @@ getentry(buf, tag, file, line) return (0); return (-1); } - + #endif diff --git a/ttyin.c b/ttyin.c index 3bb99ec..5bd3385 100644 --- a/ttyin.c +++ b/ttyin.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -28,10 +28,35 @@ public HANDLE tty; #else public int tty; #endif +#if LESSTEST +public char *ttyin_name = NULL; +public int rstat_file = -1; +#endif /*LESSTEST*/ extern int sigs; extern int utf_mode; extern int wheel_lines; +/* + * Get name of tty device. + */ +#if !MSDOS_COMPILER + public char * +tty_device(VOID_PARAM) +{ + char *dev = NULL; +#if HAVE_TTYNAME + dev = ttyname(2); +#endif + if (dev == NULL) + dev = "/dev/tty"; +#if LESSTEST + if (ttyin_name != NULL) + dev = ttyin_name; +#endif /*LESSTEST*/ + return dev; +} +#endif /* MSDOS_COMPILER */ + /* * Open keyboard for input. */ @@ -76,9 +101,9 @@ open_getchr(VOID_PARAM) */ #if OS2 /* The __open() system call translates "/dev/tty" to "con". */ - tty = __open("/dev/tty", OPEN_READ); + tty = __open(tty_device(), OPEN_READ); #else - tty = open("/dev/tty", OPEN_READ); + tty = open(tty_device(), OPEN_READ); #endif if (tty < 0) tty = 2; @@ -131,6 +156,18 @@ default_wheel_lines(VOID_PARAM) return lines; } +#if LESSTEST + public void +rstat(st) + char st; +{ + if (rstat_file < 0) + return; + lseek(rstat_file, SEEK_SET, 0); + write(rstat_file, &st, 1); +} +#endif /*LESSTEST*/ + /* * Get a character from the keyboard. */ @@ -142,11 +179,11 @@ getchr(VOID_PARAM) do { + flush(); #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC /* * In raw read, we don't see ^C so look here for it. */ - flush(); #if MSDOS_COMPILER==WIN32C if (ABORT_SIGS()) return (READ_INTR); @@ -158,11 +195,17 @@ getchr(VOID_PARAM) if (c == '\003') return (READ_INTR); #else +#if LESSTEST + rstat('R'); +#endif /*LESSTEST*/ { unsigned char uc; result = iread(tty, &uc, sizeof(char)); c = (char) uc; } +#if LESSTEST + rstat('B'); +#endif /*LESSTEST*/ if (result == READ_INTR) return (READ_INTR); if (result < 0) diff --git a/version.c b/version.c index 73169ac..7ca31e0 100644 --- a/version.c +++ b/version.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2020 Mark Nudelman + * Copyright (C) 1984-2021 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -894,6 +894,32 @@ v560 5/3/20 Fix regression when command results in no movement; v561 5/11/20 Fix erroneous EOF calculation when F command is interrupted. v562 5/19/20 Update Unicode tables; minor doc formatting. v563 6/13/20 Fix crash due to realpath() incompatibility. +v564 8/25/20 Handle realpath consistently; update docs. +v565 11/3/20 Add ESC-U command, optimize calls to realpath(). +v566 11/25/20 Fix crash when reopening a file while using LESSOPEN; + support OSC 8 hyperlinks. +v567 11/25/20 Fix typo. +v568 11/29/20 Fix some hyperlink bugs; add ^W search modifier + (thanks to Arminius); allow Makefile.aut to use Python + instead of Perl (thanks to Charlie Lin). +v569 12/1/20 Allow multiple & filters (thanks to Mattias Johansson), + allow ^X to exit F command. +v570 12/12/20 Better handling of multiple + or -p options; + fix bugs in horizontal scrolling. +v571 12/30/20 Add --line-num-width and --status-col-width options. +v572 1/4/21 Save lastmark in history file; don't toggle mouse reporting; + implement termcap delays. +v573 1/9/21 Limit eof bell to 1 per second. +v574 1/13/21 Add incremental search. +v575 1/17/21 Fix build without HILITE_SEARCH; + fix bug with ^K in lesskey extra string. +v576 2/4/21 Make sure search result is visible; add --use-color and --color. +v577 2/9/21 Use ttyname to get name of tty device. +v578 2/9/21 Doc +v579 2/14/21 Fix double-width char bugs and non-match search crash. +v580 3/2/21 Some color fixes; fix compiler warnings; some lesstest support. +v581 4/6/21 Ignore SIGTSTP in secure mode; don't print "skipping" when filtering. +v581.2 4/28/21 Fix failure to deinit mouse. */ -char version[] = "563"; +char version[] = "581.2"; From e300975576909091b342fafc992ffc5eb625586b Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 2 Oct 2022 23:37:45 -0500 Subject: [PATCH 02/13] Maint ~ whitespace clean-up (`fix-repo-whitespace` + initial makefile TABS) --- INSTALL | 1 - LICENSE | 17 +- Makefile.aut | 16 +- Makefile.dsb | 5 +- Makefile.dsg | 1 - Makefile.dsu | 5 +- Makefile.in | 7 +- Makefile.o9c | 2 +- Makefile.wnb | 19 +- Makefile.wng | 42 +- Makefile.wnm | 6 +- NEWS | 189 ++- README | 34 +- brac.c | 140 +- ch.c | 1316 ++++++++--------- charset.c | 1147 ++++++++------- cmdbuf.c | 2402 +++++++++++++++--------------- command.c | 3370 +++++++++++++++++++++--------------------- compose.uni | 672 ++++----- configure | 557 ++++--- configure.ac | 188 +-- cvt.c | 152 +- decode.c | 1501 ++++++++++--------- defines.ds | 202 +-- defines.h.in | 104 +- defines.o2 | 138 +- defines.o9 | 122 +- defines.wn | 160 +- edit.c | 1292 ++++++++--------- filename.c | 1633 +++++++++++---------- fmt.uni | 40 +- forwback.c | 648 ++++----- ifile.c | 424 +++--- input.c | 782 +++++----- install.sh | 72 +- jump.c | 482 +++--- less.h | 14 +- less.hlp | 6 +- less.nro | 114 +- lessecho.c | 396 ++--- lesskey.c | 1250 ++++++++-------- lesskey.nro | 300 ++-- line.c | 2162 +++++++++++++-------------- linenum.c | 656 ++++----- lsystem.c | 490 +++---- main.c | 578 ++++---- mark.c | 580 ++++---- mkfuncs.pl | 36 +- mkfuncs.py | 4 +- mkhelp.pl | 2 +- mkinstalldirs | 2 +- optfunc.c | 1403 +++++++++--------- option.c | 1116 +++++++------- option.h | 1 - opttbl.c | 1020 ++++++------- os.c | 402 ++--- output.c | 1016 ++++++------- pattern.c | 592 ++++---- pattern.h | 2 +- position.c | 272 ++-- prompt.c | 762 +++++----- regexp.c | 1736 +++++++++++----------- screen.c | 3861 ++++++++++++++++++++++++------------------------- scrsize.c | 96 +- search.c | 2941 +++++++++++++++++++------------------ signal.c | 252 ++-- tags.c | 1068 +++++++------- ttyin.c | 278 ++-- ubin.uni | 32 +- version.c | 66 +- wide.uni | 234 +-- 71 files changed, 20803 insertions(+), 20825 deletions(-) diff --git a/INSTALL b/INSTALL index 78ae932..19ecbd5 100644 --- a/INSTALL +++ b/INSTALL @@ -183,4 +183,3 @@ operates. script, and exit. `configure' also accepts some other, not widely useful, options. - diff --git a/LICENSE b/LICENSE index 315d1d8..65eda8c 100644 --- a/LICENSE +++ b/LICENSE @@ -10,18 +10,17 @@ are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright - notice in the documentation and/or other materials provided with + notice in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/Makefile.aut b/Makefile.aut index b6f2101..220aa1d 100644 --- a/Makefile.aut +++ b/Makefile.aut @@ -28,7 +28,7 @@ DISTFILES_W = \ defines.o2 Makefile.o2e \ defines.o9 Makefile.o9c Makefile.o9u \ defines.wn Makefile.wnm Makefile.wnb Makefile.wng \ - configure + configure UNICODE_FILES = \ compose.uni fmt.uni ubin.uni wide.uni DISTFILES = \ @@ -45,17 +45,17 @@ DISTFILES = \ mkutable $(UNICODE_FILES) \ ${DISTFILES_W} -all: help.c funcs.h $(UNICODE_FILES) ${srcdir}/configure +all: help.c funcs.h $(UNICODE_FILES) ${srcdir}/configure release: .FORCE - ${MAKE} -f Makefile.aut tagall - ${MAKE} -f Makefile.aut all - ${MAKE} -f Makefile.aut clean + ${MAKE} -f Makefile.aut tagall + ${MAKE} -f Makefile.aut all + ${MAKE} -f Makefile.aut clean ${MAKE} -f Makefile.aut dist .FORCE: -help.c: less.hlp +help.c: less.hlp -mv -f ${srcdir}/help.c ${srcdir}/help.c.old rm -rf help.c ${srcdir}/${MKHELP} < less.hlp > help.c @@ -72,11 +72,11 @@ funcs.h: ${SRC:%=${srcdir}/%} lint: lint -I. ${CPPFLAGS} ${SRC} -clean: +clean: rm -f Makefile config.status config.log config.cache defines.h stamp-h \ configure defines.h.in funcs.h help.c \ README NEWS \ - less.nro less.man lesskey.nro lesskey.man lessecho.nro lessecho.man + less.nro less.man lesskey.nro lesskey.man lessecho.nro lessecho.man distclean: clean realclean: clean diff --git a/Makefile.dsb b/Makefile.dsb index e45b602..a9697b7 100644 --- a/Makefile.dsb +++ b/Makefile.dsb @@ -28,7 +28,7 @@ OBJ = \ all: less$(EXT) lesskey$(EXT) -# This is really horrible, but the command line is too long for +# This is really horrible, but the command line is too long for # MS-DOS if we try to link $(OBJ). less$(EXT): $(OBJ) ren lesskey.obj lesskey.obo @@ -45,7 +45,6 @@ defines.h: defines.ds $(OBJ): less.h defines.h clean: - -del *.obj + -del *.obj -del less.exe -del lesskey.exe - diff --git a/Makefile.dsg b/Makefile.dsg index 4c11be0..3c25b2d 100644 --- a/Makefile.dsg +++ b/Makefile.dsg @@ -85,4 +85,3 @@ distclean: clean realclean: distclean command.com /c if exist TAGS del TAGS - diff --git a/Makefile.dsu b/Makefile.dsu index 40a2538..d26428c 100644 --- a/Makefile.dsu +++ b/Makefile.dsu @@ -37,7 +37,7 @@ OBJ = \ all: less lesskey -# This is really horrible, but the command line is too long for +# This is really horrible, but the command line is too long for # MS-DOS if we try to link $(OBJ). less: $(OBJ) -if exist lesskey.obj del lesskey.obj @@ -53,7 +53,6 @@ defines.h: defines.ds $(OBJ): less.h defines.h clean: - -del *.obj + -del *.obj -del less.exe -del lesskey.exe - diff --git a/Makefile.in b/Makefile.in index c9cbf8e..1c0a356 100644 --- a/Makefile.in +++ b/Makefile.in @@ -24,14 +24,14 @@ exec_prefix = @exec_prefix@ # Where the installed binary goes. bindir = @bindir@ -binprefix = +binprefix = sysconfdir = @sysconfdir@ datarootdir = @datarootdir@ mandir = @mandir@ manext = 1 -manprefix = +manprefix = DESTDIR = #### End of system configuration section. #### @@ -64,7 +64,7 @@ lessecho$(EXEEXT): lessecho.${O} version.${O} charset.${O}: compose.uni ubin.uni wide.uni -${OBJ}: ${srcdir}/less.h ${srcdir}/funcs.h defines.h +${OBJ}: ${srcdir}/less.h ${srcdir}/funcs.h defines.h install: all ${srcdir}/less.nro ${srcdir}/lesskey.nro ${srcdir}/lessecho.nro installdirs ${INSTALL_PROGRAM} less$(EXEEXT) ${DESTDIR}${bindir}/${binprefix}less$(EXEEXT) @@ -121,4 +121,3 @@ distclean: clean realclean: distclean rm -f TAGS - diff --git a/Makefile.o9c b/Makefile.o9c index e107f55..4be21dc 100644 --- a/Makefile.o9c +++ b/Makefile.o9c @@ -6,7 +6,7 @@ CC = cc CPPFLAGS = -D_OSK_MWC32 -DDEBUG=0 -DSTRCSPN CFLAGS = -k=0 -v=. -CFLAGS_COMPILE_ONLY = -r +CFLAGS_COMPILE_ONLY = -r LDFLAGS = -igm=8 LIBS = -l=/dd/lib/termlib.l O = r diff --git a/Makefile.wnb b/Makefile.wnb index 75a65cd..63aacaf 100644 --- a/Makefile.wnb +++ b/Makefile.wnb @@ -3,7 +3,7 @@ # Bolarnd C++ 5.5.1 free command line tools #### Start of system configuration section. #### -# +# # Borland's make knows its own location in the # filesystem. # @@ -18,10 +18,10 @@ LIBS = ${LIBDIR}\import32.lib ${LIBDIR}\cw32.lib #### End of system configuration section. #### -# +# # This rule allows us to supply the necessary -D options # in addition to whatever the user asks for. -# +# .c.obj: ${CC} -c -I. ${CPPFLAGS} ${CFLAGS} $< @@ -35,10 +35,10 @@ OBJ = \ all: less lesskey lessecho -# -# This is really horrible, but the command line is too long for +# +# This is really horrible, but the command line is too long for # MS-DOS if we try to link ${OBJ}. -# +# less: ${OBJ} ${LD} ${LDFLAGS} ${LIBDIR}\c0x32.obj $**, $@,,${LIBS} @@ -55,9 +55,9 @@ defines.h: defines.wn ${OBJ}: less.h defines.h funcs.h cmd.h clean: - -del *.obj - -del *.il? - -del *.tds + -del *.obj + -del *.il? + -del *.tds -del defines.h spotless: clean @@ -68,4 +68,3 @@ spotless: clean realclean: spotless distclean: spotless - diff --git a/Makefile.wng b/Makefile.wng index 8568606..50202aa 100644 --- a/Makefile.wng +++ b/Makefile.wng @@ -5,20 +5,20 @@ # # Usage: mingw32-make -f Makefile.wng [REGEX_PACKAGE={posix|gnu|regcomp-local}] # -# The optional command line parameter "REGEX_PACKAGE" is used to specify +# The optional command line parameter "REGEX_PACKAGE" is used to specify # a regular expression package for compilation and linking. This parameter -# can assume one of three values. +# can assume one of three values. # # REGEX_PACKAGE == regcomp-local # This choice selects the regular expression package written by Henry -# Spencer. It is implemented by the repository file "regexp.c". +# Spencer. It is implemented by the repository file "regexp.c". # # REGEX_PACKAGE == posix -# This choice selects the POSIX implementation and is provided by MingW. -# This is the default choice. +# This choice selects the POSIX implementation and is provided by MingW. +# This is the default choice. # # REGEX_PACKAGE == gnu -# This choice selects the GNU implementation and is provided by MingW. +# This choice selects the GNU implementation and is provided by MingW. # #### Start of system configuration section. #### @@ -29,23 +29,23 @@ CC = gcc # MINGW_DEFINES = -DMINGW -DWIN32 -# This specifies the "root" directory of the MingW installation. +# This specifies the "root" directory of the MingW installation. # It is defined so that the compiler and linker can find the header files -# and library that provide regular expression support. +# and library that provide regular expression support. # MINGW_ROOT_PATH = /mingw-w64/mingw64 -# Determine the regular expression package to be used. +# Determine the regular expression package to be used. # REGEX_PACKAGE ?= posix ifeq (${REGEX_PACKAGE},regcomp-local) - MINGW_DEFINES += -DUSE_REGEXP_C + MINGW_DEFINES += -DUSE_REGEXP_C else ifeq (${REGEX_PACKAGE},posix) - MINGW_DEFINES += -DUSE_POSIX_REGCOMP + MINGW_DEFINES += -DUSE_POSIX_REGCOMP else ifeq (${REGEX_PACKAGE},gnu) - MINGW_DEFINES += -DUSE_GNU_REGEX + MINGW_DEFINES += -DUSE_GNU_REGEX else - $(error REGEX_PACKAGE must be posix, gnu or regcomp-local) + $(error REGEX_PACKAGE must be posix, gnu or regcomp-local) endif MINGW_REGEX_IPATH = -I${MINGW_ROOT_PATH}/opt/include @@ -57,7 +57,7 @@ ifneq (${REGEX_PACKAGE},regcomp-local) CFLAGS_MINGW += ${MINGW_REGEX_IPATH} endif -# MingW may use sh.exe instead of cmd.exe. +# MingW may use sh.exe instead of cmd.exe. # Make sure it does not. # SHELL = cmd.exe @@ -75,13 +75,13 @@ endif .c.o: ${CC} -c -I. ${CFLAGS} $< -LESS_SRC = brac.c ch.c charset.c cmdbuf.c command.c \ - cvt.c decode.c edit.c filename.c forwback.c \ - ifile.c input.c jump.c line.c linenum.c \ - lsystem.c main.c mark.c optfunc.c option.c \ - opttbl.c os.c output.c pattern.c position.c \ - prompt.c screen.c scrsize.c search.c \ - signal.c tags.c ttyin.c version.c +LESS_SRC = brac.c ch.c charset.c cmdbuf.c command.c \ + cvt.c decode.c edit.c filename.c forwback.c \ + ifile.c input.c jump.c line.c linenum.c \ + lsystem.c main.c mark.c optfunc.c option.c \ + opttbl.c os.c output.c pattern.c position.c \ + prompt.c screen.c scrsize.c search.c \ + signal.c tags.c ttyin.c version.c ifeq (${REGEX_PACKAGE},regcomp-local) LESS_SRC += regexp.c endif diff --git a/Makefile.wnm b/Makefile.wnm index cc084a7..7765aed 100644 --- a/Makefile.wnm +++ b/Makefile.wnm @@ -6,7 +6,7 @@ CC = cl # Normal flags -CFLAGS = /nologo /W3 /EHsc /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /c +CFLAGS = /nologo /W3 /EHsc /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /c LDFLAGS = /nologo /subsystem:console /incremental:no # Debugging flags @@ -46,8 +46,6 @@ defines.h: defines.wn $(OBJ): less.h defines.h funcs.h cmd.h clean: - -del *.obj + -del *.obj -del less.exe -del lesskey.exe - - diff --git a/NEWS b/NEWS index bc5afd6..93daddd 100644 --- a/NEWS +++ b/NEWS @@ -7,16 +7,16 @@ https://greenwoodsoftware.com/less You can also download the latest version of less from there. - Report bugs, suggestions or comments at + Report bugs, suggestions or comments at https://github.com/gwsw/less/issues. ====================================================================== - Major changes between "less" versions 563 and 581.2 + Major changes between "less" versions 563 and 581.2 * Change ESC-u command to toggle, not disable, highlighting per man page. -* Add ESC-U command. +* Add ESC-U command. * Add ctrl-W search modifier for wrapping search. @@ -57,16 +57,16 @@ ====================================================================== - Major changes between "less" versions 551 and 563 + Major changes between "less" versions 551 and 563 * Update Unicode tables. * Treat Hangul Jamo medial vowels and final consonants as zero width. -* Display error message immediately when -o is toggled and +* Display error message immediately when -o is toggled and input is not a pipe. -* Fix regression: make screen repaint when "squished" and +* Fix regression: make screen repaint when "squished" and a no-movement command is given. * Fix erroneous EOF calculation when F command is interrupted. @@ -82,7 +82,7 @@ ====================================================================== - Major changes between "less" versions 530 and 551 + Major changes between "less" versions 530 and 551 * Add --mouse option. @@ -114,7 +114,7 @@ ====================================================================== - Major changes between "less" versions 487 and 530 + Major changes between "less" versions 487 and 530 * Don't output terminal init sequence if using -F and file fits on one screen. @@ -131,9 +131,9 @@ * A second ESC-u command will clear search match markers in the status column. -* Do same ANSI escape code filtering for tag matching that we do for +* Do same ANSI escape code filtering for tag matching that we do for searching, to help when viewing syntax-highlighted code. - + * Catch SIGTERM and clean up before exiting. * Fix bug initializing default charset on Windows. @@ -170,7 +170,7 @@ ====================================================================== - Major changes between "less" versions 481 and 487 + Major changes between "less" versions 481 and 487 * New commands ESC-{ and ESC-} to shift to start/end of displayed lines. @@ -190,7 +190,7 @@ ====================================================================== - Major changes between "less" versions 458 and 481 + Major changes between "less" versions 458 and 481 * Don't overwrite history file; just append to it. @@ -208,7 +208,7 @@ * Allow "extra" string in lesskey file to append to a multi-char command (like a search pattern), without executing the command. -* Ignore -u/-U setting while viewing help file, so that +* Ignore -u/-U setting while viewing help file, so that underline and bold chars are displayed correctly. * Improve detection of "binary" files in UTF-8 mode. @@ -217,7 +217,7 @@ * Fix bug where prompt was sometimes not displayed with +G. -* Fix possible memory corruption +* Fix possible memory corruption * Fix bugs and improve performance in ampersand filtering. @@ -227,7 +227,7 @@ ====================================================================== - Major changes between "less" versions 451 and 458 + Major changes between "less" versions 451 and 458 * Allow backslash escaping of metacharacters in LESS environment variable after the --use-backslash option. @@ -246,7 +246,7 @@ ====================================================================== - Major changes between "less" versions 444 and 451 + Major changes between "less" versions 444 and 451 * Add ESC-F command to keep reading data until a pattern is found. @@ -262,18 +262,18 @@ * Fix bugs handling SGR sequences in Win32. -* Fix possible crashes caused by malformed LESSOPEN or +* Fix possible crashes caused by malformed LESSOPEN or LESSCLOSE variables. -* Fix bug highlighting text which is discontiguous in the file +* Fix bug highlighting text which is discontiguous in the file due to backspace processing. -* Fix bug in displaying status column when scrolling backwards +* Fix bug in displaying status column when scrolling backwards with -J and -S in effect. ====================================================================== - Major changes between "less" versions 443 and 444 + Major changes between "less" versions 443 and 444 * Fix bug in unget handling that can cause strange effects on the command line. @@ -282,10 +282,10 @@ ====================================================================== - Major changes between "less" versions 436 and 443 + Major changes between "less" versions 436 and 443 -* Change search behavior such that when a search is given an explicit - pattern, the entire displayed screen is included in the search and +* Change search behavior such that when a search is given an explicit + pattern, the entire displayed screen is included in the search and not just the portion after the target line. * Add -A option to change search behavior to the old way: only @@ -300,7 +300,7 @@ * Fix "ungetc overflow" when passing long commands via the -p option. -* Fix bug in using line filtering via the & command +* Fix bug in using line filtering via the & command in combination with -i and -I. * Fix bug in handling negative arguments to the -j option. @@ -313,7 +313,7 @@ ====================================================================== - Major changes between "less" versions 429 and 436 + Major changes between "less" versions 429 and 436 * Don't pass "-" to non-pipe LESSOPEN unless it starts with "-". @@ -325,7 +325,7 @@ ====================================================================== - Major changes between "less" versions 424 and 429 + Major changes between "less" versions 424 and 429 * LESSOPEN pipe will now be used on standard input, if the LESSOPEN environment variable begins with "|-". @@ -348,7 +348,7 @@ ====================================================================== - Major changes between "less" versions 418 and 424 + Major changes between "less" versions 418 and 424 * New "&" command allows filtering of lines based on a pattern. @@ -366,7 +366,7 @@ ====================================================================== - Major changes between "less" versions 416 and 418 + Major changes between "less" versions 416 and 418 * Color escape sequences are now supported in WIN32 build. @@ -382,7 +382,7 @@ ====================================================================== - Major changes between "less" versions 409 and 416 + Major changes between "less" versions 409 and 416 * New --follow-name option makes F command follow the name of a file rather than the file descriptor if an open file is renamed. @@ -393,7 +393,7 @@ ====================================================================== - Major changes between "less" versions 406 and 409 + Major changes between "less" versions 406 and 409 * Support CSI escape sequences, like SGR escape sequences. @@ -407,7 +407,7 @@ ====================================================================== - Major changes between "less" versions 394 and 406 + Major changes between "less" versions 394 and 406 * Allow decimal point in number for % (percent) command. @@ -454,7 +454,7 @@ ====================================================================== - Major changes between "less" versions 382 and 394 + Major changes between "less" versions 382 and 394 * Add history file to save search and shell command history between invocations of less. @@ -503,14 +503,14 @@ ====================================================================== - Major changes between "less" versions 381 and 382 + Major changes between "less" versions 381 and 382 * Removed some old copyrighted code. This probably breaks OS/9 support. ====================================================================== - Major changes between "less" versions 378 and 381 + Major changes between "less" versions 378 and 381 * New -L option to disable LESSOPEN processing. @@ -520,7 +520,7 @@ * Use autoconf 2.54. Replace configure.in, acconfig.h, defines.h.top with configure.ac. -* Overstriking underscore with underscore is now bold or underlined +* Overstriking underscore with underscore is now bold or underlined depending on context. * Use only 7 spaces for line numbers in -N mode, if possible. @@ -531,7 +531,7 @@ ====================================================================== - Major changes between "less" versions 376 and 378 + Major changes between "less" versions 376 and 378 * Bug fixes: Default buffer space is now 64K as documented. @@ -541,7 +541,7 @@ ====================================================================== - Major changes between "less" versions 358 and 376 + Major changes between "less" versions 358 and 376 * -x option can now specify multiple variable-width tab stops. @@ -552,10 +552,10 @@ Added support for "global(1)" tags (see http://www.gnu.org/software/global/global.html). -* New prompt style set by option -Pw defines the message printed +* New prompt style set by option -Pw defines the message printed while waiting for data in the F command. -* System-wide lesskey file now defaults to sysless in etc directory +* System-wide lesskey file now defaults to sysless in etc directory instead of .sysless in bin directory. Use "configure --sysconfdir=..." to change it. (For backwards compatibility, .sysless in bin is still recognized.) @@ -590,7 +590,7 @@ ====================================================================== - Major changes between "less" versions 354 and 358 + Major changes between "less" versions 354 and 358 * Add -J (--status-column) option to display a status column. @@ -604,7 +604,7 @@ ====================================================================== - Major changes between "less" versions 352 and 354 + Major changes between "less" versions 352 and 354 * Allow space after numeric-valued command line options. @@ -620,7 +620,7 @@ ====================================================================== - Major changes between "less" versions 346 and 352 + Major changes between "less" versions 346 and 352 * Enable UTF-8 if "UTF-8" appears in locale-related environment variables. @@ -634,7 +634,7 @@ * Fix bug in doing :d on a file which contains marks. -* Fix bug causing cleared lines to sometimes be filled with standout, +* Fix bug causing cleared lines to sometimes be filled with standout, bold, underline, etc. on certain terminals. * Fixes for MS-DOS (DJGPP) version. @@ -642,14 +642,14 @@ ====================================================================== - Major changes between "less" versions 340 and 346 + Major changes between "less" versions 340 and 346 * The UTF-8 character set is now supported. * The default character set is now latin1 rather than ascii. -* New option -R (--RAW-CONTROL-CHARS) is like -r but handles - long (wrapped) lines correctly, as long as the input contains only +* New option -R (--RAW-CONTROL-CHARS) is like -r but handles + long (wrapped) lines correctly, as long as the input contains only normal text and ANSI color escape sequences. * New option -F (--quit-if-one-screen) quits if the text fits on @@ -669,9 +669,9 @@ ====================================================================== - Major changes between "less" versions 337 and 340 + Major changes between "less" versions 337 and 340 -* Command line options for less may now be given in either the old +* Command line options for less may now be given in either the old single-letter form, or a new long name form (--option-name). See the less man page or "less --help" for the list of long option names. @@ -700,14 +700,14 @@ ====================================================================== - Major changes between "less" versions 335 and 337 + Major changes between "less" versions 335 and 337 * Fixed bugs in "make install". ====================================================================== - Major changes between "less" versions 332 and 335 + Major changes between "less" versions 332 and 335 * The old -w flag (suppress tildes after end-of-file) has been removed. @@ -715,7 +715,7 @@ * New -W flag highlights the first new line after any forward movement. -* Window resize works even if LINES and/or COLUMNS environment +* Window resize works even if LINES and/or COLUMNS environment variables are incorrect. * New percent escapes for prompt strings: @@ -731,7 +731,7 @@ ====================================================================== - Major changes between "less" versions 330 and 332 + Major changes between "less" versions 330 and 332 * Filenames from the command line are entered into the command history, so UPARROW/DOWNARROW can be used to retrieve them from the :e command. @@ -739,7 +739,7 @@ * Now works correctly on Windows when using a scrolling terminal window (buffer larger than display window). -* On Windows, now restores the console screen on exit. +* On Windows, now restores the console screen on exit. Use -X to get the old behavior. * Fixed bug on Windows when CAPS-LOCK or NUM-LOCK is pressed. @@ -754,7 +754,7 @@ ====================================================================== - Major changes between "less" versions 321 and 330 + Major changes between "less" versions 321 and 330 * Now supports filenames containing spaces (in double quotes). New option -" can be used to change the quoting characters. @@ -767,7 +767,7 @@ * Added commands ESC-( and ESC-), same as ESC-[ and ESC-]. -* A "quit" command defined in a lesskey file may now have an "extra" +* A "quit" command defined in a lesskey file may now have an "extra" string, which is used to return an exit code from less when it quits. * New environment variables LESSMETACHARS and LESSMETAESCAPE provide @@ -782,9 +782,9 @@ ====================================================================== - Major changes between "less" versions 291 and 321 + Major changes between "less" versions 291 and 321 -* Command line at bottom of screen now scrolls, so it can be longer +* Command line at bottom of screen now scrolls, so it can be longer than the screen width. * New commands ESC-] and ESC-[ scroll the display horizontally. @@ -809,7 +809,7 @@ * Command line argument "--" signals that the rest of the arguments are files (not option flags). -* Help file (less.hlp) is no longer installed. Help text is now +* Help file (less.hlp) is no longer installed. Help text is now embedded in the less executable itself. * Added -Ph to change the prompt for the help text. @@ -826,7 +826,7 @@ ====================================================================== - Major changes between "less" versions 290 and 291 + Major changes between "less" versions 290 and 291 * Less environment variables can be specified in lesskey files. @@ -835,7 +835,7 @@ ====================================================================== - Major changes between "less" versions 278 and 290 + Major changes between "less" versions 278 and 290 * Accepts GNU-style options "--help" and "--version". @@ -846,21 +846,21 @@ ====================================================================== - Major changes between "less" versions 252 and 278 + Major changes between "less" versions 252 and 278 * A LESSOPEN preprocessor may now pipe the converted file data to less, rather than writing it to a temporary file. -* Search pattern highlighting has been fixed. It now highlights +* Search pattern highlighting has been fixed. It now highlights reliably, even if a string is split across two screen lines, contains TABs, etc. -* The -F flag (which suppress search highlighting) has been changed - to -G. A new flag, -g, changes search highlighting to highlight - only the string found by the last search command, instead of all +* The -F flag (which suppress search highlighting) has been changed + to -G. A new flag, -g, changes search highlighting to highlight + only the string found by the last search command, instead of all strings which match the last search command. -* New flag -I acts like -i, but ignores case even if the search +* New flag -I acts like -i, but ignores case even if the search pattern contains uppercase letters. * Less now checks for the environment variable VISUAL before EDITOR. @@ -870,11 +870,11 @@ ====================================================================== - Major changes between "less" versions 237 and 252 + Major changes between "less" versions 237 and 252 * Changes in line-editing keys: The literal key is now ^V or ^A rather than \ (backslash). - Filename completion commands (TAB and ^L) are disabled + Filename completion commands (TAB and ^L) are disabled when typing a search pattern. * Line-editing command keys can be redefined using lesskey. @@ -886,14 +886,14 @@ * New option -V displays version number of lesskey. -* Help file less.hlp is now installed by default in /usr/local/share +* Help file less.hlp is now installed by default in /usr/local/share rather than /usr/local/lib. ====================================================================== - Major changes between "less" versions 170 and 237 + Major changes between "less" versions 170 and 237 * By popular demand, text which matches the current search pattern is highlighted. New -F flag disables this feature. @@ -902,17 +902,17 @@ have a regular expression library. regexp.c is Copyright (c) 1986 by University of Toronto. -* New line-editing keys, including command history (arrow keys) and +* New line-editing keys, including command history (arrow keys) and filename completion (TAB). * Input preprocessor allows modification of input files (e.g. uncompress) via LESSOPEN/LESSCLOSE environment variables. * New -X flag disables sending termcap "ti" and "te" (initialize and - deinitialize) strings to the terminal. + deinitialize) strings to the terminal. * Changing -i from within less now correctly affects a subsequent - repeated search. + repeated search. * Searching for underlined or overstruck text now works when the -u flag is in effect, rather than the -i flag. @@ -932,25 +932,25 @@ Things that may surprise you ******************************** -* When you enter text at the bottom of the screen (search string, - filename, etc.), some keys act different than previously. - Specifically, \ (backslash), ESC, TAB, BACKTAB, and control-L +* When you enter text at the bottom of the screen (search string, + filename, etc.), some keys act different than previously. + Specifically, \ (backslash), ESC, TAB, BACKTAB, and control-L now have line editing functions. * Some previous unofficial versions of less were able to display compressed files. The new LESSOPEN/LESSCLOSE feature now provides this functionality in a different way. -* Some previous unofficial versions of less provided a -Z flag to +* Some previous unofficial versions of less provided a -Z flag to set the number of lines of text to retain between full screen scrolls. - The -z-n flag (that is, -z with a negative number) provides this + The -z-n flag (that is, -z with a negative number) provides this functionality. ====================================================================== - Major changes between "less" versions 123 and 170 + Major changes between "less" versions 123 and 170 * New option -j allows target lines to be positioned anywhere on screen. @@ -962,7 +962,7 @@ * New option -T specifies a "tags" file. * Non-printable, non-control characters are displayed in octal. - Such characters, as well as control characters, are displayed + Such characters, as well as control characters, are displayed in blinking mode. * New command -+ sets an option to its default. @@ -980,12 +980,12 @@ * New command :x directly jumps to a file in the command line list. * Search commands have been enhanced and reorganized: - n Repeat search, same direction. - N Repeat search, opposite direction. - ESC-/ Search forward thru file boundaries - ESC-? Search backward thru file boundaries - ESC-n Repeat search thru file boundaries, same direction. - ESC-N Repeat search thru file boundaries, opposite direction. + n Repeat search, same direction. + N Repeat search, opposite direction. + ESC-/ Search forward thru file boundaries + ESC-? Search backward thru file boundaries + ESC-n Repeat search thru file boundaries, same direction. + ESC-N Repeat search thru file boundaries, opposite direction. Special character * causes search to search thru file boundaries. Special character @ causes search to begin at start/end of file list. @@ -1003,7 +1003,7 @@ ====================================================================== - Major changes between "less" versions 97 and 123 + Major changes between "less" versions 97 and 123 * New option (-N) causes line numbers to be displayed in the text of the file (like vi "set nu"). @@ -1024,19 +1024,19 @@ * File marks (set by the m command) are now preserved when a new file is edited. The ' command can thus be used to switch files. -* New command ESC-/ searches all files (on the command line) +* New command ESC-/ searches all files (on the command line) for a pattern. * New command ESC-n repeats previous search, spanning files. * The N command has been changed to repeat the previous search - in the reverse direction. The old N command is still available + in the reverse direction. The old N command is still available via :n. * New command ESC-N repeats previous search in the reverse direction and spanning files. -* 8 bit characters are now supported. A new option (-g) can be +* 8 bit characters are now supported. A new option (-g) can be used to strip off the eighth bit (the previous behavior). * Options which take a following string (like -t) may now @@ -1059,9 +1059,9 @@ * Examining a file which was previously examined will return to the same position in the file. -* A "%" is expanded to the current filename and a "#" to the +* A "%" is expanded to the current filename and a "#" to the previous filename, in both shell commands and the E command. - (Previously % worked only in shell commands and # worked + (Previously % worked only in shell commands and # worked only in the E command.) * New command ":ta" is equivalent to "-t". @@ -1074,8 +1074,3 @@ * Lesskey files may now include characters after the action as extra input to be parsed after the action; for example: "toggle-option X" to toggle a specific option X. - - - - - diff --git a/README b/README index b5bf899..28842fc 100644 --- a/README +++ b/README @@ -27,13 +27,13 @@ Major changes made since the last posted version are in NEWS. INSTALLATION (Unix & Linux systems only): 1. Move the distributed source to its own directory and unpack it, - if you have not already done so. + if you have not already done so. 2. If you are building from a clone of a git repository, type "make -f Makefile.aut". - If you are building from a numbered release package (a tar or - zip file with a name like less-999.tar.gz or less-999.zip downloaded - from greenwoodsoftware.com, not from github), you should skip this step. + If you are building from a numbered release package (a tar or + zip file with a name like less-999.tar.gz or less-999.zip downloaded + from greenwoodsoftware.com, not from github), you should skip this step. 3. Type "sh configure". This will generate a Makefile and a defines.h. @@ -48,7 +48,7 @@ INSTALLATION (Unix & Linux systems only): --with-regex=lib Specifies the regular expression library used by less for pattern - matching. The default is "auto", which means the configure program + matching. The default is "auto", which means the configure program finds a regular expression library automatically. Other values are: gnu Use the GNU regex library. pcre Use the PCRE library. @@ -70,21 +70,21 @@ INSTALLATION (Unix & Linux systems only): 4. It is a good idea to look over the generated Makefile and defines.h and make sure they look ok. If you know of any peculiarities of your system that configure might not have detected, you may fix the - Makefile now. Take particular notice of the list of "terminal" - libraries in the LIBS definition in the Makefile; these may need + Makefile now. Take particular notice of the list of "terminal" + libraries in the LIBS definition in the Makefile; these may need to be edited. The terminal libraries will be some subset of -lncurses -lcurses -ltermcap -ltermlib If you wish, you may edit defines.h to remove some optional features. If you choose not to include some features in your version, you may - wish to edit the manual page "less.nro" and the help page "less.hlp" + wish to edit the manual page "less.nro" and the help page "less.hlp" to remove the descriptions of the features which you are removing. If you edit less.hlp, you should run "make -f Makefile.aut help.c". 5. Type "make" and watch the fun. 6. If the make succeeds, it will generate the programs "less", - "lesskey" and "lessecho" in your current directory. Test the + "lesskey" and "lessecho" in your current directory. Test the generated programs. 7. When satisfied that it works, if you wish to install it @@ -100,8 +100,8 @@ INSTALLATION (Unix & Linux systems only): Note to hackers: comments noting possible improvements are enclosed in double curly brackets {{ like this }}. -(Note that the above note was originally written at a time when -"hackers" most commonly meant "enthusiastic and dedicated computer +(Note that the above note was originally written at a time when +"hackers" most commonly meant "enthusiastic and dedicated computer programmers", not "persons who attempt to circumvent computer security".) @@ -111,7 +111,7 @@ INSTALLATION (MS-DOS systems only, with Microsoft C, Borland C, or DJGPP) 1. Move the distributed source to its own directory. - Depending on your compiler, you may need to convert the source + Depending on your compiler, you may need to convert the source to have CR-LF rather than LF as line terminators. 2. If you are using Microsoft C, rename MAKEFILE.DSU to MAKEFILE. @@ -134,7 +134,7 @@ INSTALLATION (MS-DOS systems only, 5. Run your "make" program and watch the fun. If your "make" requires a flag to import environment variables, you should use that flag. - If your compiler runs out of memory, try running "make -n >cmds.bat" + If your compiler runs out of memory, try running "make -n >cmds.bat" and then run cmds.bat. 6. If the make succeeds, it will generate the programs "LESS.EXE" and @@ -196,11 +196,11 @@ INSTALLATION (OS/2 systems only, 7. Make sure you have the emx runtime installed. You need the emx DLLs emx.dll and emxlibcs.dll and also the termcap database, termcap.dat. Make sure you have termcap.dat either in the default location or - somewhere in a directory listed in the PATH or INIT environment + somewhere in a directory listed in the PATH or INIT environment variables. 8. When satisfied that it works, you may wish to install less.exe, - lesskey.exe and scrsize.exe in a directory which is included in + lesskey.exe and scrsize.exe in a directory which is included in your PATH. scrsize.exe is required only if you use a terminal emulator such as xterm or rxvt. @@ -236,8 +236,8 @@ INSTALLATION (OS-9 systems only, ======================================================================= ACKNOWLEDGMENTS: - Some versions of the less distribution are packaged using + Some versions of the less distribution are packaged using Info-ZIP's compression utility. - Info-ZIP's software is free and can be obtained as source + Info-ZIP's software is free and can be obtained as source code or executables from various anonymous-ftp sites, including ftp.uu.net:/pub/archiving/zip. diff --git a/brac.c b/brac.c index 53ada50..bf9909f 100644 --- a/brac.c +++ b/brac.c @@ -16,85 +16,85 @@ #include "position.h" /* - * Try to match the n-th open bracket + * Try to match the n-th open bracket * which appears in the top displayed line (forwdir), - * or the n-th close bracket + * or the n-th close bracket * which appears in the bottom displayed line (!forwdir). - * The characters which serve as "open bracket" and + * The characters which serve as "open bracket" and * "close bracket" are given. */ - public void + public void match_brac(obrac, cbrac, forwdir, n) - int obrac; - int cbrac; - int forwdir; - int n; + int obrac; + int cbrac; + int forwdir; + int n; { - int c; - int nest; - POSITION pos; - int (*chget)(); + int c; + int nest; + POSITION pos; + int (*chget)(); - extern int ch_forw_get(), ch_back_get(); + extern int ch_forw_get(), ch_back_get(); - /* - * Seek to the line containing the open bracket. - * This is either the top or bottom line on the screen, - * depending on the type of bracket. - */ - pos = position((forwdir) ? TOP : BOTTOM); - if (pos == NULL_POSITION || ch_seek(pos)) - { - if (forwdir) - error("Nothing in top line", NULL_PARG); - else - error("Nothing in bottom line", NULL_PARG); - return; - } + /* + * Seek to the line containing the open bracket. + * This is either the top or bottom line on the screen, + * depending on the type of bracket. + */ + pos = position((forwdir) ? TOP : BOTTOM); + if (pos == NULL_POSITION || ch_seek(pos)) + { + if (forwdir) + error("Nothing in top line", NULL_PARG); + else + error("Nothing in bottom line", NULL_PARG); + return; + } - /* - * Look thru the line to find the open bracket to match. - */ - do - { - if ((c = ch_forw_get()) == '\n' || c == EOI) - { - if (forwdir) - error("No bracket in top line", NULL_PARG); - else - error("No bracket in bottom line", NULL_PARG); - return; - } - } while (c != obrac || --n > 0); + /* + * Look thru the line to find the open bracket to match. + */ + do + { + if ((c = ch_forw_get()) == '\n' || c == EOI) + { + if (forwdir) + error("No bracket in top line", NULL_PARG); + else + error("No bracket in bottom line", NULL_PARG); + return; + } + } while (c != obrac || --n > 0); - /* - * Position the file just "after" the open bracket - * (in the direction in which we will be searching). - * If searching forward, we are already after the bracket. - * If searching backward, skip back over the open bracket. - */ - if (!forwdir) - (void) ch_back_get(); + /* + * Position the file just "after" the open bracket + * (in the direction in which we will be searching). + * If searching forward, we are already after the bracket. + * If searching backward, skip back over the open bracket. + */ + if (!forwdir) + (void) ch_back_get(); - /* - * Search the file for the matching bracket. - */ - chget = (forwdir) ? ch_forw_get : ch_back_get; - nest = 0; - while ((c = (*chget)()) != EOI) - { - if (c == obrac) - nest++; - else if (c == cbrac && --nest < 0) - { - /* - * Found the matching bracket. - * If searching backward, put it on the top line. - * If searching forward, put it on the bottom line. - */ - jump_line_loc(ch_tell(), forwdir ? -1 : 1); - return; - } - } - error("No matching bracket", NULL_PARG); + /* + * Search the file for the matching bracket. + */ + chget = (forwdir) ? ch_forw_get : ch_back_get; + nest = 0; + while ((c = (*chget)()) != EOI) + { + if (c == obrac) + nest++; + else if (c == cbrac && --nest < 0) + { + /* + * Found the matching bracket. + * If searching backward, put it on the top line. + * If searching forward, put it on the bottom line. + */ + jump_line_loc(ch_tell(), forwdir ? -1 : 1); + return; + } + } + error("No matching bracket", NULL_PARG); } diff --git a/ch.c b/ch.c index bab0692..4e5c5cb 100644 --- a/ch.c +++ b/ch.c @@ -37,16 +37,16 @@ public int ignore_eoi; * The circular list is anchored by the file state "thisfile". */ struct bufnode { - struct bufnode *next, *prev; - struct bufnode *hnext, *hprev; + struct bufnode *next, *prev; + struct bufnode *hnext, *hprev; }; #define LBUFSIZE 8192 struct buf { - struct bufnode node; - BLOCKNUM block; - unsigned int datasize; - unsigned char data[LBUFSIZE]; + struct bufnode node; + BLOCKNUM block; + unsigned int datasize; + unsigned char data[LBUFSIZE]; }; #define bufnode_buf(bn) ((struct buf *) bn) @@ -56,15 +56,15 @@ struct buf { */ #define BUFHASH_SIZE 1024 struct filestate { - struct bufnode buflist; - struct bufnode hashtbl[BUFHASH_SIZE]; - int file; - int flags; - POSITION fpos; - int nbufs; - BLOCKNUM block; - unsigned int offset; - POSITION fsize; + struct bufnode buflist; + struct bufnode hashtbl[BUFHASH_SIZE]; + int file; + int flags; + POSITION fpos; + int nbufs; + BLOCKNUM block; + unsigned int offset; + POSITION fsize; }; #define ch_bufhead thisfile->buflist.next @@ -85,40 +85,40 @@ struct filestate { * Macros to manipulate the list of buffers in thisfile->buflist. */ #define FOR_BUFS(bn) \ - for (bn = ch_bufhead; bn != END_OF_CHAIN; bn = bn->next) + for (bn = ch_bufhead; bn != END_OF_CHAIN; bn = bn->next) #define BUF_RM(bn) \ - (bn)->next->prev = (bn)->prev; \ - (bn)->prev->next = (bn)->next; + (bn)->next->prev = (bn)->prev; \ + (bn)->prev->next = (bn)->next; #define BUF_INS_HEAD(bn) \ - (bn)->next = ch_bufhead; \ - (bn)->prev = END_OF_CHAIN; \ - ch_bufhead->prev = (bn); \ - ch_bufhead = (bn); + (bn)->next = ch_bufhead; \ + (bn)->prev = END_OF_CHAIN; \ + ch_bufhead->prev = (bn); \ + ch_bufhead = (bn); #define BUF_INS_TAIL(bn) \ - (bn)->next = END_OF_CHAIN; \ - (bn)->prev = ch_buftail; \ - ch_buftail->next = (bn); \ - ch_buftail = (bn); + (bn)->next = END_OF_CHAIN; \ + (bn)->prev = ch_buftail; \ + ch_buftail->next = (bn); \ + ch_buftail = (bn); /* * Macros to manipulate the list of buffers in thisfile->hashtbl[n]. */ #define FOR_BUFS_IN_CHAIN(h,bn) \ - for (bn = thisfile->hashtbl[h].hnext; \ - bn != END_OF_HCHAIN(h); bn = bn->hnext) + for (bn = thisfile->hashtbl[h].hnext; \ + bn != END_OF_HCHAIN(h); bn = bn->hnext) #define BUF_HASH_RM(bn) \ - (bn)->hnext->hprev = (bn)->hprev; \ - (bn)->hprev->hnext = (bn)->hnext; + (bn)->hnext->hprev = (bn)->hprev; \ + (bn)->hprev->hnext = (bn)->hnext; #define BUF_HASH_INS(bn,h) \ - (bn)->hnext = thisfile->hashtbl[h].hnext; \ - (bn)->hprev = END_OF_HCHAIN(h); \ - thisfile->hashtbl[h].hnext->hprev = (bn); \ - thisfile->hashtbl[h].hnext = (bn); + (bn)->hnext = thisfile->hashtbl[h].hnext; \ + (bn)->hprev = END_OF_HCHAIN(h); \ + thisfile->hashtbl[h].hnext->hprev = (bn); \ + thisfile->hashtbl[h].hnext = (bn); static struct filestate *thisfile; static int ch_ungotchar = -1; @@ -143,241 +143,241 @@ static int ch_addbuf(); /* * Get the character pointed to by the read pointer. */ - int + int ch_get(VOID_PARAM) { - struct buf *bp; - struct bufnode *bn; - int n; - int slept; - int h; - POSITION pos; - POSITION len; - - if (thisfile == NULL) - return (EOI); - - /* - * Quick check for the common case where - * the desired char is in the head buffer. - */ - if (ch_bufhead != END_OF_CHAIN) - { - bp = bufnode_buf(ch_bufhead); - if (ch_block == bp->block && ch_offset < bp->datasize) - return bp->data[ch_offset]; - } - - slept = FALSE; - - /* - * Look for a buffer holding the desired block. - */ - h = BUFHASH(ch_block); - FOR_BUFS_IN_CHAIN(h, bn) - { - bp = bufnode_buf(bn); - if (bp->block == ch_block) - { - if (ch_offset >= bp->datasize) - /* - * Need more data in this buffer. - */ - break; - goto found; - } - } - if (bn == END_OF_HCHAIN(h)) - { - /* - * Block is not in a buffer. - * Take the least recently used buffer - * and read the desired block into it. - * If the LRU buffer has data in it, - * then maybe allocate a new buffer. - */ - if (ch_buftail == END_OF_CHAIN || - bufnode_buf(ch_buftail)->block != -1) - { - /* - * There is no empty buffer to use. - * Allocate a new buffer if: - * 1. We can't seek on this file and -b is not in effect; or - * 2. We haven't allocated the max buffers for this file yet. - */ - if ((autobuf && !(ch_flags & CH_CANSEEK)) || - (maxbufs < 0 || ch_nbufs < maxbufs)) - if (ch_addbuf()) - /* - * Allocation failed: turn off autobuf. - */ - autobuf = OPT_OFF; - } - bn = ch_buftail; - bp = bufnode_buf(bn); - BUF_HASH_RM(bn); /* Remove from old hash chain. */ - bp->block = ch_block; - bp->datasize = 0; - BUF_HASH_INS(bn, h); /* Insert into new hash chain. */ - } + struct buf *bp; + struct bufnode *bn; + int n; + int slept; + int h; + POSITION pos; + POSITION len; + + if (thisfile == NULL) + return (EOI); + + /* + * Quick check for the common case where + * the desired char is in the head buffer. + */ + if (ch_bufhead != END_OF_CHAIN) + { + bp = bufnode_buf(ch_bufhead); + if (ch_block == bp->block && ch_offset < bp->datasize) + return bp->data[ch_offset]; + } + + slept = FALSE; + + /* + * Look for a buffer holding the desired block. + */ + h = BUFHASH(ch_block); + FOR_BUFS_IN_CHAIN(h, bn) + { + bp = bufnode_buf(bn); + if (bp->block == ch_block) + { + if (ch_offset >= bp->datasize) + /* + * Need more data in this buffer. + */ + break; + goto found; + } + } + if (bn == END_OF_HCHAIN(h)) + { + /* + * Block is not in a buffer. + * Take the least recently used buffer + * and read the desired block into it. + * If the LRU buffer has data in it, + * then maybe allocate a new buffer. + */ + if (ch_buftail == END_OF_CHAIN || + bufnode_buf(ch_buftail)->block != -1) + { + /* + * There is no empty buffer to use. + * Allocate a new buffer if: + * 1. We can't seek on this file and -b is not in effect; or + * 2. We haven't allocated the max buffers for this file yet. + */ + if ((autobuf && !(ch_flags & CH_CANSEEK)) || + (maxbufs < 0 || ch_nbufs < maxbufs)) + if (ch_addbuf()) + /* + * Allocation failed: turn off autobuf. + */ + autobuf = OPT_OFF; + } + bn = ch_buftail; + bp = bufnode_buf(bn); + BUF_HASH_RM(bn); /* Remove from old hash chain. */ + bp->block = ch_block; + bp->datasize = 0; + BUF_HASH_INS(bn, h); /* Insert into new hash chain. */ + } read_more: - pos = (ch_block * LBUFSIZE) + bp->datasize; - if ((len = ch_length()) != NULL_POSITION && pos >= len) - /* - * At end of file. - */ - return (EOI); - - if (pos != ch_fpos) - { - /* - * Not at the correct position: must seek. - * If input is a pipe, we're in trouble (can't seek on a pipe). - * Some data has been lost: just return "?". - */ - if (!(ch_flags & CH_CANSEEK)) - return ('?'); - if (lseek(ch_file, (off_t)pos, SEEK_SET) == BAD_LSEEK) - { - error("seek error", NULL_PARG); - clear_eol(); - return (EOI); - } - ch_fpos = pos; - } - - /* - * Read the block. - * If we read less than a full block, that's ok. - * We use partial block and pick up the rest next time. - */ - if (ch_ungotchar != -1) - { - bp->data[bp->datasize] = ch_ungotchar; - n = 1; - ch_ungotchar = -1; - } else if (ch_flags & CH_HELPFILE) - { - bp->data[bp->datasize] = helpdata[ch_fpos]; - n = 1; - } else - { - n = iread(ch_file, &bp->data[bp->datasize], - (unsigned int)(LBUFSIZE - bp->datasize)); - } - - if (n == READ_INTR) - return (EOI); - if (n < 0) - { + pos = (ch_block * LBUFSIZE) + bp->datasize; + if ((len = ch_length()) != NULL_POSITION && pos >= len) + /* + * At end of file. + */ + return (EOI); + + if (pos != ch_fpos) + { + /* + * Not at the correct position: must seek. + * If input is a pipe, we're in trouble (can't seek on a pipe). + * Some data has been lost: just return "?". + */ + if (!(ch_flags & CH_CANSEEK)) + return ('?'); + if (lseek(ch_file, (off_t)pos, SEEK_SET) == BAD_LSEEK) + { + error("seek error", NULL_PARG); + clear_eol(); + return (EOI); + } + ch_fpos = pos; + } + + /* + * Read the block. + * If we read less than a full block, that's ok. + * We use partial block and pick up the rest next time. + */ + if (ch_ungotchar != -1) + { + bp->data[bp->datasize] = ch_ungotchar; + n = 1; + ch_ungotchar = -1; + } else if (ch_flags & CH_HELPFILE) + { + bp->data[bp->datasize] = helpdata[ch_fpos]; + n = 1; + } else + { + n = iread(ch_file, &bp->data[bp->datasize], + (unsigned int)(LBUFSIZE - bp->datasize)); + } + + if (n == READ_INTR) + return (EOI); + if (n < 0) + { #if MSDOS_COMPILER==WIN32C - if (errno != EPIPE) + if (errno != EPIPE) #endif - { - error("read error", NULL_PARG); - clear_eol(); - } - n = 0; - } + { + error("read error", NULL_PARG); + clear_eol(); + } + n = 0; + } #if LOGFILE - /* - * If we have a log file, write the new data to it. - */ - if (!secure && logfile >= 0 && n > 0) - write(logfile, (char *) &bp->data[bp->datasize], n); + /* + * If we have a log file, write the new data to it. + */ + if (!secure && logfile >= 0 && n > 0) + write(logfile, (char *) &bp->data[bp->datasize], n); #endif - ch_fpos += n; - bp->datasize += n; - - /* - * If we have read to end of file, set ch_fsize to indicate - * the position of the end of file. - */ - if (n == 0) - { - ch_fsize = pos; - if (ignore_eoi) - { - /* - * We are ignoring EOF. - * Wait a while, then try again. - */ - if (!slept) - { - PARG parg; - parg.p_string = wait_message(); - ierror("%s", &parg); - } - sleep_ms(2); /* Reduce system load */ - slept = TRUE; + ch_fpos += n; + bp->datasize += n; + + /* + * If we have read to end of file, set ch_fsize to indicate + * the position of the end of file. + */ + if (n == 0) + { + ch_fsize = pos; + if (ignore_eoi) + { + /* + * We are ignoring EOF. + * Wait a while, then try again. + */ + if (!slept) + { + PARG parg; + parg.p_string = wait_message(); + ierror("%s", &parg); + } + sleep_ms(2); /* Reduce system load */ + slept = TRUE; #if HAVE_STAT_INO - if (follow_mode == FOLLOW_NAME) - { - /* See whether the file's i-number has changed, - * or the file has shrunk. - * If so, force the file to be closed and - * reopened. */ - struct stat st; - POSITION curr_pos = ch_tell(); - int r = stat(get_filename(curr_ifile), &st); - if (r == 0 && (st.st_ino != curr_ino || - st.st_dev != curr_dev || - (curr_pos != NULL_POSITION && st.st_size < curr_pos))) - { - /* screen_trashed=2 causes - * make_display to reopen the file. */ - screen_trashed = 2; - return (EOI); - } - } + if (follow_mode == FOLLOW_NAME) + { + /* See whether the file's i-number has changed, + * or the file has shrunk. + * If so, force the file to be closed and + * reopened. */ + struct stat st; + POSITION curr_pos = ch_tell(); + int r = stat(get_filename(curr_ifile), &st); + if (r == 0 && (st.st_ino != curr_ino || + st.st_dev != curr_dev || + (curr_pos != NULL_POSITION && st.st_size < curr_pos))) + { + /* screen_trashed=2 causes + * make_display to reopen the file. */ + screen_trashed = 2; + return (EOI); + } + } #endif - } - if (sigs) - return (EOI); - } + } + if (sigs) + return (EOI); + } found: - if (ch_bufhead != bn) - { - /* - * Move the buffer to the head of the buffer chain. - * This orders the buffer chain, most- to least-recently used. - */ - BUF_RM(bn); - BUF_INS_HEAD(bn); - - /* - * Move to head of hash chain too. - */ - BUF_HASH_RM(bn); - BUF_HASH_INS(bn, h); - } - - if (ch_offset >= bp->datasize) - /* - * After all that, we still don't have enough data. - * Go back and try again. - */ - goto read_more; - - return (bp->data[ch_offset]); + if (ch_bufhead != bn) + { + /* + * Move the buffer to the head of the buffer chain. + * This orders the buffer chain, most- to least-recently used. + */ + BUF_RM(bn); + BUF_INS_HEAD(bn); + + /* + * Move to head of hash chain too. + */ + BUF_HASH_RM(bn); + BUF_HASH_INS(bn, h); + } + + if (ch_offset >= bp->datasize) + /* + * After all that, we still don't have enough data. + * Go back and try again. + */ + goto read_more; + + return (bp->data[ch_offset]); } /* - * ch_ungetchar is a rather kludgy and limited way to push + * ch_ungetchar is a rather kludgy and limited way to push * a single char onto an input file descriptor. */ - public void + public void ch_ungetchar(c) - int c; + int c; { - if (c != -1 && ch_ungotchar != -1) - error("ch_ungetchar overrun", NULL_PARG); - ch_ungotchar = c; + if (c != -1 && ch_ungotchar != -1) + error("ch_ungetchar overrun", NULL_PARG); + ch_ungotchar = c; } #if LOGFILE @@ -385,25 +385,25 @@ ch_ungetchar(c) * Close the logfile. * If we haven't read all of standard input into it, do that now. */ - public void + public void end_logfile(VOID_PARAM) { - static int tried = FALSE; - - if (logfile < 0) - return; - if (!tried && ch_fsize == NULL_POSITION) - { - tried = TRUE; - ierror("Finishing logfile", NULL_PARG); - while (ch_forw_get() != EOI) - if (ABORT_SIGS()) - break; - } - close(logfile); - logfile = -1; - free(namelogfile); - namelogfile = NULL; + static int tried = FALSE; + + if (logfile < 0) + return; + if (!tried && ch_fsize == NULL_POSITION) + { + tried = TRUE; + ierror("Finishing logfile", NULL_PARG); + while (ch_forw_get() != EOI) + if (ABORT_SIGS()) + break; + } + close(logfile); + logfile = -1; + free(namelogfile); + namelogfile = NULL; } /* @@ -411,36 +411,36 @@ end_logfile(VOID_PARAM) * Invoked from the - command; see toggle_option(). * Write all the existing buffered data to the log file. */ - public void + public void sync_logfile(VOID_PARAM) { - struct buf *bp; - struct bufnode *bn; - int warned = FALSE; - BLOCKNUM block; - BLOCKNUM nblocks; - - nblocks = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE; - for (block = 0; block < nblocks; block++) - { - int wrote = FALSE; - FOR_BUFS(bn) - { - bp = bufnode_buf(bn); - if (bp->block == block) - { - write(logfile, (char *) bp->data, bp->datasize); - wrote = TRUE; - break; - } - } - if (!wrote && !warned) - { - error("Warning: log file is incomplete", - NULL_PARG); - warned = TRUE; - } - } + struct buf *bp; + struct bufnode *bn; + int warned = FALSE; + BLOCKNUM block; + BLOCKNUM nblocks; + + nblocks = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE; + for (block = 0; block < nblocks; block++) + { + int wrote = FALSE; + FOR_BUFS(bn) + { + bp = bufnode_buf(bn); + if (bp->block == block) + { + write(logfile, (char *) bp->data, bp->datasize); + wrote = TRUE; + break; + } + } + if (!wrote && !warned) + { + error("Warning: log file is incomplete", + NULL_PARG); + warned = TRUE; + } + } } #endif @@ -448,115 +448,115 @@ sync_logfile(VOID_PARAM) /* * Determine if a specific block is currently in one of the buffers. */ - static int + static int buffered(block) - BLOCKNUM block; + BLOCKNUM block; { - struct buf *bp; - struct bufnode *bn; - int h; - - h = BUFHASH(block); - FOR_BUFS_IN_CHAIN(h, bn) - { - bp = bufnode_buf(bn); - if (bp->block == block) - return (TRUE); - } - return (FALSE); + struct buf *bp; + struct bufnode *bn; + int h; + + h = BUFHASH(block); + FOR_BUFS_IN_CHAIN(h, bn) + { + bp = bufnode_buf(bn); + if (bp->block == block) + return (TRUE); + } + return (FALSE); } /* * Seek to a specified position in the file. * Return 0 if successful, non-zero if can't seek there. */ - public int + public int ch_seek(pos) - POSITION pos; + POSITION pos; { - BLOCKNUM new_block; - POSITION len; - - if (thisfile == NULL) - return (0); - - len = ch_length(); - if (pos < ch_zero() || (len != NULL_POSITION && pos > len)) - return (1); - - new_block = pos / LBUFSIZE; - if (!(ch_flags & CH_CANSEEK) && pos != ch_fpos && !buffered(new_block)) - { - if (ch_fpos > pos) - return (1); - while (ch_fpos < pos) - { - if (ch_forw_get() == EOI) - return (1); - if (ABORT_SIGS()) - return (1); - } - return (0); - } - /* - * Set read pointer. - */ - ch_block = new_block; - ch_offset = pos % LBUFSIZE; - return (0); + BLOCKNUM new_block; + POSITION len; + + if (thisfile == NULL) + return (0); + + len = ch_length(); + if (pos < ch_zero() || (len != NULL_POSITION && pos > len)) + return (1); + + new_block = pos / LBUFSIZE; + if (!(ch_flags & CH_CANSEEK) && pos != ch_fpos && !buffered(new_block)) + { + if (ch_fpos > pos) + return (1); + while (ch_fpos < pos) + { + if (ch_forw_get() == EOI) + return (1); + if (ABORT_SIGS()) + return (1); + } + return (0); + } + /* + * Set read pointer. + */ + ch_block = new_block; + ch_offset = pos % LBUFSIZE; + return (0); } /* * Seek to the end of the file. */ - public int + public int ch_end_seek(VOID_PARAM) { - POSITION len; + POSITION len; - if (thisfile == NULL) - return (0); + if (thisfile == NULL) + return (0); - if (ch_flags & CH_CANSEEK) - ch_fsize = filesize(ch_file); + if (ch_flags & CH_CANSEEK) + ch_fsize = filesize(ch_file); - len = ch_length(); - if (len != NULL_POSITION) - return (ch_seek(len)); + len = ch_length(); + if (len != NULL_POSITION) + return (ch_seek(len)); - /* - * Do it the slow way: read till end of data. - */ - while (ch_forw_get() != EOI) - if (ABORT_SIGS()) - return (1); - return (0); + /* + * Do it the slow way: read till end of data. + */ + while (ch_forw_get() != EOI) + if (ABORT_SIGS()) + return (1); + return (0); } /* * Seek to the last position in the file that is currently buffered. */ - public int + public int ch_end_buffer_seek(VOID_PARAM) { - struct buf *bp; - struct bufnode *bn; - POSITION buf_pos; - POSITION end_pos; - - if (thisfile == NULL || (ch_flags & CH_CANSEEK)) - return (ch_end_seek()); - - end_pos = 0; - FOR_BUFS(bn) - { - bp = bufnode_buf(bn); - buf_pos = (bp->block * LBUFSIZE) + bp->datasize; - if (buf_pos > end_pos) - end_pos = buf_pos; - } - - return (ch_seek(end_pos)); + struct buf *bp; + struct bufnode *bn; + POSITION buf_pos; + POSITION end_pos; + + if (thisfile == NULL || (ch_flags & CH_CANSEEK)) + return (ch_end_seek()); + + end_pos = 0; + FOR_BUFS(bn) + { + bp = bufnode_buf(bn); + buf_pos = (bp->block * LBUFSIZE) + bp->datasize; + if (buf_pos > end_pos) + end_pos = buf_pos; + } + + return (ch_seek(end_pos)); } /* @@ -564,406 +564,406 @@ ch_end_buffer_seek(VOID_PARAM) * We may not be able to seek there if input is a pipe and the * beginning of the pipe is no longer buffered. */ - public int + public int ch_beg_seek(VOID_PARAM) { - struct bufnode *bn; - struct bufnode *firstbn; - - /* - * Try a plain ch_seek first. - */ - if (ch_seek(ch_zero()) == 0) - return (0); - - /* - * Can't get to position 0. - * Look thru the buffers for the one closest to position 0. - */ - firstbn = ch_bufhead; - if (firstbn == END_OF_CHAIN) - return (1); - FOR_BUFS(bn) - { - if (bufnode_buf(bn)->block < bufnode_buf(firstbn)->block) - firstbn = bn; - } - ch_block = bufnode_buf(firstbn)->block; - ch_offset = 0; - return (0); + struct bufnode *bn; + struct bufnode *firstbn; + + /* + * Try a plain ch_seek first. + */ + if (ch_seek(ch_zero()) == 0) + return (0); + + /* + * Can't get to position 0. + * Look thru the buffers for the one closest to position 0. + */ + firstbn = ch_bufhead; + if (firstbn == END_OF_CHAIN) + return (1); + FOR_BUFS(bn) + { + if (bufnode_buf(bn)->block < bufnode_buf(firstbn)->block) + firstbn = bn; + } + ch_block = bufnode_buf(firstbn)->block; + ch_offset = 0; + return (0); } /* * Return the length of the file, if known. */ - public POSITION + public POSITION ch_length(VOID_PARAM) { - if (thisfile == NULL) - return (NULL_POSITION); - if (ignore_eoi) - return (NULL_POSITION); - if (ch_flags & CH_HELPFILE) - return (size_helpdata); - if (ch_flags & CH_NODATA) - return (0); - return (ch_fsize); + if (thisfile == NULL) + return (NULL_POSITION); + if (ignore_eoi) + return (NULL_POSITION); + if (ch_flags & CH_HELPFILE) + return (size_helpdata); + if (ch_flags & CH_NODATA) + return (0); + return (ch_fsize); } /* * Return the current position in the file. */ - public POSITION + public POSITION ch_tell(VOID_PARAM) { - if (thisfile == NULL) - return (NULL_POSITION); - return (ch_block * LBUFSIZE) + ch_offset; + if (thisfile == NULL) + return (NULL_POSITION); + return (ch_block * LBUFSIZE) + ch_offset; } /* * Get the current char and post-increment the read pointer. */ - public int + public int ch_forw_get(VOID_PARAM) { - int c; - - if (thisfile == NULL) - return (EOI); - c = ch_get(); - if (c == EOI) - return (EOI); - if (ch_offset < LBUFSIZE-1) - ch_offset++; - else - { - ch_block ++; - ch_offset = 0; - } - return (c); + int c; + + if (thisfile == NULL) + return (EOI); + c = ch_get(); + if (c == EOI) + return (EOI); + if (ch_offset < LBUFSIZE-1) + ch_offset++; + else + { + ch_block ++; + ch_offset = 0; + } + return (c); } /* * Pre-decrement the read pointer and get the new current char. */ - public int + public int ch_back_get(VOID_PARAM) { - if (thisfile == NULL) - return (EOI); - if (ch_offset > 0) - ch_offset --; - else - { - if (ch_block <= 0) - return (EOI); - if (!(ch_flags & CH_CANSEEK) && !buffered(ch_block-1)) - return (EOI); - ch_block--; - ch_offset = LBUFSIZE-1; - } - return (ch_get()); + if (thisfile == NULL) + return (EOI); + if (ch_offset > 0) + ch_offset --; + else + { + if (ch_block <= 0) + return (EOI); + if (!(ch_flags & CH_CANSEEK) && !buffered(ch_block-1)) + return (EOI); + ch_block--; + ch_offset = LBUFSIZE-1; + } + return (ch_get()); } /* * Set max amount of buffer space. * bufspace is in units of 1024 bytes. -1 mean no limit. */ - public void + public void ch_setbufspace(bufspace) - int bufspace; + int bufspace; { - if (bufspace < 0) - maxbufs = -1; - else - { - maxbufs = ((bufspace * 1024) + LBUFSIZE-1) / LBUFSIZE; - if (maxbufs < 1) - maxbufs = 1; - } + if (bufspace < 0) + maxbufs = -1; + else + { + maxbufs = ((bufspace * 1024) + LBUFSIZE-1) / LBUFSIZE; + if (maxbufs < 1) + maxbufs = 1; + } } /* * Flush (discard) any saved file state, including buffer contents. */ - public void + public void ch_flush(VOID_PARAM) { - struct bufnode *bn; - - if (thisfile == NULL) - return; - - if (!(ch_flags & CH_CANSEEK)) - { - /* - * If input is a pipe, we don't flush buffer contents, - * since the contents can't be recovered. - */ - ch_fsize = NULL_POSITION; - return; - } - - /* - * Initialize all the buffers. - */ - FOR_BUFS(bn) - { - bufnode_buf(bn)->block = -1; - } - - /* - * Figure out the size of the file, if we can. - */ - ch_fsize = filesize(ch_file); - - /* - * Seek to a known position: the beginning of the file. - */ - ch_fpos = 0; - ch_block = 0; /* ch_fpos / LBUFSIZE; */ - ch_offset = 0; /* ch_fpos % LBUFSIZE; */ + struct bufnode *bn; + + if (thisfile == NULL) + return; + + if (!(ch_flags & CH_CANSEEK)) + { + /* + * If input is a pipe, we don't flush buffer contents, + * since the contents can't be recovered. + */ + ch_fsize = NULL_POSITION; + return; + } + + /* + * Initialize all the buffers. + */ + FOR_BUFS(bn) + { + bufnode_buf(bn)->block = -1; + } + + /* + * Figure out the size of the file, if we can. + */ + ch_fsize = filesize(ch_file); + + /* + * Seek to a known position: the beginning of the file. + */ + ch_fpos = 0; + ch_block = 0; /* ch_fpos / LBUFSIZE; */ + ch_offset = 0; /* ch_fpos % LBUFSIZE; */ #if 1 - /* - * This is a kludge to workaround a Linux kernel bug: files in - * /proc have a size of 0 according to fstat() but have readable - * data. They are sometimes, but not always, seekable. - * Force them to be non-seekable here. - */ - if (ch_fsize == 0) - { - ch_fsize = NULL_POSITION; - ch_flags &= ~CH_CANSEEK; - } + /* + * This is a kludge to workaround a Linux kernel bug: files in + * /proc have a size of 0 according to fstat() but have readable + * data. They are sometimes, but not always, seekable. + * Force them to be non-seekable here. + */ + if (ch_fsize == 0) + { + ch_fsize = NULL_POSITION; + ch_flags &= ~CH_CANSEEK; + } #endif - if (lseek(ch_file, (off_t)0, SEEK_SET) == BAD_LSEEK) - { - /* - * Warning only; even if the seek fails for some reason, - * there's a good chance we're at the beginning anyway. - * {{ I think this is bogus reasoning. }} - */ - error("seek error to 0", NULL_PARG); - } + if (lseek(ch_file, (off_t)0, SEEK_SET) == BAD_LSEEK) + { + /* + * Warning only; even if the seek fails for some reason, + * there's a good chance we're at the beginning anyway. + * {{ I think this is bogus reasoning. }} + */ + error("seek error to 0", NULL_PARG); + } } /* * Allocate a new buffer. * The buffer is added to the tail of the buffer chain. */ - static int + static int ch_addbuf(VOID_PARAM) { - struct buf *bp; - struct bufnode *bn; - - /* - * Allocate and initialize a new buffer and link it - * onto the tail of the buffer list. - */ - bp = (struct buf *) calloc(1, sizeof(struct buf)); - if (bp == NULL) - return (1); - ch_nbufs++; - bp->block = -1; - bn = &bp->node; - - BUF_INS_TAIL(bn); - BUF_HASH_INS(bn, 0); - return (0); + struct buf *bp; + struct bufnode *bn; + + /* + * Allocate and initialize a new buffer and link it + * onto the tail of the buffer list. + */ + bp = (struct buf *) calloc(1, sizeof(struct buf)); + if (bp == NULL) + return (1); + ch_nbufs++; + bp->block = -1; + bn = &bp->node; + + BUF_INS_TAIL(bn); + BUF_HASH_INS(bn, 0); + return (0); } /* * */ - static void + static void init_hashtbl(VOID_PARAM) { - int h; + int h; - for (h = 0; h < BUFHASH_SIZE; h++) - { - thisfile->hashtbl[h].hnext = END_OF_HCHAIN(h); - thisfile->hashtbl[h].hprev = END_OF_HCHAIN(h); - } + for (h = 0; h < BUFHASH_SIZE; h++) + { + thisfile->hashtbl[h].hnext = END_OF_HCHAIN(h); + thisfile->hashtbl[h].hprev = END_OF_HCHAIN(h); + } } /* * Delete all buffers for this file. */ - static void + static void ch_delbufs(VOID_PARAM) { - struct bufnode *bn; - - while (ch_bufhead != END_OF_CHAIN) - { - bn = ch_bufhead; - BUF_RM(bn); - free(bufnode_buf(bn)); - } - ch_nbufs = 0; - init_hashtbl(); + struct bufnode *bn; + + while (ch_bufhead != END_OF_CHAIN) + { + bn = ch_bufhead; + BUF_RM(bn); + free(bufnode_buf(bn)); + } + ch_nbufs = 0; + init_hashtbl(); } /* * Is it possible to seek on a file descriptor? */ - public int + public int seekable(f) - int f; + int f; { #if MSDOS_COMPILER - extern int fd0; - if (f == fd0 && !isatty(fd0)) - { - /* - * In MS-DOS, pipes are seekable. Check for - * standard input, and pretend it is not seekable. - */ - return (0); - } + extern int fd0; + if (f == fd0 && !isatty(fd0)) + { + /* + * In MS-DOS, pipes are seekable. Check for + * standard input, and pretend it is not seekable. + */ + return (0); + } #endif - return (lseek(f, (off_t)1, SEEK_SET) != BAD_LSEEK); + return (lseek(f, (off_t)1, SEEK_SET) != BAD_LSEEK); } /* * Force EOF to be at the current read position. * This is used after an ignore_eof read, during which the EOF may change. */ - public void + public void ch_set_eof(VOID_PARAM) { - if (ch_fsize != NULL_POSITION && ch_fsize < ch_fpos) - ch_fsize = ch_fpos; + if (ch_fsize != NULL_POSITION && ch_fsize < ch_fpos) + ch_fsize = ch_fpos; } /* * Initialize file state for a new file. */ - public void + public void ch_init(f, flags) - int f; - int flags; + int f; + int flags; { - /* - * See if we already have a filestate for this file. - */ - thisfile = (struct filestate *) get_filestate(curr_ifile); - if (thisfile == NULL) - { - /* - * Allocate and initialize a new filestate. - */ - thisfile = (struct filestate *) - calloc(1, sizeof(struct filestate)); - thisfile->buflist.next = thisfile->buflist.prev = END_OF_CHAIN; - thisfile->nbufs = 0; - thisfile->flags = flags; - thisfile->fpos = 0; - thisfile->block = 0; - thisfile->offset = 0; - thisfile->file = -1; - thisfile->fsize = NULL_POSITION; - init_hashtbl(); - /* - * Try to seek; set CH_CANSEEK if it works. - */ - if ((flags & CH_CANSEEK) && !seekable(f)) - ch_flags &= ~CH_CANSEEK; - set_filestate(curr_ifile, (void *) thisfile); - } - if (thisfile->file == -1) - thisfile->file = f; - ch_flush(); + /* + * See if we already have a filestate for this file. + */ + thisfile = (struct filestate *) get_filestate(curr_ifile); + if (thisfile == NULL) + { + /* + * Allocate and initialize a new filestate. + */ + thisfile = (struct filestate *) + calloc(1, sizeof(struct filestate)); + thisfile->buflist.next = thisfile->buflist.prev = END_OF_CHAIN; + thisfile->nbufs = 0; + thisfile->flags = flags; + thisfile->fpos = 0; + thisfile->block = 0; + thisfile->offset = 0; + thisfile->file = -1; + thisfile->fsize = NULL_POSITION; + init_hashtbl(); + /* + * Try to seek; set CH_CANSEEK if it works. + */ + if ((flags & CH_CANSEEK) && !seekable(f)) + ch_flags &= ~CH_CANSEEK; + set_filestate(curr_ifile, (void *) thisfile); + } + if (thisfile->file == -1) + thisfile->file = f; + ch_flush(); } /* * Close a filestate. */ - public void + public void ch_close(VOID_PARAM) { - int keepstate = FALSE; - - if (thisfile == NULL) - return; - - if ((ch_flags & (CH_CANSEEK|CH_POPENED|CH_HELPFILE)) && !(ch_flags & CH_KEEPOPEN)) - { - /* - * We can seek or re-open, so we don't need to keep buffers. - */ - ch_delbufs(); - } else - keepstate = TRUE; - if (!(ch_flags & CH_KEEPOPEN)) - { - /* - * We don't need to keep the file descriptor open - * (because we can re-open it.) - * But don't really close it if it was opened via popen(), - * because pclose() wants to close it. - */ - if (!(ch_flags & (CH_POPENED|CH_HELPFILE))) - close(ch_file); - ch_file = -1; - } else - keepstate = TRUE; - if (!keepstate) - { - /* - * We don't even need to keep the filestate structure. - */ - free(thisfile); - thisfile = NULL; - set_filestate(curr_ifile, (void *) NULL); - } + int keepstate = FALSE; + + if (thisfile == NULL) + return; + + if ((ch_flags & (CH_CANSEEK|CH_POPENED|CH_HELPFILE)) && !(ch_flags & CH_KEEPOPEN)) + { + /* + * We can seek or re-open, so we don't need to keep buffers. + */ + ch_delbufs(); + } else + keepstate = TRUE; + if (!(ch_flags & CH_KEEPOPEN)) + { + /* + * We don't need to keep the file descriptor open + * (because we can re-open it.) + * But don't really close it if it was opened via popen(), + * because pclose() wants to close it. + */ + if (!(ch_flags & (CH_POPENED|CH_HELPFILE))) + close(ch_file); + ch_file = -1; + } else + keepstate = TRUE; + if (!keepstate) + { + /* + * We don't even need to keep the filestate structure. + */ + free(thisfile); + thisfile = NULL; + set_filestate(curr_ifile, (void *) NULL); + } } /* * Return ch_flags for the current file. */ - public int + public int ch_getflags(VOID_PARAM) { - if (thisfile == NULL) - return (0); - return (ch_flags); + if (thisfile == NULL) + return (0); + return (ch_flags); } #if 0 - public void + public void ch_dump(struct filestate *fs) { - struct buf *bp; - struct bufnode *bn; - unsigned char *s; - - if (fs == NULL) - { - printf(" --no filestate\n"); - return; - } - printf(" file %d, flags %x, fpos %x, fsize %x, blk/off %x/%x\n", - fs->file, fs->flags, fs->fpos, - fs->fsize, fs->block, fs->offset); - printf(" %d bufs:\n", fs->nbufs); - for (bn = fs->next; bn != &fs->buflist; bn = bn->next) - { - bp = bufnode_buf(bn); - printf("%x: blk %x, size %x \"", - bp, bp->block, bp->datasize); - for (s = bp->data; s < bp->data + 30; s++) - if (*s >= ' ' && *s < 0x7F) - printf("%c", *s); - else - printf("."); - printf("\"\n"); - } + struct buf *bp; + struct bufnode *bn; + unsigned char *s; + + if (fs == NULL) + { + printf(" --no filestate\n"); + return; + } + printf(" file %d, flags %x, fpos %x, fsize %x, blk/off %x/%x\n", + fs->file, fs->flags, fs->fpos, + fs->fsize, fs->block, fs->offset); + printf(" %d bufs:\n", fs->nbufs); + for (bn = fs->next; bn != &fs->buflist; bn = bn->next) + { + bp = bufnode_buf(bn); + printf("%x: blk %x, size %x \"", + bp, bp->block, bp->datasize); + for (s = bp->data; s < bp->data + 30; s++) + if (*s >= ' ' && *s < 0x7F) + printf("%c", *s); + else + printf("."); + printf("\"\n"); + } } #endif diff --git a/charset.c b/charset.c index b37c8a2..bac09ba 100644 --- a/charset.c +++ b/charset.c @@ -36,83 +36,83 @@ public int utf_mode = 0; * selected by the LESSCHARSET environment variable. */ struct charset { - char *name; - int *p_flag; - char *desc; + char *name; + int *p_flag; + char *desc; } charsets[] = { - { "ascii", NULL, "8bcccbcc18b95.b" }, - { "utf-8", &utf_mode, "8bcccbcc18b95.b126.bb" }, - { "iso8859", NULL, "8bcccbcc18b95.33b." }, - { "latin3", NULL, "8bcccbcc18b95.33b5.b8.b15.b4.b12.b18.b12.b." }, - { "arabic", NULL, "8bcccbcc18b95.33b.3b.7b2.13b.3b.b26.5b19.b" }, - { "greek", NULL, "8bcccbcc18b95.33b4.2b4.b3.b35.b44.b" }, - { "greek2005", NULL, "8bcccbcc18b95.33b14.b35.b44.b" }, - { "hebrew", NULL, "8bcccbcc18b95.33b.b29.32b28.2b2.b" }, - { "koi8-r", NULL, "8bcccbcc18b95.b." }, - { "KOI8-T", NULL, "8bcccbcc18b95.b8.b6.b8.b.b.5b7.3b4.b4.b3.b.b.3b." }, - { "georgianps", NULL, "8bcccbcc18b95.3b11.4b12.2b." }, - { "tcvn", NULL, "b..b...bcccbccbbb7.8b95.b48.5b." }, - { "TIS-620", NULL, "8bcccbcc18b95.b.4b.11b7.8b." }, - { "next", NULL, "8bcccbcc18b95.bb125.bb" }, - { "dos", NULL, "8bcccbcc12bc5b95.b." }, - { "windows-1251", NULL, "8bcccbcc12bc5b95.b24.b." }, - { "windows-1252", NULL, "8bcccbcc12bc5b95.b.b11.b.2b12.b." }, - { "windows-1255", NULL, "8bcccbcc12bc5b95.b.b8.b.5b9.b.4b." }, - { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." }, - { "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" }, - { NULL, NULL, NULL } + { "ascii", NULL, "8bcccbcc18b95.b" }, + { "utf-8", &utf_mode, "8bcccbcc18b95.b126.bb" }, + { "iso8859", NULL, "8bcccbcc18b95.33b." }, + { "latin3", NULL, "8bcccbcc18b95.33b5.b8.b15.b4.b12.b18.b12.b." }, + { "arabic", NULL, "8bcccbcc18b95.33b.3b.7b2.13b.3b.b26.5b19.b" }, + { "greek", NULL, "8bcccbcc18b95.33b4.2b4.b3.b35.b44.b" }, + { "greek2005", NULL, "8bcccbcc18b95.33b14.b35.b44.b" }, + { "hebrew", NULL, "8bcccbcc18b95.33b.b29.32b28.2b2.b" }, + { "koi8-r", NULL, "8bcccbcc18b95.b." }, + { "KOI8-T", NULL, "8bcccbcc18b95.b8.b6.b8.b.b.5b7.3b4.b4.b3.b.b.3b." }, + { "georgianps", NULL, "8bcccbcc18b95.3b11.4b12.2b." }, + { "tcvn", NULL, "b..b...bcccbccbbb7.8b95.b48.5b." }, + { "TIS-620", NULL, "8bcccbcc18b95.b.4b.11b7.8b." }, + { "next", NULL, "8bcccbcc18b95.bb125.bb" }, + { "dos", NULL, "8bcccbcc12bc5b95.b." }, + { "windows-1251", NULL, "8bcccbcc12bc5b95.b24.b." }, + { "windows-1252", NULL, "8bcccbcc12bc5b95.b.b11.b.2b12.b." }, + { "windows-1255", NULL, "8bcccbcc12bc5b95.b.b8.b.5b9.b.4b." }, + { "ebcdic", NULL, "5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b." }, + { "IBM-1047", NULL, "4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc191.b" }, + { NULL, NULL, NULL } }; /* * Support "locale charmap"/nl_langinfo(CODESET) values, as well as others. */ struct cs_alias { - char *name; - char *oname; + char *name; + char *oname; } cs_aliases[] = { - { "UTF-8", "utf-8" }, - { "utf8", "utf-8" }, - { "UTF8", "utf-8" }, - { "ANSI_X3.4-1968", "ascii" }, - { "US-ASCII", "ascii" }, - { "latin1", "iso8859" }, - { "ISO-8859-1", "iso8859" }, - { "latin9", "iso8859" }, - { "ISO-8859-15", "iso8859" }, - { "latin2", "iso8859" }, - { "ISO-8859-2", "iso8859" }, - { "ISO-8859-3", "latin3" }, - { "latin4", "iso8859" }, - { "ISO-8859-4", "iso8859" }, - { "cyrillic", "iso8859" }, - { "ISO-8859-5", "iso8859" }, - { "ISO-8859-6", "arabic" }, - { "ISO-8859-7", "greek" }, - { "IBM9005", "greek2005" }, - { "ISO-8859-8", "hebrew" }, - { "latin5", "iso8859" }, - { "ISO-8859-9", "iso8859" }, - { "latin6", "iso8859" }, - { "ISO-8859-10", "iso8859" }, - { "latin7", "iso8859" }, - { "ISO-8859-13", "iso8859" }, - { "latin8", "iso8859" }, - { "ISO-8859-14", "iso8859" }, - { "latin10", "iso8859" }, - { "ISO-8859-16", "iso8859" }, - { "IBM437", "dos" }, - { "EBCDIC-US", "ebcdic" }, - { "IBM1047", "IBM-1047" }, - { "KOI8-R", "koi8-r" }, - { "KOI8-U", "koi8-r" }, - { "GEORGIAN-PS", "georgianps" }, - { "TCVN5712-1", "tcvn" }, - { "NEXTSTEP", "next" }, - { "windows", "windows-1252" }, /* backward compatibility */ - { "CP1251", "windows-1251" }, - { "CP1252", "windows-1252" }, - { "CP1255", "windows-1255" }, - { NULL, NULL } + { "UTF-8", "utf-8" }, + { "utf8", "utf-8" }, + { "UTF8", "utf-8" }, + { "ANSI_X3.4-1968", "ascii" }, + { "US-ASCII", "ascii" }, + { "latin1", "iso8859" }, + { "ISO-8859-1", "iso8859" }, + { "latin9", "iso8859" }, + { "ISO-8859-15", "iso8859" }, + { "latin2", "iso8859" }, + { "ISO-8859-2", "iso8859" }, + { "ISO-8859-3", "latin3" }, + { "latin4", "iso8859" }, + { "ISO-8859-4", "iso8859" }, + { "cyrillic", "iso8859" }, + { "ISO-8859-5", "iso8859" }, + { "ISO-8859-6", "arabic" }, + { "ISO-8859-7", "greek" }, + { "IBM9005", "greek2005" }, + { "ISO-8859-8", "hebrew" }, + { "latin5", "iso8859" }, + { "ISO-8859-9", "iso8859" }, + { "latin6", "iso8859" }, + { "ISO-8859-10", "iso8859" }, + { "latin7", "iso8859" }, + { "ISO-8859-13", "iso8859" }, + { "latin8", "iso8859" }, + { "ISO-8859-14", "iso8859" }, + { "latin10", "iso8859" }, + { "ISO-8859-16", "iso8859" }, + { "IBM437", "dos" }, + { "EBCDIC-US", "ebcdic" }, + { "IBM1047", "IBM-1047" }, + { "KOI8-R", "koi8-r" }, + { "KOI8-U", "koi8-r" }, + { "GEORGIAN-PS", "georgianps" }, + { "TCVN5712-1", "tcvn" }, + { "NEXTSTEP", "next" }, + { "windows", "windows-1252" }, /* backward compatibility */ + { "CP1251", "windows-1251" }, + { "CP1252", "windows-1252" }, + { "CP1255", "windows-1255" }, + { NULL, NULL } }; #define IS_BINARY_CHAR 01 @@ -130,7 +130,7 @@ public int binattr = AT_STANDOUT|AT_COLOR_BIN; * one for each character in the charset. * If the string is shorter than 256 letters, missing letters * are taken to be identical to the last one. - * A decimal number followed by a letter is taken to be a + * A decimal number followed by a letter is taken to be a * repetition of the letter. * * Each letter is one of: @@ -138,255 +138,255 @@ public int binattr = AT_STANDOUT|AT_COLOR_BIN; * b binary character * c control character */ - static void + static void ichardef(s) - char *s; + char *s; { - char *cp; - int n; - char v; - - n = 0; - v = 0; - cp = chardef; - while (*s != '\0') - { - switch (*s++) - { - case '.': - v = 0; - break; - case 'c': - v = IS_CONTROL_CHAR; - break; - case 'b': - v = IS_BINARY_CHAR|IS_CONTROL_CHAR; - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = (10 * n) + (s[-1] - '0'); - continue; - - default: - error("invalid chardef", NULL_PARG); - quit(QUIT_ERROR); - /*NOTREACHED*/ - } - - do - { - if (cp >= chardef + sizeof(chardef)) - { - error("chardef longer than 256", NULL_PARG); - quit(QUIT_ERROR); - /*NOTREACHED*/ - } - *cp++ = v; - } while (--n > 0); - n = 0; - } - - while (cp < chardef + sizeof(chardef)) - *cp++ = v; + char *cp; + int n; + char v; + + n = 0; + v = 0; + cp = chardef; + while (*s != '\0') + { + switch (*s++) + { + case '.': + v = 0; + break; + case 'c': + v = IS_CONTROL_CHAR; + break; + case 'b': + v = IS_BINARY_CHAR|IS_CONTROL_CHAR; + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = (10 * n) + (s[-1] - '0'); + continue; + + default: + error("invalid chardef", NULL_PARG); + quit(QUIT_ERROR); + /*NOTREACHED*/ + } + + do + { + if (cp >= chardef + sizeof(chardef)) + { + error("chardef longer than 256", NULL_PARG); + quit(QUIT_ERROR); + /*NOTREACHED*/ + } + *cp++ = v; + } while (--n > 0); + n = 0; + } + + while (cp < chardef + sizeof(chardef)) + *cp++ = v; } /* * Define a charset, given a charset name. * The valid charset names are listed in the "charsets" array. */ - static int + static int icharset(name, no_error) - char *name; - int no_error; + char *name; + int no_error; { - struct charset *p; - struct cs_alias *a; - - if (name == NULL || *name == '\0') - return (0); - - /* First see if the name is an alias. */ - for (a = cs_aliases; a->name != NULL; a++) - { - if (strcmp(name, a->name) == 0) - { - name = a->oname; - break; - } - } - - for (p = charsets; p->name != NULL; p++) - { - if (strcmp(name, p->name) == 0) - { - ichardef(p->desc); - if (p->p_flag != NULL) - { + struct charset *p; + struct cs_alias *a; + + if (name == NULL || *name == '\0') + return (0); + + /* First see if the name is an alias. */ + for (a = cs_aliases; a->name != NULL; a++) + { + if (strcmp(name, a->name) == 0) + { + name = a->oname; + break; + } + } + + for (p = charsets; p->name != NULL; p++) + { + if (strcmp(name, p->name) == 0) + { + ichardef(p->desc); + if (p->p_flag != NULL) + { #if MSDOS_COMPILER==WIN32C - *(p->p_flag) = 1 + (GetConsoleOutputCP() != CP_UTF8); + *(p->p_flag) = 1 + (GetConsoleOutputCP() != CP_UTF8); #else - *(p->p_flag) = 1; + *(p->p_flag) = 1; #endif - } - return (1); - } - } - - if (!no_error) { - error("invalid charset name", NULL_PARG); - quit(QUIT_ERROR); - } - return (0); + } + return (1); + } + } + + if (!no_error) { + error("invalid charset name", NULL_PARG); + quit(QUIT_ERROR); + } + return (0); } #if HAVE_LOCALE /* * Define a charset, given a locale name. */ - static void + static void ilocale(VOID_PARAM) { - int c; - - for (c = 0; c < (int) sizeof(chardef); c++) - { - if (isprint(c)) - chardef[c] = 0; - else if (iscntrl(c)) - chardef[c] = IS_CONTROL_CHAR; - else - chardef[c] = IS_BINARY_CHAR|IS_CONTROL_CHAR; - } + int c; + + for (c = 0; c < (int) sizeof(chardef); c++) + { + if (isprint(c)) + chardef[c] = 0; + else if (iscntrl(c)) + chardef[c] = IS_CONTROL_CHAR; + else + chardef[c] = IS_BINARY_CHAR|IS_CONTROL_CHAR; + } } #endif /* * Define the printing format for control (or binary utf) chars. */ - public void + public void setfmt(s, fmtvarptr, attrptr, default_fmt) - char *s; - char **fmtvarptr; - int *attrptr; - char *default_fmt; + char *s; + char **fmtvarptr; + int *attrptr; + char *default_fmt; { - if (s && utf_mode) - { - /* It would be too hard to account for width otherwise. */ - char constant *t = s; - while (*t) - { - if (*t < ' ' || *t > '~') - { - s = default_fmt; - goto attr; - } - t++; - } - } - - /* %n is evil */ - if (s == NULL || *s == '\0' || - (*s == '*' && (s[1] == '\0' || s[2] == '\0' || strchr(s + 2, 'n'))) || - (*s != '*' && strchr(s, 'n'))) - s = default_fmt; - - /* - * Select the attributes if it starts with "*". - */ + if (s && utf_mode) + { + /* It would be too hard to account for width otherwise. */ + char constant *t = s; + while (*t) + { + if (*t < ' ' || *t > '~') + { + s = default_fmt; + goto attr; + } + t++; + } + } + + /* %n is evil */ + if (s == NULL || *s == '\0' || + (*s == '*' && (s[1] == '\0' || s[2] == '\0' || strchr(s + 2, 'n'))) || + (*s != '*' && strchr(s, 'n'))) + s = default_fmt; + + /* + * Select the attributes if it starts with "*". + */ attr: - if (*s == '*' && s[1] != '\0') - { - switch (s[1]) - { - case 'd': *attrptr = AT_BOLD; break; - case 'k': *attrptr = AT_BLINK; break; - case 's': *attrptr = AT_STANDOUT; break; - case 'u': *attrptr = AT_UNDERLINE; break; - default: *attrptr = AT_NORMAL; break; - } - s += 2; - } - *fmtvarptr = s; + if (*s == '*' && s[1] != '\0') + { + switch (s[1]) + { + case 'd': *attrptr = AT_BOLD; break; + case 'k': *attrptr = AT_BLINK; break; + case 's': *attrptr = AT_STANDOUT; break; + case 'u': *attrptr = AT_UNDERLINE; break; + default: *attrptr = AT_NORMAL; break; + } + s += 2; + } + *fmtvarptr = s; } /* * */ - static void + static void set_charset(VOID_PARAM) { - char *s; + char *s; #if MSDOS_COMPILER==WIN32C - /* - * If the Windows console is using UTF-8, we'll use it too. - */ - if (GetConsoleOutputCP() == CP_UTF8) - if (icharset("utf-8", 1)) - return; + /* + * If the Windows console is using UTF-8, we'll use it too. + */ + if (GetConsoleOutputCP() == CP_UTF8) + if (icharset("utf-8", 1)) + return; #endif - /* - * See if environment variable LESSCHARSET is defined. - */ - s = lgetenv("LESSCHARSET"); - if (icharset(s, 0)) - return; - - /* - * LESSCHARSET is not defined: try LESSCHARDEF. - */ - s = lgetenv("LESSCHARDEF"); - if (!isnullenv(s)) - { - ichardef(s); - return; - } + /* + * See if environment variable LESSCHARSET is defined. + */ + s = lgetenv("LESSCHARSET"); + if (icharset(s, 0)) + return; + + /* + * LESSCHARSET is not defined: try LESSCHARDEF. + */ + s = lgetenv("LESSCHARDEF"); + if (!isnullenv(s)) + { + ichardef(s); + return; + } #if HAVE_LOCALE #ifdef CODESET - /* - * Try using the codeset name as the charset name. - */ - s = nl_langinfo(CODESET); - if (icharset(s, 1)) - return; + /* + * Try using the codeset name as the charset name. + */ + s = nl_langinfo(CODESET); + if (icharset(s, 1)) + return; #endif #endif #if HAVE_STRSTR - /* - * Check whether LC_ALL, LC_CTYPE or LANG look like UTF-8 is used. - */ - if ((s = lgetenv("LC_ALL")) != NULL || - (s = lgetenv("LC_CTYPE")) != NULL || - (s = lgetenv("LANG")) != NULL) - { - if ( strstr(s, "UTF-8") != NULL || strstr(s, "utf-8") != NULL - || strstr(s, "UTF8") != NULL || strstr(s, "utf8") != NULL) - if (icharset("utf-8", 1)) - return; - } + /* + * Check whether LC_ALL, LC_CTYPE or LANG look like UTF-8 is used. + */ + if ((s = lgetenv("LC_ALL")) != NULL || + (s = lgetenv("LC_CTYPE")) != NULL || + (s = lgetenv("LANG")) != NULL) + { + if ( strstr(s, "UTF-8") != NULL || strstr(s, "utf-8") != NULL + || strstr(s, "UTF8") != NULL || strstr(s, "utf8") != NULL) + if (icharset("utf-8", 1)) + return; + } #endif #if HAVE_LOCALE - /* - * Get character definitions from locale functions, - * rather than from predefined charset entry. - */ - ilocale(); + /* + * Get character definitions from locale functions, + * rather than from predefined charset entry. + */ + ilocale(); #else #if MSDOS_COMPILER - /* - * Default to "dos". - */ - (void) icharset("dos", 1); + /* + * Default to "dos". + */ + (void) icharset("dos", 1); #else - /* - * Default to "latin1". - */ - (void) icharset("latin1", 1); + /* + * Default to "latin1". + */ + (void) icharset("latin1", 1); #endif #endif } @@ -394,336 +394,336 @@ set_charset(VOID_PARAM) /* * Initialize charset data structures. */ - public void + public void init_charset(VOID_PARAM) { - char *s; + char *s; #if HAVE_LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - set_charset(); + set_charset(); - s = lgetenv("LESSBINFMT"); - setfmt(s, &binfmt, &binattr, "*s<%02X>"); - - s = lgetenv("LESSUTFBINFMT"); - setfmt(s, &utfbinfmt, &binattr, ""); + s = lgetenv("LESSBINFMT"); + setfmt(s, &binfmt, &binattr, "*s<%02X>"); + + s = lgetenv("LESSUTFBINFMT"); + setfmt(s, &utfbinfmt, &binattr, ""); } /* * Is a given character a "binary" character? */ - public int + public int binary_char(c) - LWCHAR c; + LWCHAR c; { - if (utf_mode) - return (is_ubin_char(c)); - c &= 0377; - return (chardef[c] & IS_BINARY_CHAR); + if (utf_mode) + return (is_ubin_char(c)); + c &= 0377; + return (chardef[c] & IS_BINARY_CHAR); } /* * Is a given character a "control" character? */ - public int + public int control_char(c) - LWCHAR c; + LWCHAR c; { - c &= 0377; - return (chardef[c] & IS_CONTROL_CHAR); + c &= 0377; + return (chardef[c] & IS_CONTROL_CHAR); } /* * Return the printable form of a character. * For example, in the "ascii" charset '\3' is printed as "^C". */ - public char * + public char * prchar(c) - LWCHAR c; + LWCHAR c; { - /* {{ This buffer can be overrun if LESSBINFMT is a long string. }} */ - static char buf[32]; - - c &= 0377; - if ((c < 128 || !utf_mode) && !control_char(c)) - SNPRINTF1(buf, sizeof(buf), "%c", (int) c); - else if (c == ESC) - strcpy(buf, "ESC"); + /* {{ This buffer can be overrun if LESSBINFMT is a long string. }} */ + static char buf[32]; + + c &= 0377; + if ((c < 128 || !utf_mode) && !control_char(c)) + SNPRINTF1(buf, sizeof(buf), "%c", (int) c); + else if (c == ESC) + strcpy(buf, "ESC"); #if IS_EBCDIC_HOST - else if (!binary_char(c) && c < 64) - SNPRINTF1(buf, sizeof(buf), "^%c", - /* - * This array roughly inverts CONTROL() #defined in less.h, - * and should be kept in sync with CONTROL() and IBM-1047. - */ - "@ABC.I.?...KLMNO" - "PQRS.JH.XY.." - "\\]^_" - "......W[.....EFG" - "..V....D....TU.Z"[c]); + else if (!binary_char(c) && c < 64) + SNPRINTF1(buf, sizeof(buf), "^%c", + /* + * This array roughly inverts CONTROL() #defined in less.h, + * and should be kept in sync with CONTROL() and IBM-1047. + */ + "@ABC.I.?...KLMNO" + "PQRS.JH.XY.." + "\\]^_" + "......W[.....EFG" + "..V....D....TU.Z"[c]); #else - else if (c < 128 && !control_char(c ^ 0100)) - SNPRINTF1(buf, sizeof(buf), "^%c", (int) (c ^ 0100)); + else if (c < 128 && !control_char(c ^ 0100)) + SNPRINTF1(buf, sizeof(buf), "^%c", (int) (c ^ 0100)); #endif - else - SNPRINTF1(buf, sizeof(buf), binfmt, c); - return (buf); + else + SNPRINTF1(buf, sizeof(buf), binfmt, c); + return (buf); } /* * Return the printable form of a UTF-8 character. */ - public char * + public char * prutfchar(ch) - LWCHAR ch; + LWCHAR ch; { - static char buf[32]; - - if (ch == ESC) - strcpy(buf, "ESC"); - else if (ch < 128 && control_char(ch)) - { - if (!control_char(ch ^ 0100)) - SNPRINTF1(buf, sizeof(buf), "^%c", ((char) ch) ^ 0100); - else - SNPRINTF1(buf, sizeof(buf), binfmt, (char) ch); - } else if (is_ubin_char(ch)) - { - SNPRINTF1(buf, sizeof(buf), utfbinfmt, ch); - } else - { - char *p = buf; - if (ch >= 0x80000000) - ch = 0xFFFD; /* REPLACEMENT CHARACTER */ - put_wchar(&p, ch); - *p = '\0'; - } - return (buf); + static char buf[32]; + + if (ch == ESC) + strcpy(buf, "ESC"); + else if (ch < 128 && control_char(ch)) + { + if (!control_char(ch ^ 0100)) + SNPRINTF1(buf, sizeof(buf), "^%c", ((char) ch) ^ 0100); + else + SNPRINTF1(buf, sizeof(buf), binfmt, (char) ch); + } else if (is_ubin_char(ch)) + { + SNPRINTF1(buf, sizeof(buf), utfbinfmt, ch); + } else + { + char *p = buf; + if (ch >= 0x80000000) + ch = 0xFFFD; /* REPLACEMENT CHARACTER */ + put_wchar(&p, ch); + *p = '\0'; + } + return (buf); } /* * Get the length of a UTF-8 character in bytes. */ - public int + public int utf_len(ch) - int ch; + int ch; { - if ((ch & 0x80) == 0) - return 1; - if ((ch & 0xE0) == 0xC0) - return 2; - if ((ch & 0xF0) == 0xE0) - return 3; - if ((ch & 0xF8) == 0xF0) - return 4; - if ((ch & 0xFC) == 0xF8) - return 5; - if ((ch & 0xFE) == 0xFC) - return 6; - /* Invalid UTF-8 encoding. */ - return 1; + if ((ch & 0x80) == 0) + return 1; + if ((ch & 0xE0) == 0xC0) + return 2; + if ((ch & 0xF0) == 0xE0) + return 3; + if ((ch & 0xF8) == 0xF0) + return 4; + if ((ch & 0xFC) == 0xF8) + return 5; + if ((ch & 0xFE) == 0xFC) + return 6; + /* Invalid UTF-8 encoding. */ + return 1; } /* * Does the parameter point to the lead byte of a well-formed UTF-8 character? */ - public int + public int is_utf8_well_formed(ss, slen) - char *ss; - int slen; + char *ss; + int slen; { - int i; - int len; - unsigned char *s = (unsigned char *) ss; - - if (IS_UTF8_INVALID(s[0])) - return (0); - - len = utf_len(s[0]); - if (len > slen) - return (0); - if (len == 1) - return (1); - if (len == 2) - { - if (s[0] < 0xC2) - return (0); - } else - { - unsigned char mask; - mask = (~((1 << (8-len)) - 1)) & 0xFF; - if (s[0] == mask && (s[1] & mask) == 0x80) - return (0); - } - - for (i = 1; i < len; i++) - if (!IS_UTF8_TRAIL(s[i])) - return (0); - return (1); + int i; + int len; + unsigned char *s = (unsigned char *) ss; + + if (IS_UTF8_INVALID(s[0])) + return (0); + + len = utf_len(s[0]); + if (len > slen) + return (0); + if (len == 1) + return (1); + if (len == 2) + { + if (s[0] < 0xC2) + return (0); + } else + { + unsigned char mask; + mask = (~((1 << (8-len)) - 1)) & 0xFF; + if (s[0] == mask && (s[1] & mask) == 0x80) + return (0); + } + + for (i = 1; i < len; i++) + if (!IS_UTF8_TRAIL(s[i])) + return (0); + return (1); } /* * Skip bytes until a UTF-8 lead byte (11xxxxxx) or ASCII byte (0xxxxxxx) is found. */ - public void + public void utf_skip_to_lead(pp, limit) - char **pp; - char *limit; + char **pp; + char *limit; { - do { - ++(*pp); - } while (*pp < limit && !IS_UTF8_LEAD((*pp)[0] & 0377) && !IS_ASCII_OCTET((*pp)[0])); + do { + ++(*pp); + } while (*pp < limit && !IS_UTF8_LEAD((*pp)[0] & 0377) && !IS_ASCII_OCTET((*pp)[0])); } /* * Get the value of a UTF-8 character. */ - public LWCHAR + public LWCHAR get_wchar(p) - constant char *p; + constant char *p; { - switch (utf_len(p[0])) - { - case 1: - default: - /* 0xxxxxxx */ - return (LWCHAR) - (p[0] & 0xFF); - case 2: - /* 110xxxxx 10xxxxxx */ - return (LWCHAR) ( - ((p[0] & 0x1F) << 6) | - (p[1] & 0x3F)); - case 3: - /* 1110xxxx 10xxxxxx 10xxxxxx */ - return (LWCHAR) ( - ((p[0] & 0x0F) << 12) | - ((p[1] & 0x3F) << 6) | - (p[2] & 0x3F)); - case 4: - /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ - return (LWCHAR) ( - ((p[0] & 0x07) << 18) | - ((p[1] & 0x3F) << 12) | - ((p[2] & 0x3F) << 6) | - (p[3] & 0x3F)); - case 5: - /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - return (LWCHAR) ( - ((p[0] & 0x03) << 24) | - ((p[1] & 0x3F) << 18) | - ((p[2] & 0x3F) << 12) | - ((p[3] & 0x3F) << 6) | - (p[4] & 0x3F)); - case 6: - /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - return (LWCHAR) ( - ((p[0] & 0x01) << 30) | - ((p[1] & 0x3F) << 24) | - ((p[2] & 0x3F) << 18) | - ((p[3] & 0x3F) << 12) | - ((p[4] & 0x3F) << 6) | - (p[5] & 0x3F)); - } + switch (utf_len(p[0])) + { + case 1: + default: + /* 0xxxxxxx */ + return (LWCHAR) + (p[0] & 0xFF); + case 2: + /* 110xxxxx 10xxxxxx */ + return (LWCHAR) ( + ((p[0] & 0x1F) << 6) | + (p[1] & 0x3F)); + case 3: + /* 1110xxxx 10xxxxxx 10xxxxxx */ + return (LWCHAR) ( + ((p[0] & 0x0F) << 12) | + ((p[1] & 0x3F) << 6) | + (p[2] & 0x3F)); + case 4: + /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + return (LWCHAR) ( + ((p[0] & 0x07) << 18) | + ((p[1] & 0x3F) << 12) | + ((p[2] & 0x3F) << 6) | + (p[3] & 0x3F)); + case 5: + /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + return (LWCHAR) ( + ((p[0] & 0x03) << 24) | + ((p[1] & 0x3F) << 18) | + ((p[2] & 0x3F) << 12) | + ((p[3] & 0x3F) << 6) | + (p[4] & 0x3F)); + case 6: + /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + return (LWCHAR) ( + ((p[0] & 0x01) << 30) | + ((p[1] & 0x3F) << 24) | + ((p[2] & 0x3F) << 18) | + ((p[3] & 0x3F) << 12) | + ((p[4] & 0x3F) << 6) | + (p[5] & 0x3F)); + } } /* * Store a character into a UTF-8 string. */ - public void + public void put_wchar(pp, ch) - char **pp; - LWCHAR ch; + char **pp; + LWCHAR ch; { - if (!utf_mode || ch < 0x80) - { - /* 0xxxxxxx */ - *(*pp)++ = (char) ch; - } else if (ch < 0x800) - { - /* 110xxxxx 10xxxxxx */ - *(*pp)++ = (char) (0xC0 | ((ch >> 6) & 0x1F)); - *(*pp)++ = (char) (0x80 | (ch & 0x3F)); - } else if (ch < 0x10000) - { - /* 1110xxxx 10xxxxxx 10xxxxxx */ - *(*pp)++ = (char) (0xE0 | ((ch >> 12) & 0x0F)); - *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); - *(*pp)++ = (char) (0x80 | (ch & 0x3F)); - } else if (ch < 0x200000) - { - /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ - *(*pp)++ = (char) (0xF0 | ((ch >> 18) & 0x07)); - *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); - *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); - *(*pp)++ = (char) (0x80 | (ch & 0x3F)); - } else if (ch < 0x4000000) - { - /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - *(*pp)++ = (char) (0xF0 | ((ch >> 24) & 0x03)); - *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F)); - *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); - *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); - *(*pp)++ = (char) (0x80 | (ch & 0x3F)); - } else - { - /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - *(*pp)++ = (char) (0xF0 | ((ch >> 30) & 0x01)); - *(*pp)++ = (char) (0x80 | ((ch >> 24) & 0x3F)); - *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F)); - *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); - *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); - *(*pp)++ = (char) (0x80 | (ch & 0x3F)); - } + if (!utf_mode || ch < 0x80) + { + /* 0xxxxxxx */ + *(*pp)++ = (char) ch; + } else if (ch < 0x800) + { + /* 110xxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xC0 | ((ch >> 6) & 0x1F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } else if (ch < 0x10000) + { + /* 1110xxxx 10xxxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xE0 | ((ch >> 12) & 0x0F)); + *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } else if (ch < 0x200000) + { + /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xF0 | ((ch >> 18) & 0x07)); + *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } else if (ch < 0x4000000) + { + /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xF0 | ((ch >> 24) & 0x03)); + *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } else + { + /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xF0 | ((ch >> 30) & 0x01)); + *(*pp)++ = (char) (0x80 | ((ch >> 24) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } } /* * Step forward or backward one character in a string. */ - public LWCHAR + public LWCHAR step_char(pp, dir, limit) - char **pp; - signed int dir; - constant char *limit; + char **pp; + signed int dir; + constant char *limit; { - LWCHAR ch; - int len; - char *p = *pp; - - if (!utf_mode) - { - /* It's easy if chars are one byte. */ - if (dir > 0) - ch = (LWCHAR) (unsigned char) ((p < limit) ? *p++ : 0); - else - ch = (LWCHAR) (unsigned char) ((p > limit) ? *--p : 0); - } else if (dir > 0) - { - len = utf_len(*p); - if (p + len > limit) - { - ch = 0; - p = (char *) limit; - } else - { - ch = get_wchar(p); - p += len; - } - } else - { - while (p > limit && IS_UTF8_TRAIL(p[-1])) - p--; - if (p > limit) - ch = get_wchar(--p); - else - ch = 0; - } - *pp = p; - return ch; + LWCHAR ch; + int len; + char *p = *pp; + + if (!utf_mode) + { + /* It's easy if chars are one byte. */ + if (dir > 0) + ch = (LWCHAR) (unsigned char) ((p < limit) ? *p++ : 0); + else + ch = (LWCHAR) (unsigned char) ((p > limit) ? *--p : 0); + } else if (dir > 0) + { + len = utf_len(*p); + if (p + len > limit) + { + ch = 0; + p = (char *) limit; + } else + { + ch = get_wchar(p); + p += len; + } + } else + { + while (p > limit && IS_UTF8_TRAIL(p[-1])) + p--; + if (p > limit) + ch = get_wchar(--p); + else + ch = 0; + } + *pp = p; + return ch; } /* @@ -732,9 +732,9 @@ step_char(pp, dir, limit) */ #define DECLARE_RANGE_TABLE_START(name) \ - static struct wchar_range name##_array[] = { + static struct wchar_range name##_array[] = { #define DECLARE_RANGE_TABLE_END(name) \ - }; struct wchar_range_table name##_table = { name##_array, sizeof(name##_array)/sizeof(*name##_array) }; + }; struct wchar_range_table name##_table = { name##_array, sizeof(name##_array)/sizeof(*name##_array) }; DECLARE_RANGE_TABLE_START(compose) #include "compose.uni" @@ -754,80 +754,80 @@ DECLARE_RANGE_TABLE_END(fmt) /* comb_table is special pairs, not ranges. */ static struct wchar_range comb_table[] = { - {0x0644,0x0622}, {0x0644,0x0623}, {0x0644,0x0625}, {0x0644,0x0627}, + {0x0644,0x0622}, {0x0644,0x0623}, {0x0644,0x0625}, {0x0644,0x0627}, }; - static int + static int is_in_table(ch, table) - LWCHAR ch; - struct wchar_range_table *table; + LWCHAR ch; + struct wchar_range_table *table; { - int hi; - int lo; - - /* Binary search in the table. */ - if (ch < table->table[0].first) - return 0; - lo = 0; - hi = table->count - 1; - while (lo <= hi) - { - int mid = (lo + hi) / 2; - if (ch > table->table[mid].last) - lo = mid + 1; - else if (ch < table->table[mid].first) - hi = mid - 1; - else - return 1; - } - return 0; + int hi; + int lo; + + /* Binary search in the table. */ + if (ch < table->table[0].first) + return 0; + lo = 0; + hi = table->count - 1; + while (lo <= hi) + { + int mid = (lo + hi) / 2; + if (ch > table->table[mid].last) + lo = mid + 1; + else if (ch < table->table[mid].first) + hi = mid - 1; + else + return 1; + } + return 0; } /* * Is a character a UTF-8 composing character? * If a composing character follows any char, the two combine into one glyph. */ - public int + public int is_composing_char(ch) - LWCHAR ch; + LWCHAR ch; { - return is_in_table(ch, &compose_table) || - (bs_mode != BS_CONTROL && is_in_table(ch, &fmt_table)); + return is_in_table(ch, &compose_table) || + (bs_mode != BS_CONTROL && is_in_table(ch, &fmt_table)); } /* * Should this UTF-8 character be treated as binary? */ - public int + public int is_ubin_char(ch) - LWCHAR ch; + LWCHAR ch; { - int ubin = is_in_table(ch, &ubin_table) || - (bs_mode == BS_CONTROL && is_in_table(ch, &fmt_table)); + int ubin = is_in_table(ch, &ubin_table) || + (bs_mode == BS_CONTROL && is_in_table(ch, &fmt_table)); #if MSDOS_COMPILER==WIN32C - if (!ubin && utf_mode == 2 && ch < 0x10000) - { - /* - * Consider it binary if it can't be converted. - */ - BOOL used_default = TRUE; - WideCharToMultiByte(GetConsoleOutputCP(), WC_NO_BEST_FIT_CHARS, (LPCWSTR) &ch, 1, NULL, 0, NULL, &used_default); - if (used_default) - ubin = 1; - } + if (!ubin && utf_mode == 2 && ch < 0x10000) + { + /* + * Consider it binary if it can't be converted. + */ + BOOL used_default = TRUE; + WideCharToMultiByte(GetConsoleOutputCP(), WC_NO_BEST_FIT_CHARS, (LPCWSTR) &ch, 1, NULL, 0, NULL, &used_default); + if (used_default) + ubin = 1; + } #endif - return ubin; + return ubin; } /* * Is this a double width UTF-8 character? */ - public int + public int is_wide_char(ch) - LWCHAR ch; + LWCHAR ch; { - return is_in_table(ch, &wide_table); + return is_in_table(ch, &wide_table); } /* @@ -835,19 +835,18 @@ is_wide_char(ch) * A combining char acts like an ordinary char, but if it follows * a specific char (not any char), the two combine into one glyph. */ - public int + public int is_combining_char(ch1, ch2) - LWCHAR ch1; - LWCHAR ch2; + LWCHAR ch1; + LWCHAR ch2; { - /* The table is small; use linear search. */ - int i; - for (i = 0; i < sizeof(comb_table)/sizeof(*comb_table); i++) - { - if (ch1 == comb_table[i].first && - ch2 == comb_table[i].last) - return 1; - } - return 0; + /* The table is small; use linear search. */ + int i; + for (i = 0; i < sizeof(comb_table)/sizeof(*comb_table); i++) + { + if (ch1 == comb_table[i].first && + ch2 == comb_table[i].last) + return 1; + } + return 0; } - diff --git a/cmdbuf.c b/cmdbuf.c index 9cc1f3e..83f2211 100644 --- a/cmdbuf.c +++ b/cmdbuf.c @@ -67,27 +67,27 @@ public char closequote = '"'; */ struct mlist { - struct mlist *next; - struct mlist *prev; - struct mlist *curr_mp; - char *string; - int modified; + struct mlist *next; + struct mlist *prev; + struct mlist *curr_mp; + char *string; + int modified; }; /* * These are the various command histories that exist. */ -struct mlist mlist_search = - { &mlist_search, &mlist_search, &mlist_search, NULL, 0 }; +struct mlist mlist_search = + { &mlist_search, &mlist_search, &mlist_search, NULL, 0 }; public void *ml_search = (void *) &mlist_search; -struct mlist mlist_examine = - { &mlist_examine, &mlist_examine, &mlist_examine, NULL, 0 }; +struct mlist mlist_examine = + { &mlist_examine, &mlist_examine, &mlist_examine, NULL, 0 }; public void *ml_examine = (void *) &mlist_examine; #if SHELL_ESCAPE || PIPEC -struct mlist mlist_shell = - { &mlist_shell, &mlist_shell, &mlist_shell, NULL, 0 }; +struct mlist mlist_shell = + { &mlist_shell, &mlist_shell, &mlist_shell, NULL, 0 }; public void *ml_shell = (void *) &mlist_shell; #endif @@ -116,74 +116,74 @@ static int cmd_mbc_buf_index; /* * Reset command buffer (to empty). */ - public void + public void cmd_reset(VOID_PARAM) { - cp = cmdbuf; - *cp = '\0'; - cmd_col = 0; - cmd_offset = 0; - literal = 0; - cmd_mbc_buf_len = 0; - updown_match = -1; + cp = cmdbuf; + *cp = '\0'; + cmd_col = 0; + cmd_offset = 0; + literal = 0; + cmd_mbc_buf_len = 0; + updown_match = -1; } /* * Clear command line. */ - public void + public void clear_cmd(VOID_PARAM) { - cmd_col = prompt_col = 0; - cmd_mbc_buf_len = 0; - updown_match = -1; + cmd_col = prompt_col = 0; + cmd_mbc_buf_len = 0; + updown_match = -1; } /* * Display a string, usually as a prompt for input into the command buffer. */ - public void + public void cmd_putstr(s) - constant char *s; + constant char *s; { - LWCHAR prev_ch = 0; - LWCHAR ch; - constant char *endline = s + strlen(s); - while (*s != '\0') - { - char *ns = (char *) s; - int width; - ch = step_char(&ns, +1, endline); - while (s < ns) - putchr(*s++); - if (!utf_mode) - width = 1; - else if (is_composing_char(ch) || is_combining_char(prev_ch, ch)) - width = 0; - else - width = is_wide_char(ch) ? 2 : 1; - cmd_col += width; - prompt_col += width; - prev_ch = ch; - } + LWCHAR prev_ch = 0; + LWCHAR ch; + constant char *endline = s + strlen(s); + while (*s != '\0') + { + char *ns = (char *) s; + int width; + ch = step_char(&ns, +1, endline); + while (s < ns) + putchr(*s++); + if (!utf_mode) + width = 1; + else if (is_composing_char(ch) || is_combining_char(prev_ch, ch)) + width = 0; + else + width = is_wide_char(ch) ? 2 : 1; + cmd_col += width; + prompt_col += width; + prev_ch = ch; + } } /* * How many characters are in the command buffer? */ - public int + public int len_cmdbuf(VOID_PARAM) { - char *s = cmdbuf; - char *endline = s + strlen(s); - int len = 0; - - while (*s != '\0') - { - step_char(&s, +1, endline); - len++; - } - return (len); + char *s = cmdbuf; + char *endline = s + strlen(s); + int len = 0; + + while (*s != '\0') + { + step_char(&s, +1, endline); + len++; + } + return (len); } /* @@ -191,472 +191,472 @@ len_cmdbuf(VOID_PARAM) * {{ Returning pwidth and bswidth separately is a historical artifact * since they're always the same. Maybe clean this up someday. }} */ - static char * + static char * cmd_step_common(p, ch, len, pwidth, bswidth) - char *p; - LWCHAR ch; - int len; - int *pwidth; - int *bswidth; + char *p; + LWCHAR ch; + int len; + int *pwidth; + int *bswidth; { - char *pr; - int width; - - if (len == 1) - { - pr = prchar((int) ch); - width = (int) strlen(pr); - } else - { - pr = prutfchar(ch); - if (is_composing_char(ch)) - width = 0; - else if (is_ubin_char(ch)) - width = (int) strlen(pr); - else - { - LWCHAR prev_ch = step_char(&p, -1, cmdbuf); - if (is_combining_char(prev_ch, ch)) - width = 0; - else - width = is_wide_char(ch) ? 2 : 1; - } - } - if (pwidth != NULL) - *pwidth = width; - if (bswidth != NULL) - *bswidth = width; - return (pr); + char *pr; + int width; + + if (len == 1) + { + pr = prchar((int) ch); + width = (int) strlen(pr); + } else + { + pr = prutfchar(ch); + if (is_composing_char(ch)) + width = 0; + else if (is_ubin_char(ch)) + width = (int) strlen(pr); + else + { + LWCHAR prev_ch = step_char(&p, -1, cmdbuf); + if (is_combining_char(prev_ch, ch)) + width = 0; + else + width = is_wide_char(ch) ? 2 : 1; + } + } + if (pwidth != NULL) + *pwidth = width; + if (bswidth != NULL) + *bswidth = width; + return (pr); } /* * Step a pointer one character right in the command buffer. */ - static char * + static char * cmd_step_right(pp, pwidth, bswidth) - char **pp; - int *pwidth; - int *bswidth; + char **pp; + int *pwidth; + int *bswidth; { - char *p = *pp; - LWCHAR ch = step_char(pp, +1, p + strlen(p)); + char *p = *pp; + LWCHAR ch = step_char(pp, +1, p + strlen(p)); - return cmd_step_common(p, ch, *pp - p, pwidth, bswidth); + return cmd_step_common(p, ch, *pp - p, pwidth, bswidth); } /* * Step a pointer one character left in the command buffer. */ - static char * + static char * cmd_step_left(pp, pwidth, bswidth) - char **pp; - int *pwidth; - int *bswidth; + char **pp; + int *pwidth; + int *bswidth; { - char *p = *pp; - LWCHAR ch = step_char(pp, -1, cmdbuf); + char *p = *pp; + LWCHAR ch = step_char(pp, -1, cmdbuf); - return cmd_step_common(*pp, ch, p - *pp, pwidth, bswidth); + return cmd_step_common(*pp, ch, p - *pp, pwidth, bswidth); } /* * Put the cursor at "home" (just after the prompt), * and set cp to the corresponding char in cmdbuf. */ - static void + static void cmd_home(VOID_PARAM) { - while (cmd_col > prompt_col) - { - int width, bswidth; + while (cmd_col > prompt_col) + { + int width, bswidth; - cmd_step_left(&cp, &width, &bswidth); - while (bswidth-- > 0) - putbs(); - cmd_col -= width; - } + cmd_step_left(&cp, &width, &bswidth); + while (bswidth-- > 0) + putbs(); + cmd_col -= width; + } - cp = &cmdbuf[cmd_offset]; + cp = &cmdbuf[cmd_offset]; } /* * Repaint the line from cp onwards. * Then position the cursor just after the char old_cp (a pointer into cmdbuf). */ - public void + public void cmd_repaint(old_cp) - constant char *old_cp; + constant char *old_cp; { - /* - * Repaint the line from the current position. - */ - if (old_cp == NULL) - { - old_cp = cp; - cmd_home(); - } - clear_eol(); - while (*cp != '\0') - { - char *np = cp; - int width; - char *pr = cmd_step_right(&np, &width, NULL); - if (cmd_col + width >= sc_width) - break; - cp = np; - putstr(pr); - cmd_col += width; - } - while (*cp != '\0') - { - char *np = cp; - int width; - char *pr = cmd_step_right(&np, &width, NULL); - if (width > 0) - break; - cp = np; - putstr(pr); - } - - /* - * Back up the cursor to the correct position. - */ - while (cp > old_cp) - cmd_left(); + /* + * Repaint the line from the current position. + */ + if (old_cp == NULL) + { + old_cp = cp; + cmd_home(); + } + clear_eol(); + while (*cp != '\0') + { + char *np = cp; + int width; + char *pr = cmd_step_right(&np, &width, NULL); + if (cmd_col + width >= sc_width) + break; + cp = np; + putstr(pr); + cmd_col += width; + } + while (*cp != '\0') + { + char *np = cp; + int width; + char *pr = cmd_step_right(&np, &width, NULL); + if (width > 0) + break; + cp = np; + putstr(pr); + } + + /* + * Back up the cursor to the correct position. + */ + while (cp > old_cp) + cmd_left(); } /* * Shift the cmdbuf display left a half-screen. */ - static void + static void cmd_lshift(VOID_PARAM) { - char *s; - char *save_cp; - int cols; - - /* - * Start at the first displayed char, count how far to the - * right we'd have to move to reach the center of the screen. - */ - s = cmdbuf + cmd_offset; - cols = 0; - while (cols < (sc_width - prompt_col) / 2 && *s != '\0') - { - int width; - cmd_step_right(&s, &width, NULL); - cols += width; - } - while (*s != '\0') - { - int width; - char *ns = s; - cmd_step_right(&ns, &width, NULL); - if (width > 0) - break; - s = ns; - } - - cmd_offset = (int) (s - cmdbuf); - save_cp = cp; - cmd_home(); - cmd_repaint(save_cp); + char *s; + char *save_cp; + int cols; + + /* + * Start at the first displayed char, count how far to the + * right we'd have to move to reach the center of the screen. + */ + s = cmdbuf + cmd_offset; + cols = 0; + while (cols < (sc_width - prompt_col) / 2 && *s != '\0') + { + int width; + cmd_step_right(&s, &width, NULL); + cols += width; + } + while (*s != '\0') + { + int width; + char *ns = s; + cmd_step_right(&ns, &width, NULL); + if (width > 0) + break; + s = ns; + } + + cmd_offset = (int) (s - cmdbuf); + save_cp = cp; + cmd_home(); + cmd_repaint(save_cp); } /* * Shift the cmdbuf display right a half-screen. */ - static void + static void cmd_rshift(VOID_PARAM) { - char *s; - char *save_cp; - int cols; - - /* - * Start at the first displayed char, count how far to the - * left we'd have to move to traverse a half-screen width - * of displayed characters. - */ - s = cmdbuf + cmd_offset; - cols = 0; - while (cols < (sc_width - prompt_col) / 2 && s > cmdbuf) - { - int width; - cmd_step_left(&s, &width, NULL); - cols += width; - } - - cmd_offset = (int) (s - cmdbuf); - save_cp = cp; - cmd_home(); - cmd_repaint(save_cp); + char *s; + char *save_cp; + int cols; + + /* + * Start at the first displayed char, count how far to the + * left we'd have to move to traverse a half-screen width + * of displayed characters. + */ + s = cmdbuf + cmd_offset; + cols = 0; + while (cols < (sc_width - prompt_col) / 2 && s > cmdbuf) + { + int width; + cmd_step_left(&s, &width, NULL); + cols += width; + } + + cmd_offset = (int) (s - cmdbuf); + save_cp = cp; + cmd_home(); + cmd_repaint(save_cp); } /* * Move cursor right one character. */ - static int + static int cmd_right(VOID_PARAM) { - char *pr; - char *ncp; - int width; - - if (*cp == '\0') - { - /* Already at the end of the line. */ - return (CC_OK); - } - ncp = cp; - pr = cmd_step_right(&ncp, &width, NULL); - if (cmd_col + width >= sc_width) - cmd_lshift(); - else if (cmd_col + width == sc_width - 1 && cp[1] != '\0') - cmd_lshift(); - cp = ncp; - cmd_col += width; - putstr(pr); - while (*cp != '\0') - { - pr = cmd_step_right(&ncp, &width, NULL); - if (width > 0) - break; - putstr(pr); - cp = ncp; - } - return (CC_OK); + char *pr; + char *ncp; + int width; + + if (*cp == '\0') + { + /* Already at the end of the line. */ + return (CC_OK); + } + ncp = cp; + pr = cmd_step_right(&ncp, &width, NULL); + if (cmd_col + width >= sc_width) + cmd_lshift(); + else if (cmd_col + width == sc_width - 1 && cp[1] != '\0') + cmd_lshift(); + cp = ncp; + cmd_col += width; + putstr(pr); + while (*cp != '\0') + { + pr = cmd_step_right(&ncp, &width, NULL); + if (width > 0) + break; + putstr(pr); + cp = ncp; + } + return (CC_OK); } /* * Move cursor left one character. */ - static int + static int cmd_left(VOID_PARAM) { - char *ncp; - int width = 0; - int bswidth = 0; - - if (cp <= cmdbuf) - { - /* Already at the beginning of the line */ - return (CC_OK); - } - ncp = cp; - while (ncp > cmdbuf) - { - cmd_step_left(&ncp, &width, &bswidth); - if (width > 0) - break; - } - if (cmd_col < prompt_col + width) - cmd_rshift(); - cp = ncp; - cmd_col -= width; - while (bswidth-- > 0) - putbs(); - return (CC_OK); + char *ncp; + int width = 0; + int bswidth = 0; + + if (cp <= cmdbuf) + { + /* Already at the beginning of the line */ + return (CC_OK); + } + ncp = cp; + while (ncp > cmdbuf) + { + cmd_step_left(&ncp, &width, &bswidth); + if (width > 0) + break; + } + if (cmd_col < prompt_col + width) + cmd_rshift(); + cp = ncp; + cmd_col -= width; + while (bswidth-- > 0) + putbs(); + return (CC_OK); } /* * Insert a char into the command buffer, at the current position. */ - static int + static int cmd_ichar(cs, clen) - char *cs; - int clen; + char *cs; + int clen; { - char *s; - - if (strlen(cmdbuf) + clen >= sizeof(cmdbuf)-1) - { - /* No room in the command buffer for another char. */ - bell(); - return (CC_ERROR); - } - - /* - * Make room for the new character (shift the tail of the buffer right). - */ - for (s = &cmdbuf[strlen(cmdbuf)]; s >= cp; s--) - s[clen] = s[0]; - /* - * Insert the character into the buffer. - */ - for (s = cp; s < cp + clen; s++) - *s = *cs++; - /* - * Reprint the tail of the line from the inserted char. - */ - updown_match = -1; - cmd_repaint(cp); - cmd_right(); - return (CC_OK); + char *s; + + if (strlen(cmdbuf) + clen >= sizeof(cmdbuf)-1) + { + /* No room in the command buffer for another char. */ + bell(); + return (CC_ERROR); + } + + /* + * Make room for the new character (shift the tail of the buffer right). + */ + for (s = &cmdbuf[strlen(cmdbuf)]; s >= cp; s--) + s[clen] = s[0]; + /* + * Insert the character into the buffer. + */ + for (s = cp; s < cp + clen; s++) + *s = *cs++; + /* + * Reprint the tail of the line from the inserted char. + */ + updown_match = -1; + cmd_repaint(cp); + cmd_right(); + return (CC_OK); } /* * Backspace in the command buffer. * Delete the char to the left of the cursor. */ - static int + static int cmd_erase(VOID_PARAM) { - char *s; - int clen; - - if (cp == cmdbuf) - { - /* - * Backspace past beginning of the buffer: - * this usually means abort the command. - */ - return (CC_QUIT); - } - /* - * Move cursor left (to the char being erased). - */ - s = cp; - cmd_left(); - clen = (int) (s - cp); - - /* - * Remove the char from the buffer (shift the buffer left). - */ - for (s = cp; ; s++) - { - s[0] = s[clen]; - if (s[0] == '\0') - break; - } - - /* - * Repaint the buffer after the erased char. - */ - updown_match = -1; - cmd_repaint(cp); - - /* - * We say that erasing the entire command string causes us - * to abort the current command, if CF_QUIT_ON_ERASE is set. - */ - if ((curr_cmdflags & CF_QUIT_ON_ERASE) && cp == cmdbuf && *cp == '\0') - return (CC_QUIT); - return (CC_OK); + char *s; + int clen; + + if (cp == cmdbuf) + { + /* + * Backspace past beginning of the buffer: + * this usually means abort the command. + */ + return (CC_QUIT); + } + /* + * Move cursor left (to the char being erased). + */ + s = cp; + cmd_left(); + clen = (int) (s - cp); + + /* + * Remove the char from the buffer (shift the buffer left). + */ + for (s = cp; ; s++) + { + s[0] = s[clen]; + if (s[0] == '\0') + break; + } + + /* + * Repaint the buffer after the erased char. + */ + updown_match = -1; + cmd_repaint(cp); + + /* + * We say that erasing the entire command string causes us + * to abort the current command, if CF_QUIT_ON_ERASE is set. + */ + if ((curr_cmdflags & CF_QUIT_ON_ERASE) && cp == cmdbuf && *cp == '\0') + return (CC_QUIT); + return (CC_OK); } /* * Delete the char under the cursor. */ - static int + static int cmd_delete(VOID_PARAM) { - if (*cp == '\0') - { - /* At end of string; there is no char under the cursor. */ - return (CC_OK); - } - /* - * Move right, then use cmd_erase. - */ - cmd_right(); - cmd_erase(); - return (CC_OK); + if (*cp == '\0') + { + /* At end of string; there is no char under the cursor. */ + return (CC_OK); + } + /* + * Move right, then use cmd_erase. + */ + cmd_right(); + cmd_erase(); + return (CC_OK); } /* * Delete the "word" to the left of the cursor. */ - static int + static int cmd_werase(VOID_PARAM) { - if (cp > cmdbuf && cp[-1] == ' ') - { - /* - * If the char left of cursor is a space, - * erase all the spaces left of cursor (to the first non-space). - */ - while (cp > cmdbuf && cp[-1] == ' ') - (void) cmd_erase(); - } else - { - /* - * If the char left of cursor is not a space, - * erase all the nonspaces left of cursor (the whole "word"). - */ - while (cp > cmdbuf && cp[-1] != ' ') - (void) cmd_erase(); - } - return (CC_OK); + if (cp > cmdbuf && cp[-1] == ' ') + { + /* + * If the char left of cursor is a space, + * erase all the spaces left of cursor (to the first non-space). + */ + while (cp > cmdbuf && cp[-1] == ' ') + (void) cmd_erase(); + } else + { + /* + * If the char left of cursor is not a space, + * erase all the nonspaces left of cursor (the whole "word"). + */ + while (cp > cmdbuf && cp[-1] != ' ') + (void) cmd_erase(); + } + return (CC_OK); } /* * Delete the "word" under the cursor. */ - static int + static int cmd_wdelete(VOID_PARAM) { - if (*cp == ' ') - { - /* - * If the char under the cursor is a space, - * delete it and all the spaces right of cursor. - */ - while (*cp == ' ') - (void) cmd_delete(); - } else - { - /* - * If the char under the cursor is not a space, - * delete it and all nonspaces right of cursor (the whole word). - */ - while (*cp != ' ' && *cp != '\0') - (void) cmd_delete(); - } - return (CC_OK); + if (*cp == ' ') + { + /* + * If the char under the cursor is a space, + * delete it and all the spaces right of cursor. + */ + while (*cp == ' ') + (void) cmd_delete(); + } else + { + /* + * If the char under the cursor is not a space, + * delete it and all nonspaces right of cursor (the whole word). + */ + while (*cp != ' ' && *cp != '\0') + (void) cmd_delete(); + } + return (CC_OK); } /* * Delete all chars in the command buffer. */ - static int + static int cmd_kill(VOID_PARAM) { - if (cmdbuf[0] == '\0') - { - /* Buffer is already empty; abort the current command. */ - return (CC_QUIT); - } - cmd_offset = 0; - cmd_home(); - *cp = '\0'; - updown_match = -1; - cmd_repaint(cp); - - /* - * We say that erasing the entire command string causes us - * to abort the current command, if CF_QUIT_ON_ERASE is set. - */ - if (curr_cmdflags & CF_QUIT_ON_ERASE) - return (CC_QUIT); - return (CC_OK); + if (cmdbuf[0] == '\0') + { + /* Buffer is already empty; abort the current command. */ + return (CC_QUIT); + } + cmd_offset = 0; + cmd_home(); + *cp = '\0'; + updown_match = -1; + cmd_repaint(cp); + + /* + * We say that erasing the entire command string causes us + * to abort the current command, if CF_QUIT_ON_ERASE is set. + */ + if (curr_cmdflags & CF_QUIT_ON_ERASE) + return (CC_QUIT); + return (CC_OK); } /* * Select an mlist structure to be the current command history. */ - public void + public void set_mlist(mlist, cmdflags) - void *mlist; - int cmdflags; + void *mlist; + int cmdflags; { #if CMD_HISTORY - curr_mlist = (struct mlist *) mlist; - curr_cmdflags = cmdflags; + curr_mlist = (struct mlist *) mlist; + curr_cmdflags = cmdflags; - /* Make sure the next up-arrow moves to the last string in the mlist. */ - if (curr_mlist != NULL) - curr_mlist->curr_mp = curr_mlist; + /* Make sure the next up-arrow moves to the last string in the mlist. */ + if (curr_mlist != NULL) + curr_mlist->curr_mp = curr_mlist; #endif } @@ -666,146 +666,146 @@ set_mlist(mlist, cmdflags) * Only consider entries whose first updown_match chars are equal to * cmdbuf's corresponding chars. */ - static int + static int cmd_updown(action) - int action; + int action; { - constant char *s; - struct mlist *ml; - - if (curr_mlist == NULL) - { - /* - * The current command has no history list. - */ - bell(); - return (CC_OK); - } - - if (updown_match < 0) - { - updown_match = (int) (cp - cmdbuf); - } - - /* - * Find the next history entry which matches. - */ - for (ml = curr_mlist->curr_mp;;) - { - ml = (action == EC_UP) ? ml->prev : ml->next; - if (ml == curr_mlist) - { - /* - * We reached the end (or beginning) of the list. - */ - break; - } - if (strncmp(cmdbuf, ml->string, updown_match) == 0) - { - /* - * This entry matches; stop here. - * Copy the entry into cmdbuf and echo it on the screen. - */ - curr_mlist->curr_mp = ml; - s = ml->string; - if (s == NULL) - s = ""; - cmd_offset = 0; - cmd_home(); - clear_eol(); - strcpy(cmdbuf, s); - for (cp = cmdbuf; *cp != '\0'; ) - cmd_right(); - return (CC_OK); - } - } - /* - * We didn't find a history entry that matches. - */ - bell(); - return (CC_OK); + constant char *s; + struct mlist *ml; + + if (curr_mlist == NULL) + { + /* + * The current command has no history list. + */ + bell(); + return (CC_OK); + } + + if (updown_match < 0) + { + updown_match = (int) (cp - cmdbuf); + } + + /* + * Find the next history entry which matches. + */ + for (ml = curr_mlist->curr_mp;;) + { + ml = (action == EC_UP) ? ml->prev : ml->next; + if (ml == curr_mlist) + { + /* + * We reached the end (or beginning) of the list. + */ + break; + } + if (strncmp(cmdbuf, ml->string, updown_match) == 0) + { + /* + * This entry matches; stop here. + * Copy the entry into cmdbuf and echo it on the screen. + */ + curr_mlist->curr_mp = ml; + s = ml->string; + if (s == NULL) + s = ""; + cmd_offset = 0; + cmd_home(); + clear_eol(); + strcpy(cmdbuf, s); + for (cp = cmdbuf; *cp != '\0'; ) + cmd_right(); + return (CC_OK); + } + } + /* + * We didn't find a history entry that matches. + */ + bell(); + return (CC_OK); } #endif /* * */ - static void + static void ml_link(mlist, ml) - struct mlist *mlist; - struct mlist *ml; + struct mlist *mlist; + struct mlist *ml; { - ml->next = mlist; - ml->prev = mlist->prev; - mlist->prev->next = ml; - mlist->prev = ml; + ml->next = mlist; + ml->prev = mlist->prev; + mlist->prev->next = ml; + mlist->prev = ml; } /* * */ - static void + static void ml_unlink(ml) - struct mlist *ml; + struct mlist *ml; { - ml->prev->next = ml->next; - ml->next->prev = ml->prev; + ml->prev->next = ml->next; + ml->next->prev = ml->prev; } /* * Add a string to an mlist. */ - public void + public void cmd_addhist(mlist, cmd, modified) - struct mlist *mlist; - constant char *cmd; - int modified; + struct mlist *mlist; + constant char *cmd; + int modified; { #if CMD_HISTORY - struct mlist *ml; - - /* - * Don't save a trivial command. - */ - if (strlen(cmd) == 0) - return; - - if (no_hist_dups) - { - struct mlist *next = NULL; - for (ml = mlist->next; ml->string != NULL; ml = next) - { - next = ml->next; - if (strcmp(ml->string, cmd) == 0) - { - ml_unlink(ml); - free(ml->string); - free(ml); - } - } - } - - /* - * Save the command unless it's a duplicate of the - * last command in the history. - */ - ml = mlist->prev; - if (ml == mlist || strcmp(ml->string, cmd) != 0) - { - /* - * Did not find command in history. - * Save the command and put it at the end of the history list. - */ - ml = (struct mlist *) ecalloc(1, sizeof(struct mlist)); - ml->string = save(cmd); - ml->modified = modified; - ml_link(mlist, ml); - } - /* - * Point to the cmd just after the just-accepted command. - * Thus, an UPARROW will always retrieve the previous command. - */ - mlist->curr_mp = ml->next; + struct mlist *ml; + + /* + * Don't save a trivial command. + */ + if (strlen(cmd) == 0) + return; + + if (no_hist_dups) + { + struct mlist *next = NULL; + for (ml = mlist->next; ml->string != NULL; ml = next) + { + next = ml->next; + if (strcmp(ml->string, cmd) == 0) + { + ml_unlink(ml); + free(ml->string); + free(ml); + } + } + } + + /* + * Save the command unless it's a duplicate of the + * last command in the history. + */ + ml = mlist->prev; + if (ml == mlist || strcmp(ml->string, cmd) != 0) + { + /* + * Did not find command in history. + * Save the command and put it at the end of the history list. + */ + ml = (struct mlist *) ecalloc(1, sizeof(struct mlist)); + ml->string = save(cmd); + ml->modified = modified; + ml_link(mlist, ml); + } + /* + * Point to the cmd just after the just-accepted command. + * Thus, an UPARROW will always retrieve the previous command. + */ + mlist->curr_mp = ml->next; #endif } @@ -813,17 +813,17 @@ cmd_addhist(mlist, cmd, modified) * Accept the command in the command buffer. * Add it to the currently selected history list. */ - public void + public void cmd_accept(VOID_PARAM) { #if CMD_HISTORY - /* - * Nothing to do if there is no currently selected history list. - */ - if (curr_mlist == NULL || curr_mlist == ml_examine) - return; - cmd_addhist(curr_mlist, cmdbuf, 1); - curr_mlist->modified = 1; + /* + * Nothing to do if there is no currently selected history list. + */ + if (curr_mlist == NULL || curr_mlist == ml_examine) + return; + cmd_addhist(curr_mlist, cmdbuf, 1); + curr_mlist->modified = 1; #endif } @@ -835,139 +835,139 @@ cmd_accept(VOID_PARAM) * CC_OK Line edit function done. * CC_QUIT The char requests the current command to be aborted. */ - static int + static int cmd_edit(c) - int c; + int c; { - int action; - int flags; + int action; + int flags; #if TAB_COMPLETE_FILENAME #define not_in_completion() in_completion = 0 #else #define not_in_completion(VOID_PARAM) #endif - - /* - * See if the char is indeed a line-editing command. - */ - flags = 0; + + /* + * See if the char is indeed a line-editing command. + */ + flags = 0; #if CMD_HISTORY - if (curr_mlist == NULL) - /* - * No current history; don't accept history manipulation cmds. - */ - flags |= ECF_NOHISTORY; + if (curr_mlist == NULL) + /* + * No current history; don't accept history manipulation cmds. + */ + flags |= ECF_NOHISTORY; #endif #if TAB_COMPLETE_FILENAME - if (curr_mlist == ml_search) - /* - * In a search command; don't accept file-completion cmds. - */ - flags |= ECF_NOCOMPLETE; + if (curr_mlist == ml_search) + /* + * In a search command; don't accept file-completion cmds. + */ + flags |= ECF_NOCOMPLETE; #endif - action = editchar(c, flags); - - switch (action) - { - case A_NOACTION: - return (CC_OK); - case EC_RIGHT: - not_in_completion(); - return (cmd_right()); - case EC_LEFT: - not_in_completion(); - return (cmd_left()); - case EC_W_RIGHT: - not_in_completion(); - while (*cp != '\0' && *cp != ' ') - cmd_right(); - while (*cp == ' ') - cmd_right(); - return (CC_OK); - case EC_W_LEFT: - not_in_completion(); - while (cp > cmdbuf && cp[-1] == ' ') - cmd_left(); - while (cp > cmdbuf && cp[-1] != ' ') - cmd_left(); - return (CC_OK); - case EC_HOME: - not_in_completion(); - cmd_offset = 0; - cmd_home(); - cmd_repaint(cp); - return (CC_OK); - case EC_END: - not_in_completion(); - while (*cp != '\0') - cmd_right(); - return (CC_OK); - case EC_INSERT: - not_in_completion(); - return (CC_OK); - case EC_BACKSPACE: - not_in_completion(); - return (cmd_erase()); - case EC_LINEKILL: - not_in_completion(); - return (cmd_kill()); - case EC_ABORT: - not_in_completion(); - (void) cmd_kill(); - return (CC_QUIT); - case EC_W_BACKSPACE: - not_in_completion(); - return (cmd_werase()); - case EC_DELETE: - not_in_completion(); - return (cmd_delete()); - case EC_W_DELETE: - not_in_completion(); - return (cmd_wdelete()); - case EC_LITERAL: - literal = 1; - return (CC_OK); + action = editchar(c, flags); + + switch (action) + { + case A_NOACTION: + return (CC_OK); + case EC_RIGHT: + not_in_completion(); + return (cmd_right()); + case EC_LEFT: + not_in_completion(); + return (cmd_left()); + case EC_W_RIGHT: + not_in_completion(); + while (*cp != '\0' && *cp != ' ') + cmd_right(); + while (*cp == ' ') + cmd_right(); + return (CC_OK); + case EC_W_LEFT: + not_in_completion(); + while (cp > cmdbuf && cp[-1] == ' ') + cmd_left(); + while (cp > cmdbuf && cp[-1] != ' ') + cmd_left(); + return (CC_OK); + case EC_HOME: + not_in_completion(); + cmd_offset = 0; + cmd_home(); + cmd_repaint(cp); + return (CC_OK); + case EC_END: + not_in_completion(); + while (*cp != '\0') + cmd_right(); + return (CC_OK); + case EC_INSERT: + not_in_completion(); + return (CC_OK); + case EC_BACKSPACE: + not_in_completion(); + return (cmd_erase()); + case EC_LINEKILL: + not_in_completion(); + return (cmd_kill()); + case EC_ABORT: + not_in_completion(); + (void) cmd_kill(); + return (CC_QUIT); + case EC_W_BACKSPACE: + not_in_completion(); + return (cmd_werase()); + case EC_DELETE: + not_in_completion(); + return (cmd_delete()); + case EC_W_DELETE: + not_in_completion(); + return (cmd_wdelete()); + case EC_LITERAL: + literal = 1; + return (CC_OK); #if CMD_HISTORY - case EC_UP: - case EC_DOWN: - not_in_completion(); - return (cmd_updown(action)); + case EC_UP: + case EC_DOWN: + not_in_completion(); + return (cmd_updown(action)); #endif #if TAB_COMPLETE_FILENAME - case EC_F_COMPLETE: - case EC_B_COMPLETE: - case EC_EXPAND: - return (cmd_complete(action)); + case EC_F_COMPLETE: + case EC_B_COMPLETE: + case EC_EXPAND: + return (cmd_complete(action)); #endif - default: - not_in_completion(); - return (CC_PASS); - } + default: + not_in_completion(); + return (CC_PASS); + } } #if TAB_COMPLETE_FILENAME /* * Insert a string into the command buffer, at the current position. */ - static int + static int cmd_istr(str) - char *str; + char *str; { - char *s; - int action; - char *endline = str + strlen(str); - - for (s = str; *s != '\0'; ) - { - char *os = s; - step_char(&s, +1, endline); - action = cmd_ichar(os, s - os); - if (action != CC_OK) - return (action); - } - return (CC_OK); + char *s; + int action; + char *endline = str + strlen(str); + + for (s = str; *s != '\0'; ) + { + char *os = s; + step_char(&s, +1, endline); + action = cmd_ichar(os, s - os); + if (action != CC_OK) + return (action); + } + return (CC_OK); } /* @@ -976,170 +976,170 @@ cmd_istr(str) * Return pointer to the beginning of the word and put the * cursor at the end of the word. */ - static char * + static char * delimit_word(VOID_PARAM) { - char *word; + char *word; #if SPACES_IN_FILENAMES - char *p; - int delim_quoted = 0; - int meta_quoted = 0; - constant char *esc = get_meta_escape(); - int esclen = (int) strlen(esc); + char *p; + int delim_quoted = 0; + int meta_quoted = 0; + constant char *esc = get_meta_escape(); + int esclen = (int) strlen(esc); #endif - - /* - * Move cursor to end of word. - */ - if (*cp != ' ' && *cp != '\0') - { - /* - * Cursor is on a nonspace. - * Move cursor right to the next space. - */ - while (*cp != ' ' && *cp != '\0') - cmd_right(); - } else if (cp > cmdbuf && cp[-1] != ' ') - { - /* - * Cursor is on a space, and char to the left is a nonspace. - * We're already at the end of the word. - */ - ; + + /* + * Move cursor to end of word. + */ + if (*cp != ' ' && *cp != '\0') + { + /* + * Cursor is on a nonspace. + * Move cursor right to the next space. + */ + while (*cp != ' ' && *cp != '\0') + cmd_right(); + } else if (cp > cmdbuf && cp[-1] != ' ') + { + /* + * Cursor is on a space, and char to the left is a nonspace. + * We're already at the end of the word. + */ + ; #if 0 - } else - { - /* - * Cursor is on a space and char to the left is a space. - * Huh? There's no word here. - */ - return (NULL); + } else + { + /* + * Cursor is on a space and char to the left is a space. + * Huh? There's no word here. + */ + return (NULL); #endif - } - /* - * Find the beginning of the word which the cursor is in. - */ - if (cp == cmdbuf) - return (NULL); + } + /* + * Find the beginning of the word which the cursor is in. + */ + if (cp == cmdbuf) + return (NULL); #if SPACES_IN_FILENAMES - /* - * If we have an unbalanced quote (that is, an open quote - * without a corresponding close quote), we return everything - * from the open quote, including spaces. - */ - for (word = cmdbuf; word < cp; word++) - if (*word != ' ') - break; - if (word >= cp) - return (cp); - for (p = cmdbuf; p < cp; p++) - { - if (meta_quoted) - { - meta_quoted = 0; - } else if (esclen > 0 && p + esclen < cp && - strncmp(p, esc, esclen) == 0) - { - meta_quoted = 1; - p += esclen - 1; - } else if (delim_quoted) - { - if (*p == closequote) - delim_quoted = 0; - } else /* (!delim_quoted) */ - { - if (*p == openquote) - delim_quoted = 1; - else if (*p == ' ') - word = p+1; - } - } + /* + * If we have an unbalanced quote (that is, an open quote + * without a corresponding close quote), we return everything + * from the open quote, including spaces. + */ + for (word = cmdbuf; word < cp; word++) + if (*word != ' ') + break; + if (word >= cp) + return (cp); + for (p = cmdbuf; p < cp; p++) + { + if (meta_quoted) + { + meta_quoted = 0; + } else if (esclen > 0 && p + esclen < cp && + strncmp(p, esc, esclen) == 0) + { + meta_quoted = 1; + p += esclen - 1; + } else if (delim_quoted) + { + if (*p == closequote) + delim_quoted = 0; + } else /* (!delim_quoted) */ + { + if (*p == openquote) + delim_quoted = 1; + else if (*p == ' ') + word = p+1; + } + } #endif - return (word); + return (word); } /* * Set things up to enter completion mode. - * Expand the word under the cursor into a list of filenames + * Expand the word under the cursor into a list of filenames * which start with that word, and set tk_text to that list. */ - static void + static void init_compl(VOID_PARAM) { - char *word; - char c; - - /* - * Get rid of any previous tk_text. - */ - if (tk_text != NULL) - { - free(tk_text); - tk_text = NULL; - } - /* - * Find the original (uncompleted) word in the command buffer. - */ - word = delimit_word(); - if (word == NULL) - return; - /* - * Set the insertion point to the point in the command buffer - * where the original (uncompleted) word now sits. - */ - tk_ipoint = word; - /* - * Save the original (uncompleted) word - */ - if (tk_original != NULL) - free(tk_original); - tk_original = (char *) ecalloc(cp-word+1, sizeof(char)); - strncpy(tk_original, word, cp-word); - /* - * Get the expanded filename. - * This may result in a single filename, or - * a blank-separated list of filenames. - */ - c = *cp; - *cp = '\0'; - if (*word != openquote) - { - tk_text = fcomplete(word); - } else - { + char *word; + char c; + + /* + * Get rid of any previous tk_text. + */ + if (tk_text != NULL) + { + free(tk_text); + tk_text = NULL; + } + /* + * Find the original (uncompleted) word in the command buffer. + */ + word = delimit_word(); + if (word == NULL) + return; + /* + * Set the insertion point to the point in the command buffer + * where the original (uncompleted) word now sits. + */ + tk_ipoint = word; + /* + * Save the original (uncompleted) word + */ + if (tk_original != NULL) + free(tk_original); + tk_original = (char *) ecalloc(cp-word+1, sizeof(char)); + strncpy(tk_original, word, cp-word); + /* + * Get the expanded filename. + * This may result in a single filename, or + * a blank-separated list of filenames. + */ + c = *cp; + *cp = '\0'; + if (*word != openquote) + { + tk_text = fcomplete(word); + } else + { #if MSDOS_COMPILER - char *qword = NULL; + char *qword = NULL; #else - char *qword = shell_quote(word+1); + char *qword = shell_quote(word+1); #endif - if (qword == NULL) - tk_text = fcomplete(word+1); - else - { - tk_text = fcomplete(qword); - free(qword); - } - } - *cp = c; + if (qword == NULL) + tk_text = fcomplete(word+1); + else + { + tk_text = fcomplete(qword); + free(qword); + } + } + *cp = c; } /* * Return the next word in the current completion list. */ - static char * + static char * next_compl(action, prev) - int action; - char *prev; + int action; + char *prev; { - switch (action) - { - case EC_F_COMPLETE: - return (forw_textlist(&tk_tlist, prev)); - case EC_B_COMPLETE: - return (back_textlist(&tk_tlist, prev)); - } - /* Cannot happen */ - return ("?"); + switch (action) + { + case EC_F_COMPLETE: + return (forw_textlist(&tk_tlist, prev)); + case EC_B_COMPLETE: + return (back_textlist(&tk_tlist, prev)); + } + /* Cannot happen */ + return ("?"); } /* @@ -1148,92 +1148,92 @@ next_compl(action, prev) * remembers whether this call is the first time (create the list), * or a subsequent time (step thru the list). */ - static int + static int cmd_complete(action) - int action; + int action; { - char *s; - - if (!in_completion || action == EC_EXPAND) - { - /* - * Expand the word under the cursor and - * use the first word in the expansion - * (or the entire expansion if we're doing EC_EXPAND). - */ - init_compl(); - if (tk_text == NULL) - { - bell(); - return (CC_OK); - } - if (action == EC_EXPAND) - { - /* - * Use the whole list. - */ - tk_trial = tk_text; - } else - { - /* - * Use the first filename in the list. - */ - in_completion = 1; - init_textlist(&tk_tlist, tk_text); - tk_trial = next_compl(action, (char*)NULL); - } - } else - { - /* - * We already have a completion list. - * Use the next/previous filename from the list. - */ - tk_trial = next_compl(action, tk_trial); - } - - /* - * Remove the original word, or the previous trial completion. - */ - while (cp > tk_ipoint) - (void) cmd_erase(); - - if (tk_trial == NULL) - { - /* - * There are no more trial completions. - * Insert the original (uncompleted) filename. - */ - in_completion = 0; - if (cmd_istr(tk_original) != CC_OK) - goto fail; - } else - { - /* - * Insert trial completion. - */ - if (cmd_istr(tk_trial) != CC_OK) - goto fail; - /* - * If it is a directory, append a slash. - */ - if (is_dir(tk_trial)) - { - if (cp > cmdbuf && cp[-1] == closequote) - (void) cmd_erase(); - s = lgetenv("LESSSEPARATOR"); - if (s == NULL) - s = PATHNAME_SEP; - if (cmd_istr(s) != CC_OK) - goto fail; - } - } - - return (CC_OK); - + char *s; + + if (!in_completion || action == EC_EXPAND) + { + /* + * Expand the word under the cursor and + * use the first word in the expansion + * (or the entire expansion if we're doing EC_EXPAND). + */ + init_compl(); + if (tk_text == NULL) + { + bell(); + return (CC_OK); + } + if (action == EC_EXPAND) + { + /* + * Use the whole list. + */ + tk_trial = tk_text; + } else + { + /* + * Use the first filename in the list. + */ + in_completion = 1; + init_textlist(&tk_tlist, tk_text); + tk_trial = next_compl(action, (char*)NULL); + } + } else + { + /* + * We already have a completion list. + * Use the next/previous filename from the list. + */ + tk_trial = next_compl(action, tk_trial); + } + + /* + * Remove the original word, or the previous trial completion. + */ + while (cp > tk_ipoint) + (void) cmd_erase(); + + if (tk_trial == NULL) + { + /* + * There are no more trial completions. + * Insert the original (uncompleted) filename. + */ + in_completion = 0; + if (cmd_istr(tk_original) != CC_OK) + goto fail; + } else + { + /* + * Insert trial completion. + */ + if (cmd_istr(tk_trial) != CC_OK) + goto fail; + /* + * If it is a directory, append a slash. + */ + if (is_dir(tk_trial)) + { + if (cp > cmdbuf && cp[-1] == closequote) + (void) cmd_erase(); + s = lgetenv("LESSSEPARATOR"); + if (s == NULL) + s = PATHNAME_SEP; + if (cmd_istr(s) != CC_OK) + goto fail; + } + } + + return (CC_OK); + fail: - in_completion = 0; - bell(); - return (CC_OK); + in_completion = 0; + bell(); + return (CC_OK); } #endif /* TAB_COMPLETE_FILENAME */ @@ -1246,299 +1246,299 @@ cmd_complete(action) * CC_QUIT The char requests the command to be aborted. * CC_ERROR The char could not be accepted due to an error. */ - public int + public int cmd_char(c) - int c; + int c; { - int action; - int len; - - if (!utf_mode) - { - cmd_mbc_buf[0] = c; - len = 1; - } else - { - /* Perform strict validation in all possible cases. */ - if (cmd_mbc_buf_len == 0) - { - retry: - cmd_mbc_buf_index = 1; - *cmd_mbc_buf = c; - if (IS_ASCII_OCTET(c)) - cmd_mbc_buf_len = 1; + int action; + int len; + + if (!utf_mode) + { + cmd_mbc_buf[0] = c; + len = 1; + } else + { + /* Perform strict validation in all possible cases. */ + if (cmd_mbc_buf_len == 0) + { + retry: + cmd_mbc_buf_index = 1; + *cmd_mbc_buf = c; + if (IS_ASCII_OCTET(c)) + cmd_mbc_buf_len = 1; #if MSDOS_COMPILER || OS2 - else if (c == (unsigned char) '\340' && IS_ASCII_OCTET(peekcc())) - { - /* Assume a special key. */ - cmd_mbc_buf_len = 1; - } + else if (c == (unsigned char) '\340' && IS_ASCII_OCTET(peekcc())) + { + /* Assume a special key. */ + cmd_mbc_buf_len = 1; + } #endif - else if (IS_UTF8_LEAD(c)) - { - cmd_mbc_buf_len = utf_len(c); - return (CC_OK); - } else - { - /* UTF8_INVALID or stray UTF8_TRAIL */ - bell(); - return (CC_ERROR); - } - } else if (IS_UTF8_TRAIL(c)) - { - cmd_mbc_buf[cmd_mbc_buf_index++] = c; - if (cmd_mbc_buf_index < cmd_mbc_buf_len) - return (CC_OK); - if (!is_utf8_well_formed(cmd_mbc_buf, cmd_mbc_buf_index)) - { - /* complete, but not well formed (non-shortest form), sequence */ - cmd_mbc_buf_len = 0; - bell(); - return (CC_ERROR); - } - } else - { - /* Flush incomplete (truncated) sequence. */ - cmd_mbc_buf_len = 0; - bell(); - /* Handle new char. */ - goto retry; - } - - len = cmd_mbc_buf_len; - cmd_mbc_buf_len = 0; - } - - if (literal) - { - /* - * Insert the char, even if it is a line-editing char. - */ - literal = 0; - return (cmd_ichar(cmd_mbc_buf, len)); - } - - /* - * See if it is a line-editing character. - */ - if (in_mca() && len == 1) - { - action = cmd_edit(c); - switch (action) - { - case CC_OK: - case CC_QUIT: - return (action); - case CC_PASS: - break; - } - } - - /* - * Insert the char into the command buffer. - */ - return (cmd_ichar(cmd_mbc_buf, len)); + else if (IS_UTF8_LEAD(c)) + { + cmd_mbc_buf_len = utf_len(c); + return (CC_OK); + } else + { + /* UTF8_INVALID or stray UTF8_TRAIL */ + bell(); + return (CC_ERROR); + } + } else if (IS_UTF8_TRAIL(c)) + { + cmd_mbc_buf[cmd_mbc_buf_index++] = c; + if (cmd_mbc_buf_index < cmd_mbc_buf_len) + return (CC_OK); + if (!is_utf8_well_formed(cmd_mbc_buf, cmd_mbc_buf_index)) + { + /* complete, but not well formed (non-shortest form), sequence */ + cmd_mbc_buf_len = 0; + bell(); + return (CC_ERROR); + } + } else + { + /* Flush incomplete (truncated) sequence. */ + cmd_mbc_buf_len = 0; + bell(); + /* Handle new char. */ + goto retry; + } + + len = cmd_mbc_buf_len; + cmd_mbc_buf_len = 0; + } + + if (literal) + { + /* + * Insert the char, even if it is a line-editing char. + */ + literal = 0; + return (cmd_ichar(cmd_mbc_buf, len)); + } + + /* + * See if it is a line-editing character. + */ + if (in_mca() && len == 1) + { + action = cmd_edit(c); + switch (action) + { + case CC_OK: + case CC_QUIT: + return (action); + case CC_PASS: + break; + } + } + + /* + * Insert the char into the command buffer. + */ + return (cmd_ichar(cmd_mbc_buf, len)); } /* * Return the number currently in the command buffer. */ - public LINENUM + public LINENUM cmd_int(frac) - long *frac; + long *frac; { - char *p; - LINENUM n = 0; - int err; - - for (p = cmdbuf; *p >= '0' && *p <= '9'; p++) - n = (n * 10) + (*p - '0'); - *frac = 0; - if (*p++ == '.') - { - *frac = getfraction(&p, NULL, &err); - /* {{ do something if err is set? }} */ - } - return (n); + char *p; + LINENUM n = 0; + int err; + + for (p = cmdbuf; *p >= '0' && *p <= '9'; p++) + n = (n * 10) + (*p - '0'); + *frac = 0; + if (*p++ == '.') + { + *frac = getfraction(&p, NULL, &err); + /* {{ do something if err is set? }} */ + } + return (n); } /* * Return a pointer to the command buffer. */ - public char * + public char * get_cmdbuf(VOID_PARAM) { - return (cmdbuf); + return (cmdbuf); } #if CMD_HISTORY /* * Return the last (most recent) string in the current command history. */ - public char * + public char * cmd_lastpattern(VOID_PARAM) { - if (curr_mlist == NULL) - return (NULL); - return (curr_mlist->curr_mp->prev->string); + if (curr_mlist == NULL) + return (NULL); + return (curr_mlist->curr_mp->prev->string); } #endif #if CMD_HISTORY /* */ - static int + static int mlist_size(ml) - struct mlist *ml; + struct mlist *ml; { - int size = 0; - for (ml = ml->next; ml->string != NULL; ml = ml->next) - ++size; - return size; + int size = 0; + for (ml = ml->next; ml->string != NULL; ml = ml->next) + ++size; + return size; } /* * Get the name of the history file. */ - static char * + static char * histfile_name(VOID_PARAM) { - char *home; - char *name; - int len; - - /* See if filename is explicitly specified by $LESSHISTFILE. */ - name = lgetenv("LESSHISTFILE"); - if (!isnullenv(name)) - { - if (strcmp(name, "-") == 0 || strcmp(name, "/dev/null") == 0) - /* $LESSHISTFILE == "-" means don't use a history file. */ - return (NULL); - return (save(name)); - } - - /* See if history file is disabled in the build. */ - if (strcmp(LESSHISTFILE, "") == 0 || strcmp(LESSHISTFILE, "-") == 0) - return (NULL); - - /* Otherwise, file is in $HOME. */ - home = lgetenv("HOME"); - if (isnullenv(home)) - { + char *home; + char *name; + int len; + + /* See if filename is explicitly specified by $LESSHISTFILE. */ + name = lgetenv("LESSHISTFILE"); + if (!isnullenv(name)) + { + if (strcmp(name, "-") == 0 || strcmp(name, "/dev/null") == 0) + /* $LESSHISTFILE == "-" means don't use a history file. */ + return (NULL); + return (save(name)); + } + + /* See if history file is disabled in the build. */ + if (strcmp(LESSHISTFILE, "") == 0 || strcmp(LESSHISTFILE, "-") == 0) + return (NULL); + + /* Otherwise, file is in $HOME. */ + home = lgetenv("HOME"); + if (isnullenv(home)) + { #if OS2 - home = lgetenv("INIT"); - if (isnullenv(home)) + home = lgetenv("INIT"); + if (isnullenv(home)) #endif - return (NULL); - } - len = (int) (strlen(home) + strlen(LESSHISTFILE) + 2); - name = (char *) ecalloc(len, sizeof(char)); - SNPRINTF2(name, len, "%s/%s", home, LESSHISTFILE); - return (name); + return (NULL); + } + len = (int) (strlen(home) + strlen(LESSHISTFILE) + 2); + name = (char *) ecalloc(len, sizeof(char)); + SNPRINTF2(name, len, "%s/%s", home, LESSHISTFILE); + return (name); } /* * Read a .lesshst file and call a callback for each line in the file. */ - static void + static void read_cmdhist2(action, uparam, skip_search, skip_shell) - void (*action)(void*,struct mlist*,char*); - void *uparam; - int skip_search; - int skip_shell; + void (*action)(void*,struct mlist*,char*); + void *uparam; + int skip_search; + int skip_shell; { - struct mlist *ml = NULL; - char line[CMDBUF_SIZE]; - char *filename; - FILE *f; - char *p; - int *skip = NULL; - - filename = histfile_name(); - if (filename == NULL) - return; - f = fopen(filename, "r"); - free(filename); - if (f == NULL) - return; - if (fgets(line, sizeof(line), f) == NULL || - strncmp(line, HISTFILE_FIRST_LINE, strlen(HISTFILE_FIRST_LINE)) != 0) - { - fclose(f); - return; - } - while (fgets(line, sizeof(line), f) != NULL) - { - for (p = line; *p != '\0'; p++) - { - if (*p == '\n' || *p == '\r') - { - *p = '\0'; - break; - } - } - if (strcmp(line, HISTFILE_SEARCH_SECTION) == 0) - { - ml = &mlist_search; - skip = &skip_search; - } else if (strcmp(line, HISTFILE_SHELL_SECTION) == 0) - { + struct mlist *ml = NULL; + char line[CMDBUF_SIZE]; + char *filename; + FILE *f; + char *p; + int *skip = NULL; + + filename = histfile_name(); + if (filename == NULL) + return; + f = fopen(filename, "r"); + free(filename); + if (f == NULL) + return; + if (fgets(line, sizeof(line), f) == NULL || + strncmp(line, HISTFILE_FIRST_LINE, strlen(HISTFILE_FIRST_LINE)) != 0) + { + fclose(f); + return; + } + while (fgets(line, sizeof(line), f) != NULL) + { + for (p = line; *p != '\0'; p++) + { + if (*p == '\n' || *p == '\r') + { + *p = '\0'; + break; + } + } + if (strcmp(line, HISTFILE_SEARCH_SECTION) == 0) + { + ml = &mlist_search; + skip = &skip_search; + } else if (strcmp(line, HISTFILE_SHELL_SECTION) == 0) + { #if SHELL_ESCAPE || PIPEC - ml = &mlist_shell; - skip = &skip_shell; + ml = &mlist_shell; + skip = &skip_shell; #else - ml = NULL; - skip = NULL; + ml = NULL; + skip = NULL; #endif - } else if (strcmp(line, HISTFILE_MARK_SECTION) == 0) - { - ml = NULL; - } else if (*line == '"') - { - if (ml != NULL) - { - if (skip != NULL && *skip > 0) - --(*skip); - else - (*action)(uparam, ml, line+1); - } - } else if (*line == 'm') - { - (*action)(uparam, NULL, line); - } - } - fclose(f); + } else if (strcmp(line, HISTFILE_MARK_SECTION) == 0) + { + ml = NULL; + } else if (*line == '"') + { + if (ml != NULL) + { + if (skip != NULL && *skip > 0) + --(*skip); + else + (*action)(uparam, ml, line+1); + } + } else if (*line == 'm') + { + (*action)(uparam, NULL, line); + } + } + fclose(f); } - static void + static void read_cmdhist(action, uparam, skip_search, skip_shell) - void (*action)(void*,struct mlist*,char*); - void *uparam; - int skip_search; - int skip_shell; + void (*action)(void*,struct mlist*,char*); + void *uparam; + int skip_search; + int skip_shell; { - read_cmdhist2(action, uparam, skip_search, skip_shell); - (*action)(uparam, NULL, NULL); /* signal end of file */ + read_cmdhist2(action, uparam, skip_search, skip_shell); + (*action)(uparam, NULL, NULL); /* signal end of file */ } - static void + static void addhist_init(void *uparam, struct mlist *ml, char *string) { - if (ml != NULL) - cmd_addhist(ml, string, 0); - else if (string != NULL) - restore_mark(string); + if (ml != NULL) + cmd_addhist(ml, string, 0); + else if (string != NULL) + restore_mark(string); } #endif /* CMD_HISTORY */ /* * Initialize history from a .lesshist file. */ - public void + public void init_cmdhist(VOID_PARAM) { #if CMD_HISTORY - read_cmdhist(&addhist_init, NULL, 0, 0); + read_cmdhist(&addhist_init, NULL, 0, 0); #endif /* CMD_HISTORY */ } @@ -1546,56 +1546,56 @@ init_cmdhist(VOID_PARAM) * Write the header for a section of the history file. */ #if CMD_HISTORY - static void + static void write_mlist_header(ml, f) - struct mlist *ml; - FILE *f; + struct mlist *ml; + FILE *f; { - if (ml == &mlist_search) - fprintf(f, "%s\n", HISTFILE_SEARCH_SECTION); + if (ml == &mlist_search) + fprintf(f, "%s\n", HISTFILE_SEARCH_SECTION); #if SHELL_ESCAPE || PIPEC - else if (ml == &mlist_shell) - fprintf(f, "%s\n", HISTFILE_SHELL_SECTION); + else if (ml == &mlist_shell) + fprintf(f, "%s\n", HISTFILE_SHELL_SECTION); #endif } /* * Write all modified entries in an mlist to the history file. */ - static void + static void write_mlist(ml, f) - struct mlist *ml; - FILE *f; + struct mlist *ml; + FILE *f; { - for (ml = ml->next; ml->string != NULL; ml = ml->next) - { - if (!ml->modified) - continue; - fprintf(f, "\"%s\n", ml->string); - ml->modified = 0; - } - ml->modified = 0; /* entire mlist is now unmodified */ + for (ml = ml->next; ml->string != NULL; ml = ml->next) + { + if (!ml->modified) + continue; + fprintf(f, "\"%s\n", ml->string); + ml->modified = 0; + } + ml->modified = 0; /* entire mlist is now unmodified */ } /* * Make a temp name in the same directory as filename. */ - static char * + static char * make_tempname(filename) - char *filename; + char *filename; { - char lastch; - char *tempname = ecalloc(1, strlen(filename)+1); - strcpy(tempname, filename); - lastch = tempname[strlen(tempname)-1]; - tempname[strlen(tempname)-1] = (lastch == 'Q') ? 'Z' : 'Q'; - return tempname; + char lastch; + char *tempname = ecalloc(1, strlen(filename)+1); + strcpy(tempname, filename); + lastch = tempname[strlen(tempname)-1]; + tempname[strlen(tempname)-1] = (lastch == 'Q') ? 'Z' : 'Q'; + return tempname; } struct save_ctx { - struct mlist *mlist; - FILE *fout; + struct mlist *mlist; + FILE *fout; }; /* @@ -1603,136 +1603,136 @@ struct save_ctx * At the end of each mlist, append any new entries * created during this session. */ - static void + static void copy_hist(void *uparam, struct mlist *ml, char *string) { - struct save_ctx *ctx = (struct save_ctx *) uparam; - - if (ml != NULL && ml != ctx->mlist) { - /* We're changing mlists. */ - if (ctx->mlist) - /* Append any new entries to the end of the current mlist. */ - write_mlist(ctx->mlist, ctx->fout); - /* Write the header for the new mlist. */ - ctx->mlist = ml; - write_mlist_header(ctx->mlist, ctx->fout); - } - - if (string == NULL) /* End of file */ - { - /* Write any sections that were not in the original file. */ - if (mlist_search.modified) - { - write_mlist_header(&mlist_search, ctx->fout); - write_mlist(&mlist_search, ctx->fout); - } + struct save_ctx *ctx = (struct save_ctx *) uparam; + + if (ml != NULL && ml != ctx->mlist) { + /* We're changing mlists. */ + if (ctx->mlist) + /* Append any new entries to the end of the current mlist. */ + write_mlist(ctx->mlist, ctx->fout); + /* Write the header for the new mlist. */ + ctx->mlist = ml; + write_mlist_header(ctx->mlist, ctx->fout); + } + + if (string == NULL) /* End of file */ + { + /* Write any sections that were not in the original file. */ + if (mlist_search.modified) + { + write_mlist_header(&mlist_search, ctx->fout); + write_mlist(&mlist_search, ctx->fout); + } #if SHELL_ESCAPE || PIPEC - if (mlist_shell.modified) - { - write_mlist_header(&mlist_shell, ctx->fout); - write_mlist(&mlist_shell, ctx->fout); - } + if (mlist_shell.modified) + { + write_mlist_header(&mlist_shell, ctx->fout); + write_mlist(&mlist_shell, ctx->fout); + } #endif - } else if (ml != NULL) - { - /* Copy mlist entry. */ - fprintf(ctx->fout, "\"%s\n", string); - } - /* Skip marks */ + } else if (ml != NULL) + { + /* Copy mlist entry. */ + fprintf(ctx->fout, "\"%s\n", string); + } + /* Skip marks */ } #endif /* CMD_HISTORY */ /* * Make a file readable only by its owner. */ - static void + static void make_file_private(f) - FILE *f; + FILE *f; { #if HAVE_FCHMOD - int do_chmod = 1; + int do_chmod = 1; #if HAVE_STAT - struct stat statbuf; - int r = fstat(fileno(f), &statbuf); - if (r < 0 || !S_ISREG(statbuf.st_mode)) - /* Don't chmod if not a regular file. */ - do_chmod = 0; + struct stat statbuf; + int r = fstat(fileno(f), &statbuf); + if (r < 0 || !S_ISREG(statbuf.st_mode)) + /* Don't chmod if not a regular file. */ + do_chmod = 0; #endif - if (do_chmod) - fchmod(fileno(f), 0600); + if (do_chmod) + fchmod(fileno(f), 0600); #endif } /* * Does the history file need to be updated? */ - static int + static int histfile_modified(VOID_PARAM) { - if (mlist_search.modified) - return 1; + if (mlist_search.modified) + return 1; #if SHELL_ESCAPE || PIPEC - if (mlist_shell.modified) - return 1; + if (mlist_shell.modified) + return 1; #endif #if CMD_HISTORY - if (marks_modified) - return 1; + if (marks_modified) + return 1; #endif - return 0; + return 0; } /* * Update the .lesshst file. */ - public void + public void save_cmdhist(VOID_PARAM) { #if CMD_HISTORY - char *histname; - char *tempname; - int skip_search; - int skip_shell; - struct save_ctx ctx; - char *s; - FILE *fout = NULL; - int histsize = 0; - - if (!histfile_modified()) - return; - histname = histfile_name(); - if (histname == NULL) - return; - tempname = make_tempname(histname); - fout = fopen(tempname, "w"); - if (fout != NULL) - { - make_file_private(fout); - s = lgetenv("LESSHISTSIZE"); - if (s != NULL) - histsize = atoi(s); - if (histsize <= 0) - histsize = 100; - skip_search = mlist_size(&mlist_search) - histsize; + char *histname; + char *tempname; + int skip_search; + int skip_shell; + struct save_ctx ctx; + char *s; + FILE *fout = NULL; + int histsize = 0; + + if (!histfile_modified()) + return; + histname = histfile_name(); + if (histname == NULL) + return; + tempname = make_tempname(histname); + fout = fopen(tempname, "w"); + if (fout != NULL) + { + make_file_private(fout); + s = lgetenv("LESSHISTSIZE"); + if (s != NULL) + histsize = atoi(s); + if (histsize <= 0) + histsize = 100; + skip_search = mlist_size(&mlist_search) - histsize; #if SHELL_ESCAPE || PIPEC - skip_shell = mlist_size(&mlist_shell) - histsize; + skip_shell = mlist_size(&mlist_shell) - histsize; #endif - fprintf(fout, "%s\n", HISTFILE_FIRST_LINE); - ctx.fout = fout; - ctx.mlist = NULL; - read_cmdhist(©_hist, &ctx, skip_search, skip_shell); - save_marks(fout, HISTFILE_MARK_SECTION); - fclose(fout); + fprintf(fout, "%s\n", HISTFILE_FIRST_LINE); + ctx.fout = fout; + ctx.mlist = NULL; + read_cmdhist(©_hist, &ctx, skip_search, skip_shell); + save_marks(fout, HISTFILE_MARK_SECTION); + fclose(fout); #if MSDOS_COMPILER==WIN32C - /* - * Windows rename doesn't remove an existing file, - * making it useless for atomic operations. Sigh. - */ - remove(histname); + /* + * Windows rename doesn't remove an existing file, + * making it useless for atomic operations. Sigh. + */ + remove(histname); #endif - rename(tempname, histname); - } - free(tempname); - free(histname); + rename(tempname, histname); + } + free(tempname); + free(histname); #endif /* CMD_HISTORY */ } diff --git a/command.c b/command.c index cf691a7..15e6ef9 100644 --- a/command.c +++ b/command.c @@ -84,8 +84,8 @@ static char pipec; /* Stack of ungotten chars (via ungetcc) */ struct ungot { - struct ungot *ug_next; - LWCHAR ug_char; + struct ungot *ug_next; + LWCHAR ug_char; }; static struct ungot* ungot = NULL; @@ -96,790 +96,790 @@ static void multi_search LESSPARAMS((char *pattern, int n, int silent)); * This looks nicer if the command takes a long time before * updating the screen. */ - static void + static void cmd_exec(VOID_PARAM) { - clear_attn(); - clear_bot(); - flush(); + clear_attn(); + clear_bot(); + flush(); } /* * Indicate we are reading a multi-character command. */ - static void + static void set_mca(action) - int action; + int action; { - mca = action; - clear_bot(); - clear_cmd(); + mca = action; + clear_bot(); + clear_cmd(); } /* * Indicate we are not reading a multi-character command. */ - static void + static void clear_mca(VOID_PARAM) { - if (mca == 0) - return; - mca = 0; + if (mca == 0) + return; + mca = 0; } /* * Set up the display to start a new multi-character command. */ - static void + static void start_mca(action, prompt, mlist, cmdflags) - int action; - constant char *prompt; - void *mlist; - int cmdflags; + int action; + constant char *prompt; + void *mlist; + int cmdflags; { - set_mca(action); - cmd_putstr(prompt); - set_mlist(mlist, cmdflags); + set_mca(action); + cmd_putstr(prompt); + set_mlist(mlist, cmdflags); } - public int + public int in_mca(VOID_PARAM) { - return (mca != 0 && mca != A_PREFIX); + return (mca != 0 && mca != A_PREFIX); } /* * Set up the display to start a new search command. */ - static void + static void mca_search(VOID_PARAM) { #if HILITE_SEARCH - if (search_type & SRCH_FILTER) - set_mca(A_FILTER); - else + if (search_type & SRCH_FILTER) + set_mca(A_FILTER); + else #endif - if (search_type & SRCH_FORW) - set_mca(A_F_SEARCH); - else - set_mca(A_B_SEARCH); - - if (search_type & SRCH_NO_MATCH) - cmd_putstr("Non-match "); - if (search_type & SRCH_FIRST_FILE) - cmd_putstr("First-file "); - if (search_type & SRCH_PAST_EOF) - cmd_putstr("EOF-ignore "); - if (search_type & SRCH_NO_MOVE) - cmd_putstr("Keep-pos "); - if (search_type & SRCH_NO_REGEX) - cmd_putstr("Regex-off "); - if (search_type & SRCH_WRAP) - cmd_putstr("Wrap "); + if (search_type & SRCH_FORW) + set_mca(A_F_SEARCH); + else + set_mca(A_B_SEARCH); + + if (search_type & SRCH_NO_MATCH) + cmd_putstr("Non-match "); + if (search_type & SRCH_FIRST_FILE) + cmd_putstr("First-file "); + if (search_type & SRCH_PAST_EOF) + cmd_putstr("EOF-ignore "); + if (search_type & SRCH_NO_MOVE) + cmd_putstr("Keep-pos "); + if (search_type & SRCH_NO_REGEX) + cmd_putstr("Regex-off "); + if (search_type & SRCH_WRAP) + cmd_putstr("Wrap "); #if HILITE_SEARCH - if (search_type & SRCH_FILTER) - cmd_putstr("&/"); - else + if (search_type & SRCH_FILTER) + cmd_putstr("&/"); + else #endif - if (search_type & SRCH_FORW) - cmd_putstr("/"); - else - cmd_putstr("?"); - forw_prompt = 0; - set_mlist(ml_search, 0); + if (search_type & SRCH_FORW) + cmd_putstr("/"); + else + cmd_putstr("?"); + forw_prompt = 0; + set_mlist(ml_search, 0); } /* * Set up the display to start a new toggle-option command. */ - static void + static void mca_opt_toggle(VOID_PARAM) { - int no_prompt; - int flag; - char *dash; - - no_prompt = (optflag & OPT_NO_PROMPT); - flag = (optflag & ~OPT_NO_PROMPT); - dash = (flag == OPT_NO_TOGGLE) ? "_" : "-"; - - set_mca(A_OPT_TOGGLE); - cmd_putstr(dash); - if (optgetname) - cmd_putstr(dash); - if (no_prompt) - cmd_putstr("(P)"); - switch (flag) - { - case OPT_UNSET: - cmd_putstr("+"); - break; - case OPT_SET: - cmd_putstr("!"); - break; - } - forw_prompt = 0; - set_mlist(NULL, 0); + int no_prompt; + int flag; + char *dash; + + no_prompt = (optflag & OPT_NO_PROMPT); + flag = (optflag & ~OPT_NO_PROMPT); + dash = (flag == OPT_NO_TOGGLE) ? "_" : "-"; + + set_mca(A_OPT_TOGGLE); + cmd_putstr(dash); + if (optgetname) + cmd_putstr(dash); + if (no_prompt) + cmd_putstr("(P)"); + switch (flag) + { + case OPT_UNSET: + cmd_putstr("+"); + break; + case OPT_SET: + cmd_putstr("!"); + break; + } + forw_prompt = 0; + set_mlist(NULL, 0); } /* * Execute a multicharacter command. */ - static void + static void exec_mca(VOID_PARAM) { - char *cbuf; + char *cbuf; - cmd_exec(); - cbuf = get_cmdbuf(); + cmd_exec(); + cbuf = get_cmdbuf(); - switch (mca) - { - case A_F_SEARCH: - case A_B_SEARCH: - multi_search(cbuf, (int) number, 0); - break; + switch (mca) + { + case A_F_SEARCH: + case A_B_SEARCH: + multi_search(cbuf, (int) number, 0); + break; #if HILITE_SEARCH - case A_FILTER: - search_type ^= SRCH_NO_MATCH; - set_filter_pattern(cbuf, search_type); - break; + case A_FILTER: + search_type ^= SRCH_NO_MATCH; + set_filter_pattern(cbuf, search_type); + break; #endif - case A_FIRSTCMD: - /* - * Skip leading spaces or + signs in the string. - */ - while (*cbuf == '+' || *cbuf == ' ') - cbuf++; - if (every_first_cmd != NULL) - free(every_first_cmd); - if (*cbuf == '\0') - every_first_cmd = NULL; - else - every_first_cmd = save(cbuf); - break; - case A_OPT_TOGGLE: - toggle_option(curropt, opt_lower, cbuf, optflag); - curropt = NULL; - break; - case A_F_BRACKET: - match_brac(cbuf[0], cbuf[1], 1, (int) number); - break; - case A_B_BRACKET: - match_brac(cbuf[1], cbuf[0], 0, (int) number); - break; + case A_FIRSTCMD: + /* + * Skip leading spaces or + signs in the string. + */ + while (*cbuf == '+' || *cbuf == ' ') + cbuf++; + if (every_first_cmd != NULL) + free(every_first_cmd); + if (*cbuf == '\0') + every_first_cmd = NULL; + else + every_first_cmd = save(cbuf); + break; + case A_OPT_TOGGLE: + toggle_option(curropt, opt_lower, cbuf, optflag); + curropt = NULL; + break; + case A_F_BRACKET: + match_brac(cbuf[0], cbuf[1], 1, (int) number); + break; + case A_B_BRACKET: + match_brac(cbuf[1], cbuf[0], 0, (int) number); + break; #if EXAMINE - case A_EXAMINE: - if (secure) - break; - edit_list(cbuf); + case A_EXAMINE: + if (secure) + break; + edit_list(cbuf); #if TAGS - /* If tag structure is loaded then clean it up. */ - cleantags(); + /* If tag structure is loaded then clean it up. */ + cleantags(); #endif - break; + break; #endif #if SHELL_ESCAPE - case A_SHELL: - /* - * !! just uses whatever is in shellcmd. - * Otherwise, copy cmdbuf to shellcmd, - * expanding any special characters ("%" or "#"). - */ - if (*cbuf != '!') - { - if (shellcmd != NULL) - free(shellcmd); - shellcmd = fexpand(cbuf); - } - - if (secure) - break; - if (shellcmd == NULL) - lsystem("", "!done"); - else - lsystem(shellcmd, "!done"); - break; + case A_SHELL: + /* + * !! just uses whatever is in shellcmd. + * Otherwise, copy cmdbuf to shellcmd, + * expanding any special characters ("%" or "#"). + */ + if (*cbuf != '!') + { + if (shellcmd != NULL) + free(shellcmd); + shellcmd = fexpand(cbuf); + } + + if (secure) + break; + if (shellcmd == NULL) + lsystem("", "!done"); + else + lsystem(shellcmd, "!done"); + break; #endif #if PIPEC - case A_PIPE: - if (secure) - break; - (void) pipe_mark(pipec, cbuf); - error("|done", NULL_PARG); - break; + case A_PIPE: + if (secure) + break; + (void) pipe_mark(pipec, cbuf); + error("|done", NULL_PARG); + break; #endif - } + } } /* * Is a character an erase or kill char? */ - static int + static int is_erase_char(c) - int c; + int c; { - return (c == erase_char || c == erase2_char || c == kill_char); + return (c == erase_char || c == erase2_char || c == kill_char); } /* * Is a character a carriage return or newline? */ - static int + static int is_newline_char(c) - int c; + int c; { - return (c == '\n' || c == '\r'); + return (c == '\n' || c == '\r'); } /* * Handle the first char of an option (after the initial dash). */ - static int + static int mca_opt_first_char(c) - int c; + int c; { - int flag = (optflag & ~OPT_NO_PROMPT); - if (flag == OPT_NO_TOGGLE) - { - switch (c) - { - case '_': - /* "__" = long option name. */ - optgetname = TRUE; - mca_opt_toggle(); - return (MCA_MORE); - } - } else - { - switch (c) - { - case '+': - /* "-+" = UNSET. */ - optflag = (flag == OPT_UNSET) ? - OPT_TOGGLE : OPT_UNSET; - mca_opt_toggle(); - return (MCA_MORE); - case '!': - /* "-!" = SET */ - optflag = (flag == OPT_SET) ? - OPT_TOGGLE : OPT_SET; - mca_opt_toggle(); - return (MCA_MORE); - case CONTROL('P'): - optflag ^= OPT_NO_PROMPT; - mca_opt_toggle(); - return (MCA_MORE); - case '-': - /* "--" = long option name. */ - optgetname = TRUE; - mca_opt_toggle(); - return (MCA_MORE); - } - } - /* Char was not handled here. */ - return (NO_MCA); + int flag = (optflag & ~OPT_NO_PROMPT); + if (flag == OPT_NO_TOGGLE) + { + switch (c) + { + case '_': + /* "__" = long option name. */ + optgetname = TRUE; + mca_opt_toggle(); + return (MCA_MORE); + } + } else + { + switch (c) + { + case '+': + /* "-+" = UNSET. */ + optflag = (flag == OPT_UNSET) ? + OPT_TOGGLE : OPT_UNSET; + mca_opt_toggle(); + return (MCA_MORE); + case '!': + /* "-!" = SET */ + optflag = (flag == OPT_SET) ? + OPT_TOGGLE : OPT_SET; + mca_opt_toggle(); + return (MCA_MORE); + case CONTROL('P'): + optflag ^= OPT_NO_PROMPT; + mca_opt_toggle(); + return (MCA_MORE); + case '-': + /* "--" = long option name. */ + optgetname = TRUE; + mca_opt_toggle(); + return (MCA_MORE); + } + } + /* Char was not handled here. */ + return (NO_MCA); } /* * Add a char to a long option name. * See if we've got a match for an option name yet. - * If so, display the complete name and stop + * If so, display the complete name and stop * accepting chars until user hits RETURN. */ - static int + static int mca_opt_nonfirst_char(c) - int c; + int c; { - char *p; - char *oname; - int err; - - if (curropt != NULL) - { - /* - * Already have a match for the name. - * Don't accept anything but erase/kill. - */ - if (is_erase_char(c)) - return (MCA_DONE); - return (MCA_MORE); - } - /* - * Add char to cmd buffer and try to match - * the option name. - */ - if (cmd_char(c) == CC_QUIT) - return (MCA_DONE); - p = get_cmdbuf(); - opt_lower = ASCII_IS_LOWER(p[0]); - err = 0; - curropt = findopt_name(&p, &oname, &err); - if (curropt != NULL) - { - /* - * Got a match. - * Remember the option and - * display the full option name. - */ - cmd_reset(); - mca_opt_toggle(); - for (p = oname; *p != '\0'; p++) - { - c = *p; - if (!opt_lower && ASCII_IS_LOWER(c)) - c = ASCII_TO_UPPER(c); - if (cmd_char(c) != CC_OK) - return (MCA_DONE); - } - } else if (err != OPT_AMBIG) - { - bell(); - } - return (MCA_MORE); + char *p; + char *oname; + int err; + + if (curropt != NULL) + { + /* + * Already have a match for the name. + * Don't accept anything but erase/kill. + */ + if (is_erase_char(c)) + return (MCA_DONE); + return (MCA_MORE); + } + /* + * Add char to cmd buffer and try to match + * the option name. + */ + if (cmd_char(c) == CC_QUIT) + return (MCA_DONE); + p = get_cmdbuf(); + opt_lower = ASCII_IS_LOWER(p[0]); + err = 0; + curropt = findopt_name(&p, &oname, &err); + if (curropt != NULL) + { + /* + * Got a match. + * Remember the option and + * display the full option name. + */ + cmd_reset(); + mca_opt_toggle(); + for (p = oname; *p != '\0'; p++) + { + c = *p; + if (!opt_lower && ASCII_IS_LOWER(c)) + c = ASCII_TO_UPPER(c); + if (cmd_char(c) != CC_OK) + return (MCA_DONE); + } + } else if (err != OPT_AMBIG) + { + bell(); + } + return (MCA_MORE); } /* * Handle a char of an option toggle command. */ - static int + static int mca_opt_char(c) - int c; + int c; { - PARG parg; - - /* - * This may be a short option (single char), - * or one char of a long option name, - * or one char of the option parameter. - */ - if (curropt == NULL && len_cmdbuf() == 0) - { - int ret = mca_opt_first_char(c); - if (ret != NO_MCA) - return (ret); - } - if (optgetname) - { - /* We're getting a long option name. */ - if (!is_newline_char(c)) - return (mca_opt_nonfirst_char(c)); - if (curropt == NULL) - { - parg.p_string = get_cmdbuf(); - error("There is no --%s option", &parg); - return (MCA_DONE); - } - optgetname = FALSE; - cmd_reset(); - } else - { - if (is_erase_char(c)) - return (NO_MCA); - if (curropt != NULL) - /* We're getting the option parameter. */ - return (NO_MCA); - curropt = findopt(c); - if (curropt == NULL) - { - parg.p_string = propt(c); - error("There is no %s option", &parg); - return (MCA_DONE); - } - opt_lower = ASCII_IS_LOWER(c); - } - /* - * If the option which was entered does not take a - * parameter, toggle the option immediately, - * so user doesn't have to hit RETURN. - */ - if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE || - !opt_has_param(curropt)) - { - toggle_option(curropt, opt_lower, "", optflag); - return (MCA_DONE); - } - /* - * Display a prompt appropriate for the option parameter. - */ - start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)NULL, 0); - return (MCA_MORE); + PARG parg; + + /* + * This may be a short option (single char), + * or one char of a long option name, + * or one char of the option parameter. + */ + if (curropt == NULL && len_cmdbuf() == 0) + { + int ret = mca_opt_first_char(c); + if (ret != NO_MCA) + return (ret); + } + if (optgetname) + { + /* We're getting a long option name. */ + if (!is_newline_char(c)) + return (mca_opt_nonfirst_char(c)); + if (curropt == NULL) + { + parg.p_string = get_cmdbuf(); + error("There is no --%s option", &parg); + return (MCA_DONE); + } + optgetname = FALSE; + cmd_reset(); + } else + { + if (is_erase_char(c)) + return (NO_MCA); + if (curropt != NULL) + /* We're getting the option parameter. */ + return (NO_MCA); + curropt = findopt(c); + if (curropt == NULL) + { + parg.p_string = propt(c); + error("There is no %s option", &parg); + return (MCA_DONE); + } + opt_lower = ASCII_IS_LOWER(c); + } + /* + * If the option which was entered does not take a + * parameter, toggle the option immediately, + * so user doesn't have to hit RETURN. + */ + if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE || + !opt_has_param(curropt)) + { + toggle_option(curropt, opt_lower, "", optflag); + return (MCA_DONE); + } + /* + * Display a prompt appropriate for the option parameter. + */ + start_mca(A_OPT_TOGGLE, opt_prompt(curropt), (void*)NULL, 0); + return (MCA_MORE); } /* * Handle a char of a search command. */ - static int + static int mca_search_char(c) - int c; + int c; { - int flag = 0; - - /* - * Certain characters as the first char of - * the pattern have special meaning: - * ! Toggle the NO_MATCH flag - * * Toggle the PAST_EOF flag - * @ Toggle the FIRST_FILE flag - */ - if (len_cmdbuf() > 0) - return (NO_MCA); - - switch (c) - { - case CONTROL('E'): /* ignore END of file */ - case '*': - if (mca != A_FILTER) - flag = SRCH_PAST_EOF; - break; - case CONTROL('F'): /* FIRST file */ - case '@': - if (mca != A_FILTER) - flag = SRCH_FIRST_FILE; - break; - case CONTROL('K'): /* KEEP position */ - if (mca != A_FILTER) - flag = SRCH_NO_MOVE; - break; - case CONTROL('W'): /* WRAP around */ - if (mca != A_FILTER) - flag = SRCH_WRAP; - break; - case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */ - flag = SRCH_NO_REGEX; - break; - case CONTROL('N'): /* NOT match */ - case '!': - flag = SRCH_NO_MATCH; - break; - } - - if (flag != 0) - { - /* Toggle flag, but keep PAST_EOF and WRAP mutually exclusive. */ - search_type ^= flag | (search_type & (SRCH_PAST_EOF|SRCH_WRAP)); - mca_search(); - return (MCA_MORE); - } - return (NO_MCA); + int flag = 0; + + /* + * Certain characters as the first char of + * the pattern have special meaning: + * ! Toggle the NO_MATCH flag + * * Toggle the PAST_EOF flag + * @ Toggle the FIRST_FILE flag + */ + if (len_cmdbuf() > 0) + return (NO_MCA); + + switch (c) + { + case CONTROL('E'): /* ignore END of file */ + case '*': + if (mca != A_FILTER) + flag = SRCH_PAST_EOF; + break; + case CONTROL('F'): /* FIRST file */ + case '@': + if (mca != A_FILTER) + flag = SRCH_FIRST_FILE; + break; + case CONTROL('K'): /* KEEP position */ + if (mca != A_FILTER) + flag = SRCH_NO_MOVE; + break; + case CONTROL('W'): /* WRAP around */ + if (mca != A_FILTER) + flag = SRCH_WRAP; + break; + case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */ + flag = SRCH_NO_REGEX; + break; + case CONTROL('N'): /* NOT match */ + case '!': + flag = SRCH_NO_MATCH; + break; + } + + if (flag != 0) + { + /* Toggle flag, but keep PAST_EOF and WRAP mutually exclusive. */ + search_type ^= flag | (search_type & (SRCH_PAST_EOF|SRCH_WRAP)); + mca_search(); + return (MCA_MORE); + } + return (NO_MCA); } /* * Handle a character of a multi-character command. */ - static int + static int mca_char(c) - int c; + int c; { - int ret; - - switch (mca) - { - case 0: - /* - * We're not in a multicharacter command. - */ - return (NO_MCA); - - case A_PREFIX: - /* - * In the prefix of a command. - * This not considered a multichar command - * (even tho it uses cmdbuf, etc.). - * It is handled in the commands() switch. - */ - return (NO_MCA); - - case A_DIGIT: - /* - * Entering digits of a number. - * Terminated by a non-digit. - */ - if ((c >= '0' && c <= '9') || c == '.') - break; - switch (editchar(c, ECF_PEEK|ECF_NOHISTORY|ECF_NOCOMPLETE|ECF_NORIGHTLEFT)) - { - case A_NOACTION: - /* - * Ignore this char and get another one. - */ - return (MCA_MORE); - case A_INVALID: - /* - * Not part of the number. - * End the number and treat this char - * as a normal command character. - */ - number = cmd_int(&fraction); - clear_mca(); - cmd_accept(); - return (NO_MCA); - } - break; - - case A_OPT_TOGGLE: - ret = mca_opt_char(c); - if (ret != NO_MCA) - return (ret); - break; - - case A_F_SEARCH: - case A_B_SEARCH: - case A_FILTER: - ret = mca_search_char(c); - if (ret != NO_MCA) - return (ret); - break; - - default: - /* Other multicharacter command. */ - break; - } - - /* - * The multichar command is terminated by a newline. - */ - if (is_newline_char(c)) - { - /* - * Execute the command. - */ - exec_mca(); - return (MCA_DONE); - } - - /* - * Append the char to the command buffer. - */ - if (cmd_char(c) == CC_QUIT) - /* - * Abort the multi-char command. - */ - return (MCA_DONE); - - switch (mca) - { - case A_F_BRACKET: - case A_B_BRACKET: - if (len_cmdbuf() >= 2) - { - /* - * Special case for the bracket-matching commands. - * Execute the command after getting exactly two - * characters from the user. - */ - exec_mca(); - return (MCA_DONE); - } - break; - case A_F_SEARCH: - case A_B_SEARCH: - if (incr_search) - { - /* Incremental search: do a search after every input char. */ - int st = (search_type & (SRCH_FORW|SRCH_BACK|SRCH_NO_MATCH|SRCH_NO_REGEX|SRCH_NO_MOVE|SRCH_WRAP)); - char *pattern = get_cmdbuf(); - cmd_exec(); - if (*pattern == '\0') - { - /* User has backspaced to an empty pattern. */ - undo_search(1); - } else - { - if (search(st | SRCH_INCR, pattern, 1) != 0) - /* No match, invalid pattern, etc. */ - undo_search(1); - } - /* Redraw the search prompt and search string. */ - mca_search(); - cmd_repaint(NULL); - } - break; - } - - /* - * Need another character. - */ - return (MCA_MORE); + int ret; + + switch (mca) + { + case 0: + /* + * We're not in a multicharacter command. + */ + return (NO_MCA); + + case A_PREFIX: + /* + * In the prefix of a command. + * This not considered a multichar command + * (even tho it uses cmdbuf, etc.). + * It is handled in the commands() switch. + */ + return (NO_MCA); + + case A_DIGIT: + /* + * Entering digits of a number. + * Terminated by a non-digit. + */ + if ((c >= '0' && c <= '9') || c == '.') + break; + switch (editchar(c, ECF_PEEK|ECF_NOHISTORY|ECF_NOCOMPLETE|ECF_NORIGHTLEFT)) + { + case A_NOACTION: + /* + * Ignore this char and get another one. + */ + return (MCA_MORE); + case A_INVALID: + /* + * Not part of the number. + * End the number and treat this char + * as a normal command character. + */ + number = cmd_int(&fraction); + clear_mca(); + cmd_accept(); + return (NO_MCA); + } + break; + + case A_OPT_TOGGLE: + ret = mca_opt_char(c); + if (ret != NO_MCA) + return (ret); + break; + + case A_F_SEARCH: + case A_B_SEARCH: + case A_FILTER: + ret = mca_search_char(c); + if (ret != NO_MCA) + return (ret); + break; + + default: + /* Other multicharacter command. */ + break; + } + + /* + * The multichar command is terminated by a newline. + */ + if (is_newline_char(c)) + { + /* + * Execute the command. + */ + exec_mca(); + return (MCA_DONE); + } + + /* + * Append the char to the command buffer. + */ + if (cmd_char(c) == CC_QUIT) + /* + * Abort the multi-char command. + */ + return (MCA_DONE); + + switch (mca) + { + case A_F_BRACKET: + case A_B_BRACKET: + if (len_cmdbuf() >= 2) + { + /* + * Special case for the bracket-matching commands. + * Execute the command after getting exactly two + * characters from the user. + */ + exec_mca(); + return (MCA_DONE); + } + break; + case A_F_SEARCH: + case A_B_SEARCH: + if (incr_search) + { + /* Incremental search: do a search after every input char. */ + int st = (search_type & (SRCH_FORW|SRCH_BACK|SRCH_NO_MATCH|SRCH_NO_REGEX|SRCH_NO_MOVE|SRCH_WRAP)); + char *pattern = get_cmdbuf(); + cmd_exec(); + if (*pattern == '\0') + { + /* User has backspaced to an empty pattern. */ + undo_search(1); + } else + { + if (search(st | SRCH_INCR, pattern, 1) != 0) + /* No match, invalid pattern, etc. */ + undo_search(1); + } + /* Redraw the search prompt and search string. */ + mca_search(); + cmd_repaint(NULL); + } + break; + } + + /* + * Need another character. + */ + return (MCA_MORE); } /* * Discard any buffered file data. */ - static void + static void clear_buffers(VOID_PARAM) { - if (!(ch_getflags() & CH_CANSEEK)) - return; - ch_flush(); - clr_linenum(); + if (!(ch_getflags() & CH_CANSEEK)) + return; + ch_flush(); + clr_linenum(); #if HILITE_SEARCH - clr_hilite(); + clr_hilite(); #endif } /* * Make sure the screen is displayed. */ - static void + static void make_display(VOID_PARAM) { - /* - * If nothing is displayed yet, display starting from initial_scrpos. - */ - if (empty_screen()) - { - if (initial_scrpos.pos == NULL_POSITION) - jump_loc(ch_zero(), 1); - else - jump_loc(initial_scrpos.pos, initial_scrpos.ln); - } else if (screen_trashed) - { - int save_top_scroll = top_scroll; - int save_ignore_eoi = ignore_eoi; - top_scroll = 1; - ignore_eoi = 0; - if (screen_trashed == 2) - { - /* Special case used by ignore_eoi: re-open the input file - * and jump to the end of the file. */ - reopen_curr_ifile(); - jump_forw(); - } - repaint(); - top_scroll = save_top_scroll; - ignore_eoi = save_ignore_eoi; - } + /* + * If nothing is displayed yet, display starting from initial_scrpos. + */ + if (empty_screen()) + { + if (initial_scrpos.pos == NULL_POSITION) + jump_loc(ch_zero(), 1); + else + jump_loc(initial_scrpos.pos, initial_scrpos.ln); + } else if (screen_trashed) + { + int save_top_scroll = top_scroll; + int save_ignore_eoi = ignore_eoi; + top_scroll = 1; + ignore_eoi = 0; + if (screen_trashed == 2) + { + /* Special case used by ignore_eoi: re-open the input file + * and jump to the end of the file. */ + reopen_curr_ifile(); + jump_forw(); + } + repaint(); + top_scroll = save_top_scroll; + ignore_eoi = save_ignore_eoi; + } } /* * Display the appropriate prompt. */ - static void + static void prompt(VOID_PARAM) { - constant char *p; - - if (ungot != NULL && ungot->ug_char != CHAR_END_COMMAND) - { - /* - * No prompt necessary if commands are from - * ungotten chars rather than from the user. - */ - return; - } - - /* - * Make sure the screen is displayed. - */ - make_display(); - bottompos = position(BOTTOM_PLUS_ONE); - - /* - * If we've hit EOF on the last file and the -E flag is set, quit. - */ - if (get_quit_at_eof() == OPT_ONPLUS && - eof_displayed() && !(ch_getflags() & CH_HELPFILE) && - next_ifile(curr_ifile) == NULL_IFILE) - quit(QUIT_OK); - - /* - * If the entire file is displayed and the -F flag is set, quit. - */ - if (quit_if_one_screen && - entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) && - next_ifile(curr_ifile) == NULL_IFILE) - quit(QUIT_OK); + constant char *p; + + if (ungot != NULL && ungot->ug_char != CHAR_END_COMMAND) + { + /* + * No prompt necessary if commands are from + * ungotten chars rather than from the user. + */ + return; + } + + /* + * Make sure the screen is displayed. + */ + make_display(); + bottompos = position(BOTTOM_PLUS_ONE); + + /* + * If we've hit EOF on the last file and the -E flag is set, quit. + */ + if (get_quit_at_eof() == OPT_ONPLUS && + eof_displayed() && !(ch_getflags() & CH_HELPFILE) && + next_ifile(curr_ifile) == NULL_IFILE) + quit(QUIT_OK); + + /* + * If the entire file is displayed and the -F flag is set, quit. + */ + if (quit_if_one_screen && + entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) && + next_ifile(curr_ifile) == NULL_IFILE) + quit(QUIT_OK); #if MSDOS_COMPILER==WIN32C - /* - * In Win32, display the file name in the window title. - */ - if (!(ch_getflags() & CH_HELPFILE)) - { - WCHAR w[MAX_PATH+16]; - p = pr_expand("Less?f - %f.", 0); - MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w)); - SetConsoleTitleW(w); - } + /* + * In Win32, display the file name in the window title. + */ + if (!(ch_getflags() & CH_HELPFILE)) + { + WCHAR w[MAX_PATH+16]; + p = pr_expand("Less?f - %f.", 0); + MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w)); + SetConsoleTitleW(w); + } #endif - /* - * Select the proper prompt and display it. - */ - /* - * If the previous action was a forward movement, - * don't clear the bottom line of the display; - * just print the prompt since the forward movement guarantees - * that we're in the right position to display the prompt. - * Clearing the line could cause a problem: for example, if the last - * line displayed ended at the right screen edge without a newline, - * then clearing would clear the last displayed line rather than - * the prompt line. - */ - if (!forw_prompt) - clear_bot(); - clear_cmd(); - forw_prompt = 0; - p = pr_string(); + /* + * Select the proper prompt and display it. + */ + /* + * If the previous action was a forward movement, + * don't clear the bottom line of the display; + * just print the prompt since the forward movement guarantees + * that we're in the right position to display the prompt. + * Clearing the line could cause a problem: for example, if the last + * line displayed ended at the right screen edge without a newline, + * then clearing would clear the last displayed line rather than + * the prompt line. + */ + if (!forw_prompt) + clear_bot(); + clear_cmd(); + forw_prompt = 0; + p = pr_string(); #if HILITE_SEARCH - if (is_filtering()) - putstr("& "); + if (is_filtering()) + putstr("& "); #endif - if (p == NULL || *p == '\0') - { - at_enter(AT_NORMAL|AT_COLOR_PROMPT); - putchr(':'); - at_exit(); - } else - { + if (p == NULL || *p == '\0') + { + at_enter(AT_NORMAL|AT_COLOR_PROMPT); + putchr(':'); + at_exit(); + } else + { #if MSDOS_COMPILER==WIN32C - WCHAR w[MAX_PATH*2]; - char a[MAX_PATH*2]; - MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w)); - WideCharToMultiByte(utf_mode ? CP_UTF8 : GetConsoleOutputCP(), - 0, w, -1, a, sizeof(a), NULL, NULL); - p = a; + WCHAR w[MAX_PATH*2]; + char a[MAX_PATH*2]; + MultiByteToWideChar(CP_ACP, 0, p, -1, w, sizeof(w)/sizeof(*w)); + WideCharToMultiByte(utf_mode ? CP_UTF8 : GetConsoleOutputCP(), + 0, w, -1, a, sizeof(a), NULL, NULL); + p = a; #endif - at_enter(AT_STANDOUT|AT_COLOR_PROMPT); - putstr(p); - at_exit(); - } - clear_eol(); + at_enter(AT_STANDOUT|AT_COLOR_PROMPT); + putstr(p); + at_exit(); + } + clear_eol(); } /* * Display the less version message. */ - public void + public void dispversion(VOID_PARAM) { - PARG parg; + PARG parg; - parg.p_string = version; - error("less %s", &parg); + parg.p_string = version; + error("less %s", &parg); } /* * Return a character to complete a partial command, if possible. */ - static LWCHAR + static LWCHAR getcc_end_command(VOID_PARAM) { - switch (mca) - { - case A_DIGIT: - /* We have a number but no command. Treat as #g. */ - return ('g'); - case A_F_SEARCH: - case A_B_SEARCH: - /* We have "/string" but no newline. Add the \n. */ - return ('\n'); - default: - /* Some other incomplete command. Let user complete it. */ - return ((ungot == NULL) ? getchr() : 0); - } + switch (mca) + { + case A_DIGIT: + /* We have a number but no command. Treat as #g. */ + return ('g'); + case A_F_SEARCH: + case A_B_SEARCH: + /* We have "/string" but no newline. Add the \n. */ + return ('\n'); + default: + /* Some other incomplete command. Let user complete it. */ + return ((ungot == NULL) ? getchr() : 0); + } } /* @@ -888,146 +888,146 @@ getcc_end_command(VOID_PARAM) * but may come from ungotten characters * (characters previously given to ungetcc or ungetsc). */ - static LWCHAR + static LWCHAR getccu(VOID_PARAM) { - LWCHAR c = 0; - while (c == 0) - { - if (ungot == NULL) - { - /* Normal case: no ungotten chars. - * Get char from the user. */ - c = getchr(); - } else - { - /* Ungotten chars available: - * Take the top of stack (most recent). */ - struct ungot *ug = ungot; - c = ug->ug_char; - ungot = ug->ug_next; - free(ug); - - if (c == CHAR_END_COMMAND) - c = getcc_end_command(); - } - } - return (c); + LWCHAR c = 0; + while (c == 0) + { + if (ungot == NULL) + { + /* Normal case: no ungotten chars. + * Get char from the user. */ + c = getchr(); + } else + { + /* Ungotten chars available: + * Take the top of stack (most recent). */ + struct ungot *ug = ungot; + c = ug->ug_char; + ungot = ug->ug_next; + free(ug); + + if (c == CHAR_END_COMMAND) + c = getcc_end_command(); + } + } + return (c); } /* * Get a command character, but if we receive the orig sequence, * convert it to the repl sequence. */ - static LWCHAR + static LWCHAR getcc_repl(orig, repl, gr_getc, gr_ungetc) - char const* orig; - char const* repl; - LWCHAR (*gr_getc)(VOID_PARAM); - void (*gr_ungetc)(LWCHAR); + char const* orig; + char const* repl; + LWCHAR (*gr_getc)(VOID_PARAM); + void (*gr_ungetc)(LWCHAR); { - LWCHAR c; - LWCHAR keys[16]; - int ki = 0; - - c = (*gr_getc)(); - if (orig == NULL || orig[0] == '\0') - return c; - for (;;) - { - keys[ki] = c; - if (c != orig[ki] || ki >= sizeof(keys)-1) - { - /* This is not orig we have been receiving. - * If we have stashed chars in keys[], - * unget them and return the first one. */ - while (ki > 0) - (*gr_ungetc)(keys[ki--]); - return keys[0]; - } - if (orig[++ki] == '\0') - { - /* We've received the full orig sequence. - * Return the repl sequence. */ - ki = strlen(repl)-1; - while (ki > 0) - (*gr_ungetc)(repl[ki--]); - return repl[0]; - } - /* We've received a partial orig sequence (ki chars of it). - * Get next char and see if it continues to match orig. */ - c = (*gr_getc)(); - } + LWCHAR c; + LWCHAR keys[16]; + int ki = 0; + + c = (*gr_getc)(); + if (orig == NULL || orig[0] == '\0') + return c; + for (;;) + { + keys[ki] = c; + if (c != orig[ki] || ki >= sizeof(keys)-1) + { + /* This is not orig we have been receiving. + * If we have stashed chars in keys[], + * unget them and return the first one. */ + while (ki > 0) + (*gr_ungetc)(keys[ki--]); + return keys[0]; + } + if (orig[++ki] == '\0') + { + /* We've received the full orig sequence. + * Return the repl sequence. */ + ki = strlen(repl)-1; + while (ki > 0) + (*gr_ungetc)(repl[ki--]); + return repl[0]; + } + /* We've received a partial orig sequence (ki chars of it). + * Get next char and see if it continues to match orig. */ + c = (*gr_getc)(); + } } /* * Get command character. */ - public int + public int getcc(VOID_PARAM) { - /* Replace kent (keypad Enter) with a newline. */ - return getcc_repl(kent, "\n", getccu, ungetcc); + /* Replace kent (keypad Enter) with a newline. */ + return getcc_repl(kent, "\n", getccu, ungetcc); } /* * "Unget" a command character. * The next getcc() will return this character. */ - public void + public void ungetcc(c) - LWCHAR c; + LWCHAR c; { - struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot)); + struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot)); - ug->ug_char = c; - ug->ug_next = ungot; - ungot = ug; + ug->ug_char = c; + ug->ug_next = ungot; + ungot = ug; } /* * "Unget" a command character. * If any other chars are already ungotten, put this one after those. */ - public void + public void ungetcc_back(c) - LWCHAR c; + LWCHAR c; { - struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot)); - ug->ug_char = c; - ug->ug_next = NULL; - if (ungot == NULL) - ungot = ug; - else - { - struct ungot *pu; - for (pu = ungot; pu->ug_next != NULL; pu = pu->ug_next) - continue; - pu->ug_next = ug; - } + struct ungot *ug = (struct ungot *) ecalloc(1, sizeof(struct ungot)); + ug->ug_char = c; + ug->ug_next = NULL; + if (ungot == NULL) + ungot = ug; + else + { + struct ungot *pu; + for (pu = ungot; pu->ug_next != NULL; pu = pu->ug_next) + continue; + pu->ug_next = ug; + } } /* * Unget a whole string of command characters. * The next sequence of getcc()'s will return this string. */ - public void + public void ungetsc(s) - char *s; + char *s; { - while (*s != '\0') - ungetcc_back(*s++); + while (*s != '\0') + ungetcc_back(*s++); } /* * Peek the next command character, without consuming it. */ - public LWCHAR + public LWCHAR peekcc(VOID_PARAM) { - LWCHAR c = getcc(); - ungetcc(c); - return c; + LWCHAR c = getcc(); + ungetcc(c); + return c; } /* @@ -1035,1020 +1035,1020 @@ peekcc(VOID_PARAM) * If SRCH_FIRST_FILE is set, begin searching at the first file. * If SRCH_PAST_EOF is set, continue the search thru multiple files. */ - static void + static void multi_search(pattern, n, silent) - char *pattern; - int n; - int silent; + char *pattern; + int n; + int silent; { - int nomore; - IFILE save_ifile; - int changed_file; - - changed_file = 0; - save_ifile = save_curr_ifile(); - - if (search_type & SRCH_FIRST_FILE) - { - /* - * Start at the first (or last) file - * in the command line list. - */ - if (search_type & SRCH_FORW) - nomore = edit_first(); - else - nomore = edit_last(); - if (nomore) - { - unsave_ifile(save_ifile); - return; - } - changed_file = 1; - search_type &= ~SRCH_FIRST_FILE; - } - - for (;;) - { - n = search(search_type, pattern, n); - /* - * The SRCH_NO_MOVE flag doesn't "stick": it gets cleared - * after being used once. This allows "n" to work after - * using a /@@ search. - */ - search_type &= ~SRCH_NO_MOVE; - if (n == 0) - { - /* - * Found it. - */ - unsave_ifile(save_ifile); - return; - } - - if (n < 0) - /* - * Some kind of error in the search. - * Error message has been printed by search(). - */ - break; - - if ((search_type & SRCH_PAST_EOF) == 0) - /* - * We didn't find a match, but we're - * supposed to search only one file. - */ - break; - /* - * Move on to the next file. - */ - if (search_type & SRCH_FORW) - nomore = edit_next(1); - else - nomore = edit_prev(1); - if (nomore) - break; - changed_file = 1; - } - - /* - * Didn't find it. - * Print an error message if we haven't already. - */ - if (n > 0 && !silent) - error("Pattern not found", NULL_PARG); - - if (changed_file) - { - /* - * Restore the file we were originally viewing. - */ - reedit_ifile(save_ifile); - } else - { - unsave_ifile(save_ifile); - } + int nomore; + IFILE save_ifile; + int changed_file; + + changed_file = 0; + save_ifile = save_curr_ifile(); + + if (search_type & SRCH_FIRST_FILE) + { + /* + * Start at the first (or last) file + * in the command line list. + */ + if (search_type & SRCH_FORW) + nomore = edit_first(); + else + nomore = edit_last(); + if (nomore) + { + unsave_ifile(save_ifile); + return; + } + changed_file = 1; + search_type &= ~SRCH_FIRST_FILE; + } + + for (;;) + { + n = search(search_type, pattern, n); + /* + * The SRCH_NO_MOVE flag doesn't "stick": it gets cleared + * after being used once. This allows "n" to work after + * using a /@@ search. + */ + search_type &= ~SRCH_NO_MOVE; + if (n == 0) + { + /* + * Found it. + */ + unsave_ifile(save_ifile); + return; + } + + if (n < 0) + /* + * Some kind of error in the search. + * Error message has been printed by search(). + */ + break; + + if ((search_type & SRCH_PAST_EOF) == 0) + /* + * We didn't find a match, but we're + * supposed to search only one file. + */ + break; + /* + * Move on to the next file. + */ + if (search_type & SRCH_FORW) + nomore = edit_next(1); + else + nomore = edit_prev(1); + if (nomore) + break; + changed_file = 1; + } + + /* + * Didn't find it. + * Print an error message if we haven't already. + */ + if (n > 0 && !silent) + error("Pattern not found", NULL_PARG); + + if (changed_file) + { + /* + * Restore the file we were originally viewing. + */ + reedit_ifile(save_ifile); + } else + { + unsave_ifile(save_ifile); + } } /* * Forward forever, or until a highlighted line appears. */ - static int + static int forw_loop(until_hilite) - int until_hilite; + int until_hilite; { - POSITION curr_len; - - if (ch_getflags() & CH_HELPFILE) - return (A_NOACTION); - - cmd_exec(); - jump_forw_buffered(); - curr_len = ch_length(); - highest_hilite = until_hilite ? curr_len : NULL_POSITION; - ignore_eoi = 1; - while (!sigs) - { - if (until_hilite && highest_hilite > curr_len) - { - bell(); - break; - } - make_display(); - forward(1, 0, 0); - } - ignore_eoi = 0; - ch_set_eof(); - - /* - * This gets us back in "F mode" after processing - * a non-abort signal (e.g. window-change). - */ - if (sigs && !ABORT_SIGS()) - return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER); - - return (A_NOACTION); + POSITION curr_len; + + if (ch_getflags() & CH_HELPFILE) + return (A_NOACTION); + + cmd_exec(); + jump_forw_buffered(); + curr_len = ch_length(); + highest_hilite = until_hilite ? curr_len : NULL_POSITION; + ignore_eoi = 1; + while (!sigs) + { + if (until_hilite && highest_hilite > curr_len) + { + bell(); + break; + } + make_display(); + forward(1, 0, 0); + } + ignore_eoi = 0; + ch_set_eof(); + + /* + * This gets us back in "F mode" after processing + * a non-abort signal (e.g. window-change). + */ + if (sigs && !ABORT_SIGS()) + return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER); + + return (A_NOACTION); } /* * Main command processor. * Accept and execute commands until a quit command. */ - public void + public void commands(VOID_PARAM) { - int c; - int action; - char *cbuf; - int newaction; - int save_jump_sline; - int save_search_type; - char *extra; - char tbuf[2]; - PARG parg; - IFILE old_ifile; - IFILE new_ifile; - char *tagfile; - - search_type = SRCH_FORW; - wscroll = (sc_height + 1) / 2; - newaction = A_NOACTION; - - for (;;) - { - clear_mca(); - cmd_accept(); - number = 0; - curropt = NULL; - - /* - * See if any signals need processing. - */ - if (sigs) - { - psignals(); - if (quitting) - quit(QUIT_SAVED_STATUS); - } - - /* - * See if window size changed, for systems that don't - * generate SIGWINCH. - */ - check_winch(); - - /* - * Display prompt and accept a character. - */ - cmd_reset(); - prompt(); - if (sigs) - continue; - if (newaction == A_NOACTION) - c = getcc(); - - again: - if (sigs) - continue; - - if (newaction != A_NOACTION) - { - action = newaction; - newaction = A_NOACTION; - } else - { - /* - * If we are in a multicharacter command, call mca_char. - * Otherwise we call fcmd_decode to determine the - * action to be performed. - */ - if (mca) - switch (mca_char(c)) - { - case MCA_MORE: - /* - * Need another character. - */ - c = getcc(); - goto again; - case MCA_DONE: - /* - * Command has been handled by mca_char. - * Start clean with a prompt. - */ - continue; - case NO_MCA: - /* - * Not a multi-char command - * (at least, not anymore). - */ - break; - } - - /* - * Decode the command character and decide what to do. - */ - if (mca) - { - /* - * We're in a multichar command. - * Add the character to the command buffer - * and display it on the screen. - * If the user backspaces past the start - * of the line, abort the command. - */ - if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0) - continue; - cbuf = get_cmdbuf(); - } else - { - /* - * Don't use cmd_char if we're starting fresh - * at the beginning of a command, because we - * don't want to echo the command until we know - * it is a multichar command. We also don't - * want erase_char/kill_char to be treated - * as line editing characters. - */ - tbuf[0] = c; - tbuf[1] = '\0'; - cbuf = tbuf; - } - extra = NULL; - action = fcmd_decode(cbuf, &extra); - /* - * If an "extra" string was returned, - * process it as a string of command characters. - */ - if (extra != NULL) - ungetsc(extra); - } - /* - * Clear the cmdbuf string. - * (But not if we're in the prefix of a command, - * because the partial command string is kept there.) - */ - if (action != A_PREFIX) - cmd_reset(); - - switch (action) - { - case A_DIGIT: - /* - * First digit of a number. - */ - start_mca(A_DIGIT, ":", (void*)NULL, CF_QUIT_ON_ERASE); - goto again; - - case A_F_WINDOW: - /* - * Forward one window (and set the window size). - */ - if (number > 0) - swindow = (int) number; - /* FALLTHRU */ - case A_F_SCREEN: - /* - * Forward one screen. - */ - if (number <= 0) - number = get_swindow(); - cmd_exec(); - if (show_attn) - set_attnpos(bottompos); - forward((int) number, 0, 1); - break; - - case A_B_WINDOW: - /* - * Backward one window (and set the window size). - */ - if (number > 0) - swindow = (int) number; - /* FALLTHRU */ - case A_B_SCREEN: - /* - * Backward one screen. - */ - if (number <= 0) - number = get_swindow(); - cmd_exec(); - backward((int) number, 0, 1); - break; - - case A_F_LINE: - /* - * Forward N (default 1) line. - */ - if (number <= 0) - number = 1; - cmd_exec(); - if (show_attn == OPT_ONPLUS && number > 1) - set_attnpos(bottompos); - forward((int) number, 0, 0); - break; - - case A_B_LINE: - /* - * Backward N (default 1) line. - */ - if (number <= 0) - number = 1; - cmd_exec(); - backward((int) number, 0, 0); - break; - - case A_F_MOUSE: - /* - * Forward wheel_lines lines. - */ - cmd_exec(); - forward(wheel_lines, 0, 0); - break; - - case A_B_MOUSE: - /* - * Backward wheel_lines lines. - */ - cmd_exec(); - backward(wheel_lines, 0, 0); - break; - - case A_FF_LINE: - /* - * Force forward N (default 1) line. - */ - if (number <= 0) - number = 1; - cmd_exec(); - if (show_attn == OPT_ONPLUS && number > 1) - set_attnpos(bottompos); - forward((int) number, 1, 0); - break; - - case A_BF_LINE: - /* - * Force backward N (default 1) line. - */ - if (number <= 0) - number = 1; - cmd_exec(); - backward((int) number, 1, 0); - break; - - case A_FF_SCREEN: - /* - * Force forward one screen. - */ - if (number <= 0) - number = get_swindow(); - cmd_exec(); - if (show_attn == OPT_ONPLUS) - set_attnpos(bottompos); - forward((int) number, 1, 0); - break; - - case A_F_FOREVER: - /* - * Forward forever, ignoring EOF. - */ - if (show_attn) - set_attnpos(bottompos); - newaction = forw_loop(0); - break; - - case A_F_UNTIL_HILITE: - newaction = forw_loop(1); - break; - - case A_F_SCROLL: - /* - * Forward N lines - * (default same as last 'd' or 'u' command). - */ - if (number > 0) - wscroll = (int) number; - cmd_exec(); - if (show_attn == OPT_ONPLUS) - set_attnpos(bottompos); - forward(wscroll, 0, 0); - break; - - case A_B_SCROLL: - /* - * Forward N lines - * (default same as last 'd' or 'u' command). - */ - if (number > 0) - wscroll = (int) number; - cmd_exec(); - backward(wscroll, 0, 0); - break; - - case A_FREPAINT: - /* - * Flush buffers, then repaint screen. - * Don't flush the buffers on a pipe! - */ - clear_buffers(); - /* FALLTHRU */ - case A_REPAINT: - /* - * Repaint screen. - */ - cmd_exec(); - repaint(); - break; - - case A_GOLINE: - /* - * Go to line N, default beginning of file. - * If N <= 0, ignore jump_sline in order to avoid - * empty lines before the beginning of the file. - */ - save_jump_sline = jump_sline; - if (number <= 0) - { - number = 1; - jump_sline = 0; - } - cmd_exec(); - jump_back(number); - jump_sline = save_jump_sline; - break; - - case A_PERCENT: - /* - * Go to a specified percentage into the file. - */ - if (number < 0) - { - number = 0; - fraction = 0; - } - if (number > 100 || (number == 100 && fraction != 0)) - { - number = 100; - fraction = 0; - } - cmd_exec(); - jump_percent((int) number, fraction); - break; - - case A_GOEND: - /* - * Go to line N, default end of file. - */ - cmd_exec(); - if (number <= 0) - jump_forw(); - else - jump_back(number); - break; - - case A_GOEND_BUF: - /* - * Go to line N, default last buffered byte. - */ - cmd_exec(); - if (number <= 0) - jump_forw_buffered(); - else - jump_back(number); - break; - - case A_GOPOS: - /* - * Go to a specified byte position in the file. - */ - cmd_exec(); - if (number < 0) - number = 0; - jump_line_loc((POSITION) number, jump_sline); - break; - - case A_STAT: - /* - * Print file name, etc. - */ - if (ch_getflags() & CH_HELPFILE) - break; - cmd_exec(); - parg.p_string = eq_message(); - error("%s", &parg); - break; - - case A_VERSION: - /* - * Print version number. - */ - cmd_exec(); - dispversion(); - break; - - case A_QUIT: - /* - * Exit. - */ - if (curr_ifile != NULL_IFILE && - ch_getflags() & CH_HELPFILE) - { - /* - * Quit while viewing the help file - * just means return to viewing the - * previous file. - */ - hshift = save_hshift; - bs_mode = save_bs_mode; - if (edit_prev(1) == 0) - break; - } - if (extra != NULL) - quit(*extra); - quit(QUIT_OK); - break; + int c; + int action; + char *cbuf; + int newaction; + int save_jump_sline; + int save_search_type; + char *extra; + char tbuf[2]; + PARG parg; + IFILE old_ifile; + IFILE new_ifile; + char *tagfile; + + search_type = SRCH_FORW; + wscroll = (sc_height + 1) / 2; + newaction = A_NOACTION; + + for (;;) + { + clear_mca(); + cmd_accept(); + number = 0; + curropt = NULL; + + /* + * See if any signals need processing. + */ + if (sigs) + { + psignals(); + if (quitting) + quit(QUIT_SAVED_STATUS); + } + + /* + * See if window size changed, for systems that don't + * generate SIGWINCH. + */ + check_winch(); + + /* + * Display prompt and accept a character. + */ + cmd_reset(); + prompt(); + if (sigs) + continue; + if (newaction == A_NOACTION) + c = getcc(); + + again: + if (sigs) + continue; + + if (newaction != A_NOACTION) + { + action = newaction; + newaction = A_NOACTION; + } else + { + /* + * If we are in a multicharacter command, call mca_char. + * Otherwise we call fcmd_decode to determine the + * action to be performed. + */ + if (mca) + switch (mca_char(c)) + { + case MCA_MORE: + /* + * Need another character. + */ + c = getcc(); + goto again; + case MCA_DONE: + /* + * Command has been handled by mca_char. + * Start clean with a prompt. + */ + continue; + case NO_MCA: + /* + * Not a multi-char command + * (at least, not anymore). + */ + break; + } + + /* + * Decode the command character and decide what to do. + */ + if (mca) + { + /* + * We're in a multichar command. + * Add the character to the command buffer + * and display it on the screen. + * If the user backspaces past the start + * of the line, abort the command. + */ + if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0) + continue; + cbuf = get_cmdbuf(); + } else + { + /* + * Don't use cmd_char if we're starting fresh + * at the beginning of a command, because we + * don't want to echo the command until we know + * it is a multichar command. We also don't + * want erase_char/kill_char to be treated + * as line editing characters. + */ + tbuf[0] = c; + tbuf[1] = '\0'; + cbuf = tbuf; + } + extra = NULL; + action = fcmd_decode(cbuf, &extra); + /* + * If an "extra" string was returned, + * process it as a string of command characters. + */ + if (extra != NULL) + ungetsc(extra); + } + /* + * Clear the cmdbuf string. + * (But not if we're in the prefix of a command, + * because the partial command string is kept there.) + */ + if (action != A_PREFIX) + cmd_reset(); + + switch (action) + { + case A_DIGIT: + /* + * First digit of a number. + */ + start_mca(A_DIGIT, ":", (void*)NULL, CF_QUIT_ON_ERASE); + goto again; + + case A_F_WINDOW: + /* + * Forward one window (and set the window size). + */ + if (number > 0) + swindow = (int) number; + /* FALLTHRU */ + case A_F_SCREEN: + /* + * Forward one screen. + */ + if (number <= 0) + number = get_swindow(); + cmd_exec(); + if (show_attn) + set_attnpos(bottompos); + forward((int) number, 0, 1); + break; + + case A_B_WINDOW: + /* + * Backward one window (and set the window size). + */ + if (number > 0) + swindow = (int) number; + /* FALLTHRU */ + case A_B_SCREEN: + /* + * Backward one screen. + */ + if (number <= 0) + number = get_swindow(); + cmd_exec(); + backward((int) number, 0, 1); + break; + + case A_F_LINE: + /* + * Forward N (default 1) line. + */ + if (number <= 0) + number = 1; + cmd_exec(); + if (show_attn == OPT_ONPLUS && number > 1) + set_attnpos(bottompos); + forward((int) number, 0, 0); + break; + + case A_B_LINE: + /* + * Backward N (default 1) line. + */ + if (number <= 0) + number = 1; + cmd_exec(); + backward((int) number, 0, 0); + break; + + case A_F_MOUSE: + /* + * Forward wheel_lines lines. + */ + cmd_exec(); + forward(wheel_lines, 0, 0); + break; + + case A_B_MOUSE: + /* + * Backward wheel_lines lines. + */ + cmd_exec(); + backward(wheel_lines, 0, 0); + break; + + case A_FF_LINE: + /* + * Force forward N (default 1) line. + */ + if (number <= 0) + number = 1; + cmd_exec(); + if (show_attn == OPT_ONPLUS && number > 1) + set_attnpos(bottompos); + forward((int) number, 1, 0); + break; + + case A_BF_LINE: + /* + * Force backward N (default 1) line. + */ + if (number <= 0) + number = 1; + cmd_exec(); + backward((int) number, 1, 0); + break; + + case A_FF_SCREEN: + /* + * Force forward one screen. + */ + if (number <= 0) + number = get_swindow(); + cmd_exec(); + if (show_attn == OPT_ONPLUS) + set_attnpos(bottompos); + forward((int) number, 1, 0); + break; + + case A_F_FOREVER: + /* + * Forward forever, ignoring EOF. + */ + if (show_attn) + set_attnpos(bottompos); + newaction = forw_loop(0); + break; + + case A_F_UNTIL_HILITE: + newaction = forw_loop(1); + break; + + case A_F_SCROLL: + /* + * Forward N lines + * (default same as last 'd' or 'u' command). + */ + if (number > 0) + wscroll = (int) number; + cmd_exec(); + if (show_attn == OPT_ONPLUS) + set_attnpos(bottompos); + forward(wscroll, 0, 0); + break; + + case A_B_SCROLL: + /* + * Forward N lines + * (default same as last 'd' or 'u' command). + */ + if (number > 0) + wscroll = (int) number; + cmd_exec(); + backward(wscroll, 0, 0); + break; + + case A_FREPAINT: + /* + * Flush buffers, then repaint screen. + * Don't flush the buffers on a pipe! + */ + clear_buffers(); + /* FALLTHRU */ + case A_REPAINT: + /* + * Repaint screen. + */ + cmd_exec(); + repaint(); + break; + + case A_GOLINE: + /* + * Go to line N, default beginning of file. + * If N <= 0, ignore jump_sline in order to avoid + * empty lines before the beginning of the file. + */ + save_jump_sline = jump_sline; + if (number <= 0) + { + number = 1; + jump_sline = 0; + } + cmd_exec(); + jump_back(number); + jump_sline = save_jump_sline; + break; + + case A_PERCENT: + /* + * Go to a specified percentage into the file. + */ + if (number < 0) + { + number = 0; + fraction = 0; + } + if (number > 100 || (number == 100 && fraction != 0)) + { + number = 100; + fraction = 0; + } + cmd_exec(); + jump_percent((int) number, fraction); + break; + + case A_GOEND: + /* + * Go to line N, default end of file. + */ + cmd_exec(); + if (number <= 0) + jump_forw(); + else + jump_back(number); + break; + + case A_GOEND_BUF: + /* + * Go to line N, default last buffered byte. + */ + cmd_exec(); + if (number <= 0) + jump_forw_buffered(); + else + jump_back(number); + break; + + case A_GOPOS: + /* + * Go to a specified byte position in the file. + */ + cmd_exec(); + if (number < 0) + number = 0; + jump_line_loc((POSITION) number, jump_sline); + break; + + case A_STAT: + /* + * Print file name, etc. + */ + if (ch_getflags() & CH_HELPFILE) + break; + cmd_exec(); + parg.p_string = eq_message(); + error("%s", &parg); + break; + + case A_VERSION: + /* + * Print version number. + */ + cmd_exec(); + dispversion(); + break; + + case A_QUIT: + /* + * Exit. + */ + if (curr_ifile != NULL_IFILE && + ch_getflags() & CH_HELPFILE) + { + /* + * Quit while viewing the help file + * just means return to viewing the + * previous file. + */ + hshift = save_hshift; + bs_mode = save_bs_mode; + if (edit_prev(1) == 0) + break; + } + if (extra != NULL) + quit(*extra); + quit(QUIT_OK); + break; /* * Define abbreviation for a commonly used sequence below. */ #define DO_SEARCH() \ - if (number <= 0) number = 1; \ - mca_search(); \ - cmd_exec(); \ - multi_search((char *)NULL, (int) number, 0); - - - case A_F_SEARCH: - /* - * Search forward for a pattern. - * Get the first char of the pattern. - */ - search_type = SRCH_FORW; - if (number <= 0) - number = 1; - mca_search(); - c = getcc(); - goto again; - - case A_B_SEARCH: - /* - * Search backward for a pattern. - * Get the first char of the pattern. - */ - search_type = SRCH_BACK; - if (number <= 0) - number = 1; - mca_search(); - c = getcc(); - goto again; - - case A_FILTER: + if (number <= 0) number = 1; \ + mca_search(); \ + cmd_exec(); \ + multi_search((char *)NULL, (int) number, 0); + + + case A_F_SEARCH: + /* + * Search forward for a pattern. + * Get the first char of the pattern. + */ + search_type = SRCH_FORW; + if (number <= 0) + number = 1; + mca_search(); + c = getcc(); + goto again; + + case A_B_SEARCH: + /* + * Search backward for a pattern. + * Get the first char of the pattern. + */ + search_type = SRCH_BACK; + if (number <= 0) + number = 1; + mca_search(); + c = getcc(); + goto again; + + case A_FILTER: #if HILITE_SEARCH - search_type = SRCH_FORW | SRCH_FILTER; - mca_search(); - c = getcc(); - goto again; + search_type = SRCH_FORW | SRCH_FILTER; + mca_search(); + c = getcc(); + goto again; #else - error("Command not available", NULL_PARG); - break; + error("Command not available", NULL_PARG); + break; #endif - case A_AGAIN_SEARCH: - /* - * Repeat previous search. - */ - DO_SEARCH(); - break; - - case A_T_AGAIN_SEARCH: - /* - * Repeat previous search, multiple files. - */ - search_type |= SRCH_PAST_EOF; - DO_SEARCH(); - break; - - case A_REVERSE_SEARCH: - /* - * Repeat previous search, in reverse direction. - */ - save_search_type = search_type; - search_type = SRCH_REVERSE(search_type); - DO_SEARCH(); - search_type = save_search_type; - break; - - case A_T_REVERSE_SEARCH: - /* - * Repeat previous search, - * multiple files in reverse direction. - */ - save_search_type = search_type; - search_type = SRCH_REVERSE(search_type); - search_type |= SRCH_PAST_EOF; - DO_SEARCH(); - search_type = save_search_type; - break; - - case A_UNDO_SEARCH: - case A_CLR_SEARCH: - /* - * Clear search string highlighting. - */ - undo_search(action == A_CLR_SEARCH); - break; - - case A_HELP: - /* - * Help. - */ - if (ch_getflags() & CH_HELPFILE) - break; - cmd_exec(); - save_hshift = hshift; - hshift = 0; - save_bs_mode = bs_mode; - bs_mode = BS_SPECIAL; - (void) edit(FAKE_HELPFILE); - break; - - case A_EXAMINE: - /* - * Edit a new file. Get the filename. - */ + case A_AGAIN_SEARCH: + /* + * Repeat previous search. + */ + DO_SEARCH(); + break; + + case A_T_AGAIN_SEARCH: + /* + * Repeat previous search, multiple files. + */ + search_type |= SRCH_PAST_EOF; + DO_SEARCH(); + break; + + case A_REVERSE_SEARCH: + /* + * Repeat previous search, in reverse direction. + */ + save_search_type = search_type; + search_type = SRCH_REVERSE(search_type); + DO_SEARCH(); + search_type = save_search_type; + break; + + case A_T_REVERSE_SEARCH: + /* + * Repeat previous search, + * multiple files in reverse direction. + */ + save_search_type = search_type; + search_type = SRCH_REVERSE(search_type); + search_type |= SRCH_PAST_EOF; + DO_SEARCH(); + search_type = save_search_type; + break; + + case A_UNDO_SEARCH: + case A_CLR_SEARCH: + /* + * Clear search string highlighting. + */ + undo_search(action == A_CLR_SEARCH); + break; + + case A_HELP: + /* + * Help. + */ + if (ch_getflags() & CH_HELPFILE) + break; + cmd_exec(); + save_hshift = hshift; + hshift = 0; + save_bs_mode = bs_mode; + bs_mode = BS_SPECIAL; + (void) edit(FAKE_HELPFILE); + break; + + case A_EXAMINE: + /* + * Edit a new file. Get the filename. + */ #if EXAMINE - if (!secure) - { - start_mca(A_EXAMINE, "Examine: ", ml_examine, 0); - c = getcc(); - goto again; - } + if (!secure) + { + start_mca(A_EXAMINE, "Examine: ", ml_examine, 0); + c = getcc(); + goto again; + } #endif - error("Command not available", NULL_PARG); - break; - - case A_VISUAL: - /* - * Invoke an editor on the input file. - */ + error("Command not available", NULL_PARG); + break; + + case A_VISUAL: + /* + * Invoke an editor on the input file. + */ #if EDITOR - if (!secure) - { - if (ch_getflags() & CH_HELPFILE) - break; - if (strcmp(get_filename(curr_ifile), "-") == 0) - { - error("Cannot edit standard input", NULL_PARG); - break; - } - if (get_altfilename(curr_ifile) != NULL) - { - error("WARNING: This file was viewed via LESSOPEN", - NULL_PARG); - } - start_mca(A_SHELL, "!", ml_shell, 0); - /* - * Expand the editor prototype string - * and pass it to the system to execute. - * (Make sure the screen is displayed so the - * expansion of "+%lm" works.) - */ - make_display(); - cmd_exec(); - lsystem(pr_expand(editproto, 0), (char*)NULL); - break; - } + if (!secure) + { + if (ch_getflags() & CH_HELPFILE) + break; + if (strcmp(get_filename(curr_ifile), "-") == 0) + { + error("Cannot edit standard input", NULL_PARG); + break; + } + if (get_altfilename(curr_ifile) != NULL) + { + error("WARNING: This file was viewed via LESSOPEN", + NULL_PARG); + } + start_mca(A_SHELL, "!", ml_shell, 0); + /* + * Expand the editor prototype string + * and pass it to the system to execute. + * (Make sure the screen is displayed so the + * expansion of "+%lm" works.) + */ + make_display(); + cmd_exec(); + lsystem(pr_expand(editproto, 0), (char*)NULL); + break; + } #endif - error("Command not available", NULL_PARG); - break; + error("Command not available", NULL_PARG); + break; - case A_NEXT_FILE: - /* - * Examine next file. - */ + case A_NEXT_FILE: + /* + * Examine next file. + */ #if TAGS - if (ntags()) - { - error("No next file", NULL_PARG); - break; - } + if (ntags()) + { + error("No next file", NULL_PARG); + break; + } #endif - if (number <= 0) - number = 1; - if (edit_next((int) number)) - { - if (get_quit_at_eof() && eof_displayed() && - !(ch_getflags() & CH_HELPFILE)) - quit(QUIT_OK); - parg.p_string = (number > 1) ? "(N-th) " : ""; - error("No %snext file", &parg); - } - break; - - case A_PREV_FILE: - /* - * Examine previous file. - */ + if (number <= 0) + number = 1; + if (edit_next((int) number)) + { + if (get_quit_at_eof() && eof_displayed() && + !(ch_getflags() & CH_HELPFILE)) + quit(QUIT_OK); + parg.p_string = (number > 1) ? "(N-th) " : ""; + error("No %snext file", &parg); + } + break; + + case A_PREV_FILE: + /* + * Examine previous file. + */ #if TAGS - if (ntags()) - { - error("No previous file", NULL_PARG); - break; - } + if (ntags()) + { + error("No previous file", NULL_PARG); + break; + } #endif - if (number <= 0) - number = 1; - if (edit_prev((int) number)) - { - parg.p_string = (number > 1) ? "(N-th) " : ""; - error("No %sprevious file", &parg); - } - break; - - case A_NEXT_TAG: - /* - * Jump to the next tag in the current tag list. - */ + if (number <= 0) + number = 1; + if (edit_prev((int) number)) + { + parg.p_string = (number > 1) ? "(N-th) " : ""; + error("No %sprevious file", &parg); + } + break; + + case A_NEXT_TAG: + /* + * Jump to the next tag in the current tag list. + */ #if TAGS - if (number <= 0) - number = 1; - tagfile = nexttag((int) number); - if (tagfile == NULL) - { - error("No next tag", NULL_PARG); - break; - } - cmd_exec(); - if (edit(tagfile) == 0) - { - POSITION pos = tagsearch(); - if (pos != NULL_POSITION) - jump_loc(pos, jump_sline); - } + if (number <= 0) + number = 1; + tagfile = nexttag((int) number); + if (tagfile == NULL) + { + error("No next tag", NULL_PARG); + break; + } + cmd_exec(); + if (edit(tagfile) == 0) + { + POSITION pos = tagsearch(); + if (pos != NULL_POSITION) + jump_loc(pos, jump_sline); + } #else - error("Command not available", NULL_PARG); + error("Command not available", NULL_PARG); #endif - break; + break; - case A_PREV_TAG: - /* - * Jump to the previous tag in the current tag list. - */ + case A_PREV_TAG: + /* + * Jump to the previous tag in the current tag list. + */ #if TAGS - if (number <= 0) - number = 1; - tagfile = prevtag((int) number); - if (tagfile == NULL) - { - error("No previous tag", NULL_PARG); - break; - } - cmd_exec(); - if (edit(tagfile) == 0) - { - POSITION pos = tagsearch(); - if (pos != NULL_POSITION) - jump_loc(pos, jump_sline); - } + if (number <= 0) + number = 1; + tagfile = prevtag((int) number); + if (tagfile == NULL) + { + error("No previous tag", NULL_PARG); + break; + } + cmd_exec(); + if (edit(tagfile) == 0) + { + POSITION pos = tagsearch(); + if (pos != NULL_POSITION) + jump_loc(pos, jump_sline); + } #else - error("Command not available", NULL_PARG); + error("Command not available", NULL_PARG); #endif - break; - - case A_INDEX_FILE: - /* - * Examine a particular file. - */ - if (number <= 0) - number = 1; - if (edit_index((int) number)) - error("No such file", NULL_PARG); - break; - - case A_REMOVE_FILE: - /* - * Remove a file from the input file list. - */ - if (ch_getflags() & CH_HELPFILE) - break; - old_ifile = curr_ifile; - new_ifile = getoff_ifile(curr_ifile); - if (new_ifile == NULL_IFILE) - { - bell(); - break; - } - if (edit_ifile(new_ifile) != 0) - { - reedit_ifile(old_ifile); - break; - } - del_ifile(old_ifile); - break; - - case A_OPT_TOGGLE: - /* - * Change the setting of an option. - */ - optflag = OPT_TOGGLE; - optgetname = FALSE; - mca_opt_toggle(); - c = getcc(); - cbuf = opt_toggle_disallowed(c); - if (cbuf != NULL) - { - error(cbuf, NULL_PARG); - break; - } - goto again; - - case A_DISP_OPTION: - /* - * Report the setting of an option. - */ - optflag = OPT_NO_TOGGLE; - optgetname = FALSE; - mca_opt_toggle(); - c = getcc(); - goto again; - - case A_FIRSTCMD: - /* - * Set an initial command for new files. - */ - start_mca(A_FIRSTCMD, "+", (void*)NULL, 0); - c = getcc(); - goto again; - - case A_SHELL: - /* - * Shell escape. - */ + break; + + case A_INDEX_FILE: + /* + * Examine a particular file. + */ + if (number <= 0) + number = 1; + if (edit_index((int) number)) + error("No such file", NULL_PARG); + break; + + case A_REMOVE_FILE: + /* + * Remove a file from the input file list. + */ + if (ch_getflags() & CH_HELPFILE) + break; + old_ifile = curr_ifile; + new_ifile = getoff_ifile(curr_ifile); + if (new_ifile == NULL_IFILE) + { + bell(); + break; + } + if (edit_ifile(new_ifile) != 0) + { + reedit_ifile(old_ifile); + break; + } + del_ifile(old_ifile); + break; + + case A_OPT_TOGGLE: + /* + * Change the setting of an option. + */ + optflag = OPT_TOGGLE; + optgetname = FALSE; + mca_opt_toggle(); + c = getcc(); + cbuf = opt_toggle_disallowed(c); + if (cbuf != NULL) + { + error(cbuf, NULL_PARG); + break; + } + goto again; + + case A_DISP_OPTION: + /* + * Report the setting of an option. + */ + optflag = OPT_NO_TOGGLE; + optgetname = FALSE; + mca_opt_toggle(); + c = getcc(); + goto again; + + case A_FIRSTCMD: + /* + * Set an initial command for new files. + */ + start_mca(A_FIRSTCMD, "+", (void*)NULL, 0); + c = getcc(); + goto again; + + case A_SHELL: + /* + * Shell escape. + */ #if SHELL_ESCAPE - if (!secure) - { - start_mca(A_SHELL, "!", ml_shell, 0); - c = getcc(); - goto again; - } + if (!secure) + { + start_mca(A_SHELL, "!", ml_shell, 0); + c = getcc(); + goto again; + } #endif - error("Command not available", NULL_PARG); - break; - - case A_SETMARK: - case A_SETMARKBOT: - /* - * Set a mark. - */ - if (ch_getflags() & CH_HELPFILE) - break; - start_mca(A_SETMARK, "set mark: ", (void*)NULL, 0); - c = getcc(); - if (is_erase_char(c) || is_newline_char(c)) - break; - setmark(c, action == A_SETMARKBOT ? BOTTOM : TOP); - repaint(); - break; - - case A_CLRMARK: - /* - * Clear a mark. - */ - start_mca(A_CLRMARK, "clear mark: ", (void*)NULL, 0); - c = getcc(); - if (is_erase_char(c) || is_newline_char(c)) - break; - clrmark(c); - repaint(); - break; - - case A_GOMARK: - /* - * Jump to a marked position. - */ - start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0); - c = getcc(); - if (is_erase_char(c) || is_newline_char(c)) - break; - cmd_exec(); - gomark(c); - break; - - case A_PIPE: - /* - * Write part of the input to a pipe to a shell command. - */ + error("Command not available", NULL_PARG); + break; + + case A_SETMARK: + case A_SETMARKBOT: + /* + * Set a mark. + */ + if (ch_getflags() & CH_HELPFILE) + break; + start_mca(A_SETMARK, "set mark: ", (void*)NULL, 0); + c = getcc(); + if (is_erase_char(c) || is_newline_char(c)) + break; + setmark(c, action == A_SETMARKBOT ? BOTTOM : TOP); + repaint(); + break; + + case A_CLRMARK: + /* + * Clear a mark. + */ + start_mca(A_CLRMARK, "clear mark: ", (void*)NULL, 0); + c = getcc(); + if (is_erase_char(c) || is_newline_char(c)) + break; + clrmark(c); + repaint(); + break; + + case A_GOMARK: + /* + * Jump to a marked position. + */ + start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0); + c = getcc(); + if (is_erase_char(c) || is_newline_char(c)) + break; + cmd_exec(); + gomark(c); + break; + + case A_PIPE: + /* + * Write part of the input to a pipe to a shell command. + */ #if PIPEC - if (!secure) - { - start_mca(A_PIPE, "|mark: ", (void*)NULL, 0); - c = getcc(); - if (is_erase_char(c)) - break; - if (is_newline_char(c)) - c = '.'; - if (badmark(c)) - break; - pipec = c; - start_mca(A_PIPE, "!", ml_shell, 0); - c = getcc(); - goto again; - } + if (!secure) + { + start_mca(A_PIPE, "|mark: ", (void*)NULL, 0); + c = getcc(); + if (is_erase_char(c)) + break; + if (is_newline_char(c)) + c = '.'; + if (badmark(c)) + break; + pipec = c; + start_mca(A_PIPE, "!", ml_shell, 0); + c = getcc(); + goto again; + } #endif - error("Command not available", NULL_PARG); - break; - - case A_B_BRACKET: - case A_F_BRACKET: - start_mca(action, "Brackets: ", (void*)NULL, 0); - c = getcc(); - goto again; - - case A_LSHIFT: - /* - * Shift view left. - */ - if (number > 0) - shift_count = number; - else - number = (shift_count > 0) ? - shift_count : sc_width / 2; - if (number > hshift) - number = hshift; - hshift -= number; - screen_trashed = 1; - break; - - case A_RSHIFT: - /* - * Shift view right. - */ - if (number > 0) - shift_count = number; - else - number = (shift_count > 0) ? - shift_count : sc_width / 2; - hshift += number; - screen_trashed = 1; - break; - - case A_LLSHIFT: - /* - * Shift view left to margin. - */ - hshift = 0; - screen_trashed = 1; - break; - - case A_RRSHIFT: - /* - * Shift view right to view rightmost char on screen. - */ - hshift = rrshift(); - screen_trashed = 1; - break; - - case A_PREFIX: - /* - * The command is incomplete (more chars are needed). - * Display the current char, so the user knows - * what's going on, and get another character. - */ - if (mca != A_PREFIX) - { - cmd_reset(); - start_mca(A_PREFIX, " ", (void*)NULL, - CF_QUIT_ON_ERASE); - (void) cmd_char(c); - } - c = getcc(); - goto again; - - case A_NOACTION: - break; - - default: - bell(); - break; - } - } + error("Command not available", NULL_PARG); + break; + + case A_B_BRACKET: + case A_F_BRACKET: + start_mca(action, "Brackets: ", (void*)NULL, 0); + c = getcc(); + goto again; + + case A_LSHIFT: + /* + * Shift view left. + */ + if (number > 0) + shift_count = number; + else + number = (shift_count > 0) ? + shift_count : sc_width / 2; + if (number > hshift) + number = hshift; + hshift -= number; + screen_trashed = 1; + break; + + case A_RSHIFT: + /* + * Shift view right. + */ + if (number > 0) + shift_count = number; + else + number = (shift_count > 0) ? + shift_count : sc_width / 2; + hshift += number; + screen_trashed = 1; + break; + + case A_LLSHIFT: + /* + * Shift view left to margin. + */ + hshift = 0; + screen_trashed = 1; + break; + + case A_RRSHIFT: + /* + * Shift view right to view rightmost char on screen. + */ + hshift = rrshift(); + screen_trashed = 1; + break; + + case A_PREFIX: + /* + * The command is incomplete (more chars are needed). + * Display the current char, so the user knows + * what's going on, and get another character. + */ + if (mca != A_PREFIX) + { + cmd_reset(); + start_mca(A_PREFIX, " ", (void*)NULL, + CF_QUIT_ON_ERASE); + (void) cmd_char(c); + } + c = getcc(); + goto again; + + case A_NOACTION: + break; + + default: + bell(); + break; + } + } } diff --git a/compose.uni b/compose.uni index bbf4b20..1235232 100644 --- a/compose.uni +++ b/compose.uni @@ -1,337 +1,337 @@ /* Generated by "./mkutable -f2 Mn Me -- unicode/UnicodeData.txt" on Tue May 19 14:47:34 PDT 2020 */ - { 0x0300, 0x036f }, /* Mn */ - { 0x0483, 0x0487 }, /* Mn */ - { 0x0488, 0x0489 }, /* Me */ - { 0x0591, 0x05bd }, /* Mn */ - { 0x05bf, 0x05bf }, /* Mn */ - { 0x05c1, 0x05c2 }, /* Mn */ - { 0x05c4, 0x05c5 }, /* Mn */ - { 0x05c7, 0x05c7 }, /* Mn */ - { 0x0610, 0x061a }, /* Mn */ - { 0x064b, 0x065f }, /* Mn */ - { 0x0670, 0x0670 }, /* Mn */ - { 0x06d6, 0x06dc }, /* Mn */ - { 0x06df, 0x06e4 }, /* Mn */ - { 0x06e7, 0x06e8 }, /* Mn */ - { 0x06ea, 0x06ed }, /* Mn */ - { 0x0711, 0x0711 }, /* Mn */ - { 0x0730, 0x074a }, /* Mn */ - { 0x07a6, 0x07b0 }, /* Mn */ - { 0x07eb, 0x07f3 }, /* Mn */ - { 0x07fd, 0x07fd }, /* Mn */ - { 0x0816, 0x0819 }, /* Mn */ - { 0x081b, 0x0823 }, /* Mn */ - { 0x0825, 0x0827 }, /* Mn */ - { 0x0829, 0x082d }, /* Mn */ - { 0x0859, 0x085b }, /* Mn */ - { 0x08d3, 0x08e1 }, /* Mn */ - { 0x08e3, 0x0902 }, /* Mn */ - { 0x093a, 0x093a }, /* Mn */ - { 0x093c, 0x093c }, /* Mn */ - { 0x0941, 0x0948 }, /* Mn */ - { 0x094d, 0x094d }, /* Mn */ - { 0x0951, 0x0957 }, /* Mn */ - { 0x0962, 0x0963 }, /* Mn */ - { 0x0981, 0x0981 }, /* Mn */ - { 0x09bc, 0x09bc }, /* Mn */ - { 0x09c1, 0x09c4 }, /* Mn */ - { 0x09cd, 0x09cd }, /* Mn */ - { 0x09e2, 0x09e3 }, /* Mn */ - { 0x09fe, 0x09fe }, /* Mn */ - { 0x0a01, 0x0a02 }, /* Mn */ - { 0x0a3c, 0x0a3c }, /* Mn */ - { 0x0a41, 0x0a42 }, /* Mn */ - { 0x0a47, 0x0a48 }, /* Mn */ - { 0x0a4b, 0x0a4d }, /* Mn */ - { 0x0a51, 0x0a51 }, /* Mn */ - { 0x0a70, 0x0a71 }, /* Mn */ - { 0x0a75, 0x0a75 }, /* Mn */ - { 0x0a81, 0x0a82 }, /* Mn */ - { 0x0abc, 0x0abc }, /* Mn */ - { 0x0ac1, 0x0ac5 }, /* Mn */ - { 0x0ac7, 0x0ac8 }, /* Mn */ - { 0x0acd, 0x0acd }, /* Mn */ - { 0x0ae2, 0x0ae3 }, /* Mn */ - { 0x0afa, 0x0aff }, /* Mn */ - { 0x0b01, 0x0b01 }, /* Mn */ - { 0x0b3c, 0x0b3c }, /* Mn */ - { 0x0b3f, 0x0b3f }, /* Mn */ - { 0x0b41, 0x0b44 }, /* Mn */ - { 0x0b4d, 0x0b4d }, /* Mn */ - { 0x0b55, 0x0b56 }, /* Mn */ - { 0x0b62, 0x0b63 }, /* Mn */ - { 0x0b82, 0x0b82 }, /* Mn */ - { 0x0bc0, 0x0bc0 }, /* Mn */ - { 0x0bcd, 0x0bcd }, /* Mn */ - { 0x0c00, 0x0c00 }, /* Mn */ - { 0x0c04, 0x0c04 }, /* Mn */ - { 0x0c3e, 0x0c40 }, /* Mn */ - { 0x0c46, 0x0c48 }, /* Mn */ - { 0x0c4a, 0x0c4d }, /* Mn */ - { 0x0c55, 0x0c56 }, /* Mn */ - { 0x0c62, 0x0c63 }, /* Mn */ - { 0x0c81, 0x0c81 }, /* Mn */ - { 0x0cbc, 0x0cbc }, /* Mn */ - { 0x0cbf, 0x0cbf }, /* Mn */ - { 0x0cc6, 0x0cc6 }, /* Mn */ - { 0x0ccc, 0x0ccd }, /* Mn */ - { 0x0ce2, 0x0ce3 }, /* Mn */ - { 0x0d00, 0x0d01 }, /* Mn */ - { 0x0d3b, 0x0d3c }, /* Mn */ - { 0x0d41, 0x0d44 }, /* Mn */ - { 0x0d4d, 0x0d4d }, /* Mn */ - { 0x0d62, 0x0d63 }, /* Mn */ - { 0x0d81, 0x0d81 }, /* Mn */ - { 0x0dca, 0x0dca }, /* Mn */ - { 0x0dd2, 0x0dd4 }, /* Mn */ - { 0x0dd6, 0x0dd6 }, /* Mn */ - { 0x0e31, 0x0e31 }, /* Mn */ - { 0x0e34, 0x0e3a }, /* Mn */ - { 0x0e47, 0x0e4e }, /* Mn */ - { 0x0eb1, 0x0eb1 }, /* Mn */ - { 0x0eb4, 0x0ebc }, /* Mn */ - { 0x0ec8, 0x0ecd }, /* Mn */ - { 0x0f18, 0x0f19 }, /* Mn */ - { 0x0f35, 0x0f35 }, /* Mn */ - { 0x0f37, 0x0f37 }, /* Mn */ - { 0x0f39, 0x0f39 }, /* Mn */ - { 0x0f71, 0x0f7e }, /* Mn */ - { 0x0f80, 0x0f84 }, /* Mn */ - { 0x0f86, 0x0f87 }, /* Mn */ - { 0x0f8d, 0x0f97 }, /* Mn */ - { 0x0f99, 0x0fbc }, /* Mn */ - { 0x0fc6, 0x0fc6 }, /* Mn */ - { 0x102d, 0x1030 }, /* Mn */ - { 0x1032, 0x1037 }, /* Mn */ - { 0x1039, 0x103a }, /* Mn */ - { 0x103d, 0x103e }, /* Mn */ - { 0x1058, 0x1059 }, /* Mn */ - { 0x105e, 0x1060 }, /* Mn */ - { 0x1071, 0x1074 }, /* Mn */ - { 0x1082, 0x1082 }, /* Mn */ - { 0x1085, 0x1086 }, /* Mn */ - { 0x108d, 0x108d }, /* Mn */ - { 0x109d, 0x109d }, /* Mn */ - { 0x1160, 0x11ff }, /* Mn */ - { 0x135d, 0x135f }, /* Mn */ - { 0x1712, 0x1714 }, /* Mn */ - { 0x1732, 0x1734 }, /* Mn */ - { 0x1752, 0x1753 }, /* Mn */ - { 0x1772, 0x1773 }, /* Mn */ - { 0x17b4, 0x17b5 }, /* Mn */ - { 0x17b7, 0x17bd }, /* Mn */ - { 0x17c6, 0x17c6 }, /* Mn */ - { 0x17c9, 0x17d3 }, /* Mn */ - { 0x17dd, 0x17dd }, /* Mn */ - { 0x180b, 0x180d }, /* Mn */ - { 0x1885, 0x1886 }, /* Mn */ - { 0x18a9, 0x18a9 }, /* Mn */ - { 0x1920, 0x1922 }, /* Mn */ - { 0x1927, 0x1928 }, /* Mn */ - { 0x1932, 0x1932 }, /* Mn */ - { 0x1939, 0x193b }, /* Mn */ - { 0x1a17, 0x1a18 }, /* Mn */ - { 0x1a1b, 0x1a1b }, /* Mn */ - { 0x1a56, 0x1a56 }, /* Mn */ - { 0x1a58, 0x1a5e }, /* Mn */ - { 0x1a60, 0x1a60 }, /* Mn */ - { 0x1a62, 0x1a62 }, /* Mn */ - { 0x1a65, 0x1a6c }, /* Mn */ - { 0x1a73, 0x1a7c }, /* Mn */ - { 0x1a7f, 0x1a7f }, /* Mn */ - { 0x1ab0, 0x1abd }, /* Mn */ - { 0x1abe, 0x1abe }, /* Me */ - { 0x1abf, 0x1ac0 }, /* Mn */ - { 0x1b00, 0x1b03 }, /* Mn */ - { 0x1b34, 0x1b34 }, /* Mn */ - { 0x1b36, 0x1b3a }, /* Mn */ - { 0x1b3c, 0x1b3c }, /* Mn */ - { 0x1b42, 0x1b42 }, /* Mn */ - { 0x1b6b, 0x1b73 }, /* Mn */ - { 0x1b80, 0x1b81 }, /* Mn */ - { 0x1ba2, 0x1ba5 }, /* Mn */ - { 0x1ba8, 0x1ba9 }, /* Mn */ - { 0x1bab, 0x1bad }, /* Mn */ - { 0x1be6, 0x1be6 }, /* Mn */ - { 0x1be8, 0x1be9 }, /* Mn */ - { 0x1bed, 0x1bed }, /* Mn */ - { 0x1bef, 0x1bf1 }, /* Mn */ - { 0x1c2c, 0x1c33 }, /* Mn */ - { 0x1c36, 0x1c37 }, /* Mn */ - { 0x1cd0, 0x1cd2 }, /* Mn */ - { 0x1cd4, 0x1ce0 }, /* Mn */ - { 0x1ce2, 0x1ce8 }, /* Mn */ - { 0x1ced, 0x1ced }, /* Mn */ - { 0x1cf4, 0x1cf4 }, /* Mn */ - { 0x1cf8, 0x1cf9 }, /* Mn */ - { 0x1dc0, 0x1df9 }, /* Mn */ - { 0x1dfb, 0x1dff }, /* Mn */ - { 0x20d0, 0x20dc }, /* Mn */ - { 0x20dd, 0x20e0 }, /* Me */ - { 0x20e1, 0x20e1 }, /* Mn */ - { 0x20e2, 0x20e4 }, /* Me */ - { 0x20e5, 0x20f0 }, /* Mn */ - { 0x2cef, 0x2cf1 }, /* Mn */ - { 0x2d7f, 0x2d7f }, /* Mn */ - { 0x2de0, 0x2dff }, /* Mn */ - { 0x302a, 0x302d }, /* Mn */ - { 0x3099, 0x309a }, /* Mn */ - { 0xa66f, 0xa66f }, /* Mn */ - { 0xa670, 0xa672 }, /* Me */ - { 0xa674, 0xa67d }, /* Mn */ - { 0xa69e, 0xa69f }, /* Mn */ - { 0xa6f0, 0xa6f1 }, /* Mn */ - { 0xa802, 0xa802 }, /* Mn */ - { 0xa806, 0xa806 }, /* Mn */ - { 0xa80b, 0xa80b }, /* Mn */ - { 0xa825, 0xa826 }, /* Mn */ - { 0xa82c, 0xa82c }, /* Mn */ - { 0xa8c4, 0xa8c5 }, /* Mn */ - { 0xa8e0, 0xa8f1 }, /* Mn */ - { 0xa8ff, 0xa8ff }, /* Mn */ - { 0xa926, 0xa92d }, /* Mn */ - { 0xa947, 0xa951 }, /* Mn */ - { 0xa980, 0xa982 }, /* Mn */ - { 0xa9b3, 0xa9b3 }, /* Mn */ - { 0xa9b6, 0xa9b9 }, /* Mn */ - { 0xa9bc, 0xa9bd }, /* Mn */ - { 0xa9e5, 0xa9e5 }, /* Mn */ - { 0xaa29, 0xaa2e }, /* Mn */ - { 0xaa31, 0xaa32 }, /* Mn */ - { 0xaa35, 0xaa36 }, /* Mn */ - { 0xaa43, 0xaa43 }, /* Mn */ - { 0xaa4c, 0xaa4c }, /* Mn */ - { 0xaa7c, 0xaa7c }, /* Mn */ - { 0xaab0, 0xaab0 }, /* Mn */ - { 0xaab2, 0xaab4 }, /* Mn */ - { 0xaab7, 0xaab8 }, /* Mn */ - { 0xaabe, 0xaabf }, /* Mn */ - { 0xaac1, 0xaac1 }, /* Mn */ - { 0xaaec, 0xaaed }, /* Mn */ - { 0xaaf6, 0xaaf6 }, /* Mn */ - { 0xabe5, 0xabe5 }, /* Mn */ - { 0xabe8, 0xabe8 }, /* Mn */ - { 0xabed, 0xabed }, /* Mn */ - { 0xd7b0, 0xd7c6 }, /* Mn */ - { 0xd7cb, 0xd7fb }, /* Mn */ - { 0xfb1e, 0xfb1e }, /* Mn */ - { 0xfe00, 0xfe0f }, /* Mn */ - { 0xfe20, 0xfe2f }, /* Mn */ - { 0x101fd, 0x101fd }, /* Mn */ - { 0x102e0, 0x102e0 }, /* Mn */ - { 0x10376, 0x1037a }, /* Mn */ - { 0x10a01, 0x10a03 }, /* Mn */ - { 0x10a05, 0x10a06 }, /* Mn */ - { 0x10a0c, 0x10a0f }, /* Mn */ - { 0x10a38, 0x10a3a }, /* Mn */ - { 0x10a3f, 0x10a3f }, /* Mn */ - { 0x10ae5, 0x10ae6 }, /* Mn */ - { 0x10d24, 0x10d27 }, /* Mn */ - { 0x10eab, 0x10eac }, /* Mn */ - { 0x10f46, 0x10f50 }, /* Mn */ - { 0x11001, 0x11001 }, /* Mn */ - { 0x11038, 0x11046 }, /* Mn */ - { 0x1107f, 0x11081 }, /* Mn */ - { 0x110b3, 0x110b6 }, /* Mn */ - { 0x110b9, 0x110ba }, /* Mn */ - { 0x11100, 0x11102 }, /* Mn */ - { 0x11127, 0x1112b }, /* Mn */ - { 0x1112d, 0x11134 }, /* Mn */ - { 0x11173, 0x11173 }, /* Mn */ - { 0x11180, 0x11181 }, /* Mn */ - { 0x111b6, 0x111be }, /* Mn */ - { 0x111c9, 0x111cc }, /* Mn */ - { 0x111cf, 0x111cf }, /* Mn */ - { 0x1122f, 0x11231 }, /* Mn */ - { 0x11234, 0x11234 }, /* Mn */ - { 0x11236, 0x11237 }, /* Mn */ - { 0x1123e, 0x1123e }, /* Mn */ - { 0x112df, 0x112df }, /* Mn */ - { 0x112e3, 0x112ea }, /* Mn */ - { 0x11300, 0x11301 }, /* Mn */ - { 0x1133b, 0x1133c }, /* Mn */ - { 0x11340, 0x11340 }, /* Mn */ - { 0x11366, 0x1136c }, /* Mn */ - { 0x11370, 0x11374 }, /* Mn */ - { 0x11438, 0x1143f }, /* Mn */ - { 0x11442, 0x11444 }, /* Mn */ - { 0x11446, 0x11446 }, /* Mn */ - { 0x1145e, 0x1145e }, /* Mn */ - { 0x114b3, 0x114b8 }, /* Mn */ - { 0x114ba, 0x114ba }, /* Mn */ - { 0x114bf, 0x114c0 }, /* Mn */ - { 0x114c2, 0x114c3 }, /* Mn */ - { 0x115b2, 0x115b5 }, /* Mn */ - { 0x115bc, 0x115bd }, /* Mn */ - { 0x115bf, 0x115c0 }, /* Mn */ - { 0x115dc, 0x115dd }, /* Mn */ - { 0x11633, 0x1163a }, /* Mn */ - { 0x1163d, 0x1163d }, /* Mn */ - { 0x1163f, 0x11640 }, /* Mn */ - { 0x116ab, 0x116ab }, /* Mn */ - { 0x116ad, 0x116ad }, /* Mn */ - { 0x116b0, 0x116b5 }, /* Mn */ - { 0x116b7, 0x116b7 }, /* Mn */ - { 0x1171d, 0x1171f }, /* Mn */ - { 0x11722, 0x11725 }, /* Mn */ - { 0x11727, 0x1172b }, /* Mn */ - { 0x1182f, 0x11837 }, /* Mn */ - { 0x11839, 0x1183a }, /* Mn */ - { 0x1193b, 0x1193c }, /* Mn */ - { 0x1193e, 0x1193e }, /* Mn */ - { 0x11943, 0x11943 }, /* Mn */ - { 0x119d4, 0x119d7 }, /* Mn */ - { 0x119da, 0x119db }, /* Mn */ - { 0x119e0, 0x119e0 }, /* Mn */ - { 0x11a01, 0x11a0a }, /* Mn */ - { 0x11a33, 0x11a38 }, /* Mn */ - { 0x11a3b, 0x11a3e }, /* Mn */ - { 0x11a47, 0x11a47 }, /* Mn */ - { 0x11a51, 0x11a56 }, /* Mn */ - { 0x11a59, 0x11a5b }, /* Mn */ - { 0x11a8a, 0x11a96 }, /* Mn */ - { 0x11a98, 0x11a99 }, /* Mn */ - { 0x11c30, 0x11c36 }, /* Mn */ - { 0x11c38, 0x11c3d }, /* Mn */ - { 0x11c3f, 0x11c3f }, /* Mn */ - { 0x11c92, 0x11ca7 }, /* Mn */ - { 0x11caa, 0x11cb0 }, /* Mn */ - { 0x11cb2, 0x11cb3 }, /* Mn */ - { 0x11cb5, 0x11cb6 }, /* Mn */ - { 0x11d31, 0x11d36 }, /* Mn */ - { 0x11d3a, 0x11d3a }, /* Mn */ - { 0x11d3c, 0x11d3d }, /* Mn */ - { 0x11d3f, 0x11d45 }, /* Mn */ - { 0x11d47, 0x11d47 }, /* Mn */ - { 0x11d90, 0x11d91 }, /* Mn */ - { 0x11d95, 0x11d95 }, /* Mn */ - { 0x11d97, 0x11d97 }, /* Mn */ - { 0x11ef3, 0x11ef4 }, /* Mn */ - { 0x16af0, 0x16af4 }, /* Mn */ - { 0x16b30, 0x16b36 }, /* Mn */ - { 0x16f4f, 0x16f4f }, /* Mn */ - { 0x16f8f, 0x16f92 }, /* Mn */ - { 0x16fe4, 0x16fe4 }, /* Mn */ - { 0x1bc9d, 0x1bc9e }, /* Mn */ - { 0x1d167, 0x1d169 }, /* Mn */ - { 0x1d17b, 0x1d182 }, /* Mn */ - { 0x1d185, 0x1d18b }, /* Mn */ - { 0x1d1aa, 0x1d1ad }, /* Mn */ - { 0x1d242, 0x1d244 }, /* Mn */ - { 0x1da00, 0x1da36 }, /* Mn */ - { 0x1da3b, 0x1da6c }, /* Mn */ - { 0x1da75, 0x1da75 }, /* Mn */ - { 0x1da84, 0x1da84 }, /* Mn */ - { 0x1da9b, 0x1da9f }, /* Mn */ - { 0x1daa1, 0x1daaf }, /* Mn */ - { 0x1e000, 0x1e006 }, /* Mn */ - { 0x1e008, 0x1e018 }, /* Mn */ - { 0x1e01b, 0x1e021 }, /* Mn */ - { 0x1e023, 0x1e024 }, /* Mn */ - { 0x1e026, 0x1e02a }, /* Mn */ - { 0x1e130, 0x1e136 }, /* Mn */ - { 0x1e2ae, 0x1e2ae }, /* Mn */ - { 0x1e2ec, 0x1e2ef }, /* Mn */ - { 0x1e8d0, 0x1e8d6 }, /* Mn */ - { 0x1e944, 0x1e94a }, /* Mn */ - { 0xe0100, 0xe01ef }, /* Mn */ + { 0x0300, 0x036f }, /* Mn */ + { 0x0483, 0x0487 }, /* Mn */ + { 0x0488, 0x0489 }, /* Me */ + { 0x0591, 0x05bd }, /* Mn */ + { 0x05bf, 0x05bf }, /* Mn */ + { 0x05c1, 0x05c2 }, /* Mn */ + { 0x05c4, 0x05c5 }, /* Mn */ + { 0x05c7, 0x05c7 }, /* Mn */ + { 0x0610, 0x061a }, /* Mn */ + { 0x064b, 0x065f }, /* Mn */ + { 0x0670, 0x0670 }, /* Mn */ + { 0x06d6, 0x06dc }, /* Mn */ + { 0x06df, 0x06e4 }, /* Mn */ + { 0x06e7, 0x06e8 }, /* Mn */ + { 0x06ea, 0x06ed }, /* Mn */ + { 0x0711, 0x0711 }, /* Mn */ + { 0x0730, 0x074a }, /* Mn */ + { 0x07a6, 0x07b0 }, /* Mn */ + { 0x07eb, 0x07f3 }, /* Mn */ + { 0x07fd, 0x07fd }, /* Mn */ + { 0x0816, 0x0819 }, /* Mn */ + { 0x081b, 0x0823 }, /* Mn */ + { 0x0825, 0x0827 }, /* Mn */ + { 0x0829, 0x082d }, /* Mn */ + { 0x0859, 0x085b }, /* Mn */ + { 0x08d3, 0x08e1 }, /* Mn */ + { 0x08e3, 0x0902 }, /* Mn */ + { 0x093a, 0x093a }, /* Mn */ + { 0x093c, 0x093c }, /* Mn */ + { 0x0941, 0x0948 }, /* Mn */ + { 0x094d, 0x094d }, /* Mn */ + { 0x0951, 0x0957 }, /* Mn */ + { 0x0962, 0x0963 }, /* Mn */ + { 0x0981, 0x0981 }, /* Mn */ + { 0x09bc, 0x09bc }, /* Mn */ + { 0x09c1, 0x09c4 }, /* Mn */ + { 0x09cd, 0x09cd }, /* Mn */ + { 0x09e2, 0x09e3 }, /* Mn */ + { 0x09fe, 0x09fe }, /* Mn */ + { 0x0a01, 0x0a02 }, /* Mn */ + { 0x0a3c, 0x0a3c }, /* Mn */ + { 0x0a41, 0x0a42 }, /* Mn */ + { 0x0a47, 0x0a48 }, /* Mn */ + { 0x0a4b, 0x0a4d }, /* Mn */ + { 0x0a51, 0x0a51 }, /* Mn */ + { 0x0a70, 0x0a71 }, /* Mn */ + { 0x0a75, 0x0a75 }, /* Mn */ + { 0x0a81, 0x0a82 }, /* Mn */ + { 0x0abc, 0x0abc }, /* Mn */ + { 0x0ac1, 0x0ac5 }, /* Mn */ + { 0x0ac7, 0x0ac8 }, /* Mn */ + { 0x0acd, 0x0acd }, /* Mn */ + { 0x0ae2, 0x0ae3 }, /* Mn */ + { 0x0afa, 0x0aff }, /* Mn */ + { 0x0b01, 0x0b01 }, /* Mn */ + { 0x0b3c, 0x0b3c }, /* Mn */ + { 0x0b3f, 0x0b3f }, /* Mn */ + { 0x0b41, 0x0b44 }, /* Mn */ + { 0x0b4d, 0x0b4d }, /* Mn */ + { 0x0b55, 0x0b56 }, /* Mn */ + { 0x0b62, 0x0b63 }, /* Mn */ + { 0x0b82, 0x0b82 }, /* Mn */ + { 0x0bc0, 0x0bc0 }, /* Mn */ + { 0x0bcd, 0x0bcd }, /* Mn */ + { 0x0c00, 0x0c00 }, /* Mn */ + { 0x0c04, 0x0c04 }, /* Mn */ + { 0x0c3e, 0x0c40 }, /* Mn */ + { 0x0c46, 0x0c48 }, /* Mn */ + { 0x0c4a, 0x0c4d }, /* Mn */ + { 0x0c55, 0x0c56 }, /* Mn */ + { 0x0c62, 0x0c63 }, /* Mn */ + { 0x0c81, 0x0c81 }, /* Mn */ + { 0x0cbc, 0x0cbc }, /* Mn */ + { 0x0cbf, 0x0cbf }, /* Mn */ + { 0x0cc6, 0x0cc6 }, /* Mn */ + { 0x0ccc, 0x0ccd }, /* Mn */ + { 0x0ce2, 0x0ce3 }, /* Mn */ + { 0x0d00, 0x0d01 }, /* Mn */ + { 0x0d3b, 0x0d3c }, /* Mn */ + { 0x0d41, 0x0d44 }, /* Mn */ + { 0x0d4d, 0x0d4d }, /* Mn */ + { 0x0d62, 0x0d63 }, /* Mn */ + { 0x0d81, 0x0d81 }, /* Mn */ + { 0x0dca, 0x0dca }, /* Mn */ + { 0x0dd2, 0x0dd4 }, /* Mn */ + { 0x0dd6, 0x0dd6 }, /* Mn */ + { 0x0e31, 0x0e31 }, /* Mn */ + { 0x0e34, 0x0e3a }, /* Mn */ + { 0x0e47, 0x0e4e }, /* Mn */ + { 0x0eb1, 0x0eb1 }, /* Mn */ + { 0x0eb4, 0x0ebc }, /* Mn */ + { 0x0ec8, 0x0ecd }, /* Mn */ + { 0x0f18, 0x0f19 }, /* Mn */ + { 0x0f35, 0x0f35 }, /* Mn */ + { 0x0f37, 0x0f37 }, /* Mn */ + { 0x0f39, 0x0f39 }, /* Mn */ + { 0x0f71, 0x0f7e }, /* Mn */ + { 0x0f80, 0x0f84 }, /* Mn */ + { 0x0f86, 0x0f87 }, /* Mn */ + { 0x0f8d, 0x0f97 }, /* Mn */ + { 0x0f99, 0x0fbc }, /* Mn */ + { 0x0fc6, 0x0fc6 }, /* Mn */ + { 0x102d, 0x1030 }, /* Mn */ + { 0x1032, 0x1037 }, /* Mn */ + { 0x1039, 0x103a }, /* Mn */ + { 0x103d, 0x103e }, /* Mn */ + { 0x1058, 0x1059 }, /* Mn */ + { 0x105e, 0x1060 }, /* Mn */ + { 0x1071, 0x1074 }, /* Mn */ + { 0x1082, 0x1082 }, /* Mn */ + { 0x1085, 0x1086 }, /* Mn */ + { 0x108d, 0x108d }, /* Mn */ + { 0x109d, 0x109d }, /* Mn */ + { 0x1160, 0x11ff }, /* Mn */ + { 0x135d, 0x135f }, /* Mn */ + { 0x1712, 0x1714 }, /* Mn */ + { 0x1732, 0x1734 }, /* Mn */ + { 0x1752, 0x1753 }, /* Mn */ + { 0x1772, 0x1773 }, /* Mn */ + { 0x17b4, 0x17b5 }, /* Mn */ + { 0x17b7, 0x17bd }, /* Mn */ + { 0x17c6, 0x17c6 }, /* Mn */ + { 0x17c9, 0x17d3 }, /* Mn */ + { 0x17dd, 0x17dd }, /* Mn */ + { 0x180b, 0x180d }, /* Mn */ + { 0x1885, 0x1886 }, /* Mn */ + { 0x18a9, 0x18a9 }, /* Mn */ + { 0x1920, 0x1922 }, /* Mn */ + { 0x1927, 0x1928 }, /* Mn */ + { 0x1932, 0x1932 }, /* Mn */ + { 0x1939, 0x193b }, /* Mn */ + { 0x1a17, 0x1a18 }, /* Mn */ + { 0x1a1b, 0x1a1b }, /* Mn */ + { 0x1a56, 0x1a56 }, /* Mn */ + { 0x1a58, 0x1a5e }, /* Mn */ + { 0x1a60, 0x1a60 }, /* Mn */ + { 0x1a62, 0x1a62 }, /* Mn */ + { 0x1a65, 0x1a6c }, /* Mn */ + { 0x1a73, 0x1a7c }, /* Mn */ + { 0x1a7f, 0x1a7f }, /* Mn */ + { 0x1ab0, 0x1abd }, /* Mn */ + { 0x1abe, 0x1abe }, /* Me */ + { 0x1abf, 0x1ac0 }, /* Mn */ + { 0x1b00, 0x1b03 }, /* Mn */ + { 0x1b34, 0x1b34 }, /* Mn */ + { 0x1b36, 0x1b3a }, /* Mn */ + { 0x1b3c, 0x1b3c }, /* Mn */ + { 0x1b42, 0x1b42 }, /* Mn */ + { 0x1b6b, 0x1b73 }, /* Mn */ + { 0x1b80, 0x1b81 }, /* Mn */ + { 0x1ba2, 0x1ba5 }, /* Mn */ + { 0x1ba8, 0x1ba9 }, /* Mn */ + { 0x1bab, 0x1bad }, /* Mn */ + { 0x1be6, 0x1be6 }, /* Mn */ + { 0x1be8, 0x1be9 }, /* Mn */ + { 0x1bed, 0x1bed }, /* Mn */ + { 0x1bef, 0x1bf1 }, /* Mn */ + { 0x1c2c, 0x1c33 }, /* Mn */ + { 0x1c36, 0x1c37 }, /* Mn */ + { 0x1cd0, 0x1cd2 }, /* Mn */ + { 0x1cd4, 0x1ce0 }, /* Mn */ + { 0x1ce2, 0x1ce8 }, /* Mn */ + { 0x1ced, 0x1ced }, /* Mn */ + { 0x1cf4, 0x1cf4 }, /* Mn */ + { 0x1cf8, 0x1cf9 }, /* Mn */ + { 0x1dc0, 0x1df9 }, /* Mn */ + { 0x1dfb, 0x1dff }, /* Mn */ + { 0x20d0, 0x20dc }, /* Mn */ + { 0x20dd, 0x20e0 }, /* Me */ + { 0x20e1, 0x20e1 }, /* Mn */ + { 0x20e2, 0x20e4 }, /* Me */ + { 0x20e5, 0x20f0 }, /* Mn */ + { 0x2cef, 0x2cf1 }, /* Mn */ + { 0x2d7f, 0x2d7f }, /* Mn */ + { 0x2de0, 0x2dff }, /* Mn */ + { 0x302a, 0x302d }, /* Mn */ + { 0x3099, 0x309a }, /* Mn */ + { 0xa66f, 0xa66f }, /* Mn */ + { 0xa670, 0xa672 }, /* Me */ + { 0xa674, 0xa67d }, /* Mn */ + { 0xa69e, 0xa69f }, /* Mn */ + { 0xa6f0, 0xa6f1 }, /* Mn */ + { 0xa802, 0xa802 }, /* Mn */ + { 0xa806, 0xa806 }, /* Mn */ + { 0xa80b, 0xa80b }, /* Mn */ + { 0xa825, 0xa826 }, /* Mn */ + { 0xa82c, 0xa82c }, /* Mn */ + { 0xa8c4, 0xa8c5 }, /* Mn */ + { 0xa8e0, 0xa8f1 }, /* Mn */ + { 0xa8ff, 0xa8ff }, /* Mn */ + { 0xa926, 0xa92d }, /* Mn */ + { 0xa947, 0xa951 }, /* Mn */ + { 0xa980, 0xa982 }, /* Mn */ + { 0xa9b3, 0xa9b3 }, /* Mn */ + { 0xa9b6, 0xa9b9 }, /* Mn */ + { 0xa9bc, 0xa9bd }, /* Mn */ + { 0xa9e5, 0xa9e5 }, /* Mn */ + { 0xaa29, 0xaa2e }, /* Mn */ + { 0xaa31, 0xaa32 }, /* Mn */ + { 0xaa35, 0xaa36 }, /* Mn */ + { 0xaa43, 0xaa43 }, /* Mn */ + { 0xaa4c, 0xaa4c }, /* Mn */ + { 0xaa7c, 0xaa7c }, /* Mn */ + { 0xaab0, 0xaab0 }, /* Mn */ + { 0xaab2, 0xaab4 }, /* Mn */ + { 0xaab7, 0xaab8 }, /* Mn */ + { 0xaabe, 0xaabf }, /* Mn */ + { 0xaac1, 0xaac1 }, /* Mn */ + { 0xaaec, 0xaaed }, /* Mn */ + { 0xaaf6, 0xaaf6 }, /* Mn */ + { 0xabe5, 0xabe5 }, /* Mn */ + { 0xabe8, 0xabe8 }, /* Mn */ + { 0xabed, 0xabed }, /* Mn */ + { 0xd7b0, 0xd7c6 }, /* Mn */ + { 0xd7cb, 0xd7fb }, /* Mn */ + { 0xfb1e, 0xfb1e }, /* Mn */ + { 0xfe00, 0xfe0f }, /* Mn */ + { 0xfe20, 0xfe2f }, /* Mn */ + { 0x101fd, 0x101fd }, /* Mn */ + { 0x102e0, 0x102e0 }, /* Mn */ + { 0x10376, 0x1037a }, /* Mn */ + { 0x10a01, 0x10a03 }, /* Mn */ + { 0x10a05, 0x10a06 }, /* Mn */ + { 0x10a0c, 0x10a0f }, /* Mn */ + { 0x10a38, 0x10a3a }, /* Mn */ + { 0x10a3f, 0x10a3f }, /* Mn */ + { 0x10ae5, 0x10ae6 }, /* Mn */ + { 0x10d24, 0x10d27 }, /* Mn */ + { 0x10eab, 0x10eac }, /* Mn */ + { 0x10f46, 0x10f50 }, /* Mn */ + { 0x11001, 0x11001 }, /* Mn */ + { 0x11038, 0x11046 }, /* Mn */ + { 0x1107f, 0x11081 }, /* Mn */ + { 0x110b3, 0x110b6 }, /* Mn */ + { 0x110b9, 0x110ba }, /* Mn */ + { 0x11100, 0x11102 }, /* Mn */ + { 0x11127, 0x1112b }, /* Mn */ + { 0x1112d, 0x11134 }, /* Mn */ + { 0x11173, 0x11173 }, /* Mn */ + { 0x11180, 0x11181 }, /* Mn */ + { 0x111b6, 0x111be }, /* Mn */ + { 0x111c9, 0x111cc }, /* Mn */ + { 0x111cf, 0x111cf }, /* Mn */ + { 0x1122f, 0x11231 }, /* Mn */ + { 0x11234, 0x11234 }, /* Mn */ + { 0x11236, 0x11237 }, /* Mn */ + { 0x1123e, 0x1123e }, /* Mn */ + { 0x112df, 0x112df }, /* Mn */ + { 0x112e3, 0x112ea }, /* Mn */ + { 0x11300, 0x11301 }, /* Mn */ + { 0x1133b, 0x1133c }, /* Mn */ + { 0x11340, 0x11340 }, /* Mn */ + { 0x11366, 0x1136c }, /* Mn */ + { 0x11370, 0x11374 }, /* Mn */ + { 0x11438, 0x1143f }, /* Mn */ + { 0x11442, 0x11444 }, /* Mn */ + { 0x11446, 0x11446 }, /* Mn */ + { 0x1145e, 0x1145e }, /* Mn */ + { 0x114b3, 0x114b8 }, /* Mn */ + { 0x114ba, 0x114ba }, /* Mn */ + { 0x114bf, 0x114c0 }, /* Mn */ + { 0x114c2, 0x114c3 }, /* Mn */ + { 0x115b2, 0x115b5 }, /* Mn */ + { 0x115bc, 0x115bd }, /* Mn */ + { 0x115bf, 0x115c0 }, /* Mn */ + { 0x115dc, 0x115dd }, /* Mn */ + { 0x11633, 0x1163a }, /* Mn */ + { 0x1163d, 0x1163d }, /* Mn */ + { 0x1163f, 0x11640 }, /* Mn */ + { 0x116ab, 0x116ab }, /* Mn */ + { 0x116ad, 0x116ad }, /* Mn */ + { 0x116b0, 0x116b5 }, /* Mn */ + { 0x116b7, 0x116b7 }, /* Mn */ + { 0x1171d, 0x1171f }, /* Mn */ + { 0x11722, 0x11725 }, /* Mn */ + { 0x11727, 0x1172b }, /* Mn */ + { 0x1182f, 0x11837 }, /* Mn */ + { 0x11839, 0x1183a }, /* Mn */ + { 0x1193b, 0x1193c }, /* Mn */ + { 0x1193e, 0x1193e }, /* Mn */ + { 0x11943, 0x11943 }, /* Mn */ + { 0x119d4, 0x119d7 }, /* Mn */ + { 0x119da, 0x119db }, /* Mn */ + { 0x119e0, 0x119e0 }, /* Mn */ + { 0x11a01, 0x11a0a }, /* Mn */ + { 0x11a33, 0x11a38 }, /* Mn */ + { 0x11a3b, 0x11a3e }, /* Mn */ + { 0x11a47, 0x11a47 }, /* Mn */ + { 0x11a51, 0x11a56 }, /* Mn */ + { 0x11a59, 0x11a5b }, /* Mn */ + { 0x11a8a, 0x11a96 }, /* Mn */ + { 0x11a98, 0x11a99 }, /* Mn */ + { 0x11c30, 0x11c36 }, /* Mn */ + { 0x11c38, 0x11c3d }, /* Mn */ + { 0x11c3f, 0x11c3f }, /* Mn */ + { 0x11c92, 0x11ca7 }, /* Mn */ + { 0x11caa, 0x11cb0 }, /* Mn */ + { 0x11cb2, 0x11cb3 }, /* Mn */ + { 0x11cb5, 0x11cb6 }, /* Mn */ + { 0x11d31, 0x11d36 }, /* Mn */ + { 0x11d3a, 0x11d3a }, /* Mn */ + { 0x11d3c, 0x11d3d }, /* Mn */ + { 0x11d3f, 0x11d45 }, /* Mn */ + { 0x11d47, 0x11d47 }, /* Mn */ + { 0x11d90, 0x11d91 }, /* Mn */ + { 0x11d95, 0x11d95 }, /* Mn */ + { 0x11d97, 0x11d97 }, /* Mn */ + { 0x11ef3, 0x11ef4 }, /* Mn */ + { 0x16af0, 0x16af4 }, /* Mn */ + { 0x16b30, 0x16b36 }, /* Mn */ + { 0x16f4f, 0x16f4f }, /* Mn */ + { 0x16f8f, 0x16f92 }, /* Mn */ + { 0x16fe4, 0x16fe4 }, /* Mn */ + { 0x1bc9d, 0x1bc9e }, /* Mn */ + { 0x1d167, 0x1d169 }, /* Mn */ + { 0x1d17b, 0x1d182 }, /* Mn */ + { 0x1d185, 0x1d18b }, /* Mn */ + { 0x1d1aa, 0x1d1ad }, /* Mn */ + { 0x1d242, 0x1d244 }, /* Mn */ + { 0x1da00, 0x1da36 }, /* Mn */ + { 0x1da3b, 0x1da6c }, /* Mn */ + { 0x1da75, 0x1da75 }, /* Mn */ + { 0x1da84, 0x1da84 }, /* Mn */ + { 0x1da9b, 0x1da9f }, /* Mn */ + { 0x1daa1, 0x1daaf }, /* Mn */ + { 0x1e000, 0x1e006 }, /* Mn */ + { 0x1e008, 0x1e018 }, /* Mn */ + { 0x1e01b, 0x1e021 }, /* Mn */ + { 0x1e023, 0x1e024 }, /* Mn */ + { 0x1e026, 0x1e02a }, /* Mn */ + { 0x1e130, 0x1e136 }, /* Mn */ + { 0x1e2ae, 0x1e2ae }, /* Mn */ + { 0x1e2ec, 0x1e2ef }, /* Mn */ + { 0x1e8d0, 0x1e8d6 }, /* Mn */ + { 0x1e944, 0x1e94a }, /* Mn */ + { 0xe0100, 0xe01ef }, /* Mn */ diff --git a/configure b/configure index e3be2c0..686de05 100644 --- a/configure +++ b/configure @@ -57,8 +57,8 @@ else arg=$1; case $arg in #( *"$as_nl"*) - expr "X$arg" : "X\\(.*\\)$as_nl"; - arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' @@ -84,7 +84,7 @@ fi # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) -IFS=" "" $as_nl" +IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= @@ -213,23 +213,23 @@ do test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( - /*) - for as_base in sh bash ksh sh5; do - # Try only shells that exist, to save several forks. - as_shell=$as_dir/$as_base - if { test -f "$as_shell" || test -f "$as_shell.exe"; } && - { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes - if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi - done;; + done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && - { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS @@ -328,27 +328,27 @@ as_fn_mkdir_p () as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" @@ -437,22 +437,22 @@ fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)' \| . 2>/dev/null || + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ - s//\1/ - q - } - /^X\/\(\/\/\)$/{ - s//\1/ - q - } - /^X\/\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' @@ -501,10 +501,10 @@ ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in - *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null - ECHO_T=' ';; + ECHO_T=' ';; esac;; *) ECHO_N='-n';; @@ -810,7 +810,7 @@ do "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" - ac_unrecognized_sep=', ';; + ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; @@ -836,7 +836,7 @@ do "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" - ac_unrecognized_sep=', ';; + ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; @@ -1049,7 +1049,7 @@ do "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" - ac_unrecognized_sep=', ';; + ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; @@ -1065,7 +1065,7 @@ do "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" - ac_unrecognized_sep=', ';; + ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; @@ -1126,10 +1126,10 @@ if test -n "$ac_unrecognized_opts"; then fi # Check all directory arguments for consistency. -for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ - datadir sysconfdir sharedstatedir localstatedir includedir \ - oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1182,27 +1182,27 @@ if test -z "$srcdir"; then # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_myself" : 'X\(//\)[^/]' \| \ - X"$as_myself" : 'X\(//\)$' \| \ - X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. @@ -1216,8 +1216,8 @@ if test ! -r "$srcdir/$ac_unique_file"; then fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( - cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" - pwd)` + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" + pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. @@ -1435,15 +1435,15 @@ $as_echo "$ac_try_echo"; } >&5 fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err + test -z "$ac_c_werror_flag" || + test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_retval=1 + ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval @@ -1473,18 +1473,18 @@ $as_echo "$ac_try_echo"; } >&5 fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err + test -z "$ac_c_werror_flag" || + test ! -s conftest.err } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - test -x conftest$ac_exeext + test "$cross_compiling" = yes || + test -x conftest$ac_exeext }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_retval=1 + ac_retval=1 fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would @@ -1518,8 +1518,8 @@ $as_echo "$ac_try_echo"; } >&5 fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err }; then : ac_retval=0 else @@ -1590,7 +1590,7 @@ if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? @@ -1655,7 +1655,7 @@ else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno @@ -1687,7 +1687,7 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno @@ -1713,7 +1713,7 @@ int main () { if (sizeof ($2)) - return 0; + return 0; ; return 0; } @@ -1726,7 +1726,7 @@ int main () { if (sizeof (($2))) - return 0; + return 0; ; return 0; } @@ -1741,7 +1741,7 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno @@ -1808,7 +1808,7 @@ rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno @@ -1896,19 +1896,19 @@ do 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then - ac_must_keep_next=false # Got value, back to normal. + ac_must_keep_next=false # Got value, back to normal. else - case $ac_arg in - *=* | --config-cache | -C | -disable-* | --disable-* \ - | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ - | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ - | -with-* | --with-* | -without-* | --without-* | --x) - case "$ac_configure_args0 " in - "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; - esac - ;; - -* ) ac_must_keep_next=true ;; - esac + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; @@ -1953,8 +1953,8 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ - "s/'\''/'\''\\\\'\'''\''/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" @@ -1985,11 +1985,11 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; echo for ac_var in $ac_subst_files do - eval ac_val=\$$ac_var - case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; - esac - $as_echo "$ac_var='\''$ac_val'\''" + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi @@ -2117,21 +2117,21 @@ $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then - # differences in whitespace do not lead to failure. - ac_old_val_w=`echo x $ac_old_val` - ac_new_val_w=`echo x $ac_new_val` - if test "$ac_old_val_w" != "$ac_new_val_w"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} - ac_cache_corrupted=: - else - { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} - eval $ac_var=\$ac_old_val - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac @@ -2552,24 +2552,24 @@ do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) - ;; + ;; [ab].out ) - # We found the default executable, but exeext='' is most - # certainly right. - break;; + # We found the default executable, but exeext='' is most + # certainly right. + break;; *.* ) - if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; - then :; else - ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - fi - # We set ac_cv_exeext here because the later test for it is not - # safe: cross compilers may not add the suffix if given an `-o' - # argument, so we may need to know it at that point already. - # Even if this section looks crufty: it has the advantage of - # actually working. - break;; + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; * ) - break;; + break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= @@ -2621,7 +2621,7 @@ for ac_file in conftest.exe conftest conftest.*; do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - break;; + break;; * ) break;; esac done @@ -2682,9 +2682,9 @@ $as_echo "$ac_try_echo"; } >&5 cross_compiling=no else if test "$cross_compiling" = maybe; then - cross_compiling=yes + cross_compiling=yes else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. @@ -2824,8 +2824,8 @@ if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag - CFLAGS="-g" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int @@ -2923,7 +2923,7 @@ return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ - -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : @@ -3050,7 +3050,7 @@ do #else # include #endif - Syntax error + Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : @@ -3109,7 +3109,7 @@ do #else # include #endif - Syntax error + Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : @@ -3392,30 +3392,30 @@ case $as_dir/ in #(( # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then - if test $ac_prog = install && - grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - rm -rf conftest.one conftest.two conftest.dir - echo one > conftest.one - echo two > conftest.two - mkdir conftest.dir - if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && - test -s conftest.one && test -s conftest.two && - test -s conftest.dir/conftest.one && - test -s conftest.dir/conftest.two - then - ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" - break 3 - fi - fi - fi + if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi done done ;; @@ -3466,9 +3466,9 @@ else if test "$GCC" != yes; then ac_save_CC=$CC while :; do - # IRIX 6.2 and later do not support large files by default, - # so use the C compiler's -n32 option if that helps. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + # IRIX 6.2 and later do not support large files by default, + # so use the C compiler's -n32 option if that helps. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include /* Check that off_t can represent 2**63 - 1 correctly. @@ -3477,8 +3477,8 @@ else incorrectly reject 9223372036854775807. */ #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; int main () { @@ -3487,16 +3487,16 @@ main () return 0; } _ACEOF - if ac_fn_c_try_compile "$LINENO"; then : + if ac_fn_c_try_compile "$LINENO"; then : break fi rm -f core conftest.err conftest.$ac_objext - CC="$CC -n32" - if ac_fn_c_try_compile "$LINENO"; then : + CC="$CC -n32" + if ac_fn_c_try_compile "$LINENO"; then : ac_cv_sys_largefile_CC=' -n32'; break fi rm -f core conftest.err conftest.$ac_objext - break + break done CC=$ac_save_CC rm -f conftest.$ac_ext @@ -3523,8 +3523,8 @@ else incorrectly reject 9223372036854775807. */ #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; int main () { @@ -3547,8 +3547,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext incorrectly reject 9223372036854775807. */ #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; int main () { @@ -3592,8 +3592,8 @@ else incorrectly reject 9223372036854775807. */ #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; int main () { @@ -3616,8 +3616,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext incorrectly reject 9223372036854775807. */ #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; int main () { @@ -4414,9 +4414,9 @@ else # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif @@ -4427,7 +4427,7 @@ main () int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) + || toupper (i) != TOUPPER (i)) return 2; return 0; } @@ -4453,7 +4453,7 @@ fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h + inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default @@ -5673,8 +5673,8 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. @@ -5697,15 +5697,15 @@ if diff "$cache_file" confcache >/dev/null 2>&1; then :; else { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then - cat confcache >"$cache_file" + cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) - mv -f confcache "$cache_file"$$ && - mv -f "$cache_file"$$ "$cache_file" ;; #( + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( *) - mv -f confcache "$cache_file" ;; - esac + mv -f confcache "$cache_file" ;; + esac fi fi else @@ -5810,8 +5810,8 @@ else arg=$1; case $arg in #( *"$as_nl"*) - expr "X$arg" : "X\\(.*\\)$as_nl"; - arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' @@ -5837,7 +5837,7 @@ fi # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) -IFS=" "" $as_nl" +IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= @@ -5986,22 +5986,22 @@ fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)' \| . 2>/dev/null || + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ - s//\1/ - q - } - /^X\/\(\/\/\)$/{ - s//\1/ - q - } - /^X\/\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' @@ -6014,10 +6014,10 @@ ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in - *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null - ECHO_T=' ';; + ECHO_T=' ';; esac;; *) ECHO_N='-n';; @@ -6070,27 +6070,27 @@ as_fn_mkdir_p () as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" @@ -6500,21 +6500,21 @@ _ACEOF # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ + ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ -s/[ ]*$/:/ +s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x -s/\(=[ ]*\).*/\1/ +s/\(=[ ]*\).*/\1/ G s/\n// -s/^[^=]*=[ ]*$// +s/^[^=]*=[ ]*$// }' fi @@ -6556,23 +6556,23 @@ sed -n ' s/.\{148\}/&'"$ac_delim"'/g t rset :rset -s/^[ ]*#[ ]*define[ ][ ]*/ / +s/^[ ]*#[ ]*define[ ][ ]*/ / t def d :def s/\\$// t bsnl s/["\\]/\\&/g -s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3"/p -s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p d :bsnl s/["\\]/\\&/g -s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3\\\\\\n"\\/p t cont -s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p t cont d :cont @@ -6660,14 +6660,14 @@ do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree - # (if the path is not absolute). The absolute path cannot be DOS-style, - # because $ac_f cannot contain `:'. - test -f "$ac_f" || - case $ac_f in - [\\/$]*) false;; - *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; - esac || - as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" @@ -6677,8 +6677,8 @@ do # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` - $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' - `' by configure.' + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 @@ -6701,27 +6701,27 @@ $as_echo "$as_me: creating $ac_file" >&6;} ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. @@ -6829,7 +6829,7 @@ eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && - { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 @@ -6859,7 +6859,7 @@ $as_echo "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$ac_tmp/config.h" "$ac_file" \ - || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else $as_echo "/* $configure_input */" \ @@ -6906,4 +6906,3 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi - diff --git a/configure.ac b/configure.ac index 3407736..bdf9f19 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ # You may distribute under the terms of either the GNU General Public # License or the Less License, as specified in the README file. # -# For more information about less, or for information on how to +# For more information about less, or for information on how to # contact the author, see the README file. # Autoconf initialization. @@ -192,71 +192,71 @@ AC_HEADER_TIME # Autoheader templates for symbols defined later by AC_DEFINE. AH_TEMPLATE([HAVE_GNU_REGEX], - [GNU regex library]) + [GNU regex library]) AH_TEMPLATE([HAVE_POSIX_REGCOMP], - [POSIX regcomp() and regex.h]) + [POSIX regcomp() and regex.h]) AH_TEMPLATE([HAVE_PCRE], - [PCRE (Perl-compatible regular expression) library]) + [PCRE (Perl-compatible regular expression) library]) AH_TEMPLATE([HAVE_PCRE2], - [PCRE2 (Perl-compatible regular expression) library]) + [PCRE2 (Perl-compatible regular expression) library]) AH_TEMPLATE([HAVE_RE_COMP], - [BSD re_comp()]) + [BSD re_comp()]) AH_TEMPLATE([HAVE_REGCMP], - [System V regcmp()]) + [System V regcmp()]) AH_TEMPLATE([HAVE_V8_REGCOMP], - [Henry Spencer V8 regcomp() and regexp.h]) + [Henry Spencer V8 regcomp() and regexp.h]) AH_TEMPLATE([NO_REGEX], - [pattern matching is supported, but without metacharacters.]) + [pattern matching is supported, but without metacharacters.]) AH_TEMPLATE([HAVE_REGEXEC2], - []) + []) AH_TEMPLATE([HAVE_VOID], - [Define HAVE_VOID if your compiler supports the "void" type.]) + [Define HAVE_VOID if your compiler supports the "void" type.]) AH_TEMPLATE([HAVE_FLOAT], - [Define HAVE_FLOAT if your compiler supports the "double" type.]) + [Define HAVE_FLOAT if your compiler supports the "double" type.]) AH_TEMPLATE([HAVE_CONST], - [Define HAVE_CONST if your compiler supports the "const" modifier.]) + [Define HAVE_CONST if your compiler supports the "const" modifier.]) AH_TEMPLATE([HAVE_STAT_INO], - [Define HAVE_STAT_INO if your struct stat has st_ino and st_dev.]) + [Define HAVE_STAT_INO if your struct stat has st_ino and st_dev.]) AH_TEMPLATE([HAVE_TIME_T], - [Define HAVE_TIME_T if your system supports the "time_t" type.]) + [Define HAVE_TIME_T if your system supports the "time_t" type.]) AH_TEMPLATE([HAVE_STRERROR], - [Define HAVE_STRERROR if you have the strerror() function.]) + [Define HAVE_STRERROR if you have the strerror() function.]) AH_TEMPLATE([HAVE_FILENO], - [Define HAVE_FILENO if you have the fileno() macro.]) + [Define HAVE_FILENO if you have the fileno() macro.]) AH_TEMPLATE([HAVE_ERRNO], - [Define HAVE_ERRNO if you have the errno variable.]) + [Define HAVE_ERRNO if you have the errno variable.]) AH_TEMPLATE([MUST_DEFINE_ERRNO], - [Define MUST_DEFINE_ERRNO if you have errno but it is not define in errno.h.]) + [Define MUST_DEFINE_ERRNO if you have errno but it is not define in errno.h.]) AH_TEMPLATE([HAVE_SYS_ERRLIST], - [Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable.]) + [Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable.]) AH_TEMPLATE([HAVE_OSPEED], - [Define HAVE_OSPEED if your termcap library has the ospeed variable.]) + [Define HAVE_OSPEED if your termcap library has the ospeed variable.]) AH_TEMPLATE([MUST_DEFINE_OSPEED], - [Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined in termcap.h.]) + [Define MUST_DEFINE_OSPEED if you have ospeed but it is not defined in termcap.h.]) AH_TEMPLATE([HAVE_LOCALE], - [Define HAVE_LOCALE if you have locale.h and setlocale.]) + [Define HAVE_LOCALE if you have locale.h and setlocale.]) AH_TEMPLATE([HAVE_TERMIOS_FUNCS], - [Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr.]) + [Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr.]) AH_TEMPLATE([HAVE_UPPER_LOWER], - [Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower.]) + [Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower.]) AH_TEMPLATE([HAVE_WCTYPE], - [Define HAVE_WCTYPE if you have iswupper, iswlower, towupper, towlower.]) + [Define HAVE_WCTYPE if you have iswupper, iswlower, towupper, towlower.]) AH_TEMPLATE([HAVE_SIGSET_T], - [Define HAVE_SIGSET_T you have the sigset_t type.]) + [Define HAVE_SIGSET_T you have the sigset_t type.]) AH_TEMPLATE([HAVE_SIGEMPTYSET], - [Define HAVE_SIGEMPTYSET if you have the sigemptyset macro.]) + [Define HAVE_SIGEMPTYSET if you have the sigemptyset macro.]) AH_TEMPLATE([EDIT_PGM], - [Define EDIT_PGM to your editor.]) + [Define EDIT_PGM to your editor.]) AH_TEMPLATE([SECURE_COMPILE], - [Define SECURE_COMPILE=1 to build a secure version of less.]) + [Define SECURE_COMPILE=1 to build a secure version of less.]) # Checks for identifiers. AC_TYPE_OFF_T AC_MSG_CHECKING(for void) -AC_TRY_COMPILE(, [void *foo = 0;], +AC_TRY_COMPILE(, [void *foo = 0;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_VOID)], [AC_MSG_RESULT(no)]) AC_MSG_CHECKING(for const) -AC_TRY_COMPILE(, [const int foo = 0;], +AC_TRY_COMPILE(, [const int foo = 0;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_CONST)], [AC_MSG_RESULT(no)]) AC_MSG_CHECKING(for time_t) AC_TRY_COMPILE([#include ], [time_t t = 0;], @@ -322,7 +322,7 @@ AC_TRY_LINK([ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STRERROR)], [AC_MSG_RESULT(no)]) AC_MSG_CHECKING(for sys_errlist) -AC_TRY_LINK(, [extern char *sys_errlist[]; static char **x; x = sys_errlist;], +AC_TRY_LINK(, [extern char *sys_errlist[]; static char **x; x = sys_errlist;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYS_ERRLIST)], [AC_MSG_RESULT(no)]) AC_CHECK_TYPES([sigset_t],,,[#include ]) @@ -338,13 +338,13 @@ AC_MSG_CHECKING(for errno) AC_TRY_LINK([ #if HAVE_ERRNO_H #include -#endif], [static int x; x = errno;], +#endif], [static int x; x = errno;], [AC_MSG_RESULT(yes - in errno.h); AC_DEFINE(HAVE_ERRNO) have_errno=yes]) if test $have_errno = no; then AC_TRY_LINK([ #if HAVE_ERRNO_H #include -#endif], [extern int errno; static int x; x = errno;], +#endif], [extern int errno; static int x; x = errno;], [AC_MSG_RESULT(yes - must define); AC_DEFINE(HAVE_ERRNO) AC_DEFINE(MUST_DEFINE_ERRNO)], [AC_MSG_RESULT(no)]) fi @@ -379,7 +379,7 @@ AC_TRY_LINK([ #endif], [ospeed = 0;], [AC_MSG_RESULT(yes - in termcap.h); AC_DEFINE(HAVE_OSPEED) have_ospeed=yes]) if test $have_ospeed = no; then -AC_TRY_LINK(, [extern short ospeed; ospeed = 0;], +AC_TRY_LINK(, [extern short ospeed; ospeed = 0;], [AC_MSG_RESULT(yes - must define); AC_DEFINE(HAVE_OSPEED) AC_DEFINE(MUST_DEFINE_OSPEED)], [AC_MSG_RESULT(no)]) fi @@ -395,7 +395,7 @@ AC_ARG_WITH(no-float, [ --with-no-float Do not use floating point], WANT_NO_FLOAT=1, WANT_NO_FLOAT=0) if test $WANT_NO_FLOAT = 0; then - AC_TRY_LINK(, [double f1 = 12.5; double f2 = f1*f1/2.5;], + AC_TRY_LINK(, [double f1 = 12.5; double f2 = f1*f1/2.5;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_FLOAT)], [AC_MSG_RESULT(no)]) else AC_MSG_RESULT(disabled by user) @@ -449,28 +449,28 @@ fi if test $have_regex = no; then if test $WANT_REGEX = auto -o $WANT_REGEX = pcre2; then -AC_CHECK_LIB(pcre2-8, pcre2_compile_8, +AC_CHECK_LIB(pcre2-8, pcre2_compile_8, [AC_DEFINE(HAVE_PCRE2) LIBS="$LIBS -lpcre2-8" have_regex=yes; supported_regex="$supported_regex pcre2"], []) fi fi if test $have_regex = no; then if test $WANT_REGEX = auto -o $WANT_REGEX = pcre; then -AC_CHECK_LIB(pcre, pcre_compile, +AC_CHECK_LIB(pcre, pcre_compile, [AC_DEFINE(HAVE_PCRE) LIBS="$LIBS -lpcre" have_regex=yes; supported_regex="$supported_regex pcre"], []) fi fi if test $have_regex = no; then if test $WANT_REGEX = auto -o $WANT_REGEX = gnu; then -AC_CHECK_LIB(c, re_compile_pattern, +AC_CHECK_LIB(c, re_compile_pattern, [AC_DEFINE(HAVE_GNU_REGEX) have_regex=yes; supported_regex="$supported_regex gnu"], []) fi fi if test $have_regex = no; then if test $WANT_REGEX = auto -o $WANT_REGEX = regcmp; then -AC_CHECK_FUNC(regcmp, +AC_CHECK_FUNC(regcmp, [AC_DEFINE(HAVE_REGCMP) have_regex=yes; supported_regex="$supported_regex regcmp"],[]) fi fi @@ -486,7 +486,7 @@ fi if test $have_regex = no && test -f ${srcdir}/regexp.c; then if test $WANT_REGEX = auto -o $WANT_REGEX = regcomp-local; then -AC_MSG_RESULT(using V8 regcomp -- local source); AC_DEFINE(HAVE_V8_REGCOMP) +AC_MSG_RESULT(using V8 regcomp -- local source); AC_DEFINE(HAVE_V8_REGCOMP) supported_regex="$supported_regex regcomp-local" AC_DEFINE(HAVE_REGEXEC2) REGEX_O='regexp.$(O)' AC_SUBST(REGEX_O) have_regex=yes fi @@ -535,99 +535,99 @@ AH_TOP([ * be safe to run by unprivileged users. * SECURE_COMPILE is set by the --with-secure configure option. */ -#define SECURE SECURE_COMPILE +#define SECURE SECURE_COMPILE /* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE (!SECURE) +#define SHELL_ESCAPE (!SECURE) /* * EXAMINE is 1 if you wish to allow examining files by name from within less. */ -#define EXAMINE (!SECURE) +#define EXAMINE (!SECURE) /* * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME (!SECURE) +#define TAB_COMPLETE_FILENAME (!SECURE) /* * CMD_HISTORY is 1 if you wish to allow keys to cycle through * previous commands at prompts. */ -#define CMD_HISTORY 1 +#define CMD_HISTORY 1 /* - * HILITE_SEARCH is 1 if you wish to have search targets to be + * HILITE_SEARCH is 1 if you wish to have search targets to be * displayed in standout mode. */ -#define HILITE_SEARCH 1 +#define HILITE_SEARCH 1 /* * EDITOR is 1 if you wish to allow editor invocation (the "v" command). * (This is possible only if your system supplies the system() function.) * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR (!SECURE) +#define EDITOR (!SECURE) /* * TAGS is 1 if you wish to support tag files. */ -#define TAGS (!SECURE) +#define TAGS (!SECURE) /* - * USERFILE is 1 if you wish to allow a .less file to specify + * USERFILE is 1 if you wish to allow a .less file to specify * user-defined key bindings. */ -#define USERFILE (!SECURE) +#define USERFILE (!SECURE) /* * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. * This will generally work if your system provides the "popen" function * and the "echo" shell command. */ -#define GLOB (!SECURE) +#define GLOB (!SECURE) /* * PIPEC is 1 if you wish to have the "|" command * which allows the user to pipe data into a shell command. */ -#define PIPEC (!SECURE) +#define PIPEC (!SECURE) /* * LOGFILE is 1 if you wish to allow the -o option (to create log files). */ -#define LOGFILE (!SECURE) +#define LOGFILE (!SECURE) /* * GNU_OPTIONS is 1 if you wish to support the GNU-style command * line options --help and --version. */ -#define GNU_OPTIONS 1 +#define GNU_OPTIONS 1 /* * ONLY_RETURN is 1 if you want RETURN to be the only input which * will continue past an error message. * Otherwise, any key will continue past an error message. */ -#define ONLY_RETURN 0 +#define ONLY_RETURN 0 /* - * LESSKEYFILE is the filename of the default lesskey output file + * LESSKEYFILE is the filename of the default lesskey output file * (in the HOME directory). * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. - * DEF_LESSKEYINFILE is the filename of the default lesskey input + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). * LESSHISTFILE is the filename of the history file * (in the HOME directory). */ -#define LESSKEYFILE ".less" -#define LESSKEYFILE_SYS SYSDIR "/sysless" -#define DEF_LESSKEYINFILE ".lesskey" -#define LESSHISTFILE ".lesshst" +#define LESSKEYFILE ".less" +#define LESSKEYFILE_SYS SYSDIR "/sysless" +#define DEF_LESSKEYINFILE ".lesskey" +#define LESSHISTFILE ".lesshst" /* Settings always true on Unix. */ @@ -635,12 +635,12 @@ AH_TOP([ /* * Define MSDOS_COMPILER if compiling under Microsoft C. */ -#define MSDOS_COMPILER 0 +#define MSDOS_COMPILER 0 /* * Pathname separator character. */ -#define PATHNAME_SEP "/" +#define PATHNAME_SEP "/" /* * The value returned from tgetent on success. @@ -649,14 +649,14 @@ AH_TOP([ #define TGETENT_OK 1 /* - * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. + * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. */ -#define HAVE_ANSI_PROTOS 1 +#define HAVE_ANSI_PROTOS 1 /* * HAVE_SYS_TYPES_H is 1 if your system has . */ -#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_TYPES_H 1 /* * Define if you have the header file. @@ -667,28 +667,28 @@ AH_TOP([ * HAVE_PERROR is 1 if your system has the perror() call. * (Actually, if it has sys_errlist, sys_nerr and errno.) */ -#define HAVE_PERROR 1 +#define HAVE_PERROR 1 /* * HAVE_TIME is 1 if your system has the time() call. */ -#define HAVE_TIME 1 +#define HAVE_TIME 1 /* * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. */ -#define HAVE_SHELL 1 +#define HAVE_SHELL 1 /* * Default shell metacharacters and meta-escape character. */ -#define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\$%=~{}," -#define DEF_METAESCAPE "\\" +#define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\$%=~{}," +#define DEF_METAESCAPE "\\" -/* +/* * HAVE_DUP is 1 if your system has the dup() call. */ -#define HAVE_DUP 1 +#define HAVE_DUP 1 /* Define to 1 if you have the memcpy() function. */ #define HAVE_MEMCPY 1 @@ -703,25 +703,25 @@ AH_TOP([ * Sizes of various buffers. */ #if 0 /* old sizes for small memory machines */ -#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ -#define UNGOT_SIZE 100 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 200 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 512 /* Max size of line in tags file */ -#define TABSTOP_MAX 32 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ +#define UNGOT_SIZE 100 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 200 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 512 /* Max size of line in tags file */ +#define TABSTOP_MAX 32 /* Max number of custom tab stops */ #else /* more reasonable sizes for modern machines */ -#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ -#define UNGOT_SIZE 200 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 2048 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ -#define TABSTOP_MAX 128 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ +#define UNGOT_SIZE 200 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 2048 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ +#define TABSTOP_MAX 128 /* Max number of custom tab stops */ #endif /* Settings automatically determined by configure. */ diff --git a/cvt.c b/cvt.c index 9cf44b8..80ea7b8 100644 --- a/cvt.c +++ b/cvt.c @@ -19,34 +19,34 @@ extern int utf_mode; /* * Get the length of a buffer needed to convert a string. */ - public int + public int cvt_length(len, ops) - int len; - int ops; + int len; + int ops; { - if (utf_mode) - /* - * Just copying a string in UTF-8 mode can cause it to grow - * in length. - * Four output bytes for one input byte is the worst case. - */ - len *= 4; - return (len + 1); + if (utf_mode) + /* + * Just copying a string in UTF-8 mode can cause it to grow + * in length. + * Four output bytes for one input byte is the worst case. + */ + len *= 4; + return (len + 1); } /* * Allocate a chpos array for use by cvt_text. */ - public int * + public int * cvt_alloc_chpos(len) - int len; + int len; { - int i; - int *chpos = (int *) ecalloc(sizeof(int), len); - /* Initialize all entries to an invalid position. */ - for (i = 0; i < len; i++) - chpos[i] = -1; - return (chpos); + int i; + int *chpos = (int *) ecalloc(sizeof(int), len); + /* Initialize all entries to an invalid position. */ + for (i = 0; i < len; i++) + chpos[i] = -1; + return (chpos); } /* @@ -54,65 +54,65 @@ cvt_alloc_chpos(len) * Returns converted text in odst. The original offset of each * odst character (when it was in osrc) is returned in the chpos array. */ - public void + public void cvt_text(odst, osrc, chpos, lenp, ops) - char *odst; - char *osrc; - int *chpos; - int *lenp; - int ops; + char *odst; + char *osrc; + int *chpos; + int *lenp; + int ops; { - char *dst; - char *edst = odst; - char *src; - char *src_end; - LWCHAR ch; + char *dst; + char *edst = odst; + char *src; + char *src_end; + LWCHAR ch; - if (lenp != NULL) - src_end = osrc + *lenp; - else - src_end = osrc + strlen(osrc); + if (lenp != NULL) + src_end = osrc + *lenp; + else + src_end = osrc + strlen(osrc); - for (src = osrc, dst = odst; src < src_end; ) - { - int src_pos = (int) (src - osrc); - int dst_pos = (int) (dst - odst); - struct ansi_state *pansi; - ch = step_char(&src, +1, src_end); - if ((ops & CVT_BS) && ch == '\b' && dst > odst) - { - /* Delete backspace and preceding char. */ - do { - dst--; - } while (dst > odst && utf_mode && - !IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst)); - } else if ((ops & CVT_ANSI) && (pansi = ansi_start(ch)) != NULL) - { - /* Skip to end of ANSI escape sequence. */ - while (src < src_end) - { - if (ansi_step(pansi, ch) != ANSI_MID) - break; - ch = *src++; - } - ansi_done(pansi); - } else - { - /* Just copy the char to the destination buffer. */ - if ((ops & CVT_TO_LC) && IS_UPPER(ch)) - ch = TO_LOWER(ch); - put_wchar(&dst, ch); - /* Record the original position of the char. */ - if (chpos != NULL) - chpos[dst_pos] = src_pos; - } - if (dst > edst) - edst = dst; - } - if ((ops & CVT_CRLF) && edst > odst && edst[-1] == '\r') - edst--; - *edst = '\0'; - if (lenp != NULL) - *lenp = (int) (edst - odst); - /* FIXME: why was this here? if (chpos != NULL) chpos[dst - odst] = src - osrc; */ + for (src = osrc, dst = odst; src < src_end; ) + { + int src_pos = (int) (src - osrc); + int dst_pos = (int) (dst - odst); + struct ansi_state *pansi; + ch = step_char(&src, +1, src_end); + if ((ops & CVT_BS) && ch == '\b' && dst > odst) + { + /* Delete backspace and preceding char. */ + do { + dst--; + } while (dst > odst && utf_mode && + !IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst)); + } else if ((ops & CVT_ANSI) && (pansi = ansi_start(ch)) != NULL) + { + /* Skip to end of ANSI escape sequence. */ + while (src < src_end) + { + if (ansi_step(pansi, ch) != ANSI_MID) + break; + ch = *src++; + } + ansi_done(pansi); + } else + { + /* Just copy the char to the destination buffer. */ + if ((ops & CVT_TO_LC) && IS_UPPER(ch)) + ch = TO_LOWER(ch); + put_wchar(&dst, ch); + /* Record the original position of the char. */ + if (chpos != NULL) + chpos[dst_pos] = src_pos; + } + if (dst > edst) + edst = dst; + } + if ((ops & CVT_CRLF) && edst > odst && edst[-1] == '\r') + edst--; + *edst = '\0'; + if (lenp != NULL) + *lenp = (int) (edst - odst); + /* FIXME: why was this here? if (chpos != NULL) chpos[dst - odst] = src - osrc; */ } diff --git a/decode.c b/decode.c index f3bfb7a..20a2ad2 100644 --- a/decode.c +++ b/decode.c @@ -40,7 +40,7 @@ extern int screen_trashed; extern int sc_height; #define SK(k) \ - SK_SPECIAL_KEY, (k), 6, 1, 1, 1 + SK_SPECIAL_KEY, (k), 6, 1, 1, 1 /* * Command table is ordered roughly according to expected * frequency of use, so the common commands are near the beginning. @@ -48,176 +48,176 @@ extern int sc_height; static unsigned char cmdtable[] = { - '\r',0, A_F_LINE, - '\n',0, A_F_LINE, - 'e',0, A_F_LINE, - 'j',0, A_F_LINE, - SK(SK_DOWN_ARROW),0, A_F_LINE, - CONTROL('E'),0, A_F_LINE, - CONTROL('N'),0, A_F_LINE, - 'k',0, A_B_LINE, - 'y',0, A_B_LINE, - CONTROL('Y'),0, A_B_LINE, - SK(SK_CONTROL_K),0, A_B_LINE, - CONTROL('P'),0, A_B_LINE, - SK(SK_UP_ARROW),0, A_B_LINE, - 'J',0, A_FF_LINE, - 'K',0, A_BF_LINE, - 'Y',0, A_BF_LINE, - 'd',0, A_F_SCROLL, - CONTROL('D'),0, A_F_SCROLL, - 'u',0, A_B_SCROLL, - CONTROL('U'),0, A_B_SCROLL, - ESC,'[','M',0, A_X11MOUSE_IN, - ESC,'[','<',0, A_X116MOUSE_IN, - ' ',0, A_F_SCREEN, - 'f',0, A_F_SCREEN, - CONTROL('F'),0, A_F_SCREEN, - CONTROL('V'),0, A_F_SCREEN, - SK(SK_PAGE_DOWN),0, A_F_SCREEN, - 'b',0, A_B_SCREEN, - CONTROL('B'),0, A_B_SCREEN, - ESC,'v',0, A_B_SCREEN, - SK(SK_PAGE_UP),0, A_B_SCREEN, - 'z',0, A_F_WINDOW, - 'w',0, A_B_WINDOW, - ESC,' ',0, A_FF_SCREEN, - 'F',0, A_F_FOREVER, - ESC,'F',0, A_F_UNTIL_HILITE, - 'R',0, A_FREPAINT, - 'r',0, A_REPAINT, - CONTROL('R'),0, A_REPAINT, - CONTROL('L'),0, A_REPAINT, - ESC,'u',0, A_UNDO_SEARCH, - ESC,'U',0, A_CLR_SEARCH, - 'g',0, A_GOLINE, - SK(SK_HOME),0, A_GOLINE, - '<',0, A_GOLINE, - ESC,'<',0, A_GOLINE, - 'p',0, A_PERCENT, - '%',0, A_PERCENT, - ESC,'[',0, A_LSHIFT, - ESC,']',0, A_RSHIFT, - ESC,'(',0, A_LSHIFT, - ESC,')',0, A_RSHIFT, - ESC,'{',0, A_LLSHIFT, - ESC,'}',0, A_RRSHIFT, - SK(SK_RIGHT_ARROW),0, A_RSHIFT, - SK(SK_LEFT_ARROW),0, A_LSHIFT, - SK(SK_CTL_RIGHT_ARROW),0, A_RRSHIFT, - SK(SK_CTL_LEFT_ARROW),0, A_LLSHIFT, - '{',0, A_F_BRACKET|A_EXTRA, '{','}',0, - '}',0, A_B_BRACKET|A_EXTRA, '{','}',0, - '(',0, A_F_BRACKET|A_EXTRA, '(',')',0, - ')',0, A_B_BRACKET|A_EXTRA, '(',')',0, - '[',0, A_F_BRACKET|A_EXTRA, '[',']',0, - ']',0, A_B_BRACKET|A_EXTRA, '[',']',0, - ESC,CONTROL('F'),0, A_F_BRACKET, - ESC,CONTROL('B'),0, A_B_BRACKET, - 'G',0, A_GOEND, - ESC,'G',0, A_GOEND_BUF, - ESC,'>',0, A_GOEND, - '>',0, A_GOEND, - SK(SK_END),0, A_GOEND, - 'P',0, A_GOPOS, - - '0',0, A_DIGIT, - '1',0, A_DIGIT, - '2',0, A_DIGIT, - '3',0, A_DIGIT, - '4',0, A_DIGIT, - '5',0, A_DIGIT, - '6',0, A_DIGIT, - '7',0, A_DIGIT, - '8',0, A_DIGIT, - '9',0, A_DIGIT, - '.',0, A_DIGIT, - - '=',0, A_STAT, - CONTROL('G'),0, A_STAT, - ':','f',0, A_STAT, - '/',0, A_F_SEARCH, - '?',0, A_B_SEARCH, - ESC,'/',0, A_F_SEARCH|A_EXTRA, '*',0, - ESC,'?',0, A_B_SEARCH|A_EXTRA, '*',0, - 'n',0, A_AGAIN_SEARCH, - ESC,'n',0, A_T_AGAIN_SEARCH, - 'N',0, A_REVERSE_SEARCH, - ESC,'N',0, A_T_REVERSE_SEARCH, - '&',0, A_FILTER, - 'm',0, A_SETMARK, - 'M',0, A_SETMARKBOT, - ESC,'m',0, A_CLRMARK, - '\'',0, A_GOMARK, - CONTROL('X'),CONTROL('X'),0, A_GOMARK, - 'E',0, A_EXAMINE, - ':','e',0, A_EXAMINE, - CONTROL('X'),CONTROL('V'),0, A_EXAMINE, - ':','n',0, A_NEXT_FILE, - ':','p',0, A_PREV_FILE, - 't',0, A_NEXT_TAG, - 'T',0, A_PREV_TAG, - ':','x',0, A_INDEX_FILE, - ':','d',0, A_REMOVE_FILE, - '-',0, A_OPT_TOGGLE, - ':','t',0, A_OPT_TOGGLE|A_EXTRA, 't',0, - 's',0, A_OPT_TOGGLE|A_EXTRA, 'o',0, - '_',0, A_DISP_OPTION, - '|',0, A_PIPE, - 'v',0, A_VISUAL, - '!',0, A_SHELL, - '+',0, A_FIRSTCMD, - - 'H',0, A_HELP, - 'h',0, A_HELP, - SK(SK_F1),0, A_HELP, - 'V',0, A_VERSION, - 'q',0, A_QUIT, - 'Q',0, A_QUIT, - ':','q',0, A_QUIT, - ':','Q',0, A_QUIT, - 'Z','Z',0, A_QUIT + '\r',0, A_F_LINE, + '\n',0, A_F_LINE, + 'e',0, A_F_LINE, + 'j',0, A_F_LINE, + SK(SK_DOWN_ARROW),0, A_F_LINE, + CONTROL('E'),0, A_F_LINE, + CONTROL('N'),0, A_F_LINE, + 'k',0, A_B_LINE, + 'y',0, A_B_LINE, + CONTROL('Y'),0, A_B_LINE, + SK(SK_CONTROL_K),0, A_B_LINE, + CONTROL('P'),0, A_B_LINE, + SK(SK_UP_ARROW),0, A_B_LINE, + 'J',0, A_FF_LINE, + 'K',0, A_BF_LINE, + 'Y',0, A_BF_LINE, + 'd',0, A_F_SCROLL, + CONTROL('D'),0, A_F_SCROLL, + 'u',0, A_B_SCROLL, + CONTROL('U'),0, A_B_SCROLL, + ESC,'[','M',0, A_X11MOUSE_IN, + ESC,'[','<',0, A_X116MOUSE_IN, + ' ',0, A_F_SCREEN, + 'f',0, A_F_SCREEN, + CONTROL('F'),0, A_F_SCREEN, + CONTROL('V'),0, A_F_SCREEN, + SK(SK_PAGE_DOWN),0, A_F_SCREEN, + 'b',0, A_B_SCREEN, + CONTROL('B'),0, A_B_SCREEN, + ESC,'v',0, A_B_SCREEN, + SK(SK_PAGE_UP),0, A_B_SCREEN, + 'z',0, A_F_WINDOW, + 'w',0, A_B_WINDOW, + ESC,' ',0, A_FF_SCREEN, + 'F',0, A_F_FOREVER, + ESC,'F',0, A_F_UNTIL_HILITE, + 'R',0, A_FREPAINT, + 'r',0, A_REPAINT, + CONTROL('R'),0, A_REPAINT, + CONTROL('L'),0, A_REPAINT, + ESC,'u',0, A_UNDO_SEARCH, + ESC,'U',0, A_CLR_SEARCH, + 'g',0, A_GOLINE, + SK(SK_HOME),0, A_GOLINE, + '<',0, A_GOLINE, + ESC,'<',0, A_GOLINE, + 'p',0, A_PERCENT, + '%',0, A_PERCENT, + ESC,'[',0, A_LSHIFT, + ESC,']',0, A_RSHIFT, + ESC,'(',0, A_LSHIFT, + ESC,')',0, A_RSHIFT, + ESC,'{',0, A_LLSHIFT, + ESC,'}',0, A_RRSHIFT, + SK(SK_RIGHT_ARROW),0, A_RSHIFT, + SK(SK_LEFT_ARROW),0, A_LSHIFT, + SK(SK_CTL_RIGHT_ARROW),0, A_RRSHIFT, + SK(SK_CTL_LEFT_ARROW),0, A_LLSHIFT, + '{',0, A_F_BRACKET|A_EXTRA, '{','}',0, + '}',0, A_B_BRACKET|A_EXTRA, '{','}',0, + '(',0, A_F_BRACKET|A_EXTRA, '(',')',0, + ')',0, A_B_BRACKET|A_EXTRA, '(',')',0, + '[',0, A_F_BRACKET|A_EXTRA, '[',']',0, + ']',0, A_B_BRACKET|A_EXTRA, '[',']',0, + ESC,CONTROL('F'),0, A_F_BRACKET, + ESC,CONTROL('B'),0, A_B_BRACKET, + 'G',0, A_GOEND, + ESC,'G',0, A_GOEND_BUF, + ESC,'>',0, A_GOEND, + '>',0, A_GOEND, + SK(SK_END),0, A_GOEND, + 'P',0, A_GOPOS, + + '0',0, A_DIGIT, + '1',0, A_DIGIT, + '2',0, A_DIGIT, + '3',0, A_DIGIT, + '4',0, A_DIGIT, + '5',0, A_DIGIT, + '6',0, A_DIGIT, + '7',0, A_DIGIT, + '8',0, A_DIGIT, + '9',0, A_DIGIT, + '.',0, A_DIGIT, + + '=',0, A_STAT, + CONTROL('G'),0, A_STAT, + ':','f',0, A_STAT, + '/',0, A_F_SEARCH, + '?',0, A_B_SEARCH, + ESC,'/',0, A_F_SEARCH|A_EXTRA, '*',0, + ESC,'?',0, A_B_SEARCH|A_EXTRA, '*',0, + 'n',0, A_AGAIN_SEARCH, + ESC,'n',0, A_T_AGAIN_SEARCH, + 'N',0, A_REVERSE_SEARCH, + ESC,'N',0, A_T_REVERSE_SEARCH, + '&',0, A_FILTER, + 'm',0, A_SETMARK, + 'M',0, A_SETMARKBOT, + ESC,'m',0, A_CLRMARK, + '\'',0, A_GOMARK, + CONTROL('X'),CONTROL('X'),0, A_GOMARK, + 'E',0, A_EXAMINE, + ':','e',0, A_EXAMINE, + CONTROL('X'),CONTROL('V'),0, A_EXAMINE, + ':','n',0, A_NEXT_FILE, + ':','p',0, A_PREV_FILE, + 't',0, A_NEXT_TAG, + 'T',0, A_PREV_TAG, + ':','x',0, A_INDEX_FILE, + ':','d',0, A_REMOVE_FILE, + '-',0, A_OPT_TOGGLE, + ':','t',0, A_OPT_TOGGLE|A_EXTRA, 't',0, + 's',0, A_OPT_TOGGLE|A_EXTRA, 'o',0, + '_',0, A_DISP_OPTION, + '|',0, A_PIPE, + 'v',0, A_VISUAL, + '!',0, A_SHELL, + '+',0, A_FIRSTCMD, + + 'H',0, A_HELP, + 'h',0, A_HELP, + SK(SK_F1),0, A_HELP, + 'V',0, A_VERSION, + 'q',0, A_QUIT, + 'Q',0, A_QUIT, + ':','q',0, A_QUIT, + ':','Q',0, A_QUIT, + 'Z','Z',0, A_QUIT }; static unsigned char edittable[] = { - '\t',0, EC_F_COMPLETE, /* TAB */ - '\17',0, EC_B_COMPLETE, /* BACKTAB */ - SK(SK_BACKTAB),0, EC_B_COMPLETE, /* BACKTAB */ - ESC,'\t',0, EC_B_COMPLETE, /* ESC TAB */ - CONTROL('L'),0, EC_EXPAND, /* CTRL-L */ - CONTROL('V'),0, EC_LITERAL, /* BACKSLASH */ - CONTROL('A'),0, EC_LITERAL, /* BACKSLASH */ - ESC,'l',0, EC_RIGHT, /* ESC l */ - SK(SK_RIGHT_ARROW),0, EC_RIGHT, /* RIGHTARROW */ - ESC,'h',0, EC_LEFT, /* ESC h */ - SK(SK_LEFT_ARROW),0, EC_LEFT, /* LEFTARROW */ - ESC,'b',0, EC_W_LEFT, /* ESC b */ - ESC,SK(SK_LEFT_ARROW),0, EC_W_LEFT, /* ESC LEFTARROW */ - SK(SK_CTL_LEFT_ARROW),0, EC_W_LEFT, /* CTRL-LEFTARROW */ - ESC,'w',0, EC_W_RIGHT, /* ESC w */ - ESC,SK(SK_RIGHT_ARROW),0, EC_W_RIGHT, /* ESC RIGHTARROW */ - SK(SK_CTL_RIGHT_ARROW),0, EC_W_RIGHT, /* CTRL-RIGHTARROW */ - ESC,'i',0, EC_INSERT, /* ESC i */ - SK(SK_INSERT),0, EC_INSERT, /* INSERT */ - ESC,'x',0, EC_DELETE, /* ESC x */ - SK(SK_DELETE),0, EC_DELETE, /* DELETE */ - ESC,'X',0, EC_W_DELETE, /* ESC X */ - ESC,SK(SK_DELETE),0, EC_W_DELETE, /* ESC DELETE */ - SK(SK_CTL_DELETE),0, EC_W_DELETE, /* CTRL-DELETE */ - SK(SK_CTL_BACKSPACE),0, EC_W_BACKSPACE, /* CTRL-BACKSPACE */ - ESC,'\b',0, EC_W_BACKSPACE, /* ESC BACKSPACE */ - ESC,'0',0, EC_HOME, /* ESC 0 */ - SK(SK_HOME),0, EC_HOME, /* HOME */ - ESC,'$',0, EC_END, /* ESC $ */ - SK(SK_END),0, EC_END, /* END */ - ESC,'k',0, EC_UP, /* ESC k */ - SK(SK_UP_ARROW),0, EC_UP, /* UPARROW */ - ESC,'j',0, EC_DOWN, /* ESC j */ - SK(SK_DOWN_ARROW),0, EC_DOWN, /* DOWNARROW */ - CONTROL('G'),0, EC_ABORT, /* CTRL-G */ - ESC,'[','M',0, EC_X11MOUSE, /* X11 mouse report */ - ESC,'[','<',0, EC_X116MOUSE, /* X11 1006 mouse report */ + '\t',0, EC_F_COMPLETE, /* TAB */ + '\17',0, EC_B_COMPLETE, /* BACKTAB */ + SK(SK_BACKTAB),0, EC_B_COMPLETE, /* BACKTAB */ + ESC,'\t',0, EC_B_COMPLETE, /* ESC TAB */ + CONTROL('L'),0, EC_EXPAND, /* CTRL-L */ + CONTROL('V'),0, EC_LITERAL, /* BACKSLASH */ + CONTROL('A'),0, EC_LITERAL, /* BACKSLASH */ + ESC,'l',0, EC_RIGHT, /* ESC l */ + SK(SK_RIGHT_ARROW),0, EC_RIGHT, /* RIGHTARROW */ + ESC,'h',0, EC_LEFT, /* ESC h */ + SK(SK_LEFT_ARROW),0, EC_LEFT, /* LEFTARROW */ + ESC,'b',0, EC_W_LEFT, /* ESC b */ + ESC,SK(SK_LEFT_ARROW),0, EC_W_LEFT, /* ESC LEFTARROW */ + SK(SK_CTL_LEFT_ARROW),0, EC_W_LEFT, /* CTRL-LEFTARROW */ + ESC,'w',0, EC_W_RIGHT, /* ESC w */ + ESC,SK(SK_RIGHT_ARROW),0, EC_W_RIGHT, /* ESC RIGHTARROW */ + SK(SK_CTL_RIGHT_ARROW),0, EC_W_RIGHT, /* CTRL-RIGHTARROW */ + ESC,'i',0, EC_INSERT, /* ESC i */ + SK(SK_INSERT),0, EC_INSERT, /* INSERT */ + ESC,'x',0, EC_DELETE, /* ESC x */ + SK(SK_DELETE),0, EC_DELETE, /* DELETE */ + ESC,'X',0, EC_W_DELETE, /* ESC X */ + ESC,SK(SK_DELETE),0, EC_W_DELETE, /* ESC DELETE */ + SK(SK_CTL_DELETE),0, EC_W_DELETE, /* CTRL-DELETE */ + SK(SK_CTL_BACKSPACE),0, EC_W_BACKSPACE, /* CTRL-BACKSPACE */ + ESC,'\b',0, EC_W_BACKSPACE, /* ESC BACKSPACE */ + ESC,'0',0, EC_HOME, /* ESC 0 */ + SK(SK_HOME),0, EC_HOME, /* HOME */ + ESC,'$',0, EC_END, /* ESC $ */ + SK(SK_END),0, EC_END, /* END */ + ESC,'k',0, EC_UP, /* ESC k */ + SK(SK_UP_ARROW),0, EC_UP, /* UPARROW */ + ESC,'j',0, EC_DOWN, /* ESC j */ + SK(SK_DOWN_ARROW),0, EC_DOWN, /* DOWNARROW */ + CONTROL('G'),0, EC_ABORT, /* CTRL-G */ + ESC,'[','M',0, EC_X11MOUSE, /* X11 mouse report */ + ESC,'[','<',0, EC_X116MOUSE, /* X11 1006 mouse report */ }; /* @@ -225,9 +225,9 @@ static unsigned char edittable[] = */ struct tablelist { - struct tablelist *t_next; - char *t_start; - char *t_end; + struct tablelist *t_next; + char *t_start; + char *t_end; }; /* @@ -242,779 +242,778 @@ static struct tablelist *list_sysvar_tables = NULL; /* * Expand special key abbreviations in a command table. */ - static void + static void expand_special_keys(table, len) - char *table; - int len; + char *table; + int len; { - char *fm; - char *to; - int a; - char *repl; - int klen; - - for (fm = table; fm < table + len; ) - { - /* - * Rewrite each command in the table with any - * special key abbreviations expanded. - */ - for (to = fm; *fm != '\0'; ) - { - if (*fm != SK_SPECIAL_KEY) - { - *to++ = *fm++; - continue; - } - /* - * After SK_SPECIAL_KEY, next byte is the type - * of special key (one of the SK_* contants), - * and the byte after that is the number of bytes, - * N, reserved by the abbreviation (including the - * SK_SPECIAL_KEY and key type bytes). - * Replace all N bytes with the actual bytes - * output by the special key on this terminal. - */ - repl = special_key_str(fm[1]); - klen = fm[2] & 0377; - fm += klen; - if (repl == NULL || (int) strlen(repl) > klen) - repl = "\377"; - while (*repl != '\0') - *to++ = *repl++; - } - *to++ = '\0'; - /* - * Fill any unused bytes between end of command and - * the action byte with A_SKIP. - */ - while (to <= fm) - *to++ = A_SKIP; - fm++; - a = *fm++ & 0377; - if (a & A_EXTRA) - { - while (*fm++ != '\0') - continue; - } - } + char *fm; + char *to; + int a; + char *repl; + int klen; + + for (fm = table; fm < table + len; ) + { + /* + * Rewrite each command in the table with any + * special key abbreviations expanded. + */ + for (to = fm; *fm != '\0'; ) + { + if (*fm != SK_SPECIAL_KEY) + { + *to++ = *fm++; + continue; + } + /* + * After SK_SPECIAL_KEY, next byte is the type + * of special key (one of the SK_* contants), + * and the byte after that is the number of bytes, + * N, reserved by the abbreviation (including the + * SK_SPECIAL_KEY and key type bytes). + * Replace all N bytes with the actual bytes + * output by the special key on this terminal. + */ + repl = special_key_str(fm[1]); + klen = fm[2] & 0377; + fm += klen; + if (repl == NULL || (int) strlen(repl) > klen) + repl = "\377"; + while (*repl != '\0') + *to++ = *repl++; + } + *to++ = '\0'; + /* + * Fill any unused bytes between end of command and + * the action byte with A_SKIP. + */ + while (to <= fm) + *to++ = A_SKIP; + fm++; + a = *fm++ & 0377; + if (a & A_EXTRA) + { + while (*fm++ != '\0') + continue; + } + } } /* * Expand special key abbreviations in a list of command tables. */ - static void + static void expand_cmd_table(tlist) - struct tablelist *tlist; + struct tablelist *tlist; { - struct tablelist *t; - for (t = tlist; t != NULL; t = t->t_next) - { - expand_special_keys(t->t_start, t->t_end - t->t_start); - } + struct tablelist *t; + for (t = tlist; t != NULL; t = t->t_next) + { + expand_special_keys(t->t_start, t->t_end - t->t_start); + } } /* * Expand special key abbreviations in all command tables. */ - public void + public void expand_cmd_tables(VOID_PARAM) { - expand_cmd_table(list_fcmd_tables); - expand_cmd_table(list_ecmd_tables); - expand_cmd_table(list_var_tables); - expand_cmd_table(list_sysvar_tables); + expand_cmd_table(list_fcmd_tables); + expand_cmd_table(list_ecmd_tables); + expand_cmd_table(list_var_tables); + expand_cmd_table(list_sysvar_tables); } /* * Initialize the command lists. */ - public void + public void init_cmds(VOID_PARAM) { - /* - * Add the default command tables. - */ - add_fcmd_table((char*)cmdtable, sizeof(cmdtable)); - add_ecmd_table((char*)edittable, sizeof(edittable)); + /* + * Add the default command tables. + */ + add_fcmd_table((char*)cmdtable, sizeof(cmdtable)); + add_ecmd_table((char*)edittable, sizeof(edittable)); #if USERFILE - /* - * For backwards compatibility, - * try to add tables in the OLD system lesskey file. - */ + /* + * For backwards compatibility, + * try to add tables in the OLD system lesskey file. + */ #ifdef BINDIR - add_hometable(NULL, BINDIR "/.sysless", 1); + add_hometable(NULL, BINDIR "/.sysless", 1); #endif - /* - * Try to add the tables in the system lesskey file. - */ - add_hometable("LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1); - /* - * Try to add the tables in the standard lesskey file "$HOME/.less". - */ - add_hometable("LESSKEY", LESSKEYFILE, 0); + /* + * Try to add the tables in the system lesskey file. + */ + add_hometable("LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1); + /* + * Try to add the tables in the standard lesskey file "$HOME/.less". + */ + add_hometable("LESSKEY", LESSKEYFILE, 0); #endif } /* * Add a command table. */ - static int + static int add_cmd_table(tlist, buf, len) - struct tablelist **tlist; - char *buf; - int len; + struct tablelist **tlist; + char *buf; + int len; { - struct tablelist *t; - - if (len == 0) - return (0); - /* - * Allocate a tablelist structure, initialize it, - * and link it into the list of tables. - */ - if ((t = (struct tablelist *) - calloc(1, sizeof(struct tablelist))) == NULL) - { - return (-1); - } - t->t_start = buf; - t->t_end = buf + len; - t->t_next = *tlist; - *tlist = t; - return (0); + struct tablelist *t; + + if (len == 0) + return (0); + /* + * Allocate a tablelist structure, initialize it, + * and link it into the list of tables. + */ + if ((t = (struct tablelist *) + calloc(1, sizeof(struct tablelist))) == NULL) + { + return (-1); + } + t->t_start = buf; + t->t_end = buf + len; + t->t_next = *tlist; + *tlist = t; + return (0); } /* * Add a command table. */ - public void + public void add_fcmd_table(buf, len) - char *buf; - int len; + char *buf; + int len; { - if (add_cmd_table(&list_fcmd_tables, buf, len) < 0) - error("Warning: some commands disabled", NULL_PARG); + if (add_cmd_table(&list_fcmd_tables, buf, len) < 0) + error("Warning: some commands disabled", NULL_PARG); } /* * Add an editing command table. */ - public void + public void add_ecmd_table(buf, len) - char *buf; - int len; + char *buf; + int len; { - if (add_cmd_table(&list_ecmd_tables, buf, len) < 0) - error("Warning: some edit commands disabled", NULL_PARG); + if (add_cmd_table(&list_ecmd_tables, buf, len) < 0) + error("Warning: some edit commands disabled", NULL_PARG); } /* * Add an environment variable table. */ - static void + static void add_var_table(tlist, buf, len) - struct tablelist **tlist; - char *buf; - int len; + struct tablelist **tlist; + char *buf; + int len; { - if (add_cmd_table(tlist, buf, len) < 0) - error("Warning: environment variables from lesskey file unavailable", NULL_PARG); + if (add_cmd_table(tlist, buf, len) < 0) + error("Warning: environment variables from lesskey file unavailable", NULL_PARG); } /* * Return action for a mouse wheel down event. */ - static int + static int mouse_wheel_down(VOID_PARAM) { - return ((mousecap == OPT_ONPLUS) ? A_B_MOUSE : A_F_MOUSE); + return ((mousecap == OPT_ONPLUS) ? A_B_MOUSE : A_F_MOUSE); } /* * Return action for a mouse wheel up event. */ - static int + static int mouse_wheel_up(VOID_PARAM) { - return ((mousecap == OPT_ONPLUS) ? A_F_MOUSE : A_B_MOUSE); + return ((mousecap == OPT_ONPLUS) ? A_F_MOUSE : A_B_MOUSE); } /* * Return action for a mouse button release event. */ - static int + static int mouse_button_rel(x, y) - int x; - int y; + int x; + int y; { - /* - * {{ It would be better to return an action and then do this - * in commands() but it's nontrivial to pass y to it. }} - */ - if (y < sc_height-1) - { - setmark('#', y); - screen_trashed = 1; - } - return (A_NOACTION); + /* + * {{ It would be better to return an action and then do this + * in commands() but it's nontrivial to pass y to it. }} + */ + if (y < sc_height-1) + { + setmark('#', y); + screen_trashed = 1; + } + return (A_NOACTION); } /* * Read a decimal integer. Return the integer and set *pterm to the terminating char. */ - static int + static int getcc_int(pterm) - char* pterm; + char* pterm; { - int num = 0; - int digits = 0; - for (;;) - { - char ch = getcc(); - if (ch < '0' || ch > '9') - { - if (pterm != NULL) *pterm = ch; - if (digits == 0) - return (-1); - return (num); - } - num = (10 * num) + (ch - '0'); - ++digits; - } + int num = 0; + int digits = 0; + for (;;) + { + char ch = getcc(); + if (ch < '0' || ch > '9') + { + if (pterm != NULL) *pterm = ch; + if (digits == 0) + return (-1); + return (num); + } + num = (10 * num) + (ch - '0'); + ++digits; + } } /* * Read suffix of mouse input and return the action to take. * The prefix ("\e[M") has already been read. */ - static int + static int x11mouse_action(skip) - int skip; + int skip; { - int b = getcc() - X11MOUSE_OFFSET; - int x = getcc() - X11MOUSE_OFFSET-1; - int y = getcc() - X11MOUSE_OFFSET-1; - if (skip) - return (A_NOACTION); - switch (b) { - default: - return (A_NOACTION); - case X11MOUSE_WHEEL_DOWN: - return mouse_wheel_down(); - case X11MOUSE_WHEEL_UP: - return mouse_wheel_up(); - case X11MOUSE_BUTTON_REL: - return mouse_button_rel(x, y); - } + int b = getcc() - X11MOUSE_OFFSET; + int x = getcc() - X11MOUSE_OFFSET-1; + int y = getcc() - X11MOUSE_OFFSET-1; + if (skip) + return (A_NOACTION); + switch (b) { + default: + return (A_NOACTION); + case X11MOUSE_WHEEL_DOWN: + return mouse_wheel_down(); + case X11MOUSE_WHEEL_UP: + return mouse_wheel_up(); + case X11MOUSE_BUTTON_REL: + return mouse_button_rel(x, y); + } } /* * Read suffix of mouse input and return the action to take. * The prefix ("\e[<") has already been read. */ - static int + static int x116mouse_action(skip) - int skip; + int skip; { - char ch; - int x, y; - int b = getcc_int(&ch); - if (b < 0 || ch != ';') return (A_NOACTION); - x = getcc_int(&ch) - 1; - if (x < 0 || ch != ';') return (A_NOACTION); - y = getcc_int(&ch) - 1; - if (y < 0) return (A_NOACTION); - if (skip) - return (A_NOACTION); - switch (b) { - case X11MOUSE_WHEEL_DOWN: - return mouse_wheel_down(); - case X11MOUSE_WHEEL_UP: - return mouse_wheel_up(); - default: - if (ch != 'm') return (A_NOACTION); - return mouse_button_rel(x, y); - } + char ch; + int x, y; + int b = getcc_int(&ch); + if (b < 0 || ch != ';') return (A_NOACTION); + x = getcc_int(&ch) - 1; + if (x < 0 || ch != ';') return (A_NOACTION); + y = getcc_int(&ch) - 1; + if (y < 0) return (A_NOACTION); + if (skip) + return (A_NOACTION); + switch (b) { + case X11MOUSE_WHEEL_DOWN: + return mouse_wheel_down(); + case X11MOUSE_WHEEL_UP: + return mouse_wheel_up(); + default: + if (ch != 'm') return (A_NOACTION); + return mouse_button_rel(x, y); + } } /* * Search a single command table for the command string in cmd. */ - static int + static int cmd_search(cmd, table, endtable, sp) - char *cmd; - char *table; - char *endtable; - char **sp; + char *cmd; + char *table; + char *endtable; + char **sp; { - char *p; - char *q; - int a; - - *sp = NULL; - for (p = table, q = cmd; p < endtable; p++, q++) - { - if (*p == *q) - { - /* - * Current characters match. - * If we're at the end of the string, we've found it. - * Return the action code, which is the character - * after the null at the end of the string - * in the command table. - */ - if (*p == '\0') - { - a = *++p & 0377; - while (a == A_SKIP) - a = *++p & 0377; - if (a == A_END_LIST) - { - /* - * We get here only if the original - * cmd string passed in was empty (""). - * I don't think that can happen, - * but just in case ... - */ - return (A_UINVALID); - } - /* - * Check for an "extra" string. - */ - if (a & A_EXTRA) - { - *sp = ++p; - a &= ~A_EXTRA; - } - if (a == A_X11MOUSE_IN) - a = x11mouse_action(0); - else if (a == A_X116MOUSE_IN) - a = x116mouse_action(0); - return (a); - } - } else if (*q == '\0') - { - /* - * Hit the end of the user's command, - * but not the end of the string in the command table. - * The user's command is incomplete. - */ - return (A_PREFIX); - } else - { - /* - * Not a match. - * Skip ahead to the next command in the - * command table, and reset the pointer - * to the beginning of the user's command. - */ - if (*p == '\0' && p[1] == A_END_LIST) - { - /* - * A_END_LIST is a special marker that tells - * us to abort the cmd search. - */ - return (A_UINVALID); - } - while (*p++ != '\0') - continue; - while (*p == A_SKIP) - p++; - if (*p & A_EXTRA) - while (*++p != '\0') - continue; - q = cmd-1; - } - } - /* - * No match found in the entire command table. - */ - return (A_INVALID); + char *p; + char *q; + int a; + + *sp = NULL; + for (p = table, q = cmd; p < endtable; p++, q++) + { + if (*p == *q) + { + /* + * Current characters match. + * If we're at the end of the string, we've found it. + * Return the action code, which is the character + * after the null at the end of the string + * in the command table. + */ + if (*p == '\0') + { + a = *++p & 0377; + while (a == A_SKIP) + a = *++p & 0377; + if (a == A_END_LIST) + { + /* + * We get here only if the original + * cmd string passed in was empty (""). + * I don't think that can happen, + * but just in case ... + */ + return (A_UINVALID); + } + /* + * Check for an "extra" string. + */ + if (a & A_EXTRA) + { + *sp = ++p; + a &= ~A_EXTRA; + } + if (a == A_X11MOUSE_IN) + a = x11mouse_action(0); + else if (a == A_X116MOUSE_IN) + a = x116mouse_action(0); + return (a); + } + } else if (*q == '\0') + { + /* + * Hit the end of the user's command, + * but not the end of the string in the command table. + * The user's command is incomplete. + */ + return (A_PREFIX); + } else + { + /* + * Not a match. + * Skip ahead to the next command in the + * command table, and reset the pointer + * to the beginning of the user's command. + */ + if (*p == '\0' && p[1] == A_END_LIST) + { + /* + * A_END_LIST is a special marker that tells + * us to abort the cmd search. + */ + return (A_UINVALID); + } + while (*p++ != '\0') + continue; + while (*p == A_SKIP) + p++; + if (*p & A_EXTRA) + while (*++p != '\0') + continue; + q = cmd-1; + } + } + /* + * No match found in the entire command table. + */ + return (A_INVALID); } /* * Decode a command character and return the associated action. * The "extra" string, if any, is returned in sp. */ - static int + static int cmd_decode(tlist, cmd, sp) - struct tablelist *tlist; - char *cmd; - char **sp; + struct tablelist *tlist; + char *cmd; + char **sp; { - struct tablelist *t; - int action = A_INVALID; - - /* - * Search thru all the command tables. - * Stop when we find an action which is not A_INVALID. - */ - for (t = tlist; t != NULL; t = t->t_next) - { - action = cmd_search(cmd, t->t_start, t->t_end, sp); - if (action != A_INVALID) - break; - } - if (action == A_UINVALID) - action = A_INVALID; - return (action); + struct tablelist *t; + int action = A_INVALID; + + /* + * Search thru all the command tables. + * Stop when we find an action which is not A_INVALID. + */ + for (t = tlist; t != NULL; t = t->t_next) + { + action = cmd_search(cmd, t->t_start, t->t_end, sp); + if (action != A_INVALID) + break; + } + if (action == A_UINVALID) + action = A_INVALID; + return (action); } /* * Decode a command from the cmdtables list. */ - public int + public int fcmd_decode(cmd, sp) - char *cmd; - char **sp; + char *cmd; + char **sp; { - return (cmd_decode(list_fcmd_tables, cmd, sp)); + return (cmd_decode(list_fcmd_tables, cmd, sp)); } /* * Decode a command from the edittables list. */ - public int + public int ecmd_decode(cmd, sp) - char *cmd; - char **sp; + char *cmd; + char **sp; { - return (cmd_decode(list_ecmd_tables, cmd, sp)); + return (cmd_decode(list_ecmd_tables, cmd, sp)); } /* * Get the value of an environment variable. * Looks first in the lesskey file, then in the real environment. */ - public char * + public char * lgetenv(var) - char *var; + char *var; { - int a; - char *s; - - a = cmd_decode(list_var_tables, var, &s); - if (a == EV_OK) - return (s); - s = getenv(var); - if (s != NULL && *s != '\0') - return (s); - a = cmd_decode(list_sysvar_tables, var, &s); - if (a == EV_OK) - return (s); - return (NULL); + int a; + char *s; + + a = cmd_decode(list_var_tables, var, &s); + if (a == EV_OK) + return (s); + s = getenv(var); + if (s != NULL && *s != '\0') + return (s); + a = cmd_decode(list_sysvar_tables, var, &s); + if (a == EV_OK) + return (s); + return (NULL); } /* - * Is a string null or empty? + * Is a string null or empty? */ - public int + public int isnullenv(s) - char* s; + char* s; { - return (s == NULL || *s == '\0'); + return (s == NULL || *s == '\0'); } #if USERFILE /* * Get an "integer" from a lesskey file. - * Integers are stored in a funny format: + * Integers are stored in a funny format: * two bytes, low order first, in radix KRADIX. */ - static int + static int gint(sp) - char **sp; + char **sp; { - int n; + int n; - n = *(*sp)++; - n += *(*sp)++ * KRADIX; - return (n); + n = *(*sp)++; + n += *(*sp)++ * KRADIX; + return (n); } /* * Process an old (pre-v241) lesskey file. */ - static int + static int old_lesskey(buf, len) - char *buf; - int len; + char *buf; + int len; { - /* - * Old-style lesskey file. - * The file must end with either - * ...,cmd,0,action - * or ...,cmd,0,action|A_EXTRA,string,0 - * So the last byte or the second to last byte must be zero. - */ - if (buf[len-1] != '\0' && buf[len-2] != '\0') - return (-1); - add_fcmd_table(buf, len); - return (0); + /* + * Old-style lesskey file. + * The file must end with either + * ...,cmd,0,action + * or ...,cmd,0,action|A_EXTRA,string,0 + * So the last byte or the second to last byte must be zero. + */ + if (buf[len-1] != '\0' && buf[len-2] != '\0') + return (-1); + add_fcmd_table(buf, len); + return (0); } -/* +/* * Process a new (post-v241) lesskey file. */ - static int + static int new_lesskey(buf, len, sysvar) - char *buf; - int len; - int sysvar; + char *buf; + int len; + int sysvar; { - char *p; - int c; - int n; - - /* - * New-style lesskey file. - * Extract the pieces. - */ - if (buf[len-3] != C0_END_LESSKEY_MAGIC || - buf[len-2] != C1_END_LESSKEY_MAGIC || - buf[len-1] != C2_END_LESSKEY_MAGIC) - return (-1); - p = buf + 4; - for (;;) - { - c = *p++; - switch (c) - { - case CMD_SECTION: - n = gint(&p); - add_fcmd_table(p, n); - p += n; - break; - case EDIT_SECTION: - n = gint(&p); - add_ecmd_table(p, n); - p += n; - break; - case VAR_SECTION: - n = gint(&p); - add_var_table((sysvar) ? - &list_sysvar_tables : &list_var_tables, p, n); - p += n; - break; - case END_SECTION: - return (0); - default: - /* - * Unrecognized section type. - */ - return (-1); - } - } + char *p; + int c; + int n; + + /* + * New-style lesskey file. + * Extract the pieces. + */ + if (buf[len-3] != C0_END_LESSKEY_MAGIC || + buf[len-2] != C1_END_LESSKEY_MAGIC || + buf[len-1] != C2_END_LESSKEY_MAGIC) + return (-1); + p = buf + 4; + for (;;) + { + c = *p++; + switch (c) + { + case CMD_SECTION: + n = gint(&p); + add_fcmd_table(p, n); + p += n; + break; + case EDIT_SECTION: + n = gint(&p); + add_ecmd_table(p, n); + p += n; + break; + case VAR_SECTION: + n = gint(&p); + add_var_table((sysvar) ? + &list_sysvar_tables : &list_var_tables, p, n); + p += n; + break; + case END_SECTION: + return (0); + default: + /* + * Unrecognized section type. + */ + return (-1); + } + } } /* * Set up a user command table, based on a "lesskey" file. */ - public int + public int lesskey(filename, sysvar) - char *filename; - int sysvar; + char *filename; + int sysvar; { - char *buf; - POSITION len; - long n; - int f; - - if (secure) - return (1); - /* - * Try to open the lesskey file. - */ - f = open(filename, OPEN_READ); - if (f < 0) - return (1); - - /* - * Read the file into a buffer. - * We first figure out the size of the file and allocate space for it. - * {{ Minimal error checking is done here. - * A garbage .less file will produce strange results. - * To avoid a large amount of error checking code here, we - * rely on the lesskey program to generate a good .less file. }} - */ - len = filesize(f); - if (len == NULL_POSITION || len < 3) - { - /* - * Bad file (valid file must have at least 3 chars). - */ - close(f); - return (-1); - } - if ((buf = (char *) calloc((int)len, sizeof(char))) == NULL) - { - close(f); - return (-1); - } - if (lseek(f, (off_t)0, SEEK_SET) == BAD_LSEEK) - { - free(buf); - close(f); - return (-1); - } - n = read(f, buf, (unsigned int) len); - close(f); - if (n != len) - { - free(buf); - return (-1); - } - - /* - * Figure out if this is an old-style (before version 241) - * or new-style lesskey file format. - */ - if (buf[0] != C0_LESSKEY_MAGIC || buf[1] != C1_LESSKEY_MAGIC || - buf[2] != C2_LESSKEY_MAGIC || buf[3] != C3_LESSKEY_MAGIC) - return (old_lesskey(buf, (int)len)); - return (new_lesskey(buf, (int)len, sysvar)); + char *buf; + POSITION len; + long n; + int f; + + if (secure) + return (1); + /* + * Try to open the lesskey file. + */ + f = open(filename, OPEN_READ); + if (f < 0) + return (1); + + /* + * Read the file into a buffer. + * We first figure out the size of the file and allocate space for it. + * {{ Minimal error checking is done here. + * A garbage .less file will produce strange results. + * To avoid a large amount of error checking code here, we + * rely on the lesskey program to generate a good .less file. }} + */ + len = filesize(f); + if (len == NULL_POSITION || len < 3) + { + /* + * Bad file (valid file must have at least 3 chars). + */ + close(f); + return (-1); + } + if ((buf = (char *) calloc((int)len, sizeof(char))) == NULL) + { + close(f); + return (-1); + } + if (lseek(f, (off_t)0, SEEK_SET) == BAD_LSEEK) + { + free(buf); + close(f); + return (-1); + } + n = read(f, buf, (unsigned int) len); + close(f); + if (n != len) + { + free(buf); + return (-1); + } + + /* + * Figure out if this is an old-style (before version 241) + * or new-style lesskey file format. + */ + if (buf[0] != C0_LESSKEY_MAGIC || buf[1] != C1_LESSKEY_MAGIC || + buf[2] != C2_LESSKEY_MAGIC || buf[3] != C3_LESSKEY_MAGIC) + return (old_lesskey(buf, (int)len)); + return (new_lesskey(buf, (int)len, sysvar)); } /* * Add the standard lesskey file "$HOME/.less" */ - public void + public void add_hometable(envname, def_filename, sysvar) - char *envname; - char *def_filename; - int sysvar; + char *envname; + char *def_filename; + int sysvar; { - char *filename; - PARG parg; - - if (envname != NULL && (filename = lgetenv(envname)) != NULL) - filename = save(filename); - else if (sysvar) - filename = save(def_filename); - else - filename = homefile(def_filename); - if (filename == NULL) - return; - if (lesskey(filename, sysvar) < 0) - { - parg.p_string = filename; - error("Cannot use lesskey file \"%s\"", &parg); - } - free(filename); + char *filename; + PARG parg; + + if (envname != NULL && (filename = lgetenv(envname)) != NULL) + filename = save(filename); + else if (sysvar) + filename = save(def_filename); + else + filename = homefile(def_filename); + if (filename == NULL) + return; + if (lesskey(filename, sysvar) < 0) + { + parg.p_string = filename; + error("Cannot use lesskey file \"%s\"", &parg); + } + free(filename); } #endif /* * See if a char is a special line-editing command. */ - public int + public int editchar(c, flags) - int c; - int flags; + int c; + int flags; { - int action; - int nch; - char *s; - char usercmd[MAX_CMDLEN+1]; - - /* - * An editing character could actually be a sequence of characters; - * for example, an escape sequence sent by pressing the uparrow key. - * To match the editing string, we use the command decoder - * but give it the edit-commands command table - * This table is constructed to match the user's keyboard. - */ - if (c == erase_char || c == erase2_char) - return (EC_BACKSPACE); - if (c == kill_char) - { + int action; + int nch; + char *s; + char usercmd[MAX_CMDLEN+1]; + + /* + * An editing character could actually be a sequence of characters; + * for example, an escape sequence sent by pressing the uparrow key. + * To match the editing string, we use the command decoder + * but give it the edit-commands command table + * This table is constructed to match the user's keyboard. + */ + if (c == erase_char || c == erase2_char) + return (EC_BACKSPACE); + if (c == kill_char) + { #if MSDOS_COMPILER==WIN32C - if (!win32_kbhit()) + if (!win32_kbhit()) #endif - return (EC_LINEKILL); - } - - /* - * Collect characters in a buffer. - * Start with the one we have, and get more if we need them. - */ - nch = 0; - do { - if (nch > 0) - c = getcc(); - usercmd[nch] = c; - usercmd[nch+1] = '\0'; - nch++; - action = ecmd_decode(usercmd, &s); - } while (action == A_PREFIX && nch < MAX_CMDLEN); - - if (action == EC_X11MOUSE) - return (x11mouse_action(1)); - if (action == EC_X116MOUSE) - return (x116mouse_action(1)); - - if (flags & ECF_NORIGHTLEFT) - { - switch (action) - { - case EC_RIGHT: - case EC_LEFT: - action = A_INVALID; - break; - } - } + return (EC_LINEKILL); + } + + /* + * Collect characters in a buffer. + * Start with the one we have, and get more if we need them. + */ + nch = 0; + do { + if (nch > 0) + c = getcc(); + usercmd[nch] = c; + usercmd[nch+1] = '\0'; + nch++; + action = ecmd_decode(usercmd, &s); + } while (action == A_PREFIX && nch < MAX_CMDLEN); + + if (action == EC_X11MOUSE) + return (x11mouse_action(1)); + if (action == EC_X116MOUSE) + return (x116mouse_action(1)); + + if (flags & ECF_NORIGHTLEFT) + { + switch (action) + { + case EC_RIGHT: + case EC_LEFT: + action = A_INVALID; + break; + } + } #if CMD_HISTORY - if (flags & ECF_NOHISTORY) - { - /* - * The caller says there is no history list. - * Reject any history-manipulation action. - */ - switch (action) - { - case EC_UP: - case EC_DOWN: - action = A_INVALID; - break; - } - } + if (flags & ECF_NOHISTORY) + { + /* + * The caller says there is no history list. + * Reject any history-manipulation action. + */ + switch (action) + { + case EC_UP: + case EC_DOWN: + action = A_INVALID; + break; + } + } #endif #if TAB_COMPLETE_FILENAME - if (flags & ECF_NOCOMPLETE) - { - /* - * The caller says we don't want any filename completion cmds. - * Reject them. - */ - switch (action) - { - case EC_F_COMPLETE: - case EC_B_COMPLETE: - case EC_EXPAND: - action = A_INVALID; - break; - } - } + if (flags & ECF_NOCOMPLETE) + { + /* + * The caller says we don't want any filename completion cmds. + * Reject them. + */ + switch (action) + { + case EC_F_COMPLETE: + case EC_B_COMPLETE: + case EC_EXPAND: + action = A_INVALID; + break; + } + } #endif - if ((flags & ECF_PEEK) || action == A_INVALID) - { - /* - * We're just peeking, or we didn't understand the command. - * Unget all the characters we read in the loop above. - * This does NOT include the original character that was - * passed in as a parameter. - */ - while (nch > 1) - { - ungetcc(usercmd[--nch]); - } - } else - { - if (s != NULL) - ungetsc(s); - } - return action; + if ((flags & ECF_PEEK) || action == A_INVALID) + { + /* + * We're just peeking, or we didn't understand the command. + * Unget all the characters we read in the loop above. + * This does NOT include the original character that was + * passed in as a parameter. + */ + while (nch > 1) + { + ungetcc(usercmd[--nch]); + } + } else + { + if (s != NULL) + ungetsc(s); + } + return action; } - diff --git a/defines.ds b/defines.ds index fb02c89..01d72ec 100644 --- a/defines.ds +++ b/defines.ds @@ -12,64 +12,64 @@ /* * This file has 2 sections: * User preferences. - * Settings always true for MS-DOS systems. + * Settings always true for MS-DOS systems. */ - + /* User preferences. */ /* * SECURE is 1 if you wish to disable a bunch of features in order to * be safe to run by unprivileged users. */ -#define SECURE 0 +#define SECURE 0 /* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE (!SECURE) +#define SHELL_ESCAPE (!SECURE) /* * EXAMINE is 1 if you wish to allow examining files by name from within less. */ -#define EXAMINE (!SECURE) +#define EXAMINE (!SECURE) /* * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME (!SECURE) +#define TAB_COMPLETE_FILENAME (!SECURE) /* * CMD_HISTORY is 1 if you wish to allow keys to cycle through * previous commands at prompts. */ -#define CMD_HISTORY 1 +#define CMD_HISTORY 1 /* - * HILITE_SEARCH is 1 if you wish to have search targets to be + * HILITE_SEARCH is 1 if you wish to have search targets to be * displayed in standout mode. */ -#define HILITE_SEARCH 1 +#define HILITE_SEARCH 1 /* * EDITOR is 1 if you wish to allow editor invocation (the "v" command). * (This is possible only if your system supplies the system() function.) * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR (!SECURE) -#define EDIT_PGM "vi" +#define EDITOR (!SECURE) +#define EDIT_PGM "vi" /* * TAGS is 1 if you wish to support tag files. */ -#define TAGS (!SECURE) +#define TAGS (!SECURE) /* - * USERFILE is 1 if you wish to allow a .less file to specify + * USERFILE is 1 if you wish to allow a .less file to specify * user-defined key bindings. */ -#define USERFILE (!SECURE) +#define USERFILE (!SECURE) /* * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. @@ -77,9 +77,9 @@ * and the "echo" shell command. */ #ifdef __DJGPP__ -#define GLOB (!SECURE) +#define GLOB (!SECURE) #else -#define GLOB 0 +#define GLOB 0 #endif /* @@ -87,134 +87,134 @@ * which allows the user to pipe data into a shell command. */ #ifdef __DJGPP__ -#define PIPEC (!SECURE) +#define PIPEC (!SECURE) #else -#define PIPEC 0 +#define PIPEC 0 #endif /* * LOGFILE is 1 if you wish to allow the -o option (to create log files). */ -#define LOGFILE (!SECURE) +#define LOGFILE (!SECURE) /* * GNU_OPTIONS is 1 if you wish to support the GNU-style command * line options --help and --version. */ -#define GNU_OPTIONS 1 +#define GNU_OPTIONS 1 /* * ONLY_RETURN is 1 if you want RETURN to be the only input which * will continue past an error message. * Otherwise, any key will continue past an error message. */ -#define ONLY_RETURN 0 +#define ONLY_RETURN 0 /* - * LESSKEYFILE is the filename of the default lesskey output file + * LESSKEYFILE is the filename of the default lesskey output file * (in the HOME directory). * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. - * DEF_LESSKEYINFILE is the filename of the default lesskey input + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). * LESSHISTFILE is the filename of the history file * (in the HOME directory). */ -#define LESSKEYFILE "_less" -#define LESSKEYFILE_SYS "c:\\_sysless" -#define DEF_LESSKEYINFILE "_lesskey" -#define LESSHISTFILE "_lesshst" +#define LESSKEYFILE "_less" +#define LESSKEYFILE_SYS "c:\\_sysless" +#define DEF_LESSKEYINFILE "_lesskey" +#define LESSHISTFILE "_lesshst" + - /* Settings always true for MS-DOS systems. */ /* * Define MSDOS_COMPILER if compiling for MS-DOS. */ #ifdef __DJGPP__ -#define MSDOS_COMPILER DJGPPC +#define MSDOS_COMPILER DJGPPC #else #ifdef __BORLANDC__ -#define MSDOS_COMPILER BORLANDC +#define MSDOS_COMPILER BORLANDC #else -#define MSDOS_COMPILER MSOFTC +#define MSDOS_COMPILER MSOFTC #endif #endif /* * Pathname separator character. */ -#define PATHNAME_SEP "\\" +#define PATHNAME_SEP "\\" /* - * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. + * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. */ -#define HAVE_ANSI_PROTOS 1 +#define HAVE_ANSI_PROTOS 1 /* * HAVE_SYS_TYPES_H is 1 if your system has . */ -#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_TYPES_H 1 /* * Define if you have the header file. */ -#define HAVE_SGSTAT_H 0 +#define HAVE_SGSTAT_H 0 /* * HAVE_PERROR is 1 if your system has the perror() call. * (Actually, if it has sys_errlist, sys_nerr and errno.) */ -#define HAVE_PERROR 1 +#define HAVE_PERROR 1 /* * HAVE_TIME is 1 if your system has the time() call. */ -#define HAVE_TIME 1 +#define HAVE_TIME 1 /* * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. */ -#define HAVE_SHELL 0 +#define HAVE_SHELL 0 /* * Default shell metacharacters and meta-escape character. */ -#define DEF_METACHARS "; *?\t\n'\"()<>|&" -#define DEF_METAESCAPE "" +#define DEF_METACHARS "; *?\t\n'\"()<>|&" +#define DEF_METAESCAPE "" -/* +/* * HAVE_DUP is 1 if your system has the dup() call. */ -#define HAVE_DUP 1 +#define HAVE_DUP 1 /* * Sizes of various buffers. */ #if 0 /* old sizes for small memory machines -#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ -#define UNGOT_SIZE 100 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 200 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 512 /* Max size of line in tags file */ -#define TABSTOP_MAX 32 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ +#define UNGOT_SIZE 100 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 200 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 512 /* Max size of line in tags file */ +#define TABSTOP_MAX 32 /* Max number of custom tab stops */ #else /* more reasonable sizes for modern machines */ -#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ -#define UNGOT_SIZE 200 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 2048 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ -#define TABSTOP_MAX 128 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ +#define UNGOT_SIZE 200 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 2048 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ +#define TABSTOP_MAX 128 /* Max number of custom tab stops */ #endif /* Define to `long' if doesn't define. */ #if MSDOS_COMPILER==BORLANDC -#define off_t long +#define off_t long #endif /* Define if you need to in order for stat and other things to work. */ @@ -238,7 +238,7 @@ /* #undef HAVE_REGCMP */ /* #undef HAVE_V8_REGCOMP */ #if MSDOS_COMPILER==DJGPPC -#define HAVE_POSIX_REGCOMP 1 +#define HAVE_POSIX_REGCOMP 1 #else #define NO_REGEX 1 #endif @@ -289,9 +289,9 @@ /* Define if you have the _setjmp function. */ #if MSDOS_COMPILER==MSOFTC || MSDOS_COMPILER==DJGPPC -#define HAVE__SETJMP 0 +#define HAVE__SETJMP 0 #else -#define HAVE__SETJMP 1 +#define HAVE__SETJMP 1 #endif /* Define if you have the memcpy function. */ @@ -299,20 +299,20 @@ /* Define if you have the popen function. */ #if MSDOS_COMPILER==DJGPPC -#define HAVE_POPEN 1 +#define HAVE_POPEN 1 #else -#define HAVE_POPEN 0 +#define HAVE_POPEN 0 #endif /* Define if you have the sigsetmask function. */ -#define HAVE_SIGSETMASK 0 +#define HAVE_SIGSETMASK 0 /* Define if you have the sigprocmask function. */ -#define HAVE_SIGPROCMASK 0 +#define HAVE_SIGPROCMASK 0 /* Define if you have the sigset_t type and sigemptyset macro */ -#define HAVE_SIGSET_T 0 -#define HAVE_SIGEMPTYSET 0 +#define HAVE_SIGSET_T 0 +#define HAVE_SIGEMPTYSET 0 /* Define if you have the stat function. */ #define HAVE_STAT 1 @@ -321,10 +321,10 @@ #define HAVE_STRCHR 1 /* Define if you have the system function. */ -#define HAVE_SYSTEM 1 +#define HAVE_SYSTEM 1 /* Define if you have the snprintf function. */ -#define HAVE_SNPRINTF 0 +#define HAVE_SNPRINTF 0 /* Define if you have the header file. */ #define HAVE_CTYPE_H 1 @@ -357,16 +357,16 @@ #define HAVE_SYS_IOCTL_H 0 /* Define if you have the header file. */ -#define HAVE_SYS_PTEM_H 0 +#define HAVE_SYS_PTEM_H 0 /* Define if you have the header file. */ -#define HAVE_SYS_STREAM_H 0 +#define HAVE_SYS_STREAM_H 0 /* Define if you have the header file. */ -#define HAVE_TERMCAP_H 0 +#define HAVE_TERMCAP_H 0 /* Define if you have the header file. */ -#define HAVE_TERMIO_H 0 +#define HAVE_TERMIO_H 0 /* Define if you have the header file. */ #define HAVE_TERMIOS_H 0 @@ -392,28 +392,28 @@ /* * The names of these things changed in Microsoft C version 7.0. */ -#define videoconfig _videoconfig -#define rccoord _rccoord -#define O_RDONLY _O_RDONLY -#define O_WRONLY _O_WRONLY -#define O_APPEND _O_APPEND -#define O_BINARY _O_BINARY -#define O_TEXT _O_TEXT -#define find_t _find_t -#define stat _stat -#define S_IFMT _S_IFMT -#define S_IFDIR _S_IFDIR -#define S_IFREG _S_IFREG -#define dup _dup -#define open _open -#define lseek _lseek -#define write _write -#define creat _creat -#define fstat _fstat -#define isatty _isatty -#define close _close -#define read _read -#define ungetch _ungetch -#define kbhit _kbhit -#define getch _getch +#define videoconfig _videoconfig +#define rccoord _rccoord +#define O_RDONLY _O_RDONLY +#define O_WRONLY _O_WRONLY +#define O_APPEND _O_APPEND +#define O_BINARY _O_BINARY +#define O_TEXT _O_TEXT +#define find_t _find_t +#define stat _stat +#define S_IFMT _S_IFMT +#define S_IFDIR _S_IFDIR +#define S_IFREG _S_IFREG +#define dup _dup +#define open _open +#define lseek _lseek +#define write _write +#define creat _creat +#define fstat _fstat +#define isatty _isatty +#define close _close +#define read _read +#define ungetch _ungetch +#define kbhit _kbhit +#define getch _getch #endif diff --git a/defines.h.in b/defines.h.in index 389a24f..6569b65 100644 --- a/defines.h.in +++ b/defines.h.in @@ -20,99 +20,99 @@ * be safe to run by unprivileged users. * SECURE_COMPILE is set by the --with-secure configure option. */ -#define SECURE SECURE_COMPILE +#define SECURE SECURE_COMPILE /* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE (!SECURE) +#define SHELL_ESCAPE (!SECURE) /* * EXAMINE is 1 if you wish to allow examining files by name from within less. */ -#define EXAMINE (!SECURE) +#define EXAMINE (!SECURE) /* * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME (!SECURE) +#define TAB_COMPLETE_FILENAME (!SECURE) /* * CMD_HISTORY is 1 if you wish to allow keys to cycle through * previous commands at prompts. */ -#define CMD_HISTORY 1 +#define CMD_HISTORY 1 /* - * HILITE_SEARCH is 1 if you wish to have search targets to be + * HILITE_SEARCH is 1 if you wish to have search targets to be * displayed in standout mode. */ -#define HILITE_SEARCH 1 +#define HILITE_SEARCH 1 /* * EDITOR is 1 if you wish to allow editor invocation (the "v" command). * (This is possible only if your system supplies the system() function.) * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR (!SECURE) +#define EDITOR (!SECURE) /* * TAGS is 1 if you wish to support tag files. */ -#define TAGS (!SECURE) +#define TAGS (!SECURE) /* - * USERFILE is 1 if you wish to allow a .less file to specify + * USERFILE is 1 if you wish to allow a .less file to specify * user-defined key bindings. */ -#define USERFILE (!SECURE) +#define USERFILE (!SECURE) /* * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. * This will generally work if your system provides the "popen" function * and the "echo" shell command. */ -#define GLOB (!SECURE) +#define GLOB (!SECURE) /* * PIPEC is 1 if you wish to have the "|" command * which allows the user to pipe data into a shell command. */ -#define PIPEC (!SECURE) +#define PIPEC (!SECURE) /* * LOGFILE is 1 if you wish to allow the -o option (to create log files). */ -#define LOGFILE (!SECURE) +#define LOGFILE (!SECURE) /* * GNU_OPTIONS is 1 if you wish to support the GNU-style command * line options --help and --version. */ -#define GNU_OPTIONS 1 +#define GNU_OPTIONS 1 /* * ONLY_RETURN is 1 if you want RETURN to be the only input which * will continue past an error message. * Otherwise, any key will continue past an error message. */ -#define ONLY_RETURN 0 +#define ONLY_RETURN 0 /* - * LESSKEYFILE is the filename of the default lesskey output file + * LESSKEYFILE is the filename of the default lesskey output file * (in the HOME directory). * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. - * DEF_LESSKEYINFILE is the filename of the default lesskey input + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). * LESSHISTFILE is the filename of the history file * (in the HOME directory). */ -#define LESSKEYFILE ".less" -#define LESSKEYFILE_SYS SYSDIR "/sysless" -#define DEF_LESSKEYINFILE ".lesskey" -#define LESSHISTFILE ".lesshst" +#define LESSKEYFILE ".less" +#define LESSKEYFILE_SYS SYSDIR "/sysless" +#define DEF_LESSKEYINFILE ".lesskey" +#define LESSHISTFILE ".lesshst" /* Settings always true on Unix. */ @@ -120,12 +120,12 @@ /* * Define MSDOS_COMPILER if compiling under Microsoft C. */ -#define MSDOS_COMPILER 0 +#define MSDOS_COMPILER 0 /* * Pathname separator character. */ -#define PATHNAME_SEP "/" +#define PATHNAME_SEP "/" /* * The value returned from tgetent on success. @@ -134,14 +134,14 @@ #define TGETENT_OK 1 /* - * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. + * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. */ -#define HAVE_ANSI_PROTOS 1 +#define HAVE_ANSI_PROTOS 1 /* * HAVE_SYS_TYPES_H is 1 if your system has . */ -#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_TYPES_H 1 /* * Define if you have the header file. @@ -152,28 +152,28 @@ * HAVE_PERROR is 1 if your system has the perror() call. * (Actually, if it has sys_errlist, sys_nerr and errno.) */ -#define HAVE_PERROR 1 +#define HAVE_PERROR 1 /* * HAVE_TIME is 1 if your system has the time() call. */ -#define HAVE_TIME 1 +#define HAVE_TIME 1 /* * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. */ -#define HAVE_SHELL 1 +#define HAVE_SHELL 1 /* * Default shell metacharacters and meta-escape character. */ -#define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\$%=~{}," -#define DEF_METAESCAPE "\\" +#define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\$%=~{}," +#define DEF_METAESCAPE "\\" -/* +/* * HAVE_DUP is 1 if your system has the dup() call. */ -#define HAVE_DUP 1 +#define HAVE_DUP 1 /* Define to 1 if you have the memcpy() function. */ #define HAVE_MEMCPY 1 @@ -188,25 +188,25 @@ * Sizes of various buffers. */ #if 0 /* old sizes for small memory machines */ -#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ -#define UNGOT_SIZE 100 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 200 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 512 /* Max size of line in tags file */ -#define TABSTOP_MAX 32 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ +#define UNGOT_SIZE 100 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 200 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 512 /* Max size of line in tags file */ +#define TABSTOP_MAX 32 /* Max number of custom tab stops */ #else /* more reasonable sizes for modern machines */ -#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ -#define UNGOT_SIZE 200 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 2048 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ -#define TABSTOP_MAX 128 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ +#define UNGOT_SIZE 200 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 2048 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ +#define TABSTOP_MAX 128 /* Max number of custom tab stops */ #endif /* Settings automatically determined by configure. */ diff --git a/defines.o2 b/defines.o2 index 267ef5e..75d8c14 100644 --- a/defines.o2 +++ b/defines.o2 @@ -12,189 +12,189 @@ /* * This file has 2 sections: * User preferences. - * Settings always true for the emx compiler for OS/2 systems. + * Settings always true for the emx compiler for OS/2 systems. */ - + /* User preferences. */ /* * SECURE is 1 if you wish to disable a bunch of features in order to * be safe to run by unprivileged users. */ -#define SECURE 0 +#define SECURE 0 /* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE (!SECURE) +#define SHELL_ESCAPE (!SECURE) /* * EXAMINE is 1 if you wish to allow examining files by name from within less. */ -#define EXAMINE (!SECURE) +#define EXAMINE (!SECURE) /* * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME (!SECURE) +#define TAB_COMPLETE_FILENAME (!SECURE) /* * CMD_HISTORY is 1 if you wish to allow keys to cycle through * previous commands at prompts. */ -#define CMD_HISTORY 1 +#define CMD_HISTORY 1 /* - * HILITE_SEARCH is 1 if you wish to have search targets to be + * HILITE_SEARCH is 1 if you wish to have search targets to be * displayed in standout mode. */ -#define HILITE_SEARCH 1 +#define HILITE_SEARCH 1 /* * EDITOR is 1 if you wish to allow editor invocation (the "v" command). * (This is possible only if your system supplies the system() function.) * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR (!SECURE) -#define EDIT_PGM "vi" +#define EDITOR (!SECURE) +#define EDIT_PGM "vi" /* * TAGS is 1 if you wish to support tag files. */ -#define TAGS (!SECURE) +#define TAGS (!SECURE) /* - * USERFILE is 1 if you wish to allow a .less file to specify + * USERFILE is 1 if you wish to allow a .less file to specify * user-defined key bindings. */ -#define USERFILE (!SECURE) +#define USERFILE (!SECURE) /* * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. * This will generally work if your system provides the "popen" function * and the "echo" shell command. */ -#define GLOB (!SECURE) +#define GLOB (!SECURE) /* * PIPEC is 1 if you wish to have the "|" command * which allows the user to pipe data into a shell command. */ -#define PIPEC (!SECURE) +#define PIPEC (!SECURE) /* * LOGFILE is 1 if you wish to allow the -o option (to create log files). */ -#define LOGFILE (!SECURE) +#define LOGFILE (!SECURE) /* * GNU_OPTIONS is 1 if you wish to support the GNU-style command * line options --help and --version. */ -#define GNU_OPTIONS 1 +#define GNU_OPTIONS 1 /* * ONLY_RETURN is 1 if you want RETURN to be the only input which * will continue past an error message. * Otherwise, any key will continue past an error message. */ -#define ONLY_RETURN 0 +#define ONLY_RETURN 0 /* - * LESSKEYFILE is the filename of the default lesskey output file + * LESSKEYFILE is the filename of the default lesskey output file * (in the HOME directory). * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. - * DEF_LESSKEYINFILE is the filename of the default lesskey input + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). * LESSHISTFILE is the filename of the history file * (in the HOME directory). */ -#define LESSKEYFILE "less.ini" -#define LESSKEYFILE_SYS "C:\\sysless.ini" -#define DEF_LESSKEYINFILE "lesskey.ini" -#define LESSHISTFILE "lesshst.ini" +#define LESSKEYFILE "less.ini" +#define LESSKEYFILE_SYS "C:\\sysless.ini" +#define DEF_LESSKEYINFILE "lesskey.ini" +#define LESSHISTFILE "lesshst.ini" + - /* Settings always true for the emx compiler for OS/2 systems. */ #define OS2 1 /* * Pathname separator character. */ -#define PATHNAME_SEP "\\" +#define PATHNAME_SEP "\\" /* - * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. + * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. */ -#define HAVE_ANSI_PROTOS 1 +#define HAVE_ANSI_PROTOS 1 /* * HAVE_SYS_TYPES_H is 1 if your system has . */ -#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_TYPES_H 1 /* * Define if you have the header file. */ -#define HAVE_SGSTAT_H 0 +#define HAVE_SGSTAT_H 0 /* * HAVE_PERROR is 1 if your system has the perror() call. * (Actually, if it has sys_errlist, sys_nerr and errno.) */ -#define HAVE_PERROR 1 +#define HAVE_PERROR 1 /* * HAVE_TIME is 1 if your system has the time() call. */ -#define HAVE_TIME 1 +#define HAVE_TIME 1 /* * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. */ -#define HAVE_SHELL 0 +#define HAVE_SHELL 0 /* * Default shell metacharacters and meta-escape character. */ -#define DEF_METACHARS "; *?\t\n'\"()<>|&" -#define DEF_METAESCAPE "" +#define DEF_METACHARS "; *?\t\n'\"()<>|&" +#define DEF_METAESCAPE "" -/* +/* * HAVE_DUP is 1 if your system has the dup() call. */ -#define HAVE_DUP 1 +#define HAVE_DUP 1 /* * Sizes of various buffers. */ #if 0 /* old sizes for small memory machines -#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ -#define UNGOT_SIZE 100 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 200 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 512 /* Max size of line in tags file */ -#define TABSTOP_MAX 32 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ +#define UNGOT_SIZE 100 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 200 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 512 /* Max size of line in tags file */ +#define TABSTOP_MAX 32 /* Max number of custom tab stops */ #else /* more reasonable sizes for modern machines */ -#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ -#define UNGOT_SIZE 200 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 2048 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ -#define TABSTOP_MAX 128 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ +#define UNGOT_SIZE 200 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 2048 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ +#define TABSTOP_MAX 128 /* Max number of custom tab stops */ #endif /* Define to `long' if doesn't define. */ -/* #define off_t long */ +/* #define off_t long */ /* Define if you need to in order for stat and other things to work. */ /* #undef _POSIX_SOURCE */ @@ -235,7 +235,7 @@ #define HAVE_FILENO 1 /* Define HAVE_ERRNO if you have the errno variable */ -/* Define MUST_DEFINE_ERRNO if you have errno but it is not define +/* Define MUST_DEFINE_ERRNO if you have errno but it is not define * in errno.h */ #define HAVE_ERRNO 1 /* #undef MUST_DEFINE_ERRNO */ @@ -259,7 +259,7 @@ #define HAVE_UPPER_LOWER 1 /* Define if you have the _setjmp function. */ -#define HAVE__SETJMP 0 +#define HAVE__SETJMP 0 /* Define if you have the memcpy function. */ #define HAVE_MEMCPY 1 @@ -268,14 +268,14 @@ #define HAVE_POPEN 1 /* Define if you have the sigsetmask function. */ -#define HAVE_SIGSETMASK 0 +#define HAVE_SIGSETMASK 0 /* Define if you have the sigprocmask function. */ -#define HAVE_SIGPROCMASK 1 +#define HAVE_SIGPROCMASK 1 /* Define if you have the sigset_t type and sigemptyset macro */ -#define HAVE_SIGSET_T 1 -#define HAVE_SIGEMPTYSET 1 +#define HAVE_SIGSET_T 1 +#define HAVE_SIGEMPTYSET 1 /* Define if you have the stat function. */ #define HAVE_STAT 1 @@ -284,13 +284,13 @@ #define HAVE_STRCHR 1 /* Define if you have the strstr function. */ -#define HAVE_STRSTR 1 +#define HAVE_STRSTR 1 /* Define if you have the system function. */ -#define HAVE_SYSTEM 1 +#define HAVE_SYSTEM 1 /* Define if you have the snprintf function. */ -#define HAVE_SNPRINTF 0 +#define HAVE_SNPRINTF 0 /* Define if you have the header file. */ #define HAVE_CTYPE_H 1 @@ -320,16 +320,16 @@ #define HAVE_SYS_IOCTL_H 1 /* Define if you have the header file. */ -#define HAVE_SYS_PTEM_H 0 +#define HAVE_SYS_PTEM_H 0 /* Define if you have the header file. */ -#define HAVE_SYS_STREAM_H 0 +#define HAVE_SYS_STREAM_H 0 /* Define if you have the header file. */ #define HAVE_TERMCAP_H 1 /* Define if you have the header file. */ -#define HAVE_TERMIO_H 1 +#define HAVE_TERMIO_H 1 /* Define if you have the header file. */ #define HAVE_TERMIOS_H 1 diff --git a/defines.o9 b/defines.o9 index 22740ef..39238bf 100644 --- a/defines.o9 +++ b/defines.o9 @@ -12,127 +12,127 @@ /* * This file has 2 sections: * User preferences. - * Settings always true for OS-9 systems. + * Settings always true for OS-9 systems. */ - + /* User preferences. */ /* * SECURE is 1 if you wish to disable a bunch of features in order to * be safe to run by unprivileged users. */ -#define SECURE 0 +#define SECURE 0 /* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE (!SECURE) +#define SHELL_ESCAPE (!SECURE) /* * EXAMINE is 1 if you wish to allow examining files by name from within less. */ -#define EXAMINE (!SECURE) +#define EXAMINE (!SECURE) /* * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME 1 +#define TAB_COMPLETE_FILENAME 1 /* * CMD_HISTORY is 1 if you wish to allow keys to cycle through * previous commands at prompts. */ -#define CMD_HISTORY 1 +#define CMD_HISTORY 1 /* - * HILITE_SEARCH is 1 if you wish to have search targets to be + * HILITE_SEARCH is 1 if you wish to have search targets to be * displayed in standout mode. */ -#define HILITE_SEARCH 1 +#define HILITE_SEARCH 1 /* * EDITOR is 1 if you wish to allow editor invocation (the "v" command). * (This is possible only if your system supplies the system() function.) * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR (!SECURE) -#define EDIT_PGM "umacs" +#define EDITOR (!SECURE) +#define EDIT_PGM "umacs" /* * TAGS is 1 if you wish to support tag files. */ -#define TAGS (!SECURE) +#define TAGS (!SECURE) /* - * USERFILE is 1 if you wish to allow a .less file to specify + * USERFILE is 1 if you wish to allow a .less file to specify * user-defined key bindings. */ -#define USERFILE (!SECURE) +#define USERFILE (!SECURE) /* * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. * This will generally work if your system provides the "popen" function * and the "echo" shell command. */ -#define GLOB (!SECURE) +#define GLOB (!SECURE) /* * PIPEC is 1 if you wish to have the "|" command * which allows the user to pipe data into a shell command. */ -#define PIPEC (!SECURE) +#define PIPEC (!SECURE) /* * LOGFILE is 1 if you wish to allow the -o option (to create log files). */ -#define LOGFILE (!SECURE) +#define LOGFILE (!SECURE) /* * GNU_OPTIONS is 1 if you wish to support the GNU-style command * line options --help and --version. */ -#define GNU_OPTIONS 1 +#define GNU_OPTIONS 1 /* * ONLY_RETURN is 1 if you want RETURN to be the only input which * will continue past an error message. * Otherwise, any key will continue past an error message. */ -#define ONLY_RETURN 0 +#define ONLY_RETURN 0 /* - * LESSKEYFILE is the filename of the default lesskey output file + * LESSKEYFILE is the filename of the default lesskey output file * (in the HOME directory). * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. - * DEF_LESSKEYINFILE is the filename of the default lesskey input + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). * LESSHISTFILE is the filename of the history file * (in the HOME directory). */ -#define LESSKEYFILE ".less" -#define LESSKEYFILE_SYS "/.sysless" -#define DEF_LESSKEYINFILE ".lesskey" -#define LESSHISTFILE ".lesshst" +#define LESSKEYFILE ".less" +#define LESSKEYFILE_SYS "/.sysless" +#define DEF_LESSKEYINFILE ".lesskey" +#define LESSHISTFILE ".lesshst" + - /* Settings always true for OS-9. */ /* This is not needed; it is defined by the compiler. */ /* #define _OSK 1 */ -#define OS2 0 -#define MSDOS_COMPILER 0 +#define OS2 0 +#define MSDOS_COMPILER 0 /* * Pathname separator character. */ -#define PATHNAME_SEP "/" +#define PATHNAME_SEP "/" /* - * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. + * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. */ -#define HAVE_ANSI_PROTOS 1 +#define HAVE_ANSI_PROTOS 1 /* * HAVE_SYS_TYPES_H is 1 if your system has . @@ -142,27 +142,27 @@ /* * Define if you have the header file. */ -#define HAVE_SGSTAT_H 1 +#define HAVE_SGSTAT_H 1 /* * HAVE_PERROR is 1 if your system has the perror() call. * (Actually, if it has sys_errlist, sys_nerr and errno.) */ #if _OSK_MWC32 -#define HAVE_PERROR 0 +#define HAVE_PERROR 0 #else -#define HAVE_PERROR 1 +#define HAVE_PERROR 1 #endif /* * HAVE_TIME is 1 if your system has the time() call. */ -#define HAVE_TIME 1 +#define HAVE_TIME 1 /* * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. */ -#define HAVE_SHELL 0 +#define HAVE_SHELL 0 /* * Default shell metacharacters and meta-escape character. @@ -170,34 +170,34 @@ #define DEF_METACHARS "; \t\n'\"()<>|&^`#\\" #define DEF_METAESCAPE "\\" -/* +/* * HAVE_DUP is 1 if your system has the dup() call. */ -#define HAVE_DUP 0 +#define HAVE_DUP 0 /* * Sizes of various buffers. */ #if 0 /* old sizes for small memory machines -#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ -#define UNGOT_SIZE 100 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 200 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 512 /* Max size of line in tags file */ -#define TABSTOP_MAX 32 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ +#define UNGOT_SIZE 100 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 200 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 512 /* Max size of line in tags file */ +#define TABSTOP_MAX 32 /* Max number of custom tab stops */ #else /* more reasonable sizes for modern machines */ -#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ -#define UNGOT_SIZE 200 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 2048 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ -#define TABSTOP_MAX 128 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ +#define UNGOT_SIZE 200 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 2048 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ +#define TABSTOP_MAX 128 /* Max number of custom tab stops */ #endif /* Define to `long' if doesn't define. */ @@ -246,7 +246,7 @@ #define HAVE_FILENO 1 /* Define HAVE_ERRNO if you have the errno variable */ -/* Define MUST_DEFINE_ERRNO if you have errno but it is not define +/* Define MUST_DEFINE_ERRNO if you have errno but it is not define * in errno.h */ #define HAVE_ERRNO 1 #define MUST_DEFINE_ERRNO 0 @@ -282,11 +282,11 @@ #define HAVE_SIGSETMASK 0 /* Define if you have the sigprocmask function. */ -#define HAVE_SIGPROCMASK 0 +#define HAVE_SIGPROCMASK 0 /* Define if you have the sigset_t type and sigemptyset macro */ -#define HAVE_SIGSET_T 0 -#define HAVE_SIGEMPTYSET 0 +#define HAVE_SIGSET_T 0 +#define HAVE_SIGEMPTYSET 0 /* Define if you have the stat function. */ #define HAVE_STAT 0 @@ -298,7 +298,7 @@ #define HAVE_SYSTEM 1 /* Define if you have the snprintf function. */ -#define HAVE_SNPRINTF 0 +#define HAVE_SNPRINTF 0 /* Define if you have the header file. */ #define HAVE_CTYPE_H 1 diff --git a/defines.wn b/defines.wn index b8256e1..23275f4 100644 --- a/defines.wn +++ b/defines.wn @@ -12,190 +12,190 @@ /* * This file has 2 sections: * User preferences. - * Settings always true for Windows systems. + * Settings always true for Windows systems. */ - + /* User preferences. */ /* * SECURE is 1 if you wish to disable a bunch of features in order to * be safe to run by unprivileged users. */ -#define SECURE 0 +#define SECURE 0 /* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE (!SECURE) +#define SHELL_ESCAPE (!SECURE) /* * EXAMINE is 1 if you wish to allow examining files by name from within less. */ -#define EXAMINE (!SECURE) +#define EXAMINE (!SECURE) /* * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME (!SECURE) +#define TAB_COMPLETE_FILENAME (!SECURE) /* * CMD_HISTORY is 1 if you wish to allow keys to cycle through * previous commands at prompts. */ -#define CMD_HISTORY 1 +#define CMD_HISTORY 1 /* - * HILITE_SEARCH is 1 if you wish to have search targets to be + * HILITE_SEARCH is 1 if you wish to have search targets to be * displayed in standout mode. */ -#define HILITE_SEARCH 1 +#define HILITE_SEARCH 1 /* * EDITOR is 1 if you wish to allow editor invocation (the "v" command). * (This is possible only if your system supplies the system() function.) * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR (!SECURE) -#define EDIT_PGM "edit" +#define EDITOR (!SECURE) +#define EDIT_PGM "edit" /* * TAGS is 1 if you wish to support tag files. */ -#define TAGS (!SECURE) +#define TAGS (!SECURE) /* - * USERFILE is 1 if you wish to allow a .less file to specify + * USERFILE is 1 if you wish to allow a .less file to specify * user-defined key bindings. */ -#define USERFILE (!SECURE) +#define USERFILE (!SECURE) /* * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. * This will generally work if your system provides the "popen" function * and the "echo" shell command. */ -#define GLOB 0 +#define GLOB 0 /* * PIPEC is 1 if you wish to have the "|" command * which allows the user to pipe data into a shell command. */ -#define PIPEC 1 +#define PIPEC 1 /* * LOGFILE is 1 if you wish to allow the -o option (to create log files). */ -#define LOGFILE (!SECURE) +#define LOGFILE (!SECURE) /* * GNU_OPTIONS is 1 if you wish to support the GNU-style command * line options --help and --version. */ -#define GNU_OPTIONS 1 +#define GNU_OPTIONS 1 /* * ONLY_RETURN is 1 if you want RETURN to be the only input which * will continue past an error message. * Otherwise, any key will continue past an error message. */ -#define ONLY_RETURN 0 +#define ONLY_RETURN 0 /* - * LESSKEYFILE is the filename of the default lesskey output file + * LESSKEYFILE is the filename of the default lesskey output file * (in the HOME directory). * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. - * DEF_LESSKEYINFILE is the filename of the default lesskey input + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). * LESSHISTFILE is the filename of the history file * (in the HOME directory). */ -#define LESSKEYFILE "_less" -#define LESSKEYFILE_SYS "c:\\_sysless" -#define DEF_LESSKEYINFILE "_lesskey" -#define LESSHISTFILE "_lesshst" +#define LESSKEYFILE "_less" +#define LESSKEYFILE_SYS "c:\\_sysless" +#define DEF_LESSKEYINFILE "_lesskey" +#define LESSHISTFILE "_lesshst" + - /* Settings always true for Windows systems. */ -#define MSDOS_COMPILER WIN32C +#define MSDOS_COMPILER WIN32C /* * Pathname separator character. */ -#define PATHNAME_SEP "\\" +#define PATHNAME_SEP "\\" /* - * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. + * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. */ -#define HAVE_ANSI_PROTOS 1 +#define HAVE_ANSI_PROTOS 1 /* * HAVE_SYS_TYPES_H is 1 if your system has . */ -#define HAVE_SYS_TYPES_H 1 +#define HAVE_SYS_TYPES_H 1 /* * Define if you have the header file. */ -#define HAVE_SGSTAT_H 0 +#define HAVE_SGSTAT_H 0 /* * HAVE_PERROR is 1 if your system has the perror() call. * (Actually, if it has sys_errlist, sys_nerr and errno.) */ -#define HAVE_PERROR 1 +#define HAVE_PERROR 1 /* * HAVE_TIME is 1 if your system has the time() call. */ -#define HAVE_TIME 1 +#define HAVE_TIME 1 /* * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. */ -#define HAVE_SHELL 0 +#define HAVE_SHELL 0 /* * Default shell metacharacters and meta-escape character. */ -#define DEF_METACHARS "; *?\t\n'\"()<>|&" -#define DEF_METAESCAPE "" +#define DEF_METACHARS "; *?\t\n'\"()<>|&" +#define DEF_METAESCAPE "" -/* +/* * HAVE_DUP is 1 if your system has the dup() call. */ -#define HAVE_DUP 1 +#define HAVE_DUP 1 /* * Sizes of various buffers. */ #if 0 /* old sizes for small memory machines */ -#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ -#define UNGOT_SIZE 100 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 200 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 512 /* Max size of line in tags file */ -#define TABSTOP_MAX 32 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ +#define UNGOT_SIZE 100 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 200 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 512 /* Max size of line in tags file */ +#define TABSTOP_MAX 32 /* Max number of custom tab stops */ #else /* more reasonable sizes for modern machines */ -#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ -#define UNGOT_SIZE 200 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 2048 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ -#define TABSTOP_MAX 128 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ +#define UNGOT_SIZE 200 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 2048 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ +#define TABSTOP_MAX 128 /* Max number of custom tab stops */ #endif /* Define to `long' if doesn't define. */ -/* #define off_t long */ +/* #define off_t long */ /* Define if you need to in order for stat and other things to work. */ /* #undef _POSIX_SOURCE */ @@ -218,18 +218,18 @@ /* #undef HAVE_REGCMP */ #ifdef MINGW #ifdef USE_POSIX_REGCOMP - #define HAVE_POSIX_REGCOMP 1 + #define HAVE_POSIX_REGCOMP 1 #else - #ifdef USE_GNU_REGEX - #define HAVE_GNU_REGEX 1 + #ifdef USE_GNU_REGEX + #define HAVE_GNU_REGEX 1 #else #ifdef USE_REGEXP_C - #define HAVE_V8_REGCOMP 1 - #define HAVE_REGEXEC2 1 + #define HAVE_V8_REGCOMP 1 + #define HAVE_REGEXEC2 1 #else #define NO_REGEX 1 - #endif - #endif + #endif + #endif #endif #else #define HAVE_V8_REGCOMP 1 @@ -253,7 +253,7 @@ #define HAVE_FILENO 1 /* Define HAVE_ERRNO if you have the errno variable */ -/* Define MUST_DEFINE_ERRNO if you have errno but it is not define +/* Define MUST_DEFINE_ERRNO if you have errno but it is not define * in errno.h */ #define HAVE_ERRNO 1 #ifdef MINGW @@ -281,7 +281,7 @@ #define HAVE_UPPER_LOWER 1 /* Define if you have the _setjmp function. */ -#define HAVE__SETJMP 1 +#define HAVE__SETJMP 1 /* Define if you have the memcpy function. */ #define HAVE_MEMCPY 1 @@ -290,14 +290,14 @@ #define HAVE_POPEN 1 /* Define if you have the sigsetmask function. */ -#define HAVE_SIGSETMASK 0 +#define HAVE_SIGSETMASK 0 /* Define if you have the sigprocmask function. */ -#define HAVE_SIGPROCMASK 0 +#define HAVE_SIGPROCMASK 0 /* Define if you have the sigset_t type and sigemptyset macro */ -#define HAVE_SIGSET_T 0 -#define HAVE_SIGEMPTYSET 0 +#define HAVE_SIGSET_T 0 +#define HAVE_SIGEMPTYSET 0 /* Define if you have the stat function. */ #define HAVE_STAT 1 @@ -306,10 +306,10 @@ #define HAVE_STRCHR 1 /* Define if you have the system function. */ -#define HAVE_SYSTEM 1 +#define HAVE_SYSTEM 1 /* Define if you have the snprintf function. */ -#define HAVE_SNPRINTF 1 +#define HAVE_SNPRINTF 1 /* Define if you have the header file. */ #define HAVE_CTYPE_H 1 @@ -342,16 +342,16 @@ #define HAVE_SYS_IOCTL_H 0 /* Define if you have the header file. */ -#define HAVE_SYS_PTEM_H 0 +#define HAVE_SYS_PTEM_H 0 /* Define if you have the header file. */ -#define HAVE_SYS_STREAM_H 0 +#define HAVE_SYS_STREAM_H 0 /* Define if you have the header file. */ -#define HAVE_TERMCAP_H 0 +#define HAVE_TERMCAP_H 0 /* Define if you have the header file. */ -#define HAVE_TERMIO_H 0 +#define HAVE_TERMIO_H 0 /* Define if you have the header file. */ #define HAVE_TERMIOS_H 0 @@ -377,9 +377,9 @@ #endif #endif -#define popen _popen -#if !defined(_MSC_VER) || (_MSC_VER < 1900) -#define snprintf _snprintf +#define popen _popen +#if !defined(_MSC_VER) || (_MSC_VER < 1900) +#define snprintf _snprintf #endif #ifndef MINGW diff --git a/edit.c b/edit.c index 12631db..6ae542f 100644 --- a/edit.c +++ b/edit.c @@ -53,166 +53,166 @@ public ino_t curr_ino; * words, returning each one as a standard null-terminated string. * back_textlist does the same, but runs thru the list backwards. */ - public void + public void init_textlist(tlist, str) - struct textlist *tlist; - char *str; + struct textlist *tlist; + char *str; { - char *s; + char *s; #if SPACES_IN_FILENAMES - int meta_quoted = 0; - int delim_quoted = 0; - char *esc = get_meta_escape(); - int esclen = (int) strlen(esc); + int meta_quoted = 0; + int delim_quoted = 0; + char *esc = get_meta_escape(); + int esclen = (int) strlen(esc); #endif - - tlist->string = skipsp(str); - tlist->endstring = tlist->string + strlen(tlist->string); - for (s = str; s < tlist->endstring; s++) - { + + tlist->string = skipsp(str); + tlist->endstring = tlist->string + strlen(tlist->string); + for (s = str; s < tlist->endstring; s++) + { #if SPACES_IN_FILENAMES - if (meta_quoted) - { - meta_quoted = 0; - } else if (esclen > 0 && s + esclen < tlist->endstring && - strncmp(s, esc, esclen) == 0) - { - meta_quoted = 1; - s += esclen - 1; - } else if (delim_quoted) - { - if (*s == closequote) - delim_quoted = 0; - } else /* (!delim_quoted) */ - { - if (*s == openquote) - delim_quoted = 1; - else if (*s == ' ') - *s = '\0'; - } + if (meta_quoted) + { + meta_quoted = 0; + } else if (esclen > 0 && s + esclen < tlist->endstring && + strncmp(s, esc, esclen) == 0) + { + meta_quoted = 1; + s += esclen - 1; + } else if (delim_quoted) + { + if (*s == closequote) + delim_quoted = 0; + } else /* (!delim_quoted) */ + { + if (*s == openquote) + delim_quoted = 1; + else if (*s == ' ') + *s = '\0'; + } #else - if (*s == ' ') - *s = '\0'; + if (*s == ' ') + *s = '\0'; #endif - } + } } - public char * + public char * forw_textlist(tlist, prev) - struct textlist *tlist; - char *prev; + struct textlist *tlist; + char *prev; { - char *s; - - /* - * prev == NULL means return the first word in the list. - * Otherwise, return the word after "prev". - */ - if (prev == NULL) - s = tlist->string; - else - s = prev + strlen(prev); - if (s >= tlist->endstring) - return (NULL); - while (*s == '\0') - s++; - if (s >= tlist->endstring) - return (NULL); - return (s); + char *s; + + /* + * prev == NULL means return the first word in the list. + * Otherwise, return the word after "prev". + */ + if (prev == NULL) + s = tlist->string; + else + s = prev + strlen(prev); + if (s >= tlist->endstring) + return (NULL); + while (*s == '\0') + s++; + if (s >= tlist->endstring) + return (NULL); + return (s); } - public char * + public char * back_textlist(tlist, prev) - struct textlist *tlist; - char *prev; + struct textlist *tlist; + char *prev; { - char *s; - - /* - * prev == NULL means return the last word in the list. - * Otherwise, return the word before "prev". - */ - if (prev == NULL) - s = tlist->endstring; - else if (prev <= tlist->string) - return (NULL); - else - s = prev - 1; - while (*s == '\0') - s--; - if (s <= tlist->string) - return (NULL); - while (s[-1] != '\0' && s > tlist->string) - s--; - return (s); + char *s; + + /* + * prev == NULL means return the last word in the list. + * Otherwise, return the word before "prev". + */ + if (prev == NULL) + s = tlist->endstring; + else if (prev <= tlist->string) + return (NULL); + else + s = prev - 1; + while (*s == '\0') + s--; + if (s <= tlist->string) + return (NULL); + while (s[-1] != '\0' && s > tlist->string) + s--; + return (s); } /* * Close a pipe opened via popen. */ - static void + static void close_pipe(FILE *pipefd) { - if (pipefd == NULL) - return; + if (pipefd == NULL) + return; #if OS2 - /* - * The pclose function of OS/2 emx sometimes fails. - * Send SIGINT to the piped process before closing it. - */ - kill(pipefd->_pid, SIGINT); + /* + * The pclose function of OS/2 emx sometimes fails. + * Send SIGINT to the piped process before closing it. + */ + kill(pipefd->_pid, SIGINT); #endif - pclose(pipefd); + pclose(pipefd); } /* * Close the current input file. */ - static void + static void close_file(VOID_PARAM) { - struct scrpos scrpos; - int chflags; - FILE *altpipe; - char *altfilename; - - if (curr_ifile == NULL_IFILE) - return; - - /* - * Save the current position so that we can return to - * the same position if we edit this file again. - */ - get_scrpos(&scrpos, TOP); - if (scrpos.pos != NULL_POSITION) - { - store_pos(curr_ifile, &scrpos); - lastmark(); - } - /* - * Close the file descriptor, unless it is a pipe. - */ - chflags = ch_getflags(); - ch_close(); - /* - * If we opened a file using an alternate name, - * do special stuff to close it. - */ - altfilename = get_altfilename(curr_ifile); - if (altfilename != NULL) - { - altpipe = get_altpipe(curr_ifile); - if (altpipe != NULL && !(chflags & CH_KEEPOPEN)) - { - close_pipe(altpipe); - set_altpipe(curr_ifile, NULL); - } - close_altfile(altfilename, get_filename(curr_ifile)); - set_altfilename(curr_ifile, NULL); - } - curr_ifile = NULL_IFILE; + struct scrpos scrpos; + int chflags; + FILE *altpipe; + char *altfilename; + + if (curr_ifile == NULL_IFILE) + return; + + /* + * Save the current position so that we can return to + * the same position if we edit this file again. + */ + get_scrpos(&scrpos, TOP); + if (scrpos.pos != NULL_POSITION) + { + store_pos(curr_ifile, &scrpos); + lastmark(); + } + /* + * Close the file descriptor, unless it is a pipe. + */ + chflags = ch_getflags(); + ch_close(); + /* + * If we opened a file using an alternate name, + * do special stuff to close it. + */ + altfilename = get_altfilename(curr_ifile); + if (altfilename != NULL) + { + altpipe = get_altpipe(curr_ifile); + if (altpipe != NULL && !(chflags & CH_KEEPOPEN)) + { + close_pipe(altpipe); + set_altpipe(curr_ifile, NULL); + } + close_altfile(altfilename, get_filename(curr_ifile)); + set_altfilename(curr_ifile, NULL); + } + curr_ifile = NULL_IFILE; #if HAVE_STAT_INO - curr_ino = curr_dev = 0; + curr_ino = curr_dev = 0; #endif } @@ -221,276 +221,276 @@ close_file(VOID_PARAM) * Filename == "-" means standard input. * Filename == NULL means just close the current file. */ - public int + public int edit(filename) - char *filename; + char *filename; { - if (filename == NULL) - return (edit_ifile(NULL_IFILE)); - return (edit_ifile(get_ifile(filename, curr_ifile))); + if (filename == NULL) + return (edit_ifile(NULL_IFILE)); + return (edit_ifile(get_ifile(filename, curr_ifile))); } - + /* * Edit a new file (given its IFILE). * ifile == NULL means just close the current file. */ - public int + public int edit_ifile(ifile) - IFILE ifile; + IFILE ifile; { - int f; - int answer; - int chflags; - char *filename; - char *open_filename; - char *alt_filename; - void *altpipe; - IFILE was_curr_ifile; - PARG parg; - - if (ifile == curr_ifile) - { - /* - * Already have the correct file open. - */ - return (0); - } - - /* - * We must close the currently open file now. - * This is necessary to make the open_altfile/close_altfile pairs - * nest properly (or rather to avoid nesting at all). - * {{ Some stupid implementations of popen() mess up if you do: - * fA = popen("A"); fB = popen("B"); pclose(fA); pclose(fB); }} - */ + int f; + int answer; + int chflags; + char *filename; + char *open_filename; + char *alt_filename; + void *altpipe; + IFILE was_curr_ifile; + PARG parg; + + if (ifile == curr_ifile) + { + /* + * Already have the correct file open. + */ + return (0); + } + + /* + * We must close the currently open file now. + * This is necessary to make the open_altfile/close_altfile pairs + * nest properly (or rather to avoid nesting at all). + * {{ Some stupid implementations of popen() mess up if you do: + * fA = popen("A"); fB = popen("B"); pclose(fA); pclose(fB); }} + */ #if LOGFILE - end_logfile(); + end_logfile(); #endif - was_curr_ifile = save_curr_ifile(); - if (curr_ifile != NULL_IFILE) - { - chflags = ch_getflags(); - close_file(); - if ((chflags & CH_HELPFILE) && held_ifile(was_curr_ifile) <= 1) - { - /* - * Don't keep the help file in the ifile list. - */ - del_ifile(was_curr_ifile); - was_curr_ifile = old_ifile; - } - } - - if (ifile == NULL_IFILE) - { - /* - * No new file to open. - * (Don't set old_ifile, because if you call edit_ifile(NULL), - * you're supposed to have saved curr_ifile yourself, - * and you'll restore it if necessary.) - */ - unsave_ifile(was_curr_ifile); - return (0); - } - - filename = save(get_filename(ifile)); - - /* - * See if LESSOPEN specifies an "alternate" file to open. - */ - altpipe = get_altpipe(ifile); - if (altpipe != NULL) - { - /* - * File is already open. - * chflags and f are not used by ch_init if ifile has - * filestate which should be the case if we're here. - * Set them here to avoid uninitialized variable warnings. - */ - chflags = 0; - f = -1; - alt_filename = get_altfilename(ifile); - open_filename = (alt_filename != NULL) ? alt_filename : filename; - } else - { - if (strcmp(filename, FAKE_HELPFILE) == 0 || - strcmp(filename, FAKE_EMPTYFILE) == 0) - alt_filename = NULL; - else - alt_filename = open_altfile(filename, &f, &altpipe); - - open_filename = (alt_filename != NULL) ? alt_filename : filename; - - chflags = 0; - if (altpipe != NULL) - { - /* - * The alternate "file" is actually a pipe. - * f has already been set to the file descriptor of the pipe - * in the call to open_altfile above. - * Keep the file descriptor open because it was opened - * via popen(), and pclose() wants to close it. - */ - chflags |= CH_POPENED; - if (strcmp(filename, "-") == 0) - chflags |= CH_KEEPOPEN; - } else if (strcmp(filename, "-") == 0) - { - /* - * Use standard input. - * Keep the file descriptor open because we can't reopen it. - */ - f = fd0; - chflags |= CH_KEEPOPEN; - /* - * Must switch stdin to BINARY mode. - */ - SET_BINARY(f); + was_curr_ifile = save_curr_ifile(); + if (curr_ifile != NULL_IFILE) + { + chflags = ch_getflags(); + close_file(); + if ((chflags & CH_HELPFILE) && held_ifile(was_curr_ifile) <= 1) + { + /* + * Don't keep the help file in the ifile list. + */ + del_ifile(was_curr_ifile); + was_curr_ifile = old_ifile; + } + } + + if (ifile == NULL_IFILE) + { + /* + * No new file to open. + * (Don't set old_ifile, because if you call edit_ifile(NULL), + * you're supposed to have saved curr_ifile yourself, + * and you'll restore it if necessary.) + */ + unsave_ifile(was_curr_ifile); + return (0); + } + + filename = save(get_filename(ifile)); + + /* + * See if LESSOPEN specifies an "alternate" file to open. + */ + altpipe = get_altpipe(ifile); + if (altpipe != NULL) + { + /* + * File is already open. + * chflags and f are not used by ch_init if ifile has + * filestate which should be the case if we're here. + * Set them here to avoid uninitialized variable warnings. + */ + chflags = 0; + f = -1; + alt_filename = get_altfilename(ifile); + open_filename = (alt_filename != NULL) ? alt_filename : filename; + } else + { + if (strcmp(filename, FAKE_HELPFILE) == 0 || + strcmp(filename, FAKE_EMPTYFILE) == 0) + alt_filename = NULL; + else + alt_filename = open_altfile(filename, &f, &altpipe); + + open_filename = (alt_filename != NULL) ? alt_filename : filename; + + chflags = 0; + if (altpipe != NULL) + { + /* + * The alternate "file" is actually a pipe. + * f has already been set to the file descriptor of the pipe + * in the call to open_altfile above. + * Keep the file descriptor open because it was opened + * via popen(), and pclose() wants to close it. + */ + chflags |= CH_POPENED; + if (strcmp(filename, "-") == 0) + chflags |= CH_KEEPOPEN; + } else if (strcmp(filename, "-") == 0) + { + /* + * Use standard input. + * Keep the file descriptor open because we can't reopen it. + */ + f = fd0; + chflags |= CH_KEEPOPEN; + /* + * Must switch stdin to BINARY mode. + */ + SET_BINARY(f); #if MSDOS_COMPILER==DJGPPC - /* - * Setting stdin to binary by default causes - * Ctrl-C to not raise SIGINT. We must undo - * that side-effect. - */ - __djgpp_set_ctrl_c(1); + /* + * Setting stdin to binary by default causes + * Ctrl-C to not raise SIGINT. We must undo + * that side-effect. + */ + __djgpp_set_ctrl_c(1); #endif - } else if (strcmp(open_filename, FAKE_EMPTYFILE) == 0) - { - f = -1; - chflags |= CH_NODATA; - } else if (strcmp(open_filename, FAKE_HELPFILE) == 0) - { - f = -1; - chflags |= CH_HELPFILE; - } else if ((parg.p_string = bad_file(open_filename)) != NULL) - { - /* - * It looks like a bad file. Don't try to open it. - */ - error("%s", &parg); - free(parg.p_string); - err1: - if (alt_filename != NULL) - { - close_pipe(altpipe); - close_altfile(alt_filename, filename); - free(alt_filename); - } - del_ifile(ifile); - free(filename); - /* - * Re-open the current file. - */ - if (was_curr_ifile == ifile) - { - /* - * Whoops. The "current" ifile is the one we just deleted. - * Just give up. - */ - quit(QUIT_ERROR); - } - reedit_ifile(was_curr_ifile); - return (1); - } else if ((f = open(open_filename, OPEN_READ)) < 0) - { - /* - * Got an error trying to open it. - */ - parg.p_string = errno_message(filename); - error("%s", &parg); - free(parg.p_string); - goto err1; - } else - { - chflags |= CH_CANSEEK; - if (!force_open && !opened(ifile) && bin_file(f)) - { - /* - * Looks like a binary file. - * Ask user if we should proceed. - */ - parg.p_string = filename; - answer = query("\"%s\" may be a binary file. See it anyway? ", - &parg); - if (answer != 'y' && answer != 'Y') - { - close(f); - goto err1; - } - } - } - } - - /* - * Get the new ifile. - * Get the saved position for the file. - */ - if (was_curr_ifile != NULL_IFILE) - { - old_ifile = was_curr_ifile; - unsave_ifile(was_curr_ifile); - } - curr_ifile = ifile; - set_altfilename(curr_ifile, alt_filename); - set_altpipe(curr_ifile, altpipe); - set_open(curr_ifile); /* File has been opened */ - get_pos(curr_ifile, &initial_scrpos); - new_file = TRUE; - ch_init(f, chflags); - - if (!(chflags & CH_HELPFILE)) - { + } else if (strcmp(open_filename, FAKE_EMPTYFILE) == 0) + { + f = -1; + chflags |= CH_NODATA; + } else if (strcmp(open_filename, FAKE_HELPFILE) == 0) + { + f = -1; + chflags |= CH_HELPFILE; + } else if ((parg.p_string = bad_file(open_filename)) != NULL) + { + /* + * It looks like a bad file. Don't try to open it. + */ + error("%s", &parg); + free(parg.p_string); + err1: + if (alt_filename != NULL) + { + close_pipe(altpipe); + close_altfile(alt_filename, filename); + free(alt_filename); + } + del_ifile(ifile); + free(filename); + /* + * Re-open the current file. + */ + if (was_curr_ifile == ifile) + { + /* + * Whoops. The "current" ifile is the one we just deleted. + * Just give up. + */ + quit(QUIT_ERROR); + } + reedit_ifile(was_curr_ifile); + return (1); + } else if ((f = open(open_filename, OPEN_READ)) < 0) + { + /* + * Got an error trying to open it. + */ + parg.p_string = errno_message(filename); + error("%s", &parg); + free(parg.p_string); + goto err1; + } else + { + chflags |= CH_CANSEEK; + if (!force_open && !opened(ifile) && bin_file(f)) + { + /* + * Looks like a binary file. + * Ask user if we should proceed. + */ + parg.p_string = filename; + answer = query("\"%s\" may be a binary file. See it anyway? ", + &parg); + if (answer != 'y' && answer != 'Y') + { + close(f); + goto err1; + } + } + } + } + + /* + * Get the new ifile. + * Get the saved position for the file. + */ + if (was_curr_ifile != NULL_IFILE) + { + old_ifile = was_curr_ifile; + unsave_ifile(was_curr_ifile); + } + curr_ifile = ifile; + set_altfilename(curr_ifile, alt_filename); + set_altpipe(curr_ifile, altpipe); + set_open(curr_ifile); /* File has been opened */ + get_pos(curr_ifile, &initial_scrpos); + new_file = TRUE; + ch_init(f, chflags); + + if (!(chflags & CH_HELPFILE)) + { #if LOGFILE - if (namelogfile != NULL && is_tty) - use_logfile(namelogfile); + if (namelogfile != NULL && is_tty) + use_logfile(namelogfile); #endif #if HAVE_STAT_INO - /* Remember the i-number and device of the opened file. */ - if (strcmp(open_filename, "-") != 0) - { - struct stat statbuf; - int r = stat(open_filename, &statbuf); - if (r == 0) - { - curr_ino = statbuf.st_ino; - curr_dev = statbuf.st_dev; - } - } + /* Remember the i-number and device of the opened file. */ + if (strcmp(open_filename, "-") != 0) + { + struct stat statbuf; + int r = stat(open_filename, &statbuf); + if (r == 0) + { + curr_ino = statbuf.st_ino; + curr_dev = statbuf.st_dev; + } + } #endif - if (every_first_cmd != NULL) - { - ungetsc(every_first_cmd); - ungetcc_back(CHAR_END_COMMAND); - } - } - - flush(); - - if (is_tty) - { - /* - * Output is to a real tty. - */ - - /* - * Indicate there is nothing displayed yet. - */ - pos_clear(); - clr_linenum(); + if (every_first_cmd != NULL) + { + ungetsc(every_first_cmd); + ungetcc_back(CHAR_END_COMMAND); + } + } + + flush(); + + if (is_tty) + { + /* + * Output is to a real tty. + */ + + /* + * Indicate there is nothing displayed yet. + */ + pos_clear(); + clr_linenum(); #if HILITE_SEARCH - clr_hilite(); + clr_hilite(); #endif - hshift = 0; - if (strcmp(filename, FAKE_HELPFILE) && strcmp(filename, FAKE_EMPTYFILE)) - { - char *qfilename = shell_quote(filename); - cmd_addhist(ml_examine, qfilename, 1); - free(qfilename); - } - - } - free(filename); - return (0); + hshift = 0; + if (strcmp(filename, FAKE_HELPFILE) && strcmp(filename, FAKE_EMPTYFILE)) + { + char *qfilename = shell_quote(filename); + cmd_addhist(ml_examine, qfilename, 1); + free(qfilename); + } + + } + free(filename); + return (0); } /* @@ -498,273 +498,273 @@ edit_ifile(ifile) * For each filename in the list, enter it into the ifile list. * Then edit the first one. */ - public int + public int edit_list(filelist) - char *filelist; + char *filelist; { - IFILE save_ifile; - char *good_filename; - char *filename; - char *gfilelist; - char *gfilename; - char *qfilename; - struct textlist tl_files; - struct textlist tl_gfiles; - - save_ifile = save_curr_ifile(); - good_filename = NULL; - - /* - * Run thru each filename in the list. - * Try to glob the filename. - * If it doesn't expand, just try to open the filename. - * If it does expand, try to open each name in that list. - */ - init_textlist(&tl_files, filelist); - filename = NULL; - while ((filename = forw_textlist(&tl_files, filename)) != NULL) - { - gfilelist = lglob(filename); - init_textlist(&tl_gfiles, gfilelist); - gfilename = NULL; - while ((gfilename = forw_textlist(&tl_gfiles, gfilename)) != NULL) - { - qfilename = shell_unquote(gfilename); - if (edit(qfilename) == 0 && good_filename == NULL) - good_filename = get_filename(curr_ifile); - free(qfilename); - } - free(gfilelist); - } - /* - * Edit the first valid filename in the list. - */ - if (good_filename == NULL) - { - unsave_ifile(save_ifile); - return (1); - } - if (get_ifile(good_filename, curr_ifile) == curr_ifile) - { - /* - * Trying to edit the current file; don't reopen it. - */ - unsave_ifile(save_ifile); - return (0); - } - reedit_ifile(save_ifile); - return (edit(good_filename)); + IFILE save_ifile; + char *good_filename; + char *filename; + char *gfilelist; + char *gfilename; + char *qfilename; + struct textlist tl_files; + struct textlist tl_gfiles; + + save_ifile = save_curr_ifile(); + good_filename = NULL; + + /* + * Run thru each filename in the list. + * Try to glob the filename. + * If it doesn't expand, just try to open the filename. + * If it does expand, try to open each name in that list. + */ + init_textlist(&tl_files, filelist); + filename = NULL; + while ((filename = forw_textlist(&tl_files, filename)) != NULL) + { + gfilelist = lglob(filename); + init_textlist(&tl_gfiles, gfilelist); + gfilename = NULL; + while ((gfilename = forw_textlist(&tl_gfiles, gfilename)) != NULL) + { + qfilename = shell_unquote(gfilename); + if (edit(qfilename) == 0 && good_filename == NULL) + good_filename = get_filename(curr_ifile); + free(qfilename); + } + free(gfilelist); + } + /* + * Edit the first valid filename in the list. + */ + if (good_filename == NULL) + { + unsave_ifile(save_ifile); + return (1); + } + if (get_ifile(good_filename, curr_ifile) == curr_ifile) + { + /* + * Trying to edit the current file; don't reopen it. + */ + unsave_ifile(save_ifile); + return (0); + } + reedit_ifile(save_ifile); + return (edit(good_filename)); } /* * Edit the first file in the command line (ifile) list. */ - public int + public int edit_first(VOID_PARAM) { - if (nifile() == 0) - return (edit_stdin()); - curr_ifile = NULL_IFILE; - return (edit_next(1)); + if (nifile() == 0) + return (edit_stdin()); + curr_ifile = NULL_IFILE; + return (edit_next(1)); } /* * Edit the last file in the command line (ifile) list. */ - public int + public int edit_last(VOID_PARAM) { - curr_ifile = NULL_IFILE; - return (edit_prev(1)); + curr_ifile = NULL_IFILE; + return (edit_prev(1)); } /* * Edit the n-th next or previous file in the command line (ifile) list. */ - static int + static int edit_istep(h, n, dir) - IFILE h; - int n; - int dir; + IFILE h; + int n; + int dir; { - IFILE next; - - /* - * Skip n filenames, then try to edit each filename. - */ - for (;;) - { - next = (dir > 0) ? next_ifile(h) : prev_ifile(h); - if (--n < 0) - { - if (edit_ifile(h) == 0) - break; - } - if (next == NULL_IFILE) - { - /* - * Reached end of the ifile list. - */ - return (1); - } - if (ABORT_SIGS()) - { - /* - * Interrupt breaks out, if we're in a long - * list of files that can't be opened. - */ - return (1); - } - h = next; - } - /* - * Found a file that we can edit. - */ - return (0); + IFILE next; + + /* + * Skip n filenames, then try to edit each filename. + */ + for (;;) + { + next = (dir > 0) ? next_ifile(h) : prev_ifile(h); + if (--n < 0) + { + if (edit_ifile(h) == 0) + break; + } + if (next == NULL_IFILE) + { + /* + * Reached end of the ifile list. + */ + return (1); + } + if (ABORT_SIGS()) + { + /* + * Interrupt breaks out, if we're in a long + * list of files that can't be opened. + */ + return (1); + } + h = next; + } + /* + * Found a file that we can edit. + */ + return (0); } - static int + static int edit_inext(h, n) - IFILE h; - int n; + IFILE h; + int n; { - return (edit_istep(h, n, +1)); + return (edit_istep(h, n, +1)); } - public int + public int edit_next(n) - int n; + int n; { - return edit_istep(curr_ifile, n, +1); + return edit_istep(curr_ifile, n, +1); } - static int + static int edit_iprev(h, n) - IFILE h; - int n; + IFILE h; + int n; { - return (edit_istep(h, n, -1)); + return (edit_istep(h, n, -1)); } - public int + public int edit_prev(n) - int n; + int n; { - return edit_istep(curr_ifile, n, -1); + return edit_istep(curr_ifile, n, -1); } /* * Edit a specific file in the command line (ifile) list. */ - public int + public int edit_index(n) - int n; + int n; { - IFILE h; - - h = NULL_IFILE; - do - { - if ((h = next_ifile(h)) == NULL_IFILE) - { - /* - * Reached end of the list without finding it. - */ - return (1); - } - } while (get_index(h) != n); - - return (edit_ifile(h)); + IFILE h; + + h = NULL_IFILE; + do + { + if ((h = next_ifile(h)) == NULL_IFILE) + { + /* + * Reached end of the list without finding it. + */ + return (1); + } + } while (get_index(h) != n); + + return (edit_ifile(h)); } - public IFILE + public IFILE save_curr_ifile(VOID_PARAM) { - if (curr_ifile != NULL_IFILE) - hold_ifile(curr_ifile, 1); - return (curr_ifile); + if (curr_ifile != NULL_IFILE) + hold_ifile(curr_ifile, 1); + return (curr_ifile); } - public void + public void unsave_ifile(save_ifile) - IFILE save_ifile; + IFILE save_ifile; { - if (save_ifile != NULL_IFILE) - hold_ifile(save_ifile, -1); + if (save_ifile != NULL_IFILE) + hold_ifile(save_ifile, -1); } /* * Reedit the ifile which was previously open. */ - public void + public void reedit_ifile(save_ifile) - IFILE save_ifile; + IFILE save_ifile; { - IFILE next; - IFILE prev; - - /* - * Try to reopen the ifile. - * Note that opening it may fail (maybe the file was removed), - * in which case the ifile will be deleted from the list. - * So save the next and prev ifiles first. - */ - unsave_ifile(save_ifile); - next = next_ifile(save_ifile); - prev = prev_ifile(save_ifile); - if (edit_ifile(save_ifile) == 0) - return; - /* - * If can't reopen it, open the next input file in the list. - */ - if (next != NULL_IFILE && edit_inext(next, 0) == 0) - return; - /* - * If can't open THAT one, open the previous input file in the list. - */ - if (prev != NULL_IFILE && edit_iprev(prev, 0) == 0) - return; - /* - * If can't even open that, we're stuck. Just quit. - */ - quit(QUIT_ERROR); + IFILE next; + IFILE prev; + + /* + * Try to reopen the ifile. + * Note that opening it may fail (maybe the file was removed), + * in which case the ifile will be deleted from the list. + * So save the next and prev ifiles first. + */ + unsave_ifile(save_ifile); + next = next_ifile(save_ifile); + prev = prev_ifile(save_ifile); + if (edit_ifile(save_ifile) == 0) + return; + /* + * If can't reopen it, open the next input file in the list. + */ + if (next != NULL_IFILE && edit_inext(next, 0) == 0) + return; + /* + * If can't open THAT one, open the previous input file in the list. + */ + if (prev != NULL_IFILE && edit_iprev(prev, 0) == 0) + return; + /* + * If can't even open that, we're stuck. Just quit. + */ + quit(QUIT_ERROR); } - public void + public void reopen_curr_ifile(VOID_PARAM) { - IFILE save_ifile = save_curr_ifile(); - close_file(); - reedit_ifile(save_ifile); + IFILE save_ifile = save_curr_ifile(); + close_file(); + reedit_ifile(save_ifile); } /* * Edit standard input. */ - public int + public int edit_stdin(VOID_PARAM) { - if (isatty(fd0)) - { - error("Missing filename (\"less --help\" for help)", NULL_PARG); - quit(QUIT_OK); - } - return (edit("-")); + if (isatty(fd0)) + { + error("Missing filename (\"less --help\" for help)", NULL_PARG); + quit(QUIT_OK); + } + return (edit("-")); } /* * Copy a file directly to standard output. * Used if standard output is not a tty. */ - public void + public void cat_file(VOID_PARAM) { - int c; + int c; - while ((c = ch_forw_get()) != EOI) - putchr(c); - flush(); + while ((c = ch_forw_get()) != EOI) + putchr(c); + flush(); } #if LOGFILE @@ -773,94 +773,94 @@ cat_file(VOID_PARAM) /* * If the user asked for a log file and our input file - * is standard input, create the log file. + * is standard input, create the log file. * We take care not to blindly overwrite an existing file. */ - public void + public void use_logfile(filename) - char *filename; + char *filename; { - int exists; - int answer; - PARG parg; - - if (ch_getflags() & CH_CANSEEK) - /* - * Can't currently use a log file on a file that can seek. - */ - return; - - /* - * {{ We could use access() here. }} - */ - exists = open(filename, OPEN_READ); - if (exists >= 0) - close(exists); - exists = (exists >= 0); - - /* - * Decide whether to overwrite the log file or append to it. - * If it doesn't exist we "overwrite" it. - */ - if (!exists || force_logfile) - { - /* - * Overwrite (or create) the log file. - */ - answer = 'O'; - } else - { - /* - * Ask user what to do. - */ - parg.p_string = filename; - answer = query("Warning: \"%s\" exists; "OVERWRITE_OPTIONS" ", &parg); - } + int exists; + int answer; + PARG parg; + + if (ch_getflags() & CH_CANSEEK) + /* + * Can't currently use a log file on a file that can seek. + */ + return; + + /* + * {{ We could use access() here. }} + */ + exists = open(filename, OPEN_READ); + if (exists >= 0) + close(exists); + exists = (exists >= 0); + + /* + * Decide whether to overwrite the log file or append to it. + * If it doesn't exist we "overwrite" it. + */ + if (!exists || force_logfile) + { + /* + * Overwrite (or create) the log file. + */ + answer = 'O'; + } else + { + /* + * Ask user what to do. + */ + parg.p_string = filename; + answer = query("Warning: \"%s\" exists; "OVERWRITE_OPTIONS" ", &parg); + } loop: - switch (answer) - { - case 'O': case 'o': - /* - * Overwrite: create the file. - */ - logfile = creat(filename, 0644); - break; - case 'A': case 'a': - /* - * Append: open the file and seek to the end. - */ - logfile = open(filename, OPEN_APPEND); - if (lseek(logfile, (off_t)0, SEEK_END) == BAD_LSEEK) - { - close(logfile); - logfile = -1; - } - break; - case 'D': case 'd': - /* - * Don't do anything. - */ - return; - default: - /* - * Eh? - */ - - answer = query(OVERWRITE_OPTIONS" (Type \"O\", \"A\", \"D\" or \"Q\") ", NULL_PARG); - goto loop; - } - - if (logfile < 0) - { - /* - * Error in opening logfile. - */ - parg.p_string = filename; - error("Cannot write to \"%s\"", &parg); - return; - } - SET_BINARY(logfile); + switch (answer) + { + case 'O': case 'o': + /* + * Overwrite: create the file. + */ + logfile = creat(filename, 0644); + break; + case 'A': case 'a': + /* + * Append: open the file and seek to the end. + */ + logfile = open(filename, OPEN_APPEND); + if (lseek(logfile, (off_t)0, SEEK_END) == BAD_LSEEK) + { + close(logfile); + logfile = -1; + } + break; + case 'D': case 'd': + /* + * Don't do anything. + */ + return; + default: + /* + * Eh? + */ + + answer = query(OVERWRITE_OPTIONS" (Type \"O\", \"A\", \"D\" or \"Q\") ", NULL_PARG); + goto loop; + } + + if (logfile < 0) + { + /* + * Error in opening logfile. + */ + parg.p_string = filename; + error("Cannot write to \"%s\"", &parg); + return; + } + SET_BINARY(logfile); } #endif diff --git a/filename.c b/filename.c index 177cb94..82b0aeb 100644 --- a/filename.c +++ b/filename.c @@ -58,242 +58,242 @@ extern char closequote; /* * Remove quotes around a filename. */ - public char * + public char * shell_unquote(str) - char *str; + char *str; { - char *name; - char *p; - - name = p = (char *) ecalloc(strlen(str)+1, sizeof(char)); - if (*str == openquote) - { - str++; - while (*str != '\0') - { - if (*str == closequote) - { - if (str[1] != closequote) - break; - str++; - } - *p++ = *str++; - } - } else - { - char *esc = get_meta_escape(); - int esclen = (int) strlen(esc); - while (*str != '\0') - { - if (esclen > 0 && strncmp(str, esc, esclen) == 0) - str += esclen; - *p++ = *str++; - } - } - *p = '\0'; - return (name); + char *name; + char *p; + + name = p = (char *) ecalloc(strlen(str)+1, sizeof(char)); + if (*str == openquote) + { + str++; + while (*str != '\0') + { + if (*str == closequote) + { + if (str[1] != closequote) + break; + str++; + } + *p++ = *str++; + } + } else + { + char *esc = get_meta_escape(); + int esclen = (int) strlen(esc); + while (*str != '\0') + { + if (esclen > 0 && strncmp(str, esc, esclen) == 0) + str += esclen; + *p++ = *str++; + } + } + *p = '\0'; + return (name); } /* * Get the shell's escape character. */ - public char * + public char * get_meta_escape(VOID_PARAM) { - char *s; + char *s; - s = lgetenv("LESSMETAESCAPE"); - if (s == NULL) - s = DEF_METAESCAPE; - return (s); + s = lgetenv("LESSMETAESCAPE"); + if (s == NULL) + s = DEF_METAESCAPE; + return (s); } /* * Get the characters which the shell considers to be "metacharacters". */ - static char * + static char * metachars(VOID_PARAM) { - static char *mchars = NULL; - - if (mchars == NULL) - { - mchars = lgetenv("LESSMETACHARS"); - if (mchars == NULL) - mchars = DEF_METACHARS; - } - return (mchars); + static char *mchars = NULL; + + if (mchars == NULL) + { + mchars = lgetenv("LESSMETACHARS"); + if (mchars == NULL) + mchars = DEF_METACHARS; + } + return (mchars); } /* * Is this a shell metacharacter? */ - static int + static int metachar(c) - char c; + char c; { - return (strchr(metachars(), c) != NULL); + return (strchr(metachars(), c) != NULL); } /* * Insert a backslash before each metacharacter in a string. */ - public char * + public char * shell_quote(s) - char *s; + char *s; { - char *p; - char *newstr; - int len; - char *esc = get_meta_escape(); - int esclen = (int) strlen(esc); - int use_quotes = 0; - int have_quotes = 0; - - /* - * Determine how big a string we need to allocate. - */ - len = 1; /* Trailing null byte */ - for (p = s; *p != '\0'; p++) - { - len++; - if (*p == openquote || *p == closequote) - have_quotes = 1; - if (metachar(*p)) - { - if (esclen == 0) - { - /* - * We've got a metachar, but this shell - * doesn't support escape chars. Use quotes. - */ - use_quotes = 1; - } else - { - /* - * Allow space for the escape char. - */ - len += esclen; - } - } - } - if (use_quotes) - { - if (have_quotes) - /* - * We can't quote a string that contains quotes. - */ - return (NULL); - len = (int) strlen(s) + 3; - } - /* - * Allocate and construct the new string. - */ - newstr = p = (char *) ecalloc(len, sizeof(char)); - if (use_quotes) - { - SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote); - } else - { - while (*s != '\0') - { - if (metachar(*s)) - { - /* - * Add the escape char. - */ - strcpy(p, esc); - p += esclen; - } - *p++ = *s++; - } - *p = '\0'; - } - return (newstr); + char *p; + char *newstr; + int len; + char *esc = get_meta_escape(); + int esclen = (int) strlen(esc); + int use_quotes = 0; + int have_quotes = 0; + + /* + * Determine how big a string we need to allocate. + */ + len = 1; /* Trailing null byte */ + for (p = s; *p != '\0'; p++) + { + len++; + if (*p == openquote || *p == closequote) + have_quotes = 1; + if (metachar(*p)) + { + if (esclen == 0) + { + /* + * We've got a metachar, but this shell + * doesn't support escape chars. Use quotes. + */ + use_quotes = 1; + } else + { + /* + * Allow space for the escape char. + */ + len += esclen; + } + } + } + if (use_quotes) + { + if (have_quotes) + /* + * We can't quote a string that contains quotes. + */ + return (NULL); + len = (int) strlen(s) + 3; + } + /* + * Allocate and construct the new string. + */ + newstr = p = (char *) ecalloc(len, sizeof(char)); + if (use_quotes) + { + SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote); + } else + { + while (*s != '\0') + { + if (metachar(*s)) + { + /* + * Add the escape char. + */ + strcpy(p, esc); + p += esclen; + } + *p++ = *s++; + } + *p = '\0'; + } + return (newstr); } /* * Return a pathname that points to a specified file in a specified directory. * Return NULL if the file does not exist in the directory. */ - static char * + static char * dirfile(dirname, filename) - char *dirname; - char *filename; + char *dirname; + char *filename; { - char *pathname; - int len; - int f; - - if (dirname == NULL || *dirname == '\0') - return (NULL); - /* - * Construct the full pathname. - */ - len = (int) (strlen(dirname) + strlen(filename) + 2); - pathname = (char *) calloc(len, sizeof(char)); - if (pathname == NULL) - return (NULL); - SNPRINTF3(pathname, len, "%s%s%s", dirname, PATHNAME_SEP, filename); - /* - * Make sure the file exists. - */ - f = open(pathname, OPEN_READ); - if (f < 0) - { - free(pathname); - pathname = NULL; - } else - { - close(f); - } - return (pathname); + char *pathname; + int len; + int f; + + if (dirname == NULL || *dirname == '\0') + return (NULL); + /* + * Construct the full pathname. + */ + len = (int) (strlen(dirname) + strlen(filename) + 2); + pathname = (char *) calloc(len, sizeof(char)); + if (pathname == NULL) + return (NULL); + SNPRINTF3(pathname, len, "%s%s%s", dirname, PATHNAME_SEP, filename); + /* + * Make sure the file exists. + */ + f = open(pathname, OPEN_READ); + if (f < 0) + { + free(pathname); + pathname = NULL; + } else + { + close(f); + } + return (pathname); } /* * Return the full pathname of the given file in the "home directory". */ - public char * + public char * homefile(filename) - char *filename; + char *filename; { - char *pathname; - - /* - * Try $HOME/filename. - */ - pathname = dirfile(lgetenv("HOME"), filename); - if (pathname != NULL) - return (pathname); + char *pathname; + + /* + * Try $HOME/filename. + */ + pathname = dirfile(lgetenv("HOME"), filename); + if (pathname != NULL) + return (pathname); #if OS2 - /* - * Try $INIT/filename. - */ - pathname = dirfile(lgetenv("INIT"), filename); - if (pathname != NULL) - return (pathname); + /* + * Try $INIT/filename. + */ + pathname = dirfile(lgetenv("INIT"), filename); + if (pathname != NULL) + return (pathname); #endif #if MSDOS_COMPILER || OS2 - /* - * Look for the file anywhere on search path. - */ - pathname = (char *) calloc(_MAX_PATH, sizeof(char)); + /* + * Look for the file anywhere on search path. + */ + pathname = (char *) calloc(_MAX_PATH, sizeof(char)); #if MSDOS_COMPILER==DJGPPC - { - char *res = searchpath(filename); - if (res == 0) - *pathname = '\0'; - else - strcpy(pathname, res); - } + { + char *res = searchpath(filename); + if (res == 0) + *pathname = '\0'; + else + strcpy(pathname, res); + } #else - _searchenv(filename, "PATH", pathname); + _searchenv(filename, "PATH", pathname); #endif - if (*pathname != '\0') - return (pathname); - free(pathname); + if (*pathname != '\0') + return (pathname); + free(pathname); #endif - return (NULL); + return (NULL); } /* @@ -303,93 +303,93 @@ homefile(filename) * Likewise for a string of N "#"s. * {{ This is a lot of work just to support % and #. }} */ - public char * + public char * fexpand(s) - char *s; + char *s; { - char *fr, *to; - int n; - char *e; - IFILE ifile; + char *fr, *to; + int n; + char *e; + IFILE ifile; #define fchar_ifile(c) \ - ((c) == '%' ? curr_ifile : \ - (c) == '#' ? old_ifile : NULL_IFILE) - - /* - * Make one pass to see how big a buffer we - * need to allocate for the expanded string. - */ - n = 0; - for (fr = s; *fr != '\0'; fr++) - { - switch (*fr) - { - case '%': - case '#': - if (fr > s && fr[-1] == *fr) - { - /* - * Second (or later) char in a string - * of identical chars. Treat as normal. - */ - n++; - } else if (fr[1] != *fr) - { - /* - * Single char (not repeated). Treat specially. - */ - ifile = fchar_ifile(*fr); - if (ifile == NULL_IFILE) - n++; - else - n += (int) strlen(get_filename(ifile)); - } - /* - * Else it is the first char in a string of - * identical chars. Just discard it. - */ - break; - default: - n++; - break; - } - } - - e = (char *) ecalloc(n+1, sizeof(char)); - - /* - * Now copy the string, expanding any "%" or "#". - */ - to = e; - for (fr = s; *fr != '\0'; fr++) - { - switch (*fr) - { - case '%': - case '#': - if (fr > s && fr[-1] == *fr) - { - *to++ = *fr; - } else if (fr[1] != *fr) - { - ifile = fchar_ifile(*fr); - if (ifile == NULL_IFILE) - *to++ = *fr; - else - { - strcpy(to, get_filename(ifile)); - to += strlen(to); - } - } - break; - default: - *to++ = *fr; - break; - } - } - *to = '\0'; - return (e); + ((c) == '%' ? curr_ifile : \ + (c) == '#' ? old_ifile : NULL_IFILE) + + /* + * Make one pass to see how big a buffer we + * need to allocate for the expanded string. + */ + n = 0; + for (fr = s; *fr != '\0'; fr++) + { + switch (*fr) + { + case '%': + case '#': + if (fr > s && fr[-1] == *fr) + { + /* + * Second (or later) char in a string + * of identical chars. Treat as normal. + */ + n++; + } else if (fr[1] != *fr) + { + /* + * Single char (not repeated). Treat specially. + */ + ifile = fchar_ifile(*fr); + if (ifile == NULL_IFILE) + n++; + else + n += (int) strlen(get_filename(ifile)); + } + /* + * Else it is the first char in a string of + * identical chars. Just discard it. + */ + break; + default: + n++; + break; + } + } + + e = (char *) ecalloc(n+1, sizeof(char)); + + /* + * Now copy the string, expanding any "%" or "#". + */ + to = e; + for (fr = s; *fr != '\0'; fr++) + { + switch (*fr) + { + case '%': + case '#': + if (fr > s && fr[-1] == *fr) + { + *to++ = *fr; + } else if (fr[1] != *fr) + { + ifile = fchar_ifile(*fr); + if (ifile == NULL_IFILE) + *to++ = *fr; + else + { + strcpy(to, get_filename(ifile)); + to += strlen(to); + } + } + break; + default: + *to++ = *fr; + break; + } + } + *to = '\0'; + return (e); } @@ -399,59 +399,59 @@ fexpand(s) * Return a blank-separated list of filenames which "complete" * the given string. */ - public char * + public char * fcomplete(s) - char *s; + char *s; { - char *fpat; - char *qs; - - if (secure) - return (NULL); - /* - * Complete the filename "s" by globbing "s*". - */ + char *fpat; + char *qs; + + if (secure) + return (NULL); + /* + * Complete the filename "s" by globbing "s*". + */ #if MSDOS_COMPILER && (MSDOS_COMPILER == MSOFTC || MSDOS_COMPILER == BORLANDC) - /* - * But in DOS, we have to glob "s*.*". - * But if the final component of the filename already has - * a dot in it, just do "s*". - * (Thus, "FILE" is globbed as "FILE*.*", - * but "FILE.A" is globbed as "FILE.A*"). - */ - { - char *slash; - int len; - for (slash = s+strlen(s)-1; slash > s; slash--) - if (*slash == *PATHNAME_SEP || *slash == '/') - break; - len = (int) strlen(s) + 4; - fpat = (char *) ecalloc(len, sizeof(char)); - if (strchr(slash, '.') == NULL) - SNPRINTF1(fpat, len, "%s*.*", s); - else - SNPRINTF1(fpat, len, "%s*", s); - } + /* + * But in DOS, we have to glob "s*.*". + * But if the final component of the filename already has + * a dot in it, just do "s*". + * (Thus, "FILE" is globbed as "FILE*.*", + * but "FILE.A" is globbed as "FILE.A*"). + */ + { + char *slash; + int len; + for (slash = s+strlen(s)-1; slash > s; slash--) + if (*slash == *PATHNAME_SEP || *slash == '/') + break; + len = (int) strlen(s) + 4; + fpat = (char *) ecalloc(len, sizeof(char)); + if (strchr(slash, '.') == NULL) + SNPRINTF1(fpat, len, "%s*.*", s); + else + SNPRINTF1(fpat, len, "%s*", s); + } #else - { - int len = (int) strlen(s) + 2; - fpat = (char *) ecalloc(len, sizeof(char)); - SNPRINTF1(fpat, len, "%s*", s); - } + { + int len = (int) strlen(s) + 2; + fpat = (char *) ecalloc(len, sizeof(char)); + SNPRINTF1(fpat, len, "%s*", s); + } #endif - qs = lglob(fpat); - s = shell_unquote(qs); - if (strcmp(s,fpat) == 0) - { - /* - * The filename didn't expand. - */ - free(qs); - qs = NULL; - } - free(s); - free(fpat); - return (qs); + qs = lglob(fpat); + s = shell_unquote(qs); + if (strcmp(s,fpat) == 0) + { + /* + * The filename didn't expand. + */ + free(qs); + qs = NULL; + } + free(s); + free(fpat); + return (qs); } #endif @@ -459,105 +459,105 @@ fcomplete(s) * Try to determine if a file is "binary". * This is just a guess, and we need not try too hard to make it accurate. */ - public int + public int bin_file(f) - int f; + int f; { - int n; - int bin_count = 0; - char data[256]; - char* p; - char* edata; - - if (!seekable(f)) - return (0); - if (lseek(f, (off_t)0, SEEK_SET) == BAD_LSEEK) - return (0); - n = read(f, data, sizeof(data)); - if (n <= 0) - return (0); - edata = &data[n]; - for (p = data; p < edata; ) - { - if (utf_mode && !is_utf8_well_formed(p, edata-data)) - { - bin_count++; - utf_skip_to_lead(&p, edata); - } else - { - LWCHAR c = step_char(&p, +1, edata); - struct ansi_state *pansi; - if (ctldisp == OPT_ONPLUS && (pansi = ansi_start(c)) != NULL) - { - skip_ansi(pansi, &p, edata); - ansi_done(pansi); - } else if (binary_char(c)) - bin_count++; - } - } - /* - * Call it a binary file if there are more than 5 binary characters - * in the first 256 bytes of the file. - */ - return (bin_count > 5); + int n; + int bin_count = 0; + char data[256]; + char* p; + char* edata; + + if (!seekable(f)) + return (0); + if (lseek(f, (off_t)0, SEEK_SET) == BAD_LSEEK) + return (0); + n = read(f, data, sizeof(data)); + if (n <= 0) + return (0); + edata = &data[n]; + for (p = data; p < edata; ) + { + if (utf_mode && !is_utf8_well_formed(p, edata-data)) + { + bin_count++; + utf_skip_to_lead(&p, edata); + } else + { + LWCHAR c = step_char(&p, +1, edata); + struct ansi_state *pansi; + if (ctldisp == OPT_ONPLUS && (pansi = ansi_start(c)) != NULL) + { + skip_ansi(pansi, &p, edata); + ansi_done(pansi); + } else if (binary_char(c)) + bin_count++; + } + } + /* + * Call it a binary file if there are more than 5 binary characters + * in the first 256 bytes of the file. + */ + return (bin_count > 5); } /* * Try to determine the size of a file by seeking to the end. */ - static POSITION + static POSITION seek_filesize(f) - int f; + int f; { - off_t spos; + off_t spos; - spos = lseek(f, (off_t)0, SEEK_END); - if (spos == BAD_LSEEK) - return (NULL_POSITION); - return ((POSITION) spos); + spos = lseek(f, (off_t)0, SEEK_END); + if (spos == BAD_LSEEK) + return (NULL_POSITION); + return ((POSITION) spos); } /* * Read a string from a file. * Return a pointer to the string in memory. */ - static char * + static char * readfd(fd) - FILE *fd; + FILE *fd; { - int len; - int ch; - char *buf; - char *p; - - /* - * Make a guess about how many chars in the string - * and allocate a buffer to hold it. - */ - len = 100; - buf = (char *) ecalloc(len, sizeof(char)); - for (p = buf; ; p++) - { - if ((ch = getc(fd)) == '\n' || ch == EOF) - break; - if (p - buf >= len-1) - { - /* - * The string is too big to fit in the buffer we have. - * Allocate a new buffer, twice as big. - */ - len *= 2; - *p = '\0'; - p = (char *) ecalloc(len, sizeof(char)); - strcpy(p, buf); - free(buf); - buf = p; - p = buf + strlen(buf); - } - *p = ch; - } - *p = '\0'; - return (buf); + int len; + int ch; + char *buf; + char *p; + + /* + * Make a guess about how many chars in the string + * and allocate a buffer to hold it. + */ + len = 100; + buf = (char *) ecalloc(len, sizeof(char)); + for (p = buf; ; p++) + { + if ((ch = getc(fd)) == '\n' || ch == EOF) + break; + if (p - buf >= len-1) + { + /* + * The string is too big to fit in the buffer we have. + * Allocate a new buffer, twice as big. + */ + len *= 2; + *p = '\0'; + p = (char *) ecalloc(len, sizeof(char)); + strcpy(p, buf); + free(buf); + buf = p; + p = buf + strlen(buf); + } + *p = ch; + } + *p = '\0'; + return (buf); } @@ -568,49 +568,49 @@ readfd(fd) * Execute a shell command. * Return a pointer to a pipe connected to the shell command's standard output. */ - static FILE * + static FILE * shellcmd(cmd) - char *cmd; + char *cmd; { - FILE *fd; + FILE *fd; #if HAVE_SHELL - char *shell; - - shell = lgetenv("SHELL"); - if (!isnullenv(shell)) - { - char *scmd; - char *esccmd; - - /* - * Read the output of <$SHELL -c cmd>. - * Escape any metacharacters in the command. - */ - esccmd = shell_quote(cmd); - if (esccmd == NULL) - { - fd = popen(cmd, "r"); - } else - { - int len = (int) (strlen(shell) + strlen(esccmd) + 5); - scmd = (char *) ecalloc(len, sizeof(char)); - SNPRINTF3(scmd, len, "%s %s %s", shell, shell_coption(), esccmd); - free(esccmd); - fd = popen(scmd, "r"); - free(scmd); - } - } else + char *shell; + + shell = lgetenv("SHELL"); + if (!isnullenv(shell)) + { + char *scmd; + char *esccmd; + + /* + * Read the output of <$SHELL -c cmd>. + * Escape any metacharacters in the command. + */ + esccmd = shell_quote(cmd); + if (esccmd == NULL) + { + fd = popen(cmd, "r"); + } else + { + int len = (int) (strlen(shell) + strlen(esccmd) + 5); + scmd = (char *) ecalloc(len, sizeof(char)); + SNPRINTF3(scmd, len, "%s %s %s", shell, shell_coption(), esccmd); + free(esccmd); + fd = popen(scmd, "r"); + free(scmd); + } + } else #endif - { - fd = popen(cmd, "r"); - } - /* - * Redirection in `popen' might have messed with the - * standard devices. Restore binary input mode. - */ - SET_BINARY(0); - return (fd); + { + fd = popen(cmd, "r"); + } + /* + * Redirection in `popen' might have messed with the + * standard devices. Restore binary input mode. + */ + SET_BINARY(0); + return (fd); } #endif /* HAVE_POPEN */ @@ -619,412 +619,412 @@ shellcmd(cmd) /* * Expand a filename, doing any system-specific metacharacter substitutions. */ - public char * + public char * lglob(filename) - char *filename; + char *filename; { - char *gfilename; + char *gfilename; - filename = fexpand(filename); - if (secure) - return (filename); + filename = fexpand(filename); + if (secure) + return (filename); #ifdef DECL_GLOB_LIST { - /* - * The globbing function returns a list of names. - */ - int length; - char *p; - char *qfilename; - DECL_GLOB_LIST(list) - - GLOB_LIST(filename, list); - if (GLOB_LIST_FAILED(list)) - { - return (filename); - } - length = 1; /* Room for trailing null byte */ - for (SCAN_GLOB_LIST(list, p)) - { - INIT_GLOB_LIST(list, p); - qfilename = shell_quote(p); - if (qfilename != NULL) - { - length += strlen(qfilename) + 1; - free(qfilename); - } - } - gfilename = (char *) ecalloc(length, sizeof(char)); - for (SCAN_GLOB_LIST(list, p)) - { - INIT_GLOB_LIST(list, p); - qfilename = shell_quote(p); - if (qfilename != NULL) - { - sprintf(gfilename + strlen(gfilename), "%s ", qfilename); - free(qfilename); - } - } - /* - * Overwrite the final trailing space with a null terminator. - */ - *--p = '\0'; - GLOB_LIST_DONE(list); + /* + * The globbing function returns a list of names. + */ + int length; + char *p; + char *qfilename; + DECL_GLOB_LIST(list) + + GLOB_LIST(filename, list); + if (GLOB_LIST_FAILED(list)) + { + return (filename); + } + length = 1; /* Room for trailing null byte */ + for (SCAN_GLOB_LIST(list, p)) + { + INIT_GLOB_LIST(list, p); + qfilename = shell_quote(p); + if (qfilename != NULL) + { + length += strlen(qfilename) + 1; + free(qfilename); + } + } + gfilename = (char *) ecalloc(length, sizeof(char)); + for (SCAN_GLOB_LIST(list, p)) + { + INIT_GLOB_LIST(list, p); + qfilename = shell_quote(p); + if (qfilename != NULL) + { + sprintf(gfilename + strlen(gfilename), "%s ", qfilename); + free(qfilename); + } + } + /* + * Overwrite the final trailing space with a null terminator. + */ + *--p = '\0'; + GLOB_LIST_DONE(list); } #else #ifdef DECL_GLOB_NAME { - /* - * The globbing function returns a single name, and - * is called multiple times to walk thru all names. - */ - char *p; - int len; - int n; - char *pfilename; - char *qfilename; - DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) - - GLOB_FIRST_NAME(filename, &fnd, handle); - if (GLOB_FIRST_FAILED(handle)) - { - return (filename); - } - - _splitpath(filename, drive, dir, fname, ext); - len = 100; - gfilename = (char *) ecalloc(len, sizeof(char)); - p = gfilename; - do { - n = (int) (strlen(drive) + strlen(dir) + strlen(fnd.GLOB_NAME) + 1); - pfilename = (char *) ecalloc(n, sizeof(char)); - SNPRINTF3(pfilename, n, "%s%s%s", drive, dir, fnd.GLOB_NAME); - qfilename = shell_quote(pfilename); - free(pfilename); - if (qfilename != NULL) - { - n = (int) strlen(qfilename); - while (p - gfilename + n + 2 >= len) - { - /* - * No room in current buffer. - * Allocate a bigger one. - */ - len *= 2; - *p = '\0'; - p = (char *) ecalloc(len, sizeof(char)); - strcpy(p, gfilename); - free(gfilename); - gfilename = p; - p = gfilename + strlen(gfilename); - } - strcpy(p, qfilename); - free(qfilename); - p += n; - *p++ = ' '; - } - } while (GLOB_NEXT_NAME(handle, &fnd) == 0); - - /* - * Overwrite the final trailing space with a null terminator. - */ - *--p = '\0'; - GLOB_NAME_DONE(handle); + /* + * The globbing function returns a single name, and + * is called multiple times to walk thru all names. + */ + char *p; + int len; + int n; + char *pfilename; + char *qfilename; + DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) + + GLOB_FIRST_NAME(filename, &fnd, handle); + if (GLOB_FIRST_FAILED(handle)) + { + return (filename); + } + + _splitpath(filename, drive, dir, fname, ext); + len = 100; + gfilename = (char *) ecalloc(len, sizeof(char)); + p = gfilename; + do { + n = (int) (strlen(drive) + strlen(dir) + strlen(fnd.GLOB_NAME) + 1); + pfilename = (char *) ecalloc(n, sizeof(char)); + SNPRINTF3(pfilename, n, "%s%s%s", drive, dir, fnd.GLOB_NAME); + qfilename = shell_quote(pfilename); + free(pfilename); + if (qfilename != NULL) + { + n = (int) strlen(qfilename); + while (p - gfilename + n + 2 >= len) + { + /* + * No room in current buffer. + * Allocate a bigger one. + */ + len *= 2; + *p = '\0'; + p = (char *) ecalloc(len, sizeof(char)); + strcpy(p, gfilename); + free(gfilename); + gfilename = p; + p = gfilename + strlen(gfilename); + } + strcpy(p, qfilename); + free(qfilename); + p += n; + *p++ = ' '; + } + } while (GLOB_NEXT_NAME(handle, &fnd) == 0); + + /* + * Overwrite the final trailing space with a null terminator. + */ + *--p = '\0'; + GLOB_NAME_DONE(handle); } #else #if HAVE_POPEN { - /* - * We get the shell to glob the filename for us by passing - * an "echo" command to the shell and reading its output. - */ - FILE *fd; - char *s; - char *lessecho; - char *cmd; - char *esc; - int len; - - esc = get_meta_escape(); - if (strlen(esc) == 0) - esc = "-"; - esc = shell_quote(esc); - if (esc == NULL) - { - return (filename); - } - lessecho = lgetenv("LESSECHO"); - if (isnullenv(lessecho)) - lessecho = "lessecho"; - /* - * Invoke lessecho, and read its output (a globbed list of filenames). - */ - len = (int) (strlen(lessecho) + strlen(filename) + (7*strlen(metachars())) + 24); - cmd = (char *) ecalloc(len, sizeof(char)); - SNPRINTF4(cmd, len, "%s -p0x%x -d0x%x -e%s ", lessecho, openquote, closequote, esc); - free(esc); - for (s = metachars(); *s != '\0'; s++) - sprintf(cmd + strlen(cmd), "-n0x%x ", *s); - sprintf(cmd + strlen(cmd), "-- %s", filename); - fd = shellcmd(cmd); - free(cmd); - if (fd == NULL) - { - /* - * Cannot create the pipe. - * Just return the original (fexpanded) filename. - */ - return (filename); - } - gfilename = readfd(fd); - pclose(fd); - if (*gfilename == '\0') - { - free(gfilename); - return (filename); - } + /* + * We get the shell to glob the filename for us by passing + * an "echo" command to the shell and reading its output. + */ + FILE *fd; + char *s; + char *lessecho; + char *cmd; + char *esc; + int len; + + esc = get_meta_escape(); + if (strlen(esc) == 0) + esc = "-"; + esc = shell_quote(esc); + if (esc == NULL) + { + return (filename); + } + lessecho = lgetenv("LESSECHO"); + if (isnullenv(lessecho)) + lessecho = "lessecho"; + /* + * Invoke lessecho, and read its output (a globbed list of filenames). + */ + len = (int) (strlen(lessecho) + strlen(filename) + (7*strlen(metachars())) + 24); + cmd = (char *) ecalloc(len, sizeof(char)); + SNPRINTF4(cmd, len, "%s -p0x%x -d0x%x -e%s ", lessecho, openquote, closequote, esc); + free(esc); + for (s = metachars(); *s != '\0'; s++) + sprintf(cmd + strlen(cmd), "-n0x%x ", *s); + sprintf(cmd + strlen(cmd), "-- %s", filename); + fd = shellcmd(cmd); + free(cmd); + if (fd == NULL) + { + /* + * Cannot create the pipe. + * Just return the original (fexpanded) filename. + */ + return (filename); + } + gfilename = readfd(fd); + pclose(fd); + if (*gfilename == '\0') + { + free(gfilename); + return (filename); + } } #else - /* - * No globbing functions at all. Just use the fexpanded filename. - */ - gfilename = save(filename); + /* + * No globbing functions at all. Just use the fexpanded filename. + */ + gfilename = save(filename); #endif #endif #endif - free(filename); - return (gfilename); + free(filename); + return (gfilename); } /* * Return canonical pathname. */ - public char * + public char * lrealpath(path) - char *path; + char *path; { #if HAVE_REALPATH - char rpath[PATH_MAX]; - if (realpath(path, rpath) != NULL) - return (save(rpath)); + char rpath[PATH_MAX]; + if (realpath(path, rpath) != NULL) + return (save(rpath)); #endif - return (save(path)); + return (save(path)); } /* * Return number of %s escapes in a string. * Return a large number if there are any other % escapes besides %s. */ - static int + static int num_pct_s(lessopen) - char *lessopen; + char *lessopen; { - int num = 0; - - while (*lessopen != '\0') - { - if (*lessopen == '%') - { - if (lessopen[1] == '%') - ++lessopen; - else if (lessopen[1] == 's') - ++num; - else - return (999); - } - ++lessopen; - } - return (num); + int num = 0; + + while (*lessopen != '\0') + { + if (*lessopen == '%') + { + if (lessopen[1] == '%') + ++lessopen; + else if (lessopen[1] == 's') + ++num; + else + return (999); + } + ++lessopen; + } + return (num); } /* - * See if we should open a "replacement file" + * See if we should open a "replacement file" * instead of the file we're about to open. */ - public char * + public char * open_altfile(filename, pf, pfd) - char *filename; - int *pf; - void **pfd; + char *filename; + int *pf; + void **pfd; { #if !HAVE_POPEN - return (NULL); + return (NULL); #else - char *lessopen; - char *qfilename; - char *cmd; - int len; - FILE *fd; + char *lessopen; + char *qfilename; + char *cmd; + int len; + FILE *fd; #if HAVE_FILENO - int returnfd = 0; + int returnfd = 0; #endif - - if (!use_lessopen || secure) - return (NULL); - ch_ungetchar(-1); - if ((lessopen = lgetenv("LESSOPEN")) == NULL) - return (NULL); - while (*lessopen == '|') - { - /* - * If LESSOPEN starts with a |, it indicates - * a "pipe preprocessor". - */ + + if (!use_lessopen || secure) + return (NULL); + ch_ungetchar(-1); + if ((lessopen = lgetenv("LESSOPEN")) == NULL) + return (NULL); + while (*lessopen == '|') + { + /* + * If LESSOPEN starts with a |, it indicates + * a "pipe preprocessor". + */ #if !HAVE_FILENO - error("LESSOPEN pipe is not supported", NULL_PARG); - return (NULL); + error("LESSOPEN pipe is not supported", NULL_PARG); + return (NULL); #else - lessopen++; - returnfd++; + lessopen++; + returnfd++; #endif - } - if (*lessopen == '-') - { - /* - * Lessopen preprocessor will accept "-" as a filename. - */ - lessopen++; - } else - { - if (strcmp(filename, "-") == 0) - return (NULL); - } - if (num_pct_s(lessopen) != 1) - { - error("LESSOPEN ignored: must contain exactly one %%s", NULL_PARG); - return (NULL); - } - - qfilename = shell_quote(filename); - len = (int) (strlen(lessopen) + strlen(qfilename) + 2); - cmd = (char *) ecalloc(len, sizeof(char)); - SNPRINTF1(cmd, len, lessopen, qfilename); - free(qfilename); - fd = shellcmd(cmd); - free(cmd); - if (fd == NULL) - { - /* - * Cannot create the pipe. - */ - return (NULL); - } + } + if (*lessopen == '-') + { + /* + * Lessopen preprocessor will accept "-" as a filename. + */ + lessopen++; + } else + { + if (strcmp(filename, "-") == 0) + return (NULL); + } + if (num_pct_s(lessopen) != 1) + { + error("LESSOPEN ignored: must contain exactly one %%s", NULL_PARG); + return (NULL); + } + + qfilename = shell_quote(filename); + len = (int) (strlen(lessopen) + strlen(qfilename) + 2); + cmd = (char *) ecalloc(len, sizeof(char)); + SNPRINTF1(cmd, len, lessopen, qfilename); + free(qfilename); + fd = shellcmd(cmd); + free(cmd); + if (fd == NULL) + { + /* + * Cannot create the pipe. + */ + return (NULL); + } #if HAVE_FILENO - if (returnfd) - { - char c; - int f; - - /* - * The alt file is a pipe. Read one char - * to see if the pipe will produce any data. - * If it does, push the char back on the pipe. - */ - f = fileno(fd); - SET_BINARY(f); - if (read(f, &c, 1) != 1) - { - /* - * Pipe is empty. - * If more than 1 pipe char was specified, - * the exit status tells whether the file itself - * is empty, or if there is no alt file. - * If only one pipe char, just assume no alt file. - */ - int status = pclose(fd); - if (returnfd > 1 && status == 0) { - /* File is empty. */ - *pfd = NULL; - *pf = -1; - return (save(FAKE_EMPTYFILE)); - } - /* No alt file. */ - return (NULL); - } - /* Alt pipe contains data, so use it. */ - ch_ungetchar(c); - *pfd = (void *) fd; - *pf = f; - return (save("-")); - } + if (returnfd) + { + char c; + int f; + + /* + * The alt file is a pipe. Read one char + * to see if the pipe will produce any data. + * If it does, push the char back on the pipe. + */ + f = fileno(fd); + SET_BINARY(f); + if (read(f, &c, 1) != 1) + { + /* + * Pipe is empty. + * If more than 1 pipe char was specified, + * the exit status tells whether the file itself + * is empty, or if there is no alt file. + * If only one pipe char, just assume no alt file. + */ + int status = pclose(fd); + if (returnfd > 1 && status == 0) { + /* File is empty. */ + *pfd = NULL; + *pf = -1; + return (save(FAKE_EMPTYFILE)); + } + /* No alt file. */ + return (NULL); + } + /* Alt pipe contains data, so use it. */ + ch_ungetchar(c); + *pfd = (void *) fd; + *pf = f; + return (save("-")); + } #endif - /* The alt file is a regular file. Read its name from LESSOPEN. */ - cmd = readfd(fd); - pclose(fd); - if (*cmd == '\0') - /* - * Pipe is empty. This means there is no alt file. - */ - return (NULL); - return (cmd); + /* The alt file is a regular file. Read its name from LESSOPEN. */ + cmd = readfd(fd); + pclose(fd); + if (*cmd == '\0') + /* + * Pipe is empty. This means there is no alt file. + */ + return (NULL); + return (cmd); #endif /* HAVE_POPEN */ } /* * Close a replacement file. */ - public void + public void close_altfile(altfilename, filename) - char *altfilename; - char *filename; + char *altfilename; + char *filename; { #if HAVE_POPEN - char *lessclose; - FILE *fd; - char *cmd; - int len; - - if (secure) - return; - ch_ungetchar(-1); - if ((lessclose = lgetenv("LESSCLOSE")) == NULL) - return; - if (num_pct_s(lessclose) > 2) - { - error("LESSCLOSE ignored; must contain no more than 2 %%s", NULL_PARG); - return; - } - len = (int) (strlen(lessclose) + strlen(filename) + strlen(altfilename) + 2); - cmd = (char *) ecalloc(len, sizeof(char)); - SNPRINTF2(cmd, len, lessclose, filename, altfilename); - fd = shellcmd(cmd); - free(cmd); - if (fd != NULL) - pclose(fd); + char *lessclose; + FILE *fd; + char *cmd; + int len; + + if (secure) + return; + ch_ungetchar(-1); + if ((lessclose = lgetenv("LESSCLOSE")) == NULL) + return; + if (num_pct_s(lessclose) > 2) + { + error("LESSCLOSE ignored; must contain no more than 2 %%s", NULL_PARG); + return; + } + len = (int) (strlen(lessclose) + strlen(filename) + strlen(altfilename) + 2); + cmd = (char *) ecalloc(len, sizeof(char)); + SNPRINTF2(cmd, len, lessclose, filename, altfilename); + fd = shellcmd(cmd); + free(cmd); + if (fd != NULL) + pclose(fd); #endif } - + /* * Is the specified file a directory? */ - public int + public int is_dir(filename) - char *filename; + char *filename; { - int isdir = 0; + int isdir = 0; #if HAVE_STAT { - int r; - struct stat statbuf; + int r; + struct stat statbuf; - r = stat(filename, &statbuf); - isdir = (r >= 0 && S_ISDIR(statbuf.st_mode)); + r = stat(filename, &statbuf); + isdir = (r >= 0 && S_ISDIR(statbuf.st_mode)); } #else #ifdef _OSK { - int f; + int f; - f = open(filename, S_IREAD | S_IFDIR); - if (f >= 0) - close(f); - isdir = (f >= 0); + f = open(filename, S_IREAD | S_IFDIR); + if (f >= 0) + close(f); + isdir = (f >= 0); } #endif #endif - return (isdir); + return (isdir); } /* @@ -1032,94 +1032,93 @@ is_dir(filename) * is an ordinary file, otherwise an error message * (if it cannot be opened or is a directory, etc.) */ - public char * + public char * bad_file(filename) - char *filename; + char *filename; { - char *m = NULL; - - if (!force_open && is_dir(filename)) - { - static char is_a_dir[] = " is a directory"; - - m = (char *) ecalloc(strlen(filename) + sizeof(is_a_dir), - sizeof(char)); - strcpy(m, filename); - strcat(m, is_a_dir); - } else - { + char *m = NULL; + + if (!force_open && is_dir(filename)) + { + static char is_a_dir[] = " is a directory"; + + m = (char *) ecalloc(strlen(filename) + sizeof(is_a_dir), + sizeof(char)); + strcpy(m, filename); + strcat(m, is_a_dir); + } else + { #if HAVE_STAT - int r; - struct stat statbuf; - - r = stat(filename, &statbuf); - if (r < 0) - { - m = errno_message(filename); - } else if (force_open) - { - m = NULL; - } else if (!S_ISREG(statbuf.st_mode)) - { - static char not_reg[] = " is not a regular file (use -f to see it)"; - m = (char *) ecalloc(strlen(filename) + sizeof(not_reg), - sizeof(char)); - strcpy(m, filename); - strcat(m, not_reg); - } + int r; + struct stat statbuf; + + r = stat(filename, &statbuf); + if (r < 0) + { + m = errno_message(filename); + } else if (force_open) + { + m = NULL; + } else if (!S_ISREG(statbuf.st_mode)) + { + static char not_reg[] = " is not a regular file (use -f to see it)"; + m = (char *) ecalloc(strlen(filename) + sizeof(not_reg), + sizeof(char)); + strcpy(m, filename); + strcat(m, not_reg); + } #endif - } - return (m); + } + return (m); } /* * Return the size of a file, as cheaply as possible. * In Unix, we can stat the file. */ - public POSITION + public POSITION filesize(f) - int f; + int f; { #if HAVE_STAT - struct stat statbuf; + struct stat statbuf; - if (fstat(f, &statbuf) >= 0) - return ((POSITION) statbuf.st_size); + if (fstat(f, &statbuf) >= 0) + return ((POSITION) statbuf.st_size); #else #ifdef _OSK - long size; + long size; - if ((size = (long) _gs_size(f)) >= 0) - return ((POSITION) size); + if ((size = (long) _gs_size(f)) >= 0) + return ((POSITION) size); #endif #endif - return (seek_filesize(f)); + return (seek_filesize(f)); } /* - * + * */ - public char * + public char * shell_coption(VOID_PARAM) { - return ("-c"); + return ("-c"); } /* * Return last component of a pathname. */ - public char * + public char * last_component(name) - char *name; + char *name; { - char *slash; - - for (slash = name + strlen(name); slash > name; ) - { - --slash; - if (*slash == *PATHNAME_SEP || *slash == '/') - return (slash + 1); - } - return (name); + char *slash; + + for (slash = name + strlen(name); slash > name; ) + { + --slash; + if (*slash == *PATHNAME_SEP || *slash == '/') + return (slash + 1); + } + return (name); } - diff --git a/fmt.uni b/fmt.uni index bef4227..6766505 100644 --- a/fmt.uni +++ b/fmt.uni @@ -1,21 +1,21 @@ /* Generated by "./mkutable -f2 Cf -- unicode/UnicodeData.txt" on Tue May 19 14:47:34 PDT 2020 */ - { 0x00ad, 0x00ad }, /* Cf */ - { 0x0600, 0x0605 }, /* Cf */ - { 0x061c, 0x061c }, /* Cf */ - { 0x06dd, 0x06dd }, /* Cf */ - { 0x070f, 0x070f }, /* Cf */ - { 0x08e2, 0x08e2 }, /* Cf */ - { 0x180e, 0x180e }, /* Cf */ - { 0x200b, 0x200f }, /* Cf */ - { 0x202a, 0x202e }, /* Cf */ - { 0x2060, 0x2064 }, /* Cf */ - { 0x2066, 0x206f }, /* Cf */ - { 0xfeff, 0xfeff }, /* Cf */ - { 0xfff9, 0xfffb }, /* Cf */ - { 0x110bd, 0x110bd }, /* Cf */ - { 0x110cd, 0x110cd }, /* Cf */ - { 0x13430, 0x13438 }, /* Cf */ - { 0x1bca0, 0x1bca3 }, /* Cf */ - { 0x1d173, 0x1d17a }, /* Cf */ - { 0xe0001, 0xe0001 }, /* Cf */ - { 0xe0020, 0xe007f }, /* Cf */ + { 0x00ad, 0x00ad }, /* Cf */ + { 0x0600, 0x0605 }, /* Cf */ + { 0x061c, 0x061c }, /* Cf */ + { 0x06dd, 0x06dd }, /* Cf */ + { 0x070f, 0x070f }, /* Cf */ + { 0x08e2, 0x08e2 }, /* Cf */ + { 0x180e, 0x180e }, /* Cf */ + { 0x200b, 0x200f }, /* Cf */ + { 0x202a, 0x202e }, /* Cf */ + { 0x2060, 0x2064 }, /* Cf */ + { 0x2066, 0x206f }, /* Cf */ + { 0xfeff, 0xfeff }, /* Cf */ + { 0xfff9, 0xfffb }, /* Cf */ + { 0x110bd, 0x110bd }, /* Cf */ + { 0x110cd, 0x110cd }, /* Cf */ + { 0x13430, 0x13438 }, /* Cf */ + { 0x1bca0, 0x1bca3 }, /* Cf */ + { 0x1d173, 0x1d17a }, /* Cf */ + { 0xe0001, 0xe0001 }, /* Cf */ + { 0xe0020, 0xe007f }, /* Cf */ diff --git a/forwback.c b/forwback.c index e72172b..f1818d2 100644 --- a/forwback.c +++ b/forwback.c @@ -44,64 +44,64 @@ extern char *tagoption; /* * Sound the bell to indicate user is trying to move past end of file. */ - static void + static void eof_bell(VOID_PARAM) { #if HAVE_TIME - static time_type last_eof_bell = 0; - time_type now = get_time(); - if (now == last_eof_bell) /* max once per second */ - return; - last_eof_bell = now; + static time_type last_eof_bell = 0; + time_type now = get_time(); + if (now == last_eof_bell) /* max once per second */ + return; + last_eof_bell = now; #endif - if (quiet == NOT_QUIET) - bell(); - else - vbell(); + if (quiet == NOT_QUIET) + bell(); + else + vbell(); } /* * Check to see if the end of file is currently displayed. */ - public int + public int eof_displayed(VOID_PARAM) { - POSITION pos; - - if (ignore_eoi) - return (0); - - if (ch_length() == NULL_POSITION) - /* - * If the file length is not known, - * we can't possibly be displaying EOF. - */ - return (0); - - /* - * If the bottom line is empty, we are at EOF. - * If the bottom line ends at the file length, - * we must be just at EOF. - */ - pos = position(BOTTOM_PLUS_ONE); - return (pos == NULL_POSITION || pos == ch_length()); + POSITION pos; + + if (ignore_eoi) + return (0); + + if (ch_length() == NULL_POSITION) + /* + * If the file length is not known, + * we can't possibly be displaying EOF. + */ + return (0); + + /* + * If the bottom line is empty, we are at EOF. + * If the bottom line ends at the file length, + * we must be just at EOF. + */ + pos = position(BOTTOM_PLUS_ONE); + return (pos == NULL_POSITION || pos == ch_length()); } /* * Check to see if the entire file is currently displayed. */ - public int + public int entire_file_displayed(VOID_PARAM) { - POSITION pos; + POSITION pos; - /* Make sure last line of file is displayed. */ - if (!eof_displayed()) - return (0); + /* Make sure last line of file is displayed. */ + if (!eof_displayed()) + return (0); - /* Make sure first line of file is displayed. */ - pos = position(0); - return (pos == NULL_POSITION || pos == 0); + /* Make sure first line of file is displayed. */ + pos = position(0); + return (pos == NULL_POSITION || pos == 0); } /* @@ -110,17 +110,17 @@ entire_file_displayed(VOID_PARAM) * of the screen; this can happen when we display a short file * for the first time. */ - public void + public void squish_check(VOID_PARAM) { - if (!squished) - return; - squished = 0; - repaint(); + if (!squished) + return; + squished = 0; + repaint(); } /* - * Display n lines, scrolling forward, + * Display n lines, scrolling forward, * starting at position pos in the input file. * "force" means display the n lines even if we hit end of file. * "only_last" means display only the last screenful if n > screen size. @@ -128,309 +128,309 @@ squish_check(VOID_PARAM) * real line. If nblank > 0, the pos must be NULL_POSITION. * The first real line after the blanks will start at ch_zero(). */ - public void + public void forw(n, pos, force, only_last, nblank) - int n; - POSITION pos; - int force; - int only_last; - int nblank; + int n; + POSITION pos; + int force; + int only_last; + int nblank; { - int nlines = 0; - int do_repaint; - static int first_time = 1; - - squish_check(); - - /* - * do_repaint tells us not to display anything till the end, - * then just repaint the entire screen. - * We repaint if we are supposed to display only the last - * screenful and the request is for more than a screenful. - * Also if the request exceeds the forward scroll limit - * (but not if the request is for exactly a screenful, since - * repainting itself involves scrolling forward a screenful). - */ - do_repaint = (only_last && n > sc_height-1) || - (forw_scroll >= 0 && n > forw_scroll && n != sc_height-1); + int nlines = 0; + int do_repaint; + static int first_time = 1; + + squish_check(); + + /* + * do_repaint tells us not to display anything till the end, + * then just repaint the entire screen. + * We repaint if we are supposed to display only the last + * screenful and the request is for more than a screenful. + * Also if the request exceeds the forward scroll limit + * (but not if the request is for exactly a screenful, since + * repainting itself involves scrolling forward a screenful). + */ + do_repaint = (only_last && n > sc_height-1) || + (forw_scroll >= 0 && n > forw_scroll && n != sc_height-1); #if HILITE_SEARCH - if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) { - prep_hilite(pos, pos + 4*size_linebuf, ignore_eoi ? 1 : -1); - pos = next_unfiltered(pos); - } + if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) { + prep_hilite(pos, pos + 4*size_linebuf, ignore_eoi ? 1 : -1); + pos = next_unfiltered(pos); + } #endif - if (!do_repaint) - { - if (top_scroll && n >= sc_height - 1 && pos != ch_length()) - { - /* - * Start a new screen. - * {{ This is not really desirable if we happen - * to hit eof in the middle of this screen, - * but we don't yet know if that will happen. }} - */ - pos_clear(); - add_forw_pos(pos); - force = 1; - clear(); - home(); - } - - if (pos != position(BOTTOM_PLUS_ONE) || empty_screen()) - { - /* - * This is not contiguous with what is - * currently displayed. Clear the screen image - * (position table) and start a new screen. - */ - pos_clear(); - add_forw_pos(pos); - force = 1; - if (top_scroll) - { - clear(); - home(); - } else if (!first_time && !is_filtering()) - { - putstr("...skipping...\n"); - } - } - } - - while (--n >= 0) - { - /* - * Read the next line of input. - */ - if (nblank > 0) - { - /* - * Still drawing blanks; don't get a line - * from the file yet. - * If this is the last blank line, get ready to - * read a line starting at ch_zero() next time. - */ - if (--nblank == 0) - pos = ch_zero(); - } else - { - /* - * Get the next line from the file. - */ - pos = forw_line(pos); + if (!do_repaint) + { + if (top_scroll && n >= sc_height - 1 && pos != ch_length()) + { + /* + * Start a new screen. + * {{ This is not really desirable if we happen + * to hit eof in the middle of this screen, + * but we don't yet know if that will happen. }} + */ + pos_clear(); + add_forw_pos(pos); + force = 1; + clear(); + home(); + } + + if (pos != position(BOTTOM_PLUS_ONE) || empty_screen()) + { + /* + * This is not contiguous with what is + * currently displayed. Clear the screen image + * (position table) and start a new screen. + */ + pos_clear(); + add_forw_pos(pos); + force = 1; + if (top_scroll) + { + clear(); + home(); + } else if (!first_time && !is_filtering()) + { + putstr("...skipping...\n"); + } + } + } + + while (--n >= 0) + { + /* + * Read the next line of input. + */ + if (nblank > 0) + { + /* + * Still drawing blanks; don't get a line + * from the file yet. + * If this is the last blank line, get ready to + * read a line starting at ch_zero() next time. + */ + if (--nblank == 0) + pos = ch_zero(); + } else + { + /* + * Get the next line from the file. + */ + pos = forw_line(pos); #if HILITE_SEARCH - pos = next_unfiltered(pos); + pos = next_unfiltered(pos); #endif - if (pos == NULL_POSITION) - { - /* - * End of file: stop here unless the top line - * is still empty, or "force" is true. - * Even if force is true, stop when the last - * line in the file reaches the top of screen. - */ - if (!force && position(TOP) != NULL_POSITION) - break; - if (!empty_lines(0, 0) && - !empty_lines(1, 1) && - empty_lines(2, sc_height-1)) - break; - } - } - /* - * Add the position of the next line to the position table. - * Display the current line on the screen. - */ - add_forw_pos(pos); - nlines++; - if (do_repaint) - continue; - /* - * If this is the first screen displayed and - * we hit an early EOF (i.e. before the requested - * number of lines), we "squish" the display down - * at the bottom of the screen. - * But don't do this if a + option or a -t option - * was given. These options can cause us to - * start the display after the beginning of the file, - * and it is not appropriate to squish in that case. - */ - if (first_time && pos == NULL_POSITION && !top_scroll && + if (pos == NULL_POSITION) + { + /* + * End of file: stop here unless the top line + * is still empty, or "force" is true. + * Even if force is true, stop when the last + * line in the file reaches the top of screen. + */ + if (!force && position(TOP) != NULL_POSITION) + break; + if (!empty_lines(0, 0) && + !empty_lines(1, 1) && + empty_lines(2, sc_height-1)) + break; + } + } + /* + * Add the position of the next line to the position table. + * Display the current line on the screen. + */ + add_forw_pos(pos); + nlines++; + if (do_repaint) + continue; + /* + * If this is the first screen displayed and + * we hit an early EOF (i.e. before the requested + * number of lines), we "squish" the display down + * at the bottom of the screen. + * But don't do this if a + option or a -t option + * was given. These options can cause us to + * start the display after the beginning of the file, + * and it is not appropriate to squish in that case. + */ + if (first_time && pos == NULL_POSITION && !top_scroll && #if TAGS - tagoption == NULL && + tagoption == NULL && #endif - !plusoption) - { - squished = 1; - continue; - } - put_line(); + !plusoption) + { + squished = 1; + continue; + } + put_line(); #if 0 - /* {{ - * Can't call clear_eol here. The cursor might be at end of line - * on an ignaw terminal, so clear_eol would clear the last char - * of the current line instead of all of the next line. - * If we really need to do this on clear_bg terminals, we need - * to find a better way. - * }} - */ - if (clear_bg && apply_at_specials(final_attr) != AT_NORMAL) - { - /* - * Writing the last character on the last line - * of the display may have scrolled the screen. - * If we were in standout mode, clear_bg terminals - * will fill the new line with the standout color. - * Now we're in normal mode again, so clear the line. - */ - clear_eol(); - } + /* {{ + * Can't call clear_eol here. The cursor might be at end of line + * on an ignaw terminal, so clear_eol would clear the last char + * of the current line instead of all of the next line. + * If we really need to do this on clear_bg terminals, we need + * to find a better way. + * }} + */ + if (clear_bg && apply_at_specials(final_attr) != AT_NORMAL) + { + /* + * Writing the last character on the last line + * of the display may have scrolled the screen. + * If we were in standout mode, clear_bg terminals + * will fill the new line with the standout color. + * Now we're in normal mode again, so clear the line. + */ + clear_eol(); + } #endif - forw_prompt = 1; - } - - if (nlines == 0 && !ignore_eoi) - eof_bell(); - else if (do_repaint) - repaint(); - first_time = 0; - (void) currline(BOTTOM); + forw_prompt = 1; + } + + if (nlines == 0 && !ignore_eoi) + eof_bell(); + else if (do_repaint) + repaint(); + first_time = 0; + (void) currline(BOTTOM); } /* * Display n lines, scrolling backward. */ - public void + public void back(n, pos, force, only_last) - int n; - POSITION pos; - int force; - int only_last; + int n; + POSITION pos; + int force; + int only_last; { - int nlines = 0; - int do_repaint; + int nlines = 0; + int do_repaint; - squish_check(); - do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1)); + squish_check(); + do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1)); #if HILITE_SEARCH - if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) { - prep_hilite((pos < 3*size_linebuf) ? 0 : pos - 3*size_linebuf, pos, -1); - } + if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) { + prep_hilite((pos < 3*size_linebuf) ? 0 : pos - 3*size_linebuf, pos, -1); + } #endif - while (--n >= 0) - { - /* - * Get the previous line of input. - */ + while (--n >= 0) + { + /* + * Get the previous line of input. + */ #if HILITE_SEARCH - pos = prev_unfiltered(pos); + pos = prev_unfiltered(pos); #endif - pos = back_line(pos); - if (pos == NULL_POSITION) - { - /* - * Beginning of file: stop here unless "force" is true. - */ - if (!force) - break; - } - /* - * Add the position of the previous line to the position table. - * Display the line on the screen. - */ - add_back_pos(pos); - nlines++; - if (!do_repaint) - { - home(); - add_line(); - put_line(); - } - } - - if (nlines == 0) - eof_bell(); - else if (do_repaint) - repaint(); - else if (!oldbot) - lower_left(); - (void) currline(BOTTOM); + pos = back_line(pos); + if (pos == NULL_POSITION) + { + /* + * Beginning of file: stop here unless "force" is true. + */ + if (!force) + break; + } + /* + * Add the position of the previous line to the position table. + * Display the line on the screen. + */ + add_back_pos(pos); + nlines++; + if (!do_repaint) + { + home(); + add_line(); + put_line(); + } + } + + if (nlines == 0) + eof_bell(); + else if (do_repaint) + repaint(); + else if (!oldbot) + lower_left(); + (void) currline(BOTTOM); } /* * Display n more lines, forward. * Start just after the line currently displayed at the bottom of the screen. */ - public void + public void forward(n, force, only_last) - int n; - int force; - int only_last; + int n; + int force; + int only_last; { - POSITION pos; - - if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE)) - { - /* - * If the -e flag is set and we're trying to go - * forward from end-of-file, go on to the next file. - */ - if (edit_next(1)) - quit(QUIT_OK); - return; - } - - pos = position(BOTTOM_PLUS_ONE); - if (pos == NULL_POSITION && (!force || empty_lines(2, sc_height-1))) - { - if (ignore_eoi) - { - /* - * ignore_eoi is to support A_F_FOREVER. - * Back up until there is a line at the bottom - * of the screen. - */ - if (empty_screen()) - pos = ch_zero(); - else - { - do - { - back(1, position(TOP), 1, 0); - pos = position(BOTTOM_PLUS_ONE); - } while (pos == NULL_POSITION); - } - } else - { - eof_bell(); - return; - } - } - forw(n, pos, force, only_last, 0); + POSITION pos; + + if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE)) + { + /* + * If the -e flag is set and we're trying to go + * forward from end-of-file, go on to the next file. + */ + if (edit_next(1)) + quit(QUIT_OK); + return; + } + + pos = position(BOTTOM_PLUS_ONE); + if (pos == NULL_POSITION && (!force || empty_lines(2, sc_height-1))) + { + if (ignore_eoi) + { + /* + * ignore_eoi is to support A_F_FOREVER. + * Back up until there is a line at the bottom + * of the screen. + */ + if (empty_screen()) + pos = ch_zero(); + else + { + do + { + back(1, position(TOP), 1, 0); + pos = position(BOTTOM_PLUS_ONE); + } while (pos == NULL_POSITION); + } + } else + { + eof_bell(); + return; + } + } + forw(n, pos, force, only_last, 0); } /* * Display n more lines, backward. * Start just before the line currently displayed at the top of the screen. */ - public void + public void backward(n, force, only_last) - int n; - int force; - int only_last; + int n; + int force; + int only_last; { - POSITION pos; - - pos = position(TOP); - if (pos == NULL_POSITION && (!force || position(BOTTOM) == 0)) - { - eof_bell(); - return; - } - back(n, pos, force, only_last); + POSITION pos; + + pos = position(TOP); + if (pos == NULL_POSITION && (!force || position(BOTTOM) == 0)) + { + eof_bell(); + return; + } + back(n, pos, force, only_last); } /* @@ -439,31 +439,31 @@ backward(n, force, only_last) * back_scroll, because the default case depends on sc_height and * top_scroll, as well as back_scroll. */ - public int + public int get_back_scroll(VOID_PARAM) { - if (no_back_scroll) - return (0); - if (back_scroll >= 0) - return (back_scroll); - if (top_scroll) - return (sc_height - 2); - return (10000); /* infinity */ + if (no_back_scroll) + return (0); + if (back_scroll >= 0) + return (back_scroll); + if (top_scroll) + return (sc_height - 2); + return (10000); /* infinity */ } /* * Will the entire file fit on one screen? */ - public int + public int get_one_screen(VOID_PARAM) { - int nlines; - POSITION pos = ch_zero(); - - for (nlines = 0; nlines < sc_height; nlines++) - { - pos = forw_line(pos); - if (pos == NULL_POSITION) break; - } - return (nlines < sc_height); + int nlines; + POSITION pos = ch_zero(); + + for (nlines = 0; nlines < sc_height; nlines++) + { + pos = forw_line(pos); + if (pos == NULL_POSITION) break; + } + return (nlines < sc_height); } diff --git a/ifile.c b/ifile.c index bc47a66..675195f 100644 --- a/ifile.c +++ b/ifile.c @@ -13,7 +13,7 @@ * * It is actually a pointer to an ifile structure, * but is opaque outside this module. - * Ifile structures are kept in a linked list in the order they + * Ifile structures are kept in a linked list in the order they * appear on the command line. * Any new file which does not already appear in the list is * inserted after the current file. @@ -24,17 +24,17 @@ extern IFILE curr_ifile; struct ifile { - struct ifile *h_next; /* Links for command line list */ - struct ifile *h_prev; - char *h_filename; /* Name of the file */ - char *h_rfilename; /* Canonical name of the file */ - void *h_filestate; /* File state (used in ch.c) */ - int h_index; /* Index within command line list */ - int h_hold; /* Hold count */ - char h_opened; /* Has this ifile been opened? */ - struct scrpos h_scrpos; /* Saved position within the file */ - void *h_altpipe; /* Alt pipe */ - char *h_altfilename; /* Alt filename */ + struct ifile *h_next; /* Links for command line list */ + struct ifile *h_prev; + char *h_filename; /* Name of the file */ + char *h_rfilename; /* Canonical name of the file */ + void *h_filestate; /* File state (used in ch.c) */ + int h_index; /* Index within command line list */ + int h_hold; /* Hold count */ + char h_opened; /* Has this ifile been opened? */ + struct scrpos h_scrpos; /* Saved position within the file */ + void *h_altpipe; /* Alt pipe */ + char *h_altfilename; /* Alt filename */ }; /* @@ -48,55 +48,55 @@ struct ifile { * Anchor for linked list. */ static struct ifile anchor = { &anchor, &anchor, NULL, NULL, NULL, 0, 0, '\0', - { NULL_POSITION, 0 } }; + { NULL_POSITION, 0 } }; static int ifiles = 0; - static void + static void incr_index(p, incr) - struct ifile *p; - int incr; + struct ifile *p; + int incr; { - for (; p != &anchor; p = p->h_next) - p->h_index += incr; + for (; p != &anchor; p = p->h_next) + p->h_index += incr; } /* * Link an ifile into the ifile list. */ - static void + static void link_ifile(p, prev) - struct ifile *p; - struct ifile *prev; + struct ifile *p; + struct ifile *prev; { - /* - * Link into list. - */ - if (prev == NULL) - prev = &anchor; - p->h_next = prev->h_next; - p->h_prev = prev; - prev->h_next->h_prev = p; - prev->h_next = p; - /* - * Calculate index for the new one, - * and adjust the indexes for subsequent ifiles in the list. - */ - p->h_index = prev->h_index + 1; - incr_index(p->h_next, 1); - ifiles++; + /* + * Link into list. + */ + if (prev == NULL) + prev = &anchor; + p->h_next = prev->h_next; + p->h_prev = prev; + prev->h_next->h_prev = p; + prev->h_next = p; + /* + * Calculate index for the new one, + * and adjust the indexes for subsequent ifiles in the list. + */ + p->h_index = prev->h_index + 1; + incr_index(p->h_next, 1); + ifiles++; } - + /* * Unlink an ifile from the ifile list. */ - static void + static void unlink_ifile(p) - struct ifile *p; + struct ifile *p; { - p->h_next->h_prev = p->h_prev; - p->h_prev->h_next = p->h_next; - incr_index(p->h_next, -1); - ifiles--; + p->h_next->h_prev = p->h_prev; + p->h_prev->h_next = p->h_next; + incr_index(p->h_next, -1); + ifiles--; } /* @@ -105,145 +105,145 @@ unlink_ifile(p) * (or at the beginning of the list if "prev" is NULL). * Return a pointer to the new ifile structure. */ - static struct ifile * + static struct ifile * new_ifile(filename, prev) - char *filename; - struct ifile *prev; + char *filename; + struct ifile *prev; { - struct ifile *p; - - /* - * Allocate and initialize structure. - */ - p = (struct ifile *) ecalloc(1, sizeof(struct ifile)); - p->h_filename = save(filename); - p->h_rfilename = lrealpath(filename); - p->h_scrpos.pos = NULL_POSITION; - p->h_opened = 0; - p->h_hold = 0; - p->h_filestate = NULL; - p->h_altfilename = NULL; - p->h_altpipe = NULL; - link_ifile(p, prev); - /* - * {{ It's dodgy to call mark.c functions from here; - * there is potentially dangerous recursion. - * Probably need to revisit this design. }} - */ - mark_check_ifile(ext_ifile(p)); - return (p); + struct ifile *p; + + /* + * Allocate and initialize structure. + */ + p = (struct ifile *) ecalloc(1, sizeof(struct ifile)); + p->h_filename = save(filename); + p->h_rfilename = lrealpath(filename); + p->h_scrpos.pos = NULL_POSITION; + p->h_opened = 0; + p->h_hold = 0; + p->h_filestate = NULL; + p->h_altfilename = NULL; + p->h_altpipe = NULL; + link_ifile(p, prev); + /* + * {{ It's dodgy to call mark.c functions from here; + * there is potentially dangerous recursion. + * Probably need to revisit this design. }} + */ + mark_check_ifile(ext_ifile(p)); + return (p); } /* * Delete an existing ifile structure. */ - public void + public void del_ifile(h) - IFILE h; + IFILE h; { - struct ifile *p; - - if (h == NULL_IFILE) - return; - /* - * If the ifile we're deleting is the currently open ifile, - * move off it. - */ - unmark(h); - if (h == curr_ifile) - curr_ifile = getoff_ifile(curr_ifile); - p = int_ifile(h); - unlink_ifile(p); - free(p->h_rfilename); - free(p->h_filename); - free(p); + struct ifile *p; + + if (h == NULL_IFILE) + return; + /* + * If the ifile we're deleting is the currently open ifile, + * move off it. + */ + unmark(h); + if (h == curr_ifile) + curr_ifile = getoff_ifile(curr_ifile); + p = int_ifile(h); + unlink_ifile(p); + free(p->h_rfilename); + free(p->h_filename); + free(p); } /* * Get the ifile after a given one in the list. */ - public IFILE + public IFILE next_ifile(h) - IFILE h; + IFILE h; { - struct ifile *p; + struct ifile *p; - p = (h == NULL_IFILE) ? &anchor : int_ifile(h); - if (p->h_next == &anchor) - return (NULL_IFILE); - return (ext_ifile(p->h_next)); + p = (h == NULL_IFILE) ? &anchor : int_ifile(h); + if (p->h_next == &anchor) + return (NULL_IFILE); + return (ext_ifile(p->h_next)); } /* * Get the ifile before a given one in the list. */ - public IFILE + public IFILE prev_ifile(h) - IFILE h; + IFILE h; { - struct ifile *p; + struct ifile *p; - p = (h == NULL_IFILE) ? &anchor : int_ifile(h); - if (p->h_prev == &anchor) - return (NULL_IFILE); - return (ext_ifile(p->h_prev)); + p = (h == NULL_IFILE) ? &anchor : int_ifile(h); + if (p->h_prev == &anchor) + return (NULL_IFILE); + return (ext_ifile(p->h_prev)); } /* * Return a different ifile from the given one. */ - public IFILE + public IFILE getoff_ifile(ifile) - IFILE ifile; + IFILE ifile; { - IFILE newifile; - - if ((newifile = prev_ifile(ifile)) != NULL_IFILE) - return (newifile); - if ((newifile = next_ifile(ifile)) != NULL_IFILE) - return (newifile); - return (NULL_IFILE); + IFILE newifile; + + if ((newifile = prev_ifile(ifile)) != NULL_IFILE) + return (newifile); + if ((newifile = next_ifile(ifile)) != NULL_IFILE) + return (newifile); + return (NULL_IFILE); } /* * Return the number of ifiles. */ - public int + public int nifile(VOID_PARAM) { - return (ifiles); + return (ifiles); } /* * Find an ifile structure, given a filename. */ - static struct ifile * + static struct ifile * find_ifile(filename) - char *filename; + char *filename; { - struct ifile *p; - char *rfilename = lrealpath(filename); - - for (p = anchor.h_next; p != &anchor; p = p->h_next) - { - if (strcmp(rfilename, p->h_rfilename) == 0) - { - /* - * If given name is shorter than the name we were - * previously using for this file, adopt shorter name. - */ - if (strlen(filename) < strlen(p->h_filename)) - { - free(p->h_filename); - p->h_filename = save(filename); - } - break; - } - } - free(rfilename); - if (p == &anchor) - p = NULL; - return (p); + struct ifile *p; + char *rfilename = lrealpath(filename); + + for (p = anchor.h_next; p != &anchor; p = p->h_next) + { + if (strcmp(rfilename, p->h_rfilename) == 0) + { + /* + * If given name is shorter than the name we were + * previously using for this file, adopt shorter name. + */ + if (strlen(filename) < strlen(p->h_filename)) + { + free(p->h_filename); + p->h_filename = save(filename); + } + break; + } + } + free(rfilename); + if (p == &anchor) + p = NULL; + return (p); } /* @@ -251,170 +251,170 @@ find_ifile(filename) * If the filename has not been seen before, * insert the new ifile after "prev" in the list. */ - public IFILE + public IFILE get_ifile(filename, prev) - char *filename; - IFILE prev; + char *filename; + IFILE prev; { - struct ifile *p; + struct ifile *p; - if ((p = find_ifile(filename)) == NULL) - p = new_ifile(filename, int_ifile(prev)); - return (ext_ifile(p)); + if ((p = find_ifile(filename)) == NULL) + p = new_ifile(filename, int_ifile(prev)); + return (ext_ifile(p)); } /* * Get the display filename associated with a ifile. */ - public char * + public char * get_filename(ifile) - IFILE ifile; + IFILE ifile; { - if (ifile == NULL) - return (NULL); - return (int_ifile(ifile)->h_filename); + if (ifile == NULL) + return (NULL); + return (int_ifile(ifile)->h_filename); } /* * Get the canonical filename associated with a ifile. */ - public char * + public char * get_real_filename(ifile) - IFILE ifile; + IFILE ifile; { - if (ifile == NULL) - return (NULL); - return (int_ifile(ifile)->h_rfilename); + if (ifile == NULL) + return (NULL); + return (int_ifile(ifile)->h_rfilename); } /* * Get the index of the file associated with a ifile. */ - public int + public int get_index(ifile) - IFILE ifile; + IFILE ifile; { - return (int_ifile(ifile)->h_index); + return (int_ifile(ifile)->h_index); } /* * Save the file position to be associated with a given file. */ - public void + public void store_pos(ifile, scrpos) - IFILE ifile; - struct scrpos *scrpos; + IFILE ifile; + struct scrpos *scrpos; { - int_ifile(ifile)->h_scrpos = *scrpos; + int_ifile(ifile)->h_scrpos = *scrpos; } /* * Recall the file position associated with a file. * If no position has been associated with the file, return NULL_POSITION. */ - public void + public void get_pos(ifile, scrpos) - IFILE ifile; - struct scrpos *scrpos; + IFILE ifile; + struct scrpos *scrpos; { - *scrpos = int_ifile(ifile)->h_scrpos; + *scrpos = int_ifile(ifile)->h_scrpos; } /* * Mark the ifile as "opened". */ - public void + public void set_open(ifile) - IFILE ifile; + IFILE ifile; { - int_ifile(ifile)->h_opened = 1; + int_ifile(ifile)->h_opened = 1; } /* * Return whether the ifile has been opened previously. */ - public int + public int opened(ifile) - IFILE ifile; + IFILE ifile; { - return (int_ifile(ifile)->h_opened); + return (int_ifile(ifile)->h_opened); } - public void + public void hold_ifile(ifile, incr) - IFILE ifile; - int incr; + IFILE ifile; + int incr; { - int_ifile(ifile)->h_hold += incr; + int_ifile(ifile)->h_hold += incr; } - public int + public int held_ifile(ifile) - IFILE ifile; + IFILE ifile; { - return (int_ifile(ifile)->h_hold); + return (int_ifile(ifile)->h_hold); } - public void * + public void * get_filestate(ifile) - IFILE ifile; + IFILE ifile; { - return (int_ifile(ifile)->h_filestate); + return (int_ifile(ifile)->h_filestate); } - public void + public void set_filestate(ifile, filestate) - IFILE ifile; - void *filestate; + IFILE ifile; + void *filestate; { - int_ifile(ifile)->h_filestate = filestate; + int_ifile(ifile)->h_filestate = filestate; } - public void + public void set_altpipe(ifile, p) - IFILE ifile; - void *p; + IFILE ifile; + void *p; { - int_ifile(ifile)->h_altpipe = p; + int_ifile(ifile)->h_altpipe = p; } - public void * + public void * get_altpipe(ifile) - IFILE ifile; + IFILE ifile; { - return (int_ifile(ifile)->h_altpipe); + return (int_ifile(ifile)->h_altpipe); } - public void + public void set_altfilename(ifile, altfilename) - IFILE ifile; - char *altfilename; + IFILE ifile; + char *altfilename; { - struct ifile *p = int_ifile(ifile); - if (p->h_altfilename != NULL && p->h_altfilename != altfilename) - free(p->h_altfilename); - p->h_altfilename = altfilename; + struct ifile *p = int_ifile(ifile); + if (p->h_altfilename != NULL && p->h_altfilename != altfilename) + free(p->h_altfilename); + p->h_altfilename = altfilename; } - public char * + public char * get_altfilename(ifile) - IFILE ifile; + IFILE ifile; { - return (int_ifile(ifile)->h_altfilename); + return (int_ifile(ifile)->h_altfilename); } #if 0 - public void + public void if_dump(VOID_PARAM) { - struct ifile *p; - - for (p = anchor.h_next; p != &anchor; p = p->h_next) - { - printf("%x: %d. <%s> pos %d,%x\n", - p, p->h_index, p->h_filename, - p->h_scrpos.ln, p->h_scrpos.pos); - ch_dump(p->h_filestate); - } + struct ifile *p; + + for (p = anchor.h_next; p != &anchor; p = p->h_next) + { + printf("%x: %d. <%s> pos %d,%x\n", + p, p->h_index, p->h_filename, + p->h_scrpos.ln, p->h_scrpos.pos); + ch_dump(p->h_filestate); + } } #endif diff --git a/input.c b/input.c index f57c9e3..1f826c8 100644 --- a/input.c +++ b/input.c @@ -8,7 +8,7 @@ */ /* - * High level routines dealing with getting lines of input + * High level routines dealing with getting lines of input * from the file being viewed. * * When we speak of "lines" here, we mean PRINTABLE lines; @@ -41,227 +41,227 @@ extern int show_attn; * a line. The new position is the position of the first character * of the NEXT line. The line obtained is the line starting at curr_pos. */ - public POSITION + public POSITION forw_line_seg(curr_pos, get_segpos) - POSITION curr_pos; - int get_segpos; + POSITION curr_pos; + int get_segpos; { - POSITION base_pos; - POSITION new_pos; - int c; - int blankline; - int endline; - int chopped; - int backchars; + POSITION base_pos; + POSITION new_pos; + int c; + int blankline; + int endline; + int chopped; + int backchars; get_forw_line: - if (curr_pos == NULL_POSITION) - { - null_line(); - return (NULL_POSITION); - } + if (curr_pos == NULL_POSITION) + { + null_line(); + return (NULL_POSITION); + } #if HILITE_SEARCH - if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) - { - /* - * If we are ignoring EOI (command F), only prepare - * one line ahead, to avoid getting stuck waiting for - * slow data without displaying the data we already have. - * If we're not ignoring EOI, we *could* do the same, but - * for efficiency we prepare several lines ahead at once. - */ - prep_hilite(curr_pos, curr_pos + 3*size_linebuf, - ignore_eoi ? 1 : -1); - curr_pos = next_unfiltered(curr_pos); - } + if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) + { + /* + * If we are ignoring EOI (command F), only prepare + * one line ahead, to avoid getting stuck waiting for + * slow data without displaying the data we already have. + * If we're not ignoring EOI, we *could* do the same, but + * for efficiency we prepare several lines ahead at once. + */ + prep_hilite(curr_pos, curr_pos + 3*size_linebuf, + ignore_eoi ? 1 : -1); + curr_pos = next_unfiltered(curr_pos); + } #endif - if (ch_seek(curr_pos)) - { - null_line(); - return (NULL_POSITION); - } + if (ch_seek(curr_pos)) + { + null_line(); + return (NULL_POSITION); + } - /* - * Step back to the beginning of the line. - */ - base_pos = curr_pos; - for (;;) - { - if (ABORT_SIGS()) - { - null_line(); - return (NULL_POSITION); - } - c = ch_back_get(); - if (c == EOI) - break; - if (c == '\n') - { - (void) ch_forw_get(); - break; - } - --base_pos; - } + /* + * Step back to the beginning of the line. + */ + base_pos = curr_pos; + for (;;) + { + if (ABORT_SIGS()) + { + null_line(); + return (NULL_POSITION); + } + c = ch_back_get(); + if (c == EOI) + break; + if (c == '\n') + { + (void) ch_forw_get(); + break; + } + --base_pos; + } - /* - * Read forward again to the position we should start at. - */ - prewind(); - plinestart(base_pos); - (void) ch_seek(base_pos); - new_pos = base_pos; - while (new_pos < curr_pos) - { - if (ABORT_SIGS()) - { - null_line(); - return (NULL_POSITION); - } - c = ch_forw_get(); - backchars = pappend(c, new_pos); - new_pos++; - if (backchars > 0) - { - pshift_all(); - new_pos -= backchars; - while (--backchars >= 0) - (void) ch_back_get(); - } - } - (void) pflushmbc(); - pshift_all(); + /* + * Read forward again to the position we should start at. + */ + prewind(); + plinestart(base_pos); + (void) ch_seek(base_pos); + new_pos = base_pos; + while (new_pos < curr_pos) + { + if (ABORT_SIGS()) + { + null_line(); + return (NULL_POSITION); + } + c = ch_forw_get(); + backchars = pappend(c, new_pos); + new_pos++; + if (backchars > 0) + { + pshift_all(); + new_pos -= backchars; + while (--backchars >= 0) + (void) ch_back_get(); + } + } + (void) pflushmbc(); + pshift_all(); - /* - * Read the first character to display. - */ - c = ch_forw_get(); - if (c == EOI) - { - null_line(); - return (NULL_POSITION); - } - blankline = (c == '\n' || c == '\r'); + /* + * Read the first character to display. + */ + c = ch_forw_get(); + if (c == EOI) + { + null_line(); + return (NULL_POSITION); + } + blankline = (c == '\n' || c == '\r'); - /* - * Read each character in the line and append to the line buffer. - */ - chopped = FALSE; - for (;;) - { - if (ABORT_SIGS()) - { - null_line(); - return (NULL_POSITION); - } - if (c == '\n' || c == EOI) - { - /* - * End of the line. - */ - backchars = pflushmbc(); - new_pos = ch_tell(); - if (backchars > 0 && !chopline && hshift == 0) - { - new_pos -= backchars + 1; - endline = FALSE; - } else - endline = TRUE; - break; - } - if (c != '\r') - blankline = 0; + /* + * Read each character in the line and append to the line buffer. + */ + chopped = FALSE; + for (;;) + { + if (ABORT_SIGS()) + { + null_line(); + return (NULL_POSITION); + } + if (c == '\n' || c == EOI) + { + /* + * End of the line. + */ + backchars = pflushmbc(); + new_pos = ch_tell(); + if (backchars > 0 && !chopline && hshift == 0) + { + new_pos -= backchars + 1; + endline = FALSE; + } else + endline = TRUE; + break; + } + if (c != '\r') + blankline = 0; - /* - * Append the char to the line and get the next char. - */ - backchars = pappend(c, ch_tell()-1); - if (backchars > 0) - { - /* - * The char won't fit in the line; the line - * is too long to print in the screen width. - * End the line here. - */ - if ((chopline || hshift > 0) && !get_segpos) - { - /* Read to end of line. */ - do - { - if (ABORT_SIGS()) - { - null_line(); - return (NULL_POSITION); - } - c = ch_forw_get(); - } while (c != '\n' && c != EOI); - new_pos = ch_tell(); - endline = TRUE; - quit_if_one_screen = FALSE; - chopped = TRUE; - } else - { - new_pos = ch_tell() - backchars; - endline = FALSE; - } - break; - } - c = ch_forw_get(); - } + /* + * Append the char to the line and get the next char. + */ + backchars = pappend(c, ch_tell()-1); + if (backchars > 0) + { + /* + * The char won't fit in the line; the line + * is too long to print in the screen width. + * End the line here. + */ + if ((chopline || hshift > 0) && !get_segpos) + { + /* Read to end of line. */ + do + { + if (ABORT_SIGS()) + { + null_line(); + return (NULL_POSITION); + } + c = ch_forw_get(); + } while (c != '\n' && c != EOI); + new_pos = ch_tell(); + endline = TRUE; + quit_if_one_screen = FALSE; + chopped = TRUE; + } else + { + new_pos = ch_tell() - backchars; + endline = FALSE; + } + break; + } + c = ch_forw_get(); + } #if HILITE_SEARCH - if (blankline && show_attn) - { - /* Add spurious space to carry possible attn hilite. */ - pappend(' ', ch_tell()-1); - } + if (blankline && show_attn) + { + /* Add spurious space to carry possible attn hilite. */ + pappend(' ', ch_tell()-1); + } #endif - pdone(endline, chopped, 1); + pdone(endline, chopped, 1); #if HILITE_SEARCH - if (is_filtered(base_pos)) - { - /* - * We don't want to display this line. - * Get the next line. - */ - curr_pos = new_pos; - goto get_forw_line; - } + if (is_filtered(base_pos)) + { + /* + * We don't want to display this line. + * Get the next line. + */ + curr_pos = new_pos; + goto get_forw_line; + } - if (status_col) - { - int attr = is_hilited_attr(base_pos, ch_tell()-1, 1, NULL); - if (attr) - set_status_col('*', attr); - } + if (status_col) + { + int attr = is_hilited_attr(base_pos, ch_tell()-1, 1, NULL); + if (attr) + set_status_col('*', attr); + } #endif - if (squeeze && blankline) - { - /* - * This line is blank. - * Skip down to the last contiguous blank line - * and pretend it is the one which we are returning. - */ - while ((c = ch_forw_get()) == '\n' || c == '\r') - if (ABORT_SIGS()) - { - null_line(); - return (NULL_POSITION); - } - if (c != EOI) - (void) ch_back_get(); - new_pos = ch_tell(); - } + if (squeeze && blankline) + { + /* + * This line is blank. + * Skip down to the last contiguous blank line + * and pretend it is the one which we are returning. + */ + while ((c = ch_forw_get()) == '\n' || c == '\r') + if (ABORT_SIGS()) + { + null_line(); + return (NULL_POSITION); + } + if (c != EOI) + (void) ch_back_get(); + new_pos = ch_tell(); + } - return (new_pos); + return (new_pos); } - public POSITION + public POSITION forw_line(curr_pos) - POSITION curr_pos; + POSITION curr_pos; { - return forw_line_seg(curr_pos, FALSE); + return forw_line_seg(curr_pos, FALSE); } /* @@ -271,223 +271,223 @@ forw_line(curr_pos) * a line. The new position is the position of the first character * of the PREVIOUS line. The line obtained is the one starting at new_pos. */ - public POSITION + public POSITION back_line(curr_pos) - POSITION curr_pos; + POSITION curr_pos; { - POSITION new_pos, begin_new_pos, base_pos; - int c; - int endline; - int chopped; - int backchars; + POSITION new_pos, begin_new_pos, base_pos; + int c; + int endline; + int chopped; + int backchars; get_back_line: - if (curr_pos == NULL_POSITION || curr_pos <= ch_zero()) - { - null_line(); - return (NULL_POSITION); - } + if (curr_pos == NULL_POSITION || curr_pos <= ch_zero()) + { + null_line(); + return (NULL_POSITION); + } #if HILITE_SEARCH - if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) - prep_hilite((curr_pos < 3*size_linebuf) ? - 0 : curr_pos - 3*size_linebuf, curr_pos, -1); + if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) + prep_hilite((curr_pos < 3*size_linebuf) ? + 0 : curr_pos - 3*size_linebuf, curr_pos, -1); #endif - if (ch_seek(curr_pos-1)) - { - null_line(); - return (NULL_POSITION); - } + if (ch_seek(curr_pos-1)) + { + null_line(); + return (NULL_POSITION); + } - if (squeeze) - { - /* - * Find out if the "current" line was blank. - */ - (void) ch_forw_get(); /* Skip the newline */ - c = ch_forw_get(); /* First char of "current" line */ - (void) ch_back_get(); /* Restore our position */ - (void) ch_back_get(); + if (squeeze) + { + /* + * Find out if the "current" line was blank. + */ + (void) ch_forw_get(); /* Skip the newline */ + c = ch_forw_get(); /* First char of "current" line */ + (void) ch_back_get(); /* Restore our position */ + (void) ch_back_get(); - if (c == '\n' || c == '\r') - { - /* - * The "current" line was blank. - * Skip over any preceding blank lines, - * since we skipped them in forw_line(). - */ - while ((c = ch_back_get()) == '\n' || c == '\r') - if (ABORT_SIGS()) - { - null_line(); - return (NULL_POSITION); - } - if (c == EOI) - { - null_line(); - return (NULL_POSITION); - } - (void) ch_forw_get(); - } - } + if (c == '\n' || c == '\r') + { + /* + * The "current" line was blank. + * Skip over any preceding blank lines, + * since we skipped them in forw_line(). + */ + while ((c = ch_back_get()) == '\n' || c == '\r') + if (ABORT_SIGS()) + { + null_line(); + return (NULL_POSITION); + } + if (c == EOI) + { + null_line(); + return (NULL_POSITION); + } + (void) ch_forw_get(); + } + } - /* - * Scan backwards until we hit the beginning of the line. - */ - for (;;) - { - if (ABORT_SIGS()) - { - null_line(); - return (NULL_POSITION); - } - c = ch_back_get(); - if (c == '\n') - { - /* - * This is the newline ending the previous line. - * We have hit the beginning of the line. - */ - base_pos = ch_tell() + 1; - break; - } - if (c == EOI) - { - /* - * We have hit the beginning of the file. - * This must be the first line in the file. - * This must, of course, be the beginning of the line. - */ - base_pos = ch_tell(); - break; - } - } + /* + * Scan backwards until we hit the beginning of the line. + */ + for (;;) + { + if (ABORT_SIGS()) + { + null_line(); + return (NULL_POSITION); + } + c = ch_back_get(); + if (c == '\n') + { + /* + * This is the newline ending the previous line. + * We have hit the beginning of the line. + */ + base_pos = ch_tell() + 1; + break; + } + if (c == EOI) + { + /* + * We have hit the beginning of the file. + * This must be the first line in the file. + * This must, of course, be the beginning of the line. + */ + base_pos = ch_tell(); + break; + } + } - /* - * Now scan forwards from the beginning of this line. - * We keep discarding "printable lines" (based on screen width) - * until we reach the curr_pos. - * - * {{ This algorithm is pretty inefficient if the lines - * are much longer than the screen width, - * but I don't know of any better way. }} - */ - new_pos = base_pos; - if (ch_seek(new_pos)) - { - null_line(); - return (NULL_POSITION); - } - endline = FALSE; - prewind(); - plinestart(new_pos); + /* + * Now scan forwards from the beginning of this line. + * We keep discarding "printable lines" (based on screen width) + * until we reach the curr_pos. + * + * {{ This algorithm is pretty inefficient if the lines + * are much longer than the screen width, + * but I don't know of any better way. }} + */ + new_pos = base_pos; + if (ch_seek(new_pos)) + { + null_line(); + return (NULL_POSITION); + } + endline = FALSE; + prewind(); + plinestart(new_pos); loop: - begin_new_pos = new_pos; - (void) ch_seek(new_pos); - chopped = FALSE; + begin_new_pos = new_pos; + (void) ch_seek(new_pos); + chopped = FALSE; - do - { - c = ch_forw_get(); - if (c == EOI || ABORT_SIGS()) - { - null_line(); - return (NULL_POSITION); - } - new_pos++; - if (c == '\n') - { - backchars = pflushmbc(); - if (backchars > 0 && !chopline && hshift == 0) - { - backchars++; - goto shift; - } - endline = TRUE; - break; - } - backchars = pappend(c, ch_tell()-1); - if (backchars > 0) - { - /* - * Got a full printable line, but we haven't - * reached our curr_pos yet. Discard the line - * and start a new one. - */ - if (chopline || hshift > 0) - { - endline = TRUE; - chopped = TRUE; - quit_if_one_screen = FALSE; - break; - } - shift: - pshift_all(); - while (backchars-- > 0) - { - (void) ch_back_get(); - new_pos--; - } - goto loop; - } - } while (new_pos < curr_pos); + do + { + c = ch_forw_get(); + if (c == EOI || ABORT_SIGS()) + { + null_line(); + return (NULL_POSITION); + } + new_pos++; + if (c == '\n') + { + backchars = pflushmbc(); + if (backchars > 0 && !chopline && hshift == 0) + { + backchars++; + goto shift; + } + endline = TRUE; + break; + } + backchars = pappend(c, ch_tell()-1); + if (backchars > 0) + { + /* + * Got a full printable line, but we haven't + * reached our curr_pos yet. Discard the line + * and start a new one. + */ + if (chopline || hshift > 0) + { + endline = TRUE; + chopped = TRUE; + quit_if_one_screen = FALSE; + break; + } + shift: + pshift_all(); + while (backchars-- > 0) + { + (void) ch_back_get(); + new_pos--; + } + goto loop; + } + } while (new_pos < curr_pos); - pdone(endline, chopped, 0); + pdone(endline, chopped, 0); #if HILITE_SEARCH - if (is_filtered(base_pos)) - { - /* - * We don't want to display this line. - * Get the previous line. - */ - curr_pos = begin_new_pos; - goto get_back_line; - } + if (is_filtered(base_pos)) + { + /* + * We don't want to display this line. + * Get the previous line. + */ + curr_pos = begin_new_pos; + goto get_back_line; + } - if (status_col && curr_pos > 0) - { - int attr = is_hilited_attr(base_pos, curr_pos-1, 1, NULL); - if (attr) - set_status_col('*', attr); - } + if (status_col && curr_pos > 0) + { + int attr = is_hilited_attr(base_pos, curr_pos-1, 1, NULL); + if (attr) + set_status_col('*', attr); + } #endif - return (begin_new_pos); + return (begin_new_pos); } /* * Set attnpos. */ - public void + public void set_attnpos(pos) - POSITION pos; + POSITION pos; { - int c; + int c; - if (pos != NULL_POSITION) - { - if (ch_seek(pos)) - return; - for (;;) - { - c = ch_forw_get(); - if (c == EOI) - break; - if (c == '\n' || c == '\r') - { - (void) ch_back_get(); - break; - } - pos++; - } - end_attnpos = pos; - for (;;) - { - c = ch_back_get(); - if (c == EOI || c == '\n' || c == '\r') - break; - pos--; - } - } - start_attnpos = pos; + if (pos != NULL_POSITION) + { + if (ch_seek(pos)) + return; + for (;;) + { + c = ch_forw_get(); + if (c == EOI) + break; + if (c == '\n' || c == '\r') + { + (void) ch_back_get(); + break; + } + pos++; + } + end_attnpos = pos; + for (;;) + { + c = ch_back_get(); + if (c == EOI || c == '\n' || c == '\r') + break; + pos--; + } + } + start_attnpos = pos; } diff --git a/install.sh b/install.sh index 41ea84f..23a5735 100644 --- a/install.sh +++ b/install.sh @@ -39,50 +39,50 @@ dst="" while [ x"$1" != x ]; do case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - dst=$1 - fi - shift - continue;; + -c) instcmd="$cpprog" + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + dst=$1 + fi + shift + continue;; esac done if [ x"$src" = x ] then - echo "install: no input file specified" - exit 1 + echo "install: no input file specified" + exit 1 fi if [ x"$dst" = x ] then - echo "install: no destination specified" - exit 1 + echo "install: no destination specified" + exit 1 fi @@ -91,7 +91,7 @@ fi if [ -d $dst ] then - dst="$dst"/`basename $src` + dst="$dst"/`basename $src` fi # Make a temp file name in the proper directory. diff --git a/jump.c b/jump.c index a376486..1e914c9 100644 --- a/jump.c +++ b/jump.c @@ -25,169 +25,169 @@ extern int top_scroll; /* * Jump to the end of the file. */ - public void + public void jump_forw(VOID_PARAM) { - POSITION pos; - POSITION end_pos; + POSITION pos; + POSITION end_pos; - if (ch_end_seek()) - { - error("Cannot seek to end of file", NULL_PARG); - return; - } - /* - * Note; lastmark will be called later by jump_loc, but it fails - * because the position table has been cleared by pos_clear below. - * So call it here before calling pos_clear. - */ - lastmark(); - /* - * Position the last line in the file at the last screen line. - * Go back one line from the end of the file - * to get to the beginning of the last line. - */ - pos_clear(); - end_pos = ch_tell(); - pos = back_line(end_pos); - if (pos == NULL_POSITION) - jump_loc(ch_zero(), sc_height-1); - else - { - jump_loc(pos, sc_height-1); - if (position(sc_height-1) != end_pos) - repaint(); - } + if (ch_end_seek()) + { + error("Cannot seek to end of file", NULL_PARG); + return; + } + /* + * Note; lastmark will be called later by jump_loc, but it fails + * because the position table has been cleared by pos_clear below. + * So call it here before calling pos_clear. + */ + lastmark(); + /* + * Position the last line in the file at the last screen line. + * Go back one line from the end of the file + * to get to the beginning of the last line. + */ + pos_clear(); + end_pos = ch_tell(); + pos = back_line(end_pos); + if (pos == NULL_POSITION) + jump_loc(ch_zero(), sc_height-1); + else + { + jump_loc(pos, sc_height-1); + if (position(sc_height-1) != end_pos) + repaint(); + } } /* * Jump to the last buffered line in the file. */ - public void + public void jump_forw_buffered(VOID_PARAM) { - POSITION end; + POSITION end; - if (ch_end_buffer_seek()) - { - error("Cannot seek to end of buffers", NULL_PARG); - return; - } - end = ch_tell(); - if (end != NULL_POSITION && end > 0) - jump_line_loc(end-1, sc_height-1); + if (ch_end_buffer_seek()) + { + error("Cannot seek to end of buffers", NULL_PARG); + return; + } + end = ch_tell(); + if (end != NULL_POSITION && end > 0) + jump_line_loc(end-1, sc_height-1); } /* * Jump to line n in the file. */ - public void + public void jump_back(linenum) - LINENUM linenum; + LINENUM linenum; { - POSITION pos; - PARG parg; + POSITION pos; + PARG parg; - /* - * Find the position of the specified line. - * If we can seek there, just jump to it. - * If we can't seek, but we're trying to go to line number 1, - * use ch_beg_seek() to get as close as we can. - */ - pos = find_pos(linenum); - if (pos != NULL_POSITION && ch_seek(pos) == 0) - { - if (show_attn) - set_attnpos(pos); - jump_loc(pos, jump_sline); - } else if (linenum <= 1 && ch_beg_seek() == 0) - { - jump_loc(ch_tell(), jump_sline); - error("Cannot seek to beginning of file", NULL_PARG); - } else - { - parg.p_linenum = linenum; - error("Cannot seek to line number %n", &parg); - } + /* + * Find the position of the specified line. + * If we can seek there, just jump to it. + * If we can't seek, but we're trying to go to line number 1, + * use ch_beg_seek() to get as close as we can. + */ + pos = find_pos(linenum); + if (pos != NULL_POSITION && ch_seek(pos) == 0) + { + if (show_attn) + set_attnpos(pos); + jump_loc(pos, jump_sline); + } else if (linenum <= 1 && ch_beg_seek() == 0) + { + jump_loc(ch_tell(), jump_sline); + error("Cannot seek to beginning of file", NULL_PARG); + } else + { + parg.p_linenum = linenum; + error("Cannot seek to line number %n", &parg); + } } /* * Repaint the screen. */ - public void + public void repaint(VOID_PARAM) { - struct scrpos scrpos; - /* - * Start at the line currently at the top of the screen - * and redisplay the screen. - */ - get_scrpos(&scrpos, TOP); - pos_clear(); - if (scrpos.pos == NULL_POSITION) - /* Screen hasn't been drawn yet. */ - jump_loc(ch_zero(), 1); - else - jump_loc(scrpos.pos, scrpos.ln); + struct scrpos scrpos; + /* + * Start at the line currently at the top of the screen + * and redisplay the screen. + */ + get_scrpos(&scrpos, TOP); + pos_clear(); + if (scrpos.pos == NULL_POSITION) + /* Screen hasn't been drawn yet. */ + jump_loc(ch_zero(), 1); + else + jump_loc(scrpos.pos, scrpos.ln); } /* * Jump to a specified percentage into the file. */ - public void + public void jump_percent(percent, fraction) - int percent; - long fraction; + int percent; + long fraction; { - POSITION pos, len; + POSITION pos, len; - /* - * Determine the position in the file - * (the specified percentage of the file's length). - */ - if ((len = ch_length()) == NULL_POSITION) - { - ierror("Determining length of file", NULL_PARG); - ch_end_seek(); - } - if ((len = ch_length()) == NULL_POSITION) - { - error("Don't know length of file", NULL_PARG); - return; - } - pos = percent_pos(len, percent, fraction); - if (pos >= len) - pos = len-1; + /* + * Determine the position in the file + * (the specified percentage of the file's length). + */ + if ((len = ch_length()) == NULL_POSITION) + { + ierror("Determining length of file", NULL_PARG); + ch_end_seek(); + } + if ((len = ch_length()) == NULL_POSITION) + { + error("Don't know length of file", NULL_PARG); + return; + } + pos = percent_pos(len, percent, fraction); + if (pos >= len) + pos = len-1; - jump_line_loc(pos, jump_sline); + jump_line_loc(pos, jump_sline); } /* * Jump to a specified position in the file. - * Like jump_loc, but the position need not be + * Like jump_loc, but the position need not be * the first character in a line. */ - public void + public void jump_line_loc(pos, sline) - POSITION pos; - int sline; + POSITION pos; + int sline; { - int c; + int c; - if (ch_seek(pos) == 0) - { - /* - * Back up to the beginning of the line. - */ - while ((c = ch_back_get()) != '\n' && c != EOI) - ; - if (c == '\n') - (void) ch_forw_get(); - pos = ch_tell(); - } - if (show_attn) - set_attnpos(pos); - jump_loc(pos, sline); + if (ch_seek(pos) == 0) + { + /* + * Back up to the beginning of the line. + */ + while ((c = ch_back_get()) != '\n' && c != EOI) + ; + if (c == '\n') + (void) ch_forw_get(); + pos = ch_tell(); + } + if (show_attn) + set_attnpos(pos); + jump_loc(pos, sline); } /* @@ -195,140 +195,140 @@ jump_line_loc(pos, sline) * The position must be the first character in a line. * Place the target line on a specified line on the screen. */ - public void + public void jump_loc(pos, sline) - POSITION pos; - int sline; + POSITION pos; + int sline; { - int nline; - int sindex; - POSITION tpos; - POSITION bpos; + int nline; + int sindex; + POSITION tpos; + POSITION bpos; - /* - * Normalize sline. - */ - sindex = sindex_from_sline(sline); + /* + * Normalize sline. + */ + sindex = sindex_from_sline(sline); - if ((nline = onscreen(pos)) >= 0) - { - /* - * The line is currently displayed. - * Just scroll there. - */ - nline -= sindex; - if (nline > 0) - forw(nline, position(BOTTOM_PLUS_ONE), 1, 0, 0); - else - back(-nline, position(TOP), 1, 0); + if ((nline = onscreen(pos)) >= 0) + { + /* + * The line is currently displayed. + * Just scroll there. + */ + nline -= sindex; + if (nline > 0) + forw(nline, position(BOTTOM_PLUS_ONE), 1, 0, 0); + else + back(-nline, position(TOP), 1, 0); #if HILITE_SEARCH - if (show_attn) - repaint_hilite(1); + if (show_attn) + repaint_hilite(1); #endif - return; - } + return; + } - /* - * Line is not on screen. - * Seek to the desired location. - */ - if (ch_seek(pos)) - { - error("Cannot seek to that file position", NULL_PARG); - return; - } + /* + * Line is not on screen. + * Seek to the desired location. + */ + if (ch_seek(pos)) + { + error("Cannot seek to that file position", NULL_PARG); + return; + } - /* - * See if the desired line is before or after - * the currently displayed screen. - */ - tpos = position(TOP); - bpos = position(BOTTOM_PLUS_ONE); - if (tpos == NULL_POSITION || pos >= tpos) - { - /* - * The desired line is after the current screen. - * Move back in the file far enough so that we can - * call forw() and put the desired line at the - * sline-th line on the screen. - */ - for (nline = 0; nline < sindex; nline++) - { - if (bpos != NULL_POSITION && pos <= bpos) - { - /* - * Surprise! The desired line is - * close enough to the current screen - * that we can just scroll there after all. - */ - forw(sc_height-sindex+nline-1, bpos, 1, 0, 0); + /* + * See if the desired line is before or after + * the currently displayed screen. + */ + tpos = position(TOP); + bpos = position(BOTTOM_PLUS_ONE); + if (tpos == NULL_POSITION || pos >= tpos) + { + /* + * The desired line is after the current screen. + * Move back in the file far enough so that we can + * call forw() and put the desired line at the + * sline-th line on the screen. + */ + for (nline = 0; nline < sindex; nline++) + { + if (bpos != NULL_POSITION && pos <= bpos) + { + /* + * Surprise! The desired line is + * close enough to the current screen + * that we can just scroll there after all. + */ + forw(sc_height-sindex+nline-1, bpos, 1, 0, 0); #if HILITE_SEARCH - if (show_attn) - repaint_hilite(1); + if (show_attn) + repaint_hilite(1); #endif - return; - } - pos = back_line(pos); - if (pos == NULL_POSITION) - { - /* - * Oops. Ran into the beginning of the file. - * Exit the loop here and rely on forw() - * below to draw the required number of - * blank lines at the top of the screen. - */ - break; - } - } - lastmark(); - squished = 0; - screen_trashed = 0; - forw(sc_height-1, pos, 1, 0, sindex-nline); - } else - { - /* - * The desired line is before the current screen. - * Move forward in the file far enough so that we - * can call back() and put the desired line at the - * sindex-th line on the screen. - */ - for (nline = sindex; nline < sc_height - 1; nline++) - { - pos = forw_line(pos); - if (pos == NULL_POSITION) - { - /* - * Ran into end of file. - * This shouldn't normally happen, - * but may if there is some kind of read error. - */ - break; - } + return; + } + pos = back_line(pos); + if (pos == NULL_POSITION) + { + /* + * Oops. Ran into the beginning of the file. + * Exit the loop here and rely on forw() + * below to draw the required number of + * blank lines at the top of the screen. + */ + break; + } + } + lastmark(); + squished = 0; + screen_trashed = 0; + forw(sc_height-1, pos, 1, 0, sindex-nline); + } else + { + /* + * The desired line is before the current screen. + * Move forward in the file far enough so that we + * can call back() and put the desired line at the + * sindex-th line on the screen. + */ + for (nline = sindex; nline < sc_height - 1; nline++) + { + pos = forw_line(pos); + if (pos == NULL_POSITION) + { + /* + * Ran into end of file. + * This shouldn't normally happen, + * but may if there is some kind of read error. + */ + break; + } #if HILITE_SEARCH - pos = next_unfiltered(pos); + pos = next_unfiltered(pos); #endif - if (pos >= tpos) - { - /* - * Surprise! The desired line is - * close enough to the current screen - * that we can just scroll there after all. - */ - back(nline+1, tpos, 1, 0); + if (pos >= tpos) + { + /* + * Surprise! The desired line is + * close enough to the current screen + * that we can just scroll there after all. + */ + back(nline+1, tpos, 1, 0); #if HILITE_SEARCH - if (show_attn) - repaint_hilite(1); + if (show_attn) + repaint_hilite(1); #endif - return; - } - } - lastmark(); - if (!top_scroll) - clear(); - else - home(); - screen_trashed = 0; - add_back_pos(pos); - back(sc_height-1, pos, 1, 0); - } + return; + } + } + lastmark(); + if (!top_scroll) + clear(); + else + home(); + screen_trashed = 0; + add_back_pos(pos); + back(sc_height-1, pos, 1, 0); + } } diff --git a/less.h b/less.h index 4751976..5cf0c64 100644 --- a/less.h +++ b/less.h @@ -325,7 +325,7 @@ struct wchar_range LWCHAR first, last; }; -struct wchar_range_table +struct wchar_range_table { struct wchar_range *table; int count; @@ -410,12 +410,12 @@ struct wchar_range_table typedef enum { CT_NULL, CT_4BIT, CT_6BIT } COLOR_TYPE; typedef enum { - CV_BLUE = 1, - CV_GREEN = 2, - CV_RED = 4, - CV_BRIGHT = 8, - CV_NOCHANGE = -2, - CV_ERROR = -1 + CV_BLUE = 1, + CV_GREEN = 2, + CV_RED = 4, + CV_BRIGHT = 8, + CV_NOCHANGE = -2, + CV_ERROR = -1 } COLOR_VALUE; /* ANSI states */ diff --git a/less.hlp b/less.hlp index 1e1ebf4..0f3f097 100644 --- a/less.hlp +++ b/less.hlp @@ -66,9 +66,9 @@ ESC-^F _<_c_1_> _<_c_2_> * Find close bracket _<_c_2_>. ESC-^B _<_c_1_> _<_c_2_> * Find open bracket _<_c_1_>. --------------------------------------------------- - Each "find close bracket" command goes forward to the close bracket + Each "find close bracket" command goes forward to the close bracket matching the (_N-th) open bracket in the top line. - Each "find open bracket" command goes backward to the open bracket + Each "find open bracket" command goes backward to the open bracket matching the (_N-th) close bracket in the bottom line. m_<_l_e_t_t_e_r_> Mark the current top line with . @@ -235,7 +235,7 @@ LLIINNEE EEDDIITTIINNGG - These keys can be used to edit text being entered + These keys can be used to edit text being entered on the "command line" at the bottom of the screen. RightArrow ..................... ESC-l ... Move cursor right one character. diff --git a/less.nro b/less.nro index f148ccb..c7f9b59 100644 --- a/less.nro +++ b/less.nro @@ -572,7 +572,7 @@ The \-d option does not otherwise change the behavior of on a dumb terminal. .IP "\-D\fBx\fP\fIcolor\fP or \-\-color=\fBx\fP\fIcolor\fP" Changes the color of different parts of the displayed text. -\fBx\fP is a single character which selects the type of text +\fBx\fP is a single character which selects the type of text whose color is being set: .RS .IP "B" @@ -602,16 +602,16 @@ Standout text. .IP "u" Underlined text. .RE - + .RS The uppercase letters can be used only when the \-\-use-color option is enabled. When text color is specified by both an uppercase letter and a lowercase letter, -the uppercase letter takes precedence. +the uppercase letter takes precedence. For example, error messages are normally displayed as standout text. So if both "s" and "E" are given a color, the "E" color applies to error messages, and the "s" color applies to other standout text. -The "d" and "u" letters refer to bold and underline text formed by -overstriking with backspaces (see the \-u option), +The "d" and "u" letters refer to bold and underline text formed by +overstriking with backspaces (see the \-u option), not to text using ANSI escape sequences with the \-R option. .PP A lowercase letter may be followed by a + to indicate that @@ -622,8 +622,8 @@ But \-Du+g displays underlined text as both green and in underlined format. .PP \fIcolor\fP is either a 4-bit color string or an 8-bit color string: .PP -A 4-bit color string is zero, one or two characters, where -the first character specifies the foreground color and +A 4-bit color string is zero, one or two characters, where +the first character specifies the foreground color and the second specifies the background color as follows: .IP "b" Blue @@ -643,14 +643,14 @@ White Yellow .PP The corresponding upper-case letter denotes a brighter shade of the color. -For example, \-DNGk displays line numbers as bright green text on a black -background, and \-DEbR displays error messages as blue text on a +For example, \-DNGk displays line numbers as bright green text on a black +background, and \-DEbR displays error messages as blue text on a bright red background. -If either character is a "-" or is omitted, the corresponding color +If either character is a "-" or is omitted, the corresponding color is set to that of normal text. .PP An 8-bit color string is one or two decimal integers separated by a dot, -where the first integer specifies the foreground color and +where the first integer specifies the foreground color and the second specifies the background color. Each integer is a value between 0 and 255 inclusive which selects a "CSI 38;5" color value (see @@ -660,11 +660,11 @@ https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) .hy If either integer is a "-" or is omitted, the corresponding color is set to that of normal text. -On MS-DOS versions of +On MS-DOS versions of .IR less , 8-bit color is not supported; instead, decimal values are interpreted as 4-bit CHAR_INFO.Attributes values -(see +(see .br .nh https://docs.microsoft.com/en-us/windows/console/char-info-str). @@ -886,10 +886,10 @@ USE OF THE \-r OPTION IS NOT RECOMMENDED. Like \-r, but only ANSI "color" escape sequences and OSC 8 hyperlink sequences are output in "raw" form. Unlike \-r, the screen appearance is maintained correctly, -provided that there are no escape sequences in the file +provided that there are no escape sequences in the file other than these types of escape sequences. Color escape sequences are only supported when the color -is changed within one line, not across lines. +is changed within one line, not across lines. In other words, the beginning of each line is assumed to be normal (non-colored), regardless of any escape sequences in previous lines. For the purpose of keeping track of screen appearance, @@ -897,14 +897,14 @@ these escape sequences are assumed to not move the cursor. .sp OSC 8 hyperlinks are sequences of the form: .sp - ESC ] 8 ; \&...\& \\7 + ESC ] 8 ; \&...\& \\7 .sp -The terminating sequence may be either a BEL character (\\7) +The terminating sequence may be either a BEL character (\\7) or the two-character sequence "ESC \\". .sp ANSI color escape sequences are sequences of the form: .sp - ESC [ \&...\& m + ESC [ \&...\& m .sp where the "...\&" is zero or more color specification characters. You can make @@ -941,7 +941,7 @@ If the environment variable LESSGLOBALTAGS is set, it is taken to be the name of a command compatible with .IR global (1), and that command is executed to find the tag. -(See +(See .nh http://www.gnu.org/software/global/global.html). .hy @@ -1070,7 +1070,7 @@ will display the contents of that new file. .IP "\-\-incsearch" Subsequent search commands will be "incremental"; that is, .I less -will advance to the next line containing the search pattern +will advance to the next line containing the search pattern as each character of the pattern is typed in. .IP "\-\-line-num-width" Sets the minimum width of the line number field when the \-N option is in effect. @@ -1120,9 +1120,9 @@ This allows a dollar sign to be included in option strings. .IP "\-\-use-color" Enables the colored text in various places. The -D option can be used to change the colors. -Colored text works only if the terminal supports +Colored text works only if the terminal supports ANSI color escape sequences (as defined in ECMA-48 SGR; -see +see .br .nh https://www.ecma-international.org/publications-and-standards/standards/ecma-48). @@ -1327,33 +1327,33 @@ view them directly: .PP lessopen.sh: .br - #! /bin/sh + #! /bin/sh .br - case "$1" in + case "$1" in .br - *.Z) TEMPFILE=$(mktemp) + *.Z) TEMPFILE=$(mktemp) .br - uncompress \-c $1 >$TEMPFILE 2>/dev/null + uncompress \-c $1 >$TEMPFILE 2>/dev/null .br - if [ \-s $TEMPFILE ]; then + if [ \-s $TEMPFILE ]; then .br - echo $TEMPFILE + echo $TEMPFILE .br - else + else .br - rm \-f $TEMPFILE + rm \-f $TEMPFILE .br - fi + fi .br - ;; + ;; .br - esac + esac .PP lessclose.sh: .br - #! /bin/sh + #! /bin/sh .br - rm $2 + rm $2 .PP To use these scripts, put them both where they can be executed and set LESSOPEN="lessopen.sh\ %s", and @@ -1386,21 +1386,21 @@ previous example scripts: .PP lesspipe.sh: .br - #! /bin/sh + #! /bin/sh .br - case "$1" in + case "$1" in .br - *.Z) uncompress \-c $1 2>/dev/null + *.Z) uncompress \-c $1 2>/dev/null .br - ;; + ;; .br - *) exit 1 + *) exit 1 .br - ;; + ;; .br - esac + esac .br - exit $? + exit $? .br .PP To use this script, put it where it can be executed and set @@ -1513,16 +1513,16 @@ to each of the possible values for LESSCHARSET: .RS 5m .TS l l. -ascii 8bcccbcc18b95.b -dos 8bcccbcc12bc5b95.b. -ebcdic 5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b - 9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b. -IBM-1047 4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc - 191.b -iso8859 8bcccbcc18b95.33b. -koi8-r 8bcccbcc18b95.b128. -latin1 8bcccbcc18b95.33b. -next 8bcccbcc18b95.bb125.bb +ascii 8bcccbcc18b95.b +dos 8bcccbcc12bc5b95.b. +ebcdic 5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b + 9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b. +IBM-1047 4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc + 191.b +iso8859 8bcccbcc18b95.33b. +koi8-r 8bcccbcc18b95.b128. +latin1 8bcccbcc18b95.33b. +next 8bcccbcc18b95.bb125.bb .TE .RE .PP @@ -1737,17 +1737,17 @@ Each is broken into two lines here for readability only. .nf .sp ?n?f%f\ .?m(%T\ %i\ of\ %m)\ ..?e(END)\ ?x-\ Next\e:\ %x.: - ?pB%pB\e%:byte\ %bB?s/%s...%t + ?pB%pB\e%:byte\ %bB?s/%s...%t .sp ?f%f\ .?n?m(%T\ %i\ of\ %m)\ ..?ltlines\ %lt-%lb?L/%L.\ : - byte\ %bB?s/%s.\ .?e(END)\ ?x-\ Next\e:\ %x.:?pB%pB\e%..%t + byte\ %bB?s/%s.\ .?e(END)\ ?x-\ Next\e:\ %x.:?pB%pB\e%..%t .sp .fi And here is the default message produced by the = command: .nf .sp ?f%f\ .?m(%T\ %i\ of\ %m)\ .?ltlines\ %lt-%lb?L/%L.\ . - byte\ %bB?s/%s.\ ?e(END)\ :?pB%pB\e%..%t + byte\ %bB?s/%s.\ ?e(END)\ :?pB%pB\e%..%t .fi .PP The prompt expansion features are also used for another purpose: @@ -1757,7 +1757,7 @@ The LESSEDIT string is expanded in the same way as the prompt strings. The default value for LESSEDIT is: .nf .sp - %E\ ?lm+%lm.\ %g + %E\ ?lm+%lm.\ %g .sp .fi Note that this expands to the editor name, followed by a + and the diff --git a/lessecho.c b/lessecho.c index bfb0f72..22371ec 100644 --- a/lessecho.c +++ b/lessecho.c @@ -37,235 +37,235 @@ static char meta_escape_buf[2]; static char metachars[64] = ""; static int num_metachars = 0; - static void + static void pr_usage(VOID_PARAM) { - fprintf(stderr, - "usage: lessecho [-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-fn] [-a] file ...\n"); + fprintf(stderr, + "usage: lessecho [-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-fn] [-a] file ...\n"); } - static void + static void pr_version(VOID_PARAM) { - char *p; - char buf[10]; - char *pbuf = buf; + char *p; + char buf[10]; + char *pbuf = buf; - for (p = version; *p != ' '; p++) - if (*p == '\0') - return; - for (p++; *p != '$' && *p != ' ' && *p != '\0'; p++) - *pbuf++ = *p; - *pbuf = '\0'; - printf("%s\n", buf); + for (p = version; *p != ' '; p++) + if (*p == '\0') + return; + for (p++; *p != '$' && *p != ' ' && *p != '\0'; p++) + *pbuf++ = *p; + *pbuf = '\0'; + printf("%s\n", buf); } - static void + static void pr_error(s) - char *s; + char *s; { - fprintf(stderr, "%s\n", s); - exit(1); + fprintf(stderr, "%s\n", s); + exit(1); } - static long + static long lstrtol(s, radix, pend) - char *s; - int radix; - char **pend; + char *s; + int radix; + char **pend; { - int v; - int neg = 0; - long n = 0; + int v; + int neg = 0; + long n = 0; - /* Skip leading white space. */ - while (*s == ' ' || *s == '\t') - s++; + /* Skip leading white space. */ + while (*s == ' ' || *s == '\t') + s++; - /* Check for a leading + or -. */ - if (*s == '-') - { - neg = 1; - s++; - } else if (*s == '+') - { - s++; - } + /* Check for a leading + or -. */ + if (*s == '-') + { + neg = 1; + s++; + } else if (*s == '+') + { + s++; + } - /* Determine radix if caller does not specify. */ - if (radix == 0) - { - radix = 10; - if (*s == '0') - { - switch (*++s) - { - case 'x': - radix = 16; - s++; - break; - default: - radix = 8; - break; - } - } - } + /* Determine radix if caller does not specify. */ + if (radix == 0) + { + radix = 10; + if (*s == '0') + { + switch (*++s) + { + case 'x': + radix = 16; + s++; + break; + default: + radix = 8; + break; + } + } + } - /* Parse the digits of the number. */ - for (;;) - { - if (*s >= '0' && *s <= '9') - v = *s - '0'; - else if (*s >= 'a' && *s <= 'f') - v = *s - 'a' + 10; - else if (*s >= 'A' && *s <= 'F') - v = *s - 'A' + 10; - else - break; - if (v >= radix) - break; - n = n * radix + v; - s++; - } + /* Parse the digits of the number. */ + for (;;) + { + if (*s >= '0' && *s <= '9') + v = *s - '0'; + else if (*s >= 'a' && *s <= 'f') + v = *s - 'a' + 10; + else if (*s >= 'A' && *s <= 'F') + v = *s - 'A' + 10; + else + break; + if (v >= radix) + break; + n = n * radix + v; + s++; + } - if (pend != NULL) - { - /* Skip trailing white space. */ - while (*s == ' ' || *s == '\t') - s++; - *pend = s; - } - if (neg) - return (-n); - return (n); + if (pend != NULL) + { + /* Skip trailing white space. */ + while (*s == ' ' || *s == '\t') + s++; + *pend = s; + } + if (neg) + return (-n); + return (n); } #if !HAVE_STRCHR - char * + char * strchr(s, c) - char *s; - int c; + char *s; + int c; { - for ( ; *s != '\0'; s++) - if (*s == c) - return (s); - if (c == '\0') - return (s); - return (NULL); + for ( ; *s != '\0'; s++) + if (*s == c) + return (s); + if (c == '\0') + return (s); + return (NULL); } #endif - int + int main(argc, argv) - int argc; - char *argv[]; + int argc; + char *argv[]; { - char *arg; - char *s; - int no_more_options; + char *arg; + char *s; + int no_more_options; - no_more_options = 0; - while (--argc > 0) - { - arg = *++argv; - if (*arg != '-' || no_more_options) - break; - switch (*++arg) - { - case 'a': - quote_all = 1; - break; - case 'c': - closequote = *++arg; - break; - case 'd': - closequote = lstrtol(++arg, 0, &s); - if (s == arg) - pr_error("Missing number after -d"); - break; - case 'e': - if (strcmp(++arg, "-") == 0) - meta_escape = ""; - else - meta_escape = arg; - break; - case 'f': - meta_escape_buf[0] = lstrtol(++arg, 0, &s); - meta_escape = meta_escape_buf; - if (s == arg) - pr_error("Missing number after -f"); - break; - case 'o': - openquote = *++arg; - break; - case 'p': - openquote = lstrtol(++arg, 0, &s); - if (s == arg) - pr_error("Missing number after -p"); - break; - case 'm': - metachars[num_metachars++] = *++arg; - metachars[num_metachars] = '\0'; - break; - case 'n': - metachars[num_metachars++] = lstrtol(++arg, 0, &s); - if (s == arg) - pr_error("Missing number after -n"); - metachars[num_metachars] = '\0'; - break; - case '?': - pr_usage(); - return (0); - case '-': - if (*++arg == '\0') - { - no_more_options = 1; - break; - } - if (strcmp(arg, "version") == 0) - { - pr_version(); - return (0); - } - if (strcmp(arg, "help") == 0) - { - pr_usage(); - return (0); - } - pr_error("Invalid option after --"); - default: - pr_error("Invalid option letter"); - } - } + no_more_options = 0; + while (--argc > 0) + { + arg = *++argv; + if (*arg != '-' || no_more_options) + break; + switch (*++arg) + { + case 'a': + quote_all = 1; + break; + case 'c': + closequote = *++arg; + break; + case 'd': + closequote = lstrtol(++arg, 0, &s); + if (s == arg) + pr_error("Missing number after -d"); + break; + case 'e': + if (strcmp(++arg, "-") == 0) + meta_escape = ""; + else + meta_escape = arg; + break; + case 'f': + meta_escape_buf[0] = lstrtol(++arg, 0, &s); + meta_escape = meta_escape_buf; + if (s == arg) + pr_error("Missing number after -f"); + break; + case 'o': + openquote = *++arg; + break; + case 'p': + openquote = lstrtol(++arg, 0, &s); + if (s == arg) + pr_error("Missing number after -p"); + break; + case 'm': + metachars[num_metachars++] = *++arg; + metachars[num_metachars] = '\0'; + break; + case 'n': + metachars[num_metachars++] = lstrtol(++arg, 0, &s); + if (s == arg) + pr_error("Missing number after -n"); + metachars[num_metachars] = '\0'; + break; + case '?': + pr_usage(); + return (0); + case '-': + if (*++arg == '\0') + { + no_more_options = 1; + break; + } + if (strcmp(arg, "version") == 0) + { + pr_version(); + return (0); + } + if (strcmp(arg, "help") == 0) + { + pr_usage(); + return (0); + } + pr_error("Invalid option after --"); + default: + pr_error("Invalid option letter"); + } + } - while (argc-- > 0) - { - int has_meta = 0; - arg = *argv++; - for (s = arg; *s != '\0'; s++) - { - if (strchr(metachars, *s) != NULL) - { - has_meta = 1; - break; - } - } - if (quote_all || (has_meta && strlen(meta_escape) == 0)) - printf("%c%s%c", openquote, arg, closequote); - else - { - for (s = arg; *s != '\0'; s++) - { - if (strchr(metachars, *s) != NULL) - printf("%s", meta_escape); - printf("%c", *s); - } - } - if (argc > 0) - printf(" "); - else - printf("\n"); - } - return (0); + while (argc-- > 0) + { + int has_meta = 0; + arg = *argv++; + for (s = arg; *s != '\0'; s++) + { + if (strchr(metachars, *s) != NULL) + { + has_meta = 1; + break; + } + } + if (quote_all || (has_meta && strlen(meta_escape) == 0)) + printf("%c%s%c", openquote, arg, closequote); + else + { + for (s = arg; *s != '\0'; s++) + { + if (strchr(metachars, *s) != NULL) + printf("%s", meta_escape); + printf("%c", *s); + } + } + if (argc > 0) + printf(" "); + else + printf("\n"); + } + return (0); } diff --git a/lesskey.c b/lesskey.c index de7a9bf..386f915 100644 --- a/lesskey.c +++ b/lesskey.c @@ -11,7 +11,7 @@ /* * lesskey [-o output] [input] * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Make a .less file. * If no input file is specified, standard input is used. @@ -21,9 +21,9 @@ * key bindings. Basically any sequence of 1 to MAX_CMDLEN * keystrokes may be bound to an existing less function. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * The input file is an ascii file consisting of a + * The input file is an ascii file consisting of a * sequence of lines of the form: * string action [chars] * @@ -37,14 +37,14 @@ * to specify a character by its octal value. * 4. A backslash followed by b, e, n, r or t * to specify \b, ESC, \n, \r or \t, respectively. - * 5. Any character (other than those mentioned above) preceded + * 5. Any character (other than those mentioned above) preceded * by a \ to specify the character itself (characters which * must be preceded by \ include ^, \, and whitespace. * "action" is the name of a "less" action, from the table below. * "chars" is an optional sequence of characters which is treated * as keyboard input after the command is executed. * - * Blank lines and lines which start with # are ignored, + * Blank lines and lines which start with # are ignored, * except for the special control lines: * #command Signals the beginning of the command * keys section. @@ -55,7 +55,7 @@ * #stop Stops command parsing in less; * causes all default keys to be disabled. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * The output file is a non-ascii file, consisting of a header, * one or more sections, and a trailer. @@ -63,7 +63,7 @@ * and the section data. Normally there are three sections: * CMD_SECTION Definition of command keys. * EDIT_SECTION Definition of editing keys. - * END_SECTION A special section header, with no + * END_SECTION A special section header, with no * length word or section data. * * Section data consists of zero or more byte sequences of the form: @@ -77,7 +77,7 @@ * If action is ORed with A_EXTRA, the action byte is followed * by the null-terminated "chars" string. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "less.h" @@ -86,109 +86,109 @@ struct cmdname { - char *cn_name; - int cn_action; + char *cn_name; + int cn_action; }; -struct cmdname cmdnames[] = +struct cmdname cmdnames[] = { - { "back-bracket", A_B_BRACKET }, - { "back-line", A_B_LINE }, - { "back-line-force", A_BF_LINE }, - { "back-screen", A_B_SCREEN }, - { "back-scroll", A_B_SCROLL }, - { "back-search", A_B_SEARCH }, - { "back-window", A_B_WINDOW }, - { "clear-mark", A_CLRMARK }, - { "debug", A_DEBUG }, - { "digit", A_DIGIT }, - { "display-flag", A_DISP_OPTION }, - { "display-option", A_DISP_OPTION }, - { "end", A_GOEND }, - { "end-scroll", A_RRSHIFT }, - { "examine", A_EXAMINE }, - { "filter", A_FILTER }, - { "first-cmd", A_FIRSTCMD }, - { "firstcmd", A_FIRSTCMD }, - { "flush-repaint", A_FREPAINT }, - { "forw-bracket", A_F_BRACKET }, - { "forw-forever", A_F_FOREVER }, - { "forw-until-hilite", A_F_UNTIL_HILITE }, - { "forw-line", A_F_LINE }, - { "forw-line-force", A_FF_LINE }, - { "forw-screen", A_F_SCREEN }, - { "forw-screen-force", A_FF_SCREEN }, - { "forw-scroll", A_F_SCROLL }, - { "forw-search", A_F_SEARCH }, - { "forw-window", A_F_WINDOW }, - { "goto-end", A_GOEND }, - { "goto-end-buffered", A_GOEND_BUF }, - { "goto-line", A_GOLINE }, - { "goto-mark", A_GOMARK }, - { "help", A_HELP }, - { "index-file", A_INDEX_FILE }, - { "invalid", A_UINVALID }, - { "left-scroll", A_LSHIFT }, - { "next-file", A_NEXT_FILE }, - { "next-tag", A_NEXT_TAG }, - { "noaction", A_NOACTION }, - { "no-scroll", A_LLSHIFT }, - { "percent", A_PERCENT }, - { "pipe", A_PIPE }, - { "prev-file", A_PREV_FILE }, - { "prev-tag", A_PREV_TAG }, - { "quit", A_QUIT }, - { "remove-file", A_REMOVE_FILE }, - { "repaint", A_REPAINT }, - { "repaint-flush", A_FREPAINT }, - { "repeat-search", A_AGAIN_SEARCH }, - { "repeat-search-all", A_T_AGAIN_SEARCH }, - { "reverse-search", A_REVERSE_SEARCH }, - { "reverse-search-all", A_T_REVERSE_SEARCH }, - { "right-scroll", A_RSHIFT }, - { "set-mark", A_SETMARK }, - { "set-mark-bottom", A_SETMARKBOT }, - { "shell", A_SHELL }, - { "status", A_STAT }, - { "toggle-flag", A_OPT_TOGGLE }, - { "toggle-option", A_OPT_TOGGLE }, - { "undo-hilite", A_UNDO_SEARCH }, - { "clear-search", A_CLR_SEARCH }, - { "version", A_VERSION }, - { "visual", A_VISUAL }, - { NULL, 0 } + { "back-bracket", A_B_BRACKET }, + { "back-line", A_B_LINE }, + { "back-line-force", A_BF_LINE }, + { "back-screen", A_B_SCREEN }, + { "back-scroll", A_B_SCROLL }, + { "back-search", A_B_SEARCH }, + { "back-window", A_B_WINDOW }, + { "clear-mark", A_CLRMARK }, + { "debug", A_DEBUG }, + { "digit", A_DIGIT }, + { "display-flag", A_DISP_OPTION }, + { "display-option", A_DISP_OPTION }, + { "end", A_GOEND }, + { "end-scroll", A_RRSHIFT }, + { "examine", A_EXAMINE }, + { "filter", A_FILTER }, + { "first-cmd", A_FIRSTCMD }, + { "firstcmd", A_FIRSTCMD }, + { "flush-repaint", A_FREPAINT }, + { "forw-bracket", A_F_BRACKET }, + { "forw-forever", A_F_FOREVER }, + { "forw-until-hilite", A_F_UNTIL_HILITE }, + { "forw-line", A_F_LINE }, + { "forw-line-force", A_FF_LINE }, + { "forw-screen", A_F_SCREEN }, + { "forw-screen-force", A_FF_SCREEN }, + { "forw-scroll", A_F_SCROLL }, + { "forw-search", A_F_SEARCH }, + { "forw-window", A_F_WINDOW }, + { "goto-end", A_GOEND }, + { "goto-end-buffered", A_GOEND_BUF }, + { "goto-line", A_GOLINE }, + { "goto-mark", A_GOMARK }, + { "help", A_HELP }, + { "index-file", A_INDEX_FILE }, + { "invalid", A_UINVALID }, + { "left-scroll", A_LSHIFT }, + { "next-file", A_NEXT_FILE }, + { "next-tag", A_NEXT_TAG }, + { "noaction", A_NOACTION }, + { "no-scroll", A_LLSHIFT }, + { "percent", A_PERCENT }, + { "pipe", A_PIPE }, + { "prev-file", A_PREV_FILE }, + { "prev-tag", A_PREV_TAG }, + { "quit", A_QUIT }, + { "remove-file", A_REMOVE_FILE }, + { "repaint", A_REPAINT }, + { "repaint-flush", A_FREPAINT }, + { "repeat-search", A_AGAIN_SEARCH }, + { "repeat-search-all", A_T_AGAIN_SEARCH }, + { "reverse-search", A_REVERSE_SEARCH }, + { "reverse-search-all", A_T_REVERSE_SEARCH }, + { "right-scroll", A_RSHIFT }, + { "set-mark", A_SETMARK }, + { "set-mark-bottom", A_SETMARKBOT }, + { "shell", A_SHELL }, + { "status", A_STAT }, + { "toggle-flag", A_OPT_TOGGLE }, + { "toggle-option", A_OPT_TOGGLE }, + { "undo-hilite", A_UNDO_SEARCH }, + { "clear-search", A_CLR_SEARCH }, + { "version", A_VERSION }, + { "visual", A_VISUAL }, + { NULL, 0 } }; -struct cmdname editnames[] = +struct cmdname editnames[] = { - { "back-complete", EC_B_COMPLETE }, - { "backspace", EC_BACKSPACE }, - { "delete", EC_DELETE }, - { "down", EC_DOWN }, - { "end", EC_END }, - { "expand", EC_EXPAND }, - { "forw-complete", EC_F_COMPLETE }, - { "home", EC_HOME }, - { "insert", EC_INSERT }, - { "invalid", EC_UINVALID }, - { "kill-line", EC_LINEKILL }, - { "abort", EC_ABORT }, - { "left", EC_LEFT }, - { "literal", EC_LITERAL }, - { "right", EC_RIGHT }, - { "up", EC_UP }, - { "word-backspace", EC_W_BACKSPACE }, - { "word-delete", EC_W_DELETE }, - { "word-left", EC_W_LEFT }, - { "word-right", EC_W_RIGHT }, - { NULL, 0 } + { "back-complete", EC_B_COMPLETE }, + { "backspace", EC_BACKSPACE }, + { "delete", EC_DELETE }, + { "down", EC_DOWN }, + { "end", EC_END }, + { "expand", EC_EXPAND }, + { "forw-complete", EC_F_COMPLETE }, + { "home", EC_HOME }, + { "insert", EC_INSERT }, + { "invalid", EC_UINVALID }, + { "kill-line", EC_LINEKILL }, + { "abort", EC_ABORT }, + { "left", EC_LEFT }, + { "literal", EC_LITERAL }, + { "right", EC_RIGHT }, + { "up", EC_UP }, + { "word-backspace", EC_W_BACKSPACE }, + { "word-delete", EC_W_DELETE }, + { "word-left", EC_W_LEFT }, + { "word-right", EC_W_RIGHT }, + { NULL, 0 } }; struct table { - struct cmdname *names; - char *pbuffer; - char buffer[MAX_USERCMD]; + struct cmdname *names; + char *pbuffer; + char buffer[MAX_USERCMD]; }; struct table cmdtable; @@ -197,15 +197,15 @@ struct table vartable; struct table *currtable = &cmdtable; char fileheader[] = { - C0_LESSKEY_MAGIC, - C1_LESSKEY_MAGIC, - C2_LESSKEY_MAGIC, - C3_LESSKEY_MAGIC + C0_LESSKEY_MAGIC, + C1_LESSKEY_MAGIC, + C2_LESSKEY_MAGIC, + C3_LESSKEY_MAGIC }; char filetrailer[] = { - C0_END_LESSKEY_MAGIC, - C1_END_LESSKEY_MAGIC, - C2_END_LESSKEY_MAGIC + C0_END_LESSKEY_MAGIC, + C1_END_LESSKEY_MAGIC, + C2_END_LESSKEY_MAGIC }; char cmdsection[1] = { CMD_SECTION }; char editsection[1] = { EDIT_SECTION }; @@ -220,662 +220,662 @@ int errors; extern char version[]; - void + void usage(VOID_PARAM) { - fprintf(stderr, "usage: lesskey [-o output] [input]\n"); - exit(1); + fprintf(stderr, "usage: lesskey [-o output] [input]\n"); + exit(1); } - char * + char * mkpathname(dirname, filename) - char *dirname; - char *filename; + char *dirname; + char *filename; { - char *pathname; + char *pathname; - pathname = calloc(strlen(dirname) + strlen(filename) + 2, sizeof(char)); - strcpy(pathname, dirname); - strcat(pathname, PATHNAME_SEP); - strcat(pathname, filename); - return (pathname); + pathname = calloc(strlen(dirname) + strlen(filename) + 2, sizeof(char)); + strcpy(pathname, dirname); + strcat(pathname, PATHNAME_SEP); + strcat(pathname, filename); + return (pathname); } /* * Figure out the name of a default file (in the user's HOME directory). */ - char * + char * homefile(filename) - char *filename; + char *filename; { - char *p; - char *pathname; + char *p; + char *pathname; - if ((p = getenv("HOME")) != NULL && *p != '\0') - pathname = mkpathname(p, filename); + if ((p = getenv("HOME")) != NULL && *p != '\0') + pathname = mkpathname(p, filename); #if OS2 - else if ((p = getenv("INIT")) != NULL && *p != '\0') - pathname = mkpathname(p, filename); + else if ((p = getenv("INIT")) != NULL && *p != '\0') + pathname = mkpathname(p, filename); #endif - else - { - fprintf(stderr, "cannot find $HOME - using current directory\n"); - pathname = mkpathname(".", filename); - } - return (pathname); + else + { + fprintf(stderr, "cannot find $HOME - using current directory\n"); + pathname = mkpathname(".", filename); + } + return (pathname); } /* * Parse command line arguments. */ - void + void parse_args(argc, argv) - int argc; - char **argv; + int argc; + char **argv; { - char *arg; - - outfile = NULL; - while (--argc > 0) - { - arg = *++argv; - if (arg[0] != '-') - /* Arg does not start with "-"; it's not an option. */ - break; - if (arg[1] == '\0') - /* "-" means standard input. */ - break; - if (arg[1] == '-' && arg[2] == '\0') - { - /* "--" means end of options. */ - argc--; - argv++; - break; - } - switch (arg[1]) - { - case '-': - if (strncmp(arg, "--output", 8) == 0) - { - if (arg[8] == '\0') - outfile = &arg[8]; - else if (arg[8] == '=') - outfile = &arg[9]; - else - usage(); - goto opt_o; - } - if (strcmp(arg, "--version") == 0) - { - goto opt_V; - } - usage(); - break; - case 'o': - outfile = &argv[0][2]; - opt_o: - if (*outfile == '\0') - { - if (--argc <= 0) - usage(); - outfile = *(++argv); - } - break; - case 'V': - opt_V: - printf("lesskey version %s\n", version); - exit(0); - default: - usage(); - } - } - if (argc > 1) - usage(); - /* - * Open the input file, or use DEF_LESSKEYINFILE if none specified. - */ - if (argc > 0) - infile = *argv; - else - infile = homefile(DEF_LESSKEYINFILE); + char *arg; + + outfile = NULL; + while (--argc > 0) + { + arg = *++argv; + if (arg[0] != '-') + /* Arg does not start with "-"; it's not an option. */ + break; + if (arg[1] == '\0') + /* "-" means standard input. */ + break; + if (arg[1] == '-' && arg[2] == '\0') + { + /* "--" means end of options. */ + argc--; + argv++; + break; + } + switch (arg[1]) + { + case '-': + if (strncmp(arg, "--output", 8) == 0) + { + if (arg[8] == '\0') + outfile = &arg[8]; + else if (arg[8] == '=') + outfile = &arg[9]; + else + usage(); + goto opt_o; + } + if (strcmp(arg, "--version") == 0) + { + goto opt_V; + } + usage(); + break; + case 'o': + outfile = &argv[0][2]; + opt_o: + if (*outfile == '\0') + { + if (--argc <= 0) + usage(); + outfile = *(++argv); + } + break; + case 'V': + opt_V: + printf("lesskey version %s\n", version); + exit(0); + default: + usage(); + } + } + if (argc > 1) + usage(); + /* + * Open the input file, or use DEF_LESSKEYINFILE if none specified. + */ + if (argc > 0) + infile = *argv; + else + infile = homefile(DEF_LESSKEYINFILE); } /* * Initialize data structures. */ - void + void init_tables(VOID_PARAM) { - cmdtable.names = cmdnames; - cmdtable.pbuffer = cmdtable.buffer; + cmdtable.names = cmdnames; + cmdtable.pbuffer = cmdtable.buffer; - edittable.names = editnames; - edittable.pbuffer = edittable.buffer; + edittable.names = editnames; + edittable.pbuffer = edittable.buffer; - vartable.names = NULL; - vartable.pbuffer = vartable.buffer; + vartable.names = NULL; + vartable.pbuffer = vartable.buffer; } /* * Parse one character of a string. */ - char * + char * tstr(pp, xlate) - char **pp; - int xlate; + char **pp; + int xlate; { - char *p; - char ch; - int i; - static char buf[10]; - static char tstr_control_k[] = - { SK_SPECIAL_KEY, SK_CONTROL_K, 6, 1, 1, 1, '\0' }; - - p = *pp; - switch (*p) - { - case '\\': - ++p; - switch (*p) - { - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - /* - * Parse an octal number. - */ - ch = 0; - i = 0; - do - ch = 8*ch + (*p - '0'); - while (*++p >= '0' && *p <= '7' && ++i < 3); - *pp = p; - if (xlate && ch == CONTROL('K')) - return tstr_control_k; - buf[0] = ch; - buf[1] = '\0'; - return (buf); - case 'b': - *pp = p+1; - return ("\b"); - case 'e': - *pp = p+1; - buf[0] = ESC; - buf[1] = '\0'; - return (buf); - case 'n': - *pp = p+1; - return ("\n"); - case 'r': - *pp = p+1; - return ("\r"); - case 't': - *pp = p+1; - return ("\t"); - case 'k': - if (xlate) - { - switch (*++p) - { - case 'u': ch = SK_UP_ARROW; break; - case 'd': ch = SK_DOWN_ARROW; break; - case 'r': ch = SK_RIGHT_ARROW; break; - case 'l': ch = SK_LEFT_ARROW; break; - case 'U': ch = SK_PAGE_UP; break; - case 'D': ch = SK_PAGE_DOWN; break; - case 'h': ch = SK_HOME; break; - case 'e': ch = SK_END; break; - case 'x': ch = SK_DELETE; break; - default: - error("illegal char after \\k", NULL_PARG); - *pp = p+1; - return (""); - } - *pp = p+1; - buf[0] = SK_SPECIAL_KEY; - buf[1] = ch; - buf[2] = 6; - buf[3] = 1; - buf[4] = 1; - buf[5] = 1; - buf[6] = '\0'; - return (buf); - } - /* FALLTHRU */ - default: - /* - * Backslash followed by any other char - * just means that char. - */ - *pp = p+1; - buf[0] = *p; - buf[1] = '\0'; - if (xlate && buf[0] == CONTROL('K')) - return tstr_control_k; - return (buf); - } - case '^': - /* - * Caret means CONTROL. - */ - *pp = p+2; - buf[0] = CONTROL(p[1]); - buf[1] = '\0'; - if (xlate && buf[0] == CONTROL('K')) - return tstr_control_k; - return (buf); - } - *pp = p+1; - buf[0] = *p; - buf[1] = '\0'; - if (xlate && buf[0] == CONTROL('K')) - return tstr_control_k; - return (buf); + char *p; + char ch; + int i; + static char buf[10]; + static char tstr_control_k[] = + { SK_SPECIAL_KEY, SK_CONTROL_K, 6, 1, 1, 1, '\0' }; + + p = *pp; + switch (*p) + { + case '\\': + ++p; + switch (*p) + { + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + /* + * Parse an octal number. + */ + ch = 0; + i = 0; + do + ch = 8*ch + (*p - '0'); + while (*++p >= '0' && *p <= '7' && ++i < 3); + *pp = p; + if (xlate && ch == CONTROL('K')) + return tstr_control_k; + buf[0] = ch; + buf[1] = '\0'; + return (buf); + case 'b': + *pp = p+1; + return ("\b"); + case 'e': + *pp = p+1; + buf[0] = ESC; + buf[1] = '\0'; + return (buf); + case 'n': + *pp = p+1; + return ("\n"); + case 'r': + *pp = p+1; + return ("\r"); + case 't': + *pp = p+1; + return ("\t"); + case 'k': + if (xlate) + { + switch (*++p) + { + case 'u': ch = SK_UP_ARROW; break; + case 'd': ch = SK_DOWN_ARROW; break; + case 'r': ch = SK_RIGHT_ARROW; break; + case 'l': ch = SK_LEFT_ARROW; break; + case 'U': ch = SK_PAGE_UP; break; + case 'D': ch = SK_PAGE_DOWN; break; + case 'h': ch = SK_HOME; break; + case 'e': ch = SK_END; break; + case 'x': ch = SK_DELETE; break; + default: + error("illegal char after \\k", NULL_PARG); + *pp = p+1; + return (""); + } + *pp = p+1; + buf[0] = SK_SPECIAL_KEY; + buf[1] = ch; + buf[2] = 6; + buf[3] = 1; + buf[4] = 1; + buf[5] = 1; + buf[6] = '\0'; + return (buf); + } + /* FALLTHRU */ + default: + /* + * Backslash followed by any other char + * just means that char. + */ + *pp = p+1; + buf[0] = *p; + buf[1] = '\0'; + if (xlate && buf[0] == CONTROL('K')) + return tstr_control_k; + return (buf); + } + case '^': + /* + * Caret means CONTROL. + */ + *pp = p+2; + buf[0] = CONTROL(p[1]); + buf[1] = '\0'; + if (xlate && buf[0] == CONTROL('K')) + return tstr_control_k; + return (buf); + } + *pp = p+1; + buf[0] = *p; + buf[1] = '\0'; + if (xlate && buf[0] == CONTROL('K')) + return tstr_control_k; + return (buf); } /* * Skip leading spaces in a string. */ - public char * + public char * skipsp(s) - char *s; + char *s; { - while (*s == ' ' || *s == '\t') - s++; - return (s); + while (*s == ' ' || *s == '\t') + s++; + return (s); } /* * Skip non-space characters in a string. */ - public char * + public char * skipnsp(s) - char *s; + char *s; { - while (*s != '\0' && *s != ' ' && *s != '\t') - s++; - return (s); + while (*s != '\0' && *s != ' ' && *s != '\t') + s++; + return (s); } /* * Clean up an input line: * strip off the trailing newline & any trailing # comment. */ - char * + char * clean_line(s) - char *s; + char *s; { - int i; - - s = skipsp(s); - for (i = 0; s[i] != '\n' && s[i] != '\r' && s[i] != '\0'; i++) - if (s[i] == '#' && (i == 0 || s[i-1] != '\\')) - break; - s[i] = '\0'; - return (s); + int i; + + s = skipsp(s); + for (i = 0; s[i] != '\n' && s[i] != '\r' && s[i] != '\0'; i++) + if (s[i] == '#' && (i == 0 || s[i-1] != '\\')) + break; + s[i] = '\0'; + return (s); } /* * Add a byte to the output command table. */ - void + void add_cmd_char(c) - int c; + int c; { - if (currtable->pbuffer >= currtable->buffer + MAX_USERCMD) - { - error("too many commands", NULL_PARG); - exit(1); - } - *(currtable->pbuffer)++ = c; + if (currtable->pbuffer >= currtable->buffer + MAX_USERCMD) + { + error("too many commands", NULL_PARG); + exit(1); + } + *(currtable->pbuffer)++ = c; } /* * Add a string to the output command table. */ - void + void add_cmd_str(s) - char *s; + char *s; { - for ( ; *s != '\0'; s++) - add_cmd_char(*s); + for ( ; *s != '\0'; s++) + add_cmd_char(*s); } /* * See if we have a special "control" line. */ - int + int control_line(s) - char *s; + char *s; { #define PREFIX(str,pat) (strncmp(str,pat,strlen(pat)) == 0) - if (PREFIX(s, "#line-edit")) - { - currtable = &edittable; - return (1); - } - if (PREFIX(s, "#command")) - { - currtable = &cmdtable; - return (1); - } - if (PREFIX(s, "#env")) - { - currtable = &vartable; - return (1); - } - if (PREFIX(s, "#stop")) - { - add_cmd_char('\0'); - add_cmd_char(A_END_LIST); - return (1); - } - return (0); + if (PREFIX(s, "#line-edit")) + { + currtable = &edittable; + return (1); + } + if (PREFIX(s, "#command")) + { + currtable = &cmdtable; + return (1); + } + if (PREFIX(s, "#env")) + { + currtable = &vartable; + return (1); + } + if (PREFIX(s, "#stop")) + { + add_cmd_char('\0'); + add_cmd_char(A_END_LIST); + return (1); + } + return (0); } /* * Output some bytes. */ - void + void fputbytes(fd, buf, len) - FILE *fd; - char *buf; - int len; + FILE *fd; + char *buf; + int len; { - while (len-- > 0) - { - fwrite(buf, sizeof(char), 1, fd); - buf++; - } + while (len-- > 0) + { + fwrite(buf, sizeof(char), 1, fd); + buf++; + } } /* * Output an integer, in special KRADIX form. */ - void + void fputint(fd, val) - FILE *fd; - unsigned int val; + FILE *fd; + unsigned int val; { - char c; - - if (val >= KRADIX*KRADIX) - { - fprintf(stderr, "error: integer too big (%d > %d)\n", - val, KRADIX*KRADIX); - exit(1); - } - c = val % KRADIX; - fwrite(&c, sizeof(char), 1, fd); - c = val / KRADIX; - fwrite(&c, sizeof(char), 1, fd); + char c; + + if (val >= KRADIX*KRADIX) + { + fprintf(stderr, "error: integer too big (%d > %d)\n", + val, KRADIX*KRADIX); + exit(1); + } + c = val % KRADIX; + fwrite(&c, sizeof(char), 1, fd); + c = val / KRADIX; + fwrite(&c, sizeof(char), 1, fd); } /* * Find an action, given the name of the action. */ - int + int findaction(actname) - char *actname; + char *actname; { - int i; + int i; - for (i = 0; currtable->names[i].cn_name != NULL; i++) - if (strcmp(currtable->names[i].cn_name, actname) == 0) - return (currtable->names[i].cn_action); - error("unknown action", NULL_PARG); - return (A_INVALID); + for (i = 0; currtable->names[i].cn_name != NULL; i++) + if (strcmp(currtable->names[i].cn_name, actname) == 0) + return (currtable->names[i].cn_action); + error("unknown action", NULL_PARG); + return (A_INVALID); } - void + void error(s, parg) - char *s; - PARG *parg; + char *s; + PARG *parg; { - fprintf(stderr, "line %d: %s\n", linenum, s); - errors++; - (void) parg; + fprintf(stderr, "line %d: %s\n", linenum, s); + errors++; + (void) parg; } - void + void parse_cmdline(p) - char *p; + char *p; { - int cmdlen; - char *actname; - int action; - char *s; - char c; - - /* - * Parse the command string and store it in the current table. - */ - cmdlen = 0; - do - { - s = tstr(&p, 1); - cmdlen += (int) strlen(s); - if (cmdlen > MAX_CMDLEN) - error("command too long", NULL_PARG); - else - add_cmd_str(s); - } while (*p != ' ' && *p != '\t' && *p != '\0'); - /* - * Terminate the command string with a null byte. - */ - add_cmd_char('\0'); - - /* - * Skip white space between the command string - * and the action name. - * Terminate the action name with a null byte. - */ - p = skipsp(p); - if (*p == '\0') - { - error("missing action", NULL_PARG); - return; - } - actname = p; - p = skipnsp(p); - c = *p; - *p = '\0'; - - /* - * Parse the action name and store it in the current table. - */ - action = findaction(actname); - - /* - * See if an extra string follows the action name. - */ - *p = c; - p = skipsp(p); - if (*p == '\0') - { - add_cmd_char(action); - } else - { - /* - * OR the special value A_EXTRA into the action byte. - * Put the extra string after the action byte. - */ - add_cmd_char(action | A_EXTRA); - while (*p != '\0') - add_cmd_str(tstr(&p, 0)); - add_cmd_char('\0'); - } + int cmdlen; + char *actname; + int action; + char *s; + char c; + + /* + * Parse the command string and store it in the current table. + */ + cmdlen = 0; + do + { + s = tstr(&p, 1); + cmdlen += (int) strlen(s); + if (cmdlen > MAX_CMDLEN) + error("command too long", NULL_PARG); + else + add_cmd_str(s); + } while (*p != ' ' && *p != '\t' && *p != '\0'); + /* + * Terminate the command string with a null byte. + */ + add_cmd_char('\0'); + + /* + * Skip white space between the command string + * and the action name. + * Terminate the action name with a null byte. + */ + p = skipsp(p); + if (*p == '\0') + { + error("missing action", NULL_PARG); + return; + } + actname = p; + p = skipnsp(p); + c = *p; + *p = '\0'; + + /* + * Parse the action name and store it in the current table. + */ + action = findaction(actname); + + /* + * See if an extra string follows the action name. + */ + *p = c; + p = skipsp(p); + if (*p == '\0') + { + add_cmd_char(action); + } else + { + /* + * OR the special value A_EXTRA into the action byte. + * Put the extra string after the action byte. + */ + add_cmd_char(action | A_EXTRA); + while (*p != '\0') + add_cmd_str(tstr(&p, 0)); + add_cmd_char('\0'); + } } - void + void parse_varline(p) - char *p; + char *p; { - char *s; - - do - { - s = tstr(&p, 0); - add_cmd_str(s); - } while (*p != ' ' && *p != '\t' && *p != '=' && *p != '\0'); - /* - * Terminate the variable name with a null byte. - */ - add_cmd_char('\0'); - - p = skipsp(p); - if (*p++ != '=') - { - error("missing =", NULL_PARG); - return; - } - - add_cmd_char(EV_OK|A_EXTRA); - - p = skipsp(p); - while (*p != '\0') - { - s = tstr(&p, 0); - add_cmd_str(s); - } - add_cmd_char('\0'); + char *s; + + do + { + s = tstr(&p, 0); + add_cmd_str(s); + } while (*p != ' ' && *p != '\t' && *p != '=' && *p != '\0'); + /* + * Terminate the variable name with a null byte. + */ + add_cmd_char('\0'); + + p = skipsp(p); + if (*p++ != '=') + { + error("missing =", NULL_PARG); + return; + } + + add_cmd_char(EV_OK|A_EXTRA); + + p = skipsp(p); + while (*p != '\0') + { + s = tstr(&p, 0); + add_cmd_str(s); + } + add_cmd_char('\0'); } /* * Parse a line from the lesskey file. */ - void + void parse_line(line) - char *line; + char *line; { - char *p; - - /* - * See if it is a control line. - */ - if (control_line(line)) - return; - /* - * Skip leading white space. - * Replace the final newline with a null byte. - * Ignore blank lines and comments. - */ - p = clean_line(line); - if (*p == '\0') - return; - - if (currtable == &vartable) - parse_varline(p); - else - parse_cmdline(p); + char *p; + + /* + * See if it is a control line. + */ + if (control_line(line)) + return; + /* + * Skip leading white space. + * Replace the final newline with a null byte. + * Ignore blank lines and comments. + */ + p = clean_line(line); + if (*p == '\0') + return; + + if (currtable == &vartable) + parse_varline(p); + else + parse_cmdline(p); } - int + int main(argc, argv) - int argc; - char *argv[]; + int argc; + char *argv[]; { - FILE *desc; - FILE *out; - char line[1024]; + FILE *desc; + FILE *out; + char line[1024]; #ifdef WIN32 - if (getenv("HOME") == NULL) - { - /* - * If there is no HOME environment variable, - * try the concatenation of HOMEDRIVE + HOMEPATH. - */ - char *drive = getenv("HOMEDRIVE"); - char *path = getenv("HOMEPATH"); - if (drive != NULL && path != NULL) - { - char *env = (char *) calloc(strlen(drive) + - strlen(path) + 6, sizeof(char)); - strcpy(env, "HOME="); - strcat(env, drive); - strcat(env, path); - putenv(env); - } - } + if (getenv("HOME") == NULL) + { + /* + * If there is no HOME environment variable, + * try the concatenation of HOMEDRIVE + HOMEPATH. + */ + char *drive = getenv("HOMEDRIVE"); + char *path = getenv("HOMEPATH"); + if (drive != NULL && path != NULL) + { + char *env = (char *) calloc(strlen(drive) + + strlen(path) + 6, sizeof(char)); + strcpy(env, "HOME="); + strcat(env, drive); + strcat(env, path); + putenv(env); + } + } #endif /* WIN32 */ - /* - * Process command line arguments. - */ - parse_args(argc, argv); - init_tables(); - - /* - * Open the input file. - */ - if (strcmp(infile, "-") == 0) - desc = stdin; - else if ((desc = fopen(infile, "r")) == NULL) - { + /* + * Process command line arguments. + */ + parse_args(argc, argv); + init_tables(); + + /* + * Open the input file. + */ + if (strcmp(infile, "-") == 0) + desc = stdin; + else if ((desc = fopen(infile, "r")) == NULL) + { #if HAVE_PERROR - perror(infile); + perror(infile); #else - fprintf(stderr, "Cannot open %s\n", infile); + fprintf(stderr, "Cannot open %s\n", infile); #endif - usage(); - } - - /* - * Read and parse the input file, one line at a time. - */ - errors = 0; - linenum = 0; - while (fgets(line, sizeof(line), desc) != NULL) - { - ++linenum; - parse_line(line); - } - - /* - * Write the output file. - * If no output file was specified, use "$HOME/.less" - */ - if (errors > 0) - { - fprintf(stderr, "%d errors; no output produced\n", errors); - exit(1); - } - - if (outfile == NULL) - outfile = getenv("LESSKEY"); - if (outfile == NULL) - outfile = homefile(LESSKEYFILE); - if ((out = fopen(outfile, "wb")) == NULL) - { + usage(); + } + + /* + * Read and parse the input file, one line at a time. + */ + errors = 0; + linenum = 0; + while (fgets(line, sizeof(line), desc) != NULL) + { + ++linenum; + parse_line(line); + } + + /* + * Write the output file. + * If no output file was specified, use "$HOME/.less" + */ + if (errors > 0) + { + fprintf(stderr, "%d errors; no output produced\n", errors); + exit(1); + } + + if (outfile == NULL) + outfile = getenv("LESSKEY"); + if (outfile == NULL) + outfile = homefile(LESSKEYFILE); + if ((out = fopen(outfile, "wb")) == NULL) + { #if HAVE_PERROR - perror(outfile); + perror(outfile); #else - fprintf(stderr, "Cannot open %s\n", outfile); + fprintf(stderr, "Cannot open %s\n", outfile); #endif - exit(1); - } - - /* File header */ - fputbytes(out, fileheader, sizeof(fileheader)); - - /* Command key section */ - fputbytes(out, cmdsection, sizeof(cmdsection)); - fputint(out, cmdtable.pbuffer - cmdtable.buffer); - fputbytes(out, (char *)cmdtable.buffer, cmdtable.pbuffer-cmdtable.buffer); - /* Edit key section */ - fputbytes(out, editsection, sizeof(editsection)); - fputint(out, edittable.pbuffer - edittable.buffer); - fputbytes(out, (char *)edittable.buffer, edittable.pbuffer-edittable.buffer); - - /* Environment variable section */ - fputbytes(out, varsection, sizeof(varsection)); - fputint(out, vartable.pbuffer - vartable.buffer); - fputbytes(out, (char *)vartable.buffer, vartable.pbuffer-vartable.buffer); - - /* File trailer */ - fputbytes(out, endsection, sizeof(endsection)); - fputbytes(out, filetrailer, sizeof(filetrailer)); - return (0); + exit(1); + } + + /* File header */ + fputbytes(out, fileheader, sizeof(fileheader)); + + /* Command key section */ + fputbytes(out, cmdsection, sizeof(cmdsection)); + fputint(out, cmdtable.pbuffer - cmdtable.buffer); + fputbytes(out, (char *)cmdtable.buffer, cmdtable.pbuffer-cmdtable.buffer); + /* Edit key section */ + fputbytes(out, editsection, sizeof(editsection)); + fputint(out, edittable.pbuffer - edittable.buffer); + fputbytes(out, (char *)edittable.buffer, edittable.pbuffer-edittable.buffer); + + /* Environment variable section */ + fputbytes(out, varsection, sizeof(varsection)); + fputint(out, vartable.pbuffer - vartable.buffer); + fputbytes(out, (char *)vartable.buffer, vartable.pbuffer-vartable.buffer); + + /* File trailer */ + fputbytes(out, endsection, sizeof(endsection)); + fputbytes(out, filetrailer, sizeof(filetrailer)); + return (0); } diff --git a/lesskey.nro b/lesskey.nro index 1f8e5b3..7f7487d 100644 --- a/lesskey.nro +++ b/lesskey.nro @@ -65,7 +65,7 @@ If the command section is the first section in the file, this line may be omitted. The command section consists of lines of the form: .sp - \fIstring\fP \fIaction\fP [extra-string] + \fIstring\fP \fIaction\fP [extra-string] .sp Whitespace is any sequence of one or more spaces and/or tabs. The \fIstring\fP is the command key(s) which invoke the action. @@ -133,124 +133,124 @@ default command keys used by less: .TS l l. #command -\er forw-line -\en forw-line -e forw-line -j forw-line -\ekd forw-line -^E forw-line -^N forw-line -k back-line -y back-line -^Y back-line -^K back-line -^P back-line -J forw-line-force -K back-line-force -Y back-line-force -d forw-scroll -^D forw-scroll -u back-scroll -^U back-scroll -\e40 forw-screen -f forw-screen -^F forw-screen -^V forw-screen -\ekD forw-screen -b back-screen -^B back-screen -\eev back-screen -\ekU back-screen -z forw-window -w back-window -\ee\e40 forw-screen-force -F forw-forever -\eeF forw-until-hilite -R repaint-flush -r repaint -^R repaint -^L repaint -\eeu undo-hilite -\eeU clear-search -g goto-line -\ekh goto-line -< goto-line -\ee< goto-line -p percent -% percent -\ee[ left-scroll -\ee] right-scroll -\ee( left-scroll -\ee) right-scroll -\ekl left-scroll -\ekr right-scroll -\ee{ no-scroll -\ee} end-scroll -{ forw-bracket {} -} back-bracket {} -( forw-bracket () -) back-bracket () -[ forw-bracket [] -] back-bracket [] -\ee^F forw-bracket -\ee^B back-bracket -G goto-end -\ee> goto-end -> goto-end -\eke goto-end -\eeG goto-end-buffered -\&= status -^G status -:f status -/ forw-search -? back-search -\ee/ forw-search * -\ee? back-search * -n repeat-search -\een repeat-search-all -N reverse-search -\eeN reverse-search-all -& filter -m set-mark -M set-mark-bottom -\eem clear-mark -' goto-mark -^X^X goto-mark -E examine -:e examine -^X^V examine -:n next-file -:p prev-file -t next-tag -T prev-tag -:x index-file -:d remove-file -- toggle-option -:t toggle-option t -s toggle-option o -\&_ display-option -| pipe -v visual -! shell -+ firstcmd -H help -h help -V version -0 digit -1 digit -2 digit -3 digit -4 digit -5 digit -6 digit -7 digit -8 digit -9 digit -q quit -Q quit -:q quit -:Q quit -ZZ quit +\er forw-line +\en forw-line +e forw-line +j forw-line +\ekd forw-line +^E forw-line +^N forw-line +k back-line +y back-line +^Y back-line +^K back-line +^P back-line +J forw-line-force +K back-line-force +Y back-line-force +d forw-scroll +^D forw-scroll +u back-scroll +^U back-scroll +\e40 forw-screen +f forw-screen +^F forw-screen +^V forw-screen +\ekD forw-screen +b back-screen +^B back-screen +\eev back-screen +\ekU back-screen +z forw-window +w back-window +\ee\e40 forw-screen-force +F forw-forever +\eeF forw-until-hilite +R repaint-flush +r repaint +^R repaint +^L repaint +\eeu undo-hilite +\eeU clear-search +g goto-line +\ekh goto-line +< goto-line +\ee< goto-line +p percent +% percent +\ee[ left-scroll +\ee] right-scroll +\ee( left-scroll +\ee) right-scroll +\ekl left-scroll +\ekr right-scroll +\ee{ no-scroll +\ee} end-scroll +{ forw-bracket {} +} back-bracket {} +( forw-bracket () +) back-bracket () +[ forw-bracket [] +] back-bracket [] +\ee^F forw-bracket +\ee^B back-bracket +G goto-end +\ee> goto-end +> goto-end +\eke goto-end +\eeG goto-end-buffered +\&= status +^G status +:f status +/ forw-search +? back-search +\ee/ forw-search * +\ee? back-search * +n repeat-search +\een repeat-search-all +N reverse-search +\eeN reverse-search-all +& filter +m set-mark +M set-mark-bottom +\eem clear-mark +' goto-mark +^X^X goto-mark +E examine +:e examine +^X^V examine +:n next-file +:p prev-file +t next-tag +T prev-tag +:x index-file +:d remove-file +- toggle-option +:t toggle-option t +s toggle-option o +\&_ display-option +| pipe +v visual +! shell ++ firstcmd +H help +h help +V version +0 digit +1 digit +2 digit +3 digit +4 digit +5 digit +6 digit +7 digit +8 digit +9 digit +q quit +Q quit +:q quit +:Q quit +ZZ quit .TE .RE .sp @@ -299,34 +299,34 @@ default line-editing keys used by less: .TS l l. #line-edit -\et forw-complete -\e17 back-complete -\ee\et back-complete -^L expand -^V literal -^A literal -\eel right -\ekr right -\eeh left -\ekl left -\eeb word-left -\ee\ekl word-left -\eew word-right -\ee\ekr word-right -\eei insert -\eex delete -\ekx delete -\eeX word-delete -\eekx word-delete -\ee\eb word-backspace -\ee0 home -\ekh home -\ee$ end -\eke end -\eek up -\eku up -\eej down -^G abort +\et forw-complete +\e17 back-complete +\ee\et back-complete +^L expand +^V literal +^A literal +\eel right +\ekr right +\eeh left +\ekl left +\eeb word-left +\ee\ekl word-left +\eew word-right +\ee\ekr word-right +\eei insert +\eex delete +\ekx delete +\eeX word-delete +\eekx word-delete +\ee\eb word-backspace +\ee0 home +\ekh home +\ee$ end +\eke end +\eek up +\eku up +\eej down +^G abort .TE .RE .sp @@ -356,9 +356,9 @@ The following input file sets the \-i option whenever is run, and specifies the character set to be "latin1": .sp .nf - #env - LESS = \-i - LESSCHARSET = latin1 + #env + LESS = \-i + LESSCHARSET = latin1 .fi .sp . diff --git a/line.c b/line.c index 57d3cbe..6872fed 100644 --- a/line.c +++ b/line.c @@ -24,19 +24,19 @@ #define MAX_PFX_WIDTH (MAX_LINENUM_WIDTH + MAX_STATUSCOL_WIDTH + 1) static struct { - char *buf; /* Buffer which holds the current output line */ - int *attr; /* Parallel to buf, to hold attributes */ - int print; /* Index in buf of first printable char */ - int end; /* Number of chars in buf */ - char pfx[MAX_PFX_WIDTH]; /* Holds status column and line number */ - int pfx_attr[MAX_PFX_WIDTH]; - int pfx_end; /* Number of chars in pfx */ + char *buf; /* Buffer which holds the current output line */ + int *attr; /* Parallel to buf, to hold attributes */ + int print; /* Index in buf of first printable char */ + int end; /* Number of chars in buf */ + char pfx[MAX_PFX_WIDTH]; /* Holds status column and line number */ + int pfx_attr[MAX_PFX_WIDTH]; + int pfx_end; /* Number of chars in pfx */ } linebuf; static struct { - char *buf; - int size; - int end; + char *buf; + int size; + int end; } shifted_ansi; public int size_linebuf = 0; /* Size of line buffer (and attr buffer) */ @@ -92,349 +92,349 @@ static POSITION mbc_pos; /* Configurable color map */ static char color_map[AT_NUM_COLORS][12] = { - "Wm", /* AT_COLOR_ATTN */ - "kR", /* AT_COLOR_BIN */ - "kR", /* AT_COLOR_CTRL */ - "kY", /* AT_COLOR_ERROR */ - "c", /* AT_COLOR_LINENUM */ - "Wb", /* AT_COLOR_MARK */ - "kC", /* AT_COLOR_PROMPT */ - "kc", /* AT_COLOR_RSCROLL */ - "kG", /* AT_COLOR_SEARCH */ - "", /* AT_UNDERLINE */ - "", /* AT_BOLD */ - "", /* AT_BLINK */ - "", /* AT_STANDOUT */ + "Wm", /* AT_COLOR_ATTN */ + "kR", /* AT_COLOR_BIN */ + "kR", /* AT_COLOR_CTRL */ + "kY", /* AT_COLOR_ERROR */ + "c", /* AT_COLOR_LINENUM */ + "Wb", /* AT_COLOR_MARK */ + "kC", /* AT_COLOR_PROMPT */ + "kc", /* AT_COLOR_RSCROLL */ + "kG", /* AT_COLOR_SEARCH */ + "", /* AT_UNDERLINE */ + "", /* AT_BOLD */ + "", /* AT_BLINK */ + "", /* AT_STANDOUT */ }; /* State while processing an ANSI escape sequence */ struct ansi_state { - int hindex; /* Index into hyperlink prefix */ - int hlink; /* Processing hyperlink address? */ - int prev_esc; /* Prev char was ESC (to detect ESC-\ seq) */ + int hindex; /* Index into hyperlink prefix */ + int hlink; /* Processing hyperlink address? */ + int prev_esc; /* Prev char was ESC (to detect ESC-\ seq) */ }; /* * Initialize from environment variables. */ - public void + public void init_line(VOID_PARAM) { - end_ansi_chars = lgetenv("LESSANSIENDCHARS"); - if (isnullenv(end_ansi_chars)) - end_ansi_chars = "m"; - - mid_ansi_chars = lgetenv("LESSANSIMIDCHARS"); - if (isnullenv(mid_ansi_chars)) - mid_ansi_chars = "0123456789:;[?!\"'#%()*+ "; - - linebuf.buf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); - linebuf.attr = (int *) ecalloc(LINEBUF_SIZE, sizeof(int)); - size_linebuf = LINEBUF_SIZE; - shifted_ansi.buf = NULL; - shifted_ansi.size = 0; + end_ansi_chars = lgetenv("LESSANSIENDCHARS"); + if (isnullenv(end_ansi_chars)) + end_ansi_chars = "m"; + + mid_ansi_chars = lgetenv("LESSANSIMIDCHARS"); + if (isnullenv(mid_ansi_chars)) + mid_ansi_chars = "0123456789:;[?!\"'#%()*+ "; + + linebuf.buf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); + linebuf.attr = (int *) ecalloc(LINEBUF_SIZE, sizeof(int)); + size_linebuf = LINEBUF_SIZE; + shifted_ansi.buf = NULL; + shifted_ansi.size = 0; } /* * Expand the line buffer. */ - static int + static int expand_linebuf(VOID_PARAM) { - /* Double the size of the line buffer. */ - int new_size = size_linebuf * 2; + /* Double the size of the line buffer. */ + int new_size = size_linebuf * 2; - /* Just realloc to expand the buffer, if we can. */ + /* Just realloc to expand the buffer, if we can. */ #if HAVE_REALLOC - char *new_buf = (char *) realloc(linebuf.buf, new_size); - int *new_attr = (int *) realloc(linebuf.attr, new_size*sizeof(int)); + char *new_buf = (char *) realloc(linebuf.buf, new_size); + int *new_attr = (int *) realloc(linebuf.attr, new_size*sizeof(int)); #else - char *new_buf = (char *) calloc(new_size, sizeof(char)); - int *new_attr = (int *) calloc(new_size, sizeof(int)); + char *new_buf = (char *) calloc(new_size, sizeof(char)); + int *new_attr = (int *) calloc(new_size, sizeof(int)); #endif - if (new_buf == NULL || new_attr == NULL) - { - if (new_attr != NULL) - free(new_attr); - if (new_buf != NULL) - free(new_buf); - return 1; - } + if (new_buf == NULL || new_attr == NULL) + { + if (new_attr != NULL) + free(new_attr); + if (new_buf != NULL) + free(new_buf); + return 1; + } #if !HAVE_REALLOC - /* - * We just calloc'd the buffers; copy the old contents. - */ - memcpy(new_buf, linebuf.buf, size_linebuf * sizeof(char)); - memcpy(new_attr, linebuf.attr, size_linebuf * sizeof(int)); - free(linebuf.attr); - free(linebuf.buf); + /* + * We just calloc'd the buffers; copy the old contents. + */ + memcpy(new_buf, linebuf.buf, size_linebuf * sizeof(char)); + memcpy(new_attr, linebuf.attr, size_linebuf * sizeof(int)); + free(linebuf.attr); + free(linebuf.buf); #endif - linebuf.buf = new_buf; - linebuf.attr = new_attr; - size_linebuf = new_size; - return 0; + linebuf.buf = new_buf; + linebuf.attr = new_attr; + size_linebuf = new_size; + return 0; } /* * Is a character ASCII? */ - public int + public int is_ascii_char(ch) - LWCHAR ch; + LWCHAR ch; { - return (ch <= 0x7F); + return (ch <= 0x7F); } /* */ - static void + static void inc_end_column(w) - int w; + int w; { - if (end_column > right_column && w > 0) - { - right_column = end_column; - right_curr = linebuf.end; - } - end_column += w; + if (end_column > right_column && w > 0) + { + right_column = end_column; + right_curr = linebuf.end; + } + end_column += w; } /* * Rewind the line buffer. */ - public void + public void prewind(VOID_PARAM) { - linebuf.print = 6; /* big enough for longest UTF-8 sequence */ - linebuf.pfx_end = 0; - for (linebuf.end = 0; linebuf.end < linebuf.print; linebuf.end++) - { - linebuf.buf[linebuf.end] = '\0'; - linebuf.attr[linebuf.end] = 0; - } - - end_column = 0; - right_curr = 0; - right_column = 0; - cshift = 0; - overstrike = 0; - last_overstrike = AT_NORMAL; - mbc_buf_len = 0; - is_null_line = 0; - pendc = '\0'; - shifted_ansi.end = 0; + linebuf.print = 6; /* big enough for longest UTF-8 sequence */ + linebuf.pfx_end = 0; + for (linebuf.end = 0; linebuf.end < linebuf.print; linebuf.end++) + { + linebuf.buf[linebuf.end] = '\0'; + linebuf.attr[linebuf.end] = 0; + } + + end_column = 0; + right_curr = 0; + right_column = 0; + cshift = 0; + overstrike = 0; + last_overstrike = AT_NORMAL; + mbc_buf_len = 0; + is_null_line = 0; + pendc = '\0'; + shifted_ansi.end = 0; } /* * Set a character in the line buffer. */ - static void + static void set_linebuf(n, ch, attr) - int n; - char ch; - int attr; + int n; + char ch; + int attr; { - linebuf.buf[n] = ch; - linebuf.attr[n] = attr; + linebuf.buf[n] = ch; + linebuf.attr[n] = attr; } /* * Append a character to the line buffer. */ - static void + static void add_linebuf(ch, attr, w) - char ch; - int attr; - int w; + char ch; + int attr; + int w; { - set_linebuf(linebuf.end++, ch, attr); - inc_end_column(w); + set_linebuf(linebuf.end++, ch, attr); + inc_end_column(w); } /* * Set a character in the line prefix buffer. */ - static void + static void set_pfx(n, ch, attr) - int n; - char ch; - int attr; + int n; + char ch; + int attr; { - linebuf.pfx[n] = ch; - linebuf.pfx_attr[n] = attr; + linebuf.pfx[n] = ch; + linebuf.pfx_attr[n] = attr; } /* * Append a character to the line prefix buffer. */ - static void + static void add_pfx(ch, attr) - char ch; - int attr; + char ch; + int attr; { - set_pfx(linebuf.pfx_end++, ch, attr); + set_pfx(linebuf.pfx_end++, ch, attr); } /* * Insert the status column and line number into the line buffer. */ - public void + public void plinestart(pos) - POSITION pos; + POSITION pos; { - LINENUM linenum = 0; - int i; - - if (linenums == OPT_ONPLUS) - { - /* - * Get the line number and put it in the current line. - * {{ Note: since find_linenum calls forw_raw_line, - * it may seek in the input file, requiring the caller - * of plinestart to re-seek if necessary. }} - * {{ Since forw_raw_line modifies linebuf, we must - * do this first, before storing anything in linebuf. }} - */ - linenum = find_linenum(pos); - } - - /* - * Display a status column if the -J option is set. - */ - if (status_col) - { - int a = AT_NORMAL; - char c = posmark(pos); - if (c != 0) - a |= AT_HILITE|AT_COLOR_MARK; - else - { - c = ' '; - if (start_attnpos != NULL_POSITION && - pos >= start_attnpos && pos <= end_attnpos) - a |= AT_HILITE|AT_COLOR_ATTN; - } - add_pfx(c, a); /* column 0: status */ - while (linebuf.pfx_end < status_col_width) - add_pfx(' ', AT_NORMAL); - } - - /* - * Display the line number at the start of each line - * if the -N option is set. - */ - if (linenums == OPT_ONPLUS) - { - char buf[INT_STRLEN_BOUND(linenum) + 2]; - int len; - - linenumtoa(linenum, buf); - len = (int) strlen(buf); - for (i = 0; i < linenum_width - len; i++) - add_pfx(' ', AT_NORMAL); - for (i = 0; i < len; i++) - add_pfx(buf[i], AT_NORMAL|AT_COLOR_LINENUM); - add_pfx(' ', AT_NORMAL); - } - end_column = linebuf.pfx_end; + LINENUM linenum = 0; + int i; + + if (linenums == OPT_ONPLUS) + { + /* + * Get the line number and put it in the current line. + * {{ Note: since find_linenum calls forw_raw_line, + * it may seek in the input file, requiring the caller + * of plinestart to re-seek if necessary. }} + * {{ Since forw_raw_line modifies linebuf, we must + * do this first, before storing anything in linebuf. }} + */ + linenum = find_linenum(pos); + } + + /* + * Display a status column if the -J option is set. + */ + if (status_col) + { + int a = AT_NORMAL; + char c = posmark(pos); + if (c != 0) + a |= AT_HILITE|AT_COLOR_MARK; + else + { + c = ' '; + if (start_attnpos != NULL_POSITION && + pos >= start_attnpos && pos <= end_attnpos) + a |= AT_HILITE|AT_COLOR_ATTN; + } + add_pfx(c, a); /* column 0: status */ + while (linebuf.pfx_end < status_col_width) + add_pfx(' ', AT_NORMAL); + } + + /* + * Display the line number at the start of each line + * if the -N option is set. + */ + if (linenums == OPT_ONPLUS) + { + char buf[INT_STRLEN_BOUND(linenum) + 2]; + int len; + + linenumtoa(linenum, buf); + len = (int) strlen(buf); + for (i = 0; i < linenum_width - len; i++) + add_pfx(' ', AT_NORMAL); + for (i = 0; i < len; i++) + add_pfx(buf[i], AT_NORMAL|AT_COLOR_LINENUM); + add_pfx(' ', AT_NORMAL); + } + end_column = linebuf.pfx_end; } /* * Return the width of the line prefix (status column and line number). * {{ Actual line number can be wider than linenum_width. }} */ - public int + public int line_pfx_width(VOID_PARAM) { - int width = 0; - if (status_col) - width += status_col_width; - if (linenums == OPT_ONPLUS) - width += linenum_width + 1; - return width; + int width = 0; + if (status_col) + width += status_col_width; + if (linenums == OPT_ONPLUS) + width += linenum_width + 1; + return width; } /* * Add char to the shifted_ansi buffer. */ - static void + static void add_ansi(ch) - char ch; + char ch; { - if (shifted_ansi.end == shifted_ansi.size) - { - /* Expand shifted_ansi buffer. */ - int size = (shifted_ansi.size == 0) ? 8 : shifted_ansi.size * 2; - char *buf = (char *) ecalloc(size, sizeof(char)); - memcpy(buf, shifted_ansi.buf, shifted_ansi.size); - if (shifted_ansi.buf != NULL) free(shifted_ansi.buf); - shifted_ansi.buf = buf; - shifted_ansi.size = size; - } - shifted_ansi.buf[shifted_ansi.end++] = ch; + if (shifted_ansi.end == shifted_ansi.size) + { + /* Expand shifted_ansi buffer. */ + int size = (shifted_ansi.size == 0) ? 8 : shifted_ansi.size * 2; + char *buf = (char *) ecalloc(size, sizeof(char)); + memcpy(buf, shifted_ansi.buf, shifted_ansi.size); + if (shifted_ansi.buf != NULL) free(shifted_ansi.buf); + shifted_ansi.buf = buf; + shifted_ansi.size = size; + } + shifted_ansi.buf[shifted_ansi.end++] = ch; } /* * Shift line left so that the last char is just to the left * of the first visible column. */ - public void + public void pshift_all(VOID_PARAM) { - int i; - for (i = linebuf.print; i < linebuf.end; i++) - if (linebuf.attr[i] == AT_ANSI) - add_ansi(linebuf.buf[i]); - linebuf.end = linebuf.print; - end_column = linebuf.pfx_end; + int i; + for (i = linebuf.print; i < linebuf.end; i++) + if (linebuf.attr[i] == AT_ANSI) + add_ansi(linebuf.buf[i]); + linebuf.end = linebuf.print; + end_column = linebuf.pfx_end; } /* * Return the printing width of the start (enter) sequence * for a given character attribute. */ - static int + static int attr_swidth(a) - int a; + int a; { - int w = 0; + int w = 0; - a = apply_at_specials(a); + a = apply_at_specials(a); - if (a & AT_UNDERLINE) - w += ul_s_width; - if (a & AT_BOLD) - w += bo_s_width; - if (a & AT_BLINK) - w += bl_s_width; - if (a & AT_STANDOUT) - w += so_s_width; + if (a & AT_UNDERLINE) + w += ul_s_width; + if (a & AT_BOLD) + w += bo_s_width; + if (a & AT_BLINK) + w += bl_s_width; + if (a & AT_STANDOUT) + w += so_s_width; - return w; + return w; } /* * Return the printing width of the end (exit) sequence * for a given character attribute. */ - static int + static int attr_ewidth(a) - int a; + int a; { - int w = 0; + int w = 0; - a = apply_at_specials(a); + a = apply_at_specials(a); - if (a & AT_UNDERLINE) - w += ul_e_width; - if (a & AT_BOLD) - w += bo_e_width; - if (a & AT_BLINK) - w += bl_e_width; - if (a & AT_STANDOUT) - w += so_e_width; + if (a & AT_UNDERLINE) + w += ul_e_width; + if (a & AT_BOLD) + w += bo_e_width; + if (a & AT_BLINK) + w += bl_e_width; + if (a & AT_STANDOUT) + w += so_e_width; - return w; + return w; } /* @@ -443,327 +443,327 @@ attr_ewidth(a) * Adding a character with a given attribute may cause an enter or exit * attribute sequence to be inserted, so this must be taken into account. */ - public int + public int pwidth(ch, a, prev_ch, prev_a) - LWCHAR ch; - int a; - LWCHAR prev_ch; - int prev_a; + LWCHAR ch; + int a; + LWCHAR prev_ch; + int prev_a; { - int w; - - if (ch == '\b') - { - /* - * Backspace moves backwards one or two positions. - */ - if (prev_a & (AT_ANSI|AT_BINARY)) - return strlen(prchar('\b')); - return (utf_mode && is_wide_char(prev_ch)) ? -2 : -1; - } - - if (!utf_mode || is_ascii_char(ch)) - { - if (control_char((char)ch)) - { - /* - * Control characters do unpredictable things, - * so we don't even try to guess; say it doesn't move. - * This can only happen if the -r flag is in effect. - */ - return (0); - } - } else - { - if (is_composing_char(ch) || is_combining_char(prev_ch, ch)) - { - /* - * Composing and combining chars take up no space. - * - * Some terminals, upon failure to compose a - * composing character with the character(s) that - * precede(s) it will actually take up one end_column - * for the composing character; there isn't much - * we could do short of testing the (complex) - * composition process ourselves and printing - * a binary representation when it fails. - */ - return (0); - } - } - - /* - * Other characters take one or two columns, - * plus the width of any attribute enter/exit sequence. - */ - w = 1; - if (is_wide_char(ch)) - w++; - if (linebuf.end > 0 && !is_at_equiv(linebuf.attr[linebuf.end-1], a)) - w += attr_ewidth(linebuf.attr[linebuf.end-1]); - if (apply_at_specials(a) != AT_NORMAL && - (linebuf.end == 0 || !is_at_equiv(linebuf.attr[linebuf.end-1], a))) - w += attr_swidth(a); - return (w); + int w; + + if (ch == '\b') + { + /* + * Backspace moves backwards one or two positions. + */ + if (prev_a & (AT_ANSI|AT_BINARY)) + return strlen(prchar('\b')); + return (utf_mode && is_wide_char(prev_ch)) ? -2 : -1; + } + + if (!utf_mode || is_ascii_char(ch)) + { + if (control_char((char)ch)) + { + /* + * Control characters do unpredictable things, + * so we don't even try to guess; say it doesn't move. + * This can only happen if the -r flag is in effect. + */ + return (0); + } + } else + { + if (is_composing_char(ch) || is_combining_char(prev_ch, ch)) + { + /* + * Composing and combining chars take up no space. + * + * Some terminals, upon failure to compose a + * composing character with the character(s) that + * precede(s) it will actually take up one end_column + * for the composing character; there isn't much + * we could do short of testing the (complex) + * composition process ourselves and printing + * a binary representation when it fails. + */ + return (0); + } + } + + /* + * Other characters take one or two columns, + * plus the width of any attribute enter/exit sequence. + */ + w = 1; + if (is_wide_char(ch)) + w++; + if (linebuf.end > 0 && !is_at_equiv(linebuf.attr[linebuf.end-1], a)) + w += attr_ewidth(linebuf.attr[linebuf.end-1]); + if (apply_at_specials(a) != AT_NORMAL && + (linebuf.end == 0 || !is_at_equiv(linebuf.attr[linebuf.end-1], a))) + w += attr_swidth(a); + return (w); } /* * Delete to the previous base character in the line buffer. */ - static int + static int backc(VOID_PARAM) { - LWCHAR ch; - char *p; - - if (linebuf.end == 0) - return (0); - p = &linebuf.buf[linebuf.end]; - ch = step_char(&p, -1, linebuf.buf); - /* Skip back to the next nonzero-width char. */ - while (p > linebuf.buf) - { - LWCHAR prev_ch; - int width; - linebuf.end = (int) (p - linebuf.buf); - prev_ch = step_char(&p, -1, linebuf.buf); - width = pwidth(ch, linebuf.attr[linebuf.end], prev_ch, linebuf.attr[linebuf.end-1]); - end_column -= width; - /* {{ right_column? }} */ - if (width > 0) - break; - ch = prev_ch; - } - return (1); + LWCHAR ch; + char *p; + + if (linebuf.end == 0) + return (0); + p = &linebuf.buf[linebuf.end]; + ch = step_char(&p, -1, linebuf.buf); + /* Skip back to the next nonzero-width char. */ + while (p > linebuf.buf) + { + LWCHAR prev_ch; + int width; + linebuf.end = (int) (p - linebuf.buf); + prev_ch = step_char(&p, -1, linebuf.buf); + width = pwidth(ch, linebuf.attr[linebuf.end], prev_ch, linebuf.attr[linebuf.end-1]); + end_column -= width; + /* {{ right_column? }} */ + if (width > 0) + break; + ch = prev_ch; + } + return (1); } /* * Is a character the end of an ANSI escape sequence? */ - public int + public int is_ansi_end(ch) - LWCHAR ch; + LWCHAR ch; { - if (!is_ascii_char(ch)) - return (0); - return (strchr(end_ansi_chars, (char) ch) != NULL); + if (!is_ascii_char(ch)) + return (0); + return (strchr(end_ansi_chars, (char) ch) != NULL); } /* * Can a char appear in an ANSI escape sequence, before the end char? */ - public int + public int is_ansi_middle(ch) - LWCHAR ch; + LWCHAR ch; { - if (!is_ascii_char(ch)) - return (0); - if (is_ansi_end(ch)) - return (0); - return (strchr(mid_ansi_chars, (char) ch) != NULL); + if (!is_ascii_char(ch)) + return (0); + if (is_ansi_end(ch)) + return (0); + return (strchr(mid_ansi_chars, (char) ch) != NULL); } /* * Skip past an ANSI escape sequence. * pp is initially positioned just after the CSI_START char. */ - public void + public void skip_ansi(pansi, pp, limit) - struct ansi_state *pansi; - char **pp; - constant char *limit; + struct ansi_state *pansi; + char **pp; + constant char *limit; { - LWCHAR c; - do { - c = step_char(pp, +1, limit); - } while (*pp < limit && ansi_step(pansi, c) == ANSI_MID); - /* Note that we discard final char, for which is_ansi_end is true. */ + LWCHAR c; + do { + c = step_char(pp, +1, limit); + } while (*pp < limit && ansi_step(pansi, c) == ANSI_MID); + /* Note that we discard final char, for which is_ansi_end is true. */ } /* * Determine if a character starts an ANSI escape sequence. * If so, return an ansi_state struct; otherwise return NULL. */ - public struct ansi_state * + public struct ansi_state * ansi_start(ch) - LWCHAR ch; + LWCHAR ch; { - struct ansi_state *pansi; - - if (!IS_CSI_START(ch)) - return NULL; - pansi = ecalloc(1, sizeof(struct ansi_state)); - pansi->hindex = 0; - pansi->hlink = 0; - pansi->prev_esc = 0; - return pansi; + struct ansi_state *pansi; + + if (!IS_CSI_START(ch)) + return NULL; + pansi = ecalloc(1, sizeof(struct ansi_state)); + pansi->hindex = 0; + pansi->hlink = 0; + pansi->prev_esc = 0; + return pansi; } /* * Determine whether the next char in an ANSI escape sequence * ends the sequence. */ - public int + public int ansi_step(pansi, ch) - struct ansi_state *pansi; - LWCHAR ch; + struct ansi_state *pansi; + LWCHAR ch; { - if (pansi->hlink) - { - /* Hyperlink ends with \7 or ESC-backslash. */ - if (ch == '\7') - return ANSI_END; - if (pansi->prev_esc && ch == '\\') - return ANSI_END; - pansi->prev_esc = (ch == ESC); - return ANSI_MID; - } - if (pansi->hindex >= 0) - { - static char hlink_prefix[] = ESCS "]8;"; - if (ch == hlink_prefix[pansi->hindex] || - (pansi->hindex == 0 && IS_CSI_START(ch))) - { - pansi->hindex++; - if (hlink_prefix[pansi->hindex] == '\0') - pansi->hlink = 1; /* now processing hyperlink addr */ - return ANSI_MID; - } - pansi->hindex = -1; /* not a hyperlink */ - } - /* Check for SGR sequences */ - if (is_ansi_middle(ch)) - return ANSI_MID; - if (is_ansi_end(ch)) - return ANSI_END; - return ANSI_ERR; + if (pansi->hlink) + { + /* Hyperlink ends with \7 or ESC-backslash. */ + if (ch == '\7') + return ANSI_END; + if (pansi->prev_esc && ch == '\\') + return ANSI_END; + pansi->prev_esc = (ch == ESC); + return ANSI_MID; + } + if (pansi->hindex >= 0) + { + static char hlink_prefix[] = ESCS "]8;"; + if (ch == hlink_prefix[pansi->hindex] || + (pansi->hindex == 0 && IS_CSI_START(ch))) + { + pansi->hindex++; + if (hlink_prefix[pansi->hindex] == '\0') + pansi->hlink = 1; /* now processing hyperlink addr */ + return ANSI_MID; + } + pansi->hindex = -1; /* not a hyperlink */ + } + /* Check for SGR sequences */ + if (is_ansi_middle(ch)) + return ANSI_MID; + if (is_ansi_end(ch)) + return ANSI_END; + return ANSI_ERR; } /* * Free an ansi_state structure. */ - public void + public void ansi_done(pansi) - struct ansi_state *pansi; + struct ansi_state *pansi; { - free(pansi); + free(pansi); } /* * Append a character and attribute to the line buffer. */ #define STORE_CHAR(ch,a,rep,pos) \ - do { \ - if (store_char((ch),(a),(rep),(pos))) return (1); \ - } while (0) + do { \ + if (store_char((ch),(a),(rep),(pos))) return (1); \ + } while (0) - static int + static int store_char(ch, a, rep, pos) - LWCHAR ch; - int a; - char *rep; - POSITION pos; + LWCHAR ch; + int a; + char *rep; + POSITION pos; { - int w; - int i; - int replen; - char cs; + int w; + int i; + int replen; + char cs; - i = (a & (AT_UNDERLINE|AT_BOLD)); - if (i != AT_NORMAL) - last_overstrike = i; + i = (a & (AT_UNDERLINE|AT_BOLD)); + if (i != AT_NORMAL) + last_overstrike = i; #if HILITE_SEARCH - { - int matches; - int hl_attr = is_hilited_attr(pos, pos+1, 0, &matches); - if (hl_attr) - { - /* - * This character should be highlighted. - * Override the attribute passed in. - */ - if (a != AT_ANSI) - { - if (highest_hilite != NULL_POSITION && pos > highest_hilite) - highest_hilite = pos; - a |= hl_attr; - } - } - } + { + int matches; + int hl_attr = is_hilited_attr(pos, pos+1, 0, &matches); + if (hl_attr) + { + /* + * This character should be highlighted. + * Override the attribute passed in. + */ + if (a != AT_ANSI) + { + if (highest_hilite != NULL_POSITION && pos > highest_hilite) + highest_hilite = pos; + a |= hl_attr; + } + } + } #endif - if (a == AT_ANSI) { - w = 0; - } else { - char *p = &linebuf.buf[linebuf.end]; - LWCHAR prev_ch = (linebuf.end > 0) ? step_char(&p, -1, linebuf.buf) : 0; - int prev_a = (linebuf.end > 0) ? linebuf.attr[linebuf.end-1] : 0; - w = pwidth(ch, a, prev_ch, prev_a); - } - - if (ctldisp != OPT_ON && end_column - cshift + w + attr_ewidth(a) > sc_width) - /* - * Won't fit on screen. - */ - return (1); - - if (rep == NULL) - { - cs = (char) ch; - rep = &cs; - replen = 1; - } else - { - replen = utf_len(rep[0]); - } - if (linebuf.end + replen >= size_linebuf-6) - { - /* - * Won't fit in line buffer. - * Try to expand it. - */ - if (expand_linebuf()) - return (1); - } - - if (cshift == hshift && shifted_ansi.end > 0) - { - /* Copy shifted ANSI sequences to beginning of line. */ - for (i = 0; i < shifted_ansi.end; i++) - add_linebuf(shifted_ansi.buf[i], AT_ANSI, 0); - shifted_ansi.end = 0; - } - /* Add the char to the buf, even if we will left-shift it next. */ - inc_end_column(w); - for (i = 0; i < replen; i++) - add_linebuf(*rep++, a, 0); - - if (cshift < hshift) - { - /* We haven't left-shifted enough yet. */ - if (a == AT_ANSI) - add_ansi(ch); /* Save ANSI attributes */ - if (linebuf.end > linebuf.print) - { - /* Shift left enough to put last byte of this char at print-1. */ - memcpy(&linebuf.buf[0], &linebuf.buf[replen], linebuf.print); - memcpy(&linebuf.attr[0], &linebuf.attr[replen], linebuf.print); - linebuf.end -= replen; - cshift += w; - /* - * If the char we just left-shifted was double width, - * the 2 spaces we shifted may be too much. - * Represent the "half char" at start of line with a highlighted space. - */ - while (cshift > hshift) - { - add_linebuf(' ', rscroll_attr, 0); - cshift--; - } - } - } - return (0); + if (a == AT_ANSI) { + w = 0; + } else { + char *p = &linebuf.buf[linebuf.end]; + LWCHAR prev_ch = (linebuf.end > 0) ? step_char(&p, -1, linebuf.buf) : 0; + int prev_a = (linebuf.end > 0) ? linebuf.attr[linebuf.end-1] : 0; + w = pwidth(ch, a, prev_ch, prev_a); + } + + if (ctldisp != OPT_ON && end_column - cshift + w + attr_ewidth(a) > sc_width) + /* + * Won't fit on screen. + */ + return (1); + + if (rep == NULL) + { + cs = (char) ch; + rep = &cs; + replen = 1; + } else + { + replen = utf_len(rep[0]); + } + if (linebuf.end + replen >= size_linebuf-6) + { + /* + * Won't fit in line buffer. + * Try to expand it. + */ + if (expand_linebuf()) + return (1); + } + + if (cshift == hshift && shifted_ansi.end > 0) + { + /* Copy shifted ANSI sequences to beginning of line. */ + for (i = 0; i < shifted_ansi.end; i++) + add_linebuf(shifted_ansi.buf[i], AT_ANSI, 0); + shifted_ansi.end = 0; + } + /* Add the char to the buf, even if we will left-shift it next. */ + inc_end_column(w); + for (i = 0; i < replen; i++) + add_linebuf(*rep++, a, 0); + + if (cshift < hshift) + { + /* We haven't left-shifted enough yet. */ + if (a == AT_ANSI) + add_ansi(ch); /* Save ANSI attributes */ + if (linebuf.end > linebuf.print) + { + /* Shift left enough to put last byte of this char at print-1. */ + memcpy(&linebuf.buf[0], &linebuf.buf[replen], linebuf.print); + memcpy(&linebuf.attr[0], &linebuf.attr[replen], linebuf.print); + linebuf.end -= replen; + cshift += w; + /* + * If the char we just left-shifted was double width, + * the 2 spaces we shifted may be too much. + * Represent the "half char" at start of line with a highlighted space. + */ + while (cshift > hshift) + { + add_linebuf(' ', rscroll_attr, 0); + cshift--; + } + } + } + return (0); } /* @@ -771,62 +771,62 @@ store_char(ch, a, rep, pos) * Store spaces to represent the tab. */ #define STORE_TAB(a,pos) \ - do { if (store_tab((a),(pos))) return (1); } while (0) + do { if (store_tab((a),(pos))) return (1); } while (0) - static int + static int store_tab(attr, pos) - int attr; - POSITION pos; + int attr; + POSITION pos; { - int to_tab = end_column - linebuf.pfx_end; - - if (ntabstops < 2 || to_tab >= tabstops[ntabstops-1]) - to_tab = tabdefault - - ((to_tab - tabstops[ntabstops-1]) % tabdefault); - else - { - int i; - for (i = ntabstops - 2; i >= 0; i--) - if (to_tab >= tabstops[i]) - break; - to_tab = tabstops[i+1] - to_tab; - } - - do { - STORE_CHAR(' ', attr, " ", pos); - } while (--to_tab > 0); - return 0; + int to_tab = end_column - linebuf.pfx_end; + + if (ntabstops < 2 || to_tab >= tabstops[ntabstops-1]) + to_tab = tabdefault - + ((to_tab - tabstops[ntabstops-1]) % tabdefault); + else + { + int i; + for (i = ntabstops - 2; i >= 0; i--) + if (to_tab >= tabstops[i]) + break; + to_tab = tabstops[i+1] - to_tab; + } + + do { + STORE_CHAR(' ', attr, " ", pos); + } while (--to_tab > 0); + return 0; } #define STORE_PRCHAR(c, pos) \ - do { if (store_prchar((c), (pos))) return 1; } while (0) + do { if (store_prchar((c), (pos))) return 1; } while (0) - static int + static int store_prchar(c, pos) - LWCHAR c; - POSITION pos; + LWCHAR c; + POSITION pos; { - char *s; - - /* - * Convert to printable representation. - */ - s = prchar(c); - for ( ; *s != 0; s++) - STORE_CHAR(*s, AT_BINARY|AT_COLOR_CTRL, NULL, pos); - return 0; + char *s; + + /* + * Convert to printable representation. + */ + s = prchar(c); + for ( ; *s != 0; s++) + STORE_CHAR(*s, AT_BINARY|AT_COLOR_CTRL, NULL, pos); + return 0; } - static int + static int flush_mbc_buf(pos) - POSITION pos; + POSITION pos; { - int i; + int i; - for (i = 0; i < mbc_buf_index; i++) - if (store_prchar(mbc_buf[i], pos)) - return mbc_buf_index - i; - return 0; + for (i = 0; i < mbc_buf_index; i++) + if (store_prchar(mbc_buf[i], pos)) + return mbc_buf_index - i; + return 0; } /* @@ -834,404 +834,404 @@ flush_mbc_buf(pos) * Expand tabs into spaces, handle underlining, boldfacing, etc. * Returns 0 if ok, 1 if couldn't fit in buffer. */ - public int + public int pappend(c, pos) - int c; - POSITION pos; + int c; + POSITION pos; { - int r; - - if (pendc) - { - if (c == '\r' && pendc == '\r') - return (0); - if (do_append(pendc, NULL, pendpos)) - /* - * Oops. We've probably lost the char which - * was in pendc, since caller won't back up. - */ - return (1); - pendc = '\0'; - } - - if (c == '\r' && bs_mode == BS_SPECIAL) - { - if (mbc_buf_len > 0) /* utf_mode must be on. */ - { - /* Flush incomplete (truncated) sequence. */ - r = flush_mbc_buf(mbc_pos); - mbc_buf_index = r + 1; - mbc_buf_len = 0; - if (r) - return (mbc_buf_index); - } - - /* - * Don't put the CR into the buffer until we see - * the next char. If the next char is a newline, - * discard the CR. - */ - pendc = c; - pendpos = pos; - return (0); - } - - if (!utf_mode) - { - r = do_append(c, NULL, pos); - } else - { - /* Perform strict validation in all possible cases. */ - if (mbc_buf_len == 0) - { - retry: - mbc_buf_index = 1; - *mbc_buf = c; - if (IS_ASCII_OCTET(c)) - r = do_append(c, NULL, pos); - else if (IS_UTF8_LEAD(c)) - { - mbc_buf_len = utf_len(c); - mbc_pos = pos; - return (0); - } else - /* UTF8_INVALID or stray UTF8_TRAIL */ - r = flush_mbc_buf(pos); - } else if (IS_UTF8_TRAIL(c)) - { - mbc_buf[mbc_buf_index++] = c; - if (mbc_buf_index < mbc_buf_len) - return (0); - if (is_utf8_well_formed(mbc_buf, mbc_buf_index)) - r = do_append(get_wchar(mbc_buf), mbc_buf, mbc_pos); - else - /* Complete, but not shortest form, sequence. */ - mbc_buf_index = r = flush_mbc_buf(mbc_pos); - mbc_buf_len = 0; - } else - { - /* Flush incomplete (truncated) sequence. */ - r = flush_mbc_buf(mbc_pos); - mbc_buf_index = r + 1; - mbc_buf_len = 0; - /* Handle new char. */ - if (!r) - goto retry; - } - } - if (r) - { - /* How many chars should caller back up? */ - r = (!utf_mode) ? 1 : mbc_buf_index; - } - return (r); + int r; + + if (pendc) + { + if (c == '\r' && pendc == '\r') + return (0); + if (do_append(pendc, NULL, pendpos)) + /* + * Oops. We've probably lost the char which + * was in pendc, since caller won't back up. + */ + return (1); + pendc = '\0'; + } + + if (c == '\r' && bs_mode == BS_SPECIAL) + { + if (mbc_buf_len > 0) /* utf_mode must be on. */ + { + /* Flush incomplete (truncated) sequence. */ + r = flush_mbc_buf(mbc_pos); + mbc_buf_index = r + 1; + mbc_buf_len = 0; + if (r) + return (mbc_buf_index); + } + + /* + * Don't put the CR into the buffer until we see + * the next char. If the next char is a newline, + * discard the CR. + */ + pendc = c; + pendpos = pos; + return (0); + } + + if (!utf_mode) + { + r = do_append(c, NULL, pos); + } else + { + /* Perform strict validation in all possible cases. */ + if (mbc_buf_len == 0) + { + retry: + mbc_buf_index = 1; + *mbc_buf = c; + if (IS_ASCII_OCTET(c)) + r = do_append(c, NULL, pos); + else if (IS_UTF8_LEAD(c)) + { + mbc_buf_len = utf_len(c); + mbc_pos = pos; + return (0); + } else + /* UTF8_INVALID or stray UTF8_TRAIL */ + r = flush_mbc_buf(pos); + } else if (IS_UTF8_TRAIL(c)) + { + mbc_buf[mbc_buf_index++] = c; + if (mbc_buf_index < mbc_buf_len) + return (0); + if (is_utf8_well_formed(mbc_buf, mbc_buf_index)) + r = do_append(get_wchar(mbc_buf), mbc_buf, mbc_pos); + else + /* Complete, but not shortest form, sequence. */ + mbc_buf_index = r = flush_mbc_buf(mbc_pos); + mbc_buf_len = 0; + } else + { + /* Flush incomplete (truncated) sequence. */ + r = flush_mbc_buf(mbc_pos); + mbc_buf_index = r + 1; + mbc_buf_len = 0; + /* Handle new char. */ + if (!r) + goto retry; + } + } + if (r) + { + /* How many chars should caller back up? */ + r = (!utf_mode) ? 1 : mbc_buf_index; + } + return (r); } - static int + static int store_control_char(ch, rep, pos) - LWCHAR ch; - char *rep; - POSITION pos; + LWCHAR ch; + char *rep; + POSITION pos; { - if (ctldisp == OPT_ON) - { - /* Output the character itself. */ - STORE_CHAR(ch, AT_NORMAL, rep, pos); - } else - { - /* Output a printable representation of the character. */ - STORE_PRCHAR((char) ch, pos); - } - return (0); + if (ctldisp == OPT_ON) + { + /* Output the character itself. */ + STORE_CHAR(ch, AT_NORMAL, rep, pos); + } else + { + /* Output a printable representation of the character. */ + STORE_PRCHAR((char) ch, pos); + } + return (0); } - static int + static int store_ansi(ch, rep, pos) - LWCHAR ch; - char *rep; - POSITION pos; + LWCHAR ch; + char *rep; + POSITION pos; { - switch (ansi_step(line_ansi, ch)) - { - case ANSI_MID: - STORE_CHAR(ch, AT_ANSI, rep, pos); - break; - case ANSI_END: - STORE_CHAR(ch, AT_ANSI, rep, pos); - ansi_done(line_ansi); - line_ansi = NULL; - break; - case ANSI_ERR: { - /* Remove whole unrecognized sequence. */ - char *start = (cshift < hshift) ? shifted_ansi.buf : linebuf.buf; - int *end = (cshift < hshift) ? &shifted_ansi.end : &linebuf.end; - char *p = start + *end; - LWCHAR bch; - do { - bch = step_char(&p, -1, start); - } while (p > start && !IS_CSI_START(bch)); - *end = (int) (p - start); - ansi_done(line_ansi); - line_ansi = NULL; - break; } - } - return (0); -} - - static int + switch (ansi_step(line_ansi, ch)) + { + case ANSI_MID: + STORE_CHAR(ch, AT_ANSI, rep, pos); + break; + case ANSI_END: + STORE_CHAR(ch, AT_ANSI, rep, pos); + ansi_done(line_ansi); + line_ansi = NULL; + break; + case ANSI_ERR: { + /* Remove whole unrecognized sequence. */ + char *start = (cshift < hshift) ? shifted_ansi.buf : linebuf.buf; + int *end = (cshift < hshift) ? &shifted_ansi.end : &linebuf.end; + char *p = start + *end; + LWCHAR bch; + do { + bch = step_char(&p, -1, start); + } while (p > start && !IS_CSI_START(bch)); + *end = (int) (p - start); + ansi_done(line_ansi); + line_ansi = NULL; + break; } + } + return (0); +} + + static int store_bs(ch, rep, pos) - LWCHAR ch; - char *rep; - POSITION pos; + LWCHAR ch; + char *rep; + POSITION pos; { - if (bs_mode == BS_CONTROL) - return store_control_char(ch, rep, pos); - if (linebuf.end > 0 && - ((linebuf.end <= linebuf.print && linebuf.buf[linebuf.end-1] == '\0') || - (linebuf.end > 0 && linebuf.attr[linebuf.end - 1] & (AT_ANSI|AT_BINARY)))) - STORE_PRCHAR('\b', pos); - else if (bs_mode == BS_NORMAL) - STORE_CHAR(ch, AT_NORMAL, NULL, pos); - else if (bs_mode == BS_SPECIAL) - overstrike = backc(); - return 0; + if (bs_mode == BS_CONTROL) + return store_control_char(ch, rep, pos); + if (linebuf.end > 0 && + ((linebuf.end <= linebuf.print && linebuf.buf[linebuf.end-1] == '\0') || + (linebuf.end > 0 && linebuf.attr[linebuf.end - 1] & (AT_ANSI|AT_BINARY)))) + STORE_PRCHAR('\b', pos); + else if (bs_mode == BS_NORMAL) + STORE_CHAR(ch, AT_NORMAL, NULL, pos); + else if (bs_mode == BS_SPECIAL) + overstrike = backc(); + return 0; } - static int + static int do_append(ch, rep, pos) - LWCHAR ch; - char *rep; - POSITION pos; + LWCHAR ch; + char *rep; + POSITION pos; { - int a = AT_NORMAL; - - if (ctldisp == OPT_ONPLUS && line_ansi == NULL) - line_ansi = ansi_start(ch); - - if (line_ansi != NULL) - return store_ansi(ch, rep, pos); - - if (ch == '\b') - return store_bs(ch, rep, pos); - - if (overstrike > 0) - { - /* - * Overstrike the character at the current position - * in the line buffer. This will cause either - * underline (if a "_" is overstruck), - * bold (if an identical character is overstruck), - * or just replacing the character in the buffer. - */ - LWCHAR prev_ch; - overstrike = utf_mode ? -1 : 0; - if (utf_mode) - { - /* To be correct, this must be a base character. */ - prev_ch = get_wchar(&linebuf.buf[linebuf.end]); - } else - { - prev_ch = (unsigned char) linebuf.buf[linebuf.end]; - } - a = linebuf.attr[linebuf.end]; - if (ch == prev_ch) - { - /* - * Overstriking a char with itself means make it bold. - * But overstriking an underscore with itself is - * ambiguous. It could mean make it bold, or - * it could mean make it underlined. - * Use the previous overstrike to resolve it. - */ - if (ch == '_') - { - if ((a & (AT_BOLD|AT_UNDERLINE)) != AT_NORMAL) - a |= (AT_BOLD|AT_UNDERLINE); - else if (last_overstrike != AT_NORMAL) - a |= last_overstrike; - else - a |= AT_BOLD; - } else - a |= AT_BOLD; - } else if (ch == '_') - { - a |= AT_UNDERLINE; - ch = prev_ch; - rep = &linebuf.buf[linebuf.end]; - } else if (prev_ch == '_') - { - a |= AT_UNDERLINE; - } - /* Else we replace prev_ch, but we keep its attributes. */ - } else if (overstrike < 0) - { - if ( is_composing_char(ch) - || is_combining_char(get_wchar(&linebuf.buf[linebuf.end]), ch)) - /* Continuation of the same overstrike. */ - a = last_overstrike; - else - overstrike = 0; - } - - if (ch == '\t') - { - /* - * Expand a tab into spaces. - */ - switch (bs_mode) - { - case BS_CONTROL: - return store_control_char(ch, rep, pos); - case BS_NORMAL: - case BS_SPECIAL: - STORE_TAB(a, pos); - break; - } - return (0); - } - if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch)) - { - return store_control_char(ch, rep, pos); - } else if (utf_mode && ctldisp != OPT_ON && is_ubin_char(ch)) - { - char *s = prutfchar(ch); - for ( ; *s != 0; s++) - STORE_CHAR(*s, AT_BINARY, NULL, pos); - } else - { - STORE_CHAR(ch, a, rep, pos); - } - return (0); + int a = AT_NORMAL; + + if (ctldisp == OPT_ONPLUS && line_ansi == NULL) + line_ansi = ansi_start(ch); + + if (line_ansi != NULL) + return store_ansi(ch, rep, pos); + + if (ch == '\b') + return store_bs(ch, rep, pos); + + if (overstrike > 0) + { + /* + * Overstrike the character at the current position + * in the line buffer. This will cause either + * underline (if a "_" is overstruck), + * bold (if an identical character is overstruck), + * or just replacing the character in the buffer. + */ + LWCHAR prev_ch; + overstrike = utf_mode ? -1 : 0; + if (utf_mode) + { + /* To be correct, this must be a base character. */ + prev_ch = get_wchar(&linebuf.buf[linebuf.end]); + } else + { + prev_ch = (unsigned char) linebuf.buf[linebuf.end]; + } + a = linebuf.attr[linebuf.end]; + if (ch == prev_ch) + { + /* + * Overstriking a char with itself means make it bold. + * But overstriking an underscore with itself is + * ambiguous. It could mean make it bold, or + * it could mean make it underlined. + * Use the previous overstrike to resolve it. + */ + if (ch == '_') + { + if ((a & (AT_BOLD|AT_UNDERLINE)) != AT_NORMAL) + a |= (AT_BOLD|AT_UNDERLINE); + else if (last_overstrike != AT_NORMAL) + a |= last_overstrike; + else + a |= AT_BOLD; + } else + a |= AT_BOLD; + } else if (ch == '_') + { + a |= AT_UNDERLINE; + ch = prev_ch; + rep = &linebuf.buf[linebuf.end]; + } else if (prev_ch == '_') + { + a |= AT_UNDERLINE; + } + /* Else we replace prev_ch, but we keep its attributes. */ + } else if (overstrike < 0) + { + if ( is_composing_char(ch) + || is_combining_char(get_wchar(&linebuf.buf[linebuf.end]), ch)) + /* Continuation of the same overstrike. */ + a = last_overstrike; + else + overstrike = 0; + } + + if (ch == '\t') + { + /* + * Expand a tab into spaces. + */ + switch (bs_mode) + { + case BS_CONTROL: + return store_control_char(ch, rep, pos); + case BS_NORMAL: + case BS_SPECIAL: + STORE_TAB(a, pos); + break; + } + return (0); + } + if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch)) + { + return store_control_char(ch, rep, pos); + } else if (utf_mode && ctldisp != OPT_ON && is_ubin_char(ch)) + { + char *s = prutfchar(ch); + for ( ; *s != 0; s++) + STORE_CHAR(*s, AT_BINARY, NULL, pos); + } else + { + STORE_CHAR(ch, a, rep, pos); + } + return (0); } /* * */ - public int + public int pflushmbc(VOID_PARAM) { - int r = 0; - - if (mbc_buf_len > 0) - { - /* Flush incomplete (truncated) sequence. */ - r = flush_mbc_buf(mbc_pos); - mbc_buf_len = 0; - } - return r; + int r = 0; + + if (mbc_buf_len > 0) + { + /* Flush incomplete (truncated) sequence. */ + r = flush_mbc_buf(mbc_pos); + mbc_buf_len = 0; + } + return r; } /* * Switch to normal attribute at end of line. */ - static void + static void add_attr_normal(VOID_PARAM) { - char *p = "\033[m"; + char *p = "\033[m"; - if (ctldisp != OPT_ONPLUS || !is_ansi_end('m')) - return; - for ( ; *p != '\0'; p++) - add_linebuf(*p, AT_ANSI, 0); + if (ctldisp != OPT_ONPLUS || !is_ansi_end('m')) + return; + for ( ; *p != '\0'; p++) + add_linebuf(*p, AT_ANSI, 0); } /* * Terminate the line in the line buffer. */ - public void + public void pdone(endline, chopped, forw) - int endline; - int chopped; - int forw; + int endline; + int chopped; + int forw; { - (void) pflushmbc(); - - if (pendc && (pendc != '\r' || !endline)) - /* - * If we had a pending character, put it in the buffer. - * But discard a pending CR if we are at end of line - * (that is, discard the CR in a CR/LF sequence). - */ - (void) do_append(pendc, NULL, pendpos); - - if (chopped && rscroll_char) - { - /* - * Display the right scrolling char. - * If we've already filled the rightmost screen char - * (in the buffer), overwrite it. - */ - if (end_column >= sc_width + cshift) - { - /* We've already written in the rightmost char. */ - end_column = right_column; - linebuf.end = right_curr; - } - add_attr_normal(); - while (end_column < sc_width-1 + cshift) - { - /* - * Space to last (rightmost) char on screen. - * This may be necessary if the char we overwrote - * was double-width. - */ - add_linebuf(' ', rscroll_attr, 1); - } - /* Print rscroll char. It must be single-width. */ - add_linebuf(rscroll_char, rscroll_attr, 1); - } else - { - add_attr_normal(); - } - - /* - * Add a newline if necessary, - * and append a '\0' to the end of the line. - * We output a newline if we're not at the right edge of the screen, - * or if the terminal doesn't auto wrap, - * or if this is really the end of the line AND the terminal ignores - * a newline at the right edge. - * (In the last case we don't want to output a newline if the terminal - * doesn't ignore it since that would produce an extra blank line. - * But we do want to output a newline if the terminal ignores it in case - * the next line is blank. In that case the single newline output for - * that blank line would be ignored!) - */ - if (end_column < sc_width + cshift || !auto_wrap || (endline && ignaw) || ctldisp == OPT_ON) - { - add_linebuf('\n', AT_NORMAL, 0); - } - else if (ignaw && end_column >= sc_width + cshift && forw) - { - /* - * Terminals with "ignaw" don't wrap until they *really* need - * to, i.e. when the character *after* the last one to fit on a - * line is output. But they are too hard to deal with when they - * get in the state where a full screen width of characters - * have been output but the cursor is sitting on the right edge - * instead of at the start of the next line. - * So we nudge them into wrapping by outputting a space - * character plus a backspace. But do this only if moving - * forward; if we're moving backward and drawing this line at - * the top of the screen, the space would overwrite the first - * char on the next line. We don't need to do this "nudge" - * at the top of the screen anyway. - */ - add_linebuf(' ', AT_NORMAL, 1); - add_linebuf('\b', AT_NORMAL, -1); - } - set_linebuf(linebuf.end, '\0', AT_NORMAL); + (void) pflushmbc(); + + if (pendc && (pendc != '\r' || !endline)) + /* + * If we had a pending character, put it in the buffer. + * But discard a pending CR if we are at end of line + * (that is, discard the CR in a CR/LF sequence). + */ + (void) do_append(pendc, NULL, pendpos); + + if (chopped && rscroll_char) + { + /* + * Display the right scrolling char. + * If we've already filled the rightmost screen char + * (in the buffer), overwrite it. + */ + if (end_column >= sc_width + cshift) + { + /* We've already written in the rightmost char. */ + end_column = right_column; + linebuf.end = right_curr; + } + add_attr_normal(); + while (end_column < sc_width-1 + cshift) + { + /* + * Space to last (rightmost) char on screen. + * This may be necessary if the char we overwrote + * was double-width. + */ + add_linebuf(' ', rscroll_attr, 1); + } + /* Print rscroll char. It must be single-width. */ + add_linebuf(rscroll_char, rscroll_attr, 1); + } else + { + add_attr_normal(); + } + + /* + * Add a newline if necessary, + * and append a '\0' to the end of the line. + * We output a newline if we're not at the right edge of the screen, + * or if the terminal doesn't auto wrap, + * or if this is really the end of the line AND the terminal ignores + * a newline at the right edge. + * (In the last case we don't want to output a newline if the terminal + * doesn't ignore it since that would produce an extra blank line. + * But we do want to output a newline if the terminal ignores it in case + * the next line is blank. In that case the single newline output for + * that blank line would be ignored!) + */ + if (end_column < sc_width + cshift || !auto_wrap || (endline && ignaw) || ctldisp == OPT_ON) + { + add_linebuf('\n', AT_NORMAL, 0); + } + else if (ignaw && end_column >= sc_width + cshift && forw) + { + /* + * Terminals with "ignaw" don't wrap until they *really* need + * to, i.e. when the character *after* the last one to fit on a + * line is output. But they are too hard to deal with when they + * get in the state where a full screen width of characters + * have been output but the cursor is sitting on the right edge + * instead of at the start of the next line. + * So we nudge them into wrapping by outputting a space + * character plus a backspace. But do this only if moving + * forward; if we're moving backward and drawing this line at + * the top of the screen, the space would overwrite the first + * char on the next line. We don't need to do this "nudge" + * at the top of the screen anyway. + */ + add_linebuf(' ', AT_NORMAL, 1); + add_linebuf('\b', AT_NORMAL, -1); + } + set_linebuf(linebuf.end, '\0', AT_NORMAL); } /* * */ - public void + public void set_status_col(c, attr) - int c; - int attr; + int c; + int attr; { - set_pfx(0, c, attr); + set_pfx(0, c, attr); } /* @@ -1239,49 +1239,49 @@ set_status_col(c, attr) * Return the character as the function return value, * and the character attribute in *ap. */ - public int + public int gline(i, ap) - int i; - int *ap; + int i; + int *ap; { - if (is_null_line) - { - /* - * If there is no current line, we pretend the line is - * either "~" or "", depending on the "twiddle" flag. - */ - if (twiddle) - { - if (i == 0) - { - *ap = AT_BOLD; - return '~'; - } - --i; - } - /* Make sure we're back to AT_NORMAL before the '\n'. */ - *ap = AT_NORMAL; - return i ? '\0' : '\n'; - } - - if (i < linebuf.pfx_end) - { - *ap = linebuf.pfx_attr[i]; - return linebuf.pfx[i]; - } - i += linebuf.print - linebuf.pfx_end; - *ap = linebuf.attr[i]; - return (linebuf.buf[i] & 0xFF); + if (is_null_line) + { + /* + * If there is no current line, we pretend the line is + * either "~" or "", depending on the "twiddle" flag. + */ + if (twiddle) + { + if (i == 0) + { + *ap = AT_BOLD; + return '~'; + } + --i; + } + /* Make sure we're back to AT_NORMAL before the '\n'. */ + *ap = AT_NORMAL; + return i ? '\0' : '\n'; + } + + if (i < linebuf.pfx_end) + { + *ap = linebuf.pfx_attr[i]; + return linebuf.pfx[i]; + } + i += linebuf.print - linebuf.pfx_end; + *ap = linebuf.attr[i]; + return (linebuf.buf[i] & 0xFF); } /* * Indicate that there is no current line. */ - public void + public void null_line(VOID_PARAM) { - is_null_line = 1; - cshift = 0; + is_null_line = 1; + cshift = 0; } /* @@ -1289,212 +1289,212 @@ null_line(VOID_PARAM) * lines which are not split for screen width. * {{ This is supposed to be more efficient than forw_line(). }} */ - public POSITION + public POSITION forw_raw_line(curr_pos, linep, line_lenp) - POSITION curr_pos; - char **linep; - int *line_lenp; + POSITION curr_pos; + char **linep; + int *line_lenp; { - int n; - int c; - POSITION new_pos; - - if (curr_pos == NULL_POSITION || ch_seek(curr_pos) || - (c = ch_forw_get()) == EOI) - return (NULL_POSITION); - - n = 0; - for (;;) - { - if (c == '\n' || c == EOI || ABORT_SIGS()) - { - new_pos = ch_tell(); - break; - } - if (n >= size_linebuf-1) - { - if (expand_linebuf()) - { - /* - * Overflowed the input buffer. - * Pretend the line ended here. - */ - new_pos = ch_tell() - 1; - break; - } - } - linebuf.buf[n++] = c; - c = ch_forw_get(); - } - linebuf.buf[n] = '\0'; - if (linep != NULL) - *linep = linebuf.buf; - if (line_lenp != NULL) - *line_lenp = n; - return (new_pos); + int n; + int c; + POSITION new_pos; + + if (curr_pos == NULL_POSITION || ch_seek(curr_pos) || + (c = ch_forw_get()) == EOI) + return (NULL_POSITION); + + n = 0; + for (;;) + { + if (c == '\n' || c == EOI || ABORT_SIGS()) + { + new_pos = ch_tell(); + break; + } + if (n >= size_linebuf-1) + { + if (expand_linebuf()) + { + /* + * Overflowed the input buffer. + * Pretend the line ended here. + */ + new_pos = ch_tell() - 1; + break; + } + } + linebuf.buf[n++] = c; + c = ch_forw_get(); + } + linebuf.buf[n] = '\0'; + if (linep != NULL) + *linep = linebuf.buf; + if (line_lenp != NULL) + *line_lenp = n; + return (new_pos); } /* * Analogous to back_line(), but deals with "raw lines". * {{ This is supposed to be more efficient than back_line(). }} */ - public POSITION + public POSITION back_raw_line(curr_pos, linep, line_lenp) - POSITION curr_pos; - char **linep; - int *line_lenp; + POSITION curr_pos; + char **linep; + int *line_lenp; { - int n; - int c; - POSITION new_pos; - - if (curr_pos == NULL_POSITION || curr_pos <= ch_zero() || - ch_seek(curr_pos-1)) - return (NULL_POSITION); - - n = size_linebuf; - linebuf.buf[--n] = '\0'; - for (;;) - { - c = ch_back_get(); - if (c == '\n' || ABORT_SIGS()) - { - /* - * This is the newline ending the previous line. - * We have hit the beginning of the line. - */ - new_pos = ch_tell() + 1; - break; - } - if (c == EOI) - { - /* - * We have hit the beginning of the file. - * This must be the first line in the file. - * This must, of course, be the beginning of the line. - */ - new_pos = ch_zero(); - break; - } - if (n <= 0) - { - int old_size_linebuf = size_linebuf; - char *fm; - char *to; - if (expand_linebuf()) - { - /* - * Overflowed the input buffer. - * Pretend the line ended here. - */ - new_pos = ch_tell() + 1; - break; - } - /* - * Shift the data to the end of the new linebuf. - */ - for (fm = linebuf.buf + old_size_linebuf - 1, - to = linebuf.buf + size_linebuf - 1; - fm >= linebuf.buf; fm--, to--) - *to = *fm; - n = size_linebuf - old_size_linebuf; - } - linebuf.buf[--n] = c; - } - if (linep != NULL) - *linep = &linebuf.buf[n]; - if (line_lenp != NULL) - *line_lenp = size_linebuf - 1 - n; - return (new_pos); + int n; + int c; + POSITION new_pos; + + if (curr_pos == NULL_POSITION || curr_pos <= ch_zero() || + ch_seek(curr_pos-1)) + return (NULL_POSITION); + + n = size_linebuf; + linebuf.buf[--n] = '\0'; + for (;;) + { + c = ch_back_get(); + if (c == '\n' || ABORT_SIGS()) + { + /* + * This is the newline ending the previous line. + * We have hit the beginning of the line. + */ + new_pos = ch_tell() + 1; + break; + } + if (c == EOI) + { + /* + * We have hit the beginning of the file. + * This must be the first line in the file. + * This must, of course, be the beginning of the line. + */ + new_pos = ch_zero(); + break; + } + if (n <= 0) + { + int old_size_linebuf = size_linebuf; + char *fm; + char *to; + if (expand_linebuf()) + { + /* + * Overflowed the input buffer. + * Pretend the line ended here. + */ + new_pos = ch_tell() + 1; + break; + } + /* + * Shift the data to the end of the new linebuf. + */ + for (fm = linebuf.buf + old_size_linebuf - 1, + to = linebuf.buf + size_linebuf - 1; + fm >= linebuf.buf; fm--, to--) + *to = *fm; + n = size_linebuf - old_size_linebuf; + } + linebuf.buf[--n] = c; + } + if (linep != NULL) + *linep = &linebuf.buf[n]; + if (line_lenp != NULL) + *line_lenp = size_linebuf - 1 - n; + return (new_pos); } /* * Find the shift necessary to show the end of the longest displayed line. */ - public int + public int rrshift(VOID_PARAM) { - POSITION pos; - int save_width; - int line; - int longest = 0; - - save_width = sc_width; - sc_width = INT_MAX; - pos = position(TOP); - for (line = 0; line < sc_height && pos != NULL_POSITION; line++) - { - pos = forw_line(pos); - if (end_column > longest) - longest = end_column; - } - sc_width = save_width; - if (longest < sc_width) - return 0; - return longest - sc_width; + POSITION pos; + int save_width; + int line; + int longest = 0; + + save_width = sc_width; + sc_width = INT_MAX; + pos = position(TOP); + for (line = 0; line < sc_height && pos != NULL_POSITION; line++) + { + pos = forw_line(pos); + if (end_column > longest) + longest = end_column; + } + sc_width = save_width; + if (longest < sc_width) + return 0; + return longest - sc_width; } /* * Get the color_map index associated with a given attribute. */ - static int + static int color_index(attr) - int attr; + int attr; { - if (use_color) - { - switch (attr & AT_COLOR) - { - case AT_COLOR_ATTN: return 0; - case AT_COLOR_BIN: return 1; - case AT_COLOR_CTRL: return 2; - case AT_COLOR_ERROR: return 3; - case AT_COLOR_LINENUM: return 4; - case AT_COLOR_MARK: return 5; - case AT_COLOR_PROMPT: return 6; - case AT_COLOR_RSCROLL: return 7; - case AT_COLOR_SEARCH: return 8; - } - } - if (attr & AT_UNDERLINE) - return 9; - if (attr & AT_BOLD) - return 10; - if (attr & AT_BLINK) - return 11; - if (attr & AT_STANDOUT) - return 12; - return -1; + if (use_color) + { + switch (attr & AT_COLOR) + { + case AT_COLOR_ATTN: return 0; + case AT_COLOR_BIN: return 1; + case AT_COLOR_CTRL: return 2; + case AT_COLOR_ERROR: return 3; + case AT_COLOR_LINENUM: return 4; + case AT_COLOR_MARK: return 5; + case AT_COLOR_PROMPT: return 6; + case AT_COLOR_RSCROLL: return 7; + case AT_COLOR_SEARCH: return 8; + } + } + if (attr & AT_UNDERLINE) + return 9; + if (attr & AT_BOLD) + return 10; + if (attr & AT_BLINK) + return 11; + if (attr & AT_STANDOUT) + return 12; + return -1; } /* * Set the color string to use for a given attribute. */ - public int + public int set_color_map(attr, colorstr) - int attr; - char *colorstr; + int attr; + char *colorstr; { - int cx = color_index(attr); - if (cx < 0) - return -1; - if (strlen(colorstr)+1 > sizeof(color_map[cx])) - return -1; - if (*colorstr != '\0' && parse_color(colorstr, NULL, NULL) == CT_NULL) - return -1; - strcpy(color_map[cx], colorstr); - return 0; + int cx = color_index(attr); + if (cx < 0) + return -1; + if (strlen(colorstr)+1 > sizeof(color_map[cx])) + return -1; + if (*colorstr != '\0' && parse_color(colorstr, NULL, NULL) == CT_NULL) + return -1; + strcpy(color_map[cx], colorstr); + return 0; } /* * Get the color string to use for a given attribute. */ - public char * + public char * get_color_map(attr) - int attr; + int attr; { - int cx = color_index(attr); - if (cx < 0) - return NULL; - return color_map[cx]; + int cx = color_index(attr); + if (cx < 0) + return NULL; + return color_map[cx]; } diff --git a/linenum.c b/linenum.c index 00cac60..8d4fac1 100644 --- a/linenum.c +++ b/linenum.c @@ -40,11 +40,11 @@ */ struct linenum_info { - struct linenum_info *next; /* Link to next in the list */ - struct linenum_info *prev; /* Line to previous in the list */ - POSITION pos; /* File position */ - POSITION gap; /* Gap between prev and next */ - LINENUM line; /* Line number */ + struct linenum_info *next; /* Link to next in the list */ + struct linenum_info *prev; /* Line to previous in the list */ + POSITION pos; /* File position */ + POSITION gap; /* Gap between prev and next */ + LINENUM line; /* Line number */ }; /* * "gap" needs some explanation: the gap of any particular line number @@ -72,47 +72,47 @@ extern int screen_trashed; /* * Initialize the line number structures. */ - public void + public void clr_linenum(VOID_PARAM) { - struct linenum_info *p; - - /* - * Put all the entries on the free list. - * Leave one for the "spare". - */ - for (p = pool; p < &pool[NPOOL-2]; p++) - p->next = p+1; - pool[NPOOL-2].next = NULL; - freelist = pool; - - spare = &pool[NPOOL-1]; - - /* - * Initialize the anchor. - */ - anchor.next = anchor.prev = &anchor; - anchor.gap = 0; - anchor.pos = (POSITION)0; - anchor.line = 1; + struct linenum_info *p; + + /* + * Put all the entries on the free list. + * Leave one for the "spare". + */ + for (p = pool; p < &pool[NPOOL-2]; p++) + p->next = p+1; + pool[NPOOL-2].next = NULL; + freelist = pool; + + spare = &pool[NPOOL-1]; + + /* + * Initialize the anchor. + */ + anchor.next = anchor.prev = &anchor; + anchor.gap = 0; + anchor.pos = (POSITION)0; + anchor.line = 1; } /* * Calculate the gap for an entry. */ - static void + static void calcgap(p) - struct linenum_info *p; + struct linenum_info *p; { - /* - * Don't bother to compute a gap for the anchor. - * Also don't compute a gap for the last one in the list. - * The gap for that last one should be considered infinite, - * but we never look at it anyway. - */ - if (p == &anchor || p->next == &anchor) - return; - p->gap = p->next->pos - p->prev->pos; + /* + * Don't bother to compute a gap for the anchor. + * Also don't compute a gap for the last one in the list. + * The gap for that last one should be considered infinite, + * but we never look at it anyway. + */ + if (p == &anchor || p->next == &anchor) + return; + p->gap = p->next->pos - p->prev->pos; } /* @@ -120,98 +120,98 @@ calcgap(p) * The specified position (pos) should be the file position of the * FIRST character in the specified line. */ - public void + public void add_lnum(linenum, pos) - LINENUM linenum; - POSITION pos; + LINENUM linenum; + POSITION pos; { - struct linenum_info *p; - struct linenum_info *new; - struct linenum_info *nextp; - struct linenum_info *prevp; - POSITION mingap; - - /* - * Find the proper place in the list for the new one. - * The entries are sorted by position. - */ - for (p = anchor.next; p != &anchor && p->pos < pos; p = p->next) - if (p->line == linenum) - /* We already have this one. */ - return; - nextp = p; - prevp = p->prev; - - if (freelist != NULL) - { - /* - * We still have free (unused) entries. - * Use one of them. - */ - new = freelist; - freelist = freelist->next; - } else - { - /* - * No free entries. - * Use the "spare" entry. - */ - new = spare; - spare = NULL; - } - - /* - * Fill in the fields of the new entry, - * and insert it into the proper place in the list. - */ - new->next = nextp; - new->prev = prevp; - new->pos = pos; - new->line = linenum; - - nextp->prev = new; - prevp->next = new; - - /* - * Recalculate gaps for the new entry and the neighboring entries. - */ - calcgap(new); - calcgap(nextp); - calcgap(prevp); - - if (spare == NULL) - { - /* - * We have used the spare entry. - * Scan the list to find the one with the smallest - * gap, take it out and make it the spare. - * We should never remove the last one, so stop when - * we get to p->next == &anchor. This also avoids - * looking at the gap of the last one, which is - * not computed by calcgap. - */ - mingap = anchor.next->gap; - for (p = anchor.next; p->next != &anchor; p = p->next) - { - if (p->gap <= mingap) - { - spare = p; - mingap = p->gap; - } - } - spare->next->prev = spare->prev; - spare->prev->next = spare->next; - } + struct linenum_info *p; + struct linenum_info *new; + struct linenum_info *nextp; + struct linenum_info *prevp; + POSITION mingap; + + /* + * Find the proper place in the list for the new one. + * The entries are sorted by position. + */ + for (p = anchor.next; p != &anchor && p->pos < pos; p = p->next) + if (p->line == linenum) + /* We already have this one. */ + return; + nextp = p; + prevp = p->prev; + + if (freelist != NULL) + { + /* + * We still have free (unused) entries. + * Use one of them. + */ + new = freelist; + freelist = freelist->next; + } else + { + /* + * No free entries. + * Use the "spare" entry. + */ + new = spare; + spare = NULL; + } + + /* + * Fill in the fields of the new entry, + * and insert it into the proper place in the list. + */ + new->next = nextp; + new->prev = prevp; + new->pos = pos; + new->line = linenum; + + nextp->prev = new; + prevp->next = new; + + /* + * Recalculate gaps for the new entry and the neighboring entries. + */ + calcgap(new); + calcgap(nextp); + calcgap(prevp); + + if (spare == NULL) + { + /* + * We have used the spare entry. + * Scan the list to find the one with the smallest + * gap, take it out and make it the spare. + * We should never remove the last one, so stop when + * we get to p->next == &anchor. This also avoids + * looking at the gap of the last one, which is + * not computed by calcgap. + */ + mingap = anchor.next->gap; + for (p = anchor.next; p->next != &anchor; p = p->next) + { + if (p->gap <= mingap) + { + spare = p; + mingap = p->gap; + } + } + spare->next->prev = spare->prev; + spare->prev->next = spare->next; + } } /* * If we get stuck in a long loop trying to figure out the * line number, print a message to tell the user what we're doing. */ - static void + static void longloopmessage(VOID_PARAM) { - ierror("Calculating line numbers", NULL_PARG); + ierror("Calculating line numbers", NULL_PARG); } static int loopcount; @@ -219,25 +219,25 @@ static int loopcount; static time_type startime; #endif - static void + static void longish(VOID_PARAM) { #if HAVE_TIME - if (loopcount >= 0 && ++loopcount > 100) - { - loopcount = 0; - if (get_time() >= startime + LONGTIME) - { - longloopmessage(); - loopcount = -1; - } - } + if (loopcount >= 0 && ++loopcount > 100) + { + loopcount = 0; + if (get_time() >= startime + LONGTIME) + { + longloopmessage(); + loopcount = -1; + } + } #else - if (loopcount >= 0 && ++loopcount > LONGLOOP) - { - longloopmessage(); - loopcount = -1; - } + if (loopcount >= 0 && ++loopcount > LONGLOOP) + { + longloopmessage(); + loopcount = -1; + } #endif } @@ -245,204 +245,204 @@ longish(VOID_PARAM) * Turn off line numbers because the user has interrupted * a lengthy line number calculation. */ - static void + static void abort_long(VOID_PARAM) { - if (loopcount >= 0) - return; - if (linenums == OPT_ONPLUS) - /* - * We were displaying line numbers, so need to repaint. - */ - screen_trashed = 1; - linenums = 0; - error("Line numbers turned off", NULL_PARG); + if (loopcount >= 0) + return; + if (linenums == OPT_ONPLUS) + /* + * We were displaying line numbers, so need to repaint. + */ + screen_trashed = 1; + linenums = 0; + error("Line numbers turned off", NULL_PARG); } /* * Find the line number associated with a given position. * Return 0 if we can't figure it out. */ - public LINENUM + public LINENUM find_linenum(pos) - POSITION pos; + POSITION pos; { - struct linenum_info *p; - LINENUM linenum; - POSITION cpos; - - if (!linenums) - /* - * We're not using line numbers. - */ - return (0); - if (pos == NULL_POSITION) - /* - * Caller doesn't know what he's talking about. - */ - return (0); - if (pos <= ch_zero()) - /* - * Beginning of file is always line number 1. - */ - return (1); - - /* - * Find the entry nearest to the position we want. - */ - for (p = anchor.next; p != &anchor && p->pos < pos; p = p->next) - continue; - if (p->pos == pos) - /* Found it exactly. */ - return (p->line); - - /* - * This is the (possibly) time-consuming part. - * We start at the line we just found and start - * reading the file forward or backward till we - * get to the place we want. - * - * First decide whether we should go forward from the - * previous one or backwards from the next one. - * The decision is based on which way involves - * traversing fewer bytes in the file. - */ + struct linenum_info *p; + LINENUM linenum; + POSITION cpos; + + if (!linenums) + /* + * We're not using line numbers. + */ + return (0); + if (pos == NULL_POSITION) + /* + * Caller doesn't know what he's talking about. + */ + return (0); + if (pos <= ch_zero()) + /* + * Beginning of file is always line number 1. + */ + return (1); + + /* + * Find the entry nearest to the position we want. + */ + for (p = anchor.next; p != &anchor && p->pos < pos; p = p->next) + continue; + if (p->pos == pos) + /* Found it exactly. */ + return (p->line); + + /* + * This is the (possibly) time-consuming part. + * We start at the line we just found and start + * reading the file forward or backward till we + * get to the place we want. + * + * First decide whether we should go forward from the + * previous one or backwards from the next one. + * The decision is based on which way involves + * traversing fewer bytes in the file. + */ #if HAVE_TIME - startime = get_time(); + startime = get_time(); #endif - loopcount = 0; - if (p == &anchor || pos - p->prev->pos < p->pos - pos) - { - /* - * Go forward. - */ - p = p->prev; - if (ch_seek(p->pos)) - return (0); - for (linenum = p->line, cpos = p->pos; cpos < pos; linenum++) - { - /* - * Allow a signal to abort this loop. - */ - cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); - if (ABORT_SIGS()) { - abort_long(); - return (0); - } - if (cpos == NULL_POSITION) - return (0); - longish(); - } - /* - * We might as well cache it. - */ - add_lnum(linenum, cpos); - /* - * If the given position is not at the start of a line, - * make sure we return the correct line number. - */ - if (cpos > pos) - linenum--; - } else - { - /* - * Go backward. - */ - if (ch_seek(p->pos)) - return (0); - for (linenum = p->line, cpos = p->pos; cpos > pos; linenum--) - { - /* - * Allow a signal to abort this loop. - */ - cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); - if (ABORT_SIGS()) { - abort_long(); - return (0); - } - if (cpos == NULL_POSITION) - return (0); - longish(); - } - /* - * We might as well cache it. - */ - add_lnum(linenum, cpos); - } - loopcount = 0; - return (linenum); + loopcount = 0; + if (p == &anchor || pos - p->prev->pos < p->pos - pos) + { + /* + * Go forward. + */ + p = p->prev; + if (ch_seek(p->pos)) + return (0); + for (linenum = p->line, cpos = p->pos; cpos < pos; linenum++) + { + /* + * Allow a signal to abort this loop. + */ + cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); + if (ABORT_SIGS()) { + abort_long(); + return (0); + } + if (cpos == NULL_POSITION) + return (0); + longish(); + } + /* + * We might as well cache it. + */ + add_lnum(linenum, cpos); + /* + * If the given position is not at the start of a line, + * make sure we return the correct line number. + */ + if (cpos > pos) + linenum--; + } else + { + /* + * Go backward. + */ + if (ch_seek(p->pos)) + return (0); + for (linenum = p->line, cpos = p->pos; cpos > pos; linenum--) + { + /* + * Allow a signal to abort this loop. + */ + cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); + if (ABORT_SIGS()) { + abort_long(); + return (0); + } + if (cpos == NULL_POSITION) + return (0); + longish(); + } + /* + * We might as well cache it. + */ + add_lnum(linenum, cpos); + } + loopcount = 0; + return (linenum); } /* * Find the position of a given line number. * Return NULL_POSITION if we can't figure it out. */ - public POSITION + public POSITION find_pos(linenum) - LINENUM linenum; + LINENUM linenum; { - struct linenum_info *p; - POSITION cpos; - LINENUM clinenum; - - if (linenum <= 1) - /* - * Line number 1 is beginning of file. - */ - return (ch_zero()); - - /* - * Find the entry nearest to the line number we want. - */ - for (p = anchor.next; p != &anchor && p->line < linenum; p = p->next) - continue; - if (p->line == linenum) - /* Found it exactly. */ - return (p->pos); - - if (p == &anchor || linenum - p->prev->line < p->line - linenum) - { - /* - * Go forward. - */ - p = p->prev; - if (ch_seek(p->pos)) - return (NULL_POSITION); - for (clinenum = p->line, cpos = p->pos; clinenum < linenum; clinenum++) - { - /* - * Allow a signal to abort this loop. - */ - cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); - if (ABORT_SIGS()) - return (NULL_POSITION); - if (cpos == NULL_POSITION) - return (NULL_POSITION); - } - } else - { - /* - * Go backward. - */ - if (ch_seek(p->pos)) - return (NULL_POSITION); - for (clinenum = p->line, cpos = p->pos; clinenum > linenum; clinenum--) - { - /* - * Allow a signal to abort this loop. - */ - cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); - if (ABORT_SIGS()) - return (NULL_POSITION); - if (cpos == NULL_POSITION) - return (NULL_POSITION); - } - } - /* - * We might as well cache it. - */ - add_lnum(clinenum, cpos); - return (cpos); + struct linenum_info *p; + POSITION cpos; + LINENUM clinenum; + + if (linenum <= 1) + /* + * Line number 1 is beginning of file. + */ + return (ch_zero()); + + /* + * Find the entry nearest to the line number we want. + */ + for (p = anchor.next; p != &anchor && p->line < linenum; p = p->next) + continue; + if (p->line == linenum) + /* Found it exactly. */ + return (p->pos); + + if (p == &anchor || linenum - p->prev->line < p->line - linenum) + { + /* + * Go forward. + */ + p = p->prev; + if (ch_seek(p->pos)) + return (NULL_POSITION); + for (clinenum = p->line, cpos = p->pos; clinenum < linenum; clinenum++) + { + /* + * Allow a signal to abort this loop. + */ + cpos = forw_raw_line(cpos, (char **)NULL, (int *)NULL); + if (ABORT_SIGS()) + return (NULL_POSITION); + if (cpos == NULL_POSITION) + return (NULL_POSITION); + } + } else + { + /* + * Go backward. + */ + if (ch_seek(p->pos)) + return (NULL_POSITION); + for (clinenum = p->line, cpos = p->pos; clinenum > linenum; clinenum--) + { + /* + * Allow a signal to abort this loop. + */ + cpos = back_raw_line(cpos, (char **)NULL, (int *)NULL); + if (ABORT_SIGS()) + return (NULL_POSITION); + if (cpos == NULL_POSITION) + return (NULL_POSITION); + } + } + /* + * We might as well cache it. + */ + add_lnum(clinenum, cpos); + return (cpos); } /* @@ -450,22 +450,22 @@ find_pos(linenum) * The argument "where" tells which line is to be considered * the "current" line (e.g. TOP, BOTTOM, MIDDLE, etc). */ - public LINENUM + public LINENUM currline(where) - int where; + int where; { - POSITION pos; - POSITION len; - LINENUM linenum; - - pos = position(where); - len = ch_length(); - while (pos == NULL_POSITION && where >= 0 && where < sc_height) - pos = position(++where); - if (pos == NULL_POSITION) - pos = len; - linenum = find_linenum(pos); - if (pos == len) - linenum--; - return (linenum); + POSITION pos; + POSITION len; + LINENUM linenum; + + pos = position(where); + len = ch_length(); + while (pos == NULL_POSITION && where >= 0 && where < sc_height) + pos = position(++where); + if (pos == NULL_POSITION) + pos = len; + linenum = find_linenum(pos); + if (pos == len) + linenum--; + return (linenum); } diff --git a/lsystem.c b/lsystem.c index 5c67526..c21cb68 100644 --- a/lsystem.c +++ b/lsystem.c @@ -42,201 +42,201 @@ extern IFILE curr_ifile; * Pass the specified command to a shell to be executed. * Like plain "system()", but handles resetting terminal modes, etc. */ - public void + public void lsystem(cmd, donemsg) - char *cmd; - char *donemsg; + char *cmd; + char *donemsg; { - int inp; + int inp; #if HAVE_SHELL - char *shell; - char *p; + char *shell; + char *p; #endif - IFILE save_ifile; + IFILE save_ifile; #if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C - char cwd[FILENAME_MAX+1]; + char cwd[FILENAME_MAX+1]; #endif - /* - * Print the command which is to be executed, - * unless the command starts with a "-". - */ - if (cmd[0] == '-') - cmd++; - else - { - clear_bot(); - putstr("!"); - putstr(cmd); - putstr("\n"); - } + /* + * Print the command which is to be executed, + * unless the command starts with a "-". + */ + if (cmd[0] == '-') + cmd++; + else + { + clear_bot(); + putstr("!"); + putstr(cmd); + putstr("\n"); + } #if MSDOS_COMPILER #if MSDOS_COMPILER==WIN32C - if (*cmd == '\0') - cmd = getenv("COMSPEC"); + if (*cmd == '\0') + cmd = getenv("COMSPEC"); #else - /* - * Working directory is global on MSDOS. - * The child might change the working directory, so we - * must save and restore CWD across calls to "system", - * or else we won't find our file when we return and - * try to "reedit_ifile" it. - */ - getcwd(cwd, FILENAME_MAX); + /* + * Working directory is global on MSDOS. + * The child might change the working directory, so we + * must save and restore CWD across calls to "system", + * or else we won't find our file when we return and + * try to "reedit_ifile" it. + */ + getcwd(cwd, FILENAME_MAX); #endif #endif - /* - * Close the current input file. - */ - save_ifile = save_curr_ifile(); - (void) edit_ifile(NULL_IFILE); - - /* - * De-initialize the terminal and take out of raw mode. - */ - deinit(); - flush(); /* Make sure the deinit chars get out */ - raw_mode(0); + /* + * Close the current input file. + */ + save_ifile = save_curr_ifile(); + (void) edit_ifile(NULL_IFILE); + + /* + * De-initialize the terminal and take out of raw mode. + */ + deinit(); + flush(); /* Make sure the deinit chars get out */ + raw_mode(0); #if MSDOS_COMPILER==WIN32C - close_getchr(); + close_getchr(); #endif - /* - * Restore signals to their defaults. - */ - init_signals(0); + /* + * Restore signals to their defaults. + */ + init_signals(0); #if HAVE_DUP - /* - * Force standard input to be the user's terminal - * (the normal standard input), even if less's standard input - * is coming from a pipe. - */ - inp = dup(0); - close(0); + /* + * Force standard input to be the user's terminal + * (the normal standard input), even if less's standard input + * is coming from a pipe. + */ + inp = dup(0); + close(0); #if !MSDOS_COMPILER #if OS2 - /* The __open() system call translates "/dev/tty" to "con". */ - if (__open(tty_device(), OPEN_READ) < 0) + /* The __open() system call translates "/dev/tty" to "con". */ + if (__open(tty_device(), OPEN_READ) < 0) #else - if (open(tty_device(), OPEN_READ) < 0) + if (open(tty_device(), OPEN_READ) < 0) #endif #endif - dup(inp); + dup(inp); #endif - /* - * Pass the command to the system to be executed. - * If we have a SHELL environment variable, use - * <$SHELL -c "command"> instead of just . - * If the command is empty, just invoke a shell. - */ + /* + * Pass the command to the system to be executed. + * If we have a SHELL environment variable, use + * <$SHELL -c "command"> instead of just . + * If the command is empty, just invoke a shell. + */ #if HAVE_SHELL - p = NULL; - if ((shell = lgetenv("SHELL")) != NULL && *shell != '\0') - { - if (*cmd == '\0') - p = save(shell); - else - { - char *esccmd = shell_quote(cmd); - if (esccmd != NULL) - { - int len = (int) (strlen(shell) + strlen(esccmd) + 5); - p = (char *) ecalloc(len, sizeof(char)); - SNPRINTF3(p, len, "%s %s %s", shell, shell_coption(), esccmd); - free(esccmd); - } - } - } - if (p == NULL) - { - if (*cmd == '\0') - p = save("sh"); - else - p = save(cmd); - } - system(p); - free(p); + p = NULL; + if ((shell = lgetenv("SHELL")) != NULL && *shell != '\0') + { + if (*cmd == '\0') + p = save(shell); + else + { + char *esccmd = shell_quote(cmd); + if (esccmd != NULL) + { + int len = (int) (strlen(shell) + strlen(esccmd) + 5); + p = (char *) ecalloc(len, sizeof(char)); + SNPRINTF3(p, len, "%s %s %s", shell, shell_coption(), esccmd); + free(esccmd); + } + } + } + if (p == NULL) + { + if (*cmd == '\0') + p = save("sh"); + else + p = save(cmd); + } + system(p); + free(p); #else #if MSDOS_COMPILER==DJGPPC - /* - * Make stdin of the child be in cooked mode. - */ - setmode(0, O_TEXT); - /* - * We don't need to catch signals of the child (it - * also makes trouble with some DPMI servers). - */ - __djgpp_exception_toggle(); - system(cmd); - __djgpp_exception_toggle(); + /* + * Make stdin of the child be in cooked mode. + */ + setmode(0, O_TEXT); + /* + * We don't need to catch signals of the child (it + * also makes trouble with some DPMI servers). + */ + __djgpp_exception_toggle(); + system(cmd); + __djgpp_exception_toggle(); #else - system(cmd); + system(cmd); #endif #endif #if HAVE_DUP - /* - * Restore standard input, reset signals, raw mode, etc. - */ - close(0); - dup(inp); - close(inp); + /* + * Restore standard input, reset signals, raw mode, etc. + */ + close(0); + dup(inp); + close(inp); #endif #if MSDOS_COMPILER==WIN32C - open_getchr(); + open_getchr(); #endif - init_signals(1); - raw_mode(1); - if (donemsg != NULL) - { - putstr(donemsg); - putstr(" (press RETURN)"); - get_return(); - putchr('\n'); - flush(); - } - init(); - screen_trashed = 1; + init_signals(1); + raw_mode(1); + if (donemsg != NULL) + { + putstr(donemsg); + putstr(" (press RETURN)"); + get_return(); + putchr('\n'); + flush(); + } + init(); + screen_trashed = 1; #if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C - /* - * Restore the previous directory (possibly - * changed by the child program we just ran). - */ - chdir(cwd); + /* + * Restore the previous directory (possibly + * changed by the child program we just ran). + */ + chdir(cwd); #if MSDOS_COMPILER != DJGPPC - /* - * Some versions of chdir() don't change to the drive - * which is part of CWD. (DJGPP does this in chdir.) - */ - if (cwd[1] == ':') - { - if (cwd[0] >= 'a' && cwd[0] <= 'z') - setdisk(cwd[0] - 'a'); - else if (cwd[0] >= 'A' && cwd[0] <= 'Z') - setdisk(cwd[0] - 'A'); - } + /* + * Some versions of chdir() don't change to the drive + * which is part of CWD. (DJGPP does this in chdir.) + */ + if (cwd[1] == ':') + { + if (cwd[0] >= 'a' && cwd[0] <= 'z') + setdisk(cwd[0] - 'a'); + else if (cwd[0] >= 'A' && cwd[0] <= 'Z') + setdisk(cwd[0] - 'A'); + } #endif #endif - /* - * Reopen the current input file. - */ - reedit_ifile(save_ifile); + /* + * Reopen the current input file. + */ + reedit_ifile(save_ifile); #if defined(SIGWINCH) || defined(SIGWIND) - /* - * Since we were ignoring window change signals while we executed - * the system command, we must assume the window changed. - * Warning: this leaves a signal pending (in "sigs"), - * so psignals() should be called soon after lsystem(). - */ - winch(0); + /* + * Since we were ignoring window change signals while we executed + * the system command, we must assume the window changed. + * Warning: this leaves a signal pending (in "sigs"), + * so psignals() should be called soon after lsystem(). + */ + winch(0); #endif } @@ -256,124 +256,124 @@ lsystem(cmd, donemsg) * If the mark is on the current screen, or if the mark is ".", * the whole current screen is piped. */ - public int + public int pipe_mark(c, cmd) - int c; - char *cmd; + int c; + char *cmd; { - POSITION mpos, tpos, bpos; - - /* - * mpos = the marked position. - * tpos = top of screen. - * bpos = bottom of screen. - */ - mpos = markpos(c); - if (mpos == NULL_POSITION) - return (-1); - tpos = position(TOP); - if (tpos == NULL_POSITION) - tpos = ch_zero(); - bpos = position(BOTTOM); - - if (c == '.') - return (pipe_data(cmd, tpos, bpos)); - else if (mpos <= tpos) - return (pipe_data(cmd, mpos, bpos)); - else if (bpos == NULL_POSITION) - return (pipe_data(cmd, tpos, bpos)); - else - return (pipe_data(cmd, tpos, mpos)); + POSITION mpos, tpos, bpos; + + /* + * mpos = the marked position. + * tpos = top of screen. + * bpos = bottom of screen. + */ + mpos = markpos(c); + if (mpos == NULL_POSITION) + return (-1); + tpos = position(TOP); + if (tpos == NULL_POSITION) + tpos = ch_zero(); + bpos = position(BOTTOM); + + if (c == '.') + return (pipe_data(cmd, tpos, bpos)); + else if (mpos <= tpos) + return (pipe_data(cmd, mpos, bpos)); + else if (bpos == NULL_POSITION) + return (pipe_data(cmd, tpos, bpos)); + else + return (pipe_data(cmd, tpos, mpos)); } /* * Create a pipe to the given shell command. * Feed it the file contents between the positions spos and epos. */ - public int + public int pipe_data(cmd, spos, epos) - char *cmd; - POSITION spos; - POSITION epos; + char *cmd; + POSITION spos; + POSITION epos; { - FILE *f; - int c; - - /* - * This is structured much like lsystem(). - * Since we're running a shell program, we must be careful - * to perform the necessary deinitialization before running - * the command, and reinitialization after it. - */ - if (ch_seek(spos) != 0) - { - error("Cannot seek to start position", NULL_PARG); - return (-1); - } - - if ((f = popen(cmd, "w")) == NULL) - { - error("Cannot create pipe", NULL_PARG); - return (-1); - } - clear_bot(); - putstr("!"); - putstr(cmd); - putstr("\n"); - - deinit(); - flush(); - raw_mode(0); - init_signals(0); + FILE *f; + int c; + + /* + * This is structured much like lsystem(). + * Since we're running a shell program, we must be careful + * to perform the necessary deinitialization before running + * the command, and reinitialization after it. + */ + if (ch_seek(spos) != 0) + { + error("Cannot seek to start position", NULL_PARG); + return (-1); + } + + if ((f = popen(cmd, "w")) == NULL) + { + error("Cannot create pipe", NULL_PARG); + return (-1); + } + clear_bot(); + putstr("!"); + putstr(cmd); + putstr("\n"); + + deinit(); + flush(); + raw_mode(0); + init_signals(0); #if MSDOS_COMPILER==WIN32C - close_getchr(); + close_getchr(); #endif #ifdef SIGPIPE - LSIGNAL(SIGPIPE, SIG_IGN); + LSIGNAL(SIGPIPE, SIG_IGN); #endif - c = EOI; - while (epos == NULL_POSITION || spos++ <= epos) - { - /* - * Read a character from the file and give it to the pipe. - */ - c = ch_forw_get(); - if (c == EOI) - break; - if (putc(c, f) == EOF) - break; - } - - /* - * Finish up the last line. - */ - while (c != '\n' && c != EOI ) - { - c = ch_forw_get(); - if (c == EOI) - break; - if (putc(c, f) == EOF) - break; - } - - pclose(f); + c = EOI; + while (epos == NULL_POSITION || spos++ <= epos) + { + /* + * Read a character from the file and give it to the pipe. + */ + c = ch_forw_get(); + if (c == EOI) + break; + if (putc(c, f) == EOF) + break; + } + + /* + * Finish up the last line. + */ + while (c != '\n' && c != EOI ) + { + c = ch_forw_get(); + if (c == EOI) + break; + if (putc(c, f) == EOF) + break; + } + + pclose(f); #ifdef SIGPIPE - LSIGNAL(SIGPIPE, SIG_DFL); + LSIGNAL(SIGPIPE, SIG_DFL); #endif #if MSDOS_COMPILER==WIN32C - open_getchr(); + open_getchr(); #endif - init_signals(1); - raw_mode(1); - init(); - screen_trashed = 1; + init_signals(1); + raw_mode(1); + init(); + screen_trashed = 1; #if defined(SIGWINCH) || defined(SIGWIND) - /* {{ Probably don't need this here. }} */ - winch(0); + /* {{ Probably don't need this here. }} */ + winch(0); #endif - return (0); + return (0); } #endif diff --git a/main.c b/main.c index 7248842..c5e7346 100644 --- a/main.c +++ b/main.c @@ -68,289 +68,289 @@ extern int errmsgs; */ int main(argc, argv) - int argc; - char *argv[]; + int argc; + char *argv[]; { - IFILE ifile; - char *s; + IFILE ifile; + char *s; #ifdef __EMX__ - _response(&argc, &argv); - _wildcard(&argc, &argv); + _response(&argc, &argv); + _wildcard(&argc, &argv); #endif - progname = *argv++; - argc--; + progname = *argv++; + argc--; #if SECURE - secure = 1; + secure = 1; #else - secure = 0; - s = lgetenv("LESSSECURE"); - if (!isnullenv(s)) - secure = 1; + secure = 0; + s = lgetenv("LESSSECURE"); + if (!isnullenv(s)) + secure = 1; #endif #ifdef WIN32 - if (getenv("HOME") == NULL) - { - /* - * If there is no HOME environment variable, - * try the concatenation of HOMEDRIVE + HOMEPATH. - */ - char *drive = getenv("HOMEDRIVE"); - char *path = getenv("HOMEPATH"); - if (drive != NULL && path != NULL) - { - char *env = (char *) ecalloc(strlen(drive) + - strlen(path) + 6, sizeof(char)); - strcpy(env, "HOME="); - strcat(env, drive); - strcat(env, path); - putenv(env); - } - } - GetConsoleTitle(consoleTitle, sizeof(consoleTitle)/sizeof(char)); + if (getenv("HOME") == NULL) + { + /* + * If there is no HOME environment variable, + * try the concatenation of HOMEDRIVE + HOMEPATH. + */ + char *drive = getenv("HOMEDRIVE"); + char *path = getenv("HOMEPATH"); + if (drive != NULL && path != NULL) + { + char *env = (char *) ecalloc(strlen(drive) + + strlen(path) + 6, sizeof(char)); + strcpy(env, "HOME="); + strcat(env, drive); + strcat(env, path); + putenv(env); + } + } + GetConsoleTitle(consoleTitle, sizeof(consoleTitle)/sizeof(char)); #endif /* WIN32 */ - /* - * Process command line arguments and LESS environment arguments. - * Command line arguments override environment arguments. - */ - is_tty = isatty(1); - init_mark(); - init_cmds(); - get_term(); - init_charset(); - init_line(); - init_cmdhist(); - init_option(); - init_search(); - - /* - * If the name of the executable program is "more", - * act like LESS_IS_MORE is set. - */ - s = last_component(progname); - if (strcmp(s, "more") == 0) - less_is_more = 1; - - init_prompt(); - - s = lgetenv(less_is_more ? "MORE" : "LESS"); - if (s != NULL) - scan_option(save(s)); + /* + * Process command line arguments and LESS environment arguments. + * Command line arguments override environment arguments. + */ + is_tty = isatty(1); + init_mark(); + init_cmds(); + get_term(); + init_charset(); + init_line(); + init_cmdhist(); + init_option(); + init_search(); + + /* + * If the name of the executable program is "more", + * act like LESS_IS_MORE is set. + */ + s = last_component(progname); + if (strcmp(s, "more") == 0) + less_is_more = 1; + + init_prompt(); + + s = lgetenv(less_is_more ? "MORE" : "LESS"); + if (s != NULL) + scan_option(save(s)); #define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0') - while (argc > 0 && (isoptstring(*argv) || isoptpending())) - { - s = *argv++; - argc--; - if (strcmp(s, "--") == 0) - break; - scan_option(s); - } + while (argc > 0 && (isoptstring(*argv) || isoptpending())) + { + s = *argv++; + argc--; + if (strcmp(s, "--") == 0) + break; + scan_option(s); + } #undef isoptstring - if (isoptpending()) - { - /* - * Last command line option was a flag requiring a - * following string, but there was no following string. - */ - nopendopt(); - quit(QUIT_OK); - } + if (isoptpending()) + { + /* + * Last command line option was a flag requiring a + * following string, but there was no following string. + */ + nopendopt(); + quit(QUIT_OK); + } - expand_cmd_tables(); + expand_cmd_tables(); #if EDITOR - editor = lgetenv("VISUAL"); - if (editor == NULL || *editor == '\0') - { - editor = lgetenv("EDITOR"); - if (isnullenv(editor)) - editor = EDIT_PGM; - } - editproto = lgetenv("LESSEDIT"); - if (isnullenv(editproto)) - editproto = "%E ?lm+%lm. %g"; + editor = lgetenv("VISUAL"); + if (editor == NULL || *editor == '\0') + { + editor = lgetenv("EDITOR"); + if (isnullenv(editor)) + editor = EDIT_PGM; + } + editproto = lgetenv("LESSEDIT"); + if (isnullenv(editproto)) + editproto = "%E ?lm+%lm. %g"; #endif - /* - * Call get_ifile with all the command line filenames - * to "register" them with the ifile system. - */ - ifile = NULL_IFILE; - if (dohelp) - ifile = get_ifile(FAKE_HELPFILE, ifile); - while (argc-- > 0) - { + /* + * Call get_ifile with all the command line filenames + * to "register" them with the ifile system. + */ + ifile = NULL_IFILE; + if (dohelp) + ifile = get_ifile(FAKE_HELPFILE, ifile); + while (argc-- > 0) + { #if (MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC) - /* - * Because the "shell" doesn't expand filename patterns, - * treat each argument as a filename pattern rather than - * a single filename. - * Expand the pattern and iterate over the expanded list. - */ - struct textlist tlist; - char *filename; - char *gfilename; - char *qfilename; - - gfilename = lglob(*argv++); - init_textlist(&tlist, gfilename); - filename = NULL; - while ((filename = forw_textlist(&tlist, filename)) != NULL) - { - qfilename = shell_unquote(filename); - (void) get_ifile(qfilename, ifile); - free(qfilename); - ifile = prev_ifile(NULL_IFILE); - } - free(gfilename); + /* + * Because the "shell" doesn't expand filename patterns, + * treat each argument as a filename pattern rather than + * a single filename. + * Expand the pattern and iterate over the expanded list. + */ + struct textlist tlist; + char *filename; + char *gfilename; + char *qfilename; + + gfilename = lglob(*argv++); + init_textlist(&tlist, gfilename); + filename = NULL; + while ((filename = forw_textlist(&tlist, filename)) != NULL) + { + qfilename = shell_unquote(filename); + (void) get_ifile(qfilename, ifile); + free(qfilename); + ifile = prev_ifile(NULL_IFILE); + } + free(gfilename); #else - (void) get_ifile(*argv++, ifile); - ifile = prev_ifile(NULL_IFILE); + (void) get_ifile(*argv++, ifile); + ifile = prev_ifile(NULL_IFILE); #endif - } - /* - * Set up terminal, etc. - */ - if (!is_tty) - { - /* - * Output is not a tty. - * Just copy the input file(s) to output. - */ - set_output(1); /* write to stdout */ - SET_BINARY(1); - if (edit_first() == 0) - { - do { - cat_file(); - } while (edit_next(1) == 0); - } - quit(QUIT_OK); - } - - if (missing_cap && !know_dumb) - error("WARNING: terminal is not fully functional", NULL_PARG); - open_getchr(); - raw_mode(1); - init_signals(1); - - /* - * Select the first file to examine. - */ + } + /* + * Set up terminal, etc. + */ + if (!is_tty) + { + /* + * Output is not a tty. + * Just copy the input file(s) to output. + */ + set_output(1); /* write to stdout */ + SET_BINARY(1); + if (edit_first() == 0) + { + do { + cat_file(); + } while (edit_next(1) == 0); + } + quit(QUIT_OK); + } + + if (missing_cap && !know_dumb) + error("WARNING: terminal is not fully functional", NULL_PARG); + open_getchr(); + raw_mode(1); + init_signals(1); + + /* + * Select the first file to examine. + */ #if TAGS - if (tagoption != NULL || strcmp(tags, "-") == 0) - { - /* - * A -t option was given. - * Verify that no filenames were also given. - * Edit the file selected by the "tags" search, - * and search for the proper line in the file. - */ - if (nifile() > 0) - { - error("No filenames allowed with -t option", NULL_PARG); - quit(QUIT_ERROR); - } - findtag(tagoption); - if (edit_tagfile()) /* Edit file which contains the tag */ - quit(QUIT_ERROR); - /* - * Search for the line which contains the tag. - * Set up initial_scrpos so we display that line. - */ - initial_scrpos.pos = tagsearch(); - if (initial_scrpos.pos == NULL_POSITION) - quit(QUIT_ERROR); - initial_scrpos.ln = jump_sline; - } else + if (tagoption != NULL || strcmp(tags, "-") == 0) + { + /* + * A -t option was given. + * Verify that no filenames were also given. + * Edit the file selected by the "tags" search, + * and search for the proper line in the file. + */ + if (nifile() > 0) + { + error("No filenames allowed with -t option", NULL_PARG); + quit(QUIT_ERROR); + } + findtag(tagoption); + if (edit_tagfile()) /* Edit file which contains the tag */ + quit(QUIT_ERROR); + /* + * Search for the line which contains the tag. + * Set up initial_scrpos so we display that line. + */ + initial_scrpos.pos = tagsearch(); + if (initial_scrpos.pos == NULL_POSITION) + quit(QUIT_ERROR); + initial_scrpos.ln = jump_sline; + } else #endif - { - if (edit_first()) - quit(QUIT_ERROR); - /* - * See if file fits on one screen to decide whether - * to send terminal init. But don't need this - * if -X (no_init) overrides this (see init()). - */ - if (quit_if_one_screen) - { - if (nifile() > 1) /* If more than one file, -F cannot be used */ - quit_if_one_screen = FALSE; - else if (!no_init) - one_screen = get_one_screen(); - } - } - - if (errmsgs > 0) - { - /* - * We displayed some messages on error output - * (file descriptor 2; see flush()). - * Before erasing the screen contents, wait for a keystroke. - */ - less_printf("Press RETURN to continue ", NULL_PARG); - get_return(); - putchr('\n'); - } - set_output(1); - init(); - commands(); - quit(QUIT_OK); - /*NOTREACHED*/ - return (0); + { + if (edit_first()) + quit(QUIT_ERROR); + /* + * See if file fits on one screen to decide whether + * to send terminal init. But don't need this + * if -X (no_init) overrides this (see init()). + */ + if (quit_if_one_screen) + { + if (nifile() > 1) /* If more than one file, -F cannot be used */ + quit_if_one_screen = FALSE; + else if (!no_init) + one_screen = get_one_screen(); + } + } + + if (errmsgs > 0) + { + /* + * We displayed some messages on error output + * (file descriptor 2; see flush()). + * Before erasing the screen contents, wait for a keystroke. + */ + less_printf("Press RETURN to continue ", NULL_PARG); + get_return(); + putchr('\n'); + } + set_output(1); + init(); + commands(); + quit(QUIT_OK); + /*NOTREACHED*/ + return (0); } /* * Copy a string to a "safe" place * (that is, to a buffer allocated by calloc). */ - public char * + public char * save(s) - constant char *s; + constant char *s; { - char *p; + char *p; - p = (char *) ecalloc(strlen(s)+1, sizeof(char)); - strcpy(p, s); - return (p); + p = (char *) ecalloc(strlen(s)+1, sizeof(char)); + strcpy(p, s); + return (p); } /* * Allocate memory. * Like calloc(), but never returns an error (NULL). */ - public VOID_POINTER + public VOID_POINTER ecalloc(count, size) - int count; - unsigned int size; + int count; + unsigned int size; { - VOID_POINTER p; - - p = (VOID_POINTER) calloc(count, size); - if (p != NULL) - return (p); - error("Cannot allocate memory", NULL_PARG); - quit(QUIT_ERROR); - /*NOTREACHED*/ - return (NULL); + VOID_POINTER p; + + p = (VOID_POINTER) calloc(count, size); + if (p != NULL) + return (p); + error("Cannot allocate memory", NULL_PARG); + quit(QUIT_ERROR); + /*NOTREACHED*/ + return (NULL); } /* * Skip leading spaces in a string. */ - public char * + public char * skipsp(s) - char *s; + char *s; { - while (*s == ' ' || *s == '\t') - s++; - return (s); + while (*s == ' ' || *s == '\t') + s++; + return (s); } /* @@ -358,76 +358,76 @@ skipsp(s) * If uppercase is true, the first string must begin with an uppercase * character; the remainder of the first string may be either case. */ - public int + public int sprefix(ps, s, uppercase) - char *ps; - char *s; - int uppercase; + char *ps; + char *s; + int uppercase; { - int c; - int sc; - int len = 0; - - for ( ; *s != '\0'; s++, ps++) - { - c = *ps; - if (uppercase) - { - if (len == 0 && ASCII_IS_LOWER(c)) - return (-1); - if (ASCII_IS_UPPER(c)) - c = ASCII_TO_LOWER(c); - } - sc = *s; - if (len > 0 && ASCII_IS_UPPER(sc)) - sc = ASCII_TO_LOWER(sc); - if (c != sc) - break; - len++; - } - return (len); + int c; + int sc; + int len = 0; + + for ( ; *s != '\0'; s++, ps++) + { + c = *ps; + if (uppercase) + { + if (len == 0 && ASCII_IS_LOWER(c)) + return (-1); + if (ASCII_IS_UPPER(c)) + c = ASCII_TO_LOWER(c); + } + sc = *s; + if (len > 0 && ASCII_IS_UPPER(sc)) + sc = ASCII_TO_LOWER(sc); + if (c != sc) + break; + len++; + } + return (len); } /* * Exit the program. */ - public void + public void quit(status) - int status; + int status; { - static int save_status; - - /* - * Put cursor at bottom left corner, clear the line, - * reset the terminal modes, and exit. - */ - if (status < 0) - status = save_status; - else - save_status = status; + static int save_status; + + /* + * Put cursor at bottom left corner, clear the line, + * reset the terminal modes, and exit. + */ + if (status < 0) + status = save_status; + else + save_status = status; #if LESSTEST - rstat('Q'); + rstat('Q'); #endif /*LESSTEST*/ - quitting = 1; - edit((char*)NULL); - save_cmdhist(); - if (interactive()) - clear_bot(); - deinit(); - flush(); - raw_mode(0); + quitting = 1; + edit((char*)NULL); + save_cmdhist(); + if (interactive()) + clear_bot(); + deinit(); + flush(); + raw_mode(0); #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC - /* - * If we don't close 2, we get some garbage from - * 2's buffer when it flushes automatically. - * I cannot track this one down RB - * The same bug shows up if we use ^C^C to abort. - */ - close(2); + /* + * If we don't close 2, we get some garbage from + * 2's buffer when it flushes automatically. + * I cannot track this one down RB + * The same bug shows up if we use ^C^C to abort. + */ + close(2); #endif #ifdef WIN32 - SetConsoleTitle(consoleTitle); + SetConsoleTitle(consoleTitle); #endif - close_getchr(); - exit(status); + close_getchr(); + exit(status); } diff --git a/mark.c b/mark.c index cbb316f..0080a4d 100644 --- a/mark.c +++ b/mark.c @@ -19,18 +19,18 @@ extern int perma_marks; /* * A mark is an ifile (input file) plus a position within the file. */ -struct mark +struct mark { - /* - * Normally m_ifile != IFILE_NULL and m_filename == NULL. - * For restored marks we set m_filename instead of m_ifile - * because we don't want to create an ifile until the - * user explicitly requests the file (by name or mark). - */ - char m_letter; /* Associated character */ - IFILE m_ifile; /* Input file being marked */ - char *m_filename; /* Name of the input file */ - struct scrpos m_scrpos; /* Position of the mark */ + /* + * Normally m_ifile != IFILE_NULL and m_filename == NULL. + * For restored marks we set m_filename instead of m_ifile + * because we don't want to create an ifile until the + * user explicitly requests the file (by name or mark). + */ + char m_letter; /* Associated character */ + IFILE m_ifile; /* Input file being marked */ + char *m_filename; /* Name of the input file */ + struct scrpos m_scrpos; /* Position of the mark */ }; /* @@ -49,85 +49,85 @@ public int marks_modified = 0; /* * Initialize a mark struct. */ - static void + static void cmark(m, ifile, pos, ln) - struct mark *m; - IFILE ifile; - POSITION pos; - int ln; + struct mark *m; + IFILE ifile; + POSITION pos; + int ln; { - m->m_ifile = ifile; - m->m_scrpos.pos = pos; - m->m_scrpos.ln = ln; - m->m_filename = NULL; + m->m_ifile = ifile; + m->m_scrpos.pos = pos; + m->m_scrpos.ln = ln; + m->m_filename = NULL; } /* * Initialize the mark table to show no marks are set. */ - public void + public void init_mark(VOID_PARAM) { - int i; - - for (i = 0; i < NMARKS; i++) - { - char letter; - switch (i) { - case MOUSEMARK: letter = '#'; break; - case LASTMARK: letter = '\''; break; - default: letter = (i < 26) ? 'a'+i : 'A'+i-26; break; - } - marks[i].m_letter = letter; - cmark(&marks[i], NULL_IFILE, NULL_POSITION, -1); - } + int i; + + for (i = 0; i < NMARKS; i++) + { + char letter; + switch (i) { + case MOUSEMARK: letter = '#'; break; + case LASTMARK: letter = '\''; break; + default: letter = (i < 26) ? 'a'+i : 'A'+i-26; break; + } + marks[i].m_letter = letter; + cmark(&marks[i], NULL_IFILE, NULL_POSITION, -1); + } } /* * Set m_ifile and clear m_filename. */ - static void + static void mark_set_ifile(m, ifile) - struct mark *m; - IFILE ifile; + struct mark *m; + IFILE ifile; { - m->m_ifile = ifile; - /* With m_ifile set, m_filename is no longer needed. */ - free(m->m_filename); - m->m_filename = NULL; + m->m_ifile = ifile; + /* With m_ifile set, m_filename is no longer needed. */ + free(m->m_filename); + m->m_filename = NULL; } /* * Populate the m_ifile member of a mark struct from m_filename. */ - static void + static void mark_get_ifile(m) - struct mark *m; + struct mark *m; { - if (m->m_ifile != NULL_IFILE) - return; /* m_ifile is already set */ - mark_set_ifile(m, get_ifile(m->m_filename, prev_ifile(NULL_IFILE))); + if (m->m_ifile != NULL_IFILE) + return; /* m_ifile is already set */ + mark_set_ifile(m, get_ifile(m->m_filename, prev_ifile(NULL_IFILE))); } /* * Return the user mark struct identified by a character. */ - static struct mark * + static struct mark * getumark(c) - int c; + int c; { - PARG parg; - if (c >= 'a' && c <= 'z') - return (&marks[c-'a']); - if (c >= 'A' && c <= 'Z') - return (&marks[c-'A'+26]); - if (c == '\'') - return (&marks[LASTMARK]); - if (c == '#') - return (&marks[MOUSEMARK]); - parg.p_char = (char) c; - error("Invalid mark letter %c", &parg); - return (NULL); + PARG parg; + if (c >= 'a' && c <= 'z') + return (&marks[c-'a']); + if (c >= 'A' && c <= 'Z') + return (&marks[c-'A'+26]); + if (c == '\'') + return (&marks[LASTMARK]); + if (c == '#') + return (&marks[MOUSEMARK]); + parg.p_char = (char) c; + error("Invalid mark letter %c", &parg); + return (NULL); } /* @@ -135,260 +135,260 @@ getumark(c) * The mark struct may either be in the mark table (user mark) * or may be constructed on the fly for certain characters like ^, $. */ - static struct mark * + static struct mark * getmark(c) - int c; + int c; { - struct mark *m; - static struct mark sm; - - switch (c) - { - case '^': - /* - * Beginning of the current file. - */ - m = &sm; - cmark(m, curr_ifile, ch_zero(), 0); - break; - case '$': - /* - * End of the current file. - */ - if (ch_end_seek()) - { - error("Cannot seek to end of file", NULL_PARG); - return (NULL); - } - m = &sm; - cmark(m, curr_ifile, ch_tell(), sc_height); - break; - case '.': - /* - * Current position in the current file. - */ - m = &sm; - get_scrpos(&m->m_scrpos, TOP); - cmark(m, curr_ifile, m->m_scrpos.pos, m->m_scrpos.ln); - break; - case '\'': - /* - * The "last mark". - */ - m = &marks[LASTMARK]; - break; - default: - /* - * Must be a user-defined mark. - */ - m = getumark(c); - if (m == NULL) - break; - if (m->m_scrpos.pos == NULL_POSITION) - { - error("Mark not set", NULL_PARG); - return (NULL); - } - break; - } - return (m); + struct mark *m; + static struct mark sm; + + switch (c) + { + case '^': + /* + * Beginning of the current file. + */ + m = &sm; + cmark(m, curr_ifile, ch_zero(), 0); + break; + case '$': + /* + * End of the current file. + */ + if (ch_end_seek()) + { + error("Cannot seek to end of file", NULL_PARG); + return (NULL); + } + m = &sm; + cmark(m, curr_ifile, ch_tell(), sc_height); + break; + case '.': + /* + * Current position in the current file. + */ + m = &sm; + get_scrpos(&m->m_scrpos, TOP); + cmark(m, curr_ifile, m->m_scrpos.pos, m->m_scrpos.ln); + break; + case '\'': + /* + * The "last mark". + */ + m = &marks[LASTMARK]; + break; + default: + /* + * Must be a user-defined mark. + */ + m = getumark(c); + if (m == NULL) + break; + if (m->m_scrpos.pos == NULL_POSITION) + { + error("Mark not set", NULL_PARG); + return (NULL); + } + break; + } + return (m); } /* * Is a mark letter invalid? */ - public int + public int badmark(c) - int c; + int c; { - return (getmark(c) == NULL); + return (getmark(c) == NULL); } /* * Set a user-defined mark. */ - public void + public void setmark(c, where) - int c; - int where; + int c; + int where; { - struct mark *m; - struct scrpos scrpos; - - m = getumark(c); - if (m == NULL) - return; - get_scrpos(&scrpos, where); - if (scrpos.pos == NULL_POSITION) - { - bell(); - return; - } - cmark(m, curr_ifile, scrpos.pos, scrpos.ln); - marks_modified = 1; + struct mark *m; + struct scrpos scrpos; + + m = getumark(c); + if (m == NULL) + return; + get_scrpos(&scrpos, where); + if (scrpos.pos == NULL_POSITION) + { + bell(); + return; + } + cmark(m, curr_ifile, scrpos.pos, scrpos.ln); + marks_modified = 1; } /* * Clear a user-defined mark. */ - public void + public void clrmark(c) - int c; + int c; { - struct mark *m; - - m = getumark(c); - if (m == NULL) - return; - if (m->m_scrpos.pos == NULL_POSITION) - { - bell(); - return; - } - m->m_scrpos.pos = NULL_POSITION; - marks_modified = 1; + struct mark *m; + + m = getumark(c); + if (m == NULL) + return; + if (m->m_scrpos.pos == NULL_POSITION) + { + bell(); + return; + } + m->m_scrpos.pos = NULL_POSITION; + marks_modified = 1; } /* * Set lmark (the mark named by the apostrophe). */ - public void + public void lastmark(VOID_PARAM) { - struct scrpos scrpos; - - if (ch_getflags() & CH_HELPFILE) - return; - get_scrpos(&scrpos, TOP); - if (scrpos.pos == NULL_POSITION) - return; - cmark(&marks[LASTMARK], curr_ifile, scrpos.pos, scrpos.ln); - marks_modified = 1; + struct scrpos scrpos; + + if (ch_getflags() & CH_HELPFILE) + return; + get_scrpos(&scrpos, TOP); + if (scrpos.pos == NULL_POSITION) + return; + cmark(&marks[LASTMARK], curr_ifile, scrpos.pos, scrpos.ln); + marks_modified = 1; } /* * Go to a mark. */ - public void + public void gomark(c) - int c; + int c; { - struct mark *m; - struct scrpos scrpos; - - m = getmark(c); - if (m == NULL) - return; - - /* - * If we're trying to go to the lastmark and - * it has not been set to anything yet, - * set it to the beginning of the current file. - * {{ Couldn't we instead set marks[LASTMARK] in edit()? }} - */ - if (m == &marks[LASTMARK] && m->m_scrpos.pos == NULL_POSITION) - cmark(m, curr_ifile, ch_zero(), jump_sline); - - mark_get_ifile(m); - - /* Save scrpos; if it's LASTMARK it could change in edit_ifile. */ - scrpos = m->m_scrpos; - if (m->m_ifile != curr_ifile) - { - /* - * Not in the current file; edit the correct file. - */ - if (edit_ifile(m->m_ifile)) - return; - } - - jump_loc(scrpos.pos, scrpos.ln); + struct mark *m; + struct scrpos scrpos; + + m = getmark(c); + if (m == NULL) + return; + + /* + * If we're trying to go to the lastmark and + * it has not been set to anything yet, + * set it to the beginning of the current file. + * {{ Couldn't we instead set marks[LASTMARK] in edit()? }} + */ + if (m == &marks[LASTMARK] && m->m_scrpos.pos == NULL_POSITION) + cmark(m, curr_ifile, ch_zero(), jump_sline); + + mark_get_ifile(m); + + /* Save scrpos; if it's LASTMARK it could change in edit_ifile. */ + scrpos = m->m_scrpos; + if (m->m_ifile != curr_ifile) + { + /* + * Not in the current file; edit the correct file. + */ + if (edit_ifile(m->m_ifile)) + return; + } + + jump_loc(scrpos.pos, scrpos.ln); } /* * Return the position associated with a given mark letter. * - * We don't return which screen line the position + * We don't return which screen line the position * is associated with, but this doesn't matter much, * because it's always the first non-blank line on the screen. */ - public POSITION + public POSITION markpos(c) - int c; + int c; { - struct mark *m; - - m = getmark(c); - if (m == NULL) - return (NULL_POSITION); - - if (m->m_ifile != curr_ifile) - { - error("Mark not in current file", NULL_PARG); - return (NULL_POSITION); - } - return (m->m_scrpos.pos); + struct mark *m; + + m = getmark(c); + if (m == NULL) + return (NULL_POSITION); + + if (m->m_ifile != curr_ifile) + { + error("Mark not in current file", NULL_PARG); + return (NULL_POSITION); + } + return (m->m_scrpos.pos); } /* * Return the mark associated with a given position, if any. */ - public char + public char posmark(pos) - POSITION pos; + POSITION pos; { - int i; - - /* Only user marks */ - for (i = 0; i < NUMARKS; i++) - { - if (marks[i].m_ifile == curr_ifile && marks[i].m_scrpos.pos == pos) - { - if (i < 26) return 'a' + i; - if (i < 26*2) return 'A' + (i - 26); - return '#'; - } - } - return 0; + int i; + + /* Only user marks */ + for (i = 0; i < NUMARKS; i++) + { + if (marks[i].m_ifile == curr_ifile && marks[i].m_scrpos.pos == pos) + { + if (i < 26) return 'a' + i; + if (i < 26*2) return 'A' + (i - 26); + return '#'; + } + } + return 0; } /* * Clear the marks associated with a specified ifile. */ - public void + public void unmark(ifile) - IFILE ifile; + IFILE ifile; { - int i; + int i; - for (i = 0; i < NMARKS; i++) - if (marks[i].m_ifile == ifile) - marks[i].m_scrpos.pos = NULL_POSITION; + for (i = 0; i < NMARKS; i++) + if (marks[i].m_ifile == ifile) + marks[i].m_scrpos.pos = NULL_POSITION; } /* * Check if any marks refer to a specified ifile vi m_filename * rather than m_ifile. */ - public void + public void mark_check_ifile(ifile) - IFILE ifile; + IFILE ifile; { - int i; - char *filename = get_real_filename(ifile); - - for (i = 0; i < NMARKS; i++) - { - struct mark *m = &marks[i]; - char *mark_filename = m->m_filename; - if (mark_filename != NULL) - { - mark_filename = lrealpath(mark_filename); - if (strcmp(filename, mark_filename) == 0) - mark_set_ifile(m, ifile); - free(mark_filename); - } - } + int i; + char *filename = get_real_filename(ifile); + + for (i = 0; i < NMARKS; i++) + { + struct mark *m = &marks[i]; + char *mark_filename = m->m_filename; + if (mark_filename != NULL) + { + mark_filename = lrealpath(mark_filename); + if (strcmp(filename, mark_filename) == 0) + mark_set_ifile(m, ifile); + free(mark_filename); + } + } } #if CMD_HISTORY @@ -396,63 +396,63 @@ mark_check_ifile(ifile) /* * Save marks to history file. */ - public void + public void save_marks(fout, hdr) - FILE *fout; - char *hdr; + FILE *fout; + char *hdr; { - int i; - - if (!perma_marks) - return; - - fprintf(fout, "%s\n", hdr); - for (i = 0; i < NMARKS; i++) - { - char *filename; - struct mark *m = &marks[i]; - char pos_str[INT_STRLEN_BOUND(m->m_scrpos.pos) + 2]; - if (m->m_scrpos.pos == NULL_POSITION) - continue; - postoa(m->m_scrpos.pos, pos_str); - filename = m->m_filename; - if (filename == NULL) - filename = get_real_filename(m->m_ifile); - if (strcmp(filename, "-") != 0) - fprintf(fout, "m %c %d %s %s\n", - m->m_letter, m->m_scrpos.ln, pos_str, filename); - } + int i; + + if (!perma_marks) + return; + + fprintf(fout, "%s\n", hdr); + for (i = 0; i < NMARKS; i++) + { + char *filename; + struct mark *m = &marks[i]; + char pos_str[INT_STRLEN_BOUND(m->m_scrpos.pos) + 2]; + if (m->m_scrpos.pos == NULL_POSITION) + continue; + postoa(m->m_scrpos.pos, pos_str); + filename = m->m_filename; + if (filename == NULL) + filename = get_real_filename(m->m_ifile); + if (strcmp(filename, "-") != 0) + fprintf(fout, "m %c %d %s %s\n", + m->m_letter, m->m_scrpos.ln, pos_str, filename); + } } /* * Restore one mark from the history file. */ - public void + public void restore_mark(line) - char *line; + char *line; { - struct mark *m; - int ln; - POSITION pos; + struct mark *m; + int ln; + POSITION pos; #define skip_whitespace while (*line == ' ') line++ - if (*line++ != 'm') - return; - skip_whitespace; - m = getumark(*line++); - if (m == NULL) - return; - skip_whitespace; - ln = lstrtoi(line, &line); - if (ln < 1) - ln = 1; - if (ln > sc_height) - ln = sc_height; - skip_whitespace; - pos = lstrtopos(line, &line); - skip_whitespace; - cmark(m, NULL_IFILE, pos, ln); - m->m_filename = save(line); + if (*line++ != 'm') + return; + skip_whitespace; + m = getumark(*line++); + if (m == NULL) + return; + skip_whitespace; + ln = lstrtoi(line, &line); + if (ln < 1) + ln = 1; + if (ln > sc_height) + ln = sc_height; + skip_whitespace; + pos = lstrtopos(line, &line); + skip_whitespace; + cmark(m, NULL_IFILE, pos, ln); + m->m_filename = save(line); } #endif /* CMD_HISTORY */ diff --git a/mkfuncs.pl b/mkfuncs.pl index 3541733..2d3e95d 100644 --- a/mkfuncs.pl +++ b/mkfuncs.pl @@ -6,22 +6,22 @@ my $params; while (<>) { - if (/^\tpublic\s+(.*)/) { - $def = "public $1"; - $state = 1; - $params = 0; - } elsif ($state == 1 and /(\w+)\s*\(/) { - $def .= " $1 LESSPARAMS (("; - $state = 2; - } elsif ($state == 2) { - if (/^{/) { - $def .= 'VOID_PARAM' if not $params; - print "$def));\n"; - $state = 0; - } elsif (/^\s*([^;]*)/) { - $def .= ', ' if substr($def,-1) ne '('; - $def .= $1; - $params = 1; - } - } + if (/^\tpublic\s+(.*)/) { + $def = "public $1"; + $state = 1; + $params = 0; + } elsif ($state == 1 and /(\w+)\s*\(/) { + $def .= " $1 LESSPARAMS (("; + $state = 2; + } elsif ($state == 2) { + if (/^{/) { + $def .= 'VOID_PARAM' if not $params; + print "$def));\n"; + $state = 0; + } elsif (/^\s*([^;]*)/) { + $def .= ', ' if substr($def,-1) ne '('; + $def .= $1; + $params = 1; + } + } } diff --git a/mkfuncs.py b/mkfuncs.py index 7a2da5a..0674d98 100644 --- a/mkfuncs.py +++ b/mkfuncs.py @@ -21,6 +21,6 @@ print(f'{definition}));') state = 0 elif test := re.search(r'^\s*([^;]*)', line): - if (definition[-1:] != '('): definition += ', ' - definition += test.group(1) + if (definition[-1:] != '('): definition += ', ' + definition += test.group(1) params = 1 diff --git a/mkhelp.pl b/mkhelp.pl index a826e20..ec3f51f 100644 --- a/mkhelp.pl +++ b/mkhelp.pl @@ -3,7 +3,7 @@ # Silly little program to generate the help.c source file # from the less.hlp text file. -# The output of this script is a C program defining a char array +# The output of this script is a C program defining a char array # whose content is the input to this script. { diff --git a/mkinstalldirs b/mkinstalldirs index 91f6d04..5b6d1ba 100644 --- a/mkinstalldirs +++ b/mkinstalldirs @@ -7,7 +7,7 @@ errstatus=0 -for file in ${1+"$@"} ; do +for file in ${1+"$@"} ; do set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` shift diff --git a/optfunc.c b/optfunc.c index 768fe0e..5cb0250 100644 --- a/optfunc.c +++ b/optfunc.c @@ -91,216 +91,216 @@ extern int sgr_mode; /* * Handler for -o option. */ - public void + public void opt_o(type, s) - int type; - char *s; + int type; + char *s; { - PARG parg; - char *filename; - - if (secure) - { - error("log file support is not available", NULL_PARG); - return; - } - switch (type) - { - case INIT: - namelogfile = save(s); - break; - case TOGGLE: - if (ch_getflags() & CH_CANSEEK) - { - error("Input is not a pipe", NULL_PARG); - return; - } - if (logfile >= 0) - { - error("Log file is already in use", NULL_PARG); - return; - } - s = skipsp(s); - if (namelogfile != NULL) - free(namelogfile); - filename = lglob(s); - namelogfile = shell_unquote(filename); - free(filename); - use_logfile(namelogfile); - sync_logfile(); - break; - case QUERY: - if (logfile < 0) - error("No log file", NULL_PARG); - else - { - parg.p_string = namelogfile; - error("Log file \"%s\"", &parg); - } - break; - } + PARG parg; + char *filename; + + if (secure) + { + error("log file support is not available", NULL_PARG); + return; + } + switch (type) + { + case INIT: + namelogfile = save(s); + break; + case TOGGLE: + if (ch_getflags() & CH_CANSEEK) + { + error("Input is not a pipe", NULL_PARG); + return; + } + if (logfile >= 0) + { + error("Log file is already in use", NULL_PARG); + return; + } + s = skipsp(s); + if (namelogfile != NULL) + free(namelogfile); + filename = lglob(s); + namelogfile = shell_unquote(filename); + free(filename); + use_logfile(namelogfile); + sync_logfile(); + break; + case QUERY: + if (logfile < 0) + error("No log file", NULL_PARG); + else + { + parg.p_string = namelogfile; + error("Log file \"%s\"", &parg); + } + break; + } } /* * Handler for -O option. */ - public void + public void opt__O(type, s) - int type; - char *s; + int type; + char *s; { - force_logfile = TRUE; - opt_o(type, s); + force_logfile = TRUE; + opt_o(type, s); } #endif /* * Handlers for -j option. */ - public void + public void opt_j(type, s) - int type; - char *s; + int type; + char *s; { - PARG parg; - char buf[16]; - int len; - int err; - - switch (type) - { - case INIT: - case TOGGLE: - if (*s == '.') - { - s++; - jump_sline_fraction = getfraction(&s, "j", &err); - if (err) - error("Invalid line fraction", NULL_PARG); - else - calc_jump_sline(); - } else - { - int sline = getnum(&s, "j", &err); - if (err) - error("Invalid line number", NULL_PARG); - else - { - jump_sline = sline; - jump_sline_fraction = -1; - } - } - break; - case QUERY: - if (jump_sline_fraction < 0) - { - parg.p_int = jump_sline; - error("Position target at screen line %d", &parg); - } else - { - - sprintf(buf, ".%06ld", jump_sline_fraction); - len = (int) strlen(buf); - while (len > 2 && buf[len-1] == '0') - len--; - buf[len] = '\0'; - parg.p_string = buf; - error("Position target at screen position %s", &parg); - } - break; - } + PARG parg; + char buf[16]; + int len; + int err; + + switch (type) + { + case INIT: + case TOGGLE: + if (*s == '.') + { + s++; + jump_sline_fraction = getfraction(&s, "j", &err); + if (err) + error("Invalid line fraction", NULL_PARG); + else + calc_jump_sline(); + } else + { + int sline = getnum(&s, "j", &err); + if (err) + error("Invalid line number", NULL_PARG); + else + { + jump_sline = sline; + jump_sline_fraction = -1; + } + } + break; + case QUERY: + if (jump_sline_fraction < 0) + { + parg.p_int = jump_sline; + error("Position target at screen line %d", &parg); + } else + { + + sprintf(buf, ".%06ld", jump_sline_fraction); + len = (int) strlen(buf); + while (len > 2 && buf[len-1] == '0') + len--; + buf[len] = '\0'; + parg.p_string = buf; + error("Position target at screen position %s", &parg); + } + break; + } } - public void + public void calc_jump_sline(VOID_PARAM) { - if (jump_sline_fraction < 0) - return; - jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM; + if (jump_sline_fraction < 0) + return; + jump_sline = sc_height * jump_sline_fraction / NUM_FRAC_DENOM; } /* * Handlers for -# option. */ - public void + public void opt_shift(type, s) - int type; - char *s; + int type; + char *s; { - PARG parg; - char buf[16]; - int len; - int err; - - switch (type) - { - case INIT: - case TOGGLE: - if (*s == '.') - { - s++; - shift_count_fraction = getfraction(&s, "#", &err); - if (err) - error("Invalid column fraction", NULL_PARG); - else - calc_shift_count(); - } else - { - int hs = getnum(&s, "#", &err); - if (err) - error("Invalid column number", NULL_PARG); - else - { - shift_count = hs; - shift_count_fraction = -1; - } - } - break; - case QUERY: - if (shift_count_fraction < 0) - { - parg.p_int = shift_count; - error("Horizontal shift %d columns", &parg); - } else - { - - sprintf(buf, ".%06ld", shift_count_fraction); - len = (int) strlen(buf); - while (len > 2 && buf[len-1] == '0') - len--; - buf[len] = '\0'; - parg.p_string = buf; - error("Horizontal shift %s of screen width", &parg); - } - break; - } + PARG parg; + char buf[16]; + int len; + int err; + + switch (type) + { + case INIT: + case TOGGLE: + if (*s == '.') + { + s++; + shift_count_fraction = getfraction(&s, "#", &err); + if (err) + error("Invalid column fraction", NULL_PARG); + else + calc_shift_count(); + } else + { + int hs = getnum(&s, "#", &err); + if (err) + error("Invalid column number", NULL_PARG); + else + { + shift_count = hs; + shift_count_fraction = -1; + } + } + break; + case QUERY: + if (shift_count_fraction < 0) + { + parg.p_int = shift_count; + error("Horizontal shift %d columns", &parg); + } else + { + + sprintf(buf, ".%06ld", shift_count_fraction); + len = (int) strlen(buf); + while (len > 2 && buf[len-1] == '0') + len--; + buf[len] = '\0'; + parg.p_string = buf; + error("Horizontal shift %s of screen width", &parg); + } + break; + } } - public void + public void calc_shift_count(VOID_PARAM) { - if (shift_count_fraction < 0) - return; - shift_count = sc_width * shift_count_fraction / NUM_FRAC_DENOM; + if (shift_count_fraction < 0) + return; + shift_count = sc_width * shift_count_fraction / NUM_FRAC_DENOM; } #if USERFILE - public void + public void opt_k(type, s) - int type; - char *s; + int type; + char *s; { - PARG parg; - - switch (type) - { - case INIT: - if (lesskey(s, 0)) - { - parg.p_string = s; - error("Cannot use lesskey file \"%s\"", &parg); - } - break; - } + PARG parg; + + switch (type) + { + case INIT: + if (lesskey(s, 0)) + { + parg.p_string = s; + error("Cannot use lesskey file \"%s\"", &parg); + } + break; + } } #endif @@ -308,689 +308,688 @@ opt_k(type, s) /* * Handler for -t option. */ - public void + public void opt_t(type, s) - int type; - char *s; + int type; + char *s; { - IFILE save_ifile; - POSITION pos; - - switch (type) - { - case INIT: - tagoption = save(s); - /* Do the rest in main() */ - break; - case TOGGLE: - if (secure) - { - error("tags support is not available", NULL_PARG); - break; - } - findtag(skipsp(s)); - save_ifile = save_curr_ifile(); - /* - * Try to open the file containing the tag - * and search for the tag in that file. - */ - if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION) - { - /* Failed: reopen the old file. */ - reedit_ifile(save_ifile); - break; - } - unsave_ifile(save_ifile); - jump_loc(pos, jump_sline); - break; - } + IFILE save_ifile; + POSITION pos; + + switch (type) + { + case INIT: + tagoption = save(s); + /* Do the rest in main() */ + break; + case TOGGLE: + if (secure) + { + error("tags support is not available", NULL_PARG); + break; + } + findtag(skipsp(s)); + save_ifile = save_curr_ifile(); + /* + * Try to open the file containing the tag + * and search for the tag in that file. + */ + if (edit_tagfile() || (pos = tagsearch()) == NULL_POSITION) + { + /* Failed: reopen the old file. */ + reedit_ifile(save_ifile); + break; + } + unsave_ifile(save_ifile); + jump_loc(pos, jump_sline); + break; + } } /* * Handler for -T option. */ - public void + public void opt__T(type, s) - int type; - char *s; + int type; + char *s; { - PARG parg; - char *filename; - - switch (type) - { - case INIT: - tags = save(s); - break; - case TOGGLE: - s = skipsp(s); - if (tags != NULL && tags != ztags) - free(tags); - filename = lglob(s); - tags = shell_unquote(filename); - free(filename); - break; - case QUERY: - parg.p_string = tags; - error("Tags file \"%s\"", &parg); - break; - } + PARG parg; + char *filename; + + switch (type) + { + case INIT: + tags = save(s); + break; + case TOGGLE: + s = skipsp(s); + if (tags != NULL && tags != ztags) + free(tags); + filename = lglob(s); + tags = shell_unquote(filename); + free(filename); + break; + case QUERY: + parg.p_string = tags; + error("Tags file \"%s\"", &parg); + break; + } } #endif /* * Handler for -p option. */ - public void + public void opt_p(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case INIT: - /* - * Unget a command for the specified string. - */ - if (less_is_more) - { - /* - * In "more" mode, the -p argument is a command, - * not a search string, so we don't need a slash. - */ - every_first_cmd = save(s); - } else - { - plusoption = TRUE; - /* - * {{ This won't work if the "/" command is - * changed or invalidated by a .lesskey file. }} - */ - ungetsc("/"); - ungetsc(s); - ungetcc_back(CHAR_END_COMMAND); - } - break; - } + switch (type) + { + case INIT: + /* + * Unget a command for the specified string. + */ + if (less_is_more) + { + /* + * In "more" mode, the -p argument is a command, + * not a search string, so we don't need a slash. + */ + every_first_cmd = save(s); + } else + { + plusoption = TRUE; + /* + * {{ This won't work if the "/" command is + * changed or invalidated by a .lesskey file. }} + */ + ungetsc("/"); + ungetsc(s); + ungetcc_back(CHAR_END_COMMAND); + } + break; + } } /* * Handler for -P option. */ - public void + public void opt__P(type, s) - int type; - char *s; + int type; + char *s; { - char **proto; - PARG parg; - - switch (type) - { - case INIT: - case TOGGLE: - /* - * Figure out which prototype string should be changed. - */ - switch (*s) - { - case 's': proto = &prproto[PR_SHORT]; s++; break; - case 'm': proto = &prproto[PR_MEDIUM]; s++; break; - case 'M': proto = &prproto[PR_LONG]; s++; break; - case '=': proto = &eqproto; s++; break; - case 'h': proto = &hproto; s++; break; - case 'w': proto = &wproto; s++; break; - default: proto = &prproto[PR_SHORT]; break; - } - free(*proto); - *proto = save(s); - break; - case QUERY: - parg.p_string = prproto[pr_type]; - error("%s", &parg); - break; - } + char **proto; + PARG parg; + + switch (type) + { + case INIT: + case TOGGLE: + /* + * Figure out which prototype string should be changed. + */ + switch (*s) + { + case 's': proto = &prproto[PR_SHORT]; s++; break; + case 'm': proto = &prproto[PR_MEDIUM]; s++; break; + case 'M': proto = &prproto[PR_LONG]; s++; break; + case '=': proto = &eqproto; s++; break; + case 'h': proto = &hproto; s++; break; + case 'w': proto = &wproto; s++; break; + default: proto = &prproto[PR_SHORT]; break; + } + free(*proto); + *proto = save(s); + break; + case QUERY: + parg.p_string = prproto[pr_type]; + error("%s", &parg); + break; + } } /* * Handler for the -b option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_b(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case INIT: - case TOGGLE: - /* - * Set the new number of buffers. - */ - ch_setbufspace(bufspace); - break; - case QUERY: - break; - } + switch (type) + { + case INIT: + case TOGGLE: + /* + * Set the new number of buffers. + */ + ch_setbufspace(bufspace); + break; + case QUERY: + break; + } } /* * Handler for the -i option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_i(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case TOGGLE: - chg_caseless(); - break; - case QUERY: - case INIT: - break; - } + switch (type) + { + case TOGGLE: + chg_caseless(); + break; + case QUERY: + case INIT: + break; + } } /* * Handler for the -V option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt__V(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case TOGGLE: - case QUERY: - dispversion(); - break; - case INIT: - set_output(1); /* Force output to stdout per GNU standard for --version output. */ - putstr("less "); - putstr(version); - putstr(" ("); - putstr(pattern_lib_name()); - putstr(" regular expressions)\n"); - { - char constant *copyright = "Copyright (C) 1984-2021 Mark Nudelman\n\n"; - if (copyright[0] == '@') - copyright = "Copyright (C) 1984 Mark Nudelman\n\n"; - putstr(copyright); - } - if (version[strlen(version)-1] == 'x') - { - putstr("** This is an EXPERIMENTAL build of the 'less' software,\n"); - putstr("** and may not function correctly.\n"); - putstr("** Obtain release builds from the web page below.\n\n"); - } - putstr("less comes with NO WARRANTY, to the extent permitted by law.\n"); - putstr("For information about the terms of redistribution,\n"); - putstr("see the file named README in the less distribution.\n"); - putstr("Home page: https://greenwoodsoftware.com/less\n"); - quit(QUIT_OK); - break; - } + switch (type) + { + case TOGGLE: + case QUERY: + dispversion(); + break; + case INIT: + set_output(1); /* Force output to stdout per GNU standard for --version output. */ + putstr("less "); + putstr(version); + putstr(" ("); + putstr(pattern_lib_name()); + putstr(" regular expressions)\n"); + { + char constant *copyright = "Copyright (C) 1984-2021 Mark Nudelman\n\n"; + if (copyright[0] == '@') + copyright = "Copyright (C) 1984 Mark Nudelman\n\n"; + putstr(copyright); + } + if (version[strlen(version)-1] == 'x') + { + putstr("** This is an EXPERIMENTAL build of the 'less' software,\n"); + putstr("** and may not function correctly.\n"); + putstr("** Obtain release builds from the web page below.\n\n"); + } + putstr("less comes with NO WARRANTY, to the extent permitted by law.\n"); + putstr("For information about the terms of redistribution,\n"); + putstr("see the file named README in the less distribution.\n"); + putstr("Home page: https://greenwoodsoftware.com/less\n"); + quit(QUIT_OK); + break; + } } #if MSDOS_COMPILER /* * Parse an MSDOS color descriptor. */ - static void + static void colordesc(s, fg_color, bg_color) - char *s; - int *fg_color; - int *bg_color; + char *s; + int *fg_color; + int *bg_color; { - int fg, bg; + int fg, bg; #if MSDOS_COMPILER==WIN32C - int ul = 0; - - if (*s == 'u') - { - ul = COMMON_LVB_UNDERSCORE; - s++; - if (*s == '\0') - { - *fg_color = nm_fg_color | ul; - *bg_color = nm_bg_color; - return; - } - } + int ul = 0; + + if (*s == 'u') + { + ul = COMMON_LVB_UNDERSCORE; + s++; + if (*s == '\0') + { + *fg_color = nm_fg_color | ul; + *bg_color = nm_bg_color; + return; + } + } #endif - if (parse_color(s, &fg, &bg) == CT_NULL) - { - PARG p; - p.p_string = s; - error("Invalid color string \"%s\"", &p); - } else - { - if (fg == CV_NOCHANGE) - fg = nm_fg_color; - if (bg == CV_NOCHANGE) - bg = nm_bg_color; + if (parse_color(s, &fg, &bg) == CT_NULL) + { + PARG p; + p.p_string = s; + error("Invalid color string \"%s\"", &p); + } else + { + if (fg == CV_NOCHANGE) + fg = nm_fg_color; + if (bg == CV_NOCHANGE) + bg = nm_bg_color; #if MSDOS_COMPILER==WIN32C - fg |= ul; + fg |= ul; #endif - *fg_color = fg; - *bg_color = bg; - } + *fg_color = fg; + *bg_color = bg; + } } #endif - static int + static int color_from_namechar(namechar) - char namechar; + char namechar; { - switch (namechar) - { - case 'A': return AT_COLOR_ATTN; - case 'B': return AT_COLOR_BIN; - case 'C': return AT_COLOR_CTRL; - case 'E': return AT_COLOR_ERROR; - case 'M': return AT_COLOR_MARK; - case 'N': return AT_COLOR_LINENUM; - case 'P': return AT_COLOR_PROMPT; - case 'R': return AT_COLOR_RSCROLL; - case 'S': return AT_COLOR_SEARCH; - case 'n': return AT_NORMAL; - case 's': return AT_STANDOUT; - case 'd': return AT_BOLD; - case 'u': return AT_UNDERLINE; - case 'k': return AT_BLINK; - default: return -1; - } + switch (namechar) + { + case 'A': return AT_COLOR_ATTN; + case 'B': return AT_COLOR_BIN; + case 'C': return AT_COLOR_CTRL; + case 'E': return AT_COLOR_ERROR; + case 'M': return AT_COLOR_MARK; + case 'N': return AT_COLOR_LINENUM; + case 'P': return AT_COLOR_PROMPT; + case 'R': return AT_COLOR_RSCROLL; + case 'S': return AT_COLOR_SEARCH; + case 'n': return AT_NORMAL; + case 's': return AT_STANDOUT; + case 'd': return AT_BOLD; + case 'u': return AT_UNDERLINE; + case 'k': return AT_BLINK; + default: return -1; + } } /* * Handler for the -D option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_D(type, s) - int type; - char *s; + int type; + char *s; { - PARG p; - int attr; + PARG p; + int attr; - switch (type) - { - case INIT: - case TOGGLE: + switch (type) + { + case INIT: + case TOGGLE: #if MSDOS_COMPILER - if (*s == 'a') - { - sgr_mode = !sgr_mode; - break; - } + if (*s == 'a') + { + sgr_mode = !sgr_mode; + break; + } #endif - attr = color_from_namechar(s[0]); - if (attr < 0) - { - p.p_char = s[0]; - error("Invalid color specifier '%c'", &p); - return; - } - if (!use_color && (attr & AT_COLOR)) - { - error("Set --use-color before changing colors", NULL_PARG); - return; - } - s++; + attr = color_from_namechar(s[0]); + if (attr < 0) + { + p.p_char = s[0]; + error("Invalid color specifier '%c'", &p); + return; + } + if (!use_color && (attr & AT_COLOR)) + { + error("Set --use-color before changing colors", NULL_PARG); + return; + } + s++; #if MSDOS_COMPILER - if (!(attr & AT_COLOR)) - { - switch (attr) - { - case AT_NORMAL: - colordesc(s, &nm_fg_color, &nm_bg_color); - break; - case AT_BOLD: - colordesc(s, &bo_fg_color, &bo_bg_color); - break; - case AT_UNDERLINE: - colordesc(s, &ul_fg_color, &ul_bg_color); - break; - case AT_BLINK: - colordesc(s, &bl_fg_color, &bl_bg_color); - break; - case AT_STANDOUT: - colordesc(s, &so_fg_color, &so_bg_color); - break; - } - if (type == TOGGLE) - { - at_enter(AT_STANDOUT); - at_exit(); - } - } else + if (!(attr & AT_COLOR)) + { + switch (attr) + { + case AT_NORMAL: + colordesc(s, &nm_fg_color, &nm_bg_color); + break; + case AT_BOLD: + colordesc(s, &bo_fg_color, &bo_bg_color); + break; + case AT_UNDERLINE: + colordesc(s, &ul_fg_color, &ul_bg_color); + break; + case AT_BLINK: + colordesc(s, &bl_fg_color, &bl_bg_color); + break; + case AT_STANDOUT: + colordesc(s, &so_fg_color, &so_bg_color); + break; + } + if (type == TOGGLE) + { + at_enter(AT_STANDOUT); + at_exit(); + } + } else #endif - if (set_color_map(attr, s) < 0) - { - p.p_string = s; - error("Invalid color string \"%s\"", &p); - return; - } - break; + if (set_color_map(attr, s) < 0) + { + p.p_string = s; + error("Invalid color string \"%s\"", &p); + return; + } + break; #if MSDOS_COMPILER - case QUERY: - p.p_string = (sgr_mode) ? "on" : "off"; - error("SGR mode is %s", &p); - break; + case QUERY: + p.p_string = (sgr_mode) ? "on" : "off"; + error("SGR mode is %s", &p); + break; #endif - } + } } /* * Handler for the -x option. */ - public void + public void opt_x(type, s) - int type; - char *s; + int type; + char *s; { - extern int tabstops[]; - extern int ntabstops; - extern int tabdefault; - char msg[60+(4*TABSTOP_MAX)]; - int i; - PARG p; - - switch (type) - { - case INIT: - case TOGGLE: - /* Start at 1 because tabstops[0] is always zero. */ - for (i = 1; i < TABSTOP_MAX; ) - { - int n = 0; - s = skipsp(s); - while (*s >= '0' && *s <= '9') - n = (10 * n) + (*s++ - '0'); - if (n > tabstops[i-1]) - tabstops[i++] = n; - s = skipsp(s); - if (*s++ != ',') - break; - } - if (i < 2) - return; - ntabstops = i; - tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2]; - break; - case QUERY: - strcpy(msg, "Tab stops "); - if (ntabstops > 2) - { - for (i = 1; i < ntabstops; i++) - { - if (i > 1) - strcat(msg, ","); - sprintf(msg+strlen(msg), "%d", tabstops[i]); - } - sprintf(msg+strlen(msg), " and then "); - } - sprintf(msg+strlen(msg), "every %d spaces", - tabdefault); - p.p_string = msg; - error("%s", &p); - break; - } + extern int tabstops[]; + extern int ntabstops; + extern int tabdefault; + char msg[60+(4*TABSTOP_MAX)]; + int i; + PARG p; + + switch (type) + { + case INIT: + case TOGGLE: + /* Start at 1 because tabstops[0] is always zero. */ + for (i = 1; i < TABSTOP_MAX; ) + { + int n = 0; + s = skipsp(s); + while (*s >= '0' && *s <= '9') + n = (10 * n) + (*s++ - '0'); + if (n > tabstops[i-1]) + tabstops[i++] = n; + s = skipsp(s); + if (*s++ != ',') + break; + } + if (i < 2) + return; + ntabstops = i; + tabdefault = tabstops[ntabstops-1] - tabstops[ntabstops-2]; + break; + case QUERY: + strcpy(msg, "Tab stops "); + if (ntabstops > 2) + { + for (i = 1; i < ntabstops; i++) + { + if (i > 1) + strcat(msg, ","); + sprintf(msg+strlen(msg), "%d", tabstops[i]); + } + sprintf(msg+strlen(msg), " and then "); + } + sprintf(msg+strlen(msg), "every %d spaces", + tabdefault); + p.p_string = msg; + error("%s", &p); + break; + } } /* * Handler for the -" option. */ - public void + public void opt_quote(type, s) - int type; - char *s; + int type; + char *s; { - char buf[3]; - PARG parg; - - switch (type) - { - case INIT: - case TOGGLE: - if (s[0] == '\0') - { - openquote = closequote = '\0'; - break; - } - if (s[1] != '\0' && s[2] != '\0') - { - error("-\" must be followed by 1 or 2 chars", NULL_PARG); - return; - } - openquote = s[0]; - if (s[1] == '\0') - closequote = openquote; - else - closequote = s[1]; - break; - case QUERY: - buf[0] = openquote; - buf[1] = closequote; - buf[2] = '\0'; - parg.p_string = buf; - error("quotes %s", &parg); - break; - } + char buf[3]; + PARG parg; + + switch (type) + { + case INIT: + case TOGGLE: + if (s[0] == '\0') + { + openquote = closequote = '\0'; + break; + } + if (s[1] != '\0' && s[2] != '\0') + { + error("-\" must be followed by 1 or 2 chars", NULL_PARG); + return; + } + openquote = s[0]; + if (s[1] == '\0') + closequote = openquote; + else + closequote = s[1]; + break; + case QUERY: + buf[0] = openquote; + buf[1] = closequote; + buf[2] = '\0'; + parg.p_string = buf; + error("quotes %s", &parg); + break; + } } /* * Handler for the --rscroll option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_rscroll(type, s) - int type; - char *s; + int type; + char *s; { - PARG p; - - switch (type) - { - case INIT: - case TOGGLE: { - char *fmt; - int attr = AT_STANDOUT; - setfmt(s, &fmt, &attr, "*s>"); - if (strcmp(fmt, "-") == 0) - { - rscroll_char = 0; - } else - { - rscroll_char = *fmt ? *fmt : '>'; - rscroll_attr = attr|AT_COLOR_RSCROLL; - } - break; } - case QUERY: { - p.p_string = rscroll_char ? prchar(rscroll_char) : "-"; - error("rscroll char is %s", &p); - break; } - } + PARG p; + + switch (type) + { + case INIT: + case TOGGLE: { + char *fmt; + int attr = AT_STANDOUT; + setfmt(s, &fmt, &attr, "*s>"); + if (strcmp(fmt, "-") == 0) + { + rscroll_char = 0; + } else + { + rscroll_char = *fmt ? *fmt : '>'; + rscroll_attr = attr|AT_COLOR_RSCROLL; + } + break; } + case QUERY: { + p.p_string = rscroll_char ? prchar(rscroll_char) : "-"; + error("rscroll char is %s", &p); + break; } + } } /* * "-?" means display a help message. * If from the command line, exit immediately. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_query(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case QUERY: - case TOGGLE: - error("Use \"h\" for help", NULL_PARG); - break; - case INIT: - dohelp = 1; - } + switch (type) + { + case QUERY: + case TOGGLE: + error("Use \"h\" for help", NULL_PARG); + break; + case INIT: + dohelp = 1; + } } /* * Handler for the --mouse option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_mousecap(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case TOGGLE: - if (mousecap == OPT_OFF) - deinit_mouse(); - else - init_mouse(); - break; - case INIT: - case QUERY: - break; - } + switch (type) + { + case TOGGLE: + if (mousecap == OPT_OFF) + deinit_mouse(); + else + init_mouse(); + break; + case INIT: + case QUERY: + break; + } } /* * Handler for the --wheel-lines option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_wheel_lines(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case INIT: - case TOGGLE: - if (wheel_lines <= 0) - wheel_lines = default_wheel_lines(); - break; - case QUERY: - break; - } + switch (type) + { + case INIT: + case TOGGLE: + if (wheel_lines <= 0) + wheel_lines = default_wheel_lines(); + break; + case QUERY: + break; + } } /* * Handler for the --line-number-width option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_linenum_width(type, s) - int type; - char *s; + int type; + char *s; { - PARG parg; - - switch (type) - { - case INIT: - case TOGGLE: - if (linenum_width > MAX_LINENUM_WIDTH) - { - parg.p_int = MAX_LINENUM_WIDTH; - error("Line number width must not be larger than %d", &parg); - linenum_width = MIN_LINENUM_WIDTH; - } - break; - case QUERY: - break; - } + PARG parg; + + switch (type) + { + case INIT: + case TOGGLE: + if (linenum_width > MAX_LINENUM_WIDTH) + { + parg.p_int = MAX_LINENUM_WIDTH; + error("Line number width must not be larger than %d", &parg); + linenum_width = MIN_LINENUM_WIDTH; + } + break; + case QUERY: + break; + } } /* * Handler for the --status-column-width option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_status_col_width(type, s) - int type; - char *s; + int type; + char *s; { - PARG parg; - - switch (type) - { - case INIT: - case TOGGLE: - if (status_col_width > MAX_STATUSCOL_WIDTH) - { - parg.p_int = MAX_STATUSCOL_WIDTH; - error("Status column width must not be larger than %d", &parg); - status_col_width = 2; - } - break; - case QUERY: - break; - } + PARG parg; + + switch (type) + { + case INIT: + case TOGGLE: + if (status_col_width > MAX_STATUSCOL_WIDTH) + { + parg.p_int = MAX_STATUSCOL_WIDTH; + error("Status column width must not be larger than %d", &parg); + status_col_width = 2; + } + break; + case QUERY: + break; + } } #if LESSTEST /* * Handler for the --tty option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_ttyin_name(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case INIT: - ttyin_name = s; - is_tty = 1; - break; - } + switch (type) + { + case INIT: + ttyin_name = s; + is_tty = 1; + break; + } } /* * Handler for the --rstat option. */ - /*ARGSUSED*/ - public void + /*ARGSUSED*/ + public void opt_rstat(type, s) - int type; - char *s; + int type; + char *s; { - switch (type) - { - case INIT: - rstat_file = open(s, O_WRONLY|O_CREAT, 0664); - if (rstat_file < 0) - { - PARG parg; - parg.p_string = s; - error("Cannot create rstat file \"%s\"", &parg); - } - break; - } + switch (type) + { + case INIT: + rstat_file = open(s, O_WRONLY|O_CREAT, 0664); + if (rstat_file < 0) + { + PARG parg; + parg.p_string = s; + error("Cannot create rstat file \"%s\"", &parg); + } + break; + } } #endif /*LESSTEST*/ /* * Get the "screen window" size. */ - public int + public int get_swindow(VOID_PARAM) { - if (swindow > 0) - return (swindow); - return (sc_height + swindow); + if (swindow > 0) + return (swindow); + return (sc_height + swindow); } - diff --git a/option.c b/option.c index 61247d8..b8baf0b 100644 --- a/option.c +++ b/option.c @@ -13,7 +13,7 @@ * * Each option is a single letter which controls a program variable. * The options have defaults which may be changed via - * the command line option, toggled via the "-" command, + * the command line option, toggled via the "-" command, * or queried via the "_" command. */ @@ -35,261 +35,261 @@ extern int opt_use_backslash; /* * Return a printable description of an option. */ - static char * + static char * opt_desc(o) - struct loption *o; + struct loption *o; { - static char buf[OPTNAME_MAX + 10]; - if (o->oletter == OLETTER_NONE) - SNPRINTF1(buf, sizeof(buf), "--%s", o->onames->oname); - else - SNPRINTF2(buf, sizeof(buf), "-%c (--%s)", o->oletter, o->onames->oname); - return (buf); + static char buf[OPTNAME_MAX + 10]; + if (o->oletter == OLETTER_NONE) + SNPRINTF1(buf, sizeof(buf), "--%s", o->onames->oname); + else + SNPRINTF2(buf, sizeof(buf), "-%c (--%s)", o->oletter, o->onames->oname); + return (buf); } /* * Return a string suitable for printing as the "name" of an option. * For example, if the option letter is 'x', just return "-x". */ - public char * + public char * propt(c) - int c; + int c; { - static char buf[8]; + static char buf[8]; - sprintf(buf, "-%s", prchar(c)); - return (buf); + sprintf(buf, "-%s", prchar(c)); + return (buf); } -/* - * Scan an argument (either from the command line or from the +/* + * Scan an argument (either from the command line or from the * LESS environment variable) and process it. */ - public void + public void scan_option(s) - char *s; + char *s; { - struct loption *o; - int optc; - char *optname; - char *printopt; - char *str; - int set_default; - int lc; - int err; - PARG parg; - - if (s == NULL) - return; - - /* - * If we have a pending option which requires an argument, - * handle it now. - * This happens if the previous option was, for example, "-P" - * without a following string. In that case, the current - * option is simply the argument for the previous option. - */ - if (pendopt != NULL) - { - switch (pendopt->otype & OTYPE) - { - case STRING: - (*pendopt->ofunc)(INIT, s); - break; - case NUMBER: - printopt = opt_desc(pendopt); - *(pendopt->ovar) = getnum(&s, printopt, (int*)NULL); - break; - } - pendopt = NULL; - return; - } - - set_default = FALSE; - optname = NULL; - - while (*s != '\0') - { - /* - * Check some special cases first. - */ - switch (optc = *s++) - { - case ' ': - case '\t': - case END_OPTION_STRING: - continue; - case '-': - /* - * "--" indicates an option name instead of a letter. - */ - if (*s == '-') - { - optname = ++s; - break; - } - /* - * "-+" means set these options back to their defaults. - * (They may have been set otherwise by previous - * options.) - */ - set_default = (*s == '+'); - if (set_default) - s++; - continue; - case '+': - /* - * An option prefixed by a "+" is ungotten, so - * that it is interpreted as less commands - * processed at the start of the first input file. - * "++" means process the commands at the start of - * EVERY input file. - */ - plusoption = TRUE; - s = optstring(s, &str, propt('+'), NULL); - if (s == NULL) - return; - if (*str == '+') - { - if (every_first_cmd != NULL) - free(every_first_cmd); - every_first_cmd = save(str+1); - } else - { - ungetsc(str); - ungetcc_back(CHAR_END_COMMAND); - } - free(str); - continue; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* - * Special "more" compatibility form "-" - * instead of -z to set the scrolling - * window size. - */ - s--; - optc = 'z'; - break; - case 'n': - if (less_is_more) - optc = 'z'; - break; - } - - /* - * Not a special case. - * Look up the option letter in the option table. - */ - err = 0; - if (optname == NULL) - { - printopt = propt(optc); - lc = ASCII_IS_LOWER(optc); - o = findopt(optc); - } else - { - printopt = optname; - lc = ASCII_IS_LOWER(optname[0]); - o = findopt_name(&optname, NULL, &err); - s = optname; - optname = NULL; - if (*s == '\0' || *s == ' ') - { - /* - * The option name matches exactly. - */ - ; - } else if (*s == '=') - { - /* - * The option name is followed by "=value". - */ - if (o != NULL && - (o->otype & OTYPE) != STRING && - (o->otype & OTYPE) != NUMBER) - { - parg.p_string = printopt; - error("The %s option should not be followed by =", - &parg); - return; - } - s++; - } else - { - /* - * The specified name is longer than the - * real option name. - */ - o = NULL; - } - } - if (o == NULL) - { - parg.p_string = printopt; - if (err == OPT_AMBIG) - error("%s is an ambiguous abbreviation (\"less --help\" for help)", - &parg); - else - error("There is no %s option (\"less --help\" for help)", - &parg); - return; - } - - str = NULL; - switch (o->otype & OTYPE) - { - case BOOL: - if (set_default) - *(o->ovar) = o->odefault; - else - *(o->ovar) = ! o->odefault; - break; - case TRIPLE: - if (set_default) - *(o->ovar) = o->odefault; - else - *(o->ovar) = flip_triple(o->odefault, lc); - break; - case STRING: - if (*s == '\0') - { - /* - * Set pendopt and return. - * We will get the string next time - * scan_option is called. - */ - pendopt = o; - return; - } - /* - * Don't do anything here. - * All processing of STRING options is done by - * the handling function. - */ - while (*s == ' ') - s++; - s = optstring(s, &str, printopt, o->odesc[1]); - if (s == NULL) - return; - break; - case NUMBER: - if (*s == '\0') - { - pendopt = o; - return; - } - *(o->ovar) = getnum(&s, printopt, (int*)NULL); - break; - } - /* - * If the option has a handling function, call it. - */ - if (o->ofunc != NULL) - (*o->ofunc)(INIT, str); - if (str != NULL) - free(str); - } + struct loption *o; + int optc; + char *optname; + char *printopt; + char *str; + int set_default; + int lc; + int err; + PARG parg; + + if (s == NULL) + return; + + /* + * If we have a pending option which requires an argument, + * handle it now. + * This happens if the previous option was, for example, "-P" + * without a following string. In that case, the current + * option is simply the argument for the previous option. + */ + if (pendopt != NULL) + { + switch (pendopt->otype & OTYPE) + { + case STRING: + (*pendopt->ofunc)(INIT, s); + break; + case NUMBER: + printopt = opt_desc(pendopt); + *(pendopt->ovar) = getnum(&s, printopt, (int*)NULL); + break; + } + pendopt = NULL; + return; + } + + set_default = FALSE; + optname = NULL; + + while (*s != '\0') + { + /* + * Check some special cases first. + */ + switch (optc = *s++) + { + case ' ': + case '\t': + case END_OPTION_STRING: + continue; + case '-': + /* + * "--" indicates an option name instead of a letter. + */ + if (*s == '-') + { + optname = ++s; + break; + } + /* + * "-+" means set these options back to their defaults. + * (They may have been set otherwise by previous + * options.) + */ + set_default = (*s == '+'); + if (set_default) + s++; + continue; + case '+': + /* + * An option prefixed by a "+" is ungotten, so + * that it is interpreted as less commands + * processed at the start of the first input file. + * "++" means process the commands at the start of + * EVERY input file. + */ + plusoption = TRUE; + s = optstring(s, &str, propt('+'), NULL); + if (s == NULL) + return; + if (*str == '+') + { + if (every_first_cmd != NULL) + free(every_first_cmd); + every_first_cmd = save(str+1); + } else + { + ungetsc(str); + ungetcc_back(CHAR_END_COMMAND); + } + free(str); + continue; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* + * Special "more" compatibility form "-" + * instead of -z to set the scrolling + * window size. + */ + s--; + optc = 'z'; + break; + case 'n': + if (less_is_more) + optc = 'z'; + break; + } + + /* + * Not a special case. + * Look up the option letter in the option table. + */ + err = 0; + if (optname == NULL) + { + printopt = propt(optc); + lc = ASCII_IS_LOWER(optc); + o = findopt(optc); + } else + { + printopt = optname; + lc = ASCII_IS_LOWER(optname[0]); + o = findopt_name(&optname, NULL, &err); + s = optname; + optname = NULL; + if (*s == '\0' || *s == ' ') + { + /* + * The option name matches exactly. + */ + ; + } else if (*s == '=') + { + /* + * The option name is followed by "=value". + */ + if (o != NULL && + (o->otype & OTYPE) != STRING && + (o->otype & OTYPE) != NUMBER) + { + parg.p_string = printopt; + error("The %s option should not be followed by =", + &parg); + return; + } + s++; + } else + { + /* + * The specified name is longer than the + * real option name. + */ + o = NULL; + } + } + if (o == NULL) + { + parg.p_string = printopt; + if (err == OPT_AMBIG) + error("%s is an ambiguous abbreviation (\"less --help\" for help)", + &parg); + else + error("There is no %s option (\"less --help\" for help)", + &parg); + return; + } + + str = NULL; + switch (o->otype & OTYPE) + { + case BOOL: + if (set_default) + *(o->ovar) = o->odefault; + else + *(o->ovar) = ! o->odefault; + break; + case TRIPLE: + if (set_default) + *(o->ovar) = o->odefault; + else + *(o->ovar) = flip_triple(o->odefault, lc); + break; + case STRING: + if (*s == '\0') + { + /* + * Set pendopt and return. + * We will get the string next time + * scan_option is called. + */ + pendopt = o; + return; + } + /* + * Don't do anything here. + * All processing of STRING options is done by + * the handling function. + */ + while (*s == ' ') + s++; + s = optstring(s, &str, printopt, o->odesc[1]); + if (s == NULL) + return; + break; + case NUMBER: + if (*s == '\0') + { + pendopt = o; + return; + } + *(o->ovar) = getnum(&s, printopt, (int*)NULL); + break; + } + /* + * If the option has a handling function, call it. + */ + if (o->ofunc != NULL) + (*o->ofunc)(INIT, str); + if (str != NULL) + free(str); + } } /* @@ -301,280 +301,280 @@ scan_option(s) * OPT_UNSET set to the default value * OPT_SET set to the inverse of the default value */ - public void + public void toggle_option(o, lower, s, how_toggle) - struct loption *o; - int lower; - char *s; - int how_toggle; + struct loption *o; + int lower; + char *s; + int how_toggle; { - int num; - int no_prompt; - int err; - PARG parg; - - no_prompt = (how_toggle & OPT_NO_PROMPT); - how_toggle &= ~OPT_NO_PROMPT; - - if (o == NULL) - { - error("No such option", NULL_PARG); - return; - } - - if (how_toggle == OPT_TOGGLE && (o->otype & NO_TOGGLE)) - { - parg.p_string = opt_desc(o); - error("Cannot change the %s option", &parg); - return; - } - - if (how_toggle == OPT_NO_TOGGLE && (o->otype & NO_QUERY)) - { - parg.p_string = opt_desc(o); - error("Cannot query the %s option", &parg); - return; - } - - /* - * Check for something which appears to be a do_toggle - * (because the "-" command was used), but really is not. - * This could be a string option with no string, or - * a number option with no number. - */ - switch (o->otype & OTYPE) - { - case STRING: - case NUMBER: - if (how_toggle == OPT_TOGGLE && *s == '\0') - how_toggle = OPT_NO_TOGGLE; - break; - } + int num; + int no_prompt; + int err; + PARG parg; + + no_prompt = (how_toggle & OPT_NO_PROMPT); + how_toggle &= ~OPT_NO_PROMPT; + + if (o == NULL) + { + error("No such option", NULL_PARG); + return; + } + + if (how_toggle == OPT_TOGGLE && (o->otype & NO_TOGGLE)) + { + parg.p_string = opt_desc(o); + error("Cannot change the %s option", &parg); + return; + } + + if (how_toggle == OPT_NO_TOGGLE && (o->otype & NO_QUERY)) + { + parg.p_string = opt_desc(o); + error("Cannot query the %s option", &parg); + return; + } + + /* + * Check for something which appears to be a do_toggle + * (because the "-" command was used), but really is not. + * This could be a string option with no string, or + * a number option with no number. + */ + switch (o->otype & OTYPE) + { + case STRING: + case NUMBER: + if (how_toggle == OPT_TOGGLE && *s == '\0') + how_toggle = OPT_NO_TOGGLE; + break; + } #if HILITE_SEARCH - if (how_toggle != OPT_NO_TOGGLE && (o->otype & HL_REPAINT)) - repaint_hilite(0); + if (how_toggle != OPT_NO_TOGGLE && (o->otype & HL_REPAINT)) + repaint_hilite(0); #endif - /* - * Now actually toggle (change) the variable. - */ - if (how_toggle != OPT_NO_TOGGLE) - { - switch (o->otype & OTYPE) - { - case BOOL: - /* - * Boolean. - */ - switch (how_toggle) - { - case OPT_TOGGLE: - *(o->ovar) = ! *(o->ovar); - break; - case OPT_UNSET: - *(o->ovar) = o->odefault; - break; - case OPT_SET: - *(o->ovar) = ! o->odefault; - break; - } - break; - case TRIPLE: - /* - * Triple: - * If user gave the lower case letter, then switch - * to 1 unless already 1, in which case make it 0. - * If user gave the upper case letter, then switch - * to 2 unless already 2, in which case make it 0. - */ - switch (how_toggle) - { - case OPT_TOGGLE: - *(o->ovar) = flip_triple(*(o->ovar), lower); - break; - case OPT_UNSET: - *(o->ovar) = o->odefault; - break; - case OPT_SET: - *(o->ovar) = flip_triple(o->odefault, lower); - break; - } - break; - case STRING: - /* - * String: don't do anything here. - * The handling function will do everything. - */ - switch (how_toggle) - { - case OPT_SET: - case OPT_UNSET: - error("Cannot use \"-+\" or \"--\" for a string option", - NULL_PARG); - return; - } - break; - case NUMBER: - /* - * Number: set the variable to the given number. - */ - switch (how_toggle) - { - case OPT_TOGGLE: - num = getnum(&s, NULL, &err); - if (!err) - *(o->ovar) = num; - break; - case OPT_UNSET: - *(o->ovar) = o->odefault; - break; - case OPT_SET: - error("Can't use \"-!\" for a numeric option", - NULL_PARG); - return; - } - break; - } - } - - /* - * Call the handling function for any special action - * specific to this option. - */ - if (o->ofunc != NULL) - (*o->ofunc)((how_toggle==OPT_NO_TOGGLE) ? QUERY : TOGGLE, s); + /* + * Now actually toggle (change) the variable. + */ + if (how_toggle != OPT_NO_TOGGLE) + { + switch (o->otype & OTYPE) + { + case BOOL: + /* + * Boolean. + */ + switch (how_toggle) + { + case OPT_TOGGLE: + *(o->ovar) = ! *(o->ovar); + break; + case OPT_UNSET: + *(o->ovar) = o->odefault; + break; + case OPT_SET: + *(o->ovar) = ! o->odefault; + break; + } + break; + case TRIPLE: + /* + * Triple: + * If user gave the lower case letter, then switch + * to 1 unless already 1, in which case make it 0. + * If user gave the upper case letter, then switch + * to 2 unless already 2, in which case make it 0. + */ + switch (how_toggle) + { + case OPT_TOGGLE: + *(o->ovar) = flip_triple(*(o->ovar), lower); + break; + case OPT_UNSET: + *(o->ovar) = o->odefault; + break; + case OPT_SET: + *(o->ovar) = flip_triple(o->odefault, lower); + break; + } + break; + case STRING: + /* + * String: don't do anything here. + * The handling function will do everything. + */ + switch (how_toggle) + { + case OPT_SET: + case OPT_UNSET: + error("Cannot use \"-+\" or \"--\" for a string option", + NULL_PARG); + return; + } + break; + case NUMBER: + /* + * Number: set the variable to the given number. + */ + switch (how_toggle) + { + case OPT_TOGGLE: + num = getnum(&s, NULL, &err); + if (!err) + *(o->ovar) = num; + break; + case OPT_UNSET: + *(o->ovar) = o->odefault; + break; + case OPT_SET: + error("Can't use \"-!\" for a numeric option", + NULL_PARG); + return; + } + break; + } + } + + /* + * Call the handling function for any special action + * specific to this option. + */ + if (o->ofunc != NULL) + (*o->ofunc)((how_toggle==OPT_NO_TOGGLE) ? QUERY : TOGGLE, s); #if HILITE_SEARCH - if (how_toggle != OPT_NO_TOGGLE && (o->otype & HL_REPAINT)) - chg_hilite(); + if (how_toggle != OPT_NO_TOGGLE && (o->otype & HL_REPAINT)) + chg_hilite(); #endif - if (!no_prompt) - { - /* - * Print a message describing the new setting. - */ - switch (o->otype & OTYPE) - { - case BOOL: - case TRIPLE: - /* - * Print the odesc message. - */ - error(o->odesc[*(o->ovar)], NULL_PARG); - break; - case NUMBER: - /* - * The message is in odesc[1] and has a %d for - * the value of the variable. - */ - parg.p_int = *(o->ovar); - error(o->odesc[1], &parg); - break; - case STRING: - /* - * Message was already printed by the handling function. - */ - break; - } - } - - if (how_toggle != OPT_NO_TOGGLE && (o->otype & REPAINT)) - screen_trashed = TRUE; + if (!no_prompt) + { + /* + * Print a message describing the new setting. + */ + switch (o->otype & OTYPE) + { + case BOOL: + case TRIPLE: + /* + * Print the odesc message. + */ + error(o->odesc[*(o->ovar)], NULL_PARG); + break; + case NUMBER: + /* + * The message is in odesc[1] and has a %d for + * the value of the variable. + */ + parg.p_int = *(o->ovar); + error(o->odesc[1], &parg); + break; + case STRING: + /* + * Message was already printed by the handling function. + */ + break; + } + } + + if (how_toggle != OPT_NO_TOGGLE && (o->otype & REPAINT)) + screen_trashed = TRUE; } /* * "Toggle" a triple-valued option. */ - static int + static int flip_triple(val, lc) - int val; - int lc; + int val; + int lc; { - if (lc) - return ((val == OPT_ON) ? OPT_OFF : OPT_ON); - else - return ((val == OPT_ONPLUS) ? OPT_OFF : OPT_ONPLUS); + if (lc) + return ((val == OPT_ON) ? OPT_OFF : OPT_ON); + else + return ((val == OPT_ONPLUS) ? OPT_OFF : OPT_ONPLUS); } /* * Determine if an option takes a parameter. */ - public int + public int opt_has_param(o) - struct loption *o; + struct loption *o; { - if (o == NULL) - return (0); - if (o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE)) - return (0); - return (1); + if (o == NULL) + return (0); + if (o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE)) + return (0); + return (1); } /* * Return the prompt to be used for a given option letter. * Only string and number valued options have prompts. */ - public char * + public char * opt_prompt(o) - struct loption *o; + struct loption *o; { - if (o == NULL || (o->otype & (STRING|NUMBER)) == 0) - return ("?"); - return (o->odesc[0]); + if (o == NULL || (o->otype & (STRING|NUMBER)) == 0) + return ("?"); + return (o->odesc[0]); } /* * If the specified option can be toggled, return NULL. * Otherwise return an appropriate error message. */ - public char * + public char * opt_toggle_disallowed(c) - int c; + int c; { - switch (c) - { - case 'o': - if (ch_getflags() & CH_CANSEEK) - return "Input is not a pipe"; - break; - } - return NULL; + switch (c) + { + case 'o': + if (ch_getflags() & CH_CANSEEK) + return "Input is not a pipe"; + break; + } + return NULL; } /* * Return whether or not there is a string option pending; - * that is, if the previous option was a string-valued option letter + * that is, if the previous option was a string-valued option letter * (like -P) without a following string. * In that case, the current option is taken to be the string for * the previous option. */ - public int + public int isoptpending(VOID_PARAM) { - return (pendopt != NULL); + return (pendopt != NULL); } /* * Print error message about missing string. */ - static void + static void nostring(printopt) - char *printopt; + char *printopt; { - PARG parg; - parg.p_string = printopt; - error("Value is required after %s", &parg); + PARG parg; + parg.p_string = printopt; + error("Value is required after %s", &parg); } /* * Print error message if a STRING type option is not followed by a string. */ - public void + public void nopendopt(VOID_PARAM) { - nostring(opt_desc(pendopt)); + nostring(opt_desc(pendopt)); } /* @@ -582,64 +582,64 @@ nopendopt(VOID_PARAM) * In the latter case, replace the char with a null char. * Return a pointer to the remainder of the string, if any. */ - static char * + static char * optstring(s, p_str, printopt, validchars) - char *s; - char **p_str; - char *printopt; - char *validchars; + char *s; + char **p_str; + char *printopt; + char *validchars; { - char *p; - char *out; - - if (*s == '\0') - { - nostring(printopt); - return (NULL); - } - /* Alloc could be more than needed, but not worth trimming. */ - *p_str = (char *) ecalloc(strlen(s)+1, sizeof(char)); - out = *p_str; - - for (p = s; *p != '\0'; p++) - { - if (opt_use_backslash && *p == '\\' && p[1] != '\0') - { - /* Take next char literally. */ - ++p; - } else - { - if (*p == END_OPTION_STRING || - (validchars != NULL && strchr(validchars, *p) == NULL)) - /* End of option string. */ - break; - } - *out++ = *p; - } - *out = '\0'; - return (p); + char *p; + char *out; + + if (*s == '\0') + { + nostring(printopt); + return (NULL); + } + /* Alloc could be more than needed, but not worth trimming. */ + *p_str = (char *) ecalloc(strlen(s)+1, sizeof(char)); + out = *p_str; + + for (p = s; *p != '\0'; p++) + { + if (opt_use_backslash && *p == '\\' && p[1] != '\0') + { + /* Take next char literally. */ + ++p; + } else + { + if (*p == END_OPTION_STRING || + (validchars != NULL && strchr(validchars, *p) == NULL)) + /* End of option string. */ + break; + } + *out++ = *p; + } + *out = '\0'; + return (p); } /* */ - static int + static int num_error(printopt, errp) - char *printopt; - int *errp; + char *printopt; + int *errp; { - PARG parg; - - if (errp != NULL) - { - *errp = TRUE; - return (-1); - } - if (printopt != NULL) - { - parg.p_string = printopt; - error("Number is required after %s", &parg); - } - return (-1); + PARG parg; + + if (errp != NULL) + { + *errp = TRUE; + return (-1); + } + if (printopt != NULL) + { + parg.p_string = printopt; + error("Number is required after %s", &parg); + } + return (-1); } /* @@ -647,35 +647,35 @@ num_error(printopt, errp) * Like atoi(), but takes a pointer to a char *, and updates * the char * to point after the translated number. */ - public int + public int getnum(sp, printopt, errp) - char **sp; - char *printopt; - int *errp; + char **sp; + char *printopt; + int *errp; { - char *s; - int n; - int neg; - - s = skipsp(*sp); - neg = FALSE; - if (*s == '-') - { - neg = TRUE; - s++; - } - if (*s < '0' || *s > '9') - return (num_error(printopt, errp)); - - n = 0; - while (*s >= '0' && *s <= '9') - n = 10 * n + *s++ - '0'; - *sp = s; - if (errp != NULL) - *errp = FALSE; - if (neg) - n = -n; - return (n); + char *s; + int n; + int neg; + + s = skipsp(*sp); + neg = FALSE; + if (*s == '-') + { + neg = TRUE; + s++; + } + if (*s < '0' || *s > '9') + return (num_error(printopt, errp)); + + n = 0; + while (*s >= '0' && *s <= '9') + n = 10 * n + *s++ - '0'; + *sp = s; + if (errp != NULL) + *errp = FALSE; + if (neg) + n = -n; + return (n); } /* @@ -684,46 +684,46 @@ getnum(sp, printopt, errp) * The value of the fraction is returned as parts per NUM_FRAC_DENOM. * That is, if "n" is returned, the fraction intended is n/NUM_FRAC_DENOM. */ - public long + public long getfraction(sp, printopt, errp) - char **sp; - char *printopt; - int *errp; + char **sp; + char *printopt; + int *errp; { - char *s; - long frac = 0; - int fraclen = 0; - - s = skipsp(*sp); - if (*s < '0' || *s > '9') - return (num_error(printopt, errp)); - - for ( ; *s >= '0' && *s <= '9'; s++) - { - frac = (frac * 10) + (*s - '0'); - fraclen++; - } - if (fraclen > NUM_LOG_FRAC_DENOM) - while (fraclen-- > NUM_LOG_FRAC_DENOM) - frac /= 10; - else - while (fraclen++ < NUM_LOG_FRAC_DENOM) - frac *= 10; - *sp = s; - if (errp != NULL) - *errp = FALSE; - return (frac); + char *s; + long frac = 0; + int fraclen = 0; + + s = skipsp(*sp); + if (*s < '0' || *s > '9') + return (num_error(printopt, errp)); + + for ( ; *s >= '0' && *s <= '9'; s++) + { + frac = (frac * 10) + (*s - '0'); + fraclen++; + } + if (fraclen > NUM_LOG_FRAC_DENOM) + while (fraclen-- > NUM_LOG_FRAC_DENOM) + frac /= 10; + else + while (fraclen++ < NUM_LOG_FRAC_DENOM) + frac *= 10; + *sp = s; + if (errp != NULL) + *errp = FALSE; + return (frac); } /* * Get the value of the -e flag. */ - public int + public int get_quit_at_eof(VOID_PARAM) { - if (!less_is_more) - return quit_at_eof; - /* When less_is_more is set, the -e flag semantics are different. */ - return quit_at_eof ? OPT_ONPLUS : OPT_ON; + if (!less_is_more) + return quit_at_eof; + /* When less_is_more is set, the -e flag semantics are different. */ + return quit_at_eof ? OPT_ONPLUS : OPT_ON; } diff --git a/option.h b/option.h index 4a10d6b..a72be2c 100644 --- a/option.h +++ b/option.h @@ -63,4 +63,3 @@ struct loption void (*ofunc) LESSPARAMS ((int, char*)); /* Pointer to special handling function */ char *odesc[3]; /* Description of each value */ }; - diff --git a/opttbl.c b/opttbl.c index 3a5d283..cc91325 100644 --- a/opttbl.c +++ b/opttbl.c @@ -146,7 +146,7 @@ static struct optname rstat_optname = { "rstat", NULL }; * For BOOL and TRIPLE options, odesc[0], odesc[1], odesc[2] are * the description of the option when set to 0, 1 or 2, respectively. * For NUMBER options, odesc[0] is the prompt to use when entering - * a new value, and odesc[1] is the description, which should contain + * a new value, and odesc[1] is the description, which should contain * one %d which is replaced by the value of the number. * For STRING options, odesc[0] is the prompt to use when entering * a new value, and odesc[1], if not NULL, is the set of characters @@ -154,475 +154,475 @@ static struct optname rstat_optname = { "rstat", NULL }; */ static struct loption option[] = { - { 'a', &a_optname, - TRIPLE, OPT_ONPLUS, &how_search, NULL, - { - "Search includes displayed screen", - "Search skips displayed screen", - "Search includes all of displayed screen" - } - }, + { 'a', &a_optname, + TRIPLE, OPT_ONPLUS, &how_search, NULL, + { + "Search includes displayed screen", + "Search skips displayed screen", + "Search includes all of displayed screen" + } + }, - { 'b', &b_optname, - NUMBER|INIT_HANDLER, 64, &bufspace, opt_b, - { - "Max buffer space per file (K): ", - "Max buffer space per file: %dK", - NULL - } - }, - { 'B', &B__optname, - BOOL, OPT_ON, &autobuf, NULL, - { - "Don't automatically allocate buffers", - "Automatically allocate buffers when needed", - NULL - } - }, - { 'c', &c_optname, - TRIPLE, OPT_OFF, &top_scroll, NULL, - { - "Repaint by scrolling from bottom of screen", - "Repaint by painting from top of screen", - "Repaint by painting from top of screen" - } - }, - { 'd', &d_optname, - BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL, - { - "Assume intelligent terminal", - "Assume dumb terminal", - NULL - } - }, - { 'D', &D__optname, - STRING|REPAINT|NO_QUERY, 0, NULL, opt_D, - { - "color desc: ", - NULL, - NULL - } - }, - { 'e', &e_optname, - TRIPLE, OPT_OFF, &quit_at_eof, NULL, - { - "Don't quit at end-of-file", - "Quit at end-of-file", - "Quit immediately at end-of-file" - } - }, - { 'f', &f_optname, - BOOL, OPT_OFF, &force_open, NULL, - { - "Open only regular files", - "Open even non-regular files", - NULL - } - }, - { 'F', &F__optname, - BOOL, OPT_OFF, &quit_if_one_screen, NULL, - { - "Don't quit if end-of-file on first screen", - "Quit if end-of-file on first screen", - NULL - } - }, + { 'b', &b_optname, + NUMBER|INIT_HANDLER, 64, &bufspace, opt_b, + { + "Max buffer space per file (K): ", + "Max buffer space per file: %dK", + NULL + } + }, + { 'B', &B__optname, + BOOL, OPT_ON, &autobuf, NULL, + { + "Don't automatically allocate buffers", + "Automatically allocate buffers when needed", + NULL + } + }, + { 'c', &c_optname, + TRIPLE, OPT_OFF, &top_scroll, NULL, + { + "Repaint by scrolling from bottom of screen", + "Repaint by painting from top of screen", + "Repaint by painting from top of screen" + } + }, + { 'd', &d_optname, + BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL, + { + "Assume intelligent terminal", + "Assume dumb terminal", + NULL + } + }, + { 'D', &D__optname, + STRING|REPAINT|NO_QUERY, 0, NULL, opt_D, + { + "color desc: ", + NULL, + NULL + } + }, + { 'e', &e_optname, + TRIPLE, OPT_OFF, &quit_at_eof, NULL, + { + "Don't quit at end-of-file", + "Quit at end-of-file", + "Quit immediately at end-of-file" + } + }, + { 'f', &f_optname, + BOOL, OPT_OFF, &force_open, NULL, + { + "Open only regular files", + "Open even non-regular files", + NULL + } + }, + { 'F', &F__optname, + BOOL, OPT_OFF, &quit_if_one_screen, NULL, + { + "Don't quit if end-of-file on first screen", + "Quit if end-of-file on first screen", + NULL + } + }, #if HILITE_SEARCH - { 'g', &g_optname, - TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL, - { - "Don't highlight search matches", - "Highlight matches for previous search only", - "Highlight all matches for previous search pattern", - } - }, + { 'g', &g_optname, + TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL, + { + "Don't highlight search matches", + "Highlight matches for previous search only", + "Highlight all matches for previous search pattern", + } + }, #endif - { 'h', &h_optname, - NUMBER, -1, &back_scroll, NULL, - { - "Backwards scroll limit: ", - "Backwards scroll limit is %d lines", - NULL - } - }, - { 'i', &i_optname, - TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i, - { - "Case is significant in searches", - "Ignore case in searches", - "Ignore case in searches and in patterns" - } - }, - { 'j', &j_optname, - STRING, 0, NULL, opt_j, - { - "Target line: ", - "0123456789.-", - NULL - } - }, - { 'J', &J__optname, - BOOL|REPAINT, OPT_OFF, &status_col, NULL, - { - "Don't display a status column", - "Display a status column", - NULL - } - }, + { 'h', &h_optname, + NUMBER, -1, &back_scroll, NULL, + { + "Backwards scroll limit: ", + "Backwards scroll limit is %d lines", + NULL + } + }, + { 'i', &i_optname, + TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i, + { + "Case is significant in searches", + "Ignore case in searches", + "Ignore case in searches and in patterns" + } + }, + { 'j', &j_optname, + STRING, 0, NULL, opt_j, + { + "Target line: ", + "0123456789.-", + NULL + } + }, + { 'J', &J__optname, + BOOL|REPAINT, OPT_OFF, &status_col, NULL, + { + "Don't display a status column", + "Display a status column", + NULL + } + }, #if USERFILE - { 'k', &k_optname, - STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k, - { NULL, NULL, NULL } - }, + { 'k', &k_optname, + STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k, + { NULL, NULL, NULL } + }, #endif - { 'K', &K__optname, - BOOL, OPT_OFF, &quit_on_intr, NULL, - { - "Interrupt (ctrl-C) returns to prompt", - "Interrupt (ctrl-C) exits less", - NULL - } - }, - { 'L', &L__optname, - BOOL, OPT_ON, &use_lessopen, NULL, - { - "Don't use the LESSOPEN filter", - "Use the LESSOPEN filter", - NULL - } - }, - { 'm', &m_optname, - TRIPLE, OPT_OFF, &pr_type, NULL, - { - "Short prompt", - "Medium prompt", - "Long prompt" - } - }, - { 'n', &n_optname, - TRIPLE|REPAINT, OPT_ON, &linenums, NULL, - { - "Don't use line numbers", - "Use line numbers", - "Constantly display line numbers" - } - }, + { 'K', &K__optname, + BOOL, OPT_OFF, &quit_on_intr, NULL, + { + "Interrupt (ctrl-C) returns to prompt", + "Interrupt (ctrl-C) exits less", + NULL + } + }, + { 'L', &L__optname, + BOOL, OPT_ON, &use_lessopen, NULL, + { + "Don't use the LESSOPEN filter", + "Use the LESSOPEN filter", + NULL + } + }, + { 'm', &m_optname, + TRIPLE, OPT_OFF, &pr_type, NULL, + { + "Short prompt", + "Medium prompt", + "Long prompt" + } + }, + { 'n', &n_optname, + TRIPLE|REPAINT, OPT_ON, &linenums, NULL, + { + "Don't use line numbers", + "Use line numbers", + "Constantly display line numbers" + } + }, #if LOGFILE - { 'o', &o_optname, - STRING, 0, NULL, opt_o, - { "log file: ", NULL, NULL } - }, - { 'O', &O__optname, - STRING, 0, NULL, opt__O, - { "Log file: ", NULL, NULL } - }, + { 'o', &o_optname, + STRING, 0, NULL, opt_o, + { "log file: ", NULL, NULL } + }, + { 'O', &O__optname, + STRING, 0, NULL, opt__O, + { "Log file: ", NULL, NULL } + }, #endif - { 'p', &p_optname, - STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p, - { NULL, NULL, NULL } - }, - { 'P', &P__optname, - STRING, 0, NULL, opt__P, - { "prompt: ", NULL, NULL } - }, - { 'q', &q_optname, - TRIPLE, OPT_OFF, &quiet, NULL, - { - "Ring the bell for errors AND at eof/bof", - "Ring the bell for errors but not at eof/bof", - "Never ring the bell" - } - }, - { 'r', &r_optname, - TRIPLE|REPAINT, OPT_OFF, &ctldisp, NULL, - { - "Display control characters as ^X", - "Display control characters directly", - "Display control characters directly, processing ANSI sequences" - } - }, - { 's', &s_optname, - BOOL|REPAINT, OPT_OFF, &squeeze, NULL, - { - "Display all blank lines", - "Squeeze multiple blank lines", - NULL - } - }, - { 'S', &S__optname, - BOOL|REPAINT, OPT_OFF, &chopline, NULL, - { - "Fold long lines", - "Chop long lines", - NULL - } - }, + { 'p', &p_optname, + STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p, + { NULL, NULL, NULL } + }, + { 'P', &P__optname, + STRING, 0, NULL, opt__P, + { "prompt: ", NULL, NULL } + }, + { 'q', &q_optname, + TRIPLE, OPT_OFF, &quiet, NULL, + { + "Ring the bell for errors AND at eof/bof", + "Ring the bell for errors but not at eof/bof", + "Never ring the bell" + } + }, + { 'r', &r_optname, + TRIPLE|REPAINT, OPT_OFF, &ctldisp, NULL, + { + "Display control characters as ^X", + "Display control characters directly", + "Display control characters directly, processing ANSI sequences" + } + }, + { 's', &s_optname, + BOOL|REPAINT, OPT_OFF, &squeeze, NULL, + { + "Display all blank lines", + "Squeeze multiple blank lines", + NULL + } + }, + { 'S', &S__optname, + BOOL|REPAINT, OPT_OFF, &chopline, NULL, + { + "Fold long lines", + "Chop long lines", + NULL + } + }, #if TAGS - { 't', &t_optname, - STRING|NO_QUERY, 0, NULL, opt_t, - { "tag: ", NULL, NULL } - }, - { 'T', &T__optname, - STRING, 0, NULL, opt__T, - { "tags file: ", NULL, NULL } - }, + { 't', &t_optname, + STRING|NO_QUERY, 0, NULL, opt_t, + { "tag: ", NULL, NULL } + }, + { 'T', &T__optname, + STRING, 0, NULL, opt__T, + { "tags file: ", NULL, NULL } + }, #endif - { 'u', &u_optname, - TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL, - { - "Display underlined text in underline mode", - "Backspaces cause overstrike", - "Print backspace as ^H" - } - }, - { 'V', &V__optname, - NOVAR, 0, NULL, opt__V, - { NULL, NULL, NULL } - }, - { 'w', &w_optname, - TRIPLE|REPAINT, OPT_OFF, &show_attn, NULL, - { - "Don't highlight first unread line", - "Highlight first unread line after forward-screen", - "Highlight first unread line after any forward movement", - } - }, - { 'x', &x_optname, - STRING|REPAINT, 0, NULL, opt_x, - { - "Tab stops: ", - "0123456789,", - NULL - } - }, - { 'X', &X__optname, - BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL, - { - "Send init/deinit strings to terminal", - "Don't use init/deinit strings", - NULL - } - }, - { 'y', &y_optname, - NUMBER, -1, &forw_scroll, NULL, - { - "Forward scroll limit: ", - "Forward scroll limit is %d lines", - NULL - } - }, - { 'z', &z_optname, - NUMBER, -1, &swindow, NULL, - { - "Scroll window size: ", - "Scroll window size is %d lines", - NULL - } - }, - { '"', "e_optname, - STRING, 0, NULL, opt_quote, - { "quotes: ", NULL, NULL } - }, - { '~', &tilde_optname, - BOOL|REPAINT, OPT_ON, &twiddle, NULL, - { - "Don't show tildes after end of file", - "Show tildes after end of file", - NULL - } - }, - { '?', &query_optname, - NOVAR, 0, NULL, opt_query, - { NULL, NULL, NULL } - }, - { '#', £_optname, - STRING, 0, NULL, opt_shift, - { - "Horizontal shift: ", - "0123456789.", - NULL - } - }, - { OLETTER_NONE, &keypad_optname, - BOOL|NO_TOGGLE, OPT_OFF, &no_keypad, NULL, - { - "Use keypad mode", - "Don't use keypad mode", - NULL - } - }, - { OLETTER_NONE, &oldbot_optname, - BOOL, OPT_OFF, &oldbot, NULL, - { - "Use new bottom of screen behavior", - "Use old bottom of screen behavior", - NULL - } - }, - { OLETTER_NONE, &follow_optname, - BOOL, FOLLOW_DESC, &follow_mode, NULL, - { - "F command follows file descriptor", - "F command follows file name", - NULL - } - }, - { OLETTER_NONE, &use_backslash_optname, - BOOL, OPT_OFF, &opt_use_backslash, NULL, - { - "Use backslash escaping in command line parameters", - "Don't use backslash escaping in command line parameters", - NULL - } - }, - { OLETTER_NONE, &rscroll_optname, - STRING|REPAINT|INIT_HANDLER, 0, NULL, opt_rscroll, - { "right scroll character: ", NULL, NULL } - }, - { OLETTER_NONE, &nohistdups_optname, - BOOL, OPT_OFF, &no_hist_dups, NULL, - { - "Allow duplicates in history list", - "Remove duplicates from history list", - NULL - } - }, - { OLETTER_NONE, &mousecap_optname, - TRIPLE, OPT_OFF, &mousecap, opt_mousecap, - { - "Ignore mouse input", - "Use the mouse for scrolling", - "Use the mouse for scrolling (reverse)" - } - }, - { OLETTER_NONE, &wheel_lines_optname, - NUMBER|INIT_HANDLER, 0, &wheel_lines, opt_wheel_lines, - { - "Lines to scroll on mouse wheel: ", - "Scroll %d line(s) on mouse wheel", - NULL - } - }, - { OLETTER_NONE, &perma_marks_optname, - BOOL, OPT_OFF, &perma_marks, NULL, - { - "Don't save marks in history file", - "Save marks in history file", - NULL - } - }, - { OLETTER_NONE, &linenum_width_optname, - NUMBER|REPAINT, MIN_LINENUM_WIDTH, &linenum_width, opt_linenum_width, - { - "Line number width: ", - "Line number width is %d chars", - NULL - } - }, - { OLETTER_NONE, &status_col_width_optname, - NUMBER|REPAINT, 2, &status_col_width, opt_status_col_width, - { - "Status column width: ", - "Status column width is %d chars", - NULL - } - }, - { OLETTER_NONE, &incr_search_optname, - BOOL, OPT_OFF, &incr_search, NULL, - { - "Incremental search is off", - "Incremental search is on", - NULL - } - }, - { OLETTER_NONE, &use_color_optname, - BOOL|REPAINT, OPT_OFF, &use_color, NULL, - { - "Don't use color", - "Use color", - NULL - } - }, + { 'u', &u_optname, + TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL, + { + "Display underlined text in underline mode", + "Backspaces cause overstrike", + "Print backspace as ^H" + } + }, + { 'V', &V__optname, + NOVAR, 0, NULL, opt__V, + { NULL, NULL, NULL } + }, + { 'w', &w_optname, + TRIPLE|REPAINT, OPT_OFF, &show_attn, NULL, + { + "Don't highlight first unread line", + "Highlight first unread line after forward-screen", + "Highlight first unread line after any forward movement", + } + }, + { 'x', &x_optname, + STRING|REPAINT, 0, NULL, opt_x, + { + "Tab stops: ", + "0123456789,", + NULL + } + }, + { 'X', &X__optname, + BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL, + { + "Send init/deinit strings to terminal", + "Don't use init/deinit strings", + NULL + } + }, + { 'y', &y_optname, + NUMBER, -1, &forw_scroll, NULL, + { + "Forward scroll limit: ", + "Forward scroll limit is %d lines", + NULL + } + }, + { 'z', &z_optname, + NUMBER, -1, &swindow, NULL, + { + "Scroll window size: ", + "Scroll window size is %d lines", + NULL + } + }, + { '"', "e_optname, + STRING, 0, NULL, opt_quote, + { "quotes: ", NULL, NULL } + }, + { '~', &tilde_optname, + BOOL|REPAINT, OPT_ON, &twiddle, NULL, + { + "Don't show tildes after end of file", + "Show tildes after end of file", + NULL + } + }, + { '?', &query_optname, + NOVAR, 0, NULL, opt_query, + { NULL, NULL, NULL } + }, + { '#', £_optname, + STRING, 0, NULL, opt_shift, + { + "Horizontal shift: ", + "0123456789.", + NULL + } + }, + { OLETTER_NONE, &keypad_optname, + BOOL|NO_TOGGLE, OPT_OFF, &no_keypad, NULL, + { + "Use keypad mode", + "Don't use keypad mode", + NULL + } + }, + { OLETTER_NONE, &oldbot_optname, + BOOL, OPT_OFF, &oldbot, NULL, + { + "Use new bottom of screen behavior", + "Use old bottom of screen behavior", + NULL + } + }, + { OLETTER_NONE, &follow_optname, + BOOL, FOLLOW_DESC, &follow_mode, NULL, + { + "F command follows file descriptor", + "F command follows file name", + NULL + } + }, + { OLETTER_NONE, &use_backslash_optname, + BOOL, OPT_OFF, &opt_use_backslash, NULL, + { + "Use backslash escaping in command line parameters", + "Don't use backslash escaping in command line parameters", + NULL + } + }, + { OLETTER_NONE, &rscroll_optname, + STRING|REPAINT|INIT_HANDLER, 0, NULL, opt_rscroll, + { "right scroll character: ", NULL, NULL } + }, + { OLETTER_NONE, &nohistdups_optname, + BOOL, OPT_OFF, &no_hist_dups, NULL, + { + "Allow duplicates in history list", + "Remove duplicates from history list", + NULL + } + }, + { OLETTER_NONE, &mousecap_optname, + TRIPLE, OPT_OFF, &mousecap, opt_mousecap, + { + "Ignore mouse input", + "Use the mouse for scrolling", + "Use the mouse for scrolling (reverse)" + } + }, + { OLETTER_NONE, &wheel_lines_optname, + NUMBER|INIT_HANDLER, 0, &wheel_lines, opt_wheel_lines, + { + "Lines to scroll on mouse wheel: ", + "Scroll %d line(s) on mouse wheel", + NULL + } + }, + { OLETTER_NONE, &perma_marks_optname, + BOOL, OPT_OFF, &perma_marks, NULL, + { + "Don't save marks in history file", + "Save marks in history file", + NULL + } + }, + { OLETTER_NONE, &linenum_width_optname, + NUMBER|REPAINT, MIN_LINENUM_WIDTH, &linenum_width, opt_linenum_width, + { + "Line number width: ", + "Line number width is %d chars", + NULL + } + }, + { OLETTER_NONE, &status_col_width_optname, + NUMBER|REPAINT, 2, &status_col_width, opt_status_col_width, + { + "Status column width: ", + "Status column width is %d chars", + NULL + } + }, + { OLETTER_NONE, &incr_search_optname, + BOOL, OPT_OFF, &incr_search, NULL, + { + "Incremental search is off", + "Incremental search is on", + NULL + } + }, + { OLETTER_NONE, &use_color_optname, + BOOL|REPAINT, OPT_OFF, &use_color, NULL, + { + "Don't use color", + "Use color", + NULL + } + }, #if LESSTEST - { OLETTER_NONE, &ttyin_name_optname, - STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name, - { - NULL, - NULL, - NULL - } - }, - { OLETTER_NONE, &rstat_optname, - STRING|NO_TOGGLE, 0, NULL, opt_rstat, - { - NULL, - NULL, - NULL - } - }, + { OLETTER_NONE, &ttyin_name_optname, + STRING|NO_TOGGLE, 0, NULL, opt_ttyin_name, + { + NULL, + NULL, + NULL + } + }, + { OLETTER_NONE, &rstat_optname, + STRING|NO_TOGGLE, 0, NULL, opt_rstat, + { + NULL, + NULL, + NULL + } + }, #endif /*LESSTEST*/ - { '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } } + { '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } } }; /* * Initialize each option to its default value. */ - public void + public void init_option(VOID_PARAM) { - struct loption *o; - char *p; + struct loption *o; + char *p; - p = lgetenv("LESS_IS_MORE"); - if (!isnullenv(p)) - less_is_more = 1; + p = lgetenv("LESS_IS_MORE"); + if (!isnullenv(p)) + less_is_more = 1; - for (o = option; o->oletter != '\0'; o++) - { - /* - * Set each variable to its default. - */ - if (o->ovar != NULL) - *(o->ovar) = o->odefault; - if (o->otype & INIT_HANDLER) - (*(o->ofunc))(INIT, (char *) NULL); - } + for (o = option; o->oletter != '\0'; o++) + { + /* + * Set each variable to its default. + */ + if (o->ovar != NULL) + *(o->ovar) = o->odefault; + if (o->otype & INIT_HANDLER) + (*(o->ofunc))(INIT, (char *) NULL); + } } /* * Find an option in the option table, given its option letter. */ - public struct loption * + public struct loption * findopt(c) - int c; + int c; { - struct loption *o; + struct loption *o; - for (o = option; o->oletter != '\0'; o++) - { - if (o->oletter == c) - return (o); - if ((o->otype & TRIPLE) && ASCII_TO_UPPER(o->oletter) == c) - return (o); - } - return (NULL); + for (o = option; o->oletter != '\0'; o++) + { + if (o->oletter == c) + return (o); + if ((o->otype & TRIPLE) && ASCII_TO_UPPER(o->oletter) == c) + return (o); + } + return (NULL); } /* * */ - static int + static int is_optchar(c) - char c; + char c; { - if (ASCII_IS_UPPER(c)) - return 1; - if (ASCII_IS_LOWER(c)) - return 1; - if (c == '-') - return 1; - return 0; + if (ASCII_IS_UPPER(c)) + return 1; + if (ASCII_IS_LOWER(c)) + return 1; + if (c == '-') + return 1; + return 0; } /* @@ -631,83 +631,83 @@ is_optchar(c) * is updated to point after the matched name. * p_oname if non-NULL is set to point to the full option name. */ - public struct loption * + public struct loption * findopt_name(p_optname, p_oname, p_err) - char **p_optname; - char **p_oname; - int *p_err; + char **p_optname; + char **p_oname; + int *p_err; { - char *optname = *p_optname; - struct loption *o; - struct optname *oname; - int len; - int uppercase; - struct loption *maxo = NULL; - struct optname *maxoname = NULL; - int maxlen = 0; - int ambig = 0; - int exact = 0; + char *optname = *p_optname; + struct loption *o; + struct optname *oname; + int len; + int uppercase; + struct loption *maxo = NULL; + struct optname *maxoname = NULL; + int maxlen = 0; + int ambig = 0; + int exact = 0; - /* - * Check all options. - */ - for (o = option; o->oletter != '\0'; o++) - { - /* - * Check all names for this option. - */ - for (oname = o->onames; oname != NULL; oname = oname->onext) - { - /* - * Try normal match first (uppercase == 0), - * then, then if it's a TRIPLE option, - * try uppercase match (uppercase == 1). - */ - for (uppercase = 0; uppercase <= 1; uppercase++) - { - len = sprefix(optname, oname->oname, uppercase); - if (len <= 0 || is_optchar(optname[len])) - { - /* - * We didn't use all of the option name. - */ - continue; - } - if (!exact && len == maxlen) - /* - * Already had a partial match, - * and now there's another one that - * matches the same length. - */ - ambig = 1; - else if (len > maxlen) - { - /* - * Found a better match than - * the one we had. - */ - maxo = o; - maxoname = oname; - maxlen = len; - ambig = 0; - exact = (len == (int)strlen(oname->oname)); - } - if (!(o->otype & TRIPLE)) - break; - } - } - } - if (ambig) - { - /* - * Name matched more than one option. - */ - if (p_err != NULL) - *p_err = OPT_AMBIG; - return (NULL); - } - *p_optname = optname + maxlen; - if (p_oname != NULL) - *p_oname = maxoname == NULL ? NULL : maxoname->oname; - return (maxo); + /* + * Check all options. + */ + for (o = option; o->oletter != '\0'; o++) + { + /* + * Check all names for this option. + */ + for (oname = o->onames; oname != NULL; oname = oname->onext) + { + /* + * Try normal match first (uppercase == 0), + * then, then if it's a TRIPLE option, + * try uppercase match (uppercase == 1). + */ + for (uppercase = 0; uppercase <= 1; uppercase++) + { + len = sprefix(optname, oname->oname, uppercase); + if (len <= 0 || is_optchar(optname[len])) + { + /* + * We didn't use all of the option name. + */ + continue; + } + if (!exact && len == maxlen) + /* + * Already had a partial match, + * and now there's another one that + * matches the same length. + */ + ambig = 1; + else if (len > maxlen) + { + /* + * Found a better match than + * the one we had. + */ + maxo = o; + maxoname = oname; + maxlen = len; + ambig = 0; + exact = (len == (int)strlen(oname->oname)); + } + if (!(o->otype & TRIPLE)) + break; + } + } + } + if (ambig) + { + /* + * Name matched more than one option. + */ + if (p_err != NULL) + *p_err = OPT_AMBIG; + return (NULL); + } + *p_optname = optname + maxlen; + if (p_oname != NULL) + *p_oname = maxoname == NULL ? NULL : maxoname->oname; + return (maxo); } diff --git a/os.c b/os.c index 1723787..927bc39 100644 --- a/os.c +++ b/os.c @@ -74,16 +74,16 @@ extern int tty; /* * Return true if one of the events has occurred on the specified file. */ - static int + static int poll_events(fd, events) - int fd; - int events; + int fd; + int events; { - struct pollfd poller = { fd, events, 0 }; - int n = poll(&poller, 1, 0); - if (n <= 0) - return 0; - return (poller.revents & events); + struct pollfd poller = { fd, events, 0 }; + int n = poll(&poller, 1, 0); + if (n <= 0) + return 0; + return (poller.revents & events); } #endif @@ -92,161 +92,161 @@ poll_events(fd, events) * A call to intread() from a signal handler will interrupt * any pending iread(). */ - public int + public int iread(fd, buf, len) - int fd; - unsigned char *buf; - unsigned int len; + int fd; + unsigned char *buf; + unsigned int len; { - int n; + int n; start: #if MSDOS_COMPILER==WIN32C - if (ABORT_SIGS()) - return (READ_INTR); + if (ABORT_SIGS()) + return (READ_INTR); #else #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC - if (kbhit()) - { - int c; - - c = getch(); - if (c == '\003') - return (READ_INTR); - ungetch(c); - } -#endif -#endif - if (SET_JUMP(read_label)) - { - /* - * We jumped here from intread. - */ - reading = 0; + if (kbhit()) + { + int c; + + c = getch(); + if (c == '\003') + return (READ_INTR); + ungetch(c); + } +#endif +#endif + if (SET_JUMP(read_label)) + { + /* + * We jumped here from intread. + */ + reading = 0; #if HAVE_SIGPROCMASK - { - sigset_t mask; - sigemptyset(&mask); - sigprocmask(SIG_SETMASK, &mask, NULL); - } + { + sigset_t mask; + sigemptyset(&mask); + sigprocmask(SIG_SETMASK, &mask, NULL); + } #else #if HAVE_SIGSETMASK - sigsetmask(0); + sigsetmask(0); #else #ifdef _OSK - sigmask(~0); + sigmask(~0); #endif #endif #endif - return (READ_INTR); - } + return (READ_INTR); + } - flush(); - reading = 1; + flush(); + reading = 1; #if MSDOS_COMPILER==DJGPPC - if (isatty(fd)) - { - /* - * Don't try reading from a TTY until a character is - * available, because that makes some background programs - * believe DOS is busy in a way that prevents those - * programs from working while "less" waits. - */ - fd_set readfds; - - FD_ZERO(&readfds); - FD_SET(fd, &readfds); - if (select(fd+1, &readfds, 0, 0, 0) == -1) - return (-1); - } + if (isatty(fd)) + { + /* + * Don't try reading from a TTY until a character is + * available, because that makes some background programs + * believe DOS is busy in a way that prevents those + * programs from working while "less" waits. + */ + fd_set readfds; + + FD_ZERO(&readfds); + FD_SET(fd, &readfds); + if (select(fd+1, &readfds, 0, 0, 0) == -1) + return (-1); + } #endif #if USE_POLL - if (ignore_eoi && fd != tty) - { - if (poll_events(tty, POLLIN) && getchr() == CONTROL('X')) - { - sigs |= S_INTERRUPT; - return (READ_INTR); - } - if (poll_events(fd, POLLERR|POLLHUP)) - { - sigs |= S_INTERRUPT; - return (READ_INTR); - } - } + if (ignore_eoi && fd != tty) + { + if (poll_events(tty, POLLIN) && getchr() == CONTROL('X')) + { + sigs |= S_INTERRUPT; + return (READ_INTR); + } + if (poll_events(fd, POLLERR|POLLHUP)) + { + sigs |= S_INTERRUPT; + return (READ_INTR); + } + } #else #if MSDOS_COMPILER==WIN32C - if (win32_kbhit() && WIN32getch() == CONTROL('X')) - { - sigs |= S_INTERRUPT; - return (READ_INTR); - } + if (win32_kbhit() && WIN32getch() == CONTROL('X')) + { + sigs |= S_INTERRUPT; + return (READ_INTR); + } #endif #endif - n = read(fd, buf, len); + n = read(fd, buf, len); #if 1 - /* - * This is a kludge to workaround a problem on some systems - * where terminating a remote tty connection causes read() to - * start returning 0 forever, instead of -1. - */ - { - if (!ignore_eoi) - { - static int consecutive_nulls = 0; - if (n == 0) - consecutive_nulls++; - else - consecutive_nulls = 0; - if (consecutive_nulls > 20) - quit(QUIT_ERROR); - } - } -#endif - reading = 0; - if (n < 0) - { + /* + * This is a kludge to workaround a problem on some systems + * where terminating a remote tty connection causes read() to + * start returning 0 forever, instead of -1. + */ + { + if (!ignore_eoi) + { + static int consecutive_nulls = 0; + if (n == 0) + consecutive_nulls++; + else + consecutive_nulls = 0; + if (consecutive_nulls > 20) + quit(QUIT_ERROR); + } + } +#endif + reading = 0; + if (n < 0) + { #if HAVE_ERRNO - /* - * Certain values of errno indicate we should just retry the read. - */ + /* + * Certain values of errno indicate we should just retry the read. + */ #if MUST_DEFINE_ERRNO - extern int errno; + extern int errno; #endif #ifdef EINTR - if (errno == EINTR) - goto start; + if (errno == EINTR) + goto start; #endif #ifdef EAGAIN - if (errno == EAGAIN) - goto start; + if (errno == EAGAIN) + goto start; #endif #endif - return (-1); - } - return (n); + return (-1); + } + return (n); } /* * Interrupt a pending iread(). */ - public void + public void intread(VOID_PARAM) { - LONG_JUMP(read_label, 1); + LONG_JUMP(read_label, 1); } /* * Return the current time. */ #if HAVE_TIME - public time_type + public time_type get_time(VOID_PARAM) { - time_type t; + time_type t; - time(&t); - return (t); + time(&t); + return (t); } #endif @@ -255,66 +255,66 @@ get_time(VOID_PARAM) /* * Local version of strerror, if not available from the system. */ - static char * + static char * strerror(err) - int err; + int err; { - static char buf[16]; + static char buf[16]; #if HAVE_SYS_ERRLIST - extern char *sys_errlist[]; - extern int sys_nerr; - - if (err < sys_nerr) - return sys_errlist[err]; -#endif - sprintf(buf, "Error %d", err); - return buf; + extern char *sys_errlist[]; + extern int sys_nerr; + + if (err < sys_nerr) + return sys_errlist[err]; +#endif + sprintf(buf, "Error %d", err); + return buf; } #endif /* * errno_message: Return an error message based on the value of "errno". */ - public char * + public char * errno_message(filename) - char *filename; + char *filename; { - char *p; - char *m; - int len; + char *p; + char *m; + int len; #if HAVE_ERRNO #if MUST_DEFINE_ERRNO - extern int errno; + extern int errno; #endif - p = strerror(errno); + p = strerror(errno); #else - p = "cannot open"; + p = "cannot open"; #endif - len = (int) (strlen(filename) + strlen(p) + 3); - m = (char *) ecalloc(len, sizeof(char)); - SNPRINTF2(m, len, "%s: %s", filename, p); - return (m); + len = (int) (strlen(filename) + strlen(p) + 3); + m = (char *) ecalloc(len, sizeof(char)); + SNPRINTF2(m, len, "%s: %s", filename, p); + return (m); } /* #define HAVE_FLOAT 0 */ - static POSITION + static POSITION muldiv(val, num, den) - POSITION val, num, den; + POSITION val, num, den; { #if HAVE_FLOAT - double v = (((double) val) * num) / den; - return ((POSITION) (v + 0.5)); + double v = (((double) val) * num) / den; + return ((POSITION) (v + 0.5)); #else - POSITION v = ((POSITION) val) * num; + POSITION v = ((POSITION) val) * num; - if (v / num == val) - /* No overflow */ - return (POSITION) (v / den); - else - /* Above calculation overflows; - * use a method that is less precise but won't overflow. */ - return (POSITION) (val / (den / num)); + if (v / num == val) + /* No overflow */ + return (POSITION) (v / den); + else + /* Above calculation overflows; + * use a method that is less precise but won't overflow. */ + return (POSITION) (val / (den / num)); #endif } @@ -322,63 +322,63 @@ muldiv(val, num, den) * Return the ratio of two POSITIONS, as a percentage. * {{ Assumes a POSITION is a long int. }} */ - public int + public int percentage(num, den) - POSITION num; - POSITION den; + POSITION num; + POSITION den; { - return (int) muldiv(num, (POSITION) 100, den); + return (int) muldiv(num, (POSITION) 100, den); } /* * Return the specified percentage of a POSITION. */ - public POSITION + public POSITION percent_pos(pos, percent, fraction) - POSITION pos; - int percent; - long fraction; + POSITION pos; + int percent; + long fraction; { - /* Change percent (parts per 100) to perden (parts per NUM_FRAC_DENOM). */ - POSITION perden = (percent * (NUM_FRAC_DENOM / 100)) + (fraction / 100); + /* Change percent (parts per 100) to perden (parts per NUM_FRAC_DENOM). */ + POSITION perden = (percent * (NUM_FRAC_DENOM / 100)) + (fraction / 100); - if (perden == 0) - return (0); - return (POSITION) muldiv(pos, perden, (POSITION) NUM_FRAC_DENOM); + if (perden == 0) + return (0); + return (POSITION) muldiv(pos, perden, (POSITION) NUM_FRAC_DENOM); } #if !HAVE_STRCHR /* * strchr is used by regexp.c. */ - char * + char * strchr(s, c) - char *s; - int c; + char *s; + int c; { - for ( ; *s != '\0'; s++) - if (*s == c) - return (s); - if (c == '\0') - return (s); - return (NULL); + for ( ; *s != '\0'; s++) + if (*s == c) + return (s); + if (c == '\0') + return (s); + return (NULL); } #endif #if !HAVE_MEMCPY - VOID_POINTER + VOID_POINTER memcpy(dst, src, len) - VOID_POINTER dst; - VOID_POINTER src; - int len; + VOID_POINTER dst; + VOID_POINTER src; + int len; { - char *dstp = (char *) dst; - char *srcp = (char *) src; - int i; + char *dstp = (char *) dst; + char *srcp = (char *) src; + int i; - for (i = 0; i < len; i++) - dstp[i] = srcp[i]; - return (dst); + for (i = 0; i < len; i++) + dstp[i] = srcp[i]; + return (dst); } #endif @@ -387,45 +387,45 @@ memcpy(dst, src, len) /* * This implements an ANSI-style intercept setup for Microware C 3.2 */ - public int + public int os9_signal(type, handler) - int type; - RETSIGTYPE (*handler)(); + int type; + RETSIGTYPE (*handler)(); { - intercept(handler); + intercept(handler); } #include - int + int isatty(f) - int f; + int f; { - struct sgbuf sgbuf; + struct sgbuf sgbuf; - if (_gs_opt(f, &sgbuf) < 0) - return -1; - return (sgbuf.sg_class == 0); + if (_gs_opt(f, &sgbuf) < 0) + return -1; + return (sgbuf.sg_class == 0); } - + #endif - public void + public void sleep_ms(ms) - int ms; + int ms; { #if MSDOS_COMPILER==WIN32C - Sleep(ms); + Sleep(ms); #else #if HAVE_NANOSLEEP - int sec = ms / 1000; - struct timespec t = { sec, (ms - sec*1000) * 1000000 }; - nanosleep(&t, NULL); + int sec = ms / 1000; + struct timespec t = { sec, (ms - sec*1000) * 1000000 }; + nanosleep(&t, NULL); #else #if HAVE_USLEEP - usleep(ms); + usleep(ms); #else - sleep((ms+999) / 1000); + sleep((ms+999) / 1000); #endif #endif #endif diff --git a/output.c b/output.c index ddb6ad2..3097db8 100644 --- a/output.c +++ b/output.c @@ -48,35 +48,35 @@ extern int vt_enabled; /* * Display the line which is in the line buffer. */ - public void + public void put_line(VOID_PARAM) { - int c; - int i; - int a; - - if (ABORT_SIGS()) - { - /* - * Don't output if a signal is pending. - */ - screen_trashed = 1; - return; - } - - final_attr = AT_NORMAL; - - for (i = 0; (c = gline(i, &a)) != '\0'; i++) - { - at_switch(a); - final_attr = a; - if (c == '\b') - putbs(); - else - putchr(c); - } - - at_exit(); + int c; + int i; + int a; + + if (ABORT_SIGS()) + { + /* + * Don't output if a signal is pending. + */ + screen_trashed = 1; + return; + } + + final_attr = AT_NORMAL; + + for (i = 0; (c = gline(i, &a)) != '\0'; i++) + { + at_switch(a); + final_attr = a; + if (c == '\b') + putbs(); + else + putchr(c); + } + + at_exit(); } static char obuf[OUTBUF_SIZE]; @@ -84,264 +84,264 @@ static char *ob = obuf; static int outfd = 2; /* stderr */ #if MSDOS_COMPILER==WIN32C || MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - static void + static void win_flush(VOID_PARAM) { - if (ctldisp != OPT_ONPLUS || (vt_enabled && sgr_mode)) - WIN32textout(obuf, ob - obuf); - else - { - /* - * Look for SGR escape sequences, and convert them - * to color commands. Replace bold, underline, - * and italic escapes into colors specified via - * the -D command-line option. - */ - char *anchor, *p, *p_next; - static int fg, fgi, bg, bgi; - static int at; - int f, b; + if (ctldisp != OPT_ONPLUS || (vt_enabled && sgr_mode)) + WIN32textout(obuf, ob - obuf); + else + { + /* + * Look for SGR escape sequences, and convert them + * to color commands. Replace bold, underline, + * and italic escapes into colors specified via + * the -D command-line option. + */ + char *anchor, *p, *p_next; + static int fg, fgi, bg, bgi; + static int at; + int f, b; #if MSDOS_COMPILER==WIN32C - /* Screen colors used by 3x and 4x SGR commands. */ - static unsigned char screen_color[] = { - 0, /* BLACK */ - FOREGROUND_RED, - FOREGROUND_GREEN, - FOREGROUND_RED|FOREGROUND_GREEN, - FOREGROUND_BLUE, - FOREGROUND_BLUE|FOREGROUND_RED, - FOREGROUND_BLUE|FOREGROUND_GREEN, - FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED - }; + /* Screen colors used by 3x and 4x SGR commands. */ + static unsigned char screen_color[] = { + 0, /* BLACK */ + FOREGROUND_RED, + FOREGROUND_GREEN, + FOREGROUND_RED|FOREGROUND_GREEN, + FOREGROUND_BLUE, + FOREGROUND_BLUE|FOREGROUND_RED, + FOREGROUND_BLUE|FOREGROUND_GREEN, + FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED + }; #else - static enum COLORS screen_color[] = { - BLACK, RED, GREEN, BROWN, - BLUE, MAGENTA, CYAN, LIGHTGRAY - }; + static enum COLORS screen_color[] = { + BLACK, RED, GREEN, BROWN, + BLUE, MAGENTA, CYAN, LIGHTGRAY + }; #endif - if (fg == 0 && bg == 0) - { - fg = nm_fg_color & 7; - fgi = nm_fg_color & 8; - bg = nm_bg_color & 7; - bgi = nm_bg_color & 8; - } - for (anchor = p_next = obuf; - (p_next = memchr(p_next, ESC, ob - p_next)) != NULL; ) - { - p = p_next; - if (p[1] == '[') /* "ESC-[" sequence */ - { - if (p > anchor) - { - /* - * If some chars seen since - * the last escape sequence, - * write them out to the screen. - */ - WIN32textout(anchor, p-anchor); - anchor = p; - } - p += 2; /* Skip the "ESC-[" */ - if (is_ansi_end(*p)) - { - /* - * Handle null escape sequence - * "ESC[m", which restores - * the normal color. - */ - p++; - anchor = p_next = p; - fg = nm_fg_color & 7; - fgi = nm_fg_color & 8; - bg = nm_bg_color & 7; - bgi = nm_bg_color & 8; - at = 0; - WIN32setcolors(nm_fg_color, nm_bg_color); - continue; - } - p_next = p; - at &= ~32; - - /* - * Select foreground/background colors - * based on the escape sequence. - */ - while (!is_ansi_end(*p)) - { - char *q; - long code = strtol(p, &q, 10); - - if (*q == '\0') - { - /* - * Incomplete sequence. - * Leave it unprocessed - * in the buffer. - */ - int slop = (int) (q - anchor); - /* {{ strcpy args overlap! }} */ - strcpy(obuf, anchor); - ob = &obuf[slop]; - return; - } - - if (q == p || - code > 49 || code < 0 || - (!is_ansi_end(*q) && *q != ';')) - { - p_next = q; - break; - } - if (*q == ';') - { - q++; - at |= 32; - } - - switch (code) - { - default: - /* case 0: all attrs off */ - fg = nm_fg_color & 7; - bg = nm_bg_color & 7; - at &= 32; - /* - * \e[0m use normal - * intensities, but - * \e[0;...m resets them - */ - if (at & 32) - { - fgi = 0; - bgi = 0; - } else - { - fgi = nm_fg_color & 8; - bgi = nm_bg_color & 8; - } - break; - case 1: /* bold on */ - fgi = 8; - at |= 1; - break; - case 3: /* italic on */ - case 7: /* inverse on */ - at |= 2; - break; - case 4: /* underline on */ - bgi = 8; - at |= 4; - break; - case 5: /* slow blink on */ - case 6: /* fast blink on */ - bgi = 8; - at |= 8; - break; - case 8: /* concealed on */ - at |= 16; - break; - case 22: /* bold off */ - fgi = 0; - at &= ~1; - break; - case 23: /* italic off */ - case 27: /* inverse off */ - at &= ~2; - break; - case 24: /* underline off */ - bgi = 0; - at &= ~4; - break; - case 28: /* concealed off */ - at &= ~16; - break; - case 30: case 31: case 32: - case 33: case 34: case 35: - case 36: case 37: - fg = screen_color[code - 30]; - at |= 32; - break; - case 39: /* default fg */ - fg = nm_fg_color & 7; - at |= 32; - break; - case 40: case 41: case 42: - case 43: case 44: case 45: - case 46: case 47: - bg = screen_color[code - 40]; - at |= 32; - break; - case 49: /* default bg */ - bg = nm_bg_color & 7; - at |= 32; - break; - } - p = q; - } - if (!is_ansi_end(*p) || p == p_next) - break; - /* - * In SGR mode, the ANSI sequence is - * always honored; otherwise if an attr - * is used by itself ("\e[1m" versus - * "\e[1;33m", for example), set the - * color assigned to that attribute. - */ - if (sgr_mode || (at & 32)) - { - if (at & 2) - { - f = bg | bgi; - b = fg | fgi; - } else - { - f = fg | fgi; - b = bg | bgi; - } - } else - { - if (at & 1) - { - f = bo_fg_color; - b = bo_bg_color; - } else if (at & 2) - { - f = so_fg_color; - b = so_bg_color; - } else if (at & 4) - { - f = ul_fg_color; - b = ul_bg_color; - } else if (at & 8) - { - f = bl_fg_color; - b = bl_bg_color; - } else - { - f = nm_fg_color; - b = nm_bg_color; - } - } - if (at & 16) - f = b ^ 8; + if (fg == 0 && bg == 0) + { + fg = nm_fg_color & 7; + fgi = nm_fg_color & 8; + bg = nm_bg_color & 7; + bgi = nm_bg_color & 8; + } + for (anchor = p_next = obuf; + (p_next = memchr(p_next, ESC, ob - p_next)) != NULL; ) + { + p = p_next; + if (p[1] == '[') /* "ESC-[" sequence */ + { + if (p > anchor) + { + /* + * If some chars seen since + * the last escape sequence, + * write them out to the screen. + */ + WIN32textout(anchor, p-anchor); + anchor = p; + } + p += 2; /* Skip the "ESC-[" */ + if (is_ansi_end(*p)) + { + /* + * Handle null escape sequence + * "ESC[m", which restores + * the normal color. + */ + p++; + anchor = p_next = p; + fg = nm_fg_color & 7; + fgi = nm_fg_color & 8; + bg = nm_bg_color & 7; + bgi = nm_bg_color & 8; + at = 0; + WIN32setcolors(nm_fg_color, nm_bg_color); + continue; + } + p_next = p; + at &= ~32; + + /* + * Select foreground/background colors + * based on the escape sequence. + */ + while (!is_ansi_end(*p)) + { + char *q; + long code = strtol(p, &q, 10); + + if (*q == '\0') + { + /* + * Incomplete sequence. + * Leave it unprocessed + * in the buffer. + */ + int slop = (int) (q - anchor); + /* {{ strcpy args overlap! }} */ + strcpy(obuf, anchor); + ob = &obuf[slop]; + return; + } + + if (q == p || + code > 49 || code < 0 || + (!is_ansi_end(*q) && *q != ';')) + { + p_next = q; + break; + } + if (*q == ';') + { + q++; + at |= 32; + } + + switch (code) + { + default: + /* case 0: all attrs off */ + fg = nm_fg_color & 7; + bg = nm_bg_color & 7; + at &= 32; + /* + * \e[0m use normal + * intensities, but + * \e[0;...m resets them + */ + if (at & 32) + { + fgi = 0; + bgi = 0; + } else + { + fgi = nm_fg_color & 8; + bgi = nm_bg_color & 8; + } + break; + case 1: /* bold on */ + fgi = 8; + at |= 1; + break; + case 3: /* italic on */ + case 7: /* inverse on */ + at |= 2; + break; + case 4: /* underline on */ + bgi = 8; + at |= 4; + break; + case 5: /* slow blink on */ + case 6: /* fast blink on */ + bgi = 8; + at |= 8; + break; + case 8: /* concealed on */ + at |= 16; + break; + case 22: /* bold off */ + fgi = 0; + at &= ~1; + break; + case 23: /* italic off */ + case 27: /* inverse off */ + at &= ~2; + break; + case 24: /* underline off */ + bgi = 0; + at &= ~4; + break; + case 28: /* concealed off */ + at &= ~16; + break; + case 30: case 31: case 32: + case 33: case 34: case 35: + case 36: case 37: + fg = screen_color[code - 30]; + at |= 32; + break; + case 39: /* default fg */ + fg = nm_fg_color & 7; + at |= 32; + break; + case 40: case 41: case 42: + case 43: case 44: case 45: + case 46: case 47: + bg = screen_color[code - 40]; + at |= 32; + break; + case 49: /* default bg */ + bg = nm_bg_color & 7; + at |= 32; + break; + } + p = q; + } + if (!is_ansi_end(*p) || p == p_next) + break; + /* + * In SGR mode, the ANSI sequence is + * always honored; otherwise if an attr + * is used by itself ("\e[1m" versus + * "\e[1;33m", for example), set the + * color assigned to that attribute. + */ + if (sgr_mode || (at & 32)) + { + if (at & 2) + { + f = bg | bgi; + b = fg | fgi; + } else + { + f = fg | fgi; + b = bg | bgi; + } + } else + { + if (at & 1) + { + f = bo_fg_color; + b = bo_bg_color; + } else if (at & 2) + { + f = so_fg_color; + b = so_bg_color; + } else if (at & 4) + { + f = ul_fg_color; + b = ul_bg_color; + } else if (at & 8) + { + f = bl_fg_color; + b = bl_bg_color; + } else + { + f = nm_fg_color; + b = nm_bg_color; + } + } + if (at & 16) + f = b ^ 8; #if MSDOS_COMPILER==WIN32C - f &= 0xf | COMMON_LVB_UNDERSCORE; + f &= 0xf | COMMON_LVB_UNDERSCORE; #else - f &= 0xf; + f &= 0xf; #endif - b &= 0xf; - WIN32setcolors(f, b); - p_next = anchor = p + 1; - } else - p_next++; - } - - /* Output what's left in the buffer. */ - WIN32textout(anchor, ob - anchor); - } - ob = obuf; + b &= 0xf; + WIN32setcolors(f, b); + p_next = anchor = p + 1; + } else + p_next++; + } + + /* Output what's left in the buffer. */ + WIN32textout(anchor, ob - anchor); + } + ob = obuf; } #endif @@ -361,113 +361,113 @@ win_flush(VOID_PARAM) * sure these messages can be seen before they are * overwritten or scrolled away. */ - public void + public void flush(VOID_PARAM) { - int n; + int n; - n = (int) (ob - obuf); - if (n == 0) - return; - ob = obuf; + n = (int) (ob - obuf); + if (n == 0) + return; + ob = obuf; #if MSDOS_COMPILER==MSOFTC - if (interactive()) - { - obuf[n] = '\0'; - _outtext(obuf); - return; - } + if (interactive()) + { + obuf[n] = '\0'; + _outtext(obuf); + return; + } #else #if MSDOS_COMPILER==WIN32C || MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - if (interactive()) - { - ob = obuf + n; - *ob = '\0'; - win_flush(); - return; - } + if (interactive()) + { + ob = obuf + n; + *ob = '\0'; + win_flush(); + return; + } #endif #endif - if (write(outfd, obuf, n) != n) - screen_trashed = 1; + if (write(outfd, obuf, n) != n) + screen_trashed = 1; } /* * Set the output file descriptor (1=stdout or 2=stderr). */ - public void + public void set_output(fd) - int fd; + int fd; { - flush(); - outfd = fd; + flush(); + outfd = fd; } /* * Output a character. */ - public int + public int putchr(c) - int c; + int c; { #if 0 /* fake UTF-8 output for testing */ - extern int utf_mode; - if (utf_mode) - { - static char ubuf[MAX_UTF_CHAR_LEN]; - static int ubuf_len = 0; - static int ubuf_index = 0; - if (ubuf_len == 0) - { - ubuf_len = utf_len(c); - ubuf_index = 0; - } - ubuf[ubuf_index++] = c; - if (ubuf_index < ubuf_len) - return c; - c = get_wchar(ubuf) & 0xFF; - ubuf_len = 0; - } + extern int utf_mode; + if (utf_mode) + { + static char ubuf[MAX_UTF_CHAR_LEN]; + static int ubuf_len = 0; + static int ubuf_index = 0; + if (ubuf_len == 0) + { + ubuf_len = utf_len(c); + ubuf_index = 0; + } + ubuf[ubuf_index++] = c; + if (ubuf_index < ubuf_len) + return c; + c = get_wchar(ubuf) & 0xFF; + ubuf_len = 0; + } #endif - if (need_clr) - { - need_clr = 0; - clear_bot(); - } + if (need_clr) + { + need_clr = 0; + clear_bot(); + } #if MSDOS_COMPILER - if (c == '\n' && is_tty) - { - /* remove_top(1); */ - putchr('\r'); - } + if (c == '\n' && is_tty) + { + /* remove_top(1); */ + putchr('\r'); + } #else #ifdef _OSK - if (c == '\n' && is_tty) /* In OS-9, '\n' == 0x0D */ - putchr(0x0A); + if (c == '\n' && is_tty) /* In OS-9, '\n' == 0x0D */ + putchr(0x0A); #endif #endif - /* - * Some versions of flush() write to *ob, so we must flush - * when we are still one char from the end of obuf. - */ - if (ob >= &obuf[sizeof(obuf)-1]) - flush(); - *ob++ = c; - at_prompt = 0; - return (c); + /* + * Some versions of flush() write to *ob, so we must flush + * when we are still one char from the end of obuf. + */ + if (ob >= &obuf[sizeof(obuf)-1]) + flush(); + *ob++ = c; + at_prompt = 0; + return (c); } /* * Output a string. */ - public void + public void putstr(s) - constant char *s; + constant char *s; { - while (*s != '\0') - putchr(*s++); + while (*s != '\0') + putchr(*s++); } @@ -476,19 +476,19 @@ putstr(s) */ #define TYPE_TO_A_FUNC(funcname, type) \ void funcname(num, buf) \ - type num; \ - char *buf; \ + type num; \ + char *buf; \ { \ - int neg = (num < 0); \ - char tbuf[INT_STRLEN_BOUND(num)+2]; \ - char *s = tbuf + sizeof(tbuf); \ - if (neg) num = -num; \ - *--s = '\0'; \ - do { \ - *--s = (num % 10) + '0'; \ - } while ((num /= 10) != 0); \ - if (neg) *--s = '-'; \ - strcpy(buf, s); \ + int neg = (num < 0); \ + char tbuf[INT_STRLEN_BOUND(num)+2]; \ + char *s = tbuf + sizeof(tbuf); \ + if (neg) num = -num; \ + *--s = '\0'; \ + do { \ + *--s = (num % 10) + '0'; \ + } while ((num /= 10) != 0); \ + if (neg) *--s = '-'; \ + strcpy(buf, s); \ } TYPE_TO_A_FUNC(postoa, POSITION) @@ -500,17 +500,17 @@ TYPE_TO_A_FUNC(inttoa, int) */ #define STR_TO_TYPE_FUNC(funcname, type) \ type funcname(buf, ebuf) \ - char *buf; \ - char **ebuf; \ + char *buf; \ + char **ebuf; \ { \ - type val = 0; \ - for (;; buf++) { \ - char c = *buf; \ - if (c < '0' || c > '9') break; \ - val = 10 * val + c - '0'; \ - } \ - if (ebuf != NULL) *ebuf = buf; \ - return val; \ + type val = 0; \ + for (;; buf++) { \ + char c = *buf; \ + if (c < '0' || c > '9') break; \ + val = 10 * val + c - '0'; \ + } \ + if (ebuf != NULL) *ebuf = buf; \ + return val; \ } STR_TO_TYPE_FUNC(lstrtopos, POSITION) @@ -519,29 +519,29 @@ STR_TO_TYPE_FUNC(lstrtoi, int) /* * Output an integer in a given radix. */ - static int + static int iprint_int(num) - int num; + int num; { - char buf[INT_STRLEN_BOUND(num)]; + char buf[INT_STRLEN_BOUND(num)]; - inttoa(num, buf); - putstr(buf); - return ((int) strlen(buf)); + inttoa(num, buf); + putstr(buf); + return ((int) strlen(buf)); } /* * Output a line number in a given radix. */ - static int + static int iprint_linenum(num) - LINENUM num; + LINENUM num; { - char buf[INT_STRLEN_BOUND(num)]; + char buf[INT_STRLEN_BOUND(num)]; - linenumtoa(num, buf); - putstr(buf); - return ((int) strlen(buf)); + linenumtoa(num, buf); + putstr(buf); + return ((int) strlen(buf)); } /* @@ -551,54 +551,54 @@ iprint_linenum(num) * {{ This paranoia about the portability of printf dates from experiences * with systems in the 1980s and is of course no longer necessary. }} */ - public int + public int less_printf(fmt, parg) - char *fmt; - PARG *parg; + char *fmt; + PARG *parg; { - char *s; - int col; - - col = 0; - while (*fmt != '\0') - { - if (*fmt != '%') - { - putchr(*fmt++); - col++; - } else - { - ++fmt; - switch (*fmt++) - { - case 's': - s = parg->p_string; - parg++; - while (*s != '\0') - { - putchr(*s++); - col++; - } - break; - case 'd': - col += iprint_int(parg->p_int); - parg++; - break; - case 'n': - col += iprint_linenum(parg->p_linenum); - parg++; - break; - case 'c': - putchr(parg->p_char); - col++; - break; - case '%': - putchr('%'); - break; - } - } - } - return (col); + char *s; + int col; + + col = 0; + while (*fmt != '\0') + { + if (*fmt != '%') + { + putchr(*fmt++); + col++; + } else + { + ++fmt; + switch (*fmt++) + { + case 's': + s = parg->p_string; + parg++; + while (*s != '\0') + { + putchr(*s++); + col++; + } + break; + case 'd': + col += iprint_int(parg->p_int); + parg++; + break; + case 'n': + col += iprint_linenum(parg->p_linenum); + parg++; + break; + case 'c': + putchr(parg->p_char); + col++; + break; + case '%': + putchr('%'); + break; + } + } + } + return (col); } /* @@ -606,18 +606,18 @@ less_printf(fmt, parg) * If some other non-trivial char is pressed, unget it, so it will * become the next command. */ - public void + public void get_return(VOID_PARAM) { - int c; + int c; #if ONLY_RETURN - while ((c = getchr()) != '\n' && c != '\r') - bell(); + while ((c = getchr()) != '\n' && c != '\r') + bell(); #else - c = getchr(); - if (c != '\n' && c != '\r' && c != ' ' && c != READ_INTR) - ungetcc(c); + c = getchr(); + if (c != '\n' && c != '\r' && c != ' ' && c != READ_INTR) + ungetcc(c); #endif } @@ -625,47 +625,47 @@ get_return(VOID_PARAM) * Output a message in the lower left corner of the screen * and wait for carriage return. */ - public void + public void error(fmt, parg) - char *fmt; - PARG *parg; + char *fmt; + PARG *parg; { - int col = 0; - static char return_to_continue[] = " (press RETURN)"; - - errmsgs++; - - if (!interactive()) - { - less_printf(fmt, parg); - putchr('\n'); - return; - } - - if (!oldbot) - squish_check(); - at_exit(); - clear_bot(); - at_enter(AT_STANDOUT|AT_COLOR_ERROR); - col += so_s_width; - col += less_printf(fmt, parg); - putstr(return_to_continue); - at_exit(); - col += sizeof(return_to_continue) + so_e_width; - - get_return(); - lower_left(); - clear_eol(); - - if (col >= sc_width) - /* - * Printing the message has probably scrolled the screen. - * {{ Unless the terminal doesn't have auto margins, - * in which case we just hammered on the right margin. }} - */ - screen_trashed = 1; - - flush(); + int col = 0; + static char return_to_continue[] = " (press RETURN)"; + + errmsgs++; + + if (!interactive()) + { + less_printf(fmt, parg); + putchr('\n'); + return; + } + + if (!oldbot) + squish_check(); + at_exit(); + clear_bot(); + at_enter(AT_STANDOUT|AT_COLOR_ERROR); + col += so_s_width; + col += less_printf(fmt, parg); + putstr(return_to_continue); + at_exit(); + col += sizeof(return_to_continue) + so_e_width; + + get_return(); + lower_left(); + clear_eol(); + + if (col >= sc_width) + /* + * Printing the message has probably scrolled the screen. + * {{ Unless the terminal doesn't have auto margins, + * in which case we just hammered on the right margin. }} + */ + screen_trashed = 1; + + flush(); } static char intr_to_abort[] = "... (interrupt to abort)"; @@ -676,51 +676,51 @@ static char intr_to_abort[] = "... (interrupt to abort)"; * Usually used to warn that we are beginning a potentially * time-consuming operation. */ - public void + public void ierror(fmt, parg) - char *fmt; - PARG *parg; + char *fmt; + PARG *parg; { - at_exit(); - clear_bot(); - at_enter(AT_STANDOUT|AT_COLOR_ERROR); - (void) less_printf(fmt, parg); - putstr(intr_to_abort); - at_exit(); - flush(); - need_clr = 1; + at_exit(); + clear_bot(); + at_enter(AT_STANDOUT|AT_COLOR_ERROR); + (void) less_printf(fmt, parg); + putstr(intr_to_abort); + at_exit(); + flush(); + need_clr = 1; } /* * Output a message in the lower left corner of the screen * and return a single-character response. */ - public int + public int query(fmt, parg) - char *fmt; - PARG *parg; + char *fmt; + PARG *parg; { - int c; - int col = 0; - - if (interactive()) - clear_bot(); - - (void) less_printf(fmt, parg); - c = getchr(); - - if (interactive()) - { - lower_left(); - if (col >= sc_width) - screen_trashed = 1; - flush(); - } else - { - putchr('\n'); - } - - if (c == 'Q') - quit(QUIT_OK); - return (c); + int c; + int col = 0; + + if (interactive()) + clear_bot(); + + (void) less_printf(fmt, parg); + c = getchr(); + + if (interactive()) + { + lower_left(); + if (col >= sc_width) + screen_trashed = 1; + flush(); + } else + { + putchr('\n'); + } + + if (c == 'Q') + quit(QUIT_OK); + return (c); } diff --git a/pattern.c b/pattern.c index c2266fc..fae66f7 100644 --- a/pattern.c +++ b/pattern.c @@ -19,199 +19,199 @@ extern int utf_mode; /* * Compile a search pattern, for future use by match_pattern. */ - static int + static int compile_pattern2(pattern, search_type, comp_pattern, show_error) - char *pattern; - int search_type; - PATTERN_TYPE *comp_pattern; - int show_error; + char *pattern; + int search_type; + PATTERN_TYPE *comp_pattern; + int show_error; { - if (search_type & SRCH_NO_REGEX) - return (0); + if (search_type & SRCH_NO_REGEX) + return (0); { #if HAVE_GNU_REGEX - struct re_pattern_buffer *comp = (struct re_pattern_buffer *) - ecalloc(1, sizeof(struct re_pattern_buffer)); - re_set_syntax(RE_SYNTAX_POSIX_EXTENDED); - if (re_compile_pattern(pattern, strlen(pattern), comp)) - { - free(comp); - if (show_error) - error("Invalid pattern", NULL_PARG); - return (-1); - } - if (*comp_pattern != NULL) - { - regfree(*comp_pattern); - free(*comp_pattern); - } - *comp_pattern = comp; + struct re_pattern_buffer *comp = (struct re_pattern_buffer *) + ecalloc(1, sizeof(struct re_pattern_buffer)); + re_set_syntax(RE_SYNTAX_POSIX_EXTENDED); + if (re_compile_pattern(pattern, strlen(pattern), comp)) + { + free(comp); + if (show_error) + error("Invalid pattern", NULL_PARG); + return (-1); + } + if (*comp_pattern != NULL) + { + regfree(*comp_pattern); + free(*comp_pattern); + } + *comp_pattern = comp; #endif #if HAVE_POSIX_REGCOMP - regex_t *comp = (regex_t *) ecalloc(1, sizeof(regex_t)); - if (regcomp(comp, pattern, REGCOMP_FLAG)) - { - free(comp); - if (show_error) - error("Invalid pattern", NULL_PARG); - return (-1); - } - if (*comp_pattern != NULL) - { - regfree(*comp_pattern); - free(*comp_pattern); - } - *comp_pattern = comp; + regex_t *comp = (regex_t *) ecalloc(1, sizeof(regex_t)); + if (regcomp(comp, pattern, REGCOMP_FLAG)) + { + free(comp); + if (show_error) + error("Invalid pattern", NULL_PARG); + return (-1); + } + if (*comp_pattern != NULL) + { + regfree(*comp_pattern); + free(*comp_pattern); + } + *comp_pattern = comp; #endif #if HAVE_PCRE - constant char *errstring; - int erroffset; - PARG parg; - pcre *comp = pcre_compile(pattern, - (utf_mode) ? PCRE_UTF8 | PCRE_NO_UTF8_CHECK : 0, - &errstring, &erroffset, NULL); - if (comp == NULL) - { - parg.p_string = (char *) errstring; - if (show_error) - error("%s", &parg); - return (-1); - } - *comp_pattern = comp; + constant char *errstring; + int erroffset; + PARG parg; + pcre *comp = pcre_compile(pattern, + (utf_mode) ? PCRE_UTF8 | PCRE_NO_UTF8_CHECK : 0, + &errstring, &erroffset, NULL); + if (comp == NULL) + { + parg.p_string = (char *) errstring; + if (show_error) + error("%s", &parg); + return (-1); + } + *comp_pattern = comp; #endif #if HAVE_PCRE2 - int errcode; - PCRE2_SIZE erroffset; - PARG parg; - pcre2_code *comp = pcre2_compile((PCRE2_SPTR)pattern, strlen(pattern), - 0, &errcode, &erroffset, NULL); - if (comp == NULL) - { - if (show_error) - { - char msg[160]; - pcre2_get_error_message(errcode, (PCRE2_UCHAR*)msg, sizeof(msg)); - parg.p_string = msg; - error("%s", &parg); - } - return (-1); - } - *comp_pattern = comp; + int errcode; + PCRE2_SIZE erroffset; + PARG parg; + pcre2_code *comp = pcre2_compile((PCRE2_SPTR)pattern, strlen(pattern), + 0, &errcode, &erroffset, NULL); + if (comp == NULL) + { + if (show_error) + { + char msg[160]; + pcre2_get_error_message(errcode, (PCRE2_UCHAR*)msg, sizeof(msg)); + parg.p_string = msg; + error("%s", &parg); + } + return (-1); + } + *comp_pattern = comp; #endif #if HAVE_RE_COMP - PARG parg; - if ((parg.p_string = re_comp(pattern)) != NULL) - { - if (show_error) - error("%s", &parg); - return (-1); - } - *comp_pattern = 1; + PARG parg; + if ((parg.p_string = re_comp(pattern)) != NULL) + { + if (show_error) + error("%s", &parg); + return (-1); + } + *comp_pattern = 1; #endif #if HAVE_REGCMP - char *comp; - if ((comp = regcmp(pattern, 0)) == NULL) - { - if (show_error) - error("Invalid pattern", NULL_PARG); - return (-1); - } - if (comp_pattern != NULL) - free(*comp_pattern); - *comp_pattern = comp; + char *comp; + if ((comp = regcmp(pattern, 0)) == NULL) + { + if (show_error) + error("Invalid pattern", NULL_PARG); + return (-1); + } + if (comp_pattern != NULL) + free(*comp_pattern); + *comp_pattern = comp; #endif #if HAVE_V8_REGCOMP - struct regexp *comp; - reg_show_error = show_error; - comp = regcomp(pattern); - reg_show_error = 1; - if (comp == NULL) - { - /* - * regcomp has already printed an error message - * via regerror(). - */ - return (-1); - } - if (*comp_pattern != NULL) - free(*comp_pattern); - *comp_pattern = comp; + struct regexp *comp; + reg_show_error = show_error; + comp = regcomp(pattern); + reg_show_error = 1; + if (comp == NULL) + { + /* + * regcomp has already printed an error message + * via regerror(). + */ + return (-1); + } + if (*comp_pattern != NULL) + free(*comp_pattern); + *comp_pattern = comp; #endif } - return (0); + return (0); } /* * Like compile_pattern2, but convert the pattern to lowercase if necessary. */ - public int + public int compile_pattern(pattern, search_type, show_error, comp_pattern) - char *pattern; - int search_type; - int show_error; - PATTERN_TYPE *comp_pattern; + char *pattern; + int search_type; + int show_error; + PATTERN_TYPE *comp_pattern; { - char *cvt_pattern; - int result; + char *cvt_pattern; + int result; - if (caseless != OPT_ONPLUS) - cvt_pattern = pattern; - else - { - cvt_pattern = (char*) ecalloc(1, cvt_length(strlen(pattern), CVT_TO_LC)); - cvt_text(cvt_pattern, pattern, (int *)NULL, (int *)NULL, CVT_TO_LC); - } - result = compile_pattern2(cvt_pattern, search_type, comp_pattern, show_error); - if (cvt_pattern != pattern) - free(cvt_pattern); - return (result); + if (caseless != OPT_ONPLUS) + cvt_pattern = pattern; + else + { + cvt_pattern = (char*) ecalloc(1, cvt_length(strlen(pattern), CVT_TO_LC)); + cvt_text(cvt_pattern, pattern, (int *)NULL, (int *)NULL, CVT_TO_LC); + } + result = compile_pattern2(cvt_pattern, search_type, comp_pattern, show_error); + if (cvt_pattern != pattern) + free(cvt_pattern); + return (result); } /* * Forget that we have a compiled pattern. */ - public void + public void uncompile_pattern(pattern) - PATTERN_TYPE *pattern; + PATTERN_TYPE *pattern; { #if HAVE_GNU_REGEX - if (*pattern != NULL) - { - regfree(*pattern); - free(*pattern); - } - *pattern = NULL; + if (*pattern != NULL) + { + regfree(*pattern); + free(*pattern); + } + *pattern = NULL; #endif #if HAVE_POSIX_REGCOMP - if (*pattern != NULL) - { - regfree(*pattern); - free(*pattern); - } - *pattern = NULL; + if (*pattern != NULL) + { + regfree(*pattern); + free(*pattern); + } + *pattern = NULL; #endif #if HAVE_PCRE - if (*pattern != NULL) - pcre_free(*pattern); - *pattern = NULL; + if (*pattern != NULL) + pcre_free(*pattern); + *pattern = NULL; #endif #if HAVE_PCRE2 - if (*pattern != NULL) - pcre2_code_free(*pattern); - *pattern = NULL; + if (*pattern != NULL) + pcre2_code_free(*pattern); + *pattern = NULL; #endif #if HAVE_RE_COMP - *pattern = 0; + *pattern = 0; #endif #if HAVE_REGCMP - if (*pattern != NULL) - free(*pattern); - *pattern = NULL; + if (*pattern != NULL) + free(*pattern); + *pattern = NULL; #endif #if HAVE_V8_REGCOMP - if (*pattern != NULL) - free(*pattern); - *pattern = NULL; + if (*pattern != NULL) + free(*pattern); + *pattern = NULL; #endif } @@ -219,52 +219,52 @@ uncompile_pattern(pattern) /* * Can a pattern be successfully compiled? */ - public int + public int valid_pattern(pattern) - char *pattern; + char *pattern; { - PATTERN_TYPE comp_pattern; - int result; + PATTERN_TYPE comp_pattern; + int result; - SET_NULL_PATTERN(comp_pattern); - result = compile_pattern2(pattern, 0, &comp_pattern, 0); - if (result != 0) - return (0); - uncompile_pattern(&comp_pattern); - return (1); + SET_NULL_PATTERN(comp_pattern); + result = compile_pattern2(pattern, 0, &comp_pattern, 0); + if (result != 0) + return (0); + uncompile_pattern(&comp_pattern); + return (1); } #endif /* * Is a compiled pattern null? */ - public int + public int is_null_pattern(pattern) - PATTERN_TYPE pattern; + PATTERN_TYPE pattern; { #if HAVE_GNU_REGEX - return (pattern == NULL); + return (pattern == NULL); #endif #if HAVE_POSIX_REGCOMP - return (pattern == NULL); + return (pattern == NULL); #endif #if HAVE_PCRE - return (pattern == NULL); + return (pattern == NULL); #endif #if HAVE_PCRE2 - return (pattern == NULL); + return (pattern == NULL); #endif #if HAVE_RE_COMP - return (pattern == 0); + return (pattern == 0); #endif #if HAVE_REGCMP - return (pattern == NULL); + return (pattern == NULL); #endif #if HAVE_V8_REGCOMP - return (pattern == NULL); + return (pattern == NULL); #endif #if NO_REGEX - return (pattern == NULL); + return (pattern == NULL); #endif } @@ -272,190 +272,190 @@ is_null_pattern(pattern) * Simple pattern matching function. * It supports no metacharacters like *, etc. */ - static int + static int match(pattern, pattern_len, buf, buf_len, pfound, pend) - char *pattern; - int pattern_len; - char *buf; - int buf_len; - char **pfound, **pend; + char *pattern; + int pattern_len; + char *buf; + int buf_len; + char **pfound, **pend; { - char *pp, *lp; - char *pattern_end = pattern + pattern_len; - char *buf_end = buf + buf_len; + char *pp, *lp; + char *pattern_end = pattern + pattern_len; + char *buf_end = buf + buf_len; - for ( ; buf < buf_end; buf++) - { - for (pp = pattern, lp = buf; ; pp++, lp++) - { - char cp = *pp; - char cl = *lp; - if (caseless == OPT_ONPLUS && ASCII_IS_UPPER(cp)) - cp = ASCII_TO_LOWER(cp); - if (cp != cl) - break; - if (pp == pattern_end || lp == buf_end) - break; - } - if (pp == pattern_end) - { - if (pfound != NULL) - *pfound = buf; - if (pend != NULL) - *pend = lp; - return (1); - } - } - return (0); + for ( ; buf < buf_end; buf++) + { + for (pp = pattern, lp = buf; ; pp++, lp++) + { + char cp = *pp; + char cl = *lp; + if (caseless == OPT_ONPLUS && ASCII_IS_UPPER(cp)) + cp = ASCII_TO_LOWER(cp); + if (cp != cl) + break; + if (pp == pattern_end || lp == buf_end) + break; + } + if (pp == pattern_end) + { + if (pfound != NULL) + *pfound = buf; + if (pend != NULL) + *pend = lp; + return (1); + } + } + return (0); } /* * Perform a pattern match with the previously compiled pattern. * Set sp and ep to the start and end of the matched string. */ - public int + public int match_pattern(pattern, tpattern, line, line_len, sp, ep, notbol, search_type) - PATTERN_TYPE pattern; - char *tpattern; - char *line; - int line_len; - char **sp; - char **ep; - int notbol; - int search_type; + PATTERN_TYPE pattern; + char *tpattern; + char *line; + int line_len; + char **sp; + char **ep; + int notbol; + int search_type; { - int matched; + int matched; - *sp = *ep = NULL; + *sp = *ep = NULL; #if NO_REGEX - search_type |= SRCH_NO_REGEX; + search_type |= SRCH_NO_REGEX; #endif - if (search_type & SRCH_NO_REGEX) - matched = match(tpattern, strlen(tpattern), line, line_len, sp, ep); - else - { + if (search_type & SRCH_NO_REGEX) + matched = match(tpattern, strlen(tpattern), line, line_len, sp, ep); + else + { #if HAVE_GNU_REGEX - { - struct re_registers search_regs; - pattern->not_bol = notbol; - pattern->regs_allocated = REGS_UNALLOCATED; - matched = re_search(pattern, line, line_len, 0, line_len, &search_regs) >= 0; - if (matched) - { - *sp = line + search_regs.start[0]; - *ep = line + search_regs.end[0]; - } - } + { + struct re_registers search_regs; + pattern->not_bol = notbol; + pattern->regs_allocated = REGS_UNALLOCATED; + matched = re_search(pattern, line, line_len, 0, line_len, &search_regs) >= 0; + if (matched) + { + *sp = line + search_regs.start[0]; + *ep = line + search_regs.end[0]; + } + } #endif #if HAVE_POSIX_REGCOMP - { - regmatch_t rm; - int flags = (notbol) ? REG_NOTBOL : 0; + { + regmatch_t rm; + int flags = (notbol) ? REG_NOTBOL : 0; #ifdef REG_STARTEND - flags |= REG_STARTEND; - rm.rm_so = 0; - rm.rm_eo = line_len; + flags |= REG_STARTEND; + rm.rm_so = 0; + rm.rm_eo = line_len; #endif - matched = !regexec(pattern, line, 1, &rm, flags); - if (matched) - { + matched = !regexec(pattern, line, 1, &rm, flags); + if (matched) + { #ifndef __WATCOMC__ - *sp = line + rm.rm_so; - *ep = line + rm.rm_eo; + *sp = line + rm.rm_so; + *ep = line + rm.rm_eo; #else - *sp = rm.rm_sp; - *ep = rm.rm_ep; + *sp = rm.rm_sp; + *ep = rm.rm_ep; #endif - } - } + } + } #endif #if HAVE_PCRE - { - int flags = (notbol) ? PCRE_NOTBOL : 0; - int ovector[3]; - matched = pcre_exec(pattern, NULL, line, line_len, - 0, flags, ovector, 3) >= 0; - if (matched) - { - *sp = line + ovector[0]; - *ep = line + ovector[1]; - } - } + { + int flags = (notbol) ? PCRE_NOTBOL : 0; + int ovector[3]; + matched = pcre_exec(pattern, NULL, line, line_len, + 0, flags, ovector, 3) >= 0; + if (matched) + { + *sp = line + ovector[0]; + *ep = line + ovector[1]; + } + } #endif #if HAVE_PCRE2 - { - int flags = (notbol) ? PCRE2_NOTBOL : 0; - pcre2_match_data *md = pcre2_match_data_create(3, NULL); - matched = pcre2_match(pattern, (PCRE2_SPTR)line, line_len, - 0, flags, md, NULL) >= 0; - if (matched) - { - PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(md); - *sp = line + ovector[0]; - *ep = line + ovector[1]; - } - pcre2_match_data_free(md); - } + { + int flags = (notbol) ? PCRE2_NOTBOL : 0; + pcre2_match_data *md = pcre2_match_data_create(3, NULL); + matched = pcre2_match(pattern, (PCRE2_SPTR)line, line_len, + 0, flags, md, NULL) >= 0; + if (matched) + { + PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(md); + *sp = line + ovector[0]; + *ep = line + ovector[1]; + } + pcre2_match_data_free(md); + } #endif #if HAVE_RE_COMP - matched = (re_exec(line) == 1); - /* - * re_exec doesn't seem to provide a way to get the matched string. - */ - *sp = *ep = NULL; + matched = (re_exec(line) == 1); + /* + * re_exec doesn't seem to provide a way to get the matched string. + */ + *sp = *ep = NULL; #endif #if HAVE_REGCMP - *ep = regex(pattern, line); - matched = (*ep != NULL); - if (matched) - *sp = __loc1; + *ep = regex(pattern, line); + matched = (*ep != NULL); + if (matched) + *sp = __loc1; #endif #if HAVE_V8_REGCOMP #if HAVE_REGEXEC2 - matched = regexec2(pattern, line, notbol); + matched = regexec2(pattern, line, notbol); #else - matched = regexec(pattern, line); -#endif - if (matched) - { - *sp = pattern->startp[0]; - *ep = pattern->endp[0]; - } -#endif - } - matched = (!(search_type & SRCH_NO_MATCH) && matched) || - ((search_type & SRCH_NO_MATCH) && !matched); - return (matched); + matched = regexec(pattern, line); +#endif + if (matched) + { + *sp = pattern->startp[0]; + *ep = pattern->endp[0]; + } +#endif + } + matched = (!(search_type & SRCH_NO_MATCH) && matched) || + ((search_type & SRCH_NO_MATCH) && !matched); + return (matched); } /* * Return the name of the pattern matching library. */ - public char * + public char * pattern_lib_name(VOID_PARAM) { #if HAVE_GNU_REGEX - return ("GNU"); + return ("GNU"); #else #if HAVE_POSIX_REGCOMP - return ("POSIX"); + return ("POSIX"); #else #if HAVE_PCRE2 - return ("PCRE2"); + return ("PCRE2"); #else #if HAVE_PCRE - return ("PCRE"); + return ("PCRE"); #else #if HAVE_RE_COMP - return ("BSD"); + return ("BSD"); #else #if HAVE_REGCMP - return ("V8"); + return ("V8"); #else #if HAVE_V8_REGCOMP - return ("Spencer V8"); + return ("Spencer V8"); #else - return ("no"); + return ("no"); #endif #endif #endif diff --git a/pattern.h b/pattern.h index 6cd9d1a..5bd3bfa 100644 --- a/pattern.h +++ b/pattern.h @@ -62,5 +62,5 @@ extern int reg_show_error; #if NO_REGEX #define PATTERN_TYPE void * -#define SET_NULL_PATTERN(name) +#define SET_NULL_PATTERN(name) #endif diff --git a/position.c b/position.c index 8f6edc9..eff68ea 100644 --- a/position.c +++ b/position.c @@ -14,7 +14,7 @@ * first char on each currently displayed line. * * {{ The position table is scrolled by moving all the entries. - * Would be better to have a circular table + * Would be better to have a circular table * and just change a couple of pointers. }} */ @@ -35,96 +35,96 @@ extern int sc_width, sc_height; * the bottom line on the screen * the line after the bottom line on the screen */ - public POSITION + public POSITION position(sindex) - int sindex; + int sindex; { - switch (sindex) - { - case BOTTOM: - sindex = sc_height - 2; - break; - case BOTTOM_PLUS_ONE: - sindex = sc_height - 1; - break; - case MIDDLE: - sindex = (sc_height - 1) / 2; - break; - } - return (table[sindex]); + switch (sindex) + { + case BOTTOM: + sindex = sc_height - 2; + break; + case BOTTOM_PLUS_ONE: + sindex = sc_height - 1; + break; + case MIDDLE: + sindex = (sc_height - 1) / 2; + break; + } + return (table[sindex]); } /* * Add a new file position to the bottom of the position table. */ - public void + public void add_forw_pos(pos) - POSITION pos; + POSITION pos; { - int i; + int i; - /* - * Scroll the position table up. - */ - for (i = 1; i < sc_height; i++) - table[i-1] = table[i]; - table[sc_height - 1] = pos; + /* + * Scroll the position table up. + */ + for (i = 1; i < sc_height; i++) + table[i-1] = table[i]; + table[sc_height - 1] = pos; } /* * Add a new file position to the top of the position table. */ - public void + public void add_back_pos(pos) - POSITION pos; + POSITION pos; { - int i; + int i; - /* - * Scroll the position table down. - */ - for (i = sc_height - 1; i > 0; i--) - table[i] = table[i-1]; - table[0] = pos; + /* + * Scroll the position table down. + */ + for (i = sc_height - 1; i > 0; i--) + table[i] = table[i-1]; + table[0] = pos; } /* * Initialize the position table, done whenever we clear the screen. */ - public void + public void pos_clear(VOID_PARAM) { - int i; + int i; - for (i = 0; i < sc_height; i++) - table[i] = NULL_POSITION; + for (i = 0; i < sc_height; i++) + table[i] = NULL_POSITION; } /* * Allocate or reallocate the position table. */ - public void + public void pos_init(VOID_PARAM) { - struct scrpos scrpos; + struct scrpos scrpos; - if (sc_height <= table_size) - return; - /* - * If we already have a table, remember the first line in it - * before we free it, so we can copy that line to the new table. - */ - if (table != NULL) - { - get_scrpos(&scrpos, TOP); - free((char*)table); - } else - scrpos.pos = NULL_POSITION; - table = (POSITION *) ecalloc(sc_height, sizeof(POSITION)); - table_size = sc_height; - pos_clear(); - if (scrpos.pos != NULL_POSITION) - table[scrpos.ln-1] = scrpos.pos; + if (sc_height <= table_size) + return; + /* + * If we already have a table, remember the first line in it + * before we free it, so we can copy that line to the new table. + */ + if (table != NULL) + { + get_scrpos(&scrpos, TOP); + free((char*)table); + } else + scrpos.pos = NULL_POSITION; + table = (POSITION *) ecalloc(sc_height, sizeof(POSITION)); + table_size = sc_height; + pos_clear(); + if (scrpos.pos != NULL_POSITION) + table[scrpos.ln-1] = scrpos.pos; } /* @@ -132,40 +132,40 @@ pos_init(VOID_PARAM) * Check the position table to see if the position falls within its range. * Return the position table entry if found, -1 if not. */ - public int + public int onscreen(pos) - POSITION pos; + POSITION pos; { - int i; + int i; - if (pos < table[0]) - return (-1); - for (i = 1; i < sc_height; i++) - if (pos < table[i]) - return (i-1); - return (-1); + if (pos < table[0]) + return (-1); + for (i = 1; i < sc_height; i++) + if (pos < table[i]) + return (i-1); + return (-1); } /* * See if the entire screen is empty. */ - public int + public int empty_screen(VOID_PARAM) { - return (empty_lines(0, sc_height-1)); + return (empty_lines(0, sc_height-1)); } - public int + public int empty_lines(s, e) - int s; - int e; + int s; + int e; { - int i; + int i; - for (i = s; i <= e; i++) - if (table[i] != NULL_POSITION && table[i] != 0) - return (0); - return (1); + for (i = s; i <= e; i++) + if (table[i] != NULL_POSITION && table[i] != 0) + return (0); + return (1); } /* @@ -176,51 +176,51 @@ empty_lines(s, e) * such that the top few lines are empty, we may have to set * the screen line to a number > 0. */ - public void + public void get_scrpos(scrpos, where) - struct scrpos *scrpos; - int where; + struct scrpos *scrpos; + int where; { - int i; - int dir; - int last; + int i; + int dir; + int last; - switch (where) - { - case TOP: - i = 0; dir = +1; last = sc_height-2; - break; - case BOTTOM: case BOTTOM_PLUS_ONE: - i = sc_height-2; dir = -1; last = 0; - break; - default: - i = where; - if (table[i] == NULL_POSITION) { - scrpos->pos = NULL_POSITION; - return; - } - /* Values of dir and last don't matter after this. */ - break; - } + switch (where) + { + case TOP: + i = 0; dir = +1; last = sc_height-2; + break; + case BOTTOM: case BOTTOM_PLUS_ONE: + i = sc_height-2; dir = -1; last = 0; + break; + default: + i = where; + if (table[i] == NULL_POSITION) { + scrpos->pos = NULL_POSITION; + return; + } + /* Values of dir and last don't matter after this. */ + break; + } - /* - * Find the first line on the screen which has something on it, - * and return the screen line number and the file position. - */ - for (;; i += dir) - { - if (table[i] != NULL_POSITION) - { - scrpos->ln = i+1; - scrpos->pos = table[i]; - return; - } - if (i == last) break; - } - /* - * The screen is empty. - */ - scrpos->pos = NULL_POSITION; + /* + * Find the first line on the screen which has something on it, + * and return the screen line number and the file position. + */ + for (;; i += dir) + { + if (table[i] != NULL_POSITION) + { + scrpos->ln = i+1; + scrpos->pos = table[i]; + return; + } + if (i == last) break; + } + /* + * The screen is empty. + */ + scrpos->pos = NULL_POSITION; } /* @@ -232,25 +232,25 @@ get_scrpos(scrpos, where) * or it may be in { -1 .. -(sc_height-1) } to refer to lines * relative to the bottom of the screen. */ - public int + public int sindex_from_sline(sline) - int sline; + int sline; { - /* - * Negative screen line number means - * relative to the bottom of the screen. - */ - if (sline < 0) - sline += sc_height; - /* - * Can't be less than 1 or greater than sc_height. - */ - if (sline <= 0) - sline = 1; - if (sline > sc_height) - sline = sc_height; - /* - * Return zero-based line number, not one-based. - */ - return (sline-1); + /* + * Negative screen line number means + * relative to the bottom of the screen. + */ + if (sline < 0) + sline += sc_height; + /* + * Can't be less than 1 or greater than sc_height. + */ + if (sline <= 0) + sline = 1; + if (sline > sc_height) + sline = sc_height; + /* + * Return zero-based line number, not one-based. + */ + return (sline-1); } diff --git a/prompt.c b/prompt.c index 0e38c0f..18481a4 100644 --- a/prompt.c +++ b/prompt.c @@ -13,7 +13,7 @@ * There are three flavors of prompts, SHORT, MEDIUM and LONG, * selected by the -m/-M options. * There is also the "equals message", printed by the = command. - * A prompt is a message composed of various pieces, such as the + * A prompt is a message composed of various pieces, such as the * name of the file being viewed, the percentage into the file, etc. */ @@ -65,177 +65,177 @@ static char *mp; /* * Initialize the prompt prototype strings. */ - public void + public void init_prompt(VOID_PARAM) { - prproto[0] = save(s_proto); - prproto[1] = save(less_is_more ? more_proto : m_proto); - prproto[2] = save(M_proto); - eqproto = save(e_proto); - hproto = save(h_proto); - wproto = save(w_proto); + prproto[0] = save(s_proto); + prproto[1] = save(less_is_more ? more_proto : m_proto); + prproto[2] = save(M_proto); + eqproto = save(e_proto); + hproto = save(h_proto); + wproto = save(w_proto); } /* * Append a string to the end of the message. */ - static void + static void ap_str(s) - char *s; + char *s; { - int len; - - len = (int) strlen(s); - if (mp + len >= message + PROMPT_SIZE) - len = (int) (message + PROMPT_SIZE - mp - 1); - strncpy(mp, s, len); - mp += len; - *mp = '\0'; + int len; + + len = (int) strlen(s); + if (mp + len >= message + PROMPT_SIZE) + len = (int) (message + PROMPT_SIZE - mp - 1); + strncpy(mp, s, len); + mp += len; + *mp = '\0'; } /* * Append a character to the end of the message. */ - static void + static void ap_char(c) - char c; + char c; { - char buf[2]; + char buf[2]; - buf[0] = c; - buf[1] = '\0'; - ap_str(buf); + buf[0] = c; + buf[1] = '\0'; + ap_str(buf); } /* * Append a POSITION (as a decimal integer) to the end of the message. */ - static void + static void ap_pos(pos) - POSITION pos; + POSITION pos; { - char buf[INT_STRLEN_BOUND(pos) + 2]; + char buf[INT_STRLEN_BOUND(pos) + 2]; - postoa(pos, buf); - ap_str(buf); + postoa(pos, buf); + ap_str(buf); } /* * Append a line number to the end of the message. */ - static void + static void ap_linenum(linenum) - LINENUM linenum; + LINENUM linenum; { - char buf[INT_STRLEN_BOUND(linenum) + 2]; + char buf[INT_STRLEN_BOUND(linenum) + 2]; - linenumtoa(linenum, buf); - ap_str(buf); + linenumtoa(linenum, buf); + ap_str(buf); } /* * Append an integer to the end of the message. */ - static void + static void ap_int(num) - int num; + int num; { - char buf[INT_STRLEN_BOUND(num) + 2]; + char buf[INT_STRLEN_BOUND(num) + 2]; - inttoa(num, buf); - ap_str(buf); + inttoa(num, buf); + ap_str(buf); } /* * Append a question mark to the end of the message. */ - static void + static void ap_quest(VOID_PARAM) { - ap_str("?"); + ap_str("?"); } /* * Return the "current" byte offset in the file. */ - static POSITION + static POSITION curr_byte(where) - int where; + int where; { - POSITION pos; - - pos = position(where); - while (pos == NULL_POSITION && where >= 0 && where < sc_height-1) - pos = position(++where); - if (pos == NULL_POSITION) - pos = ch_length(); - return (pos); + POSITION pos; + + pos = position(where); + while (pos == NULL_POSITION && where >= 0 && where < sc_height-1) + pos = position(++where); + if (pos == NULL_POSITION) + pos = ch_length(); + return (pos); } /* * Return the value of a prototype conditional. - * A prototype string may include conditionals which consist of a + * A prototype string may include conditionals which consist of a * question mark followed by a single letter. * Here we decode that letter and return the appropriate boolean value. */ - static int + static int cond(c, where) - char c; - int where; + char c; + int where; { - POSITION len; - - switch (c) - { - case 'a': /* Anything in the message yet? */ - return (mp > message); - case 'b': /* Current byte offset known? */ - return (curr_byte(where) != NULL_POSITION); - case 'c': - return (hshift != 0); - case 'e': /* At end of file? */ - return (eof_displayed()); - case 'f': /* Filename known? */ - case 'g': - return (strcmp(get_filename(curr_ifile), "-") != 0); - case 'l': /* Line number known? */ - case 'd': /* Same as l */ - if (!linenums) - return 0; - return (currline(where) != 0); - case 'L': /* Final line number known? */ - case 'D': /* Final page number known? */ - return (linenums && ch_length() != NULL_POSITION); - case 'm': /* More than one file? */ + POSITION len; + + switch (c) + { + case 'a': /* Anything in the message yet? */ + return (mp > message); + case 'b': /* Current byte offset known? */ + return (curr_byte(where) != NULL_POSITION); + case 'c': + return (hshift != 0); + case 'e': /* At end of file? */ + return (eof_displayed()); + case 'f': /* Filename known? */ + case 'g': + return (strcmp(get_filename(curr_ifile), "-") != 0); + case 'l': /* Line number known? */ + case 'd': /* Same as l */ + if (!linenums) + return 0; + return (currline(where) != 0); + case 'L': /* Final line number known? */ + case 'D': /* Final page number known? */ + return (linenums && ch_length() != NULL_POSITION); + case 'm': /* More than one file? */ #if TAGS - return (ntags() ? (ntags() > 1) : (nifile() > 1)); + return (ntags() ? (ntags() > 1) : (nifile() > 1)); #else - return (nifile() > 1); + return (nifile() > 1); #endif - case 'n': /* First prompt in a new file? */ + case 'n': /* First prompt in a new file? */ #if TAGS - return (ntags() ? 1 : new_file); + return (ntags() ? 1 : new_file); #else - return (new_file); + return (new_file); #endif - case 'p': /* Percent into file (bytes) known? */ - return (curr_byte(where) != NULL_POSITION && - ch_length() > 0); - case 'P': /* Percent into file (lines) known? */ - return (currline(where) != 0 && - (len = ch_length()) > 0 && - find_linenum(len) != 0); - case 's': /* Size of file known? */ - case 'B': - return (ch_length() != NULL_POSITION); - case 'x': /* Is there a "next" file? */ + case 'p': /* Percent into file (bytes) known? */ + return (curr_byte(where) != NULL_POSITION && + ch_length() > 0); + case 'P': /* Percent into file (lines) known? */ + return (currline(where) != 0 && + (len = ch_length()) > 0 && + find_linenum(len) != 0); + case 's': /* Size of file known? */ + case 'B': + return (ch_length() != NULL_POSITION); + case 'x': /* Is there a "next" file? */ #if TAGS - if (ntags()) - return (0); + if (ntags()) + return (0); #endif - return (next_ifile(curr_ifile) != NULL_IFILE); - } - return (0); + return (next_ifile(curr_ifile) != NULL_IFILE); + } + return (0); } /* @@ -245,324 +245,324 @@ cond(c, where) * Here we decode that letter and take the appropriate action, * usually by appending something to the message being built. */ - static void + static void protochar(c, where, iseditproto) - int c; - int where; - int iseditproto; + int c; + int where; + int iseditproto; { - POSITION pos; - POSITION len; - int n; - LINENUM linenum; - LINENUM last_linenum; - IFILE h; - char *s; + POSITION pos; + POSITION len; + int n; + LINENUM linenum; + LINENUM last_linenum; + IFILE h; + char *s; #undef PAGE_NUM #define PAGE_NUM(linenum) ((((linenum) - 1) / (sc_height - 1)) + 1) - switch (c) - { - case 'b': /* Current byte offset */ - pos = curr_byte(where); - if (pos != NULL_POSITION) - ap_pos(pos); - else - ap_quest(); - break; - case 'c': - ap_int(hshift); - break; - case 'd': /* Current page number */ - linenum = currline(where); - if (linenum > 0 && sc_height > 1) - ap_linenum(PAGE_NUM(linenum)); - else - ap_quest(); - break; - case 'D': /* Final page number */ - /* Find the page number of the last byte in the file (len-1). */ - len = ch_length(); - if (len == NULL_POSITION) - ap_quest(); - else if (len == 0) - /* An empty file has no pages. */ - ap_linenum(0); - else - { - linenum = find_linenum(len - 1); - if (linenum <= 0) - ap_quest(); - else - ap_linenum(PAGE_NUM(linenum)); - } - break; + switch (c) + { + case 'b': /* Current byte offset */ + pos = curr_byte(where); + if (pos != NULL_POSITION) + ap_pos(pos); + else + ap_quest(); + break; + case 'c': + ap_int(hshift); + break; + case 'd': /* Current page number */ + linenum = currline(where); + if (linenum > 0 && sc_height > 1) + ap_linenum(PAGE_NUM(linenum)); + else + ap_quest(); + break; + case 'D': /* Final page number */ + /* Find the page number of the last byte in the file (len-1). */ + len = ch_length(); + if (len == NULL_POSITION) + ap_quest(); + else if (len == 0) + /* An empty file has no pages. */ + ap_linenum(0); + else + { + linenum = find_linenum(len - 1); + if (linenum <= 0) + ap_quest(); + else + ap_linenum(PAGE_NUM(linenum)); + } + break; #if EDITOR - case 'E': /* Editor name */ - ap_str(editor); - break; + case 'E': /* Editor name */ + ap_str(editor); + break; #endif - case 'f': /* File name */ - ap_str(get_filename(curr_ifile)); - break; - case 'F': /* Last component of file name */ - ap_str(last_component(get_filename(curr_ifile))); - break; - case 'g': /* Shell-escaped file name */ - s = shell_quote(get_filename(curr_ifile)); - ap_str(s); - free(s); - break; - case 'i': /* Index into list of files */ + case 'f': /* File name */ + ap_str(get_filename(curr_ifile)); + break; + case 'F': /* Last component of file name */ + ap_str(last_component(get_filename(curr_ifile))); + break; + case 'g': /* Shell-escaped file name */ + s = shell_quote(get_filename(curr_ifile)); + ap_str(s); + free(s); + break; + case 'i': /* Index into list of files */ #if TAGS - if (ntags()) - ap_int(curr_tag()); - else + if (ntags()) + ap_int(curr_tag()); + else #endif - ap_int(get_index(curr_ifile)); - break; - case 'l': /* Current line number */ - linenum = currline(where); - if (linenum != 0) - ap_linenum(linenum); - else - ap_quest(); - break; - case 'L': /* Final line number */ - len = ch_length(); - if (len == NULL_POSITION || len == ch_zero() || - (linenum = find_linenum(len)) <= 0) - ap_quest(); - else - ap_linenum(linenum-1); - break; - case 'm': /* Number of files */ + ap_int(get_index(curr_ifile)); + break; + case 'l': /* Current line number */ + linenum = currline(where); + if (linenum != 0) + ap_linenum(linenum); + else + ap_quest(); + break; + case 'L': /* Final line number */ + len = ch_length(); + if (len == NULL_POSITION || len == ch_zero() || + (linenum = find_linenum(len)) <= 0) + ap_quest(); + else + ap_linenum(linenum-1); + break; + case 'm': /* Number of files */ #if TAGS - n = ntags(); - if (n) - ap_int(n); - else + n = ntags(); + if (n) + ap_int(n); + else #endif - ap_int(nifile()); - break; - case 'p': /* Percent into file (bytes) */ - pos = curr_byte(where); - len = ch_length(); - if (pos != NULL_POSITION && len > 0) - ap_int(percentage(pos,len)); - else - ap_quest(); - break; - case 'P': /* Percent into file (lines) */ - linenum = currline(where); - if (linenum == 0 || - (len = ch_length()) == NULL_POSITION || len == ch_zero() || - (last_linenum = find_linenum(len)) <= 0) - ap_quest(); - else - ap_int(percentage(linenum, last_linenum)); - break; - case 's': /* Size of file */ - case 'B': - len = ch_length(); - if (len != NULL_POSITION) - ap_pos(len); - else - ap_quest(); - break; - case 't': /* Truncate trailing spaces in the message */ - while (mp > message && mp[-1] == ' ') - mp--; - *mp = '\0'; - break; - case 'T': /* Type of list */ + ap_int(nifile()); + break; + case 'p': /* Percent into file (bytes) */ + pos = curr_byte(where); + len = ch_length(); + if (pos != NULL_POSITION && len > 0) + ap_int(percentage(pos,len)); + else + ap_quest(); + break; + case 'P': /* Percent into file (lines) */ + linenum = currline(where); + if (linenum == 0 || + (len = ch_length()) == NULL_POSITION || len == ch_zero() || + (last_linenum = find_linenum(len)) <= 0) + ap_quest(); + else + ap_int(percentage(linenum, last_linenum)); + break; + case 's': /* Size of file */ + case 'B': + len = ch_length(); + if (len != NULL_POSITION) + ap_pos(len); + else + ap_quest(); + break; + case 't': /* Truncate trailing spaces in the message */ + while (mp > message && mp[-1] == ' ') + mp--; + *mp = '\0'; + break; + case 'T': /* Type of list */ #if TAGS - if (ntags()) - ap_str("tag"); - else + if (ntags()) + ap_str("tag"); + else #endif - ap_str("file"); - break; - case 'x': /* Name of next file */ - h = next_ifile(curr_ifile); - if (h != NULL_IFILE) - ap_str(get_filename(h)); - else - ap_quest(); - break; - } + ap_str("file"); + break; + case 'x': /* Name of next file */ + h = next_ifile(curr_ifile); + if (h != NULL_IFILE) + ap_str(get_filename(h)); + else + ap_quest(); + break; + } } /* * Skip a false conditional. - * When a false condition is found (either a false IF or the ELSE part + * When a false condition is found (either a false IF or the ELSE part * of a true IF), this routine scans the prototype string to decide * where to resume parsing the string. * We must keep track of nested IFs and skip them properly. */ - static constant char * + static constant char * skipcond(p) - constant char *p; + constant char *p; { - int iflevel; - - /* - * We came in here after processing a ? or :, - * so we start nested one level deep. - */ - iflevel = 1; - - for (;;) switch (*++p) - { - case '?': - /* - * Start of a nested IF. - */ - iflevel++; - break; - case ':': - /* - * Else. - * If this matches the IF we came in here with, - * then we're done. - */ - if (iflevel == 1) - return (p); - break; - case '.': - /* - * Endif. - * If this matches the IF we came in here with, - * then we're done. - */ - if (--iflevel == 0) - return (p); - break; - case '\\': - /* - * Backslash escapes the next character. - */ - ++p; - break; - case '\0': - /* - * Whoops. Hit end of string. - * This is a malformed conditional, but just treat it - * as if all active conditionals ends here. - */ - return (p-1); - } - /*NOTREACHED*/ + int iflevel; + + /* + * We came in here after processing a ? or :, + * so we start nested one level deep. + */ + iflevel = 1; + + for (;;) switch (*++p) + { + case '?': + /* + * Start of a nested IF. + */ + iflevel++; + break; + case ':': + /* + * Else. + * If this matches the IF we came in here with, + * then we're done. + */ + if (iflevel == 1) + return (p); + break; + case '.': + /* + * Endif. + * If this matches the IF we came in here with, + * then we're done. + */ + if (--iflevel == 0) + return (p); + break; + case '\\': + /* + * Backslash escapes the next character. + */ + ++p; + break; + case '\0': + /* + * Whoops. Hit end of string. + * This is a malformed conditional, but just treat it + * as if all active conditionals ends here. + */ + return (p-1); + } + /*NOTREACHED*/ } /* * Decode a char that represents a position on the screen. */ - static constant char * + static constant char * wherechar(p, wp) - char constant *p; - int *wp; + char constant *p; + int *wp; { - switch (*p) - { - case 'b': case 'd': case 'l': case 'p': case 'P': - switch (*++p) - { - case 't': *wp = TOP; break; - case 'm': *wp = MIDDLE; break; - case 'b': *wp = BOTTOM; break; - case 'B': *wp = BOTTOM_PLUS_ONE; break; - case 'j': *wp = sindex_from_sline(jump_sline); break; - default: *wp = TOP; p--; break; - } - } - return (p); + switch (*p) + { + case 'b': case 'd': case 'l': case 'p': case 'P': + switch (*++p) + { + case 't': *wp = TOP; break; + case 'm': *wp = MIDDLE; break; + case 'b': *wp = BOTTOM; break; + case 'B': *wp = BOTTOM_PLUS_ONE; break; + case 'j': *wp = sindex_from_sline(jump_sline); break; + default: *wp = TOP; p--; break; + } + } + return (p); } /* * Construct a message based on a prototype string. */ - public char * + public char * pr_expand(proto, maxwidth) - constant char *proto; - int maxwidth; + constant char *proto; + int maxwidth; { - constant char *p; - int c; - int where; - - mp = message; - - if (*proto == '\0') - return (""); - - for (p = proto; *p != '\0'; p++) - { - switch (*p) - { - default: /* Just put the character in the message */ - ap_char(*p); - break; - case '\\': /* Backslash escapes the next character */ - p++; - ap_char(*p); - break; - case '?': /* Conditional (IF) */ - if ((c = *++p) == '\0') - --p; - else - { - where = 0; - p = wherechar(p, &where); - if (!cond(c, where)) - p = skipcond(p); - } - break; - case ':': /* ELSE */ - p = skipcond(p); - break; - case '.': /* ENDIF */ - break; - case '%': /* Percent escape */ - if ((c = *++p) == '\0') - --p; - else - { - where = 0; - p = wherechar(p, &where); - protochar(c, where, + constant char *p; + int c; + int where; + + mp = message; + + if (*proto == '\0') + return (""); + + for (p = proto; *p != '\0'; p++) + { + switch (*p) + { + default: /* Just put the character in the message */ + ap_char(*p); + break; + case '\\': /* Backslash escapes the next character */ + p++; + ap_char(*p); + break; + case '?': /* Conditional (IF) */ + if ((c = *++p) == '\0') + --p; + else + { + where = 0; + p = wherechar(p, &where); + if (!cond(c, where)) + p = skipcond(p); + } + break; + case ':': /* ELSE */ + p = skipcond(p); + break; + case '.': /* ENDIF */ + break; + case '%': /* Percent escape */ + if ((c = *++p) == '\0') + --p; + else + { + where = 0; + p = wherechar(p, &where); + protochar(c, where, #if EDITOR - (proto == editproto)); + (proto == editproto)); #else - 0); + 0); #endif - } - break; - } - } - - if (mp == message) - return (""); - if (maxwidth > 0 && mp >= message + maxwidth) - { - /* - * Message is too long. - * Return just the final portion of it. - */ - return (mp - maxwidth); - } - return (message); + } + break; + } + } + + if (mp == message) + return (""); + if (maxwidth > 0 && mp >= message + maxwidth) + { + /* + * Message is too long. + * Return just the final portion of it. + */ + return (mp - maxwidth); + } + return (message); } /* * Return a message suitable for printing by the "=" command. */ - public char * + public char * eq_message(VOID_PARAM) { - return (pr_expand(eqproto, 0)); + return (pr_expand(eqproto, 0)); } /* @@ -571,25 +571,25 @@ eq_message(VOID_PARAM) * If we can't come up with an appropriate prompt, return NULL * and the caller will prompt with a colon. */ - public char * + public char * pr_string(VOID_PARAM) { - char *prompt; - int type; - - type = (!less_is_more) ? pr_type : pr_type ? 0 : 1; - prompt = pr_expand((ch_getflags() & CH_HELPFILE) ? - hproto : prproto[type], - sc_width-so_s_width-so_e_width-2); - new_file = 0; - return (prompt); + char *prompt; + int type; + + type = (!less_is_more) ? pr_type : pr_type ? 0 : 1; + prompt = pr_expand((ch_getflags() & CH_HELPFILE) ? + hproto : prproto[type], + sc_width-so_s_width-so_e_width-2); + new_file = 0; + return (prompt); } /* * Return a message suitable for printing while waiting in the F command. */ - public char * + public char * wait_message(VOID_PARAM) { - return (pr_expand(wproto, sc_width-so_s_width-so_e_width-2)); + return (pr_expand(wproto, sc_width-so_s_width-so_e_width-2)); } diff --git a/regexp.c b/regexp.c index fcf7c9a..17f6a83 100644 --- a/regexp.c +++ b/regexp.c @@ -1,22 +1,22 @@ /* * regcomp and regexec -- regsub and regerror are elsewhere * - * Copyright (c) 1986 by University of Toronto. - * Written by Henry Spencer. Not derived from licensed software. + * Copyright (c) 1986 by University of Toronto. + * Written by Henry Spencer. Not derived from licensed software. * - * Permission is granted to anyone to use this software for any - * purpose on any computer system, and to redistribute it freely, - * subject to the following restrictions: + * Permission is granted to anyone to use this software for any + * purpose on any computer system, and to redistribute it freely, + * subject to the following restrictions: * - * 1. The author is not responsible for the consequences of use of - * this software, no matter how awful, even if they arise - * from defects in it. + * 1. The author is not responsible for the consequences of use of + * this software, no matter how awful, even if they arise + * from defects in it. * - * 2. The origin of this software must not be misrepresented, either - * by explicit claim or by omission. + * 2. The origin of this software must not be misrepresented, either + * by explicit claim or by omission. * - * 3. Altered versions must be plainly marked as such, and must not - * be misrepresented as being the original software. + * 3. Altered versions must be plainly marked as such, and must not + * be misrepresented as being the original software. * * Beware that some of this code is subtly aware of the way operator * precedence is structured in regular expressions. Serious changes in @@ -44,10 +44,10 @@ * compile to execute that permits the execute phase to run lots faster on * simple cases. They are: * - * regstart char that must begin a match; '\0' if none obvious - * reganch is the match anchored (at beginning-of-line only)? - * regmust string (pointer into program) that match must include, or NULL - * regmlen length of regmust string + * regstart char that must begin a match; '\0' if none obvious + * reganch is the match anchored (at beginning-of-line only)? + * regmust string (pointer into program) that match must include, or NULL + * regmlen length of regmust string * * Regstart and reganch permit very fast decisions on suitable starting points * for a match, cutting down the work a lot. Regmust permits fast rejection @@ -75,44 +75,44 @@ * to the thing following the set of BRANCHes.) The opcodes are: */ -/* definition number opnd? meaning */ +/* definition number opnd? meaning */ #undef EOL -#define END 0 /* no End of program. */ -#define BOL 1 /* no Match "" at beginning of line. */ -#define EOL 2 /* no Match "" at end of line. */ -#define ANY 3 /* no Match any one character. */ -#define ANYOF 4 /* str Match any character in this string. */ -#define ANYBUT 5 /* str Match any character not in this string. */ -#define BRANCH 6 /* node Match this alternative, or the next... */ -#define BACK 7 /* no Match "", "next" ptr points backward. */ -#define EXACTLY 8 /* str Match this string. */ -#define NOTHING 9 /* no Match empty string. */ -#define STAR 10 /* node Match this (simple) thing 0 or more times. */ -#define PLUS 11 /* node Match this (simple) thing 1 or more times. */ -#define OPEN 20 /* no Mark this point in input as start of #n. */ - /* OPEN+1 is number 1, etc. */ -#define CLOSE 30 /* no Analogous to OPEN. */ +#define END 0 /* no End of program. */ +#define BOL 1 /* no Match "" at beginning of line. */ +#define EOL 2 /* no Match "" at end of line. */ +#define ANY 3 /* no Match any one character. */ +#define ANYOF 4 /* str Match any character in this string. */ +#define ANYBUT 5 /* str Match any character not in this string. */ +#define BRANCH 6 /* node Match this alternative, or the next... */ +#define BACK 7 /* no Match "", "next" ptr points backward. */ +#define EXACTLY 8 /* str Match this string. */ +#define NOTHING 9 /* no Match empty string. */ +#define STAR 10 /* node Match this (simple) thing 0 or more times. */ +#define PLUS 11 /* node Match this (simple) thing 1 or more times. */ +#define OPEN 20 /* no Mark this point in input as start of #n. */ + /* OPEN+1 is number 1, etc. */ +#define CLOSE 30 /* no Analogous to OPEN. */ /* * Opcode notes: * - * BRANCH The set of branches constituting a single choice are hooked - * together with their "next" pointers, since precedence prevents - * anything being concatenated to any individual branch. The - * "next" pointer of the last BRANCH in a choice points to the - * thing following the whole choice. This is also where the - * final "next" pointer of each individual branch points; each - * branch starts with the operand node of a BRANCH node. + * BRANCH The set of branches constituting a single choice are hooked + * together with their "next" pointers, since precedence prevents + * anything being concatenated to any individual branch. The + * "next" pointer of the last BRANCH in a choice points to the + * thing following the whole choice. This is also where the + * final "next" pointer of each individual branch points; each + * branch starts with the operand node of a BRANCH node. * - * BACK Normal "next" pointers all implicitly point forward; BACK - * exists to make loop structures possible. + * BACK Normal "next" pointers all implicitly point forward; BACK + * exists to make loop structures possible. * - * STAR,PLUS '?', and complex '*' and '+', are implemented as circular - * BRANCH structures using BACK. Simple cases (one character - * per match) are implemented with STAR and PLUS for speed - * and to minimize recursive plunges. + * STAR,PLUS '?', and complex '*' and '+', are implemented as circular + * BRANCH structures using BACK. Simple cases (one character + * per match) are implemented with STAR and PLUS for speed + * and to minimize recursive plunges. * - * OPEN,CLOSE ...are numbered at compile time. + * OPEN,CLOSE ...are numbered at compile time. */ /* @@ -125,9 +125,9 @@ * Using two bytes for the "next" pointer is vast overkill for most things, * but allows patterns to get big without disasters. */ -#define OP(p) (*(p)) -#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377)) -#define OPERAND(p) ((p) + 3) +#define OP(p) (*(p)) +#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377)) +#define OPERAND(p) ((p) + 3) /* * See regmagic.h for one further detail of program structure. @@ -138,44 +138,44 @@ * Utility definitions. */ #ifndef CHARBITS -#define UCHARAT(p) ((int)*(unsigned char *)(p)) +#define UCHARAT(p) ((int)*(unsigned char *)(p)) #else -#define UCHARAT(p) ((int)*(p)&CHARBITS) +#define UCHARAT(p) ((int)*(p)&CHARBITS) #endif -#define FAIL(m) { regerror(m); return(NULL); } -#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?') -#define META "^$.[()|?+*\\" +#define FAIL(m) { regerror(m); return(NULL); } +#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?') +#define META "^$.[()|?+*\\" /* * Flags to be passed up and down. */ -#define HASWIDTH 01 /* Known never to match null string. */ -#define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */ -#define SPSTART 04 /* Starts with * or +. */ -#define WORST 0 /* Worst case. */ +#define HASWIDTH 01 /* Known never to match null string. */ +#define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */ +#define SPSTART 04 /* Starts with * or +. */ +#define WORST 0 /* Worst case. */ /* * Global work variables for regcomp(). */ -static char *regparse; /* Input-scan pointer. */ -static int regnpar; /* () count. */ +static char *regparse; /* Input-scan pointer. */ +static int regnpar; /* () count. */ static char regdummy; -static char *regcode; /* Code-emit pointer; ®dummy = don't. */ -static long regsize; /* Code size. */ +static char *regcode; /* Code-emit pointer; ®dummy = don't. */ +static long regsize; /* Code size. */ /* * The first byte of the regexp internal "program" is actually this magic * number; the start node begins in the second byte. */ -#define MAGIC 0234 +#define MAGIC 0234 /* * Forward declarations for regcomp()'s friends. */ #ifndef STATIC -#define STATIC static +#define STATIC static #endif STATIC char *reg(); STATIC char *regbranch(); @@ -210,81 +210,81 @@ regexp * regcomp(exp) char *exp; { - register regexp *r; - register char *scan; - register char *longest; - register int len; - int flags; - - if (exp == NULL) - FAIL("NULL argument"); - - /* First pass: determine size, legality. */ - regparse = exp; - regnpar = 1; - regsize = 0L; - regcode = ®dummy; - regc(MAGIC); - if (reg(0, &flags) == NULL) - return(NULL); - - /* Small enough for pointer-storage convention? */ - if (regsize >= 32767L) /* Probably could be 65535L. */ - FAIL("regexp too big"); - - /* Allocate space. */ - r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize); - if (r == NULL) - FAIL("out of space"); - - /* Second pass: emit code. */ - regparse = exp; - regnpar = 1; - regcode = r->program; - regc(MAGIC); - if (reg(0, &flags) == NULL) - { - free(r); - return(NULL); - } - - /* Dig out information for optimizations. */ - r->regstart = '\0'; /* Worst-case defaults. */ - r->reganch = 0; - r->regmust = NULL; - r->regmlen = 0; - scan = r->program+1; /* First BRANCH. */ - if (OP(regnext(scan)) == END) { /* Only one top-level choice. */ - scan = OPERAND(scan); - - /* Starting-point info. */ - if (OP(scan) == EXACTLY) - r->regstart = *OPERAND(scan); - else if (OP(scan) == BOL) - r->reganch++; - - /* - * If there's something expensive in the r.e., find the - * longest literal string that must appear and make it the - * regmust. Resolve ties in favor of later strings, since - * the regstart check works with the beginning of the r.e. - * and avoiding duplication strengthens checking. Not a - * strong reason, but sufficient in the absence of others. - */ - if (flags&SPSTART) { - longest = NULL; - len = 0; - for (; scan != NULL; scan = regnext(scan)) - if (OP(scan) == EXACTLY && ((int) strlen(OPERAND(scan))) >= len) { - longest = OPERAND(scan); - len = (int) strlen(OPERAND(scan)); - } - r->regmust = longest; - r->regmlen = len; - } - } - - return(r); + register regexp *r; + register char *scan; + register char *longest; + register int len; + int flags; + + if (exp == NULL) + FAIL("NULL argument"); + + /* First pass: determine size, legality. */ + regparse = exp; + regnpar = 1; + regsize = 0L; + regcode = ®dummy; + regc(MAGIC); + if (reg(0, &flags) == NULL) + return(NULL); + + /* Small enough for pointer-storage convention? */ + if (regsize >= 32767L) /* Probably could be 65535L. */ + FAIL("regexp too big"); + + /* Allocate space. */ + r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize); + if (r == NULL) + FAIL("out of space"); + + /* Second pass: emit code. */ + regparse = exp; + regnpar = 1; + regcode = r->program; + regc(MAGIC); + if (reg(0, &flags) == NULL) + { + free(r); + return(NULL); + } + + /* Dig out information for optimizations. */ + r->regstart = '\0'; /* Worst-case defaults. */ + r->reganch = 0; + r->regmust = NULL; + r->regmlen = 0; + scan = r->program+1; /* First BRANCH. */ + if (OP(regnext(scan)) == END) { /* Only one top-level choice. */ + scan = OPERAND(scan); + + /* Starting-point info. */ + if (OP(scan) == EXACTLY) + r->regstart = *OPERAND(scan); + else if (OP(scan) == BOL) + r->reganch++; + + /* + * If there's something expensive in the r.e., find the + * longest literal string that must appear and make it the + * regmust. Resolve ties in favor of later strings, since + * the regstart check works with the beginning of the r.e. + * and avoiding duplication strengthens checking. Not a + * strong reason, but sufficient in the absence of others. + */ + if (flags&SPSTART) { + longest = NULL; + len = 0; + for (; scan != NULL; scan = regnext(scan)) + if (OP(scan) == EXACTLY && ((int) strlen(OPERAND(scan))) >= len) { + longest = OPERAND(scan); + len = (int) strlen(OPERAND(scan)); + } + r->regmust = longest; + r->regmlen = len; + } + } + + return(r); } /* @@ -298,69 +298,69 @@ char *exp; */ static char * reg(paren, flagp) -int paren; /* Parenthesized? */ +int paren; /* Parenthesized? */ int *flagp; { - register char *ret; - register char *br; - register char *ender; - register int parno = 0; - int flags; - - *flagp = HASWIDTH; /* Tentatively. */ - - /* Make an OPEN node, if parenthesized. */ - if (paren) { - if (regnpar >= NSUBEXP) - FAIL("too many ()"); - parno = regnpar; - regnpar++; - ret = regnode(OPEN+parno); - } else - ret = NULL; - - /* Pick up the branches, linking them together. */ - br = regbranch(&flags); - if (br == NULL) - return(NULL); - if (ret != NULL) - regtail(ret, br); /* OPEN -> first. */ - else - ret = br; - if (!(flags&HASWIDTH)) - *flagp &= ~HASWIDTH; - *flagp |= flags&SPSTART; - while (*regparse == '|') { - regparse++; - br = regbranch(&flags); - if (br == NULL) - return(NULL); - regtail(ret, br); /* BRANCH -> BRANCH. */ - if (!(flags&HASWIDTH)) - *flagp &= ~HASWIDTH; - *flagp |= flags&SPSTART; - } - - /* Make a closing node, and hook it on the end. */ - ender = regnode((paren) ? CLOSE+parno : END); - regtail(ret, ender); - - /* Hook the tails of the branches to the closing node. */ - for (br = ret; br != NULL; br = regnext(br)) - regoptail(br, ender); - - /* Check for proper termination. */ - if (paren && *regparse++ != ')') { - FAIL("unmatched ()"); - } else if (!paren && *regparse != '\0') { - if (*regparse == ')') { - FAIL("unmatched ()"); - } else - FAIL("junk on end"); /* "Can't happen". */ - /* NOTREACHED */ - } - - return(ret); + register char *ret; + register char *br; + register char *ender; + register int parno = 0; + int flags; + + *flagp = HASWIDTH; /* Tentatively. */ + + /* Make an OPEN node, if parenthesized. */ + if (paren) { + if (regnpar >= NSUBEXP) + FAIL("too many ()"); + parno = regnpar; + regnpar++; + ret = regnode(OPEN+parno); + } else + ret = NULL; + + /* Pick up the branches, linking them together. */ + br = regbranch(&flags); + if (br == NULL) + return(NULL); + if (ret != NULL) + regtail(ret, br); /* OPEN -> first. */ + else + ret = br; + if (!(flags&HASWIDTH)) + *flagp &= ~HASWIDTH; + *flagp |= flags&SPSTART; + while (*regparse == '|') { + regparse++; + br = regbranch(&flags); + if (br == NULL) + return(NULL); + regtail(ret, br); /* BRANCH -> BRANCH. */ + if (!(flags&HASWIDTH)) + *flagp &= ~HASWIDTH; + *flagp |= flags&SPSTART; + } + + /* Make a closing node, and hook it on the end. */ + ender = regnode((paren) ? CLOSE+parno : END); + regtail(ret, ender); + + /* Hook the tails of the branches to the closing node. */ + for (br = ret; br != NULL; br = regnext(br)) + regoptail(br, ender); + + /* Check for proper termination. */ + if (paren && *regparse++ != ')') { + FAIL("unmatched ()"); + } else if (!paren && *regparse != '\0') { + if (*regparse == ')') { + FAIL("unmatched ()"); + } else + FAIL("junk on end"); /* "Can't happen". */ + /* NOTREACHED */ + } + + return(ret); } /* @@ -372,30 +372,30 @@ static char * regbranch(flagp) int *flagp; { - register char *ret; - register char *chain; - register char *latest; - int flags; - - *flagp = WORST; /* Tentatively. */ - - ret = regnode(BRANCH); - chain = NULL; - while (*regparse != '\0' && *regparse != '|' && *regparse != ')') { - latest = regpiece(&flags); - if (latest == NULL) - return(NULL); - *flagp |= flags&HASWIDTH; - if (chain == NULL) /* First piece. */ - *flagp |= flags&SPSTART; - else - regtail(chain, latest); - chain = latest; - } - if (chain == NULL) /* Loop ran zero times. */ - (void) regnode(NOTHING); - - return(ret); + register char *ret; + register char *chain; + register char *latest; + int flags; + + *flagp = WORST; /* Tentatively. */ + + ret = regnode(BRANCH); + chain = NULL; + while (*regparse != '\0' && *regparse != '|' && *regparse != ')') { + latest = regpiece(&flags); + if (latest == NULL) + return(NULL); + *flagp |= flags&HASWIDTH; + if (chain == NULL) /* First piece. */ + *flagp |= flags&SPSTART; + else + regtail(chain, latest); + chain = latest; + } + if (chain == NULL) /* Loop ran zero times. */ + (void) regnode(NOTHING); + + return(ret); } /* @@ -411,56 +411,56 @@ static char * regpiece(flagp) int *flagp; { - register char *ret; - register char op; - register char *next; - int flags; - - ret = regatom(&flags); - if (ret == NULL) - return(NULL); - - op = *regparse; - if (!ISMULT(op)) { - *flagp = flags; - return(ret); - } - - if (!(flags&HASWIDTH) && op != '?') - FAIL("*+ operand could be empty"); - *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH); - - if (op == '*' && (flags&SIMPLE)) - reginsert(STAR, ret); - else if (op == '*') { - /* Emit x* as (x&|), where & means "self". */ - reginsert(BRANCH, ret); /* Either x */ - regoptail(ret, regnode(BACK)); /* and loop */ - regoptail(ret, ret); /* back */ - regtail(ret, regnode(BRANCH)); /* or */ - regtail(ret, regnode(NOTHING)); /* null. */ - } else if (op == '+' && (flags&SIMPLE)) - reginsert(PLUS, ret); - else if (op == '+') { - /* Emit x+ as x(&|), where & means "self". */ - next = regnode(BRANCH); /* Either */ - regtail(ret, next); - regtail(regnode(BACK), ret); /* loop back */ - regtail(next, regnode(BRANCH)); /* or */ - regtail(ret, regnode(NOTHING)); /* null. */ - } else if (op == '?') { - /* Emit x? as (x|) */ - reginsert(BRANCH, ret); /* Either x */ - regtail(ret, regnode(BRANCH)); /* or */ - next = regnode(NOTHING); /* null. */ - regtail(ret, next); - regoptail(ret, next); - } - regparse++; - if (ISMULT(*regparse)) - FAIL("nested *?+"); - - return(ret); + register char *ret; + register char op; + register char *next; + int flags; + + ret = regatom(&flags); + if (ret == NULL) + return(NULL); + + op = *regparse; + if (!ISMULT(op)) { + *flagp = flags; + return(ret); + } + + if (!(flags&HASWIDTH) && op != '?') + FAIL("*+ operand could be empty"); + *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH); + + if (op == '*' && (flags&SIMPLE)) + reginsert(STAR, ret); + else if (op == '*') { + /* Emit x* as (x&|), where & means "self". */ + reginsert(BRANCH, ret); /* Either x */ + regoptail(ret, regnode(BACK)); /* and loop */ + regoptail(ret, ret); /* back */ + regtail(ret, regnode(BRANCH)); /* or */ + regtail(ret, regnode(NOTHING)); /* null. */ + } else if (op == '+' && (flags&SIMPLE)) + reginsert(PLUS, ret); + else if (op == '+') { + /* Emit x+ as x(&|), where & means "self". */ + next = regnode(BRANCH); /* Either */ + regtail(ret, next); + regtail(regnode(BACK), ret); /* loop back */ + regtail(next, regnode(BRANCH)); /* or */ + regtail(ret, regnode(NOTHING)); /* null. */ + } else if (op == '?') { + /* Emit x? as (x|) */ + reginsert(BRANCH, ret); /* Either x */ + regtail(ret, regnode(BRANCH)); /* or */ + next = regnode(NOTHING); /* null. */ + regtail(ret, next); + regoptail(ret, next); + } + regparse++; + if (ISMULT(*regparse)) + FAIL("nested *?+"); + + return(ret); } /* @@ -475,133 +475,133 @@ static char * regatom(flagp) int *flagp; { - register char *ret; - int flags; - - *flagp = WORST; /* Tentatively. */ - - switch (*regparse++) { - case '^': - ret = regnode(BOL); - break; - case '$': - ret = regnode(EOL); - break; - case '.': - ret = regnode(ANY); - *flagp |= HASWIDTH|SIMPLE; - break; - case '[': { - register int clss; - register int classend; - - if (*regparse == '^') { /* Complement of range. */ - ret = regnode(ANYBUT); - regparse++; - } else - ret = regnode(ANYOF); - if (*regparse == ']' || *regparse == '-') - regc(*regparse++); - while (*regparse != '\0' && *regparse != ']') { - if (*regparse == '-') { - regparse++; - if (*regparse == ']' || *regparse == '\0') - regc('-'); - else { - clss = UCHARAT(regparse-2)+1; - classend = UCHARAT(regparse); - if (clss > classend+1) - FAIL("invalid [] range"); - for (; clss <= classend; clss++) - regc(clss); - regparse++; - } - } else - regc(*regparse++); - } - regc('\0'); - if (*regparse != ']') - FAIL("unmatched []"); - regparse++; - *flagp |= HASWIDTH|SIMPLE; - } - break; - case '(': - ret = reg(1, &flags); - if (ret == NULL) - return(NULL); - *flagp |= flags&(HASWIDTH|SPSTART); - break; - case '\0': - case '|': - case ')': - FAIL("internal urp"); /* Supposed to be caught earlier. */ - /* NOTREACHED */ - break; - case '?': - case '+': - case '*': - FAIL("?+* follows nothing"); - /* NOTREACHED */ - break; - case '\\': - if (*regparse == '\0') - FAIL("trailing \\"); - ret = regnode(EXACTLY); - regc(*regparse++); - regc('\0'); - *flagp |= HASWIDTH|SIMPLE; - break; - default: { - register int len; - register char ender; - - regparse--; - len = (int) strcspn(regparse, META); - if (len <= 0) - FAIL("internal disaster"); - ender = *(regparse+len); - if (len > 1 && ISMULT(ender)) - len--; /* Back off clear of ?+* operand. */ - *flagp |= HASWIDTH; - if (len == 1) - *flagp |= SIMPLE; - ret = regnode(EXACTLY); - while (len > 0) { - regc(*regparse++); - len--; - } - regc('\0'); - } - break; - } - - return(ret); + register char *ret; + int flags; + + *flagp = WORST; /* Tentatively. */ + + switch (*regparse++) { + case '^': + ret = regnode(BOL); + break; + case '$': + ret = regnode(EOL); + break; + case '.': + ret = regnode(ANY); + *flagp |= HASWIDTH|SIMPLE; + break; + case '[': { + register int clss; + register int classend; + + if (*regparse == '^') { /* Complement of range. */ + ret = regnode(ANYBUT); + regparse++; + } else + ret = regnode(ANYOF); + if (*regparse == ']' || *regparse == '-') + regc(*regparse++); + while (*regparse != '\0' && *regparse != ']') { + if (*regparse == '-') { + regparse++; + if (*regparse == ']' || *regparse == '\0') + regc('-'); + else { + clss = UCHARAT(regparse-2)+1; + classend = UCHARAT(regparse); + if (clss > classend+1) + FAIL("invalid [] range"); + for (; clss <= classend; clss++) + regc(clss); + regparse++; + } + } else + regc(*regparse++); + } + regc('\0'); + if (*regparse != ']') + FAIL("unmatched []"); + regparse++; + *flagp |= HASWIDTH|SIMPLE; + } + break; + case '(': + ret = reg(1, &flags); + if (ret == NULL) + return(NULL); + *flagp |= flags&(HASWIDTH|SPSTART); + break; + case '\0': + case '|': + case ')': + FAIL("internal urp"); /* Supposed to be caught earlier. */ + /* NOTREACHED */ + break; + case '?': + case '+': + case '*': + FAIL("?+* follows nothing"); + /* NOTREACHED */ + break; + case '\\': + if (*regparse == '\0') + FAIL("trailing \\"); + ret = regnode(EXACTLY); + regc(*regparse++); + regc('\0'); + *flagp |= HASWIDTH|SIMPLE; + break; + default: { + register int len; + register char ender; + + regparse--; + len = (int) strcspn(regparse, META); + if (len <= 0) + FAIL("internal disaster"); + ender = *(regparse+len); + if (len > 1 && ISMULT(ender)) + len--; /* Back off clear of ?+* operand. */ + *flagp |= HASWIDTH; + if (len == 1) + *flagp |= SIMPLE; + ret = regnode(EXACTLY); + while (len > 0) { + regc(*regparse++); + len--; + } + regc('\0'); + } + break; + } + + return(ret); } /* - regnode - emit a node */ -static char * /* Location. */ +static char * /* Location. */ regnode(op) char op; { - register char *ret; - register char *ptr; - - ret = regcode; - if (ret == ®dummy) { - regsize += 3; - return(ret); - } - - ptr = ret; - *ptr++ = op; - *ptr++ = '\0'; /* Null "next" pointer. */ - *ptr++ = '\0'; - regcode = ptr; - - return(ret); + register char *ret; + register char *ptr; + + ret = regcode; + if (ret == ®dummy) { + regsize += 3; + return(ret); + } + + ptr = ret; + *ptr++ = op; + *ptr++ = '\0'; /* Null "next" pointer. */ + *ptr++ = '\0'; + regcode = ptr; + + return(ret); } /* @@ -611,10 +611,10 @@ static void regc(b) char b; { - if (regcode != ®dummy) - *regcode++ = b; - else - regsize++; + if (regcode != ®dummy) + *regcode++ = b; + else + regsize++; } /* @@ -627,25 +627,25 @@ reginsert(op, opnd) char op; char *opnd; { - register char *src; - register char *dst; - register char *place; - - if (regcode == ®dummy) { - regsize += 3; - return; - } - - src = regcode; - regcode += 3; - dst = regcode; - while (src > opnd) - *--dst = *--src; - - place = opnd; /* Op node, where operand used to be. */ - *place++ = op; - *place++ = '\0'; - *place++ = '\0'; + register char *src; + register char *dst; + register char *place; + + if (regcode == ®dummy) { + regsize += 3; + return; + } + + src = regcode; + regcode += 3; + dst = regcode; + while (src > opnd) + *--dst = *--src; + + place = opnd; /* Op node, where operand used to be. */ + *place++ = op; + *place++ = '\0'; + *place++ = '\0'; } /* @@ -656,28 +656,28 @@ regtail(p, val) char *p; char *val; { - register char *scan; - register char *temp; - register int offset; - - if (p == ®dummy) - return; - - /* Find last node. */ - scan = p; - for (;;) { - temp = regnext(scan); - if (temp == NULL) - break; - scan = temp; - } - - if (OP(scan) == BACK) - offset = (int) (scan - val); - else - offset = (int) (val - scan); - *(scan+1) = (offset>>8)&0377; - *(scan+2) = offset&0377; + register char *scan; + register char *temp; + register int offset; + + if (p == ®dummy) + return; + + /* Find last node. */ + scan = p; + for (;;) { + temp = regnext(scan); + if (temp == NULL) + break; + scan = temp; + } + + if (OP(scan) == BACK) + offset = (int) (scan - val); + else + offset = (int) (val - scan); + *(scan+1) = (offset>>8)&0377; + *(scan+2) = offset&0377; } /* @@ -688,10 +688,10 @@ regoptail(p, val) char *p; char *val; { - /* "Operandless" and "op != BRANCH" are synonymous in practice. */ - if (p == NULL || p == ®dummy || OP(p) != BRANCH) - return; - regtail(OPERAND(p), val); + /* "Operandless" and "op != BRANCH" are synonymous in practice. */ + if (p == NULL || p == ®dummy || OP(p) != BRANCH) + return; + regtail(OPERAND(p), val); } /* @@ -701,10 +701,10 @@ char *val; /* * Global work variables for regexec(). */ -static char *reginput; /* String-input pointer. */ -static char *regbol; /* Beginning of input, for ^ check. */ -static char **regstartp; /* Pointer to startp array. */ -static char **regendp; /* Ditto for endp. */ +static char *reginput; /* String-input pointer. */ +static char *regbol; /* Beginning of input, for ^ check. */ +static char **regstartp; /* Pointer to startp array. */ +static char **regendp; /* Ditto for endp. */ /* * Forwards. @@ -728,60 +728,60 @@ register regexp *prog; register char *string; int notbol; { - register char *s; - - /* Be paranoid... */ - if (prog == NULL || string == NULL) { - regerror("NULL parameter"); - return(0); - } - - /* Check validity of program. */ - if (UCHARAT(prog->program) != MAGIC) { - regerror("corrupted program"); - return(0); - } - - /* If there is a "must appear" string, look for it. */ - if (prog->regmust != NULL) { - s = string; - while ((s = strchr(s, prog->regmust[0])) != NULL) { - if (strncmp(s, prog->regmust, prog->regmlen) == 0) - break; /* Found it. */ - s++; - } - if (s == NULL) /* Not present. */ - return(0); - } - - /* Mark beginning of line for ^ . */ - if (notbol) - regbol = NULL; - else - regbol = string; - - /* Simplest case: anchored match need be tried only once. */ - if (prog->reganch) - return(regtry(prog, string)); - - /* Messy cases: unanchored match. */ - s = string; - if (prog->regstart != '\0') - /* We know what char it must start with. */ - while ((s = strchr(s, prog->regstart)) != NULL) { - if (regtry(prog, s)) - return(1); - s++; - } - else - /* We don't -- general case. */ - do { - if (regtry(prog, s)) - return(1); - } while (*s++ != '\0'); - - /* Failure. */ - return(0); + register char *s; + + /* Be paranoid... */ + if (prog == NULL || string == NULL) { + regerror("NULL parameter"); + return(0); + } + + /* Check validity of program. */ + if (UCHARAT(prog->program) != MAGIC) { + regerror("corrupted program"); + return(0); + } + + /* If there is a "must appear" string, look for it. */ + if (prog->regmust != NULL) { + s = string; + while ((s = strchr(s, prog->regmust[0])) != NULL) { + if (strncmp(s, prog->regmust, prog->regmlen) == 0) + break; /* Found it. */ + s++; + } + if (s == NULL) /* Not present. */ + return(0); + } + + /* Mark beginning of line for ^ . */ + if (notbol) + regbol = NULL; + else + regbol = string; + + /* Simplest case: anchored match need be tried only once. */ + if (prog->reganch) + return(regtry(prog, string)); + + /* Messy cases: unanchored match. */ + s = string; + if (prog->regstart != '\0') + /* We know what char it must start with. */ + while ((s = strchr(s, prog->regstart)) != NULL) { + if (regtry(prog, s)) + return(1); + s++; + } + else + /* We don't -- general case. */ + do { + if (regtry(prog, s)) + return(1); + } while (*s++ != '\0'); + + /* Failure. */ + return(0); } int @@ -789,37 +789,37 @@ regexec(prog, string) register regexp *prog; register char *string; { - return regexec2(prog, string, 0); + return regexec2(prog, string, 0); } /* - regtry - try match at specific point */ -static int /* 0 failure, 1 success */ +static int /* 0 failure, 1 success */ regtry(prog, string) regexp *prog; char *string; { - register int i; - register char **sp; - register char **ep; - - reginput = string; - regstartp = prog->startp; - regendp = prog->endp; - - sp = prog->startp; - ep = prog->endp; - for (i = NSUBEXP; i > 0; i--) { - *sp++ = NULL; - *ep++ = NULL; - } - if (regmatch(prog->program + 1)) { - prog->startp[0] = string; - prog->endp[0] = reginput; - return(1); - } else - return(0); + register int i; + register char **sp; + register char **ep; + + reginput = string; + regstartp = prog->startp; + regendp = prog->endp; + + sp = prog->startp; + ep = prog->endp; + for (i = NSUBEXP; i > 0; i--) { + *sp++ = NULL; + *ep++ = NULL; + } + if (regmatch(prog->program + 1)) { + prog->startp[0] = string; + prog->endp[0] = reginput; + return(1); + } else + return(0); } /* @@ -832,194 +832,194 @@ char *string; * need to know whether the rest of the match failed) by a loop instead of * by recursion. */ -static int /* 0 failure, 1 success */ +static int /* 0 failure, 1 success */ regmatch(prog) char *prog; { - register char *scan; /* Current node. */ - char *next; /* Next node. */ + register char *scan; /* Current node. */ + char *next; /* Next node. */ - scan = prog; + scan = prog; #ifdef DEBUG - if (scan != NULL && regnarrate) - fprintf(stderr, "%s(\n", regprop(scan)); + if (scan != NULL && regnarrate) + fprintf(stderr, "%s(\n", regprop(scan)); #endif - while (scan != NULL) { + while (scan != NULL) { #ifdef DEBUG - if (regnarrate) - fprintf(stderr, "%s...\n", regprop(scan)); + if (regnarrate) + fprintf(stderr, "%s...\n", regprop(scan)); #endif - next = regnext(scan); - - switch (OP(scan)) { - case BOL: - if (reginput != regbol) - return(0); - break; - case EOL: - if (*reginput != '\0') - return(0); - break; - case ANY: - if (*reginput == '\0') - return(0); - reginput++; - break; - case EXACTLY: { - register int len; - register char *opnd; - - opnd = OPERAND(scan); - /* Inline the first character, for speed. */ - if (*opnd != *reginput) - return(0); - len = (int) strlen(opnd); - if (len > 1 && strncmp(opnd, reginput, len) != 0) - return(0); - reginput += len; - } - break; - case ANYOF: - if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == NULL) - return(0); - reginput++; - break; - case ANYBUT: - if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != NULL) - return(0); - reginput++; - break; - case NOTHING: - break; - case BACK: - break; - case OPEN+1: - case OPEN+2: - case OPEN+3: - case OPEN+4: - case OPEN+5: - case OPEN+6: - case OPEN+7: - case OPEN+8: - case OPEN+9: { - register int no; - register char *save; - - no = OP(scan) - OPEN; - save = reginput; - - if (regmatch(next)) { - /* - * Don't set startp if some later - * invocation of the same parentheses - * already has. - */ - if (regstartp[no] == NULL) - regstartp[no] = save; - return(1); - } else - return(0); - } - /* NOTREACHED */ - break; - case CLOSE+1: - case CLOSE+2: - case CLOSE+3: - case CLOSE+4: - case CLOSE+5: - case CLOSE+6: - case CLOSE+7: - case CLOSE+8: - case CLOSE+9: { - register int no; - register char *save; - - no = OP(scan) - CLOSE; - save = reginput; - - if (regmatch(next)) { - /* - * Don't set endp if some later - * invocation of the same parentheses - * already has. - */ - if (regendp[no] == NULL) - regendp[no] = save; - return(1); - } else - return(0); - } - /* NOTREACHED */ - break; - case BRANCH: { - register char *save; - - if (OP(next) != BRANCH) /* No choice. */ - next = OPERAND(scan); /* Avoid recursion. */ - else { - do { - save = reginput; - if (regmatch(OPERAND(scan))) - return(1); - reginput = save; - scan = regnext(scan); - } while (scan != NULL && OP(scan) == BRANCH); - return(0); - /* NOTREACHED */ - } - } - /* NOTREACHED */ - break; - case STAR: - case PLUS: { - register char nextch; - register int no; - register char *save; - register int min; - - /* - * Lookahead to avoid useless match attempts - * when we know what character comes next. - */ - nextch = '\0'; - if (OP(next) == EXACTLY) - nextch = *OPERAND(next); - min = (OP(scan) == STAR) ? 0 : 1; - save = reginput; - no = regrepeat(OPERAND(scan)); - while (no >= min) { - /* If it could work, try it. */ - if (nextch == '\0' || *reginput == nextch) - if (regmatch(next)) - return(1); - /* Couldn't or didn't -- back up. */ - no--; - reginput = save + no; - } - return(0); - } - /* NOTREACHED */ - break; - case END: - return(1); /* Success! */ - /* NOTREACHED */ - break; - default: - regerror("memory corruption"); - return(0); - /* NOTREACHED */ - break; - } - - scan = next; - } - - /* - * We get here only if there's trouble -- normally "case END" is - * the terminating point. - */ - regerror("corrupted pointers"); - return(0); + next = regnext(scan); + + switch (OP(scan)) { + case BOL: + if (reginput != regbol) + return(0); + break; + case EOL: + if (*reginput != '\0') + return(0); + break; + case ANY: + if (*reginput == '\0') + return(0); + reginput++; + break; + case EXACTLY: { + register int len; + register char *opnd; + + opnd = OPERAND(scan); + /* Inline the first character, for speed. */ + if (*opnd != *reginput) + return(0); + len = (int) strlen(opnd); + if (len > 1 && strncmp(opnd, reginput, len) != 0) + return(0); + reginput += len; + } + break; + case ANYOF: + if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == NULL) + return(0); + reginput++; + break; + case ANYBUT: + if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != NULL) + return(0); + reginput++; + break; + case NOTHING: + break; + case BACK: + break; + case OPEN+1: + case OPEN+2: + case OPEN+3: + case OPEN+4: + case OPEN+5: + case OPEN+6: + case OPEN+7: + case OPEN+8: + case OPEN+9: { + register int no; + register char *save; + + no = OP(scan) - OPEN; + save = reginput; + + if (regmatch(next)) { + /* + * Don't set startp if some later + * invocation of the same parentheses + * already has. + */ + if (regstartp[no] == NULL) + regstartp[no] = save; + return(1); + } else + return(0); + } + /* NOTREACHED */ + break; + case CLOSE+1: + case CLOSE+2: + case CLOSE+3: + case CLOSE+4: + case CLOSE+5: + case CLOSE+6: + case CLOSE+7: + case CLOSE+8: + case CLOSE+9: { + register int no; + register char *save; + + no = OP(scan) - CLOSE; + save = reginput; + + if (regmatch(next)) { + /* + * Don't set endp if some later + * invocation of the same parentheses + * already has. + */ + if (regendp[no] == NULL) + regendp[no] = save; + return(1); + } else + return(0); + } + /* NOTREACHED */ + break; + case BRANCH: { + register char *save; + + if (OP(next) != BRANCH) /* No choice. */ + next = OPERAND(scan); /* Avoid recursion. */ + else { + do { + save = reginput; + if (regmatch(OPERAND(scan))) + return(1); + reginput = save; + scan = regnext(scan); + } while (scan != NULL && OP(scan) == BRANCH); + return(0); + /* NOTREACHED */ + } + } + /* NOTREACHED */ + break; + case STAR: + case PLUS: { + register char nextch; + register int no; + register char *save; + register int min; + + /* + * Lookahead to avoid useless match attempts + * when we know what character comes next. + */ + nextch = '\0'; + if (OP(next) == EXACTLY) + nextch = *OPERAND(next); + min = (OP(scan) == STAR) ? 0 : 1; + save = reginput; + no = regrepeat(OPERAND(scan)); + while (no >= min) { + /* If it could work, try it. */ + if (nextch == '\0' || *reginput == nextch) + if (regmatch(next)) + return(1); + /* Couldn't or didn't -- back up. */ + no--; + reginput = save + no; + } + return(0); + } + /* NOTREACHED */ + break; + case END: + return(1); /* Success! */ + /* NOTREACHED */ + break; + default: + regerror("memory corruption"); + return(0); + /* NOTREACHED */ + break; + } + + scan = next; + } + + /* + * We get here only if there's trouble -- normally "case END" is + * the terminating point. + */ + regerror("corrupted pointers"); + return(0); } /* @@ -1029,43 +1029,43 @@ static int regrepeat(p) char *p; { - register int count = 0; - register char *scan; - register char *opnd; - - scan = reginput; - opnd = OPERAND(p); - switch (OP(p)) { - case ANY: - count = (int) strlen(scan); - scan += count; - break; - case EXACTLY: - while (*opnd == *scan) { - count++; - scan++; - } - break; - case ANYOF: - while (*scan != '\0' && strchr(opnd, *scan) != NULL) { - count++; - scan++; - } - break; - case ANYBUT: - while (*scan != '\0' && strchr(opnd, *scan) == NULL) { - count++; - scan++; - } - break; - default: /* Oh dear. Called inappropriately. */ - regerror("internal foulup"); - count = 0; /* Best compromise. */ - break; - } - reginput = scan; - - return(count); + register int count = 0; + register char *scan; + register char *opnd; + + scan = reginput; + opnd = OPERAND(p); + switch (OP(p)) { + case ANY: + count = (int) strlen(scan); + scan += count; + break; + case EXACTLY: + while (*opnd == *scan) { + count++; + scan++; + } + break; + case ANYOF: + while (*scan != '\0' && strchr(opnd, *scan) != NULL) { + count++; + scan++; + } + break; + case ANYBUT: + while (*scan != '\0' && strchr(opnd, *scan) == NULL) { + count++; + scan++; + } + break; + default: /* Oh dear. Called inappropriately. */ + regerror("internal foulup"); + count = 0; /* Best compromise. */ + break; + } + reginput = scan; + + return(count); } /* @@ -1075,19 +1075,19 @@ static char * regnext(p) register char *p; { - register int offset; + register int offset; - if (p == ®dummy) - return(NULL); + if (p == ®dummy) + return(NULL); - offset = NEXT(p); - if (offset == 0) - return(NULL); + offset = NEXT(p); + if (offset == 0) + return(NULL); - if (OP(p) == BACK) - return(p-offset); - else - return(p+offset); + if (OP(p) == BACK) + return(p-offset); + else + return(p+offset); } #ifdef DEBUG @@ -1101,40 +1101,40 @@ void regdump(r) regexp *r; { - register char *s; - register char op = EXACTLY; /* Arbitrary non-END op. */ - register char *next; - - - s = r->program + 1; - while (op != END) { /* While that wasn't END last time... */ - op = OP(s); - printf("%2d%s", s-r->program, regprop(s)); /* Where, what. */ - next = regnext(s); - if (next == NULL) /* Next ptr. */ - printf("(0)"); - else - printf("(%d)", (s-r->program)+(next-s)); - s += 3; - if (op == ANYOF || op == ANYBUT || op == EXACTLY) { - /* Literal string, where present. */ - while (*s != '\0') { - putchar(*s); - s++; - } - s++; - } - putchar('\n'); - } - - /* Header fields of interest. */ - if (r->regstart != '\0') - printf("start `%c' ", r->regstart); - if (r->reganch) - printf("anchored "); - if (r->regmust != NULL) - printf("must have \"%s\"", r->regmust); - printf("\n"); + register char *s; + register char op = EXACTLY; /* Arbitrary non-END op. */ + register char *next; + + + s = r->program + 1; + while (op != END) { /* While that wasn't END last time... */ + op = OP(s); + printf("%2d%s", s-r->program, regprop(s)); /* Where, what. */ + next = regnext(s); + if (next == NULL) /* Next ptr. */ + printf("(0)"); + else + printf("(%d)", (s-r->program)+(next-s)); + s += 3; + if (op == ANYOF || op == ANYBUT || op == EXACTLY) { + /* Literal string, where present. */ + while (*s != '\0') { + putchar(*s); + s++; + } + s++; + } + putchar('\n'); + } + + /* Header fields of interest. */ + if (r->regstart != '\0') + printf("start `%c' ", r->regstart); + if (r->reganch) + printf("anchored "); + if (r->regmust != NULL) + printf("must have \"%s\"", r->regmust); + printf("\n"); } /* @@ -1144,79 +1144,79 @@ static char * regprop(op) char *op; { - register char *p; - static char buf[50]; - - (void) strcpy(buf, ":"); - - switch (OP(op)) { - case BOL: - p = "BOL"; - break; - case EOL: - p = "EOL"; - break; - case ANY: - p = "ANY"; - break; - case ANYOF: - p = "ANYOF"; - break; - case ANYBUT: - p = "ANYBUT"; - break; - case BRANCH: - p = "BRANCH"; - break; - case EXACTLY: - p = "EXACTLY"; - break; - case NOTHING: - p = "NOTHING"; - break; - case BACK: - p = "BACK"; - break; - case END: - p = "END"; - break; - case OPEN+1: - case OPEN+2: - case OPEN+3: - case OPEN+4: - case OPEN+5: - case OPEN+6: - case OPEN+7: - case OPEN+8: - case OPEN+9: - sprintf(buf+strlen(buf), "OPEN%d", OP(op)-OPEN); - p = NULL; - break; - case CLOSE+1: - case CLOSE+2: - case CLOSE+3: - case CLOSE+4: - case CLOSE+5: - case CLOSE+6: - case CLOSE+7: - case CLOSE+8: - case CLOSE+9: - sprintf(buf+strlen(buf), "CLOSE%d", OP(op)-CLOSE); - p = NULL; - break; - case STAR: - p = "STAR"; - break; - case PLUS: - p = "PLUS"; - break; - default: - regerror("corrupted opcode"); - break; - } - if (p != NULL) - (void) strcat(buf, p); - return(buf); + register char *p; + static char buf[50]; + + (void) strcpy(buf, ":"); + + switch (OP(op)) { + case BOL: + p = "BOL"; + break; + case EOL: + p = "EOL"; + break; + case ANY: + p = "ANY"; + break; + case ANYOF: + p = "ANYOF"; + break; + case ANYBUT: + p = "ANYBUT"; + break; + case BRANCH: + p = "BRANCH"; + break; + case EXACTLY: + p = "EXACTLY"; + break; + case NOTHING: + p = "NOTHING"; + break; + case BACK: + p = "BACK"; + break; + case END: + p = "END"; + break; + case OPEN+1: + case OPEN+2: + case OPEN+3: + case OPEN+4: + case OPEN+5: + case OPEN+6: + case OPEN+7: + case OPEN+8: + case OPEN+9: + sprintf(buf+strlen(buf), "OPEN%d", OP(op)-OPEN); + p = NULL; + break; + case CLOSE+1: + case CLOSE+2: + case CLOSE+3: + case CLOSE+4: + case CLOSE+5: + case CLOSE+6: + case CLOSE+7: + case CLOSE+8: + case CLOSE+9: + sprintf(buf+strlen(buf), "CLOSE%d", OP(op)-CLOSE); + p = NULL; + break; + case STAR: + p = "STAR"; + break; + case PLUS: + p = "PLUS"; + break; + default: + regerror("corrupted opcode"); + break; + } + if (p != NULL) + (void) strcat(buf, p); + return(buf); } #endif @@ -1237,17 +1237,17 @@ strcspn(s1, s2) char *s1; char *s2; { - register char *scan1; - register char *scan2; - register int count; - - count = 0; - for (scan1 = s1; *scan1 != '\0'; scan1++) { - for (scan2 = s2; *scan2 != '\0';) /* ++ moved down. */ - if (*scan1 == *scan2++) - return(count); - count++; - } - return(count); + register char *scan1; + register char *scan2; + register int count; + + count = 0; + for (scan1 = s1; *scan1 != '\0'; scan1++) { + for (scan2 = s2; *scan2 != '\0';) /* ++ moved down. */ + if (*scan1 == *scan2++) + return(count); + count++; + } + return(count); } #endif diff --git a/screen.c b/screen.c index ff6b6d7..5b94a12 100644 --- a/screen.c +++ b/screen.c @@ -36,13 +36,13 @@ extern int fd0; #include #ifndef FOREGROUND_BLUE -#define FOREGROUND_BLUE 0x0001 +#define FOREGROUND_BLUE 0x0001 #endif #ifndef FOREGROUND_GREEN -#define FOREGROUND_GREEN 0x0002 +#define FOREGROUND_GREEN 0x0002 #endif #ifndef FOREGROUND_RED -#define FOREGROUND_RED 0x0004 +#define FOREGROUND_RED 0x0004 #endif #ifndef FOREGROUND_INTENSITY #define FOREGROUND_INTENSITY 0x0008 @@ -130,8 +130,8 @@ extern int sc_height; #if MSDOS_COMPILER==WIN32C struct keyRecord { - int ascii; - int scan; + int ascii; + int scan; } currentKey; static int keyCount = 0; @@ -187,31 +187,31 @@ public int vt_enabled = -1; /* Is virtual terminal processing available? */ * Strings passed to tputs() to do various terminal functions. */ static char - *sc_pad, /* Pad string */ - *sc_home, /* Cursor home */ - *sc_addline, /* Add line, scroll down following lines */ - *sc_lower_left, /* Cursor to last line, first column */ - *sc_return, /* Cursor to beginning of current line */ - *sc_move, /* General cursor positioning */ - *sc_clear, /* Clear screen */ - *sc_eol_clear, /* Clear to end of line */ - *sc_eos_clear, /* Clear to end of screen */ - *sc_s_in, /* Enter standout (highlighted) mode */ - *sc_s_out, /* Exit standout mode */ - *sc_u_in, /* Enter underline mode */ - *sc_u_out, /* Exit underline mode */ - *sc_b_in, /* Enter bold mode */ - *sc_b_out, /* Exit bold mode */ - *sc_bl_in, /* Enter blink mode */ - *sc_bl_out, /* Exit blink mode */ - *sc_visual_bell, /* Visual bell (flash screen) sequence */ - *sc_backspace, /* Backspace cursor */ - *sc_s_keypad, /* Start keypad mode */ - *sc_e_keypad, /* End keypad mode */ - *sc_s_mousecap, /* Start mouse capture mode */ - *sc_e_mousecap, /* End mouse capture mode */ - *sc_init, /* Startup terminal initialization */ - *sc_deinit; /* Exit terminal de-initialization */ + *sc_pad, /* Pad string */ + *sc_home, /* Cursor home */ + *sc_addline, /* Add line, scroll down following lines */ + *sc_lower_left, /* Cursor to last line, first column */ + *sc_return, /* Cursor to beginning of current line */ + *sc_move, /* General cursor positioning */ + *sc_clear, /* Clear screen */ + *sc_eol_clear, /* Clear to end of line */ + *sc_eos_clear, /* Clear to end of screen */ + *sc_s_in, /* Enter standout (highlighted) mode */ + *sc_s_out, /* Exit standout mode */ + *sc_u_in, /* Enter underline mode */ + *sc_u_out, /* Exit underline mode */ + *sc_b_in, /* Enter bold mode */ + *sc_b_out, /* Exit bold mode */ + *sc_bl_in, /* Enter blink mode */ + *sc_bl_out, /* Exit blink mode */ + *sc_visual_bell, /* Visual bell (flash screen) sequence */ + *sc_backspace, /* Backspace cursor */ + *sc_s_keypad, /* Start keypad mode */ + *sc_e_keypad, /* End keypad mode */ + *sc_s_mousecap, /* Start mouse capture mode */ + *sc_e_mousecap, /* End mouse capture mode */ + *sc_init, /* Startup terminal initialization */ + *sc_deinit; /* Exit terminal de-initialization */ static int attrcolor = -1; #endif @@ -296,372 +296,372 @@ extern char *tgoto(); /* * Change terminal to "raw mode", or restore to "normal" mode. - * "Raw mode" means + * "Raw mode" means * 1. An outstanding read will complete on receipt of a single keystroke. - * 2. Input is not echoed. + * 2. Input is not echoed. * 3. On output, \n is mapped to \r\n. * 4. \t is NOT expanded into spaces. * 5. Signal-causing characters such as ctrl-C (interrupt), * etc. are NOT disabled. * It doesn't matter whether an input \n is mapped to \r, or vice versa. */ - public void + public void raw_mode(on) - int on; + int on; { - static int curr_on = 0; + static int curr_on = 0; - if (on == curr_on) - return; - erase2_char = '\b'; /* in case OS doesn't know about erase2 */ + if (on == curr_on) + return; + erase2_char = '\b'; /* in case OS doesn't know about erase2 */ #if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS { - struct termios s; - static struct termios save_term; - static int saved_term = 0; - - if (on) - { - /* - * Get terminal modes. - */ - tcgetattr(tty, &s); - - /* - * Save modes and set certain variables dependent on modes. - */ - if (!saved_term) - { - save_term = s; - saved_term = 1; - } + struct termios s; + static struct termios save_term; + static int saved_term = 0; + + if (on) + { + /* + * Get terminal modes. + */ + tcgetattr(tty, &s); + + /* + * Save modes and set certain variables dependent on modes. + */ + if (!saved_term) + { + save_term = s; + saved_term = 1; + } #if HAVE_OSPEED - switch (cfgetospeed(&s)) - { + switch (cfgetospeed(&s)) + { #ifdef B0 - case B0: ospeed = 0; break; + case B0: ospeed = 0; break; #endif #ifdef B50 - case B50: ospeed = 1; break; + case B50: ospeed = 1; break; #endif #ifdef B75 - case B75: ospeed = 2; break; + case B75: ospeed = 2; break; #endif #ifdef B110 - case B110: ospeed = 3; break; + case B110: ospeed = 3; break; #endif #ifdef B134 - case B134: ospeed = 4; break; + case B134: ospeed = 4; break; #endif #ifdef B150 - case B150: ospeed = 5; break; + case B150: ospeed = 5; break; #endif #ifdef B200 - case B200: ospeed = 6; break; + case B200: ospeed = 6; break; #endif #ifdef B300 - case B300: ospeed = 7; break; + case B300: ospeed = 7; break; #endif #ifdef B600 - case B600: ospeed = 8; break; + case B600: ospeed = 8; break; #endif #ifdef B1200 - case B1200: ospeed = 9; break; + case B1200: ospeed = 9; break; #endif #ifdef B1800 - case B1800: ospeed = 10; break; + case B1800: ospeed = 10; break; #endif #ifdef B2400 - case B2400: ospeed = 11; break; + case B2400: ospeed = 11; break; #endif #ifdef B4800 - case B4800: ospeed = 12; break; + case B4800: ospeed = 12; break; #endif #ifdef B9600 - case B9600: ospeed = 13; break; + case B9600: ospeed = 13; break; #endif #ifdef EXTA - case EXTA: ospeed = 14; break; + case EXTA: ospeed = 14; break; #endif #ifdef EXTB - case EXTB: ospeed = 15; break; + case EXTB: ospeed = 15; break; #endif #ifdef B57600 - case B57600: ospeed = 16; break; + case B57600: ospeed = 16; break; #endif #ifdef B115200 - case B115200: ospeed = 17; break; + case B115200: ospeed = 17; break; #endif - default: ; - } + default: ; + } #endif - erase_char = s.c_cc[VERASE]; + erase_char = s.c_cc[VERASE]; #ifdef VERASE2 - erase2_char = s.c_cc[VERASE2]; + erase2_char = s.c_cc[VERASE2]; #endif - kill_char = s.c_cc[VKILL]; + kill_char = s.c_cc[VKILL]; #ifdef VWERASE - werase_char = s.c_cc[VWERASE]; + werase_char = s.c_cc[VWERASE]; #else - werase_char = CONTROL('W'); + werase_char = CONTROL('W'); #endif - /* - * Set the modes to the way we want them. - */ - s.c_lflag &= ~(0 + /* + * Set the modes to the way we want them. + */ + s.c_lflag &= ~(0 #ifdef ICANON - | ICANON + | ICANON #endif #ifdef ECHO - | ECHO + | ECHO #endif #ifdef ECHOE - | ECHOE + | ECHOE #endif #ifdef ECHOK - | ECHOK + | ECHOK #endif #if ECHONL - | ECHONL + | ECHONL #endif - ); + ); - s.c_oflag |= (0 + s.c_oflag |= (0 #ifdef OXTABS - | OXTABS + | OXTABS #else #ifdef TAB3 - | TAB3 + | TAB3 #else #ifdef XTABS - | XTABS + | XTABS #endif #endif #endif #ifdef OPOST - | OPOST + | OPOST #endif #ifdef ONLCR - | ONLCR + | ONLCR #endif - ); + ); - s.c_oflag &= ~(0 + s.c_oflag &= ~(0 #ifdef ONOEOT - | ONOEOT + | ONOEOT #endif #ifdef OCRNL - | OCRNL + | OCRNL #endif #ifdef ONOCR - | ONOCR + | ONOCR #endif #ifdef ONLRET - | ONLRET + | ONLRET #endif - ); - s.c_cc[VMIN] = 1; - s.c_cc[VTIME] = 0; + ); + s.c_cc[VMIN] = 1; + s.c_cc[VTIME] = 0; #ifdef VLNEXT - s.c_cc[VLNEXT] = 0; + s.c_cc[VLNEXT] = 0; #endif #ifdef VDSUSP - s.c_cc[VDSUSP] = 0; + s.c_cc[VDSUSP] = 0; #endif #if MUST_SET_LINE_DISCIPLINE - /* - * System's termios is broken; need to explicitly - * request TERMIODISC line discipline. - */ - s.c_line = TERMIODISC; -#endif - } else - { - /* - * Restore saved modes. - */ - s = save_term; - } + /* + * System's termios is broken; need to explicitly + * request TERMIODISC line discipline. + */ + s.c_line = TERMIODISC; +#endif + } else + { + /* + * Restore saved modes. + */ + s = save_term; + } #if HAVE_FSYNC - fsync(tty); + fsync(tty); #endif - tcsetattr(tty, TCSADRAIN, &s); + tcsetattr(tty, TCSADRAIN, &s); #if MUST_SET_LINE_DISCIPLINE - if (!on) - { - /* - * Broken termios *ignores* any line discipline - * except TERMIODISC. A different old line discipline - * is therefore not restored, yet. Restore the old - * line discipline by hand. - */ - ioctl(tty, TIOCSETD, &save_term.c_line); - } + if (!on) + { + /* + * Broken termios *ignores* any line discipline + * except TERMIODISC. A different old line discipline + * is therefore not restored, yet. Restore the old + * line discipline by hand. + */ + ioctl(tty, TIOCSETD, &save_term.c_line); + } #endif } #else #ifdef TCGETA { - struct termio s; - static struct termio save_term; - static int saved_term = 0; - - if (on) - { - /* - * Get terminal modes. - */ - ioctl(tty, TCGETA, &s); - - /* - * Save modes and set certain variables dependent on modes. - */ - if (!saved_term) - { - save_term = s; - saved_term = 1; - } + struct termio s; + static struct termio save_term; + static int saved_term = 0; + + if (on) + { + /* + * Get terminal modes. + */ + ioctl(tty, TCGETA, &s); + + /* + * Save modes and set certain variables dependent on modes. + */ + if (!saved_term) + { + save_term = s; + saved_term = 1; + } #if HAVE_OSPEED - ospeed = s.c_cflag & CBAUD; + ospeed = s.c_cflag & CBAUD; #endif - erase_char = s.c_cc[VERASE]; - kill_char = s.c_cc[VKILL]; + erase_char = s.c_cc[VERASE]; + kill_char = s.c_cc[VKILL]; #ifdef VWERASE - werase_char = s.c_cc[VWERASE]; + werase_char = s.c_cc[VWERASE]; #else - werase_char = CONTROL('W'); -#endif - - /* - * Set the modes to the way we want them. - */ - s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); - s.c_oflag |= (OPOST|ONLCR|TAB3); - s.c_oflag &= ~(OCRNL|ONOCR|ONLRET); - s.c_cc[VMIN] = 1; - s.c_cc[VTIME] = 0; - } else - { - /* - * Restore saved modes. - */ - s = save_term; - } - ioctl(tty, TCSETAW, &s); + werase_char = CONTROL('W'); +#endif + + /* + * Set the modes to the way we want them. + */ + s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); + s.c_oflag |= (OPOST|ONLCR|TAB3); + s.c_oflag &= ~(OCRNL|ONOCR|ONLRET); + s.c_cc[VMIN] = 1; + s.c_cc[VTIME] = 0; + } else + { + /* + * Restore saved modes. + */ + s = save_term; + } + ioctl(tty, TCSETAW, &s); } #else #ifdef TIOCGETP { - struct sgttyb s; - static struct sgttyb save_term; - static int saved_term = 0; - - if (on) - { - /* - * Get terminal modes. - */ - ioctl(tty, TIOCGETP, &s); - - /* - * Save modes and set certain variables dependent on modes. - */ - if (!saved_term) - { - save_term = s; - saved_term = 1; - } + struct sgttyb s; + static struct sgttyb save_term; + static int saved_term = 0; + + if (on) + { + /* + * Get terminal modes. + */ + ioctl(tty, TIOCGETP, &s); + + /* + * Save modes and set certain variables dependent on modes. + */ + if (!saved_term) + { + save_term = s; + saved_term = 1; + } #if HAVE_OSPEED - ospeed = s.sg_ospeed; -#endif - erase_char = s.sg_erase; - kill_char = s.sg_kill; - werase_char = CONTROL('W'); - - /* - * Set the modes to the way we want them. - */ - s.sg_flags |= CBREAK; - s.sg_flags &= ~(ECHO|XTABS); - } else - { - /* - * Restore saved modes. - */ - s = save_term; - } - ioctl(tty, TIOCSETN, &s); + ospeed = s.sg_ospeed; +#endif + erase_char = s.sg_erase; + kill_char = s.sg_kill; + werase_char = CONTROL('W'); + + /* + * Set the modes to the way we want them. + */ + s.sg_flags |= CBREAK; + s.sg_flags &= ~(ECHO|XTABS); + } else + { + /* + * Restore saved modes. + */ + s = save_term; + } + ioctl(tty, TIOCSETN, &s); } #else #ifdef _OSK { - struct sgbuf s; - static struct sgbuf save_term; - static int saved_term = 0; - - if (on) - { - /* - * Get terminal modes. - */ - _gs_opt(tty, &s); - - /* - * Save modes and set certain variables dependent on modes. - */ - if (!saved_term) - { - save_term = s; - saved_term = 1; - } - erase_char = s.sg_bspch; - kill_char = s.sg_dlnch; - werase_char = CONTROL('W'); - - /* - * Set the modes to the way we want them. - */ - s.sg_echo = 0; - s.sg_eofch = 0; - s.sg_pause = 0; - s.sg_psch = 0; - } else - { - /* - * Restore saved modes. - */ - s = save_term; - } - _ss_opt(tty, &s); + struct sgbuf s; + static struct sgbuf save_term; + static int saved_term = 0; + + if (on) + { + /* + * Get terminal modes. + */ + _gs_opt(tty, &s); + + /* + * Save modes and set certain variables dependent on modes. + */ + if (!saved_term) + { + save_term = s; + saved_term = 1; + } + erase_char = s.sg_bspch; + kill_char = s.sg_dlnch; + werase_char = CONTROL('W'); + + /* + * Set the modes to the way we want them. + */ + s.sg_echo = 0; + s.sg_eofch = 0; + s.sg_pause = 0; + s.sg_psch = 0; + } else + { + /* + * Restore saved modes. + */ + s = save_term; + } + _ss_opt(tty, &s); } #else - /* MS-DOS, Windows, or OS2 */ + /* MS-DOS, Windows, or OS2 */ #if OS2 - /* OS2 */ - LSIGNAL(SIGINT, SIG_IGN); + /* OS2 */ + LSIGNAL(SIGINT, SIG_IGN); #endif - erase_char = '\b'; + erase_char = '\b'; #if MSDOS_COMPILER==DJGPPC - kill_char = CONTROL('U'); - /* - * So that when we shell out or run another program, its - * stdin is in cooked mode. We do not switch stdin to binary - * mode if fd0 is zero, since that means we were called before - * tty was reopened in open_getchr, in which case we would be - * changing the original stdin device outside less. - */ - if (fd0 != 0) - setmode(0, on ? O_BINARY : O_TEXT); + kill_char = CONTROL('U'); + /* + * So that when we shell out or run another program, its + * stdin is in cooked mode. We do not switch stdin to binary + * mode if fd0 is zero, since that means we were called before + * tty was reopened in open_getchr, in which case we would be + * changing the original stdin device outside less. + */ + if (fd0 != 0) + setmode(0, on ? O_BINARY : O_TEXT); #else - kill_char = ESC; + kill_char = ESC; #endif - werase_char = CONTROL('W'); + werase_char = CONTROL('W'); #endif #endif #endif #endif - curr_on = on; + curr_on = on; } #if !MSDOS_COMPILER @@ -670,84 +670,84 @@ raw_mode(on) */ static int hardcopy; - static char * + static char * ltget_env(capname) - char *capname; -{ - char name[64]; - - if (termcap_debug) - { - struct env { struct env *next; char *name; char *value; }; - static struct env *envs = NULL; - struct env *p; - for (p = envs; p != NULL; p = p->next) - if (strcmp(p->name, capname) == 0) - return p->value; - p = (struct env *) ecalloc(1, sizeof(struct env)); - p->name = save(capname); - p->value = (char *) ecalloc(strlen(capname)+3, sizeof(char)); - sprintf(p->value, "<%s>", capname); - p->next = envs; - envs = p; - return p->value; - } - SNPRINTF1(name, sizeof(name), "LESS_TERMCAP_%s", capname); - return (lgetenv(name)); -} - - static int + char *capname; +{ + char name[64]; + + if (termcap_debug) + { + struct env { struct env *next; char *name; char *value; }; + static struct env *envs = NULL; + struct env *p; + for (p = envs; p != NULL; p = p->next) + if (strcmp(p->name, capname) == 0) + return p->value; + p = (struct env *) ecalloc(1, sizeof(struct env)); + p->name = save(capname); + p->value = (char *) ecalloc(strlen(capname)+3, sizeof(char)); + sprintf(p->value, "<%s>", capname); + p->next = envs; + envs = p; + return p->value; + } + SNPRINTF1(name, sizeof(name), "LESS_TERMCAP_%s", capname); + return (lgetenv(name)); +} + + static int ltgetflag(capname) - char *capname; + char *capname; { - char *s; + char *s; - if ((s = ltget_env(capname)) != NULL) - return (*s != '\0' && *s != '0'); - if (hardcopy) - return (0); - return (tgetflag(capname)); + if ((s = ltget_env(capname)) != NULL) + return (*s != '\0' && *s != '0'); + if (hardcopy) + return (0); + return (tgetflag(capname)); } - static int + static int ltgetnum(capname) - char *capname; + char *capname; { - char *s; + char *s; - if ((s = ltget_env(capname)) != NULL) - return (atoi(s)); - if (hardcopy) - return (-1); - return (tgetnum(capname)); + if ((s = ltget_env(capname)) != NULL) + return (atoi(s)); + if (hardcopy) + return (-1); + return (tgetnum(capname)); } - static char * + static char * ltgetstr(capname, pp) - char *capname; - char **pp; + char *capname; + char **pp; { - char *s; + char *s; - if ((s = ltget_env(capname)) != NULL) - return (s); - if (hardcopy) - return (NULL); - return (tgetstr(capname, pp)); + if ((s = ltget_env(capname)) != NULL) + return (s); + if (hardcopy) + return (NULL); + return (tgetstr(capname, pp)); } #endif /* MSDOS_COMPILER */ /* * Get size of the output screen. */ - public void + public void scrsize(VOID_PARAM) { - char *s; - int sys_height; - int sys_width; + char *s; + int sys_height; + int sys_width; #if !MSDOS_COMPILER - int n; + int n; #endif #define DEF_SC_WIDTH 80 @@ -758,84 +758,84 @@ scrsize(VOID_PARAM) #endif - sys_width = sys_height = 0; + sys_width = sys_height = 0; #if MSDOS_COMPILER==MSOFTC - { - struct videoconfig w; - _getvideoconfig(&w); - sys_height = w.numtextrows; - sys_width = w.numtextcols; - } + { + struct videoconfig w; + _getvideoconfig(&w); + sys_height = w.numtextrows; + sys_width = w.numtextcols; + } #else #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - { - struct text_info w; - gettextinfo(&w); - sys_height = w.screenheight; - sys_width = w.screenwidth; - } + { + struct text_info w; + gettextinfo(&w); + sys_height = w.screenheight; + sys_width = w.screenwidth; + } #else #if MSDOS_COMPILER==WIN32C - { - CONSOLE_SCREEN_BUFFER_INFO scr; - GetConsoleScreenBufferInfo(con_out, &scr); - sys_height = scr.srWindow.Bottom - scr.srWindow.Top + 1; - sys_width = scr.srWindow.Right - scr.srWindow.Left + 1; - } + { + CONSOLE_SCREEN_BUFFER_INFO scr; + GetConsoleScreenBufferInfo(con_out, &scr); + sys_height = scr.srWindow.Bottom - scr.srWindow.Top + 1; + sys_width = scr.srWindow.Right - scr.srWindow.Left + 1; + } #else #if OS2 - { - int s[2]; - _scrsize(s); - sys_width = s[0]; - sys_height = s[1]; - /* - * When using terminal emulators for XFree86/OS2, the - * _scrsize function does not work well. - * Call the scrsize.exe program to get the window size. - */ - windowid = getenv("WINDOWID"); - if (windowid != NULL) - { - FILE *fd = popen("scrsize", "rt"); - if (fd != NULL) - { - int w, h; - fscanf(fd, "%i %i", &w, &h); - if (w > 0 && h > 0) - { - sys_width = w; - sys_height = h; - } - pclose(fd); - } - } - } + { + int s[2]; + _scrsize(s); + sys_width = s[0]; + sys_height = s[1]; + /* + * When using terminal emulators for XFree86/OS2, the + * _scrsize function does not work well. + * Call the scrsize.exe program to get the window size. + */ + windowid = getenv("WINDOWID"); + if (windowid != NULL) + { + FILE *fd = popen("scrsize", "rt"); + if (fd != NULL) + { + int w, h; + fscanf(fd, "%i %i", &w, &h); + if (w > 0 && h > 0) + { + sys_width = w; + sys_height = h; + } + pclose(fd); + } + } + } #else #ifdef TIOCGWINSZ - { - struct winsize w; - if (ioctl(2, TIOCGWINSZ, &w) == 0) - { - if (w.ws_row > 0) - sys_height = w.ws_row; - if (w.ws_col > 0) - sys_width = w.ws_col; - } - } + { + struct winsize w; + if (ioctl(2, TIOCGWINSZ, &w) == 0) + { + if (w.ws_row > 0) + sys_height = w.ws_row; + if (w.ws_col > 0) + sys_width = w.ws_col; + } + } #else #ifdef WIOCGETD - { - struct uwdata w; - if (ioctl(2, WIOCGETD, &w) == 0) - { - if (w.uw_height > 0) - sys_height = w.uw_height / w.uw_vs; - if (w.uw_width > 0) - sys_width = w.uw_width / w.uw_hs; - } - } + { + struct uwdata w; + if (ioctl(2, WIOCGETD, &w) == 0) + { + if (w.uw_height > 0) + sys_height = w.uw_height / w.uw_vs; + if (w.uw_width > 0) + sys_width = w.uw_width / w.uw_hs; + } + } #endif #endif #endif @@ -843,543 +843,543 @@ scrsize(VOID_PARAM) #endif #endif - if ((s = lgetenv("LINES")) != NULL) - sc_height = atoi(s); - else if (sys_height > 0) - sc_height = sys_height; + if ((s = lgetenv("LINES")) != NULL) + sc_height = atoi(s); + else if (sys_height > 0) + sc_height = sys_height; #if !MSDOS_COMPILER - else if ((n = ltgetnum("li")) > 0) - sc_height = n; + else if ((n = ltgetnum("li")) > 0) + sc_height = n; #endif - if (sc_height <= 0) - sc_height = DEF_SC_HEIGHT; + if (sc_height <= 0) + sc_height = DEF_SC_HEIGHT; - if ((s = lgetenv("COLUMNS")) != NULL) - sc_width = atoi(s); - else if (sys_width > 0) - sc_width = sys_width; + if ((s = lgetenv("COLUMNS")) != NULL) + sc_width = atoi(s); + else if (sys_width > 0) + sc_width = sys_width; #if !MSDOS_COMPILER - else if ((n = ltgetnum("co")) > 0) - sc_width = n; + else if ((n = ltgetnum("co")) > 0) + sc_width = n; #endif - if (sc_width <= 0) - sc_width = DEF_SC_WIDTH; + if (sc_width <= 0) + sc_width = DEF_SC_WIDTH; } #if MSDOS_COMPILER==MSOFTC /* * Figure out how many empty loops it takes to delay a millisecond. */ - static void + static void get_clock(VOID_PARAM) { - clock_t start; - - /* - * Get synchronized at the start of a tick. - */ - start = clock(); - while (clock() == start) - ; - /* - * Now count loops till the next tick. - */ - start = clock(); - msec_loops = 0; - while (clock() == start) - msec_loops++; - /* - * Convert from (loops per clock) to (loops per millisecond). - */ - msec_loops *= CLOCKS_PER_SEC; - msec_loops /= 1000; + clock_t start; + + /* + * Get synchronized at the start of a tick. + */ + start = clock(); + while (clock() == start) + ; + /* + * Now count loops till the next tick. + */ + start = clock(); + msec_loops = 0; + while (clock() == start) + msec_loops++; + /* + * Convert from (loops per clock) to (loops per millisecond). + */ + msec_loops *= CLOCKS_PER_SEC; + msec_loops /= 1000; } /* * Delay for a specified number of milliseconds. */ - static void + static void delay(msec) - int msec; + int msec; { - long i; - - while (msec-- > 0) - { - for (i = 0; i < msec_loops; i++) - (void) clock(); - } + long i; + + while (msec-- > 0) + { + for (i = 0; i < msec_loops; i++) + (void) clock(); + } } #endif /* * Return the characters actually input by a "special" key. */ - public char * + public char * special_key_str(key) - int key; + int key; { - static char tbuf[40]; - char *s; + static char tbuf[40]; + char *s; #if MSDOS_COMPILER || OS2 - static char k_right[] = { '\340', PCK_RIGHT, 0 }; - static char k_left[] = { '\340', PCK_LEFT, 0 }; - static char k_ctl_right[] = { '\340', PCK_CTL_RIGHT, 0 }; - static char k_ctl_left[] = { '\340', PCK_CTL_LEFT, 0 }; - static char k_insert[] = { '\340', PCK_INSERT, 0 }; - static char k_delete[] = { '\340', PCK_DELETE, 0 }; - static char k_ctl_delete[] = { '\340', PCK_CTL_DELETE, 0 }; - static char k_ctl_backspace[] = { '\177', 0 }; - static char k_home[] = { '\340', PCK_HOME, 0 }; - static char k_end[] = { '\340', PCK_END, 0 }; - static char k_up[] = { '\340', PCK_UP, 0 }; - static char k_down[] = { '\340', PCK_DOWN, 0 }; - static char k_backtab[] = { '\340', PCK_SHIFT_TAB, 0 }; - static char k_pagedown[] = { '\340', PCK_PAGEDOWN, 0 }; - static char k_pageup[] = { '\340', PCK_PAGEUP, 0 }; - static char k_f1[] = { '\340', PCK_F1, 0 }; + static char k_right[] = { '\340', PCK_RIGHT, 0 }; + static char k_left[] = { '\340', PCK_LEFT, 0 }; + static char k_ctl_right[] = { '\340', PCK_CTL_RIGHT, 0 }; + static char k_ctl_left[] = { '\340', PCK_CTL_LEFT, 0 }; + static char k_insert[] = { '\340', PCK_INSERT, 0 }; + static char k_delete[] = { '\340', PCK_DELETE, 0 }; + static char k_ctl_delete[] = { '\340', PCK_CTL_DELETE, 0 }; + static char k_ctl_backspace[] = { '\177', 0 }; + static char k_home[] = { '\340', PCK_HOME, 0 }; + static char k_end[] = { '\340', PCK_END, 0 }; + static char k_up[] = { '\340', PCK_UP, 0 }; + static char k_down[] = { '\340', PCK_DOWN, 0 }; + static char k_backtab[] = { '\340', PCK_SHIFT_TAB, 0 }; + static char k_pagedown[] = { '\340', PCK_PAGEDOWN, 0 }; + static char k_pageup[] = { '\340', PCK_PAGEUP, 0 }; + static char k_f1[] = { '\340', PCK_F1, 0 }; #endif #if !MSDOS_COMPILER - char *sp = tbuf; + char *sp = tbuf; #endif - switch (key) - { + switch (key) + { #if OS2 - /* - * If windowid is not NULL, assume less is executed in - * the XFree86 environment. - */ - case SK_RIGHT_ARROW: - s = windowid ? ltgetstr("kr", &sp) : k_right; - break; - case SK_LEFT_ARROW: - s = windowid ? ltgetstr("kl", &sp) : k_left; - break; - case SK_UP_ARROW: - s = windowid ? ltgetstr("ku", &sp) : k_up; - break; - case SK_DOWN_ARROW: - s = windowid ? ltgetstr("kd", &sp) : k_down; - break; - case SK_PAGE_UP: - s = windowid ? ltgetstr("kP", &sp) : k_pageup; - break; - case SK_PAGE_DOWN: - s = windowid ? ltgetstr("kN", &sp) : k_pagedown; - break; - case SK_HOME: - s = windowid ? ltgetstr("kh", &sp) : k_home; - break; - case SK_END: - s = windowid ? ltgetstr("@7", &sp) : k_end; - break; - case SK_DELETE: - s = windowid ? ltgetstr("kD", &sp) : k_delete; - if (s == NULL) - { - tbuf[0] = '\177'; - tbuf[1] = '\0'; - s = tbuf; - } - break; + /* + * If windowid is not NULL, assume less is executed in + * the XFree86 environment. + */ + case SK_RIGHT_ARROW: + s = windowid ? ltgetstr("kr", &sp) : k_right; + break; + case SK_LEFT_ARROW: + s = windowid ? ltgetstr("kl", &sp) : k_left; + break; + case SK_UP_ARROW: + s = windowid ? ltgetstr("ku", &sp) : k_up; + break; + case SK_DOWN_ARROW: + s = windowid ? ltgetstr("kd", &sp) : k_down; + break; + case SK_PAGE_UP: + s = windowid ? ltgetstr("kP", &sp) : k_pageup; + break; + case SK_PAGE_DOWN: + s = windowid ? ltgetstr("kN", &sp) : k_pagedown; + break; + case SK_HOME: + s = windowid ? ltgetstr("kh", &sp) : k_home; + break; + case SK_END: + s = windowid ? ltgetstr("@7", &sp) : k_end; + break; + case SK_DELETE: + s = windowid ? ltgetstr("kD", &sp) : k_delete; + if (s == NULL) + { + tbuf[0] = '\177'; + tbuf[1] = '\0'; + s = tbuf; + } + break; #endif #if MSDOS_COMPILER - case SK_RIGHT_ARROW: - s = k_right; - break; - case SK_LEFT_ARROW: - s = k_left; - break; - case SK_UP_ARROW: - s = k_up; - break; - case SK_DOWN_ARROW: - s = k_down; - break; - case SK_PAGE_UP: - s = k_pageup; - break; - case SK_PAGE_DOWN: - s = k_pagedown; - break; - case SK_HOME: - s = k_home; - break; - case SK_END: - s = k_end; - break; - case SK_DELETE: - s = k_delete; - break; + case SK_RIGHT_ARROW: + s = k_right; + break; + case SK_LEFT_ARROW: + s = k_left; + break; + case SK_UP_ARROW: + s = k_up; + break; + case SK_DOWN_ARROW: + s = k_down; + break; + case SK_PAGE_UP: + s = k_pageup; + break; + case SK_PAGE_DOWN: + s = k_pagedown; + break; + case SK_HOME: + s = k_home; + break; + case SK_END: + s = k_end; + break; + case SK_DELETE: + s = k_delete; + break; #endif #if MSDOS_COMPILER || OS2 - case SK_INSERT: - s = k_insert; - break; - case SK_CTL_LEFT_ARROW: - s = k_ctl_left; - break; - case SK_CTL_RIGHT_ARROW: - s = k_ctl_right; - break; - case SK_CTL_BACKSPACE: - s = k_ctl_backspace; - break; - case SK_CTL_DELETE: - s = k_ctl_delete; - break; - case SK_F1: - s = k_f1; - break; - case SK_BACKTAB: - s = k_backtab; - break; + case SK_INSERT: + s = k_insert; + break; + case SK_CTL_LEFT_ARROW: + s = k_ctl_left; + break; + case SK_CTL_RIGHT_ARROW: + s = k_ctl_right; + break; + case SK_CTL_BACKSPACE: + s = k_ctl_backspace; + break; + case SK_CTL_DELETE: + s = k_ctl_delete; + break; + case SK_F1: + s = k_f1; + break; + case SK_BACKTAB: + s = k_backtab; + break; #else - case SK_RIGHT_ARROW: - s = ltgetstr("kr", &sp); - break; - case SK_LEFT_ARROW: - s = ltgetstr("kl", &sp); - break; - case SK_UP_ARROW: - s = ltgetstr("ku", &sp); - break; - case SK_DOWN_ARROW: - s = ltgetstr("kd", &sp); - break; - case SK_PAGE_UP: - s = ltgetstr("kP", &sp); - break; - case SK_PAGE_DOWN: - s = ltgetstr("kN", &sp); - break; - case SK_HOME: - s = ltgetstr("kh", &sp); - break; - case SK_END: - s = ltgetstr("@7", &sp); - break; - case SK_DELETE: - s = ltgetstr("kD", &sp); - if (s == NULL) - { - tbuf[0] = '\177'; - tbuf[1] = '\0'; - s = tbuf; - } - break; -#endif - case SK_CONTROL_K: - tbuf[0] = CONTROL('K'); - tbuf[1] = '\0'; - s = tbuf; - break; - default: - return (NULL); - } - return (s); + case SK_RIGHT_ARROW: + s = ltgetstr("kr", &sp); + break; + case SK_LEFT_ARROW: + s = ltgetstr("kl", &sp); + break; + case SK_UP_ARROW: + s = ltgetstr("ku", &sp); + break; + case SK_DOWN_ARROW: + s = ltgetstr("kd", &sp); + break; + case SK_PAGE_UP: + s = ltgetstr("kP", &sp); + break; + case SK_PAGE_DOWN: + s = ltgetstr("kN", &sp); + break; + case SK_HOME: + s = ltgetstr("kh", &sp); + break; + case SK_END: + s = ltgetstr("@7", &sp); + break; + case SK_DELETE: + s = ltgetstr("kD", &sp); + if (s == NULL) + { + tbuf[0] = '\177'; + tbuf[1] = '\0'; + s = tbuf; + } + break; +#endif + case SK_CONTROL_K: + tbuf[0] = CONTROL('K'); + tbuf[1] = '\0'; + s = tbuf; + break; + default: + return (NULL); + } + return (s); } /* * Get terminal capabilities via termcap. */ - public void + public void get_term(VOID_PARAM) { - termcap_debug = !isnullenv(lgetenv("LESS_TERMCAP_DEBUG")); + termcap_debug = !isnullenv(lgetenv("LESS_TERMCAP_DEBUG")); #if MSDOS_COMPILER - auto_wrap = 1; - ignaw = 0; - can_goto_line = 1; - clear_bg = 1; - /* - * Set up default colors. - * The xx_s_width and xx_e_width vars are already initialized to 0. - */ + auto_wrap = 1; + ignaw = 0; + can_goto_line = 1; + clear_bg = 1; + /* + * Set up default colors. + * The xx_s_width and xx_e_width vars are already initialized to 0. + */ #if MSDOS_COMPILER==MSOFTC - sy_bg_color = _getbkcolor(); - sy_fg_color = _gettextcolor(); - get_clock(); + sy_bg_color = _getbkcolor(); + sy_fg_color = _gettextcolor(); + get_clock(); #else #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC { - struct text_info w; - gettextinfo(&w); - sy_bg_color = (w.attribute >> 4) & 0x0F; - sy_fg_color = (w.attribute >> 0) & 0x0F; + struct text_info w; + gettextinfo(&w); + sy_bg_color = (w.attribute >> 4) & 0x0F; + sy_fg_color = (w.attribute >> 0) & 0x0F; } #else #if MSDOS_COMPILER==WIN32C { - CONSOLE_SCREEN_BUFFER_INFO scr; - - con_out_save = con_out = GetStdHandle(STD_OUTPUT_HANDLE); - /* - * Always open stdin in binary. Note this *must* be done - * before any file operations have been done on fd0. - */ - SET_BINARY(0); - GetConsoleMode(con_out, &init_output_mode); - GetConsoleScreenBufferInfo(con_out, &scr); - curr_attr = scr.wAttributes; - sy_bg_color = (curr_attr & BG_COLORS) >> 4; /* normalize */ - sy_fg_color = curr_attr & FG_COLORS; + CONSOLE_SCREEN_BUFFER_INFO scr; + + con_out_save = con_out = GetStdHandle(STD_OUTPUT_HANDLE); + /* + * Always open stdin in binary. Note this *must* be done + * before any file operations have been done on fd0. + */ + SET_BINARY(0); + GetConsoleMode(con_out, &init_output_mode); + GetConsoleScreenBufferInfo(con_out, &scr); + curr_attr = scr.wAttributes; + sy_bg_color = (curr_attr & BG_COLORS) >> 4; /* normalize */ + sy_fg_color = curr_attr & FG_COLORS; } #endif #endif #endif - nm_fg_color = sy_fg_color; - nm_bg_color = sy_bg_color; - bo_fg_color = 11; - bo_bg_color = 0; - ul_fg_color = 9; - ul_bg_color = 0; - so_fg_color = 15; - so_bg_color = 9; - bl_fg_color = 15; - bl_bg_color = 0; - sgr_mode = 0; + nm_fg_color = sy_fg_color; + nm_bg_color = sy_bg_color; + bo_fg_color = 11; + bo_bg_color = 0; + ul_fg_color = 9; + ul_bg_color = 0; + so_fg_color = 15; + so_bg_color = 9; + bl_fg_color = 15; + bl_bg_color = 0; + sgr_mode = 0; - /* - * Get size of the screen. - */ - scrsize(); - pos_init(); + /* + * Get size of the screen. + */ + scrsize(); + pos_init(); #else /* !MSDOS_COMPILER */ { - char *sp; - char *t1, *t2; - char *term; - /* - * Some termcap libraries assume termbuf is static - * (accessible after tgetent returns). - */ - static char termbuf[TERMBUF_SIZE]; - static char sbuf[TERMSBUF_SIZE]; + char *sp; + char *t1, *t2; + char *term; + /* + * Some termcap libraries assume termbuf is static + * (accessible after tgetent returns). + */ + static char termbuf[TERMBUF_SIZE]; + static char sbuf[TERMSBUF_SIZE]; #if OS2 - /* - * Make sure the termcap database is available. - */ - sp = lgetenv("TERMCAP"); - if (isnullenv(sp)) - { - char *termcap; - if ((sp = homefile("termcap.dat")) != NULL) - { - termcap = (char *) ecalloc(strlen(sp)+9, sizeof(char)); - sprintf(termcap, "TERMCAP=%s", sp); - free(sp); - putenv(termcap); - } - } -#endif - /* - * Find out what kind of terminal this is. - */ - if ((term = lgetenv("TERM")) == NULL) - term = DEFAULT_TERM; - hardcopy = 0; - /* {{ Should probably just pass NULL instead of termbuf. }} */ - if (tgetent(termbuf, term) != TGETENT_OK) - hardcopy = 1; - if (ltgetflag("hc")) - hardcopy = 1; - - /* - * Get size of the screen. - */ - scrsize(); - pos_init(); - - auto_wrap = ltgetflag("am"); - ignaw = ltgetflag("xn"); - above_mem = ltgetflag("da"); - below_mem = ltgetflag("db"); - clear_bg = ltgetflag("ut"); - - /* - * Assumes termcap variable "sg" is the printing width of: - * the standout sequence, the end standout sequence, - * the underline sequence, the end underline sequence, - * the boldface sequence, and the end boldface sequence. - */ - if ((so_s_width = ltgetnum("sg")) < 0) - so_s_width = 0; - so_e_width = so_s_width; - - bo_s_width = bo_e_width = so_s_width; - ul_s_width = ul_e_width = so_s_width; - bl_s_width = bl_e_width = so_s_width; + /* + * Make sure the termcap database is available. + */ + sp = lgetenv("TERMCAP"); + if (isnullenv(sp)) + { + char *termcap; + if ((sp = homefile("termcap.dat")) != NULL) + { + termcap = (char *) ecalloc(strlen(sp)+9, sizeof(char)); + sprintf(termcap, "TERMCAP=%s", sp); + free(sp); + putenv(termcap); + } + } +#endif + /* + * Find out what kind of terminal this is. + */ + if ((term = lgetenv("TERM")) == NULL) + term = DEFAULT_TERM; + hardcopy = 0; + /* {{ Should probably just pass NULL instead of termbuf. }} */ + if (tgetent(termbuf, term) != TGETENT_OK) + hardcopy = 1; + if (ltgetflag("hc")) + hardcopy = 1; + + /* + * Get size of the screen. + */ + scrsize(); + pos_init(); + + auto_wrap = ltgetflag("am"); + ignaw = ltgetflag("xn"); + above_mem = ltgetflag("da"); + below_mem = ltgetflag("db"); + clear_bg = ltgetflag("ut"); + + /* + * Assumes termcap variable "sg" is the printing width of: + * the standout sequence, the end standout sequence, + * the underline sequence, the end underline sequence, + * the boldface sequence, and the end boldface sequence. + */ + if ((so_s_width = ltgetnum("sg")) < 0) + so_s_width = 0; + so_e_width = so_s_width; + + bo_s_width = bo_e_width = so_s_width; + ul_s_width = ul_e_width = so_s_width; + bl_s_width = bl_e_width = so_s_width; #if HILITE_SEARCH - if (so_s_width > 0 || so_e_width > 0) - /* - * Disable highlighting by default on magic cookie terminals. - * Turning on highlighting might change the displayed width - * of a line, causing the display to get messed up. - * The user can turn it back on with -g, - * but she won't like the results. - */ - hilite_search = 0; -#endif - - /* - * Get various string-valued capabilities. - */ - sp = sbuf; + if (so_s_width > 0 || so_e_width > 0) + /* + * Disable highlighting by default on magic cookie terminals. + * Turning on highlighting might change the displayed width + * of a line, causing the display to get messed up. + * The user can turn it back on with -g, + * but she won't like the results. + */ + hilite_search = 0; +#endif + + /* + * Get various string-valued capabilities. + */ + sp = sbuf; #if HAVE_OSPEED - sc_pad = ltgetstr("pc", &sp); - if (sc_pad != NULL) - PC = *sc_pad; -#endif - - sc_s_keypad = ltgetstr("ks", &sp); - if (sc_s_keypad == NULL) - sc_s_keypad = ""; - sc_e_keypad = ltgetstr("ke", &sp); - if (sc_e_keypad == NULL) - sc_e_keypad = ""; - kent = ltgetstr("@8", &sp); - - sc_s_mousecap = ltgetstr("MOUSE_START", &sp); - if (sc_s_mousecap == NULL) - sc_s_mousecap = ESCS "[?1000h" ESCS "[?1006h"; - sc_e_mousecap = ltgetstr("MOUSE_END", &sp); - if (sc_e_mousecap == NULL) - sc_e_mousecap = ESCS "[?1006l" ESCS "[?1000l"; - - sc_init = ltgetstr("ti", &sp); - if (sc_init == NULL) - sc_init = ""; - - sc_deinit= ltgetstr("te", &sp); - if (sc_deinit == NULL) - sc_deinit = ""; - - sc_eol_clear = ltgetstr("ce", &sp); - if (sc_eol_clear == NULL || *sc_eol_clear == '\0') - { - missing_cap = 1; - sc_eol_clear = ""; - } - - sc_eos_clear = ltgetstr("cd", &sp); - if (below_mem && (sc_eos_clear == NULL || *sc_eos_clear == '\0')) - { - missing_cap = 1; - sc_eos_clear = ""; - } - - sc_clear = ltgetstr("cl", &sp); - if (sc_clear == NULL || *sc_clear == '\0') - { - missing_cap = 1; - sc_clear = "\n\n"; - } - - sc_move = ltgetstr("cm", &sp); - if (sc_move == NULL || *sc_move == '\0') - { - /* - * This is not an error here, because we don't - * always need sc_move. - * We need it only if we don't have home or lower-left. - */ - sc_move = ""; - can_goto_line = 0; - } else - can_goto_line = 1; - - tmodes("so", "se", &sc_s_in, &sc_s_out, "", "", &sp); - tmodes("us", "ue", &sc_u_in, &sc_u_out, sc_s_in, sc_s_out, &sp); - tmodes("md", "me", &sc_b_in, &sc_b_out, sc_s_in, sc_s_out, &sp); - tmodes("mb", "me", &sc_bl_in, &sc_bl_out, sc_s_in, sc_s_out, &sp); - - sc_visual_bell = ltgetstr("vb", &sp); - if (sc_visual_bell == NULL) - sc_visual_bell = ""; - - if (ltgetflag("bs")) - sc_backspace = "\b"; - else - { - sc_backspace = ltgetstr("bc", &sp); - if (sc_backspace == NULL || *sc_backspace == '\0') - sc_backspace = "\b"; - } - - /* - * Choose between using "ho" and "cm" ("home" and "cursor move") - * to move the cursor to the upper left corner of the screen. - */ - t1 = ltgetstr("ho", &sp); - if (t1 == NULL) - t1 = ""; - if (*sc_move == '\0') - t2 = ""; - else - { - strcpy(sp, tgoto(sc_move, 0, 0)); - t2 = sp; - sp += strlen(sp) + 1; - } - sc_home = cheaper(t1, t2, "|\b^"); - - /* - * Choose between using "ll" and "cm" ("lower left" and "cursor move") - * to move the cursor to the lower left corner of the screen. - */ - t1 = ltgetstr("ll", &sp); - if (t1 == NULL) - t1 = ""; - if (*sc_move == '\0') - t2 = ""; - else - { - strcpy(sp, tgoto(sc_move, 0, sc_height-1)); - t2 = sp; - sp += strlen(sp) + 1; - } - sc_lower_left = cheaper(t1, t2, "\r"); - - /* - * Get carriage return string. - */ - sc_return = ltgetstr("cr", &sp); - if (sc_return == NULL) - sc_return = "\r"; - - /* - * Choose between using "al" or "sr" ("add line" or "scroll reverse") - * to add a line at the top of the screen. - */ - t1 = ltgetstr("al", &sp); - if (t1 == NULL) - t1 = ""; - t2 = ltgetstr("sr", &sp); - if (t2 == NULL) - t2 = ""; + sc_pad = ltgetstr("pc", &sp); + if (sc_pad != NULL) + PC = *sc_pad; +#endif + + sc_s_keypad = ltgetstr("ks", &sp); + if (sc_s_keypad == NULL) + sc_s_keypad = ""; + sc_e_keypad = ltgetstr("ke", &sp); + if (sc_e_keypad == NULL) + sc_e_keypad = ""; + kent = ltgetstr("@8", &sp); + + sc_s_mousecap = ltgetstr("MOUSE_START", &sp); + if (sc_s_mousecap == NULL) + sc_s_mousecap = ESCS "[?1000h" ESCS "[?1006h"; + sc_e_mousecap = ltgetstr("MOUSE_END", &sp); + if (sc_e_mousecap == NULL) + sc_e_mousecap = ESCS "[?1006l" ESCS "[?1000l"; + + sc_init = ltgetstr("ti", &sp); + if (sc_init == NULL) + sc_init = ""; + + sc_deinit= ltgetstr("te", &sp); + if (sc_deinit == NULL) + sc_deinit = ""; + + sc_eol_clear = ltgetstr("ce", &sp); + if (sc_eol_clear == NULL || *sc_eol_clear == '\0') + { + missing_cap = 1; + sc_eol_clear = ""; + } + + sc_eos_clear = ltgetstr("cd", &sp); + if (below_mem && (sc_eos_clear == NULL || *sc_eos_clear == '\0')) + { + missing_cap = 1; + sc_eos_clear = ""; + } + + sc_clear = ltgetstr("cl", &sp); + if (sc_clear == NULL || *sc_clear == '\0') + { + missing_cap = 1; + sc_clear = "\n\n"; + } + + sc_move = ltgetstr("cm", &sp); + if (sc_move == NULL || *sc_move == '\0') + { + /* + * This is not an error here, because we don't + * always need sc_move. + * We need it only if we don't have home or lower-left. + */ + sc_move = ""; + can_goto_line = 0; + } else + can_goto_line = 1; + + tmodes("so", "se", &sc_s_in, &sc_s_out, "", "", &sp); + tmodes("us", "ue", &sc_u_in, &sc_u_out, sc_s_in, sc_s_out, &sp); + tmodes("md", "me", &sc_b_in, &sc_b_out, sc_s_in, sc_s_out, &sp); + tmodes("mb", "me", &sc_bl_in, &sc_bl_out, sc_s_in, sc_s_out, &sp); + + sc_visual_bell = ltgetstr("vb", &sp); + if (sc_visual_bell == NULL) + sc_visual_bell = ""; + + if (ltgetflag("bs")) + sc_backspace = "\b"; + else + { + sc_backspace = ltgetstr("bc", &sp); + if (sc_backspace == NULL || *sc_backspace == '\0') + sc_backspace = "\b"; + } + + /* + * Choose between using "ho" and "cm" ("home" and "cursor move") + * to move the cursor to the upper left corner of the screen. + */ + t1 = ltgetstr("ho", &sp); + if (t1 == NULL) + t1 = ""; + if (*sc_move == '\0') + t2 = ""; + else + { + strcpy(sp, tgoto(sc_move, 0, 0)); + t2 = sp; + sp += strlen(sp) + 1; + } + sc_home = cheaper(t1, t2, "|\b^"); + + /* + * Choose between using "ll" and "cm" ("lower left" and "cursor move") + * to move the cursor to the lower left corner of the screen. + */ + t1 = ltgetstr("ll", &sp); + if (t1 == NULL) + t1 = ""; + if (*sc_move == '\0') + t2 = ""; + else + { + strcpy(sp, tgoto(sc_move, 0, sc_height-1)); + t2 = sp; + sp += strlen(sp) + 1; + } + sc_lower_left = cheaper(t1, t2, "\r"); + + /* + * Get carriage return string. + */ + sc_return = ltgetstr("cr", &sp); + if (sc_return == NULL) + sc_return = "\r"; + + /* + * Choose between using "al" or "sr" ("add line" or "scroll reverse") + * to add a line at the top of the screen. + */ + t1 = ltgetstr("al", &sp); + if (t1 == NULL) + t1 = ""; + t2 = ltgetstr("sr", &sp); + if (t2 == NULL) + t2 = ""; #if OS2 - if (*t1 == '\0' && *t2 == '\0') - sc_addline = ""; - else -#endif - if (above_mem) - sc_addline = t1; - else - sc_addline = cheaper(t1, t2, ""); - if (*sc_addline == '\0') - { - /* - * Force repaint on any backward movement. - */ - no_back_scroll = 1; - } + if (*t1 == '\0' && *t2 == '\0') + sc_addline = ""; + else +#endif + if (above_mem) + sc_addline = t1; + else + sc_addline = cheaper(t1, t2, ""); + if (*sc_addline == '\0') + { + /* + * Force repaint on any backward movement. + */ + no_back_scroll = 1; + } } #endif /* MSDOS_COMPILER */ } @@ -1395,80 +1395,80 @@ get_term(VOID_PARAM) static int costcount; /*ARGSUSED*/ - static int + static int inc_costcount(c) - int c; + int c; { - costcount++; - return (c); + costcount++; + return (c); } - static int + static int cost(t) - char *t; + char *t; { - costcount = 0; - tputs(t, sc_height, inc_costcount); - return (costcount); + costcount = 0; + tputs(t, sc_height, inc_costcount); + return (costcount); } /* * Return the "best" of the two given termcap strings. - * The best, if both exist, is the one with the lower + * The best, if both exist, is the one with the lower * cost (see cost() function). */ - static char * + static char * cheaper(t1, t2, def) - char *t1, *t2; - char *def; -{ - if (*t1 == '\0' && *t2 == '\0') - { - missing_cap = 1; - return (def); - } - if (*t1 == '\0') - return (t2); - if (*t2 == '\0') - return (t1); - if (cost(t1) < cost(t2)) - return (t1); - return (t2); -} - - static void + char *t1, *t2; + char *def; +{ + if (*t1 == '\0' && *t2 == '\0') + { + missing_cap = 1; + return (def); + } + if (*t1 == '\0') + return (t2); + if (*t2 == '\0') + return (t1); + if (cost(t1) < cost(t2)) + return (t1); + return (t2); +} + + static void tmodes(incap, outcap, instr, outstr, def_instr, def_outstr, spp) - char *incap; - char *outcap; - char **instr; - char **outstr; - char *def_instr; - char *def_outstr; - char **spp; -{ - *instr = ltgetstr(incap, spp); - if (*instr == NULL) - { - /* Use defaults. */ - *instr = def_instr; - *outstr = def_outstr; - return; - } - - *outstr = ltgetstr(outcap, spp); - if (*outstr == NULL) - /* No specific out capability; use "me". */ - *outstr = ltgetstr("me", spp); - if (*outstr == NULL) - /* Don't even have "me"; use a null string. */ - *outstr = ""; + char *incap; + char *outcap; + char **instr; + char **outstr; + char *def_instr; + char *def_outstr; + char **spp; +{ + *instr = ltgetstr(incap, spp); + if (*instr == NULL) + { + /* Use defaults. */ + *instr = def_instr; + *outstr = def_outstr; + return; + } + + *outstr = ltgetstr(outcap, spp); + if (*outstr == NULL) + /* No specific out capability; use "me". */ + *outstr = ltgetstr("me", spp); + if (*outstr == NULL) + /* Don't even have "me"; use a null string. */ + *outstr = ""; } #endif /* MSDOS_COMPILER */ /* - * Below are the functions which perform all the + * Below are the functions which perform all the * terminal-specific screen manipulation. */ @@ -1476,49 +1476,49 @@ tmodes(incap, outcap, instr, outstr, def_instr, def_outstr, spp) #if MSDOS_COMPILER #if MSDOS_COMPILER==WIN32C - static void + static void _settextposition(int row, int col) { - COORD cpos; - CONSOLE_SCREEN_BUFFER_INFO csbi; + COORD cpos; + CONSOLE_SCREEN_BUFFER_INFO csbi; - GetConsoleScreenBufferInfo(con_out, &csbi); - cpos.X = csbi.srWindow.Left + (col - 1); - cpos.Y = csbi.srWindow.Top + (row - 1); - SetConsoleCursorPosition(con_out, cpos); + GetConsoleScreenBufferInfo(con_out, &csbi); + cpos.X = csbi.srWindow.Left + (col - 1); + cpos.Y = csbi.srWindow.Top + (row - 1); + SetConsoleCursorPosition(con_out, cpos); } #endif /* * Initialize the screen to the correct color at startup. */ - static void + static void initcolor(VOID_PARAM) { #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - intensevideo(); + intensevideo(); #endif - SETCOLORS(nm_fg_color, nm_bg_color); + SETCOLORS(nm_fg_color, nm_bg_color); #if 0 - /* - * This clears the screen at startup. This is different from - * the behavior of other versions of less. Disable it for now. - */ - char *blanks; - int row; - int col; - - /* - * Create a complete, blank screen using "normal" colors. - */ - SETCOLORS(nm_fg_color, nm_bg_color); - blanks = (char *) ecalloc(width+1, sizeof(char)); - for (col = 0; col < sc_width; col++) - blanks[col] = ' '; - blanks[sc_width] = '\0'; - for (row = 0; row < sc_height; row++) - _outtext(blanks); - free(blanks); + /* + * This clears the screen at startup. This is different from + * the behavior of other versions of less. Disable it for now. + */ + char *blanks; + int row; + int col; + + /* + * Create a complete, blank screen using "normal" colors. + */ + SETCOLORS(nm_fg_color, nm_bg_color); + blanks = (char *) ecalloc(width+1, sizeof(char)); + for (col = 0; col < sc_width; col++) + blanks[col] = ' '; + blanks[sc_width] = '\0'; + for (row = 0; row < sc_height; row++) + _outtext(blanks); + free(blanks); #endif } #endif @@ -1528,157 +1528,157 @@ initcolor(VOID_PARAM) /* * Enable virtual terminal processing, if available. */ - static void + static void win32_init_vt_term(VOID_PARAM) { - DWORD output_mode; + DWORD output_mode; - if (vt_enabled == 0 || (vt_enabled == 1 && con_out == con_out_ours)) - return; + if (vt_enabled == 0 || (vt_enabled == 1 && con_out == con_out_ours)) + return; - GetConsoleMode(con_out, &output_mode); - vt_enabled = SetConsoleMode(con_out, - output_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); - if (vt_enabled) - { - auto_wrap = 0; - ignaw = 1; - } + GetConsoleMode(con_out, &output_mode); + vt_enabled = SetConsoleMode(con_out, + output_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); + if (vt_enabled) + { + auto_wrap = 0; + ignaw = 1; + } } - static void + static void win32_deinit_vt_term(VOID_PARAM) { - if (vt_enabled == 1 && con_out == con_out_save) - SetConsoleMode(con_out, init_output_mode); + if (vt_enabled == 1 && con_out == con_out_save) + SetConsoleMode(con_out, init_output_mode); } /* * Termcap-like init with a private win32 console. */ - static void + static void win32_init_term(VOID_PARAM) { - CONSOLE_SCREEN_BUFFER_INFO scr; - COORD size; + CONSOLE_SCREEN_BUFFER_INFO scr; + COORD size; - if (con_out_save == INVALID_HANDLE_VALUE) - return; + if (con_out_save == INVALID_HANDLE_VALUE) + return; - GetConsoleScreenBufferInfo(con_out_save, &scr); + GetConsoleScreenBufferInfo(con_out_save, &scr); - if (con_out_ours == INVALID_HANDLE_VALUE) - { - /* - * Create our own screen buffer, so that we - * may restore the original when done. - */ - con_out_ours = CreateConsoleScreenBuffer( - GENERIC_WRITE | GENERIC_READ, - FILE_SHARE_WRITE | FILE_SHARE_READ, - (LPSECURITY_ATTRIBUTES) NULL, - CONSOLE_TEXTMODE_BUFFER, - (LPVOID) NULL); - } + if (con_out_ours == INVALID_HANDLE_VALUE) + { + /* + * Create our own screen buffer, so that we + * may restore the original when done. + */ + con_out_ours = CreateConsoleScreenBuffer( + GENERIC_WRITE | GENERIC_READ, + FILE_SHARE_WRITE | FILE_SHARE_READ, + (LPSECURITY_ATTRIBUTES) NULL, + CONSOLE_TEXTMODE_BUFFER, + (LPVOID) NULL); + } - size.X = scr.srWindow.Right - scr.srWindow.Left + 1; - size.Y = scr.srWindow.Bottom - scr.srWindow.Top + 1; - SetConsoleScreenBufferSize(con_out_ours, size); - SetConsoleActiveScreenBuffer(con_out_ours); - con_out = con_out_ours; + size.X = scr.srWindow.Right - scr.srWindow.Left + 1; + size.Y = scr.srWindow.Bottom - scr.srWindow.Top + 1; + SetConsoleScreenBufferSize(con_out_ours, size); + SetConsoleActiveScreenBuffer(con_out_ours); + con_out = con_out_ours; } /* * Restore the startup console. */ - static void + static void win32_deinit_term(VOID_PARAM) { - if (con_out_save == INVALID_HANDLE_VALUE) - return; - if (quitting) - (void) CloseHandle(con_out_ours); - SetConsoleActiveScreenBuffer(con_out_save); - con_out = con_out_save; + if (con_out_save == INVALID_HANDLE_VALUE) + return; + if (quitting) + (void) CloseHandle(con_out_ours); + SetConsoleActiveScreenBuffer(con_out_save); + con_out = con_out_save; } #endif #if !MSDOS_COMPILER - static void + static void do_tputs(str, affcnt, f_putc) - char *str; - int affcnt; - int (*f_putc)(int); + char *str; + int affcnt; + int (*f_putc)(int); { #if LESSTEST - if (ttyin_name != NULL) - putstr(str); - else + if (ttyin_name != NULL) + putstr(str); + else #endif /*LESSTEST*/ - tputs(str, affcnt, f_putc); + tputs(str, affcnt, f_putc); } /* * Like tputs but we handle $<...> delay strings here because * some implementations of tputs don't perform delays correctly. */ - static void + static void ltputs(str, affcnt, f_putc) - char *str; - int affcnt; - int (*f_putc)(int); + char *str; + int affcnt; + int (*f_putc)(int); { - while (str != NULL && *str != '\0') - { + while (str != NULL && *str != '\0') + { #if HAVE_STRSTR - char *obrac = strstr(str, "$<"); - if (obrac != NULL) - { - char str2[64]; - int slen = obrac - str; - if (slen < sizeof(str2)) - { - int delay; - /* Output first part of string (before "$<"). */ - memcpy(str2, str, slen); - str2[slen] = '\0'; - do_tputs(str2, affcnt, f_putc); - str += slen + 2; - /* Perform the delay. */ - delay = lstrtoi(str, &str); - if (*str == '*') - delay *= affcnt; - flush(); - sleep_ms(delay); - /* Skip past closing ">" at end of delay string. */ - str = strstr(str, ">"); - if (str != NULL) - str++; - continue; - } - } -#endif - /* Pass the rest of the string to tputs and we're done. */ - do_tputs(str, affcnt, f_putc); - break; - } + char *obrac = strstr(str, "$<"); + if (obrac != NULL) + { + char str2[64]; + int slen = obrac - str; + if (slen < sizeof(str2)) + { + int delay; + /* Output first part of string (before "$<"). */ + memcpy(str2, str, slen); + str2[slen] = '\0'; + do_tputs(str2, affcnt, f_putc); + str += slen + 2; + /* Perform the delay. */ + delay = lstrtoi(str, &str); + if (*str == '*') + delay *= affcnt; + flush(); + sleep_ms(delay); + /* Skip past closing ">" at end of delay string. */ + str = strstr(str, ">"); + if (str != NULL) + str++; + continue; + } + } +#endif + /* Pass the rest of the string to tputs and we're done. */ + do_tputs(str, affcnt, f_putc); + break; + } } #endif /* MSDOS_COMPILER */ /* - * Configure the termimal so mouse clicks and wheel moves + * Configure the termimal so mouse clicks and wheel moves * produce input to less. */ - public void + public void init_mouse(VOID_PARAM) { #if !MSDOS_COMPILER - ltputs(sc_s_mousecap, sc_height, putchr); + ltputs(sc_s_mousecap, sc_height, putchr); #else #if MSDOS_COMPILER==WIN32C - SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT - | ENABLE_EXTENDED_FLAGS /* disable quick edit */); + SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT + | ENABLE_EXTENDED_FLAGS /* disable quick edit */); #endif #endif @@ -1688,15 +1688,15 @@ init_mouse(VOID_PARAM) * Configure the terminal so mouse clicks and wheel moves * are handled by the system (so text can be selected, etc). */ - public void + public void deinit_mouse(VOID_PARAM) { #if !MSDOS_COMPILER - ltputs(sc_e_mousecap, sc_height, putchr); + ltputs(sc_e_mousecap, sc_height, putchr); #else #if MSDOS_COMPILER==WIN32C - SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_EXTENDED_FLAGS - | (console_mode & ENABLE_QUICK_EDIT_MODE)); + SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_EXTENDED_FLAGS + | (console_mode & ENABLE_QUICK_EDIT_MODE)); #endif #endif } @@ -1704,118 +1704,118 @@ deinit_mouse(VOID_PARAM) /* * Initialize terminal */ - public void + public void init(VOID_PARAM) { #if !MSDOS_COMPILER - if (!(quit_if_one_screen && one_screen)) - { - if (!no_init) - ltputs(sc_init, sc_height, putchr); - if (!no_keypad) - ltputs(sc_s_keypad, sc_height, putchr); - if (mousecap) - init_mouse(); - } - init_done = 1; - if (top_scroll) - { - int i; - - /* - * This is nice to terminals with no alternate screen, - * but with saved scrolled-off-the-top lines. This way, - * no previous line is lost, but we start with a whole - * screen to ourself. - */ - for (i = 1; i < sc_height; i++) - putchr('\n'); - } else - line_left(); + if (!(quit_if_one_screen && one_screen)) + { + if (!no_init) + ltputs(sc_init, sc_height, putchr); + if (!no_keypad) + ltputs(sc_s_keypad, sc_height, putchr); + if (mousecap) + init_mouse(); + } + init_done = 1; + if (top_scroll) + { + int i; + + /* + * This is nice to terminals with no alternate screen, + * but with saved scrolled-off-the-top lines. This way, + * no previous line is lost, but we start with a whole + * screen to ourself. + */ + for (i = 1; i < sc_height; i++) + putchr('\n'); + } else + line_left(); #else #if MSDOS_COMPILER==WIN32C - if (!(quit_if_one_screen && one_screen)) - { - if (!no_init) - win32_init_term(); - if (mousecap) - init_mouse(); + if (!(quit_if_one_screen && one_screen)) + { + if (!no_init) + win32_init_term(); + if (mousecap) + init_mouse(); - } - win32_init_vt_term(); + } + win32_init_vt_term(); #endif - init_done = 1; - initcolor(); - flush(); + init_done = 1; + initcolor(); + flush(); #endif } /* * Deinitialize terminal */ - public void + public void deinit(VOID_PARAM) { - if (!init_done) - return; + if (!init_done) + return; #if !MSDOS_COMPILER - if (!(quit_if_one_screen && one_screen)) - { - if (mousecap) - deinit_mouse(); - if (!no_keypad) - ltputs(sc_e_keypad, sc_height, putchr); - if (!no_init) - ltputs(sc_deinit, sc_height, putchr); - } + if (!(quit_if_one_screen && one_screen)) + { + if (mousecap) + deinit_mouse(); + if (!no_keypad) + ltputs(sc_e_keypad, sc_height, putchr); + if (!no_init) + ltputs(sc_deinit, sc_height, putchr); + } #else - /* Restore system colors. */ - SETCOLORS(sy_fg_color, sy_bg_color); + /* Restore system colors. */ + SETCOLORS(sy_fg_color, sy_bg_color); #if MSDOS_COMPILER==WIN32C - win32_deinit_vt_term(); - if (!(quit_if_one_screen && one_screen)) - { - if (mousecap) - deinit_mouse(); - if (!no_init) - win32_deinit_term(); - } + win32_deinit_vt_term(); + if (!(quit_if_one_screen && one_screen)) + { + if (mousecap) + deinit_mouse(); + if (!no_init) + win32_deinit_term(); + } #else - /* Need clreol to make SETCOLORS take effect. */ - clreol(); + /* Need clreol to make SETCOLORS take effect. */ + clreol(); #endif #endif - init_done = 0; + init_done = 0; } /* * Are we interactive (ie. writing to an initialized tty)? */ - public int + public int interactive(VOID_PARAM) { - return (is_tty && init_done); + return (is_tty && init_done); } - static void + static void assert_interactive(VOID_PARAM) { - if (interactive()) return; - /* abort(); */ + if (interactive()) return; + /* abort(); */ } /* * Home cursor (move to upper left corner of screen). */ - public void + public void home(VOID_PARAM) { - assert_interactive(); + assert_interactive(); #if !MSDOS_COMPILER - ltputs(sc_home, 1, putchr); + ltputs(sc_home, 1, putchr); #else - flush(); - _settextposition(1,1); + flush(); + _settextposition(1,1); #endif } @@ -1823,52 +1823,52 @@ home(VOID_PARAM) * Add a blank line (called with cursor at home). * Should scroll the display down. */ - public void + public void add_line(VOID_PARAM) { - assert_interactive(); + assert_interactive(); #if !MSDOS_COMPILER - ltputs(sc_addline, sc_height, putchr); + ltputs(sc_addline, sc_height, putchr); #else - flush(); + flush(); #if MSDOS_COMPILER==MSOFTC - _scrolltextwindow(_GSCROLLDOWN); - _settextposition(1,1); + _scrolltextwindow(_GSCROLLDOWN); + _settextposition(1,1); #else #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - movetext(1,1, sc_width,sc_height-1, 1,2); - gotoxy(1,1); - clreol(); + movetext(1,1, sc_width,sc_height-1, 1,2); + gotoxy(1,1); + clreol(); #else #if MSDOS_COMPILER==WIN32C { - CHAR_INFO fillchar; - SMALL_RECT rcSrc, rcClip; - COORD new_org; - CONSOLE_SCREEN_BUFFER_INFO csbi; - - GetConsoleScreenBufferInfo(con_out,&csbi); - - /* The clip rectangle is the entire visible screen. */ - rcClip.Left = csbi.srWindow.Left; - rcClip.Top = csbi.srWindow.Top; - rcClip.Right = csbi.srWindow.Right; - rcClip.Bottom = csbi.srWindow.Bottom; - - /* The source rectangle is the visible screen minus the last line. */ - rcSrc = rcClip; - rcSrc.Bottom--; - - /* Move the top left corner of the source window down one row. */ - new_org.X = rcSrc.Left; - new_org.Y = rcSrc.Top + 1; - - /* Fill the right character and attributes. */ - fillchar.Char.AsciiChar = ' '; - curr_attr = MAKEATTR(nm_fg_color, nm_bg_color); - fillchar.Attributes = curr_attr; - ScrollConsoleScreenBuffer(con_out, &rcSrc, &rcClip, new_org, &fillchar); - _settextposition(1,1); + CHAR_INFO fillchar; + SMALL_RECT rcSrc, rcClip; + COORD new_org; + CONSOLE_SCREEN_BUFFER_INFO csbi; + + GetConsoleScreenBufferInfo(con_out,&csbi); + + /* The clip rectangle is the entire visible screen. */ + rcClip.Left = csbi.srWindow.Left; + rcClip.Top = csbi.srWindow.Top; + rcClip.Right = csbi.srWindow.Right; + rcClip.Bottom = csbi.srWindow.Bottom; + + /* The source rectangle is the visible screen minus the last line. */ + rcSrc = rcClip; + rcSrc.Bottom--; + + /* Move the top left corner of the source window down one row. */ + new_org.X = rcSrc.Left; + new_org.Y = rcSrc.Top + 1; + + /* Fill the right character and attributes. */ + fillchar.Char.AsciiChar = ' '; + curr_attr = MAKEATTR(nm_fg_color, nm_bg_color); + fillchar.Attributes = curr_attr; + ScrollConsoleScreenBuffer(con_out, &rcSrc, &rcClip, new_org, &fillchar); + _settextposition(1,1); } #endif #endif @@ -1878,56 +1878,56 @@ add_line(VOID_PARAM) #if 0 /* - * Remove the n topmost lines and scroll everything below it in the - * window upward. This is needed to stop leaking the topmost line + * Remove the n topmost lines and scroll everything below it in the + * window upward. This is needed to stop leaking the topmost line * into the scrollback buffer when we go down-one-line (in WIN32). */ - public void + public void remove_top(n) - int n; + int n; { #if MSDOS_COMPILER==WIN32C - SMALL_RECT rcSrc, rcClip; - CHAR_INFO fillchar; - COORD new_org; - CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ + SMALL_RECT rcSrc, rcClip; + CHAR_INFO fillchar; + COORD new_org; + CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ - if (n >= sc_height - 1) - { - clear(); - home(); - return; - } + if (n >= sc_height - 1) + { + clear(); + home(); + return; + } - flush(); + flush(); - GetConsoleScreenBufferInfo(con_out, &csbi); + GetConsoleScreenBufferInfo(con_out, &csbi); - /* Get the extent of all-visible-rows-but-the-last. */ - rcSrc.Left = csbi.srWindow.Left; - rcSrc.Top = csbi.srWindow.Top + n; - rcSrc.Right = csbi.srWindow.Right; - rcSrc.Bottom = csbi.srWindow.Bottom; + /* Get the extent of all-visible-rows-but-the-last. */ + rcSrc.Left = csbi.srWindow.Left; + rcSrc.Top = csbi.srWindow.Top + n; + rcSrc.Right = csbi.srWindow.Right; + rcSrc.Bottom = csbi.srWindow.Bottom; - /* Get the clip rectangle. */ - rcClip.Left = rcSrc.Left; - rcClip.Top = csbi.srWindow.Top; - rcClip.Right = rcSrc.Right; - rcClip.Bottom = rcSrc.Bottom ; + /* Get the clip rectangle. */ + rcClip.Left = rcSrc.Left; + rcClip.Top = csbi.srWindow.Top; + rcClip.Right = rcSrc.Right; + rcClip.Bottom = rcSrc.Bottom ; - /* Move the source window up n rows. */ - new_org.X = rcSrc.Left; - new_org.Y = rcSrc.Top - n; + /* Move the source window up n rows. */ + new_org.X = rcSrc.Left; + new_org.Y = rcSrc.Top - n; - /* Fill the right character and attributes. */ - fillchar.Char.AsciiChar = ' '; - curr_attr = MAKEATTR(nm_fg_color, nm_bg_color); - fillchar.Attributes = curr_attr; + /* Fill the right character and attributes. */ + fillchar.Char.AsciiChar = ' '; + curr_attr = MAKEATTR(nm_fg_color, nm_bg_color); + fillchar.Attributes = curr_attr; - ScrollConsoleScreenBuffer(con_out, &rcSrc, &rcClip, new_org, &fillchar); + ScrollConsoleScreenBuffer(con_out, &rcSrc, &rcClip, new_org, &fillchar); - /* Position cursor on first blank line. */ - goto_line(sc_height - n - 1); + /* Position cursor on first blank line. */ + goto_line(sc_height - n - 1); #endif } #endif @@ -1936,193 +1936,193 @@ remove_top(n) /* * Clear the screen. */ - static void + static void win32_clear(VOID_PARAM) { - /* - * This will clear only the currently visible rows of the NT - * console buffer, which means none of the precious scrollback - * rows are touched making for faster scrolling. Note that, if - * the window has fewer columns than the console buffer (i.e. - * there is a horizontal scrollbar as well), the entire width - * of the visible rows will be cleared. - */ - COORD topleft; - DWORD nchars; - DWORD winsz; - CONSOLE_SCREEN_BUFFER_INFO csbi; - - /* get the number of cells in the current buffer */ - GetConsoleScreenBufferInfo(con_out, &csbi); - winsz = csbi.dwSize.X * (csbi.srWindow.Bottom - csbi.srWindow.Top + 1); - topleft.X = 0; - topleft.Y = csbi.srWindow.Top; - - curr_attr = MAKEATTR(nm_fg_color, nm_bg_color); - FillConsoleOutputCharacter(con_out, ' ', winsz, topleft, &nchars); - FillConsoleOutputAttribute(con_out, curr_attr, winsz, topleft, &nchars); + /* + * This will clear only the currently visible rows of the NT + * console buffer, which means none of the precious scrollback + * rows are touched making for faster scrolling. Note that, if + * the window has fewer columns than the console buffer (i.e. + * there is a horizontal scrollbar as well), the entire width + * of the visible rows will be cleared. + */ + COORD topleft; + DWORD nchars; + DWORD winsz; + CONSOLE_SCREEN_BUFFER_INFO csbi; + + /* get the number of cells in the current buffer */ + GetConsoleScreenBufferInfo(con_out, &csbi); + winsz = csbi.dwSize.X * (csbi.srWindow.Bottom - csbi.srWindow.Top + 1); + topleft.X = 0; + topleft.Y = csbi.srWindow.Top; + + curr_attr = MAKEATTR(nm_fg_color, nm_bg_color); + FillConsoleOutputCharacter(con_out, ' ', winsz, topleft, &nchars); + FillConsoleOutputAttribute(con_out, curr_attr, winsz, topleft, &nchars); } /* - * Remove the n topmost lines and scroll everything below it in the + * Remove the n topmost lines and scroll everything below it in the * window upward. */ - public void + public void win32_scroll_up(n) - int n; -{ - SMALL_RECT rcSrc, rcClip; - CHAR_INFO fillchar; - COORD topleft; - COORD new_org; - DWORD nchars; - DWORD size; - CONSOLE_SCREEN_BUFFER_INFO csbi; - - if (n <= 0) - return; - - if (n >= sc_height - 1) - { - win32_clear(); - _settextposition(1,1); - return; - } - - /* Get the extent of what will remain visible after scrolling. */ - GetConsoleScreenBufferInfo(con_out, &csbi); - rcSrc.Left = csbi.srWindow.Left; - rcSrc.Top = csbi.srWindow.Top + n; - rcSrc.Right = csbi.srWindow.Right; - rcSrc.Bottom = csbi.srWindow.Bottom; - - /* Get the clip rectangle. */ - rcClip.Left = rcSrc.Left; - rcClip.Top = csbi.srWindow.Top; - rcClip.Right = rcSrc.Right; - rcClip.Bottom = rcSrc.Bottom ; - - /* Move the source text to the top of the screen. */ - new_org.X = rcSrc.Left; - new_org.Y = rcClip.Top; - - /* Fill the right character and attributes. */ - fillchar.Char.AsciiChar = ' '; - fillchar.Attributes = MAKEATTR(nm_fg_color, nm_bg_color); - - /* Scroll the window. */ - SetConsoleTextAttribute(con_out, fillchar.Attributes); - ScrollConsoleScreenBuffer(con_out, &rcSrc, &rcClip, new_org, &fillchar); - - /* Clear remaining lines at bottom. */ - topleft.X = csbi.dwCursorPosition.X; - topleft.Y = rcSrc.Bottom - n; - size = (n * csbi.dwSize.X) + (rcSrc.Right - topleft.X); - FillConsoleOutputCharacter(con_out, ' ', size, topleft, - &nchars); - FillConsoleOutputAttribute(con_out, fillchar.Attributes, size, topleft, - &nchars); - SetConsoleTextAttribute(con_out, curr_attr); - - /* Move cursor n lines up from where it was. */ - csbi.dwCursorPosition.Y -= n; - SetConsoleCursorPosition(con_out, csbi.dwCursorPosition); + int n; +{ + SMALL_RECT rcSrc, rcClip; + CHAR_INFO fillchar; + COORD topleft; + COORD new_org; + DWORD nchars; + DWORD size; + CONSOLE_SCREEN_BUFFER_INFO csbi; + + if (n <= 0) + return; + + if (n >= sc_height - 1) + { + win32_clear(); + _settextposition(1,1); + return; + } + + /* Get the extent of what will remain visible after scrolling. */ + GetConsoleScreenBufferInfo(con_out, &csbi); + rcSrc.Left = csbi.srWindow.Left; + rcSrc.Top = csbi.srWindow.Top + n; + rcSrc.Right = csbi.srWindow.Right; + rcSrc.Bottom = csbi.srWindow.Bottom; + + /* Get the clip rectangle. */ + rcClip.Left = rcSrc.Left; + rcClip.Top = csbi.srWindow.Top; + rcClip.Right = rcSrc.Right; + rcClip.Bottom = rcSrc.Bottom ; + + /* Move the source text to the top of the screen. */ + new_org.X = rcSrc.Left; + new_org.Y = rcClip.Top; + + /* Fill the right character and attributes. */ + fillchar.Char.AsciiChar = ' '; + fillchar.Attributes = MAKEATTR(nm_fg_color, nm_bg_color); + + /* Scroll the window. */ + SetConsoleTextAttribute(con_out, fillchar.Attributes); + ScrollConsoleScreenBuffer(con_out, &rcSrc, &rcClip, new_org, &fillchar); + + /* Clear remaining lines at bottom. */ + topleft.X = csbi.dwCursorPosition.X; + topleft.Y = rcSrc.Bottom - n; + size = (n * csbi.dwSize.X) + (rcSrc.Right - topleft.X); + FillConsoleOutputCharacter(con_out, ' ', size, topleft, + &nchars); + FillConsoleOutputAttribute(con_out, fillchar.Attributes, size, topleft, + &nchars); + SetConsoleTextAttribute(con_out, curr_attr); + + /* Move cursor n lines up from where it was. */ + csbi.dwCursorPosition.Y -= n; + SetConsoleCursorPosition(con_out, csbi.dwCursorPosition); } #endif /* * Move cursor to lower left corner of screen. */ - public void + public void lower_left(VOID_PARAM) { - assert_interactive(); + assert_interactive(); #if !MSDOS_COMPILER - ltputs(sc_lower_left, 1, putchr); + ltputs(sc_lower_left, 1, putchr); #else - flush(); - _settextposition(sc_height, 1); + flush(); + _settextposition(sc_height, 1); #endif } /* * Move cursor to left position of current line. */ - public void + public void line_left(VOID_PARAM) { - assert_interactive(); + assert_interactive(); #if !MSDOS_COMPILER - ltputs(sc_return, 1, putchr); + ltputs(sc_return, 1, putchr); #else - { - int row; - flush(); + { + int row; + flush(); #if MSDOS_COMPILER==WIN32C - { - CONSOLE_SCREEN_BUFFER_INFO scr; - GetConsoleScreenBufferInfo(con_out, &scr); - row = scr.dwCursorPosition.Y - scr.srWindow.Top + 1; - } + { + CONSOLE_SCREEN_BUFFER_INFO scr; + GetConsoleScreenBufferInfo(con_out, &scr); + row = scr.dwCursorPosition.Y - scr.srWindow.Top + 1; + } #else #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - row = wherey(); + row = wherey(); #else - { - struct rccoord tpos = _gettextposition(); - row = tpos.row; - } + { + struct rccoord tpos = _gettextposition(); + row = tpos.row; + } #endif #endif - _settextposition(row, 1); - } + _settextposition(row, 1); + } #endif } /* - * Check if the console size has changed and reset internals + * Check if the console size has changed and reset internals * (in lieu of SIGWINCH for WIN32). */ - public void + public void check_winch(VOID_PARAM) { #if MSDOS_COMPILER==WIN32C - CONSOLE_SCREEN_BUFFER_INFO scr; - COORD size; - - if (con_out == INVALID_HANDLE_VALUE) - return; - - flush(); - GetConsoleScreenBufferInfo(con_out, &scr); - size.Y = scr.srWindow.Bottom - scr.srWindow.Top + 1; - size.X = scr.srWindow.Right - scr.srWindow.Left + 1; - if (size.Y != sc_height || size.X != sc_width) - { - sc_height = size.Y; - sc_width = size.X; - if (!no_init && con_out_ours == con_out) - SetConsoleScreenBufferSize(con_out, size); - pos_init(); - wscroll = (sc_height + 1) / 2; - screen_trashed = 1; - } + CONSOLE_SCREEN_BUFFER_INFO scr; + COORD size; + + if (con_out == INVALID_HANDLE_VALUE) + return; + + flush(); + GetConsoleScreenBufferInfo(con_out, &scr); + size.Y = scr.srWindow.Bottom - scr.srWindow.Top + 1; + size.X = scr.srWindow.Right - scr.srWindow.Left + 1; + if (size.Y != sc_height || size.X != sc_width) + { + sc_height = size.Y; + sc_width = size.X; + if (!no_init && con_out_ours == con_out) + SetConsoleScreenBufferSize(con_out, size); + pos_init(); + wscroll = (sc_height + 1) / 2; + screen_trashed = 1; + } #endif } /* * Goto a specific line on the screen. */ - public void + public void goto_line(sindex) - int sindex; + int sindex; { - assert_interactive(); + assert_interactive(); #if !MSDOS_COMPILER - ltputs(tgoto(sc_move, 0, sindex), 1, putchr); + ltputs(tgoto(sc_move, 0, sindex), 1, putchr); #else - flush(); - _settextposition(sindex+1, 1); + flush(); + _settextposition(sindex+1, 1); #endif } @@ -2133,107 +2133,107 @@ goto_line(sindex) * briefly and then switching back to the normal screen. * {{ Yuck! There must be a better way to get a visual bell. }} */ - static void + static void create_flash(VOID_PARAM) { #if MSDOS_COMPILER==MSOFTC - struct videoconfig w; - char *blanks; - int row, col; - - _getvideoconfig(&w); - videopages = w.numvideopages; - if (videopages < 2) - { - at_enter(AT_STANDOUT); - at_exit(); - } else - { - _setactivepage(1); - at_enter(AT_STANDOUT); - blanks = (char *) ecalloc(w.numtextcols, sizeof(char)); - for (col = 0; col < w.numtextcols; col++) - blanks[col] = ' '; - for (row = w.numtextrows; row > 0; row--) - _outmem(blanks, w.numtextcols); - _setactivepage(0); - _setvisualpage(0); - free(blanks); - at_exit(); - } + struct videoconfig w; + char *blanks; + int row, col; + + _getvideoconfig(&w); + videopages = w.numvideopages; + if (videopages < 2) + { + at_enter(AT_STANDOUT); + at_exit(); + } else + { + _setactivepage(1); + at_enter(AT_STANDOUT); + blanks = (char *) ecalloc(w.numtextcols, sizeof(char)); + for (col = 0; col < w.numtextcols; col++) + blanks[col] = ' '; + for (row = w.numtextrows; row > 0; row--) + _outmem(blanks, w.numtextcols); + _setactivepage(0); + _setvisualpage(0); + free(blanks); + at_exit(); + } #else #if MSDOS_COMPILER==BORLANDC - int n; + int n; - whitescreen = (unsigned short *) - malloc(sc_width * sc_height * sizeof(short)); - if (whitescreen == NULL) - return; - for (n = 0; n < sc_width * sc_height; n++) - whitescreen[n] = 0x7020; + whitescreen = (unsigned short *) + malloc(sc_width * sc_height * sizeof(short)); + if (whitescreen == NULL) + return; + for (n = 0; n < sc_width * sc_height; n++) + whitescreen[n] = 0x7020; #endif #endif - flash_created = 1; + flash_created = 1; } #endif /* MSDOS_COMPILER */ /* * Output the "visual bell", if there is one. */ - public void + public void vbell(VOID_PARAM) { #if !MSDOS_COMPILER - if (*sc_visual_bell == '\0') - return; - ltputs(sc_visual_bell, sc_height, putchr); + if (*sc_visual_bell == '\0') + return; + ltputs(sc_visual_bell, sc_height, putchr); #else #if MSDOS_COMPILER==DJGPPC - ScreenVisualBell(); + ScreenVisualBell(); #else #if MSDOS_COMPILER==MSOFTC - /* - * Create a flash screen on the second video page. - * Switch to that page, then switch back. - */ - if (!flash_created) - create_flash(); - if (videopages < 2) - return; - _setvisualpage(1); - delay(100); - _setvisualpage(0); + /* + * Create a flash screen on the second video page. + * Switch to that page, then switch back. + */ + if (!flash_created) + create_flash(); + if (videopages < 2) + return; + _setvisualpage(1); + delay(100); + _setvisualpage(0); #else #if MSDOS_COMPILER==BORLANDC - unsigned short *currscreen; - - /* - * Get a copy of the current screen. - * Display the flash screen. - * Then restore the old screen. - */ - if (!flash_created) - create_flash(); - if (whitescreen == NULL) - return; - currscreen = (unsigned short *) - malloc(sc_width * sc_height * sizeof(short)); - if (currscreen == NULL) return; - gettext(1, 1, sc_width, sc_height, currscreen); - puttext(1, 1, sc_width, sc_height, whitescreen); - delay(100); - puttext(1, 1, sc_width, sc_height, currscreen); - free(currscreen); + unsigned short *currscreen; + + /* + * Get a copy of the current screen. + * Display the flash screen. + * Then restore the old screen. + */ + if (!flash_created) + create_flash(); + if (whitescreen == NULL) + return; + currscreen = (unsigned short *) + malloc(sc_width * sc_height * sizeof(short)); + if (currscreen == NULL) return; + gettext(1, 1, sc_width, sc_height, currscreen); + puttext(1, 1, sc_width, sc_height, whitescreen); + delay(100); + puttext(1, 1, sc_width, sc_height, currscreen); + free(currscreen); #else #if MSDOS_COMPILER==WIN32C - /* paint screen with an inverse color */ - clear(); + /* paint screen with an inverse color */ + clear(); - /* leave it displayed for 100 msec. */ - Sleep(100); + /* leave it displayed for 100 msec. */ + Sleep(100); - /* restore with a redraw */ - repaint(); + /* restore with a redraw */ + repaint(); #endif #endif #endif @@ -2244,16 +2244,16 @@ vbell(VOID_PARAM) /* * Make a noise. */ - static void + static void beep(VOID_PARAM) { #if !MSDOS_COMPILER - putchr(CONTROL('G')); + putchr(CONTROL('G')); #else #if MSDOS_COMPILER==WIN32C - MessageBeep(0); + MessageBeep(0); #else - write(1, "\7", 1); + write(1, "\7", 1); #endif #endif } @@ -2261,30 +2261,30 @@ beep(VOID_PARAM) /* * Ring the terminal bell. */ - public void + public void bell(VOID_PARAM) { - if (quiet == VERY_QUIET) - vbell(); - else - beep(); + if (quiet == VERY_QUIET) + vbell(); + else + beep(); } /* * Clear the screen. */ - public void + public void clear(VOID_PARAM) { - assert_interactive(); + assert_interactive(); #if !MSDOS_COMPILER - ltputs(sc_clear, sc_height, putchr); + ltputs(sc_clear, sc_height, putchr); #else - flush(); + flush(); #if MSDOS_COMPILER==WIN32C - win32_clear(); + win32_clear(); #else - _clearscreen(_GCLEARSCREEN); + _clearscreen(_GCLEARSCREEN); #endif #endif } @@ -2293,56 +2293,56 @@ clear(VOID_PARAM) * Clear from the cursor to the end of the cursor's line. * {{ This must not move the cursor. }} */ - public void + public void clear_eol(VOID_PARAM) { - /* assert_interactive();*/ + /* assert_interactive();*/ #if !MSDOS_COMPILER - ltputs(sc_eol_clear, 1, putchr); + ltputs(sc_eol_clear, 1, putchr); #else #if MSDOS_COMPILER==MSOFTC - short top, left; - short bot, right; - struct rccoord tpos; - - flush(); - /* - * Save current state. - */ - tpos = _gettextposition(); - _gettextwindow(&top, &left, &bot, &right); - /* - * Set a temporary window to the current line, - * from the cursor's position to the right edge of the screen. - * Then clear that window. - */ - _settextwindow(tpos.row, tpos.col, tpos.row, sc_width); - _clearscreen(_GWINDOW); - /* - * Restore state. - */ - _settextwindow(top, left, bot, right); - _settextposition(tpos.row, tpos.col); + short top, left; + short bot, right; + struct rccoord tpos; + + flush(); + /* + * Save current state. + */ + tpos = _gettextposition(); + _gettextwindow(&top, &left, &bot, &right); + /* + * Set a temporary window to the current line, + * from the cursor's position to the right edge of the screen. + * Then clear that window. + */ + _settextwindow(tpos.row, tpos.col, tpos.row, sc_width); + _clearscreen(_GWINDOW); + /* + * Restore state. + */ + _settextwindow(top, left, bot, right); + _settextposition(tpos.row, tpos.col); #else #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - flush(); - clreol(); + flush(); + clreol(); #else #if MSDOS_COMPILER==WIN32C - DWORD nchars; - COORD cpos; - CONSOLE_SCREEN_BUFFER_INFO scr; + DWORD nchars; + COORD cpos; + CONSOLE_SCREEN_BUFFER_INFO scr; - flush(); - memset(&scr, 0, sizeof(scr)); - GetConsoleScreenBufferInfo(con_out, &scr); - cpos.X = scr.dwCursorPosition.X; - cpos.Y = scr.dwCursorPosition.Y; - curr_attr = MAKEATTR(nm_fg_color, nm_bg_color); - FillConsoleOutputAttribute(con_out, curr_attr, - scr.dwSize.X - cpos.X, cpos, &nchars); - FillConsoleOutputCharacter(con_out, ' ', - scr.dwSize.X - cpos.X, cpos, &nchars); + flush(); + memset(&scr, 0, sizeof(scr)); + GetConsoleScreenBufferInfo(con_out, &scr); + cpos.X = scr.dwCursorPosition.X; + cpos.Y = scr.dwCursorPosition.Y; + curr_attr = MAKEATTR(nm_fg_color, nm_bg_color); + FillConsoleOutputAttribute(con_out, curr_attr, + scr.dwSize.X - cpos.X, cpos, &nchars); + FillConsoleOutputCharacter(con_out, ' ', + scr.dwSize.X - cpos.X, cpos, &nchars); #endif #endif #endif @@ -2353,17 +2353,17 @@ clear_eol(VOID_PARAM) * Clear the current line. * Clear the screen if there's off-screen memory below the display. */ - static void + static void clear_eol_bot(VOID_PARAM) { - assert_interactive(); + assert_interactive(); #if MSDOS_COMPILER - clear_eol(); + clear_eol(); #else - if (below_mem) - ltputs(sc_eos_clear, 1, putchr); - else - ltputs(sc_eol_clear, 1, putchr); + if (below_mem) + ltputs(sc_eos_clear, 1, putchr); + else + ltputs(sc_eol_clear, 1, putchr); #endif } @@ -2371,29 +2371,29 @@ clear_eol_bot(VOID_PARAM) * Clear the bottom line of the display. * Leave the cursor at the beginning of the bottom line. */ - public void + public void clear_bot(VOID_PARAM) { - /* - * If we're in a non-normal attribute mode, temporarily exit - * the mode while we do the clear. Some terminals fill the - * cleared area with the current attribute. - */ - if (oldbot) - lower_left(); - else - line_left(); - - if (attrmode == AT_NORMAL) - clear_eol_bot(); - else - { - int saved_attrmode = attrmode; + /* + * If we're in a non-normal attribute mode, temporarily exit + * the mode while we do the clear. Some terminals fill the + * cleared area with the current attribute. + */ + if (oldbot) + lower_left(); + else + line_left(); + + if (attrmode == AT_NORMAL) + clear_eol_bot(); + else + { + int saved_attrmode = attrmode; - at_exit(); - clear_eol_bot(); - at_enter(saved_attrmode); - } + at_exit(); + clear_eol_bot(); + at_enter(saved_attrmode); + } } /* @@ -2405,52 +2405,52 @@ clear_bot(VOID_PARAM) /* * Parse a 4-bit color char. */ - static int + static int parse_color4(ch) - char ch; -{ - switch (ch) - { - case 'k': return 0; - case 'r': return CV_RED; - case 'g': return CV_GREEN; - case 'y': return CV_RED|CV_GREEN; - case 'b': return CV_BLUE; - case 'm': return CV_RED|CV_BLUE; - case 'c': return CV_GREEN|CV_BLUE; - case 'w': return CV_RED|CV_GREEN|CV_BLUE; - case 'K': return 0|CV_BRIGHT; - case 'R': return CV_RED|CV_BRIGHT; - case 'G': return CV_GREEN|CV_BRIGHT; - case 'Y': return CV_RED|CV_GREEN|CV_BRIGHT; - case 'B': return CV_BLUE|CV_BRIGHT; - case 'M': return CV_RED|CV_BLUE|CV_BRIGHT; - case 'C': return CV_GREEN|CV_BLUE|CV_BRIGHT; - case 'W': return CV_RED|CV_GREEN|CV_BLUE|CV_BRIGHT; - case '-': return CV_NOCHANGE; - default: return CV_ERROR; - } + char ch; +{ + switch (ch) + { + case 'k': return 0; + case 'r': return CV_RED; + case 'g': return CV_GREEN; + case 'y': return CV_RED|CV_GREEN; + case 'b': return CV_BLUE; + case 'm': return CV_RED|CV_BLUE; + case 'c': return CV_GREEN|CV_BLUE; + case 'w': return CV_RED|CV_GREEN|CV_BLUE; + case 'K': return 0|CV_BRIGHT; + case 'R': return CV_RED|CV_BRIGHT; + case 'G': return CV_GREEN|CV_BRIGHT; + case 'Y': return CV_RED|CV_GREEN|CV_BRIGHT; + case 'B': return CV_BLUE|CV_BRIGHT; + case 'M': return CV_RED|CV_BLUE|CV_BRIGHT; + case 'C': return CV_GREEN|CV_BLUE|CV_BRIGHT; + case 'W': return CV_RED|CV_GREEN|CV_BLUE|CV_BRIGHT; + case '-': return CV_NOCHANGE; + default: return CV_ERROR; + } } /* * Parse a color as a decimal integer. */ - static int + static int parse_color6(ps) - char **ps; -{ - if (**ps == '-') - { - (*ps)++; - return CV_NOCHANGE; - } else - { - char *ops = *ps; - int color = lstrtoi(ops, ps); - if (*ps == ops) - return CV_ERROR; - return color; - } + char **ps; +{ + if (**ps == '-') + { + (*ps)++; + return CV_NOCHANGE; + } else + { + char *ops = *ps; + int color = lstrtoi(ops, ps); + if (*ps == ops) + return CV_ERROR; + return color; + } } /* @@ -2459,528 +2459,527 @@ parse_color6(ps) * CV_4BIT: fg/bg values are OR of CV_{RGB} bits. * CV_6BIT: fg/bg values are integers entered by user. */ - public COLOR_TYPE + public COLOR_TYPE parse_color(str, p_fg, p_bg) - char *str; - int *p_fg; - int *p_bg; -{ - int fg; - int bg; - COLOR_TYPE type = CT_NULL; - - if (str == NULL || *str == '\0') - return CT_NULL; - if (*str == '+') - str++; /* ignore leading + */ - - fg = parse_color4(str[0]); - bg = parse_color4((strlen(str) < 2) ? '-' : str[1]); - if (fg != CV_ERROR && bg != CV_ERROR) - type = CT_4BIT; - else - { - fg = parse_color6(&str); - bg = (fg != CV_ERROR && *str++ == '.') ? parse_color6(&str) : CV_NOCHANGE; - if (fg != CV_ERROR && bg != CV_ERROR) - type = CT_6BIT; - } - if (p_fg != NULL) *p_fg = fg; - if (p_bg != NULL) *p_bg = bg; - return type; + char *str; + int *p_fg; + int *p_bg; +{ + int fg; + int bg; + COLOR_TYPE type = CT_NULL; + + if (str == NULL || *str == '\0') + return CT_NULL; + if (*str == '+') + str++; /* ignore leading + */ + + fg = parse_color4(str[0]); + bg = parse_color4((strlen(str) < 2) ? '-' : str[1]); + if (fg != CV_ERROR && bg != CV_ERROR) + type = CT_4BIT; + else + { + fg = parse_color6(&str); + bg = (fg != CV_ERROR && *str++ == '.') ? parse_color6(&str) : CV_NOCHANGE; + if (fg != CV_ERROR && bg != CV_ERROR) + type = CT_6BIT; + } + if (p_fg != NULL) *p_fg = fg; + if (p_bg != NULL) *p_bg = bg; + return type; } #if !MSDOS_COMPILER - static int + static int sgr_color(color) - int color; -{ - switch (color) - { - case 0: return 30; - case CV_RED: return 31; - case CV_GREEN: return 32; - case CV_RED|CV_GREEN: return 33; - case CV_BLUE: return 34; - case CV_RED|CV_BLUE: return 35; - case CV_GREEN|CV_BLUE: return 36; - case CV_RED|CV_GREEN|CV_BLUE: return 37; - - case CV_BRIGHT: return 90; - case CV_RED|CV_BRIGHT: return 91; - case CV_GREEN|CV_BRIGHT: return 92; - case CV_RED|CV_GREEN|CV_BRIGHT: return 93; - case CV_BLUE|CV_BRIGHT: return 94; - case CV_RED|CV_BLUE|CV_BRIGHT: return 95; - case CV_GREEN|CV_BLUE|CV_BRIGHT: return 96; - case CV_RED|CV_GREEN|CV_BLUE|CV_BRIGHT: return 97; - - default: return color; - } -} - - static void + int color; +{ + switch (color) + { + case 0: return 30; + case CV_RED: return 31; + case CV_GREEN: return 32; + case CV_RED|CV_GREEN: return 33; + case CV_BLUE: return 34; + case CV_RED|CV_BLUE: return 35; + case CV_GREEN|CV_BLUE: return 36; + case CV_RED|CV_GREEN|CV_BLUE: return 37; + + case CV_BRIGHT: return 90; + case CV_RED|CV_BRIGHT: return 91; + case CV_GREEN|CV_BRIGHT: return 92; + case CV_RED|CV_GREEN|CV_BRIGHT: return 93; + case CV_BLUE|CV_BRIGHT: return 94; + case CV_RED|CV_BLUE|CV_BRIGHT: return 95; + case CV_GREEN|CV_BLUE|CV_BRIGHT: return 96; + case CV_RED|CV_GREEN|CV_BLUE|CV_BRIGHT: return 97; + + default: return color; + } +} + + static void tput_fmt(fmt, color, f_putc) - char *fmt; - int color; - int (*f_putc)(int); + char *fmt; + int color; + int (*f_putc)(int); { - char buf[16]; - if (color == attrcolor) - return; - SNPRINTF1(buf, sizeof(buf), fmt, color); - ltputs(buf, 1, f_putc); - attrcolor = color; + char buf[16]; + if (color == attrcolor) + return; + SNPRINTF1(buf, sizeof(buf), fmt, color); + ltputs(buf, 1, f_putc); + attrcolor = color; } - static void + static void tput_color(str, f_putc) - char *str; - int (*f_putc)(int); -{ - int fg; - int bg; - - if (str != NULL && strcmp(str, "*") == 0) - { - /* Special case: reset to normal */ - tput_fmt(ESCS"[m", -1, f_putc); - return; - } - switch (parse_color(str, &fg, &bg)) - { - case CT_4BIT: - if (fg >= 0) - tput_fmt(ESCS"[%dm", sgr_color(fg), f_putc); - if (bg >= 0) - tput_fmt(ESCS"[%dm", sgr_color(bg)+10, f_putc); - break; - case CT_6BIT: - if (fg >= 0) - tput_fmt(ESCS"[38;5;%dm", fg, f_putc); - if (bg >= 0) - tput_fmt(ESCS"[48;5;%dm", bg, f_putc); - break; - default: - break; - } -} - - static void + char *str; + int (*f_putc)(int); +{ + int fg; + int bg; + + if (str != NULL && strcmp(str, "*") == 0) + { + /* Special case: reset to normal */ + tput_fmt(ESCS"[m", -1, f_putc); + return; + } + switch (parse_color(str, &fg, &bg)) + { + case CT_4BIT: + if (fg >= 0) + tput_fmt(ESCS"[%dm", sgr_color(fg), f_putc); + if (bg >= 0) + tput_fmt(ESCS"[%dm", sgr_color(bg)+10, f_putc); + break; + case CT_6BIT: + if (fg >= 0) + tput_fmt(ESCS"[38;5;%dm", fg, f_putc); + if (bg >= 0) + tput_fmt(ESCS"[48;5;%dm", bg, f_putc); + break; + default: + break; + } +} + + static void tput_inmode(mode_str, attr, attr_bit, f_putc) - char *mode_str; - int attr; - int attr_bit; - int (*f_putc)(int); -{ - char *color_str; - if ((attr & attr_bit) == 0) - return; - color_str = get_color_map(attr_bit); - if (color_str == NULL || *color_str == '\0' || *color_str == '+') - { - ltputs(mode_str, 1, f_putc); - if (color_str == NULL || *color_str++ != '+') - return; - } - /* Color overrides mode string */ - tput_color(color_str, f_putc); -} - - static void + char *mode_str; + int attr; + int attr_bit; + int (*f_putc)(int); +{ + char *color_str; + if ((attr & attr_bit) == 0) + return; + color_str = get_color_map(attr_bit); + if (color_str == NULL || *color_str == '\0' || *color_str == '+') + { + ltputs(mode_str, 1, f_putc); + if (color_str == NULL || *color_str++ != '+') + return; + } + /* Color overrides mode string */ + tput_color(color_str, f_putc); +} + + static void tput_outmode(mode_str, attr_bit, f_putc) - char *mode_str; - int attr_bit; - int (*f_putc)(int); + char *mode_str; + int attr_bit; + int (*f_putc)(int); { - if ((attrmode & attr_bit) == 0) - return; - ltputs(mode_str, 1, f_putc); + if ((attrmode & attr_bit) == 0) + return; + ltputs(mode_str, 1, f_putc); } #else /* MSDOS_COMPILER */ #if MSDOS_COMPILER==WIN32C - static int + static int WIN32put_fmt(fmt, color) - char *fmt; - int color; + char *fmt; + int color; { - char buf[16]; - int len = SNPRINTF1(buf, sizeof(buf), fmt, color); - WIN32textout(buf, len); - return TRUE; + char buf[16]; + int len = SNPRINTF1(buf, sizeof(buf), fmt, color); + WIN32textout(buf, len); + return TRUE; } #endif - static int + static int win_set_color(attr) - int attr; -{ - int fg; - int bg; - int out = FALSE; - char *str = get_color_map(attr); - if (str == NULL || str[0] == '\0') - return FALSE; - switch (parse_color(str, &fg, &bg)) - { - case CT_4BIT: - if (fg >= 0 && bg >= 0) - { - SETCOLORS(fg, bg); - out = TRUE; - } else if (fg >= 0) - { - SET_FG_COLOR(fg); - out = TRUE; - } else if (bg >= 0) - { - SET_BG_COLOR(bg); - out = TRUE; - } - break; + int attr; +{ + int fg; + int bg; + int out = FALSE; + char *str = get_color_map(attr); + if (str == NULL || str[0] == '\0') + return FALSE; + switch (parse_color(str, &fg, &bg)) + { + case CT_4BIT: + if (fg >= 0 && bg >= 0) + { + SETCOLORS(fg, bg); + out = TRUE; + } else if (fg >= 0) + { + SET_FG_COLOR(fg); + out = TRUE; + } else if (bg >= 0) + { + SET_BG_COLOR(bg); + out = TRUE; + } + break; #if MSDOS_COMPILER==WIN32C - case CT_6BIT: - if (vt_enabled) - { - if (fg > 0) - out = WIN32put_fmt(ESCS"[38;5;%dm", fg); - if (bg > 0) - out = WIN32put_fmt(ESCS"[48;5;%dm", bg); - } - break; -#endif - default: - break; - } - return out; + case CT_6BIT: + if (vt_enabled) + { + if (fg > 0) + out = WIN32put_fmt(ESCS"[38;5;%dm", fg); + if (bg > 0) + out = WIN32put_fmt(ESCS"[48;5;%dm", bg); + } + break; +#endif + default: + break; + } + return out; } #endif /* MSDOS_COMPILER */ - public void + public void at_enter(attr) - int attr; + int attr; { - attr = apply_at_specials(attr); + attr = apply_at_specials(attr); #if !MSDOS_COMPILER - /* The one with the most priority is last. */ - tput_inmode(sc_u_in, attr, AT_UNDERLINE, putchr); - tput_inmode(sc_b_in, attr, AT_BOLD, putchr); - tput_inmode(sc_bl_in, attr, AT_BLINK, putchr); - /* Don't use standout and color at the same time. */ - if (use_color && (attr & AT_COLOR)) - tput_color(get_color_map(attr), putchr); - else - tput_inmode(sc_s_in, attr, AT_STANDOUT, putchr); + /* The one with the most priority is last. */ + tput_inmode(sc_u_in, attr, AT_UNDERLINE, putchr); + tput_inmode(sc_b_in, attr, AT_BOLD, putchr); + tput_inmode(sc_bl_in, attr, AT_BLINK, putchr); + /* Don't use standout and color at the same time. */ + if (use_color && (attr & AT_COLOR)) + tput_color(get_color_map(attr), putchr); + else + tput_inmode(sc_s_in, attr, AT_STANDOUT, putchr); #else - flush(); - /* The one with the most priority is first. */ - if ((attr & AT_COLOR) && use_color) - { - win_set_color(attr); - } else if (attr & AT_STANDOUT) - { - SETCOLORS(so_fg_color, so_bg_color); - } else if (attr & AT_BLINK) - { - SETCOLORS(bl_fg_color, bl_bg_color); - } else if (attr & AT_BOLD) - { - SETCOLORS(bo_fg_color, bo_bg_color); - } else if (attr & AT_UNDERLINE) - { - SETCOLORS(ul_fg_color, ul_bg_color); - } -#endif - attrmode = attr; -} - - public void + flush(); + /* The one with the most priority is first. */ + if ((attr & AT_COLOR) && use_color) + { + win_set_color(attr); + } else if (attr & AT_STANDOUT) + { + SETCOLORS(so_fg_color, so_bg_color); + } else if (attr & AT_BLINK) + { + SETCOLORS(bl_fg_color, bl_bg_color); + } else if (attr & AT_BOLD) + { + SETCOLORS(bo_fg_color, bo_bg_color); + } else if (attr & AT_UNDERLINE) + { + SETCOLORS(ul_fg_color, ul_bg_color); + } +#endif + attrmode = attr; +} + + public void at_exit(VOID_PARAM) { #if !MSDOS_COMPILER - /* Undo things in the reverse order we did them. */ - tput_color("*", putchr); - tput_outmode(sc_s_out, AT_STANDOUT, putchr); - tput_outmode(sc_bl_out, AT_BLINK, putchr); - tput_outmode(sc_b_out, AT_BOLD, putchr); - tput_outmode(sc_u_out, AT_UNDERLINE, putchr); + /* Undo things in the reverse order we did them. */ + tput_color("*", putchr); + tput_outmode(sc_s_out, AT_STANDOUT, putchr); + tput_outmode(sc_bl_out, AT_BLINK, putchr); + tput_outmode(sc_b_out, AT_BOLD, putchr); + tput_outmode(sc_u_out, AT_UNDERLINE, putchr); #else - flush(); - SETCOLORS(nm_fg_color, nm_bg_color); + flush(); + SETCOLORS(nm_fg_color, nm_bg_color); #endif - attrmode = AT_NORMAL; + attrmode = AT_NORMAL; } - public void + public void at_switch(attr) - int attr; + int attr; { - int new_attrmode = apply_at_specials(attr); - int ignore_modes = AT_ANSI; + int new_attrmode = apply_at_specials(attr); + int ignore_modes = AT_ANSI; - if ((new_attrmode & ~ignore_modes) != (attrmode & ~ignore_modes)) - { - at_exit(); - at_enter(attr); - } + if ((new_attrmode & ~ignore_modes) != (attrmode & ~ignore_modes)) + { + at_exit(); + at_enter(attr); + } } - public int + public int is_at_equiv(attr1, attr2) - int attr1; - int attr2; + int attr1; + int attr2; { - attr1 = apply_at_specials(attr1); - attr2 = apply_at_specials(attr2); + attr1 = apply_at_specials(attr1); + attr2 = apply_at_specials(attr2); - return (attr1 == attr2); + return (attr1 == attr2); } - public int + public int apply_at_specials(attr) - int attr; + int attr; { - if (attr & AT_BINARY) - attr |= binattr; - if (attr & AT_HILITE) - attr |= AT_STANDOUT; - attr &= ~(AT_BINARY|AT_HILITE); + if (attr & AT_BINARY) + attr |= binattr; + if (attr & AT_HILITE) + attr |= AT_STANDOUT; + attr &= ~(AT_BINARY|AT_HILITE); - return attr; + return attr; } /* * Output a plain backspace, without erasing the previous char. */ - public void + public void putbs(VOID_PARAM) { - if (termcap_debug) - putstr(""); - else - { + if (termcap_debug) + putstr(""); + else + { #if !MSDOS_COMPILER - ltputs(sc_backspace, 1, putchr); + ltputs(sc_backspace, 1, putchr); #else - int row, col; + int row, col; - flush(); - { + flush(); + { #if MSDOS_COMPILER==MSOFTC - struct rccoord tpos; - tpos = _gettextposition(); - row = tpos.row; - col = tpos.col; + struct rccoord tpos; + tpos = _gettextposition(); + row = tpos.row; + col = tpos.col; #else #if MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC - row = wherey(); - col = wherex(); + row = wherey(); + col = wherex(); #else #if MSDOS_COMPILER==WIN32C - CONSOLE_SCREEN_BUFFER_INFO scr; - GetConsoleScreenBufferInfo(con_out, &scr); - row = scr.dwCursorPosition.Y - scr.srWindow.Top + 1; - col = scr.dwCursorPosition.X - scr.srWindow.Left + 1; + CONSOLE_SCREEN_BUFFER_INFO scr; + GetConsoleScreenBufferInfo(con_out, &scr); + row = scr.dwCursorPosition.Y - scr.srWindow.Top + 1; + col = scr.dwCursorPosition.X - scr.srWindow.Left + 1; #endif #endif #endif - } - if (col <= 1) - return; - _settextposition(row, col-1); + } + if (col <= 1) + return; + _settextposition(row, col-1); #endif /* MSDOS_COMPILER */ - } + } } #if MSDOS_COMPILER==WIN32C /* * Determine whether an input character is waiting to be read. */ - public int + public int win32_kbhit(VOID_PARAM) { - INPUT_RECORD ip; - DWORD read; - - if (keyCount > 0) - return (TRUE); - - currentKey.ascii = 0; - currentKey.scan = 0; - - if (x11mouseCount > 0) - { - currentKey.ascii = x11mousebuf[x11mousePos++]; - --x11mouseCount; - keyCount = 1; - return (TRUE); - } - - /* - * Wait for a real key-down event, but - * ignore SHIFT and CONTROL key events. - */ - do - { - PeekConsoleInput(tty, &ip, 1, &read); - if (read == 0) - return (FALSE); - ReadConsoleInput(tty, &ip, 1, &read); - /* generate an X11 mouse sequence from the mouse event */ - if (mousecap && ip.EventType == MOUSE_EVENT && - ip.Event.MouseEvent.dwEventFlags != MOUSE_MOVED) - { - x11mousebuf[3] = X11MOUSE_OFFSET + ip.Event.MouseEvent.dwMousePosition.X + 1; - x11mousebuf[4] = X11MOUSE_OFFSET + ip.Event.MouseEvent.dwMousePosition.Y + 1; - switch (ip.Event.MouseEvent.dwEventFlags) - { - case 0: /* press or release */ - if (ip.Event.MouseEvent.dwButtonState == 0) - x11mousebuf[2] = X11MOUSE_OFFSET + X11MOUSE_BUTTON_REL; - else if (ip.Event.MouseEvent.dwButtonState & (FROM_LEFT_3RD_BUTTON_PRESSED | FROM_LEFT_4TH_BUTTON_PRESSED)) - continue; - else - x11mousebuf[2] = X11MOUSE_OFFSET + X11MOUSE_BUTTON1 + ((int)ip.Event.MouseEvent.dwButtonState << 1); - break; - case MOUSE_WHEELED: - x11mousebuf[2] = X11MOUSE_OFFSET + (((int)ip.Event.MouseEvent.dwButtonState < 0) ? X11MOUSE_WHEEL_DOWN : X11MOUSE_WHEEL_UP); - break; - default: - continue; - } - x11mousePos = 0; - x11mouseCount = 5; - currentKey.ascii = ESC; - keyCount = 1; - return (TRUE); - } - } while (ip.EventType != KEY_EVENT || - ip.Event.KeyEvent.bKeyDown != TRUE || - ip.Event.KeyEvent.wVirtualScanCode == 0 || - ip.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT || - ip.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL || - ip.Event.KeyEvent.wVirtualKeyCode == VK_MENU); - - currentKey.ascii = ip.Event.KeyEvent.uChar.AsciiChar; - currentKey.scan = ip.Event.KeyEvent.wVirtualScanCode; - keyCount = ip.Event.KeyEvent.wRepeatCount; - - if (ip.Event.KeyEvent.dwControlKeyState & - (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) - { - switch (currentKey.scan) - { - case PCK_ALT_E: /* letter 'E' */ - currentKey.ascii = 0; - break; - } - } else if (ip.Event.KeyEvent.dwControlKeyState & - (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) - { - switch (currentKey.scan) - { - case PCK_RIGHT: /* right arrow */ - currentKey.scan = PCK_CTL_RIGHT; - break; - case PCK_LEFT: /* left arrow */ - currentKey.scan = PCK_CTL_LEFT; - break; - case PCK_DELETE: /* delete */ - currentKey.scan = PCK_CTL_DELETE; - break; - } - } else if (ip.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) - { - switch (currentKey.scan) - { - case PCK_SHIFT_TAB: /* tab */ - currentKey.ascii = 0; - break; - } - } - - return (TRUE); + INPUT_RECORD ip; + DWORD read; + + if (keyCount > 0) + return (TRUE); + + currentKey.ascii = 0; + currentKey.scan = 0; + + if (x11mouseCount > 0) + { + currentKey.ascii = x11mousebuf[x11mousePos++]; + --x11mouseCount; + keyCount = 1; + return (TRUE); + } + + /* + * Wait for a real key-down event, but + * ignore SHIFT and CONTROL key events. + */ + do + { + PeekConsoleInput(tty, &ip, 1, &read); + if (read == 0) + return (FALSE); + ReadConsoleInput(tty, &ip, 1, &read); + /* generate an X11 mouse sequence from the mouse event */ + if (mousecap && ip.EventType == MOUSE_EVENT && + ip.Event.MouseEvent.dwEventFlags != MOUSE_MOVED) + { + x11mousebuf[3] = X11MOUSE_OFFSET + ip.Event.MouseEvent.dwMousePosition.X + 1; + x11mousebuf[4] = X11MOUSE_OFFSET + ip.Event.MouseEvent.dwMousePosition.Y + 1; + switch (ip.Event.MouseEvent.dwEventFlags) + { + case 0: /* press or release */ + if (ip.Event.MouseEvent.dwButtonState == 0) + x11mousebuf[2] = X11MOUSE_OFFSET + X11MOUSE_BUTTON_REL; + else if (ip.Event.MouseEvent.dwButtonState & (FROM_LEFT_3RD_BUTTON_PRESSED | FROM_LEFT_4TH_BUTTON_PRESSED)) + continue; + else + x11mousebuf[2] = X11MOUSE_OFFSET + X11MOUSE_BUTTON1 + ((int)ip.Event.MouseEvent.dwButtonState << 1); + break; + case MOUSE_WHEELED: + x11mousebuf[2] = X11MOUSE_OFFSET + (((int)ip.Event.MouseEvent.dwButtonState < 0) ? X11MOUSE_WHEEL_DOWN : X11MOUSE_WHEEL_UP); + break; + default: + continue; + } + x11mousePos = 0; + x11mouseCount = 5; + currentKey.ascii = ESC; + keyCount = 1; + return (TRUE); + } + } while (ip.EventType != KEY_EVENT || + ip.Event.KeyEvent.bKeyDown != TRUE || + ip.Event.KeyEvent.wVirtualScanCode == 0 || + ip.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT || + ip.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL || + ip.Event.KeyEvent.wVirtualKeyCode == VK_MENU); + + currentKey.ascii = ip.Event.KeyEvent.uChar.AsciiChar; + currentKey.scan = ip.Event.KeyEvent.wVirtualScanCode; + keyCount = ip.Event.KeyEvent.wRepeatCount; + + if (ip.Event.KeyEvent.dwControlKeyState & + (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) + { + switch (currentKey.scan) + { + case PCK_ALT_E: /* letter 'E' */ + currentKey.ascii = 0; + break; + } + } else if (ip.Event.KeyEvent.dwControlKeyState & + (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) + { + switch (currentKey.scan) + { + case PCK_RIGHT: /* right arrow */ + currentKey.scan = PCK_CTL_RIGHT; + break; + case PCK_LEFT: /* left arrow */ + currentKey.scan = PCK_CTL_LEFT; + break; + case PCK_DELETE: /* delete */ + currentKey.scan = PCK_CTL_DELETE; + break; + } + } else if (ip.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) + { + switch (currentKey.scan) + { + case PCK_SHIFT_TAB: /* tab */ + currentKey.ascii = 0; + break; + } + } + + return (TRUE); } /* * Read a character from the keyboard. */ - public char + public char WIN32getch(VOID_PARAM) { - int ascii; - - if (pending_scancode) - { - pending_scancode = 0; - return ((char)(currentKey.scan & 0x00FF)); - } - - do { - while (win32_kbhit() == FALSE) - { - Sleep(20); - if (ABORT_SIGS()) - return ('\003'); - continue; - } - keyCount --; - ascii = currentKey.ascii; - /* - * On PC's, the extended keys return a 2 byte sequence beginning - * with '00', so if the ascii code is 00, the next byte will be - * the lsb of the scan code. - */ - pending_scancode = (ascii == 0x00); - } while (pending_scancode && - (currentKey.scan == PCK_CAPS_LOCK || currentKey.scan == PCK_NUM_LOCK)); - - return ((char)ascii); + int ascii; + + if (pending_scancode) + { + pending_scancode = 0; + return ((char)(currentKey.scan & 0x00FF)); + } + + do { + while (win32_kbhit() == FALSE) + { + Sleep(20); + if (ABORT_SIGS()) + return ('\003'); + continue; + } + keyCount --; + ascii = currentKey.ascii; + /* + * On PC's, the extended keys return a 2 byte sequence beginning + * with '00', so if the ascii code is 00, the next byte will be + * the lsb of the scan code. + */ + pending_scancode = (ascii == 0x00); + } while (pending_scancode && + (currentKey.scan == PCK_CAPS_LOCK || currentKey.scan == PCK_NUM_LOCK)); + + return ((char)ascii); } #endif #if MSDOS_COMPILER /* */ - public void + public void WIN32setcolors(fg, bg) - int fg; - int bg; + int fg; + int bg; { - SETCOLORS(fg, bg); + SETCOLORS(fg, bg); } /* */ - public void + public void WIN32textout(text, len) - char *text; - int len; + char *text; + int len; { #if MSDOS_COMPILER==WIN32C - DWORD written; - if (utf_mode == 2) - { - /* - * We've got UTF-8 text in a non-UTF-8 console. Convert it to - * wide and use WriteConsoleW. - */ - WCHAR wtext[1024]; - len = MultiByteToWideChar(CP_UTF8, 0, text, len, wtext, - sizeof(wtext)/sizeof(*wtext)); - WriteConsoleW(con_out, wtext, len, &written, NULL); - } else - WriteConsole(con_out, text, len, &written, NULL); + DWORD written; + if (utf_mode == 2) + { + /* + * We've got UTF-8 text in a non-UTF-8 console. Convert it to + * wide and use WriteConsoleW. + */ + WCHAR wtext[1024]; + len = MultiByteToWideChar(CP_UTF8, 0, text, len, wtext, + sizeof(wtext)/sizeof(*wtext)); + WriteConsoleW(con_out, wtext, len, &written, NULL); + } else + WriteConsole(con_out, text, len, &written, NULL); #else - char c = text[len]; - text[len] = '\0'; - cputs(text); - text[len] = c; + char c = text[len]; + text[len] = '\0'; + cputs(text); + text[len] = c; #endif } #endif - diff --git a/scrsize.c b/scrsize.c index ee07cb8..6361e86 100644 --- a/scrsize.c +++ b/scrsize.c @@ -13,7 +13,7 @@ */ /* - * When I wrote this routine, I consulted some part of the source code + * When I wrote this routine, I consulted some part of the source code * of the xwininfo utility by X Consortium. * * Copyright (c) 1987, X Consortium @@ -46,58 +46,58 @@ #include static int get_winsize(dpy, window, p_width, p_height) - Display *dpy; - Window window; - int *p_width; - int *p_height; + Display *dpy; + Window window; + int *p_width; + int *p_height; { - XWindowAttributes win_attributes; - XSizeHints hints; - long longjunk; + XWindowAttributes win_attributes; + XSizeHints hints; + long longjunk; - if (!XGetWindowAttributes(dpy, window, &win_attributes)) - return 1; - if (!XGetWMNormalHints(dpy, window, &hints, &longjunk)) - return 1; - if (!(hints.flags & PResizeInc)) - return 1; - if (hints.width_inc == 0 || hints.height_inc == 0) - return 1; - if (!(hints.flags & (PBaseSize|PMinSize))) - return 1; - if (hints.flags & PBaseSize) - { - win_attributes.width -= hints.base_width; - win_attributes.height -= hints.base_height; - } else - { - win_attributes.width -= hints.min_width; - win_attributes.height -= hints.min_height; - } - *p_width = win_attributes.width / hints.width_inc; - *p_height = win_attributes.height / hints.height_inc; - return 0; + if (!XGetWindowAttributes(dpy, window, &win_attributes)) + return 1; + if (!XGetWMNormalHints(dpy, window, &hints, &longjunk)) + return 1; + if (!(hints.flags & PResizeInc)) + return 1; + if (hints.width_inc == 0 || hints.height_inc == 0) + return 1; + if (!(hints.flags & (PBaseSize|PMinSize))) + return 1; + if (hints.flags & PBaseSize) + { + win_attributes.width -= hints.base_width; + win_attributes.height -= hints.base_height; + } else + { + win_attributes.width -= hints.min_width; + win_attributes.height -= hints.min_height; + } + *p_width = win_attributes.width / hints.width_inc; + *p_height = win_attributes.height / hints.height_inc; + return 0; } int main(argc, argv) - int argc; - char *argv[]; + int argc; + char *argv[]; { - char *cp; - Display *dpy; - int size[2]; + char *cp; + Display *dpy; + int size[2]; - _scrsize(size); - cp = getenv("WINDOWID"); - if (cp != NULL) - { - dpy = XOpenDisplay(NULL); - if (dpy != NULL) - { - get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]); - XCloseDisplay(dpy); - } - } - printf("%i %i\n", size[0], size[1]); - return (0); + _scrsize(size); + cp = getenv("WINDOWID"); + if (cp != NULL) + { + dpy = XOpenDisplay(NULL); + if (dpy != NULL) + { + get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]); + XCloseDisplay(dpy); + } + } + printf("%i %i\n", size[0], size[1]); + return (0); } diff --git a/search.c b/search.c index f619fbe..5ce4fdb 100644 --- a/search.c +++ b/search.c @@ -65,32 +65,32 @@ extern POSITION xxpos; */ struct hilite { - POSITION hl_startpos; - POSITION hl_endpos; + POSITION hl_startpos; + POSITION hl_endpos; }; struct hilite_node { - struct hilite_node *parent; - struct hilite_node *left; - struct hilite_node *right; - struct hilite_node *prev; - struct hilite_node *next; - int red; - struct hilite r; + struct hilite_node *parent; + struct hilite_node *left; + struct hilite_node *right; + struct hilite_node *prev; + struct hilite_node *next; + int red; + struct hilite r; }; struct hilite_storage { - int capacity; - int used; - struct hilite_storage *next; - struct hilite_node *nodes; + int capacity; + int used; + struct hilite_storage *next; + struct hilite_node *nodes; }; struct hilite_tree { - struct hilite_storage *first; - struct hilite_storage *current; - struct hilite_node *root; - struct hilite_node *lookaside; + struct hilite_storage *first; + struct hilite_storage *current; + struct hilite_node *root; + struct hilite_node *lookaside; }; #define HILITE_INITIALIZER() { NULL, NULL, NULL, NULL } #define HILITE_LOOKASIDE_STEPS 2 @@ -106,10 +106,10 @@ static struct pattern_info *filter_infos = NULL; * search pattern and filter pattern. */ struct pattern_info { - PATTERN_TYPE compiled; - char* text; - int search_type; - struct pattern_info *next; + PATTERN_TYPE compiled; + char* text; + int search_type; + struct pattern_info *next; }; #if NO_REGEX @@ -117,7 +117,7 @@ struct pattern_info { #else #define info_compiled(info) ((info)->compiled) #endif - + static struct pattern_info search_info; static int is_ucase_pattern; static int is_caseless; @@ -125,129 +125,129 @@ static int is_caseless; /* * Are there any uppercase letters in this string? */ - static int + static int is_ucase(str) - char *str; + char *str; { - char *str_end = str + strlen(str); - LWCHAR ch; - - while (str < str_end) - { - ch = step_char(&str, +1, str_end); - if (IS_UPPER(ch)) - return (1); - } - return (0); + char *str_end = str + strlen(str); + LWCHAR ch; + + while (str < str_end) + { + ch = step_char(&str, +1, str_end); + if (IS_UPPER(ch)) + return (1); + } + return (0); } /* * Discard a saved pattern. */ - static void + static void clear_pattern(info) - struct pattern_info *info; + struct pattern_info *info; { - if (info->text != NULL) - free(info->text); - info->text = NULL; + if (info->text != NULL) + free(info->text); + info->text = NULL; #if !NO_REGEX - uncompile_pattern(&info->compiled); + uncompile_pattern(&info->compiled); #endif } /* * Compile and save a search pattern. */ - static int + static int set_pattern(info, pattern, search_type, show_error) - struct pattern_info *info; - char *pattern; - int search_type; - int show_error; + struct pattern_info *info; + char *pattern; + int search_type; + int show_error; { #if !NO_REGEX - if (pattern == NULL) - SET_NULL_PATTERN(info->compiled); - else if (compile_pattern(pattern, search_type, show_error, &info->compiled) < 0) - return -1; + if (pattern == NULL) + SET_NULL_PATTERN(info->compiled); + else if (compile_pattern(pattern, search_type, show_error, &info->compiled) < 0) + return -1; #endif - /* Pattern compiled successfully; save the text too. */ - if (info->text != NULL) - free(info->text); - info->text = NULL; - if (pattern != NULL) - { - info->text = (char *) ecalloc(1, strlen(pattern)+1); - strcpy(info->text, pattern); - } - info->search_type = search_type; - - /* - * Ignore case if -I is set OR - * -i is set AND the pattern is all lowercase. - */ - is_ucase_pattern = is_ucase(pattern); - if (is_ucase_pattern && caseless != OPT_ONPLUS) - is_caseless = 0; - else - is_caseless = caseless; - return 0; + /* Pattern compiled successfully; save the text too. */ + if (info->text != NULL) + free(info->text); + info->text = NULL; + if (pattern != NULL) + { + info->text = (char *) ecalloc(1, strlen(pattern)+1); + strcpy(info->text, pattern); + } + info->search_type = search_type; + + /* + * Ignore case if -I is set OR + * -i is set AND the pattern is all lowercase. + */ + is_ucase_pattern = is_ucase(pattern); + if (is_ucase_pattern && caseless != OPT_ONPLUS) + is_caseless = 0; + else + is_caseless = caseless; + return 0; } /* * Initialize saved pattern to nothing. */ - static void + static void init_pattern(info) - struct pattern_info *info; + struct pattern_info *info; { - SET_NULL_PATTERN(info->compiled); - info->text = NULL; - info->search_type = 0; - info->next = NULL; + SET_NULL_PATTERN(info->compiled); + info->text = NULL; + info->search_type = 0; + info->next = NULL; } /* * Initialize search variables. */ - public void + public void init_search(VOID_PARAM) { - init_pattern(&search_info); + init_pattern(&search_info); } /* * Determine which text conversions to perform before pattern matching. */ - static int + static int get_cvt_ops(VOID_PARAM) { - int ops = 0; - - if (is_caseless) - ops |= CVT_TO_LC; - if (bs_mode == BS_SPECIAL) - ops |= CVT_BS; - if (bs_mode != BS_CONTROL) - ops |= CVT_CRLF; - if (ctldisp == OPT_ONPLUS) - ops |= CVT_ANSI; - return (ops); + int ops = 0; + + if (is_caseless) + ops |= CVT_TO_LC; + if (bs_mode == BS_SPECIAL) + ops |= CVT_BS; + if (bs_mode != BS_CONTROL) + ops |= CVT_CRLF; + if (ctldisp == OPT_ONPLUS) + ops |= CVT_ANSI; + return (ops); } /* * Is there a previous (remembered) search pattern? */ - static int + static int prev_pattern(info) - struct pattern_info *info; + struct pattern_info *info; { #if !NO_REGEX - if ((info->search_type & SRCH_NO_REGEX) == 0) - return (!is_null_pattern(info->compiled)); + if ((info->search_type & SRCH_NO_REGEX) == 0) + return (!is_null_pattern(info->compiled)); #endif - return (info->text != NULL); + return (info->text != NULL); } #if HILITE_SEARCH @@ -256,116 +256,116 @@ prev_pattern(info) * Repaint each line which contains highlighted text. * If on==0, force all hilites off. */ - public void + public void repaint_hilite(on) - int on; + int on; { - int sindex; - POSITION pos; - int save_hide_hilite; - - if (squished) - repaint(); - - save_hide_hilite = hide_hilite; - if (!on) - { - if (hide_hilite) - return; - hide_hilite = 1; - } - - if (!can_goto_line) - { - repaint(); - hide_hilite = save_hide_hilite; - return; - } - - for (sindex = TOP; sindex < TOP + sc_height-1; sindex++) - { - pos = position(sindex); - if (pos == NULL_POSITION) - continue; - (void) forw_line(pos); - goto_line(sindex); - put_line(); - } - lower_left(); - hide_hilite = save_hide_hilite; + int sindex; + POSITION pos; + int save_hide_hilite; + + if (squished) + repaint(); + + save_hide_hilite = hide_hilite; + if (!on) + { + if (hide_hilite) + return; + hide_hilite = 1; + } + + if (!can_goto_line) + { + repaint(); + hide_hilite = save_hide_hilite; + return; + } + + for (sindex = TOP; sindex < TOP + sc_height-1; sindex++) + { + pos = position(sindex); + if (pos == NULL_POSITION) + continue; + (void) forw_line(pos); + goto_line(sindex); + put_line(); + } + lower_left(); + hide_hilite = save_hide_hilite; } #endif /* * Clear the attn hilite. */ - public void + public void clear_attn(VOID_PARAM) { #if HILITE_SEARCH - int sindex; - POSITION old_start_attnpos; - POSITION old_end_attnpos; - POSITION pos; - POSITION epos; - int moved = 0; - - if (start_attnpos == NULL_POSITION) - return; - old_start_attnpos = start_attnpos; - old_end_attnpos = end_attnpos; - start_attnpos = end_attnpos = NULL_POSITION; - - if (!can_goto_line) - { - repaint(); - return; - } - if (squished) - repaint(); - - for (sindex = TOP; sindex < TOP + sc_height-1; sindex++) - { - pos = position(sindex); - if (pos == NULL_POSITION) - continue; - epos = position(sindex+1); - if (pos <= old_end_attnpos && - (epos == NULL_POSITION || epos > old_start_attnpos)) - { - (void) forw_line(pos); - goto_line(sindex); - put_line(); - moved = 1; - } - } - if (moved) - lower_left(); + int sindex; + POSITION old_start_attnpos; + POSITION old_end_attnpos; + POSITION pos; + POSITION epos; + int moved = 0; + + if (start_attnpos == NULL_POSITION) + return; + old_start_attnpos = start_attnpos; + old_end_attnpos = end_attnpos; + start_attnpos = end_attnpos = NULL_POSITION; + + if (!can_goto_line) + { + repaint(); + return; + } + if (squished) + repaint(); + + for (sindex = TOP; sindex < TOP + sc_height-1; sindex++) + { + pos = position(sindex); + if (pos == NULL_POSITION) + continue; + epos = position(sindex+1); + if (pos <= old_end_attnpos && + (epos == NULL_POSITION || epos > old_start_attnpos)) + { + (void) forw_line(pos); + goto_line(sindex); + put_line(); + moved = 1; + } + } + if (moved) + lower_left(); #endif } /* * Toggle or clear search string highlighting. */ - public void + public void undo_search(clear) - int clear; + int clear; { - clear_pattern(&search_info); + clear_pattern(&search_info); #if HILITE_SEARCH - if (clear) - { - clr_hilite(); - } else - { - if (hilite_anchor.first == NULL) - { - error("No previous regular expression", NULL_PARG); - return; - } - hide_hilite = !hide_hilite; - } - repaint_hilite(1); + if (clear) + { + clr_hilite(); + } else + { + if (hilite_anchor.first == NULL) + { + error("No previous regular expression", NULL_PARG); + return; + } + hide_hilite = !hide_hilite; + } + repaint_hilite(1); #endif } @@ -373,62 +373,62 @@ undo_search(clear) /* * Clear the hilite list. */ - public void + public void clr_hlist(anchor) - struct hilite_tree *anchor; + struct hilite_tree *anchor; { - struct hilite_storage *hls; - struct hilite_storage *nexthls; - - for (hls = anchor->first; hls != NULL; hls = nexthls) - { - nexthls = hls->next; - free((void*)hls->nodes); - free((void*)hls); - } - anchor->first = NULL; - anchor->current = NULL; - anchor->root = NULL; - - anchor->lookaside = NULL; - - prep_startpos = prep_endpos = NULL_POSITION; + struct hilite_storage *hls; + struct hilite_storage *nexthls; + + for (hls = anchor->first; hls != NULL; hls = nexthls) + { + nexthls = hls->next; + free((void*)hls->nodes); + free((void*)hls); + } + anchor->first = NULL; + anchor->current = NULL; + anchor->root = NULL; + + anchor->lookaside = NULL; + + prep_startpos = prep_endpos = NULL_POSITION; } - public void + public void clr_hilite(VOID_PARAM) { - clr_hlist(&hilite_anchor); + clr_hlist(&hilite_anchor); } - public void + public void clr_filter(VOID_PARAM) { - clr_hlist(&filter_anchor); + clr_hlist(&filter_anchor); } - struct hilite_node* + struct hilite_node* hlist_last(anchor) - struct hilite_tree *anchor; + struct hilite_tree *anchor; { - struct hilite_node *n = anchor->root; - while (n != NULL && n->right != NULL) - n = n->right; - return n; + struct hilite_node *n = anchor->root; + while (n != NULL && n->right != NULL) + n = n->right; + return n; } - struct hilite_node* + struct hilite_node* hlist_next(n) - struct hilite_node *n; + struct hilite_node *n; { - return n->next; + return n->next; } - struct hilite_node* + struct hilite_node* hlist_prev(n) - struct hilite_node *n; + struct hilite_node *n; { - return n->prev; + return n->prev; } /* @@ -437,169 +437,169 @@ hlist_prev(n) * to speed up subsequent searches for the same or similar positions (if * we return NULL, remember the last node.) */ - struct hilite_node* + struct hilite_node* hlist_find(anchor, pos) - struct hilite_tree *anchor; - POSITION pos; + struct hilite_tree *anchor; + POSITION pos; { - struct hilite_node *n, *m; - - if (anchor->lookaside) - { - int steps = 0; - int hit = 0; - - n = anchor->lookaside; - - for (;;) - { - if (pos < n->r.hl_endpos) - { - if (n->prev == NULL || pos >= n->prev->r.hl_endpos) - { - hit = 1; - break; - } - } else if (n->next == NULL) - { - n = NULL; - hit = 1; - break; - } - - /* - * If we don't find the right node within a small - * distance, don't keep doing a linear search! - */ - if (steps >= HILITE_LOOKASIDE_STEPS) - break; - steps++; - - if (pos < n->r.hl_endpos) - anchor->lookaside = n = n->prev; - else - anchor->lookaside = n = n->next; - } - - if (hit) - return n; - } - - n = anchor->root; - m = NULL; - - while (n != NULL) - { - if (pos < n->r.hl_startpos) - { - if (n->left != NULL) - { - m = n; - n = n->left; - continue; - } - break; - } - if (pos >= n->r.hl_endpos) - { - if (n->right != NULL) - { - n = n->right; - continue; - } - if (m != NULL) - { - n = m; - } else - { - m = n; - n = NULL; - } - } - break; - } - - if (n != NULL) - anchor->lookaside = n; - else if (m != NULL) - anchor->lookaside = m; - - return n; + struct hilite_node *n, *m; + + if (anchor->lookaside) + { + int steps = 0; + int hit = 0; + + n = anchor->lookaside; + + for (;;) + { + if (pos < n->r.hl_endpos) + { + if (n->prev == NULL || pos >= n->prev->r.hl_endpos) + { + hit = 1; + break; + } + } else if (n->next == NULL) + { + n = NULL; + hit = 1; + break; + } + + /* + * If we don't find the right node within a small + * distance, don't keep doing a linear search! + */ + if (steps >= HILITE_LOOKASIDE_STEPS) + break; + steps++; + + if (pos < n->r.hl_endpos) + anchor->lookaside = n = n->prev; + else + anchor->lookaside = n = n->next; + } + + if (hit) + return n; + } + + n = anchor->root; + m = NULL; + + while (n != NULL) + { + if (pos < n->r.hl_startpos) + { + if (n->left != NULL) + { + m = n; + n = n->left; + continue; + } + break; + } + if (pos >= n->r.hl_endpos) + { + if (n->right != NULL) + { + n = n->right; + continue; + } + if (m != NULL) + { + n = m; + } else + { + m = n; + n = NULL; + } + } + break; + } + + if (n != NULL) + anchor->lookaside = n; + else if (m != NULL) + anchor->lookaside = m; + + return n; } /* * Should any characters in a specified range be highlighted? */ - static int + static int is_hilited_range(pos, epos) - POSITION pos; - POSITION epos; + POSITION pos; + POSITION epos; { - struct hilite_node *n = hlist_find(&hilite_anchor, pos); - return (n != NULL && (epos == NULL_POSITION || epos > n->r.hl_startpos)); + struct hilite_node *n = hlist_find(&hilite_anchor, pos); + return (n != NULL && (epos == NULL_POSITION || epos > n->r.hl_startpos)); } -/* +/* * Is a line "filtered" -- that is, should it be hidden? */ - public int + public int is_filtered(pos) - POSITION pos; + POSITION pos; { - struct hilite_node *n; + struct hilite_node *n; - if (ch_getflags() & CH_HELPFILE) - return (0); + if (ch_getflags() & CH_HELPFILE) + return (0); - n = hlist_find(&filter_anchor, pos); - return (n != NULL && pos >= n->r.hl_startpos); + n = hlist_find(&filter_anchor, pos); + return (n != NULL && pos >= n->r.hl_startpos); } /* * If pos is hidden, return the next position which isn't, otherwise * just return pos. */ - public POSITION + public POSITION next_unfiltered(pos) - POSITION pos; + POSITION pos; { - struct hilite_node *n; - - if (ch_getflags() & CH_HELPFILE) - return (pos); - - n = hlist_find(&filter_anchor, pos); - while (n != NULL && pos >= n->r.hl_startpos) - { - pos = n->r.hl_endpos; - n = n->next; - } - return (pos); + struct hilite_node *n; + + if (ch_getflags() & CH_HELPFILE) + return (pos); + + n = hlist_find(&filter_anchor, pos); + while (n != NULL && pos >= n->r.hl_startpos) + { + pos = n->r.hl_endpos; + n = n->next; + } + return (pos); } /* * If pos is hidden, return the previous position which isn't or 0 if * we're filtered right to the beginning, otherwise just return pos. */ - public POSITION + public POSITION prev_unfiltered(pos) - POSITION pos; + POSITION pos; { - struct hilite_node *n; - - if (ch_getflags() & CH_HELPFILE) - return (pos); - - n = hlist_find(&filter_anchor, pos); - while (n != NULL && pos >= n->r.hl_startpos) - { - pos = n->r.hl_startpos; - if (pos == 0) - break; - pos--; - n = n->prev; - } - return (pos); + struct hilite_node *n; + + if (ch_getflags() & CH_HELPFILE) + return (pos); + + n = hlist_find(&filter_anchor, pos); + while (n != NULL && pos >= n->r.hl_startpos) + { + pos = n->r.hl_startpos; + if (pos == 0) + break; + pos--; + n = n->prev; + } + return (pos); } @@ -607,429 +607,429 @@ prev_unfiltered(pos) * Should any characters in a specified range be highlighted? * If nohide is nonzero, don't consider hide_hilite. */ - public int + public int is_hilited_attr(pos, epos, nohide, p_matches) - POSITION pos; - POSITION epos; - int nohide; - int *p_matches; + POSITION pos; + POSITION epos; + int nohide; + int *p_matches; { - int match; - - if (p_matches != NULL) - *p_matches = 0; - - if (!status_col && - start_attnpos != NULL_POSITION && - pos <= end_attnpos && - (epos == NULL_POSITION || epos >= start_attnpos)) - /* - * The attn line overlaps this range. - */ - return (AT_HILITE|AT_COLOR_ATTN); - - match = is_hilited_range(pos, epos); - if (!match) - return (0); - - if (p_matches == NULL) - /* - * Kinda kludgy way to recognize that caller is checking for - * hilite in status column. In this case we want to return - * hilite status even if hiliting is disabled or hidden. - */ - return (AT_HILITE|AT_COLOR_SEARCH); - - /* - * Report matches, even if we're hiding highlights. - */ - *p_matches = 1; - - if (hilite_search == 0) - /* - * Not doing highlighting. - */ - return (0); - - if (!nohide && hide_hilite) - /* - * Highlighting is hidden. - */ - return (0); - - return (AT_HILITE|AT_COLOR_SEARCH); + int match; + + if (p_matches != NULL) + *p_matches = 0; + + if (!status_col && + start_attnpos != NULL_POSITION && + pos <= end_attnpos && + (epos == NULL_POSITION || epos >= start_attnpos)) + /* + * The attn line overlaps this range. + */ + return (AT_HILITE|AT_COLOR_ATTN); + + match = is_hilited_range(pos, epos); + if (!match) + return (0); + + if (p_matches == NULL) + /* + * Kinda kludgy way to recognize that caller is checking for + * hilite in status column. In this case we want to return + * hilite status even if hiliting is disabled or hidden. + */ + return (AT_HILITE|AT_COLOR_SEARCH); + + /* + * Report matches, even if we're hiding highlights. + */ + *p_matches = 1; + + if (hilite_search == 0) + /* + * Not doing highlighting. + */ + return (0); + + if (!nohide && hide_hilite) + /* + * Highlighting is hidden. + */ + return (0); + + return (AT_HILITE|AT_COLOR_SEARCH); } /* * Tree node storage: get the current block of nodes if it has spare * capacity, or create a new one if not. */ - static struct hilite_storage* + static struct hilite_storage* hlist_getstorage(anchor) - struct hilite_tree *anchor; + struct hilite_tree *anchor; { - int capacity = 1; - struct hilite_storage *s; - - if (anchor->current) - { - if (anchor->current->used < anchor->current->capacity) - return anchor->current; - capacity = anchor->current->capacity * 2; - } - - s = (struct hilite_storage *) ecalloc(1, sizeof(struct hilite_storage)); - s->nodes = (struct hilite_node *) ecalloc(capacity, sizeof(struct hilite_node)); - s->capacity = capacity; - s->used = 0; - s->next = NULL; - if (anchor->current) - anchor->current->next = s; - else - anchor->first = s; - anchor->current = s; - return s; + int capacity = 1; + struct hilite_storage *s; + + if (anchor->current) + { + if (anchor->current->used < anchor->current->capacity) + return anchor->current; + capacity = anchor->current->capacity * 2; + } + + s = (struct hilite_storage *) ecalloc(1, sizeof(struct hilite_storage)); + s->nodes = (struct hilite_node *) ecalloc(capacity, sizeof(struct hilite_node)); + s->capacity = capacity; + s->used = 0; + s->next = NULL; + if (anchor->current) + anchor->current->next = s; + else + anchor->first = s; + anchor->current = s; + return s; } /* * Tree node storage: retrieve a new empty node to be inserted into the * tree. */ - static struct hilite_node* + static struct hilite_node* hlist_getnode(anchor) - struct hilite_tree *anchor; + struct hilite_tree *anchor; { - struct hilite_storage *s = hlist_getstorage(anchor); - return &s->nodes[s->used++]; + struct hilite_storage *s = hlist_getstorage(anchor); + return &s->nodes[s->used++]; } /* * Rotate the tree left around a pivot node. */ - static void + static void hlist_rotate_left(anchor, n) - struct hilite_tree *anchor; - struct hilite_node *n; + struct hilite_tree *anchor; + struct hilite_node *n; { - struct hilite_node *np = n->parent; - struct hilite_node *nr = n->right; - struct hilite_node *nrl = n->right->left; - - if (np != NULL) - { - if (n == np->left) - np->left = nr; - else - np->right = nr; - } else - { - anchor->root = nr; - } - nr->left = n; - n->right = nrl; - - nr->parent = np; - n->parent = nr; - if (nrl != NULL) - nrl->parent = n; + struct hilite_node *np = n->parent; + struct hilite_node *nr = n->right; + struct hilite_node *nrl = n->right->left; + + if (np != NULL) + { + if (n == np->left) + np->left = nr; + else + np->right = nr; + } else + { + anchor->root = nr; + } + nr->left = n; + n->right = nrl; + + nr->parent = np; + n->parent = nr; + if (nrl != NULL) + nrl->parent = n; } /* * Rotate the tree right around a pivot node. */ - static void + static void hlist_rotate_right(anchor, n) - struct hilite_tree *anchor; - struct hilite_node *n; + struct hilite_tree *anchor; + struct hilite_node *n; { - struct hilite_node *np = n->parent; - struct hilite_node *nl = n->left; - struct hilite_node *nlr = n->left->right; - - if (np != NULL) - { - if (n == np->right) - np->right = nl; - else - np->left = nl; - } else - { - anchor->root = nl; - } - nl->right = n; - n->left = nlr; - - nl->parent = np; - n->parent = nl; - if (nlr != NULL) - nlr->parent = n; + struct hilite_node *np = n->parent; + struct hilite_node *nl = n->left; + struct hilite_node *nlr = n->left->right; + + if (np != NULL) + { + if (n == np->right) + np->right = nl; + else + np->left = nl; + } else + { + anchor->root = nl; + } + nl->right = n; + n->left = nlr; + + nl->parent = np; + n->parent = nl; + if (nlr != NULL) + nlr->parent = n; } /* * Add a new hilite to a hilite list. */ - static void + static void add_hilite(anchor, hl) - struct hilite_tree *anchor; - struct hilite *hl; + struct hilite_tree *anchor; + struct hilite *hl; { - struct hilite_node *p, *n, *u; - - /* Ignore empty ranges. */ - if (hl->hl_startpos >= hl->hl_endpos) - return; - - p = anchor->root; - - /* Inserting the very first node is trivial. */ - if (p == NULL) - { - n = hlist_getnode(anchor); - n->r = *hl; - anchor->root = n; - anchor->lookaside = n; - return; - } - - /* - * Find our insertion point. If we come across any overlapping - * or adjoining existing ranges, shrink our range and discard - * if it become empty. - */ - for (;;) - { - if (hl->hl_startpos < p->r.hl_startpos) - { - if (hl->hl_endpos > p->r.hl_startpos) - hl->hl_endpos = p->r.hl_startpos; - if (p->left != NULL) - { - p = p->left; - continue; - } - break; - } - if (hl->hl_startpos < p->r.hl_endpos) { - hl->hl_startpos = p->r.hl_endpos; - if (hl->hl_startpos >= hl->hl_endpos) - return; - } - if (p->right != NULL) - { - p = p->right; - continue; - } - break; - } - - /* - * Now we're at the right leaf, again check for contiguous ranges - * and extend the existing node if possible to avoid the - * insertion. Otherwise insert a new node at the leaf. - */ - if (hl->hl_startpos < p->r.hl_startpos) { - if (hl->hl_endpos == p->r.hl_startpos) - { - p->r.hl_startpos = hl->hl_startpos; - return; - } - if (p->prev != NULL && p->prev->r.hl_endpos == hl->hl_startpos) - { - p->prev->r.hl_endpos = hl->hl_endpos; - return; - } - - p->left = n = hlist_getnode(anchor); - n->next = p; - if (p->prev != NULL) - { - n->prev = p->prev; - p->prev->next = n; - } - p->prev = n; - } else { - if (p->r.hl_endpos == hl->hl_startpos) - { - p->r.hl_endpos = hl->hl_endpos; - return; - } - if (p->next != NULL && hl->hl_endpos == p->next->r.hl_startpos) { - p->next->r.hl_startpos = hl->hl_startpos; - return; - } - - p->right = n = hlist_getnode(anchor); - n->prev = p; - if (p->next != NULL) - { - n->next = p->next; - p->next->prev = n; - } - p->next = n; - } - n->parent = p; - n->red = 1; - n->r = *hl; - - /* - * The tree is in the correct order and covers the right ranges - * now, but may have become unbalanced. Rebalance it using the - * standard red-black tree constraints and operations. - */ - for (;;) - { - /* case 1 - current is root, root is always black */ - if (n->parent == NULL) - { - n->red = 0; - break; - } - - /* case 2 - parent is black, we can always be red */ - if (!n->parent->red) - break; - - /* - * constraint: because the root must be black, if our - * parent is red it cannot be the root therefore we must - * have a grandparent - */ - - /* - * case 3 - parent and uncle are red, repaint them black, - * the grandparent red, and start again at the grandparent. - */ - u = n->parent->parent->left; - if (n->parent == u) - u = n->parent->parent->right; - if (u != NULL && u->red) - { - n->parent->red = 0; - u->red = 0; - n = n->parent->parent; - n->red = 1; - continue; - } - - /* - * case 4 - parent is red but uncle is black, parent and - * grandparent on opposite sides. We need to start - * changing the structure now. This and case 5 will shorten - * our branch and lengthen the sibling, between them - * restoring balance. - */ - if (n == n->parent->right && - n->parent == n->parent->parent->left) - { - hlist_rotate_left(anchor, n->parent); - n = n->left; - } else if (n == n->parent->left && - n->parent == n->parent->parent->right) - { - hlist_rotate_right(anchor, n->parent); - n = n->right; - } - - /* - * case 5 - parent is red but uncle is black, parent and - * grandparent on same side - */ - n->parent->red = 0; - n->parent->parent->red = 1; - if (n == n->parent->left) - hlist_rotate_right(anchor, n->parent->parent); - else - hlist_rotate_left(anchor, n->parent->parent); - break; - } + struct hilite_node *p, *n, *u; + + /* Ignore empty ranges. */ + if (hl->hl_startpos >= hl->hl_endpos) + return; + + p = anchor->root; + + /* Inserting the very first node is trivial. */ + if (p == NULL) + { + n = hlist_getnode(anchor); + n->r = *hl; + anchor->root = n; + anchor->lookaside = n; + return; + } + + /* + * Find our insertion point. If we come across any overlapping + * or adjoining existing ranges, shrink our range and discard + * if it become empty. + */ + for (;;) + { + if (hl->hl_startpos < p->r.hl_startpos) + { + if (hl->hl_endpos > p->r.hl_startpos) + hl->hl_endpos = p->r.hl_startpos; + if (p->left != NULL) + { + p = p->left; + continue; + } + break; + } + if (hl->hl_startpos < p->r.hl_endpos) { + hl->hl_startpos = p->r.hl_endpos; + if (hl->hl_startpos >= hl->hl_endpos) + return; + } + if (p->right != NULL) + { + p = p->right; + continue; + } + break; + } + + /* + * Now we're at the right leaf, again check for contiguous ranges + * and extend the existing node if possible to avoid the + * insertion. Otherwise insert a new node at the leaf. + */ + if (hl->hl_startpos < p->r.hl_startpos) { + if (hl->hl_endpos == p->r.hl_startpos) + { + p->r.hl_startpos = hl->hl_startpos; + return; + } + if (p->prev != NULL && p->prev->r.hl_endpos == hl->hl_startpos) + { + p->prev->r.hl_endpos = hl->hl_endpos; + return; + } + + p->left = n = hlist_getnode(anchor); + n->next = p; + if (p->prev != NULL) + { + n->prev = p->prev; + p->prev->next = n; + } + p->prev = n; + } else { + if (p->r.hl_endpos == hl->hl_startpos) + { + p->r.hl_endpos = hl->hl_endpos; + return; + } + if (p->next != NULL && hl->hl_endpos == p->next->r.hl_startpos) { + p->next->r.hl_startpos = hl->hl_startpos; + return; + } + + p->right = n = hlist_getnode(anchor); + n->prev = p; + if (p->next != NULL) + { + n->next = p->next; + p->next->prev = n; + } + p->next = n; + } + n->parent = p; + n->red = 1; + n->r = *hl; + + /* + * The tree is in the correct order and covers the right ranges + * now, but may have become unbalanced. Rebalance it using the + * standard red-black tree constraints and operations. + */ + for (;;) + { + /* case 1 - current is root, root is always black */ + if (n->parent == NULL) + { + n->red = 0; + break; + } + + /* case 2 - parent is black, we can always be red */ + if (!n->parent->red) + break; + + /* + * constraint: because the root must be black, if our + * parent is red it cannot be the root therefore we must + * have a grandparent + */ + + /* + * case 3 - parent and uncle are red, repaint them black, + * the grandparent red, and start again at the grandparent. + */ + u = n->parent->parent->left; + if (n->parent == u) + u = n->parent->parent->right; + if (u != NULL && u->red) + { + n->parent->red = 0; + u->red = 0; + n = n->parent->parent; + n->red = 1; + continue; + } + + /* + * case 4 - parent is red but uncle is black, parent and + * grandparent on opposite sides. We need to start + * changing the structure now. This and case 5 will shorten + * our branch and lengthen the sibling, between them + * restoring balance. + */ + if (n == n->parent->right && + n->parent == n->parent->parent->left) + { + hlist_rotate_left(anchor, n->parent); + n = n->left; + } else if (n == n->parent->left && + n->parent == n->parent->parent->right) + { + hlist_rotate_right(anchor, n->parent); + n = n->right; + } + + /* + * case 5 - parent is red but uncle is black, parent and + * grandparent on same side + */ + n->parent->red = 0; + n->parent->parent->red = 1; + if (n == n->parent->left) + hlist_rotate_right(anchor, n->parent->parent); + else + hlist_rotate_left(anchor, n->parent->parent); + break; + } } /* * Hilight every character in a range of displayed characters. */ - static void + static void create_hilites(linepos, start_index, end_index, chpos) - POSITION linepos; - int start_index; - int end_index; - int *chpos; + POSITION linepos; + int start_index; + int end_index; + int *chpos; { - struct hilite hl; - int i; - - /* Start the first hilite. */ - hl.hl_startpos = linepos + chpos[start_index]; - - /* - * Step through the displayed chars. - * If the source position (before cvt) of the char is one more - * than the source pos of the previous char (the usual case), - * just increase the size of the current hilite by one. - * Otherwise (there are backspaces or something involved), - * finish the current hilite and start a new one. - */ - for (i = start_index+1; i <= end_index; i++) - { - if (chpos[i] != chpos[i-1] + 1 || i == end_index) - { - hl.hl_endpos = linepos + chpos[i-1] + 1; - add_hilite(&hilite_anchor, &hl); - /* Start new hilite unless this is the last char. */ - if (i < end_index) - { - hl.hl_startpos = linepos + chpos[i]; - } - } - } + struct hilite hl; + int i; + + /* Start the first hilite. */ + hl.hl_startpos = linepos + chpos[start_index]; + + /* + * Step through the displayed chars. + * If the source position (before cvt) of the char is one more + * than the source pos of the previous char (the usual case), + * just increase the size of the current hilite by one. + * Otherwise (there are backspaces or something involved), + * finish the current hilite and start a new one. + */ + for (i = start_index+1; i <= end_index; i++) + { + if (chpos[i] != chpos[i-1] + 1 || i == end_index) + { + hl.hl_endpos = linepos + chpos[i-1] + 1; + add_hilite(&hilite_anchor, &hl); + /* Start new hilite unless this is the last char. */ + if (i < end_index) + { + hl.hl_startpos = linepos + chpos[i]; + } + } + } } /* - * Make a hilite for each string in a physical line which matches + * Make a hilite for each string in a physical line which matches * the current pattern. * sp,ep delimit the first match already found. */ - static void + static void hilite_line(linepos, line, line_len, chpos, sp, ep, cvt_ops) - POSITION linepos; - char *line; - int line_len; - int *chpos; - char *sp; - char *ep; - int cvt_ops; + POSITION linepos; + char *line; + int line_len; + int *chpos; + char *sp; + char *ep; + int cvt_ops; { - char *searchp; - char *line_end = line + line_len; - - /* - * sp and ep delimit the first match in the line. - * Mark the corresponding file positions, then - * look for further matches and mark them. - * {{ This technique, of calling match_pattern on subsequent - * substrings of the line, may mark more than is correct - * if the pattern starts with "^". This bug is fixed - * for those regex functions that accept a notbol parameter - * (currently POSIX, PCRE and V8-with-regexec2). }} - */ - searchp = line; - do { - if (sp == NULL || ep == NULL) - return; - create_hilites(linepos, sp-line, ep-line, chpos); - /* - * If we matched more than zero characters, - * move to the first char after the string we matched. - * If we matched zero, just move to the next char. - */ - if (ep > searchp) - searchp = ep; - else if (searchp != line_end) - searchp++; - else /* end of line */ - break; - } while (match_pattern(info_compiled(&search_info), search_info.text, - searchp, line_end - searchp, &sp, &ep, 1, search_info.search_type)); + char *searchp; + char *line_end = line + line_len; + + /* + * sp and ep delimit the first match in the line. + * Mark the corresponding file positions, then + * look for further matches and mark them. + * {{ This technique, of calling match_pattern on subsequent + * substrings of the line, may mark more than is correct + * if the pattern starts with "^". This bug is fixed + * for those regex functions that accept a notbol parameter + * (currently POSIX, PCRE and V8-with-regexec2). }} + */ + searchp = line; + do { + if (sp == NULL || ep == NULL) + return; + create_hilites(linepos, sp-line, ep-line, chpos); + /* + * If we matched more than zero characters, + * move to the first char after the string we matched. + * If we matched zero, just move to the next char. + */ + if (ep > searchp) + searchp = ep; + else if (searchp != line_end) + searchp++; + else /* end of line */ + break; + } while (match_pattern(info_compiled(&search_info), search_info.text, + searchp, line_end - searchp, &sp, &ep, 1, search_info.search_type)); } #endif @@ -1037,129 +1037,129 @@ hilite_line(linepos, line, line_len, chpos, sp, ep, cvt_ops) /* * Find matching text which is currently on screen and highlight it. */ - static void + static void hilite_screen(VOID_PARAM) { - struct scrpos scrpos; + struct scrpos scrpos; - get_scrpos(&scrpos, TOP); - if (scrpos.pos == NULL_POSITION) - return; - prep_hilite(scrpos.pos, position(BOTTOM_PLUS_ONE), -1); - repaint_hilite(1); + get_scrpos(&scrpos, TOP); + if (scrpos.pos == NULL_POSITION) + return; + prep_hilite(scrpos.pos, position(BOTTOM_PLUS_ONE), -1); + repaint_hilite(1); } /* * Change highlighting parameters. */ - public void + public void chg_hilite(VOID_PARAM) { - /* - * Erase any highlights currently on screen. - */ - clr_hilite(); - hide_hilite = 0; - - if (hilite_search == OPT_ONPLUS) - /* - * Display highlights. - */ - hilite_screen(); + /* + * Erase any highlights currently on screen. + */ + clr_hilite(); + hide_hilite = 0; + + if (hilite_search == OPT_ONPLUS) + /* + * Display highlights. + */ + hilite_screen(); } #endif /* * Figure out where to start a search. */ - static POSITION + static POSITION search_pos(search_type) - int search_type; + int search_type; { - POSITION pos; - int sindex; - - if (empty_screen()) - { - /* - * Start at the beginning (or end) of the file. - * The empty_screen() case is mainly for - * command line initiated searches; - * for example, "+/xyz" on the command line. - * Also for multi-file (SRCH_PAST_EOF) searches. - */ - if (search_type & SRCH_FORW) - { - pos = ch_zero(); - } else - { - pos = ch_length(); - if (pos == NULL_POSITION) - { - (void) ch_end_seek(); - pos = ch_length(); - } - } - sindex = 0; - } else - { - int add_one = 0; - - if (how_search == OPT_ON) - { - /* - * Search does not include current screen. - */ - if (search_type & SRCH_FORW) - sindex = sc_height-1; /* BOTTOM_PLUS_ONE */ - else - sindex = 0; /* TOP */ - } else if (how_search == OPT_ONPLUS && !(search_type & SRCH_AFTER_TARGET)) - { - /* - * Search includes all of displayed screen. - */ - if (search_type & SRCH_FORW) - sindex = 0; /* TOP */ - else - sindex = sc_height-1; /* BOTTOM_PLUS_ONE */ - } else - { - /* - * Search includes the part of current screen beyond the jump target. - * It starts at the jump target (if searching backwards), - * or at the jump target plus one (if forwards). - */ - sindex = sindex_from_sline(jump_sline); - if (search_type & SRCH_FORW) - add_one = 1; - } - pos = position(sindex); - if (add_one) - pos = forw_raw_line(pos, (char **)NULL, (int *)NULL); - } - - /* - * If the line is empty, look around for a plausible starting place. - */ - if (search_type & SRCH_FORW) - { - while (pos == NULL_POSITION) - { - if (++sindex >= sc_height) - break; - pos = position(sindex); - } - } else - { - while (pos == NULL_POSITION) - { - if (--sindex < 0) - break; - pos = position(sindex); - } - } - return (pos); + POSITION pos; + int sindex; + + if (empty_screen()) + { + /* + * Start at the beginning (or end) of the file. + * The empty_screen() case is mainly for + * command line initiated searches; + * for example, "+/xyz" on the command line. + * Also for multi-file (SRCH_PAST_EOF) searches. + */ + if (search_type & SRCH_FORW) + { + pos = ch_zero(); + } else + { + pos = ch_length(); + if (pos == NULL_POSITION) + { + (void) ch_end_seek(); + pos = ch_length(); + } + } + sindex = 0; + } else + { + int add_one = 0; + + if (how_search == OPT_ON) + { + /* + * Search does not include current screen. + */ + if (search_type & SRCH_FORW) + sindex = sc_height-1; /* BOTTOM_PLUS_ONE */ + else + sindex = 0; /* TOP */ + } else if (how_search == OPT_ONPLUS && !(search_type & SRCH_AFTER_TARGET)) + { + /* + * Search includes all of displayed screen. + */ + if (search_type & SRCH_FORW) + sindex = 0; /* TOP */ + else + sindex = sc_height-1; /* BOTTOM_PLUS_ONE */ + } else + { + /* + * Search includes the part of current screen beyond the jump target. + * It starts at the jump target (if searching backwards), + * or at the jump target plus one (if forwards). + */ + sindex = sindex_from_sline(jump_sline); + if (search_type & SRCH_FORW) + add_one = 1; + } + pos = position(sindex); + if (add_one) + pos = forw_raw_line(pos, (char **)NULL, (int *)NULL); + } + + /* + * If the line is empty, look around for a plausible starting place. + */ + if (search_type & SRCH_FORW) + { + while (pos == NULL_POSITION) + { + if (++sindex >= sc_height) + break; + pos = position(sindex); + } + } else + { + while (pos == NULL_POSITION) + { + if (--sindex < 0) + break; + pos = position(sindex); + } + } + return (pos); } /* @@ -1167,34 +1167,34 @@ search_pos(search_type) * If so, add an entry to the filter list. */ #if HILITE_SEARCH - static int + static int matches_filters(pos, cline, line_len, chpos, linepos, sp, ep) - POSITION pos; - char *cline; - int line_len; - int *chpos; - POSITION linepos; - char **sp; - char **ep; + POSITION pos; + char *cline; + int line_len; + int *chpos; + POSITION linepos; + char **sp; + char **ep; { - struct pattern_info *filter; - - for (filter = filter_infos; filter != NULL; filter = filter->next) - { - int line_filter = match_pattern(info_compiled(filter), filter->text, - cline, line_len, sp, ep, 0, filter->search_type); - if (line_filter) - { - struct hilite hl; - hl.hl_startpos = linepos; - hl.hl_endpos = pos; - add_hilite(&filter_anchor, &hl); - free(cline); - free(chpos); - return (1); - } - } - return (0); + struct pattern_info *filter; + + for (filter = filter_infos; filter != NULL; filter = filter->next) + { + int line_filter = match_pattern(info_compiled(filter), filter->text, + cline, line_len, sp, ep, 0, filter->search_type); + if (line_filter) + { + struct hilite hl; + hl.hl_startpos = linepos; + hl.hl_endpos = pos; + add_hilite(&filter_anchor, &hl); + free(cline); + free(chpos); + return (1); + } + } + return (0); } #endif @@ -1202,505 +1202,505 @@ matches_filters(pos, cline, line_len, chpos, linepos, sp, ep) * Get the position of the first char in the screen line which * puts tpos on screen. */ - static POSITION + static POSITION get_lastlinepos(pos, tpos, sheight) - POSITION pos; - POSITION tpos; - int sheight; + POSITION pos; + POSITION tpos; + int sheight; { - int nlines; - - for (nlines = 0;; nlines++) - { - POSITION npos = forw_line(pos); - if (npos > tpos) - { - if (nlines < sheight) - return NULL_POSITION; - return pos; - } - pos = npos; - } + int nlines; + + for (nlines = 0;; nlines++) + { + POSITION npos = forw_line(pos); + if (npos > tpos) + { + if (nlines < sheight) + return NULL_POSITION; + return pos; + } + pos = npos; + } } /* * Get the segment index of tpos in the line starting at pos. * A segment is a string of printable chars that fills the screen width. */ - static int + static int get_seg(pos, tpos) - POSITION pos; - POSITION tpos; + POSITION pos; + POSITION tpos; { - int seg; - - for (seg = 0;; seg++) - { - POSITION npos = forw_line_seg(pos, TRUE); - if (npos > tpos) - return seg; - pos = npos; - } + int seg; + + for (seg = 0;; seg++) + { + POSITION npos = forw_line_seg(pos, TRUE); + if (npos > tpos) + return seg; + pos = npos; + } } /* * Search a subset of the file, specified by start/end position. */ - static int + static int search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, plastlinepos) - POSITION pos; - POSITION endpos; - int search_type; - int matches; - int maxlines; - POSITION *plinepos; - POSITION *pendpos; - POSITION *plastlinepos; + POSITION pos; + POSITION endpos; + int search_type; + int matches; + int maxlines; + POSITION *plinepos; + POSITION *pendpos; + POSITION *plastlinepos; { - char *line; - char *cline; - int line_len; - LINENUM linenum; - char *sp, *ep; - int line_match; - int cvt_ops; - int cvt_len; - int *chpos; - POSITION linepos, oldpos; - int swidth = sc_width - line_pfx_width(); - int sheight = sc_height - sindex_from_sline(jump_sline); - - linenum = find_linenum(pos); - oldpos = pos; - /* When the search wraps around, end at starting position. */ - if ((search_type & SRCH_WRAP) && endpos == NULL_POSITION) - endpos = pos; - for (;;) - { - /* - * Get lines until we find a matching one or until - * we hit end-of-file (or beginning-of-file if we're - * going backwards), or until we hit the end position. - */ - if (ABORT_SIGS()) - { - /* - * A signal aborts the search. - */ - return (-1); - } - - if ((endpos != NULL_POSITION && !(search_type & SRCH_WRAP) && - (((search_type & SRCH_FORW) && pos >= endpos) || - ((search_type & SRCH_BACK) && pos <= endpos))) || maxlines == 0) - { - /* - * Reached end position without a match. - */ - if (pendpos != NULL) - *pendpos = pos; - return (matches); - } - if (maxlines > 0) - maxlines--; - - if (search_type & SRCH_FORW) - { - /* - * Read the next line, and save the - * starting position of that line in linepos. - */ - linepos = pos; - pos = forw_raw_line(pos, &line, &line_len); - if (linenum != 0) - linenum++; - } else - { - /* - * Read the previous line and save the - * starting position of that line in linepos. - */ - pos = back_raw_line(pos, &line, &line_len); - linepos = pos; - if (linenum != 0) - linenum--; - } - - if (pos == NULL_POSITION) - { - /* - * Reached EOF/BOF without a match. - */ - if (search_type & SRCH_WRAP) - { - /* - * The search wraps around the current file, so - * try to continue at BOF/EOF. - */ - if (search_type & SRCH_FORW) - { - pos = ch_zero(); - } else - { - pos = ch_length(); - if (pos == NULL_POSITION) - { - (void) ch_end_seek(); - pos = ch_length(); - } - } - if (pos != NULL_POSITION) { - /* - * Wrap-around was successful. Clear - * the flag so we don't wrap again, and - * continue the search at new pos. - */ - search_type &= ~SRCH_WRAP; - linenum = find_linenum(pos); - continue; - } - } - if (pendpos != NULL) - *pendpos = oldpos; - return (matches); - } - - /* - * If we're using line numbers, we might as well - * remember the information we have now (the position - * and line number of the current line). - * Don't do it for every line because it slows down - * the search. Remember the line number only if - * we're "far" from the last place we remembered it. - */ - if (linenums && abs((int)(pos - oldpos)) > 2048) - add_lnum(linenum, pos); - oldpos = pos; + char *line; + char *cline; + int line_len; + LINENUM linenum; + char *sp, *ep; + int line_match; + int cvt_ops; + int cvt_len; + int *chpos; + POSITION linepos, oldpos; + int swidth = sc_width - line_pfx_width(); + int sheight = sc_height - sindex_from_sline(jump_sline); + + linenum = find_linenum(pos); + oldpos = pos; + /* When the search wraps around, end at starting position. */ + if ((search_type & SRCH_WRAP) && endpos == NULL_POSITION) + endpos = pos; + for (;;) + { + /* + * Get lines until we find a matching one or until + * we hit end-of-file (or beginning-of-file if we're + * going backwards), or until we hit the end position. + */ + if (ABORT_SIGS()) + { + /* + * A signal aborts the search. + */ + return (-1); + } + + if ((endpos != NULL_POSITION && !(search_type & SRCH_WRAP) && + (((search_type & SRCH_FORW) && pos >= endpos) || + ((search_type & SRCH_BACK) && pos <= endpos))) || maxlines == 0) + { + /* + * Reached end position without a match. + */ + if (pendpos != NULL) + *pendpos = pos; + return (matches); + } + if (maxlines > 0) + maxlines--; + + if (search_type & SRCH_FORW) + { + /* + * Read the next line, and save the + * starting position of that line in linepos. + */ + linepos = pos; + pos = forw_raw_line(pos, &line, &line_len); + if (linenum != 0) + linenum++; + } else + { + /* + * Read the previous line and save the + * starting position of that line in linepos. + */ + pos = back_raw_line(pos, &line, &line_len); + linepos = pos; + if (linenum != 0) + linenum--; + } + + if (pos == NULL_POSITION) + { + /* + * Reached EOF/BOF without a match. + */ + if (search_type & SRCH_WRAP) + { + /* + * The search wraps around the current file, so + * try to continue at BOF/EOF. + */ + if (search_type & SRCH_FORW) + { + pos = ch_zero(); + } else + { + pos = ch_length(); + if (pos == NULL_POSITION) + { + (void) ch_end_seek(); + pos = ch_length(); + } + } + if (pos != NULL_POSITION) { + /* + * Wrap-around was successful. Clear + * the flag so we don't wrap again, and + * continue the search at new pos. + */ + search_type &= ~SRCH_WRAP; + linenum = find_linenum(pos); + continue; + } + } + if (pendpos != NULL) + *pendpos = oldpos; + return (matches); + } + + /* + * If we're using line numbers, we might as well + * remember the information we have now (the position + * and line number of the current line). + * Don't do it for every line because it slows down + * the search. Remember the line number only if + * we're "far" from the last place we remembered it. + */ + if (linenums && abs((int)(pos - oldpos)) > 2048) + add_lnum(linenum, pos); + oldpos = pos; #if HILITE_SEARCH - if (is_filtered(linepos)) - continue; + if (is_filtered(linepos)) + continue; #endif - /* - * If it's a caseless search, convert the line to lowercase. - * If we're doing backspace processing, delete backspaces. - */ - cvt_ops = get_cvt_ops(); - cvt_len = cvt_length(line_len, cvt_ops); - cline = (char *) ecalloc(1, cvt_len); - chpos = cvt_alloc_chpos(cvt_len); - cvt_text(cline, line, chpos, &line_len, cvt_ops); + /* + * If it's a caseless search, convert the line to lowercase. + * If we're doing backspace processing, delete backspaces. + */ + cvt_ops = get_cvt_ops(); + cvt_len = cvt_length(line_len, cvt_ops); + cline = (char *) ecalloc(1, cvt_len); + chpos = cvt_alloc_chpos(cvt_len); + cvt_text(cline, line, chpos, &line_len, cvt_ops); #if HILITE_SEARCH - /* - * If any filters are in effect, ignore non-matching lines. - */ - if (filter_infos != NULL && - ((search_type & SRCH_FIND_ALL) || - prep_startpos == NULL_POSITION || - linepos < prep_startpos || linepos >= prep_endpos)) { - if (matches_filters(pos, cline, line_len, chpos, linepos, &sp, &ep)) - continue; - } + /* + * If any filters are in effect, ignore non-matching lines. + */ + if (filter_infos != NULL && + ((search_type & SRCH_FIND_ALL) || + prep_startpos == NULL_POSITION || + linepos < prep_startpos || linepos >= prep_endpos)) { + if (matches_filters(pos, cline, line_len, chpos, linepos, &sp, &ep)) + continue; + } #endif - /* - * Test the next line to see if we have a match. - * We are successful if we either want a match and got one, - * or if we want a non-match and got one. - */ - if (prev_pattern(&search_info)) - { - line_match = match_pattern(info_compiled(&search_info), search_info.text, - cline, line_len, &sp, &ep, 0, search_type); - if (line_match) - { - /* - * Got a match. - */ - if (search_type & SRCH_FIND_ALL) - { + /* + * Test the next line to see if we have a match. + * We are successful if we either want a match and got one, + * or if we want a non-match and got one. + */ + if (prev_pattern(&search_info)) + { + line_match = match_pattern(info_compiled(&search_info), search_info.text, + cline, line_len, &sp, &ep, 0, search_type); + if (line_match) + { + /* + * Got a match. + */ + if (search_type & SRCH_FIND_ALL) + { #if HILITE_SEARCH - /* - * We are supposed to find all matches in the range. - * Just add the matches in this line to the - * hilite list and keep searching. - */ - hilite_line(linepos, cline, line_len, chpos, sp, ep, cvt_ops); + /* + * We are supposed to find all matches in the range. + * Just add the matches in this line to the + * hilite list and keep searching. + */ + hilite_line(linepos, cline, line_len, chpos, sp, ep, cvt_ops); #endif - } else if (--matches <= 0) - { - /* - * Found the one match we're looking for. - * Return it. - */ + } else if (--matches <= 0) + { + /* + * Found the one match we're looking for. + * Return it. + */ #if HILITE_SEARCH - if (hilite_search == OPT_ON) - { - /* - * Clear the hilite list and add only - * the matches in this one line. - */ - clr_hilite(); - hilite_line(linepos, cline, line_len, chpos, sp, ep, cvt_ops); - } + if (hilite_search == OPT_ON) + { + /* + * Clear the hilite list and add only + * the matches in this one line. + */ + clr_hilite(); + hilite_line(linepos, cline, line_len, chpos, sp, ep, cvt_ops); + } #endif - if (chopline) - { - /* - * If necessary, shift horizontally to make sure - * search match is fully visible. - */ - if (sp != NULL && ep != NULL) - { - int start_off = sp - cline; - int end_off = ep - cline; - int save_hshift = hshift; - int sshift; - int eshift; - hshift = 0; /* make get_seg count screen lines */ - chopline = FALSE; - sshift = swidth * get_seg(linepos, linepos + chpos[start_off]); - eshift = swidth * get_seg(linepos, linepos + chpos[end_off]); - chopline = TRUE; - if (sshift >= save_hshift && eshift <= save_hshift) - { - hshift = save_hshift; - } else - { - hshift = sshift; - screen_trashed = 1; - } - } - } else if (plastlinepos != NULL) - { - /* - * If the line is so long that the highlighted match - * won't be seen when the line is displayed normally - * (starting at the first char) because it fills the whole - * screen and more, scroll forward until the last char - * of the match appears in the last line on the screen. - * lastlinepos is the position of the first char of that last line. - */ - if (ep != NULL) - { - int end_off = ep - cline; - if (end_off >= swidth * sheight / 4) /* heuristic */ - *plastlinepos = get_lastlinepos(linepos, linepos + chpos[end_off], sheight); - } - } - free(cline); - free(chpos); - if (plinepos != NULL) - *plinepos = linepos; - return (0); - } - } - } - free(cline); - free(chpos); - } + if (chopline) + { + /* + * If necessary, shift horizontally to make sure + * search match is fully visible. + */ + if (sp != NULL && ep != NULL) + { + int start_off = sp - cline; + int end_off = ep - cline; + int save_hshift = hshift; + int sshift; + int eshift; + hshift = 0; /* make get_seg count screen lines */ + chopline = FALSE; + sshift = swidth * get_seg(linepos, linepos + chpos[start_off]); + eshift = swidth * get_seg(linepos, linepos + chpos[end_off]); + chopline = TRUE; + if (sshift >= save_hshift && eshift <= save_hshift) + { + hshift = save_hshift; + } else + { + hshift = sshift; + screen_trashed = 1; + } + } + } else if (plastlinepos != NULL) + { + /* + * If the line is so long that the highlighted match + * won't be seen when the line is displayed normally + * (starting at the first char) because it fills the whole + * screen and more, scroll forward until the last char + * of the match appears in the last line on the screen. + * lastlinepos is the position of the first char of that last line. + */ + if (ep != NULL) + { + int end_off = ep - cline; + if (end_off >= swidth * sheight / 4) /* heuristic */ + *plastlinepos = get_lastlinepos(linepos, linepos + chpos[end_off], sheight); + } + } + free(cline); + free(chpos); + if (plinepos != NULL) + *plinepos = linepos; + return (0); + } + } + } + free(cline); + free(chpos); + } } /* * search for a pattern in history. If found, compile that pattern. */ - static int -hist_pattern(search_type) - int search_type; + static int +hist_pattern(search_type) + int search_type; { #if CMD_HISTORY - char *pattern; + char *pattern; - set_mlist(ml_search, 0); - pattern = cmd_lastpattern(); - if (pattern == NULL) - return (0); + set_mlist(ml_search, 0); + pattern = cmd_lastpattern(); + if (pattern == NULL) + return (0); - if (set_pattern(&search_info, pattern, search_type, 1) < 0) - return (-1); + if (set_pattern(&search_info, pattern, search_type, 1) < 0) + return (-1); #if HILITE_SEARCH - if (hilite_search == OPT_ONPLUS && !hide_hilite) - hilite_screen(); + if (hilite_search == OPT_ONPLUS && !hide_hilite) + hilite_screen(); #endif - return (1); + return (1); #else /* CMD_HISTORY */ - return (0); + return (0); #endif /* CMD_HISTORY */ } /* - * Change the caseless-ness of searches. + * Change the caseless-ness of searches. * Updates the internal search state to reflect a change in the -i flag. */ - public void + public void chg_caseless(VOID_PARAM) { - if (!is_ucase_pattern) - /* - * Pattern did not have uppercase. - * Just set the search caselessness to the global caselessness. - */ - is_caseless = caseless; - else - { - /* - * Pattern did have uppercase. - * Regenerate the pattern using the new state. - */ - clear_pattern(&search_info); - (void) hist_pattern(search_info.search_type); - } + if (!is_ucase_pattern) + /* + * Pattern did not have uppercase. + * Just set the search caselessness to the global caselessness. + */ + is_caseless = caseless; + else + { + /* + * Pattern did have uppercase. + * Regenerate the pattern using the new state. + */ + clear_pattern(&search_info); + (void) hist_pattern(search_info.search_type); + } } /* - * Search for the n-th occurrence of a specified pattern, + * Search for the n-th occurrence of a specified pattern, * either forward or backward. * Return the number of matches not yet found in this file * (that is, n minus the number of matches found). * Return -1 if the search should be aborted. - * Caller may continue the search in another file + * Caller may continue the search in another file * if less than n matches are found in this file. */ - public int + public int search(search_type, pattern, n) - int search_type; - char *pattern; - int n; + int search_type; + char *pattern; + int n; { - POSITION pos; - POSITION opos; - POSITION lastlinepos = NULL_POSITION; - - if (pattern == NULL || *pattern == '\0') - { - /* - * A null pattern means use the previously compiled pattern. - */ - search_type |= SRCH_AFTER_TARGET; - if (!prev_pattern(&search_info)) - { - int r = hist_pattern(search_type); - if (r == 0) - error("No previous regular expression", NULL_PARG); - if (r <= 0) - return (-1); - } - if ((search_type & SRCH_NO_REGEX) != - (search_info.search_type & SRCH_NO_REGEX)) - { - error("Please re-enter search pattern", NULL_PARG); - return -1; - } + POSITION pos; + POSITION opos; + POSITION lastlinepos = NULL_POSITION; + + if (pattern == NULL || *pattern == '\0') + { + /* + * A null pattern means use the previously compiled pattern. + */ + search_type |= SRCH_AFTER_TARGET; + if (!prev_pattern(&search_info)) + { + int r = hist_pattern(search_type); + if (r == 0) + error("No previous regular expression", NULL_PARG); + if (r <= 0) + return (-1); + } + if ((search_type & SRCH_NO_REGEX) != + (search_info.search_type & SRCH_NO_REGEX)) + { + error("Please re-enter search pattern", NULL_PARG); + return -1; + } #if HILITE_SEARCH - if (hilite_search == OPT_ON || status_col) - { - /* - * Erase the highlights currently on screen. - * If the search fails, we'll redisplay them later. - */ - repaint_hilite(0); - } - if (hilite_search == OPT_ONPLUS && hide_hilite) - { - /* - * Highlight any matches currently on screen, - * before we actually start the search. - */ - hide_hilite = 0; - hilite_screen(); - } - hide_hilite = 0; + if (hilite_search == OPT_ON || status_col) + { + /* + * Erase the highlights currently on screen. + * If the search fails, we'll redisplay them later. + */ + repaint_hilite(0); + } + if (hilite_search == OPT_ONPLUS && hide_hilite) + { + /* + * Highlight any matches currently on screen, + * before we actually start the search. + */ + hide_hilite = 0; + hilite_screen(); + } + hide_hilite = 0; #endif - } else - { - /* - * Compile the pattern. - */ - int show_error = !(search_type & SRCH_INCR); - if (set_pattern(&search_info, pattern, search_type, show_error) < 0) - return (-1); + } else + { + /* + * Compile the pattern. + */ + int show_error = !(search_type & SRCH_INCR); + if (set_pattern(&search_info, pattern, search_type, show_error) < 0) + return (-1); #if HILITE_SEARCH - if (hilite_search || status_col) - { - /* - * Erase the highlights currently on screen. - * Also permanently delete them from the hilite list. - */ - repaint_hilite(0); - hide_hilite = 0; - clr_hilite(); - } - if (hilite_search == OPT_ONPLUS || status_col) - { - /* - * Highlight any matches currently on screen, - * before we actually start the search. - */ - hilite_screen(); - } + if (hilite_search || status_col) + { + /* + * Erase the highlights currently on screen. + * Also permanently delete them from the hilite list. + */ + repaint_hilite(0); + hide_hilite = 0; + clr_hilite(); + } + if (hilite_search == OPT_ONPLUS || status_col) + { + /* + * Highlight any matches currently on screen, + * before we actually start the search. + */ + hilite_screen(); + } #endif - } - - /* - * Figure out where to start the search. - */ - pos = search_pos(search_type); - opos = position(sindex_from_sline(jump_sline)); - if (pos == NULL_POSITION) - { - /* - * Can't find anyplace to start searching from. - */ - if (search_type & SRCH_PAST_EOF) - return (n); + } + + /* + * Figure out where to start the search. + */ + pos = search_pos(search_type); + opos = position(sindex_from_sline(jump_sline)); + if (pos == NULL_POSITION) + { + /* + * Can't find anyplace to start searching from. + */ + if (search_type & SRCH_PAST_EOF) + return (n); #if HILITE_SEARCH - if (hilite_search == OPT_ON || status_col) - repaint_hilite(1); + if (hilite_search == OPT_ON || status_col) + repaint_hilite(1); #endif - error("Nothing to search", NULL_PARG); - return (-1); - } - - n = search_range(pos, NULL_POSITION, search_type, n, -1, - &pos, (POSITION*)NULL, &lastlinepos); - if (n != 0) - { - /* - * Search was unsuccessful. - */ + error("Nothing to search", NULL_PARG); + return (-1); + } + + n = search_range(pos, NULL_POSITION, search_type, n, -1, + &pos, (POSITION*)NULL, &lastlinepos); + if (n != 0) + { + /* + * Search was unsuccessful. + */ #if HILITE_SEARCH - if ((hilite_search == OPT_ON || status_col) && n > 0) - /* - * Redisplay old hilites. - */ - repaint_hilite(1); + if ((hilite_search == OPT_ON || status_col) && n > 0) + /* + * Redisplay old hilites. + */ + repaint_hilite(1); #endif - return (n); - } - - if (!(search_type & SRCH_NO_MOVE)) - { - /* - * Go to the matching line. - */ - if (lastlinepos != NULL_POSITION) - jump_loc(lastlinepos, BOTTOM); - else if (pos != opos) - jump_loc(pos, jump_sline); - } + return (n); + } + + if (!(search_type & SRCH_NO_MOVE)) + { + /* + * Go to the matching line. + */ + if (lastlinepos != NULL_POSITION) + jump_loc(lastlinepos, BOTTOM); + else if (pos != opos) + jump_loc(pos, jump_sline); + } #if HILITE_SEARCH - if (hilite_search == OPT_ON || status_col) - /* - * Display new hilites in the matching line. - */ - repaint_hilite(1); + if (hilite_search == OPT_ON || status_col) + /* + * Display new hilites in the matching line. + */ + repaint_hilite(1); #endif - return (0); + return (0); } #if HILITE_SEARCH @@ -1714,18 +1714,18 @@ search(search_type, pattern, n) * If prep_endpos == NULL_POSITION, the prep region extends to EOF. * prep_hilite asks that the range (spos,epos) be covered by the prep region. */ - public void + public void prep_hilite(spos, epos, maxlines) - POSITION spos; - POSITION epos; - int maxlines; + POSITION spos; + POSITION epos; + int maxlines; { - POSITION nprep_startpos = prep_startpos; - POSITION nprep_endpos = prep_endpos; - POSITION new_epos; - POSITION max_epos; - int result; - int i; + POSITION nprep_startpos = prep_startpos; + POSITION nprep_endpos = prep_endpos; + POSITION new_epos; + POSITION max_epos; + int result; + int i; /* * Search beyond where we're asked to search, so the prep region covers @@ -1733,217 +1733,216 @@ prep_hilite(spos, epos, maxlines) */ #define SEARCH_MORE (3*size_linebuf) - if (!prev_pattern(&search_info) && !is_filtering()) - return; - - /* - * Make sure our prep region always starts at the beginning of - * a line. (search_range takes care of the end boundary below.) - */ - spos = back_raw_line(spos+1, (char **)NULL, (int *)NULL); - - /* - * If we're limited to a max number of lines, figure out the - * file position we should stop at. - */ - if (maxlines < 0) - max_epos = NULL_POSITION; - else - { - max_epos = spos; - for (i = 0; i < maxlines; i++) - max_epos = forw_raw_line(max_epos, (char **)NULL, (int *)NULL); - } - - /* - * Find two ranges: - * The range that we need to search (spos,epos); and the range that - * the "prep" region will then cover (nprep_startpos,nprep_endpos). - */ - - if (prep_startpos == NULL_POSITION || - (epos != NULL_POSITION && epos < prep_startpos) || - spos > prep_endpos) - { - /* - * New range is not contiguous with old prep region. - * Discard the old prep region and start a new one. - */ - clr_hilite(); - clr_filter(); - if (epos != NULL_POSITION) - epos += SEARCH_MORE; - nprep_startpos = spos; - } else - { - /* - * New range partially or completely overlaps old prep region. - */ - if (epos == NULL_POSITION) - { - /* - * New range goes to end of file. - */ - ; - } else if (epos > prep_endpos) - { - /* - * New range ends after old prep region. - * Extend prep region to end at end of new range. - */ - epos += SEARCH_MORE; - } else /* (epos <= prep_endpos) */ - { - /* - * New range ends within old prep region. - * Truncate search to end at start of old prep region. - */ - epos = prep_startpos; - } - - if (spos < prep_startpos) - { - /* - * New range starts before old prep region. - * Extend old prep region backwards to start at - * start of new range. - */ - if (spos < SEARCH_MORE) - spos = 0; - else - spos -= SEARCH_MORE; - nprep_startpos = spos; - } else /* (spos >= prep_startpos) */ - { - /* - * New range starts within or after old prep region. - * Trim search to start at end of old prep region. - */ - spos = prep_endpos; - } - } - - if (epos != NULL_POSITION && max_epos != NULL_POSITION && - epos > max_epos) - /* - * Don't go past the max position we're allowed. - */ - epos = max_epos; - - if (epos == NULL_POSITION || epos > spos) - { - int search_type = SRCH_FORW | SRCH_FIND_ALL; - search_type |= (search_info.search_type & SRCH_NO_REGEX); - for (;;) - { - result = search_range(spos, epos, search_type, 0, maxlines, (POSITION*)NULL, &new_epos, (POSITION*)NULL); - if (result < 0) - return; - if (prep_endpos == NULL_POSITION || new_epos > prep_endpos) - nprep_endpos = new_epos; - - /* - * Check both ends of the resulting prep region to - * make sure they're not filtered. If they are, - * keep going at least one more line until we find - * something that isn't filtered, or hit the end. - */ - if (prep_endpos == NULL_POSITION || nprep_endpos > prep_endpos) - { - if (new_epos >= nprep_endpos && is_filtered(new_epos-1)) - { - spos = nprep_endpos; - epos = forw_raw_line(nprep_endpos, (char **)NULL, (int *)NULL); - if (epos == NULL_POSITION) - break; - maxlines = 1; - continue; - } - } - - if (prep_startpos == NULL_POSITION || nprep_startpos < prep_startpos) - { - if (nprep_startpos > 0 && is_filtered(nprep_startpos)) - { - epos = nprep_startpos; - spos = back_raw_line(nprep_startpos, (char **)NULL, (int *)NULL); - if (spos == NULL_POSITION) - break; - nprep_startpos = spos; - maxlines = 1; - continue; - } - } - break; - } - } - prep_startpos = nprep_startpos; - prep_endpos = nprep_endpos; + if (!prev_pattern(&search_info) && !is_filtering()) + return; + + /* + * Make sure our prep region always starts at the beginning of + * a line. (search_range takes care of the end boundary below.) + */ + spos = back_raw_line(spos+1, (char **)NULL, (int *)NULL); + + /* + * If we're limited to a max number of lines, figure out the + * file position we should stop at. + */ + if (maxlines < 0) + max_epos = NULL_POSITION; + else + { + max_epos = spos; + for (i = 0; i < maxlines; i++) + max_epos = forw_raw_line(max_epos, (char **)NULL, (int *)NULL); + } + + /* + * Find two ranges: + * The range that we need to search (spos,epos); and the range that + * the "prep" region will then cover (nprep_startpos,nprep_endpos). + */ + + if (prep_startpos == NULL_POSITION || + (epos != NULL_POSITION && epos < prep_startpos) || + spos > prep_endpos) + { + /* + * New range is not contiguous with old prep region. + * Discard the old prep region and start a new one. + */ + clr_hilite(); + clr_filter(); + if (epos != NULL_POSITION) + epos += SEARCH_MORE; + nprep_startpos = spos; + } else + { + /* + * New range partially or completely overlaps old prep region. + */ + if (epos == NULL_POSITION) + { + /* + * New range goes to end of file. + */ + ; + } else if (epos > prep_endpos) + { + /* + * New range ends after old prep region. + * Extend prep region to end at end of new range. + */ + epos += SEARCH_MORE; + } else /* (epos <= prep_endpos) */ + { + /* + * New range ends within old prep region. + * Truncate search to end at start of old prep region. + */ + epos = prep_startpos; + } + + if (spos < prep_startpos) + { + /* + * New range starts before old prep region. + * Extend old prep region backwards to start at + * start of new range. + */ + if (spos < SEARCH_MORE) + spos = 0; + else + spos -= SEARCH_MORE; + nprep_startpos = spos; + } else /* (spos >= prep_startpos) */ + { + /* + * New range starts within or after old prep region. + * Trim search to start at end of old prep region. + */ + spos = prep_endpos; + } + } + + if (epos != NULL_POSITION && max_epos != NULL_POSITION && + epos > max_epos) + /* + * Don't go past the max position we're allowed. + */ + epos = max_epos; + + if (epos == NULL_POSITION || epos > spos) + { + int search_type = SRCH_FORW | SRCH_FIND_ALL; + search_type |= (search_info.search_type & SRCH_NO_REGEX); + for (;;) + { + result = search_range(spos, epos, search_type, 0, maxlines, (POSITION*)NULL, &new_epos, (POSITION*)NULL); + if (result < 0) + return; + if (prep_endpos == NULL_POSITION || new_epos > prep_endpos) + nprep_endpos = new_epos; + + /* + * Check both ends of the resulting prep region to + * make sure they're not filtered. If they are, + * keep going at least one more line until we find + * something that isn't filtered, or hit the end. + */ + if (prep_endpos == NULL_POSITION || nprep_endpos > prep_endpos) + { + if (new_epos >= nprep_endpos && is_filtered(new_epos-1)) + { + spos = nprep_endpos; + epos = forw_raw_line(nprep_endpos, (char **)NULL, (int *)NULL); + if (epos == NULL_POSITION) + break; + maxlines = 1; + continue; + } + } + + if (prep_startpos == NULL_POSITION || nprep_startpos < prep_startpos) + { + if (nprep_startpos > 0 && is_filtered(nprep_startpos)) + { + epos = nprep_startpos; + spos = back_raw_line(nprep_startpos, (char **)NULL, (int *)NULL); + if (spos == NULL_POSITION) + break; + nprep_startpos = spos; + maxlines = 1; + continue; + } + } + break; + } + } + prep_startpos = nprep_startpos; + prep_endpos = nprep_endpos; } /* * Set the pattern to be used for line filtering. */ - public void + public void set_filter_pattern(pattern, search_type) - char *pattern; - int search_type; + char *pattern; + int search_type; { - struct pattern_info *filter; - - clr_filter(); - if (pattern == NULL || *pattern == '\0') - { - /* Clear and free all filters. */ - for (filter = filter_infos; filter != NULL; ) - { - struct pattern_info *next_filter = filter->next; - clear_pattern(filter); - free(filter); - filter = next_filter; - } - filter_infos = NULL; - } else - { - /* Create a new filter and add it to the filter_infos list. */ - filter = ecalloc(1, sizeof(struct pattern_info)); - init_pattern(filter); - set_pattern(filter, pattern, search_type, 1); - filter->next = filter_infos; - filter_infos = filter; - } - screen_trashed = 1; + struct pattern_info *filter; + + clr_filter(); + if (pattern == NULL || *pattern == '\0') + { + /* Clear and free all filters. */ + for (filter = filter_infos; filter != NULL; ) + { + struct pattern_info *next_filter = filter->next; + clear_pattern(filter); + free(filter); + filter = next_filter; + } + filter_infos = NULL; + } else + { + /* Create a new filter and add it to the filter_infos list. */ + filter = ecalloc(1, sizeof(struct pattern_info)); + init_pattern(filter); + set_pattern(filter, pattern, search_type, 1); + filter->next = filter_infos; + filter_infos = filter; + } + screen_trashed = 1; } /* * Is there a line filter in effect? */ - public int + public int is_filtering(VOID_PARAM) { - if (ch_getflags() & CH_HELPFILE) - return (0); - return (filter_infos != NULL); + if (ch_getflags() & CH_HELPFILE) + return (0); + return (filter_infos != NULL); } #endif #if HAVE_V8_REGCOMP /* - * This function is called by the V8 regcomp to report + * This function is called by the V8 regcomp to report * errors in regular expressions. */ public int reg_show_error = 1; - void -regerror(s) - char *s; + void +regerror(s) + char *s; { - PARG parg; + PARG parg; - if (!reg_show_error) - return; - parg.p_string = s; - error("%s", &parg); + if (!reg_show_error) + return; + parg.p_string = s; + error("%s", &parg); } #endif - diff --git a/signal.c b/signal.c index dd66683..3b44633 100644 --- a/signal.c +++ b/signal.c @@ -40,31 +40,31 @@ extern long jump_sline_fraction; * Interrupt signal handler. */ #if MSDOS_COMPILER!=WIN32C - /* ARGSUSED*/ - static RETSIGTYPE + /* ARGSUSED*/ + static RETSIGTYPE u_interrupt(type) - int type; + int type; { - bell(); + bell(); #if OS2 - LSIGNAL(SIGINT, SIG_ACK); + LSIGNAL(SIGINT, SIG_ACK); #endif - LSIGNAL(SIGINT, u_interrupt); - sigs |= S_INTERRUPT; + LSIGNAL(SIGINT, u_interrupt); + sigs |= S_INTERRUPT; #if MSDOS_COMPILER==DJGPPC - /* - * If a keyboard has been hit, it must be Ctrl-C - * (as opposed to Ctrl-Break), so consume it. - * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.) - */ - if (kbhit()) - getkey(); + /* + * If a keyboard has been hit, it must be Ctrl-C + * (as opposed to Ctrl-Break), so consume it. + * (Otherwise, Less will beep when it sees Ctrl-C from keyboard.) + */ + if (kbhit()) + getkey(); #endif #if HILITE_SEARCH - set_filter_pattern(NULL, 0); + set_filter_pattern(NULL, 0); #endif - if (reading) - intread(); /* May longjmp */ + if (reading) + intread(); /* May longjmp */ } #endif @@ -72,15 +72,15 @@ u_interrupt(type) /* * "Stop" (^Z) signal handler. */ - /* ARGSUSED*/ - static RETSIGTYPE + /* ARGSUSED*/ + static RETSIGTYPE stop(type) - int type; + int type; { - LSIGNAL(SIGTSTP, stop); - sigs |= S_STOP; - if (reading) - intread(); + LSIGNAL(SIGTSTP, stop); + sigs |= S_STOP; + if (reading) + intread(); } #endif @@ -97,15 +97,15 @@ stop(type) /* * "Window" change handler */ - /* ARGSUSED*/ - public RETSIGTYPE + /* ARGSUSED*/ + public RETSIGTYPE winch(type) - int type; + int type; { - LSIGNAL(SIG_LESSWINDOW, winch); - sigs |= S_WINCH; - if (reading) - intread(); + LSIGNAL(SIG_LESSWINDOW, winch); + sigs |= S_WINCH; + if (reading) + intread(); } #endif @@ -116,159 +116,159 @@ winch(type) #define WIN32_LEAN_AND_MEAN #include - static BOOL WINAPI + static BOOL WINAPI wbreak_handler(dwCtrlType) - DWORD dwCtrlType; + DWORD dwCtrlType; { - switch (dwCtrlType) - { - case CTRL_C_EVENT: - case CTRL_BREAK_EVENT: - sigs |= S_INTERRUPT; + switch (dwCtrlType) + { + case CTRL_C_EVENT: + case CTRL_BREAK_EVENT: + sigs |= S_INTERRUPT; #if HILITE_SEARCH - set_filter_pattern(NULL, 0); + set_filter_pattern(NULL, 0); #endif - return (TRUE); - default: - break; - } - return (FALSE); + return (TRUE); + default: + break; + } + return (FALSE); } #endif - static RETSIGTYPE + static RETSIGTYPE terminate(type) - int type; + int type; { - quit(15); + quit(15); } /* * Set up the signal handlers. */ - public void + public void init_signals(on) - int on; + int on; { - if (on) - { - /* - * Set signal handlers. - */ + if (on) + { + /* + * Set signal handlers. + */ #if MSDOS_COMPILER==WIN32C - SetConsoleCtrlHandler(wbreak_handler, TRUE); + SetConsoleCtrlHandler(wbreak_handler, TRUE); #else - (void) LSIGNAL(SIGINT, u_interrupt); + (void) LSIGNAL(SIGINT, u_interrupt); #endif #ifdef SIGTSTP - (void) LSIGNAL(SIGTSTP, secure ? SIG_IGN : stop); + (void) LSIGNAL(SIGTSTP, secure ? SIG_IGN : stop); #endif #ifdef SIGWINCH - (void) LSIGNAL(SIGWINCH, winch); + (void) LSIGNAL(SIGWINCH, winch); #endif #ifdef SIGWIND - (void) LSIGNAL(SIGWIND, winch); + (void) LSIGNAL(SIGWIND, winch); #endif #ifdef SIGQUIT - (void) LSIGNAL(SIGQUIT, SIG_IGN); + (void) LSIGNAL(SIGQUIT, SIG_IGN); #endif #ifdef SIGTERM - (void) LSIGNAL(SIGTERM, terminate); + (void) LSIGNAL(SIGTERM, terminate); #endif - } else - { - /* - * Restore signals to defaults. - */ + } else + { + /* + * Restore signals to defaults. + */ #if MSDOS_COMPILER==WIN32C - SetConsoleCtrlHandler(wbreak_handler, FALSE); + SetConsoleCtrlHandler(wbreak_handler, FALSE); #else - (void) LSIGNAL(SIGINT, SIG_DFL); + (void) LSIGNAL(SIGINT, SIG_DFL); #endif #ifdef SIGTSTP - (void) LSIGNAL(SIGTSTP, SIG_DFL); + (void) LSIGNAL(SIGTSTP, SIG_DFL); #endif #ifdef SIGWINCH - (void) LSIGNAL(SIGWINCH, SIG_IGN); + (void) LSIGNAL(SIGWINCH, SIG_IGN); #endif #ifdef SIGWIND - (void) LSIGNAL(SIGWIND, SIG_IGN); + (void) LSIGNAL(SIGWIND, SIG_IGN); #endif #ifdef SIGQUIT - (void) LSIGNAL(SIGQUIT, SIG_DFL); + (void) LSIGNAL(SIGQUIT, SIG_DFL); #endif #ifdef SIGTERM - (void) LSIGNAL(SIGTERM, SIG_DFL); + (void) LSIGNAL(SIGTERM, SIG_DFL); #endif - } + } } /* * Process any signals we have received. * A received signal cause a bit to be set in "sigs". */ - public void + public void psignals(VOID_PARAM) { - int tsignals; + int tsignals; - if ((tsignals = sigs) == 0) - return; - sigs = 0; + if ((tsignals = sigs) == 0) + return; + sigs = 0; #ifdef SIGTSTP - if (tsignals & S_STOP) - { - /* - * Clean up the terminal. - */ + if (tsignals & S_STOP) + { + /* + * Clean up the terminal. + */ #ifdef SIGTTOU - LSIGNAL(SIGTTOU, SIG_IGN); + LSIGNAL(SIGTTOU, SIG_IGN); #endif - clear_bot(); - deinit(); - flush(); - raw_mode(0); + clear_bot(); + deinit(); + flush(); + raw_mode(0); #ifdef SIGTTOU - LSIGNAL(SIGTTOU, SIG_DFL); + LSIGNAL(SIGTTOU, SIG_DFL); #endif - LSIGNAL(SIGTSTP, SIG_DFL); - kill(getpid(), SIGTSTP); - /* - * ... Bye bye. ... - * Hopefully we'll be back later and resume here... - * Reset the terminal and arrange to repaint the - * screen when we get back to the main command loop. - */ - LSIGNAL(SIGTSTP, stop); - raw_mode(1); - init(); - screen_trashed = 1; - tsignals |= S_WINCH; - } + LSIGNAL(SIGTSTP, SIG_DFL); + kill(getpid(), SIGTSTP); + /* + * ... Bye bye. ... + * Hopefully we'll be back later and resume here... + * Reset the terminal and arrange to repaint the + * screen when we get back to the main command loop. + */ + LSIGNAL(SIGTSTP, stop); + raw_mode(1); + init(); + screen_trashed = 1; + tsignals |= S_WINCH; + } #endif #ifdef S_WINCH - if (tsignals & S_WINCH) - { - int old_width, old_height; - /* - * Re-execute scrsize() to read the new window size. - */ - old_width = sc_width; - old_height = sc_height; - get_term(); - if (sc_width != old_width || sc_height != old_height) - { - wscroll = (sc_height + 1) / 2; - calc_jump_sline(); - calc_shift_count(); - } - screen_trashed = 1; - } + if (tsignals & S_WINCH) + { + int old_width, old_height; + /* + * Re-execute scrsize() to read the new window size. + */ + old_width = sc_width; + old_height = sc_height; + get_term(); + if (sc_width != old_width || sc_height != old_height) + { + wscroll = (sc_height + 1) / 2; + calc_jump_sline(); + calc_shift_count(); + } + screen_trashed = 1; + } #endif - if (tsignals & S_INTERRUPT) - { - if (quit_on_intr) - quit(QUIT_INTERRUPT); - } + if (tsignals & S_INTERRUPT) + { + if (quit_on_intr) + quit(QUIT_INTERRUPT); + } } diff --git a/tags.c b/tags.c index d449c03..6466743 100644 --- a/tags.c +++ b/tags.c @@ -25,23 +25,23 @@ extern int sigs; extern int ctldisp; enum tag_result { - TAG_FOUND, - TAG_NOFILE, - TAG_NOTAG, - TAG_NOTYPE, - TAG_INTR + TAG_FOUND, + TAG_NOFILE, + TAG_NOTAG, + TAG_NOTYPE, + TAG_INTR }; /* * Tag type */ enum { - T_CTAGS, /* 'tags': standard and extended format (ctags) */ - T_CTAGS_X, /* stdin: cross reference format (ctags) */ - T_GTAGS, /* 'GTAGS': function definition (global) */ - T_GRTAGS, /* 'GRTAGS': function reference (global) */ - T_GSYMS, /* 'GSYMS': other symbols (global) */ - T_GPATH /* 'GPATH': path name (global) */ + T_CTAGS, /* 'tags': standard and extended format (ctags) */ + T_CTAGS_X, /* stdin: cross reference format (ctags) */ + T_GTAGS, /* 'GTAGS': function definition (global) */ + T_GRTAGS, /* 'GRTAGS': function reference (global) */ + T_GSYMS, /* 'GSYMS': other symbols (global) */ + T_GPATH /* 'GPATH': path name (global) */ }; static enum tag_result findctag LESSPARAMS((char *tag)); @@ -61,107 +61,107 @@ static int getentry LESSPARAMS((char *buf, char **tag, char **file, char **line) * or line number (in which case pattern is NULL). */ struct taglist { - struct tag *tl_first; - struct tag *tl_last; + struct tag *tl_first; + struct tag *tl_last; }; struct tag { - struct tag *next, *prev; /* List links */ - char *tag_file; /* Source file containing the tag */ - LINENUM tag_linenum; /* Appropriate line number in source file */ - char *tag_pattern; /* Pattern used to find the tag */ - char tag_endline; /* True if the pattern includes '$' */ + struct tag *next, *prev; /* List links */ + char *tag_file; /* Source file containing the tag */ + LINENUM tag_linenum; /* Appropriate line number in source file */ + char *tag_pattern; /* Pattern used to find the tag */ + char tag_endline; /* True if the pattern includes '$' */ }; #define TAG_END ((struct tag *) &taglist) static struct taglist taglist = { TAG_END, TAG_END }; static struct tag *curtag; #define TAG_INS(tp) \ - (tp)->next = TAG_END; \ - (tp)->prev = taglist.tl_last; \ - taglist.tl_last->next = (tp); \ - taglist.tl_last = (tp); + (tp)->next = TAG_END; \ + (tp)->prev = taglist.tl_last; \ + taglist.tl_last->next = (tp); \ + taglist.tl_last = (tp); #define TAG_RM(tp) \ - (tp)->next->prev = (tp)->prev; \ - (tp)->prev->next = (tp)->next; + (tp)->next->prev = (tp)->prev; \ + (tp)->prev->next = (tp)->next; /* * Delete tag structures. */ - public void + public void cleantags(VOID_PARAM) { - struct tag *tp; - - /* - * Delete any existing tag list. - * {{ Ideally, we wouldn't do this until after we know that we - * can load some other tag information. }} - */ - while ((tp = taglist.tl_first) != TAG_END) - { - TAG_RM(tp); - free(tp->tag_file); - free(tp->tag_pattern); - free(tp); - } - curtag = NULL; - total = curseq = 0; + struct tag *tp; + + /* + * Delete any existing tag list. + * {{ Ideally, we wouldn't do this until after we know that we + * can load some other tag information. }} + */ + while ((tp = taglist.tl_first) != TAG_END) + { + TAG_RM(tp); + free(tp->tag_file); + free(tp->tag_pattern); + free(tp); + } + curtag = NULL; + total = curseq = 0; } /* * Create a new tag entry. */ - static struct tag * + static struct tag * maketagent(name, file, linenum, pattern, endline) - char *name; - char *file; - LINENUM linenum; - char *pattern; - int endline; + char *name; + char *file; + LINENUM linenum; + char *pattern; + int endline; { - struct tag *tp; - - tp = (struct tag *) ecalloc(sizeof(struct tag), 1); - tp->tag_file = (char *) ecalloc(strlen(file) + 1, sizeof(char)); - strcpy(tp->tag_file, file); - tp->tag_linenum = linenum; - tp->tag_endline = endline; - if (pattern == NULL) - tp->tag_pattern = NULL; - else - { - tp->tag_pattern = (char *) ecalloc(strlen(pattern) + 1, sizeof(char)); - strcpy(tp->tag_pattern, pattern); - } - return (tp); + struct tag *tp; + + tp = (struct tag *) ecalloc(sizeof(struct tag), 1); + tp->tag_file = (char *) ecalloc(strlen(file) + 1, sizeof(char)); + strcpy(tp->tag_file, file); + tp->tag_linenum = linenum; + tp->tag_endline = endline; + if (pattern == NULL) + tp->tag_pattern = NULL; + else + { + tp->tag_pattern = (char *) ecalloc(strlen(pattern) + 1, sizeof(char)); + strcpy(tp->tag_pattern, pattern); + } + return (tp); } /* * Get tag mode. */ - public int + public int gettagtype(VOID_PARAM) { - int f; - - if (strcmp(tags, "GTAGS") == 0) - return T_GTAGS; - if (strcmp(tags, "GRTAGS") == 0) - return T_GRTAGS; - if (strcmp(tags, "GSYMS") == 0) - return T_GSYMS; - if (strcmp(tags, "GPATH") == 0) - return T_GPATH; - if (strcmp(tags, "-") == 0) - return T_CTAGS_X; - f = open(tags, OPEN_READ); - if (f >= 0) - { - close(f); - return T_CTAGS; - } - return T_GTAGS; + int f; + + if (strcmp(tags, "GTAGS") == 0) + return T_GTAGS; + if (strcmp(tags, "GRTAGS") == 0) + return T_GRTAGS; + if (strcmp(tags, "GSYMS") == 0) + return T_GSYMS; + if (strcmp(tags, "GPATH") == 0) + return T_GPATH; + if (strcmp(tags, "-") == 0) + return T_CTAGS_X; + f = open(tags, OPEN_READ); + if (f >= 0) + { + close(f); + return T_CTAGS; + } + return T_GTAGS; } /* @@ -171,92 +171,92 @@ gettagtype(VOID_PARAM) * and "tagpattern" to the search pattern which should be used * to find the tag. */ - public void + public void findtag(tag) - char *tag; + char *tag; { - int type = gettagtype(); - enum tag_result result; - - if (type == T_CTAGS) - result = findctag(tag); - else - result = findgtag(tag, type); - switch (result) - { - case TAG_FOUND: - case TAG_INTR: - break; - case TAG_NOFILE: - error("No tags file", NULL_PARG); - break; - case TAG_NOTAG: - error("No such tag in tags file", NULL_PARG); - break; - case TAG_NOTYPE: - error("unknown tag type", NULL_PARG); - break; - } + int type = gettagtype(); + enum tag_result result; + + if (type == T_CTAGS) + result = findctag(tag); + else + result = findgtag(tag, type); + switch (result) + { + case TAG_FOUND: + case TAG_INTR: + break; + case TAG_NOFILE: + error("No tags file", NULL_PARG); + break; + case TAG_NOTAG: + error("No such tag in tags file", NULL_PARG); + break; + case TAG_NOTYPE: + error("unknown tag type", NULL_PARG); + break; + } } /* * Search for a tag. */ - public POSITION + public POSITION tagsearch(VOID_PARAM) { - if (curtag == NULL) - return (NULL_POSITION); /* No gtags loaded! */ - if (curtag->tag_linenum != 0) - return gtagsearch(); - else - return ctagsearch(); + if (curtag == NULL) + return (NULL_POSITION); /* No gtags loaded! */ + if (curtag->tag_linenum != 0) + return gtagsearch(); + else + return ctagsearch(); } /* * Go to the next tag. */ - public char * + public char * nexttag(n) - int n; + int n; { - char *tagfile = (char *) NULL; + char *tagfile = (char *) NULL; - while (n-- > 0) - tagfile = nextgtag(); - return tagfile; + while (n-- > 0) + tagfile = nextgtag(); + return tagfile; } /* * Go to the previous tag. */ - public char * + public char * prevtag(n) - int n; + int n; { - char *tagfile = (char *) NULL; + char *tagfile = (char *) NULL; - while (n-- > 0) - tagfile = prevgtag(); - return tagfile; + while (n-- > 0) + tagfile = prevgtag(); + return tagfile; } /* * Return the total number of tags. */ - public int + public int ntags(VOID_PARAM) { - return total; + return total; } /* * Return the sequence number of current tag. */ - public int + public int curr_tag(VOID_PARAM) { - return curseq; + return curseq; } /***************************************************************************** @@ -267,144 +267,144 @@ curr_tag(VOID_PARAM) * Find tags in the "tags" file. * Sets curtag to the first tag entry. */ - static enum tag_result + static enum tag_result findctag(tag) - char *tag; + char *tag; { - char *p; - FILE *f; - int taglen; - LINENUM taglinenum; - char *tagfile; - char *tagpattern; - int tagendline; - int search_char; - int err; - char tline[TAGLINE_SIZE]; - struct tag *tp; - - p = shell_unquote(tags); - f = fopen(p, "r"); - free(p); - if (f == NULL) - return TAG_NOFILE; - - cleantags(); - total = 0; - taglen = (int) strlen(tag); - - /* - * Search the tags file for the desired tag. - */ - while (fgets(tline, sizeof(tline), f) != NULL) - { - if (tline[0] == '!') - /* Skip header of extended format. */ - continue; - if (strncmp(tag, tline, taglen) != 0 || !WHITESP(tline[taglen])) - continue; - - /* - * Found it. - * The line contains the tag, the filename and the - * location in the file, separated by white space. - * The location is either a decimal line number, - * or a search pattern surrounded by a pair of delimiters. - * Parse the line and extract these parts. - */ - tagpattern = NULL; - - /* - * Skip over the whitespace after the tag name. - */ - p = skipsp(tline+taglen); - if (*p == '\0') - /* File name is missing! */ - continue; - - /* - * Save the file name. - * Skip over the whitespace after the file name. - */ - tagfile = p; - while (!WHITESP(*p) && *p != '\0') - p++; - *p++ = '\0'; - p = skipsp(p); - if (*p == '\0') - /* Pattern is missing! */ - continue; - - /* - * First see if it is a line number. - */ - tagendline = 0; - taglinenum = getnum(&p, 0, &err); - if (err) - { - /* - * No, it must be a pattern. - * Delete the initial "^" (if present) and - * the final "$" from the pattern. - * Delete any backslash in the pattern. - */ - taglinenum = 0; - search_char = *p++; - if (*p == '^') - p++; - tagpattern = p; - while (*p != search_char && *p != '\0') - { - if (*p == '\\') - p++; - p++; - } - tagendline = (p[-1] == '$'); - if (tagendline) - p--; - *p = '\0'; - } - tp = maketagent(tag, tagfile, taglinenum, tagpattern, tagendline); - TAG_INS(tp); - total++; - } - fclose(f); - if (total == 0) - return TAG_NOTAG; - curtag = taglist.tl_first; - curseq = 1; - return TAG_FOUND; + char *p; + FILE *f; + int taglen; + LINENUM taglinenum; + char *tagfile; + char *tagpattern; + int tagendline; + int search_char; + int err; + char tline[TAGLINE_SIZE]; + struct tag *tp; + + p = shell_unquote(tags); + f = fopen(p, "r"); + free(p); + if (f == NULL) + return TAG_NOFILE; + + cleantags(); + total = 0; + taglen = (int) strlen(tag); + + /* + * Search the tags file for the desired tag. + */ + while (fgets(tline, sizeof(tline), f) != NULL) + { + if (tline[0] == '!') + /* Skip header of extended format. */ + continue; + if (strncmp(tag, tline, taglen) != 0 || !WHITESP(tline[taglen])) + continue; + + /* + * Found it. + * The line contains the tag, the filename and the + * location in the file, separated by white space. + * The location is either a decimal line number, + * or a search pattern surrounded by a pair of delimiters. + * Parse the line and extract these parts. + */ + tagpattern = NULL; + + /* + * Skip over the whitespace after the tag name. + */ + p = skipsp(tline+taglen); + if (*p == '\0') + /* File name is missing! */ + continue; + + /* + * Save the file name. + * Skip over the whitespace after the file name. + */ + tagfile = p; + while (!WHITESP(*p) && *p != '\0') + p++; + *p++ = '\0'; + p = skipsp(p); + if (*p == '\0') + /* Pattern is missing! */ + continue; + + /* + * First see if it is a line number. + */ + tagendline = 0; + taglinenum = getnum(&p, 0, &err); + if (err) + { + /* + * No, it must be a pattern. + * Delete the initial "^" (if present) and + * the final "$" from the pattern. + * Delete any backslash in the pattern. + */ + taglinenum = 0; + search_char = *p++; + if (*p == '^') + p++; + tagpattern = p; + while (*p != search_char && *p != '\0') + { + if (*p == '\\') + p++; + p++; + } + tagendline = (p[-1] == '$'); + if (tagendline) + p--; + *p = '\0'; + } + tp = maketagent(tag, tagfile, taglinenum, tagpattern, tagendline); + TAG_INS(tp); + total++; + } + fclose(f); + if (total == 0) + return TAG_NOTAG; + curtag = taglist.tl_first; + curseq = 1; + return TAG_FOUND; } /* * Edit current tagged file. */ - public int + public int edit_tagfile(VOID_PARAM) { - if (curtag == NULL) - return (1); - return (edit(curtag->tag_file)); + if (curtag == NULL) + return (1); + return (edit(curtag->tag_file)); } - static int + static int curtag_match(char const *line, POSITION linepos) { - /* - * Test the line to see if we have a match. - * Use strncmp because the pattern may be - * truncated (in the tags file) if it is too long. - * If tagendline is set, make sure we match all - * the way to end of line (no extra chars after the match). - */ - int len = (int) strlen(curtag->tag_pattern); - if (strncmp(curtag->tag_pattern, line, len) == 0 && - (!curtag->tag_endline || line[len] == '\0' || line[len] == '\r')) - { - curtag->tag_linenum = find_linenum(linepos); - return 1; - } - return 0; + /* + * Test the line to see if we have a match. + * Use strncmp because the pattern may be + * truncated (in the tags file) if it is too long. + * If tagendline is set, make sure we match all + * the way to end of line (no extra chars after the match). + */ + int len = (int) strlen(curtag->tag_pattern); + if (strncmp(curtag->tag_pattern, line, len) == 0 && + (!curtag->tag_endline || line[len] == '\0' || line[len] == '\r')) + { + curtag->tag_linenum = find_linenum(linepos); + return 1; + } + return 0; } /* @@ -413,75 +413,75 @@ curtag_match(char const *line, POSITION linepos) * We don't use search() for several reasons: * - We don't want to blow away any search string we may have saved. * - The various regular-expression functions (from different systems: - * regcmp vs. re_comp) behave differently in the presence of + * regcmp vs. re_comp) behave differently in the presence of * parentheses (which are almost always found in a tag). */ - static POSITION + static POSITION ctagsearch(VOID_PARAM) { - POSITION pos, linepos; - LINENUM linenum; - int line_len; - char *line; - int found; - - pos = ch_zero(); - linenum = find_linenum(pos); - - for (found = 0; !found;) - { - /* - * Get lines until we find a matching one or - * until we hit end-of-file. - */ - if (ABORT_SIGS()) - return (NULL_POSITION); - - /* - * Read the next line, and save the - * starting position of that line in linepos. - */ - linepos = pos; - pos = forw_raw_line(pos, &line, &line_len); - if (linenum != 0) - linenum++; - - if (pos == NULL_POSITION) - { - /* - * We hit EOF without a match. - */ - error("Tag not found", NULL_PARG); - return (NULL_POSITION); - } - - /* - * If we're using line numbers, we might as well - * remember the information we have now (the position - * and line number of the current line). - */ - if (linenums) - add_lnum(linenum, pos); - - if (ctldisp != OPT_ONPLUS) - { - if (curtag_match(line, linepos)) - found = 1; - } else - { - int cvt_ops = CVT_ANSI; - int cvt_len = cvt_length(line_len, cvt_ops); - int *chpos = cvt_alloc_chpos(cvt_len); - char *cline = (char *) ecalloc(1, cvt_len); - cvt_text(cline, line, chpos, &line_len, cvt_ops); - if (curtag_match(cline, linepos)) - found = 1; - free(chpos); - free(cline); - } - } - - return (linepos); + POSITION pos, linepos; + LINENUM linenum; + int line_len; + char *line; + int found; + + pos = ch_zero(); + linenum = find_linenum(pos); + + for (found = 0; !found;) + { + /* + * Get lines until we find a matching one or + * until we hit end-of-file. + */ + if (ABORT_SIGS()) + return (NULL_POSITION); + + /* + * Read the next line, and save the + * starting position of that line in linepos. + */ + linepos = pos; + pos = forw_raw_line(pos, &line, &line_len); + if (linenum != 0) + linenum++; + + if (pos == NULL_POSITION) + { + /* + * We hit EOF without a match. + */ + error("Tag not found", NULL_PARG); + return (NULL_POSITION); + } + + /* + * If we're using line numbers, we might as well + * remember the information we have now (the position + * and line number of the current line). + */ + if (linenums) + add_lnum(linenum, pos); + + if (ctldisp != OPT_ONPLUS) + { + if (curtag_match(line, linepos)) + found = 1; + } else + { + int cvt_ops = CVT_ANSI; + int cvt_len = cvt_length(line_len, cvt_ops); + int *chpos = cvt_alloc_chpos(cvt_len); + char *cline = (char *) ecalloc(1, cvt_len); + cvt_text(cline, line, chpos, &line_len, cvt_ops); + if (curtag_match(cline, linepos)) + found = 1; + free(chpos); + free(cline); + } + } + + return (linepos); } /******************************************************************************* @@ -495,132 +495,132 @@ ctagsearch(VOID_PARAM) * for future use by gtagsearch(). * Sets curtag to the first tag entry. */ - static enum tag_result + static enum tag_result findgtag(tag, type) - char *tag; /* tag to load */ - int type; /* tags type */ + char *tag; /* tag to load */ + int type; /* tags type */ { - char buf[256]; - FILE *fp; - struct tag *tp; - - if (type != T_CTAGS_X && tag == NULL) - return TAG_NOFILE; - - cleantags(); - total = 0; - - /* - * If type == T_CTAGS_X then read ctags's -x format from stdin - * else execute global(1) and read from it. - */ - if (type == T_CTAGS_X) - { - fp = stdin; - /* Set tag default because we cannot read stdin again. */ - tags = ztags; - } else - { + char buf[256]; + FILE *fp; + struct tag *tp; + + if (type != T_CTAGS_X && tag == NULL) + return TAG_NOFILE; + + cleantags(); + total = 0; + + /* + * If type == T_CTAGS_X then read ctags's -x format from stdin + * else execute global(1) and read from it. + */ + if (type == T_CTAGS_X) + { + fp = stdin; + /* Set tag default because we cannot read stdin again. */ + tags = ztags; + } else + { #if !HAVE_POPEN - return TAG_NOFILE; + return TAG_NOFILE; #else - char *command; - char *flag; - char *qtag; - char *cmd = lgetenv("LESSGLOBALTAGS"); - - if (isnullenv(cmd)) - return TAG_NOFILE; - /* Get suitable flag value for global(1). */ - switch (type) - { - case T_GTAGS: - flag = "" ; - break; - case T_GRTAGS: - flag = "r"; - break; - case T_GSYMS: - flag = "s"; - break; - case T_GPATH: - flag = "P"; - break; - default: - return TAG_NOTYPE; - } - - /* Get our data from global(1). */ - qtag = shell_quote(tag); - if (qtag == NULL) - qtag = tag; - command = (char *) ecalloc(strlen(cmd) + strlen(flag) + - strlen(qtag) + 5, sizeof(char)); - sprintf(command, "%s -x%s %s", cmd, flag, qtag); - if (qtag != tag) - free(qtag); - fp = popen(command, "r"); - free(command); + char *command; + char *flag; + char *qtag; + char *cmd = lgetenv("LESSGLOBALTAGS"); + + if (isnullenv(cmd)) + return TAG_NOFILE; + /* Get suitable flag value for global(1). */ + switch (type) + { + case T_GTAGS: + flag = "" ; + break; + case T_GRTAGS: + flag = "r"; + break; + case T_GSYMS: + flag = "s"; + break; + case T_GPATH: + flag = "P"; + break; + default: + return TAG_NOTYPE; + } + + /* Get our data from global(1). */ + qtag = shell_quote(tag); + if (qtag == NULL) + qtag = tag; + command = (char *) ecalloc(strlen(cmd) + strlen(flag) + + strlen(qtag) + 5, sizeof(char)); + sprintf(command, "%s -x%s %s", cmd, flag, qtag); + if (qtag != tag) + free(qtag); + fp = popen(command, "r"); + free(command); #endif - } - if (fp != NULL) - { - while (fgets(buf, sizeof(buf), fp)) - { - char *name, *file, *line; - int len; - - if (sigs) - { + } + if (fp != NULL) + { + while (fgets(buf, sizeof(buf), fp)) + { + char *name, *file, *line; + int len; + + if (sigs) + { #if HAVE_POPEN - if (fp != stdin) - pclose(fp); + if (fp != stdin) + pclose(fp); #endif - return TAG_INTR; - } - len = (int) strlen(buf); - if (len > 0 && buf[len-1] == '\n') - buf[len-1] = '\0'; - else - { - int c; - do { - c = fgetc(fp); - } while (c != '\n' && c != EOF); - } - - if (getentry(buf, &name, &file, &line)) - { - /* - * Couldn't parse this line for some reason. - * We'll just pretend it never happened. - */ - break; - } - - /* Make new entry and add to list. */ - tp = maketagent(name, file, (LINENUM) atoi(line), NULL, 0); - TAG_INS(tp); - total++; - } - if (fp != stdin) - { - if (pclose(fp)) - { - curtag = NULL; - total = curseq = 0; - return TAG_NOFILE; - } - } - } - - /* Check to see if we found anything. */ - tp = taglist.tl_first; - if (tp == TAG_END) - return TAG_NOTAG; - curtag = tp; - curseq = 1; - return TAG_FOUND; + return TAG_INTR; + } + len = (int) strlen(buf); + if (len > 0 && buf[len-1] == '\n') + buf[len-1] = '\0'; + else + { + int c; + do { + c = fgetc(fp); + } while (c != '\n' && c != EOF); + } + + if (getentry(buf, &name, &file, &line)) + { + /* + * Couldn't parse this line for some reason. + * We'll just pretend it never happened. + */ + break; + } + + /* Make new entry and add to list. */ + tp = maketagent(name, file, (LINENUM) atoi(line), NULL, 0); + TAG_INS(tp); + total++; + } + if (fp != stdin) + { + if (pclose(fp)) + { + curtag = NULL; + total = curseq = 0; + return TAG_NOFILE; + } + } + } + + /* Check to see if we found anything. */ + tp = taglist.tl_first; + if (tp == TAG_END) + return TAG_NOTAG; + curtag = tp; + curseq = 1; + return TAG_FOUND; } static int circular = 0; /* 1: circular tag structure */ @@ -630,29 +630,29 @@ static int circular = 0; /* 1: circular tag structure */ * by findgtag(). The next call to gtagsearch() will try to position at the * appropriate tag. */ - static char * + static char * nextgtag(VOID_PARAM) { - struct tag *tp; - - if (curtag == NULL) - /* No tag loaded */ - return NULL; - - tp = curtag->next; - if (tp == TAG_END) - { - if (!circular) - return NULL; - /* Wrapped around to the head of the queue */ - curtag = taglist.tl_first; - curseq = 1; - } else - { - curtag = tp; - curseq++; - } - return (curtag->tag_file); + struct tag *tp; + + if (curtag == NULL) + /* No tag loaded */ + return NULL; + + tp = curtag->next; + if (tp == TAG_END) + { + if (!circular) + return NULL; + /* Wrapped around to the head of the queue */ + curtag = taglist.tl_first; + curseq = 1; + } else + { + curtag = tp; + curseq++; + } + return (curtag->tag_file); } /* @@ -660,29 +660,29 @@ nextgtag(VOID_PARAM) * setup by findgtat(). The next call to gtagsearch() will try to position * at the appropriate tag. */ - static char * + static char * prevgtag(VOID_PARAM) { - struct tag *tp; - - if (curtag == NULL) - /* No tag loaded */ - return NULL; - - tp = curtag->prev; - if (tp == TAG_END) - { - if (!circular) - return NULL; - /* Wrapped around to the tail of the queue */ - curtag = taglist.tl_last; - curseq = total; - } else - { - curtag = tp; - curseq--; - } - return (curtag->tag_file); + struct tag *tp; + + if (curtag == NULL) + /* No tag loaded */ + return NULL; + + tp = curtag->prev; + if (tp == TAG_END) + { + if (!circular) + return NULL; + /* Wrapped around to the tail of the queue */ + curtag = taglist.tl_last; + curseq = total; + } else + { + curtag = tp; + curseq--; + } + return (curtag->tag_file); } /* @@ -690,12 +690,12 @@ prevgtag(VOID_PARAM) * using either findtag() or one of nextgtag() and prevgtag(). Returns -1 * if it was unable to position at the tag, 0 if successful. */ - static POSITION + static POSITION gtagsearch(VOID_PARAM) { - if (curtag == NULL) - return (NULL_POSITION); /* No gtags loaded! */ - return (find_pos(curtag->tag_linenum)); + if (curtag == NULL) + return (NULL_POSITION); /* No gtags loaded! */ + return (find_pos(curtag->tag_linenum)); } /* @@ -726,58 +726,58 @@ gtagsearch(VOID_PARAM) * The tag, file, and line will each be NUL-terminated pointers * into buf. */ - static int + static int getentry(buf, tag, file, line) - char *buf; /* standard or extended ctags -x format data */ - char **tag; /* name of the tag we actually found */ - char **file; /* file in which to find this tag */ - char **line; /* line number of file where this tag is found */ + char *buf; /* standard or extended ctags -x format data */ + char **tag; /* name of the tag we actually found */ + char **file; /* file in which to find this tag */ + char **line; /* line number of file where this tag is found */ { - char *p = buf; - - for (*tag = p; *p && !IS_SPACE(*p); p++) /* tag name */ - ; - if (*p == 0) - return (-1); - *p++ = 0; - for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ - ; - if (*p == 0) - return (-1); - /* - * If the second part begin with other than digit, - * it is assumed tag type. Skip it. - */ - if (!IS_DIGIT(*p)) - { - for ( ; *p && !IS_SPACE(*p); p++) /* (skip tag type) */ - ; - for (; *p && IS_SPACE(*p); p++) /* (skip blanks) */ - ; - } - if (!IS_DIGIT(*p)) - return (-1); - *line = p; /* line number */ - for (*line = p; *p && !IS_SPACE(*p); p++) - ; - if (*p == 0) - return (-1); - *p++ = 0; - for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ - ; - if (*p == 0) - return (-1); - *file = p; /* file name */ - for (*file = p; *p && !IS_SPACE(*p); p++) - ; - if (*p == 0) - return (-1); - *p = 0; - - /* value check */ - if (strlen(*tag) && strlen(*line) && strlen(*file) && atoi(*line) > 0) - return (0); - return (-1); + char *p = buf; + + for (*tag = p; *p && !IS_SPACE(*p); p++) /* tag name */ + ; + if (*p == 0) + return (-1); + *p++ = 0; + for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ + ; + if (*p == 0) + return (-1); + /* + * If the second part begin with other than digit, + * it is assumed tag type. Skip it. + */ + if (!IS_DIGIT(*p)) + { + for ( ; *p && !IS_SPACE(*p); p++) /* (skip tag type) */ + ; + for (; *p && IS_SPACE(*p); p++) /* (skip blanks) */ + ; + } + if (!IS_DIGIT(*p)) + return (-1); + *line = p; /* line number */ + for (*line = p; *p && !IS_SPACE(*p); p++) + ; + if (*p == 0) + return (-1); + *p++ = 0; + for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ + ; + if (*p == 0) + return (-1); + *file = p; /* file name */ + for (*file = p; *p && !IS_SPACE(*p); p++) + ; + if (*p == 0) + return (-1); + *p = 0; + + /* value check */ + if (strlen(*tag) && strlen(*line) && strlen(*file) && atoi(*line) > 0) + return (0); + return (-1); } #endif diff --git a/ttyin.c b/ttyin.c index 5bd3385..be60d03 100644 --- a/ttyin.c +++ b/ttyin.c @@ -40,73 +40,73 @@ extern int wheel_lines; * Get name of tty device. */ #if !MSDOS_COMPILER - public char * + public char * tty_device(VOID_PARAM) { - char *dev = NULL; + char *dev = NULL; #if HAVE_TTYNAME - dev = ttyname(2); + dev = ttyname(2); #endif - if (dev == NULL) - dev = "/dev/tty"; + if (dev == NULL) + dev = "/dev/tty"; #if LESSTEST - if (ttyin_name != NULL) - dev = ttyin_name; + if (ttyin_name != NULL) + dev = ttyin_name; #endif /*LESSTEST*/ - return dev; + return dev; } #endif /* MSDOS_COMPILER */ /* * Open keyboard for input. */ - public void + public void open_getchr(VOID_PARAM) { #if MSDOS_COMPILER==WIN32C - /* Need this to let child processes inherit our console handle */ - SECURITY_ATTRIBUTES sa; - memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES)); - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.bInheritHandle = TRUE; - tty = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ, &sa, - OPEN_EXISTING, 0L, NULL); - GetConsoleMode(tty, &console_mode); - /* Make sure we get Ctrl+C events. */ - SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT); + /* Need this to let child processes inherit our console handle */ + SECURITY_ATTRIBUTES sa; + memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES)); + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.bInheritHandle = TRUE; + tty = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, &sa, + OPEN_EXISTING, 0L, NULL); + GetConsoleMode(tty, &console_mode); + /* Make sure we get Ctrl+C events. */ + SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT); #else #if MSDOS_COMPILER - extern int fd0; - /* - * Open a new handle to CON: in binary mode - * for unbuffered keyboard read. - */ - fd0 = dup(0); - close(0); - tty = open("CON", OPEN_READ); + extern int fd0; + /* + * Open a new handle to CON: in binary mode + * for unbuffered keyboard read. + */ + fd0 = dup(0); + close(0); + tty = open("CON", OPEN_READ); #if MSDOS_COMPILER==DJGPPC - /* - * Setting stdin to binary causes Ctrl-C to not - * raise SIGINT. We must undo that side-effect. - */ - (void) __djgpp_set_ctrl_c(1); + /* + * Setting stdin to binary causes Ctrl-C to not + * raise SIGINT. We must undo that side-effect. + */ + (void) __djgpp_set_ctrl_c(1); #endif #else - /* - * Try /dev/tty. - * If that doesn't work, use file descriptor 2, - * which in Unix is usually attached to the screen, - * but also usually lets you read from the keyboard. - */ + /* + * Try /dev/tty. + * If that doesn't work, use file descriptor 2, + * which in Unix is usually attached to the screen, + * but also usually lets you read from the keyboard. + */ #if OS2 - /* The __open() system call translates "/dev/tty" to "con". */ - tty = __open(tty_device(), OPEN_READ); + /* The __open() system call translates "/dev/tty" to "con". */ + tty = __open(tty_device(), OPEN_READ); #else - tty = open(tty_device(), OPEN_READ); + tty = open(tty_device(), OPEN_READ); #endif - if (tty < 0) - tty = 2; + if (tty < 0) + tty = 2; #endif #endif } @@ -114,12 +114,12 @@ open_getchr(VOID_PARAM) /* * Close the keyboard. */ - public void + public void close_getchr(VOID_PARAM) { #if MSDOS_COMPILER==WIN32C - SetConsoleMode(tty, console_mode); - CloseHandle(tty); + SetConsoleMode(tty, console_mode); + CloseHandle(tty); #endif } @@ -127,136 +127,136 @@ close_getchr(VOID_PARAM) /* * Close the pipe, restoring the keyboard (CMD resets it, losing the mouse). */ - int + int pclose(f) - FILE *f; + FILE *f; { - int result; + int result; - result = _pclose(f); - SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT); - return result; + result = _pclose(f); + SetConsoleMode(tty, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT); + return result; } #endif /* * Get the number of lines to scroll when mouse wheel is moved. */ - public int + public int default_wheel_lines(VOID_PARAM) { - int lines = 1; + int lines = 1; #if MSDOS_COMPILER==WIN32C - if (SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &lines, 0)) - { - if (lines == WHEEL_PAGESCROLL) - lines = 3; - } + if (SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &lines, 0)) + { + if (lines == WHEEL_PAGESCROLL) + lines = 3; + } #endif - return lines; + return lines; } #if LESSTEST - public void + public void rstat(st) - char st; + char st; { - if (rstat_file < 0) - return; - lseek(rstat_file, SEEK_SET, 0); - write(rstat_file, &st, 1); + if (rstat_file < 0) + return; + lseek(rstat_file, SEEK_SET, 0); + write(rstat_file, &st, 1); } #endif /*LESSTEST*/ /* * Get a character from the keyboard. */ - public int + public int getchr(VOID_PARAM) { - char c; - int result; + char c; + int result; - do - { - flush(); + do + { + flush(); #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC - /* - * In raw read, we don't see ^C so look here for it. - */ + /* + * In raw read, we don't see ^C so look here for it. + */ #if MSDOS_COMPILER==WIN32C - if (ABORT_SIGS()) - return (READ_INTR); - c = WIN32getch(); + if (ABORT_SIGS()) + return (READ_INTR); + c = WIN32getch(); #else - c = getch(); + c = getch(); #endif - result = 1; - if (c == '\003') - return (READ_INTR); + result = 1; + if (c == '\003') + return (READ_INTR); #else #if LESSTEST - rstat('R'); + rstat('R'); #endif /*LESSTEST*/ - { - unsigned char uc; - result = iread(tty, &uc, sizeof(char)); - c = (char) uc; - } + { + unsigned char uc; + result = iread(tty, &uc, sizeof(char)); + c = (char) uc; + } #if LESSTEST - rstat('B'); + rstat('B'); #endif /*LESSTEST*/ - if (result == READ_INTR) - return (READ_INTR); - if (result < 0) - { - /* - * Don't call error() here, - * because error calls getchr! - */ - quit(QUIT_ERROR); - } + if (result == READ_INTR) + return (READ_INTR); + if (result < 0) + { + /* + * Don't call error() here, + * because error calls getchr! + */ + quit(QUIT_ERROR); + } #endif #if 0 /* allow entering arbitrary hex chars for testing */ - /* ctrl-A followed by two hex chars makes a byte */ - { - static int hex_in = 0; - static int hex_value = 0; - if (c == CONTROL('A')) - { - hex_in = 2; - result = 0; - continue; - } - if (hex_in > 0) - { - int v; - if (c >= '0' && c <= '9') - v = c - '0'; - else if (c >= 'a' && c <= 'f') - v = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - v = c - 'A' + 10; - else - v = 0; - hex_value = (hex_value << 4) | v; - if (--hex_in > 0) - { - result = 0; - continue; - } - c = hex_value; - } - } + /* ctrl-A followed by two hex chars makes a byte */ + { + static int hex_in = 0; + static int hex_value = 0; + if (c == CONTROL('A')) + { + hex_in = 2; + result = 0; + continue; + } + if (hex_in > 0) + { + int v; + if (c >= '0' && c <= '9') + v = c - '0'; + else if (c >= 'a' && c <= 'f') + v = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + v = c - 'A' + 10; + else + v = 0; + hex_value = (hex_value << 4) | v; + if (--hex_in > 0) + { + result = 0; + continue; + } + c = hex_value; + } + } #endif - /* - * Various parts of the program cannot handle - * an input character of '\0'. - * If a '\0' was actually typed, convert it to '\340' here. - */ - if (c == '\0') - c = '\340'; - } while (result != 1); + /* + * Various parts of the program cannot handle + * an input character of '\0'. + * If a '\0' was actually typed, convert it to '\340' here. + */ + if (c == '\0') + c = '\340'; + } while (result != 1); - return (c & 0xFF); + return (c & 0xFF); } diff --git a/ubin.uni b/ubin.uni index 10a48d5..7391121 100644 --- a/ubin.uni +++ b/ubin.uni @@ -1,17 +1,17 @@ /* Generated by "./mkutable -f2 Cc Cs Co Zl Zp -- unicode/UnicodeData.txt" on Tue May 19 14:47:34 PDT 2020 */ - { 0x0000, 0x0007 }, /* Cc */ - { 0x000b, 0x000b }, /* Cc */ - { 0x000e, 0x001f }, /* Cc */ - { 0x007f, 0x009f }, /* Cc */ - { 0x2028, 0x2028 }, /* Zl */ - { 0x2029, 0x2029 }, /* Zp */ - { 0xd800, 0xd800 }, /* Cs */ - { 0xdb7f, 0xdb80 }, /* Cs */ - { 0xdbff, 0xdc00 }, /* Cs */ - { 0xdfff, 0xdfff }, /* Cs */ - { 0xe000, 0xe000 }, /* Co */ - { 0xf8ff, 0xf8ff }, /* Co */ - { 0xf0000, 0xf0000 }, /* Co */ - { 0xffffd, 0xffffd }, /* Co */ - { 0x100000, 0x100000 }, /* Co */ - { 0x10fffd, 0x10fffd }, /* Co */ + { 0x0000, 0x0007 }, /* Cc */ + { 0x000b, 0x000b }, /* Cc */ + { 0x000e, 0x001f }, /* Cc */ + { 0x007f, 0x009f }, /* Cc */ + { 0x2028, 0x2028 }, /* Zl */ + { 0x2029, 0x2029 }, /* Zp */ + { 0xd800, 0xd800 }, /* Cs */ + { 0xdb7f, 0xdb80 }, /* Cs */ + { 0xdbff, 0xdc00 }, /* Cs */ + { 0xdfff, 0xdfff }, /* Cs */ + { 0xe000, 0xe000 }, /* Co */ + { 0xf8ff, 0xf8ff }, /* Co */ + { 0xf0000, 0xf0000 }, /* Co */ + { 0xffffd, 0xffffd }, /* Co */ + { 0x100000, 0x100000 }, /* Co */ + { 0x10fffd, 0x10fffd }, /* Co */ diff --git a/version.c b/version.c index 7ca31e0..6b71755 100644 --- a/version.c +++ b/version.c @@ -43,7 +43,7 @@ v22 5/24/85 Added support for no RECOMP nor REGCMP. v23 5/25/85 Miscellanous changes and prettying up. Posted to USENET. ----------------------------------------------------------------- -v24 6/3/85 Added ti,te terminal init & de-init. +v24 6/3/85 Added ti,te terminal init & de-init. (Thanks to Mike Kersenbrock) v25 6/8/85 Added -U flag, standout mode underlining. v26 6/9/85 Added -M flag. @@ -53,7 +53,7 @@ v27 6/15/85 Renamed some variables to make unique in v28 6/28/85 Fixed right margin bug. v29 6/28/85 Incorporated M.Rose's changes to signal.c v30 6/29/85 Fixed stupid bug in argument processing. -v31 7/15/85 Added -p flag, changed repaint algorithm. +v31 7/15/85 Added -p flag, changed repaint algorithm. Added kludge for magic cookie terminals. v32 7/16/85 Added cat_file if output not a tty. v33 7/23/85 Added -e flag and EDITOR. @@ -125,7 +125,7 @@ v73 6/26/87 Allow Examine "#" for previous file. ----------------------------------------------------------------- v74 9/18/87 Fix conflict in EOF symbol with stdio.h, Make os.c more portable to BSD. -v75 9/23/87 Fix problems in get_term (thanks to +v75 9/23/87 Fix problems in get_term (thanks to Paul Eggert); new backwards scrolling in jump_loc (thanks to Marion Hakanson). v76 9/23/87 Added -i flag; allow single "!" to @@ -180,17 +180,17 @@ v103 3/14/89 Add -N, -f and -? options. Add z and w v104 3/16/89 Added EDITPROTO. v105 3/20/89 Fix bug in find_linenum which cached incorrectly on long lines. -v106 3/31/89 Added -k option and multiple lesskey +v106 3/31/89 Added -k option and multiple lesskey files. v107 4/27/89 Add 8-bit char support and -g option. Split option code into 3 files. -v108 5/5/89 Allocate position table dynamically +v108 5/5/89 Allocate position table dynamically (thanks to Paul Eggert); change % command from "percent" to vi-style brace finder. v109 5/10/89 Added ESC-% command, split prim.c. v110 5/24/89 Fixed bug in + option; fixed repaint bug under Sun windows (thanks to Paul Eggert). -v111 5/25/89 Generalized # and % expansion; use +v111 5/25/89 Generalized # and % expansion; use calloc for some error messages. v112 5/30/89 Get rid of ESC-%, add {}()[] commands. v113 5/31/89 Optimize lseeks (thanks to Paul Eggert). @@ -240,7 +240,7 @@ v141 2/8/90 Add edit_list for editing >1 file. v142 2/10/90 Add :x command. v143 2/11/90 Add * and @ modifies to search cmds. Change ESC-/ cmd from /@* to / *. -v144 3/1/90 Messed around with ch_zero; +v144 3/1/90 Messed around with ch_zero; no real change. v145 3/2/90 Added -R and -v/-V for MSDOS; renamed FILENAME to avoid conflict. @@ -252,7 +252,7 @@ v150 4/6/90 Add LESS_CHARSET, LESS_CHARDEF. v151 4/13/90 Remove -g option; clean up ispipe. v152 4/14/90 lsystem() closes input file, for editors which require exclusive open. -v153 4/18/90 Fix bug if SHELL unset; +v153 4/18/90 Fix bug if SHELL unset; fix bug in overstrike control char. v154 4/25/90 Output to fd 2 via buffer. v155 4/30/90 Ignore -i if uppercase in pattern @@ -319,7 +319,7 @@ v185 7/11/91 -Pxxx sets short prompt; assume SIGWINCH v186 4/20/92 Port to MS-DOS (Microsoft C). v187 4/23/92 Added -D option & TAB_COMPLETE_FILENAME. v188 4/28/92 Added command line editing features. -v189 12/8/92 Fix mem overrun in anscreen.c:init; +v189 12/8/92 Fix mem overrun in anscreen.c:init; fix edit_list to recover from bin file. v190 2/13/93 Make TAB enter one filename at a time; create ^L with old TAB functionality. @@ -341,7 +341,7 @@ v200 7/25/94 Clean up copyright, minor fixes. v201 7/27/94 Check for no memcpy; add casts to calloc; look for regcmp in libgen.a. (thanks to Kaveh Ghazi). -v202 7/28/94 Fix bug in edit_next/edit_prev with +v202 7/28/94 Fix bug in edit_next/edit_prev with non-existent files. v203 8/2/94 Fix a variety of configuration bugs on various systems. (thanks to Sakai @@ -361,7 +361,7 @@ v206 8/10/94 Use initial_scrpos for -t to avoid v207 8/12/94 Fix bug if stdout is not tty. v208 8/16/94 Fix bug in close_altfile if goto err1 in edit_ifile. (Thanks to M.J. Hewitt) -v209 8/16/94 Change scroll to wscroll to avoid +v209 8/16/94 Change scroll to wscroll to avoid conflict with library function. v210 8/16/94 Fix bug with bold on 8 bit chars. (thanks to Vitor Duarte) @@ -384,7 +384,7 @@ v223 8/27/94 Support setlocale. v224 8/29/94 Revert v216: process BS in search only if -u. v225 9/6/94 Rewrite undo_search again: toggle. -v226 9/15/94 Configuration fixes. +v226 9/15/94 Configuration fixes. (thanks to David MacKenzie) v227 9/19/94 Fixed strerror config problem. Posted to prep.ai.mit.edu @@ -397,7 +397,7 @@ v230 9/21/94 Don't print extra error msg in search after regerror(). v231 9/22/94 Fix hilite bug if search matches 0 chars. (thanks to John Polstra) -v232 9/23/94 Deal with weird systems that have +v232 9/23/94 Deal with weird systems that have termios.h but not tcgetattr(). Posted to prep.ai.mit.edu ----------------------------------------------------------------- @@ -406,7 +406,7 @@ v233 9/26/94 Use get_term() instead of pos_init() in (Thanks to John Malecki) v234 9/26/94 Make MIDDLE closer to middle of screen. v235 9/27/94 Use local strchr if system doesn't have. -v236 9/28/94 Don't use libucb; use libterm if +v236 9/28/94 Don't use libucb; use libterm if libtermcap & libcurses doesn't work. (Fix for Solaris; thanks to Frank Kaefer) v237 9/30/94 Use system isupper() etc if provided. @@ -432,7 +432,7 @@ v249 11/5/94 Remove -f flag from lesskey; default v250 11/7/94 Lesskey input file "-" means stdin. v251 11/9/94 Convert cfgetospeed result to ospeed. (Thanks to Andrew Chernov) -v252 11/16/94 Change default lesskey input file from +v252 11/16/94 Change default lesskey input file from .lesskey.in to .lesskey. Posted to prep.ai.mit.edu ----------------------------------------------------------------- @@ -467,7 +467,7 @@ v273 1/6/95 Fix ch_ungetchar bug; don't call v274 1/6/95 Ported to OS/2 (thanks to Kai Uwe Rommel) v275 1/18/95 Fix bug if toggle -G at EOF. v276 1/30/95 Fix OS/2 version. -v277 1/31/95 Add "next" charset; don't display ^X +v277 1/31/95 Add "next" charset; don't display ^X for X > 128. v278 2/14/95 Change default for -G. Posted to prep.ai.mit.edu @@ -481,7 +481,7 @@ v282 3/2/95 Minor fixes. v283 3/2/95 Fix homefile; make OS2 look in $HOME. v284 3/2/95 Error if "v" on LESSOPENed file; "%" figures out file size on pipe. -v285 3/7/95 Don't set # in lsystem; +v285 3/7/95 Don't set # in lsystem; lesskey try $HOME first. v286 3/7/95 Reformat change history (too much free time?). v287 3/8/95 Fix hilite bug if overstrike multiple chars. @@ -501,9 +501,9 @@ v293 4/28/95 Add auto-versioning stuff to make dist. v294 5/12/95 Fix Borland build. v295 1/20/96 Fix search on squished file; add /@@. v296 1/23/96 Allow cmdbuf larger than screen width. -v297 1/24/96 Don't call termcap if tgetent fails; +v297 1/24/96 Don't call termcap if tgetent fails; add #defines for buffers. -v298 1/24/96 Change @@ to ^K. +v298 1/24/96 Change @@ to ^K. Add alternate search modifiers ^N, ^F, ^E. v299 1/25/96 Fix percent overflow in jump_percent (thanks to Brent Wiese); don't send "ti" after shell command till RETURN pressed. @@ -526,14 +526,14 @@ v315 4/26/96 Fix "!;TAB" bug. v316 5/2/96 Make "|a" when (a < curr screen) go to end of curr screen. v317 5/14/96 Various fixes for the MS-DOS and OS/2 builds. Added ## and %% handling for filenames -v318 5/29/96 Port to OS-9 Microware compiler; minor fixes +v318 5/29/96 Port to OS-9 Microware compiler; minor fixes (thanks to Martin Gregorie). v319 7/8/96 Fix Windows port (thanks to Jeff Paquette). v320 7/11/96 Final fixes for Windows port. v321 7/18/96 Minor fixes. Posted to Web page. ----------------------------------------------------------------- -v322 8/13/96 Fix bug in shell escape from help file; add support for +v322 8/13/96 Fix bug in shell escape from help file; add support for Microsoft Visual C under Windows; numerous small fixes. v323 8/19/96 Fixes for Windows version (thanks to Simon Munton); fix for Linux library weirdness (thanks to Jim Diamond); @@ -658,8 +658,8 @@ v386 9/13/05 Improvements to UTF-8 shift & color (thanks to Charles Levert); protect against invalid LESSOPEN and LESSCLOSE values. v387 9/14/05 Update Charles Levert's UTF-8 patch. v388 9/14/05 Change history behavior; change most sprintf calls to snprintf. -v389 9/14/05 Fix copy & paste with long lines; improve performance of - expand_linebuf; fix crash in init_mlist; +v389 9/14/05 Fix copy & paste with long lines; improve performance of + expand_linebuf; fix crash in init_mlist; v390 9/15/05 Show search matches in status column even if -G is set. ----------------------------------------------------------------- v391 9/17/05 Fix bugs. @@ -671,7 +671,7 @@ v394 11/8/05 Fix prompt bug; fix compile problem in Windows build. v395 1/12/07 Update Unicode tables (thanks to Charles Levert); don't chmod if LESSHISTFILE = /dev/null; make -f work for directories; support DESTDIR in Makefile; - fix sigset_t detection in configure; + fix sigset_t detection in configure; make "t" cmd traverse tags in correct order v396 1/13/07 Add compatibility with POSIX more. v397 3/21/07 Allow decimal point in number for % command; @@ -731,7 +731,7 @@ v436 7/05/09 Fix memory leak. ----------------------------------------------------------------- v437 7/14/09 Fix bug in handling some long option names; make percentage calculation more accurate. -v438 12/29/10 Fix bugs with -i/-I and & filtering; +v438 12/29/10 Fix bugs with -i/-I and & filtering; exit with status 2 on ctrl-C with -K. v439 12/31/10 Add -A option. v440 1/5/11 Fix bug displaying prompt after = command. @@ -782,7 +782,7 @@ v471 12/14/14 Fix unget issues with prompt. Allow disabling history v473 12/19/14 Fix prompt bug with stdin and -^P in lesskey extra string. v474 1/30/15 Fix bug in backwards search with match on bottom line. Make follow mode reopen file if file shrinks. -v475 3/2/15 Fix possible buffer overrun with invalid UTF-8; +v475 3/2/15 Fix possible buffer overrun with invalid UTF-8; fix bug when compiled with no regex; fix non-match search. v476 5/3/15 Update man pages. v477 5/19/15 Fix off-by-one in jump_forw_buffered; @@ -799,10 +799,10 @@ v483 2/27/16 Regenerate hilite when change search caselessness. v484 9/20/16 Update to Unicode 9.0.0 database. v485 10/21/16 Fix "nothing to search" bug when top/bottom line is empty; Display line numbers in bold. (thanks to Jason Hood); - Fix incorrect display when entering double-width chars in + Fix incorrect display when entering double-width chars in search string. -v486 10/22/16 New commands ESC-{ and ESC-} to shift to start/end of - displayed lines; new option -Da in Windows version to +v486 10/22/16 New commands ESC-{ and ESC-} to shift to start/end of + displayed lines; new option -Da in Windows version to enable SGR mode (thanks to Jason Hood). v487 10/23/16 configure --help formatting. ----------------------------------------------------------------- @@ -825,7 +825,7 @@ v501 7/12/17 Make sure rscroll char is standout by default. v502 7/13/17 Control rscroll char via command line option not env variable. v503 7/13/17 Switch to git. v504 7/13/17 Call opt_rscroll at startup; change mkhelp.c to mkhelp.pl. -v505 7/17/17 Add M and ESC-M commands; +v505 7/17/17 Add M and ESC-M commands; fix buffer handling with stdin and LESSOPEN. v506 7/17/17 On Windows, convert UTF-8 to multibyte if console is not UTF-8; handle extended chars on input (thanks to Jason Hood). @@ -854,10 +854,10 @@ v528 11/3/17 Make second ESC-u clear status column. v529 11/12/17 Display Unicode formatting chars in hex if -U is set. v530 12/2/17 Minor doc change and add missing VOID_PARAM. ----------------------------------------------------------------- -v531 5/13/18 Fix bug with v on empty file; fix bug with v on file with +v531 5/13/18 Fix bug with v on empty file; fix bug with v on file with metachars in name; add --nohistdups option. v532 7/27/18 Redraw screen on SIGWINCH even if screen size doesn't change. -v533 8/1/18 Shell escape filenames in history; use PCRE_UTF8 flag; +v533 8/1/18 Shell escape filenames in history; use PCRE_UTF8 flag; use wide-chars for Windows console title (thanks to Jason Hood). v534 8/9/18 Support PCRE2. v535 8/16/18 Don't count lines of initial screen if using -X with -F @@ -900,7 +900,7 @@ v566 11/25/20 Fix crash when reopening a file while using LESSOPEN; support OSC 8 hyperlinks. v567 11/25/20 Fix typo. v568 11/29/20 Fix some hyperlink bugs; add ^W search modifier - (thanks to Arminius); allow Makefile.aut to use Python + (thanks to Arminius); allow Makefile.aut to use Python instead of Perl (thanks to Charlie Lin). v569 12/1/20 Allow multiple & filters (thanks to Mattias Johansson), allow ^X to exit F command. diff --git a/wide.uni b/wide.uni index f1ec98d..54d7b2d 100644 --- a/wide.uni +++ b/wide.uni @@ -1,118 +1,118 @@ /* Generated by "./mkutable -f1 W F -- unicode/EastAsianWidth.txt" on Tue May 19 14:47:35 PDT 2020 */ - { 0x1100, 0x115f }, /* W */ - { 0x231a, 0x231b }, /* W */ - { 0x2329, 0x232a }, /* W */ - { 0x23e9, 0x23ec }, /* W */ - { 0x23f0, 0x23f0 }, /* W */ - { 0x23f3, 0x23f3 }, /* W */ - { 0x25fd, 0x25fe }, /* W */ - { 0x2614, 0x2615 }, /* W */ - { 0x2648, 0x2653 }, /* W */ - { 0x267f, 0x267f }, /* W */ - { 0x2693, 0x2693 }, /* W */ - { 0x26a1, 0x26a1 }, /* W */ - { 0x26aa, 0x26ab }, /* W */ - { 0x26bd, 0x26be }, /* W */ - { 0x26c4, 0x26c5 }, /* W */ - { 0x26ce, 0x26ce }, /* W */ - { 0x26d4, 0x26d4 }, /* W */ - { 0x26ea, 0x26ea }, /* W */ - { 0x26f2, 0x26f3 }, /* W */ - { 0x26f5, 0x26f5 }, /* W */ - { 0x26fa, 0x26fa }, /* W */ - { 0x26fd, 0x26fd }, /* W */ - { 0x2705, 0x2705 }, /* W */ - { 0x270a, 0x270b }, /* W */ - { 0x2728, 0x2728 }, /* W */ - { 0x274c, 0x274c }, /* W */ - { 0x274e, 0x274e }, /* W */ - { 0x2753, 0x2755 }, /* W */ - { 0x2757, 0x2757 }, /* W */ - { 0x2795, 0x2797 }, /* W */ - { 0x27b0, 0x27b0 }, /* W */ - { 0x27bf, 0x27bf }, /* W */ - { 0x2b1b, 0x2b1c }, /* W */ - { 0x2b50, 0x2b50 }, /* W */ - { 0x2b55, 0x2b55 }, /* W */ - { 0x2e80, 0x2e99 }, /* W */ - { 0x2e9b, 0x2ef3 }, /* W */ - { 0x2f00, 0x2fd5 }, /* W */ - { 0x2ff0, 0x2ffb }, /* W */ - { 0x3000, 0x3000 }, /* F */ - { 0x3001, 0x303e }, /* W */ - { 0x3041, 0x3096 }, /* W */ - { 0x3099, 0x30ff }, /* W */ - { 0x3105, 0x312f }, /* W */ - { 0x3131, 0x318e }, /* W */ - { 0x3190, 0x31e3 }, /* W */ - { 0x31f0, 0x321e }, /* W */ - { 0x3220, 0x3247 }, /* W */ - { 0x3250, 0x4dbf }, /* W */ - { 0x4e00, 0xa48c }, /* W */ - { 0xa490, 0xa4c6 }, /* W */ - { 0xa960, 0xa97c }, /* W */ - { 0xac00, 0xd7a3 }, /* W */ - { 0xf900, 0xfaff }, /* W */ - { 0xfe10, 0xfe19 }, /* W */ - { 0xfe30, 0xfe52 }, /* W */ - { 0xfe54, 0xfe66 }, /* W */ - { 0xfe68, 0xfe6b }, /* W */ - { 0xff01, 0xff60 }, /* F */ - { 0xffe0, 0xffe6 }, /* F */ - { 0x16fe0, 0x16fe4 }, /* W */ - { 0x16ff0, 0x16ff1 }, /* W */ - { 0x17000, 0x187f7 }, /* W */ - { 0x18800, 0x18cd5 }, /* W */ - { 0x18d00, 0x18d08 }, /* W */ - { 0x1b000, 0x1b11e }, /* W */ - { 0x1b150, 0x1b152 }, /* W */ - { 0x1b164, 0x1b167 }, /* W */ - { 0x1b170, 0x1b2fb }, /* W */ - { 0x1f004, 0x1f004 }, /* W */ - { 0x1f0cf, 0x1f0cf }, /* W */ - { 0x1f18e, 0x1f18e }, /* W */ - { 0x1f191, 0x1f19a }, /* W */ - { 0x1f200, 0x1f202 }, /* W */ - { 0x1f210, 0x1f23b }, /* W */ - { 0x1f240, 0x1f248 }, /* W */ - { 0x1f250, 0x1f251 }, /* W */ - { 0x1f260, 0x1f265 }, /* W */ - { 0x1f300, 0x1f320 }, /* W */ - { 0x1f32d, 0x1f335 }, /* W */ - { 0x1f337, 0x1f37c }, /* W */ - { 0x1f37e, 0x1f393 }, /* W */ - { 0x1f3a0, 0x1f3ca }, /* W */ - { 0x1f3cf, 0x1f3d3 }, /* W */ - { 0x1f3e0, 0x1f3f0 }, /* W */ - { 0x1f3f4, 0x1f3f4 }, /* W */ - { 0x1f3f8, 0x1f43e }, /* W */ - { 0x1f440, 0x1f440 }, /* W */ - { 0x1f442, 0x1f4fc }, /* W */ - { 0x1f4ff, 0x1f53d }, /* W */ - { 0x1f54b, 0x1f54e }, /* W */ - { 0x1f550, 0x1f567 }, /* W */ - { 0x1f57a, 0x1f57a }, /* W */ - { 0x1f595, 0x1f596 }, /* W */ - { 0x1f5a4, 0x1f5a4 }, /* W */ - { 0x1f5fb, 0x1f64f }, /* W */ - { 0x1f680, 0x1f6c5 }, /* W */ - { 0x1f6cc, 0x1f6cc }, /* W */ - { 0x1f6d0, 0x1f6d2 }, /* W */ - { 0x1f6d5, 0x1f6d7 }, /* W */ - { 0x1f6eb, 0x1f6ec }, /* W */ - { 0x1f6f4, 0x1f6fc }, /* W */ - { 0x1f7e0, 0x1f7eb }, /* W */ - { 0x1f90c, 0x1f93a }, /* W */ - { 0x1f93c, 0x1f945 }, /* W */ - { 0x1f947, 0x1f978 }, /* W */ - { 0x1f97a, 0x1f9cb }, /* W */ - { 0x1f9cd, 0x1f9ff }, /* W */ - { 0x1fa70, 0x1fa74 }, /* W */ - { 0x1fa78, 0x1fa7a }, /* W */ - { 0x1fa80, 0x1fa86 }, /* W */ - { 0x1fa90, 0x1faa8 }, /* W */ - { 0x1fab0, 0x1fab6 }, /* W */ - { 0x1fac0, 0x1fac2 }, /* W */ - { 0x1fad0, 0x1fad6 }, /* W */ - { 0x20000, 0x2fffd }, /* W */ - { 0x30000, 0x3fffd }, /* W */ + { 0x1100, 0x115f }, /* W */ + { 0x231a, 0x231b }, /* W */ + { 0x2329, 0x232a }, /* W */ + { 0x23e9, 0x23ec }, /* W */ + { 0x23f0, 0x23f0 }, /* W */ + { 0x23f3, 0x23f3 }, /* W */ + { 0x25fd, 0x25fe }, /* W */ + { 0x2614, 0x2615 }, /* W */ + { 0x2648, 0x2653 }, /* W */ + { 0x267f, 0x267f }, /* W */ + { 0x2693, 0x2693 }, /* W */ + { 0x26a1, 0x26a1 }, /* W */ + { 0x26aa, 0x26ab }, /* W */ + { 0x26bd, 0x26be }, /* W */ + { 0x26c4, 0x26c5 }, /* W */ + { 0x26ce, 0x26ce }, /* W */ + { 0x26d4, 0x26d4 }, /* W */ + { 0x26ea, 0x26ea }, /* W */ + { 0x26f2, 0x26f3 }, /* W */ + { 0x26f5, 0x26f5 }, /* W */ + { 0x26fa, 0x26fa }, /* W */ + { 0x26fd, 0x26fd }, /* W */ + { 0x2705, 0x2705 }, /* W */ + { 0x270a, 0x270b }, /* W */ + { 0x2728, 0x2728 }, /* W */ + { 0x274c, 0x274c }, /* W */ + { 0x274e, 0x274e }, /* W */ + { 0x2753, 0x2755 }, /* W */ + { 0x2757, 0x2757 }, /* W */ + { 0x2795, 0x2797 }, /* W */ + { 0x27b0, 0x27b0 }, /* W */ + { 0x27bf, 0x27bf }, /* W */ + { 0x2b1b, 0x2b1c }, /* W */ + { 0x2b50, 0x2b50 }, /* W */ + { 0x2b55, 0x2b55 }, /* W */ + { 0x2e80, 0x2e99 }, /* W */ + { 0x2e9b, 0x2ef3 }, /* W */ + { 0x2f00, 0x2fd5 }, /* W */ + { 0x2ff0, 0x2ffb }, /* W */ + { 0x3000, 0x3000 }, /* F */ + { 0x3001, 0x303e }, /* W */ + { 0x3041, 0x3096 }, /* W */ + { 0x3099, 0x30ff }, /* W */ + { 0x3105, 0x312f }, /* W */ + { 0x3131, 0x318e }, /* W */ + { 0x3190, 0x31e3 }, /* W */ + { 0x31f0, 0x321e }, /* W */ + { 0x3220, 0x3247 }, /* W */ + { 0x3250, 0x4dbf }, /* W */ + { 0x4e00, 0xa48c }, /* W */ + { 0xa490, 0xa4c6 }, /* W */ + { 0xa960, 0xa97c }, /* W */ + { 0xac00, 0xd7a3 }, /* W */ + { 0xf900, 0xfaff }, /* W */ + { 0xfe10, 0xfe19 }, /* W */ + { 0xfe30, 0xfe52 }, /* W */ + { 0xfe54, 0xfe66 }, /* W */ + { 0xfe68, 0xfe6b }, /* W */ + { 0xff01, 0xff60 }, /* F */ + { 0xffe0, 0xffe6 }, /* F */ + { 0x16fe0, 0x16fe4 }, /* W */ + { 0x16ff0, 0x16ff1 }, /* W */ + { 0x17000, 0x187f7 }, /* W */ + { 0x18800, 0x18cd5 }, /* W */ + { 0x18d00, 0x18d08 }, /* W */ + { 0x1b000, 0x1b11e }, /* W */ + { 0x1b150, 0x1b152 }, /* W */ + { 0x1b164, 0x1b167 }, /* W */ + { 0x1b170, 0x1b2fb }, /* W */ + { 0x1f004, 0x1f004 }, /* W */ + { 0x1f0cf, 0x1f0cf }, /* W */ + { 0x1f18e, 0x1f18e }, /* W */ + { 0x1f191, 0x1f19a }, /* W */ + { 0x1f200, 0x1f202 }, /* W */ + { 0x1f210, 0x1f23b }, /* W */ + { 0x1f240, 0x1f248 }, /* W */ + { 0x1f250, 0x1f251 }, /* W */ + { 0x1f260, 0x1f265 }, /* W */ + { 0x1f300, 0x1f320 }, /* W */ + { 0x1f32d, 0x1f335 }, /* W */ + { 0x1f337, 0x1f37c }, /* W */ + { 0x1f37e, 0x1f393 }, /* W */ + { 0x1f3a0, 0x1f3ca }, /* W */ + { 0x1f3cf, 0x1f3d3 }, /* W */ + { 0x1f3e0, 0x1f3f0 }, /* W */ + { 0x1f3f4, 0x1f3f4 }, /* W */ + { 0x1f3f8, 0x1f43e }, /* W */ + { 0x1f440, 0x1f440 }, /* W */ + { 0x1f442, 0x1f4fc }, /* W */ + { 0x1f4ff, 0x1f53d }, /* W */ + { 0x1f54b, 0x1f54e }, /* W */ + { 0x1f550, 0x1f567 }, /* W */ + { 0x1f57a, 0x1f57a }, /* W */ + { 0x1f595, 0x1f596 }, /* W */ + { 0x1f5a4, 0x1f5a4 }, /* W */ + { 0x1f5fb, 0x1f64f }, /* W */ + { 0x1f680, 0x1f6c5 }, /* W */ + { 0x1f6cc, 0x1f6cc }, /* W */ + { 0x1f6d0, 0x1f6d2 }, /* W */ + { 0x1f6d5, 0x1f6d7 }, /* W */ + { 0x1f6eb, 0x1f6ec }, /* W */ + { 0x1f6f4, 0x1f6fc }, /* W */ + { 0x1f7e0, 0x1f7eb }, /* W */ + { 0x1f90c, 0x1f93a }, /* W */ + { 0x1f93c, 0x1f945 }, /* W */ + { 0x1f947, 0x1f978 }, /* W */ + { 0x1f97a, 0x1f9cb }, /* W */ + { 0x1f9cd, 0x1f9ff }, /* W */ + { 0x1fa70, 0x1fa74 }, /* W */ + { 0x1fa78, 0x1fa7a }, /* W */ + { 0x1fa80, 0x1fa86 }, /* W */ + { 0x1fa90, 0x1faa8 }, /* W */ + { 0x1fab0, 0x1fab6 }, /* W */ + { 0x1fac0, 0x1fac2 }, /* W */ + { 0x1fad0, 0x1fad6 }, /* W */ + { 0x20000, 0x2fffd }, /* W */ + { 0x30000, 0x3fffd }, /* W */ From ff92e84a80eca9c88c58dfd1aeb65088c6b5b089 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 26 Aug 2023 17:09:37 -0500 Subject: [PATCH 03/13] fix missing function declarations for 'signal.c' --- signal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/signal.c b/signal.c index 7b2ab5f..52625a1 100644 --- a/signal.c +++ b/signal.c @@ -117,6 +117,9 @@ winch(type) #define WIN32_LEAN_AND_MEAN #include +static BOOL WINAPI wbreak_handler LESSPARAMS ((DWORD dwCtrlType)); +static RETSIGTYPE terminate LESSPARAMS ((int type)); + static BOOL WINAPI wbreak_handler(dwCtrlType) DWORD dwCtrlType; From 66dc09ecdfae5154296bba265f966b2106897951 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 26 Aug 2023 15:33:32 -0500 Subject: [PATCH 04/13] fix `LWCHAR` to `char` comparison warnings - note: FixME's added to prompt later verification that the re-cast code is safe --- line.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/line.c b/line.c index 6872fed..c2c06ba 100644 --- a/line.c +++ b/line.c @@ -621,7 +621,8 @@ ansi_step(pansi, ch) if (pansi->hindex >= 0) { static char hlink_prefix[] = ESCS "]8;"; - if (ch == hlink_prefix[pansi->hindex] || + // FixME: [2023-08-14; rivy] verify re-cast of `hlink_prefix[pansi->hindex]' to LWCHAR is correct and safe + if (ch == (LWCHAR)hlink_prefix[pansi->hindex] || (pansi->hindex == 0 && IS_CSI_START(ch))) { pansi->hindex++; From cab2c0993259fe6ef5f11c19f10ce51041c7bb76 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 26 Aug 2023 15:47:30 -0500 Subject: [PATCH 05/13] fix `size_t` usage inconsistencies --- charset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charset.c b/charset.c index 6d32fde..d39d638 100644 --- a/charset.c +++ b/charset.c @@ -542,7 +542,7 @@ is_utf8_well_formed(ss, slen) if (IS_UTF8_INVALID(s[0])) return (0); - len = utf_len(s[0]); + len = (size_t)utf_len(s[0]); if (len > slen) return (0); if (len == 1) From 2ab93b569e32013f4cba1e540aa87c2d4670369b Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 26 Aug 2023 17:21:23 -0500 Subject: [PATCH 06/13] fix 'possible loss of data' warnings with explicit types and conversions --- line.c | 2 +- search.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/line.c b/line.c index c2c06ba..c4c32b4 100644 --- a/line.c +++ b/line.c @@ -458,7 +458,7 @@ pwidth(ch, a, prev_ch, prev_a) * Backspace moves backwards one or two positions. */ if (prev_a & (AT_ANSI|AT_BINARY)) - return strlen(prchar('\b')); + return (int)strlen(prchar('\b')); return (utf_mode && is_wide_char(prev_ch)) ? -2 : -1; } diff --git a/search.c b/search.c index d80ad95..4cd4d4d 100644 --- a/search.c +++ b/search.c @@ -1454,8 +1454,8 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla */ if (sp != NULL && ep != NULL) { - int start_off = sp - cline; - int end_off = ep - cline; + POSITION start_off = (POSITION)(sp - cline); + POSITION end_off = (POSITION)(ep - cline); int save_hshift = hshift; int sshift; int eshift; @@ -1485,7 +1485,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos, pla */ if (ep != NULL) { - int end_off = ep - cline; + POSITION end_off = (POSITION)(ep - cline); if (end_off >= swidth * sheight / 4) /* heuristic */ *plastlinepos = get_lastlinepos(linepos, linepos + chpos[end_off], sheight); } From 9bcd52f65a855a491e5ad980c96e680baaf4d077 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 5 Oct 2023 16:45:36 -0500 Subject: [PATCH 07/13] fix compiler warning (i586-pc-msdosdjgpp-gcc; -Werror=maybe-uninitialized) --- filename.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filename.c b/filename.c index 82b0aeb..c8b6501 100644 --- a/filename.c +++ b/filename.c @@ -635,8 +635,8 @@ lglob(filename) * The globbing function returns a list of names. */ int length; - char *p; - char *qfilename; + char *p = 0; + char *qfilename = 0; DECL_GLOB_LIST(list) GLOB_LIST(filename, list); From 4657d2d50269a2c47938871beaa37342c352db76 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 5 Oct 2023 17:01:46 -0500 Subject: [PATCH 08/13] fix compiler link error (i586-pc-msdosdjgpp-gcc; missing 'vt_enabled') --- output.c | 2 +- screen.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/output.c b/output.c index 9c4693f..51f7f76 100644 --- a/output.c +++ b/output.c @@ -40,7 +40,7 @@ extern int ul_fg_color, ul_bg_color; extern int so_fg_color, so_bg_color; extern int bl_fg_color, bl_bg_color; extern int sgr_mode; -#if MSDOS_COMPILER==WIN32C +#if MSDOS_COMPILER==WIN32C || MSDOS_COMPILER==DJGPPC extern int vt_enabled; #endif #endif diff --git a/screen.c b/screen.c index 3913bf0..43cb2bd 100644 --- a/screen.c +++ b/screen.c @@ -185,6 +185,8 @@ static int sy_bg_color; public int sgr_mode; /* Honor ANSI sequences rather than using above */ #if MSDOS_COMPILER==WIN32C static DWORD init_output_mode; /* The initial console output mode */ +#endif +#if MSDOS_COMPILER==WIN32C || MSDOS_COMPILER==DJGPPC public int vt_enabled = -1; /* Is virtual terminal processing available? */ #endif #else From f3c15eb76516dd449d7b9417b1d4e906b407db06 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 26 Aug 2023 17:43:20 -0500 Subject: [PATCH 09/13] maint/CI ~ update `outputs()` function --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 1f8b533..d00caf2 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -55,7 +55,7 @@ jobs: run: | ## VARs setup log() { for var in "$@" ; do echo ${var}="${!var}"; done; } - outputs() { for var in "$@" ; do echo steps.vars.outputs.${var}="${!var}"; echo ::set-output name=${var}::${!var}; done; } + outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; } # staging directory STAGING='_staging' outputs STAGING From 11c2be8582a2adcc1320144a8ebb1b3ad2655697 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 26 Aug 2023 17:46:53 -0500 Subject: [PATCH 10/13] maint/CI ~ terminate outdated-but-executing workflows (for non-default branches) --- .github/workflows/CICD.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index d00caf2..3119f0b 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -18,6 +18,13 @@ env: on: [push, pull_request] +# terminate execution of the current workflow group when there is a newer changeset detected +# * the group is defined by "WORKFLOW_NAME-REF", where REF can be a branch, tag, or pull-request reference +# * workflows executing for the default branch are excluded from termination +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }} + jobs: build: name: Build From f643ee9dcd61508f1cd3bc6e196af416cdd44508 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Mon, 14 Nov 2022 09:54:17 -0600 Subject: [PATCH 11/13] maint/dev ~ (VSCode) update debug configuration for enhanced Makefile debug support --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ba91353..233e839 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "type": "cppdbg", "request": "launch", "program": "${fileWorkspaceFolder}/${config:project.build_dir}/debug-x32/executable.exe", - "args": [], // * note: use this configuration array to add run-time arguments to the debugged process + "args": ["main.c"], // * note: use this configuration array to add run-time arguments to the debugged process // "args": ["/?"], // * note: use this configuration array to add run-time arguments to the debugged process // "args": ["${fileWorkspaceFolder}/../causes-fault-single-line.txt"], "stopAtEntry": false, From 7554135eb8764685fe9a1c603894b8fe17446e80 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Mon, 14 Nov 2022 09:58:15 -0600 Subject: [PATCH 12/13] maint/dev ~ update gitignore --- .gitignore | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 29e502d..f401759 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -# v2022-08-26+less-mods [rivy] +# v2022-08-27 [rivy] +# + local-start/end mods for `less` # NOTE: Git GLOBSTAR syntax [see `git help gitignore`] # * ref: [.gitignore] http://git-scm.com/docs/gitignore @@ http://archive.is/Rk6rO @@ -19,13 +20,14 @@ node_modules package-lock.json yarn.lock -# ignore localized VSCode logs/settings +# ignore local-only VSCode artifacts +# * logs/settings .vscode/c_cpp_properties.json .vscode/makefile.extension.output -# * ignore VSCode precompiled headers for IntelliSense +# * precompiled headers for IntelliSense .vscode/ipch/ -## local additions ## +#!local-start # `less` ~ most older Makefiles still generate artifacts *within* the source code folder @@ -44,3 +46,5 @@ defines.h # * object files *.o *.obj + +#!local-end From fbb43c67bb62aca7a0170a07427ee8296a9a10f0 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 5 Oct 2023 10:28:45 -0500 Subject: [PATCH 13/13] maint/build ~ (Makefile.win) update (v2023.10.09); fixes and refine - fix 'define.h' update logic - multiple other small fixes - improved robustness of shell environment variable handling - feedback display improvements - improved separation of concerns for shell command functions - revised function names for better clarity - DRY improvements - commentary polish - improve correspondence between Makefile types (ie, CC vs Go) --- Makefile.win | 242 ++++++++++++++++++++++++++------------------ Makefile.win.target | 37 ++++++- 2 files changed, 180 insertions(+), 99 deletions(-) diff --git a/Makefile.win b/Makefile.win index 441b52a..b26d8cb 100644 --- a/Makefile.win +++ b/Makefile.win @@ -1,9 +1,9 @@ -# Makefile (C/C++; OOS-build support; gmake-form/style; v2022.10.05) +# Makefile (C/C++; OOS-build support; gmake-form/style; v2023.10.09) # Cross-platform (bash/sh + CMD/PowerShell) # `bcc32`, `cl`, `clang`, `embcc32`, and `gcc` (defaults to `CC=clang`) # * supports multi-binary projects; adapts to project structure # GNU make (gmake) compatible; ref: -# Copyright (C) 2020-2022 ~ Roy Ivy III ; MIT+Apache-2.0 license +# Copyright (C) 2020-2023 ~ Roy Ivy III ; MIT+Apache-2.0 license # NOTE: * requires `make` version 4.0+ (minimum needed for correct path functions); for windows, install using `scoop install make` # NOTE: `make` doesn't handle spaces within file names without gyrations (see @@) @@ -29,7 +29,8 @@ # spell-checker:ignore (abbrev/acronyms) LCID LCIDs LLVM MSVC MinGW MSDOS POSIX VCvars WinMain # spell-checker:ignore (jargon) autoset deps depfile depfiles delims executables maint multilib # spell-checker:ignore (libraries) advapi crtl libcmt libcmtd libgcc libstdc lmsvcrt lmsvcrtd lstdc stdext wsock -# spell-checker:ignore (names) benhoyt rivy Borland Deno Watcom +# spell-checker:ignore (names) Borland Deno DosBox Watcom +# spell-checker:ignore (people) benhoyt rivy # spell-checker:ignore (shell/nix) mkdir printf rmdir uname # spell-checker:ignore (shell/win) COMSPEC SystemDrive SystemRoot findstr findstring mkdir windir # spell-checker:ignore (utils) goawk ilink windres vcpkg @@ -89,9 +90,10 @@ OSID := $(or $(and $(filter .exe,$(patsubst %.exe,.exe,$(subst $() $(),_,${SHELL # for Windows OS, set SHELL to `%ComSpec%` or `cmd` (note: environment/${OS}=="Windows_NT" for XP, 2000, Vista, 7, 10 ...) # * `make` may otherwise use an incorrect shell (eg, `bash`), if found; "syntax error: unexpected end of file" error output is indicative ifeq (${OSID},win) -# use case and location fallbacks; note: assumes *no spaces* within the path values specified by ${ComSpec}, ${SystemRoot}, or ${windir} -COMSPEC := $(or ${ComSpec},${COMSPEC},${comspec}) -SystemRoot := $(or ${SystemRoot},${SYSTEMROOT},${systemroot},${windir}) +# use fallbacks, avoiding env var case variance issues; note: assumes *no spaces* within the path values specified by ${ComSpec}, ${SystemRoot}, or ${windir} +COMSPEC := $(strip $(shell echo %ComSpec%)) +HOME := $(or $(strip $(shell echo %HOME%)),$(strip $(shell echo %UserProfile%))) +SystemRoot := $(or $(strip $(shell echo %SystemRoot%)),$(strip $(shell echo %windir%))) SHELL := $(firstword $(wildcard ${COMSPEC} ${SystemRoot}/System32/cmd.exe) cmd) endif @@ -219,22 +221,34 @@ SPACE := $() $() # %all_gui = $(call %all,%is_gui,${1}) ifeq (${OSID},win) -%rm_dir = $(shell if EXIST $(call %as_win_path,${1}) ${RMDIR} $(call %as_win_path,${1}) >${devnull} 2>&1 && ${ECHO} ${true}) -%rm_file = $(shell if EXIST $(call %as_win_path,${1}) ${RM} $(call %as_win_path,${1}) >${devnull} 2>&1 && ${ECHO} ${true}) -%rm_file_globset = $(shell for %%G in ($(call %as_win_path,${1})) do ${RM} "%%G" >${devnull} 2>&1 && ${ECHO} ${true}) +%mkdir_shell_s = (if NOT EXIST $(call %shell_escape,$(call %as_win_path,${1})) ${MKDIR} $(call %shell_escape,$(call %as_win_path,${1})) >${devnull} 2>&1 && ${ECHO} ${true}) else -%rm_dir = $(shell ls -d ${1} >${devnull} 2>&1 && { ${RMDIR} ${1} >${devnull} 2>&1 && ${ECHO} ${true}; } || true) -%rm_file = $(shell ls -d ${1} >${devnull} 2>&1 && { ${RM} ${1} >${devnull} 2>&1 && ${ECHO} ${true}; } || true) -%rm_file_globset = $(shell for file in ${1}; do ls -d "$${file}" >${devnull} 2>&1 && ${RM} "$${file}"; done && ${ECHO} "${true}"; done) +%mkdir_shell_s = (${MKDIR} $(call %shell_escape,${1}) >${devnull} 2>&1 && ${ECHO} ${true}) endif +%mkdir = $(shell $(call %mkdir_shell_s,${1})) + +# * `rm` shell commands; note: return `${true}` result when argument (`${1}`) is successfully removed (to support verbose feedback display) +ifeq (${OSID},win) +%rm_dir_shell_s = (if EXIST $(call %shell_quote,$(call %as_win_path,${1})) ${RMDIR} $(call %shell_quote,$(call %as_win_path,${1})) >${devnull} 2>&1 && ${ECHO} ${true}) +%rm_file_shell_s = (if EXIST $(call %shell_quote,$(call %as_win_path,${1})) ${RM} $(call %shell_quote,$(call %as_win_path,${1})) >${devnull} 2>&1 && ${ECHO} ${true}) +%rm_file_globset_shell_s = (for %%G in $(call %shell_quote,($(call %as_win_path,${1}))) do ${RM} "%%G" >${devnull} 2>&1 && ${ECHO} ${true}) +else +%rm_dir_shell_s = (ls -d $(call %shell_escape,${1}) >${devnull} 2>&1 && { ${RMDIR} $(call %shell_escape,${1}) >${devnull} 2>&1 && ${ECHO} ${true}; } || true) +%rm_file_shell_s = (ls -d $(call %shell_escape,${1}) >${devnull} 2>&1 && { ${RM} $(call %shell_escape,${1}) >${devnull} 2>&1 && ${ECHO} ${true}; } || true) +%rm_file_globset_shell_s = (for file in $(call %shell_escape,${1}); do ls -d "$${file}" >${devnull} 2>&1 && ${RM} "$${file}"; done && ${ECHO} "${true}"; done) +endif + +%rm_dir = $(shell $(call %rm_dir_shell_s,${1})) +%rm_file = $(shell $(call %rm_file_shell_s,${1})) +%rm_file_globset = $(shell $(call %rm_file_globset_shell_s,${1})) %rm_dirs = $(strip $(call %map,%rm_dir,${1})) -%rm_dirs_verbose = $(strip $(call %map,$(eval %f=$$(if $$(call %rm_dir,$${1}),$$(call %info,$${1} removed),))%f,${1})) +%rm_dirs_verbose = $(strip $(call %map,$(eval %f=$$(if $$(call %rm_dir,$${1}),$$(call %info,'$${1}' removed.),))%f,${1})) %rm_files = $(strip $(call %map,%rm_file,${1})) -%rm_files_verbose = $(strip $(call %map,$(eval %f=$$(if $$(call %rm_file,$${1}),$$(call %info,$${1} removed),))%f,${1})) +%rm_files_verbose = $(strip $(call %map,$(eval %f=$$(if $$(call %rm_file,$${1}),$$(call %info,'$${1}' removed.),))%f,${1})) %rm_file_globsets = $(strip $(call %map,%rm_file_globset,${1})) -%rm_file_globsets_verbose = $(strip $(call %map,$(eval %f=$$(if $$(call %rm_file_globset,$${1}),$$(call %info,$${1} removed),))%f,${1})) +%rm_file_globsets_verbose = $(strip $(call %map,$(eval %f=$$(if $$(call %rm_file_globset,$${1}),$$(call %info,'$${1}' removed.),))%f,${1})) -%rm_dirs_verbose_cli = $(call !shell_noop,$(call %rm_dirs_verbose,${1})) +# %rm_dirs_verbose_cli = $(call !shell_noop,$(call %rm_dirs_verbose,${1})) ifeq (${OSID},win) %shell_escape = $(call %tr,^ | < > %,^^ ^| ^< ^> ^%,${1}) @@ -250,12 +264,13 @@ endif # ref: @@ ifeq (${OSID},win) -%touch_cli = type NUL >> $(call %as_win_path,${1}) & copy >NUL /B $(call %as_win_path,${1}) +,, $(call %as_win_path,${1}) +%touch_shell_s = type NUL >> $(call %shell_quote,$(call %as_win_path,${1})) & copy >NUL /B $(call %shell_quote,$(call %as_win_path,${1})) +,, $(call %shell_quote,$(call %as_win_path,${1})) else -%touch_cli = touch ${1} +%touch_shell_s = touch $(call %shell_quote,${1}) endif +%touch = $(shell $(call %touch_shell_s,${1})) -@mkdir_rule = ${1} : ${2} ; ${MKDIR} $(call %shell_quote,$$@) +@mkdir_rule = ${1} : ${2} ; @${MKDIR} $(call %shell_quote,$$@) >${devnull} 2>&1 && ${ECHO} $(call %shell_escape,$(call %info_text,created '$$@'.)) !shell_noop = ${ECHO} >${devnull} @@ -319,23 +334,25 @@ OSID_name := windows OS_PREFIX := win. EXEEXT := ${EXEEXT_win} # -AWK := gawk ## from `scoop install gawk`; or "goawk" from `go get github.com/benhoyt/goawk` -CAT := "${SystemRoot}\System32\findstr" /r .* +AWK := gawk## from `scoop install gawk`; or "goawk" from `go get github.com/benhoyt/goawk` +CAT := "${SystemRoot}\System32\findstr" /r .*## note: (unlike `type`) will read from STDIN; BUT with multiple file arguments, this will prefix each line with the file name CP := copy /y ECHO := echo -GREP := grep ## from `scoop install grep` +GREP := grep## from `scoop install grep` MKDIR := mkdir RM := del -RM_r := $(RM) /s +RM_r := ${RM} /s RMDIR := rmdir /s/q +RMDIR_f := rmdir /s/q FIND := "${SystemRoot}\System32\find" FINDSTR := "${SystemRoot}\System32\findstr" MORE := "${SystemRoot}\System32\more" SORT := "${SystemRoot}\System32\sort" -TYPE := type +TYPE := type## note: will not read from STDIN unless invoked as `${TYPE} CON` WHICH := where # ECHO_newline := echo. +shell_true := cd . else OSID_name ?= $(shell uname | tr '[:upper:]' '[:lower:]') OS_PREFIX := ${OSID_name}. @@ -350,29 +367,14 @@ MKDIR := mkdir -p RM := rm RM_r := ${RM} -r RMDIR := ${RM} -r +RMDIR_f := ${RM} -rf SORT := sort WHICH := which # ECHO_newline := echo +shell_true := true endif -# find/calculate best available `strip` -STRIP_check_flags := --version -# * calculate `strip`; general overrides for ${CC_ID} and ${OSID} -STRIP := $(or ${STRIP_CC_${CC_ID}_OSID_${OSID}},${STRIP_CC_${CC_ID}},${STRIP}) -# $(call %debug_var,STRIP) -# * available as ${CC}-prefixed variant? -STRIP_CC_${CC}_name := $(call %neq,${CC:-${CC_ID}=-strip},${CC}) -$(call %debug_var,STRIP_CC_${CC}_name) -STRIP_CC_${CC} := $(or ${STRIP_CC_${CC}},$(and ${STRIP_CC_${CC}_name},$(shell "${STRIP_CC_${CC}_name}" ${STRIP_check_flags} >${devnull} 2>&1 && echo ${STRIP_CC_${CC}_name}))) -$(call %debug_var,STRIP_CC_${CC}) -# * calculate `strip`; specific overrides for ${CC} -STRIP := $(or ${STRIP_CC_${CC}},${STRIP}) -# $(call %debug_var,STRIP) -# * and... ${STRIP} available? (missing in some distributions) -STRIP := $(shell "${STRIP}" ${STRIP_check_flags} >${devnull} 2>&1 && echo ${STRIP}) -$(call %debug_var,STRIP) - #### * `vcpkg` support (note: delayed expansion b/c of dependency on multiple later defined variables) ifneq (${VCPKG_ROOT},) @@ -727,6 +729,25 @@ OUT_obj_filesets := ${OUT_obj_filesets} $() *.obj *.ilc *.ild *.ilf *.ils *.tds# #### +## find/calculate best available `strip` +STRIP_check_flags := --version +# * calculate `strip`; general overrides for ${CC_ID} and ${OSID} +STRIP := $(or ${STRIP_CC_${CC_ID}_OSID_${OSID}},${STRIP_CC_${CC_ID}},${STRIP}) +# $(call %debug_var,STRIP) +# * available as ${CC}-prefixed variant? +STRIP_CC_${CC}_name := $(call %neq,${CC:-${CC_ID}=-strip},${CC}) +$(call %debug_var,STRIP_CC_${CC}_name) +STRIP_CC_${CC} := $(or ${STRIP_CC_${CC}},$(and ${STRIP_CC_${CC}_name},$(shell "${STRIP_CC_${CC}_name}" ${STRIP_check_flags} >${devnull} 2>&1 && echo ${STRIP_CC_${CC}_name}))) +$(call %debug_var,STRIP_CC_${CC}) +# * calculate `strip`; specific overrides for ${CC} +STRIP := $(or ${STRIP_CC_${CC}},${STRIP}) +# $(call %debug_var,STRIP) +# * and... ${STRIP} available? (missing in some distributions) +STRIP := $(shell "${STRIP}" ${STRIP_check_flags} >${devnull} 2>&1 && echo ${STRIP}) +# $(call %debug_var,STRIP) + +#### + $(call %debug_var,OSID) $(call %debug_var,SHELL) @@ -742,6 +763,7 @@ $(call %debug_var,CC) $(call %debug_var,CXX) $(call %debug_var,LD) $(call %debug_var,RC)## if $(), default/fixup later +$(call %debug_var,STRIP) $(call %debug_var,CFLAGS) $(call %debug_var,CPPFLAGS) $(call %debug_var,CXXFLAGS) @@ -775,7 +797,7 @@ REZ := $(or ${REZ_ext_${CC_ID}},res) $(call %debug_var,REZ) -#### End of compiler configuration section. #### +#### # NOTE: early configuration; must be done before ${CC_ID} (`clang`) is used as a linker (eg, during configuration) ifeq (${OSID},win) @@ -788,7 +810,9 @@ endif endif $(call %debug_var,LIB) -#### +#### End of compiler configuration section. #### + +#### * ensure `make` environment requirements # detect ${CC} ifeq (,$(shell "${CC}" ${CFLAGS_check} >${devnull} 2>&1 <${devnull} && echo ${CC} present)) @@ -799,10 +823,11 @@ ifeq (${SPACE},$(findstring ${SPACE},${makefile_abs_path})) $(call %error,'s within project directory path are not allowed)## `make` has very limited ability to quote characters endif -# # Since we rely on paths relative to the makefile location, abort if make isn't being run from there. -# ifneq (${makefile_dir},${current_dir}) -# $(call %error,Invalid current directory; this makefile must be invoked from the directory it resides in) -# endif +# use of BASEPATH allows `make -f ../Makefile ...`; no need for this error +## # since we rely on paths relative to the makefile location, abort if current directory != makefile directory +## ifneq ($(current_dir),$(makefile_dir)) +## $(call %error,Invalid current directory; this makefile must be invoked from the directory it resides in ('$(makefile_dir)')) +## endif #### @@ -935,7 +960,7 @@ $(call %debug_var,is_VC6) OUT_DIR_EXT := $(if $(call %is_truthy,${STATIC}),,.dynamic) ifeq (,${TARGET}) -OUT_DIR_EXT :=-x${ARCH_ID} +OUT_DIR_EXT := ${OUT_DIR_EXT}-x${ARCH_ID} RCFLAGS_TARGET := ${RCFLAGS_TARGET_${CC_ID}_ARCH_${ARCH_ID}} else CFLAGS_TARGET := --target=${TARGET} @@ -1082,18 +1107,26 @@ endif BUILD_DIR := ${BASEPATH}/$(or ${BUILD_PATH},${HASH}build)## note: `${HASH}build` causes issues with OpenWatcom-v2.0 [2020-09-01], but `${DOLLAR}build` causes variable expansion issues for VSCode debugging; note: 'target' is a common alternative -SRC_DIR := $(firstword $(wildcard $(foreach segment,${SRC_PATH} src source,${BASEPATH}/${segment}))) -SRC_DIR := ${SRC_DIR:/=} -SRC_DIR := ${SRC_DIR:./.=.} +$(call %debug_var,BUILD_DIR) CONFIG := $(if $(call %is_truthy,${DEBUG}),debug,release) -SRC_files := $(wildcard ${SRC_DIR}/*.c ${SRC_DIR}/*.cpp ${SRC_DIR}/*.cxx) +$(call %debug_var,CONFIG) + +SOURCE_dirs := src source +SOURCE_exts = *.c *.cc *.cpp *.cxx +HEADER_exts = *.h *.hh *.hpp *.hxx + +SRC_DIR := $(firstword $(wildcard $(foreach segment,${SRC_PATH} ${SOURCE_dirs},${BASEPATH}/${segment}))) +SRC_DIR := ${SRC_DIR:/=} +SRC_DIR := ${SRC_DIR:./.=.} + +SRC_files := $(wildcard $(foreach elem,${SOURCE_exts},${SRC_DIR}/${elem})) $(call %debug_var,SRC_DIR) $(call %debug_var,SRC_files) -OUT_DIR := ${BUILD_DIR}/${OS_PREFIX}${CONFIG}$(if $(call %is_truthy,${STATIC}),,.dynamic).(${CC}@${CC_version_Mm})${OUT_DIR_EXT} +OUT_DIR := ${BUILD_DIR}/${OS_PREFIX}${CONFIG}.(${CC}@${CC_version_Mm})${OUT_DIR_EXT} OUT_DIR_bin := ${OUT_DIR}/bin OUT_DIR_obj := ${OUT_DIR}/obj OUT_DIR_targets := ${OUT_DIR}/targets @@ -1110,9 +1143,9 @@ BIN_DIR := $(firstword $(wildcard $(foreach segment,bin bins,${SRC_DIR}/${segmen BIN_DIR_filename := $(notdir ${BIN_DIR}) BIN_OUT_DIR_bin := $(and ${BIN_DIR},${OUT_DIR_bin}) BIN_OUT_DIR_obj := $(and ${BIN_DIR},${OUT_DIR_obj}.${BIN_DIR_filename}) -BIN_SRC_files := $(and ${BIN_DIR},$(wildcard ${BIN_DIR}/*.c ${BIN_DIR}/*.cpp ${BIN_DIR}/*.cxx)) -BIN_SRC_sup_files := $(and ${BIN_DIR},$(call %recursive_wildcard,$(patsubst %/,%,$(call %dirs,${BIN_DIR})),*.c *.cpp *.cxx)) -BIN_deps := $(and ${BIN_DIR},$(call %recursive_wildcard,${BIN_DIR},*.h *.hpp *.hxx)) +BIN_SRC_files := $(and ${BIN_DIR},$(wildcard $(foreach elem,${SOURCE_exts},${BIN_DIR}/${elem}))) +BIN_SRC_sup_files := $(and ${BIN_DIR},$(call %recursive_wildcard,$(patsubst %/,%,$(call %dirs,${BIN_DIR})),${SOURCE_exts})) +BIN_deps := $(and ${BIN_DIR},$(call %recursive_wildcard,${BIN_DIR},${HEADER_exts})) BIN_OBJ_files := $(foreach file,$(strip ${BIN_SRC_files}),$(basename $(patsubst ${BIN_DIR}/%,${BIN_OUT_DIR_obj}/%,${file})).${O}) BIN_OBJ_sup_files := $(foreach file,${BIN_SRC_sup_files},$(basename $(patsubst ${BIN_DIR}/%,${BIN_OUT_DIR_obj}/%,${file})).${O}) BIN_RES_files := $(call %recursive_wildcard,${BIN_DIR},*.rc)## resource files @@ -1134,7 +1167,7 @@ $(call %debug_var,BIN_RES_files) $(call %debug_var,BIN_REZ_files) $(call %debug_var,BIN_cflags_includes) -SRC_sup_files := $(filter-out ${BIN_SRC_files} ${BIN_SRC_sup_files},$(call %recursive_wildcard,$(patsubst %/,%,$(call %dirs_in,${SRC_DIR})),*.c *.cpp *.cxx))## supplemental source files (eg, common or library code) +SRC_sup_files := $(filter-out ${BIN_SRC_files} ${BIN_SRC_sup_files},$(call %recursive_wildcard,$(patsubst %/,%,$(call %dirs_in,${SRC_DIR})),${SOURCE_exts}))## supplemental source files (eg, common or library code) $(call %debug_var,SRC_sup_files) @@ -1156,7 +1189,7 @@ $(call %debug_var,OBJ_sup_files) DEP_files := $(wildcard $(OBJ_files:%.${O}=%.${D})) # DEPS := $(%strip_leading_dotslash,${DEPS}) -OBJ_deps := $(strip $(or ${DEPS},$(if ${DEP_files},$(),$(filter ${BIN_deps},$(call %recursive_wildcard,${SRC_DIR},*.h *.hpp *.hxx)))))## common/shared dependencies (fallback to SRC_DIR header files) +OBJ_deps := $(strip $(or ${DEPS},$(if ${DEP_files},$(),$(filter ${BIN_deps},$(call %recursive_wildcard,${SRC_DIR},${HEADER_exts})))))## common/shared dependencies (fallback to SRC_DIR header files) $(call %debug_var,DEP_files) $(call %debug_var,DEPS) @@ -1175,9 +1208,9 @@ EG_DIR := $(firstword $(wildcard $(foreach segment,eg egs ex exs example example EG_DIR_filename := $(notdir ${EG_DIR}) EG_OUT_DIR_bin := $(and ${EG_DIR},${OUT_DIR}/${EG_DIR:${BASEPATH}/%=%}) EG_OUT_DIR_obj := $(and ${EG_DIR},${OUT_DIR_obj}.${EG_DIR_filename}) -EG_SRC_files := $(and ${EG_DIR},$(wildcard ${EG_DIR}/*.c ${EG_DIR}/*.cpp ${EG_DIR}/*.cxx)) -EG_SRC_sup_files := $(and ${EG_DIR},$(call %recursive_wildcard,$(patsubst %/,%,$(call %dirs,${EG_DIR})),*.c *.cpp *.cxx)) -EG_deps := $(and ${EG_DIR},$(call %recursive_wildcard,${EG_DIR},*.h *.hpp *.hxx)) +EG_SRC_files := $(and ${EG_DIR},$(wildcard $(foreach elem,${SOURCE_exts},${EG_DIR}/${elem}))) +EG_SRC_sup_files := $(and ${EG_DIR},$(call %recursive_wildcard,$(patsubst %/,%,$(call %dirs,${EG_DIR})),${SOURCE_exts})) +EG_deps := $(and ${EG_DIR},$(call %recursive_wildcard,${EG_DIR},${HEADER_exts})) EG_OBJ_files := $(foreach file,$(strip ${EG_SRC_files}),$(basename $(patsubst ${EG_DIR}/%,${EG_OUT_DIR_obj}/%,${file})).${O}) EG_OBJ_sup_files := $(foreach file,${EG_SRC_sup_files},$(basename $(patsubst ${EG_DIR}/%,${EG_OUT_DIR_obj}/%,${file})).${O}) EG_RES_files := $(call %recursive_wildcard,${EG_DIR},*.rc)## resource files @@ -1206,9 +1239,9 @@ TEST_DIR := $(firstword $(wildcard $(foreach segment,t test tests,${BASEPATH}/${ TEST_DIR_filename := $(notdir ${TEST_DIR}) TEST_OUT_DIR_bin := $(and ${TEST_DIR},${OUT_DIR}/${TEST_DIR:${BASEPATH}/%=%}) TEST_OUT_DIR_obj := $(and ${TEST_DIR},${OUT_DIR_obj}.$(notdir ${TEST_DIR})) -TEST_SRC_files := $(and ${TEST_DIR},$(wildcard ${TEST_DIR}/*.c ${TEST_DIR}/*.cpp ${TEST_DIR}/*.cxx)) -TEST_SRC_sup_files := $(and ${TEST_DIR},$(call %recursive_wildcard,$(patsubst %/,%,$(call %dirs_in,${TEST_DIR})),*.c *.cpp *.cxx)) -TEST_deps := $(and ${TEST_DIR},$(call %recursive_wildcard,${TEST_DIR},*.h *.hpp *.hxx)) +TEST_SRC_files := $(and ${TEST_DIR},$(wildcard $(foreach elem,${SOURCE_exts},${TEST_DIR}/${elem}))) +TEST_SRC_sup_files := $(and ${TEST_DIR},$(call %recursive_wildcard,$(patsubst %/,%,$(call %dirs_in,${TEST_DIR})),${SOURCE_exts})) +TEST_deps := $(and ${TEST_DIR},$(call %recursive_wildcard,${TEST_DIR},${HEADER_exts})) TEST_OBJ_files := $(foreach file,$(strip ${TEST_SRC_files}),$(basename $(patsubst ${TEST_DIR}/%,${TEST_OUT_DIR_obj}/%,${file})).${O}) TEST_OBJ_sup_files := $(foreach file,${TEST_SRC_sup_files},$(basename $(patsubst ${TEST_DIR}/%,${TEST_OUT_DIR_obj}/%,${file})).${O}) TEST_RES_files := $(call %recursive_wildcard,${TEST_DIR},*.rc)## resource files @@ -1235,7 +1268,6 @@ $(call %debug_var,TEST_cflags_includes) #### -DEFAULT_TARGET := ${OUT_DIR_bin}/${NAME}${EXEEXT} PROJECT_TARGET := ${OUT_DIR_bin}/${NAME}${EXEEXT} .DEFAULT_GOAL := $(if ${SRC_files},${PROJECT_TARGET},$(if ${BIN_SRC_files},bins,all))# *default* target @@ -1300,9 +1332,8 @@ all_phony_targets += $() #### ifneq (${NULL},$(filter-out all bins,${.DEFAULT_GOAL}))## define 'run' target only for real executable targets (ignore 'all' or 'bins') -.PHONY: run all_phony_targets += run -run: ${.DEFAULT_GOAL} ## Build/execute project executable (for ARGS, use `-- [ARGS]` or `ARGS="..."`) +run: ${.DEFAULT_GOAL} ## Build and execute project executable (for ARGS, use `-- [ARGS]` or `ARGS="..."`) @$(strip ${RUNNER} $(call %shell_quote,$^)) ${ARGS} endif @@ -1311,7 +1342,7 @@ ifeq (${false},${has_run_first})## define standard phony targets only when 'run' #### ifeq (${OSID},win) -shell_filter_targets := ${FINDSTR} "." +shell_filter_targets := ${FINDSTR} -rc:"^[a-zA-Z][^: ]*:[^=].*${HASH}${HASH}" shell_filter_targets := $(strip ${shell_filter_targets} $(and $(filter all bins,${.DEFAULT_GOAL}), | ${FINDSTR} -v "^run:")) shell_filter_targets := $(strip ${shell_filter_targets} $(if ${SRC_files}${BIN_SRC_files}${EG_SRC_files}${TEST_SRC_files},, | ${FINDSTR} -v "^all:")) shell_filter_targets := $(strip ${shell_filter_targets} $(if ${SRC_files}${BIN_SRC_files}${EG_SRC_files}${TEST_SRC_files},, | ${FINDSTR} -v "^debug:")) @@ -1323,7 +1354,7 @@ shell_filter_targets := $(strip ${shell_filter_targets} $(and $(call %not,${EG_S shell_filter_targets := $(strip ${shell_filter_targets} $(and $(call %not,${TEST_SRC_files}), | ${FINDSTR} -v "^test:")) shell_filter_targets := $(strip ${shell_filter_targets} $(and $(call %not,${TEST_SRC_files}), | ${FINDSTR} -v "^tests:")) else -shell_filter_targets := ${GREP} -P "." +shell_filter_targets := ${GREP} -P '(?i)^[[:alpha:]][^:\s]*:[^=].*${HASH}${HASH}' shell_filter_targets := $(strip ${shell_filter_targets} $(and $(filter all bins,${.DEFAULT_GOAL}), | ${GREP} -Pv "^run:")) shell_filter_targets := $(strip ${shell_filter_targets} $(if ${SRC_files}${BIN_SRC_files}${EG_SRC_files}${TEST_SRC_files},, | ${GREP} -Pv "^all:")) shell_filter_targets := $(strip ${shell_filter_targets} $(if ${SRC_files}${BIN_SRC_files}${EG_SRC_files}${TEST_SRC_files},, | ${GREP} -Pv "^debug:")) @@ -1335,13 +1366,13 @@ shell_filter_targets := $(strip ${shell_filter_targets} $(and $(call %not,${EG_S shell_filter_targets := $(strip ${shell_filter_targets} $(and $(call %not,${TEST_SRC_files}), | ${GREP} -Pv "^test:")) shell_filter_targets := $(strip ${shell_filter_targets} $(and $(call %not,${TEST_SRC_files}), | ${GREP} -Pv "^tests:")) endif +$(call %debug_var,shell_filter_targets) -.PHONY: help all_phony_targets += help help: ## Display help @${ECHO} $(call %shell_escape,`${color_command}${make_invoke_alias}${color_reset}`) @${ECHO} $(call %shell_escape,Usage: `${color_command}${make_invoke_alias} [MAKE_TARGET...] [ARCH=32|64|..] [CC=cl|clang|gcc|..] [CC_DEFINES=] [DEBUG=] [STATIC=] [SUBSYSTEM=console|windows|..] [TARGET=..] [COLOR=] [MAKEFLAGS_debug=] [VERBOSE=]${color_reset}`) - @${ECHO} $(call %shell_escape,Builds $(if $(filter all bins,${.DEFAULT_GOAL}),'${color_target}${.DEFAULT_GOAL}${color_reset}' targets,"${color_target}$(call %strip_leading_dotslash,${.DEFAULT_GOAL})${color_reset}") within "${color_path}$(call %strip_leading_dotslash,${current_dir})${color_reset}") + @${ECHO} $(call %shell_escape,Builds $(if $(filter all bins,${.DEFAULT_GOAL}),'${color_target}${.DEFAULT_GOAL}${color_reset}' targets,'${color_target}$(call %strip_leading_dotslash,${.DEFAULT_GOAL})${color_reset}') within '${color_path}$(call %strip_leading_dotslash,${current_dir})${color_reset}') ifeq (,${SRC_files}${BIN_SRC_files}${EG_SRC_files}${TEST_SRC_files}) @${ECHO} $(call %shell_escape,$(call %info_text,Add files to project to enable more MAKEFILE_TARGETs.)) endif @@ -1361,48 +1392,51 @@ endif @${ECHO} $(call %shell_escape,MAKE_TARGETs:) @${ECHO_newline} ifeq (${OSID},win) - @${TYPE} $(call %map,%shell_quote,${makefile_set}) 2>${devnull} | ${FINDSTR} "^[a-zA-Z-]*:.*${HASH}${HASH}" | ${shell_filter_targets} | ${SORT} | for /f "tokens=1-2,* delims=:${HASH}" %%g in ('${MORE}') do @(@call set "t=%%g " & @call echo ${color_success}%%t:~0,15%%${color_reset} ${color_info}%%i${color_reset}) + @${TYPE} $(call %map,%shell_quote,${makefile_set}) 2>${devnull} | ${shell_filter_targets} | ${SORT} | for /f "tokens=1-2,* delims=:${HASH}" %%g in ('${MORE}') do @(@call set "t=%%g " & @call echo ${color_success}%%t:~0,15%%${color_reset} ${color_info}%%i${color_reset}) else - @${CAT} $(call %map,%shell_quote,${makefile_set}) | ${GREP} -P "(?i)^[[:alpha:]-]+:" | ${shell_filter_targets} | ${SORT} | ${AWK} 'match($$0,"^([[:alpha:]]+):.*?${HASH}${HASH}\\s*(.*)$$",m){ printf "${color_success}%-10s${color_reset}\t${color_info}%s${color_reset}\n", m[1], m[2] }END{printf "\n"}' + @${CAT} $(call %map,%shell_quote,${makefile_set}) | ${shell_filter_targets} | ${SORT} | ${AWK} 'match($$0,"^([^:]+):.*?${HASH}${HASH}\\s*(.*)$$",m){ printf "${color_success}%-10s${color_reset}\t${color_info}%s${color_reset}\n", m[1], m[2] }END{}' endif #### -.PHONY: clean -all_phony_targets += clean -clean: ## Remove build artifacts (for the active configuration, including intermediate artifacts) -# * note: filter-out to avoid removing main directory - @$(call %rm_dirs_verbose_cli,$(call %map,%shell_quote,$(filter-out ${DOT},${out_dirs}))) +all_phony_targets += clean realclean -.PHONY: realclean -all_phony_targets += realclean -realclean: ## Remove *all* build artifacts (includes all configurations and the build directory) -# * note: 'clean' is not needed as a dependency b/c `${BUILD_DIR}` contains *all* build and intermediate artifacts - @$(call %rm_dirs_verbose_cli,$(call %shell_quote,$(filter-out ${DOT},${BUILD_DIR}))) +clean: ## Remove build artifacts (for the active configuration; includes intermediate files) +# * notes: avoid removing the main directory and filter-out directories which are obviously invalid + @$(call !shell_noop,::note ~ pre-executed call::$(call %rm_dirs_verbose,$(filter-out filter-out ${DOT} ${DOT}${DOT} ${SLASH} ${BACKSLASH},${out_dirs}))) + +realclean: clean ## Remove *all* build artifacts (including all configurations and the build directory) +ifeq ($(filter-out ${DOT} ${DOT}${DOT} ${SLASH} ${BACKSLASH},${BUILD_DIR}),) + @${ECHO} $(call %failure,'realclean' is unavailable for the current build directory ('${BUILD_DIR}').) +else + @$(call !shell_noop,::note ~ pre-executed call::$(call %rm_dirs_verbose,${BUILD_DIR})) +endif #### -.PHONY: all build compile rebuild -all_phony_targets += all build compile rebuild -all: $(if $(filter all,${.DEFAULT_GOAL}),,build) $(if ${BIN_SRC_files},bins,$()) $(if ${EG_SRC_files},examples,$()) $(if ${TEST_SRC_files},tests,$()) ## Build all project targets +all_phony_targets += build rebuild + build: ${.DEFAULT_GOAL} ## Build project -compile: ${OBJ_files} ${OBJ_sup_files} $(if $(filter all bins,${.DEFAULT_GOAL}),${BIN_OBJ_files} ${BIN_sup_files},) $(if $(filter all,${.DEFAULT_GOAL}),${EG_OBJ_files} ${EG_sup_files},)## Build intermediate targets rebuild: clean build ## Clean and re-build project #### +all_phony_targets += all compile + +all: $(if $(filter all,${.DEFAULT_GOAL}),,build) $(if ${BIN_SRC_files},bins,$()) $(if ${EG_SRC_files},examples,$()) $(if ${TEST_SRC_files},tests,$()) ## Build all project targets +compile: ${OBJ_files} ${OBJ_sup_files} $(if $(filter all bins,${.DEFAULT_GOAL}),${BIN_OBJ_files} ${BIN_sup_files},) $(if $(filter all,${.DEFAULT_GOAL}),${EG_OBJ_files} ${EG_sup_files},)## Build intermediate targets + +#### + ifneq (${NULL},${BIN_SRC_files})## define 'bins' target only when bin source files are found -.PHONY: bins all_phony_targets += bins bins: ${BIN_bin_files} ## Build extra project binaries endif ifneq (${NULL},${EG_SRC_files})## define 'examples' target only when examples source files are found -.PHONY: examples all_phony_targets += examples examples: ${EG_bin_files} ## Build project examples endif ifneq (${NULL},${TEST_SRC_files})## define 'test' and 'tests' targets only when test source files are found -.PHONY: test tests all_phony_targets += test tests test: tests $(addsuffix *[makefile.run]*,${TEST_bin_files}) ## Build/execute project tests tests: ${TEST_bin_files} ## Build project tests @@ -1410,7 +1444,6 @@ endif #### -.PHONY: debug ${DEBUG_TARGET} all_phony_targets += debug ${DEBUG_TARGET} debug: ${DEBUG_TARGET} ## Build a specific executable for debugging (use `DEBUG_FROM=...` to specify a specific source file) @@ -1430,7 +1463,7 @@ endif ## not ${has_run_first} #### -${NAME}: ${PROJECT_TARGET} +# ${NAME}: ${PROJECT_TARGET} ${PROJECT_TARGET}: ${OBJ_files} ${OBJ_sup_files} ${DEPS_common} ${DEPS_target} | ${OUT_DIR_bin} @$(if $(call %is_truthy,${VERBOSE}),${ECHO} $(call %shell_escape,$(call %info_text,'$@' is $(if $(call %is_gui,$@),GUI,console)-type.)),$(call !shell_noop)) $(call %link,${LDFLAGS},$(call %shell_quote,$@),$(call %map,%shell_quote,${OBJ_files} ${OBJ_sup_files} ${LINKS}),$(call %map,%shell_quote,${REZ_files}),$(call %LDX_flags,$(if $(call %is_gui,$@),windows,))) @@ -1442,6 +1475,9 @@ ${PROJECT_TARGET}: ${OBJ_files} ${OBJ_sup_files} ${DEPS_common} ${DEPS_target} | ${OUT_DIR_obj}/%.${O}: ${SRC_DIR}/%.c ${OBJ_deps} ${DEPS_common} | ${out_dirs} ${CC} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} $(call %shell_quote,$<) +${OUT_DIR_obj}/%.${O}: ${SRC_DIR}/%.cc ${OBJ_deps} ${DEPS_common} | ${out_dirs} + ${CXX} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${CXXFLAGS} $(call %shell_quote,$<) + ${OUT_DIR_obj}/%.${O}: ${SRC_DIR}/%.cpp ${OBJ_deps} ${DEPS_common} | ${out_dirs} ${CXX} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${CXXFLAGS} $(call %shell_quote,$<) @@ -1464,6 +1500,9 @@ ${BIN_OUT_DIR_bin}/%${EXEEXT}: ${BIN_OUT_DIR_obj}/%.${O} ${BIN_OBJ_sup_files} ${ ${BIN_OUT_DIR_obj}/%.${O}: ${BIN_DIR}/%.c ${BIN_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} ${CC} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${BIN_cflags_includes} $(call %shell_quote,$<) +${BIN_OUT_DIR_obj}/%.${O}: ${BIN_DIR}/%.cc ${BIN_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} + ${CXX} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${BIN_cflags_includes} ${CXXFLAGS} $(call %shell_quote,$<) + ${BIN_OUT_DIR_obj}/%.${O}: ${BIN_DIR}/%.cpp ${BIN_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} ${CXX} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${BIN_cflags_includes} ${CXXFLAGS} $(call %shell_quote,$<) @@ -1486,6 +1525,9 @@ ${EG_OUT_DIR_bin}/%${EXEEXT}: ${EG_OUT_DIR_obj}/%.${O} ${EG_OBJ_sup_files} ${EG_ ${EG_OUT_DIR_obj}/%.${O}: ${EG_DIR}/%.c ${EG_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} ${CC} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${EG_cflags_includes} $(call %shell_quote,$<) +${EG_OUT_DIR_obj}/%.${O}: ${EG_DIR}/%.cc ${EG_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} + ${CXX} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${EG_cflags_includes} ${CXXFLAGS} $(call %shell_quote,$<) + ${EG_OUT_DIR_obj}/%.${O}: ${EG_DIR}/%.cpp ${EG_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} ${CXX} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${EG_cflags_includes} ${CXXFLAGS} $(call %shell_quote,$<) @@ -1508,6 +1550,9 @@ ${TEST_OUT_DIR_bin}/%${EXEEXT}: ${TEST_OUT_DIR_obj}/%.${O} ${TEST_OBJ_sup_files} ${TEST_OUT_DIR_obj}/%.${O}: ${TEST_DIR}/%.c ${TEST_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} ${CC} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${TEST_cflags_includes} $(call %shell_quote,$<) +${TEST_OUT_DIR_obj}/%.${O}: ${TEST_DIR}/%.cc ${TEST_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} + ${CXX} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${TEST_cflags_includes} ${CXXFLAGS} $(call %shell_quote,$<) + ${TEST_OUT_DIR_obj}/%.${O}: ${TEST_DIR}/%.cpp ${TEST_deps} ${OBJ_deps} ${DEPS_common} | ${out_dirs} ${CXX} ${CC_o}$(call %shell_quote,$@) ${CFLAGS_COMPILE_ONLY} $(call %CPP_flags,$(if $(call %is_gui,$@),windows,)) ${CFLAGS} ${TEST_cflags_includes} ${CXXFLAGS} $(call %shell_quote,$<) @@ -1525,23 +1570,26 @@ ${DEBUG_TARGET}: ${DEBUG_OUT_FILE} @${CP} $(call %shell_quote,$(call %as_os_path,$<)) $(call %shell_quote,$(call %as_os_path,${DEBUG_TARGET})) >${devnull} @${ECHO} $(call %shell_escape,$(call %success_text,(re-)created '$(call %strip_leading_dotslash,${DEBUG_TARGET})'.)) -#### +#### * auxiliary/configuration rules -$(foreach dir,$(filter-out . ..,${out_dirs_for_rules}),$(eval $(call @mkdir_rule,${dir}))) +# * directory rules +# $(foreach dir,$(filter-out ${DOT} ${DOT}${DOT},${out_dirs_for_rules}),$(call %info,eval $(call @mkdir_rule,${dir}))) +$(foreach dir,$(filter-out ${DOT} ${DOT}${DOT},${out_dirs_for_rules}),$(eval $(call @mkdir_rule,${dir}))) -#### +# * all known phony targets +.PHONY: ${all_phony_targets} # suppress auto-deletion of intermediate files # ref: [`gmake` ~ removing intermediate files](https://stackoverflow.com/questions/47447369/gnu-make-removing-intermediate-files) @@ .SECONDARY: -#### +#### * final checks and hints ifeq (${NULL},$(or ${SRC_files},${BIN_SRC_files},${EG_SRC_files})) $(call %warning,no source files found; is `SRC_DIR` ('${SRC_DIR}') set correctly for the project?) endif -$(call %debug_var,NULL) +# $(call %debug_var,NULL) $(call %debug_var,has_runner_target) $(call %debug_var,all_phony_targets) $(call %debug_var,make_runner_ARGS) diff --git a/Makefile.win.target b/Makefile.win.target index 1e262df..eb352a6 100644 --- a/Makefile.win.target +++ b/Makefile.win.target @@ -1,4 +1,4 @@ -# spell-checker:ignore (make) EXEEXT addsuffix addprefix devnull falsey ; (names/vars) lessecho lesskey scrsize POSIX +# spell-checker:ignore (make) EXEEXT LDFLAGS SHELLSTATUS addsuffix addprefix devnull falsey ifeq ; (names/vars) msdosdjgpp lessecho lesskey scrsize OSID POSIX AUX_names := lessecho lesskey AUX_skips := scrsize## `scrsize` is POSIX only @@ -16,11 +16,42 @@ $(call %debug_var,OBJ_files) #### +# ref: @@ +# NOTE: after execution, ${.SHELLSTATUS} == 0 if files are identical; 1 if files are different; 2 if error +ifeq (${OSID},win) +%diff_shell_s = "${SystemRoot}\System32\fc" $(call %map,%shell_quote,$(call %map,%as_win_path,${1} ${2})) 2> ${devnull} +else +%diff_shell_s = diff ${1} ${2} 2> ${devnull} +endif + +#### + DEFINE_EXT := $(if $(filter-out i586-pc-msdosdjgpp-gcc,${CC}),wn,ds) +DEFINE_DIFFERS := ${false} +DEFINE_DIFF := $(shell $(call %diff_shell_s,${SRC_DIR}/defines.h,${SRC_DIR}/defines.${DEFINE_EXT})) +# * if ${.SHELLSTATUS} == 0, there is no difference (${DEFINE_DIFF} may contain other, extraneous, text) +# * if ${.SHELLSTATUS} == 1, then ${DEFINE_DIFF} contains the difference text +$(call %debug_var,.SHELLSTATUS) +ifeq (${.SHELLSTATUS},0) +DEFINE_DIFF := $() +else +DEFINE_DIFFERS := ${true} +endif +$(call %debug_var,DEFINE_EXT) +$(call %debug_var,DEFINE_DIFF) +$(call %debug_var,DEFINE_DIFFERS) + +ifneq (${DEFINE_DIFFERS},${false}) +$(call %rm_files,${SRC_DIR}/defines.h) +$(call %info,previous (incompatible) '${SRC_DIR}/defines.h' removed.) +endif + +#### + ${SRC_DIR}/defines.h: ${SRC_DIR}/defines.${DEFINE_EXT} $(filter-out ${SRC_DIR}/defines.h,${DEPS_common}) @${CP} $(call %map,%shell_quote,$(call %map,%as_win_path,$< $@)) >${devnull} - @$(call %touch,$(call %shell_quote,$@)) + @$(call %touch_shell_s,$(call %shell_quote,$@)) @${ECHO} $(call %shell_escape,$(call %info_text,created '$@' from '$<'.)) ${AUX_targets}: ${OUT_DIR_bin}/%${EXEEXT}: ${OUT_DIR_obj}/%.${O} ${OUT_DIR_obj}/version.${O} ${DEPS_common} | ${OUT_DIR_bin} @@ -31,5 +62,7 @@ ${AUX_targets}: ${OUT_DIR_bin}/%${EXEEXT}: ${OUT_DIR_obj}/%.${O} ${OUT_DIR_obj}/ #### all: aux + +all_phony_targets += aux # aux: build ${AUX_targets} ## Build auxillary executables (`lessecho` and `lesskey`) aux: ${AUX_targets} ## Build auxillary executables (`lessecho` and `lesskey`)