diff options
| -rw-r--r-- | Changes | 60 | ||||
| -rw-r--r-- | Makefile.in (renamed from Makefile) | 60 | ||||
| -rw-r--r-- | README | 28 | ||||
| -rw-r--r-- | README.md | 43 | ||||
| -rw-r--r-- | compat.c | 47 | ||||
| -rwxr-xr-x | configure | 333 | ||||
| -rw-r--r-- | ex.1 | 6 | ||||
| -rw-r--r-- | ex.c | 10 | ||||
| -rw-r--r-- | ex.h | 17 | ||||
| -rw-r--r-- | ex_cmds.c | 7 | ||||
| -rw-r--r-- | ex_cmds2.c | 9 | ||||
| -rw-r--r-- | ex_cmdsub.c | 27 | ||||
| -rw-r--r-- | ex_data.c | 92 | ||||
| -rw-r--r-- | ex_get.c | 9 | ||||
| -rw-r--r-- | ex_io.c | 66 | ||||
| -rw-r--r-- | ex_proto.h | 6 | ||||
| -rw-r--r-- | ex_put.c | 24 | ||||
| -rw-r--r-- | ex_re.c | 8 | ||||
| -rw-r--r-- | ex_set.c | 8 | ||||
| -rw-r--r-- | ex_subr.c | 97 | ||||
| -rw-r--r-- | ex_temp.c | 16 | ||||
| -rw-r--r-- | ex_tty.c | 15 | ||||
| -rw-r--r-- | ex_tty.c.orig | 405 | ||||
| -rw-r--r-- | ex_tty.h | 9 | ||||
| -rw-r--r-- | ex_unix.c | 10 | ||||
| -rw-r--r-- | ex_v.c | 6 | ||||
| -rw-r--r-- | ex_vadj.c | 18 | ||||
| -rw-r--r-- | ex_version.c | 4 | ||||
| -rw-r--r-- | ex_vget.c | 21 | ||||
| -rw-r--r-- | ex_vmain.c | 23 | ||||
| -rw-r--r-- | ex_voper.c | 9 | ||||
| -rw-r--r-- | ex_vops.c | 21 | ||||
| -rw-r--r-- | ex_vops2.c | 11 | ||||
| -rw-r--r-- | ex_vops3.c | 20 | ||||
| -rw-r--r-- | ex_vput.c | 13 | ||||
| -rw-r--r-- | ex_vwind.c | 4 | ||||
| -rw-r--r-- | expreserve.c | 12 | ||||
| -rw-r--r-- | exrecover.c | 29 | ||||
| -rw-r--r-- | libterm/Makefile | 18 | ||||
| -rw-r--r-- | libterm/termcap.c | 2 | ||||
| -rw-r--r-- | libterm/tgoto.c | 2 | ||||
| -rw-r--r-- | libterm/tputs.c | 2 | ||||
| -rw-r--r-- | libuxre/CVS/Entries | 21 | ||||
| -rw-r--r-- | libuxre/CVS/Repository | 1 | ||||
| -rw-r--r-- | libuxre/CVS/Root | 1 | ||||
| l---------[-rw-r--r--] | libuxre/Makefile | 13 | ||||
| -rw-r--r-- | libuxre/Makefile.mk | 32 | ||||
| -rw-r--r-- | libuxre/bracket.c | 14 | ||||
| -rw-r--r-- | libuxre/regcomp.c | 2 | ||||
| -rw-r--r-- | libuxre/regdfa.c | 2 | ||||
| -rw-r--r-- | libuxre/regerror.c | 5 | ||||
| -rw-r--r-- | libuxre/regnfa.c | 16 | ||||
| -rw-r--r-- | libuxre/stubs.c | 58 | ||||
| -rw-r--r-- | libuxre/wcharm.h | 4 | ||||
| -rw-r--r-- | mapmalloc.c | 38 | ||||
| -rw-r--r-- | printf.c | 8 | ||||
| -rw-r--r-- | vi.1 | 6 | ||||
| -rwxr-xr-x | wvi | 19 | ||||
| -rw-r--r-- | wvi.1 | 42 |
59 files changed, 1075 insertions, 834 deletions
@@ -1,4 +1,62 @@ -Release ... +Release 4.1.3 +============= + +2016-11-14 + +* Bugfix: Tags did not work in heirloom CVS repository. + Bug #1 reported by @larryhynes (GitHub). + +2016-09-05 + +* Bugfix: Line 1 had been corrupted after window resize at startup + when the file path was longer than the window width and the user + did enlarge the window before pressing return. + +Release 4.1.2 +============= + +2016-07-27 + +* Number mode command line bugfix: Wrong cursor position when using + backspace in number mode fixed. + +2016-07-20 + +* Command line option "+" did never work in heirloom vi. This is + fixed now. + +2016-07-18 + +* Data type overflow bug fixed, which did occur on large displays. + +Release 4.1.1 +============= + +2016-06-24 + +* Showmode updated with input mode macros. This avoids a wrong state + indication. + +Release 4.1.0 +============= + +2016-04-24 + +* Half screen scrolling using ^D or ^U did not take terminal resizing + into account. Instead the number of lines to scroll had been set up + at start time and not changed after that. It is now updated after + each resize. + +2016-04-22 + +* In the last changes after release 3/25/05 until 2/25/07 a bug had been + introduced in the cursor positioning of the line numbering mode. This + is fixed now. + +_____________________________________________________________________________ + +Last changes from Gunnar Ritter (2/25/07): + * The screen buffers for visual mode are now dynamically allocated, so vi usually does not return to ex mode with "screen too large" when the terminal is resized on a large monitor anymore. @@ -79,11 +79,11 @@ # Destinations for installation. $(PRESERVEDIR) is used for recovery files. # It will get mode 1777. # -PREFIX=/home/tmu/.local +PREFIX = /usr/local BINDIR = $(PREFIX)/bin LIBEXECDIR = $(PREFIX)/libexec MANDIR = $(PREFIX)/share/man -PRESERVEDIR=/tmp/ex-preserve/ +PRESERVEDIR = /var/preserve # # DESTDIR is prepended to the installation paths. It is mostly useful @@ -94,7 +94,7 @@ DESTDIR = # # A BSD-like install program. GNU install will fit well here, too. # -INSTALL=/usr/bin/install +INSTALL = install # # Compiler and linker flags. @@ -130,7 +130,7 @@ INSTALL=/usr/bin/install # # If your system expands tabs to 4 spaces you should -DTABS=4 below # -FEATURES = -DLISPCODE -DCHDIR -DFASTTAG -DUCVISUAL -DBIT8 +FEATURES = -DLISPCODE -DCHDIR -DFASTTAG -DUCVISUAL -DMB -DBIT8 # # This disables the LC_CTYPE locale settings and assumes all characters @@ -163,7 +163,7 @@ FEATURES = -DLISPCODE -DCHDIR -DFASTTAG -DUCVISUAL -DBIT8 # REINC = -I./libuxre -DUXRE RELIB = -L./libuxre -luxre -RETGT = uxre +RETGT = libuxre/libuxre.a # # VMUNIX should be correct for any modern Unix. @@ -211,7 +211,7 @@ OSTYPE = -DVMUNIX # provide a good termcap file, or when setting the TERMCAP environment # variable is deemed sufficient, is the included 2.11BSD termcap library. # -TERMLIB = termlib +#TERMLIB = termlib # # Since ex uses sbrk() internally, a conflict with the libc's version of @@ -233,13 +233,15 @@ MALLOC=mapmalloc.o # # ############################################################################### -#WARN = -Wall -Wno-parentheses -Werror +WARN = $(__CDBG) $(__CLDBG) +STRIP = -s -STRIP = -s RECOVER = -DEXRECOVER=\"$(LIBEXECDIR)/exrecover\" \ - -DEXPRESERVE=\"$(LIBEXECDIR)/expreserve\" + -DEXPRESERVE=\"$(LIBEXECDIR)/expreserve\" \ + -DPRESERVEDIR=\"$(PRESERVEDIR)\" CCFLAGS = $(CFLAGS) $(WARN) $(CPPFLAGS) $(FEATURES) $(CHARSET) $(OSTYPE) \ - $(LARGEF) $(RECOVER) $(LANGMSG) $(REINC) $(RPMCFLAGS) + $(LARGEF) $(RECOVER) $(LANGMSG) $(REINC) $(RPMCFLAGS) \ + $(DEFINES) TLIB = libterm/libtermlib.a INCLUDE = /usr/include OBJS = ex.o ex_addr.o ex_cmds.o ex_cmds2.o ex_cmdsub.o \ @@ -248,6 +250,8 @@ OBJS = ex.o ex_addr.o ex_cmds.o ex_cmds2.o ex_cmdsub.o \ ex_v.o ex_vadj.o ex_vget.o ex_vmain.o ex_voper.o \ ex_vops.o ex_vops2.o ex_vops3.o ex_vput.o ex_vwind.o \ printf.o ex_version.o $(MALLOC) +EXRECOBJS=exrecover.o $(MALLOC) compat.o +EXPREOBJS=expreserve.o compat.o HDRS = ex.h ex_argv.h ex_re.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h \ ex_vis.h libterm/libterm.h SRC1 = ex.c ex_addr.c ex_cmds.c ex_cmds2.c ex_cmdsub.c @@ -261,37 +265,41 @@ SRC7 = mapmalloc.c malloc.c .SUFFIXES: .o .c .c.o: ; $(CC) $(CCFLAGS) -c $< -all: $(RETGT) exrecover expreserve ex +all: exrecover expreserve ex wvi.out -ex: $(TLIB) $(OBJS) - $(CC) -o ex $(LDFLAGS) $(OBJS) $(LDADD) -Llibterm -l$(TERMLIB) $(RELIB) +ex: $(OBJS) $(RETGT) $(TLIB) + $(CC) -o ex $(LDFLAGS) $(DEFINES) $(OBJS) $(LDADD) $(WARN) $(TERMLIB) \ + $(RELIB) size ex $(TLIB): libterm/termcap.c libterm/tgoto.c libterm/tputs.c libterm/libterm.h - @cd libterm && $(MAKE) CC="$(CC)" \ + cd libterm && $(MAKE) CC="$(CC)" \ COPT="$(CFLAGS) $(WARN) $(CPPFLAGS) $(OSTYPE)" -exrecover: exrecover.o $(MALLOC) - $(CC) -o exrecover $(LDFLAGS) exrecover.o $(MALLOC) $(LDADD) +exrecover: $(EXRECOBJS) + $(CC) -o exrecover $(LDFLAGS) $(WARN) $(EXRECOBJS) $(LDADD) -expreserve: expreserve.o - $(CC) -o expreserve $(LDFLAGS) expreserve.o $(LDADD) +expreserve: $(EXPREOBJS) + $(CC) -o expreserve $(LDFLAGS) $(WARN) $(EXPREOBJS) $(LDADD) + +wvi.out: wvi + sed 's"BINDIR"$(BINDIR)"g' wvi >wvi.out ex_vars.h: ex_data.c sh makeoptions $(CCFLAGS) -uxre: - @cd libuxre && $(MAKE) CC="$(CC)" \ +$(RETGT): + cd libuxre && $(MAKE) CC="$(CC)" \ COPT="$(CFLAGS) $(WARN) $(CPPFLAGS) $(OSTYPE)" clean: - @cd libterm && $(MAKE) clean - @test ! -d libuxre || (cd libuxre && $(MAKE) clean) + cd libterm && $(MAKE) clean + test ! -d libuxre || (cd libuxre && $(MAKE) clean) # If we dont have ex we cant make it so don't rm ex_vars.h - -rm -f ex exrecover expreserve *.o x*.[cs] core errs trace + -rm -f ex exrecover expreserve *.o x*.[cs] core errs trace *.out mrproper: clean - -rm -f log + -rm -f log Makefile config.log compat.h # install in standard place @@ -308,6 +316,7 @@ install-man: ln -s ex.1 $(DESTDIR)$(MANDIR)/man1/edit.1 ln -s vi.1 $(DESTDIR)$(MANDIR)/man1/vedit.1 ln -s vi.1 $(DESTDIR)$(MANDIR)/man1/view.1 + $(INSTALL) -m 644 wvi.1 $(DESTDIR)$(MANDIR)/man1/ install: all install-man rm -f $(DESTDIR)$(BINDIR)/ex $(DESTDIR)$(BINDIR)/edit \ @@ -330,8 +339,9 @@ install: all install-man ln -s ex $(DESTDIR)$(BINDIR)/vedit ln -s ex $(DESTDIR)$(BINDIR)/vi ln -s ex $(DESTDIR)$(BINDIR)/view + $(INSTALL) wvi.out $(DESTDIR)$(BINDIR)/wvi test -d $(DESTDIR)$(PRESERVEDIR) || mkdir -p $(DESTDIR)$(PRESERVEDIR) - chmod 1777 $(DESTDIR)$(PRESERVEDIR) + -chmod 1777 $(DESTDIR)$(PRESERVEDIR) PKGROOT = /var/tmp/heirloom-sh PKGTEMP = /var/tmp @@ -10,11 +10,8 @@ changes were made to get closer to the POSIX.2 guidelines for ex and vi. Some issues that were clearly bugs and not features have also been resolved; see the Changes file for details. -New releases are announced on Freshmeat. If you want to get -notified by email on each release, use their subscription service at -<http://freshmeat.net/projects/vi/>. - -The project homepage is currently at <http://ex-vi.sourceforge.net>. +The project homepage is currently at +<https://github.com/n-t-roff/heirloom-ex-vi>. How to build @@ -25,16 +22,14 @@ build environment. Explanations are provided directly in this file. You can tune the sizes of some internal buffers by editing config.h. -Then type 'make' and 'make install'. - -It is possible to build a RPM file directly from the source distribution -by executing - - rpmbuild -tb ex-<version>.tar.bz2 +Then type -Note that the RPM spec installs the binary in /usr/5bin by default to -avoid conflicts with vendor files in /usr/bin. The default locations -match those of the Heirloom Toolchest <http://heirloom.sourceforge.net>. + $ ./configure + $ make + $ su + # make install + # exit + $ make mrproper The following systems have been reported to compile this code: @@ -49,10 +44,11 @@ IBM AIX 5.1, 4.3 NEC SUPER-UX 10.2 NEC UX/4800 Release11.5 Rev.A Control Data EP/IX 2.2.1AA -FreeBSD 3.1, 4.5, 5.x, 6.1 -NetBSD 1.6, 2.0 +FreeBSD CURRENT (11.0+) +NetBSD CURRENT (7.0+) DragonFlyBSD 1.3.7-DEVELOPMENT Mac OS X 10.4.3 +OpenBSD CURRENT (5.9+) Reports about other Unix systems are welcome, whether successful or not (in the latter case add a detailed description). This port of vi is only diff --git a/README.md b/README.md new file mode 100644 index 0000000..ae524d0 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# The traditional Vi +This implementation had been derived by Gunnar Ritter +from ex/vi 3.7 of 6/7/85 and the BSD +termcap library, originally from the 2.11BSD distribution. +He had added some useful enhancements, +most notably UTF-8 support. + +The last release of *heirloom-ex-vi* had been +version 050325 (4.0). +Until 2007 he added new features, e.g. +dynamically allocated screen buffers for resizing the terminal +and support for files with arbitrary line length. + +These changes did introduce an issue to numbered lines mode. +This and other found bugs are fixed now. +A simple `./configure` had been added to set curses +as the terminal capabilities access library +on some systems. +## How to install +The embedded termcap library may cause problems on systems where +there is no `/etc/termcap` and `$TERMCAP` of the user that runs +`./configure` and other users (e.g. `root`) differs. +Therefore using termcap has lowest priority during auto-configure. +To prefere termcap put the corresponding line before the curses +entries in +[configure](https://github.com/n-t-roff/heirloom-ex-vi/blob/master/configure). +``` +$ ./configure +$ make +$ su +# make install +# exit +$ make mrproper +``` +## Usage information +The traditional `vi` reads the file `~/.exrc` at start-up. +For full screen scrolling `vi` uses the keys `^F` and `^B`. +To make <PAGE-DOWN> and <PAGE-UP> work add the following +lines to `.exrc`: +``` +map ^[[5~ ^B +map ^[[6~ ^F +``` diff --git a/compat.c b/compat.c new file mode 100644 index 0000000..85a46b1 --- /dev/null +++ b/compat.c @@ -0,0 +1,47 @@ +/* Carsten Kunze, 2016 */ + +#include <string.h> + +#ifndef HAVE_STRLCPY +size_t +strlcpy(char *dst, const char *src, size_t dstsize) { + size_t srcsize; + /* Not conform to strlcpy, but avoids to access illegal memory in case + * of unterminated strings */ + for (srcsize = 0; srcsize < dstsize; srcsize++) + if (!src[srcsize]) + break; + if (dstsize > srcsize) + dstsize = srcsize; + else if (dstsize) + dstsize--; + if (dstsize) + /* assumes non-overlapping buffers */ + memcpy(dst, src, dstsize); + dst[dstsize] = 0; + return srcsize; +} +#endif + +#ifndef HAVE_STRLCAT +size_t +strlcat(char *dst, const char *src, size_t dstsize) { + size_t ld, ls; + for (ld = 0; ld < dstsize - 1; ld++) + if (!dst[ld]) + break; + dst += ld; + dstsize -= ld; + for (ls = 0; ls < dstsize; ls++) + if (!src[ls]) + break; + if (dstsize > ls) + dstsize = ls; + else if (dstsize) + dstsize--; + if (dstsize) + memcpy(dst, src, dstsize); + dst[dstsize] = 0; + return ld + ls; +} +#endif diff --git a/configure b/configure new file mode 100755 index 0000000..f569405 --- /dev/null +++ b/configure @@ -0,0 +1,333 @@ +#!/bin/sh + +# Copyright (c) 2016-2018, Carsten Kunze <carsten.kunze@arcor.de> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +usage () { + echo "Usage: $0 [-s] [-D<define> ...]" + echo " -s Silence output" + echo " -D<define>" + echo " Add define to CFLAGS" + exit $1 +} + +SFLAG= +MAKE= +DEFS= +LIB_LEX= +LIB_CURSES= +cat /dev/null > compat.h + +while [ $# -gt 0 ]; do + case $1 in + -s) + SFLAG=1 + ;; + -D*) + DEFS="$DEFS $1" + ;; + *) + echo "$0: $1: Unknown option" >&2 + usage 1 + ;; + esac + shift +done + +check_for () { + [ -e $LOG ] && cat <<EOT >>$LOG + +================================================================================ + +EOT + A="Checking for $1 ... " + printf "$A\n\n" >>$LOG + [ -z "$SFLAG" ] && printf "$A" +} + +compile () { + rm -f ${TMPNAM}.o $TMPNAM $OUT $ERR + $MAKE -f $OUTMK $TMPNAM > $OUT 2> $ERR + RESULT=$? + cat $OUT $ERR >> $LOG + if [ $RESULT -eq 0 ]; then true; else false; fi +} + +test_result () { + RESULT=$? + RESULT_TEXT=${1:-0} # 1: omit "no", 2: say nothing + if [ $RESULT -eq 0 ]; then + echo success >>$LOG + [ -z "$SFLAG" -a $RESULT_TEXT -lt 2 ] && \ + echo "yes$PASS_TEXT" + PASS_TEXT= + [ -e $TMPC ] && rm -f $TMPC + true + else + [ -z "$SFLAG" -a $RESULT_TEXT -lt 1 ] && echo no + if [ -e $TMPC ]; then + echo "Failed program:" >>$LOG + pr -n -t $TMPC >>$LOG + rm -f $TMPC + fi + false + fi +} + +gen_mk () { + [ $# -eq 0 ] && rm -f $OUTMK + [ -n "$LEX" ] && echo "LEX=$LEX" >> $OUTMK + [ -n "$FLOAT_STORE" ] && echo "FLOAT_STORE=$FLOAT_STORE" >> $OUTMK + [ -n "$DEFS" ] && echo "DEFINES=$DEFS" >> $OUTMK + [ -n "$INCDIR_CURSES" ] && echo "INCDIR_CURSES=$INCDIR_CURSES" >> $OUTMK + [ -n "$RPATH_CURSES" ] && echo "RPATH_CURSES=$RPATH_CURSES" >> $OUTMK + [ -n "$LIBDIR_CURSES" ] && echo "LIBDIR_CURSES=$LIBDIR_CURSES" \ + >> $OUTMK + [ -n "$LIB_CURSES" ] && echo "LIB_CURSES=$LIB_CURSES" >> $OUTMK + [ -n "$LIB_AVLBST" ] && echo "LIB_AVLBST=$LIB_AVLBST" >> $OUTMK + [ -n "$LIB_LEX" ] && echo "LIB_LEX=$LIB_LEX" >> $OUTMK + [ -n "$__CDBG" ] && echo "__CDBG=$__CDBG" >> $OUTMK + [ -n "$__CXXDBG" ] && echo "__CXXDBG=$__CXXDBG" >> $OUTMK + [ -n "$__CLDBG" ] && echo "__CLDBG=$__CLDBG" >> $OUTMK + [ -n "$__CLXXDBG" ] && echo "__CLXXDBG=$__CLXXDBG" >> $OUTMK + cat $INMK >> $OUTMK || exit 1 +} +check_make () { + check_for "make(1)" + + cat <<EOT >$TMPMK +all: + true +EOT + make -f $TMPMK >> $LOG 2>&1 + test_result && { + MAKE=make + return + } + + echo "Failed makefile:" >>$LOG + pr -n -t $TMPMK >>$LOG + + check_for "bmake(1)" + + cat <<EOT >$TMPMK +all: + true +EOT + bmake -f $TMPMK >> $LOG 2>&1 + test_result && MAKE=bmake +} +check_strlcpy () { + check_for "strlcpy(3)" + + cat <<EOT >$TMPC +#include <string.h> +int +main(int argc, char **argv) { + char a[10]; + (void)argc; + strlcpy(a, *argv, sizeof a); + return 0; +} +EOT + compile + if test_result; then + DEFS="$DEFS -DHAVE_STRLCPY" + else + H=compat.h + grep -q '<sys/types\.h>' $H 2>/dev/null || cat <<EOT >>$H +#include <sys/types.h> +EOT + cat <<EOT >>$H +size_t strlcpy(char *, const char *, size_t); +EOT + fi +} +check_strlcat () { + check_for "strlcat(3)" + + cat <<EOT >$TMPC +#include <string.h> +int +main(int argc, char **argv) { + char a[10]; + (void)argc; + *a = 0; + strlcat(a, *argv, sizeof a); + return 0; +} +EOT + compile + if test_result; then + DEFS="$DEFS -DHAVE_STRLCAT" + else + H=compat.h + grep -q '<sys/types\.h>' $H 2>/dev/null || cat <<EOT >>$H +#include <sys/types.h> +EOT + cat <<EOT >>$H +size_t strlcat(char *, const char *, size_t); +EOT + fi +} +check_Sanitizer () { + check_for "CC Sanitizer" + + # C only + __CDBG= + __CLDBG= + __CCXXDBG= + # C++ only + __CXXDBG= + __CLXXDBG= + __CDBG="$__CDBG -Wmissing-prototypes" + __CDBG="$__CDBG -Wstrict-prototypes" + __CCXXDBG="$__CCXXDBG -g -O0 -fno-omit-frame-pointer -fno-optimize-sibling-calls" + __CCXXDBG="$__CCXXDBG -Wall" + __CCXXDBG="$__CCXXDBG -Wextra" + __CCXXDBG="$__CCXXDBG -Wbad-function-cast" + __CCXXDBG="$__CCXXDBG -Wcast-align" + __CCXXDBG="$__CCXXDBG -Wcast-qual" + #__CCXXDBG="$__CCXXDBG -Wconversion" + __CCXXDBG="$__CCXXDBG -Wfloat-equal" + __CCXXDBG="$__CCXXDBG -Wlogical-not-parentheses" + __CCXXDBG="$__CCXXDBG -Wshadow" + __CCXXDBG="$__CCXXDBG -Wsign-compare" + __CCXXDBG="$__CCXXDBG -Wundef" + __CCXXDBG="$__CCXXDBG -Wuninitialized" + __CCXXDBG="$__CCXXDBG -Wunused-parameter" + __CCXXDBG="$__CCXXDBG -Wunused-function" + __CCXXDBG="$__CCXXDBG -Wwrite-strings" + __CLXXDBG="$__CLXXDBG -fno-common -fsanitize=address -fsanitize=undefined" + #__CLXXDBG="$__CLXXDBG -fsanitize-recover=all" + + [ -n "$CC" ] || CC=cc + VER=`$CC --version` + + if echo $VER | grep -iq gcc || echo $VER | \ + grep -iq 'Free Software Foundation'; then + [ -z "$SFLAG" ] && printf "(gcc) " + #__CCXXDBG="$__CCXXDBG -Wduplicated-branches" + __CCXXDBG="$__CCXXDBG -Wduplicated-cond" + __CCXXDBG="$__CCXXDBG -Wjump-misses-init" + __CCXXDBG="$__CCXXDBG -Wlogical-op" + #__CLXXDBG="$__CLXXDBG -fprofile-arcs -ftest-coverage" + __CLXXDBG="$__CLXXDBG -fsanitize=float-divide-by-zero" + __CLXXDBG="$__CLXXDBG -fsanitize=float-cast-overflow" + elif echo $VER | grep -q clang; then + [ -z "$SFLAG" ] && printf "(clang) " + __CCXXDBG="$__CCXXDBG -Wincompatible-pointer-types-discards-qualifiers" + __CCXXDBG="$__CCXXDBG -Wmissing-variable-declarations" + __CXXDBG="$__CXXDBG -Wunused-private-field" + __CLXXDBG="$__CLXXDBG -fsanitize=unsigned-integer-overflow" + else + [ -z "$SFLAG" ] && echo "Unknown compiler" + return + fi + + # Most C++ options can be used for C too + __CDBG="$__CDBG $__CCXXDBG" + __CLDBG="$__CLDBG $__CLXXDBG" + __CXXDBG="$__CXXDBG $__CCXXDBG" + cat <<EOT >$TMPC +int +main() { + return 0; +} +EOT + gen_mk + cat <<EOT >>$OUTMK +$TMPNAM: ${TMPNAM}.o + \$(CC) \$(__CDBG) \$(__CLDBG) -o \$@ ${TMPNAM}.o +EOT + compile + test_result || { + __CLDBG= + __CLXXDBG= + } +} + [ ! -s compat.h ] && rm compat.h +OUTMK=Makefile +INMK=${OUTMK}.in +CFG=config +TMPNAM=.$CFG +TMPMK=${TMPNAM}.mk +TMPC=${TMPNAM}.c +TMPL=${TMPNAM}.l # For lex tests only ... +OUT=${TMPNAM}.out +ERR=${TMPNAM}.err +LOG=${CFG}.log +rm -f $LOG +gen_mk + +check_make +check_strlcpy +check_strlcat +#check_Sanitizer + +__CLDBG=`echo $__CLDBG | sed 's/-fsanitize=address//'` +__CLXXDBG=`echo $__CLXXDBG | sed 's/-fsanitize=address//'` + +TermTest () { + check_for "$1" + Term="$1" + echo "TERMLIB=$1" > $OUTMK + gen_mk 1 + cat <<EOT >>$OUTMK +$TMPNAM: ${TMPNAM}.o \$(TLIB) + \$(CC) \$(WARN) \$(DEFINES) -o \$@ ${TMPNAM}.o \$(TERMLIB) +EOT + cat <<EOT >>$TMPC +#include <stdio.h> +int tgetent(char *, const char *); +int main() { + char tcbuf[2048]; + char *terms[] = { "xterm", "screen" }; + unsigned i; + for (i = 0; i < sizeof(terms)/sizeof(*terms); i++) + if (tgetent(tcbuf, terms[i]) != 1) { + fprintf(stderr, "Unknown terminal type \"%s\"\n", + terms[i]); + return i + 1; + } + return 0; +} +EOT + compile + test_result 2 && ./$TMPNAM 2>> $LOG && { + echo yes + return + } + echo no + false +} + +TestLocalTermlib () { + #TermTest "-Llibterm -ltermlib" && return + TermTest "-ltinfo" && return + TermTest "-lncurses" && return + ODEFS=$DEFS + D="-I/usr/pkg/include -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib" + DEFS="$DEFS $D" + TermTest "-lncurses $D" && return + DEFS=$ODEFS + TermTest "-lcurses" && return + TermTest "-Llibterm -ltermlib" && return +} + +TestLocalTermlib + +echo "TERMLIB=$Term" > $OUTMK +gen_mk 1 +rm -f $TMPNAM* @@ -1932,10 +1932,10 @@ The program file used to execute external commands. Determines the terminal type. .SH FILES .TP -.B /usr/lib/ex/expreserve +.B /usr/libexec/expreserve preserve command .TP -.B /usr/lib/ex/exrecover +.B /usr/libexec/exrecover recover command .TP .B /etc/termcap @@ -1950,7 +1950,7 @@ editor temporary .B /var/tmp/Rx\fInnnnnnnnnn\fP named buffer temporary .TP -.B /var/lib/ex +.B /var/preserve preservation directory .SH DOCUMENTATION The document @@ -154,7 +154,7 @@ erropen(void) void usage(void) { - printf(catgets(catd, 1, 1, "\ + ex_printf(catgets(catd, 1, 1, "\ Usage: %s [- | -s] [-l] [-L] [-R] [-r [file]] [-t tag]\n\ [-v] [-V] [-w size] [+cmd | -c cmd] file...\n"), progname); @@ -166,7 +166,7 @@ void needarg(int c) { erropen(); - printf(catgets(catd, 1, 2, + ex_printf(catgets(catd, 1, 2, "%s: option requires an argument -- %c\n"), progname, c); usage(); } @@ -175,7 +175,7 @@ void invopt(int c) { erropen(); - printf(catgets(catd, 1, 3, "%s: illegal option -- %c\n"), progname, c); + ex_printf(catgets(catd, 1, 3, "%s: illegal option -- %c\n"), progname, c); usage(); } @@ -399,8 +399,6 @@ main(register int ac, register char *av[]) while (ac) { if (av[0][0] == '+') { firstpat = &av[0][1]; - if (*firstpat == '\0') - needarg('+'); } else if (av[0][0] == '-') { arggroup: c = av[0][1]; @@ -437,7 +435,7 @@ arggroup: trace = fopen(tracef, "w"); #define tracbuf NULL if (trace == NULL) - printf(catgets(catd, 1, 4, + ex_printf(catgets(catd, 1, 4, "Trace create error\n")); else setbuf(trace, tracbuf); @@ -136,6 +136,7 @@ #endif #ifdef MB +int wcwidth(wchar_t); #include <wchar.h> #include <wctype.h> #endif @@ -191,6 +192,8 @@ typedef short line; typedef int line; #endif +typedef short bool; + #ifdef LARGEF typedef off_t bloc; #else @@ -252,9 +255,6 @@ typedef short bbloc; #ifdef EOF #undef EOF #endif -#ifdef printf -#undef printf -#endif #ifdef vprintf #undef vprintf #endif @@ -441,7 +441,8 @@ var int exitoneof; /* exit command loop on EOF */ /* * Macros */ -#define CP(a, b) (ignore(movestr(a, b))) +#define Copy(t, f, s) memmove(t, f, s) +#define CP(a, b) memmove(a, b, strlen(b) + 1) /* * FIXUNDO: do we want to mung undo vars? * Usually yes unless in a macro or global. @@ -449,7 +450,7 @@ var int exitoneof; /* exit command loop on EOF */ #define FIXUNDO (inopen >= 0 && (inopen || !inglobal)) #define ckaw() {if (chng && value(AUTOWRITE)) wop(0);} #define copy(a,b,c) Copy((char *) (a), (char *) (b), (c)) -#define eq(a, b) ((a) && (b) && strcmp(a, b) == 0) +#define eq(a, b) ((void *)(a) != NULL && (void *)(b) != NULL && strcmp(a, b) == 0) #define getexit(a) copy(a, resetlab, sizeof (JMP_BUF)) #define lastchar() lastc #define outchar(c) (*Outchar)(c) @@ -551,7 +552,7 @@ var int mb_cur_max; ((c) = *(s) & 0377, (n) = 1)) #define colsc(c) (mb_cur_max > 1 && ((c)&0177) != (c) ? wcwidth(c) : 1) #define skipleft(l, p) (mb_cur_max > 1 && ((p)[0]&0200 || \ - (p)>(l) && (p)[-1]&0200) ? wskipleft(l, p) : -1) + ((p)>(l) && (p)[-1]&0200)) ? wskipleft(l, p) : -1) #define skipright(l, p) (mb_cur_max > 1 && (p)>=(l) && (p)[0]&0200 ? \ wskipright(l, p) : 1) #define samechar(cp, c) (mb_cur_max > 1 && *(cp)&0200 ? wsamechar(cp, c) : \ @@ -562,8 +563,8 @@ var int mb_cur_max; #define xisspace(c) (mb_cur_max > 1 ? iswspace(c) : isspace(c)) #define xisupper(c) (mb_cur_max > 1 ? iswupper(c) : isupper(c)) #define xislower(c) (mb_cur_max > 1 ? iswlower(c) : islower(c)) -#define xtolower(c) (mb_cur_max > 1 ? towlower(c) : tolower(c)) -#define xtoupper(c) (mb_cur_max > 1 ? towupper(c) : toupper(c)) +#define xtolower(c) (mb_cur_max > 1 ? towlower(c) : (wint_t)tolower(c)) +#define xtoupper(c) (mb_cur_max > 1 ? towupper(c) : (wint_t)toupper(c)) #else /* !MB */ #define nextc(c, s, n) ((c) = *(s) & 0377, (n) = 1) #define colsc(c) (1) @@ -128,7 +128,7 @@ commands(int noprompt, int _exitoneof) * before the next command. */ if (pflag || - lchng != chng && value(AUTOPRINT) && !inglobal && !inopen && endline) { + (lchng != chng && value(AUTOPRINT) && !inglobal && !inopen && endline)) { pflag = 0; nochng(); if (dol != zero) { @@ -166,7 +166,7 @@ error(catgets(catd, 1, 17, addr1 = addr2; addr = address(0); c = getcd(); - if (addr == 0) + if (addr == 0) { if (c == ',') addr = dot; else if (addr1 != 0) { @@ -174,6 +174,7 @@ error(catgets(catd, 1, 17, break; } else break; + } addr2 = addr; given++; if (c == ';') { @@ -911,7 +912,7 @@ numberit: setall(); if (inglobal == 2) pofix(); - printf("%d", lineno(addr2)); + ex_printf("%d", lineno(addr2)); noonl(); continue; @@ -281,7 +281,7 @@ erewind(void) argv = argv0; args = args0; if (argc > 1 && !hush) { - printf(mesg(catgets(catd, 1, 30, "%d files@to edit")), argc); + ex_printf(mesg(catgets(catd, 1, 30, "%d files@to edit")), argc); if (inopen) putchar(' '); else @@ -346,7 +346,7 @@ next(void) morargc = argc; isalt = (strcmp(altfile, args)==0) + 1; if (savedfile[0]) - strcpy(altfile, savedfile); + lcpy(altfile, savedfile, sizeof altfile); safecp(savedfile, args, sizeof savedfile, "File name too long"); argc--; args = argv ? *++argv : strend(args) + 1; @@ -554,7 +554,7 @@ tailprim(register char *comm, int xi, bool notinvis) c = peekchar(); if (notinvis || isalpha(c) #ifdef BIT8 - || xi == 0 && (c&(0200|QUOTE)) == 0200 + || (xi == 0 && (c&(0200|QUOTE)) == 0200) #endif ) { /* @@ -568,7 +568,7 @@ tailprim(register char *comm, int xi, bool notinvis) while (cp < &tcommand[19] && (c = peekchar(), isalpha(c) #ifdef BIT8 - || xi == 0 && (c&(0200|QUOTE)) == 0200 + || (xi == 0 && (c&(0200|QUOTE)) == 0200) #endif )) *cp++ = getchar(); @@ -618,6 +618,7 @@ vcontin(bool ask) if (ask) { merror(catgets(catd, 1, 38, "[Hit return to continue] ")); + getline(*dot); flush(); } if (ask) { diff --git a/ex_cmdsub.c b/ex_cmdsub.c index 6271626..7f200a8 100644 --- a/ex_cmdsub.c +++ b/ex_cmdsub.c @@ -166,10 +166,10 @@ pargs(void) if (ac != 0) putchar(' ' | QUOTE); if (ac + argc == argc0 - 1) - printf("["); + ex_printf("["); lprintf("%s", as); if (ac + argc == argc0 - 1) - printf("]"); + ex_printf("]"); as = av ? *++av : strend(as) + 1; } noonl(); @@ -299,7 +299,7 @@ join(int c) } } } - while (*cp++ = *cp1++) + while ((*cp++ = *cp1++)) if (cp > &genbuf[LBSIZE-2]) grow( "Line overflow|Result line of join would be too long", @@ -435,6 +435,7 @@ put(int unused) { register int cnt; + (void)unused; if (!FIXUNDO) error(catgets(catd, 1, 44, "Cannot put inside global/macro")); cnt = unddol - dol; @@ -473,7 +474,7 @@ pragged(int kill) getline(*unddol); if (kill) *pkill[1] = 0; - strcat(linebuf, gp); + lcat(linebuf, gp, LBSIZE); putmark(unddol); getline(dol[1]); if (kill) @@ -601,7 +602,8 @@ badtag: * Loop once for each file in tags "path". */ safecp(tagfbuf, svalue(TAGS), sizeof tagfbuf, "Tag too long"); - fne = tagfbuf - 1; + fne = tagfbuf; + fne--; #ifdef FASTTAG ft_iofbuf = smalloc(MAXBSIZE); #endif @@ -657,7 +659,7 @@ badtag: if(tgets(linebuf, LBSIZE, ft_iof)==0) goto goleft; #ifdef TDEBUG - printf("tag: %o %o %o %s\n", bot, mid, top, linebuf); + ex_printf("tag: %o %o %o %s\n", bot, mid, top, linebuf); #endif #endif while (*cp && *lp == *cp) @@ -690,11 +692,12 @@ goleft: /* name of file */ while (*cp && is_white(*cp)) cp++; - if (!*cp) + if (!*cp) { badtags: free(ft_iofbuf); serror(catgets(catd, 1, 48, "%s: Bad tags file entry"), lasttag); + } lp = filebuf; while (*cp && *cp != ' ' && *cp != '\t') { if (lp < &filebuf[sizeof filebuf - 2]) @@ -733,8 +736,8 @@ badtags: } } oglobp = globp; - strcpy(cmdbuf2, "e! "); - strcat(cmdbuf2, filebuf); + lcpy(cmdbuf2, "e! ", sizeof cmdbuf2); + lcat(cmdbuf2, filebuf, sizeof cmdbuf2); globp = cmdbuf2; d = peekc; ungetchar(0); commands(1, 1); @@ -804,7 +807,7 @@ badtags: void yank(int unused) { - + (void)unused; if (!FIXUNDO) error(catgets(catd, 1, 52, "Can't yank inside global/macro")); save12(); @@ -1286,7 +1289,7 @@ mapcmd(int un, int ab) fnkey = fkey(lhs[1] - '0'); funkey[0] = 'f'; funkey[1] = lhs[1]; funkey[2] = 0; if (fnkey) - strcpy(lhs, fnkey); + lcpy(lhs, fnkey, sizeof lhs); dname = funkey; } else { dname = lhs; @@ -1350,7 +1353,7 @@ addmac1(register char *src,register char *dest,register char *dname, * linefeed, and escape, he can screw himself. This is * so weird I don't bother to check for it. */ - if (isalpha(src[0]&0377) && src[1] || any(src[0],":")) + if ((isalpha(src[0]&0377) && src[1]) || any(src[0],":")) error(catgets(catd, 1, 64, "Too dangerous to map that")); } @@ -121,50 +121,50 @@ short TCOLUMNS = 80; short TLINES = 24; struct option options[NOPTS + 1] = { - { "autoindent", "ai", ONOFF, 0, 0, 0, }, - { "autoprint", "ap", ONOFF, 1, 1, 0, }, - { "autowrite", "aw", ONOFF, 0, 0, 0, }, - { "beautify", "bf", ONOFF, 0, 0, 0, }, - { "directory", "dir", STRING, 0, 0, direct, }, - { "edcompatible","ed", ONOFF, 0, 0, 0, }, - { "errorbells", "eb", ONOFF, 0, 0, 0, }, - { "exrc", "ex", ONOFF, 0, 0, 0, }, - { "flash", "fl", ONOFF, 1, 1, 0, }, - { "hardtabs", "ht", NUMERIC, 8, 8, 0, }, - { "ignorecase", "ic", ONOFF, 0, 0, 0, }, - { "lisp", 0, ONOFF, 0, 0, 0, }, - { "list", 0, ONOFF, 0, 0, 0, }, - { "magic", 0, ONOFF, 1, 1, 0, }, - { "mesg", 0, ONOFF, 1, 1, 0, }, - { "modelines", "ml", ONOFF, 0, 0, 0, }, - { "number", "nu", ONOFF, 0, 0, 0, }, - { "open", 0, ONOFF, 1, 1, 0, }, - { "optimize", "opt", ONOFF, 0, 0, 0, }, - { "paragraphs", "para", STRING, 0, 0, paragraphs, }, - { "prompt", 0, ONOFF, 1, 1, 0, }, - { "readonly", "ro", ONOFF, 0, 0, 0, }, - { "redraw", 0, ONOFF, 0, 0, 0, }, - { "remap", 0, ONOFF, 1, 1, 0, }, - { "report", 0, NUMERIC, 5, 5, 0, }, - { "scroll", "scr", NUMERIC, 12, 12, 0, }, - { "sections", "sect", STRING, 0, 0, sections, }, - { "shell", "sh", STRING, 0, 0, shell, }, - { "shiftwidth", "sw", NUMERIC, TABS, TABS, 0, }, - { "showmatch", "sm", ONOFF, 0, 0, 0, }, - { "showmode", "smd", ONOFF, 0, 0, 0, }, - { "slowopen", "slow", ONOFF, 0, 0, 0, }, - { "sourceany", 0, ONOFF, 0, 0, 0, }, - { "tabstop", "ts", NUMERIC, TABS, TABS, 0, }, - { "taglength", "tl", NUMERIC, 0, 0, 0, }, - { "tags", "tag", STRING, 0, 0, tags, }, - { "term", 0, OTERM, 0, 0, ttylongname, }, - { "terse", 0, ONOFF, 0, 0, 0, }, - { "timeout", "to", ONOFF, 1, 1, 0, }, - { "ttytype", "tty", OTERM, 0, 0, ttylongname, }, - { "warn", 0, ONOFF, 1, 1, 0, }, - { "window", "wi", NUMERIC, 23, 23, 0, }, - { "wrapscan", "ws", ONOFF, 1, 1, 0, }, - { "wrapmargin", "wm", NUMERIC, 0, 0, 0, }, - { "writeany", "wa", ONOFF, 0, 0, 0, }, - { 0, 0, 0, 0, 0, 0, } + { "autoindent", "ai", ONOFF, 0, 0, 0 }, + { "autoprint", "ap", ONOFF, 1, 1, 0 }, + { "autowrite", "aw", ONOFF, 0, 0, 0 }, + { "beautify", "bf", ONOFF, 0, 0, 0 }, + { "directory", "dir", STRING, 0, 0, direct }, + { "edcompatible","ed", ONOFF, 0, 0, 0 }, + { "errorbells", "eb", ONOFF, 0, 0, 0 }, + { "exrc", "ex", ONOFF, 0, 0, 0 }, + { "flash", "fl", ONOFF, 1, 1, 0 }, + { "hardtabs", "ht", NUMERIC, 8, 8, 0 }, + { "ignorecase", "ic", ONOFF, 0, 0, 0 }, + { "lisp", 0, ONOFF, 0, 0, 0 }, + { "list", 0, ONOFF, 0, 0, 0 }, + { "magic", 0, ONOFF, 1, 1, 0 }, + { "mesg", 0, ONOFF, 1, 1, 0 }, + { "modelines", "ml", ONOFF, 0, 0, 0 }, + { "number", "nu", ONOFF, 0, 0, 0 }, + { "open", 0, ONOFF, 1, 1, 0 }, + { "optimize", "opt", ONOFF, 0, 0, 0 }, + { "paragraphs", "para", STRING, 0, 0, paragraphs }, + { "prompt", 0, ONOFF, 1, 1, 0 }, + { "readonly", "ro", ONOFF, 0, 0, 0 }, + { "redraw", 0, ONOFF, 0, 0, 0 }, + { "remap", 0, ONOFF, 1, 1, 0 }, + { "report", 0, NUMERIC, 5, 5, 0 }, + { "scroll", "scr", NUMERIC, 12, 12, 0 }, + { "sections", "sect", STRING, 0, 0, sections }, + { "shell", "sh", STRING, 0, 0, shell }, + { "shiftwidth", "sw", NUMERIC, TABS, TABS, 0 }, + { "showmatch", "sm", ONOFF, 0, 0, 0 }, + { "showmode", "smd", ONOFF, 0, 0, 0 }, + { "slowopen", "slow", ONOFF, 0, 0, 0 }, + { "sourceany", 0, ONOFF, 0, 0, 0 }, + { "tabstop", "ts", NUMERIC, TABS, TABS, 0 }, + { "taglength", "tl", NUMERIC, 0, 0, 0 }, + { "tags", "tag", STRING, 0, 0, tags }, + { "term", 0, OTERM, 0, 0, ttylongname }, + { "terse", 0, ONOFF, 0, 0, 0 }, + { "timeout", "to", ONOFF, 1, 1, 0 }, + { "ttytype", "tty", OTERM, 0, 0, ttylongname }, + { "warn", 0, ONOFF, 1, 1, 0 }, + { "window", "wi", NUMERIC, 23, 23, 0 }, + { "wrapscan", "ws", ONOFF, 1, 1, 0 }, + { "wrapmargin", "wm", NUMERIC, 0, 0, 0 }, + { "writeany", "wa", ONOFF, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0 } }; @@ -116,7 +116,7 @@ getach(void) } top: if (input) { - if (c = *input++&0377) { + if ((c = *input++&0377)) { if (verbose && !intty) write(2, &input[-1], 1); if (c &= TRIM) @@ -184,13 +184,14 @@ again: if (c == EOF) return (c); c &= TRIM; - if (!inopen) + if (!inopen) { if (!globp && c == CTRL('d')) setlastchar('\n'); else if (junk(c)) { checkjunk(c); goto again; } + } return (c); } @@ -260,7 +261,7 @@ gettty(void) if (intty && !inglobal) { if (offset) { holdcm = 1; - printf(" %4d ", lineDOT() + 1); + ex_printf(" %4d ", lineDOT() + 1); flush(); holdcm = 0; } @@ -338,7 +339,7 @@ gettty(void) for (; c > 0; c--) *cp++ = ' '; } - CP(cp, genbuf); + lcpy(cp, genbuf, LBSIZE - (cp - linebuf)); if (linebuf[0] == '.' && linebuf[1] == 0) return (EOF); return (0); @@ -99,11 +99,7 @@ bool wasalt; short isalt; long cntch; /* Count of characters on unit io */ -#ifndef VMUNIX -short cntln; /* Count of lines " */ -#else -int cntln; -#endif +long cntln; /* Count of lines " */ long cntnull; /* Count of nulls " */ #ifndef BIT8 long cntodd; /* Count of non-ascii characters " */ @@ -125,7 +121,7 @@ filename(int comm) if (savedfile[0] == 0 && comm != 'f') error(catgets(catd, 1, 72, "No file|No current filename")); - CP(file, savedfile); + lcpy(file, savedfile, sizeof file); wasalt = (isalt > 0) ? isalt-1 : 0; isalt = 0; oldadot = altdot; @@ -152,39 +148,39 @@ filename(int comm) case 'e': if (savedfile[0]) { altdot = lineDOT(); - CP(altfile, savedfile); + lcpy(altfile, savedfile, sizeof altfile); } - CP(savedfile, file); + lcpy(savedfile, file, sizeof savedfile); break; default: if (file[0]) { if (c != 'E') altdot = lineDOT(); - CP(altfile, file); + lcpy(altfile, file, sizeof altfile); } break; } } - if (hush && comm != 'f' || comm == 'E') + if ((hush && comm != 'f') || comm == 'E') return; if (file[0] != 0) { lprintf("\"%s\"", file); if (comm == 'f') { if (value(READONLY)) - printf(catgets(catd, 1, 73, " [Read only]")); + ex_printf(catgets(catd, 1, 73, " [Read only]")); if (!edited) - printf(catgets(catd, 1, 74, " [Not edited]")); + ex_printf(catgets(catd, 1, 74, " [Not edited]")); if (tchng) - printf(catgets(catd, 1, 75, " [Modified]")); + ex_printf(catgets(catd, 1, 75, " [Modified]")); } flush(); } else - printf(catgets(catd, 1, 76, "No file ")); + ex_printf(catgets(catd, 1, 76, "No file ")); if (comm == 'f') { if (!(i = lineDOL())) i++; - printf(catgets(catd, 1, 77, + ex_printf(catgets(catd, 1, 77, " line %d of %d --%ld%%--"), lineDOT(), lineDOL(), (long) 100 * lineDOT() / i); } @@ -384,7 +380,7 @@ missing: if (strlen(str) > FNSIZE - 4) error(catgets(catd, 1, 89, "Filename too long")); /* samef: */ - CP(file, str); + lcpy(file, str, sizeof file); } /* @@ -424,7 +420,7 @@ rop(int c) * "edit" commands, not just for the first one. */ if (1 || !seenprompt) { - printf(catgets(catd, 1, 90, " [New file]")); + ex_printf(catgets(catd, 1, 90, " [New file]")); noonl(); return; } @@ -470,7 +466,7 @@ rop(int c) } } if (value(READONLY) && !hush) { - printf(catgets(catd, 1, 102, " [Read only]")); + ex_printf(catgets(catd, 1, 102, " [Read only]")); flush(); } if (c == 'r') @@ -528,29 +524,29 @@ iostats(void) io = -1; if (hush == 0) { if (value(TERSE)) - printf(catgets(catd, 1, 103, - " %d/%d"), cntln, (int)cntch); + ex_printf(catgets(catd, 1, 103, + " %ld/%ld"), cntln, cntch); else - printf(catgets(catd, 1, 104, - " %d line%s, %d character%s"), cntln, plural((long) cntln), - (int)cntch, plural((int)cntch)); + ex_printf(catgets(catd, 1, 104, + " %ld line%s, %ld character%s"), cntln, plural(cntln), + cntch, plural(cntch)); if (cntnull #ifndef BIT8 || cntodd #endif ) { - printf(catgets(catd, 1, 105, " (")); + ex_printf(catgets(catd, 1, 105, " (")); if (cntnull) { - printf(catgets(catd, 1, 106, + ex_printf(catgets(catd, 1, 106, "%d null"), (int)cntnull); #ifndef BIT8 if (cntodd) - printf(catgets(catd, 1, 107, ", ")); + ex_printf(catgets(catd, 1, 107, ", ")); #endif } #ifndef BIT8 if (cntodd) - printf(catgets(catd, 1, 108, + ex_printf(catgets(catd, 1, 108, "%d non-ASCII"), (int)cntodd); #endif putchar(')'); @@ -654,7 +650,7 @@ wop(bool dofname) saddr2=addr2; addr1=one; addr2=dol; - CP(file, savedfile); + lcpy(file, savedfile, sizeof file); if (inopen) { vclrech(0); splitw++; @@ -707,12 +703,13 @@ cre: if (io < 0) syserror(); writing = 1; - if (hush == 0) + if (hush == 0) { if (nonexist) - printf(catgets(catd, 1, 115, " [New file]")); + ex_printf(catgets(catd, 1, 115, " [New file]")); else if (value(WRITEANY) && edfile() != EDF) - printf(catgets(catd, 1, 116, + ex_printf(catgets(catd, 1, 116, " [Existing file]")); + } break; case 2: @@ -758,7 +755,7 @@ getfile(void) if (ninbuf < 0) { if (lp != linebuf) { lp++; - printf(catgets(catd, 1, 117, + ex_printf(catgets(catd, 1, 117, " [Incomplete last line]")); break; } @@ -805,6 +802,7 @@ putfile(int isfilter) register int nib; struct stat statb; + (void)isfilter; a1 = addr1; clrstats(); cntln = fixedzero ? 0 : addr2 - a1 + 1; @@ -882,7 +880,7 @@ source(char *fil, bool okfail) saveglobp = globp; saveinput = input; if (input) - strcpy(saveinline, input); + lcpy(saveinline, input, sizeof saveinline); peekc = 0; lastc = 0; globp = 0; input = 0; if (saveinp < 0) error(catgets(catd, 1, 119, "Too many nested sources")); @@ -992,7 +990,7 @@ mbtowi(int *cp, const char *s, size_t n) if (i >= 0 && widthok(wc) && !(wc & 0x70000000)) *cp = wc; else { - *cp = *s&0377 | INVBIT; + *cp = (*s & 0377) | INVBIT; i = 1; } return i; @@ -259,7 +259,8 @@ extern void change(void); extern int column(register char *); extern int lcolumn(register char *); extern void comment(void); -extern void Copy(register char *, register char *, register int); +size_t lcpy(char *, const char *, size_t); +size_t lcat(char *, const char *, size_t); extern void copyw(register line *, register line *, register int); extern void copywR(register line *, register line *, register int); extern int ctlof(int); @@ -322,7 +323,6 @@ extern int preserve(void); extern int exitex(int); extern void onsusp(int); extern void onemt(int); -extern char *movestr(char *, const char *); extern char *safecp(char *, const char *, size_t, char *, ...); extern char *safecat(char *, const char *, size_t, char *, ...); extern void grow(char *, char **, char **, char **, char **); @@ -566,6 +566,6 @@ extern void vnline(char *); /* mapmalloc.c */ extern char *poolsbrk(intptr_t); /* printf.c */ -extern int printf(const char *, ...); +extern int ex_printf(char *, ...); extern int vprintf(const char *, va_list); extern char *p_dconv(long, char *); @@ -158,7 +158,7 @@ listchar(int c) if (c < ' ' && c != '\n') outchar('^'), c = ctlof(c); #else /* !BIT8 */ - if (!printable(c) && c != '\n' || c == DELETE) + if ((!printable(c) && c != '\n') || c == DELETE) c = printof(c); #endif break; @@ -213,7 +213,7 @@ normchar(register int c) putchar('^'), c = ctlof(c); #endif /* !BIT8 */ #ifdef UCVISUAL - else if (UPPERCASE) + else if (UPPERCASE) { if (xisupper(c)) { outchar('\\'); c = tolower(c); @@ -226,6 +226,7 @@ normchar(register int c) break; } } + } #endif /* UCVISUAL */ #ifdef BIT8 } @@ -276,9 +277,12 @@ int numbline(int i, int max) { + extern short vcntcol; if (shudclob) slobber(' '); - max -= printf("%6d ", i); + max -= ex_printf("%6d ", i); + if (max > 0) + vcntcol = value(NUMBER) << 3; return normline(0, max); } @@ -295,8 +299,7 @@ normline(int unused, int max) int c, n; int ret = 0; - if (max > 0) - vcntcol = 0; + (void)unused; if (shudclob) slobber(linebuf[0]); /* pdp-11 doprnt is not reentrant so can't use "printf" here @@ -626,7 +629,7 @@ plod(int cnt) * If it will be cheaper, or if we can't back up, then send * a return preliminarily. */ - if (j > i + 1 || outcol > destcol && !BS && !BC) { + if (j > i + 1 || (outcol > destcol && !BS && !BC)) { /* * BUG: this doesn't take the (possibly long) length * of xCR into account. @@ -825,11 +828,12 @@ fgoto(void) outcol %= TCOLUMNS; if (AM == 0) { while (l > 0) { - if (pfast && ospeed != B0) + if (pfast && ospeed != B0) { if (xCR) tputs(xCR, 0, putch); else putch('\r'); + } if (xNL) tputs(xNL, 0, putch); else @@ -881,7 +885,7 @@ fgoto(void) outcol = 0; } } - if (destline < outline && !(CA && !holdcm || UP != NOSTR)) + if (destline < outline && !((CA && !holdcm) || UP != NOSTR)) destline = outline; if (CA && !holdcm) if (plod(costCM) > 0) @@ -1185,14 +1189,16 @@ ttcharoff(void) #ifdef VSTATUS tty.c_cc[VSTATUS] = vdis; #endif -# ifdef VSTART /* * The following is sample code if USG ever lets people change * their start/stop chars. As long as they can't we can't get * into trouble so we just leave them alone. */ +# ifdef VSTART if (tty.c_cc[VSTART] != CTRL('q')) tty.c_cc[VSTART] = vdis; +# endif +# ifdef VSTOP if (tty.c_cc[VSTOP] != CTRL('s')) tty.c_cc[VSTOP] = vdis; # endif @@ -475,7 +475,7 @@ comprhs(int seof) #ifdef BIT8 qp = rhsquo; #endif - CP(orhsbuf, rp); + lcpy(orhsbuf, rp, sizeof orhsbuf); #ifdef BIT8 copy(orhsquo, qp, (size_t) strlen(rp)); #endif @@ -778,7 +778,7 @@ ovflo: loc2 += n; } #endif /* UXRE */ - while (*sp++ = *lp++) + while ((*sp++ = *lp++)) if (sp >= &genbuf[LBSIZE]) goto ovflo; strcLIN(genbuf); @@ -857,9 +857,9 @@ snote(register int total, register int lines) if (!notable(total)) return; - printf(mesg(catgets(catd, 1, 131, "%d subs|%d substitutions")), total); + ex_printf(mesg(catgets(catd, 1, 131, "%d subs|%d substitutions")), total); if (lines != 1 && lines != total) - printf(catgets(catd, 1, 132, " on %d lines"), lines); + ex_printf(catgets(catd, 1, 132, " on %d lines"), lines); noonl(); flush(); } @@ -141,7 +141,7 @@ dontset: cp = "window"; } for (op = options; op < &options[NOPTS]; op++) - if (eq(op->oname, cp) || op->oabbrev && eq(op->oabbrev, cp)) + if (eq(op->oname, cp) || (op->oabbrev && eq(op->oabbrev, cp))) break; if (op->oname == 0) serror(catgets(catd, 1, 159, @@ -296,18 +296,18 @@ propt(register struct option *op) switch (op->otype) { case ONOFF: - printf(catgets(catd, 1, 165, "%s%s"), + ex_printf(catgets(catd, 1, 165, "%s%s"), op->ovalue ? catgets(catd, 1, 166, "") : catgets(catd, 1, 167, "no"), name); break; case NUMERIC: - printf(catgets(catd, 1, 168, "%s=%d"), name, op->ovalue); + ex_printf(catgets(catd, 1, 168, "%s=%d"), name, op->ovalue); break; case STRING: case OTERM: - printf(catgets(catd, 1, 169, "%s=%s"), name, op->osvalue); + ex_printf(catgets(catd, 1, 169, "%s=%s"), name, op->osvalue); break; } } @@ -79,6 +79,7 @@ static char sccsid[] = "@(#)ex_subr.c 1.41 (gritter) 12/25/06"; /* from ex_subr.c 7.10.1 (2.11BSD) 1996/3/22 */ +#include <sys/ioctl.h> #include "ex.h" #include "ex_re.h" #include "ex_tty.h" @@ -95,7 +96,7 @@ any(int c, register char *s) { register int x; - while (x = *s++) + while ((x = *s++)) if (x == c) return (1); return (0); @@ -161,14 +162,60 @@ comment(void) ungetchar(c); } -void -Copy(register char *to, register char *from, register int size) -{ +/* + * strlcpy not used since buffers may overlap. + */ +size_t +lcpy(char *dst, const char *src, const size_t dstsize) { + size_t srclen = 0; + size_t copylen = dstsize; + /* avoids to access illegal memory in case + * of unterminated strings */ + while (srclen < copylen && src[srclen]) { + ++srclen; + } + if (srclen < copylen) { + /* '<' means there is room for the final 0 byte */ + copylen = srclen; + } else if (copylen) { + /* src string is too long. Set size to be copied to + * buffer size - 1 to have room for the final 0 byte */ + --copylen; + } + if (copylen) { + memcpy(dst, src, copylen); + } + if (dstsize) { + dst[copylen] = 0; + } + return srclen; /* [sic!] see strlcpy man page */ +} - if (size > 0) - do - *to++ = *from++; - while (--size > 0); +size_t +lcat(char *dst, const char *src, const size_t dstsize) { + size_t srclen = 0; + size_t dstlen = 0; + size_t copylen = dstsize; + while (dstlen < copylen && dst[dstlen]) { + ++dstlen; + } + dst += dstlen; + copylen -= dstlen; + while (srclen < copylen && src[srclen]) { + ++srclen; + } + if (srclen < copylen) { + copylen = srclen; + } else if (copylen) { + --copylen; + } + if (copylen) { + memcpy(dst, src, copylen); + } + if (dstsize) { + dst[dstlen + copylen] = 0; + } + return dstlen + srclen; /* [sic!] see strlcat man page */ } void @@ -340,9 +387,9 @@ killcnt(register int cnt) } if (!notable(cnt)) return; - printf(catgets(catd, 1, 170, "%d lines"), cnt); + ex_printf(catgets(catd, 1, 170, "%d lines"), cnt); if (value(TERSE) == 0) { - printf(catgets(catd, 1, 171, " %c%s"), + ex_printf(catgets(catd, 1, 171, " %c%s"), Command[0] | ' ', Command + 1); if (Command[strlen(Command) - 1] != 'e') putchar('e'); @@ -437,11 +484,11 @@ merror1(intptr_t seekpt) { #ifdef VMUNIX - strcpy(linebuf, (char *)seekpt); + lcpy(linebuf, (char *)seekpt, LBSIZE); #else lseek(erfile, (off_t) seekpt, SEEK_SET); if (read(erfile, linebuf, 128) < 2) - CP(linebuf, "ERROR"); + lcpy(linebuf, "ERROR", LBSIZE); #endif } @@ -553,7 +600,7 @@ netchange(register int i) } if (!notable(i)) return; - printf(mesg(catgets(catd, 1, 177, "%d %slines@in file after %s")), + ex_printf(mesg(catgets(catd, 1, 177, "%d %slines@in file after %s")), i, cp, Command); putNFL(); } @@ -816,7 +863,7 @@ void strcLIN(char *dp) { - CP(linebuf, dp); + lcpy(linebuf, dp, LBSIZE); } void @@ -928,9 +975,10 @@ int _ovno; void onemt(int signum) { - int oovno; + /* int oovno; unused? */ - oovno = _ovno; + (void)signum; + /* oovno = _ovno; unused? */ /* 2 and 3 are valid on 11/40 type vi, so */ if (_ovno < 0 || _ovno > 3) _ovno = 0; @@ -951,7 +999,7 @@ onemt(int signum) void onhup(int signum) { - + (void)signum; /* * USG tty driver can send multiple HUP's!! */ @@ -981,7 +1029,7 @@ onhup(int signum) void onintr(int signum) { - + (void)signum; alarm(0); /* in case we were called from map */ draino(); if (!inopen) { @@ -1061,6 +1109,7 @@ onsusp(int signum) #endif sigset_t set; + (void)signum; f = setty(normf); vnfl(); putpad(TE); @@ -1099,18 +1148,6 @@ onsusp(int signum) #endif /* SIGTSTP */ /* - * For regular strcpy(), source and destination may not overlap. - */ -char * -movestr(char *s1, const char *s2) -{ - char *cp = s1; - - while (*s1++ = *s2++); - return cp; -} - -/* * strcpy() checking the maximum size of s1, printing msg in case of overflow. */ char * @@ -203,7 +203,7 @@ getline(line tl) bp = getblock(tl, READ); nl = nleft; tl &= ~OFFMSK; - while (*lp++ = *bp++) + while ((*lp++ = *bp++)) if (--nl == 0) { bp = getblock(tl += INCRMT, READ); nl = nleft; @@ -224,7 +224,7 @@ putline(void) bp = getblock(tl, WRITE); nl = nleft; tl &= ~OFFMSK; - while (*bp = *lp++) { + while ((*bp = *lp++)) { if (*bp++ == '\n') { *--bp = 0; linebp = lp; @@ -509,7 +509,7 @@ oops: int REGblk(void) { - register int i, j, m; + unsigned int i, j, m; for (i = 0; i < sizeof rused / sizeof rused[0]; i++) { m = (rused[i] ^ 0177777) & 0177777; @@ -521,7 +521,7 @@ REGblk(void) j++, m >>= 1; rused[i] |= (1 << j); #ifdef RDEBUG - printf("allocating block %d\n", i * 16 + j); + ex_printf("allocating block %d\n", i * 16 + j); #endif return (i * 16 + j); } @@ -552,7 +552,7 @@ KILLreg(register int c) sp->rg_flags = sp->rg_nleft = 0; while (rblock != 0) { #ifdef RDEBUG - printf("freeing block %d\n", rblock); + ex_printf("freeing block %d\n", rblock); #endif rused[rblock / 16] &= ~(1 << (rblock % 16)); regio(rblock, (ssize_t (*)(int, void *, size_t))shread); @@ -679,20 +679,20 @@ YANKreg(register int c) rblock = 0; rnleft = 0; } - CP(savelb,linebuf); + lcpy(savelb,linebuf, LBSIZE); for (addr = addr1; addr <= addr2; addr++) { getline(*addr); if (sp->rg_flags) { if (addr == addr2) *wcursor = 0; if (addr == addr1) - strcpy(linebuf, cursor); + lcpy(linebuf, cursor, LBSIZE); } YANKline(); } rbflush(); killed(); - CP(linebuf,savelb); + lcpy(linebuf,savelb, LBSIZE); free(savelb); } @@ -79,6 +79,7 @@ static char sccsid[] = "@(#)ex_tty.c 1.30 (gritter) 8/4/05"; /* from ex_tty.c 7.10.1 (2.11BSD GTE) 12/9/94 */ +#include <sys/ioctl.h> #include "ex.h" #include "ex_tty.h" @@ -132,8 +133,7 @@ char **sstrs[] = { &ED, &EI, &F0, &F1, &F2, &F3, &F4, &F5, &F6, &F7, &F8, &F9, &HO, &IC, &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU, &LL, &ND, &xNL, &xPC, &RC, &SC, &SE, &SF, &SO, &SR, &TA, &TE, &TI, &UP, &VB, &VS, &VE, - &AL_PARM, &DL_PARM, &UP_PARM, &DOWN_PARM, &LEFT_PARM, &RIGHT_PARM, - &kI, &kD, &kh, &at7, &kP, &kN + &AL_PARM, &DL_PARM, &UP_PARM, &DOWN_PARM, &LEFT_PARM, &RIGHT_PARM }; bool *sflags[] = { &AM, &BS, &DA, &DB, &EO, &HC, @@ -158,7 +158,7 @@ setterm(char *type) putpad(TE); if (tgetent(ltcbuf, type) != 1) { unknown++; - CP(ltcbuf, "xx|dumb:"); + lcpy(ltcbuf, "xx|dumb:", sizeof ltcbuf); } gettmode(); /* must call gettmode() before setsize(). GR */ setsize(); @@ -171,12 +171,7 @@ setterm(char *type) addmac1(KD, "j", "down", arrows, 1); addmac1(KL, "h", "left", arrows, 1); addmac1(KR, "l", "right", arrows, 1); - addmac1(kI, "i", "insert", arrows, 1); - addmac1(kD, "x", "delete", arrows, 1); - addmac1(kh, "^", "home", arrows, 1); - addmac1(at7, "$", "end", arrows, 1); - addmac1(kP, "", "pgup", arrows, 1); - addmac1(kN, "", "pgdn", arrows, 1); + addmac1(KH, "H", "home", arrows, 1); /* * Handle funny termcap capabilities @@ -345,7 +340,7 @@ zap(void) *(*fp++) = flag; namp += 2; } while (*namp); - namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullndnlpcrcscsesfsosrtatetiupvbvsveALDLUPDOLERIkIkDkh@7kPkN"; + namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullndnlpcrcscsesfsosrtatetiupvbvsveALDLUPDOLERI"; sp = sstrs; do { string = tgetstr(namp, &aoftspace); diff --git a/ex_tty.c.orig b/ex_tty.c.orig deleted file mode 100644 index 7d3a7ed..0000000 --- a/ex_tty.c.orig +++ /dev/null @@ -1,405 +0,0 @@ -/* - * This code contains changes by - * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved. - * - * Conditions 1, 2, and 4 and the no-warranty notice below apply - * to these changes. - * - * - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * - * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * Redistributions of source code and documentation must retain the - * above copyright notice, this list of conditions and the following - * disclaimer. - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed or owned by Caldera - * International, Inc. - * Neither the name of Caldera International, Inc. nor the names of - * other contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA - * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE - * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef lint -#ifdef DOSCCS -static char sccsid[] = "@(#)ex_tty.c 1.30 (gritter) 8/4/05"; -#endif -#endif - -/* from ex_tty.c 7.10.1 (2.11BSD GTE) 12/9/94 */ - -#include "ex.h" -#include "ex_tty.h" - -int ATTN = DELETE; - -/* - * Terminal type initialization routines, - * and calculation of flags at entry or after - * a shell escape which may change them. - */ -/* short ospeed = -1; mjm: def also in tputs.c of termcap.a */ - -void -gettmode(void) -{ - speed_t pospeed; - - if (tcgetattr(1, &tty) < 0) { - ospeed = B0; - return; - } - pospeed = cfgetospeed(&tty); - if (ospeed != pospeed) - value(SLOWOPEN) = pospeed < B1200; - ospeed = pospeed; - normf = tty; -#if defined (UCVISUAL) && defined (IUCLC) - UPPERCASE = (tty.c_iflag & IUCLC) != 0; -#endif -#if defined (TAB3) - GT = (tty.c_oflag & TABDLY) != TAB3 && !XT; -#elif defined (XTABS) - GT = (tty.c_oflag & TABDLY) != XTABS && !XT; -#else - GT = !XT; -#endif /* !TAB3, XTABS */ - /* - * Tabs and multi-column characters do not combine properly - * unless vi performs a look-ahead on the current line. Just - * do not use them for now. - */ - if (mb_cur_max > 1) - GT = 0; - NONL = (tty.c_oflag & ONLCR) == 0; - ATTN = tty.c_cc[VINTR]; -} - -char *xPC; -char **sstrs[] = { - &AL, &BC, &BT, &CD, &CE, &CL, &CM, &xCR, &xCS, &DC, &DL, &DM, &DO, - &ED, &EI, &F0, &F1, &F2, &F3, &F4, &F5, &F6, &F7, &F8, &F9, - &HO, &IC, &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU, &LL, &ND, &xNL, - &xPC, &RC, &SC, &SE, &SF, &SO, &SR, &TA, &TE, &TI, &UP, &VB, &VS, &VE, - &AL_PARM, &DL_PARM, &UP_PARM, &DOWN_PARM, &LEFT_PARM, &RIGHT_PARM -}; -bool *sflags[] = { - &AM, &BS, &DA, &DB, &EO, &HC, -#ifdef UCVISUAL - &xHZ, -#endif - &IN, &MI, &NC, &NS, &OS, &UL, - &XB, &XN, &XT, &XX -}; -char **fkeys[10] = { - &F0, &F1, &F2, &F3, &F4, &F5, &F6, &F7, &F8, &F9 -}; -void -setterm(char *type) -{ - register int unknown; - char ltcbuf[TCBUFSIZE]; - - if (type[0] == 0) - type = "xx"; - unknown = 0; - putpad(TE); - if (tgetent(ltcbuf, type) != 1) { - unknown++; - CP(ltcbuf, "xx|dumb:"); - } - gettmode(); /* must call gettmode() before setsize(). GR */ - setsize(); - aoftspace = tspace; - zap(); - /* - * Initialize keypad arrow keys. - */ - addmac1(KU, "k", "up", arrows, 1); - addmac1(KD, "j", "down", arrows, 1); - addmac1(KL, "h", "left", arrows, 1); - addmac1(KR, "l", "right", arrows, 1); - addmac1(KH, "H", "home", arrows, 1); - - /* - * Handle funny termcap capabilities - */ - if (xCS && SC && RC) { - if (AL==NULL) AL=""; - if (DL==NULL) DL=""; - } - if (AL_PARM && AL==NULL) AL=""; - if (DL_PARM && DL==NULL) DL=""; - if (IC && IM==NULL) IM=""; - if (IC && EI==NULL) EI=""; - if (!GT) BT=NULL; /* If we can't tab, we can't backtab either */ - -#ifdef TIOCLGET -#define HAS_JOB_CONTROL -#endif -#ifdef _SC_JOB_CONTROL -#define HAS_JOB_CONTROL -#endif -#ifdef HAS_JOB_CONTROL - /* - * Now map users susp char to ^Z, being careful that the susp - * overrides any arrow key, but only for hackers (=new tty driver). - */ - { - static char sc[2]; - int i /* , fnd */; - - if (sysconf(_SC_JOB_CONTROL) != -1) - { - /* - * If a system supports job control but no job - * control shell is used, only one method of - * detection remains: Our session id equals our - * process group id. Any job control shell would - * have created at least one new process group. - * But as the VSUSP key may be active, we have - * to override arrow keys either. - */ -#ifndef _CRAY /* getsid() is a bad syscall on UNICOS */ - if (getsid(0) != getpgid(0)) -#endif /* !_CRAY */ - ldisc = 2; /* value of NTTYDISC */ - sc[0] = tty.c_cc[VSUSP]; - sc[1] = 0; - if (tty.c_cc[VSUSP] == CTRL('z')) { - for (i=0; i<=4; i++) - if (arrows[i].cap && - arrows[i].cap[0] == CTRL('z')) - addmac(sc, NULL, NULL, arrows); - } else if (sc[0] -#ifdef _PC_VDISABLE - && sc[0] != fpathconf(1, _PC_VDISABLE) -#endif - ) - addmac(sc, "\32", "susp", arrows); - } - } -#endif /* HAS_JOB_CONTROL */ - - if (CM != 0) { - if (tgoto(CM, 2, 2)[0] == 'O') /* OOPS */ - CA = 0, CM = 0; - else - CA = 1, costCM = cost(tgoto(CM, 8, 10)); - } else { - CA = 0, CM = 0; - } - costSR = cost(SR); - costAL = cost(AL); - costDP = cost(tgoto(DOWN_PARM, 10, 10)); - costLP = cost(tgoto(LEFT_PARM, 10, 10)); - costRP = cost(tgoto(RIGHT_PARM, 10, 10)); - PC = xPC ? xPC[0] : 0; - aoftspace = tspace; - safecp(ttylongname, gettlongname(ltcbuf, type), sizeof ttylongname, - "Terminal name too long"); - /* proper strings to change tty type */ - termreset(); - gettmode(); - value(REDRAW) = AL && DL; - value(OPTIMIZE) = !CA && !GT; - if (ospeed == B1200 && !value(REDRAW)) - value(SLOWOPEN) = 1; /* see also gettmode above */ - if (unknown) - serror(catgets(catd, 1, 191, - "%s: Unknown terminal type"), type); -} - -void -setsize(void) -{ - register int l, i; -#ifdef TIOCGWINSZ - struct winsize win; -#endif - - char *e; - -#ifdef TIOCGWINSZ - i = ioctl(0, TIOCGWINSZ, &win); -#endif - TLINES = TCOLUMNS = 0; - e = getenv("COLUMNS"); - if (e != NULL && *e != '\0') - TCOLUMNS = atoi(e); - if (TCOLUMNS <= 0) { -#ifdef TIOCGWINSZ - if (i >= 0 && win.ws_col != 0) - TCOLUMNS = winsz.ws_col = win.ws_col; - else -#endif - TCOLUMNS = tgetnum("co"); - } - e = getenv("LINES"); - if (e != NULL && *e != '\0') - TLINES = atoi(e); - if (TLINES <= 0) { -#ifdef TIOCGWINSZ - if (i >= 0 && win.ws_row != 0) - TLINES = winsz.ws_row = win.ws_row; - else -#endif - TLINES = tgetnum("li"); - } - i = TLINES; - if (TLINES <= 5) - TLINES = 24; - l = TLINES; - if (ospeed < B1200) - l = 9; /* including the message line at the bottom */ - else if (ospeed < B2400) - l = 17; - if (l > TLINES) - l = TLINES; - if (TCOLUMNS <= 4) - TCOLUMNS = 1000; - options[WINDOW].ovalue = options[WINDOW].odefault = l - 1; - if (defwind) { - options[WINDOW].ovalue = defwind; - l = defwind + 1; - } - options[SCROLL].ovalue = options[SCROLL].odefault = HC ? 11 : ((l-1) / 2); - if (i <= 0) - TLINES = 2; -} - -void -zap(void) -{ - register char *namp; - register bool **fp; - register char ***sp; - int flag; - char *string; - -#ifndef UCVISUAL - namp = "ambsdadbeohcinmincnsosulxbxnxtxx"; -#else - namp = "ambsdadbeohchzinmincnsosulxbxnxtxx"; -#endif - fp = sflags; - do { - flag = tgetflag(namp); - *(*fp++) = flag; - namp += 2; - } while (*namp); - namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullndnlpcrcscsesfsosrtatetiupvbvsveALDLUPDOLERI"; - sp = sstrs; - do { - string = tgetstr(namp, &aoftspace); - *(*sp++) = string; - namp += 2; - } while (*namp); -} - -char * -gettlongname(register char *bp, char *def) -{ - register char *cp; - - while (*bp && *bp != ':' && *bp != '|') - bp++; - if (*bp == '|') { - bp++; - cp = bp; - while (*cp && *cp != ':' && *cp != '|') - cp++; - *cp = 0; - return (bp); - } - return (def); -} - -char * -fkey(int i) -{ - if (0 <= i && i <= 9) - return(*fkeys[i]); - else - return(NOSTR); -} - -/* - * cost figures out how much (in characters) it costs to send the string - * str to the terminal. It takes into account padding information, as - * much as it can, for a typical case. (Right now the typical case assumes - * the number of lines affected is the size of the screen, since this is - * mainly used to decide if AL or SR is better, and this always happens - * at the top of the screen. We assume cursor motion (CM) has little - * padding, if any, required, so that case, which is really more important - * than AL vs SR, won't be really affected.) - */ -static int costnum; -int -cost(char *str) -{ - if (str == NULL || *str=='O') /* OOPS */ - return 10000; /* infinity */ - costnum = 0; - tputs(str, TLINES, countnum); - return costnum; -} - -/*ARGSUSED*/ -int -countnum(int ch) -{ - costnum++; - return ch; -} @@ -183,15 +183,6 @@ var bool XT; /* Tabs are destructive */ var bool XX; /* Tektronix 4025 insert line */ /* X? is reserved for severely nauseous glitches */ /* If there are enough of these we may need bit masks! */ -/* - * Insert, Delete, Home, End, PgUp an PgDown keys - */ -var char *kI; -var char *kD; -var char *kh; -var char *at7; -var char *kP; -var char *kN; /* * From the tty modes... @@ -101,7 +101,7 @@ unix0(int warn) char printub, puxb[UXBSIZE + sizeof (int)]; printub = 0; - CP(puxb, uxb); + lcpy(puxb, uxb, sizeof puxb); c = getchar(); if (c == '\n' || c == EOF) error(catgets(catd, 1, 192, @@ -179,7 +179,7 @@ uexp: if (warn && hush == 0 && chng && xchng != chng && value(WARN) && dol > zero) { xchng = chng; vnfl(); - printf(mesg(catgets(catd, 1, 197, + ex_printf(mesg(catgets(catd, 1, 197, "[No write]|[No write since last change]"))); noonl(); flush(); @@ -224,7 +224,7 @@ unixex(char *opt, char *up, int newstdin, int mode) if (dosusp) signal(SIGTSTP, SIG_DFL); #endif - if (inopen) + /*if (inopen)*/ f = setty(normf); if ((mode & 1) && pipe(pvec) < 0) { /* Newstdin should be io so it will be closed */ @@ -276,7 +276,7 @@ unixex(char *opt, char *up, int newstdin, int mode) if (ruptible) signal(SIGINT, SIG_DFL); execl(svalue(SHELL), "sh", opt, up, (char *)0); - printf(catgets(catd, 1, 201, "No %s!\n"), svalue(SHELL)); + ex_printf(catgets(catd, 1, 201, "No %s!\n"), svalue(SHELL)); error(NOSTR); } if (mode & 1) { @@ -306,7 +306,7 @@ unixwt(int c, struct termios f) setty(f); setrupt(); if (!inopen && c && hush == 0) { - printf("!\n"); + ex_printf("!\n"); flush(); termreset(); gettmode(); @@ -494,9 +494,7 @@ vok(register cell *atube) holdupd = 0; Peekkey = 0; vcnt = vcline = 0; - if (vSCROLL == 0) - vSCROLL = value(SCROLL); - /*old vSCROLL = (value(WINDOW)+1)/2;*//* round up so dft=6,11 */ + vSCROLL = value(SCROLL); } void @@ -505,6 +503,7 @@ vintr(int signum) extern JMP_BUF readbuf; extern int doingread; + (void)signum; signal(SIGINT, vintr); if (vcatch) onintr(SIGINT); @@ -540,6 +539,7 @@ vsetsiz(int size) void onwinch(int signum) { + (void)signum; vsave(); setty(normf); LONGJMP(venv, 1); @@ -110,11 +110,12 @@ vopen(line *tp, int p) tfixnl(), fprintf(trace, "vopen(%d, %d)\n", lineno(tp), p); #endif if (state != VISUAL) { - if (vcnt) + if (vcnt) { if (hold & HOLDROL) vup1(); else vclean(); + } /* * Forget all that we once knew. @@ -602,15 +603,16 @@ vrepaint(char *curs) /* * Deal with a totally useless display. */ - if (vcnt == 0 || vcline < 0 || vcline > vcnt || holdupd && state != VISUAL) { + if (vcnt == 0 || vcline < 0 || vcline > vcnt || (holdupd && state != VISUAL)) { register line *odol = dol; vcnt = 0; - if (holdupd) + if (holdupd) { if (state == VISUAL) ignore(peekkey()); else vup1(); + } holdupd = 0; if (odol == zero) fixzero(); @@ -708,7 +710,7 @@ vredraw(register int p) * search for first logical line affected by the redraw. */ vscrap(); - CP(temp, linebuf); + lcpy(temp, linebuf, LBSIZE); l = 0; tp = dot - vcline; if (vcnt == 0) @@ -920,7 +922,7 @@ vsync1(register int p) return; temp = smalloc(LBSIZE); vscrap(); - CP(temp, linebuf); + lcpy(temp, linebuf, LBSIZE); if (vcnt == 0) LINE(0) = WTOP; l = 0; @@ -935,7 +937,7 @@ vsync1(register int p) * the current line, or if this line is piled under the * next line (vreplace does this and we undo it). */ - if (l == 0 && state != VISUAL || + if ((l == 0 && state != VISUAL) || (l < vcnt && (vp->vliny <= p || vp[0].vliny == vp[1].vliny))) { if (l == 0 || vp->vliny < p || (vp->vflags & VDIRT)) { if (l == vcline) @@ -1056,7 +1058,7 @@ vreplace(int l, int cnt, int newcnt) * over them, since otherwise we will push them * slowly off the screen, a clear lose. */ - if (cnt == newcnt || vcnt - l == newcnt && AL && DL) { + if (cnt == newcnt || (vcnt - l == newcnt && AL && DL)) { if (cnt > 1 && l + cnt > vcnt) savenote++; vdirty(l, newcnt); @@ -1150,7 +1152,7 @@ sethard(void) vup1(); LINE(0) = WBOT; if (Pline == numbline) - vgoto(WBOT, 0), printf("%6d ", lineDOT()); + vgoto(WBOT, 0), ex_printf("%6d ", lineDOT()); } /* diff --git a/ex_version.c b/ex_version.c index 103d5a9..c485da1 100644 --- a/ex_version.c +++ b/ex_version.c @@ -75,12 +75,12 @@ #include "ex.h" -static char *versionstring = "@(#)Version 4.0 (gritter) 12/25/06"; +static char *versionstring = "@(#)Version 4.1.3 (gritter) 11/14/16"; void printver(void) { - printf("%s%s%s", versionstring + 4, + ex_printf("%s%s%s", versionstring + 4, #ifdef BIT8 "", "" #else @@ -317,7 +317,7 @@ again: d = xtoupper(c); else { colp = "({)}!|^~'~"; - while (d = *colp++) + while ((d = *colp++)) if (d == c) { d = *colp++; break; @@ -529,17 +529,17 @@ noteit(int must) { register int sdl = destline, sdc = destcol; - if (notecnt < 2 || !must && state == VISUAL) + if (notecnt < 2 || (!must && state == VISUAL)) return (0); splitw++; if (WBOT == WECHO) vmoveitup(1, 1); vigoto(WECHO, 0); - printf(catgets(catd, 1, 223, "%d %sline"), notecnt, notesgn); + ex_printf(catgets(catd, 1, 223, "%d %sline"), notecnt, notesgn); if (notecnt > 1) putchar('s'); if (*notenam) { - printf(" %s", notenam); + ex_printf(" %s", notenam); if (*(strend(notenam) - 1) != 'e') putchar('e'); putchar('d'); @@ -636,7 +636,7 @@ map(register int c, register struct maps *maps) if (trace) fprintf(trace,"\ntry '%s', ",maps[d].cap); #endif - if (p = maps[d].icap) { + if ((p = maps[d].icap)) { for (q=b; *p; p++, q++) { #ifdef MDEBUG if (trace) @@ -725,13 +725,13 @@ macpush(char *st, int canundo) error(catgets(catd, 1, 224, "Macro too long@ - maybe recursive?")); if (vmacp) { - strcpy(tmpbuf, vmacp); + lcpy(tmpbuf, vmacp, sizeof tmpbuf); if (!FIXUNDO) canundo = 0; /* can't undo inside a macro anyway */ } - strcpy(vmacbuf, st); + lcpy(vmacbuf, st, sizeof vmacbuf); if (vmacp) - strcat(vmacbuf, tmpbuf); + lcat(vmacbuf, tmpbuf, sizeof vmacbuf); vmacp = vmacbuf; /* arrange to be able to undo the whole macro */ if (canundo) { @@ -777,7 +777,7 @@ vudump(char *s) fprintf(trace, " undadot=%d, dot=%d, dol=%d, unddol=%d, truedol=%d\n", lineno(undadot), lineno(dot), lineno(dol), lineno(unddol), lineno(truedol)); fprintf(trace, " [\n"); - CP(savelb, linebuf); + lcpy(savelb, linebuf, sizeof savelb); fprintf(trace, "linebuf = '%s'\n", linebuf); for (p=zero+1; p<=truedol; p++) { fprintf(trace, "%o ", *p); @@ -785,7 +785,7 @@ vudump(char *s) fprintf(trace, "'%s'\n", linebuf); } fprintf(trace, "]\n"); - CP(linebuf, savelb); + lcpy(linebuf, savelb, LBSIZE); } #endif @@ -813,6 +813,7 @@ vgetcnt(void) void trapalarm(int signum) { + (void)signum; alarm(0); if (vcatch) LONGJMP(vreslab,1); @@ -159,7 +159,7 @@ vmain(void) Xhadcnt = hadcnt = 0; Xcnt = cnt = 1; splitw = 0; - if (i = holdupd) { + if ((i = holdupd)) { if (state == VISUAL) ignore(peekkey()); holdupd = 0; @@ -204,7 +204,7 @@ looptop: * an 'empty' named buffer spec in the routine * kshift (see ex_temp.c). */ - forbid (c == '0' || !xisalpha(c) && !xisdigit(c)); + forbid (c == '0' || (!xisalpha(c) && !xisdigit(c))); vreg = c; } reread: @@ -836,7 +836,7 @@ case_ATTN: vmacchng(1); setLAST(); i = 0; - if (vreg && partreg(vreg) || !vreg && pkill[0]) { + if ((vreg && partreg(vreg)) || (!vreg && pkill[0])) { /* * Restoring multiple lines which were partial * lines; will leave cursor in middle @@ -1123,7 +1123,10 @@ fixup: * in open mode and . moved, then redraw. */ i = vcline + (dot - addr); - if (i < 0 || i >= vcnt && i >= -vcnt || state != VISUAL && dot != addr) { + if (i < 0 + || (vcnt >= 0 && i >= vcnt) + || (vcnt < 0 && i >= -vcnt) + || (state != VISUAL && dot != addr)) { if (state == CRTOPEN) vup1(); if (vcnt > 0) @@ -1275,8 +1278,8 @@ vsave(void) { char *temp = smalloc(LBSIZE); - CP(temp, linebuf); - if (FIXUNDO && vundkind == VCHNG || vundkind == VCAPU) { + lcpy(temp, linebuf, LBSIZE); + if ((FIXUNDO && vundkind == VCHNG) || vundkind == VCAPU) { /* * If the undo state is saved in the temporary buffer * vutmp, then we sync this into the temp file so that @@ -1286,7 +1289,7 @@ vsave(void) * with line dot (e.g. in case ':') above, so beware. */ prepapp(); - CP(linebuf, vutmp); + lcpy(linebuf, vutmp, LBSIZE); putmark(dot); vremote(1, yank, 0); vundkind = VMCHNG; @@ -1416,7 +1419,7 @@ str2cell(cell *dst, register char *src) } while (src[-n]); } else #endif /* MB */ - while (*cp++ = *src++ & 0377); + while ((*cp++ = *src++ & 0377)); return dst; } @@ -1425,7 +1428,7 @@ cell2str(char *dst, register cell *src) { register char *cp = dst; - while (*cp++ = *src++); + while ((*cp++ = *src++)); return dst; } @@ -1434,7 +1437,7 @@ cellcpy(cell *dst, register cell *src) { register cell *cp = dst; - while (*cp++ = *src++); + while ((*cp++ = *src++)); return dst; } @@ -159,7 +159,7 @@ operate(register int c, register int cnt) * c Change operator. */ case 'c': - if (c == 'c' && workcmd[0] == 'C' || workcmd[0] == 'S') + if ((c == 'c' && workcmd[0] == 'C') || workcmd[0] == 'S') subop++; moveop = vchange; deleteop = (void (*)(int))beep; @@ -492,13 +492,13 @@ fixup: */ case 'l': case ' ': - forbid (margin() || opf == vmove && edge()); + forbid (margin() || (opf == vmove && edge())); while (cnt > 0 && !margin()) { wcursor += dir>0 ? skipright(linebuf, wcursor) : skipleft(linebuf, wcursor); cnt--; } - if (margin() && opf == vmove || wcursor < linebuf) + if ((margin() && opf == vmove) || wcursor < linebuf) wcursor -= dir; vmoving = 0; break; @@ -838,7 +838,7 @@ find(int c) int word(register void (*op)(int), int cnt) { - register int which = 0, i; + register int which, i; register char *iwc; register line *iwdot = wdot; @@ -881,6 +881,7 @@ word(register void (*op)(int), int cnt) while (!margin() && wordof(which, wcursor)) wcursor--; } + which = wordch(wcursor); if (wcursor < linebuf || !wordof(which, wcursor)) wcursor += skipright(linebuf, wcursor); } @@ -173,12 +173,13 @@ vundo ( * with dol through unddol-1. Hack screen image to * reflect this replacement. */ - if (show) + if (show) { if (undkind == UNDMOVE) vdirty(0, TLINES); else vreplace(undap1 - addr, undap2 - undap1, undkind == UNDPUT ? 0 : unddol - dol); + } savenote = notecnt; undo(1); if (show && (vundkind != VMCHNG || addr != dot)) @@ -202,7 +203,7 @@ vundo ( case VCHNG: case VCAPU: vundkind = VCHNG; - CP(temp, vutmp); + lcpy(temp, vutmp, LBSIZE); CP(vutmp, linebuf); doomed = column(vUA2 - 1) - column(vUA1 - 1); strcLIN(temp); @@ -290,7 +291,7 @@ vmacchng(int fromvis) vudump("before vmacchng hairy case"); #endif savedot = dot; savedol = dol; savecursor = cursor; - CP(savelb, linebuf); + lcpy(savelb, linebuf, LBSIZE); nlines = dol - zero; while ((line *) endcore - truedol < nlines) morelines(); @@ -322,7 +323,7 @@ vmacchng(int fromvis) truedol -= nlines; copyw(zero+1, truedol+1, nlines); dot = savedot; dol = savedol ; cursor = savecursor; - CP(linebuf, savelb); + lcpy(linebuf, savelb, LBSIZE); vch_mac = VC_MANYCHANGE; /* Arrange that no further undo saving happens within macro */ @@ -370,6 +371,7 @@ vmove(int unused) { register int cnt; + (void)unused; if (wdot) { if (wdot < one || wdot > dol) { beep(); @@ -530,7 +532,7 @@ vchange(int c) *cursor = 0; strcpy(genbuf, linebuf); getline(*wdot); - if (strlen(genbuf) + strlen(wcursor) > LBSIZE - 2) { + if ((ssize_t)(strlen(genbuf) + strlen(wcursor)) > LBSIZE - 2) { getDOT(); beep(); return; @@ -730,7 +732,7 @@ voOpen ( sigset_t set, oset; #endif - if (value(SLOWOPEN) || value(REDRAW) && AL && DL) + if (value(SLOWOPEN) || (value(REDRAW) && AL && DL)) cnt = 1; #ifdef SIGWINCH sigemptyset(&set); @@ -804,6 +806,7 @@ vshftop(int unused) register line *addr; register int cnt; + (void)unused; if ((cnt = xdw()) < 0) return; addr = dot; @@ -834,6 +837,7 @@ vfilter(int unused) cell cuxb[UXBSIZE + 2]; #endif + (void)unused; if ((cnt = xdw()) < 0) return; if (vglobp) @@ -968,7 +972,7 @@ xdw(void) void vshift(int unused) { - + (void)unused; shift(op, 1); } @@ -981,7 +985,7 @@ vrep(register int cnt) { register int i, c; - if (cnt > strlen(cursor)) { + if (cnt > (ssize_t)strlen(cursor)) { beep(); return; } @@ -1024,6 +1028,7 @@ vyankit(int unused) { register int cnt; + (void)unused; if (wdot) { if ((cnt = xdw()) < 0) return; @@ -178,7 +178,7 @@ showmode(int mode) char *ocurs, *str; if (value(SHOWMODE) == 0 || TCOLUMNS <= 20 || state == ONEOPEN - || state == HARDOPEN || vmacp != NULL) + || state == HARDOPEN /*|| vmacp != NULL*/) return; ocurs = cursor; fixech(); @@ -211,7 +211,7 @@ showmode(int mode) if (value(TERSE)) putchar(str[0]); else - printf(&str[1]); + ex_printf(&str[1]); vgoto(sdl, sdc); cursor = ocurs; splitw = 0; @@ -426,7 +426,7 @@ vappend(int ch, int cnt, int indent) Outchar = vinschar; hold |= HOLDQIK; - printf("%s", genbuf); + ex_printf("%s", genbuf); hold = oldhold; Outchar = vputchar; } @@ -806,7 +806,7 @@ vbackup: } if (value(WRAPMARGIN) && (outcol >= OCOLUMNS - value(WRAPMARGIN) || - backsl && outcol==0) && + (backsl && outcol == 0)) && commch != 'r') { /* * At end of word and hit wrapmargin. @@ -961,7 +961,7 @@ btrp: * generated autoindent. We count the ^D for repeat * purposes. */ - if (c == iwhite && c != 0) + if (c == iwhite && c != 0) { if (cp == gcursor) { iwhite = backtab(c); CDCNT++; @@ -985,6 +985,7 @@ btrp: vputchar(' '); goto vbackup; } + } if (vglobp && vglobp - iglobp >= 2 && (vglobp[-2] == '^' || vglobp[-2] == '0') && gcursor == ogcursor + 1) @@ -127,7 +127,7 @@ llfind(bool pastatom, int cnt, void (*f)(int), line *limit) */ wasend = 0; lf = f; - strcpy(save, linebuf); + lcpy(save, linebuf, LBSIZE); if (limit == 0) limit = dir < 0 ? one : dol; llimit = limit; @@ -195,7 +195,7 @@ begin: while (!endsent(pastatom)) if (!lnext()) goto ret; - if (!pastatom || wcursor == linebuf && endPS()) + if (!pastatom || (wcursor == linebuf && endPS())) if (--cnt <= 0) break; if (linebuf[0] == 0) { @@ -231,7 +231,7 @@ begin: * If we are not at a section/paragraph division, * advance to next. */ - if (wcursor == icurs && wdot == idot || wcursor != linebuf || !endPS()) + if ((wcursor == icurs && wdot == idot) || wcursor != linebuf || !endPS()) ignore(lskipa1("")); } #ifdef LISPCODE @@ -241,7 +241,7 @@ begin: * Startup by skipping if at a ( going left or a ) going * right to keep from getting stuck immediately. */ - if (dir < 0 && c == '(' || dir > 0 && c == ')') { + if ((dir < 0 && c == '(') || (dir > 0 && c == ')')) { if (!lnext()) { rc = -1; goto ret; @@ -257,7 +257,7 @@ begin: */ while (cnt > 0) { c = *wcursor; - if (dir < 0 && c == ')' || dir > 0 && c == '(') { + if ((dir < 0 && c == ')') || (dir > 0 && c == '(')) { if (!lskipbal("()")) goto ret; /* @@ -270,7 +270,7 @@ begin: if (!lnext() || !ltosolid()) goto ret; --cnt; - } else if (dir < 0 && c == '(' || dir > 0 && c == ')') + } else if ((dir < 0 && c == '(') || (dir > 0 && c == ')')) /* Found a higher level paren */ goto ret; else { @@ -297,6 +297,7 @@ endsent(bool pastatom) register char *cp = wcursor; register int c, d; + (void)pastatom; /* * If this is the beginning of a line, then * check for the end of a paragraph or section. @@ -316,7 +317,7 @@ endsent(bool pastatom) if ((d = *++cp) == 0) return (1); while (any(d, ")]'")); - if (*cp == 0 || *cp++ == ' ' && *cp == ' ') + if (*cp == 0 || (*cp++ == ' ' && *cp == ' ')) return (1); tryps: if (cp[1] == 0) @@ -430,7 +431,7 @@ lsmatch(char *cp) register char *scurs = cursor; wcursor = cp; - strcpy(sp, linebuf); + lcpy(sp, linebuf, LBSIZE); *wcursor = 0; strcpy(cursor, genbuf); cursor = strend(linebuf) - 1; @@ -588,7 +589,7 @@ lbrack(register int c, void (*f)(int)) getline(*addr); if (linebuf[0] == '{' || #ifdef LISPCODE - value(LISP) && linebuf[0] == '(' || + (value(LISP) && linebuf[0] == '(') || #endif isa(svalue(SECTIONS))) { if (c == ']' && f != vmove) { @@ -716,6 +717,7 @@ wskipright(char *line, char *pos) { int c, n; + (void)line; nextc(c, pos, n); return n; } @@ -155,7 +155,7 @@ vclreol(void) i = WCOLS - destcol; tp = vtube[destline] + destcol; if (CE) { - if (IN && *tp || !ateopr()) { + if ((IN && *tp) || !ateopr()) { vcsync(); vputp(CE, 1); } @@ -1018,7 +1018,7 @@ viin(int c) short oldhold = hold; hold |= HOLDPUPD; - if (tabsize && (IM && EI) && inssiz - doomed > tabslack) + if (tabsize && (IM && EI) && inssiz - doomed > tabslack) { /* * There is a tab out there which will be affected * by the insertion since there aren't enough doomed @@ -1057,6 +1057,7 @@ viin(int c) enddm(); } } + } /* * Now put out the characters of the actual insertion. @@ -1067,7 +1068,7 @@ viin(int c) if (remdoom > insmc1) { remdoom--; endim(); - } else if (noim || insmc1 && remdoom == insmc1) + } else if (noim || (insmc1 && remdoom == insmc1)) endim(); else if (IM && EI) { vcsync(); @@ -1076,7 +1077,7 @@ viin(int c) vputchar(c); } - if (!IM || !EI || remdoom && remdoom == insmc1) { + if (!IM || !EI || (remdoom && remdoom == insmc1)) { /* * We are a dumb terminal; brute force update * the rest of the line; this is very much an n^^2 process, @@ -1388,7 +1389,7 @@ def: * that we have overstruct something. */ if (!insmode && d && d != ' ' && d != (c & TRIM)) { - if (EO && (OS || UL && (c == '_' || d == '_'))) { + if (EO && (OS || (UL && (c == '_' || d == '_')))) { vputc(' '); outcol++, destcol++; back1(); @@ -1551,7 +1552,7 @@ physdc(int stcol, int endcol) if (IN) { up = vtube0 + stcol; tp = vtube0 + endcol; - while (i = *tp++) { + while ((i = *tp++)) { if ((i & (QUOTE|TRIM)) == QUOTE) break; *up++ = i; @@ -453,7 +453,7 @@ vrollR(register int cnt) /* * Go into cooked mode (allow interrupts) during * a scroll if we are at less than 1200 baud and not - * a 'vi' command, of if we are in a 'vi' command and the + * a 'vi' command, or if we are in a 'vi' command and the * scroll is more than 2 full screens. * * BUG: An interrupt during a scroll in this way @@ -463,7 +463,7 @@ int vcookit(register int cnt) { - return (cnt > 1 && (ospeed < B1200 && !initev || cnt > TLINES * 2)); + return (cnt > 1 && ((ospeed < B1200 && !initev) || cnt > TLINES * 2)); } /* diff --git a/expreserve.c b/expreserve.c index 29a1b4b..d6c3c9b 100644 --- a/expreserve.c +++ b/expreserve.c @@ -102,6 +102,9 @@ static char sccsid[] UNUSED = "@(#)expreserve.c 1.23 (gritter) 11/27/04"; #include <stdlib.h> #include <pwd.h> #include <time.h> +#if !defined(HAVE_STRLCPY) || !defined(HAVE_STRLCAT) +# include "compat.h" +#endif #include "config.h" @@ -217,6 +220,7 @@ main(int argc, char **argv) struct dirent *dirent; struct stat stbuf; + (void)argv; #ifdef LANGMSG setlocale(LC_MESSAGES, ""); catd = catopen(CATNAME, NL_CAT_LOCALE); @@ -272,7 +276,7 @@ main(int argc, char **argv) #ifdef notdef char pattern[] = "/usr/preserve/Exaa`XXXXX"; #else -char pattern[] = "/var/lib/ex/Exa`XXXXXXXXXX"; +char pattern[] = PRESERVEDIR "/Exa`XXXXXXXXXX"; #endif /* @@ -296,7 +300,7 @@ notify(uid_t uid, char *fname, int flag, time_t time) timestamp = ctime(&time); timestamp[16] = 0; /* blast from seconds on */ putenv("MAILRC=/dev/null"); - sprintf(cmd, "/usr/bin/mail %s", pp->pw_name); + snprintf(cmd, sizeof cmd, "/bin/mail %s", pp->pw_name); setuid(getuid()); mf = popen(cmd, "w"); if (mf == NULL) @@ -308,7 +312,7 @@ notify(uid_t uid, char *fname, int flag, time_t time) * error message. Usually, either it was forcably terminated * or the phone was hung up, but we don't know which. */ - sprintf(croak, flag + snprintf(croak, sizeof croak, flag ? catgets(catd, 3, 2, "the system went down") : catgets(catd, 3, 3, "the editor was killed")); if (fname[0] == 0) { @@ -426,7 +430,7 @@ format: * LOST, by putting this in the header. */ if (H.Savedfile[0] == 0) { - strcpy(H.Savedfile, "LOST"); + memcpy(H.Savedfile, "LOST", 5); ignore(write(0, (char *) &H, sizeof H)); H.Savedfile[0] = 0; lseek(0, (off_t) 0, SEEK_SET); diff --git a/exrecover.c b/exrecover.c index 17ba06f..c9a45a8 100644 --- a/exrecover.c +++ b/exrecover.c @@ -98,7 +98,8 @@ static char sccsid[] UNUSED = "@(#)exrecover.c 1.23 (gritter) 12/25/06"; #define xstderr (int*)0 typedef int xFILE; extern void perror(const char *); -extern int vsprintf(char *, const char *, va_list); +#include <sys/types.h> +extern int vsnprintf(char *, size_t, const char *, va_list); #endif #define var @@ -108,6 +109,9 @@ extern int vsprintf(char *, const char *, va_list); #include "ex_tty.h" #include <dirent.h> #include <time.h> +#if !defined(HAVE_STRLCPY) || !defined(HAVE_STRLCAT) +# include "compat.h" +#endif #ifndef MAXNAMLEN #ifdef FNSIZE @@ -167,7 +171,7 @@ struct svfile { #ifdef notdef char mydir[] = "/usr/preserve"; #else -char mydir[] = "/var/lib/ex"; +char mydir[] = PRESERVEDIR; #endif /* @@ -238,7 +242,7 @@ main(int argc, char *argv[]) error(catgets(catd, 2, 1, " Wrong number of arguments to exrecover"), 0); - strcpy(file, argv[2]); + strlcpy(file, argv[2], sizeof file); /* * Search for this file. @@ -277,7 +281,7 @@ main(int argc, char *argv[]) while (H.Flines > 0) { ignorl(lseek(tfile, (off_t) ((blocks[b] & BLKMSK) * BUFSIZ), SEEK_SET)); - i = H.Flines < BUFSIZ / sizeof (line) ? + i = H.Flines < (ssize_t)(BUFSIZ / sizeof (line)) ? H.Flines * sizeof (line) : BUFSIZ; if (read(tfile, (char *) dot, i) != i) { perror(nb); @@ -478,7 +482,7 @@ enter(struct svfile *fp, char *fname, int count) fp->sf_time = H.Time; fp->sf_lines = H.Flines; cp2 = fp->sf_name, cp = savedfile; - while (*cp2++ = *cp++); + while ((*cp2++ = *cp++)); for (cp2 = fp->sf_entry, cp = fname; *cp && cp-fname < 14;) *cp2++ = *cp++; *cp2++ = 0; @@ -493,7 +497,7 @@ qucmp(struct svfile *p1, struct svfile *p2) { register int t; - if (t = strcmp(p1->sf_name, p2->sf_name)) + if ((t = strcmp(p1->sf_name, p2->sf_name))) return(t); if (p1->sf_time > p2->sf_time) return(-1); @@ -537,7 +541,7 @@ findtmp(char *dir) * name for later unlinking. */ tfile = bestfd; - strcpy(nb, bestnb); + strlcpy(nb, bestnb, sizeof nb); ignorl(lseek(tfile, (off_t) 0, SEEK_SET)); /* @@ -584,7 +588,9 @@ searchdir(char *dirname) * later, and check that this is really a file * we are looking for. */ - ignore(strcat(strcat(strcpy(nb, dirname), "/"), dirent->d_name)); + strlcpy(nb, dirname, sizeof nb); + strlcat(nb, "/", sizeof nb); + strlcat(nb, dirent->d_name, sizeof nb); if (yeah(nb)) { /* * Well, it is the file we are looking for. @@ -597,7 +603,7 @@ searchdir(char *dirname) ignore(close(bestfd)); bestfd = dup(tfile); besttime = H.Time; - strcpy(bestnb, nb); + strlcpy(bestnb, nb, sizeof bestnb); } /* * Count versions so user can be told there are @@ -754,6 +760,7 @@ putfile(int unused) register char *fp, *lp; register int nib; + (void)unused; a1 = addr1; clrstats(); cntln = addr2 - a1 + 1; @@ -816,7 +823,7 @@ getline(line tl) bp = getblock(tl, READ); nl = nleft; tl &= ~OFFMSK; - while (*lp++ = *bp++) + while ((*lp++ = *bp++)) if (--nl == 0) { bp = getblock(tl += INCRMT, READ); nl = nleft; @@ -888,7 +895,7 @@ xvfprintf(xFILE *fp, char *fmt, va_list ap) if (fp != xstderr) return; - vsprintf(buf, fmt, ap); + vsnprintf(buf, sizeof buf, fmt, ap); write(2, buf, strlen(buf)); } diff --git a/libterm/Makefile b/libterm/Makefile index b3432b1..c2ab882 100644 --- a/libterm/Makefile +++ b/libterm/Makefile @@ -41,21 +41,23 @@ # # Sccsid @(#)Makefile 1.2 (gritter) 2/4/02 # + +LIB = libtermlib.a DEFS = -DCM_N -DCM_GT -DCM_B -DCM_D -# COPT comes from ex. -CFLAGS = $(DEFS) $(COPT) SRCS = termcap.c tgoto.c tputs.c -OBJS = termcap.o tgoto.o tputs.o +OBJS = $(SRCS:.c=.o) -.c.o: ; $(CC) $(CFLAGS) -c $< +.c.o: + # COPT comes from ex + $(CC) $(CFLAGS) $(DEFS) $(COPT) -c $< -all: libtermlib.a +all: $(LIB) -libtermlib.a: $(OBJS) - ar cr libtermlib.a $(OBJS) +$(LIB): $(OBJS) + $(AR) crs $@ $(OBJS) clean: - rm -f libtermlib.a $(OBJS) core + rm -f $(LIB) $(OBJS) core # DO NOT DELETE diff --git a/libterm/termcap.c b/libterm/termcap.c index 6cee780..a4d018e 100644 --- a/libterm/termcap.c +++ b/libterm/termcap.c @@ -406,5 +406,5 @@ nextc: } /* -*/ static const char sccssl[] = "@(#)libterm.sl 1.7 (gritter) 11/23/04"; +*/ diff --git a/libterm/tgoto.c b/libterm/tgoto.c index 07316db..c497046 100644 --- a/libterm/tgoto.c +++ b/libterm/tgoto.c @@ -102,7 +102,7 @@ toohard: return ("OOPS"); } added[0] = 0; - while (c = *cp++) { + while ((c = *cp++)) { if (c != '%') { *dp++ = c; continue; diff --git a/libterm/tputs.c b/libterm/tputs.c index 58e0665..18fc579 100644 --- a/libterm/tputs.c +++ b/libterm/tputs.c @@ -116,7 +116,7 @@ tputs(const char *cp, int affcnt, int (*outc)(int)) */ if (i == 0) return 1; - if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0])) + if (ospeed <= 0 || ospeed >= (int)(sizeof tmspc10 / sizeof tmspc10[0])) return 1; /* diff --git a/libuxre/CVS/Entries b/libuxre/CVS/Entries new file mode 100644 index 0000000..3d7a5f2 --- /dev/null +++ b/libuxre/CVS/Entries @@ -0,0 +1,21 @@ +/COPYING.LGPL/1.1.1.1/Sat Dec 4 13:51:20 2004// +/Makefile.mk/1.2/Sun Jan 22 21:47:27 2006// +/NOTES/1.1.1.1/Sat Dec 4 13:51:18 2004// +/_collelem.c/1.1.1.1/Sat Dec 4 13:51:19 2004// +/_collmult.c/1.1.1.1/Sat Dec 4 13:51:19 2004// +/bracket.c/1.1.1.1/Sat Dec 4 13:51:19 2004// +/colldata.h/1.1.1.1/Sat Dec 4 13:51:18 2004// +/onefile.c/1.1.1.1/Sat Dec 4 13:51:19 2004// +/re.h/1.2/Sun Feb 6 14:58:27 2005// +/regcomp.c/1.1.1.1/Sat Dec 4 13:51:20 2004// +/regdfa.c/1.1.1.1/Sat Dec 4 13:51:20 2004// +/regdfa.h/1.1.1.1/Sat Dec 4 13:51:20 2004// +/regerror.c/1.1.1.1/Sat Dec 4 13:51:19 2004// +/regex.h/1.2/Sun Feb 6 14:58:27 2005// +/regexec.c/1.2/Sun Feb 6 16:14:00 2005// +/regfree.c/1.1.1.1/Sat Dec 4 13:51:20 2004// +/regnfa.c/1.2/Sun Feb 6 14:58:27 2005// +/regparse.c/1.1.1.1/Sat Dec 4 13:51:19 2004// +/stubs.c/1.3/Sun Jun 26 18:52:43 2005// +/wcharm.h/1.1.1.1/Sat Dec 4 13:51:19 2004// +D diff --git a/libuxre/CVS/Repository b/libuxre/CVS/Repository new file mode 100644 index 0000000..9a6917a --- /dev/null +++ b/libuxre/CVS/Repository @@ -0,0 +1 @@ +heirloom/libuxre diff --git a/libuxre/CVS/Root b/libuxre/CVS/Root new file mode 100644 index 0000000..9a7684b --- /dev/null +++ b/libuxre/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@heirloom.cvs.sourceforge.net:/cvsroot/heirloom diff --git a/libuxre/Makefile b/libuxre/Makefile index 46d7320..f568cf7 100644..120000 --- a/libuxre/Makefile +++ b/libuxre/Makefile @@ -1,12 +1 @@ -CFLAGS = $(COPT) $(RPMCFLAGS) -I. -OBJS = bracket.o _collelem.o _collmult.o regcomp.o regdfa.o regerror.o regexec.o regfree.o regnfa.o regparse.o stubs.o - -.c.o: ; $(CC) $(CFLAGS) -c $< - -all: libuxre.a - -libuxre.a: $(OBJS) - ar cr libuxre.a $(OBJS) - -clean: - rm -f libuxre.a $(OBJS) core +Makefile.mk
\ No newline at end of file diff --git a/libuxre/Makefile.mk b/libuxre/Makefile.mk new file mode 100644 index 0000000..106e132 --- /dev/null +++ b/libuxre/Makefile.mk @@ -0,0 +1,32 @@ +all: libuxre.a + +#OBJ = bracket.o _collelem.o _collmult.o regcomp.o regdfa.o regerror.o \ +# regexec.o regfree.o regnfa.o regparse.o stubs.o + +OBJ = onefile.o regfree.o regerror.o + +libuxre.a: $(OBJ) + $(AR) crs $@ $(OBJ) + +.c.o: + $(CC) $(CFLAGS2) $(CPPFLAGS) $(XO5FL) $(IWCHAR) $(COPT) -I. -c $< + +install: + +clean: + rm -f libuxre.a $(OBJ) core log *~ + +_collelem.o: colldata.h re.h regex.h wcharm.h +_collmult.o: colldata.h re.h regex.h wcharm.h +bracket.o: colldata.h re.h regex.h wcharm.h +regcomp.o: colldata.h re.h regex.h wcharm.h +regdfa.o: colldata.h regdfa.h re.h regex.h wcharm.h +regerror.o: colldata.h re.h regex.h wcharm.h +regexec.o: colldata.h re.h regex.h wcharm.h +regfree.o: colldata.h re.h regex.h wcharm.h +regnfa.o: colldata.h re.h regex.h wcharm.h +regparse.o: colldata.h re.h regex.h wcharm.h +stubs.o: colldata.h wcharm.h +onefile.o: _collelem.c _collmult.c bracket.c regcomp.c regdfa.c regexec.c +onefile.o: regfree.c regnfa.c regparse.c stubs.c +MRPROPER = libuxre.a diff --git a/libuxre/bracket.c b/libuxre/bracket.c index bc31b23..cb8db72 100644 --- a/libuxre/bracket.c +++ b/libuxre/bracket.c @@ -130,6 +130,7 @@ place(Bracket *bp, wchar_t wc, w_type prev, int mb_cur_max) CollElem spare; int ret; + (void)mb_cur_max; if ((cep = libuxre_collelem(bp->col, &spare, wc)) != ELEM_ENCODED) { if (cep == ELEM_BADCHAR) @@ -338,7 +339,7 @@ eqcls(Bracket *bp, const unsigned char *s, int n, w_type prev, int mb_cur_max) * Permit ranges up to the first and * after the last. */ - if (prev > 0 && prev != cep->weight[0] + if (prev > 0 && (unsigned)prev != cep->weight[0] && (prev = addrange(bp, cep->weight[0], prev)) != 0) { @@ -426,7 +427,7 @@ LIBUXRE_STATIC int libuxre_bktmbcomp(Bracket *bp, const unsigned char *pat0, int flags, int mb_cur_max) { - static const Bracket zero = {0}; + static const Bracket zero; const unsigned char *pat = pat0; struct lc_collate *savecol; w_type n, wc, prev = 0; @@ -709,11 +710,12 @@ libuxre_bktmbexec(Bracket *bp, wchar_t wc, } for (;;) { - if (iswctype(mb_cur_max==1?btowc(wc):wc, *wctp)) + if (iswctype(mb_cur_max == 1 ? btowc(wc) + : (wint_t)wc, *wctp)) goto match; if (wc != mcbuf.ch && - iswctype(mb_cur_max==1?btowc(mcbuf.ch):mcbuf.ch, - *wctp)) + iswctype(mb_cur_max == 1 ? btowc(mcbuf.ch) + : (wint_t)mcbuf.ch, *wctp)) goto match; if (--i == 0) break; @@ -801,7 +803,7 @@ libuxre_bktmbexec(Bracket *bp, wchar_t wc, mcbuf.wc = mcbuf.cep->weight[1]; for (;;) { - if (mcbuf.wc == *wucp) + if ((wuchar_type)mcbuf.wc == *wucp) goto match; if (--i == 0) break; diff --git a/libuxre/regcomp.c b/libuxre/regcomp.c index 20a197d..4f6eb8c 100644 --- a/libuxre/regcomp.c +++ b/libuxre/regcomp.c @@ -52,7 +52,7 @@ regcomp(regex_t *ep, const char *pat, int flags) * doesn't, libuxre_regnfacomp() must be called first, if both are to * be called. */ - if (ep->re_nsub != 0 && (flags & (REG_NOSUB | REG_ONESUB)) == 0 + if ((ep->re_nsub != 0 && (flags & (REG_NOSUB | REG_ONESUB)) == 0) || lex.flags & REG_NFA) { ep->re_flags |= REG_NFA; diff --git a/libuxre/regdfa.c b/libuxre/regdfa.c index 8142e8d..d4daa17 100644 --- a/libuxre/regdfa.c +++ b/libuxre/regdfa.c @@ -457,7 +457,7 @@ addstate(Dfa *dp) /* install state if unique; return its index */ fp = dp->sigfoll; if ((n = dp->nset) > dp->avail) /* grow strip */ { - i = dp->avail + n << 1; + i = (dp->avail + n) << 1; if ((fp = realloc(fp, sizeof(size_t) * (i + dp->used))) == 0) return 0; dp->avail = i; diff --git a/libuxre/regerror.c b/libuxre/regerror.c index 397e3e5..c6958d8 100644 --- a/libuxre/regerror.c +++ b/libuxre/regerror.c @@ -69,19 +69,16 @@ regerror(int err, const regex_t *ep, char *str, size_t max) }; const char *p; size_t len; - int i; + (void)ep; if (err < REG_ENOSYS || REG_ILLSEQ < err) { - i = unk.index; p = unk.str; } else { - i = msgs[err - REG_ENOSYS].index; p = msgs[err - REG_ENOSYS].str; } -/* p = __gtxt(_str_uxlibc, i, p); */ len = strlen(p) + 1; if (max != 0) { diff --git a/libuxre/regnfa.c b/libuxre/regnfa.c index 6953f1f..40a59eb 100644 --- a/libuxre/regnfa.c +++ b/libuxre/regnfa.c @@ -607,7 +607,7 @@ casecmp(const Uchar *s, Exec *xp, ssize_t i, ssize_t n, int mb_cur_max) w_type wc1, wc2; int k; - if (strncmp((char *)s, (char *)p, n) == 0) /* try for exact match */ + if (strncmp((const char *)s, (const char *)p, n) == 0) /* try for exact match */ return 1; if ((xp->flags & REG_ICASE) == 0) return 0; @@ -808,7 +808,7 @@ libuxre_regnfaexec(Nfa *np, Exec *xp) if (gp->op != wc) { if ((xp->flags & REG_ICASE) == 0 - || gp->op != to_lower(wc)) + || (wint_t)gp->op != to_lower(wc)) { goto failed; } @@ -850,18 +850,18 @@ libuxre_regnfaexec(Nfa *np, Exec *xp) w_type pwc; if (wc != '_' && - !iswalnum(mb_cur_max == 1 ? btowc(wc) : wc)) + !iswalnum(mb_cur_max == 1 ? btowc(wc) : (wint_t)wc)) goto failed; if (!ISONEBYTE(pwc = *s2)) libuxre_mb2wc(&pwc, &s2[1]); if (pwc == '_' || - iswalnum(mb_cur_max== 1 ? btowc(pwc) : pwc)) + iswalnum(mb_cur_max== 1 ? btowc(pwc) : (wint_t)pwc)) goto failed; } goto tonext; case ROP_GT: if (wc == '_' || - iswalnum(mb_cur_max == 1 ? btowc(wc) : wc)) + iswalnum(mb_cur_max == 1 ? btowc(wc) : (wint_t)wc)) goto failed; goto tonext; case ROP_BKT: @@ -895,7 +895,7 @@ libuxre_regnfaexec(Nfa *np, Exec *xp) goto tonext; if (casecmp(s1, xp, n, len, mb_cur_max) == 0) goto failed; - if ((n = s - s1) >= len) + if ((ssize_t)(n = s - s1) >= len) goto nextwc; n = len - n; goto spin; @@ -922,7 +922,7 @@ libuxre_regnfaexec(Nfa *np, Exec *xp) * Note the left-most match that's longest. */ n = cp->rm[0].rm_so; - if (rmso < 0 || n < rmso) + if (rmso < 0 || (ssize_t)n < rmso) { rmso = n; record:; @@ -930,7 +930,7 @@ libuxre_regnfaexec(Nfa *np, Exec *xp) xp->nmatch * sizeof(regmatch_t)); goto failed; } - if (rmso < n || xp->match[0].rm_eo > cp->rm[0].rm_eo) + if (rmso < (ssize_t)n || xp->match[0].rm_eo > cp->rm[0].rm_eo) goto failed; if (xp->match[0].rm_eo < cp->rm[0].rm_eo) goto record; diff --git a/libuxre/stubs.c b/libuxre/stubs.c index bd670db..cbc1028 100644 --- a/libuxre/stubs.c +++ b/libuxre/stubs.c @@ -1,7 +1,7 @@ /* * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002. * - * Sccsid @(#)stubs.c 1.24 (gritter) 10/12/04 + * Sccsid @(#)stubs.c 1.27 (gritter) 6/26/05 */ /* UNIX(R) Regular Expresssion Library * @@ -31,8 +31,9 @@ struct lc_collate * libuxre_lc_collate(struct lc_collate *cp) { - static struct lc_collate curinfo = {0}; /* means CHF_ENCODED */ + static struct lc_collate curinfo; /* means CHF_ENCODED */ + (void)cp; return &curinfo; } @@ -53,45 +54,30 @@ libuxre_mb2wc(w_type *wt, const unsigned char *s) return len > 0 ? len - 1 : len; } -#if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 +#if __GNUC__ >= 3 && __GNUC_MINOR__ >= 4 || __GNUC__ >= 4 #define USED __attribute__ ((used)) #elif defined __GNUC__ #define USED __attribute__ ((unused)) #else #define USED #endif -static const char sccsid[] USED = "@(#)libuxre.sl 1.24 (gritter) 10/12/04"; +static const char sccsid[] USED = "@(#)libuxre.sl 1.27 (gritter) 6/26/05"; +/* SLIST */ /* -_collelem.c: - _collelem.c 1.4 (gritter) 10/18/03 -_collmult.c: - _collmult.c 1.4 (gritter) 9/22/03 -bracket.c: - bracket.c 1.14 (gritter) 10/18/03 -colldata.h: - colldata.h 1.4 (gritter) 10/18/03 -onefile.c: - onefile.c 1.1 (gritter) 9/22/03 -re.h: - re.h 1.14 (gritter) 10/18/03 -regcomp.c: - regcomp.c 1.6 (gritter) 9/22/03 -regdfa.c: - regdfa.c 1.9 (gritter) 9/22/03 -regdfa.h: - regdfa.h 1.3 (gritter) 9/22/03 -regerror.c: - regerror.c 1.4 (gritter) 3/29/03 -regex.h: - regex.h 1.12 (gritter) 9/22/03 -regexec.c: - regexec.c 1.6 (gritter) 9/22/03 -regfree.c: - regfree.c 1.3 (gritter) 9/22/03 -regnfa.c: - regnfa.c 1.7 (gritter) 9/22/03 -regparse.c: - regparse.c 1.12 (gritter) 9/22/03 -wcharm.h: - wcharm.h 1.12 (gritter) 10/18/03 +_collelem.c: * Sccsid @(#)_collelem.c 1.4 (gritter) 10/18/03 +_collmult.c: * Sccsid @(#)_collmult.c 1.4 (gritter) 9/22/03 +bracket.c: * Sccsid @(#)bracket.c 1.14 (gritter) 10/18/03 +colldata.h: * Sccsid @(#)colldata.h 1.5 (gritter) 5/1/04 +onefile.c: * Sccsid @(#)onefile.c 1.1 (gritter) 9/22/03 +re.h: * Sccsid @(#)re.h 1.15 (gritter) 2/6/05 +regcomp.c: * Sccsid @(#)regcomp.c 1.6 (gritter) 9/22/03 +regdfa.c: * Sccsid @(#)regdfa.c 1.9 (gritter) 9/22/03 +regdfa.h: * Sccsid @(#)regdfa.h 1.3 (gritter) 9/22/03 +regerror.c: * Sccsid @(#)regerror.c 1.4 (gritter) 3/29/03 +regex.h: * Sccsid @(#)regex.h 1.13 (gritter) 2/6/05 +regexec.c: * Sccsid @(#)regexec.c 1.7 (gritter) 2/6/05 +regfree.c: * Sccsid @(#)regfree.c 1.3 (gritter) 9/22/03 +regnfa.c: * Sccsid @(#)regnfa.c 1.8 (gritter) 2/6/05 +regparse.c: * Sccsid @(#)regparse.c 1.12 (gritter) 9/22/03 +wcharm.h: * Sccsid @(#)wcharm.h 1.12 (gritter) 10/18/03 */ diff --git a/libuxre/wcharm.h b/libuxre/wcharm.h index 8985d6b..9df1e8b 100644 --- a/libuxre/wcharm.h +++ b/libuxre/wcharm.h @@ -55,8 +55,8 @@ typedef int w_type; #define ISONEBYTE(ch) (((ch) & 0200) == 0 || mb_cur_max == 1) -#define to_lower(ch) (mb_cur_max > 1 ? towlower(ch) : tolower(ch)) -#define to_upper(ch) (mb_cur_max > 1 ? towupper(ch) : toupper(ch)) +#define to_lower(ch) (mb_cur_max > 1 ? towlower(ch) : (wint_t)tolower(ch)) +#define to_upper(ch) (mb_cur_max > 1 ? towupper(ch) : (wint_t)toupper(ch)) LIBUXRE_STATIC int libuxre_mb2wc(w_type *, const unsigned char *); diff --git a/mapmalloc.c b/mapmalloc.c index 5869ca3..44fc8af 100644 --- a/mapmalloc.c +++ b/mapmalloc.c @@ -151,7 +151,7 @@ void dump(const char *msg, uintptr_t t) #ifdef NULL #undef NULL #endif -#define NULL 0 +#define NULL 0 #define testbusy(p) ((INT)(p)&BUSY) #define setbusy(p) (union store *)((INT)(p)|BUSY) #define clearbusy(p) (union store *)((INT)(p)&~BUSY) @@ -203,10 +203,10 @@ map(void *addr, size_t len) static void * mallock(size_t nbytes, union store *start, union store *end) { - register union store *p, *q; + union store *p, *q; struct pool *o; - register int nw; - static int temp; /*coroutines assume no auto*/ + size_t nw; + static size_t temp; /*coroutines assume no auto*/ static size_t poolblock = 0100000; if (nbytes == 0) @@ -315,7 +315,7 @@ malloc(size_t nbytes) void free(register void *ap) { - register union store *p = ap; + union store *p = ap; struct pool *o; dump(" free", (uintptr_t)ap); @@ -340,11 +340,11 @@ free(register void *ap) void * realloc(void *ap, size_t nbytes) { - register union store *p = ap; - register union store *q; + union store *p = ap; + union store *q; struct pool *o; union store *s, *t; - register size_t nw; + size_t nw; size_t onw; if (p==NULL) @@ -365,8 +365,10 @@ realloc(void *ap, size_t nbytes) nw = (nbytes+WORD-1)/WORD; if(nw<onw) onw = nw; - while(onw--!=0) + while (onw) { + onw--; *t++ = *s++; + } if(q<p && q+nw>=p && p[-1].pool==q[-1].pool) (q+(q+nw-p))->ptr = allocx; return(q); @@ -378,7 +380,7 @@ allock(void *ao) { #ifdef longdebug struct pool *o = ao; - register union store *p; + union store *p; int x; x = 0; for(p= &allocs[0]; clearbusy(p->ptr) > p; p=clearbusy(p->ptr)) { @@ -399,9 +401,9 @@ allock(void *ao) void * calloc(size_t num, size_t size) { - register char *mp; - register INT *q; - register int m; + char *mp; + INT *q; + size_t m; num *= size; mp = malloc(num); @@ -409,8 +411,10 @@ calloc(size_t num, size_t size) return(NULL); q = (INT *) mp; m = (num+CHARPERINT-1)/CHARPERINT; - while(--m >= 0) + while(m) { + m--; *q++ = 0; + } return(mp); } @@ -450,6 +454,10 @@ mallopt(void) } #endif /* notdef */ -char *poolsbrk(intptr_t val) { return NULL; } +char * +poolsbrk(intptr_t val) { + (void)val; + return NULL; +} #endif /* VMUNIX */ @@ -99,7 +99,7 @@ char *p_dconv(long, char *); static int p_emit(char *, char *); int -printf(const char *fmt, ...) +ex_printf(char *fmt, ...) { va_list ap; int ret; @@ -252,7 +252,7 @@ vprintf(const char *fmt, va_list ap) *--bptr = ((int) num & mask1) + 060; else *--bptr = ((int) num & mask1) + 0127; - while (num = (num >> nbits) & mask2); + while ((num = (num >> nbits) & mask2)); if (fcode=='o') { if (n) @@ -288,7 +288,7 @@ vprintf(const char *fmt, va_list ap) else num = (long) n; } - if (n = (fcode != 'u' && num < 0)) + if ((n = (fcode != 'u' && num < 0))) num = -num; /* now convert to digits */ bptr = p_dconv(num, buf); @@ -359,7 +359,7 @@ p_dconv(long value, char *buffer) */ bp += MAXDIGS + 1; while (value > LRGINT) { - *--bp = (int)(value % 10) + '0'; + *--bp = (value % 10) + '0'; value /= 10; } @@ -961,10 +961,10 @@ The program file used to execute external commands. Determines the terminal type. .SH FILES .TP -.B /usr/lib/ex/expreserve +.B /usr/libexec/expreserve preserve command .TP -.B /usr/lib/ex/exrecover +.B /usr/libexec/exrecover recover command .TP .B /etc/termcap @@ -979,7 +979,7 @@ editor temporary .B /var/tmp/Rx\fInnnnnnnnnn\fP named buffer temporary .TP -.B /var/lib/ex +.B /var/preserve preservation directory .SH SEE ALSO ex(1), @@ -0,0 +1,19 @@ +#!/bin/sh +while [ $# -gt 0 ]; do + case "$1" in + -fg | -bg | -fn | -geometry) + XFl="$XFl $1 $2" + shift ;; + -*) + Fl="$Fl $1" ;; + *) + break ;; + esac + shift +done +RC=$HOME/.exrc +echo $XFl | grep -q '\-geometry' || { + [ -e $RC ] && grep -q '^set\{0,1\}[[:space:]]\{1,\}nu' $RC && + XFl="$XFl -geometry 88" +} +xterm $XFl -T "vi $*" -e "BINDIR/vi $Fl $*" & @@ -0,0 +1,42 @@ +.\" Carsten Kunze, 2016 +.Dd August 5, 2016 +.Dt WVI 1 +.Sh NAME +.Nm wvi +.Nd open vi in a separate xterm +.Sh SYNOPSIS +.Nm +.Op Ar "X options" +.Op Ar "vi options" +.Sh DESCRIPTION +There are use cases for +.Nm vi +where it is desirable to start it in a separate X window. +.Nm +just starts +.Do Nm xterm Ar "X options" Fl e Dc +with +.Nm vi +and the +.Ar "vi options" +as argument. +Possible X options are: +.Bl -tag +.It Fl bg Ar color +Set background color. +.It Fl fg Ar color +Set foreground color. +.It Fl fn Ar font name +Set font name. +.It Fl geometry Ar geometry string +Set xterm window geometry. +.El +.Pp +File names with spaces need to be enclosed in single or double quotes +.Po Sq Li \(aq +or +.Sq Li \(dq +.Pc +.Em and +the spaces needs to be protected with a backslash +.Pq Sq \(rs . |
