Index: head/contrib/nvi/CMakeLists.txt =================================================================== --- head/contrib/nvi/CMakeLists.txt +++ head/contrib/nvi/CMakeLists.txt @@ -13,6 +13,7 @@ include(CheckIncludeFiles) include(CheckFunctionExists) +include(CheckStructHasMember) include(CheckCSourceCompiles) mark_as_advanced(CMAKE_INSTALL_PREFIX) @@ -127,6 +128,7 @@ 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 @@ 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 @@ 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) Index: head/contrib/nvi/catalog/dump.c =================================================================== --- head/contrib/nvi/catalog/dump.c +++ head/contrib/nvi/catalog/dump.c @@ -36,24 +36,24 @@ { 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); Index: head/contrib/nvi/cl/cl.h =================================================================== --- head/contrib/nvi/cl/cl.h +++ head/contrib/nvi/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 +#elif defined HAVE_NCURSES_H #include #else #include Index: head/contrib/nvi/cl/cl_read.c =================================================================== --- head/contrib/nvi/cl/cl_read.c +++ head/contrib/nvi/cl/cl_read.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include Index: head/contrib/nvi/cl/cl_term.c =================================================================== --- head/contrib/nvi/cl/cl_term.c +++ head/contrib/nvi/cl/cl_term.c @@ -424,16 +424,18 @@ 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. */ Index: head/contrib/nvi/common/common.h =================================================================== --- head/contrib/nvi/common/common.h +++ head/contrib/nvi/common/common.h @@ -7,7 +7,15 @@ * See the LICENSE file for redistribution information. */ -#include /* Only include db1. */ +#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 /* May refer to the bundled regex. */ /* Index: head/contrib/nvi/common/cut.h =================================================================== --- head/contrib/nvi/common/cut.h +++ head/contrib/nvi/common/cut.h @@ -63,13 +63,13 @@ * 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. */ Index: head/contrib/nvi/common/exf.c =================================================================== --- head/contrib/nvi/common/exf.c +++ head/contrib/nvi/common/exf.c @@ -199,7 +199,7 @@ 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 @@ 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 @@ 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 @@ * 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 @@ 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 @@ */ 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 @@ * 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 @@ "263|File modified since last complete write; write or use :edit! to override"); return (1); } + } return (file_m3(sp, force)); } Index: head/contrib/nvi/common/key.c =================================================================== --- head/contrib/nvi/common/key.c +++ head/contrib/nvi/common/key.c @@ -424,12 +424,12 @@ } /* 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 -- Index: head/contrib/nvi/common/log.c =================================================================== --- head/contrib/nvi/common/log.c +++ head/contrib/nvi/common/log.c @@ -69,10 +69,10 @@ 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 Index: head/contrib/nvi/common/main.c =================================================================== --- head/contrib/nvi/common/main.c +++ head/contrib/nvi/common/main.c @@ -48,8 +48,8 @@ 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 @@ } 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 @@ 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 @@ argv[0][1] == 't' || argv[0][1] == 'w') && argv[0][2] == '\0') ++argv; + } return (0); } Index: head/contrib/nvi/common/mark.c =================================================================== --- head/contrib/nvi/common/mark.c +++ head/contrib/nvi/common/mark.c @@ -216,12 +216,13 @@ 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: /* Index: head/contrib/nvi/common/mem.h =================================================================== --- head/contrib/nvi/common/mem.h +++ head/contrib/nvi/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 -- Index: head/contrib/nvi/common/msg.c =================================================================== --- head/contrib/nvi/common/msg.c +++ head/contrib/nvi/common/msg.c @@ -731,7 +731,11 @@ * 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 Index: head/contrib/nvi/common/options.c =================================================================== --- head/contrib/nvi/common/options.c +++ head/contrib/nvi/common/options.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "common.h" @@ -312,7 +313,7 @@ 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 @@ 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 @@ 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 @@ * 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 @@ opts_print(SCR *sp, OPTLIST const *op) { int curlen, offset; + const char *p; curlen = 0; offset = op - optlist; @@ -958,8 +961,13 @@ 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); Index: head/contrib/nvi/common/put.c =================================================================== --- head/contrib/nvi/common/put.c +++ head/contrib/nvi/common/put.c @@ -39,7 +39,7 @@ 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 @@ return (1); } } + } tp = TAILQ_FIRST(cbp->textq); /* Index: head/contrib/nvi/common/recover.c =================================================================== --- head/contrib/nvi/common/recover.c +++ head/contrib/nvi/common/recover.c @@ -421,7 +421,7 @@ getprogname(), " -r ", qt); free(qt); free(host); - if (buf == NULL) { + if (len == -1) { msgq(sp, M_SYSERR, NULL); goto err; } @@ -701,7 +701,7 @@ /* 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 @@ 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 @@ { 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; Index: head/contrib/nvi/common/util.c =================================================================== --- head/contrib/nvi/common/util.c +++ head/contrib/nvi/common/util.c @@ -111,8 +111,9 @@ 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 @@ 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) Index: head/contrib/nvi/ex/ex.h =================================================================== --- head/contrib/nvi/ex/ex.h +++ head/contrib/nvi/ex/ex.h @@ -55,12 +55,12 @@ * 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 @@ 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. */ Index: head/contrib/nvi/ex/ex.c =================================================================== --- head/contrib/nvi/ex/ex.c +++ head/contrib/nvi/ex/ex.c @@ -811,13 +811,14 @@ * 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 @@ 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 @@ ex_badaddr(sp, NULL, A_EOF, NUM_OK); goto err; } + } /* FALLTHROUGH */ case 1: if (ecp->addr1.lno == 0) { @@ -2117,7 +2119,7 @@ /* 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 @@ if (sp->lno == 0) sp->lno = 1; } + } free(ecp->o_cp); } Index: head/contrib/nvi/ex/ex_argv.c =================================================================== --- head/contrib/nvi/ex/ex_argv.c +++ head/contrib/nvi/ex/ex_argv.c @@ -611,9 +611,17 @@ 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; } Index: head/contrib/nvi/ex/ex_bang.c =================================================================== --- head/contrib/nvi/ex/ex_bang.c +++ head/contrib/nvi/ex/ex_bang.c @@ -96,7 +96,7 @@ */ 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 @@ 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); Index: head/contrib/nvi/ex/ex_cscope.c =================================================================== --- head/contrib/nvi/ex/ex_cscope.c +++ head/contrib/nvi/ex/ex_cscope.c @@ -261,7 +261,7 @@ 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 @@ 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 @@ *dirp = *pp; *dlenp = strlen(*pp); *isolderp = timespeccmp( - &sb.st_mtimespec, &csc->mtim, <); + &sb.st_mtim, &csc->mtim, <); return; } free(buf); @@ -843,7 +844,7 @@ { 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 @@ 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) Index: head/contrib/nvi/ex/ex_filter.c =================================================================== --- head/contrib/nvi/ex/ex_filter.c +++ head/contrib/nvi/ex/ex_filter.c @@ -174,11 +174,12 @@ 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; } Index: head/contrib/nvi/ex/ex_global.c =================================================================== --- head/contrib/nvi/ex/ex_global.c +++ head/contrib/nvi/ex/ex_global.c @@ -112,11 +112,12 @@ *t = '\0'; break; } - if (p[0] == '\\') + if (p[0] == '\\') { if (p[1] == delim) ++p; else if (p[1] == '\\') *t++ = *p++; + } *t++ = *p++; } Index: head/contrib/nvi/ex/ex_script.c =================================================================== --- head/contrib/nvi/ex/ex_script.c +++ head/contrib/nvi/ex/ex_script.c @@ -32,6 +32,8 @@ #include #ifdef HAVE_LIBUTIL_H #include +#elif defined HAVE_PTY_H +#include #else #include #endif Index: head/contrib/nvi/ex/ex_shell.c =================================================================== --- head/contrib/nvi/ex/ex_shell.c +++ head/contrib/nvi/ex/ex_shell.c @@ -48,8 +48,7 @@ * 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); } Index: head/contrib/nvi/ex/ex_subst.c =================================================================== --- head/contrib/nvi/ex/ex_subst.c +++ head/contrib/nvi/ex/ex_subst.c @@ -115,11 +115,12 @@ *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 @@ * 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 @@ 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 @@ } \ 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 @@ } \ 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 @@ 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 @@ /* 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 @@ 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 @@ /* 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 @@ * 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 @@ 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++) { Index: head/contrib/nvi/files/config.h.in =================================================================== --- head/contrib/nvi/files/config.h.in +++ head/contrib/nvi/files/config.h.in @@ -13,5 +13,14 @@ /* Define if you have */ #cmakedefine HAVE_NCURSES_H +/* Define if you have */ +#cmakedefine HAVE_NCURSESW_NCURSES_H + +/* Define if you have */ +#cmakedefine HAVE_PTY_H + /* Define if you have */ #cmakedefine HAVE_TERM_H + +/* Define if struct dirent has field d_namlen */ +#cmakedefine HAVE_DIRENT_D_NAMLEN Index: head/contrib/nvi/files/pathnames.h.in =================================================================== --- head/contrib/nvi/files/pathnames.h.in +++ head/contrib/nvi/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" Index: head/contrib/nvi/regex/engine.c =================================================================== --- head/contrib/nvi/regex/engine.c +++ head/contrib/nvi/regex/engine.c @@ -118,7 +118,7 @@ #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®_TRACE) printf("=%s\n", (str)); } +#define NOTE(str) do { if (m->eflags®_TRACE) printf("=%s\n", (str)); } while(0); #else #define SP(t, s, c) /* nothing */ #define AT(t, p1, p2, s1, s2) /* nothing */ Index: head/contrib/nvi/regex/regexec.c =================================================================== --- head/contrib/nvi/regex/regexec.c +++ head/contrib/nvi/regex/regexec.c @@ -114,10 +114,10 @@ #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)) Index: head/contrib/nvi/vi/v_itxt.c =================================================================== --- head/contrib/nvi/vi/v_itxt.c +++ head/contrib/nvi/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); Index: head/contrib/nvi/vi/v_paragraph.c =================================================================== --- head/contrib/nvi/vi/v_paragraph.c +++ head/contrib/nvi/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 @@ * 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 @@ 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 @@ */ 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 @@ F_SET(vp, VM_LMODE); } else --vp->m_start.cno; + } if (vp->m_start.lno <= 1) goto sof; Index: head/contrib/nvi/vi/v_section.c =================================================================== --- head/contrib/nvi/vi/v_section.c +++ head/contrib/nvi/vi/v_section.c @@ -77,7 +77,7 @@ * 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 @@ 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);) { Index: head/contrib/nvi/vi/v_sentence.c =================================================================== --- head/contrib/nvi/vi/v_sentence.c +++ head/contrib/nvi/vi/v_sentence.c @@ -336,7 +336,7 @@ * 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 @@ F_SET(vp, VM_LMODE); } else --vp->m_start.cno; + } vp->m_final = vp->m_stop; return (0); } Index: head/contrib/nvi/vi/v_txt.c =================================================================== --- head/contrib/nvi/vi/v_txt.c +++ head/contrib/nvi/vi/v_txt.c @@ -221,10 +221,10 @@ * 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 @@ goto k_escape; } -#define LINE_RESOLVE { \ +#define LINE_RESOLVE do { \ /* \ * Handle abbreviations. If there was one, discard the \ * replay characters. \ @@ -708,7 +708,7 @@ --tp->len; \ --tp->insert; \ } \ -} +} while (0) LINE_RESOLVE; /* @@ -1527,7 +1527,7 @@ * * 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 @@ else if (*turnoffp) return (0); + } /* Check for any abbreviations. */ if ((qp = seq_find(sp, NULL, NULL, p, len, SEQ_ABBREV, NULL)) == NULL) Index: head/contrib/nvi/vi/vi.c =================================================================== --- head/contrib/nvi/vi/vi.c +++ head/contrib/nvi/vi/vi.c @@ -405,7 +405,7 @@ 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 @@ 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 Index: head/contrib/nvi/vi/vs_line.c =================================================================== --- head/contrib/nvi/vi/vs_line.c +++ head/contrib/nvi/vi/vs_line.c @@ -165,7 +165,7 @@ * 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 @@ 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 @@ 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 Index: head/contrib/nvi/vi/vs_msg.c =================================================================== --- head/contrib/nvi/vi/vs_msg.c +++ head/contrib/nvi/vi/vs_msg.c @@ -240,12 +240,13 @@ * 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 @@ * 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 @@ 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 @@ (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) { /* Index: head/contrib/nvi/vi/vs_refresh.c =================================================================== --- head/contrib/nvi/vi/vs_refresh.c +++ head/contrib/nvi/vi/vs_refresh.c @@ -241,7 +241,7 @@ * 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 @@ goto adjust; } } + } /* * 6b: Line down, or current screen. @@ -390,7 +391,7 @@ 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 @@ 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 @@ while (cnt > TMAP->soff) if (vs_sm_1up(sp)) return (1); + } } /* Index: head/contrib/nvi/vi/vs_relative.c =================================================================== --- head/contrib/nvi/vi/vs_relative.c +++ head/contrib/nvi/vi/vs_relative.c @@ -142,15 +142,16 @@ * 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); Index: head/contrib/nvi/vi/vs_smap.c =================================================================== --- head/contrib/nvi/vi/vs_smap.c +++ head/contrib/nvi/vi/vs_smap.c @@ -292,12 +292,12 @@ * 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 -- Index: head/usr.bin/vi/catalog/Makefile =================================================================== --- head/usr.bin/vi/catalog/Makefile +++ head/usr.bin/vi/catalog/Makefile @@ -20,6 +20,7 @@ all: dump build-tools: dump +WARNS= 3 # Helper since iconv is non trivial to make a build tool utf8convert: @@ -102,7 +103,7 @@ sed -e '/|/!d' \ -e 's/|/ "/' \ -e 's/^"//' |\ - sort -nu > $@ + LC_ALL=C sort -nu > $@ DEPENDOBJS+= dump Index: head/usr.bin/vi/pathnames.h =================================================================== --- head/usr.bin/vi/pathnames.h +++ head/usr.bin/vi/pathnames.h @@ -15,9 +15,8 @@ #define _PATH_NEXRC ".nexrc" #endif -#ifndef _PATH_PRESERVE -#define _PATH_PRESERVE "/var/tmp/vi.recover/" -#endif +/* On linux _PATH_PRESERVE is only writable by root */ +#define NVI_PATH_PRESERVE "/var/tmp/vi.recover/" #ifndef _PATH_SYSEXRC #define _PATH_SYSEXRC "/etc/vi.exrc"