Reorganize the way that arguments are processed in lpc's generic-queue
commands, to make things a little cleaner (mainly for a later update). Reviewed by: freebsd-print@bostonradio.org MFC after: 10 days
This commit is contained in:
parent
6bfe568248
commit
d26b6e946e
@ -104,6 +104,7 @@ enum qsel_val { /* how a given ptr was selected */
|
|||||||
|
|
||||||
static enum qsel_val generic_qselect; /* indicates how ptr was selected */
|
static enum qsel_val generic_qselect; /* indicates how ptr was selected */
|
||||||
static int generic_initerr; /* result of initrtn processing */
|
static int generic_initerr; /* result of initrtn processing */
|
||||||
|
static char *generic_cmdname;
|
||||||
static char *generic_msg; /* if a -msg was specified */
|
static char *generic_msg; /* if a -msg was specified */
|
||||||
static char *generic_nullarg;
|
static char *generic_nullarg;
|
||||||
static void (*generic_wrapup)(int _last_status); /* perform rtn wrap-up */
|
static void (*generic_wrapup)(int _last_status); /* perform rtn wrap-up */
|
||||||
@ -114,7 +115,7 @@ generic(void (*specificrtn)(struct printer *_pp), int cmdopts,
|
|||||||
{
|
{
|
||||||
int cmdstatus, more, targc;
|
int cmdstatus, more, targc;
|
||||||
struct printer myprinter, *pp;
|
struct printer myprinter, *pp;
|
||||||
char **targv;
|
char **margv, **targv;
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
printf("usage: %s {all | printer ...}", argv[0]);
|
printf("usage: %s {all | printer ...}", argv[0]);
|
||||||
@ -124,6 +125,10 @@ generic(void (*specificrtn)(struct printer *_pp), int cmdopts,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The first argument is the command name. */
|
||||||
|
generic_cmdname = *argv++;
|
||||||
|
argc--;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The initialization routine for a command might set a generic
|
* The initialization routine for a command might set a generic
|
||||||
* "wrapup" routine, which should be called after processing all
|
* "wrapup" routine, which should be called after processing all
|
||||||
@ -149,8 +154,7 @@ generic(void (*specificrtn)(struct printer *_pp), int cmdopts,
|
|||||||
if (cmdopts & LPC_MSGOPT) {
|
if (cmdopts & LPC_MSGOPT) {
|
||||||
targc = argc;
|
targc = argc;
|
||||||
targv = argv;
|
targv = argv;
|
||||||
while (--targc) {
|
for (; targc > 0; targc--, targv++) {
|
||||||
++targv;
|
|
||||||
if (strcmp(*targv, "-msg") == 0) {
|
if (strcmp(*targv, "-msg") == 0) {
|
||||||
argc -= targc;
|
argc -= targc;
|
||||||
generic_msg = args2line(targc - 1, targv + 1);
|
generic_msg = args2line(targc - 1, targv + 1);
|
||||||
@ -165,22 +169,26 @@ generic(void (*specificrtn)(struct printer *_pp), int cmdopts,
|
|||||||
(*initrtn)(argc, argv);
|
(*initrtn)(argc, argv);
|
||||||
if (generic_initerr)
|
if (generic_initerr)
|
||||||
return;
|
return;
|
||||||
/* skip any initial arguments null-ified by initrtn */
|
/*
|
||||||
|
* The initrtn may have null'ed out some of the parameters.
|
||||||
|
* Compact the parameter list to remove those nulls, and
|
||||||
|
* correct the arg-count.
|
||||||
|
*/
|
||||||
targc = argc;
|
targc = argc;
|
||||||
targv = argv;
|
targv = argv;
|
||||||
while (--targc) {
|
margv = argv;
|
||||||
if (targv[1] != generic_nullarg)
|
argc = 0;
|
||||||
break;
|
for (; targc > 0; targc--, targv++) {
|
||||||
++targv;
|
if (*targv != generic_nullarg) {
|
||||||
}
|
if (targv != margv)
|
||||||
if (targv != argv) {
|
*margv = *targv;
|
||||||
targv[0] = argv[0]; /* copy the command-name */
|
margv++;
|
||||||
argv = targv;
|
argc++;
|
||||||
argc = targc + 1;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 2 && strcmp(argv[1], "all") == 0) {
|
if (argc == 1 && strcmp(*argv, "all") == 0) {
|
||||||
generic_qselect = QSEL_ALL;
|
generic_qselect = QSEL_ALL;
|
||||||
more = firstprinter(pp, &cmdstatus);
|
more = firstprinter(pp, &cmdstatus);
|
||||||
if (cmdstatus)
|
if (cmdstatus)
|
||||||
@ -206,10 +214,7 @@ looperr:
|
|||||||
}
|
}
|
||||||
|
|
||||||
generic_qselect = QSEL_BYNAME; /* specifically-named ptrs */
|
generic_qselect = QSEL_BYNAME; /* specifically-named ptrs */
|
||||||
while (--argc) {
|
for (; argc > 0; argc--, argv++) {
|
||||||
++argv;
|
|
||||||
if (*argv == generic_nullarg)
|
|
||||||
continue;
|
|
||||||
init_printer(pp);
|
init_printer(pp);
|
||||||
cmdstatus = getprintcap(*argv, pp);
|
cmdstatus = getprintcap(*argv, pp);
|
||||||
switch (cmdstatus) {
|
switch (cmdstatus) {
|
||||||
@ -693,8 +698,7 @@ init_clean(int argc, char *argv[])
|
|||||||
generic_wrapup = &wrapup_clean;
|
generic_wrapup = &wrapup_clean;
|
||||||
|
|
||||||
/* see if there are any options specified before the ptr list */
|
/* see if there are any options specified before the ptr list */
|
||||||
while (--argc) {
|
for (; argc > 0; argc--, argv++) {
|
||||||
++argv;
|
|
||||||
if (**argv != '-')
|
if (**argv != '-')
|
||||||
break;
|
break;
|
||||||
if (strcmp(*argv, "-d") == 0) {
|
if (strcmp(*argv, "-d") == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user