Your diff completely breaks a majority of the ways people use it.
Jan Stary <h...@stare.cz> wrote: > # dump /home > dump: option requires an argument -- h > > # dump /music > dump: option requires an argument -- s > > # dump /media > dump: option requires an argument -- d > > What? Before passing its options to getopt(), > dump's main() processes them with obsolete(): > > Change set of key letters and ordered arguments > into something getopt(3) will like. > > That results in the above. What obsolete options format > is this trying to accomodate? The manpage doesn't say - > the options it describes are perfectly getopt()-likable. > Looking at the CVS log, this was already "obsolete" > in the original 1995 import. Does anyone still use > that undescribed obsolete syntax dump "supports"? > > The diff below simply removes the function. > With the diff, dump does the right thing, > i.e. just tries to dump the given fs to rst0. > > # dump /home > DUMP: Date of this level 0 dump: Thu Jun 2 14:20:44 2022 > DUMP: Date of last level 0 dump: the epoch > DUMP: Dumping /dev/rsd0a (/home) to /dev/rst0 > DUMP: mapping (Pass I) [regular files] > DUMP: mapping (Pass II) [directories] > DUMP: estimated 47580129 tape blocks on 1222.00 tape(s). > DUMP: Cannot open output "/dev/rst0". > > Jan > > > Index: main.c > =================================================================== > RCS file: /cvs/src/sbin/dump/main.c,v > retrieving revision 1.62 > diff -u -p -r1.62 main.c > --- main.c 21 Jan 2021 00:16:36 -0000 1.62 > +++ main.c 2 Jun 2022 12:23:56 -0000 > @@ -99,7 +99,6 @@ struct disklabel lab; > static int sblock_try[] = SBLOCKSEARCH; > > static long long numarg(char *, long long, long long); > -static void obsolete(int *, char **[]); > static void usage(void); > > int > @@ -134,7 +133,6 @@ main(int argc, char *argv[]) > if (argc < 2) > usage(); > > - obsolete(&argc, &argv); > while ((ch = getopt(argc, argv, "0123456789aB:b:cd:f:h:ns:ST:uWw")) != > -1) > switch (ch) { > /* dump level */ > @@ -700,80 +698,4 @@ getduid(char *path) > } > > return (NULL); > -} > - > -/* > - * obsolete -- > - * Change set of key letters and ordered arguments into something > - * getopt(3) will like. > - */ > -static void > -obsolete(int *argcp, char **argvp[]) > -{ > - int argc, flags; > - char *ap, **argv, *flagsp, **nargv, *p; > - size_t len; > - > - /* Setup. */ > - argv = *argvp; > - argc = *argcp; > - > - /* Return if no arguments or first argument has leading dash. */ > - ap = argv[1]; > - if (argc == 1 || *ap == '-') > - return; > - > - /* Allocate space for new arguments. */ > - if ((*argvp = nargv = calloc(argc + 1, sizeof(char *))) == NULL || > - (p = flagsp = malloc(strlen(ap) + 2)) == NULL) > - err(1, NULL); > - > - *nargv++ = *argv; > - argv += 2; > - > - for (flags = 0; *ap; ++ap) { > - switch (*ap) { > - case 'B': > - case 'b': > - case 'd': > - case 'f': > - case 'h': > - case 's': > - case 'T': > - if (*argv == NULL) { > - warnx("option requires an argument -- %c", *ap); > - usage(); > - } > - len = 2 + strlen(*argv) + 1; > - if ((nargv[0] = malloc(len)) == NULL) > - err(1, NULL); > - nargv[0][0] = '-'; > - nargv[0][1] = *ap; > - (void)strlcpy(&nargv[0][2], *argv, len - 2); > - ++argv; > - ++nargv; > - break; > - default: > - if (!flags) { > - *p++ = '-'; > - flags = 1; > - } > - *p++ = *ap; > - break; > - } > - } > - > - /* Terminate flags, or toss the buffer we did not use. */ > - if (flags) { > - *p = '\0'; > - *nargv++ = flagsp; > - } else > - free(flagsp); > - > - /* Copy remaining arguments. */ > - while ((*nargv++ = *argv++)) > - continue; > - > - /* Update argument count. */ > - *argcp = nargv - *argvp - 1; > } >