Module Name: src Committed By: kre Date: Wed Dec 12 20:22:43 UTC 2018
Modified Files: src/bin/kill: kill.c src/bin/sh: sh.1 trap.c Log Message: Reverse a decision made when the printsignals() routines from kill and sh were merged so that the shell (for trap -l) and kill (for kill -l) can use the same routine, and site that function in the shell, rather than in kill (use the code that is in kill as the basis for that routine). This allows access to sh internals, and in particular to the posix option, so the builtin kill can operate in posix mode where the standard requires just a single character (space of newline) between successive signal names (and we prefer nicely aligned columns instead).. In a SMALL shell, use the ancient sh printsignals routine instead, it is smaller (and very much dumber). /bin/kill still uses the routine that is in its source, and is not posix compliant. A task for some other day... To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/bin/kill/kill.c cvs rdiff -u -r1.215 -r1.216 src/bin/sh/sh.1 cvs rdiff -u -r1.49 -r1.50 src/bin/sh/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/kill/kill.c diff -u src/bin/kill/kill.c:1.29 src/bin/kill/kill.c:1.30 --- src/bin/kill/kill.c:1.29 Sun Oct 28 18:26:52 2018 +++ src/bin/kill/kill.c Wed Dec 12 20:22:43 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kill.c,v 1.29 2018/10/28 18:26:52 kre Exp $ */ +/* $NetBSD: kill.c,v 1.30 2018/12/12 20:22:43 kre Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)kill.c 8.4 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: kill.c,v 1.29 2018/10/28 18:26:52 kre Exp $"); +__RCSID("$NetBSD: kill.c,v 1.30 2018/12/12 20:22:43 kre Exp $"); #endif #endif /* not lint */ @@ -254,6 +254,7 @@ nosig(const char *name) /* NOTREACHED */ } +#ifndef SHELL /* * Print the names of all the signals (neatly) to fp * "len" gives the number of chars already printed to @@ -302,6 +303,7 @@ printsignals(FILE *fp, int len) if (len != 0) fprintf(fp, "\n"); } +#endif static void usage(void) Index: src/bin/sh/sh.1 diff -u src/bin/sh/sh.1:1.215 src/bin/sh/sh.1:1.216 --- src/bin/sh/sh.1:1.215 Wed Dec 12 12:56:17 2018 +++ src/bin/sh/sh.1 Wed Dec 12 20:22:43 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.215 2018/12/12 12:56:17 kre Exp $ +.\" $NetBSD: sh.1,v 1.216 2018/12/12 20:22:43 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -530,11 +530,16 @@ whether a colon (:) terminates the user other than in assignment statements .Dq ( no in posix mode), +the format of the output of the +.Ic kill Fl l +command, where posix mode causes the names of the signals +be separated by either a single space or newline, and where otherwise +sufficient spaces are inserted to generate nice looking columns, and whether the shell treats an empty brace-list compound statement as a syntax error (expected by POSIX) or permits it. Such statements -.Dq "{ }" +.Dq "{\ }" can be useful when defining dummy functions. Lastly, in posix mode, only one .Dq \&! Index: src/bin/sh/trap.c diff -u src/bin/sh/trap.c:1.49 src/bin/sh/trap.c:1.50 --- src/bin/sh/trap.c:1.49 Wed Dec 5 22:25:38 2018 +++ src/bin/sh/trap.c Wed Dec 12 20:22:43 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.49 2018/12/05 22:25:38 kre Exp $ */ +/* $NetBSD: trap.c,v 1.50 2018/12/12 20:22:43 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; #else -__RCSID("$NetBSD: trap.c,v 1.49 2018/12/05 22:25:38 kre Exp $"); +__RCSID("$NetBSD: trap.c,v 1.50 2018/12/12 20:22:43 kre Exp $"); #endif #endif /* not lint */ @@ -46,7 +46,11 @@ __RCSID("$NetBSD: trap.c,v 1.49 2018/12/ #include <stdlib.h> #include <stdio.h> #include <errno.h> +#include <termios.h> +#undef CEOF /* from <termios.h> but concflicts with sh use */ + +#include <sys/ioctl.h> #include <sys/resource.h> #include "shell.h" @@ -135,7 +139,7 @@ trap_signame(int signo) return nbuf; } -#if 0 /* Share the version of this in src/bin/kill/kill.c */ +#ifdef SMALL /* * Print a list of valid signal names */ @@ -154,7 +158,62 @@ printsignals(struct output *out, int len outc(' ', out); } } -#endif +#else /* !SMALL */ +/* + * Print the names of all the signals (neatly) to fp + * "len" gives the number of chars already printed to + * the current output line (in kill.c, always 0) + */ +void +printsignals(struct output *out, int len) +{ + int sig; + int nl, pad; + const char *name; + int termwidth = 80; + + if ((name = bltinlookup("COLUMNS", 1)) != NULL) + termwidth = (int)strtol(name, NULL, 10); + else if (isatty(1)) { + struct winsize win; + + if (ioctl(1, TIOCGWINSZ, &win) == 0 && win.ws_col > 0) + termwidth = win.ws_col; + } + + if (posix) + pad = 1; + else + pad = (len | 7) + 1 - len; + + for (sig = 0; (sig = signalnext(sig)) != 0; ) { + name = signalname(sig); + if (name == NULL) + continue; + + nl = strlen(name); + + if (len > 0 && nl + len + pad >= termwidth) { + outc('\n', out); + len = 0; + pad = 0; + } else if (pad > 0 && len != 0) + outfmt(out, "%*s", pad, ""); + else + pad = 0; + + len += nl + pad; + if (!posix) + pad = (nl | 7) + 1 - nl; + else + pad = 1; + + outstr(name, out); + } + if (len != 0) + outc('\n', out); +} +#endif /* SMALL */ /* * The trap builtin.