On Tue, Jun 22, 2021 at 03:22:34PM +0000, Klemens Nanni wrote:
> On Tue, Jun 22, 2021 at 03:57:08PM +0100, Jason McIntyre wrote:
> > On Tue, Jun 22, 2021 at 02:19:32PM +0000, Klemens Nanni wrote:
> > > On Tue, Jun 22, 2021 at 01:47:13PM +0100, Jason McIntyre wrote:
> > > > after:
> > > >
> > > > $ /usr/obj/usr.bin/tset/tset -Z
> > > > tset: unknown option -- Z
> > > > usage: tset [-cIQqrsVw] [-] [-e ch] [-i ch] [-k ch] [-m mapping]
> > > > [terminal]
> > >
> > > OK kn
> > >
> >
> > thanks. i noticed sth else though:
> >
> > $ reset -Z
> > reset: unknown option -- Z
> > usage: tset [-cIQqrsVw] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]
> >
> > can we change it so that when you run tset as reset, the usage name
> > matches? i thought it would do that already but see now it does not. it
> > uses a weird _nc_progname argument in usage, which i do not understand
> > at all.
> Right, this is using /usr/src/lib/libcurses/tinfo/access.c
> _nc_rootname() here.
>
> > could it be easily fixed?
> I see no reason to not use getprogname(3) in usage(), with that our
> usage will always match the getopt(3) warning for `-Z'.
>
I think we should pull the assignment up. Our execve(2) guarantees that
argc >= 1, so it's safe to do *argv. We need to do this before calling
the internal err() the first time as that uses _nc_progname() internally.
Index: tset.c
===================================================================
RCS file: /cvs/src/usr.bin/tset/tset.c,v
retrieving revision 1.41
diff -u -p -r1.41 tset.c
--- tset.c 28 Jun 2019 13:35:05 -0000 1.41
+++ tset.c 22 Jun 2021 15:50:44 -0000
@@ -110,7 +110,7 @@ extern char **environ;
#undef CTRL
#define CTRL(x) ((x) & 0x1f)
-const char *_nc_progname = "tset";
+const char *_nc_progname;
static TTY mode, oldmode, original;
@@ -1094,28 +1094,9 @@ obsolete(char **argv)
static void
usage(void)
{
- static const char *tbl[] =
- {
- ""
- ,"Options:"
- ," -c set control characters"
- ," -e ch erase character"
- ," -I no initialization strings"
- ," -i ch interrupt character"
- ," -k ch kill character"
- ," -m mapping map identifier to type"
- ," -Q do not output control key settings"
- ," -r display term on stderr"
- ," -s output TERM set command"
- ," -V print curses-version"
- ," -w set window-size"
- };
- unsigned n;
- (void) fprintf(stderr, "Usage: %s [-cIQqrsVw] [-] "
- "[-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n",
+ (void) fprintf(stderr, "usage: %s [-cIQqrsVw] [-] "
+ "[-e ch] [-i ch] [-k ch] [-m mapping] [terminal]",
_nc_progname);
- for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); ++n)
- fprintf(stderr, "%s\n", tbl[n]);
exit_error();
/* NOTREACHED */
@@ -1136,6 +1117,8 @@ main(int argc, char **argv)
const char *p;
const char *ttype;
+ _nc_progname = _nc_rootname(*argv);
+
if (pledge("stdio rpath wpath tty", NULL) == -1)
err("pledge: %s", strerror(errno));
@@ -1198,8 +1181,6 @@ main(int argc, char **argv)
usage();
}
}
-
- _nc_progname = _nc_rootname(*argv);
argc -= optind;
argv += optind;