From naddy@mips.inka.de  Sat Oct 21 06:30:24 2000
Return-Path: <naddy@mips.inka.de>
Received: from mail.inka.de (quechua.inka.de [212.227.14.2])
	by hub.freebsd.org (Postfix) with ESMTP id 3377337B4CF
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 21 Oct 2000 06:30:23 -0700 (PDT)
Received: from kemoauc.mips.inka.de (uucp@)
	by mail.inka.de with local-bsmtp 
	id 13myj7-0000w0-00; Sat, 21 Oct 2000 15:30:21 +0200
Received: (from naddy@localhost)
	by kemoauc.mips.inka.de (8.11.0/8.11.0) id e9LCtSn71210;
	Sat, 21 Oct 2000 14:55:28 +0200 (CEST)
	(envelope-from naddy)
Message-Id: <200010211255.e9LCtSn71210@kemoauc.mips.inka.de>
Date: Sat, 21 Oct 2000 14:55:28 +0200 (CEST)
From: Christian Weisgerber <naddy@mips.inka.de>
Reply-To: naddy@mips.inka.de
To: FreeBSD-gnats-submit@freebsd.org
Subject: vi options noprint/print/octal broken
X-Send-Pr-Version: 3.2

>Number:         22182
>Category:       bin
>Synopsis:       vi(1) options noprint/print/octal broken
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 21 06:40:01 PDT 2000
>Closed-Date:    
>Last-Modified:  Mon Dec  9 18:50:02 UTC 2013
>Originator:     Christian Weisgerber
>Release:        FreeBSD 5.0-CURRENT alpha
>Organization:
>Environment:

>Description:

There's a bug in our vi (nvi 1.79).  The options "noprint", "print",
and "octal" don't work properly.  When these options are changed,
the routine that evaluates them is called before the option has
been set.

>How-To-Repeat:

For option "octal":
* Insert a non-printable character >0x80.
* :set octal
  => The character is still displayed in hex.
* :set nooctal
  => The display switches to octal.

Similarly for "print" and "noprint".

>Fix:

From NetBSD:

diff -ur /usr/src/contrib/nvi/common/options.c nvi/common/options.c
--- /usr/src/contrib/nvi/common/options.c	Sat Apr 19 01:36:33 1997
+++ nvi/common/options.c	Sat Oct 21 14:42:25 2000
@@ -128,11 +128,11 @@
 /* O_MSGCAT	  4.4BSD */
 	{"msgcat",	f_msgcat,	OPT_STR,	0},
 /* O_NOPRINT	  4.4BSD */
-	{"noprint",	f_print,	OPT_STR,	0},
+	{"noprint",	f_print,	OPT_STR,	OPT_EARLYSET},
 /* O_NUMBER	    4BSD */
 	{"number",	f_reformat,	OPT_0BOOL,	0},
 /* O_OCTAL	  4.4BSD */
-	{"octal",	f_print,	OPT_0BOOL,	0},
+	{"octal",	f_print,	OPT_0BOOL,	OPT_EARLYSET},
 /* O_OPEN	    4BSD */
 	{"open",	NULL,		OPT_1BOOL,	0},
 /* O_OPTIMIZE	    4BSD */
@@ -142,7 +142,7 @@
 /* O_PATH	  4.4BSD */
 	{"path",	NULL,		OPT_STR,	0},
 /* O_PRINT	  4.4BSD */
-	{"print",	f_print,	OPT_STR,	0},
+	{"print",	f_print,	OPT_STR,	OPT_EARLYSET},
 /* O_PROMPT	    4BSD */
 	{"prompt",	NULL,		OPT_1BOOL,	0},
 /* O_READONLY	    4BSD (undocumented) */
@@ -568,6 +568,14 @@
 						break;
 				}
 
