Pull up following revision(s) (requested by lukem in ticket #292): netbsd-5
authorsnj <snj@NetBSD.org>
Tue, 20 Jan 2009 02:41:11 +0000
branchnetbsd-5
changeset 258105 710c7d35a652
parent 258104 4a0faaa71f26
child 258106 3fee7813c340
Pull up following revision(s) (requested by lukem in ticket #292): dist/nvi/cl/cl_bsd.c: revision 1.3 dist/nvi/cl/cl_funcs.c: revision 1.2 dist/nvi/cl/cl_main.c: revision 1.2 dist/nvi/cl/cl_read.c: revision 1.2 dist/nvi/cl/cl_screen.c: revision 1.2 dist/nvi/cl/cl_term.c: revision 1.2 dist/nvi/cl/extern.h: revision 1.2 dist/nvi/common/api.c: revision 1.2 dist/nvi/common/conv.c: revision 1.4 dist/nvi/common/conv.h: revision 1.2 dist/nvi/common/cut.c: revision 1.2 dist/nvi/common/cut.h: revision 1.2 dist/nvi/common/db.c: revision 1.2 dist/nvi/common/db1.c: revision 1.4 dist/nvi/common/dbinternal.h: revision 1.1 dist/nvi/common/exf.c: revision 1.2 dist/nvi/common/extern.h: revision 1.2 dist/nvi/common/gs.h: revision 1.3 dist/nvi/common/key.c: revision 1.3 dist/nvi/common/log.c: revision 1.2 dist/nvi/common/main.c: revision 1.3 dist/nvi/common/mark.c: revision 1.2 dist/nvi/common/mem.h: revision 1.2 dist/nvi/common/msg.c: revision 1.2 dist/nvi/common/options.c: revision 1.4 dist/nvi/common/options.h: revision 1.3 dist/nvi/common/options_f.c: revision 1.3 dist/nvi/common/put.c: revision 1.2 dist/nvi/common/recover.c: revision 1.2 dist/nvi/common/search.c: revision 1.2 dist/nvi/common/seq.c: revision 1.2 dist/nvi/common/util.c: revision 1.3 dist/nvi/ex/ex.c: revision 1.2 dist/nvi/ex/ex.h: revision 1.3 dist/nvi/ex/ex_append.c: revision 1.2 dist/nvi/ex/ex_args.c: revision 1.2 dist/nvi/ex/ex_argv.c: revision 1.2 dist/nvi/ex/ex_at.c: revision 1.2 dist/nvi/ex/ex_bang.c: revision 1.2 dist/nvi/ex/ex_cd.c: revision 1.2 dist/nvi/ex/ex_cmd.c: revision 1.3 dist/nvi/ex/ex_cscope.c: revision 1.2 dist/nvi/ex/ex_display.c: revision 1.2 dist/nvi/ex/ex_edit.c: revision 1.2 dist/nvi/ex/ex_file.c: revision 1.2 dist/nvi/ex/ex_filter.c: revision 1.2 dist/nvi/ex/ex_global.c: revision 1.2 dist/nvi/ex/ex_init.c: revision 1.2 dist/nvi/ex/ex_join.c: revision 1.2 dist/nvi/ex/ex_mkexrc.c: revision 1.2 dist/nvi/ex/ex_preserve.c: revision 1.2 dist/nvi/ex/ex_print.c: revision 1.2 dist/nvi/ex/ex_read.c: revision 1.2 dist/nvi/ex/ex_script.c: revision 1.3 dist/nvi/ex/ex_shell.c: revision 1.2 dist/nvi/ex/ex_source.c: revision 1.2 dist/nvi/ex/ex_subst.c: revision 1.2 dist/nvi/ex/ex_tag.c: revision 1.4 dist/nvi/ex/ex_txt.c: revision 1.2 dist/nvi/ex/ex_usage.c: revision 1.2 dist/nvi/ex/ex_util.c: revision 1.2 dist/nvi/ex/ex_visual.c: revision 1.2 dist/nvi/ex/ex_write.c: revision 1.2 dist/nvi/ex/ex_z.c: revision 1.2 dist/nvi/ex/extern.h: revision 1.3 dist/nvi/regex/cclass.h: revision 1.2 dist/nvi/regex/cname.h: revision 1.2 dist/nvi/regex/engine.c: revision 1.2 dist/nvi/regex/regcomp.c: revision 1.2 dist/nvi/regex/regerror.c: revision 1.2 dist/nvi/regex/regexec.c: revision 1.2 dist/nvi/vi/extern.h: revision 1.2 dist/nvi/vi/getc.c: revision 1.2 dist/nvi/vi/v_at.c: revision 1.2 dist/nvi/vi/v_cmd.c: revision 1.2 dist/nvi/vi/v_event.c: revision 1.2 dist/nvi/vi/v_ex.c: revision 1.3 dist/nvi/vi/v_increment.c: revision 1.2 dist/nvi/vi/v_init.c: revision 1.2 dist/nvi/vi/v_mark.c: revision 1.2 dist/nvi/vi/v_match.c: revision 1.3 dist/nvi/vi/v_paragraph.c: revision 1.2 dist/nvi/vi/v_replace.c: revision 1.2 dist/nvi/vi/v_scroll.c: revision 1.2 dist/nvi/vi/v_search.c: revision 1.2 dist/nvi/vi/v_section.c: revision 1.2 dist/nvi/vi/v_sentence.c: revision 1.2 dist/nvi/vi/v_txt.c: revision 1.2 dist/nvi/vi/v_util.c: revision 1.2 dist/nvi/vi/v_word.c: revision 1.2 dist/nvi/vi/vi.c: revision 1.2 dist/nvi/vi/vi.h: revision 1.3 dist/nvi/vi/vs_line.c: revision 1.2 dist/nvi/vi/vs_msg.c: revision 1.2 dist/nvi/vi/vs_refresh.c: revision 1.2 dist/nvi/vi/vs_relative.c: revision 1.2 dist/nvi/vi/vs_split.c: revision 1.2 WARNS=4
dist/nvi/cl/cl_bsd.c
dist/nvi/cl/cl_funcs.c
dist/nvi/cl/cl_main.c
dist/nvi/cl/cl_read.c
dist/nvi/cl/cl_screen.c
dist/nvi/cl/cl_term.c
dist/nvi/cl/extern.h
dist/nvi/common/api.c
dist/nvi/common/conv.c
dist/nvi/common/conv.h
dist/nvi/common/cut.c
dist/nvi/common/cut.h
dist/nvi/common/db.c
dist/nvi/common/db1.c
dist/nvi/common/dbinternal.h
dist/nvi/common/exf.c
dist/nvi/common/extern.h
dist/nvi/common/gs.h
dist/nvi/common/key.c
dist/nvi/common/log.c
dist/nvi/common/main.c
dist/nvi/common/mark.c
dist/nvi/common/mem.h
dist/nvi/common/msg.c
dist/nvi/common/options.c
dist/nvi/common/options.h
dist/nvi/common/options_f.c
dist/nvi/common/put.c
dist/nvi/common/recover.c
dist/nvi/common/search.c
dist/nvi/common/seq.c
dist/nvi/common/util.c
dist/nvi/ex/ex.c
dist/nvi/ex/ex.h
dist/nvi/ex/ex_append.c
dist/nvi/ex/ex_args.c
dist/nvi/ex/ex_argv.c
dist/nvi/ex/ex_at.c
dist/nvi/ex/ex_bang.c
dist/nvi/ex/ex_cd.c
dist/nvi/ex/ex_cmd.c
dist/nvi/ex/ex_cscope.c
dist/nvi/ex/ex_display.c
dist/nvi/ex/ex_edit.c
dist/nvi/ex/ex_file.c
dist/nvi/ex/ex_filter.c
dist/nvi/ex/ex_global.c
dist/nvi/ex/ex_init.c
dist/nvi/ex/ex_join.c
dist/nvi/ex/ex_mkexrc.c
dist/nvi/ex/ex_preserve.c
dist/nvi/ex/ex_print.c
dist/nvi/ex/ex_read.c
dist/nvi/ex/ex_script.c
dist/nvi/ex/ex_shell.c
dist/nvi/ex/ex_source.c
dist/nvi/ex/ex_subst.c
dist/nvi/ex/ex_tag.c
dist/nvi/ex/ex_txt.c
dist/nvi/ex/ex_usage.c
dist/nvi/ex/ex_util.c
dist/nvi/ex/ex_visual.c
dist/nvi/ex/ex_write.c
dist/nvi/ex/ex_z.c
dist/nvi/ex/extern.h
dist/nvi/regex/cclass.h
dist/nvi/regex/cname.h
dist/nvi/regex/engine.c
dist/nvi/regex/regcomp.c
dist/nvi/regex/regerror.c
dist/nvi/regex/regexec.c
dist/nvi/vi/extern.h
dist/nvi/vi/getc.c
dist/nvi/vi/v_at.c
dist/nvi/vi/v_cmd.c
dist/nvi/vi/v_event.c
dist/nvi/vi/v_ex.c
dist/nvi/vi/v_increment.c
dist/nvi/vi/v_init.c
dist/nvi/vi/v_mark.c
dist/nvi/vi/v_match.c
dist/nvi/vi/v_paragraph.c
dist/nvi/vi/v_replace.c
dist/nvi/vi/v_scroll.c
dist/nvi/vi/v_search.c
dist/nvi/vi/v_section.c
dist/nvi/vi/v_sentence.c
dist/nvi/vi/v_txt.c
dist/nvi/vi/v_util.c
dist/nvi/vi/v_word.c
dist/nvi/vi/vi.c
dist/nvi/vi/vi.h
dist/nvi/vi/vs_line.c
dist/nvi/vi/vs_msg.c
dist/nvi/vi/vs_refresh.c
dist/nvi/vi/vs_relative.c
dist/nvi/vi/vs_split.c
--- a/dist/nvi/cl/cl_bsd.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/cl/cl_bsd.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cl_bsd.c,v 1.2 2008/05/20 17:52:10 aymeric Exp $ */
+/*	$NetBSD: cl_bsd.c,v 1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1995, 1996
@@ -195,8 +195,8 @@
 #ifndef	HAVE_CURSES_TIGETSTR
 /* Terminfo-to-termcap translation table. */
 typedef struct _tl {
-	char *terminfo;			/* Terminfo name. */
-	char *termcap;			/* Termcap name. */
+	const char *terminfo;		/* Terminfo name. */
+	const char *termcap;		/* Termcap name. */
 } TL;
 static const TL list[] = {
 	{ "cols",	"co", },	/* Terminal columns. */
@@ -270,7 +270,7 @@
 static int
 lcmp(const void *a, const void *b)
 {
-	return (strcmp(a, ((TL *)b)->terminfo));
+	return (strcmp(a, ((const TL *)b)->terminfo));
 }
 
 /*
@@ -288,29 +288,29 @@
  */
 char *
 tigetstr(name)
-	char *name;
+	const char *name;
 {
 	static char sbuf[256];
 	TL *tlp;
 	int n;
-	char *p, keyname[3];
+	char *p, mykeyname[3];
 
 	if ((tlp = bsearch(name,
 	    list, sizeof(list) / sizeof(TL), sizeof(TL), lcmp)) == NULL) {
 #ifdef _AIX
 		if (name[0] == 'k' &&
 		    name[1] == 'f' && (n = atoi(name + 2)) <= 36) {
-			keyname[0] = 'k';
-			keyname[1] = codes[n];
-			keyname[2] = '\0';
+			mykeyname[0] = 'k';
+			mykeyname[1] = codes[n];
+			mykeyname[2] = '\0';
 #else
 		if (name[0] == 'k' &&
 		    name[1] == 'f' && (n = atoi(name + 2)) <= 63) {
-			keyname[0] = n <= 10 ? 'k' : 'F';
-			keyname[1] = codes[n];
-			keyname[2] = '\0';
+			mykeyname[0] = n <= 10 ? 'k' : 'F';
+			mykeyname[1] = codes[n];
+			mykeyname[2] = '\0';
 #endif
-			name = keyname;
+			name = mykeyname;
 		}
 	} else
 		name = tlp->termcap;
@@ -332,7 +332,7 @@
  */
 int
 tigetnum(name)
-	char *name;
+	const char *name;
 {
 	TL *tlp;
 	int val;
--- a/dist/nvi/cl/cl_funcs.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/cl/cl_funcs.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cl_funcs.c,v 1.1.1.2 2008/05/18 14:29:36 aymeric Exp $ */
+/*	$NetBSD: cl_funcs.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -35,7 +35,7 @@
 static void cl_rdiv __P((SCR *));
 
 static int 
-addstr4(SCR *sp, void *str, size_t len, int wide)
+addstr4(SCR *sp, const void *str, size_t len, int wide)
 {
 	CL_PRIVATE *clp;
 	WINDOW *win;
@@ -80,7 +80,7 @@
 int
 cl_waddstr(SCR *sp, const CHAR_T *str, size_t len)
 {
-    return addstr4(sp, (void *)str, len, 1);
+    return addstr4(sp, (const void *)str, len, 1);
 }
 
 /*
@@ -92,7 +92,7 @@
 int
 cl_addstr(SCR *sp, const char *str, size_t len)
 {
-    return addstr4(sp, (void *)str, len, 0);
+    return addstr4(sp, (const void *)str, len, 0);
 }
 
 /*
@@ -257,7 +257,9 @@
 cl_clrtoeol(SCR *sp)
 {
 	WINDOW *win;
+#if 0
 	size_t spcnt, y, x;
+#endif
 
 	win = CLSP(sp) ? CLSP(sp) : stdscr;
 
--- a/dist/nvi/cl/cl_main.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/cl/cl_main.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cl_main.c,v 1.1.1.2 2008/05/18 14:29:37 aymeric Exp $ */
+/*	$NetBSD: cl_main.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -37,12 +37,14 @@
 sigset_t __sigblockset;				/* GLOBAL: Blocked signals. */
 
 static void	   cl_func_std __P((WIN *));
+#ifdef notused
 static void	   cl_end __P((CL_PRIVATE *));
+#endif
 static CL_PRIVATE *cl_init __P((WIN *));
-static void	   perr __P((char *, char *));
+static void	   perr __P((const char *, const char *));
 static int	   setsig __P((int, struct sigaction *, void (*)(int)));
 static void	   sig_end __P((GS *));
-static void	   term_init __P((char *, char *));
+static void	   term_init __P((const char *, const char *));
 
 /*
  * main --
@@ -57,7 +59,8 @@
 	WIN *wp;
 	size_t rows, cols;
 	int rval;
-	char **p_av, **t_av, *ttype;
+	char **p_av, **t_av;
+	const char *ttype;
 
 	/* If loaded at 0 and jumping through a NULL pointer, stop. */
 	if (reenter++)
@@ -212,6 +215,7 @@
 	return (clp);
 }
 
+#ifdef notused
 /*
  * cl_end --
  *	Discard the CL structure.
@@ -223,18 +227,19 @@
 		free(clp->oname);
 	free(clp);
 }
+#endif
 
 /*
  * term_init --
  *	Initialize terminal information.
  */
 static void
-term_init(char *name, char *ttype)
+term_init(const char *name, const char *ttype)
 {
 	int err;
 
 	/* Set up the terminal database information. */
-	setupterm(ttype, STDOUT_FILENO, &err);
+	setupterm(__UNCONST(ttype), STDOUT_FILENO, &err);
 	switch (err) {
 	case -1:
 		(void)fprintf(stderr,
@@ -421,7 +426,7 @@
  *	Print system error.
  */
 static void
-perr(char *name, char *msg)
+perr(const char *name, const char *msg)
 {
 	(void)fprintf(stderr, "%s:", name);
 	if (msg != NULL)
--- a/dist/nvi/cl/cl_read.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/cl/cl_read.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cl_read.c,v 1.1.1.2 2008/05/18 14:29:37 aymeric Exp $ */
+/*	$NetBSD: cl_read.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -56,8 +56,8 @@
 	struct timeval t, *tp;
 	CL_PRIVATE *clp;
 	size_t lines, columns;
-	int changed, nr;
-	CHAR_T *wp;
+	int changed, nr = 0;
+	const CHAR_T *wp;
 	size_t wlen;
 	int rc;
 
@@ -112,7 +112,7 @@
 	case INP_OK:
 		rc = INPUT2INT5(sp, clp->cw, clp->ibuf, nr + clp->skip, 
 				wp, wlen);
-		evp->e_csp = wp;
+		evp->e_csp = __UNCONST(wp);
 		evp->e_len = wlen;
 		evp->e_event = E_STRING;
 		if (rc < 0) {
@@ -154,7 +154,6 @@
 	struct timeval poll;
 	CL_PRIVATE *clp;
 	GS *gp;
-	SCR *tsp;
 	fd_set rdfd;
 	input_t rval;
 	int maxfd, nr, term_reset;
--- a/dist/nvi/cl/cl_screen.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/cl/cl_screen.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cl_screen.c,v 1.1.1.2 2008/05/18 14:29:38 aymeric Exp $ */
+/*	$NetBSD: cl_screen.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -35,7 +35,7 @@
 static void	cl_freecap __P((CL_PRIVATE *));
 static int	cl_vi_end __P((GS *));
 static int	cl_vi_init __P((SCR *));
-static int	cl_putenv __P((SCR *sp, char *, char *, u_long));
+static int	cl_putenv __P((SCR *, const char *, const char *, u_long));
 
 /*
  * cl_screen --
@@ -186,7 +186,8 @@
 {
 	CL_PRIVATE *clp;
 	GS *gp;
-	char *o_cols, *o_lines, *o_term, *ttype;
+	char *o_cols, *o_lines, *o_term;
+	const char *ttype;
 
 	gp = sp->gp;
 	clp = CLP(sp);
@@ -246,7 +247,7 @@
 	 * have to specify the terminal type.
 	 */
 	errno = 0;
-	if (newterm(ttype, stdout, stdin) == NULL) {
+	if (newterm(__UNCONST(ttype), stdout, stdin) == NULL) {
 		if (errno)
 			msgq(sp, M_SYSERR, "%s", ttype);
 		else
@@ -520,7 +521,7 @@
  * PUBLIC: int cl_getcap __P((SCR *, char *, char **));
  */
 int
-cl_getcap(SCR *sp, char *name, char **elementp)
+cl_getcap(SCR *sp, const char *name, char **elementp)
 {
 	size_t len;
 	char *t;
@@ -567,7 +568,7 @@
  *	Put a value into the environment.
  */
 static int
-cl_putenv(SCR *sp, char *name, char *str, u_long value)
+cl_putenv(SCR *sp, const char *name, const char *str, u_long value)
 {
 	char buf[40];
 
--- a/dist/nvi/cl/cl_term.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/cl/cl_term.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cl_term.c,v 1.1.1.2 2008/05/18 14:29:38 aymeric Exp $ */
+/*	$NetBSD: cl_term.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -40,40 +40,43 @@
  * THIS REQUIRES THAT ALL SCREENS SHARE A TERMINAL TYPE.
  */
 typedef struct _tklist {
-	char	*ts;			/* Key's termcap string. */
-	char	*output;		/* Corresponding vi command. */
-	char	*name;			/* Name. */
+	const char	*ts;		/* Key's termcap string. */
+	const char	*output;	/* Corresponding vi command. */
+	const char	*name;		/* Name. */
 	u_char	 value;			/* Special value (for lookup). */
 } TKLIST;
+
+#define TKINIT(a, b, c) { a, b, c, 0 }
+
 static TKLIST const c_tklist[] = {	/* Command mappings. */
-	{"kil1",	"O",	"insert line"},
-	{"kdch1",	"x",	"delete character"},
-	{"kcud1",	"j",	"cursor down"},
-	{"kel",		"D",	"delete to eol"},
-	{"kind",     "\004",	"scroll down"},			/* ^D */
-	{"kll",		"$",	"go to eol"},
-	{"kend",	"$",	"go to eol"},
-	{"khome",	"^",	"go to sol"},
-	{"kich1",	"i",	"insert at cursor"},
-	{"kdl1",       "dd",	"delete line"},
-	{"kcub1",	"h",	"cursor left"},
-	{"knp",	     "\006",	"page down"},			/* ^F */
-	{"kpp",	     "\002",	"page up"},			/* ^B */
-	{"kri",	     "\025",	"scroll up"},			/* ^U */
-	{"ked",	       "dG",	"delete to end of screen"},
-	{"kcuf1",	"l",	"cursor right"},
-	{"kcuu1",	"k",	"cursor up"},
-	{NULL},
+	TKINIT("kil1",	"O",	"insert line"),
+	TKINIT("kdch1",	"x",	"delete character"),
+	TKINIT("kcud1",	"j",	"cursor down"),
+	TKINIT("kel",	"D",	"delete to eol"),
+	TKINIT("kind",  "\004",	"scroll down"),			/* ^D */
+	TKINIT("kll",	"$",	"go to eol"),
+	TKINIT("kend",	"$",	"go to eol"),
+	TKINIT("khome",	"^",	"go to sol"),
+	TKINIT("kich1",	"i",	"insert at cursor"),
+	TKINIT("kdl1",  "dd",	"delete line"),
+	TKINIT("kcub1",	"h",	"cursor left"),
+	TKINIT("knp",	"\006",	"page down"),			/* ^F */
+	TKINIT("kpp",	"\002",	"page up"),			/* ^B */
+	TKINIT("kri",	"\025",	"scroll up"),			/* ^U */
+	TKINIT("ked",	"dG",	"delete to end of screen"),
+	TKINIT("kcuf1",	"l",	"cursor right"),
+	TKINIT("kcuu1",	"k",	"cursor up"),
+	TKINIT(NULL, NULL, NULL),
 };
 static TKLIST const m1_tklist[] = {	/* Input mappings (lookup). */
-	{NULL},
+	TKINIT(NULL, NULL, NULL),
 };
 static TKLIST const m2_tklist[] = {	/* Input mappings (set or delete). */
-	{"kcud1",  "\033ja",	"cursor down"},			/* ^[ja */
-	{"kcub1",  "\033ha",	"cursor left"},			/* ^[ha */
-	{"kcuu1",  "\033ka",	"cursor up"},			/* ^[ka */
-	{"kcuf1",  "\033la",	"cursor right"},		/* ^[la */
-	{NULL},
+	TKINIT("kcud1",  "\033ja",	"cursor down"),		/* ^[ja */
+	TKINIT("kcub1",  "\033ha",	"cursor left"),		/* ^[ha */
+	TKINIT("kcuu1",  "\033ka",	"cursor up"),		/* ^[ka */
+	TKINIT("kcuf1",  "\033la",	"cursor right"),	/* ^[la */
+	TKINIT(NULL, NULL, NULL),
 };
 
 /*
@@ -92,7 +95,7 @@
 	CHAR_T name[60];
 	CHAR_T output[5];
 	CHAR_T ts[20];
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/* Command mappings. */
@@ -224,9 +227,9 @@
 	size_t nlen;
 	char *p;
 	char name[64];
-	CHAR_T keyname[64];
+	CHAR_T mykeyname[64];
 	CHAR_T ts[20];
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	(void)snprintf(name, sizeof(name), "kf%d", 
@@ -239,12 +242,12 @@
 		return (1);
 	}
 
-	nlen = SPRINTF(keyname,
-	    SIZE(keyname), L("function key %d"), 
+	nlen = SPRINTF(mykeyname,
+	    SIZE(mykeyname), L("function key %d"), 
 			(int)STRTOL(from+1,NULL,10));
 	CHAR2INT(sp, p, strlen(p), wp, wlen);
 	MEMCPYW(ts, wp, wlen);
-	return (seq_set(sp, keyname, nlen,
+	return (seq_set(sp, mykeyname, nlen,
 	    ts, strlen(p), to, tlen, stype, SEQ_NOOVERWRITE | SEQ_SCREEN));
 }
 
@@ -252,10 +255,10 @@
  * cl_optchange --
  *	Curses screen specific "option changed" routine.
  *
- * PUBLIC: int cl_optchange __P((SCR *, int, char *, u_long *));
+ * PUBLIC: int cl_optchange __P((SCR *, int, const char *, u_long *));
  */
 int
-cl_optchange(SCR *sp, int opt, char *str, u_long *valp)
+cl_optchange(SCR *sp, int opt, const char *str, u_long *valp)
 {
 	CL_PRIVATE *clp;
 
@@ -424,16 +427,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. */
--- a/dist/nvi/cl/extern.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/cl/extern.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.1.1.1 2008/05/18 14:29:38 aymeric Exp $ */
+/*	$NetBSD: extern.h,v 1.1.1.1.8.1 2009/01/20 02:41:11 snj Exp $ */
 
 /* Do not edit: automatically built by build/distrib. */
 #ifndef HAVE_CURSES_WADDNSTR
@@ -25,10 +25,10 @@
 #ifdef HAVE_CURSES_TIGETSTR
 char *tigetstr();
 #else
-char *tigetstr __P((char *));
+char *tigetstr __P((const char *));
 #endif
 #ifndef HAVE_CURSES_TIGETSTR
-int tigetnum __P((char *));
+int tigetnum __P((const char *));
 #endif
 int cl_waddstr __P((SCR *, const CHAR_T *, size_t));
 int cl_addstr __P((SCR *, const char *, size_t));
@@ -53,11 +53,11 @@
 int cl_event __P((SCR *, EVENT *, u_int32_t, int));
 int cl_screen __P((SCR *, u_int32_t));
 int cl_quit __P((GS *));
-int cl_getcap __P((SCR *, char *, char **));
+int cl_getcap __P((SCR *, const char *, char **));
 int cl_term_init __P((SCR *));
 int cl_term_end __P((GS *));
 int cl_fmap __P((SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t));
-int cl_optchange __P((SCR *, int, char *, u_long *));
+int cl_optchange __P((SCR *, int, const char *, u_long *));
 int cl_omesg __P((SCR *, CL_PRIVATE *, int));
 int cl_ssize __P((SCR *, int, size_t *, size_t *, int *));
 int cl_putchar __P((int));
--- a/dist/nvi/common/api.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/api.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: api.c,v 1.1.1.2 2008/05/18 14:29:40 aymeric Exp $ */
+/*	$NetBSD: api.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -82,7 +82,7 @@
 api_aline(SCR *sp, db_recno_t lno, char *line, size_t len)
 {
 	size_t wblen;
-	CHAR_T *wbp;
+	const CHAR_T *wbp;
 
 	CHAR2INT(sp, line, len, wbp, wblen);
 
@@ -257,7 +257,7 @@
 
 	if (db_get(sp, mp->lno, DBG_FATAL, NULL, &len))
 		return (1);
-	if (mp->cno < 0 || mp->cno > len) {
+	if (mp->cno > len) {
 		msgq(sp, M_ERR, "Cursor set to nonexistent column");
 		return (1);
 	}
@@ -304,7 +304,7 @@
 {
 	EXCMD cmd;
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 
 	if (file) {
 		ex_cinit(sp, &cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0);
@@ -371,7 +371,7 @@
 {
 	EXCMD cmd;
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 
 	ex_cinit(sp, &cmd, C_MAP, 0, OOBLNO, OOBLNO, 0);
 	CHAR2INT(sp, name, strlen(name) + 1, wp, wlen);
@@ -392,7 +392,7 @@
 {
 	EXCMD cmd;
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 
 	ex_cinit(sp, &cmd, C_UNMAP, 0, OOBLNO, OOBLNO, 0);
 	CHAR2INT(sp, name, strlen(name) + 1, wp, wlen);
@@ -409,7 +409,7 @@
  * PUBLIC: int api_opts_get __P((SCR *, CHAR_T *, char **, int *));
  */
 int
-api_opts_get(SCR *sp, CHAR_T *name, char **value, int *boolvalue)
+api_opts_get(SCR *sp, const CHAR_T *name, char **value, int *boolvalue)
 {
 	OPTLIST const *op;
 	int offset;
@@ -456,8 +456,8 @@
  * PUBLIC: int api_opts_set __P((SCR *, CHAR_T *, char *, u_long, int));
  */
 int
-api_opts_set(SCR *sp, CHAR_T *name, 
-	     char *str_value, u_long num_value, int bool_value)
+api_opts_set(SCR *sp, const CHAR_T *name, 
+	     const char *str_value, u_long num_value, int bool_value)
 {
 	ARGS *ap[2], a, b;
 	OPTLIST const *op;
@@ -511,7 +511,7 @@
 api_run_str(SCR *sp, char *cmd)
 {
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 
 	CHAR2INT(sp, cmd, strlen(cmd)+1, wp, wlen);
 	return (ex_run_str(sp, NULL, wp, wlen - 1, 0, 0));
@@ -546,7 +546,7 @@
 api_tagq_add(SCR *sp, TAGQ *tqp, char *filename, char *search, char *msg)
 {
 	TAG *tp;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 	size_t flen = strlen(filename);
 	size_t slen = strlen(search);
--- a/dist/nvi/common/conv.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/conv.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: conv.c,v 1.3 2008/05/21 16:02:30 aymeric Exp $ */
+/*	$NetBSD: conv.c,v 1.3.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -43,12 +43,12 @@
 #include <locale.h>
 
 #ifdef USE_WIDECHAR
-int 
+static int 
 raw2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, size_t *tolen,
-	CHAR_T **dst)
+	const CHAR_T **dst)
 {
     int i;
-    CHAR_T **tostr = (CHAR_T **)&cw->bp1;
+    CHAR_T **tostr = (CHAR_T **)(void *)&cw->bp1;
     size_t  *blen = &cw->blen1;
 
     BINC_RETW(NULL, *tostr, *blen, len);
@@ -87,17 +87,17 @@
 #define CONVERT(str, left, src, len)
 #endif
 
-int 
+static int 
 default_char2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, 
-		size_t *tolen, CHAR_T **dst, char *enc)
+		size_t *tolen, const CHAR_T **dst, const char *enc)
 {
     int i = 0, j;
-    CHAR_T **tostr = (CHAR_T **)&cw->bp1;
+    CHAR_T **tostr = (CHAR_T **)(void *)&cw->bp1;
     size_t  *blen = &cw->blen1;
     mbstate_t mbs;
     size_t   n;
     ssize_t  nlen = len;
-    char *src = (char *)str;
+    const char *src = (const char *)str;
     iconv_t	id = (iconv_t)-1;
     char	buffer[CONV_BUFFER_SIZE];
     size_t	left = len;
@@ -148,53 +148,53 @@
     return error;
 }
 
-int 
+static int 
 fe_char2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, 
-	    size_t *tolen, CHAR_T **dst)
+	    size_t *tolen, const CHAR_T **dst)
 {
     return default_char2int(sp, str, len, cw, tolen, dst, O_STR(sp, O_FILEENCODING));
 }
 
-int 
+static int 
 ie_char2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, 
-	    size_t *tolen, CHAR_T **dst)
+	    size_t *tolen, const CHAR_T **dst)
 {
     return default_char2int(sp, str, len, cw, tolen, dst, O_STR(sp, O_INPUTENCODING));
 }
 
-int 
+static int 
 cs_char2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, 
-	    size_t *tolen, CHAR_T **dst)
+	    size_t *tolen, const CHAR_T **dst)
 {
     return default_char2int(sp, str, len, cw, tolen, dst, LANGCODESET);
 }
 
-int 
+static int 
 CHAR_T_int2char(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, 
-	size_t *tolen, char **dst)
+	size_t *tolen, const char **dst)
 {
     *tolen = len * sizeof(CHAR_T);
-    *dst = (char*) str;
+    *dst = (const char *)(const void *)str;
 
     return 0;
 }
 
-int 
+static int 
 CHAR_T_char2int(SCR *sp, const char * str, ssize_t len, CONVWIN *cw, 
-	size_t *tolen, CHAR_T **dst)
+	size_t *tolen, const CHAR_T **dst)
 {
     *tolen = len / sizeof(CHAR_T);
-    *dst = (CHAR_T*) str;
+    *dst = (const CHAR_T*) str;
 
     return 0;
 }
 
-int 
+static int 
 int2raw(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, size_t *tolen,
-	char **dst)
+	const char **dst)
 {
     int i;
-    char **tostr = (char **)&cw->bp1;
+    char **tostr = (char **)(void *)&cw->bp1;
     size_t  *blen = &cw->blen1;
 
     BINC_RETC(NULL, *tostr, *blen, len);
@@ -208,12 +208,12 @@
     return 0;
 }
 
-int 
+static int 
 default_int2char(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, 
-		size_t *tolen, char **pdst, char *enc)
+		size_t *tolen, const char **pdst, const char *enc)
 {
     int i, j, offset = 0;
-    char **tostr = (char **)&cw->bp1;
+    char **tostr = (char **)(void *)&cw->bp1;
     size_t  *blen = &cw->blen1;
     mbstate_t mbs;
     size_t n;
@@ -299,16 +299,16 @@
     return 1;
 }
 
-int 
+static int 
 fe_int2char(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, 
-	    size_t *tolen, char **dst)
+	    size_t *tolen, const char **dst)
 {
     return default_int2char(sp, str, len, cw, tolen, dst, O_STR(sp, O_FILEENCODING));
 }
 
-int 
+static int 
 cs_int2char(SCR *sp, const CHAR_T * str, ssize_t len, CONVWIN *cw, 
-	    size_t *tolen, char **dst)
+	    size_t *tolen, const char **dst)
 {
     return default_int2char(sp, str, len, cw, tolen, dst, LANGCODESET);
 }
@@ -338,7 +338,7 @@
 }
 
 int
-conv_enc (SCR *sp, int option, char *enc)
+conv_enc (SCR *sp, int option, const char *enc)
 {
 #if defined(USE_WIDECHAR) && defined(USE_ICONV)
     iconv_t id;
@@ -354,6 +354,10 @@
 	c2w = &sp->conv.input2int;
 	w2c = NULL;
 	break;
+    default:
+	c2w = NULL;
+	w2c = NULL;
+	break;
     }
 
     if (!*enc) {
--- a/dist/nvi/common/conv.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/conv.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: conv.h,v 1.1.1.2 2008/05/18 14:29:40 aymeric Exp $ */
+/*	$NetBSD: conv.h,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 #define KEY_COL(sp, ch)							\
 	(INTISWIDE(ch) ? CHAR_WIDTH(sp, ch) ? CHAR_WIDTH(sp, ch) : 	\
@@ -11,9 +11,9 @@
 };
 
 typedef int (*char2wchar_t) 
-    (SCR *, const char *, ssize_t, struct _conv_win *, size_t *, CHAR_T **);
+    (SCR *, const char *, ssize_t, struct _conv_win *, size_t *, const CHAR_T **);
 typedef int (*wchar2char_t) 
-    (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *, char **);
+    (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *, const char **);
 
 struct _conv {
 	char2wchar_t	sys2int;
@@ -23,3 +23,5 @@
 	char2wchar_t	input2int;
 	wchar2char_t	int2disp;
 };
+void conv_init __P((SCR *, SCR *));
+int conv_enc __P((SCR *, int, const char *));
--- a/dist/nvi/common/cut.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/cut.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cut.c,v 1.1.1.2 2008/05/18 14:29:40 aymeric Exp $ */
+/*	$NetBSD: cut.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -69,7 +69,7 @@
 cut(SCR *sp, CHAR_T *namep, MARK *fm, MARK *tm, int flags)
 {
 	CB *cbp;
-	CHAR_T name;
+	CHAR_T name = '\0';
 	db_recno_t lno;
 	int append, copy_one, copy_def;
 
@@ -98,8 +98,8 @@
 	append = copy_one = copy_def = 0;
 	if (namep != NULL) {
 		name = *namep;
-		if (LF_ISSET(CUT_NUMREQ) || LF_ISSET(CUT_NUMOPT) &&
-		    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno)) {
+		if (LF_ISSET(CUT_NUMREQ) || (LF_ISSET(CUT_NUMOPT) &&
+		    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno))) {
 			copy_one = 1;
 			cb_rotate(sp);
 		}
@@ -109,8 +109,8 @@
 			name = tolower(name);
 		}
 namecb:		CBNAME(sp, cbp, name);
-	} else if (LF_ISSET(CUT_NUMREQ) || LF_ISSET(CUT_NUMOPT) &&
-	    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno)) {
+	} else if (LF_ISSET(CUT_NUMREQ) || (LF_ISSET(CUT_NUMOPT) &&
+	    (LF_ISSET(CUT_LINEMODE) || fm->lno != tm->lno))) {
 		name = '1';
 		cb_rotate(sp);
 		goto namecb;
--- a/dist/nvi/common/cut.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/cut.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cut.h,v 1.1.1.2 2008/05/18 14:29:40 aymeric Exp $ */
+/*	$NetBSD: cut.h,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -67,7 +67,8 @@
  */
 #define	CBNAME(sp, cbp, nch) {						\
 	CHAR_T L__name;							\
-	L__name = isupper(nch) ? tolower(nch) : (nch);			\
+	L__name = isupper((unsigned char)nch) ? 			\
+	    tolower((unsigned char)nch) : (nch);			\
 	for (cbp = sp->wp->cutq.lh_first;				\
 	    cbp != NULL; cbp = cbp->q.le_next)				\
 		if (cbp->name == L__name)				\
--- a/dist/nvi/common/db.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/db.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: db.c,v 1.1.1.2 2008/05/18 14:29:40 aymeric Exp $ */
+/*	$NetBSD: db.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -24,11 +24,12 @@
 #include <limits.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include "common.h"
 #include "../vi/vi.h"
 
-static int append __P((SCR*, db_recno_t, CHAR_T*, size_t, lnop_t, int));
+static int append __P((SCR*, db_recno_t, const CHAR_T*, size_t, lnop_t, int));
 
 /*
  * db_eget --
@@ -88,7 +89,7 @@
 	EXF *ep;
 	TEXT *tp;
 	db_recno_t l1, l2;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 	size_t nlen;
 
@@ -276,12 +277,12 @@
  *				line
  */
 static int
-append(SCR *sp, db_recno_t lno, CHAR_T *p, size_t len, lnop_t op, int update)
+append(SCR *sp, db_recno_t lno, const CHAR_T *p, size_t len, lnop_t op, int update)
 {
 	DBT data, key;
 	DBC *dbcp_put;
 	EXF *ep;
-	char *fp;
+	const char *fp;
 	size_t flen;
 	int rval;
 
@@ -313,7 +314,7 @@
 	    if ((sp->db_error = dbcp_put->c_get(dbcp_put, &key, &data, DB_SET)) != 0) 
 		goto err2;
 
-	    data.data = fp;
+	    data.data = __UNCONST(fp);
 	    data.size = flen;
 	    if ((sp->db_error = dbcp_put->c_put(dbcp_put, &key, &data, DB_AFTER)) != 0) {
 err2:
@@ -330,7 +331,7 @@
 		if (sp->db_error != DB_NOTFOUND)
 		    goto err2;
 
-		data.data = fp;
+		data.data = __UNCONST(fp);
 		data.size = flen;
 		if ((sp->db_error = ep->db->put(ep->db, NULL, &key, &data, DB_APPEND)) != 0) {
 		    goto err2;
@@ -338,7 +339,7 @@
 	    } else {
 		key.data = &lno;
 		key.size = sizeof(lno);
-		data.data = fp;
+		data.data = __UNCONST(fp);
 		data.size = flen;
 		if ((sp->db_error = dbcp_put->c_put(dbcp_put, &key, &data, DB_BEFORE)) != 0) {
 		    goto err2;
@@ -383,7 +384,7 @@
  * PUBLIC: int db_append __P((SCR *, int, db_recno_t, CHAR_T *, size_t));
  */
 int
-db_append(SCR *sp, int update, db_recno_t lno, CHAR_T *p, size_t len)
+db_append(SCR *sp, int update, db_recno_t lno, const CHAR_T *p, size_t len)
 {
 #if defined(DEBUG) && 0
 	vtrace(sp, "append to %lu: len %u {%.*s}\n", lno, len, MIN(len, 20), p);
@@ -420,7 +421,7 @@
 {
 	DBT data, key;
 	EXF *ep;
-	char *fp;
+	const char *fp;
 	size_t flen;
 
 #if defined(DEBUG) && 0
@@ -447,7 +448,7 @@
 	key.data = &lno;
 	key.size = sizeof(lno);
 	memset(&data, 0, sizeof(data));
-	data.data = fp;
+	data.data = __UNCONST(fp);
 	data.size = flen;
 	if ((sp->db_error = ep->db->put(ep->db, NULL, &key, &data, 0)) != 0) {
 		msgq(sp, M_DBERR, "006|unable to store line %lu", (u_long)lno);
@@ -515,7 +516,7 @@
 	DBC *dbcp;
 	EXF *ep;
 	db_recno_t lno;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/* Check for no underlying file. */
@@ -652,6 +653,8 @@
 			if (lno == scrp->c_lno)
 				scrp->c_lno = OOBLNO;
 			break;
+		case LINE_APPEND:
+			abort();
 		}
 
 	if (ep->c_nlines != OOBLNO)
@@ -662,6 +665,9 @@
 		case LINE_DELETE:
 			--ep->c_nlines;
 			break;
+		case LINE_APPEND:
+		case LINE_RESET:
+			abort();
 		}
 }
 
--- a/dist/nvi/common/db1.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/db1.c	Tue Jan 20 02:41:11 2009 +0000
@@ -12,6 +12,7 @@
 #include <fcntl.h>
 
 #include "../common/db.h"
+#include "../common/dbinternal.h"
 
 /*
  * DB_ENV emulation
@@ -118,7 +119,7 @@
 	return 0;
 }
 
-char *
+const char *
 db_strerror(int error) {
 	return error > 0? strerror(error) : "record not found";
 }
@@ -154,11 +155,11 @@
 		oldflags |= O_TRUNC;
 
 	if (type == DB_RECNO) {
-		char *tmp = (char *) file;
+		const char *tmp = file;
 
 		/* The interface is reversed in DB3 */
 		file = db->_recno_info.bfname;
-		db->_recno_info.bfname = tmp;
+		db->_recno_info.bfname = __UNCONST(tmp);
 
 		/* ... and so, we should avoid to truncate the main file! */
 		oldflags &= ~O_TRUNC;
@@ -219,13 +220,14 @@
 	key1 = *key;
 
 	if (flags & DB_APPEND) {
-		if (db_v1->seq(db_v1,
-			    (DBT_v1 *) key, (DBT_v1 *) &data1, R_LAST) == 1) {
+		if (db_v1->seq(db_v1, (DBT_v1 *)(void *)key,
+		    (DBT_v1 *)(void *)&data1, R_LAST) == 1) {
 			key1.data = &recno;
 			key1.size = sizeof recno;
 		}
 	}
-	err = db_v1->put(db_v1, (DBT_v1 *) &key1, (DBT_v1 *) data, 0);
+	err = db_v1->put(db_v1, (DBT_v1 *)(void *)&key1, (DBT_v1 *)(void *)data,
+	    0);
 
 	return err == -1? errno : err;
 }
@@ -270,7 +272,7 @@
 
 static int
 db1_db_set_re_source(DB *db, const char *re_source) {
-	db->_recno_info.bfname = (char *) re_source;
+	db->_recno_info.bfname = __UNCONST(re_source);
 
 	return 0;
 }
@@ -306,6 +308,7 @@
 static int
 db1_dbc_close(DBC *cursor) {
 	free(cursor);
+	return 0;
 }
 
 static int
@@ -346,7 +349,6 @@
 db1_dbc_put(DBC *cursor, DBT *key, DBT *data, u_int32_t flags) {
 	DB *db = cursor->db;
 	DB_old *db_v1 = db->actual_db;
-	DBT data1;
 	int ret = 0;
 
 	assert((flags & ~(DB_BEFORE | DB_AFTER)) == 0);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dist/nvi/common/dbinternal.h	Tue Jan 20 02:41:11 2009 +0000
@@ -0,0 +1,3 @@
+int db_env_create(DB_ENV **, u_int32_t);
+int db_create(DB **, DB_ENV *, u_int32_t);
+const char *db_strerror(int);
--- a/dist/nvi/common/exf.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/exf.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: exf.c,v 1.1.1.2 2008/05/18 14:29:45 aymeric Exp $ */
+/*	$NetBSD: exf.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -39,8 +39,9 @@
 #include <time.h>
 
 #include "common.h"
+#include "dbinternal.h"
 
-static int	file_backup __P((SCR *, char *, char *));
+static int	file_backup __P((SCR *, const char *, const char *));
 static void	file_cinit __P((SCR *));
 static void	file_comment __P((SCR *));
 static int	file_spath __P((SCR *, FREF *, struct stat *, int *));
@@ -62,7 +63,7 @@
  * PUBLIC: FREF *file_add __P((SCR *, char *));
  */
 FREF *
-file_add(SCR *sp, char *name)
+file_add(SCR *sp, const char *name)
 {
 	GS *gp;
 	FREF *frp, *tfrp;
@@ -79,7 +80,7 @@
 	gp = sp->gp;
 	if (name != NULL)
 		for (frp = gp->frefq.cqh_first;
-		    frp != (FREF *)&gp->frefq; frp = frp->q.cqe_next) {
+		    frp != (FREF *)(void *)&gp->frefq; frp = frp->q.cqe_next) {
 			if (frp->name == NULL) {
 				tfrp = frp->q.cqe_next;
 				CIRCLEQ_REMOVE(&gp->frefq, frp, q);
@@ -131,7 +132,7 @@
 	struct stat sb;
 	size_t psize;
 	int fd, exists, open_err, readonly, stolen;
-	char *oname, tname[MAXPATHLEN];
+	char *oname = NULL, tname[MAXPATHLEN];
 
 	stolen = open_err = readonly = 0;
 
@@ -521,10 +522,10 @@
 static int
 file_spath(SCR *sp, FREF *frp, struct stat *sbp, int *existsp)
 {
-	CHAR_T savech;
 	size_t len;
 	int found;
-	char *name, *p, *t, path[MAXPATHLEN];
+	char *name, path[MAXPATHLEN];
+	const char *p, *t;
 
 	/*
 	 * If the name is NULL or an explicit reference (i.e., the first
@@ -551,11 +552,8 @@
 	for (found = 0, p = t = O_STR(sp, O_PATH);; ++p)
 		if (*p == ':' || *p == '\0') {
 			if (t < p - 1) {
-				savech = *p;
-				*p = '\0';
-				len = snprintf(path,
-				    sizeof(path), "%s/%s", t, name);
-				*p = savech;
+				len = snprintf(path, sizeof(path), "%.*s/%s",
+				    (int)(p - t), t, name);
 				if (!stat(path, sbp)) {
 					found = 1;
 					break;
@@ -568,10 +566,11 @@
 
 	/* If we found it, build a new pathname and discard the old one. */
 	if (found) {
-		MALLOC_RET(sp, p, char *, len + 1);
-		memcpy(p, path, len + 1);
+		char *q;
+		MALLOC_RET(sp, q, char *, len + 1);
+		memcpy(q, path, len + 1);
 		free(frp->name);
-		frp->name = p;
+		frp->name = q;
 	}
 	*existsp = found;
 	return (0);
@@ -588,7 +587,7 @@
 	MARK m;
 	size_t len;
 	int nb;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/* Set some basic defaults. */
@@ -1084,7 +1083,7 @@
  * recreate the file.  So, let's not risk it.
  */
 static int
-file_backup(SCR *sp, char *name, char *bname)
+file_backup(SCR *sp, const char *name, const char *bname)
 {
 	struct dirent *dp;
 	struct stat sb;
@@ -1093,14 +1092,16 @@
 	off_t off;
 	size_t blen;
 	int flags, maxnum, nr, num, nw, rfd, wfd, version;
-	char *bp, *estr, *p, *pct, *slash, *t, *wfname, buf[8192];
-	CHAR_T *wp;
+	char *bp, *pct, *slash, *t, buf[8192];
+	const char *p, *estr, *wfname;
+	const CHAR_T *wp;
 	size_t wlen;
 	size_t nlen;
 	char *d = NULL;
 
 	rfd = wfd = -1;
-	bp = estr = wfname = NULL;
+	estr = wfname = NULL;
+	bp = NULL;
 
 	/*
 	 * Open the current file for reading.  Do this first, so that
@@ -1478,7 +1479,7 @@
  * PUBLIC: void set_alt_name __P((SCR *, char *));
  */
 void
-set_alt_name(SCR *sp, char *name)
+set_alt_name(SCR *sp, const char *name)
 {
 	if (sp->alt_name != NULL)
 		free(sp->alt_name);
--- a/dist/nvi/common/extern.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/extern.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.1.1.1 2008/05/18 14:29:54 aymeric Exp $ */
+/*	$NetBSD: extern.h,v 1.1.1.1.8.1 2009/01/20 02:41:11 snj Exp $ */
 
 /* Do not edit: automatically built by build/distrib. */
 SCR *api_fscreen __P((int, char *));
@@ -21,8 +21,8 @@
 int api_swscreen __P((SCR *, SCR *));
 int api_map __P((SCR *, char *, char *, size_t));
 int api_unmap __P((SCR *, char *));
-int api_opts_get __P((SCR *, CHAR_T *, char **, int *));
-int api_opts_set __P((SCR *, CHAR_T *, char *, u_long, int));
+int api_opts_get __P((SCR *, const CHAR_T *, char **, int *));
+int api_opts_set __P((SCR *, const CHAR_T *, const char *, u_long, int));
 int api_run_str __P((SCR *, char *));
 TAGQ * api_tagq_new __P((SCR*, char*));
 void api_tagq_add __P((SCR*, TAGQ*, char*, char *, char *));
@@ -37,7 +37,7 @@
 int db_eget __P((SCR *, db_recno_t, CHAR_T **, size_t *, int *));
 int db_get __P((SCR *, db_recno_t, u_int32_t, CHAR_T **, size_t *));
 int db_delete __P((SCR *, db_recno_t));
-int db_append __P((SCR *, int, db_recno_t, CHAR_T *, size_t));
+int db_append __P((SCR *, int, db_recno_t, const CHAR_T *, size_t));
 int db_insert __P((SCR *, db_recno_t, CHAR_T *, size_t));
 int db_set __P((SCR *, db_recno_t, CHAR_T *, size_t));
 int db_exist __P((SCR *, db_recno_t));
@@ -47,17 +47,8 @@
 			lnop_t op, int current));
 void update_cache __P((SCR *sp, lnop_t op, db_recno_t lno));
 int line_insdel __P((SCR *sp, lnop_t op, db_recno_t lno));
-int db_eget __P((SCR *, db_recno_t, CHAR_T **, size_t *, int *));
-int db_get __P((SCR *, db_recno_t, u_int32_t, CHAR_T **, size_t *));
-int db_delete __P((SCR *, db_recno_t));
-int db_append __P((SCR *, int, db_recno_t, CHAR_T *, size_t));
-int db_insert __P((SCR *, db_recno_t, CHAR_T *, size_t));
-int db_set __P((SCR *, db_recno_t, CHAR_T *, size_t));
-int db_exist __P((SCR *, db_recno_t));
-int db_last __P((SCR *, db_recno_t *));
-void db_err __P((SCR *, db_recno_t));
 int del __P((SCR *, MARK *, MARK *, int));
-FREF *file_add __P((SCR *, char *));
+FREF *file_add __P((SCR *, const char *));
 int file_init __P((SCR *, FREF *, char *, int));
 int file_end __P((SCR *, EXF *, int));
 int file_write __P((SCR *, MARK *, MARK *, char *, int));
@@ -65,7 +56,7 @@
 int file_m2 __P((SCR *, int));
 int file_m3 __P((SCR *, int));
 int file_aw __P((SCR *, int));
-void set_alt_name __P((SCR *, char *));
+void set_alt_name __P((SCR *, const char *));
 lockr_t file_lock __P((SCR *, char *, int *, int, int));
 GS * gs_init __P((char*));
 WIN * gs_new_win __P((GS *gp));
@@ -76,7 +67,7 @@
 size_t v_key_len __P((SCR *, ARG_CHAR_T));
 u_char *v_key_name __P((SCR *, ARG_CHAR_T));
 int v_key_val __P((SCR *, ARG_CHAR_T));
-int v_event_push __P((SCR *, EVENT *, CHAR_T *, size_t, u_int));
+int v_event_push __P((SCR *, EVENT *, const CHAR_T *, size_t, u_int));
 int v_event_get __P((SCR *, EVENT *, int, u_int32_t));
 void v_event_err __P((SCR *, EVENT *));
 int v_event_flush __P((SCR *, u_int));
@@ -103,43 +94,43 @@
 int mark_set __P((SCR *, ARG_CHAR_T, MARK *, int));
 int mark_insdel __P((SCR *, lnop_t, db_recno_t));
 void msgq __P((SCR *, mtype_t, const char *, ...));
-void msgq_wstr __P((SCR *, mtype_t, CHAR_T *, char *));
-void msgq_str __P((SCR *, mtype_t, char *, char *));
+void msgq_wstr __P((SCR *, mtype_t, const CHAR_T *, const char *));
+void msgq_str __P((SCR *, mtype_t, const char *, const char *));
 void mod_rpt __P((SCR *));
 void msgq_status __P((SCR *, db_recno_t, u_int));
-int msg_open __P((SCR *, char *));
+int msg_open __P((SCR *, const char *));
 void msg_close __P((GS *));
 const char *msg_cmsg __P((SCR *, cmsg_t, size_t *));
 const char *msg_cat __P((SCR *, const char *, size_t *));
 char *msg_print __P((SCR *, const char *, int *));
 void thread_init __P((GS *gp));
 int opts_init __P((SCR *, int *));
-int opts_set __P((SCR *, ARGS *[], char *));
-int o_set __P((SCR *, int, u_int, char *, u_long));
+int opts_set __P((SCR *, ARGS *[], const char *));
+int o_set __P((SCR *, int, u_int, const char *, u_long));
 int opts_empty __P((SCR *, int, int));
 void opts_dump __P((SCR *, enum optdisp));
 int opts_save __P((SCR *, FILE *));
-OPTLIST const *opts_search __P((CHAR_T *));
-void opts_nomatch __P((SCR *, CHAR_T *));
+OPTLIST const *opts_search __P((const CHAR_T *));
+void opts_nomatch __P((SCR *, const CHAR_T *));
 int opts_copy __P((SCR *, SCR *));
 void opts_free __P((SCR *));
-int f_altwerase __P((SCR *, OPTION *, char *, u_long *));
-int f_columns __P((SCR *, OPTION *, char *, u_long *));
-int f_lines __P((SCR *, OPTION *, char *, u_long *));
-int f_lisp __P((SCR *, OPTION *, char *, u_long *));
-int f_msgcat __P((SCR *, OPTION *, char *, u_long *));
-int f_paragraph __P((SCR *, OPTION *, char *, u_long *));
-int f_print __P((SCR *, OPTION *, char *, u_long *));
-int f_readonly __P((SCR *, OPTION *, char *, u_long *));
-int f_recompile __P((SCR *, OPTION *, char *, u_long *));
-int f_reformat __P((SCR *, OPTION *, char *, u_long *));
-int f_section __P((SCR *, OPTION *, char *, u_long *));
-int f_ttywerase __P((SCR *, OPTION *, char *, u_long *));
-int f_w300 __P((SCR *, OPTION *, char *, u_long *));
-int f_w1200 __P((SCR *, OPTION *, char *, u_long *));
-int f_w9600 __P((SCR *, OPTION *, char *, u_long *));
-int f_window __P((SCR *, OPTION *, char *, u_long *));
-int f_encoding __P((SCR *, OPTION *, char *, u_long *));
+int f_altwerase __P((SCR *, OPTION *, const char *, u_long *));
+int f_columns __P((SCR *, OPTION *, const char *, u_long *));
+int f_lines __P((SCR *, OPTION *, const char *, u_long *));
+int f_lisp __P((SCR *, OPTION *, const char *, u_long *));
+int f_msgcat __P((SCR *, OPTION *, const char *, u_long *));
+int f_paragraph __P((SCR *, OPTION *, const char *, u_long *));
+int f_print __P((SCR *, OPTION *, const char *, u_long *));
+int f_readonly __P((SCR *, OPTION *, const char *, u_long *));
+int f_recompile __P((SCR *, OPTION *, const char *, u_long *));
+int f_reformat __P((SCR *, OPTION *, const char *, u_long *));
+int f_section __P((SCR *, OPTION *, const char *, u_long *));
+int f_ttywerase __P((SCR *, OPTION *, const char *, u_long *));
+int f_w300 __P((SCR *, OPTION *, const char *, u_long *));
+int f_w1200 __P((SCR *, OPTION *, const char *, u_long *));
+int f_w9600 __P((SCR *, OPTION *, const char *, u_long *));
+int f_window __P((SCR *, OPTION *, const char *, u_long *));
+int f_encoding __P((SCR *, OPTION *, const char *, u_long *));
 void thread_init __P((GS *gp));
 int put __P((SCR *, CB *, CHAR_T *, MARK *, MARK *, int));
 int rcv_tmp __P((SCR *, EXF *, char *));
@@ -163,14 +154,14 @@
    __P((SCR *, SEQ **, EVENT *, CHAR_T *, size_t, seq_t, int *));
 void seq_close __P((GS *));
 int seq_dump __P((SCR *, seq_t, int));
-int seq_save __P((SCR *, FILE *, char *, seq_t));
+int seq_save __P((SCR *, FILE *, const char *, seq_t));
 int e_memcmp __P((CHAR_T *, EVENT *, size_t));
 void vtrace_end __P((void));
 void vtrace_init __P((char *));
 void vtrace __P((const char *, ...));
 void *binc __P((SCR *, void *, size_t *, size_t));
 int nonblank __P((SCR *, db_recno_t, size_t *));
-char *tail __P((char *));
+const char *tail __P((const char *));
 char *v_strdup __P((SCR *, const char *, size_t));
 CHAR_T *v_wstrdup __P((SCR *, const CHAR_T *, size_t));
 enum nresult nget_uslong __P((SCR *, u_long *, const CHAR_T *, CHAR_T **, int));
--- a/dist/nvi/common/gs.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/gs.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: gs.h,v 1.2 2008/06/11 21:32:17 aymeric Exp $ */
+/*	$NetBSD: gs.h,v 1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -158,7 +158,7 @@
 					/* Insert a line. */
 	int	(*scr_insertln) __P((SCR *));
 					/* Handle an option change. */
-	int	(*scr_optchange) __P((SCR *, int, char *, u_long *));
+	int	(*scr_optchange) __P((SCR *, int, const char *, u_long *));
 					/* Move the cursor. */
 	int	(*scr_move) __P((SCR *, size_t, size_t));
 					/* Refresh the screen. */
--- a/dist/nvi/common/key.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/key.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.2 2008/08/27 10:18:41 christos Exp $ */
+/*	$NetBSD: key.c,v 1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -204,7 +204,7 @@
 v_key_ilookup(SCR *sp)
 {
 	UCHAR_T ch;
-	char *p, *t;
+	unsigned char *p, *t;
 	GS *gp;
 	size_t len;
 
@@ -246,7 +246,7 @@
 	CHAR_T ch, mask;
 	size_t len;
 	int cnt, shift;
-	char *chp;
+	const char *chp;
 
 	ch = ach;
 
@@ -301,7 +301,7 @@
 	} else {
 		sp->cname[0] = '\\';
 		sp->cname[1] = 'x';
-		for (len = 2, chp = (u_int8_t *)&ch,
+		for (len = 2, chp = (char *)&ch,
 		    /* sizeof(CHAR_T) conflict with MAX_CHARACTER_COLUMNS
 		     * and code depends on big endian
 		     * and might not be needed in the long run
@@ -342,10 +342,10 @@
  * an associated flag value, which indicates if it has already been quoted,
  * and if it is the result of a mapping or an abbreviation.
  *
- * PUBLIC: int v_event_push __P((SCR *, EVENT *, CHAR_T *, size_t, u_int));
+ * PUBLIC: int v_event_push __P((SCR *, EVENT *, const CHAR_T *, size_t, u_int));
  */
 int
-v_event_push(SCR *sp, EVENT *p_evp, CHAR_T *p_s, size_t nitems, u_int flags)
+v_event_push(SCR *sp, EVENT *p_evp, const CHAR_T *p_s, size_t nitems, u_int flags)
 	        
 	             			/* Push event. */
 	            			/* Push characters. */
@@ -628,7 +628,7 @@
 	 */
 	if (istimeout || FL_ISSET(evp->e_flags, CH_NOMAP) ||
 	    !LF_ISSET(EC_MAPCOMMAND | EC_MAPINPUT) ||
-	    evp->e_c < MAX_BIT_SEQ && !bit_test(gp->seqb, evp->e_c))
+	    (evp->e_c < MAX_BIT_SEQ && !bit_test(gp->seqb, evp->e_c)))
 		goto nomap;
 
 	/* Search the map. */
@@ -847,5 +847,5 @@
 static int
 v_key_cmp(const void *ap, const void *bp)
 {
-	return (((KEYLIST *)ap)->ch - ((KEYLIST *)bp)->ch);
+	return (((const KEYLIST *)ap)->ch - ((const KEYLIST *)bp)->ch);
 }
--- a/dist/nvi/common/log.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/log.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: log.c,v 1.1.1.2 2008/05/18 14:29:46 aymeric Exp $ */
+/*	$NetBSD: log.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -28,6 +28,7 @@
 #include <string.h>
 
 #include "common.h"
+#include "dbinternal.h"
 
 /*
  * The log consists of records, each containing a type byte and a variable
@@ -67,9 +68,9 @@
 
 static int	vi_log_get __P((SCR *sp, db_recno_t *lnop, size_t *size));
 static int	log_cursor1 __P((SCR *, int));
-static void	log_err __P((SCR *, char *, int));
+static void	log_err __P((SCR *, const char *, int));
 #if defined(DEBUG) && 0
-static void	log_trace __P((SCR *, char *, db_recno_t, u_char *));
+static void	log_trace __P((SCR *, const char *, db_recno_t, u_char *));
 #endif
 
 /* Try and restart the log on failure, i.e. if we run out of memory. */
@@ -741,7 +742,7 @@
  *	Try and restart the log on failure, i.e. if we run out of memory.
  */
 static void
-log_err(SCR *sp, char *file, int line)
+log_err(SCR *sp, const char *file, int line)
 {
 	EXF *ep;
 
@@ -754,11 +755,7 @@
 
 #if defined(DEBUG) && 0
 static void
-log_trace(sp, msg, rno, p)
-	SCR *sp;
-	char *msg;
-	db_recno_t rno;
-	u_char *p;
+log_trace(SCR *sp, const char *msg, db_recno_t rno, u_char *p)
 {
 	LMARK lm;
 	MARK m;
--- a/dist/nvi/common/main.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/main.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.2 2008/10/29 17:50:49 christos Exp $ */
+/*	$NetBSD: main.c,v 1.2.2.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -41,8 +41,7 @@
 #include "../vi/vi.h"
 #include "pathnames.h"
 
-static void	 attach __P((GS *));
-static void	 v_estr __P((char *, int, char *));
+static void	 v_estr __P((const char *, int, const char *));
 static int	 v_obsolete __P((char *, char *[]));
 
 /*
@@ -68,7 +67,7 @@
 	int gtags = 0;
 #endif
 	char *tag_f, *wsizearg, path[256];
-	CHAR_T *w;
+	const CHAR_T *w;
 	size_t wlen;
 
 	gp = wp->gp;
@@ -519,7 +518,7 @@
 #endif
 
 static void
-v_estr(char *name, int eno, char *msg)
+v_estr(const char *name, int eno, const char *msg)
 {
 	(void)fprintf(stderr, "%s", name);
 	if (msg != NULL)
--- a/dist/nvi/common/mark.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/mark.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: mark.c,v 1.1.1.2 2008/05/18 14:29:47 aymeric Exp $ */
+/*	$NetBSD: mark.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -221,12 +221,13 @@
 	case LINE_DELETE:
 		for (lmp = sp->ep->marks.lh_first;
 		    lmp != NULL; lmp = lmp->q.le_next)
-			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:
 		/*
--- a/dist/nvi/common/mem.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/mem.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: mem.h,v 1.1.1.2 2008/05/18 14:29:48 aymeric Exp $ */
+/*	$NetBSD: mem.h,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -11,9 +11,9 @@
  *	Id: mem.h,v 10.13 2002/01/05 23:13:37 skimo Exp (Berkeley) Date: 2002/01/05 23:13:37
  */
 
-#ifdef HAVE_GCC
+#if defined(HAVE_GCC) && !defined(__NetBSD__)
 #define CHECK_TYPE(type, var)						\
-	type L__lp __attribute__((unused)) = var;
+	do { type L__lp __attribute__((__unused__)) = var; } while (/*CONSTCOND*/0);
 #else
 #define CHECK_TYPE(type, var)
 #endif
@@ -103,8 +103,8 @@
  * returns, one that jumps to an error label.
  */
 #define	ADD_SPACE_GOTO(sp, type, bp, blen, nlen) {			\
+	WIN *L__wp = (sp) == NULL ? NULL : (sp)->wp;			\
 	CHECK_TYPE(type *, bp)						\
-	WIN *L__wp = (sp) == NULL ? NULL : (sp)->wp;			\
 	if (L__wp == NULL || bp == (type *)L__wp->tmp_bp) {		\
 		F_CLR(L__wp, W_TMP_INUSE);				\
 		BINC_GOTOC(sp, L__wp->tmp_bp, L__wp->tmp_blen, nlen);	\
--- a/dist/nvi/common/msg.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/msg.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.c,v 1.1.1.2 2008/05/18 14:29:48 aymeric Exp $ */
+/*	$NetBSD: msg.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -38,6 +38,7 @@
 #endif
 
 #include "common.h"
+#include "dbinternal.h"
 #include "../vi/vi.h"
 
 /*
@@ -68,13 +69,18 @@
 	} str[__NL_ARGMAX];
 #endif
 	static int reenter;		/* STATIC: Re-entrancy check. */
+	GS *gp;
+	WIN *wp = NULL;
+	size_t blen, len, mlen, nlen;
+	const char *p;
+	char *bp, *mp;
+        va_list ap;
+#ifndef NL_ARGMAX
 	CHAR_T ch;
-	GS *gp;
-	WIN *wp;
-	size_t blen, cnt1, cnt2, len, mlen, nlen, soff;
-	const char *p, *t, *u;
-	char *bp, *mp, *rbp, *s_rbp;
-        va_list ap;
+	char *rbp, *s_rbp;
+	const char *t, *u;
+	size_t cnt1, cnt2, soff;
+#endif
 
 	/*
 	 * !!!
@@ -277,7 +283,9 @@
 	fmt = rbp;
 #endif
 
+#ifndef NL_ARGMAX
 format:	/* Format the arguments into the string. */
+#endif
 #ifdef __STDC__
         va_start(ap, fmt);
 #else
@@ -359,7 +367,10 @@
 		(void)fprintf(stderr, "%.*s", (int)mlen, bp);
 
 	/* Cleanup. */
-ret:	FREE_SPACE(sp, bp, blen);
+#ifndef NL_ARGMAX
+ret:
+#endif
+	FREE_SPACE(sp, bp, blen);
 alloc_err:
 	reenter = 0;
 }
@@ -368,13 +379,13 @@
  * msgq_str --
  *	Display a message with an embedded string.
  *
- * PUBLIC: void msgq_wstr __P((SCR *, mtype_t, CHAR_T *, char *));
+ * PUBLIC: void msgq_wstr __P((SCR *, mtype_t, const CHAR_T *, const char *));
  */
 void
-msgq_wstr(SCR *sp, mtype_t mtype, CHAR_T *str, char *fmt)
+msgq_wstr(SCR *sp, mtype_t mtype, const CHAR_T *str, const char *fmt)
 {
 	size_t nlen;
-	char *nstr;
+	const char *nstr;
 
 	if (str == NULL) {
 		msgq(sp, mtype, fmt);
@@ -391,7 +402,7 @@
  * PUBLIC: void msgq_str __P((SCR *, mtype_t, char *, char *));
  */
 void
-msgq_str(SCR *sp, mtype_t mtype, char *str, char *fmt)
+msgq_str(SCR *sp, mtype_t mtype, const char *str, const char *fmt)
 {
 	int nf, sv_errno;
 	char *p;
@@ -432,7 +443,7 @@
 void
 mod_rpt(SCR *sp)
 {
-	static char * const action[] = {
+	static const char * const action[] = {
 		"293|added",
 		"294|changed",
 		"295|deleted",
@@ -441,7 +452,7 @@
 		"298|shifted",
 		"299|yanked",
 	};
-	static char * const lines[] = {
+	static const char * const lines[] = {
 		"300|line",
 		"301|lines",
 	};
@@ -450,7 +461,7 @@
 	int first, cnt;
 	size_t blen, len, tlen;
 	const char *t;
-	char * const *ap;
+	const char * const *ap;
 	char *bp, *p;
 
 	/* Change reports are turned off in batch mode. */
@@ -699,10 +710,10 @@
  * msg_open --
  *	Open the message catalogs.
  *
- * PUBLIC: int msg_open __P((SCR *, char *));
+ * PUBLIC: int msg_open __P((SCR *, const char *));
  */
 int
-msg_open(SCR *sp, char *file)
+msg_open(SCR *sp, const char *file)
 {
 	/*
 	 * !!!
@@ -717,7 +728,8 @@
 	DB *db;
 	DBT data, key;
 	db_recno_t msgno;
-	char *p, *t, buf[MAXPATHLEN];
+	char buf[MAXPATHLEN];
+	const char *p, *t;
 
 	if ((p = strrchr(file, '/')) != NULL && p[1] == '\0' &&
 	    (((t = getenv("LC_MESSAGES")) != NULL && t[0] != '\0') ||
@@ -834,8 +846,9 @@
 	 * If it's not a catalog message, i.e. has doesn't have a leading
 	 * number and '|' symbol, we're done.
 	 */
-	if (isdigit(str[0]) &&
-	    isdigit(str[1]) && isdigit(str[2]) && str[3] == '|') {
+	if (isdigit((unsigned char)str[0]) &&
+	    isdigit((unsigned char)str[1]) && isdigit((unsigned char)str[2]) &&
+	    str[3] == '|') {
 		memset(&key, 0, sizeof(key));
 		key.data = &msgno;
 		key.size = sizeof(db_recno_t);
@@ -877,15 +890,16 @@
 {
 	size_t blen, nlen;
 	const char *cp;
-	char *bp, *ep, *p, *t;
+	char *bp, *ep, *p;
+	unsigned char *t;
 
 	*needfree = 0;
 
 	for (cp = s; *cp != '\0'; ++cp)
-		if (!isprint(*cp))
+		if (!isprint((unsigned char)*cp))
 			break;
 	if (*cp == '\0')
-		return ((char *)s);	/* SAFE: needfree set to 0. */
+		return ((char *)__UNCONST(s));	/* SAFE: needfree set to 0. */
 
 	nlen = 0;
 	if (0) {
@@ -902,7 +916,7 @@
 	} else
 		GET_SPACE_GOTOC(sp, bp, blen, nlen);
 	if (0) {
-alloc_err:	return ("");
+alloc_err:	return __UNCONST("");
 	}
 	*needfree = 1;
 
--- a/dist/nvi/common/options.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/options.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: options.c,v 1.3 2008/10/29 17:50:49 christos Exp $ */
+/*	$NetBSD: options.c,v 1.3.2.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -248,11 +248,11 @@
 	{L("wrapscan"),	NULL,		OPT_1BOOL,	0},
 /* O_WRITEANY	    4BSD */
 	{L("writeany"),	NULL,		OPT_0BOOL,	0},
-	{NULL},
+	{NULL,		NULL,		OPT_NUM,	0},
 };
 
 typedef struct abbrev {
-        CHAR_T *name;
+        const CHAR_T *name;
         int offset;
 } OABBREV;
 
@@ -299,7 +299,7 @@
 	{L("wl"),	O_WRAPLEN},		/*   4.4BSD */
 	{L("wm"),	O_WRAPMARGIN},		/*     4BSD */
 	{L("ws"),	O_WRAPSCAN},		/*     4BSD */
-	{NULL},
+	{NULL,		0},
 };
 
 /*
@@ -314,11 +314,9 @@
 	ARGS *argv[2], a, b;
 	OPTLIST const *op;
 	u_long isset, v;
-	int cnt, optindx;
+	int cnt, optindx = 0;
 	char *s;
 	CHAR_T b2[1024];
-	CHAR_T *wp;
-	size_t wlen;
 
 	if (sizeof optlist / sizeof optlist[0] - 1 != O_OPTIONCOUNT) {
 		fprintf(stderr, "vi: option table size error (%d != %d)\n",
@@ -336,7 +334,7 @@
 	/* Set numeric and string default values. */
 #define	OI(indx, str) {							\
 	a.len = STRLEN(str);						\
-	if ((CHAR_T*)str != b2)	  /* GCC puts strings in text-space. */	\
+	if ((const CHAR_T*)str != b2)/* GCC puts strings in text-space. */\
 		(void)MEMCPY(b2, str, a.len+1);				\
 	if (opts_set(sp, argv, NULL)) {					\
 		 optindx = indx;					\
@@ -486,7 +484,7 @@
  * PUBLIC: int opts_set __P((SCR *, ARGS *[], char *));
  */
 int
-opts_set(SCR *sp, ARGS **argv, char *usage)
+opts_set(SCR *sp, ARGS **argv, const char *usage)
 {
 	enum optdisp disp;
 	enum nresult nret;
@@ -494,9 +492,9 @@
 	OPTION *spo;
 	u_long isset, turnoff, value;
 	int ch, equals, nf, nf2, offset, qmark, rval;
-	CHAR_T *endp, *name, *p, *sep, *t;
+	CHAR_T *endp, *name, *p, *sep;
 	char *p2, *t2;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	disp = NO_DISPLAY;
@@ -599,17 +597,18 @@
 			 * 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 &&
-			    op->func(sp, spo, NULL, &isset) ||
+			if ((op->func != NULL &&
+			    op->func(sp, spo, NULL, &isset)) ||
 			    ex_optchange(sp, offset, NULL, &isset) ||
 			    v_optchange(sp, offset, NULL, &isset) ||
 			    sp->gp->scr_optchange(sp, offset, NULL, &isset)) {
@@ -702,8 +701,8 @@
 
 			/* Report to subsystems. */
 			INT2CHAR(sp, sep, STRLEN(sep) + 1, np, nlen);
-			if (op->func != NULL &&
-			    op->func(sp, spo, np, &value) ||
+			if ((op->func != NULL &&
+			    op->func(sp, spo, np, &value)) ||
 			    ex_optchange(sp, offset, np, &value) ||
 			    v_optchange(sp, offset, np, &value) ||
 			    sp->gp->scr_optchange(sp, offset, np, &value)) {
@@ -748,8 +747,8 @@
 				break;
 
 			/* Report to subsystems. */
-			if (op->func != NULL &&
-			    op->func(sp, spo, np, NULL) ||
+			if ((op->func != NULL &&
+			    op->func(sp, spo, np, NULL)) ||
 			    ex_optchange(sp, offset, np, NULL) ||
 			    v_optchange(sp, offset, np, NULL) ||
 			    sp->gp->scr_optchange(sp, offset, np, NULL)) {
@@ -774,10 +773,10 @@
  * o_set --
  *	Set an option's value.
  *
- * PUBLIC: int o_set __P((SCR *, int, u_int, char *, u_long));
+ * PUBLIC: int o_set __P((SCR *, int, u_int, const char *, u_long));
  */
 int
-o_set(SCR *sp, int opt, u_int flags, char *str, u_long val)
+o_set(SCR *sp, int opt, u_int flags, const char *str, u_long val)
 {
 	OPTION *op;
 
@@ -795,14 +794,14 @@
 	if LF_ISSET(OS_DEF)
 		if (LF_ISSET(OS_STR | OS_STRDUP)) {
 			if (!LF_ISSET(OS_NOFREE) && op->o_def.str != NULL)
-				free(op->o_def.str);
+				free(__UNCONST(op->o_def.str));
 			op->o_def.str = str;
 		} else
 			op->o_def.val = val;
 	else
 		if (LF_ISSET(OS_STR | OS_STRDUP)) {
 			if (!LF_ISSET(OS_NOFREE) && op->o_cur.str != NULL)
-				free(op->o_cur.str);
+				free(__UNCONST(op->o_cur.str));
 			op->o_cur.str = str;
 		} else
 			op->o_cur.val = val;
@@ -818,7 +817,7 @@
 int
 opts_empty(SCR *sp, int off, int silent)
 {
-	char *p;
+	const char *p;
 
 	if ((p = O_STR(sp, off)) == NULL || p[0] == '\0') {
 		if (!silent)
@@ -843,7 +842,6 @@
 	int numcols, numrows, row;
 	int b_op[O_OPTIONCOUNT], s_op[O_OPTIONCOUNT];
 	char nbuf[20];
-	CHAR_T *kp;
 
 	/*
 	 * Options are output in two groups -- those that fit in a column and
@@ -892,8 +890,8 @@
 				break;
 			case OPT_STR:
 				if (O_STR(sp, cnt) == O_D_STR(sp, cnt) ||
-				    O_D_STR(sp, cnt) != NULL &&
-				    !strcmp(O_STR(sp, cnt), O_D_STR(sp, cnt)))
+				    (O_D_STR(sp, cnt) != NULL &&
+				    !strcmp(O_STR(sp, cnt), O_D_STR(sp, cnt))))
 					continue;
 				break;
 			}
@@ -1002,8 +1000,10 @@
 opts_save(SCR *sp, FILE *fp)
 {
 	OPTLIST const *op;
-	CHAR_T ch, *p;
-	char nch, *np;
+	CHAR_T ch;
+	const CHAR_T *p;
+	char nch;
+	const char *np;
 	int cnt;
 
 	for (op = optlist; op->name != NULL; ++op) {
@@ -1055,7 +1055,7 @@
  * PUBLIC: OPTLIST const *opts_search __P((CHAR_T *));
  */
 OPTLIST const *
-opts_search(CHAR_T *name)
+opts_search(const CHAR_T *name)
 {
 	OPTLIST const *op, *found;
 	OABBREV atmp, *ap;
@@ -1100,7 +1100,7 @@
  * PUBLIC: void opts_nomatch __P((SCR *, CHAR_T *));
  */
 void
-opts_nomatch(SCR *sp, CHAR_T *name)
+opts_nomatch(SCR *sp, const CHAR_T *name)
 {
 	msgq_wstr(sp, M_ERR, name,
 	    "033|set: no %s option: 'set all' gives all option values");
@@ -1109,13 +1109,13 @@
 static int
 opts_abbcmp(const void *a, const void *b)
 {
-        return(STRCMP(((OABBREV *)a)->name, ((OABBREV *)b)->name));
+        return(STRCMP(((const OABBREV *)a)->name, ((const OABBREV *)b)->name));
 }
 
 static int
 opts_cmp(const void *a, const void *b)
 {
-        return(STRCMP(((OPTLIST *)a)->name, ((OPTLIST *)b)->name));
+        return(STRCMP(((const OPTLIST *)a)->name, ((const OPTLIST *)b)->name));
 }
 
 /*
@@ -1180,8 +1180,8 @@
 		    F_ISSET(&sp->opts[cnt], OPT_GLOBAL))
 			continue;
 		if (O_STR(sp, cnt) != NULL)
-			free(O_STR(sp, cnt));
+			free(__UNCONST(O_STR(sp, cnt)));
 		if (O_D_STR(sp, cnt) != NULL)
-			free(O_D_STR(sp, cnt));
+			free(__UNCONST(O_D_STR(sp, cnt)));
 	}
 }
--- a/dist/nvi/common/options.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/options.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: options.h,v 1.2 2008/10/01 21:20:09 christos Exp $ */
+/*	$NetBSD: options.h,v 1.2.4.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -53,7 +53,7 @@
 struct _option {
 	union {
 		u_long	 val;		/* Value or boolean. */
-		char	*str;		/* String. */
+		const char *str;	/* String. */
 	} o_cur;
 #define	O_CLR(sp, o)		o_set(sp, o, 0, NULL, 0)
 #define	O_SET(sp, o)		o_set(sp, o, 0, NULL, 1)
@@ -63,7 +63,7 @@
 
 	union {
 		u_long	 val;		/* Value or boolean. */
-		char	*str;		/* String. */
+		const char *str;	/* String. */
 	} o_def;
 #define	O_D_CLR(sp, o)		o_set(sp, o, OS_DEF, NULL, 0)
 #define	O_D_SET(sp, o)		o_set(sp, o, OS_DEF, NULL, 1)
@@ -78,9 +78,9 @@
 
 /* List of option names, associated update functions and information. */
 struct _optlist {
-	CHAR_T	*name;			/* Name. */
+	const CHAR_T *name;		/* Name. */
 					/* Change function. */
-	int	(*func) __P((SCR *, OPTION *, char *, u_long *));
+	int	(*func) __P((SCR *, OPTION *, const char *, u_long *));
 					/* Type of object. */
 	enum { OPT_0BOOL, OPT_1BOOL, OPT_NUM, OPT_STR } type;
 
--- a/dist/nvi/common/options_f.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/options_f.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: options_f.c,v 1.2 2008/10/01 21:20:09 christos Exp $ */
+/*	$NetBSD: options_f.c,v 1.2.4.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -31,10 +31,10 @@
 #include "common.h"
 
 /*
- * PUBLIC: int f_altwerase __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_altwerase __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_altwerase(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_altwerase(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	if (*valp)
 		O_CLR(sp, O_TTYWERASE);
@@ -42,10 +42,10 @@
 }
 
 /*
- * PUBLIC: int f_columns __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_columns __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_columns(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_columns(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	/* Validate the number. */
 	if (*valp < MINIMUM_SCREEN_COLS) {
@@ -72,10 +72,10 @@
 }
 
 /*
- * PUBLIC: int f_lines __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_lines __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_lines(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_lines(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	/* Validate the number. */
 	if (*valp < MINIMUM_SCREEN_ROWS) {
@@ -125,30 +125,30 @@
 }
 
 /*
- * PUBLIC: int f_lisp __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_lisp __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_lisp(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_lisp(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	msgq(sp, M_ERR, "044|The lisp option is not implemented");
 	return (0);
 }
 
 /*
- * PUBLIC: int f_msgcat __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_msgcat __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_msgcat(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_msgcat(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	(void)msg_open(sp, str);
 	return (0);
 }
 
 /*
- * PUBLIC: int f_print __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_print __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_print(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_print(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	int offset = op - sp->opts;
 
@@ -170,10 +170,10 @@
 }
 
 /*
- * PUBLIC: int f_readonly __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_readonly __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_readonly(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_readonly(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	/*
 	 * !!!
@@ -187,10 +187,10 @@
 }
 
 /*
- * PUBLIC: int f_recompile __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_recompile __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_recompile(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_recompile(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	if (F_ISSET(sp, SC_RE_SEARCH)) {
 		regfree(&sp->re_c);
@@ -204,20 +204,20 @@
 }
 
 /*
- * PUBLIC: int f_reformat __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_reformat __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_reformat(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_reformat(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	F_SET(sp, SC_SCR_REFORMAT);
 	return (0);
 }
 
 /*
- * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_ttywerase __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_ttywerase(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_ttywerase(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	if (*valp)
 		O_CLR(sp, O_ALTWERASE);
@@ -225,10 +225,10 @@
 }
 
 /*
- * PUBLIC: int f_w300 __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_w300 __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_w300(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_w300(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	u_long v;
 
@@ -242,10 +242,10 @@
 }
 
 /*
- * PUBLIC: int f_w1200 __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_w1200 __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_w1200(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_w1200(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	u_long v;
 
@@ -259,10 +259,10 @@
 }
 
 /*
- * PUBLIC: int f_w9600 __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_w9600 __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_w9600(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_w9600(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	u_long v;
 
@@ -276,10 +276,10 @@
 }
 
 /*
- * PUBLIC: int f_window __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_window __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_window(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_window(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	if (*valp >= O_VAL(sp, O_LINES) - 1 &&
 	    (*valp = O_VAL(sp, O_LINES) - 1) == 0)
@@ -288,10 +288,10 @@
 }
 
 /*
- * PUBLIC: int f_encoding __P((SCR *, OPTION *, char *, u_long *));
+ * PUBLIC: int f_encoding __P((SCR *, OPTION *, const char *, u_long *));
  */
 int
-f_encoding(SCR *sp, OPTION *op, char *str, u_long *valp)
+f_encoding(SCR *sp, OPTION *op, const char *str, u_long *valp)
 {
 	int offset = op - sp->opts;
 
--- a/dist/nvi/common/put.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/put.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: put.c,v 1.1.1.2 2008/05/18 14:29:50 aymeric Exp $ */
+/*	$NetBSD: put.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -44,7 +44,7 @@
 	CHAR_T *bp, *t;
 	CHAR_T *p;
 
-	if (cbp == NULL)
+	if (cbp == NULL) {
 		if (namep == NULL) {
 			cbp = sp->wp->dcbp;
 			if (cbp == NULL) {
@@ -61,6 +61,7 @@
 				return (1);
 			}
 		}
+	}
 	tp = cbp->textq.cqh_first;
 
 	/*
--- a/dist/nvi/common/recover.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/recover.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: recover.c,v 1.1.1.2 2008/05/18 14:29:51 aymeric Exp $ */
+/*	$NetBSD: recover.c,v 1.1.1.2.6.1 2009/01/20 02:41:11 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -115,7 +115,7 @@
 static void	 rcv_email __P((SCR *, char *));
 static char	*rcv_gets __P((char *, size_t, int));
 static int	 rcv_mailfile __P((SCR *, int, char *));
-static int	 rcv_mktemp __P((SCR *, char *, char *, int));
+static int	 rcv_mktemp __P((SCR *, char *, const char *, int));
 
 /*
  * rcv_tmp --
@@ -128,7 +128,8 @@
 {
 	struct stat sb;
 	int fd;
-	char *dp, path[MAXPATHLEN];
+	char path[MAXPATHLEN];
+	const char *dp;
 
 	/*
 	 * !!!
@@ -250,7 +251,8 @@
 {
 	EXF *ep;
 	int fd, rval;
-	char *dp, buf[1024];
+	char buf[1024];
+	const char *dp;
 
 	/* Make sure that there's something to recover/sync. */
 	ep = sp->ep;
@@ -328,7 +330,8 @@
 	time_t now;
 	uid_t uid;
 	int fd;
-	char *dp, *p, *t, buf[4096], mpath[MAXPATHLEN];
+	char *p, *t, buf[4096], mpath[MAXPATHLEN];
+	const char *dp;
 	char *t1, *t2, *t3;
 
 	/*
@@ -484,14 +487,16 @@
 	DIR *dirp;
 	FILE *fp;
 	int found;
-	char *p, *t, file[MAXPATHLEN], path[MAXPATHLEN];
+	char *p, *t;
+	const char *d;
+	char file[MAXPATHLEN], path[MAXPATHLEN];
 
 	/* Open the recovery directory for reading. */
 	if (opts_empty(sp, O_RECDIR, 0))
 		return (1);
-	p = O_STR(sp, O_RECDIR);
-	if (chdir(p) || (dirp = opendir(".")) == NULL) {
-		msgq_str(sp, M_SYSERR, p, "recdir: %s");
+	d = O_STR(sp, O_RECDIR);
+	if (chdir(d) || (dirp = opendir(".")) == NULL) {
+		msgq_str(sp, M_SYSERR, d, "recdir: %s");
 		return (1);
 	}
 
@@ -586,8 +591,9 @@
 	DIR *dirp;
 	EXF *ep;
 	time_t rec_mtime;
-	int fd, found, locked, requested, sv_fd;
-	char *name, *p, *t, *rp, *recp, *pathp;
+	int fd, found, locked = 0, requested, sv_fd;
+	char *name, *p, *t, *recp, *pathp;
+	const char *rp;
 	char file[MAXPATHLEN], path[MAXPATHLEN], recpath[MAXPATHLEN];
 
 	if (opts_empty(sp, O_RECDIR, 0))
@@ -804,7 +810,7 @@
  *	Paranoid make temporary file routine.
  */
 static int
-rcv_mktemp(SCR *sp, char *path, char *dname, int perms)
+rcv_mktemp(SCR *sp, char *path, const char *dname, int perms)
 {
 	int fd;
 
--- a/dist/nvi/common/search.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/search.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: search.c,v 1.1.1.2 2008/05/18 14:29:51 aymeric Exp $ */
+/*	$NetBSD: search.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -203,7 +203,8 @@
 			}
 			cnt = INTERRUPT_CHECK;
 		}
-		if (wrapped && lno > fm->lno || db_get(sp, lno, 0, &l, &len)) {
+		if ((wrapped && lno > fm->lno) ||
+		    db_get(sp, lno, 0, &l, &len)) {
 			if (wrapped) {
 				if (LF_ISSET(SEARCH_MSG))
 					search_msg(sp, S_NOTFOUND);
@@ -334,7 +335,7 @@
 			}
 			cnt = INTERRUPT_CHECK;
 		}
-		if (wrapped && lno < fm->lno || lno == 0) {
+		if ((wrapped && lno < fm->lno) || lno == 0) {
 			if (wrapped) {
 				if (LF_ISSET(SEARCH_MSG))
 					search_msg(sp, S_NOTFOUND);
--- a/dist/nvi/common/seq.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/seq.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: seq.c,v 1.1.1.2 2008/05/18 14:29:52 aymeric Exp $ */
+/*	$NetBSD: seq.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -284,14 +284,14 @@
 		++cnt;
 		for (p = qp->input,
 		    olen = qp->ilen, len = 0; olen > 0; --olen, ++p)
-			len += ex_puts(sp, KEY_NAME(sp, *p));
+			len += ex_puts(sp, (char *)KEY_NAME(sp, *p));
 		for (len = STANDARD_TAB - len % STANDARD_TAB; len > 0;)
 			len -= ex_puts(sp, " ");
 
 		if (qp->output != NULL)
 			for (p = qp->output,
 			    olen = qp->olen, len = 0; olen > 0; --olen, ++p)
-				len += ex_puts(sp, KEY_NAME(sp, *p));
+				len += ex_puts(sp, (char *)KEY_NAME(sp, *p));
 		else
 			len = 0;
 
@@ -300,7 +300,7 @@
 				len -= ex_puts(sp, " ");
 			for (p = qp->name,
 			    olen = qp->nlen; olen > 0; --olen, ++p)
-				(void)ex_puts(sp, KEY_NAME(sp, *p));
+				(void)ex_puts(sp, (char *)KEY_NAME(sp, *p));
 		}
 		(void)ex_puts(sp, "\n");
 	}
@@ -314,7 +314,7 @@
  * PUBLIC: int seq_save __P((SCR *, FILE *, char *, seq_t));
  */
 int
-seq_save(SCR *sp, FILE *fp, char *prefix, seq_t stype)
+seq_save(SCR *sp, FILE *fp, const char *prefix, seq_t stype)
 {
 	CHAR_T *p;
 	SEQ *qp;
--- a/dist/nvi/common/util.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/common/util.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.2 2008/08/27 10:18:41 christos Exp $ */
+/*	$NetBSD: util.c,v 1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -107,10 +107,10 @@
  *
  * PUBLIC: char *tail __P((char *));
  */
-char *
-tail(char *path)
+const char *
+tail(const char *path)
 {
-	char *p;
+	const char *p;
 
 	if ((p = strrchr(path, '/')) == NULL)
 		return (path);
--- a/dist/nvi/ex/ex.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex.c,v 1.1.1.2 2008/05/18 14:31:11 aymeric Exp $ */
+/*	$NetBSD: ex.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -80,7 +80,7 @@
 	/* If reading from a file, errors should have name and line info. */
 	if (F_ISSET(gp, G_SCRIPTED)) {
 		wp->excmd.if_lno = 1;
-		wp->excmd.if_name = "script";
+		wp->excmd.if_name = strdup("script");
 	}
 
 	/*
@@ -213,8 +213,8 @@
 	int newscreen, notempty, tmp, vi_address;
 	CHAR_T *arg1, *s, *p, *t;
 	CHAR_T ch;
-	CHAR_T *n;
-	char *np;
+	const CHAR_T *n;
+	const char *np;
 
 	gp = sp->gp;
 	wp = sp->wp;
@@ -784,16 +784,16 @@
 	for (p = ecp->cp; ecp->clen > 0; --ecp->clen, ++ecp->cp) {
 		ch = ecp->cp[0];
 		if (IS_ESCAPE(sp, ecp, ch) && ecp->clen > 1) {
-			CHAR_T tmp = ecp->cp[1];
-			if (tmp == '\n' || tmp == '|') {
-				if (tmp == '\n') {
+			CHAR_T tmp1 = ecp->cp[1];
+			if (tmp1 == '\n' || tmp1 == '|') {
+				if (tmp1 == '\n') {
 					++wp->if_lno;
 					++ecp->if_lno;
 				}
 				++discard;
 				--ecp->clen;
 				++ecp->cp;
-				ch = tmp;
+				ch = tmp1;
 			}
 		} else if (ch == '\n' || ch == '|') {
 			if (ch == '\n')
@@ -1896,7 +1896,7 @@
 		 * difference.  C'est la vie.
 		 */
 		if (ecp->clen < 2 ||
-		    ecp->cp[1] != '/' && ecp->cp[1] != '?') {
+		    (ecp->cp[1] != '/' && ecp->cp[1] != '?')) {
 			msgq(sp, M_ERR, "096|\\ not followed by / or ?");
 			*errp = 1;
 			return (0);
@@ -2002,9 +2002,9 @@
 		for (;;) {
 			for (; ecp->clen > 0 && ISBLANK(ecp->cp[0]);
 			    ++ecp->cp, --ecp->clen);
-			if (ecp->clen == 0 || !ISDIGIT(ecp->cp[0]) &&
+			if (ecp->clen == 0 || (!ISDIGIT(ecp->cp[0]) &&
 			    ecp->cp[0] != '+' && ecp->cp[0] != '-' &&
-			    ecp->cp[0] != '^')
+			    ecp->cp[0] != '^'))
 				break;
 			if (!ISDIGIT(ecp->cp[0]) &&
 			    !ISDIGIT(ecp->cp[1])) {
@@ -2120,7 +2120,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 {
@@ -2129,6 +2129,7 @@
 					if (sp->lno == 0)
 						sp->lno = 1;
 				}
+			}
 			free(ecp->o_cp);
 		}
 
--- a/dist/nvi/ex/ex.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex.h,v 1.2 2008/10/29 17:50:49 christos Exp $ */
+/*	$NetBSD: ex.h,v 1.2.2.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -14,7 +14,7 @@
 #define	PROMPTCHAR	':'		/* Prompt using a colon. */
 
 typedef struct _excmdlist {		/* Ex command table structure. */
-	CHAR_T *name;			/* Command name, underlying function. */
+	const CHAR_T *name;		/* Command name, underlying function. */
 	int (*fn) __P((SCR *, EXCMD *));
 
 #define	E_ADDR1		0x00000001	/* One address. */
@@ -31,9 +31,9 @@
 #define	__INUSE1	0xfffff800	/* Same name space as EX_PRIVATE. */
 	u_int16_t flags;
 
-	char *syntax;			/* Syntax script. */
-	char *usage;			/* Usage line. */
-	char *help;			/* Help line. */
+	const char *syntax;		/* Syntax script. */
+	const char *usage;		/* Usage line. */
+	const char *help;		/* Help line. */
 } EXCMDLIST;
 
 #define	MAXCMDNAMELEN	12		/* Longest command name. */
--- a/dist/nvi/ex/ex_append.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_append.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_append.c,v 1.1.1.2 2008/05/18 14:31:11 aymeric Exp $ */
+/*	$NetBSD: ex_append.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -254,7 +254,7 @@
 		return (1);
 
 	for (cnt = 0, tp = tiq.cqh_first;
-	    tp != (TEXT *)&tiq; ++cnt, tp = tp->q.cqe_next)
+	    tp != (TEXT *)(void *)&tiq; ++cnt, tp = tp->q.cqe_next)
 		if (db_append(sp, 1, lno++, tp->lb, tp->len))
 			return (1);
 
--- a/dist/nvi/ex/ex_args.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_args.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_args.c,v 1.1.1.2 2008/05/18 14:31:11 aymeric Exp $ */
+/*	$NetBSD: ex_args.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -50,9 +50,9 @@
 	FREF *frp;
 	int noargs;
 	char **ap;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	/* Check for file to move to. */
@@ -135,7 +135,7 @@
 {
 	SCR *new;
 	FREF *frp;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	/* Get a new screen. */
@@ -180,7 +180,7 @@
 {
 	FREF *frp;
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 
 	if (sp->cargv == sp->argv) {
 		msgq(sp, M_ERR, "112|No previous files to edit");
@@ -309,7 +309,7 @@
 	ARGS **argv;
 	int argc;
 	char **ap, **s_argv;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	argc = cmdp == NULL ? 1 : cmdp->argc;
--- a/dist/nvi/ex/ex_argv.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_argv.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_argv.c,v 1.1.1.2 2008/05/18 14:31:12 aymeric Exp $ */
+/*	$NetBSD: ex_argv.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -33,8 +33,8 @@
 static int argv_alloc __P((SCR *, size_t));
 static int argv_comp __P((const void *, const void *));
 static int argv_fexp __P((SCR *, EXCMD *,
-	CHAR_T *, size_t, CHAR_T *, size_t *, CHAR_T **, size_t *, int));
-static int argv_lexp __P((SCR *, EXCMD *, char *));
+	const CHAR_T *, size_t, CHAR_T *, size_t *, CHAR_T **, size_t *, int));
+static int argv_lexp __P((SCR *, EXCMD *, const char *));
 static int argv_sexp __P((SCR *, CHAR_T **, size_t *, size_t *));
 
 /*
@@ -64,7 +64,7 @@
  * PUBLIC: int argv_exp0 __P((SCR *, EXCMD *, CHAR_T *, size_t));
  */
 int
-argv_exp0(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen)
+argv_exp0(SCR *sp, EXCMD *excp, const CHAR_T *cmd, size_t cmdlen)
 {
 	EX_PRIVATE *exp;
 
@@ -84,16 +84,14 @@
  *	Do file name expansion on a string, and append it to the
  *	argument list.
  *
- * PUBLIC: int argv_exp1 __P((SCR *, EXCMD *, CHAR_T *, size_t, int));
+ * PUBLIC: int argv_exp1 __P((SCR *, EXCMD *, const CHAR_T *, size_t, int));
  */
 int
-argv_exp1(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen, int is_bang)
+argv_exp1(SCR *sp, EXCMD *excp, const CHAR_T *cmd, size_t cmdlen, int is_bang)
 {
 	EX_PRIVATE *exp;
 	size_t blen, len;
 	CHAR_T *p, *t, *bp;
-	size_t wlen;
-	CHAR_T *wp;
 
 	GET_SPACE_RETW(sp, bp, blen, 512);
 
@@ -128,12 +126,12 @@
  * PUBLIC: int argv_exp2 __P((SCR *, EXCMD *, CHAR_T *, size_t));
  */
 int
-argv_exp2(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen)
+argv_exp2(SCR *sp, EXCMD *excp, const CHAR_T *cmd, size_t cmdlen)
 {
 	size_t blen, len, n;
 	int rval;
 	CHAR_T *bp, *p;
-	char *mp, *np;
+	const char *mp, *np;
 
 	GET_SPACE_RETW(sp, bp, blen, 512);
 
@@ -178,7 +176,8 @@
 		n = 0;
 	else {
 		for (np = mp = O_STR(sp, O_SHELLMETA); *np != '\0'; ++np)
-			if (isblank(*np) || isalnum(*np))
+			if (isblank((unsigned char)*np) ||
+			    isalnum((unsigned char)*np))
 				break;
 		p = bp + SHELLOFFSET;
 		n = len - SHELLOFFSET;
@@ -188,8 +187,8 @@
 					break;
 		} else
 			for (; n > 0; --n, ++p)
-				if (!isblank(*p) &&
-				    !isalnum(*p) && strchr(mp, *p) != NULL)
+				if (!isblank((unsigned char)*p) &&
+				    !isalnum((unsigned char)*p) && strchr(mp, *p) != NULL)
 					break;
 	}
 
@@ -214,12 +213,13 @@
 		break;
 	case 1:
 		if (*p == '*') {
-			char *np, *d;
+			const char *np1;
+			char *d;
 			size_t nlen;
 
 			*p = '\0';
 			INT2CHAR(sp, bp + SHELLOFFSET, 
-				 STRLEN(bp + SHELLOFFSET) + 1, np, nlen);
+				 STRLEN(bp + SHELLOFFSET) + 1, np1, nlen);
 			d = strdup(np);
 			rval = argv_lexp(sp, excp, d);
 			free (d);
@@ -248,12 +248,13 @@
  * PUBLIC: int argv_exp3 __P((SCR *, EXCMD *, CHAR_T *, size_t));
  */
 int
-argv_exp3(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen)
+argv_exp3(SCR *sp, EXCMD *excp, const CHAR_T *cmd, size_t cmdlen)
 {
 	EX_PRIVATE *exp;
 	size_t len;
 	int ch, off;
-	CHAR_T *ap, *p;
+	const CHAR_T *ap;
+	CHAR_T *p;
 
 	for (exp = EXP(sp); cmdlen > 0; ++exp->argsoff) {
 		/* Skip any leading whitespace. */
@@ -313,13 +314,13 @@
  *	Do file name and bang command expansion.
  */
 static int
-argv_fexp(SCR *sp, EXCMD *excp, CHAR_T *cmd, size_t cmdlen, CHAR_T *p, size_t *lenp, CHAR_T **bpp, size_t *blenp, int is_bang)
+argv_fexp(SCR *sp, EXCMD *excp, const CHAR_T *cmd, size_t cmdlen, CHAR_T *p, size_t *lenp, CHAR_T **bpp, size_t *blenp, int is_bang)
 {
 	EX_PRIVATE *exp;
 	char *t;
 	size_t blen, len, off, tlen;
 	CHAR_T *bp;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/* Replace file name characters. */
@@ -506,17 +507,17 @@
  *	buffer.
  */
 static int
-argv_lexp(SCR *sp, EXCMD *excp, char *path)
+argv_lexp(SCR *sp, EXCMD *excp, const char *path)
 {
 	struct dirent *dp;
 	DIR *dirp;
 	EX_PRIVATE *exp;
 	int off;
 	size_t dlen, len, nlen;
-	char *dname, *name;
+	const char *dname, *name;
 	char *p;
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	CHAR_T *n;
 
 	exp = EXP(sp);
@@ -598,7 +599,43 @@
 static int
 argv_comp(const void *a, const void *b)
 {
-	return (STRCMP((*(ARGS **)a)->bp, (*(ARGS **)b)->bp));
+	return (STRCMP((*(const ARGS * const*)a)->bp, (*(const ARGS * const*)b)->bp));
+}
+
+static pid_t
+runcmd(SCR *sp, const char *sh_path, const char *sh, const char *np,
+    int *std_output)
+{
+	pid_t pid;
+	/*
+	 * Do the minimal amount of work possible, the shell is going to run
+	 * briefly and then exit.  We sincerely hope.
+	 */
+	switch (pid = vfork()) {
+	case -1:			/* Error. */
+		msgq(sp, M_SYSERR, "vfork");
+		return (pid_t)-1;
+	case 0:				/* Utility. */
+		/* Redirect stdout to the write end of the pipe. */
+		(void)dup2(std_output[1], STDOUT_FILENO);
+
+		/* Close the utility's file descriptors. */
+		(void)close(std_output[0]);
+		(void)close(std_output[1]);
+		(void)close(STDERR_FILENO);
+
+		/*
+		 * XXX
+		 * Assume that all shells have -c.
+		 */
+		execl(sh_path, sh, "-c", np, (char *)NULL);
+		msgq_str(sp, M_SYSERR, sh_path, "118|Error: execl: %s");
+		_exit(127);
+	default:			/* Parent. */
+		/* Close the pipe ends the parent won't use. */
+		(void)close(std_output[1]);
+		return pid;
+	}
 }
 
 /*
@@ -615,8 +652,8 @@
 	size_t blen, len;
 	int ch, std_output[2];
 	CHAR_T *bp, *p;
-	char *sh, *sh_path;
-	char *np;
+	const char *sh, *sh_path;
+	const char *np;
 	size_t nlen;
 
 	/* Secure means no shell access. */
@@ -657,43 +694,10 @@
 		msgq(sp, M_SYSERR, "fdopen");
 		goto err;
 	}
-
-	/*
-	 * Do the minimal amount of work possible, the shell is going to run
-	 * briefly and then exit.  We sincerely hope.
-	 */
-	switch (pid = vfork()) {
-	case -1:			/* Error. */
-		msgq(sp, M_SYSERR, "vfork");
-err:		if (ifp != NULL)
-			(void)fclose(ifp);
-		else if (std_output[0] != -1)
-			close(std_output[0]);
-		if (std_output[1] != -1)
-			close(std_output[0]);
-		return (1);
-	case 0:				/* Utility. */
-		/* Redirect stdout to the write end of the pipe. */
-		(void)dup2(std_output[1], STDOUT_FILENO);
-
-		/* Close the utility's file descriptors. */
-		(void)close(std_output[0]);
-		(void)close(std_output[1]);
-		(void)close(STDERR_FILENO);
-
-		/*
-		 * XXX
-		 * Assume that all shells have -c.
-		 */
-		INT2CHAR(sp, bp, STRLEN(bp)+1, np, nlen);
-		execl(sh_path, sh, "-c", np, (char *)NULL);
-		msgq_str(sp, M_SYSERR, sh_path, "118|Error: execl: %s");
-		_exit(127);
-	default:			/* Parent. */
-		/* Close the pipe ends the parent won't use. */
-		(void)close(std_output[1]);
-		break;
-	}
+	INT2CHAR(sp, bp, STRLEN(bp)+1, np, nlen);
+	pid = runcmd(sp, sh_path, sh, np, std_output);
+	if (pid == -1)
+		goto err;
 
 	/*
 	 * Copy process standard output into a buffer.
@@ -750,4 +754,11 @@
 		msgq(sp, M_ERR, "304|Shell expansion failed");
 
 	return (rval == SEXP_OK ? 0 : 1);
+err:	if (ifp != NULL)
+		(void)fclose(ifp);
+	else if (std_output[0] != -1)
+		close(std_output[0]);
+	if (std_output[1] != -1)
+		close(std_output[0]);
+	return 1;
 }
--- a/dist/nvi/ex/ex_at.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_at.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_at.c,v 1.1.1.2 2008/05/18 14:31:12 aymeric Exp $ */
+/*	$NetBSD: ex_at.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -64,7 +64,7 @@
 
 	CBNAME(sp, cbp, name);
 	if (cbp == NULL) {
-		ex_emsg(sp, KEY_NAME(sp, name), EXM_EMPTYBUF);
+		ex_emsg(sp, (char *)KEY_NAME(sp, name), EXM_EMPTYBUF);
 		return (1);
 	}
 
--- a/dist/nvi/ex/ex_bang.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_bang.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_bang.c,v 1.1.1.2 2008/05/18 14:31:12 aymeric Exp $ */
+/*	$NetBSD: ex_bang.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -58,7 +58,7 @@
 	db_recno_t lno;
 	int rval;
 	const char *msg;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	ap = cmdp->argv[0];
@@ -103,7 +103,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);
@@ -112,6 +112,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);
--- a/dist/nvi/ex/ex_cd.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_cd.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_cd.c,v 1.1.1.2 2008/05/18 14:31:12 aymeric Exp $ */
+/*	$NetBSD: ex_cd.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -40,8 +40,8 @@
 {
 	struct passwd *pw;
 	ARGS *ap;
-	CHAR_T savech;
-	char *dir, *p, *t;	/* XXX: END OF THE STACK, DON'T TRUST GETCWD. */
+	const char *p, *t;	/* XXX: END OF THE STACK, DON'T TRUST GETCWD. */
+	const char *dir;
 	char buf[MAXPATHLEN * 2];
 	size_t dlen;
 
@@ -93,9 +93,9 @@
 	 */
 	if (cmdp->argc == 0 ||
 	    (ap = cmdp->argv[0])->bp[0] == '/' ||
-	    ap->len == 1 && ap->bp[0] == '.' ||
-	    ap->len >= 2 && ap->bp[0] == '.' && ap->bp[1] == '.' &&
-	    (ap->bp[2] == '/' || ap->bp[2] == '\0'))
+	    (ap->len == 1 && ap->bp[0] == '.') ||
+	    (ap->len >= 2 && ap->bp[0] == '.' && ap->bp[1] == '.' &&
+	    (ap->bp[2] == '/' || ap->bp[2] == '\0')))
 		goto err;
 
 	/* Try the O_CDPATH option values. */
@@ -110,11 +110,9 @@
 			 * already tried dot, we ignore tham all.
 			 */
 			if (t < p - 1) {
-				savech = *p;
-				*p = '\0';
 				(void)snprintf(buf,
-				    sizeof(buf), "%s/%s", t, dir);
-				*p = savech;
+				    sizeof(buf), "%.*s/%s", (int)(p - t),
+					t, dir);
 				if (!chdir(buf)) {
 					if (getcwd(buf, sizeof(buf)) != NULL)
 		msgq_str(sp, M_INFO, buf, "122|New current directory: %s");
--- a/dist/nvi/ex/ex_cmd.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_cmd.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_cmd.c,v 1.2 2008/10/29 17:50:49 christos Exp $ */
+/*	$NetBSD: ex_cmd.c,v 1.2.2.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -467,5 +467,8 @@
 	    "s",
 	    "[line [,line]] ~ [cgr] [count] [#lp]",
 	    "replace previous RE with previous replacement string,"},
-	{NULL},
+	{NULL,			NULL,		0,
+	     NULL,
+	     NULL,
+	     NULL,},
 };
--- a/dist/nvi/ex/ex_cscope.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_cscope.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_cscope.c,v 1.1.1.2 2008/05/18 14:31:14 aymeric Exp $ */
+/*	$NetBSD: ex_cscope.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1994, 1996
@@ -64,17 +64,17 @@
       s: find all uses of name\n\
       t: find assignments to name"
 
-static int cscope_add __P((SCR *, EXCMD *, CHAR_T *));
-static int cscope_find __P((SCR *, EXCMD*, CHAR_T *));
-static int cscope_help __P((SCR *, EXCMD *, CHAR_T *));
-static int cscope_kill __P((SCR *, EXCMD *, CHAR_T *));
-static int cscope_reset __P((SCR *, EXCMD *, CHAR_T *));
+static int cscope_add __P((SCR *, EXCMD *, const CHAR_T *));
+static int cscope_find __P((SCR *, EXCMD*, const CHAR_T *));
+static int cscope_help __P((SCR *, EXCMD *, const CHAR_T *));
+static int cscope_kill __P((SCR *, EXCMD *, const CHAR_T *));
+static int cscope_reset __P((SCR *, EXCMD *, const CHAR_T *));
 
 typedef struct _cc {
-	char	 *name;
-	int	(*function) __P((SCR *, EXCMD *, CHAR_T *));
-	char	 *help_msg;
-	char	 *usage_msg;
+	const char	 *name;
+	int	(*function) __P((SCR *, EXCMD *, const CHAR_T *));
+	const char	 *help_msg;
+	const char	 *usage_msg;
 } CC;
 
 static CC const cscope_cmds[] = {
@@ -88,18 +88,18 @@
 	  "Kill a cscope connection", "kill number" },
 	{ "reset", cscope_reset,
 	  "Discard all current cscope connections", "reset" },
-	{ NULL }
+	{ NULL, NULL, NULL, NULL }
 };
 
-static TAGQ	*create_cs_cmd __P((SCR *, char *, size_t *));
-static int	 csc_help __P((SCR *, char *));
+static TAGQ	*create_cs_cmd __P((SCR *, const char *, size_t *));
+static int	 csc_help __P((SCR *, const char *));
 static void	 csc_file __P((SCR *,
 		    CSC *, char *, char **, size_t *, int *));
 static int	 get_paths __P((SCR *, CSC *));
-static CC const	*lookup_ccmd __P((char *));
+static CC const	*lookup_ccmd __P((const char *));
 static int	 parse __P((SCR *, CSC *, TAGQ *, int *));
 static int	 read_prompt __P((SCR *, CSC *));
-static int	 run_cscope __P((SCR *, CSC *, char *));
+static int	 run_cscope __P((SCR *, CSC *, const char *));
 static int	 start_cscopes __P((SCR *, EXCMD *));
 static int	 terminate __P((SCR *, CSC *, int));
 
@@ -117,7 +117,7 @@
 	int i;
 	CHAR_T *cmd;
 	CHAR_T *p;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	/* Initialize the default cscope directories. */
@@ -161,7 +161,7 @@
 {
 	size_t blen, len;
 	char *bp, *cscopes, *p, *t;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/*
@@ -197,15 +197,17 @@
  *	The cscope add command.
  */
 static int
-cscope_add(SCR *sp, EXCMD *cmdp, CHAR_T *dname)
+cscope_add(SCR *sp, EXCMD *cmdp, const CHAR_T *dname)
 {
 	struct stat sb;
 	EX_PRIVATE *exp;
 	CSC *csc;
 	size_t len;
 	int cur_argc;
-	char *dbname, path[MAXPATHLEN];
-	char *np;
+	const char *dbname;
+	char path[MAXPATHLEN];
+	const char *np;
+	char *npp;
 	size_t nlen;
 
 	exp = EXP(sp);
@@ -251,9 +253,10 @@
 			return (1);
 		}
 		dbname = CSCOPE_DBFILE;
-	} else if ((dbname = strrchr(np, '/')) != NULL)
-		*dbname++ = '\0';
-	else {
+	} else if ((npp = strrchr(np, '/')) != NULL) {
+		*npp = '\0';
+		dbname = npp + 1;
+	} else {
 		dbname = np;
 		np = ".";
 	}
@@ -367,7 +370,7 @@
  *	Fork off the cscope process.
  */
 static int
-run_cscope(SCR *sp, CSC *csc, char *dbname)
+run_cscope(SCR *sp, CSC *csc, const char *dbname)
 {
 	int to_cs[2], from_cs[2];
 	char cmd[MAXPATHLEN * 2];
@@ -433,7 +436,7 @@
  *	The cscope find command.
  */
 static int
-cscope_find(SCR *sp, EXCMD *cmdp, CHAR_T *pattern)
+cscope_find(SCR *sp, EXCMD *cmdp, const CHAR_T *pattern)
 {
 	CSC *csc, *csc_next;
 	EX_PRIVATE *exp;
@@ -443,7 +446,7 @@
 	db_recno_t lno;
 	size_t cno, search;
 	int force, istmp, matches;
-	char *np = NULL;
+	const char *np = NULL;
 	size_t nlen;
 
 	exp = EXP(sp);
@@ -574,7 +577,7 @@
 	if (rtp != NULL)
 		free(rtp);
 	if (np != NULL)
-		free(np);
+		free(__UNCONST(np));
 	return (1);
 }
 
@@ -583,12 +586,12 @@
  *	Build a cscope command, creating and initializing the base TAGQ.
  */
 static TAGQ *
-create_cs_cmd(SCR *sp, char *pattern, size_t *searchp)
+create_cs_cmd(SCR *sp, const char *pattern, size_t *searchp)
 {
 	CB *cbp;
 	TAGQ *tqp;
 	size_t tlen;
-	char *p;
+	const char *p;
 
 	/*
 	 * Cscope supports a "change pattern" command which we never use,
@@ -656,10 +659,10 @@
 parse(SCR *sp, CSC *csc, TAGQ *tqp, int *matchesp)
 {
 	TAG *tp;
-	db_recno_t slno;
-	size_t dlen, nlen, slen;
-	int ch, i, isolder, nlines;
-	char *dname, *name, *search, *p, *t, dummy[2], buf[2048];
+	db_recno_t slno = 0;
+	size_t dlen, nlen = 0, slen = 0;
+	int ch, i, isolder = 0, nlines;
+	char *dname = NULL, *name = NULL, *search, *p, *t, dummy[2], buf[2048];
 
 	for (;;) {
 		if (!fgets(buf, sizeof(buf), csc->from_fp))
@@ -798,9 +801,9 @@
  *	The cscope help command.
  */
 static int
-cscope_help(SCR *sp, EXCMD *cmdp, CHAR_T *subcmd)
+cscope_help(SCR *sp, EXCMD *cmdp, const CHAR_T *subcmd)
 {
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	INT2CHAR(sp, subcmd, STRLEN(subcmd) + 1, np, nlen);
@@ -812,11 +815,11 @@
  *	Display help/usage messages.
  */
 static int
-csc_help(SCR *sp, char *cmd)
+csc_help(SCR *sp, const 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);
@@ -827,6 +830,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)
@@ -839,9 +843,9 @@
  *	The cscope kill command.
  */
 static int
-cscope_kill(SCR *sp, EXCMD *cmdp, CHAR_T *cn)
+cscope_kill(SCR *sp, EXCMD *cmdp, const CHAR_T *cn)
 {
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	INT2CHAR(sp, cn, STRLEN(cn) + 1, np, nlen);
@@ -906,7 +910,7 @@
  *	The cscope reset command.
  */
 static int
-cscope_reset(SCR *sp, EXCMD *cmdp, CHAR_T *notusedp)
+cscope_reset(SCR *sp, EXCMD *cmdp, const CHAR_T *notusedp)
 {
 	EX_PRIVATE *exp;
 
@@ -999,7 +1003,7 @@
  *	Return a pointer to the command structure.
  */
 static CC const *
-lookup_ccmd(char *name)
+lookup_ccmd(const char *name)
 {
 	CC const *ccp;
 	size_t len;
--- a/dist/nvi/ex/ex_display.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_display.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_display.c,v 1.1.1.2 2008/05/18 14:31:14 aymeric Exp $ */
+/*	$NetBSD: ex_display.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -28,7 +28,7 @@
 #include "tag.h"
 
 static int	bdisplay __P((SCR *));
-static void	db __P((SCR *, CB *, u_char *));
+static void	db __P((SCR *, CB *, const char *));
 
 /*
  * ex_display -- :display b[uffers] | c[onnections] | s[creens] | t[ags]
@@ -118,12 +118,13 @@
  *	Display a buffer.
  */
 static void
-db(SCR *sp, CB *cbp, u_char *name)
+db(SCR *sp, CB *cbp, const char *np)
 {
 	CHAR_T *p;
 	GS *gp;
 	TEXT *tp;
 	size_t len;
+	const unsigned char *name = (const void *)np;
 
 	gp = sp->gp;
 	(void)ex_printf(sp, "********** %s%s\n",
@@ -132,7 +133,7 @@
 	for (tp = cbp->textq.cqh_first;
 	    tp != (void *)&cbp->textq; tp = tp->q.cqe_next) {
 		for (len = tp->len, p = tp->lb; len--; ++p) {
-			(void)ex_puts(sp, KEY_NAME(sp, *p));
+			(void)ex_puts(sp, (char *)KEY_NAME(sp, *p));
 			if (INTERRUPTED(sp))
 				return;
 		}
--- a/dist/nvi/ex/ex_edit.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_edit.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_edit.c,v 1.1.1.2 2008/05/18 14:31:14 aymeric Exp $ */
+/*	$NetBSD: ex_edit.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -52,7 +52,7 @@
 {
 	FREF *frp;
 	int attach, setalt;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	switch (cmdp->argc) {
@@ -119,8 +119,8 @@
 	/* Get a new screen. */
 	if (screen_init(sp->gp, sp, &new))
 		return (1);
-	if (cmdp->cmd == &cmds[C_VSPLIT] && vs_vsplit(sp, new) ||
-	    cmdp->cmd != &cmds[C_VSPLIT] && vs_split(sp, new, 0)) {
+	if ((cmdp->cmd == &cmds[C_VSPLIT] && vs_vsplit(sp, new)) ||
+	    (cmdp->cmd != &cmds[C_VSPLIT] && vs_split(sp, new, 0))) {
 		(void)screen_end(new);
 		return (1);
 	}
--- a/dist/nvi/ex/ex_file.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_file.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_file.c,v 1.1.1.2 2008/05/18 14:31:14 aymeric Exp $ */
+/*	$NetBSD: ex_file.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -38,7 +38,7 @@
 {
 	char *p;
 	FREF *frp;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	NEEDFILE(sp, cmdp);
--- a/dist/nvi/ex/ex_filter.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_filter.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_filter.c,v 1.1.1.2 2008/05/18 14:31:15 aymeric Exp $ */
+/*	$NetBSD: ex_filter.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -31,6 +31,57 @@
 
 static int filter_ldisplay __P((SCR *, FILE *));
 
+static pid_t
+runcmd(SCR *sp, const char *np, int* input, int *output)
+{
+	pid_t pid;
+	const char *name;
+	switch (pid = vfork()) {
+	case -1:			/* Error. */
+		msgq(sp, M_SYSERR, "vfork");
+		return -1;
+	case 0:				/* Utility. */
+		/*
+		 * Redirect stdin from the read end of the input pipe, and
+		 * redirect stdout/stderr to the write end of the output pipe.
+		 *
+		 * !!!
+		 * Historically, ex only directed stdout into the input pipe,
+		 * letting stderr come out on the terminal as usual.  Vi did
+		 * not, directing both stdout and stderr into the input pipe.
+		 * We match that practice in both ex and vi for consistency.
+		 */
+		if (input[0] != -1)
+			(void)dup2(input[0], STDIN_FILENO);
+		(void)dup2(output[1], STDOUT_FILENO);
+		(void)dup2(output[1], STDERR_FILENO);
+
+		/* Close the utility's file descriptors. */
+		if (input[0] != -1)
+			(void)close(input[0]);
+		if (input[1] != -1)
+			(void)close(input[1]);
+		(void)close(output[0]);
+		(void)close(output[1]);
+
+		if ((name = strrchr(O_STR(sp, O_SHELL), '/')) == NULL)
+			name = O_STR(sp, O_SHELL);
+		else
+			++name;
+
+		execl(O_STR(sp, O_SHELL), name, "-c", np, (char *)NULL);
+		msgq_str(sp, M_SYSERR, O_STR(sp, O_SHELL), "execl: %s");
+		_exit (127);
+		/* NOTREACHED */
+	default:			/* Parent-reader, parent-writer. */
+		/* Close the pipe ends neither parent will use. */
+		if (input[0] != -1)
+			(void)close(input[0]);
+		(void)close(output[1]);
+		return pid;
+	}
+}
+
 /*
  * ex_filter --
  *	Run a range of lines through a filter utility and optionally
@@ -47,8 +98,7 @@
 	pid_t parent_writer_pid, utility_pid;
 	db_recno_t nread;
 	int input[2], output[2], rval;
-	char *name;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	rval = 0;
@@ -97,61 +147,8 @@
 	}
 
 	/* Fork off the utility process. */
-	switch (utility_pid = vfork()) {
-	case -1:			/* Error. */
-		msgq(sp, M_SYSERR, "vfork");
-err:		if (input[0] != -1)
-			(void)close(input[0]);
-		if (input[1] != -1)
-			(void)close(input[1]);
-		if (ofp != NULL)
-			(void)fclose(ofp);
-		else if (output[0] != -1)
-			(void)close(output[0]);
-		if (output[1] != -1)
-			(void)close(output[1]);
-		return (1);
-	case 0:				/* Utility. */
-		/*
-		 * Redirect stdin from the read end of the input pipe, and
-		 * redirect stdout/stderr to the write end of the output pipe.
-		 *
-		 * !!!
-		 * Historically, ex only directed stdout into the input pipe,
-		 * letting stderr come out on the terminal as usual.  Vi did
-		 * not, directing both stdout and stderr into the input pipe.
-		 * We match that practice in both ex and vi for consistency.
-		 */
-		if (input[0] != -1)
-			(void)dup2(input[0], STDIN_FILENO);
-		(void)dup2(output[1], STDOUT_FILENO);
-		(void)dup2(output[1], STDERR_FILENO);
-
-		/* Close the utility's file descriptors. */
-		if (input[0] != -1)
-			(void)close(input[0]);
-		if (input[1] != -1)
-			(void)close(input[1]);
-		(void)close(output[0]);
-		(void)close(output[1]);
-
-		if ((name = strrchr(O_STR(sp, O_SHELL), '/')) == NULL)
-			name = O_STR(sp, O_SHELL);
-		else
-			++name;
-
-		INT2SYS(sp, cmd, STRLEN(cmd)+1, np, nlen);
-		execl(O_STR(sp, O_SHELL), name, "-c", np, (char *)NULL);
-		msgq_str(sp, M_SYSERR, O_STR(sp, O_SHELL), "execl: %s");
-		_exit (127);
-		/* NOTREACHED */
-	default:			/* Parent-reader, parent-writer. */
-		/* Close the pipe ends neither parent will use. */
-		if (input[0] != -1)
-			(void)close(input[0]);
-		(void)close(output[1]);
-		break;
-	}
+	INT2SYS(sp, cmd, STRLEN(cmd)+1, np, nlen);
+	utility_pid = runcmd(sp, np, input, output);
 
 	/*
 	 * FILTER_RBANG, FILTER_READ:
@@ -179,11 +176,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;
 	}
 
@@ -288,6 +286,17 @@
 uwait:	INT2CHAR(sp, cmd, STRLEN(cmd) + 1, np, nlen);
 	return (proc_wait(sp, (long)utility_pid, np,
 	    ftype == FILTER_READ && F_ISSET(sp, SC_VI) ? 1 : 0, 0) || rval);
+err:	if (input[0] != -1)
+		(void)close(input[0]);
+	if (input[1] != -1)
+		(void)close(input[1]);
+	if (ofp != NULL)
+		(void)fclose(ofp);
+	else if (output[0] != -1)
+		(void)close(output[0]);
+	if (output[1] != -1)
+		(void)close(output[1]);
+	return 1;
 }
 
 /*
@@ -303,7 +312,7 @@
 {
 	size_t len;
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 
 	EX_PRIVATE *exp;
 
--- a/dist/nvi/ex/ex_global.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_global.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_global.c,v 1.1.1.2 2008/05/18 14:31:15 aymeric Exp $ */
+/*	$NetBSD: ex_global.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -67,7 +67,7 @@
 {
 	CHAR_T *ptrn, *p, *t;
 	EXCMD *ecp;
-	MARK abs;
+	MARK myabs;
 	RANGE *rp;
 	busy_t btype;
 	db_recno_t start, end;
@@ -118,11 +118,12 @@
 			*t = L('\0');
 			break;
 		}
-		if (p[0] == L('\\'))
+		if (p[0] == L('\\')) {
 			if (p[1] == delim)
 				++p;
 			else if (p[1] == L('\\'))
 				*t++ = *p++;
+		}
 		*t++ = *p++;
 	}
 
@@ -153,9 +154,9 @@
 	re = &sp->re_c;
 
 	/* The global commands always set the previous context mark. */
-	abs.lno = sp->lno;
-	abs.cno = sp->cno;
-	if (mark_set(sp, ABSMARK1, &abs, 1))
+	myabs.lno = sp->lno;
+	myabs.cno = sp->cno;
+	if (mark_set(sp, ABSMARK1, &myabs, 1))
 		return (1);
 
 	/* Get an EXCMD structure. */
@@ -170,7 +171,7 @@
 	 * parsing it.
 	 */
 	if ((len = cmdp->argv[0]->len - (p - cmdp->argv[0]->bp)) == 0) {
-		p = L("p");
+		p = __UNCONST(L("p"));
 		len = 1;
 	}
 
--- a/dist/nvi/ex/ex_init.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_init.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_init.c,v 1.1.1.2 2008/05/18 14:31:16 aymeric Exp $ */
+/*	$NetBSD: ex_init.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -33,9 +33,9 @@
 #include "pathnames.h"
 
 enum rc { NOEXIST, NOPERM, RCOK };
-static enum rc	exrc_isok __P((SCR *, struct stat *, char *, int, int));
+static enum rc	exrc_isok __P((SCR *, struct stat *, const char *, int, int));
 
-static int ex_run_file __P((SCR *, char *));
+static int ex_run_file __P((SCR *, const char *));
 
 /*
  * ex_screen_copy --
@@ -117,10 +117,10 @@
  * ex_optchange --
  *	Handle change of options for ex.
  *
- * PUBLIC: int ex_optchange __P((SCR *, int, char *, u_long *));
+ * PUBLIC: int ex_optchange __P((SCR *, int, const char *, u_long *));
  */
 int
-ex_optchange(SCR *sp, int offset, char *str, u_long *valp)
+ex_optchange(SCR *sp, int offset, const char *str, u_long *valp)
 {
 	switch (offset) {
 	case O_TAGS:
@@ -141,7 +141,7 @@
 {
 	struct stat hsb, lsb;
 	char *p, path[MAXPATHLEN];
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/*
@@ -251,10 +251,10 @@
  *	Set up a file of ex commands to run.
  */
 static int
-ex_run_file(SCR *sp, char *name)
+ex_run_file(SCR *sp, const char *name)
 {
 	EXCMD cmd;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	ex_cinit(sp, &cmd, C_SOURCE, 0, OOBLNO, OOBLNO, 0);
@@ -270,7 +270,7 @@
  * PUBLIC: int ex_run_str __P((SCR *, char *, CHAR_T *, size_t, int, int));
  */
 int
-ex_run_str(SCR *sp, char *name, CHAR_T *str, size_t len, int ex_flags, int nocopy)
+ex_run_str(SCR *sp, const char *name, const CHAR_T *str, size_t len, int ex_flags, int nocopy)
 {
 	WIN *wp;
 	EXCMD *ecp;
@@ -286,7 +286,7 @@
 	    ex_flags ? E_BLIGNORE | E_NOAUTO | E_NOPRDEF | E_VLITONLY : 0);
 
 	if (nocopy)
-		ecp->cp = str;
+		ecp->cp = __UNCONST(str);
 	else
 		if ((ecp->cp = v_wstrdup(sp, str, len)) == NULL)
 			return (1);
@@ -341,7 +341,7 @@
  * files.
  */
 static enum rc
-exrc_isok(SCR *sp, struct stat *sbp, char *path, int rootown, int rootid)
+exrc_isok(SCR *sp, struct stat *sbp, const char *path, int rootown, int rootid)
 {
 	enum { ROOTOWN, OWN, WRITER } etype;
 	uid_t euid;
--- a/dist/nvi/ex/ex_join.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_join.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_join.c,v 1.1.1.2 2008/05/18 14:31:16 aymeric Exp $ */
+/*	$NetBSD: ex_join.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -38,8 +38,8 @@
 {
 	db_recno_t from, to;
 	size_t blen, clen, len, tlen;
-	int echar, extra, first;
-	CHAR_T *bp, *tbp;
+	int echar = 0, extra, first;
+	CHAR_T *bp, *tbp = NULL;
 	CHAR_T *p;
 
 	NEEDFILE(sp, cmdp);
--- a/dist/nvi/ex/ex_mkexrc.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_mkexrc.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_mkexrc.c,v 1.1.1.2 2008/05/18 14:31:16 aymeric Exp $ */
+/*	$NetBSD: ex_mkexrc.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -44,14 +44,12 @@
 	struct stat sb;
 	FILE *fp;
 	int fd, sverrno;
-	char *fname;
+	const char *fname;
 	size_t flen;
 
 	switch (cmdp->argc) {
 	case 0:
 		fname = _PATH_EXRC;
-		break;
-	case 1:
 		INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1, 
 			    fname, flen);
 		set_alt_name(sp, fname);
--- a/dist/nvi/ex/ex_preserve.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_preserve.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_preserve.c,v 1.1.1.2 2008/05/18 14:31:09 aymeric Exp $ */
+/*	$NetBSD: ex_preserve.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -71,7 +71,7 @@
 {
 	ARGS *ap;
 	FREF *frp;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	ap = cmdp->argv[0];
--- a/dist/nvi/ex/ex_print.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_print.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_print.c,v 1.1.1.2 2008/05/18 14:31:17 aymeric Exp $ */
+/*	$NetBSD: ex_print.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -100,10 +100,9 @@
 	GS *gp;
 	db_recno_t from, to;
 	size_t col, len;
-	CHAR_T *p;
+	const CHAR_T *p;
 	CHAR_T buf[10];
-	CHAR_T *wp;
-	size_t wlen;
+	CHAR_T *q;
 
 	NEEDFILE(sp, cmdp);
 
@@ -131,8 +130,9 @@
 		 * especially in handling end-of-line tabs, but they're almost
 		 * backward compatible.
 		 */
-		if (db_get(sp, from, DBG_FATAL, &p, &len))
+		if (db_get(sp, from, DBG_FATAL, &q, &len))
 			return (1);
+		p = q;
 
 		if (len == 0 && !LF_ISSET(E_C_LIST))
 			(void)ex_puts(sp, "\n");
@@ -175,7 +175,8 @@
 int
 ex_scprint(SCR *sp, MARK *fp, MARK *tp)
 {
-	CHAR_T *p;
+	const CHAR_T *p;
+	CHAR_T *q;
 	size_t col, len;
 
 	col = 0;
@@ -185,8 +186,9 @@
 			return (1);
 	}
 
-	if (db_get(sp, fp->lno, DBG_FATAL, &p, &len))
+	if (db_get(sp, fp->lno, DBG_FATAL, &q, &len))
 		return (1);
+	p = q;
 
 	if (ex_prchars(sp, p, &col, fp->cno, 0, ' '))
 		return (1);
@@ -212,7 +214,7 @@
 	    u_int flags, int repeatc)
 {
 	CHAR_T ch;
-	char *kp;
+	const char *kp;
 	GS *gp;
 	size_t col, tlen, ts;
 
@@ -236,7 +238,7 @@
 			    str[0] = ch;
 			    INT2CHAR(sp, str, 2, kp, tlen);
 			} else {
-			    kp = KEY_NAME(sp, ch);
+			    kp = (char *)KEY_NAME(sp, ch);
 			    tlen = KEY_LEN(sp, ch);
 			}
 			if (!repeatc  && col + tlen < sp->cols) {
@@ -277,7 +279,6 @@
 	EX_PRIVATE *exp;
 	va_list ap;
 	size_t n;
-	CHAR_T *kp;
 
 	exp = EXP(sp);
 
--- a/dist/nvi/ex/ex_read.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_read.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_read.c,v 1.1.1.2 2008/05/18 14:31:17 aymeric Exp $ */
+/*	$NetBSD: ex_read.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -46,8 +46,8 @@
 {
 	enum { R_ARG, R_EXPANDARG, R_FILTER } which;
 	struct stat sb;
-	CHAR_T *arg;
-	char *name;
+	CHAR_T *arg = NULL;
+	const char *name;
 	size_t nlen;
 	EX_PRIVATE *exp;
 	FILE *fp;
@@ -55,10 +55,9 @@
 	GS *gp;
 	MARK rm;
 	db_recno_t nlines;
-	size_t arglen;
+	size_t arglen = 0;
 	int argc, rval;
 	char *p;
-	char *np;
 
 	gp = sp->gp;
 
@@ -298,7 +297,7 @@
  * PUBLIC: int ex_readfp __P((SCR *, char *, FILE *, MARK *, db_recno_t *, int));
  */
 int
-ex_readfp(SCR *sp, char *name, FILE *fp, MARK *fm, db_recno_t *nlinesp, int silent)
+ex_readfp(SCR *sp, const char *name, FILE *fp, MARK *fm, db_recno_t *nlinesp, int silent)
 {
 	EX_PRIVATE *exp;
 	GS *gp;
@@ -306,9 +305,9 @@
 	size_t len;
 	u_long ccnt;			/* XXX: can't print off_t portably. */
 	int nf, rval;
-	char *p;
+	const char *p;
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 
 	gp = sp->gp;
 	exp = EXP(sp);
@@ -344,11 +343,11 @@
 		*nlinesp = lcnt;
 
 	if (!silent) {
-		p = msg_print(sp, name, &nf);
+		char *q = msg_print(sp, name, &nf);
 		msgq(sp, M_INFO,
-		    "148|%s: %lu lines, %lu characters", p, lcnt, ccnt);
+		    "148|%s: %lu lines, %lu characters", q, lcnt, ccnt);
 		if (nf)
-			FREE_SPACE(sp, p, 0);
+			FREE_SPACE(sp, q, 0);
 	}
 
 	rval = 0;
--- a/dist/nvi/ex/ex_script.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_script.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_script.c,v 1.2 2008/05/20 17:55:05 aymeric Exp $ */
+/*	$NetBSD: ex_script.c,v 1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -90,7 +90,7 @@
 sscr_init(SCR *sp)
 {
 	SCRIPT *sc;
-	char *sh, *sh_path;
+	const char *sh, *sh_path;
 
 	/* We're going to need a shell. */
 	if (opts_empty(sp, O_SHELL, 0))
@@ -303,7 +303,7 @@
 	db_recno_t last_lno;
 	size_t blen, len, last_len, tlen;
 	int isempty, matchprompt, nw, rval;
-	CHAR_T *bp;
+	CHAR_T *bp = NULL;
 	CHAR_T *p;
 
 	/* If there's a prompt on the last line, append the command. */
@@ -470,7 +470,7 @@
 	SCRIPT *sc;
 	fd_set rdfd;
 	db_recno_t lno;
-	size_t blen, len, tlen;
+	size_t blen, len = 0, tlen;
 	u_int value;
 	int nr, rval;
 	CHAR_T *bp;
@@ -555,7 +555,7 @@
 sscr_setprompt(SCR *sp, CHAR_T *buf, size_t len)
 {
 	SCRIPT *sc;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	sc = sp->script;
@@ -673,7 +673,7 @@
 static int
 sscr_pty(int *amaster, int *aslave, char *name, struct termios *termp, void *winp)
 {
-	int master, slave, ttygid;
+	int master, slave;
 
 	/* open master terminal */
 	if ((master = ptym_open(name)) < 0)  {
@@ -708,7 +708,7 @@
 ptym_open(char *pts_name)
 {
 	int fdm;
-	char *ptr, *ptsname();
+	char *ptr;
 
 	strcpy(pts_name, _PATH_SYSV_PTY);
 	if ((fdm = open(pts_name, O_RDWR)) < 0 )
--- a/dist/nvi/ex/ex_shell.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_shell.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_shell.c,v 1.1.1.2 2008/05/18 14:31:17 aymeric Exp $ */
+/*	$NetBSD: ex_shell.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -78,10 +78,10 @@
  * ex_exec_proc --
  *	Run a separate process.
  *
- * PUBLIC: int ex_exec_proc __P((SCR *, EXCMD *, char *, const char *, int));
+ * PUBLIC: int ex_exec_proc __P((SCR *, EXCMD *, const char *, const char *, int));
  */
 int
-ex_exec_proc(SCR *sp, EXCMD *cmdp, char *cmd, const char *msg, int need_newline)
+ex_exec_proc(SCR *sp, EXCMD *cmdp, const char *cmd, const char *msg, int need_newline)
 {
 	GS *gp;
 	const char *name;
@@ -212,141 +212,141 @@
  */
 typedef struct _sigs {
 	int	 number;		/* signal number */
-	char	*message;		/* related message */
+	const char *message;		/* related message */
 } SIGS;
 
 SIGS const sigs[] = {
 #ifdef SIGABRT
-	SIGABRT,	"Abort trap",
+	{ SIGABRT,	"Abort trap" },
 #endif
 #ifdef SIGALRM
-	SIGALRM,	"Alarm clock",
+	{ SIGALRM,	"Alarm clock" },
 #endif
 #ifdef SIGBUS
-	SIGBUS,		"Bus error",
+	{ SIGBUS,		"Bus error" },
 #endif
 #ifdef SIGCLD
-	SIGCLD,		"Child exited or stopped",
+	{ SIGCLD,		"Child exited or stopped" },
 #endif
 #ifdef SIGCHLD
-	SIGCHLD,	"Child exited",
+	{ SIGCHLD,	"Child exited" },
 #endif
 #ifdef SIGCONT
-	SIGCONT,	"Continued",
+	{ SIGCONT,	"Continued" },
 #endif
 #ifdef SIGDANGER
-	SIGDANGER,	"System crash imminent",
+	{ SIGDANGER,	"System crash imminent" },
 #endif
 #ifdef SIGEMT
-	SIGEMT,		"EMT trap",
+	{ SIGEMT,		"EMT trap" },
 #endif
 #ifdef SIGFPE
-	SIGFPE,		"Floating point exception",
+	{ SIGFPE,		"Floating point exception" },
 #endif
 #ifdef SIGGRANT
-	SIGGRANT,	"HFT monitor mode granted",
+	{ SIGGRANT,	"HFT monitor mode granted" },
 #endif
 #ifdef SIGHUP
-	SIGHUP,		"Hangup",
+	{ SIGHUP,		"Hangup" },
 #endif
 #ifdef SIGILL
-	SIGILL,		"Illegal instruction",
+	{ SIGILL,		"Illegal instruction" },
 #endif
 #ifdef SIGINFO
-	SIGINFO,	"Information request",
+	{ SIGINFO,	"Information request" },
 #endif
 #ifdef SIGINT
-	SIGINT,		"Interrupt",
+	{ SIGINT,		"Interrupt" },
 #endif
 #ifdef SIGIO
-	SIGIO,		"I/O possible",
+	{ SIGIO,		"I/O possible" },
 #endif
 #ifdef SIGIOT
-	SIGIOT,		"IOT trap",
+	{ SIGIOT,		"IOT trap" },
 #endif
 #ifdef SIGKILL
-	SIGKILL,	"Killed",
+	{ SIGKILL,	"Killed" },
 #endif
 #ifdef SIGLOST
-	SIGLOST,	"Record lock",
+	{ SIGLOST,	"Record lock" },
 #endif
 #ifdef SIGMIGRATE
-	SIGMIGRATE,	"Migrate process to another CPU",
+	{ SIGMIGRATE,	"Migrate process to another CPU" },
 #endif
 #ifdef SIGMSG
-	SIGMSG,		"HFT input data pending",
+	{ SIGMSG,		"HFT input data pending" },
 #endif
 #ifdef SIGPIPE
-	SIGPIPE,	"Broken pipe",
+	{ SIGPIPE,	"Broken pipe" },
 #endif
 #ifdef SIGPOLL
-	SIGPOLL,	"I/O possible",
+	{ SIGPOLL,	"I/O possible" },
 #endif
 #ifdef SIGPRE
-	SIGPRE,		"Programming error",
+	{ SIGPRE,		"Programming error" },
 #endif
 #ifdef SIGPROF
-	SIGPROF,	"Profiling timer expired",
+	{ SIGPROF,	"Profiling timer expired" },
 #endif
 #ifdef SIGPWR
-	SIGPWR,		"Power failure imminent",
+	{ SIGPWR,		"Power failure imminent" },
 #endif
 #ifdef SIGRETRACT
-	SIGRETRACT,	"HFT monitor mode retracted",
+	{ SIGRETRACT,	"HFT monitor mode retracted" },
 #endif
 #ifdef SIGQUIT
-	SIGQUIT,	"Quit",
+	{ SIGQUIT,	"Quit" },
 #endif
 #ifdef SIGSAK
-	SIGSAK,		"Secure Attention Key",
+	{ SIGSAK,		"Secure Attention Key" },
 #endif
 #ifdef SIGSEGV
-	SIGSEGV,	"Segmentation fault",
+	{ SIGSEGV,	"Segmentation fault" },
 #endif
 #ifdef SIGSOUND
-	SIGSOUND,	"HFT sound sequence completed",
+	{ SIGSOUND,	"HFT sound sequence completed" },
 #endif
 #ifdef SIGSTOP
-	SIGSTOP,	"Suspended (signal)",
+	{ SIGSTOP,	"Suspended (signal)" },
 #endif
 #ifdef SIGSYS
-	SIGSYS,		"Bad system call",
+	{ SIGSYS,		"Bad system call" },
 #endif
 #ifdef SIGTERM
-	SIGTERM,	"Terminated",
+	{ SIGTERM,	"Terminated" },
 #endif
 #ifdef SIGTRAP
-	SIGTRAP,	"Trace/BPT trap",
+	{ SIGTRAP,	"Trace/BPT trap" },
 #endif
 #ifdef SIGTSTP
-	SIGTSTP,	"Suspended",
+	{ SIGTSTP,	"Suspended" },
 #endif
 #ifdef SIGTTIN
-	SIGTTIN,	"Stopped (tty input)",
+	{ SIGTTIN,	"Stopped (tty input)" },
 #endif
 #ifdef SIGTTOU
-	SIGTTOU,	"Stopped (tty output)",
+	{ SIGTTOU,	"Stopped (tty output)" },
 #endif
 #ifdef SIGURG
-	SIGURG,		"Urgent I/O condition",
+	{ SIGURG,		"Urgent I/O condition" },
 #endif
 #ifdef SIGUSR1
-	SIGUSR1,	"User defined signal 1",
+	{ SIGUSR1,	"User defined signal 1" },
 #endif
 #ifdef SIGUSR2
-	SIGUSR2,	"User defined signal 2",
+	{ SIGUSR2,	"User defined signal 2" },
 #endif
 #ifdef SIGVTALRM
-	SIGVTALRM,	"Virtual timer expired",
+	{ SIGVTALRM,	"Virtual timer expired" },
 #endif
 #ifdef SIGWINCH
-	SIGWINCH,	"Window size changes",
+	{ SIGWINCH,	"Window size changes" },
 #endif
 #ifdef SIGXCPU
-	SIGXCPU,	"Cputime limit exceeded",
+	{ SIGXCPU,	"Cputime limit exceeded" },
 #endif
 #ifdef SIGXFSZ
-	SIGXFSZ,	"Filesize limit exceeded",
+	{ SIGXFSZ,	"Filesize limit exceeded" },
 #endif
 };
 
--- a/dist/nvi/ex/ex_source.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_source.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_source.c,v 1.1.1.2 2008/05/18 14:31:18 aymeric Exp $ */
+/*	$NetBSD: ex_source.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -42,9 +42,10 @@
 	struct stat sb;
 	int fd, len;
 	char *bp;
-	char *name;
+	const char *name;
 	size_t nlen;
-	CHAR_T *wp, *dp;
+	const CHAR_T *wp;
+	CHAR_T *dp;
 	size_t wlen;
 
 	INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1, name, nlen);
--- a/dist/nvi/ex/ex_subst.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_subst.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_subst.c,v 1.1.1.2 2008/05/18 14:31:19 aymeric Exp $ */
+/*	$NetBSD: ex_subst.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -121,11 +121,12 @@
 			*t = '\0';
 			break;
 		}
-		if (p[0] == '\\')
+		if (p[0] == '\\') {
 			if (p[1] == delim)
 				++p;
 			else if (p[1] == '\\')
 				*t++ = *p++;
+		}
 		*t++ = *p++;
 	}
 
@@ -342,7 +343,7 @@
 }
 
 static int
-s(SCR *sp, EXCMD *cmdp, CHAR_T *s, regex_t *re, u_int flags)
+s(SCR *sp, EXCMD *cmdp, CHAR_T *st, regex_t *re, u_int flags)
 {
 	EVENT ev;
 	MARK from, to;
@@ -355,7 +356,7 @@
 	int cflag, lflag, nflag, pflag, rflag;
 	int didsub, do_eol_match, eflags, empty_ok, eval;
 	int linechanged, matched, quit, rval;
-	CHAR_T *p, *lb, *bp;
+	CHAR_T *lb, *bp;
 	enum nresult nret;
 
 	NEEDFILE(sp, cmdp);
@@ -391,10 +392,10 @@
 	 * usage statement doesn't reflect this.)
 	 */
 	cflag = lflag = nflag = pflag = rflag = 0;
-	if (s == NULL)
+	if (st == NULL)
 		goto noargs;
-	for (lno = OOBLNO; *s != '\0'; ++s)
-		switch (*s) {
+	for (lno = OOBLNO; *st != '\0'; ++st)
+		switch (*st) {
 		case ' ':
 		case '\t':
 			continue;
@@ -409,10 +410,10 @@
 			if (lno != OOBLNO)
 				goto usage;
 			errno = 0;
-			nret = nget_uslong(sp, &ul, s, &s, 10);
+			nret = nget_uslong(sp, &ul, st, &st, 10);
 			lno = ul;
-			if (*s == '\0')		/* Loop increment correction. */
-				--s;
+			if (*st == '\0')		/* Loop increment correction. */
+				--st;
 			if (nret != NUM_OK) {
 				if (nret == NUM_OVER)
 					msgq(sp, M_ERR, "153|Count overflow");
@@ -470,7 +471,7 @@
 			goto usage;
 		}
 
-	if (*s != '\0' || !rflag && LF_ISSET(SUB_MUSTSETR)) {
+	if (*st != '\0' || (!rflag && LF_ISSET(SUB_MUSTSETR))) {
 usage:		ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
 		return (1);
 	}
@@ -501,7 +502,7 @@
 			break;
 
 		/* Get the line. */
-		if (db_get(sp, lno, DBG_FATAL, &s, &llen))
+		if (db_get(sp, lno, DBG_FATAL, &st, &llen))
 			goto err;
 
 		/*
@@ -513,8 +514,8 @@
 				GET_SPACE_RETW(sp, bp, blen, llen);
 			} else
 				ADD_SPACE_RETW(sp, bp, blen, llen);
-			MEMCPYW(bp, s, llen);
-			s = bp;
+			MEMCPYW(bp, st, llen);
+			st = bp;
 		}
 
 		/* Start searching from the beginning. */
@@ -542,7 +543,7 @@
 		eflags = REG_STARTEND;
 
 		/*
-		 * The search area is from s + offset to the EOL.
+		 * The search area is from st + offset to the EOL.
 		 *
 		 * Generally, match[0].rm_so is the offset of the start
 		 * of the match from the start of the search, and offset
@@ -552,7 +553,7 @@
 		match[0].rm_eo = len;
 
 		/* Get the next match. */
-		eval = regexec(re, s + offset, 10, match, eflags);
+		eval = regexec(re, st + offset, 10, match, eflags);
 
 		/*
 		 * There wasn't a match or if there was an error, deal with
@@ -594,7 +595,7 @@
 			empty_ok = 1;
 			if (len == 0)
 				goto endmatch;
-			BUILD(sp, s + offset, 1)
+			BUILD(sp, st + offset, 1)
 			++offset;
 			--len;
 			goto nextmatch;
@@ -666,7 +667,7 @@
 			default:
 			case CH_NO:
 				didsub = 0;
-				BUILD(sp, s +offset, match[0].rm_eo);
+				BUILD(sp, st + offset, match[0].rm_eo);
 				goto skip;
 			case CH_QUIT:
 				/* Set the quit/interrupted flags. */
@@ -689,11 +690,11 @@
 		sp->cno = match[0].rm_so;
 
 		/* Copy the bytes before the match into the build buffer. */
-		BUILD(sp, s + offset, match[0].rm_so);
+		BUILD(sp, st + offset, match[0].rm_so);
 
 		/* Substitute the matching bytes. */
 		didsub = 1;
-		if (re_sub(sp, s + offset, &lb, &lbclen, &lblen, match))
+		if (re_sub(sp, st + offset, &lb, &lbclen, &lblen, match))
 			goto err;
 
 		/* Set the change flag so we know this line was modified. */
@@ -720,7 +721,7 @@
 
 			/* Copy the rest of the line. */
 			if (len)
-				BUILD(sp, s + offset, len)
+				BUILD(sp, st + offset, len)
 
 			/* Set the new offset. */
 			offset = saved_offset;
@@ -744,16 +745,16 @@
 			/* Store and retrieve the line. */
 			if (db_set(sp, lno, lb + last, lbclen))
 				goto err;
-			if (db_get(sp, lno, DBG_FATAL, &s, &llen))
+			if (db_get(sp, lno, DBG_FATAL, &st, &llen))
 				goto err;
 			ADD_SPACE_RETW(sp, bp, blen, llen)
-			MEMCPYW(bp, s, llen);
-			s = bp;
+			MEMCPYW(bp, st, llen);
+			st = bp;
 			len = llen - offset;
 
 			/* Restart the build. */
 			lbclen = 0;
-			BUILD(sp, s, offset);
+			BUILD(sp, st, offset);
 
 			/*
 			 * If we haven't already done the after-the-string
@@ -789,7 +790,7 @@
 
 		/* Copy any remaining bytes into the build buffer. */
 		if (len)
-			BUILD(sp, s + offset, len)
+			BUILD(sp, st + offset, len)
 
 		/* Store inserted lines, adjusting the build buffer. */
 		last = 0;
@@ -1238,7 +1239,7 @@
 	size_t blen, len, nspaces;
 	CHAR_T *bp, *t;
 	CHAR_T *p;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/*
@@ -1297,14 +1298,14 @@
 void
 re_error(SCR *sp, int errcode, regex_t *preg)
 {
-	size_t s;
+	size_t sz;
 	char *oe;
 
-	s = regerror(errcode, preg, "", 0);
-	if ((oe = malloc(s)) == NULL)
+	sz = regerror(errcode, preg, NULL, 0);
+	if ((oe = malloc(sz)) == NULL)
 		msgq(sp, M_SYSERR, NULL);
 	else {
-		(void)regerror(errcode, preg, oe, s);
+		(void)regerror(errcode, preg, oe, sz);
 		msgq(sp, M_ERR, "RE error: %s", oe);
 		free(oe);
 	}
@@ -1322,7 +1323,7 @@
 	                         
 	                     
 {
-	enum { C_NOTSET, C_LOWER, C_ONELOWER, C_ONEUPPER, C_UPPER } conv;
+	enum { C_NOT_SET, C_LOWER, C_ONE_LOWER, C_ONE_UPPER, C_UPPER } conv;
 	size_t lbclen, lblen;		/* Local copies. */
 	size_t mlen;			/* Match length. */
 	size_t rpl;			/* Remaining replacement length. */
@@ -1359,17 +1360,17 @@
 	if (nltrans && (__value == K_CR || __value == K_NL)) {		\
 		NEEDNEWLINE(sp);					\
 		sp->newl[sp->newl_cnt++] = lbclen;			\
-	} else if (conv != C_NOTSET) {					\
+	} else if (conv != C_NOT_SET) {					\
 		switch (conv) {						\
-		case C_ONELOWER:					\
-			conv = C_NOTSET;				\
+		case C_ONE_LOWER:					\
+			conv = C_NOT_SET;				\
 			/* FALLTHROUGH */				\
 		case C_LOWER:						\
 			if (isupper(__ch))				\
 				__ch = tolower(__ch);			\
 			break;						\
-		case C_ONEUPPER:					\
-			conv = C_NOTSET;				\
+		case C_ONE_UPPER:					\
+			conv = C_NOT_SET;				\
 			/* FALLTHROUGH */				\
 		case C_UPPER:						\
 			if (islower(__ch))				\
@@ -1383,7 +1384,7 @@
 	*p++ = __ch;							\
 	++lbclen;							\
 }
-	conv = C_NOTSET;
+	conv = C_NOT_SET;
 	for (rp = sp->repl, rpl = sp->repl_len, p = lb + lbclen; rpl--;) {
 		switch (ch = *rp++) {
 		case '&':
@@ -1417,11 +1418,11 @@
 			case 'e':
 			case 'E':
 				++rp;
-				conv = C_NOTSET;
+				conv = C_NOT_SET;
 				continue;
 			case 'l':
 				++rp;
-				conv = C_ONELOWER;
+				conv = C_ONE_LOWER;
 				continue;
 			case 'L':
 				++rp;
@@ -1429,7 +1430,7 @@
 				continue;
 			case 'u':
 				++rp;
-				conv = C_ONEUPPER;
+				conv = C_ONE_UPPER;
 				continue;
 			case 'U':
 				++rp;
--- a/dist/nvi/ex/ex_tag.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_tag.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_tag.c,v 1.3 2008/10/29 19:57:27 christos Exp $ */
+/*	$NetBSD: ex_tag.c,v 1.3.2.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -68,7 +68,7 @@
  * PUBLIC: int ex_tag_first __P((SCR *, CHAR_T *));
  */
 int
-ex_tag_first(SCR *sp, CHAR_T *tagarg)
+ex_tag_first(SCR *sp, const CHAR_T *tagarg)
 {
 	EXCMD cmd;
 
@@ -181,7 +181,7 @@
 	EX_PRIVATE *exp;
 	TAG *tp;
 	TAGQ *tqp;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	exp = EXP(sp);
@@ -221,7 +221,7 @@
 	EX_PRIVATE *exp;
 	TAG *tp;
 	TAGQ *tqp;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	exp = EXP(sp);
@@ -351,7 +351,8 @@
 	TAGQ *tqp, *dtqp;
 	size_t arglen;
 	long off;
-	char *arg, *p, *t;
+	const char *arg;
+	char *p, *t;
 	size_t nlen;
 
 	/* Check for an empty stack. */
@@ -757,7 +758,7 @@
 	db_recno_t lno;
 	size_t cno;
 	int istmp;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	exp = EXP(sp);
@@ -787,8 +788,7 @@
 	frp = sp->frp;
 	lno = sp->lno;
 	cno = sp->cno;
-	istmp = frp == NULL ||
-	    F_ISSET(frp, FR_TMPFILE) && !new_screen;
+	istmp = frp == NULL || (F_ISSET(frp, FR_TMPFILE) && !new_screen);
 
 	/* Try to switch to the tag. */
 	if (new_screen) {
@@ -882,15 +882,15 @@
  * ex_tagf_alloc --
  *	Create a new list of ctag files.
  *
- * PUBLIC: int ex_tagf_alloc __P((SCR *, char *));
+ * PUBLIC: int ex_tagf_alloc __P((SCR *, const char *));
  */
 int
-ex_tagf_alloc(SCR *sp, char *str)
+ex_tagf_alloc(SCR *sp, const char *str)
 {
 	EX_PRIVATE *exp;
 	TAGF *tfp;
 	size_t len;
-	char *p, *t;
+	const char *p, *t;
 
 	/* Free current queue. */
 	exp = EXP(sp);
@@ -953,7 +953,7 @@
 {
 	MARK m;
 	char *p;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	/*
@@ -1027,27 +1027,27 @@
 {
 	char *p = buf;
 
-	for (*tag = p; *p && !isspace(*p); p++)		/* tag name */
+	for (*tag = p; *p && !isspace((unsigned char)*p); p++)	/* tag name */
 		;
 	if (*p == 0)
 		goto err;
 	*p++ = 0;
-	for (; *p && isspace(*p); p++)			/* (skip blanks) */
+	for (; *p && isspace((unsigned char)*p); p++)	/* (skip blanks) */
 		;
 	if (*p == 0)
 		goto err;
 	*line = p;					/* line no */
-	for (*line = p; *p && !isspace(*p); p++)
+	for (*line = p; *p && !isspace((unsigned char)*p); p++)
 		;
 	if (*p == 0)
 		goto err;
 	*p++ = 0;
-	for (; *p && isspace(*p); p++)			/* (skip blanks) */
+	for (; *p && isspace((unsigned char)*p); p++)	/* (skip blanks) */
 		;
 	if (*p == 0)
 		goto err;
 	*file = p;					/* file name */
-	for (*file = p; *p && !isspace(*p); p++)
+	for (*file = p; *p && !isspace((unsigned char)*p); p++)
 		;
 	if (*p == 0)
 		goto err;
@@ -1067,17 +1067,15 @@
 static TAGQ *
 gtag_slist(SCR *sp, CHAR_T *tag, int ref)
 {
-	EX_PRIVATE *exp;
-	TAGF *tfp;
 	TAGQ *tqp;
 	size_t len, nlen, slen, wlen;
 	int echk;
 	TAG *tp;
-	char *np;
+	const char *np;
 	char *name, *file, *search;
 	char command[BUFSIZ];
 	char buf[BUFSIZ];
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	FILE *fp;
 
 	/* Allocate and initialize the tag queue structure. */
@@ -1094,7 +1092,7 @@
 	 */
 	snprintf(command, sizeof(command), "global -%s '%s'", ref ? "rx" : "x",
 	    np);
-	if (fp = popen(command, "r")) {
+	if ((fp = popen(command, "r")) != NULL) {
 		while (fgets(buf, sizeof(buf), fp)) {
 			if (buf[strlen(buf)-1] == '\n')		/* chop(buf) */
 				buf[strlen(buf)-1] = 0;
@@ -1103,7 +1101,6 @@
 					;
 			if (getentry(buf, &name, &file, &search) == 0) {
 				echk = 1;
-				F_SET(tfp, TAGF_ERR);
 				break;
 			}
 			slen = strlen(search);
@@ -1148,7 +1145,7 @@
 	TAGQ *tqp;
 	size_t len;
 	int echk;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	exp = EXP(sp);
@@ -1205,10 +1202,11 @@
 {
 	struct stat sb;
 	TAG *tp;
-	size_t dlen, nlen, slen;
+	size_t dlen, nlen = 0, slen;
 	int fd, i, nf1, nf2;
-	char *back, *cname, *dname, *front, *map, *name, *p, *search, *t;
-	CHAR_T *wp;
+	char *back, *front, *map, *p, *search, *t;
+	char *cname = NULL, *dname = NULL, *name = NULL;
+	const CHAR_T *wp;
 	size_t wlen;
 	long tl;
 
--- a/dist/nvi/ex/ex_txt.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_txt.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_txt.c,v 1.1.1.2 2008/05/18 14:31:20 aymeric Exp $ */
+/*	$NetBSD: ex_txt.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -392,8 +392,8 @@
 			++scno;
 
 	/* Get the previous shiftwidth column. */
-	cno = scno;
-	scno -= --scno % sw;
+	cno = scno--;
+	scno -= scno % sw;
 
 	/*
 	 * Since we don't know what comes before the character(s) being
--- a/dist/nvi/ex/ex_usage.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_usage.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_usage.c,v 1.1.1.2 2008/05/18 14:31:20 aymeric Exp $ */
+/*	$NetBSD: ex_usage.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -62,7 +62,8 @@
 	ARGS *ap;
 	EXCMDLIST const *cp;
 	int newscreen;
-	CHAR_T *name, *p, nb[MAXCMDNAMELEN + 5];
+	CHAR_T *p, nb[MAXCMDNAMELEN + 5];
+	const CHAR_T *name;
 
 	switch (cmdp->argc) {
 	case 1:
@@ -75,7 +76,7 @@
 		for (cp = cmds; cp->name != NULL &&
 		    memcmp(ap->bp, cp->name, ap->len); ++cp);
 		if (cp->name == NULL ||
-		    newscreen && !F_ISSET(cp, E_NEWSCREEN)) {
+		    (newscreen && !F_ISSET(cp, E_NEWSCREEN))) {
 			if (newscreen)
 				ap->bp[0] = toupper(ap->bp[0]);
 			(void)ex_printf(sp, "The %.*s command is unknown\n",
--- a/dist/nvi/ex/ex_util.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_util.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_util.c,v 1.1.1.2 2008/05/18 14:31:20 aymeric Exp $ */
+/*	$NetBSD: ex_util.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -150,9 +150,9 @@
  * PUBLIC: void ex_wemsg __P((SCR *, CHAR_T *, exm_t));
  */
 void
-ex_wemsg(SCR* sp, CHAR_T *p, exm_t which)
+ex_wemsg(SCR* sp, const CHAR_T *p, exm_t which)
 {
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	if (p) INT2CHAR(sp, p, STRLEN(p), np, nlen);
@@ -167,7 +167,7 @@
  * PUBLIC: void ex_emsg __P((SCR *, char *, exm_t));
  */
 void
-ex_emsg(SCR *sp, char *p, exm_t which)
+ex_emsg(SCR *sp, const char *p, exm_t which)
 {
 	switch (which) {
 	case EXM_EMPTYBUF:
--- a/dist/nvi/ex/ex_visual.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_visual.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_visual.c,v 1.1.1.2 2008/05/18 14:31:21 aymeric Exp $ */
+/*	$NetBSD: ex_visual.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -43,7 +43,7 @@
 	int pos;
 	char buf[256];
 	size_t wlen;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 
 	/* If open option off, disallow visual command. */
 	if (!O_ISSET(sp, O_OPEN)) {
@@ -83,9 +83,10 @@
 
 	if (FL_ISSET(cmdp->iflags, E_C_COUNT))
 		len = snprintf(buf, sizeof(buf),
-		     "%luz%c%lu", sp->lno, pos, cmdp->count);
+		    "%luz%c%lu", (unsigned long)sp->lno, pos, cmdp->count);
 	else
-		len = snprintf(buf, sizeof(buf), "%luz%c", sp->lno, pos);
+		len = snprintf(buf, sizeof(buf),
+		    "%luz%c", (unsigned long)sp->lno, pos);
 	CHAR2INT(sp, buf, len, wp, wlen);
 	(void)v_event_push(sp, NULL, wp, wlen, CH_NOMAP | CH_QUOTED);
 
--- a/dist/nvi/ex/ex_write.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_write.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_write.c,v 1.1.1.2 2008/05/18 14:31:16 aymeric Exp $ */
+/*	$NetBSD: ex_write.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -130,9 +130,9 @@
 	MARK rm;
 	int flags;
 	char *name;
-	CHAR_T *p;
+	CHAR_T *p = NULL;
 	size_t nlen;
-	char *n;
+	const char *n;
 	int rc;
 
 	NEEDFILE(sp, cmdp);
@@ -235,9 +235,10 @@
 		 */
 		if (F_ISSET(sp->frp, FR_TMPFILE) &&
 		    !F_ISSET(sp->frp, FR_EXNAMED)) {
-			if ((n = v_strdup(sp, name, nlen - 1)) != NULL) {
+			char *q;
+			if ((q = v_strdup(sp, name, nlen - 1)) != NULL) {
 				free(sp->frp->name);
-				sp->frp->name = n;
+				sp->frp->name = q;
 			}
 			/*
 			 * The file has a real name, it's no longer a
@@ -274,10 +275,10 @@
  *	Write a range of lines to a FILE *.
  *
  * PUBLIC: int ex_writefp __P((SCR *,
- * PUBLIC:    char *, FILE *, MARK *, MARK *, u_long *, u_long *, int));
+ * PUBLIC:    const char *, FILE *, MARK *, MARK *, u_long *, u_long *, int));
  */
 int
-ex_writefp(SCR *sp, char *name, FILE *fp, MARK *fm, MARK *tm, u_long *nlno, u_long *nch, int silent)
+ex_writefp(SCR *sp, const char *name, FILE *fp, MARK *fm, MARK *tm, u_long *nlno, u_long *nch, int silent)
 {
 	struct stat sb;
 	GS *gp;
@@ -285,9 +286,9 @@
 	db_recno_t fline, tline, lcnt;
 	size_t len;
 	int rval;
-	char *msg;
+	const char *msg;
 	CHAR_T *p;
-	char *f;
+	const char *f;
 	size_t flen;
 
 	gp = sp->gp;
--- a/dist/nvi/ex/ex_z.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/ex_z.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ex_z.c,v 1.1.1.2 2008/05/18 14:31:21 aymeric Exp $ */
+/*	$NetBSD: ex_z.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -35,7 +35,7 @@
 int
 ex_z(SCR *sp, EXCMD *cmdp)
 {
-	MARK abs;
+	MARK abm;
 	db_recno_t cnt, equals, lno;
 	int eofcheck;
 
@@ -96,9 +96,9 @@
 		 * !!!
 		 * Historically, z. set the absolute cursor mark.
 		 */
-		abs.lno = sp->lno;
-		abs.cno = sp->cno;
-		(void)mark_set(sp, ABSMARK1, &abs, 1);
+		abm.lno = sp->lno;
+		abm.cno = sp->cno;
+		(void)mark_set(sp, ABSMARK1, &abm, 1);
 		break;
 	case E_C_EQUAL:		/* Center with hyphens. */
 		/*
--- a/dist/nvi/ex/extern.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/ex/extern.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.2 2008/10/29 17:50:49 christos Exp $ */
+/*	$NetBSD: extern.h,v 1.2.2.1 2009/01/20 02:41:12 snj Exp $ */
 
 /* Do not edit: automatically built by build/distrib. */
 int ex __P((SCR **));
@@ -19,10 +19,10 @@
 int ex_args __P((SCR *, EXCMD *));
 char **ex_buildargv __P((SCR *, EXCMD *, char *));
 int argv_init __P((SCR *, EXCMD *));
-int argv_exp0 __P((SCR *, EXCMD *, CHAR_T *, size_t));
-int argv_exp1 __P((SCR *, EXCMD *, CHAR_T *, size_t, int));
-int argv_exp2 __P((SCR *, EXCMD *, CHAR_T *, size_t));
-int argv_exp3 __P((SCR *, EXCMD *, CHAR_T *, size_t));
+int argv_exp0 __P((SCR *, EXCMD *, const CHAR_T *, size_t));
+int argv_exp1 __P((SCR *, EXCMD *, const CHAR_T *, size_t, int));
+int argv_exp2 __P((SCR *, EXCMD *, const CHAR_T *, size_t));
+int argv_exp3 __P((SCR *, EXCMD *, const CHAR_T *, size_t));
 int argv_free __P((SCR *));
 int ex_at __P((SCR *, EXCMD *));
 int ex_bang __P((SCR *, EXCMD *));
@@ -42,9 +42,9 @@
 int ex_g_insdel __P((SCR *, lnop_t, db_recno_t));
 int ex_screen_copy __P((SCR *, SCR *));
 int ex_screen_end __P((SCR *));
-int ex_optchange __P((SCR *, int, char *, u_long *));
+int ex_optchange __P((SCR *, int, const char *, u_long *));
 int ex_exrc __P((SCR *));
-int ex_run_str __P((SCR *, char *, CHAR_T *, size_t, int, int));
+int ex_run_str __P((SCR *, const char *, const CHAR_T *, size_t, int, int));
 int ex_join __P((SCR *, EXCMD *));
 int ex_map __P((SCR *, EXCMD *));
 int ex_unmap __P((SCR *, EXCMD *));
@@ -68,7 +68,7 @@
 int ex_put __P((SCR *, EXCMD *));
 int ex_quit __P((SCR *, EXCMD *));
 int ex_read __P((SCR *, EXCMD *));
-int ex_readfp __P((SCR *, char *, FILE *, MARK *, db_recno_t *, int));
+int ex_readfp __P((SCR *, const char *, FILE *, MARK *, db_recno_t *, int));
 int ex_bg __P((SCR *, EXCMD *));
 int ex_fg __P((SCR *, EXCMD *));
 int ex_resize __P((SCR *, EXCMD *));
@@ -80,7 +80,7 @@
 int sscr_end __P((SCR *));
 int ex_set __P((SCR *, EXCMD *));
 int ex_shell __P((SCR *, EXCMD *));
-int ex_exec_proc __P((SCR *, EXCMD *, char *, const char *, int));
+int ex_exec_proc __P((SCR *, EXCMD *, const char *, const char *, int));
 int proc_wait __P((SCR *, long, const char *, int, int));
 int ex_shiftl __P((SCR *, EXCMD *));
 int ex_shiftr __P((SCR *, EXCMD *));
@@ -92,7 +92,7 @@
 int re_compile __P((SCR *,
     CHAR_T *, size_t, CHAR_T **, size_t *, regex_t *, u_int));
 void re_error __P((SCR *, int, regex_t *));
-int ex_tag_first __P((SCR *, CHAR_T *));
+int ex_tag_first __P((SCR *, const CHAR_T *));
 int ex_rtag_push __P((SCR *, EXCMD *));
 int ex_tag_push __P((SCR *, EXCMD *));
 int ex_tag_next __P((SCR *, EXCMD *));
@@ -106,7 +106,7 @@
 int tagq_free __P((SCR *, TAGQ *));
 int tagq_push __P((SCR*, TAGQ*, int, int ));
 void tag_msg __P((SCR *, tagmsg_t, char *));
-int ex_tagf_alloc __P((SCR *, char *));
+int ex_tagf_alloc __P((SCR *, const char *));
 int ex_tag_free __P((SCR *));
 int ex_tcl __P((SCR*, EXCMD *));
 int ex_txt __P((SCR *, TEXTH *, ARG_CHAR_T, u_int32_t));
@@ -118,8 +118,8 @@
 int ex_getline __P((SCR *, FILE *, size_t *));
 int ex_ncheck __P((SCR *, int));
 int ex_init __P((SCR *));
-void ex_wemsg __P((SCR *, CHAR_T *, exm_t));
-void ex_emsg __P((SCR *, char *, exm_t));
+void ex_wemsg __P((SCR *, const CHAR_T *, exm_t));
+void ex_emsg __P((SCR *, const char *, exm_t));
 int ex_version __P((SCR *, EXCMD *));
 int ex_visual __P((SCR *, EXCMD *));
 int ex_wn __P((SCR *, EXCMD *));
@@ -127,6 +127,6 @@
 int ex_write __P((SCR *, EXCMD *));
 int ex_xit __P((SCR *, EXCMD *));
 int ex_writefp __P((SCR *,
-   char *, FILE *, MARK *, MARK *, u_long *, u_long *, int));
+   const char *, FILE *, MARK *, MARK *, u_long *, u_long *, int));
 int ex_yank __P((SCR *, EXCMD *));
 int ex_z __P((SCR *, EXCMD *));
--- a/dist/nvi/regex/cclass.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/regex/cclass.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cclass.h,v 1.1.1.2 2008/05/18 14:31:34 aymeric Exp $ */
+/*	$NetBSD: cclass.h,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -55,31 +55,31 @@
 /* character-class table */
 static struct cclass {
 	RCHAR_T *name;
-	char *chars;
-	char *multis;
+	const char *chars;
+	const char *multis;
 } cclasses[] = {
-	ALNUM,	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789",				"",
-	ALPHA,	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
-					"",
-	BLANK,	" \t",		"",
-	CNTRL,	"\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
-\25\26\27\30\31\32\33\34\35\36\37\177",	"",
-	DIGIT,	"0123456789",	"",
-	GRAPH,	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
+	{ ALNUM,	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
+0123456789",				"" },
+	{ ALPHA,	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
+					"" },
+	{ BLANK,	" \t",		"" },
+	{ CNTRL,	"\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
+\25\26\27\30\31\32\33\34\35\36\37\177",	"" },
+	{ DIGIT,	"0123456789",	"" },
+	{ GRAPH,	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
-					"",
-	LOWER,	"abcdefghijklmnopqrstuvwxyz",
-					"",
-	PRINT,	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
+					"" },
+	{ LOWER,	"abcdefghijklmnopqrstuvwxyz",
+					"" },
+	{ PRINT,	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
-					"",
-	PUNCT,	"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
-					"",
-	SPACE,	"\t\n\v\f\r ",	"",
-	UPPER,	"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
-					"",
-	XDIGIT,	"0123456789ABCDEFabcdef",
-					"",
-	NULL,		0,		""
+					"" },
+	{ PUNCT,	"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
+					"" },
+	{ SPACE,	"\t\n\v\f\r ",	"" },
+	{ UPPER,	"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+					"" },
+	{ XDIGIT,	"0123456789ABCDEFabcdef",
+					"" },
+	{ NULL,		0,		"" },
 };
--- a/dist/nvi/regex/cname.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/regex/cname.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cname.h,v 1.1.1.2 2008/05/18 14:31:35 aymeric Exp $ */
+/*	$NetBSD: cname.h,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -41,103 +41,103 @@
 
 /* character-name table */
 static struct cname {
-	RCHAR_T *name;
+	const RCHAR_T *name;
 	char code;
 } cnames[] = {
-	L("NUL"),	'\0',
-	L("SOH"),	'\001',
-	L("STX"),	'\002',
-	L("ETX"),	'\003',
-	L("EOT"),	'\004',
-	L("ENQ"),	'\005',
-	L("ACK"),	'\006',
-	L("BEL"),	'\007',
-	L("alert"),	'\007',
-	L("BS"),		'\010',
-	L("backspace"),	'\b',
-	L("HT"),		'\011',
-	L("tab"),		'\t',
-	L("LF"),		'\012',
-	L("newline"),	'\n',
-	L("VT"),		'\013',
-	L("vertical-tab"),	'\v',
-	L("FF"),		'\014',
-	L("form-feed"),	'\f',
-	L("CR"),		'\015',
-	L("carriage-return"),	'\r',
-	L("SO"),	'\016',
-	L("SI"),	'\017',
-	L("DLE"),	'\020',
-	L("DC1"),	'\021',
-	L("DC2"),	'\022',
-	L("DC3"),	'\023',
-	L("DC4"),	'\024',
-	L("NAK"),	'\025',
-	L("SYN"),	'\026',
-	L("ETB"),	'\027',
-	L("CAN"),	'\030',
-	L("EM"),	'\031',
-	L("SUB"),	'\032',
-	L("ESC"),	'\033',
-	L("IS4"),	'\034',
-	L("FS"),	'\034',
-	L("IS3"),	'\035',
-	L("GS"),	'\035',
-	L("IS2"),	'\036',
-	L("RS"),	'\036',
-	L("IS1"),	'\037',
-	L("US"),	'\037',
-	L("space"),		' ',
-	L("exclamation-mark"),	'!',
-	L("quotation-mark"),	'"',
-	L("number-sign"),		'#',
-	L("dollar-sign"),		'$',
-	L("percent-sign"),		'%',
-	L("ampersand"),		'&',
-	L("apostrophe"),		'\'',
-	L("left-parenthesis"),	'(',
-	L("right-parenthesis"),	')',
-	L("asterisk"),	'*',
-	L("plus-sign"),	'+',
-	L("comma"),	',',
-	L("hyphen"),	'-',
-	L("hyphen-minus"),	'-',
-	L("period"),	'.',
-	L("full-stop"),	'.',
-	L("slash"),	'/',
-	L("solidus"),	'/',
-	L("zero"),		'0',
-	L("one"),		'1',
-	L("two"),		'2',
-	L("three"),	'3',
-	L("four"),		'4',
-	L("five"),		'5',
-	L("six"),		'6',
-	L("seven"),	'7',
-	L("eight"),	'8',
-	L("nine"),		'9',
-	L("colon"),	':',
-	L("semicolon"),	';',
-	L("less-than-sign"),	'<',
-	L("equals-sign"),		'=',
-	L("greater-than-sign"),	'>',
-	L("question-mark"),	'?',
-	L("commercial-at"),	'@',
-	L("left-square-bracket"),	'[',
-	L("backslash"),		'\\',
-	L("reverse-solidus"),	'\\',
-	L("right-square-bracket"),	']',
-	L("circumflex"),		'^',
-	L("circumflex-accent"),	'^',
-	L("underscore"),		'_',
-	L("low-line"),		'_',
-	L("grave-accent"),		'`',
-	L("left-brace"),		'{',
-	L("left-curly-bracket"),	'{',
-	L("vertical-line"),	'|',
-	L("right-brace"),		'}',
-	L("right-curly-bracket"),	'}',
-	L("tilde"),		'~',
-	L("DEL"),	'\177',
-	NULL,	0,
+	{ L("NUL"),		'\0' },
+	{ L("SOH"),		'\001' },
+	{ L("STX"),		'\002' },
+	{ L("ETX"),		'\003' },
+	{ L("EOT"),		'\004' },
+	{ L("ENQ"),		'\005' },
+	{ L("ACK"),		'\006' },
+	{ L("BEL"),		'\007' },
+	{ L("alert"),		'\007' },
+	{ L("BS"),		'\010' },
+	{ L("backspace"),	'\b' },
+	{ L("HT"),		'\011' },
+	{ L("tab"),		'\t' },
+	{ L("LF"),		'\012' },
+	{ L("newline"),		'\n' },
+	{ L("VT"),		'\013' },
+	{ L("vertical-tab"),	'\v' },
+	{ L("FF"),		'\014' },
+	{ L("form-feed"),	'\f' },
+	{ L("CR"),		'\015' },
+	{ L("carriage-return"),	'\r' },
+	{ L("SO"),		'\016' },
+	{ L("SI"),		'\017' },
+	{ L("DLE"),		'\020' },
+	{ L("DC1"),		'\021' },
+	{ L("DC2"),		'\022' },
+	{ L("DC3"),		'\023' },
+	{ L("DC4"),		'\024' },
+	{ L("NAK"),		'\025' },
+	{ L("SYN"),		'\026' },
+	{ L("ETB"),		'\027' },
+	{ L("CAN"),		'\030' },
+	{ L("EM"),		'\031' },
+	{ L("SUB"),		'\032' },
+	{ L("ESC"),		'\033' },
+	{ L("IS4"),		'\034' },
+	{ L("FS"),		'\034' },
+	{ L("IS3"),		'\035' },
+	{ L("GS"),		'\035' },
+	{ L("IS2"),		'\036' },
+	{ L("RS"),		'\036' },
+	{ L("IS1"),		'\037' },
+	{ L("US"),		'\037' },
+	{ L("space"),		' ' },
+	{ L("exclamation-mark"),'!' },
+	{ L("quotation-mark"),	'"' },
+	{ L("number-sign"),	'#' },
+	{ L("dollar-sign"),	'$' },
+	{ L("percent-sign"),	'%' },
+	{ L("ampersand"),	'&' },
+	{ L("apostrophe"),	'\'' },
+	{ L("left-parenthesis"),'(' },
+	{ L("right-parenthesis"),')' },
+	{ L("asterisk"),	'*' },
+	{ L("plus-sign"),	'+' },
+	{ L("comma"),		',' },
+	{ L("hyphen"),		'-' },
+	{ L("hyphen-minus"),	'-' },
+	{ L("period"),		'.' },
+	{ L("full-stop"),	'.' },
+	{ L("slash"),		'/' },
+	{ L("solidus"),		'/' },
+	{ L("zero"),		'0' },
+	{ L("one"),		'1' },
+	{ L("two"),		'2' },
+	{ L("three"),		'3' },
+	{ L("four"),		'4' },
+	{ L("five"),		'5' },
+	{ L("six"),		'6' },
+	{ L("seven"),		'7' },
+	{ L("eight"),		'8' },
+	{ L("nine"),		'9' },
+	{ L("colon"),		':' },
+	{ L("semicolon"),	';' },
+	{ L("less-than-sign"),	'<' },
+	{ L("equals-sign"),	'=' },
+	{ L("greater-than-sign"),'>' },
+	{ L("question-mark"),	'?' },
+	{ L("commercial-at"),	'@' },
+	{ L("left-square-bracket"),'[' },
+	{ L("backslash"),	'\\' },
+	{ L("reverse-solidus"),	'\\' },
+	{ L("right-square-bracket"),']' },
+	{ L("circumflex"),	'^' },
+	{ L("circumflex-accent"),'^' },
+	{ L("underscore"),	'_' },
+	{ L("low-line"),	'_' },
+	{ L("grave-accent"),	'`' },
+	{ L("left-brace"),	'{' },
+	{ L("left-curly-bracket"),'{' },
+	{ L("vertical-line"),	'|' },
+	{ L("right-brace"),	'}' },
+	{ L("right-curly-bracket"),'}' },
+	{ L("tilde"),		'~' },
+	{ L("DEL"),		'\177' },
+	{ NULL,			0 },
 };
--- a/dist/nvi/regex/engine.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/regex/engine.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: engine.c,v 1.1.1.2 2008/05/18 14:31:36 aymeric Exp $ */
+/*	$NetBSD: engine.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -150,8 +150,8 @@
 	struct match mv;
 	register struct match *m = &mv;
 	register RCHAR_T *dp;
-	const register sopno gf = g->firststate+1;	/* +1 for OEND */
-	const register sopno gl = g->laststate;
+	register const sopno gf = g->firststate+1;	/* +1 for OEND */
+	register const sopno gl = g->laststate;
 	RCHAR_T *start;
 	RCHAR_T *stop;
 
@@ -688,6 +688,7 @@
 	/* "can't happen" */
 	assert(nope);
 	/* NOTREACHED */
+	return NULL;
 }
 
 /*
--- a/dist/nvi/regex/regcomp.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/regex/regcomp.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: regcomp.c,v 1.1.1.2 2008/05/18 14:31:37 aymeric Exp $ */
+/*	$NetBSD: regcomp.c,v 1.1.1.2.6.1 2009/01/20 02:41:12 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -104,14 +104,18 @@
 static int freezeset __P((struct parse *p, cset *cs));
 static int firstch __P((struct parse *p, cset *cs));
 static int nch __P((struct parse *p, cset *cs));
-static void mcadd __P((struct parse *p, cset *cs, char *cp));
+static void mcadd __P((struct parse *p, cset *cs, const char *cp));
+#ifdef notdef
 static void mcsub __P((cset *cs, char *cp));
 static int mcin __P((cset *cs, char *cp));
 static char *mcfind __P((cset *cs, char *cp));
+#endif
 static void mcinvert __P((struct parse *p, cset *cs));
 static void mccase __P((struct parse *p, cset *cs));
+#ifdef notdef
 static int isinsets __P((struct re_guts *g, int c));
 static int samesets __P((struct re_guts *g, int c1, int c2));
+#endif
 static void categorize __P((struct parse *p, struct re_guts *g));
 static sopno dupl __P((struct parse *p, sopno start, sopno finish));
 static void doemit __P((struct parse *p, sop op, size_t opnd));
@@ -217,7 +221,7 @@
 
 	/* set things up */
 	p->g = g;
-	p->next = (RCHAR_T *)pattern;	/* convenience; we do not modify it */
+	p->next = (RCHAR_T *)__UNCONST(pattern);	/* convenience; we do not modify it */
 	p->end = p->next + len;
 	p->error = 0;
 	p->ncsalloc = 0;
@@ -286,8 +290,8 @@
          			/* character this ERE should end at */
 {
 	register char c;
-	register sopno prevback;
-	register sopno prevfwd;
+	register sopno prevback = 0;
+	register sopno prevfwd = 0;
 	register sopno conc;
 	register int first = 1;		/* is this the first alternative? */
 
@@ -296,7 +300,7 @@
 		conc = HERE();
 		while (MORE() && (c = PEEK()) != '|' && c != stop)
 			p_ere_exp(p);
-		REQUIRE(HERE() != conc, REG_EMPTY);	/* require nonempty */
+		(void)REQUIRE(HERE() != conc, REG_EMPTY);	/* require nonempty */
 
 		if (!EAT('|'))
 			break;		/* NOTE BREAK OUT */
@@ -342,7 +346,7 @@
 	pos = HERE();
 	switch (c) {
 	case '(':
-		REQUIRE(MORE(), REG_EPAREN);
+		(void)REQUIRE(MORE(), REG_EPAREN);
 		p->g->nsub++;
 		subno = p->g->nsub;
 		if (subno < NPAREN)
@@ -355,7 +359,7 @@
 			assert(p->pend[subno] != 0);
 		}
 		EMIT(ORPAREN, subno);
-		MUSTEAT(')', REG_EPAREN);
+		(void)MUSTEAT(')', REG_EPAREN);
 		break;
 #ifndef POSIX_MISTAKE
 	case ')':		/* happens only if no current unmatched ( */
@@ -398,12 +402,12 @@
 		p_bracket(p);
 		break;
 	case '\\':
-		REQUIRE(MORE(), REG_EESCAPE);
+		(void)REQUIRE(MORE(), REG_EESCAPE);
 		c = GETNEXT();
 		ordinary(p, c);
 		break;
 	case '{':		/* okay as ordinary except if digit follows */
-		REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT);
+		(void)REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT);
 		/* FALLTHROUGH */
 	default:
 		ordinary(p, c);
@@ -419,7 +423,7 @@
 		return;		/* no repetition, we're done */
 	NEXT();
 
-	REQUIRE(!wascaret, REG_BADRPT);
+	(void)REQUIRE(!wascaret, REG_BADRPT);
 	switch (c) {
 	case '*':	/* implemented as +? */
 		/* this case does not require the (y|) trick, noKLUDGE */
@@ -446,7 +450,7 @@
 		if (EAT(',')) {
 			if (isdigit(PEEK())) {
 				count2 = p_count(p);
-				REQUIRE(count <= count2, REG_BADBR);
+				(void)REQUIRE(count <= count2, REG_BADBR);
 			} else		/* single number with comma */
 				count2 = INFINITY;
 		} else		/* just a single number */
@@ -455,7 +459,7 @@
 		if (!EAT('}')) {	/* error heuristics */
 			while (MORE() && PEEK() != '}')
 				NEXT();
-			REQUIRE(MORE(), REG_EBRACE);
+			(void)REQUIRE(MORE(), REG_EBRACE);
 			SETERROR(REG_BADBR);
 		}
 		break;
@@ -477,7 +481,7 @@
 static void
 p_str(register struct parse *p)
 {
-	REQUIRE(MORE(), REG_EMPTY);
+	(void)REQUIRE(MORE(), REG_EMPTY);
 	while (MORE())
 		ordinary(p, GETNEXT());
 }
@@ -520,7 +524,7 @@
 		p->g->neol++;
 	}
 
-	REQUIRE(HERE() != start, REG_EMPTY);	/* require nonempty */
+	(void)REQUIRE(HERE() != start, REG_EMPTY);	/* require nonempty */
 }
 
 /*
@@ -545,7 +549,7 @@
 	assert(MORE());		/* caller should have ensured this */
 	c = GETNEXT();
 	if (c == '\\') {
-		REQUIRE(MORE(), REG_EESCAPE);
+		(void)REQUIRE(MORE(), REG_EESCAPE);
 		c = BACKSL | (unsigned char)GETNEXT();
 	}
 	switch (c) {
@@ -575,7 +579,7 @@
 			assert(p->pend[subno] != 0);
 		}
 		EMIT(ORPAREN, subno);
-		REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
+		(void)REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
 		break;
 	case BACKSL|')':	/* should not get here -- must be user */
 	case BACKSL|'}':
@@ -605,7 +609,7 @@
 		p->g->backrefs = 1;
 		break;
 	case '*':
-		REQUIRE(starordinary, REG_BADRPT);
+		(void)REQUIRE(starordinary, REG_BADRPT);
 		/* FALLTHROUGH */
 	default:
 		ordinary(p, c &~ BACKSL);
@@ -623,7 +627,7 @@
 		if (EAT(',')) {
 			if (MORE() && isdigit(PEEK())) {
 				count2 = p_count(p);
-				REQUIRE(count <= count2, REG_BADBR);
+				(void)REQUIRE(count <= count2, REG_BADBR);
 			} else		/* single number with comma */
 				count2 = INFINITY;
 		} else		/* just a single number */
@@ -632,7 +636,7 @@
 		if (!EATTWO('\\', '}')) {	/* error heuristics */
 			while (MORE() && !SEETWO('\\', '}'))
 				NEXT();
-			REQUIRE(MORE(), REG_EBRACE);
+			(void)REQUIRE(MORE(), REG_EBRACE);
 			SETERROR(REG_BADBR);
 		}
 	} else if (c == (unsigned char)'$')	/* $ (but not \$) ends it */
@@ -656,7 +660,7 @@
 		ndigits++;
 	}
 
-	REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR);
+	(void)REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR);
 	return(count);
 }
 
@@ -670,7 +674,6 @@
 static void
 p_bracket(register struct parse *p)
 {
-	register char c;
 	register cset *cs = allocset(p);
 	register int invert = 0;
 	static RCHAR_T bow[] = { '[', ':', '<', ':', ']', ']' };
@@ -698,7 +701,7 @@
 		p_b_term(p, cs);
 	if (EAT('-'))
 		CHadd(cs, '-');
-	MUSTEAT(']', REG_EBRACK);
+	(void)MUSTEAT(']', REG_EBRACK);
 
 	if (p->error != 0)	/* don't mess things up further */
 		return;
@@ -767,21 +770,21 @@
 	switch (c) {
 	case ':':		/* character class */
 		NEXT2();
-		REQUIRE(MORE(), REG_EBRACK);
+		(void)REQUIRE(MORE(), REG_EBRACK);
 		c = PEEK();
-		REQUIRE(c != '-' && c != ']', REG_ECTYPE);
+		(void)REQUIRE(c != '-' && c != ']', REG_ECTYPE);
 		p_b_cclass(p, cs);
-		REQUIRE(MORE(), REG_EBRACK);
-		REQUIRE(EATTWO(':', ']'), REG_ECTYPE);
+		(void)REQUIRE(MORE(), REG_EBRACK);
+		(void)REQUIRE(EATTWO(':', ']'), REG_ECTYPE);
 		break;
 	case '=':		/* equivalence class */
 		NEXT2();
-		REQUIRE(MORE(), REG_EBRACK);
+		(void)REQUIRE(MORE(), REG_EBRACK);
 		c = PEEK();
-		REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
+		(void)REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
 		p_b_eclass(p, cs);
-		REQUIRE(MORE(), REG_EBRACK);
-		REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
+		(void)REQUIRE(MORE(), REG_EBRACK);
+		(void)REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
 		break;
 	default:		/* symbol, ordinary character, or range */
 /* xxx revision needed for multichar stuff */
@@ -796,7 +799,7 @@
 		} else
 			finish = start;
 /* xxx what about signed chars here... */
-		REQUIRE(start <= finish, REG_ERANGE);
+		(void)REQUIRE(start <= finish, REG_ERANGE);
 		for (i = start; i <= finish; i++)
 			CHadd(cs, i);
 		break;
@@ -813,7 +816,7 @@
 	register RCHAR_T *sp = p->next;
 	register struct cclass *cp;
 	register size_t len;
-	register char *u;
+	register const char *u;
 	register char c;
 
 	while (MORE() && isalpha(PEEK()))
@@ -859,13 +862,13 @@
 {
 	register char value;
 
-	REQUIRE(MORE(), REG_EBRACK);
+	(void)REQUIRE(MORE(), REG_EBRACK);
 	if (!EATTWO('[', '.'))
 		return(GETNEXT());
 
 	/* collating symbol */
 	value = p_b_coll_elem(p, '.');
-	REQUIRE(EATTWO('.', ']'), REG_ECOLLATE);
+	(void)REQUIRE(EATTWO('.', ']'), REG_ECOLLATE);
 	return(value);
 }
 
@@ -881,7 +884,6 @@
 	register RCHAR_T *sp = p->next;
 	register struct cname *cp;
 	register int len;
-	register char c;
 
 	while (MORE() && !SEETWO(endc, ']'))
 		NEXT();
@@ -1222,7 +1224,7 @@
  ==	register char *cp);
  */
 static void
-mcadd(register struct parse *p, register cset *cs, register char *cp)
+mcadd(register struct parse *p, register cset *cs, register const char *cp)
 {
 	register size_t oldend = cs->smultis;
 
@@ -1240,6 +1242,7 @@
 	cs->multis[cs->smultis - 1] = '\0';
 }
 
+#ifdef notdef
 /*
  - mcsub - subtract a collating element from a cset
  == static void mcsub(register cset *cs, register char *cp);
@@ -1291,6 +1294,7 @@
 			return(p);
 	return(NULL);
 }
+#endif
 
 /*
  - mcinvert - invert the list of collating elements in a cset
@@ -1318,6 +1322,7 @@
 	assert(cs->multis == NULL);	/* xxx */
 }
 
+#ifdef notdef
 /*
  - isinsets - is this character in any sets?
  == static int isinsets(register struct re_guts *g, int c);
@@ -1354,6 +1359,7 @@
 			return(0);
 	return(1);
 }
+#endif
 
 /*
  - categorize - sort out character categories
@@ -1362,9 +1368,8 @@
 static void
 categorize(struct parse *p, register struct re_guts *g)
 {
-/*
+#ifdef notdef
 	register cat_t *cats = g->categories;
-*/
 	register int c;
 	register int c2;
 	register cat_t cat;
@@ -1373,7 +1378,6 @@
 	if (p->error != 0)
 		return;
 
-/*
 	for (c = CHAR_MIN; c <= CHAR_MAX; c++)
 		if (cats[c] == 0 && isinsets(g, c)) {
 			cat = g->ncategories++;
@@ -1382,7 +1386,7 @@
 				if (cats[c2] == 0 && samesets(g, c, c2))
 					cats[c2] = cat;
 		}
-*/
+#endif
 }
 
 /*
@@ -1537,8 +1541,8 @@
 findmust(struct parse *p, register struct re_guts *g)
 {
 	register sop *scan;
-	sop *start;
-	register sop *newstart;
+	sop *start = 0;
+	register sop *newstart = 0;
 	register sopno newlen;
 	register sop s;
 	register RCHAR_T *cp;
--- a/dist/nvi/regex/regerror.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/regex/regerror.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: regerror.c,v 1.1.1.2 2008/05/18 14:31:38 aymeric Exp $ */
+/*	$NetBSD: regerror.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -87,26 +87,26 @@
  */
 static struct rerr {
 	int code;
-	char *name;
-	char *explain;
+	const char *name;
+	const char *explain;
 } rerrs[] = {
-	REG_NOMATCH,	"REG_NOMATCH",	"regexec() failed to match",
-	REG_BADPAT,	"REG_BADPAT",	"invalid regular expression",
-	REG_ECOLLATE,	"REG_ECOLLATE",	"invalid collating element",
-	REG_ECTYPE,	"REG_ECTYPE",	"invalid character class",
-	REG_EESCAPE,	"REG_EESCAPE",	"trailing backslash (\\)",
-	REG_ESUBREG,	"REG_ESUBREG",	"invalid backreference number",
-	REG_EBRACK,	"REG_EBRACK",	"brackets ([ ]) not balanced",
-	REG_EPAREN,	"REG_EPAREN",	"parentheses not balanced",
-	REG_EBRACE,	"REG_EBRACE",	"braces not balanced",
-	REG_BADBR,	"REG_BADBR",	"invalid repetition count(s)",
-	REG_ERANGE,	"REG_ERANGE",	"invalid character range",
-	REG_ESPACE,	"REG_ESPACE",	"out of memory",
-	REG_BADRPT,	"REG_BADRPT",	"repetition-operator operand invalid",
-	REG_EMPTY,	"REG_EMPTY",	"empty (sub)expression",
-	REG_ASSERT,	"REG_ASSERT",	"\"can't happen\" -- you found a bug",
-	REG_INVARG,	"REG_INVARG",	"invalid argument to regex routine",
-	0,		"",		"*** unknown regexp error code ***",
+	{ REG_NOMATCH,	"REG_NOMATCH",	"regexec() failed to match" },
+	{ REG_BADPAT,	"REG_BADPAT",	"invalid regular expression" },
+	{ REG_ECOLLATE,	"REG_ECOLLATE",	"invalid collating element" },
+	{ REG_ECTYPE,	"REG_ECTYPE",	"invalid character class" },
+	{ REG_EESCAPE,	"REG_EESCAPE",	"trailing backslash (\\)" },
+	{ REG_ESUBREG,	"REG_ESUBREG",	"invalid backreference number" },
+	{ REG_EBRACK,	"REG_EBRACK",	"brackets ([ ]) not balanced" },
+	{ REG_EPAREN,	"REG_EPAREN",	"parentheses not balanced" },
+	{ REG_EBRACE,	"REG_EBRACE",	"braces not balanced" },
+	{ REG_BADBR,	"REG_BADBR",	"invalid repetition count(s)" },
+	{ REG_ERANGE,	"REG_ERANGE",	"invalid character range" },
+	{ REG_ESPACE,	"REG_ESPACE",	"out of memory" },
+	{ REG_BADRPT,	"REG_BADRPT",	"repetition-operator operand invalid" },
+	{ REG_EMPTY,	"REG_EMPTY",	"empty (sub)expression" },
+	{ REG_ASSERT,	"REG_ASSERT",	"\"can't happen\" -- you found a bug" },
+	{ REG_INVARG,	"REG_INVARG",	"invalid argument to regex routine" },
+	{ 0,		"",		"*** unknown regexp error code ***" },
 };
 
 /*
@@ -120,7 +120,7 @@
 	register struct rerr *r;
 	register size_t len;
 	register int target = errcode &~ REG_ITOA;
-	register char *s;
+	register const char *s;
 	char convbuf[50];
 
 	if (errcode == REG_ATOI)
--- a/dist/nvi/regex/regexec.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/regex/regexec.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: regexec.c,v 1.1.1.2 2008/05/18 14:31:39 aymeric Exp $ */
+/*	$NetBSD: regexec.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -61,7 +61,9 @@
 #include "utils.h"
 #include "regex2.h"
 
+#ifdef notdef
 static int nope = 0;		/* for use in asserts; shuts lint up */
+#endif
 
 /* macros for manipulating states, small version */
 #define	states	int
@@ -172,7 +174,7 @@
 	eflags = GOODFLAGS(eflags);
 
 	if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
-		return(smatcher(g, (RCHAR_T *)string, nmatch, pmatch, eflags));
+		return(smatcher(g, (RCHAR_T *)__UNCONST(string), nmatch, pmatch, eflags));
 	else
-		return(lmatcher(g, (RCHAR_T *)string, nmatch, pmatch, eflags));
+		return(lmatcher(g, (RCHAR_T *)__UNCONST(string), nmatch, pmatch, eflags));
 }
--- a/dist/nvi/vi/extern.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/extern.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.1.1.1 2008/05/18 14:31:53 aymeric Exp $ */
+/*	$NetBSD: extern.h,v 1.1.1.1.8.1 2009/01/20 02:41:13 snj Exp $ */
 
 /* Do not edit: automatically built by build/distrib. */
 int cs_init __P((SCR *, VCS *));
@@ -33,7 +33,7 @@
 int v_increment __P((SCR *, VICMD *));
 int v_screen_copy __P((SCR *, SCR *));
 int v_screen_end __P((SCR *));
-int v_optchange __P((SCR *, int, char *, u_long *));
+int v_optchange __P((SCR *, int, const char *, u_long *));
 int v_iA __P((SCR *, VICMD *));
 int v_ia __P((SCR *, VICMD *));
 int v_iI __P((SCR *, VICMD *));
@@ -55,7 +55,7 @@
 int v_match __P((SCR *, VICMD *));
 int v_paragraphf __P((SCR *, VICMD *));
 int v_paragraphb __P((SCR *, VICMD *));
-int v_buildps __P((SCR *, char *, char *));
+int v_buildps __P((SCR *, const char *, const char *));
 int v_Put __P((SCR *, VICMD *));
 int v_put __P((SCR *, VICMD *));
 int v_redraw __P((SCR *, VICMD *));
@@ -102,7 +102,7 @@
 void v_sof __P((SCR *, MARK *));
 void v_sol __P((SCR *));
 int v_isempty __P((CHAR_T *, size_t));
-void v_emsg __P((SCR *, char *, vim_t));
+void v_emsg __P((SCR *, const char *, vim_t));
 int v_wordW __P((SCR *, VICMD *));
 int v_wordw __P((SCR *, VICMD *));
 int v_wordE __P((SCR *, VICMD *));
@@ -146,5 +146,5 @@
 int vs_discard __P((SCR *, SCR **));
 int vs_fg __P((SCR *, SCR **, CHAR_T *, int));
 int vs_bg __P((SCR *));
-int vs_swap __P((SCR *, SCR **, char *));
+int vs_swap __P((SCR *, SCR **, const char *));
 int vs_resize __P((SCR *, long, adj_t));
--- a/dist/nvi/vi/getc.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/getc.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: getc.c,v 1.1.1.2 2008/05/18 14:31:40 aymeric Exp $ */
+/*	$NetBSD: getc.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -147,7 +147,7 @@
 		if (cs_next(sp, csp))
 			return (1);
 		if (csp->cs_flags == CS_EOL || csp->cs_flags == CS_EMP ||
-		    csp->cs_flags == 0 && isblank(csp->cs_ch))
+		    (csp->cs_flags == 0 && isblank(csp->cs_ch)))
 			continue;
 		break;
 	}
@@ -216,7 +216,7 @@
 		if (cs_prev(sp, csp))
 			return (1);
 		if (csp->cs_flags == CS_EOL || csp->cs_flags == CS_EMP ||
-		    csp->cs_flags == 0 && isblank(csp->cs_ch))
+		    (csp->cs_flags == 0 && isblank(csp->cs_ch)))
 			continue;
 		break;
 	}
--- a/dist/nvi/vi/v_at.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_at.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_at.c,v 1.1.1.2 2008/05/18 14:31:40 aymeric Exp $ */
+/*	$NetBSD: v_at.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -43,7 +43,7 @@
 	size_t len;
 	char nbuf[20];
 	CHAR_T wbuf[20];
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/*
@@ -68,7 +68,7 @@
 
 	CBNAME(sp, cbp, name);
 	if (cbp == NULL) {
-		ex_emsg(sp, KEY_NAME(sp, name), EXM_EMPTYBUF);
+		ex_emsg(sp, (char *)KEY_NAME(sp, name), EXM_EMPTYBUF);
 		return (1);
 	}
 
@@ -95,8 +95,8 @@
 	    tp != (void *)&cbp->textq; tp = tp->q.cqe_prev) {
 		static CHAR_T nl[] = { '\n', 0 };
 		if ((F_ISSET(cbp, CB_LMODE) ||
-		    tp->q.cqe_next != (void *)&cbp->textq) &&
-		    v_event_push(sp, NULL, nl, 1, 0) ||
+		    ((tp->q.cqe_next != (void *)&cbp->textq) &&
+		    v_event_push(sp, NULL, nl, 1, 0))) ||
 		    v_event_push(sp, NULL, tp->lb, tp->len, 0))
 			return (1);
 	}
--- a/dist/nvi/vi/v_cmd.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_cmd.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_cmd.c,v 1.1.1.2 2008/05/18 14:31:41 aymeric Exp $ */
+/*	$NetBSD: v_cmd.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -26,13 +26,14 @@
 #include "../common/common.h"
 #include "vi.h"
 
+#define VINULLKEY { NULL, 0, NULL, NULL }
 /*
  * This array maps keystrokes to vi command functions.  It is known
  * in ex/ex_usage.c that it takes four columns to name a vi character.
  */
 VIKEYS const vikeys [MAXVIKEY + 1] = {
 /* 000 NUL -- The code in vi.c expects key 0 to be undefined. */
-	{NULL},
+	VINULLKEY,
 /* 001  ^A */
 	{v_searchw,	V_ABS|V_CNT|V_MOVE|V_KEYW|VM_CUTREQ|VM_RCM_SET,
 	    "[count]^A",
@@ -66,13 +67,13 @@
 	    "[count]^H",
 	    "^H move left by characters"},
 /* 011  ^I */
-	{NULL},
+	VINULLKEY,
 /* 012  ^J */
 	{v_down,	V_CNT|V_MOVE|VM_LMODE|VM_RCM,
 	    "[count]^J",
 	    "^J move down by lines"},
 /* 013  ^K */
-	{NULL},
+	VINULLKEY,
 /* 014  ^L */
 	{v_redraw,	0,
 	    "^L",
@@ -86,19 +87,19 @@
 	    "[count]^N",
 	    "^N move down by lines"},
 /* 017  ^O */
-	{NULL},
+	VINULLKEY,
 /* 020  ^P */
 	{v_up,		V_CNT|V_MOVE|VM_LMODE|VM_RCM,
 	    "[count]^P",
 	    "^P move up by lines"},
 /* 021  ^Q -- same as ^V if not used for hardware flow control. */
-	{NULL},
+	VINULLKEY,
 /* 022  ^R */
 	{v_redraw,	0,
 	    "^R",
 	    "^R redraw screen"},
 /* 023  ^S -- not available, used for hardware flow control. */
-	{NULL},
+	VINULLKEY,
 /* 024  ^T */
 	{v_tagpop,	V_ABS|VM_RCM_SET,
 	    "^T",
@@ -116,7 +117,7 @@
 	    "^W",
 	    "^W move to next screen"},
 /* 030  ^X */
-	{NULL},
+	VINULLKEY,
 /* 031  ^Y */
 	{v_lineup,	V_CNT,
 	    "[count]^Y",
@@ -142,7 +143,7 @@
 	    "^^",
 	    "^^ switch to previous file"},
 /* 037  ^_ */
-	{NULL},
+	VINULLKEY,
 /* 040 ' ' */
 	{v_right,	V_CNT|V_MOVE|VM_RCM_SET,
 	    "[count]' '",
@@ -152,7 +153,7 @@
 	    "[count]![count]motion command(s)",
 	    " ! filter through command(s) to motion"},
 /* 042   " */
-	{NULL},
+	VINULLKEY,
 /* 043   # */
 	{v_increment,	V_CHAR|V_CNT|V_DOT|VM_RCM_SET,
 	    "[count]# +|-|#",
@@ -182,7 +183,7 @@
 	    "[count])",
 	    " ) move forward sentence"},
 /* 052   * */
-	{NULL},
+	VINULLKEY,
 /* 053   + */
 	{v_down,	V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETFNB,
 	    "[count]+",
@@ -208,23 +209,23 @@
 	    "0",
 	    " 0 move to first character"},
 /* 061   1 */
-	{NULL},
+	VINULLKEY,
 /* 062   2 */
-	{NULL},
+	VINULLKEY,
 /* 063   3 */
-	{NULL},
+	VINULLKEY,
 /* 064   4 */
-	{NULL},
+	VINULLKEY,
 /* 065   5 */
-	{NULL},
+	VINULLKEY,
 /* 066   6 */
-	{NULL},
+	VINULLKEY,
 /* 067   7 */
-	{NULL},
+	VINULLKEY,
 /* 070   8 */
-	{NULL},
+	VINULLKEY,
 /* 071   9 */
-	{NULL},
+	VINULLKEY,
 /* 072   : */
 	{v_ex,		0,
 	    ":command [| command] ...",
@@ -238,7 +239,7 @@
 	    "[count]<[count]motion",
 	    " < shift lines left to motion"},
 /* 075   = */
-	{NULL},
+	VINULLKEY,
 /* 076   > */
 	{v_shiftr,	V_CNT|V_DOT|V_MOTION|VM_RCM_SET,
 	    "[count]>[count]motion",
@@ -292,7 +293,7 @@
 	    "[count]J",
 	    " J join lines"},
 /* 113   K */
-	{NULL},
+	VINULLKEY,
 /* 114   L */
 	{v_bottom,	V_ABS_L|V_CNT|V_MOVE|VM_LMODE|VM_RCM_SETNNB,
 	    "[count]L",
@@ -334,7 +335,7 @@
 	    "U",
 	    " U Restore the current line"},
 /* 126   V */
-	{NULL},
+	VINULLKEY,
 /* 127   W */
 	{v_wordW,	V_CNT|V_MOVE|VM_RCM_SET,
 	    "[count]W",
@@ -356,7 +357,7 @@
 	    "[[",
 	    "[[ move back section"},
 /* 134   \ */
-	{NULL},
+	VINULLKEY,
 /* 135   ] */
 	{v_sectionf,	V_ABS|V_CNT|V_MOVE|VM_RCM_SET,
 	    "]]",
@@ -407,7 +408,7 @@
 	    "[count]f character",
 	    " f character in line forward search"},
 /* 147   g */
-	{NULL},
+	VINULLKEY,
 /* 150   h */
 	{v_left,	V_CNT|V_MOVE|VM_RCM_SET,
 	    "[count]h",
@@ -445,7 +446,7 @@
 	    "[buffer]p",
 	    " p insert after cursor from buffer"},
 /* 161   q */
-	{NULL},
+	VINULLKEY,
 /* 162   r */
 	{v_replace,	V_CNT|V_DOT|VM_RCM_SET,
 	    "[count]r character",
@@ -467,7 +468,7 @@
 	    "u",
 	    " u undo last change"},
 /* 166   v */
-	{NULL},
+	VINULLKEY,
 /* 167   w */
 	{v_wordw,	V_CNT|V_MOVE|VM_RCM_SET,
 	    "[count]w",
--- a/dist/nvi/vi/v_event.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_event.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_event.c,v 1.1.1.2 2008/05/18 14:31:41 aymeric Exp $ */
+/*	$NetBSD: v_event.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1996
@@ -95,7 +95,7 @@
 v_editopt(SCR *sp, VICMD *vp)
 {
 	int rval;
-	char *np;
+	const char *np;
 	size_t nlen;
 	char *p2;
 
@@ -210,7 +210,7 @@
  * v_sel_end --
  *	End selection.
  */
-int
+static int
 v_sel_end(SCR *sp, EVENT *evp)
 {
 	SMAP *smp;
@@ -233,7 +233,7 @@
  * v_sel_start --
  *	Start selection.
  */
-int
+static int
 v_sel_start(SCR *sp, EVENT *evp)
 {
 	SMAP *smp;
@@ -314,33 +314,34 @@
 v_event(SCR *sp, VICMD *vp)
 {
 	/* This array maps events to vi command functions. */
+#define VIKEYDEF(a, b) { a, b, NULL, NULL }
 	static VIKEYS const vievents[] = {
 #define	V_C_SETTOP	 0				/* VI_C_SETTOP */
-		{v_c_settop,	0},
+		VIKEYDEF(v_c_settop,	0),
 #define	V_EDIT		 1				/* VI_EDIT */
-		{v_edit,	0},
+		VIKEYDEF(v_edit,	0),
 #define	V_EDITOPT	 2				/* VI_EDITOPT */
-		{v_editopt,	0},
+		VIKEYDEF(v_editopt,	0),
 #define	V_EDITSPLIT	 3				/* VI_EDITSPLIT */
-		{v_editsplit,	0},
+		VIKEYDEF(v_editsplit,	0),
 #define	V_EMARK		 4				/* VI_MOUSE_MOVE */
-		{v_emark,	V_ABS_L|V_MOVE},
+		VIKEYDEF(v_emark,	V_ABS_L|V_MOVE),
 #define	V_QUIT		 5				/* VI_QUIT */
-		{v_quit,	0},
+		VIKEYDEF(v_quit,	0),
 #define	V_SEARCH	 6				/* VI_SEARCH */
-		{v_esearch,	V_ABS_L|V_MOVE},
+		VIKEYDEF(v_esearch,	V_ABS_L|V_MOVE),
 #define	V_TAG		 7				/* VI_TAG */
-		{v_tag,	0},
+		VIKEYDEF(v_tag,	0),
 #define	V_TAGAS	 8					/* VI_TAGAS */
-		{v_tagas,	0},
+		VIKEYDEF(v_tagas,	0),
 #define	V_TAGSPLIT	 9				/* VI_TAGSPLIT */
-		{v_tagsplit,	0},
+		VIKEYDEF(v_tagsplit,	0),
 #define	V_WQ		10				/* VI_WQ */
-		{v_wq,		0},
+		VIKEYDEF(v_wq,		0),
 #define	V_WRITE	11					/* VI_WRITE */
-		{v_write,	0},
+		VIKEYDEF(v_write,	0),
 #define	V_WRITEAS	12				/* VI_WRITEAS */
-		{v_writeas,	0},
+		VIKEYDEF(v_writeas,	0),
 	};
 
 	switch (vp->ev.e_ipcom) {
--- a/dist/nvi/vi/v_ex.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_ex.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_ex.c,v 1.2 2008/10/29 17:50:49 christos Exp $ */
+/*	$NetBSD: v_ex.c,v 1.2.2.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -178,7 +178,7 @@
 {
 	EXCMD cmd;
 	char *name;
-	CHAR_T *wp;
+	const CHAR_T *wp;
 	size_t wlen;
 
 	/*
--- a/dist/nvi/vi/v_increment.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_increment.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_increment.c,v 1.1.1.2 2008/05/18 14:31:40 aymeric Exp $ */
+/*	$NetBSD: v_increment.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -30,7 +30,7 @@
 #include "../common/common.h"
 #include "vi.h"
 
-static char * const fmt[] = {
+static const char * const fmt[] = {
 #define	DEC	0
 	"%ld",
 #define	SDEC	1
@@ -59,7 +59,8 @@
 	long change, ltmp, lval;
 	size_t beg, blen, end, len, nlen, wlen;
 	int base, isempty, rval;
-	char *ntype, nbuf[100];
+	const char *ntype;
+	char nbuf[100];
 	CHAR_T *bp, *p, *t;
 
 	/* Validate the operator. */
--- a/dist/nvi/vi/v_init.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_init.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_init.c,v 1.1.1.2 2008/05/18 14:31:42 aymeric Exp $ */
+/*	$NetBSD: v_init.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -105,10 +105,10 @@
  * v_optchange --
  *	Handle change of options for vi.
  *
- * PUBLIC: int v_optchange __P((SCR *, int, char *, u_long *));
+ * PUBLIC: int v_optchange __P((SCR *, int, const char *, u_long *));
  */
 int
-v_optchange(SCR *sp, int offset, char *str, u_long *valp)
+v_optchange(SCR *sp, int offset, const char *str, u_long *valp)
 {
 	switch (offset) {
 	case O_PARAGRAPHS:
--- a/dist/nvi/vi/v_mark.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_mark.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_mark.c,v 1.1.1.2 2008/05/18 14:31:42 aymeric Exp $ */
+/*	$NetBSD: v_mark.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -125,7 +125,7 @@
 		if (db_get(sp, vp->m_stop.lno, DBG_FATAL, NULL, &len))
 			return (1);
 		if (vp->m_stop.cno < len ||
-		    vp->m_stop.cno == len && len == 0)
+		    (vp->m_stop.cno == len && len == 0))
 			break;
 
 		if (ISMOTION(vp))
@@ -166,8 +166,8 @@
 	 * and backward motions can happen for any kind of search command.
 	 */
 	if (vp->m_start.lno > vp->m_stop.lno ||
-	    vp->m_start.lno == vp->m_stop.lno &&
-	    vp->m_start.cno > vp->m_stop.cno) {
+	    (vp->m_start.lno == vp->m_stop.lno &&
+	    vp->m_start.cno > vp->m_stop.cno)) {
 		m = vp->m_start;
 		vp->m_start = vp->m_stop;
 		vp->m_stop = m;
--- a/dist/nvi/vi/v_match.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_match.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_match.c,v 1.2 2008/10/01 21:20:09 christos Exp $ */
+/*	$NetBSD: v_match.c,v 1.2.4.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -42,7 +42,7 @@
 	int cnt, isempty, matchc, startc, (*gc)__P((SCR *, VCS *));
 	CHAR_T *p;
 	char *cp;
-	char *match_chars;
+	const char *match_chars;
 
 	static int match_lno, match_col, match_dir;
 
@@ -131,8 +131,8 @@
 	 * starting cursor position when deleting to a match.
 	 */
 	if (vp->m_start.lno < vp->m_stop.lno ||
-	    vp->m_start.lno == vp->m_stop.lno &&
-	    vp->m_start.cno < vp->m_stop.cno)
+	    (vp->m_start.lno == vp->m_stop.lno &&
+	    vp->m_start.cno < vp->m_stop.cno))
 		vp->m_final = ISMOTION(vp) ? vp->m_start : vp->m_stop;
 	else
 		vp->m_final = vp->m_stop;
--- a/dist/nvi/vi/v_paragraph.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_paragraph.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_paragraph.c,v 1.1.1.2 2008/05/18 14:31:43 aymeric Exp $ */
+/*	$NetBSD: v_paragraph.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -51,7 +51,7 @@
 		continue;						\
 	for (lp = VIP(sp)->ps; *lp != '\0'; lp += 2)			\
 		if (lp[0] == p[1] &&					\
-		    (lp[1] == ' ' && len == 2 || lp[1] == p[2]) &&	\
+		    ((lp[1] == ' ' && len == 2) || lp[1] == p[2]) &&	\
 		    !--cnt)						\
 			goto found;					\
 }
@@ -89,7 +89,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 {
@@ -100,6 +100,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;
@@ -232,7 +233,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);
@@ -242,6 +243,7 @@
 			F_SET(vp, VM_LMODE);
 		} else
 			--vp->m_start.cno;
+	}
 
 	if (vp->m_start.lno <= 1)
 		goto sof;
@@ -308,10 +310,10 @@
  * v_buildps --
  *	Build the paragraph command search pattern.
  *
- * PUBLIC: int v_buildps __P((SCR *, char *, char *));
+ * PUBLIC: int v_buildps __P((SCR *, const char *, const char *));
  */
 int
-v_buildps(SCR *sp, char *p_p, char *s_p)
+v_buildps(SCR *sp, const char *p_p, const char *s_p)
 {
 	VI_PRIVATE *vip;
 	size_t p_len, s_len;
--- a/dist/nvi/vi/v_replace.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_replace.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_replace.c,v 1.1.1.2 2008/05/18 14:31:43 aymeric Exp $ */
+/*	$NetBSD: v_replace.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -155,7 +155,7 @@
 	 * is different from the historic vi, which replaced N characters with
 	 * a single new line.  Users complained, so we match historic practice.
 	 */
-	if (!quote && vip->rvalue == K_CR || vip->rvalue == K_NL) {
+	if ((!quote && vip->rvalue == K_CR) || vip->rvalue == K_NL) {
 		/* Set return line. */
 		vp->m_stop.lno = vp->m_start.lno + 1;
 		vp->m_stop.cno = 0;
--- a/dist/nvi/vi/v_scroll.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_scroll.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_scroll.c,v 1.1.1.2 2008/05/18 14:31:44 aymeric Exp $ */
+/*	$NetBSD: v_scroll.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -192,8 +192,8 @@
 	 * stay at the start of the range.  Ignore others.
 	 */
 	if (vp->m_stop.lno < vp->m_start.lno ||
-	    vp->m_stop.lno == vp->m_start.lno &&
-	    vp->m_stop.cno < vp->m_start.cno) {
+	    (vp->m_stop.lno == vp->m_start.lno &&
+	    vp->m_stop.cno < vp->m_start.cno)) {
 		if (ISCMD(vp->rkp, 'y') && vp->m_stop.lno == vp->m_start.lno)
 			vp->m_final = vp->m_start;
 	} else
--- a/dist/nvi/vi/v_search.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_search.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_search.c,v 1.1.1.2 2008/05/18 14:31:44 aymeric Exp $ */
+/*	$NetBSD: v_search.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -65,7 +65,7 @@
 static int
 v_exaddr(SCR *sp, VICMD *vp, dir_t dir)
 {
-	static EXCMDLIST fake = { L("search") };
+	static EXCMDLIST fake = { .name = L("search") };
 	EXCMD *cmdp;
 	WIN *wp;
 	TEXT *tp;
@@ -74,7 +74,7 @@
 	int err, nb, type;
 	char buf[20];
 	CHAR_T *cmd, *t;
-	CHAR_T *w;
+	const CHAR_T *w;
 	size_t wlen;
 
 	/*
@@ -483,8 +483,8 @@
 	 * because of the wrapscan option.
 	 */
 	if (vp->m_start.lno > vp->m_stop.lno ||
-	    vp->m_start.lno == vp->m_stop.lno &&
-	    vp->m_start.cno > vp->m_stop.cno) {
+	    (vp->m_start.lno == vp->m_stop.lno &&
+	    vp->m_start.cno > vp->m_stop.cno)) {
 		m = vp->m_start;
 		vp->m_start = vp->m_stop;
 		vp->m_stop = m;
--- a/dist/nvi/vi/v_section.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_section.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_section.c,v 1.1.1.2 2008/05/18 14:31:44 aymeric Exp $ */
+/*	$NetBSD: v_section.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -69,7 +69,7 @@
 	db_recno_t cnt, lno;
 	size_t len;
 	CHAR_T *p;
-	char *list, *lp;
+	const char *list, *lp;
 
 	/* Get the macro list. */
 	if ((list = O_STR(sp, O_SECTIONS)) == NULL)
@@ -83,7 +83,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 {
@@ -94,12 +94,13 @@
 			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);) {
 		if (len == 0)
 			continue;
-		if (p[0] == '{' || ISMOTION(vp) && p[0] == '}') {
+		if (p[0] == '{' || (ISMOTION(vp) && p[0] == '}')) {
 			if (!--cnt) {
 				if (p[0] == '{')
 					goto adjust1;
@@ -123,7 +124,7 @@
 			continue;
 		for (lp = list; *lp != '\0'; lp += 2 * sizeof(*lp))
 			if (lp[0] == p[1] &&
-			    (lp[1] == ' ' && len == 2 || lp[1] == p[2]) &&
+			    ((lp[1] == ' ' && len == 2) || lp[1] == p[2]) &&
 			    !--cnt) {
 				/*
 				 * !!!
@@ -176,7 +177,7 @@
 	size_t len;
 	db_recno_t cnt, lno;
 	CHAR_T *p;
-	char *list, *lp;
+	const char *list, *lp;
 
 	/* An empty file or starting from line 1 is always illegal. */
 	if (vp->m_start.lno <= 1) {
@@ -213,7 +214,7 @@
 			continue;
 		for (lp = list; *lp != '\0'; lp += 2 * sizeof(*lp))
 			if (lp[0] == p[1] &&
-			    (lp[1] == ' ' && len == 2 || lp[1] == p[2]) &&
+			    ((lp[1] == ' ' && len == 2) || lp[1] == p[2]) &&
 			    !--cnt) {
 adjust1:			vp->m_stop.lno = lno;
 				vp->m_stop.cno = 0;
--- a/dist/nvi/vi/v_sentence.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_sentence.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_sentence.c,v 1.1.1.2 2008/05/18 14:31:44 aymeric Exp $ */
+/*	$NetBSD: v_sentence.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -74,7 +74,7 @@
 	 * This may not handle "  .  " correctly, but it's real unclear
 	 * what correctly means in that case.
 	 */
-	if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && isblank(cs.cs_ch)) {
+	if (cs.cs_flags == CS_EMP || (cs.cs_flags == 0 && isblank(cs.cs_ch))) {
 		if (cs_fblank(sp, &cs))
 			return (1);
 		if (--cnt == 0) {
@@ -342,7 +342,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,
@@ -352,6 +352,7 @@
 			F_SET(vp, VM_LMODE);
 		} else
 			--vp->m_start.cno;
+	}
 	vp->m_final = vp->m_stop;
 	return (0);
 }
--- a/dist/nvi/vi/v_txt.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_txt.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_txt.c,v 1.1.1.2 2008/05/18 14:31:47 aymeric Exp $ */
+/*	$NetBSD: v_txt.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -252,7 +252,7 @@
 	              		/* Replay count. */
 	                	/* TXT_* flags. */
 {
-	EVENT ev, *evp;		/* Current event. */
+	EVENT ev, *evp = NULL;	/* Current event. */
 	EVENT fc;		/* File name completion event. */
 	GS *gp;
 	TEXT *ntp, *tp;		/* Input text structures. */
@@ -281,6 +281,7 @@
 
 	gp = sp->gp;
 	vip = VIP(sp);
+	memset(&wmt, 0, sizeof(wmt));
 
 	/*
 	 * Set the input flag, so tabs get displayed correctly
@@ -1559,7 +1560,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(sp, p, len)) {
 				*turnoffp = 1;
@@ -1569,6 +1570,7 @@
 		else
 			if (*turnoffp)
 				return (0);
+	}
 
 	/* Check for any abbreviations. */
 	if ((qp = seq_find(sp, NULL, NULL, p, len, SEQ_ABBREV, NULL)) == NULL)
@@ -1677,7 +1679,7 @@
 txt_ai_resolve(SCR *sp, TEXT *tp, int *changedp)
 {
 	u_long ts;
-	int del;
+	int delc;
 	size_t cno, len, new, old, scno, spaces, tab_after_sp, tabs;
 	CHAR_T *p;
 
@@ -1722,7 +1724,7 @@
 	 * If there are no spaces, or no tabs after spaces and less than
 	 * ts spaces, it's already minimal.
 	 */
-	if (!spaces || !tab_after_sp && spaces < ts)
+	if (!spaces || (!tab_after_sp && spaces < ts))
 		return;
 
 	/* Count up spaces/tabs needed to get to the target. */
@@ -1740,10 +1742,10 @@
 		return;
 
 	/* Shift the rest of the characters down, adjust the counts. */
-	del = old - new;
-	MEMMOVEW(p - del, p, tp->len - old);
-	tp->len -= del;
-	tp->cno -= del;
+	delc = old - new;
+	MEMMOVEW(p - delc, p, tp->len - old);
+	tp->len -= delc;
+	tp->cno -= delc;
 
 	/* Fill in space/tab characters. */
 	for (p = tp->lb; tabs--;)
@@ -1890,7 +1892,7 @@
 {
 	CHAR_T ch;
 	u_long sw, ts;
-	size_t cno, current, spaces, target, tabs, off;
+	size_t cno, current, spaces, target, tabs;
 	int ai_reset;
 
 	ts = O_VAL(sp, O_TABSTOP);
@@ -1919,8 +1921,10 @@
 	target = current;
 	if (isindent)
 		target += COL_OFF(target, sw);
-	else
-		target -= --target % sw;
+	else {
+		--target;
+		target -= target % sw;
+	}
 
 	/*
 	 * The AI characters will be turned into overwrite characters if the
@@ -1994,7 +1998,7 @@
 	size_t indx, len, nlen, off;
 	int argc, trydir;
 	CHAR_T *p, *t;
-	char *np;
+	const char *np;
 	size_t nplen;
 
 	trydir = 0;
@@ -2148,7 +2152,8 @@
 	GS *gp;
 	size_t base, cnt, col, colwidth, numrows, numcols, prefix, row;
 	int ac, nf, reset;
-	char *np, *pp;
+	const char *np;
+	char *pp;
 	size_t nlen;
 
 	gp = sp->gp;
@@ -2261,7 +2266,7 @@
 txt_emark(SCR *sp, TEXT *tp, size_t cno)
 {
 	CHAR_T ch;
-	char *kp;
+	unsigned char *kp;
 	size_t chlen, nlen, olen;
 	CHAR_T *p;
 
@@ -2424,7 +2429,7 @@
 static int
 txt_insch(SCR *sp, TEXT *tp, CHAR_T *chp, u_int flags)
 {
-	char *kp;
+	unsigned char *kp;
 	CHAR_T savech;
 	size_t chlen, cno, copydown, olen, nlen;
 	CHAR_T *p;
@@ -2678,7 +2683,7 @@
 	else
 		changed = 0;
 	if (db_set(sp, tp->lno, tp->lb, tp->len) ||
-	    changed && vs_change(sp, tp->lno, LINE_RESET))
+	    (changed && vs_change(sp, tp->lno, LINE_RESET)))
 		return (1);
 
 	for (lno = tp->lno; (tp = tp->q.cqe_next) != (void *)&sp->tiq; ++lno) {
@@ -2687,7 +2692,7 @@
 		else
 			changed = 0;
 		if (db_append(sp, 0, lno, tp->lb, tp->len) ||
-		    changed && vs_change(sp, tp->lno, LINE_RESET))
+		    (changed && vs_change(sp, tp->lno, LINE_RESET)))
 			return (1);
 	}
 
@@ -2760,7 +2765,7 @@
 	}
 
 	/* If the match is on the screen, move to it. */
-	if (cs.cs_lno < m.lno || cs.cs_lno == m.lno && cs.cs_cno < m.cno)
+	if (cs.cs_lno < m.lno || (cs.cs_lno == m.lno && cs.cs_cno < m.cno))
 		return (0);
 	sp->lno = cs.cs_lno;
 	sp->cno = cs.cs_cno;
--- a/dist/nvi/vi/v_util.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_util.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_util.c,v 1.1.1.2 2008/05/18 14:31:47 aymeric Exp $ */
+/*	$NetBSD: v_util.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -134,10 +134,10 @@
  * v_emsg --
  *	Display a few common vi messages.
  *
- * PUBLIC: void v_emsg __P((SCR *, char *, vim_t));
+ * PUBLIC: void v_emsg __P((SCR *, const char *, vim_t));
  */
 void
-v_emsg(SCR *sp, char *p, vim_t which)
+v_emsg(SCR *sp, const char *p, vim_t which)
 {
 	switch (which) {
 	case VIM_COMBUF:
--- a/dist/nvi/vi/v_word.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/v_word.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: v_word.c,v 1.1.1.2 2008/05/18 14:31:48 aymeric Exp $ */
+/*	$NetBSD: v_word.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -120,7 +120,7 @@
 	 *	counts as a single word move.  If it's a motion command,
 	 *	don't move off the end of the line.
 	 */
-	if (cs.cs_flags == CS_EMP || cs.cs_flags == 0 && isblank(cs.cs_ch)) {
+	if (cs.cs_flags == CS_EMP || (cs.cs_flags == 0 && isblank(cs.cs_ch))) {
 		if (ISMOTION(vp) && cs.cs_flags != CS_EMP && cnt == 1) {
 			if (ISCMD(vp->rkp, 'c'))
 				return (0);
--- a/dist/nvi/vi/vi.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/vi.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vi.c,v 1.1.1.2 2008/05/18 14:31:49 aymeric Exp $ */
+/*	$NetBSD: vi.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -67,7 +67,7 @@
 {
 	GS *gp;
 	WIN *wp;
-	MARK abs;
+	MARK abst;
 	SCR *next, *sp;
 	VICMD cmd, *vp;
 	VI_PRIVATE *vip;
@@ -170,7 +170,8 @@
 
 		/* Check for security setting. */
 		if (F_ISSET(vp->kp, V_SECURE) && O_ISSET(sp, O_SECURE)) {
-			ex_emsg(sp, KEY_NAME(sp, vp->key), EXM_SECURE);
+			ex_emsg(sp, (const char *)KEY_NAME(sp, vp->key),
+			    EXM_SECURE);
 			goto err;
 		}
 
@@ -187,8 +188,8 @@
 
 		/* Prepare to set the previous context. */
 		if (F_ISSET(vp, V_ABS | V_ABS_C | V_ABS_L)) {
-			abs.lno = sp->lno;
-			abs.cno = sp->cno;
+			abst.lno = sp->lno;
+			abst.cno = sp->cno;
 		}
 
 		/*
@@ -345,10 +346,10 @@
 		 * command, since the tag may be moving to the same file.
 		 */
 		if ((F_ISSET(vp, V_ABS) ||
-		    F_ISSET(vp, V_ABS_L) && sp->lno != abs.lno ||
-		    F_ISSET(vp, V_ABS_C) &&
-		    (sp->lno != abs.lno || sp->cno != abs.cno)) &&
-		    mark_set(sp, ABSMARK1, &abs, 1))
+		    (F_ISSET(vp, V_ABS_L) && sp->lno != abst.lno) ||
+		    (F_ISSET(vp, V_ABS_C) &&
+		    (sp->lno != abst.lno || sp->cno != abst.cno))) &&
+		    mark_set(sp, ABSMARK1, &abst, 1))
 			goto err;
 
 		if (0) {
@@ -453,7 +454,7 @@
 	VIKEYS const *kp;
 	gcret_t gcret;
 	u_int flags;
-	char *s;
+	const char *s;
 
 	/*
 	 * Get an event command or a key.  Event commands are simple, and
@@ -554,7 +555,7 @@
 	/* Check for an OOB command key. */
 	cpart = ISPARTIAL;
 	if (key > MAXVIKEY) {
-		v_emsg(sp, KEY_NAME(sp, key), VIM_NOCOM);
+		v_emsg(sp, (const char *)KEY_NAME(sp, key), VIM_NOCOM);
 		return (GC_ERR);
 	}
 	kp = &vikeys[vp->key = key];
@@ -592,7 +593,7 @@
 	 */
 	if (kp->func == NULL) {
 		if (key != '.') {
-			v_emsg(sp, KEY_NAME(sp, key),
+			v_emsg(sp, (const char *)KEY_NAME(sp, key),
 			    vp->ev.e_value == K_ESCAPE ?
 			    VIM_NOCOM_B : VIM_NOCOM);
 			return (GC_ERR);
@@ -803,7 +804,7 @@
 		vp->m_stop.lno = sp->lno + motion.count - 1;
 		if (db_get(sp, vp->m_stop.lno, 0, NULL, &len)) {
 			if (vp->m_stop.lno != 1 ||
-			   vp->key != 'c' && vp->key != '!') {
+			   (vp->key != 'c' && vp->key != '!')) {
 				v_emsg(sp, NULL, VIM_EMPTY);
 				return (1);
 			}
@@ -875,7 +876,7 @@
 		 */
 		if (!db_exist(sp, vp->m_stop.lno)) {
 			if (vp->m_stop.lno != 1 ||
-			   vp->key != 'c' && vp->key != '!') {
+			   (vp->key != 'c' && vp->key != '!')) {
 				v_emsg(sp, NULL, VIM_EMPTY);
 				return (1);
 			}
@@ -919,8 +920,8 @@
 		 * Motions are from the from MARK to the to MARK (inclusive).
 		 */
 		if (motion.m_start.lno > motion.m_stop.lno ||
-		    motion.m_start.lno == motion.m_stop.lno &&
-		    motion.m_start.cno > motion.m_stop.cno) {
+		    (motion.m_start.lno == motion.m_stop.lno &&
+		    motion.m_start.cno > motion.m_stop.cno)) {
 			vp->m_start = motion.m_stop;
 			vp->m_stop = motion.m_start;
 		} else {
--- a/dist/nvi/vi/vi.h	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/vi.h	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vi.h,v 1.2 2008/08/27 10:18:41 christos Exp $ */
+/*	$NetBSD: vi.h,v 1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -147,8 +147,8 @@
 #define	V_RBUF		0x01000000	/* Buffer (required, trailing). */
 #define	V_SECURE	0x02000000	/* Permission denied if O_SECURE set. */
 	u_int32_t flags;
-	char	*usage;			/* Usage line. */
-	char	*help;			/* Help line. */
+	const char *usage;		/* Usage line. */
+	const char *help;		/* Help line. */
 };
 #define	MAXVIKEY	126		/* List of vi commands. */
 extern VIKEYS const vikeys[MAXVIKEY + 1];
--- a/dist/nvi/vi/vs_line.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/vs_line.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vs_line.c,v 1.1.1.2 2008/05/18 14:31:50 aymeric Exp $ */
+/*	$NetBSD: vs_line.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -42,7 +42,7 @@
 int
 vs_line(SCR *sp, SMAP *smp, size_t *yp, size_t *xp)
 {
-	char *kp;
+	unsigned char *kp;
 	GS *gp;
 	SMAP *tsmp;
 	size_t chlen, cno_cnt, cols_per_screen, len, nlen;
@@ -52,7 +52,7 @@
 	int list_tab, list_dollar;
 	CHAR_T *p;
 	CHAR_T *cbp, *ecbp, cbuf[128];
-	CHAR_T ch;
+	CHAR_T ch = '\0';
 
 #if defined(DEBUG) && 0
 	vtrace(sp, "vs_line: row %u: line: %u off: %u\n",
@@ -141,7 +141,8 @@
 			cols_per_screen -= O_NUMBER_LENGTH;
 			if ((!dne || smp->lno == 1) && skip_cols == 0) {
 				nlen = snprintf((char*)cbuf,
-				    sizeof(cbuf), O_NUMBER_FMT, smp->lno);
+				    sizeof(cbuf), O_NUMBER_FMT,
+				    (unsigned long)smp->lno);
 				(void)gp->scr_addstr(sp, (char*)cbuf, nlen);
 			}
 		}
@@ -171,7 +172,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) {
@@ -186,8 +187,10 @@
 				if (list_dollar) {
 					ch = L('$');
 empty:					(void)gp->scr_addstr(sp,
-					    KEY_NAME(sp, ch), KEY_LEN(sp, ch));
+					    (const char *)KEY_NAME(sp, ch),
+					    KEY_LEN(sp, ch));
 				}
+		}
 
 		(void)gp->scr_clrtoeol(sp);
 		(void)gp->scr_move(sp, oldy, oldx);
@@ -534,7 +537,8 @@
 			break;
 
 		(void)gp->scr_move(sp, smp - HMAP, 0);
-		len = snprintf(nbuf, sizeof(nbuf), O_NUMBER_FMT, smp->lno);
+		len = snprintf(nbuf, sizeof(nbuf), O_NUMBER_FMT,
+		    (unsigned long)smp->lno);
 		(void)gp->scr_addstr(sp, nbuf, len);
 	}
 	(void)gp->scr_move(sp, oldy, oldx);
--- a/dist/nvi/vi/vs_msg.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/vs_msg.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vs_msg.c,v 1.1.1.2 2008/05/18 14:31:51 aymeric Exp $ */
+/*	$NetBSD: vs_msg.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -162,7 +162,7 @@
 {
 	GS *gp;
 	size_t len, mlen, oldx, oldy;
-	CONST char *np;
+	const char *np;
 	size_t nlen;
 
 	gp = sp->gp;
@@ -244,12 +244,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
@@ -275,13 +276,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);
@@ -343,13 +345,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(*s); --len, ++s);
@@ -392,7 +395,7 @@
 static void
 vs_output(SCR *sp, mtype_t mtype, const char *line, int llen)
 {
-	char *kp;
+	unsigned char *kp;
 	GS *gp;
 	VI_PRIVATE *vip;
 	size_t chlen, notused;
--- a/dist/nvi/vi/vs_refresh.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/vs_refresh.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vs_refresh.c,v 1.1.1.2 2008/05/18 14:31:51 aymeric Exp $ */
+/*	$NetBSD: vs_refresh.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -147,7 +147,7 @@
 	VI_PRIVATE *vip;
 	db_recno_t lastline, lcnt;
 	size_t cwtotal, cnt, len, notused, off, y;
-	int ch, didpaint, isempty, leftright_warp;
+	int ch = 0, didpaint, isempty, leftright_warp;
 	CHAR_T *p;
 
 #define	 LNO	sp->lno			/* Current file line. */
@@ -223,7 +223,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))
@@ -260,6 +260,7 @@
 				goto adjust;
 			}
 		}
+	}
 
 	/*
 	 * 6b: Line down, or current screen.
@@ -371,7 +372,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);
@@ -380,7 +381,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);
@@ -389,6 +391,7 @@
 				while (cnt > TMAP->soff)
 					if (vs_sm_1up(sp))
 						return (1);
+		}
 	}
 
 	/*
@@ -589,8 +592,8 @@
 		}
 
 		/* Adjust the window towards the end of the line. */
-		if (off == 0 && off + SCREEN_COLS(sp) < cnt ||
-		    off != 0 && off + sp->cols < cnt) {
+		if ((off == 0 && off + SCREEN_COLS(sp) < cnt) ||
+		    (off != 0 && off + sp->cols < cnt)) {
 			do {
 				off += O_VAL(sp, O_SIDESCROLL);
 			} while (off + sp->cols < cnt);
@@ -744,7 +747,7 @@
 static void
 vs_modeline(SCR *sp)
 {
-	static char * const modes[] = {
+	static const char * const modes[] = {
 		"215|Append",			/* SM_APPEND */
 		"216|Change",			/* SM_CHANGE */
 		"217|Command",			/* SM_COMMAND */
@@ -753,7 +756,7 @@
 	};
 	GS *gp;
 	size_t cols, curcol, curlen, endpoint, len, midpoint;
-	const char *t;
+	const char *t = NULL;
 	int ellipsis;
 	char *p, buf[20];
 
@@ -797,13 +800,14 @@
 		if (ellipsis) {
 			while (ellipsis--)
 				(void)gp->scr_addstr(sp,
-				    KEY_NAME(sp, '.'), KEY_LEN(sp, '.'));
+				    (const char *)KEY_NAME(sp, '.'),
+				    KEY_LEN(sp, '.'));
 			(void)gp->scr_addstr(sp,
-			    KEY_NAME(sp, ' '), KEY_LEN(sp, ' '));
+			    (const char *)KEY_NAME(sp, ' '), KEY_LEN(sp, ' '));
 		}
 		for (; *p != '\0'; ++p)
 			(void)gp->scr_addstr(sp,
-			    KEY_NAME(sp, *p), KEY_LEN(sp, *p));
+			    (const char *)KEY_NAME(sp, *p), KEY_LEN(sp, *p));
 	}
 
 	/* Clear the rest of the line. */
@@ -824,7 +828,8 @@
 	if (O_ISSET(sp, O_RULER)) {
 		vs_column(sp, &curcol);
 		len =
-		    snprintf(buf, sizeof(buf), "%lu,%lu", sp->lno, curcol + 1);
+		    snprintf(buf, sizeof(buf), "%lu,%lu",
+			(unsigned long)sp->lno, (unsigned long)curcol + 1);
 
 		midpoint = (cols - ((len + 1) / 2)) / 2;
 		if (curlen < midpoint) {
@@ -856,7 +861,8 @@
 		if (O_ISSET(sp, O_SHOWMODE)) {
 			if (F_ISSET(sp->ep, F_MODIFIED))
 				(void)gp->scr_addstr(sp,
-				    KEY_NAME(sp, '*'), KEY_LEN(sp, '*'));
+				    (const char *)KEY_NAME(sp, '*'),
+				    KEY_LEN(sp, '*'));
 			(void)gp->scr_addstr(sp, t, len);
 		}
 	}
--- a/dist/nvi/vi/vs_relative.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/vs_relative.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vs_relative.c,v 1.1.1.2 2008/05/18 14:31:41 aymeric Exp $ */
+/*	$NetBSD: vs_relative.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -100,7 +100,7 @@
 size_t
 vs_columns(SCR *sp, CHAR_T *lp, db_recno_t lno, size_t *cnop, size_t *diffp)
 {
-	size_t chlen, cno, curoff, last, len, scno;
+	size_t chlen, cno, curoff, last = 0, len, scno;
 	int ch, leftright, listset;
 	CHAR_T *p;
 
@@ -150,12 +150,13 @@
 	 */
 #define	TAB_RESET {							\
 	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;				\
+	}								\
 }
 	if (cnop == NULL)
 		while (len--) {
@@ -226,7 +227,7 @@
 vs_colpos(SCR *sp, db_recno_t lno, size_t cno)
 {
 	size_t chlen, curoff, len, llen, off, scno;
-	int ch, leftright, listset;
+	int ch = 0, leftright, listset;
 	CHAR_T *lp, *p;
 
 	/* Need the line to go any further. */
--- a/dist/nvi/vi/vs_split.c	Tue Jan 20 02:14:45 2009 +0000
+++ b/dist/nvi/vi/vs_split.c	Tue Jan 20 02:41:11 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vs_split.c,v 1.1.1.2 2008/05/18 14:31:53 aymeric Exp $ */
+/*	$NetBSD: vs_split.c,v 1.1.1.2.6.1 2009/01/20 02:41:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -31,7 +31,7 @@
 
 typedef enum { HORIZ_FOLLOW, HORIZ_PRECEDE, VERT_FOLLOW, VERT_PRECEDE } jdir_t;
 
-static SCR	*vs_getbg __P((SCR *, char *));
+static SCR	*vs_getbg __P((SCR *, const char *));
 static void      vs_insert __P((SCR *sp, WIN *wp));
 static int	 vs_join __P((SCR *, SCR **, jdir_t *));
 
@@ -623,7 +623,7 @@
 	GS *gp;
 	WIN *wp;
 	SCR *nsp;
-	char *np;
+	const char *np;
 	size_t nlen;
 
 	gp = sp->gp;
@@ -710,10 +710,10 @@
  * vs_swap --
  *	Swap the current screen with a backgrounded one.
  *
- * PUBLIC: int vs_swap __P((SCR *, SCR **, char *));
+ * PUBLIC: int vs_swap __P((SCR *, SCR **, const char *));
  */
 int
-vs_swap(SCR *sp, SCR **nspp, char *name)
+vs_swap(SCR *sp, SCR **nspp, const char *name)
 {
 	GS *gp;
 	WIN *wp;
@@ -931,7 +931,7 @@
  *	background screen.
  */
 static SCR *
-vs_getbg(SCR *sp, char *name)
+vs_getbg(SCR *sp, const char *name)
 {
 	GS *gp;
 	SCR *nsp;