Module Name:    src
Committed By:   martin
Date:           Wed Feb 10 16:56:52 UTC 2021

Modified Files:
        src/usr.bin/nl [netbsd-8]: nl.c

Log Message:
Pull up following revision(s) (requested by ginsbach in ticket #1651):

        usr.bin/nl/nl.c: revision 1.13
        usr.bin/nl/nl.c: revision 1.14
        usr.bin/nl/nl.c: revision 1.15

nl(1): remove superfluous exit

Remove exit(3) call missed when errors were converted to errx(3).

nl: fix -d delim parsing for POSIX
POSIX specifies it is possible to specify a one delimiter character.
Fix the logic so that both one and two character delimiters are accepted.

PR/55891 supress displaying separator when numbers supressed

Fix based on patch provided by Kobayashi Takashi. This brings nl(1) further
in to POSIX compliance. Verified behavior with classic SysV nl(1) and GNU
nl(1). There could still be edge cases here not specified by POSIX.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.12.18.1 src/usr.bin/nl/nl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/nl/nl.c
diff -u src/usr.bin/nl/nl.c:1.12 src/usr.bin/nl/nl.c:1.12.18.1
--- src/usr.bin/nl/nl.c:1.12	Tue Sep 17 20:00:50 2013
+++ src/usr.bin/nl/nl.c	Wed Feb 10 16:56:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nl.c,v 1.12 2013/09/17 20:00:50 wiz Exp $	*/
+/*	$NetBSD: nl.c,v 1.12.18.1 2021/02/10 16:56:52 martin Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: nl.c,v 1.12 2013/09/17 20:00:50 wiz Exp $");
+__RCSID("$NetBSD: nl.c,v 1.12.18.1 2021/02/10 16:56:52 martin Exp $");
 #endif    
 
 #include <errno.h>
@@ -157,14 +157,15 @@ main(int argc, char *argv[])
 		case 'd':
 			if (optarg[0] != '\0')
 				delim[0] = optarg[0];
-			if (optarg[1] != '\0')
+			if (optarg[1] != '\0') {
 				delim[1] = optarg[1];
-			/* at most two delimiter characters */
-			if (optarg[2] != '\0') {
-				errx(EXIT_FAILURE,
-				    "invalid delim argument -- %s",
-				    optarg);
-				/* NOTREACHED */
+				/* at most two delimiter characters */
+				if (optarg[2] != '\0') {
+					errx(EXIT_FAILURE,
+					    "invalid delim argument -- %s",
+					    optarg);
+					/* NOTREACHED */
+				}
 			}
 			break;
 		case 'f':
@@ -331,13 +332,13 @@ filter(void)
 		if (donumber) {
 			consumed = snprintf(intbuffer, intbuffersize, format,
 			    width, line);
-			(void)printf("%s",
-			    intbuffer + max(0, consumed - width));
+			(void)printf("%s%s",
+			    intbuffer + max(0, consumed - width), sep);
 			line += incr;
 		} else {
-			(void)printf("%*s", width, "");
+			(void)printf("%*s%*s", width, "", (int)strlen(sep), "");
 		}
-		(void)printf("%s%s", sep, buffer);
+		(void)printf("%s", buffer);
 
 		if (ferror(stdout))
 			err(EXIT_FAILURE, "output error");
@@ -392,7 +393,6 @@ parse_numbering(const char *argstr, int 
 		errx(EXIT_FAILURE,
 		    "illegal %s line numbering type -- %s",
 		    numbering_properties[section].name, argstr);
-		exit(EXIT_FAILURE);
 	}
 }
 

Reply via email to