$NetBSD: patch-al,v 1.3 2006/04/11 15:08:38 joerg Exp $

--- uip/vmh.c.orig	2006-04-11 14:16:00.000000000 +0000
+++ uip/vmh.c
@@ -113,13 +113,20 @@ void     __cputchar __P((int));
 #define	SMALLMOVE	1
 #define	LARGEMOVE	10
 
+#ifndef A_CHARTEXT
+#define	A_CHARTEXT	0xff
+#endif
 
 #define	XYZ			/* XXX */
 
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 5) || (defined(linux))
+#if (defined(__FreeBSD__) && __FreeBSD__ >= 5) || (defined(linux)) || defined(__DragonFly__)
 struct ldat
 {
+#ifdef __DragonFly__
+	char		*text;
+#else
 	NCURSES_CH_T	*text;
+#endif
 	NCURSES_SIZE_T	firstchar;
 	NCURSES_SIZE_T	lastchar;
 	NCURSES_SIZE_T	oldindex;
@@ -222,6 +229,15 @@ static struct ltchars ltc;
 #endif
 #endif	/* TIOCGLTC */
 
+#ifdef __NetBSD__
+static char *tc_CE, *tc_CM, *tc_SO, *tc_SE, *tc_US, *tc_UE;
+#define	CE	tc_CE
+#define	CM	tc_CM
+#define	SO	tc_SO
+#define	SE	tc_SE
+#define	US	tc_US
+#define	UE	tc_UE
+#endif
 
 #if !defined(SYS5) && !defined(BSD44) && !defined(TERMINFO)
 int	_putchar ();
@@ -239,7 +255,6 @@ static TYPESIG	TSTPser ();
 
 
 					/* MISCELLANY */
-extern int  errno;
 #if !defined(BSD44) && !defined(__GNU_LIBRARY__)
 extern int  sys_nerr;
 extern char *sys_errlist[];
@@ -348,7 +363,11 @@ static  vmh () {
 	wclrtoeol (Command);
 	wrefresh (Command);
 
-	switch (WINgetstr (Command, buffer)) {
+#ifndef JAPAN
+	switch (WINgetstr (Command, buffer, sizeof(buffer))) {
+#else
+	switch (WINgetstr (Command, (unsigned char *)buffer, sizeof(buffer))) {
+#endif
 	    case NOTOK: 
 		break;
 
@@ -808,6 +827,9 @@ static int  WINinit (nprog) {
     sideground ();
 
 #ifndef	TERMINFO
+#ifdef __NetBSD__
+    CM = getcap("cm");
+#endif
     if (CM == NULL)
 #else	/* TERMINFO */
     if (cursor_address == NULL)	/* assume mtr wanted "cm", not "CM" */
@@ -822,6 +844,15 @@ static int  WINinit (nprog) {
 #ifndef	TERMINFO
     if (tgetflag ("xt") || tgetnum ("sg") > 0)
 	SO = SE = US = UE = NULL;
+#ifdef __NetBSD__
+    else {
+	SO = getcap("so");
+	SE = getcap("se");
+	US = getcap("us");
+	UE = getcap("ue");
+    }
+    CE = getcap("ce");
+#endif
 #else	/* TERMINFO */
 /*
  * If termcap mapped directly to terminfo, we'd use the following:
@@ -862,21 +893,36 @@ static int  WINinit (nprog) {
 
 /*  */
 
-static int WINgetstr (w, buffer)
+static int WINgetstr (w, buffer, size)
 register WINDOW *w;
+#ifndef JAPAN
 char   *buffer;
+#else	/* JAPAN */
+unsigned char   *buffer;
+#endif	/* JAPAN */
+size_t    size;
 {
     register int    c;
+#ifndef JAPAN
     register char  *bp;
+#else	/* JAPAN */
+    register unsigned char  *bp;
+#endif	/* JAPAN */
 
     bp = buffer;
     *bp = 0;
+    --size;
 
     for (;;) {
-	switch (c = wgetch (w) & 0xff) {
-	    case ERR: 
-		adios (NULLCP, "wgetch lost");
+	c = wgetch(w);
+	if (c == ERR)
+	    adios (NULLCP, "wgetch lost");
+	if (bp - buffer >= size &&
+	    !(c == intrc || c == EOFC || c == ERASE || c == KILL ||
+	      c == WERASC || c == '\r' || c == '\n'))
+	    continue;
 
+	switch (c &= A_CHARTEXT) {
 	    case '\f':
 		wrefresh (curscr);
 		break;
@@ -1382,7 +1428,7 @@ WINDOW *w;
 	    lp -> l_buf[i] = w -> lines[getcury(w)] -> line[i].ch;
 #else
 	    wmove(w, getcury(w), i);
-	    lp -> l_buf[i] = winch(w); /* 8bit ?? */
+	    lp -> l_buf[i] = winch(w) & A_CHARTEXT;
 #endif
 	}
 	lp -> l_buf[getmaxx(w)] = '\0';
@@ -1413,8 +1459,12 @@ WINDOW *w;
     }
 #endif /* __NCURSES_H */
     for (cp = lp -> l_buf + strlen (lp -> l_buf) - 1; cp >= lp -> l_buf; cp--)
+#ifndef JAPAN
 	if (isspace (*cp))
-	    *cp = 0;
+#else	/* JAPAN */
+	if (isspace ((unsigned char)(*cp)))
+#endif	/* JAPAN */
+	    *cp = '\0';
 	else
 	    break;
 
@@ -1579,7 +1629,9 @@ static	TTYoff () {
 
     INTR = intrc;
 #ifndef	SYS5
+#ifndef __NetBSD__
     (void) ioctl (fileno (stdin), TIOCSETC, (char *) &tc);
+#endif
 #else	/* SYS5 */
 #if defined(TCGETATTR) && !defined(TCSETA) && defined(TCSANOW)
     (void) tcsetattr (fileno (stdin), TCSANOW, &sg);
@@ -1591,6 +1643,9 @@ static	TTYoff () {
     leaveok (curscr, TRUE);
     mvcur (0, COLS - 1, LINES - 1, 0);
     endwin ();
+#ifdef __NetBSD__
+    (void) ioctl (fileno (stdin), TIOCSETC, (char *) &tc);
+#endif
     if (tty_ready == DONE) {
 #ifndef	TERMINFO
 	if (CE)
