aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2020-10-01 04:25:54 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2020-10-01 04:25:54 +0000
commitb4ed613595432ece6802d09bfabad18e09aa26f3 (patch)
treebd2db6b09b756624c1b2babdd12ea05a9dffcdaf
parent7cef6c685d23e4dcdf3f64b0b2ea92151e652db6 (diff)
downloadsrc-vendor/nvi.tar.gz
src-vendor/nvi.zip
Import nvi 2.2.0-05ed8b9vendor/nvi/2.2.0-05ed8b9vendor/nvi
This snapshot just brings a bunch of fixes in particular a fix for vi -w PR: 241985 Reported by: fernape
Notes
Notes: svn path=/vendor/nvi/dist/; revision=366307 svn path=/vendor/nvi/2.2.0-05ed8b9/; revision=366308; tag=vendor/nvi/2.2.0-05ed8b9
-rw-r--r--CMakeLists.txt24
-rw-r--r--catalog/dump.c12
-rw-r--r--cl/cl.h4
-rw-r--r--cl/cl_read.c1
-rw-r--r--cl/cl_term.c6
-rw-r--r--common/common.h8
-rw-r--r--common/cut.h4
-rw-r--r--common/exf.c17
-rw-r--r--common/key.c4
-rw-r--r--common/log.c4
-rw-r--r--common/main.c11
-rw-r--r--common/mark.c3
-rw-r--r--common/mem.h60
-rw-r--r--common/msg.c4
-rw-r--r--common/options.c20
-rw-r--r--common/put.c3
-rw-r--r--common/recover.c9
-rw-r--r--common/util.c10
-rw-r--r--ex/ex.c9
-rw-r--r--ex/ex.h8
-rw-r--r--ex/ex_argv.c8
-rw-r--r--ex/ex_bang.c3
-rw-r--r--ex/ex_cscope.c10
-rw-r--r--ex/ex_filter.c3
-rw-r--r--ex/ex_global.c3
-rw-r--r--ex/ex_script.c2
-rw-r--r--ex/ex_shell.c3
-rw-r--r--ex/ex_subst.c27
-rw-r--r--files/config.h.in9
-rw-r--r--files/pathnames.h.in5
-rw-r--r--man/vi.14
-rw-r--r--regex/engine.c2
-rw-r--r--regex/regexec.c6
-rw-r--r--vi/v_itxt.c4
-rw-r--r--vi/v_paragraph.c10
-rw-r--r--vi/v_section.c3
-rw-r--r--vi/v_sentence.c3
-rw-r--r--vi/v_txt.c11
-rw-r--r--vi/vi.c4
-rw-r--r--vi/vs_line.c10
-rw-r--r--vi/vs_msg.c13
-rw-r--r--vi/vs_refresh.c9
-rw-r--r--vi/vs_relative.c7
-rw-r--r--vi/vs_smap.c4
44 files changed, 242 insertions, 142 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 00f43283f022..996e0e72de99 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,7 @@ project(nvi2 C)
include(CheckIncludeFiles)
include(CheckFunctionExists)
+include(CheckStructHasMember)
include(CheckCSourceCompiles)
mark_as_advanced(CMAKE_INSTALL_PREFIX)
@@ -127,6 +128,7 @@ endif()
if(USE_WIDECHAR)
find_library(CURSES_LIBRARY NAMES ncursesw cursesw curses HINTS /usr/lib)
+ find_library(TERMINFO_LIBRARY NAMES tinfow terminfo HINTS /usr/lib)
# link to the wchar_t awared BSD libregex.a
add_library(regex STATIC)
@@ -136,13 +138,14 @@ if(USE_WIDECHAR)
target_link_libraries(nvi PRIVATE regex)
else()
find_library(CURSES_LIBRARY NAMES ncurses curses HINTS /usr/lib)
+ find_library(TERMINFO_LIBRARY NAMES tinfo terminfo HINTS /usr/lib)
target_compile_options(nvi PRIVATE -Wno-pointer-sign)
endif()
-target_link_libraries(nvi PRIVATE ${CURSES_LIBRARY})
+target_link_libraries(nvi PRIVATE ${CURSES_LIBRARY} ${TERMINFO_LIBRARY})
if(USE_ICONV)
- check_function_exists(__iconv ICONV_IN_LIBC)
+ check_function_exists(iconv ICONV_IN_LIBC)
if(NOT ICONV_IN_LIBC)
find_path(ICONV_INCLUDE_DIR iconv.h)
find_library(ICONV_LIBRARY iconv)
@@ -173,9 +176,26 @@ if(USE_ICONV)
target_link_libraries(nvi PRIVATE ${ICONV_LIBRARY})
endif()
+check_function_exists(getprogname GETPROGNAME_IN_LIBC)
+check_function_exists(strlcpy STRLCPY_IN_LIBC)
+if(NOT GETPROGNAME_IN_LIBC OR NOT STRLCPY_IN_LIBC)
+ find_package(PkgConfig REQUIRED)
+ pkg_check_modules(LIBBSD libbsd-overlay)
+ add_definitions(${LIBBSD_CFLAGS})
+ target_link_libraries(nvi PRIVATE ${LIBBSD_LIBRARIES})
+endif()
+
+check_function_exists(dbopen DBOPEN_IN_LIBC)
+if(NOT DBOPEN_IN_LIBC)
+ target_link_libraries(nvi PRIVATE db1)
+endif()
+
check_include_files(libutil.h HAVE_LIBUTIL_H)
check_include_files(ncurses.h HAVE_NCURSES_H)
+check_include_files(ncursesw/ncurses.h HAVE_NCURSESW_NCURSES_H)
+check_include_files(pty.h HAVE_PTY_H)
check_include_files(term.h HAVE_TERM_H)
+check_struct_has_member("struct dirent" d_namlen dirent.h HAVE_DIRENT_D_NAMLEN LANGUAGE C)
configure_file(files/config.h.in config.h)
diff --git a/catalog/dump.c b/catalog/dump.c
index ef893d647edf..248f718d719b 100644
--- a/catalog/dump.c
+++ b/catalog/dump.c
@@ -35,24 +35,24 @@ parse(FILE *fp)
{
int ch, s1, s2, s3;
-#define TESTD(s) { \
+#define TESTD(s) do { \
if ((s = getc(fp)) == EOF) \
return; \
if (!isdigit(s)) \
continue; \
-}
-#define TESTP { \
+} while (0)
+#define TESTP do { \
if ((ch = getc(fp)) == EOF) \
return; \
if (ch != '|') \
continue; \
-}
-#define MOVEC(t) { \
+} while (0)
+#define MOVEC(t) do { \
do { \
if ((ch = getc(fp)) == EOF) \
return; \
} while (ch != (t)); \
-}
+} while (0)
for (;;) {
MOVEC('"');
TESTD(s1);
diff --git a/cl/cl.h b/cl/cl.h
index 894e5ede7fa9..d230a55a56d7 100644
--- a/cl/cl.h
+++ b/cl/cl.h
@@ -10,7 +10,9 @@
#ifdef USE_WIDECHAR
#define _XOPEN_SOURCE_EXTENDED
#endif
-#ifdef HAVE_NCURSES_H
+#ifdef HAVE_NCURSESW_NCURSES_H
+#include <ncursesw/ncurses.h>
+#elif defined HAVE_NCURSES_H
#include <ncurses.h>
#else
#include <curses.h>
diff --git a/cl/cl_read.c b/cl/cl_read.c
index f5f18fd616f1..ddf3acc1918c 100644
--- a/cl/cl_read.c
+++ b/cl/cl_read.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
diff --git a/cl/cl_term.c b/cl/cl_term.c
index 601460585530..106f37149565 100644
--- a/cl/cl_term.c
+++ b/cl/cl_term.c
@@ -424,16 +424,18 @@ cl_ssize(SCR *sp, int sigwinch, size_t *rowp, size_t *colp, int *changedp)
if (row == 0 || col == 0) {
if ((p = getenv("TERM")) == NULL)
goto noterm;
- if (row == 0)
+ if (row == 0) {
if ((rval = tigetnum("lines")) < 0)
msgq(sp, M_SYSERR, "tigetnum: lines");
else
row = rval;
- if (col == 0)
+ }
+ if (col == 0) {
if ((rval = tigetnum("cols")) < 0)
msgq(sp, M_SYSERR, "tigetnum: cols");
else
col = rval;
+ }
}
/* If nothing else, well, it's probably a VT100. */
diff --git a/common/common.h b/common/common.h
index ad559a5a2267..dc4155610225 100644
--- a/common/common.h
+++ b/common/common.h
@@ -7,7 +7,15 @@
* See the LICENSE file for redistribution information.
*/
+#ifndef TCSASOFT
+#define TCSASOFT 0
+#endif
+
+#ifdef __linux__
+#include "/usr/include/db1/db.h" /* Only include db1. */
+#else
#include "/usr/include/db.h" /* Only include db1. */
+#endif
#include <regex.h> /* May refer to the bundled regex. */
/*
diff --git a/common/cut.h b/common/cut.h
index d220cd8cc69c..a94c3f9ce58d 100644
--- a/common/cut.h
+++ b/common/cut.h
@@ -63,13 +63,13 @@ struct _text { /* Text: a linked list of lines. */
* Get named buffer 'name'.
* Translate upper-case buffer names to lower-case buffer names.
*/
-#define CBNAME(sp, cbp, nch) { \
+#define CBNAME(sp, cbp, nch) do { \
CHAR_T L__name; \
L__name = isupper(nch) ? tolower(nch) : (nch); \
SLIST_FOREACH(cbp, sp->gp->cutq, q) \
if (cbp->name == L__name) \
break; \
-}
+} while (0)
/* Flags to the cut() routine. */
#define CUT_LINEMODE 0x01 /* Cut in line mode. */
diff --git a/common/exf.c b/common/exf.c
index ccfa66ef4089..f9eb2150276d 100644
--- a/common/exf.c
+++ b/common/exf.c
@@ -199,7 +199,7 @@ file_init(SCR *sp, FREF *frp, char *rcv_name, int flags)
if (!LF_ISSET(FS_OPENERR))
F_SET(frp, FR_NEWFILE);
- ep->mtim = sb.st_mtimespec;
+ ep->mtim = sb.st_mtim;
} else {
/*
* XXX
@@ -218,7 +218,7 @@ file_init(SCR *sp, FREF *frp, char *rcv_name, int flags)
ep->mdev = sb.st_dev;
ep->minode = sb.st_ino;
- ep->mtim = sb.st_mtimespec;
+ ep->mtim = sb.st_mtim;
if (!S_ISREG(sb.st_mode))
msgq_str(sp, M_ERR, oname,
@@ -796,7 +796,7 @@ file_write(SCR *sp, MARK *fm, MARK *tm, char *name, int flags)
if (noname && !LF_ISSET(FS_FORCE | FS_APPEND) &&
((F_ISSET(ep, F_DEVSET) &&
(sb.st_dev != ep->mdev || sb.st_ino != ep->minode)) ||
- timespeccmp(&sb.st_mtimespec, &ep->mtim, !=))) {
+ timespeccmp(&sb.st_mtim, &ep->mtim, !=))) {
msgq_str(sp, M_ERR, name, LF_ISSET(FS_POSSIBLE) ?
"250|%s: file modified more recently than this copy; use ! to override" :
"251|%s: file modified more recently than this copy");
@@ -887,7 +887,7 @@ success_open:
* we re-init the time. That way the user can clean up the disk
* and rewrite without having to force it.
*/
- if (noname)
+ if (noname) {
if (stat(name, &sb))
timepoint_system(&ep->mtim);
else {
@@ -895,8 +895,9 @@ success_open:
ep->mdev = sb.st_dev;
ep->minode = sb.st_ino;
- ep->mtim = sb.st_mtimespec;
+ ep->mtim = sb.st_mtim;
}
+ }
/*
* If the write failed, complain loudly. ex_writefp() has already
@@ -925,11 +926,12 @@ success_open:
*/
if (LF_ISSET(FS_ALL) && !LF_ISSET(FS_APPEND)) {
F_CLR(ep, F_MODIFIED);
- if (F_ISSET(frp, FR_TMPFILE))
+ if (F_ISSET(frp, FR_TMPFILE)) {
if (noname)
F_SET(frp, FR_TMPEXIT);
else
F_CLR(frp, FR_TMPEXIT);
+ }
}
p = msg_print(sp, name, &nf);
@@ -1290,7 +1292,7 @@ file_m1(SCR *sp, int force, int flags)
* unless force is also set. Otherwise, we fail unless forced or
* there's another open screen on this file.
*/
- if (F_ISSET(ep, F_MODIFIED))
+ if (F_ISSET(ep, F_MODIFIED)) {
if (O_ISSET(sp, O_AUTOWRITE)) {
if (!force && file_aw(sp, flags))
return (1);
@@ -1300,6 +1302,7 @@ file_m1(SCR *sp, int force, int flags)
"263|File modified since last complete write; write or use :edit! to override");
return (1);
}
+ }
return (file_m3(sp, force));
}
diff --git a/common/key.c b/common/key.c
index 23da0498a757..e71396893fd4 100644
--- a/common/key.c
+++ b/common/key.c
@@ -424,12 +424,12 @@ v_event_append(SCR *sp, EVENT *argp)
}
/* Remove events from the queue. */
-#define QREM(len) { \
+#define QREM(len) do { \
if ((gp->i_cnt -= len) == 0) \
gp->i_next = 0; \
else \
gp->i_next += len; \
-}
+} while (0)
/*
* v_event_get --
diff --git a/common/log.c b/common/log.c
index 5dcd9a2945fc..96b246efad02 100644
--- a/common/log.c
+++ b/common/log.c
@@ -69,10 +69,10 @@ static int apply_with(int (*)(SCR *, recno_t, CHAR_T *, size_t),
SCR *, recno_t, u_char *, size_t);
/* Try and restart the log on failure, i.e. if we run out of memory. */
-#define LOG_ERR { \
+#define LOG_ERR do { \
log_err(sp, __FILE__, __LINE__); \
return (1); \
-}
+} while (0)
/* offset of CHAR_T string in log needs to be aligned on some systems
* because it is passed to db_set as a string
diff --git a/common/main.c b/common/main.c
index c0b81960bd55..a7e60f1af806 100644
--- a/common/main.c
+++ b/common/main.c
@@ -48,8 +48,8 @@ editor(GS *gp, int argc, char *argv[])
size_t len;
u_int flags;
int ch, flagchk, lflag, secure, startup, readonly, rval, silent;
- char *tag_f, *wsizearg, path[256];
- CHAR_T *w;
+ char *tag_f, *wsizearg;
+ CHAR_T *w, path[256];
size_t wlen;
/* Initialize the busy routine, if not defined by the screen. */
@@ -242,9 +242,9 @@ editor(GS *gp, int argc, char *argv[])
}
if (wsizearg != NULL) {
ARGS *av[2], a, b;
- (void)snprintf(path, sizeof(path), "window=%s", wsizearg);
+ (void)SPRINTF(path, SIZE(path), L("window=%s"), wsizearg);
a.bp = (CHAR_T *)path;
- a.len = strlen(path);
+ a.len = SIZE(path);
b.bp = NULL;
b.len = 0;
av[0] = &a;
@@ -533,7 +533,7 @@ v_obsolete(char *argv[])
argv[0][1] = 'c';
(void)strlcpy(argv[0] + 2, p + 1, len);
}
- } else if (argv[0][0] == '-')
+ } else if (argv[0][0] == '-') {
if (argv[0][1] == '\0') {
argv[0] = strdup("-s");
if (argv[0] == NULL) {
@@ -545,6 +545,7 @@ nomem: warn(NULL);
argv[0][1] == 't' || argv[0][1] == 'w') &&
argv[0][2] == '\0')
++argv;
+ }
return (0);
}
diff --git a/common/mark.c b/common/mark.c
index 9af4612cb22a..86e3cb8ea6d9 100644
--- a/common/mark.c
+++ b/common/mark.c
@@ -216,12 +216,13 @@ mark_insdel(SCR *sp, lnop_t op, recno_t lno)
abort();
case LINE_DELETE:
SLIST_FOREACH(lmp, sp->ep->marks, q)
- if (lmp->lno >= lno)
+ if (lmp->lno >= lno) {
if (lmp->lno == lno) {
F_SET(lmp, MARK_DELETED);
(void)log_mark(sp, lmp);
} else
--lmp->lno;
+ }
break;
case LINE_INSERT:
/*
diff --git a/common/mem.h b/common/mem.h
index 1e26a6ea6549..d24ec0b50b09 100644
--- a/common/mem.h
+++ b/common/mem.h
@@ -17,7 +17,7 @@
/* Increase the size of a malloc'd buffer. Two versions, one that
* returns, one that jumps to an error label.
*/
-#define BINC_GOTO(sp, type, lp, llen, nlen) { \
+#define BINC_GOTO(sp, type, lp, llen, nlen) do { \
CHECK_TYPE(type *, lp) \
void *L__bincp; \
if ((nlen) > llen) { \
@@ -29,12 +29,12 @@
*/ \
lp = L__bincp; \
} \
-}
+} while (0)
#define BINC_GOTOC(sp, lp, llen, nlen) \
BINC_GOTO(sp, char, lp, llen, nlen)
#define BINC_GOTOW(sp, lp, llen, nlen) \
BINC_GOTO(sp, CHAR_T, lp, llen, (nlen) * sizeof(CHAR_T))
-#define BINC_RET(sp, type, lp, llen, nlen) { \
+#define BINC_RET(sp, type, lp, llen, nlen) do { \
CHECK_TYPE(type *, lp) \
void *L__bincp; \
if ((nlen) > llen) { \
@@ -46,7 +46,7 @@
*/ \
lp = L__bincp; \
} \
-}
+} while (0)
#define BINC_RETC(sp, lp, llen, nlen) \
BINC_RET(sp, char, lp, llen, nlen)
#define BINC_RETW(sp, lp, llen, nlen) \
@@ -57,7 +57,7 @@
* from a malloc'd buffer otherwise. Two versions, one that returns, one
* that jumps to an error label.
*/
-#define GET_SPACE_GOTO(sp, type, bp, blen, nlen) { \
+#define GET_SPACE_GOTO(sp, type, bp, blen, nlen) do { \
CHECK_TYPE(type *, bp) \
GS *L__gp = (sp) == NULL ? NULL : (sp)->gp; \
if (L__gp == NULL || F_ISSET(L__gp, G_TMP_INUSE)) { \
@@ -70,12 +70,12 @@
blen = L__gp->tmp_blen; \
F_SET(L__gp, G_TMP_INUSE); \
} \
-}
+} while (0)
#define GET_SPACE_GOTOC(sp, bp, blen, nlen) \
GET_SPACE_GOTO(sp, char, bp, blen, nlen)
#define GET_SPACE_GOTOW(sp, bp, blen, nlen) \
GET_SPACE_GOTO(sp, CHAR_T, bp, blen, (nlen) * sizeof(CHAR_T))
-#define GET_SPACE_RET(sp, type, bp, blen, nlen) { \
+#define GET_SPACE_RET(sp, type, bp, blen, nlen) do { \
CHECK_TYPE(type *, bp) \
GS *L__gp = (sp) == NULL ? NULL : (sp)->gp; \
if (L__gp == NULL || F_ISSET(L__gp, G_TMP_INUSE)) { \
@@ -88,7 +88,7 @@
blen = L__gp->tmp_blen; \
F_SET(L__gp, G_TMP_INUSE); \
} \
-}
+} while (0)
#define GET_SPACE_RETC(sp, bp, blen, nlen) \
GET_SPACE_RET(sp, char, bp, blen, nlen)
#define GET_SPACE_RETW(sp, bp, blen, nlen) \
@@ -98,7 +98,7 @@
* Add space to a GET_SPACE returned buffer. Two versions, one that
* returns, one that jumps to an error label.
*/
-#define ADD_SPACE_GOTO(sp, type, bp, blen, nlen) { \
+#define ADD_SPACE_GOTO(sp, type, bp, blen, nlen) do { \
CHECK_TYPE(type *, bp) \
GS *L__gp = (sp) == NULL ? NULL : (sp)->gp; \
if (L__gp == NULL || bp == (type *)L__gp->tmp_bp) { \
@@ -109,12 +109,12 @@
F_SET(L__gp, G_TMP_INUSE); \
} else \
BINC_GOTO(sp, type, bp, blen, nlen); \
-}
+} while (0)
#define ADD_SPACE_GOTOC(sp, bp, blen, nlen) \
ADD_SPACE_GOTO(sp, char, bp, blen, nlen)
#define ADD_SPACE_GOTOW(sp, bp, blen, nlen) \
ADD_SPACE_GOTO(sp, CHAR_T, bp, blen, (nlen) * sizeof(CHAR_T))
-#define ADD_SPACE_RET(sp, type, bp, blen, nlen) { \
+#define ADD_SPACE_RET(sp, type, bp, blen, nlen) do { \
CHECK_TYPE(type *, bp) \
GS *L__gp = (sp) == NULL ? NULL : (sp)->gp; \
if (L__gp == NULL || bp == (type *)L__gp->tmp_bp) { \
@@ -125,70 +125,70 @@
F_SET(L__gp, G_TMP_INUSE); \
} else \
BINC_RET(sp, type, bp, blen, nlen); \
-}
+} while (0)
#define ADD_SPACE_RETC(sp, bp, blen, nlen) \
ADD_SPACE_RET(sp, char, bp, blen, nlen)
#define ADD_SPACE_RETW(sp, bp, blen, nlen) \
ADD_SPACE_RET(sp, CHAR_T, bp, blen, (nlen) * sizeof(CHAR_T))
/* Free a GET_SPACE returned buffer. */
-#define FREE_SPACE(sp, bp, blen) { \
+#define FREE_SPACE(sp, bp, blen) do { \
GS *L__gp = (sp) == NULL ? NULL : (sp)->gp; \
if (L__gp != NULL && bp == L__gp->tmp_bp) \
F_CLR(L__gp, G_TMP_INUSE); \
else \
free(bp); \
-}
-#define FREE_SPACEW(sp, bp, blen) { \
+} while (0)
+#define FREE_SPACEW(sp, bp, blen) do { \
CHECK_TYPE(CHAR_T *, bp) \
FREE_SPACE(sp, (char *)bp, blen); \
-}
+} while (0)
/*
* Malloc a buffer, casting the return pointer. Various versions.
*/
-#define CALLOC(sp, p, nmemb, size) { \
+#define CALLOC(sp, p, nmemb, size) do { \
if ((p = calloc(nmemb, size)) == NULL) \
msgq(sp, M_SYSERR, NULL); \
-}
-#define CALLOC_GOTO(sp, p, nmemb, size) { \
+} while (0)
+#define CALLOC_GOTO(sp, p, nmemb, size) do { \
if ((p = calloc(nmemb, size)) == NULL) \
goto alloc_err; \
-}
-#define CALLOC_RET(sp, p, nmemb, size) { \
+} while (0)
+#define CALLOC_RET(sp, p, nmemb, size) do { \
if ((p = calloc(nmemb, size)) == NULL) { \
msgq(sp, M_SYSERR, NULL); \
return (1); \
} \
-}
+} while (0)
-#define MALLOC(sp, p, size) { \
+#define MALLOC(sp, p, size) do { \
if ((p = malloc(size)) == NULL) \
msgq(sp, M_SYSERR, NULL); \
-}
-#define MALLOC_GOTO(sp, p, size) { \
+} while (0)
+#define MALLOC_GOTO(sp, p, size) do { \
if ((p = malloc(size)) == NULL) \
goto alloc_err; \
-}
-#define MALLOC_RET(sp, p, size) { \
+} while (0)
+#define MALLOC_RET(sp, p, size) do { \
if ((p = malloc(size)) == NULL) { \
msgq(sp, M_SYSERR, NULL); \
return (1); \
} \
-}
+} while (0)
/*
* Resize a buffer, free any already held memory if we can't get more.
* FreeBSD's reallocf(3) does the same thing, but it's not portable yet.
*/
-#define REALLOC(sp, p, cast, size) { \
+#define REALLOC(sp, p, cast, size) do { \
cast newp; \
if ((newp = realloc(p, size)) == NULL) { \
free(p); \
msgq(sp, M_SYSERR, NULL); \
} \
p = newp; \
-}
+} while (0)
/*
* p2roundup --
diff --git a/common/msg.c b/common/msg.c
index d2463a3ecccd..7499f451be59 100644
--- a/common/msg.c
+++ b/common/msg.c
@@ -731,7 +731,11 @@ msg_open(SCR *sp, char *file)
* corrupt catalog file. Errno == 0 is not rare; add
* EFTYPE, which is seen on FreeBSD, for a good measure.
*/
+#ifdef EFTYPE
if (errno == 0 || errno == EFTYPE)
+#else
+ if (errno == 0)
+#endif
msgq_str(sp, M_ERR, p,
"030|The file %s is not a message catalog");
else
diff --git a/common/options.c b/common/options.c
index 25b10fe67012..d5c039f97228 100644
--- a/common/options.c
+++ b/common/options.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unctrl.h>
#include <unistd.h>
#include "common.h"
@@ -312,7 +313,7 @@ opts_init(SCR *sp, int *oargs)
argv[1] = &b;
/* Set numeric and string default values. */
-#define OI(indx, str) { \
+#define OI(indx, str) do { \
a.len = STRLEN(str); \
if ((CHAR_T*)str != b2) /* GCC puts strings in text-space. */ \
(void)MEMCPY(b2, str, a.len+1); \
@@ -320,7 +321,7 @@ opts_init(SCR *sp, int *oargs)
optindx = indx; \
goto err; \
} \
-}
+} while (0)
/*
* Indirect global options to global space. Specifically, set up
* terminal, lines, columns first, they're used by other options.
@@ -366,7 +367,7 @@ opts_init(SCR *sp, int *oargs)
OI(O_PARAGRAPHS, L("paragraphs=IPLPPPQPP LIpplpipbp"));
(void)SPRINTF(b2, SIZE(b2), L("path=%s"), "");
OI(O_PATH, b2);
- (void)SPRINTF(b2, SIZE(b2), L("recdir=%s"), _PATH_PRESERVE);
+ (void)SPRINTF(b2, SIZE(b2), L("recdir=%s"), NVI_PATH_PRESERVE);
OI(O_RECDIR, b2);
OI(O_SECTIONS, L("sections=NHSHH HUnhsh"));
(void)SPRINTF(b2, SIZE(b2),
@@ -573,13 +574,14 @@ opts_set(SCR *sp, ARGS *argv[], char *usage)
* functions can be expensive.
*/
isset = !turnoff;
- if (!F_ISSET(op, OPT_ALWAYS))
+ if (!F_ISSET(op, OPT_ALWAYS)) {
if (isset) {
if (O_ISSET(sp, offset))
break;
} else
if (!O_ISSET(sp, offset))
break;
+ }
/* Report to subsystems. */
if ((op->func != NULL &&
@@ -945,6 +947,7 @@ static int
opts_print(SCR *sp, OPTLIST const *op)
{
int curlen, offset;
+ const char *p;
curlen = 0;
offset = op - optlist;
@@ -958,8 +961,13 @@ opts_print(SCR *sp, OPTLIST const *op)
curlen += ex_printf(sp, WS"=%ld", op->name, O_VAL(sp, offset));
break;
case OPT_STR:
- curlen += ex_printf(sp, WS"=\"%s\"", op->name,
- O_STR(sp, offset) == NULL ? "" : O_STR(sp, offset));
+ curlen += ex_printf(sp, WS"=\"", op->name);
+ p = O_STR(sp, offset);
+ /* Keep correct count for unprintable character sequences */
+ if (p != NULL)
+ for (; *p != '\0'; ++p)
+ curlen += ex_puts(sp, unctrl(*p));
+ curlen += ex_puts(sp, "\"");
break;
}
return (curlen);
diff --git a/common/put.c b/common/put.c
index 26a67ac8711c..f39948808e7d 100644
--- a/common/put.c
+++ b/common/put.c
@@ -39,7 +39,7 @@ put(SCR *sp, CB *cbp, CHAR_T *namep, MARK *cp, MARK *rp, int append)
CHAR_T *bp, *t;
CHAR_T *p;
- if (cbp == NULL)
+ if (cbp == NULL) {
if (namep == NULL) {
cbp = sp->gp->dcbp;
if (cbp == NULL) {
@@ -56,6 +56,7 @@ put(SCR *sp, CB *cbp, CHAR_T *namep, MARK *cp, MARK *rp, int append)
return (1);
}
}
+ }
tp = TAILQ_FIRST(cbp->textq);
/*
diff --git a/common/recover.c b/common/recover.c
index 89f25a4146e9..120cf4f60b19 100644
--- a/common/recover.c
+++ b/common/recover.c
@@ -421,7 +421,7 @@ rcv_mailfile(SCR *sp, int issync, char *cp_path)
getprogname(), " -r ", qt);
free(qt);
free(host);
- if (buf == NULL) {
+ if (len == -1) {
msgq(sp, M_SYSERR, NULL);
goto err;
}
@@ -701,7 +701,7 @@ rcv_read(SCR *sp, FREF *frp)
/* If we've found more than one, take the most recent. */
(void)fstat(fileno(fp), &sb);
if (recp == NULL ||
- timespeccmp(&rec_mtim, &sb.st_mtimespec, <)) {
+ timespeccmp(&rec_mtim, &sb.st_mtim, <)) {
p = recp;
t = pathp;
recp = recpath;
@@ -710,7 +710,7 @@ rcv_read(SCR *sp, FREF *frp)
free(p);
free(t);
}
- rec_mtim = sb.st_mtimespec;
+ rec_mtim = sb.st_mtim;
if (sv_fd != -1)
(void)close(sv_fd);
sv_fd = dup(fileno(fp));
@@ -813,8 +813,7 @@ rcv_email(SCR *sp, char *fname)
{
char *buf;
- (void)asprintf(&buf, _PATH_SENDMAIL " -odb -t < %s", fname);
- if (buf == NULL) {
+ if (asprintf(&buf, _PATH_SENDMAIL " -odb -t < %s", fname) == -1) {
msgq_str(sp, M_ERR, strerror(errno),
"071|not sending email: %s");
return;
diff --git a/common/util.c b/common/util.c
index 1e87c6293550..8046ce373016 100644
--- a/common/util.c
+++ b/common/util.c
@@ -111,8 +111,9 @@ join(char *path1, char *path2)
if (path1[0] == '\0' || path2[0] == '/')
return strdup(path2);
- (void)asprintf(&p, path1[strlen(path1)-1] == '/' ?
- "%s%s" : "%s/%s", path1, path2);
+ if (asprintf(&p, path1[strlen(path1)-1] == '/' ?
+ "%s%s" : "%s/%s", path1, path2) == -1)
+ return NULL;
return p;
}
@@ -140,8 +141,13 @@ expanduser(char *str)
continue;
if (t == p) {
/* ~ */
+#ifdef __GLIBC__
+ extern char *secure_getenv(const char *);
+ if ((h = secure_getenv("HOME")) == NULL) {
+#else
if (issetugid() != 0 ||
(h = getenv("HOME")) == NULL) {
+#endif
if (((h = getlogin()) != NULL &&
(pwd = getpwnam(h)) != NULL) ||
(pwd = getpwuid(getuid())) != NULL)
diff --git a/ex/ex.c b/ex/ex.c
index c93d49717b22..343131537afa 100644
--- a/ex/ex.c
+++ b/ex/ex.c
@@ -811,13 +811,14 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI))
* this isn't a particularly complex trap, and if backslashes were
* legal in set commands, this would have to be much more complicated.
*/
- if (ecp->cmd == &cmds[C_SET])
+ if (ecp->cmd == &cmds[C_SET]) {
for (p = ecp->cp, len = ecp->clen; len > 0; --len, ++p)
if (IS_ESCAPE(sp, ecp, *p) && len > 1) {
--len;
++p;
} else if (*p == '\\')
*p = CH_LITERAL;
+ }
/*
* Set the default addresses. It's an error to specify an address for
@@ -1254,7 +1255,7 @@ addr_verify:
ex_badaddr(sp, ecp->cmd, A_ZERO, NUM_OK);
goto err;
}
- } else if (!db_exist(sp, ecp->addr2.lno))
+ } else if (!db_exist(sp, ecp->addr2.lno)) {
if (FL_ISSET(ecp->iflags, E_C_COUNT)) {
if (db_last(sp, &lno))
goto err;
@@ -1263,6 +1264,7 @@ addr_verify:
ex_badaddr(sp, NULL, A_EOF, NUM_OK);
goto err;
}
+ }
/* FALLTHROUGH */
case 1:
if (ecp->addr1.lno == 0) {
@@ -2117,7 +2119,7 @@ ex_load(SCR *sp)
/* If it's a global/v command, fix up the last line. */
if (FL_ISSET(ecp->agv_flags,
- AGV_GLOBAL | AGV_V) && ecp->range_lno != OOBLNO)
+ AGV_GLOBAL | AGV_V) && ecp->range_lno != OOBLNO) {
if (db_exist(sp, ecp->range_lno))
sp->lno = ecp->range_lno;
else {
@@ -2126,6 +2128,7 @@ ex_load(SCR *sp)
if (sp->lno == 0)
sp->lno = 1;
}
+ }
free(ecp->o_cp);
}
diff --git a/ex/ex.h b/ex/ex.h
index 5ccf7c6c362b..b2d8ad0f4fef 100644
--- a/ex/ex.h
+++ b/ex/ex.h
@@ -55,12 +55,12 @@ extern EXCMDLIST const cmds[]; /* Table of ex commands. */
* at any time, and most of them won't work well if a file hasn't yet been read
* in. Historic vi generally took the easy way out and dropped core.
*/
-#define NEEDFILE(sp, cmdp) { \
+#define NEEDFILE(sp, cmdp) do { \
if ((sp)->ep == NULL) { \
ex_wemsg(sp, (cmdp)->cmd->name, EXM_NOFILEYET); \
return (1); \
} \
-}
+} while (0)
/* Range structures for global and @ commands. */
typedef struct _range RANGE;
@@ -102,12 +102,12 @@ struct _excmd {
u_int8_t agv_flags;
/* Clear the structure before each ex command. */
-#define CLEAR_EX_CMD(cmdp) { \
+#define CLEAR_EX_CMD(cmdp) do { \
u_int32_t L__f = F_ISSET(cmdp, E_PRESERVE); \
memset(&((cmdp)->buffer), 0, ((char *)&(cmdp)->flags - \
(char *)&((cmdp)->buffer)) + sizeof((cmdp)->flags)); \
F_SET(cmdp, L__f); \
-}
+} while (0)
CHAR_T buffer; /* Command: named buffer. */
recno_t lineno; /* Command: line number. */
diff --git a/ex/ex_argv.c b/ex/ex_argv.c
index d6f9a8bb8aa5..8b1fd7858fb1 100644
--- a/ex/ex_argv.c
+++ b/ex/ex_argv.c
@@ -611,9 +611,17 @@ argv_flt_path(SCR *sp, EXCMD *excp, CHAR_T *path, size_t plen)
if (nlen == 0) {
if (dp->d_name[0] == '.')
continue;
+#ifdef HAVE_DIRENT_D_NAMLEN
len = dp->d_namlen;
+#else
+ len = strlen(dp->d_name);
+#endif
} else {
+#ifdef HAVE_DIRENT_D_NAMLEN
len = dp->d_namlen;
+#else
+ len = strlen(dp->d_name);
+#endif
if (len < nlen || memcmp(dp->d_name, name, nlen))
continue;
}
diff --git a/ex/ex_bang.c b/ex/ex_bang.c
index ff2b39bbff9a..c5744708664a 100644
--- a/ex/ex_bang.c
+++ b/ex/ex_bang.c
@@ -96,7 +96,7 @@ ex_bang(SCR *sp, EXCMD *cmdp)
*/
if (cmdp->addrcnt == 0) {
msg = NULL;
- if (sp->ep != NULL && F_ISSET(sp->ep, F_MODIFIED))
+ if (sp->ep != NULL && F_ISSET(sp->ep, F_MODIFIED)) {
if (O_ISSET(sp, O_AUTOWRITE)) {
if (file_aw(sp, FS_ALL))
return (0);
@@ -105,6 +105,7 @@ ex_bang(SCR *sp, EXCMD *cmdp)
msg = msg_cat(sp,
"303|File modified since last write.",
NULL);
+ }
/* If we're still in a vi screen, move out explicitly. */
INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
diff --git a/ex/ex_cscope.c b/ex/ex_cscope.c
index 629861d55680..74d7f8af95be 100644
--- a/ex/ex_cscope.c
+++ b/ex/ex_cscope.c
@@ -261,7 +261,7 @@ cscope_add(SCR *sp, EXCMD *cmdp, CHAR_T *dname)
csc->dname = csc->buf;
csc->dlen = len;
memcpy(csc->dname, np, len);
- csc->mtim = sb.st_mtimespec;
+ csc->mtim = sb.st_mtim;
/* Get the search paths for the cscope. */
if (get_paths(sp, csc))
@@ -411,7 +411,8 @@ err: if (to_cs[0] != -1)
free(dn);
goto nomem;
}
- (void)asprintf(&cmd, CSCOPE_CMD_FMT, dn, dbn);
+ if (asprintf(&cmd, CSCOPE_CMD_FMT, dn, dbn) == -1)
+ cmd = NULL;
free(dbn);
free(dn);
if (cmd == NULL) {
@@ -812,7 +813,7 @@ csc_file(SCR *sp, CSC *csc, char *name, char **dirp, size_t *dlenp, int *isolder
*dirp = *pp;
*dlenp = strlen(*pp);
*isolderp = timespeccmp(
- &sb.st_mtimespec, &csc->mtim, <);
+ &sb.st_mtim, &csc->mtim, <);
return;
}
free(buf);
@@ -843,7 +844,7 @@ csc_help(SCR *sp, char *cmd)
{
CC const *ccp;
- if (cmd != NULL && *cmd != '\0')
+ if (cmd != NULL && *cmd != '\0') {
if ((ccp = lookup_ccmd(cmd)) == NULL) {
ex_printf(sp,
"%s doesn't match any cscope command\n", cmd);
@@ -854,6 +855,7 @@ csc_help(SCR *sp, char *cmd)
ex_printf(sp, " Usage: %s\n", ccp->usage_msg);
return (0);
}
+ }
ex_printf(sp, "cscope commands:\n");
for (ccp = cscope_cmds; ccp->name != NULL; ++ccp)
diff --git a/ex/ex_filter.c b/ex/ex_filter.c
index cd04643b5f08..fee34a6dc639 100644
--- a/ex/ex_filter.c
+++ b/ex/ex_filter.c
@@ -174,11 +174,12 @@ err: if (input[0] != -1)
if (ex_readfp(sp, "filter", ofp, fm, &nread, 1))
rval = 1;
sp->rptlines[L_ADDED] += nread;
- if (ftype == FILTER_READ)
+ if (ftype == FILTER_READ) {
if (fm->lno == 0)
rp->lno = nread;
else
rp->lno += nread;
+ }
goto uwait;
}
diff --git a/ex/ex_global.c b/ex/ex_global.c
index 54c6411d8799..cf3c8c9ce7cb 100644
--- a/ex/ex_global.c
+++ b/ex/ex_global.c
@@ -112,11 +112,12 @@ usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
*t = '\0';
break;
}
- if (p[0] == '\\')
+ if (p[0] == '\\') {
if (p[1] == delim)
++p;
else if (p[1] == '\\')
*t++ = *p++;
+ }
*t++ = *p++;
}
diff --git a/ex/ex_script.c b/ex/ex_script.c
index 5ba8c028f81a..def590d86741 100644
--- a/ex/ex_script.c
+++ b/ex/ex_script.c
@@ -32,6 +32,8 @@
#include <unistd.h>
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
+#elif defined HAVE_PTY_H
+#include <pty.h>
#else
#include <util.h>
#endif
diff --git a/ex/ex_shell.c b/ex/ex_shell.c
index 7b483fd4e14c..7d73253dfbc5 100644
--- a/ex/ex_shell.c
+++ b/ex/ex_shell.c
@@ -48,8 +48,7 @@ ex_shell(SCR *sp, EXCMD *cmdp)
* XXX
* Assumes all shells use -i.
*/
- (void)asprintf(&buf, "%s -i", O_STR(sp, O_SHELL));
- if (buf == NULL) {
+ if (asprintf(&buf, "%s -i", O_STR(sp, O_SHELL)) == -1) {
msgq(sp, M_SYSERR, NULL);
return (1);
}
diff --git a/ex/ex_subst.c b/ex/ex_subst.c
index d32d583f6a3b..bf03e4417e91 100644
--- a/ex/ex_subst.c
+++ b/ex/ex_subst.c
@@ -115,11 +115,12 @@ subagain: return (ex_subagain(sp, cmdp));
*t = '\0';
break;
}
- if (p[0] == '\\')
+ if (p[0] == '\\') {
if (p[1] == delim)
++p;
else if (p[1] == '\\')
*t++ = *p++;
+ }
*t++ = *p++;
}
@@ -296,7 +297,7 @@ ex_subtilde(SCR *sp, EXCMD *cmdp)
* when the replacement is done. Don't change it unless you're *damned*
* confident.
*/
-#define NEEDNEWLINE(sp) { \
+#define NEEDNEWLINE(sp) do { \
if (sp->newl_len == sp->newl_cnt) { \
sp->newl_len += 25; \
REALLOC(sp, sp->newl, size_t *, \
@@ -306,9 +307,9 @@ ex_subtilde(SCR *sp, EXCMD *cmdp)
return (1); \
} \
} \
-}
+} while (0)
-#define BUILD(sp, l, len) { \
+#define BUILD(sp, l, len) do { \
if (lbclen + (len) > lblen) { \
lblen = p2roundup(MAX(lbclen + (len), 256)); \
REALLOC(sp, lb, CHAR_T *, lblen * sizeof(CHAR_T)); \
@@ -319,9 +320,9 @@ ex_subtilde(SCR *sp, EXCMD *cmdp)
} \
MEMCPY(lb + lbclen, l, len); \
lbclen += len; \
-}
+} while (0)
-#define NEEDSP(sp, len, pnt) { \
+#define NEEDSP(sp, len, pnt) do { \
if (lbclen + (len) > lblen) { \
lblen = p2roundup(MAX(lbclen + (len), 256)); \
REALLOC(sp, lb, CHAR_T *, lblen * sizeof(CHAR_T)); \
@@ -331,7 +332,7 @@ ex_subtilde(SCR *sp, EXCMD *cmdp)
} \
pnt = lb + lbclen; \
} \
-}
+} while (0)
static int
s(SCR *sp, EXCMD *cmdp, CHAR_T *s, regex_t *re, u_int flags)
@@ -584,7 +585,7 @@ nextmatch: match[0].rm_so = 0;
empty_ok = 1;
if (len == 0)
goto endmatch;
- BUILD(sp, s + offset, 1)
+ BUILD(sp, s + offset, 1);
++offset;
--len;
goto nextmatch;
@@ -710,7 +711,7 @@ skip: offset += match[0].rm_eo;
/* Copy the rest of the line. */
if (len)
- BUILD(sp, s + offset, len)
+ BUILD(sp, s + offset, len);
/* Set the new offset. */
offset = saved_offset;
@@ -736,7 +737,7 @@ skip: offset += match[0].rm_eo;
goto err;
if (db_get(sp, lno, DBG_FATAL, &s, &llen))
goto err;
- ADD_SPACE_RETW(sp, bp, blen, llen)
+ ADD_SPACE_RETW(sp, bp, blen, llen);
MEMCPY(bp, s, llen);
s = bp;
len = llen - offset;
@@ -779,7 +780,7 @@ endmatch: if (!linechanged)
/* Copy any remaining bytes into the build buffer. */
if (len)
- BUILD(sp, s + offset, len)
+ BUILD(sp, s + offset, len);
/* Store inserted lines, adjusting the build buffer. */
last = 0;
@@ -1333,7 +1334,7 @@ re_sub(
* Otherwise, since this is the lowest level of replacement, discard
* all escaping characters. This (hopefully) matches historic practice.
*/
-#define OUTCH(ch, nltrans) { \
+#define OUTCH(ch, nltrans) do { \
ARG_CHAR_T __ch = (ch); \
e_key_t __value = KEY_VAL(sp, __ch); \
if (nltrans && (__value == K_CR || __value == K_NL)) { \
@@ -1362,7 +1363,7 @@ re_sub(
NEEDSP(sp, 1, p); \
*p++ = __ch; \
++lbclen; \
-}
+} while (0)
conv = C_NOTSET;
for (rp = sp->repl, rpl = sp->repl_len, p = lb + lbclen; rpl--;) {
switch (ch = *rp++) {
diff --git a/files/config.h.in b/files/config.h.in
index f592f3551a54..f6444357678c 100644
--- a/files/config.h.in
+++ b/files/config.h.in
@@ -13,5 +13,14 @@
/* Define if you have <ncurses.h> */
#cmakedefine HAVE_NCURSES_H
+/* Define if you have <ncursesw/ncurses.h> */
+#cmakedefine HAVE_NCURSESW_NCURSES_H
+
+/* Define if you have <pty.h> */
+#cmakedefine HAVE_PTY_H
+
/* Define if you have <term.h> */
#cmakedefine HAVE_TERM_H
+
+/* Define if struct dirent has field d_namlen */
+#cmakedefine HAVE_DIRENT_D_NAMLEN
diff --git a/files/pathnames.h.in b/files/pathnames.h.in
index f1c2821f41c0..eb03f11d979a 100644
--- a/files/pathnames.h.in
+++ b/files/pathnames.h.in
@@ -13,9 +13,8 @@
#define _PATH_NEXRC ".nexrc"
#endif
-#ifndef _PATH_PRESERVE
-#define _PATH_PRESERVE "@vi_cv_path_preserve@"
-#endif
+/* On linux _PATH_PRESERVE is only writable by root */
+#define NVI_PATH_PRESERVE "@vi_cv_path_preserve@"
#ifndef _PATH_SYSEXRC
#define _PATH_SYSEXRC "/etc/vi.exrc"
diff --git a/man/vi.1 b/man/vi.1
index fcbc1531d9ac..ce7b883f8497 100644
--- a/man/vi.1
+++ b/man/vi.1
@@ -2743,6 +2743,10 @@ and \*(Gt0 if an error occurs.
.Xr ctags 1 ,
.Xr iconv 1 ,
.Xr re_format 7
+.Rs
+.%T vi/ex reference manual
+.%U https://docs.freebsd.org/44doc/usd/13.viref/paper.pdf
+.Re
.Sh STANDARDS
.Nm nex Ns / Ns Nm nvi
is close to
diff --git a/regex/engine.c b/regex/engine.c
index 069a473921c5..056be0c9786e 100644
--- a/regex/engine.c
+++ b/regex/engine.c
@@ -118,7 +118,7 @@ static char *pchar(int ch);
#ifdef REDEBUG
#define SP(t, s, c) print(m, t, s, c, stdout)
#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
-#define NOTE(str) { if (m->eflags&REG_TRACE) printf("=%s\n", (str)); }
+#define NOTE(str) do { if (m->eflags&REG_TRACE) printf("=%s\n", (str)); } while(0);
#else
#define SP(t, s, c) /* nothing */
#define AT(t, p1, p2, s1, s2) /* nothing */
diff --git a/regex/regexec.c b/regex/regexec.c
index 67abd01e5c87..6fed64010f40 100644
--- a/regex/regexec.c
+++ b/regex/regexec.c
@@ -114,10 +114,10 @@ static char sccsid[] = "@(#)regexec.c 8.2 (Berkeley) 3/16/94";
#define ASSIGN(d, s) memcpy(d, s, m->g->nstates)
#define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
#define STATEVARS int vn; char *space
-#define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
+#define STATESETUP(m, nv) do { (m)->space = malloc((nv)*(m)->g->nstates); \
if ((m)->space == NULL) return(REG_ESPACE); \
- (m)->vn = 0; }
-#define STATETEARDOWN(m) { free((m)->space); }
+ (m)->vn = 0; } while (0)
+#define STATETEARDOWN(m) free((m)->space)
#define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
#define onestate int
#define INIT(o, n) ((o) = (n))
diff --git a/vi/v_itxt.c b/vi/v_itxt.c
index 704a0c322176..3c69ed7065fe 100644
--- a/vi/v_itxt.c
+++ b/vi/v_itxt.c
@@ -48,10 +48,10 @@
* position.) We also check for mapped keys waiting, i.e. if we're in the
* middle of a map, don't bother logging the cursor.
*/
-#define LOG_CORRECT { \
+#define LOG_CORRECT do { \
if (!MAPPED_KEYS_WAITING(sp)) \
(void)log_cursor(sp); \
-}
+} while (0)
static u_int32_t set_txt_std(SCR *, VICMD *, u_int32_t);
diff --git a/vi/v_paragraph.c b/vi/v_paragraph.c
index e3fdce969695..abe8d9cf50e0 100644
--- a/vi/v_paragraph.c
+++ b/vi/v_paragraph.c
@@ -23,7 +23,7 @@
#include "../common/common.h"
#include "vi.h"
-#define INTEXT_CHECK { \
+#define INTEXT_CHECK do { \
if (len == 0 || v_isempty(p, len)) { \
if (!--cnt) \
goto found; \
@@ -48,7 +48,7 @@
(lp[1] == ' ' && len == 2 || lp[1] == p[2]) && \
!--cnt) \
goto found; \
-}
+} while (0)
/*
* v_paragraphf -- [count]}
@@ -83,7 +83,7 @@ v_paragraphf(SCR *sp, VICMD *vp)
* line itself remained. If somebody complains, don't pause, don't
* hesitate, just hit them.
*/
- if (ISMOTION(vp))
+ if (ISMOTION(vp)) {
if (vp->m_start.cno == 0)
F_SET(vp, VM_LMODE);
else {
@@ -94,6 +94,7 @@ v_paragraphf(SCR *sp, VICMD *vp)
if (vp->m_start.cno <= vp->m_stop.cno)
F_SET(vp, VM_LMODE);
}
+ }
/* Figure out what state we're currently in. */
lno = vp->m_start.lno;
@@ -226,7 +227,7 @@ v_paragraphb(SCR *sp, VICMD *vp)
*/
lno = vp->m_start.lno;
- if (ISMOTION(vp))
+ if (ISMOTION(vp)) {
if (vp->m_start.cno == 0) {
if (vp->m_start.lno == 1) {
v_sof(sp, &vp->m_start);
@@ -236,6 +237,7 @@ v_paragraphb(SCR *sp, VICMD *vp)
F_SET(vp, VM_LMODE);
} else
--vp->m_start.cno;
+ }
if (vp->m_start.lno <= 1)
goto sof;
diff --git a/vi/v_section.c b/vi/v_section.c
index 5314f4621ad0..09da4bac38ee 100644
--- a/vi/v_section.c
+++ b/vi/v_section.c
@@ -77,7 +77,7 @@ v_sectionf(SCR *sp, VICMD *vp)
* check here, because we know that the end is going to be the start
* or end of a line.
*/
- if (ISMOTION(vp))
+ if (ISMOTION(vp)) {
if (vp->m_start.cno == 0)
F_SET(vp, VM_LMODE);
else {
@@ -88,6 +88,7 @@ v_sectionf(SCR *sp, VICMD *vp)
if (vp->m_start.cno <= vp->m_stop.cno)
F_SET(vp, VM_LMODE);
}
+ }
cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
for (lno = vp->m_start.lno; !db_get(sp, ++lno, 0, &p, &len);) {
diff --git a/vi/v_sentence.c b/vi/v_sentence.c
index 3415fbd18937..4ba9cfc1df33 100644
--- a/vi/v_sentence.c
+++ b/vi/v_sentence.c
@@ -336,7 +336,7 @@ okret: vp->m_stop.lno = cs.cs_lno;
* All commands move to the end of the range. Adjust the start of
* the range for motion commands.
*/
- if (ISMOTION(vp))
+ if (ISMOTION(vp)) {
if (vp->m_start.cno == 0 &&
(cs.cs_flags != 0 || vp->m_stop.cno == 0)) {
if (db_get(sp,
@@ -346,6 +346,7 @@ okret: vp->m_stop.lno = cs.cs_lno;
F_SET(vp, VM_LMODE);
} else
--vp->m_start.cno;
+ }
vp->m_final = vp->m_stop;
return (0);
}
diff --git a/vi/v_txt.c b/vi/v_txt.c
index 84d20c6ad1c1..c6dc7cee4659 100644
--- a/vi/v_txt.c
+++ b/vi/v_txt.c
@@ -221,10 +221,10 @@ txt_map_end(SCR *sp)
* Internally, we maintain tp->lno and tp->cno, externally, everyone uses
* sp->lno and sp->cno. Make them consistent as necessary.
*/
-#define UPDATE_POSITION(sp, tp) { \
+#define UPDATE_POSITION(sp, tp) do { \
(sp)->lno = (tp)->lno; \
(sp)->cno = (tp)->cno; \
-}
+} while (0)
/*
* v_txt --
@@ -677,7 +677,7 @@ k_cr: if (LF_ISSET(TXT_CR)) {
goto k_escape;
}
-#define LINE_RESOLVE { \
+#define LINE_RESOLVE do { \
/* \
* Handle abbreviations. If there was one, discard the \
* replay characters. \
@@ -708,7 +708,7 @@ k_cr: if (LF_ISSET(TXT_CR)) {
--tp->len; \
--tp->insert; \
} \
-}
+} while (0)
LINE_RESOLVE;
/*
@@ -1527,7 +1527,7 @@ txt_abbrev(SCR *sp, TEXT *tp, CHAR_T *pushcp, int isinfoline, int *didsubp, int
*
* This makes the layering look like a Nachos Supreme.
*/
-search: if (isinfoline)
+search: if (isinfoline) {
if (off == tp->ai || off == tp->offset)
if (ex_is_abbrev(p, len)) {
*turnoffp = 1;
@@ -1537,6 +1537,7 @@ search: if (isinfoline)
else
if (*turnoffp)
return (0);
+ }
/* Check for any abbreviations. */
if ((qp = seq_find(sp, NULL, NULL, p, len, SEQ_ABBREV, NULL)) == NULL)
diff --git a/vi/vi.c b/vi/vi.c
index 27ace47a8ea3..af0b7598beea 100644
--- a/vi/vi.c
+++ b/vi/vi.c
@@ -405,7 +405,7 @@ ret: rval = 1;
return (rval);
}
-#define KEY(key, ec_flags) { \
+#define KEY(key, ec_flags) do { \
if ((gcret = v_key(sp, 0, &ev, ec_flags)) != GC_OK) \
return (gcret); \
if (ev.e_value == K_ESCAPE) \
@@ -413,7 +413,7 @@ ret: rval = 1;
if (F_ISSET(&ev.e_ch, CH_MAPPED)) \
*mappedp = 1; \
key = ev.e_c; \
-}
+} while (0)
/*
* The O_TILDEOP option makes the ~ command take a motion instead
diff --git a/vi/vs_line.c b/vi/vs_line.c
index 3bb8057ade92..e5778e1971e6 100644
--- a/vi/vs_line.c
+++ b/vi/vs_line.c
@@ -165,7 +165,7 @@ vs_line(SCR *sp, SMAP *smp, size_t *yp, size_t *xp)
* Lots of special cases for empty lines, but they only apply
* if we're displaying the first screen of the line.
*/
- if (skip_cols == 0)
+ if (skip_cols == 0) {
if (dne) {
if (smp->lno == 1) {
if (list_dollar) {
@@ -176,12 +176,14 @@ vs_line(SCR *sp, SMAP *smp, size_t *yp, size_t *xp)
ch = '~';
goto empty;
}
- } else
+ } else {
if (list_dollar) {
ch = '$';
empty: (void)gp->scr_addstr(sp,
KEY_NAME(sp, ch), KEY_LEN(sp, ch));
}
+ }
+ }
(void)gp->scr_clrtoeol(sp);
(void)gp->scr_move(sp, oldy, oldx);
@@ -402,11 +404,11 @@ display:
if (is_cached || no_draw)
continue;
-#define FLUSH { \
+#define FLUSH do { \
*cbp = '\0'; \
(void)gp->scr_waddstr(sp, cbuf, cbp - cbuf); \
cbp = cbuf; \
-}
+} while (0)
/*
* Display the character. We do tab expansion here because
* the screen interface doesn't have any way to set the tab
diff --git a/vi/vs_msg.c b/vi/vs_msg.c
index d6144bca692c..25421f0bb1e2 100644
--- a/vi/vs_msg.c
+++ b/vi/vs_msg.c
@@ -240,12 +240,13 @@ vs_msg(SCR *sp, mtype_t mtype, char *line, size_t len)
* XXX
* Shouldn't we save this, too?
*/
- if (F_ISSET(sp, SC_TINPUT_INFO) || F_ISSET(gp, G_BELLSCHED))
+ if (F_ISSET(sp, SC_TINPUT_INFO) || F_ISSET(gp, G_BELLSCHED)) {
if (F_ISSET(sp, SC_SCR_VI)) {
F_CLR(gp, G_BELLSCHED);
(void)gp->scr_bell(sp);
} else
F_SET(gp, G_BELLSCHED);
+ }
/*
* If vi is using the error line for text input, there's no screen
@@ -271,13 +272,14 @@ vs_msg(SCR *sp, mtype_t mtype, char *line, size_t len)
* the screen, so previous opinions are ignored.
*/
if (F_ISSET(sp, SC_EX | SC_SCR_EXWROTE)) {
- if (!F_ISSET(sp, SC_SCR_EX))
+ if (!F_ISSET(sp, SC_SCR_EX)) {
if (F_ISSET(sp, SC_SCR_EXWROTE)) {
if (sp->gp->scr_screen(sp, SC_EX))
return;
} else
if (ex_init(sp))
return;
+ }
if (mtype == M_ERR)
(void)gp->scr_attr(sp, SA_INVERSE, 1);
@@ -339,13 +341,14 @@ vs_msg(SCR *sp, mtype_t mtype, char *line, size_t len)
padding += 2;
maxcols = sp->cols - 1;
- if (vip->lcontinue != 0)
+ if (vip->lcontinue != 0) {
if (len + vip->lcontinue + padding > maxcols)
vs_output(sp, vip->mtype, ".\n", 2);
else {
vs_output(sp, vip->mtype, ";", 1);
vs_output(sp, M_NONE, " ", 1);
}
+ }
vip->mtype = mtype;
for (s = line;; s = t) {
for (; len > 0 && isblank((u_char)*s); --len, ++s);
@@ -452,11 +455,11 @@ vs_output(SCR *sp, mtype_t mtype, const char *line, int llen)
(void)gp->scr_attr(sp, SA_INVERSE, 1);
/* Display the line, doing character translation. */
-#define FLUSH { \
+#define FLUSH do { \
*cbp = '\0'; \
(void)gp->scr_addstr(sp, cbuf, cbp - cbuf); \
cbp = cbuf; \
-}
+} while (0)
ecbp = (cbp = cbuf) + sizeof(cbuf) - 1;
for (t = line, tlen = len; tlen--; ++t) {
/*
diff --git a/vi/vs_refresh.c b/vi/vs_refresh.c
index a512f0a04c00..b64ec7392cbb 100644
--- a/vi/vs_refresh.c
+++ b/vi/vs_refresh.c
@@ -241,7 +241,7 @@ vs_paint(
* screen but the column offset is not, we'll end up in the adjust
* code, when we should probably have compressed the screen.
*/
- if (IS_SMALL(sp))
+ if (IS_SMALL(sp)) {
if (LNO < HMAP->lno) {
lcnt = vs_sm_nlines(sp, HMAP, LNO, sp->t_maxrows);
if (lcnt <= HALFSCREEN(sp))
@@ -278,6 +278,7 @@ small_fill: (void)gp->scr_move(sp, LASTLINE(sp), 0);
goto adjust;
}
}
+ }
/*
* 6b: Line down, or current screen.
@@ -390,7 +391,7 @@ top: if (vs_sm_fill(sp, LNO, P_TOP))
adjust: if (!O_ISSET(sp, O_LEFTRIGHT) &&
(LNO == HMAP->lno || LNO == TMAP->lno)) {
cnt = vs_screens(sp, LNO, &CNO);
- if (LNO == HMAP->lno && cnt < HMAP->soff)
+ if (LNO == HMAP->lno && cnt < HMAP->soff) {
if ((HMAP->soff - cnt) > HALFTEXT(sp)) {
HMAP->soff = cnt;
vs_sm_fill(sp, OOBLNO, P_TOP);
@@ -399,7 +400,8 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) &&
while (cnt < HMAP->soff)
if (vs_sm_1down(sp))
return (1);
- if (LNO == TMAP->lno && cnt > TMAP->soff)
+ }
+ if (LNO == TMAP->lno && cnt > TMAP->soff) {
if ((cnt - TMAP->soff) > HALFTEXT(sp)) {
TMAP->soff = cnt;
vs_sm_fill(sp, OOBLNO, P_BOTTOM);
@@ -408,6 +410,7 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) &&
while (cnt > TMAP->soff)
if (vs_sm_1up(sp))
return (1);
+ }
}
/*
diff --git a/vi/vs_relative.c b/vi/vs_relative.c
index 5df8c3c3f22d..353dcbe9d572 100644
--- a/vi/vs_relative.c
+++ b/vi/vs_relative.c
@@ -142,15 +142,16 @@ done: if (diffp != NULL) /* XXX */
* last column of the screen. Otherwise, display the rest of the
* character in the next screen.
*/
-#define TAB_RESET { \
+#define TAB_RESET do { \
curoff += chlen; \
- if (!leftright && curoff >= sp->cols) \
+ if (!leftright && curoff >= sp->cols) { \
if (ch == '\t') { \
curoff = 0; \
scno -= scno % sp->cols; \
} else \
curoff -= sp->cols; \
-}
+ } \
+} while (0)
if (cnop == NULL)
while (len--) {
chlen = CHLEN(curoff);
diff --git a/vi/vs_smap.c b/vi/vs_smap.c
index 971502ebd62b..2c0f2a4d94d3 100644
--- a/vi/vs_smap.c
+++ b/vi/vs_smap.c
@@ -292,12 +292,12 @@ err: HMAP->lno = 1;
* so the screen map is refilled and the screen redrawn, and return. This
* is amazingly slow, but it's not clear that anyone will care.
*/
-#define HANDLE_WEIRDNESS(cnt) { \
+#define HANDLE_WEIRDNESS(cnt) do { \
if (cnt >= sp->t_rows) { \
F_SET(sp, SC_SCR_REFORMAT); \
return (0); \
} \
-}
+} while (0)
/*
* vs_sm_delete --