+			if (F_ISSET(op, OPT_EARLYSET)) {
+			    /* Set the value. */
+			    if (turnoff)
+				O_CLR(sp, offset);
+			    else
+				O_SET(sp, offset);
+			}
+
 			/* Report to subsystems. */
 			if (op->func != NULL &&
 			    op->func(sp, spo, NULL, &turnoff) ||
@@ -578,11 +586,13 @@
 				break;
 			}
 
-			/* Set the value. */
-			if (turnoff)
+			if (!F_ISSET(op, OPT_EARLYSET)) {
+			    /* Set the value. */
+			    if (turnoff)
 				O_CLR(sp, offset);
-			else
+			    else
 				O_SET(sp, offset);
+			}
 			break;
 		case OPT_NUM:
 			if (turnoff) {
@@ -653,6 +663,14 @@
 			    O_VAL(sp, offset) == value)
 				break;
 
+			if (F_ISSET(op, OPT_EARLYSET)) {
+			    /* Set the value. */
+			    if (o_set(sp, offset, 0, NULL, value)) {
+				rval = 1;
+				break;
+			    }
+			}
+
 			/* Report to subsystems. */
 			if (op->func != NULL &&
 			    op->func(sp, spo, sep, &value) ||
@@ -663,9 +681,11 @@
 				break;
 			}
 
-			/* Set the value. */
-			if (o_set(sp, offset, 0, NULL, value))
+			if (!F_ISSET(op, OPT_EARLYSET)) {
+			    /* Set the value. */
+			    if (o_set(sp, offset, 0, NULL, value))
 				rval = 1;
+			}
 			break;
 		case OPT_STR:
 			if (turnoff) {
@@ -690,6 +710,14 @@
 			    !strcmp(O_STR(sp, offset), sep))
 				break;
 
+			if (F_ISSET(op, OPT_EARLYSET)) {
+			    /* Set the value. */
+			    if (o_set(sp, offset, OS_STRDUP, sep, 0)) {
+				rval = 1;
+				break;
+			    }
+			}
+
 			/* Report to subsystems. */
 			if (op->func != NULL &&
 			    op->func(sp, spo, sep, NULL) ||
@@ -700,9 +728,11 @@
 				break;
 			}
 
-			/* Set the value. */
-			if (o_set(sp, offset, OS_STRDUP, sep, 0))
+			if (!F_ISSET(op, OPT_EARLYSET)) {
+			    /* Set the value. */
+			    if (o_set(sp, offset, OS_STRDUP, sep, 0))
 				rval = 1;
+			}
 			break;
 		default:
 			abort();
diff -ur /usr/src/contrib/nvi/common/options.h nvi/common/options.h
--- /usr/src/contrib/nvi/common/options.h	Fri Nov  1 07:45:38 1996
+++ nvi/common/options.h	Sat Oct 21 14:41:48 2000
@@ -89,6 +89,7 @@
 #define	OPT_NOSET	0x010		/* Option may not be set. */
 #define	OPT_NOUNSET	0x020		/* Option may not be unset. */
 #define	OPT_NOZERO	0x040		/* Option may not be set to 0. */
+#define	OPT_EARLYSET	0x080		/* Func called after value is set */
 	u_int8_t flags;
 };
 

>Release-Note:
>Audit-Trail:

From: Zhihao Yuan <zhihao.yuan@rackspace.com>
To: bug-followup@FreeBSD.org, naddy@mips.inka.de
Cc:  
Subject: Re: bin/22182: vi(1) options noprint/print/octal broken
Date: Mon, 9 Dec 2013 13:43:27 -0500

 Fixed without additional flags in -CURRENT.
 
 PS: you may need LC_CTYPE=C (8-bit mode) to test this feature if the
 non-printable character is not a valid Unicode character.
 
 -- 
 Zhihao Yuan <zhihao.yuan@rackspace.com>
 The best way to predict the future is to invent it.
 ___________________________________________________
 4BSD -- http://4bsd.biz/
>Unformatted:
