From bdbfacc73eb01dc0bb79842da2b0da47d7c6aaab Mon Sep 17 00:00:00 2001 From: Michael Sweet Date: Wed, 25 May 2016 19:33:42 -0400 Subject: [PATCH] Support POSIX option processing (Issue #4813) --- CHANGES.txt | 1 + berkeley/lpq.c | 197 ++++++----- berkeley/lpr.c | 407 +++++++++++----------- berkeley/lprm.c | 148 ++++---- systemv/cancel.c | 164 ++++----- systemv/cupsaccept.c | 154 +++++---- systemv/lp.c | 702 +++++++++++++++++++------------------- systemv/lpadmin.c | 783 +++++++++++++++++++++---------------------- systemv/lpinfo.c | 327 +++++++++--------- systemv/lpmove.c | 67 ++-- systemv/lpoptions.c | 411 +++++++++++------------ systemv/lpstat.c | 598 ++++++++++++++++----------------- 12 files changed, 1980 insertions(+), 1979 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d8d1f7246..3fe44e5f6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,7 @@ CHANGES.txt - 2.2b1 - 2016-05-25 CHANGES IN CUPS V2.2b1 + - All CUPS commands now support POSIX options (Issue #4813) - Improved performance of web interface with large numbers of jobs (Issue #3819) - Encrypted printing can now be limited to only trusted printers and diff --git a/berkeley/lpq.c b/berkeley/lpq.c index 592a83665..f01168ca5 100644 --- a/berkeley/lpq.c +++ b/berkeley/lpq.c @@ -1,7 +1,7 @@ /* * "lpq" command for CUPS. * - * Copyright 2007-2014 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -39,7 +39,8 @@ main(int argc, /* I - Number of command-line arguments */ { int i; /* Looping var */ http_t *http; /* Connection to server */ - const char *dest, /* Desired printer */ + const char *opt, /* Option pointer */ + *dest, /* Desired printer */ *user, /* Desired user */ *val; /* Environment variable name */ char *instance; /* Printer instance */ @@ -65,128 +66,138 @@ main(int argc, /* I - Number of command-line arguments */ all = 0; for (i = 1; i < argc; i ++) + { if (argv[i][0] == '+') + { interval = atoi(argv[i] + 1); + } else if (argv[i][0] == '-') { - switch (argv[i][1]) + for (opt = argv[i] + 1; *opt; opt ++) { - case 'E' : /* Encrypt */ + switch (*opt) + { + case 'E' : /* Encrypt */ #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); - if (http) - httpEncryption(http, HTTP_ENCRYPT_REQUIRED); + if (http) + httpEncryption(http, HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), - argv[0]); + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ - break; - - case 'U' : /* Username */ - if (argv[i][2] != '\0') - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) + break; + + case 'U' : /* Username */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after " - "\"-U\" option."), argv[0]); - return (1); + cupsSetUser(opt + 1); + opt += strlen(opt) - 1; } + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]); + return (1); + } - cupsSetUser(argv[i]); - } - break; - - case 'P' : /* Printer */ - if (argv[i][2]) - dest = argv[i] + 2; - else - { - i ++; + cupsSetUser(argv[i]); + } + break; - if (i >= argc) + case 'P' : /* Printer */ + if (opt[1] != '\0') { - httpClose(http); + dest = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; + + if (i >= argc) + { + httpClose(http); + + usage(); + } - usage(); + dest = argv[i]; } - dest = argv[i]; - } - - if ((instance = strchr(dest, '/')) != NULL) - *instance++ = '\0'; - - http = connect_server(argv[0], http); - - if ((named_dest = cupsGetNamedDest(http, dest, instance)) == NULL) - { - if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || - cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); - else if (instance) - _cupsLangPrintf(stderr, - _("%s: Error - unknown destination \"%s/%s\"."), - argv[0], dest, instance); - else - _cupsLangPrintf(stderr, _("%s: Unknown destination \"%s\"."), - argv[0], dest); - - return (1); - } - - cupsFreeDests(1, named_dest); - break; - - case 'a' : /* All printers */ - all = 1; - break; - - case 'h' : /* Connect to host */ - if (http) - { - httpClose(http); - http = NULL; - } + if ((instance = strchr(dest, '/')) != NULL) + *instance++ = '\0'; - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; + http = connect_server(argv[0], http); - if (i >= argc) + if ((named_dest = cupsGetNamedDest(http, dest, instance)) == NULL) { - _cupsLangPrintf(stderr, - _("%s: Error - expected hostname after " - "\"-h\" option."), argv[0]); + if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) + _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); + else if (instance) + _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s/%s\"."), argv[0], dest, instance); + else + _cupsLangPrintf(stderr, _("%s: Unknown destination \"%s\"."), argv[0], dest); + return (1); - } + } + + cupsFreeDests(1, named_dest); + break; + + case 'a' : /* All printers */ + all = 1; + break; + + case 'h' : /* Connect to host */ + if (http) + { + httpClose(http); + http = NULL; + } + + if (opt[1] != '\0') + { + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } else - cupsSetServer(argv[i]); - } - break; + { + i ++; - case 'l' : /* Long status */ - longstatus = 1; - break; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]); + return (1); + } + else + cupsSetServer(argv[i]); + } + break; - default : - httpClose(http); + case 'l' : /* Long status */ + longstatus = 1; + break; - usage(); + default : + httpClose(http); + + usage(); + } } } else if (isdigit(argv[i][0] & 255)) + { id = atoi(argv[i]); + } else + { user = argv[i]; + } + } http = connect_server(argv[0], http); diff --git a/berkeley/lpr.c b/berkeley/lpr.c index eb58c8bd9..418ef4b55 100644 --- a/berkeley/lpr.c +++ b/berkeley/lpr.c @@ -1,7 +1,7 @@ /* * "lpr" command for CUPS. * - * Copyright 2007-2014 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2007 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -30,7 +30,8 @@ main(int argc, /* I - Number of command-line arguments */ int job_id; /* Job ID */ char ch; /* Option character */ char *printer, /* Destination printer or class */ - *instance; /* Instance */ + *instance, /* Instance */ + *opt; /* Option pointer */ const char *title, /* Job title */ *val; /* Environment variable name */ int num_copies; /* Number of copies per file */ @@ -54,229 +55,235 @@ main(int argc, /* I - Number of command-line arguments */ title = NULL; for (i = 1; i < argc; i ++) + { if (argv[i][0] == '-') { - switch (ch = argv[i][1]) + for (opt = argv[i] + 1; *opt; opt ++) { - case 'E' : /* Encrypt */ + switch (ch = *opt) + { + case 'E' : /* Encrypt */ #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), - argv[0]); + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ - break; - - case 'U' : /* Username */ - if (argv[i][2] != '\0') - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) + break; + + case 'U' : /* Username */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after " - "\"-U\" option."), argv[0]); - return (1); + cupsSetUser(opt + 1); + opt += strlen(opt) - 1; } + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]); + return (1); + } + + cupsSetUser(argv[i]); + } + break; - cupsSetUser(argv[i]); - } - break; - - case 'H' : /* Connect to host */ - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; + case 'H' : /* Connect to host */ + if (opt[1] != '\0') + { + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-H\" option."), argv[0]); + return (1); + } + else + cupsSetServer(argv[i]); + } + break; + + case '1' : /* TROFF font set 1 */ + case '2' : /* TROFF font set 2 */ + case '3' : /* TROFF font set 3 */ + case '4' : /* TROFF font set 4 */ + case 'i' : /* indent */ + case 'w' : /* width */ + if (opt[1] != '\0') + { + opt += strlen(opt) - 1; + } + else + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, + _("%s: Error - expected value after \"-%c\" " + "option."), argv[0], ch); + return (1); + } + } - if (i >= argc) + case 'c' : /* CIFPLOT */ + case 'd' : /* DVI */ + case 'f' : /* FORTRAN */ + case 'g' : /* plot */ + case 'n' : /* Ditroff */ + case 't' : /* Troff */ + case 'v' : /* Raster image */ + _cupsLangPrintf(stderr, _("%s: Warning - \"%c\" format modifier not supported - output may not be correct."), argv[0], ch); + break; + + case 'o' : /* Option */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected hostname after " - "\"-H\" option."), argv[0]); - return (1); - } + num_options = cupsParseOptions(opt + 1, num_options, &options); + opt += strlen(opt) - 1; + } else - cupsSetServer(argv[i]); - } - break; - - case '1' : /* TROFF font set 1 */ - case '2' : /* TROFF font set 2 */ - case '3' : /* TROFF font set 3 */ - case '4' : /* TROFF font set 4 */ - case 'i' : /* indent */ - case 'w' : /* width */ - if (argv[i][2] == '\0') - { - i ++; - - if (i >= argc) { - _cupsLangPrintf(stderr, - _("%s: Error - expected value after \"-%c\" " - "option."), argv[0], ch); - return (1); + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected option=value after \"-o\" option."), argv[0]); + return (1); + } + + num_options = cupsParseOptions(argv[i], num_options, &options); } - } - - case 'c' : /* CIFPLOT */ - case 'd' : /* DVI */ - case 'f' : /* FORTRAN */ - case 'g' : /* plot */ - case 'n' : /* Ditroff */ - case 't' : /* Troff */ - case 'v' : /* Raster image */ - _cupsLangPrintf(stderr, - _("%s: Warning - \"%c\" format modifier not " - "supported - output may not be correct."), - argv[0], ch); - break; - - case 'o' : /* Option */ - if (argv[i][2] != '\0') - num_options = cupsParseOptions(argv[i] + 2, num_options, &options); - else - { - i ++; - if (i >= argc) + break; + + case 'l' : /* Literal/raw */ + num_options = cupsAddOption("raw", "true", num_options, &options); + break; + + case 'p' : /* Prettyprint */ + num_options = cupsAddOption("prettyprint", "true", num_options, &options); + break; + + case 'h' : /* Suppress burst page */ + num_options = cupsAddOption("job-sheets", "none", num_options, &options); + break; + + case 's' : /* Don't use symlinks */ + break; + + case 'm' : /* Mail on completion */ { - _cupsLangPrintf(stderr, - _("%s: Error - expected option=value after " - "\"-o\" option."), argv[0]); - return (1); + char email[1024]; /* EMail address */ + + snprintf(email, sizeof(email), "mailto:%s@%s", cupsUser(), httpGetHostname(NULL, buffer, sizeof(buffer))); + num_options = cupsAddOption("notify-recipient-uri", email, num_options, &options); + } + break; + + case 'q' : /* Queue file but don't print */ + num_options = cupsAddOption("job-hold-until", "indefinite", num_options, &options); + break; + + case 'r' : /* Remove file after printing */ + deletefile = 1; + break; + + case 'P' : /* Destination printer or class */ + if (opt[1] != '\0') + { + printer = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected destination after \"-P\" option."), argv[0]); + return (1); + } + + printer = argv[i]; } - num_options = cupsParseOptions(argv[i], num_options, &options); - } - break; - - case 'l' : /* Literal/raw */ - num_options = cupsAddOption("raw", "true", num_options, &options); - break; - - case 'p' : /* Prettyprint */ - num_options = cupsAddOption("prettyprint", "true", num_options, - &options); - break; - - case 'h' : /* Suppress burst page */ - num_options = cupsAddOption("job-sheets", "none", num_options, - &options); - break; - - case 's' : /* Don't use symlinks */ - break; - - case 'm' : /* Mail on completion */ - { - char email[1024]; /* EMail address */ - - - snprintf(email, sizeof(email), "mailto:%s@%s", cupsUser(), - httpGetHostname(NULL, buffer, sizeof(buffer))); - num_options = cupsAddOption("notify-recipient-uri", email, - num_options, &options); - } - break; - - case 'q' : /* Queue file but don't print */ - num_options = cupsAddOption("job-hold-until", "indefinite", - num_options, &options); - break; - - case 'r' : /* Remove file after printing */ - deletefile = 1; - break; - - case 'P' : /* Destination printer or class */ - if (argv[i][2] != '\0') - printer = argv[i] + 2; - else - { - i ++; - if (i >= argc) + if ((instance = strrchr(printer, '/')) != NULL) + *instance++ = '\0'; + + if ((dest = cupsGetNamedDest(NULL, printer, instance)) != NULL) + { + for (j = 0; j < dest->num_options; j ++) + if (cupsGetOption(dest->options[j].name, num_options, + options) == NULL) + num_options = cupsAddOption(dest->options[j].name, + dest->options[j].value, + num_options, &options); + } + else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) { - _cupsLangPrintf(stderr, - _("%s: Error - expected destination after " - "\"-P\" option."), argv[0]); + _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); return (1); } + break; - printer = argv[i]; - } - - if ((instance = strrchr(printer, '/')) != NULL) - *instance++ = '\0'; - - if ((dest = cupsGetNamedDest(NULL, printer, instance)) != NULL) - { - for (j = 0; j < dest->num_options; j ++) - if (cupsGetOption(dest->options[j].name, num_options, - options) == NULL) - num_options = cupsAddOption(dest->options[j].name, - dest->options[j].value, - num_options, &options); - } - else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || - cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) - { - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); - return (1); - } - break; - - case '#' : /* Number of copies */ - if (argv[i][2] != '\0') - num_copies = atoi(argv[i] + 2); - else - { - i ++; - if (i >= argc) + case '#' : /* Number of copies */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected copies after " - "\"-#\" option."), argv[0]); - return (1); + num_copies = atoi(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected copies after \"-#\" option."), argv[0]); + return (1); + } + + num_copies = atoi(argv[i]); } - num_copies = atoi(argv[i]); - } - - sprintf(buffer, "%d", num_copies); - num_options = cupsAddOption("copies", buffer, num_options, &options); - break; - - case 'C' : /* Class */ - case 'J' : /* Job name */ - case 'T' : /* Title */ - if (argv[i][2] != '\0') - title = argv[i] + 2; - else - { - i ++; - if (i >= argc) + if (num_copies < 1) { - _cupsLangPrintf(stderr, - _("%s: Error - expected name after \"-%c\" " - "option."), argv[0], ch); + _cupsLangPrintf(stderr, _("%s: Error - copies must be 1 or more."), argv[0]); return (1); } - title = argv[i]; - } - break; + sprintf(buffer, "%d", num_copies); + num_options = cupsAddOption("copies", buffer, num_options, &options); + break; + + case 'C' : /* Class */ + case 'J' : /* Job name */ + case 'T' : /* Title */ + if (opt[1] != '\0') + { + title = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected name after \"-%c\" option."), argv[0], ch); + return (1); + } + + title = argv[i]; + } + break; - default : - _cupsLangPrintf(stderr, - _("%s: Error - unknown option \"%c\"."), argv[0], - argv[i][1]); - return (1); + default : + _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], *opt); + return (1); + } } } else if (num_files < 1000) @@ -305,9 +312,11 @@ main(int argc, /* I - Number of command-line arguments */ } } else - _cupsLangPrintf(stderr, - _("%s: Error - too many files - \"%s\"."), argv[0], - argv[i]); + { + _cupsLangPrintf(stderr, _("%s: Error - too many files - \"%s\"."), argv[0], argv[i]); + } + } + /* * See if we have any files to print; if not, print from stdin... */ diff --git a/berkeley/lprm.c b/berkeley/lprm.c index 981b94b55..2271d4872 100644 --- a/berkeley/lprm.c +++ b/berkeley/lprm.c @@ -1,7 +1,7 @@ /* * "lprm" command for CUPS. * - * Copyright 2007-2010 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -29,7 +29,8 @@ main(int argc, /* I - Number of command-line arguments */ int i; /* Looping var */ int job_id; /* Job ID */ const char *name; /* Destination printer */ - char *instance; /* Pointer to instance name */ + char *instance, /* Pointer to instance name */ + *opt; /* Option pointer */ cups_dest_t *dest, /* Destination */ *defdest; /* Default destination */ int did_cancel; /* Did we cancel something? */ @@ -50,90 +51,96 @@ main(int argc, /* I - Number of command-line arguments */ */ for (i = 1; i < argc; i ++) + { if (argv[i][0] == '-' && argv[i][1] != '\0') - switch (argv[i][1]) + { + for (opt = argv[i] + 1; *opt; opt ++) { - case 'E' : /* Encrypt */ + switch (*opt) + { + case 'E' : /* Encrypt */ #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, - _("%s: Sorry, no encryption support."), argv[0]); + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ - break; - - case 'P' : /* Cancel jobs on a printer */ - if (argv[i][2]) - name = argv[i] + 2; - else - { - i ++; - name = argv[i]; - } - - if ((instance = strchr(name, '/')) != NULL) - *instance = '\0'; - - if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name, - NULL)) == NULL) - { - _cupsLangPrintf(stderr, - _("%s: Error - unknown destination \"%s\"."), - argv[0], name); - goto error; - } - - cupsFreeDests(1, dest); - break; - - case 'U' : /* Username */ - if (argv[i][2] != '\0') - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) + break; + + case 'P' : /* Cancel jobs on a printer */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after " - "\"-U\" option."), argv[0]); - goto error; + name = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; + name = argv[i]; } - cupsSetUser(argv[i]); - } - break; - - case 'h' : /* Connect to host */ - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; + if ((instance = strchr(name, '/')) != NULL) + *instance = '\0'; - if (i >= argc) + if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, name, NULL)) == NULL) { - _cupsLangPrintf(stderr, - _("%s: Error - expected hostname after " - "\"-h\" option."), argv[0]); + _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s\"."), argv[0], name); goto error; - } + } + + cupsFreeDests(1, dest); + break; + + case 'U' : /* Username */ + if (opt[1] != '\0') + { + cupsSetUser(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]); + goto error; + } + + cupsSetUser(argv[i]); + } + break; + + case 'h' : /* Connect to host */ + if (opt[1] != '\0') + { + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } else - cupsSetServer(argv[i]); - } + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]); + goto error; + } + else + cupsSetServer(argv[i]); + } - if (defdest) - cupsFreeDests(1, defdest); + if (defdest) + cupsFreeDests(1, defdest); - defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); - name = defdest ? defdest->name : NULL; - break; + defdest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); + name = defdest ? defdest->name : NULL; + break; - default : - _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), - argv[0], argv[i][1]); - goto error; + default : + _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], *opt); + goto error; + } } + } else { /* @@ -176,6 +183,7 @@ main(int argc, /* I - Number of command-line arguments */ did_cancel = 1; } + } /* * If nothing has been canceled yet, cancel the current job on the specified diff --git a/systemv/cancel.c b/systemv/cancel.c index 7540d0ba8..e72822abf 100644 --- a/systemv/cancel.c +++ b/systemv/cancel.c @@ -1,7 +1,7 @@ /* * "cancel" command for CUPS. * - * Copyright 2007-2013 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -31,7 +31,8 @@ main(int argc, /* I - Number of command-line arguments */ int job_id; /* Job ID */ int num_dests; /* Number of destinations */ cups_dest_t *dests; /* Destinations */ - char *dest, /* Destination printer */ + char *opt, /* Option pointer */ + *dest, /* Destination printer */ *job, /* Job ID pointer */ *user; /* Cancel jobs for a user */ int purge; /* Purge or cancel jobs? */ @@ -61,102 +62,106 @@ main(int argc, /* I - Number of command-line arguments */ */ for (i = 1; i < argc; i ++) + { if (argv[i][0] == '-' && argv[i][1]) { - switch (argv[i][1]) + for (opt = argv[i] + 1; *opt; opt ++) { - case 'E' : /* Encrypt */ + switch (*opt) + { + case 'E' : /* Encrypt */ #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); - if (http) - httpEncryption(http, HTTP_ENCRYPT_REQUIRED); + if (http) + httpEncryption(http, HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, - _("%s: Sorry, no encryption support."), argv[0]); + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ - break; - - case 'U' : /* Username */ - if (argv[i][2] != '\0') - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) + break; + + case 'U' : /* Username */ + if (opt[1] != '\0') + { + cupsSetUser(opt + 1); + opt += strlen(opt) - 1; + } + else { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after " - "\"-U\" option."), argv[0]); - return (1); + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]); + return (1); + } + + cupsSetUser(argv[i]); } + break; - cupsSetUser(argv[i]); - } - break; + case 'a' : /* Cancel all jobs */ + op = purge ? IPP_PURGE_JOBS : IPP_CANCEL_JOBS; + break; - case 'a' : /* Cancel all jobs */ - op = purge ? IPP_PURGE_JOBS : IPP_CANCEL_JOBS; - break; + case 'h' : /* Connect to host */ + if (http != NULL) + { + httpClose(http); + http = NULL; + } - case 'h' : /* Connect to host */ - if (http != NULL) - { - httpClose(http); - http = NULL; - } + if (opt[1] != '\0') + { + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]); + return (1); + } + else + cupsSetServer(argv[i]); + } + break; - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; + case 'u' : /* Username */ + op = IPP_CANCEL_MY_JOBS; - if (i >= argc) + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected hostname after " - "\"-h\" option."), argv[0]); - return (1); - } + user = opt + 1; + opt += strlen(opt) - 1; + } else - cupsSetServer(argv[i]); - } - break; + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-u\" option."), argv[0]); + return (1); + } + else + user = argv[i]; + } + break; - case 'u' : /* Username */ - op = IPP_CANCEL_MY_JOBS; + case 'x' : /* Purge job(s) */ + purge = 1; - if (argv[i][2] != '\0') - user = argv[i] + 2; - else - { - i ++; + if (op == IPP_CANCEL_JOBS) + op = IPP_PURGE_JOBS; + break; - if (i >= argc) - { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after " - "\"-u\" option."), argv[0]); - return (1); - } - else - user = argv[i]; - } - break; - - case 'x' : /* Purge job(s) */ - purge = 1; - - if (op == IPP_CANCEL_JOBS) - op = IPP_PURGE_JOBS; - break; - - default : - _cupsLangPrintf(stderr, - _("%s: Error - unknown option \"%c\"."), - argv[0], argv[i][1]); - return (1); + default : + _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], *opt); + return (1); + } } } else @@ -308,6 +313,7 @@ main(int argc, /* I - Number of command-line arguments */ ippDelete(response); } + } if (num_dests == 0 && op != IPP_CANCEL_JOB) { diff --git a/systemv/cupsaccept.c b/systemv/cupsaccept.c index 38dff283d..27f379df3 100644 --- a/systemv/cupsaccept.c +++ b/systemv/cupsaccept.c @@ -2,7 +2,7 @@ * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for * CUPS. * - * Copyright 2007-2010 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -29,6 +29,7 @@ main(int argc, /* I - Number of command-line arguments */ { int i; /* Looping var */ char *command, /* Command to do */ + *opt, /* Option pointer */ uri[1024], /* Printer URI */ *reason; /* Reason for reject/disable */ ipp_t *request; /* IPP request */ @@ -70,94 +71,90 @@ main(int argc, /* I - Number of command-line arguments */ */ for (i = 1; i < argc; i ++) - if (argv[i][0] == '-') + { + if (!strcmp(argv[i], "--hold")) + op = IPP_HOLD_NEW_JOBS; + else if (!strcmp(argv[i], "--release")) + op = IPP_RELEASE_HELD_NEW_JOBS; + else if (argv[i][0] == '-') { - switch (argv[i][1]) + for (opt = argv[i] + 1; *opt; opt ++) { - case 'E' : /* Encrypt */ -#ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); -#else - _cupsLangPrintf(stderr, - _("%s: Sorry, no encryption support."), command); -#endif /* HAVE_SSL */ - break; - - case 'U' : /* Username */ - if (argv[i][2] != '\0') - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) + switch (*opt) + { + case 'E' : /* Encrypt */ + #ifdef HAVE_SSL + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + #else + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), command); + #endif /* HAVE_SSL */ + break; + + case 'U' : /* Username */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after " - "\"-U\" option."), command); - return (1); + cupsSetUser(opt + 1); + opt += strlen(opt) - 1; } - - cupsSetUser(argv[i]); - } - break; - - case 'c' : /* Cancel jobs */ - cancel = 1; - break; - - case 'h' : /* Connect to host */ - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; - if (i >= argc) + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), command); + return (1); + } + + cupsSetUser(argv[i]); + } + break; + + case 'c' : /* Cancel jobs */ + cancel = 1; + break; + + case 'h' : /* Connect to host */ + if (opt[1] != '\0') + { + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } + else { - _cupsLangPrintf(stderr, - _("%s: Error - expected hostname after " - "\"-h\" option."), command); - return (1); + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), command); + return (1); + } + + cupsSetServer(argv[i]); } + break; - cupsSetServer(argv[i]); - } - break; - - case 'r' : /* Reason for cancellation */ - if (argv[i][2] != '\0') - reason = argv[i] + 2; - else - { - i ++; - if (i >= argc) + case 'r' : /* Reason for cancellation */ + if (opt[1] != '\0') + { + reason = opt + 1; + opt += strlen(opt) - 1; + } + else { - _cupsLangPrintf(stderr, - _("%s: Error - expected reason text after " - "\"-r\" option."), command); - return (1); + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected reason text after \"-r\" option."), command); + return (1); + } + + reason = argv[i]; } + break; - reason = argv[i]; - } - break; - - case '-' : - if (!strcmp(argv[i], "--hold")) - op = IPP_HOLD_NEW_JOBS; - else if (!strcmp(argv[i], "--release")) - op = IPP_RELEASE_HELD_NEW_JOBS; - else - { - _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."), - command, argv[i]); + default : + _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), command, *opt); return (1); - } - break; - - default : - _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), - command, argv[i][1]); - return (1); + } } } else @@ -223,6 +220,7 @@ main(int argc, /* I - Number of command-line arguments */ } } } + } return (0); } diff --git a/systemv/lp.c b/systemv/lp.c index e0f5541c3..bc09b4b20 100644 --- a/systemv/lp.c +++ b/systemv/lp.c @@ -1,7 +1,7 @@ /* * "lp" command for CUPS. * - * Copyright 2007-2014 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2007 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -39,6 +39,7 @@ main(int argc, /* I - Number of command-line arguments */ int job_id; /* Job ID */ char *printer, /* Printer name */ *instance, /* Instance name */ + *opt, /* Option pointer */ *val, /* Option value */ *title; /* Job title */ int priority; /* Job priority (1-100) */ @@ -84,427 +85,431 @@ main(int argc, /* I - Number of command-line arguments */ end_options = 0; for (i = 1; i < argc; i ++) + { if (argv[i][0] == '-' && argv[i][1] && !end_options) - switch (argv[i][1]) + { + for (opt = argv[i] + 1; *opt; opt ++) { - case 'E' : /* Encrypt */ + switch (*opt) + { + case 'E' : /* Encrypt */ #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), - argv[0]); + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ - break; + break; - case 'U' : /* Username */ - if (argv[i][2] != '\0') - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) + case 'U' : /* Username */ + if (opt[1] != '\0') + { + cupsSetUser(opt + 1); + opt += strlen(opt) - 1; + } + else { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after \"-U\" " - "option."), argv[0]); - return (1); + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]); + return (1); + } + + cupsSetUser(argv[i]); } + break; - cupsSetUser(argv[i]); - } - break; + case 'c' : /* Copy to spool dir (always enabled) */ + break; - case 'c' : /* Copy to spool dir (always enabled) */ - break; + case 'd' : /* Destination printer or class */ + if (opt[1] != '\0') + { + printer = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - case 'd' : /* Destination printer or class */ - if (argv[i][2] != '\0') - printer = argv[i] + 2; - else - { - i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected destination after \"-d\" option."), argv[0]); + return (1); + } - if (i >= argc) - { - _cupsLangPrintf(stderr, - _("%s: Error - expected destination after " - "\"-d\" option."), argv[0]); - return (1); - } - - printer = argv[i]; - } - - if ((instance = strrchr(printer, '/')) != NULL) - *instance++ = '\0'; - - if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, - instance)) != NULL) - { - for (j = 0; j < dest->num_options; j ++) - if (cupsGetOption(dest->options[j].name, num_options, - options) == NULL) - num_options = cupsAddOption(dest->options[j].name, - dest->options[j].value, - num_options, &options); - } - else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || - cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) - { - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); - return (1); - } - break; + printer = argv[i]; + } - case 'f' : /* Form */ - if (!argv[i][2]) - { - i ++; + if ((instance = strrchr(printer, '/')) != NULL) + *instance++ = '\0'; - if (i >= argc) + if ((dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, + instance)) != NULL) + { + for (j = 0; j < dest->num_options; j ++) + if (cupsGetOption(dest->options[j].name, num_options, + options) == NULL) + num_options = cupsAddOption(dest->options[j].name, + dest->options[j].value, + num_options, &options); + } + else if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) { - _cupsLangPrintf(stderr, - _("%s: Error - expected form after \"-f\" " - "option."), - argv[0]); + _cupsLangPrintf(stderr, + _("%s: Error - add '/version=1.1' to server " + "name."), argv[0]); return (1); - } - } + } + break; - _cupsLangPrintf(stderr, _("%s: Warning - form option ignored."), - argv[0]); - break; + case 'f' : /* Form */ + if (opt[1] != '\0') + { + opt += strlen(opt) - 1; + } + else + { + i ++; - case 'h' : /* Destination host */ - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected form after \"-f\" option."), argv[0]); + return (1); + } + } - if (i >= argc) + _cupsLangPrintf(stderr, _("%s: Warning - form option ignored."), argv[0]); + break; + + case 'h' : /* Destination host */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected hostname after " - "\"-h\" option."), argv[0]); - return (1); - } + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; - cupsSetServer(argv[i]); - } - break; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]); + return (1); + } - case 'i' : /* Change job */ - if (argv[i][2]) - val = argv[i] + 2; - else - { - i ++; + cupsSetServer(argv[i]); + } + break; - if (i >= argc) + case 'i' : /* Change job */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Expected job ID after \"-i\" option."), - argv[0]); - return (1); - } + val = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - val = argv[i]; - } + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Expected job ID after \"-i\" option."), argv[0]); + return (1); + } - if (num_files > 0) - { - _cupsLangPrintf(stderr, - _("%s: Error - cannot print files and alter " - "jobs simultaneously."), argv[0]); - return (1); - } + val = argv[i]; + } + + if (num_files > 0) + { + _cupsLangPrintf(stderr, _("%s: Error - cannot print files and alter jobs simultaneously."), argv[0]); + return (1); + } - if (strrchr(val, '-') != NULL) - job_id = atoi(strrchr(val, '-') + 1); - else - job_id = atoi(val); + if (strrchr(val, '-') != NULL) + job_id = atoi(strrchr(val, '-') + 1); + else + job_id = atoi(val); - if (job_id < 0) - { - _cupsLangPrintf(stderr, _("%s: Error - bad job ID."), argv[0]); + if (job_id < 0) + { + _cupsLangPrintf(stderr, _("%s: Error - bad job ID."), argv[0]); + break; + } break; - } - break; - case 'm' : /* Send email when job is done */ + case 'm' : /* Send email when job is done */ #ifdef __sun - case 'p' : /* Notify on completion */ + case 'p' : /* Notify on completion */ #endif /* __sun */ - case 'w' : /* Write to console or email */ - { - char email[1024]; /* EMail address */ - + case 'w' : /* Write to console or email */ + { + char email[1024]; /* EMail address */ - snprintf(email, sizeof(email), "mailto:%s@%s", cupsUser(), - httpGetHostname(NULL, buffer, sizeof(buffer))); - num_options = cupsAddOption("notify-recipient-uri", email, - num_options, &options); - } - silent = 1; - break; + snprintf(email, sizeof(email), "mailto:%s@%s", cupsUser(), httpGetHostname(NULL, buffer, sizeof(buffer))); + num_options = cupsAddOption("notify-recipient-uri", email, num_options, &options); + } - case 'n' : /* Number of copies */ - if (argv[i][2] != '\0') - num_copies = atoi(argv[i] + 2); - else - { - i ++; + silent = 1; + break; - if (i >= argc) + case 'n' : /* Number of copies */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected copies after " - "\"-n\" option."), argv[0]); - return (1); - } - - num_copies = atoi(argv[i]); - } + num_copies = atoi(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; - sprintf(buffer, "%d", num_copies); - num_options = cupsAddOption("copies", buffer, num_options, - &options); - break; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected copies after \"-n\" option."), argv[0]); + return (1); + } - case 'o' : /* Option */ - if (argv[i][2] != '\0') - num_options = cupsParseOptions(argv[i] + 2, num_options, - &options); - else - { - i ++; + num_copies = atoi(argv[i]); + } - if (i >= argc) + if (num_copies < 1) { - _cupsLangPrintf(stderr, - _("%s: Error - expected option=value after " - "\"-o\" option."), argv[0]); + _cupsLangPrintf(stderr, _("%s: Error - copies must be 1 or more."), argv[0]); return (1); - } + } + + sprintf(buffer, "%d", num_copies); + num_options = cupsAddOption("copies", buffer, num_options, + &options); + break; - num_options = cupsParseOptions(argv[i], num_options, &options); - } - break; + case 'o' : /* Option */ + if (opt[1] != '\0') + { + num_options = cupsParseOptions(opt + 1, num_options, &options); + opt += strlen(opt) - 1; + } + else + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected option=value after \"-o\" option."), argv[0]); + return (1); + } + + num_options = cupsParseOptions(argv[i], num_options, &options); + } + break; #ifndef __sun - case 'p' : /* Queue priority */ + case 'p' : /* Queue priority */ #endif /* !__sun */ - case 'q' : /* Queue priority */ - if (argv[i][2] != '\0') - priority = atoi(argv[i] + 2); - else - { - if ((i + 1) >= argc) - { - _cupsLangPrintf(stderr, - _("%s: Error - expected priority after " - "\"-%c\" option."), argv[0], argv[i][1]); - return (1); - } - - i ++; - - priority = atoi(argv[i]); - } - - /* - * For 100% Solaris compatibility, need to add: - * - * priority = 99 * (39 - priority) / 39 + 1; - * - * However, to keep CUPS lp the same across all platforms - * we will break compatibility this far... - */ - - if (priority < 1 || priority > 100) - { - _cupsLangPrintf(stderr, - _("%s: Error - priority must be between 1 and " - "100."), argv[0]); - return (1); - } + case 'q' : /* Queue priority */ + if (opt[1] != '\0') + { + priority = atoi(opt + 1); + opt += strlen(opt) - 1; + } + else + { + if ((i + 1) >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected priority after \"-%c\" option."), argv[0], *opt); + return (1); + } - sprintf(buffer, "%d", priority); - num_options = cupsAddOption("job-priority", buffer, num_options, - &options); - break; + i ++; - case 's' : /* Silent */ - silent = 1; - break; + priority = atoi(argv[i]); + } - case 't' : /* Title */ - if (argv[i][2] != '\0') - title = argv[i] + 2; - else - { - i ++; + /* + * For 100% Solaris compatibility, need to add: + * + * priority = 99 * (39 - priority) / 39 + 1; + * + * However, to keep CUPS lp the same across all platforms + * we will break compatibility this far... + */ - if (i >= argc) + if (priority < 1 || priority > 100) { - _cupsLangPrintf(stderr, - _("%s: Error - expected title after " - "\"-t\" option."), argv[0]); + _cupsLangPrintf(stderr, _("%s: Error - priority must be between 1 and 100."), argv[0]); return (1); - } + } - title = argv[i]; - } - break; + sprintf(buffer, "%d", priority); + num_options = cupsAddOption("job-priority", buffer, num_options, + &options); + break; - case 'y' : /* mode-list */ - if (!argv[i][2]) - { - i ++; + case 's' : /* Silent */ + silent = 1; + break; - if (i >= argc) + case 't' : /* Title */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected mode list after " - "\"-y\" option."), argv[0]); - return (1); - } - } + title = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - _cupsLangPrintf(stderr, - _("%s: Warning - mode option ignored."), argv[0]); - break; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected title after \"-t\" option."), argv[0]); + return (1); + } - case 'H' : /* Hold job */ - if (argv[i][2]) - val = argv[i] + 2; - else - { - i ++; + title = argv[i]; + } + break; - if (i >= argc) + case 'y' : /* mode-list */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected hold name after " - "\"-H\" option."), argv[0]); - return (1); - } - - val = argv[i]; - } - - if (!strcmp(val, "hold")) - num_options = cupsAddOption("job-hold-until", "indefinite", - num_options, &options); - else if (!strcmp(val, "resume") || - !strcmp(val, "release")) - num_options = cupsAddOption("job-hold-until", "no-hold", - num_options, &options); - else if (!strcmp(val, "immediate")) - { - num_options = cupsAddOption("job-hold-until", "no-hold", - num_options, &options); - num_options = cupsAddOption("job-priority", "100", - num_options, &options); - } - else if (!strcmp(val, "restart")) - { - if (job_id < 1) - { - _cupsLangPrintf(stderr, - _("%s: Need job ID (\"-i jobid\") before " - "\"-H restart\"."), argv[0]); - return (1); + opt += strlen(opt) - 1; } + else + { + i ++; - if (restart_job(argv[0], job_id)) - return (1); - } - else - num_options = cupsAddOption("job-hold-until", val, - num_options, &options); - break; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected mode list after \"-y\" option."), argv[0]); + return (1); + } + } - case 'P' : /* Page list */ - if (argv[i][2]) - val = argv[i] + 2; - else - { - i ++; + _cupsLangPrintf(stderr, _("%s: Warning - mode option ignored."), argv[0]); + break; - if (i >= argc) + case 'H' : /* Hold job */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected page list after " - "\"-P\" option."), argv[0]); - return (1); - } + val = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - val = argv[i]; - } + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected hold name after \"-H\" option."), argv[0]); + return (1); + } - num_options = cupsAddOption("page-ranges", val, num_options, - &options); - break; + val = argv[i]; + } - case 'S' : /* character set */ - if (!argv[i][2]) - { - i ++; + if (!strcmp(val, "hold")) + num_options = cupsAddOption("job-hold-until", "indefinite", num_options, &options); + else if (!strcmp(val, "resume") || !strcmp(val, "release")) + num_options = cupsAddOption("job-hold-until", "no-hold", num_options, &options); + else if (!strcmp(val, "immediate")) + { + num_options = cupsAddOption("job-hold-until", "no-hold", num_options, &options); + num_options = cupsAddOption("job-priority", "100", num_options, &options); + } + else if (!strcmp(val, "restart")) + { + if (job_id < 1) + { + _cupsLangPrintf(stderr, _("%s: Need job ID (\"-i jobid\") before \"-H restart\"."), argv[0]); + return (1); + } + + if (restart_job(argv[0], job_id)) + return (1); + } + else + num_options = cupsAddOption("job-hold-until", val, num_options, &options); + break; - if (i >= argc) + case 'P' : /* Page list */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected character set after " - "\"-S\" option."), argv[0]); - return (1); - } - } + val = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - _cupsLangPrintf(stderr, - _("%s: Warning - character set option ignored."), - argv[0]); - break; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected page list after \"-P\" option."), argv[0]); + return (1); + } + + val = argv[i]; + } - case 'T' : /* Content-Type */ - if (!argv[i][2]) - { - i ++; + num_options = cupsAddOption("page-ranges", val, num_options, &options); + break; - if (i >= argc) + case 'S' : /* character set */ + if (opt[1] != '\0') + { + opt += strlen(opt) - 1; + } + else + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected character set after \"-S\" option."), argv[0]); + return (1); + } + } + + _cupsLangPrintf(stderr, _("%s: Warning - character set option ignored."), argv[0]); + break; + + case 'T' : /* Content-Type */ + if (opt[1] != '\0') + { + opt += strlen(opt) - 1; + } + else { - _cupsLangPrintf(stderr, - _("%s: Error - expected content type after " - "\"-T\" option."), argv[0]); + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected content type after \"-T\" option."), argv[0]); + return (1); + } + } + + _cupsLangPrintf(stderr, _("%s: Warning - content type option ignored."), argv[0]); + break; + + case '-' : /* Stop processing options */ + if (opt[1] != '\0') + { + _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."), argv[0], argv[i]); return (1); - } - } - - _cupsLangPrintf(stderr, - _("%s: Warning - content type option ignored."), - argv[0]); - break; - - case '-' : /* Stop processing options */ - if (argv[i][2]) - { - _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."), - argv[0], argv[i]); - return (1); - } + } - end_options = 1; - break; + end_options = 1; + break; - default : - _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), - argv[0], argv[i][1]); - return (1); + default : + _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], *opt); + return (1); + } } + } else if (!strcmp(argv[i], "-")) { if (num_files || job_id) @@ -525,8 +530,7 @@ main(int argc, /* I - Number of command-line arguments */ if (access(argv[i], R_OK) != 0) { - _cupsLangPrintf(stderr, _("%s: Error - unable to access \"%s\" - %s"), - argv[0], argv[i], strerror(errno)); + _cupsLangPrintf(stderr, _("%s: Error - unable to access \"%s\" - %s"), argv[0], argv[i], strerror(errno)); return (1); } @@ -542,8 +546,10 @@ main(int argc, /* I - Number of command-line arguments */ } } else - _cupsLangPrintf(stderr, _("%s: Error - too many files - \"%s\"."), - argv[0], argv[i]); + { + _cupsLangPrintf(stderr, _("%s: Error - too many files - \"%s\"."), argv[0], argv[i]); + } + } /* * See if we are altering an existing job... diff --git a/systemv/lpadmin.c b/systemv/lpadmin.c index 7775b4024..1344b596e 100644 --- a/systemv/lpadmin.c +++ b/systemv/lpadmin.c @@ -1,7 +1,7 @@ /* * "lpadmin" command for CUPS. * - * Copyright 2007-2015 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -54,6 +54,7 @@ main(int argc, /* I - Number of command-line arguments */ http_t *http; /* Connection to server */ char *printer, /* Destination printer */ *pclass, /* Printer class name */ + *opt, /* Option pointer */ *val; /* Pointer to allow/deny value */ int num_options; /* Number of options */ cups_option_t *options; /* Options */ @@ -73,530 +74,518 @@ main(int argc, /* I - Number of command-line arguments */ file = NULL; for (i = 1; i < argc; i ++) + { if (argv[i][0] == '-') - switch (argv[i][1]) + { + for (opt = argv[i] + 1; *opt; opt ++) { - case 'c' : /* Add printer to class */ - if (!http) - { - http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + switch (*opt) + { + case 'c' : /* Add printer to class */ + if (!http) + { + http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + + if (http == NULL) + { + _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); + return (1); + } + } - if (http == NULL) + if (printer == NULL) { - _cupsLangPrintf(stderr, - _("lpadmin: Unable to connect to server: %s"), - strerror(errno)); + _cupsLangPuts(stderr, + _("lpadmin: Unable to add a printer to the class:\n" + " You must specify a printer name first.")); return (1); } - } - - if (printer == NULL) - { - _cupsLangPuts(stderr, - _("lpadmin: Unable to add a printer to the class:\n" - " You must specify a printer name " - "first.")); - return (1); - } - if (argv[i][2]) - pclass = argv[i] + 2; - else - { - i ++; + if (opt[1] != '\0') + { + pclass = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - if (i >= argc) + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected class name after \"-c\" option.")); + return (1); + } + + pclass = argv[i]; + } + + if (!validate_name(pclass)) { _cupsLangPuts(stderr, - _("lpadmin: Expected class name after \"-c\" " - "option.")); + _("lpadmin: Class name can only contain printable " + "characters.")); return (1); } - pclass = argv[i]; - } - - if (!validate_name(pclass)) - { - _cupsLangPuts(stderr, - _("lpadmin: Class name can only contain printable " - "characters.")); - return (1); - } + if (add_printer_to_class(http, printer, pclass)) + return (1); + break; - if (add_printer_to_class(http, printer, pclass)) - return (1); - break; + case 'd' : /* Set as default destination */ + if (!http) + { + http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); - case 'd' : /* Set as default destination */ - if (!http) - { - http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + if (http == NULL) + { + _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); + return (1); + } + } - if (http == NULL) + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("lpadmin: Unable to connect to server: %s"), - strerror(errno)); - return (1); + printer = opt + 1; + opt += strlen(opt) - 1; } - } + else + { + i ++; - if (argv[i][2]) - printer = argv[i] + 2; - else - { - i ++; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected printer name after \"-d\" option.")); + return (1); + } - if (i >= argc) + printer = argv[i]; + } + + if (!validate_name(printer)) { - _cupsLangPuts(stderr, - _("lpadmin: Expected printer name after \"-d\" " - "option.")); + _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain printable characters.")); return (1); } - printer = argv[i]; - } - - if (!validate_name(printer)) - { - _cupsLangPuts(stderr, - _("lpadmin: Printer name can only contain " - "printable characters.")); - return (1); - } - - if (default_printer(http, printer)) - return (1); + if (default_printer(http, printer)) + return (1); - i = argc; - break; + i = argc; + break; - case 'h' : /* Connect to host */ - if (http) - { - httpClose(http); - http = NULL; - } - - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; + case 'h' : /* Connect to host */ + if (http) + { + httpClose(http); + http = NULL; + } - if (i >= argc) + if (opt[1] != '\0') { - _cupsLangPuts(stderr, - _("lpadmin: Expected hostname after \"-h\" " - "option.")); - return (1); - } + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; - cupsSetServer(argv[i]); - } - break; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected hostname after \"-h\" option.")); + return (1); + } - case 'P' : /* Use the specified PPD file */ - case 'i' : /* Use the specified PPD file */ - if (argv[i][2]) - file = argv[i] + 2; - else - { - i ++; + cupsSetServer(argv[i]); + } + break; - if (i >= argc) + case 'P' : /* Use the specified PPD file */ + case 'i' : /* Use the specified PPD file */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, _("lpadmin: Expected PPD after \"-%c\" option."), argv[i - 1][1]); - return (1); + file = opt + 1; + opt += strlen(opt) - 1; } + else + { + i ++; - file = argv[i]; - } - break; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("lpadmin: Expected PPD after \"-%c\" option."), argv[i - 1][1]); + return (1); + } - case 'E' : /* Enable the printer */ - if (printer == NULL) - { + file = argv[i]; + } + break; + + case 'E' : /* Enable the printer/enable encryption */ + if (printer == NULL) + { #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED); - if (http) - httpEncryption(http, HTTP_ENCRYPTION_REQUIRED); + if (http) + httpEncryption(http, HTTP_ENCRYPTION_REQUIRED); #else - _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), - argv[0]); + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ - break; - } - - if (!http) - { - http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + break; + } - if (http == NULL) + if (!http) { - _cupsLangPrintf(stderr, - _("lpadmin: Unable to connect to server: %s"), - strerror(errno)); - return (1); + http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + + if (http == NULL) + { + _cupsLangPrintf(stderr, + _("lpadmin: Unable to connect to server: %s"), + strerror(errno)); + return (1); + } } - } - if (enable_printer(http, printer)) - return (1); - break; - - case 'm' : /* Use the specified standard script/PPD file */ - if (argv[i][2]) - num_options = cupsAddOption("ppd-name", argv[i] + 2, num_options, - &options); - else - { - i ++; + if (enable_printer(http, printer)) + return (1); + break; - if (i >= argc) + case 'm' : /* Use the specified standard script/PPD file */ + if (opt[1] != '\0') { - _cupsLangPuts(stderr, - _("lpadmin: Expected model after \"-m\" " - "option.")); - return (1); + num_options = cupsAddOption("ppd-name", opt + 1, num_options, &options); + opt += strlen(opt) - 1; } + else + { + i ++; - num_options = cupsAddOption("ppd-name", argv[i], num_options, - &options); - } - break; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected model after \"-m\" option.")); + return (1); + } - case 'o' : /* Set option */ - if (argv[i][2]) - num_options = cupsParseOptions(argv[i] + 2, num_options, &options); - else - { - i ++; + num_options = cupsAddOption("ppd-name", argv[i], num_options, &options); + } + break; - if (i >= argc) + case 'o' : /* Set option */ + if (opt[1] != '\0') { - _cupsLangPuts(stderr, - _("lpadmin: Expected name=value after \"-o\" " - "option.")); - return (1); + num_options = cupsParseOptions(opt + 1, num_options, &options); + opt += strlen(opt) - 1; } + else + { + i ++; - num_options = cupsParseOptions(argv[i], num_options, &options); - } - break; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected name=value after \"-o\" option.")); + return (1); + } - case 'p' : /* Add/modify a printer */ - if (argv[i][2]) - printer = argv[i] + 2; - else - { - i ++; + num_options = cupsParseOptions(argv[i], num_options, &options); + } + break; - if (i >= argc) + case 'p' : /* Add/modify a printer */ + if (opt[1] != '\0') { - _cupsLangPuts(stderr, - _("lpadmin: Expected printer after \"-p\" " - "option.")); - return (1); + printer = opt + 1; + opt += strlen(opt) - 1; } + else + { + i ++; - printer = argv[i]; - } - - if (!validate_name(printer)) - { - _cupsLangPuts(stderr, - _("lpadmin: Printer name can only contain " - "printable characters.")); - return (1); - } - break; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected printer after \"-p\" option.")); + return (1); + } - case 'r' : /* Remove printer from class */ - if (!http) - { - http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + printer = argv[i]; + } - if (http == NULL) + if (!validate_name(printer)) { - _cupsLangPrintf(stderr, - _("lpadmin: Unable to connect to server: %s"), - strerror(errno)); + _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain printable characters.")); return (1); } - } - - if (printer == NULL) - { - _cupsLangPuts(stderr, - _("lpadmin: Unable to remove a printer from the " - "class:\n" - " You must specify a printer name " - "first.")); - return (1); - } + break; - if (argv[i][2]) - pclass = argv[i] + 2; - else - { - i ++; + case 'r' : /* Remove printer from class */ + if (!http) + { + http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + + if (http == NULL) + { + _cupsLangPrintf(stderr, + _("lpadmin: Unable to connect to server: %s"), + strerror(errno)); + return (1); + } + } - if (i >= argc) + if (printer == NULL) { _cupsLangPuts(stderr, - _("lpadmin: Expected class after \"-r\" " - "option.")); + _("lpadmin: Unable to remove a printer from the class:\n" + " You must specify a printer name first.")); return (1); } - pclass = argv[i]; - } - - if (!validate_name(pclass)) - { - _cupsLangPuts(stderr, - _("lpadmin: Class name can only contain printable " - "characters.")); - return (1); - } + if (opt[1] != '\0') + { + pclass = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - if (delete_printer_from_class(http, printer, pclass)) - return (1); - break; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected class after \"-r\" option.")); + return (1); + } - case 'R' : /* Remove option */ - if (!http) - { - http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + pclass = argv[i]; + } - if (http == NULL) + if (!validate_name(pclass)) { - _cupsLangPrintf(stderr, - _("lpadmin: Unable to connect to server: %s"), - strerror(errno)); + _cupsLangPuts(stderr, _("lpadmin: Class name can only contain printable characters.")); return (1); } - } - - if (printer == NULL) - { - _cupsLangPuts(stderr, - _("lpadmin: Unable to delete option:\n" - " You must specify a printer name " - "first.")); - return (1); - } - if (argv[i][2]) - val = argv[i] + 2; - else - { - i ++; + if (delete_printer_from_class(http, printer, pclass)) + return (1); + break; - if (i >= argc) + case 'R' : /* Remove option */ + if (!http) + { + http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + + if (http == NULL) + { + _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno)); + return (1); + } + } + + if (printer == NULL) { _cupsLangPuts(stderr, - _("lpadmin: Expected name after \"-R\" " - "option.")); + _("lpadmin: Unable to delete option:\n" + " You must specify a printer name first.")); return (1); } - val = argv[i]; - } - - if (delete_printer_option(http, printer, val)) - return (1); - break; - - case 'U' : /* Username */ - if (argv[i][2] != '\0') - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after " - "\"-U\" option."), argv[0]); - return (1); + val = opt + 1; + opt += strlen(opt) - 1; } + else + { + i ++; - cupsSetUser(argv[i]); - } - break; - - case 'u' : /* Allow/deny users */ - if (argv[i][2]) - val = argv[i] + 2; - else - { - i ++; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected name after \"-R\" option.")); + return (1); + } - if (i >= argc) - { - _cupsLangPuts(stderr, - _("lpadmin: Expected allow/deny:userlist after " - "\"-u\" option.")); - return (1); + val = argv[i]; } - val = argv[i]; - } - - if (!_cups_strncasecmp(val, "allow:", 6)) - num_options = cupsAddOption("requesting-user-name-allowed", - val + 6, num_options, &options); - else if (!_cups_strncasecmp(val, "deny:", 5)) - num_options = cupsAddOption("requesting-user-name-denied", - val + 5, num_options, &options); - else - { - _cupsLangPrintf(stderr, - _("lpadmin: Unknown allow/deny option \"%s\"."), - val); - return (1); - } - break; + if (delete_printer_option(http, printer, val)) + return (1); + break; - case 'v' : /* Set the device-uri attribute */ - if (argv[i][2]) - num_options = cupsAddOption("device-uri", argv[i] + 2, - num_options, &options); - else - { - i ++; + case 'U' : /* Username */ + if (opt[1] != '\0') + { + cupsSetUser(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]); + return (1); + } + + cupsSetUser(argv[i]); + } + break; - if (i >= argc) + case 'u' : /* Allow/deny users */ + if (opt[1] != '\0') { - _cupsLangPuts(stderr, - _("lpadmin: Expected device URI after \"-v\" " - "option.")); - return (1); + val = opt + 1; + opt += strlen(opt) - 1; } + else + { + i ++; - num_options = cupsAddOption("device-uri", argv[i], - num_options, &options); - } - break; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected allow/deny:userlist after \"-u\" option.")); + return (1); + } - case 'x' : /* Delete a printer */ - if (!http) - { - http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + val = argv[i]; + } - if (http == NULL) + if (!_cups_strncasecmp(val, "allow:", 6)) + num_options = cupsAddOption("requesting-user-name-allowed", val + 6, num_options, &options); + else if (!_cups_strncasecmp(val, "deny:", 5)) + num_options = cupsAddOption("requesting-user-name-denied", val + 5, num_options, &options); + else { - _cupsLangPrintf(stderr, - _("lpadmin: Unable to connect to server: %s"), - strerror(errno)); + _cupsLangPrintf(stderr, _("lpadmin: Unknown allow/deny option \"%s\"."), val); return (1); } - } - - if (argv[i][2]) - printer = argv[i] + 2; - else - { - i ++; + break; - if (i >= argc) + case 'v' : /* Set the device-uri attribute */ + if (opt[1] != '\0') { - _cupsLangPuts(stderr, - _("lpadmin: Expected printer or class after " - "\"-x\" option.")); - return (1); + num_options = cupsAddOption("device-uri", opt + 1, num_options, &options); + opt += strlen(opt) - 1; } + else + { + i ++; - printer = argv[i]; - } + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected device URI after \"-v\" option.")); + return (1); + } - if (!validate_name(printer)) - { - _cupsLangPuts(stderr, - _("lpadmin: Printer name can only contain " - "printable characters.")); - return (1); - } + num_options = cupsAddOption("device-uri", argv[i], num_options, &options); + } + break; - if (delete_printer(http, printer)) - return (1); + case 'x' : /* Delete a printer */ + if (!http) + { + http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL); + + if (http == NULL) + { + _cupsLangPrintf(stderr, + _("lpadmin: Unable to connect to server: %s"), + strerror(errno)); + return (1); + } + } - i = argc; - break; + if (opt[1] != '\0') + { + printer = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - case 'D' : /* Set the printer-info attribute */ - if (argv[i][2]) - num_options = cupsAddOption("printer-info", argv[i] + 2, - num_options, &options); - else - { - i ++; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected printer or class after \"-x\" option.")); + return (1); + } - if (i >= argc) + printer = argv[i]; + } + + if (!validate_name(printer)) { - _cupsLangPuts(stderr, - _("lpadmin: Expected description after " - "\"-D\" option.")); + _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain printable characters.")); return (1); } - num_options = cupsAddOption("printer-info", argv[i], - num_options, &options); - } - break; + if (delete_printer(http, printer)) + return (1); - case 'I' : /* Set the supported file types (ignored) */ - i ++; + i = argc; + break; - if (i >= argc) - { - _cupsLangPuts(stderr, - _("lpadmin: Expected file type(s) after \"-I\" " - "option.")); - return (1); - } + case 'D' : /* Set the printer-info attribute */ + if (opt[1] != '\0') + { + num_options = cupsAddOption("printer-info", opt + 1, num_options, &options); + opt += strlen(opt) - 1; + } + else + { + i ++; - _cupsLangPuts(stderr, - _("lpadmin: Warning - content type list ignored.")); - break; + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected description after \"-D\" option.")); + return (1); + } - case 'L' : /* Set the printer-location attribute */ - if (argv[i][2]) - num_options = cupsAddOption("printer-location", argv[i] + 2, - num_options, &options); - else - { + num_options = cupsAddOption("printer-info", argv[i], num_options, &options); + } + break; + + case 'I' : /* Set the supported file types (ignored) */ i ++; if (i >= argc) { - _cupsLangPuts(stderr, - _("lpadmin: Expected location after \"-L\" " - "option.")); + _cupsLangPuts(stderr, _("lpadmin: Expected file type(s) after \"-I\" option.")); return (1); } - num_options = cupsAddOption("printer-location", argv[i], - num_options, &options); - } - break; + _cupsLangPuts(stderr, _("lpadmin: Warning - content type list ignored.")); + break; - default : - _cupsLangPrintf(stderr, - _("lpadmin: Unknown option \"%c\"."), argv[i][1]); - return (1); + case 'L' : /* Set the printer-location attribute */ + if (opt[1] != '\0') + { + num_options = cupsAddOption("printer-location", opt + 1, num_options, &options); + opt += strlen(opt) - 1; + } + else + { + i ++; + + if (i >= argc) + { + _cupsLangPuts(stderr, _("lpadmin: Expected location after \"-L\" option.")); + return (1); + } + + num_options = cupsAddOption("printer-location", argv[i], num_options, &options); + } + break; + + default : + _cupsLangPrintf(stderr, _("lpadmin: Unknown option \"%c\"."), *opt); + return (1); + } } + } else { - _cupsLangPrintf(stderr, _("lpadmin: Unknown argument \"%s\"."), - argv[i]); + _cupsLangPrintf(stderr, _("lpadmin: Unknown argument \"%s\"."), argv[i]); return (1); } + } /* * Set options as needed... diff --git a/systemv/lpinfo.c b/systemv/lpinfo.c index 692cb3ab7..16bdf0f99 100644 --- a/systemv/lpinfo.c +++ b/systemv/lpinfo.c @@ -1,7 +1,7 @@ /* * "lpinfo" command for CUPS. * - * Copyright 2007-2010 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -48,7 +48,8 @@ main(int argc, /* I - Number of command-line arguments */ { int i; /* Looping var */ int long_status; /* Long listing? */ - const char *device_id, /* 1284 device ID */ + const char *opt, /* Option pointer */ + *device_id, /* 1284 device ID */ *language, /* Language */ *make_model, /* Make and model */ *product, /* Product */ @@ -69,195 +70,175 @@ main(int argc, /* I - Number of command-line arguments */ timeout = CUPS_TIMEOUT_DEFAULT; for (i = 1; i < argc; i ++) - if (argv[i][0] == '-') - switch (argv[i][1]) + { + if (!strcmp(argv[i], "--device-id")) + { + i ++; + + if (i < argc) + device_id = argv[i]; + else + { + _cupsLangPuts(stderr, _("lpinfo: Expected 1284 device ID string after \"--device-id\".")); + return (1); + } + } + else if (!strncmp(argv[i], "--device-id=", 12) && argv[i][12]) + { + device_id = argv[i] + 12; + } + else if (!strcmp(argv[i], "--exclude-schemes")) + { + i ++; + + if (i < argc) + exclude_schemes = argv[i]; + else { - case 'E' : /* Encrypt */ + _cupsLangPuts(stderr, _("lpinfo: Expected scheme list after \"--exclude-schemes\".")); + return (1); + } + } + else if (!strncmp(argv[i], "--exclude-schemes=", 18) && argv[i][18]) + { + exclude_schemes = argv[i] + 18; + } + else if (!strcmp(argv[i], "--include-schemes")) + { + i ++; + + if (i < argc) + include_schemes = argv[i]; + else + { + _cupsLangPuts(stderr, _("lpinfo: Expected scheme list after \"--include-schemes\".")); + return (1); + } + } + else if (!strncmp(argv[i], "--include-schemes=", 18) && argv[i][18]) + { + include_schemes = argv[i] + 18; + } + else if (!strcmp(argv[i], "--language")) + { + i ++; + if (i < argc) + language = argv[i]; + else + { + _cupsLangPuts(stderr, _("lpinfo: Expected language after \"--language\".")); + return (1); + } + } + else if (!strncmp(argv[i], "--language=", 11) && argv[i][11]) + { + language = argv[i] + 11; + } + else if (!strcmp(argv[i], "--make-and-model")) + { + i ++; + if (i < argc) + make_model= argv[i]; + else + { + _cupsLangPuts(stderr, _("lpinfo: Expected make and model after \"--make-and-model\".")); + return (1); + } + } + else if (!strncmp(argv[i], "--make-and-model=", 17) && argv[i][17]) + { + make_model = argv[i] + 17; + } + else if (!strcmp(argv[i], "--product")) + { + i ++; + if (i < argc) + product = argv[i]; + else + { + _cupsLangPuts(stderr, _("lpinfo: Expected product string after \"--product\".")); + return (1); + } + } + else if (!strncmp(argv[i], "--product=", 10) && argv[i][10]) + { + product = argv[i] + 10; + } + else if (!strcmp(argv[i], "--timeout")) + { + i ++; + if (i < argc) + timeout = atoi(argv[i]); + else + { + _cupsLangPuts(stderr, _("lpinfo: Expected timeout after \"--timeout\".")); + return (1); + } + } + else if (!strncmp(argv[i], "--timeout=", 10) && argv[i][10]) + { + timeout = atoi(argv[i] + 10); + } + else if (argv[i][0] == '-') + { + for (opt = argv[i] + 1; *opt; opt ++) + { + switch (*opt) + { + case 'E' : /* Encrypt */ #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, - _("%s: Sorry, no encryption support."), - argv[0]); + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ - break; - - case 'h' : /* Connect to host */ - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; - - if (i >= argc) - { - _cupsLangPuts(stderr, - _("Error: need hostname after \"-h\" option.")); - return (1); - } - - cupsSetServer(argv[i]); - } - break; + break; - case 'l' : /* Show long listing */ - long_status = 1; - break; - - case 'm' : /* Show models */ - if (show_models(long_status, device_id, language, make_model, - product, include_schemes, exclude_schemes)) - return (1); - break; - - case 'v' : /* Show available devices */ - if (show_devices(long_status, timeout, include_schemes, - exclude_schemes)) - return (1); - break; - - case '-' : /* --something */ - if (!strcmp(argv[i], "--device-id")) - { - i ++; - - if (i < argc) - device_id = argv[i]; - else - { - _cupsLangPuts(stderr, - _("lpinfo: Expected 1284 device ID string " - "after \"--device-id\".")); - return (1); - } - } - else if (!strncmp(argv[i], "--device-id=", 12) && argv[i][12]) - { - device_id = argv[i] + 12; - } - else if (!strcmp(argv[i], "--exclude-schemes")) - { - i ++; - - if (i < argc) - exclude_schemes = argv[i]; - else - { - _cupsLangPuts(stderr, - _("lpinfo: Expected scheme list after " - "\"--exclude-schemes\".")); - return (1); - } - } - else if (!strncmp(argv[i], "--exclude-schemes=", 18) && argv[i][18]) - { - exclude_schemes = argv[i] + 18; - } - else if (!strcmp(argv[i], "--include-schemes")) - { - i ++; - - if (i < argc) - include_schemes = argv[i]; - else - { - _cupsLangPuts(stderr, - _("lpinfo: Expected scheme list after " - "\"--include-schemes\".")); - return (1); - } - } - else if (!strncmp(argv[i], "--include-schemes=", 18) && argv[i][18]) - { - include_schemes = argv[i] + 18; - } - else if (!strcmp(argv[i], "--language")) - { - i ++; - if (i < argc) - language = argv[i]; - else + case 'h' : /* Connect to host */ + if (opt[1] != '\0') { - _cupsLangPuts(stderr, - _("lpinfo: Expected language after " - "\"--language\".")); - return (1); + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; } - } - else if (!strncmp(argv[i], "--language=", 11) && argv[i][11]) - { - language = argv[i] + 11; - } - else if (!strcmp(argv[i], "--make-and-model")) - { - i ++; - if (i < argc) - make_model= argv[i]; else { - _cupsLangPuts(stderr, - _("lpinfo: Expected make and model after " - "\"--make-and-model\".")); - return (1); + i ++; + + if (i >= argc) + { + _cupsLangPuts(stderr, _("Error: need hostname after \"-h\" option.")); + return (1); + } + + cupsSetServer(argv[i]); } - } - else if (!strncmp(argv[i], "--make-and-model=", 17) && argv[i][17]) - { - make_model = argv[i] + 17; - } - else if (!strcmp(argv[i], "--product")) - { - i ++; - if (i < argc) - product = argv[i]; - else - { - _cupsLangPuts(stderr, - _("lpinfo: Expected product string after " - "\"--product\".")); + break; + + case 'l' : /* Show long listing */ + long_status = 1; + break; + + case 'm' : /* Show models */ + if (show_models(long_status, device_id, language, make_model, product, include_schemes, exclude_schemes)) return (1); - } - } - else if (!strncmp(argv[i], "--product=", 10) && argv[i][10]) - { - product = argv[i] + 10; - } - else if (!strcmp(argv[i], "--timeout")) - { - i ++; - if (i < argc) - timeout = atoi(argv[i]); - else - { - _cupsLangPuts(stderr, - _("lpinfo: Expected timeout after " - "\"--timeout\".")); + break; + + case 'v' : /* Show available devices */ + if (show_devices(long_status, timeout, include_schemes, exclude_schemes)) return (1); - } - } - else if (!strncmp(argv[i], "--timeout=", 10) && argv[i][10]) - { - timeout = atoi(argv[i] + 10); - } - else - { - _cupsLangPrintf(stderr, _("lpinfo: Unknown option \"%s\"."), - argv[i]); - return (1); - } - break; + break; - default : - _cupsLangPrintf(stderr, _("lpinfo: Unknown option \"%c\"."), - argv[i][1]); - return (1); + default : + _cupsLangPrintf(stderr, _("%s: Unknown option \"%c\"."), argv[0], *opt); + return (1); + } } + } else { - _cupsLangPrintf(stderr, _("lpinfo: Unknown argument \"%s\"."), - argv[i]); + _cupsLangPrintf(stderr, _("%s: Unknown argument \"%s\"."), argv[0], argv[i]); return (1); } + } return (0); } diff --git a/systemv/lpmove.c b/systemv/lpmove.c index 9cba172c4..a3c4f0182 100644 --- a/systemv/lpmove.c +++ b/systemv/lpmove.c @@ -1,7 +1,7 @@ /* * "lpmove" command for CUPS. * - * Copyright 2007-2010 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -36,7 +36,8 @@ main(int argc, /* I - Number of command-line arguments */ { int i; /* Looping var */ http_t *http; /* Connection to server */ - const char *job; /* Job name */ + const char *opt, /* Option pointer */ + *job; /* Job name */ int jobid; /* Job ID */ int num_dests; /* Number of destinations */ cups_dest_t *dests; /* Destinations */ @@ -54,43 +55,48 @@ main(int argc, /* I - Number of command-line arguments */ src = NULL; for (i = 1; i < argc; i ++) + { if (argv[i][0] == '-') - switch (argv[i][1]) + { + for (opt = argv[i] + 1; *opt; opt ++) { - case 'E' : /* Encrypt */ + switch (*opt) + { + case 'E' : /* Encrypt */ #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, - _("%s: Sorry, no encryption support."), - argv[0]); + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ - break; - - case 'h' : /* Connect to host */ - if (argv[i][2] != '\0') - cupsSetServer(argv[i] + 2); - else - { - i ++; + break; - if (i >= argc) + case 'h' : /* Connect to host */ + if (opt[1] != '\0') { - _cupsLangPuts(stderr, - _("Error: need hostname after \"-h\" option.")); - return (1); - } - - cupsSetServer(argv[i]); - } - break; - - default : - _cupsLangPrintf(stderr, _("lpmove: Unknown option \"%c\"."), - argv[i][1]); - return (1); + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; + + if (i >= argc) + { + _cupsLangPuts(stderr, _("Error: need hostname after \"-h\" option.")); + return (1); + } + + cupsSetServer(argv[i]); + } + break; + + default : + _cupsLangPrintf(stderr, _("%s: Unknown option \"%c\"."), argv[0], *opt); + return (1); + } } + } else if (!jobid && !src) { if (num_dests == 0) @@ -112,6 +118,7 @@ main(int argc, /* I - Number of command-line arguments */ _cupsLangPrintf(stderr, _("lpmove: Unknown argument \"%s\"."), argv[i]); return (1); } + } if ((!jobid && !src) || !dest) { diff --git a/systemv/lpoptions.c b/systemv/lpoptions.c index e2d95a941..56b4f604e 100644 --- a/systemv/lpoptions.c +++ b/systemv/lpoptions.c @@ -1,7 +1,7 @@ /* * Printer option program for CUPS. * - * Copyright 2007-2015 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -43,7 +43,8 @@ main(int argc, /* I - Number of command-line arguments */ int num_dests; /* Number of destinations */ cups_dest_t *dests; /* Destinations */ cups_dest_t *dest; /* Current destination */ - char *printer, /* Printer name */ + char *opt, /* Option pointer */ + *printer, /* Printer name */ *instance, /* Instance name */ *option; /* Current option */ @@ -62,272 +63,256 @@ main(int argc, /* I - Number of command-line arguments */ changes = 0; for (i = 1; i < argc; i ++) + { if (argv[i][0] == '-') { - switch (argv[i][1]) + for (opt = argv[i] + 1; *opt; opt ++) { - case 'd' : /* -d printer */ - if (argv[i][2]) - printer = argv[i] + 2; - else - { - i ++; - if (i >= argc) - usage(); - - printer = argv[i]; - } - - if ((instance = strrchr(printer, '/')) != NULL) - *instance++ = '\0'; - - if (num_dests == 0) - num_dests = cupsGetDests(&dests); - - if (num_dests == 0 || !dests || - (dest = cupsGetDest(printer, instance, num_dests, - dests)) == NULL) - { - _cupsLangPuts(stderr, _("lpoptions: Unknown printer or class.")); - return (1); - } + switch (*opt) + { + case 'd' : /* -d printer */ + if (opt[1] != '\0') + { + printer = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + usage(); - /* - * Set the default destination... - */ + printer = argv[i]; + } - for (j = 0; j < num_dests; j ++) - dests[j].is_default = 0; + if ((instance = strrchr(printer, '/')) != NULL) + *instance++ = '\0'; - dest->is_default = 1; + if (num_dests == 0) + num_dests = cupsGetDests(&dests); - cupsSetDests(num_dests, dests); + if (num_dests == 0 || !dests || (dest = cupsGetDest(printer, instance, num_dests, dests)) == NULL) + { + _cupsLangPuts(stderr, _("lpoptions: Unknown printer or class.")); + return (1); + } - for (j = 0; j < dest->num_options; j ++) - if (cupsGetOption(dest->options[j].name, num_options, - options) == NULL) - num_options = cupsAddOption(dest->options[j].name, - dest->options[j].value, - num_options, &options); - break; + /* + * Set the default destination... + */ - case 'h' : /* -h server */ - if (argv[i][2]) - cupsSetServer(argv[i] + 2); - else - { - i ++; - if (i >= argc) - usage(); + for (j = 0; j < num_dests; j ++) + dests[j].is_default = 0; - cupsSetServer(argv[i]); - } - break; + dest->is_default = 1; - case 'E' : /* Encrypt connection */ - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); - break; + cupsSetDests(num_dests, dests); - case 'l' : /* -l (list options) */ - if (dest == NULL) - { - if (num_dests == 0) - num_dests = cupsGetDests(&dests); + for (j = 0; j < dest->num_options; j ++) + if (cupsGetOption(dest->options[j].name, num_options, + options) == NULL) + num_options = cupsAddOption(dest->options[j].name, + dest->options[j].value, + num_options, &options); + break; - if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) == NULL) - dest = dests; - } + case 'h' : /* -h server */ + if (opt[1] != '\0') + { + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + usage(); - if (dest == NULL) - _cupsLangPuts(stderr, _("lpoptions: No printers.")); - else - list_options(dest); + cupsSetServer(argv[i]); + } + break; - changes = -1; - break; + case 'E' : /* Encrypt connection */ + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + break; - case 'o' : /* -o option[=value] */ - if (dest == NULL) - { - if (num_dests == 0) - num_dests = cupsGetDests(&dests); + case 'l' : /* -l (list options) */ + if (dest == NULL) + { + if (num_dests == 0) + num_dests = cupsGetDests(&dests); - if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) == NULL) - dest = dests; + if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) == NULL) + dest = dests; + } if (dest == NULL) - { _cupsLangPuts(stderr, _("lpoptions: No printers.")); - return (1); - } - - for (j = 0; j < dest->num_options; j ++) - if (cupsGetOption(dest->options[j].name, num_options, options) == NULL) - num_options = cupsAddOption(dest->options[j].name, - dest->options[j].value, - num_options, &options); - } - - if (argv[i][2]) - num_options = cupsParseOptions(argv[i] + 2, num_options, &options); - else - { - i ++; - if (i >= argc) - usage(); - - num_options = cupsParseOptions(argv[i], num_options, &options); - } - - changes = 1; - break; + else + list_options(dest); - case 'p' : /* -p printer */ - if (argv[i][2]) - printer = argv[i] + 2; - else - { - i ++; - if (i >= argc) - usage(); + changes = -1; + break; - printer = argv[i]; - } + case 'o' : /* -o option[=value] */ + if (dest == NULL) + { + if (num_dests == 0) + num_dests = cupsGetDests(&dests); + + if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) == NULL) + dest = dests; + + if (dest == NULL) + { + _cupsLangPuts(stderr, _("lpoptions: No printers.")); + return (1); + } + + for (j = 0; j < dest->num_options; j ++) + if (cupsGetOption(dest->options[j].name, num_options, options) == NULL) + num_options = cupsAddOption(dest->options[j].name, + dest->options[j].value, + num_options, &options); + } - if ((instance = strrchr(printer, '/')) != NULL) - *instance++ = '\0'; + if (opt[1] != '\0') + { + num_options = cupsParseOptions(opt + 1, num_options, &options); + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + usage(); - if (num_dests == 0) - num_dests = cupsGetDests(&dests); + num_options = cupsParseOptions(argv[i], num_options, &options); + } - if ((dest = cupsGetDest(printer, instance, num_dests, dests)) == NULL) - { - num_dests = cupsAddDest(printer, instance, num_dests, &dests); - dest = cupsGetDest(printer, instance, num_dests, dests); + changes = 1; + break; - if (dest == NULL) + case 'p' : /* -p printer */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("lpoptions: Unable to add printer or " - "instance: %s"), - strerror(errno)); - return (1); + printer = opt + 1; + opt += strlen(opt) - 1; } - } + else + { + i ++; + if (i >= argc) + usage(); - for (j = 0; j < dest->num_options; j ++) - if (cupsGetOption(dest->options[j].name, num_options, options) == NULL) - num_options = cupsAddOption(dest->options[j].name, - dest->options[j].value, - num_options, &options); - break; + printer = argv[i]; + } + + if ((instance = strrchr(printer, '/')) != NULL) + *instance++ = '\0'; - case 'r' : /* -r option (remove) */ - if (dest == NULL) - { if (num_dests == 0) num_dests = cupsGetDests(&dests); - if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) == NULL) - dest = dests; - - if (dest == NULL) - { - _cupsLangPuts(stderr, _("lpoptions: No printers.")); - return (1); - } + if ((dest = cupsGetDest(printer, instance, num_dests, dests)) == NULL) + { + num_dests = cupsAddDest(printer, instance, num_dests, &dests); + dest = cupsGetDest(printer, instance, num_dests, dests); + + if (dest == NULL) + { + _cupsLangPrintf(stderr, _("lpoptions: Unable to add printer or instance: %s"), strerror(errno)); + return (1); + } + } for (j = 0; j < dest->num_options; j ++) - if (cupsGetOption(dest->options[j].name, num_options, - options) == NULL) + if (cupsGetOption(dest->options[j].name, num_options, options) == NULL) num_options = cupsAddOption(dest->options[j].name, - dest->options[j].value, - num_options, &options); - } + dest->options[j].value, + num_options, &options); + break; - if (argv[i][2]) - option = argv[i] + 2; - else - { - i ++; - if (i >= argc) - usage(); - - option = argv[i]; - } - - for (j = 0; j < num_options; j ++) - if (!_cups_strcasecmp(options[j].name, option)) + case 'r' : /* -r option (remove) */ + if (dest == NULL) { - /* - * Remove this option... - */ - - num_options --; - - if (j < num_options) - memmove(options + j, options + j + 1, sizeof(cups_option_t) * (size_t)(num_options - j)); - break; - } - - changes = 1; - break; - - case 'x' : /* -x printer */ - if (argv[i][2]) - printer = argv[i] + 2; - else - { - i ++; - if (i >= argc) - usage(); - - printer = argv[i]; - } + if (num_dests == 0) + num_dests = cupsGetDests(&dests); + + if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) == NULL) + dest = dests; + + if (dest == NULL) + { + _cupsLangPuts(stderr, _("lpoptions: No printers.")); + return (1); + } + + for (j = 0; j < dest->num_options; j ++) + if (cupsGetOption(dest->options[j].name, num_options, + options) == NULL) + num_options = cupsAddOption(dest->options[j].name, + dest->options[j].value, + num_options, &options); + } - if ((instance = strrchr(printer, '/')) != NULL) - *instance++ = '\0'; + if (opt[1] != '\0') + { + option = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + usage(); - if (num_dests == 0) - num_dests = cupsGetDests(&dests); + option = argv[i]; + } - if ((dest = cupsGetDest(printer, instance, num_dests, - dests)) != NULL) - { - cupsFreeOptions(dest->num_options, dest->options); + num_options = cupsRemoveOption(option, num_options, &options); - /* - * If we are "deleting" the default printer, then just set the - * number of options to 0; if it is also the system default - * then cupsSetDests() will remove it for us... - */ + changes = 1; + break; - if (dest->is_default) + case 'x' : /* -x printer */ + if (opt[1] != '\0') { - dest->num_options = 0; - dest->options = NULL; + printer = opt + 1; + opt += strlen(opt) - 1; } else { - num_dests --; + i ++; + if (i >= argc) + usage(); - j = dest - dests; - if (j < num_dests) - memmove(dest, dest + 1, (size_t)(num_dests - j) * sizeof(cups_dest_t)); + printer = argv[i]; } - } - cupsSetDests(num_dests, dests); - dest = NULL; - changes = -1; - break; + if ((instance = strrchr(printer, '/')) != NULL) + *instance++ = '\0'; + + if (num_dests == 0) + num_dests = cupsGetDests(&dests); + + num_dests = cupsRemoveDest(printer, instance, num_dests, &dests); - default : - usage(); + cupsSetDests(num_dests, dests); + dest = NULL; + changes = -1; + break; + + default : + usage(); + } } } else + { usage(); + } + } if (num_dests == 0) num_dests = cupsGetDests(&dests); diff --git a/systemv/lpstat.c b/systemv/lpstat.c index c487f8708..c13739fc8 100644 --- a/systemv/lpstat.c +++ b/systemv/lpstat.c @@ -1,7 +1,7 @@ /* * "lpstat" command for CUPS. * - * Copyright 2007-2014 by Apple Inc. + * Copyright 2007-2016 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -48,6 +48,7 @@ main(int argc, /* I - Number of command-line arguments */ { int i, /* Looping var */ status; /* Exit status */ + char *opt; /* Option pointer */ int num_dests; /* Number of user destinations */ cups_dest_t *dests; /* User destinations */ int long_status; /* Long status report? */ @@ -71,395 +72,394 @@ main(int argc, /* I - Number of command-line arguments */ op = 0; for (i = 1; i < argc; i ++) + { if (argv[i][0] == '-') - switch (argv[i][1]) + { + for (opt = argv[i] + 1; *opt; opt ++) { - case 'D' : /* Show description */ - long_status = 1; - break; + switch (argv[i][1]) + { + case 'D' : /* Show description */ + long_status = 1; + break; - case 'E' : /* Encrypt */ + case 'E' : /* Encrypt */ #ifdef HAVE_SSL - cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); + cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, - _("%s: Sorry, no encryption support."), - argv[0]); + _cupsLangPrintf(stderr, + _("%s: Sorry, no encryption support."), + argv[0]); #endif /* HAVE_SSL */ - break; + break; - case 'H' : /* Show server and port */ - if (cupsServer()[0] == '/') - _cupsLangPuts(stdout, cupsServer()); - else - _cupsLangPrintf(stdout, "%s:%d", cupsServer(), ippPort()); - op = 'H'; - break; - - case 'P' : /* Show paper types */ - op = 'P'; - break; - - case 'R' : /* Show ranking */ - ranking = 1; - break; - - case 'S' : /* Show charsets */ - op = 'S'; - if (!argv[i][2]) - i ++; - break; - - case 'U' : /* Username */ - if (argv[i][2]) - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) + case 'H' : /* Show server and port */ + if (cupsServer()[0] == '/') + _cupsLangPuts(stdout, cupsServer()); + else + _cupsLangPrintf(stdout, "%s:%d", cupsServer(), ippPort()); + op = 'H'; + break; + + case 'P' : /* Show paper types */ + op = 'P'; + break; + + case 'R' : /* Show ranking */ + ranking = 1; + break; + + case 'S' : /* Show charsets */ + op = 'S'; + if (!argv[i][2]) + i ++; + break; + + case 'U' : /* Username */ + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected username after " - "\"-U\" option."), - argv[0]); - return (1); + cupsSetUser(opt + 1); + opt += strlen(opt) - 1; } + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]); + return (1); + } - cupsSetUser(argv[i]); - } - break; + cupsSetUser(argv[i]); + } + break; - case 'W' : /* Show which jobs? */ - if (argv[i][2]) - which = argv[i] + 2; - else - { - i ++; + case 'W' : /* Show which jobs? */ + if (opt[1] != '\0') + { + which = opt + 1; + opt += strlen(opt) - 1; + } + else + { + i ++; - if (i >= argc) + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv[0]); + return (1); + } + + which = argv[i]; + } + + if (strcmp(which, "completed") && strcmp(which, "not-completed") && strcmp(which, "all")) { - _cupsLangPrintf(stderr, - _("%s: Error - need \"completed\", " - "\"not-completed\", or \"all\" after " - "\"-W\" option."), - argv[0]); + _cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv[0]); return (1); - } + } + break; - which = argv[i]; - } + case 'a' : /* Show acceptance status */ + op = 'a'; - if (strcmp(which, "completed") && strcmp(which, "not-completed") && - strcmp(which, "all")) - { - _cupsLangPrintf(stderr, - _("%s: Error - need \"completed\", " - "\"not-completed\", or \"all\" after " - "\"-W\" option."), - argv[0]); - return (1); - } - break; + if (opt[1] != '\0') + { + check_dest(argv[0], opt + 1, &num_dests, &dests); - case 'a' : /* Show acceptance status */ - op = 'a'; + status |= show_accepting(opt + 1, num_dests, dests); + opt += strlen(opt) - 1; + } + else if ((i + 1) < argc && argv[i + 1][0] != '-') + { + i ++; - if (argv[i][2]) - { - check_dest(argv[0], argv[i] + 2, &num_dests, &dests); + check_dest(argv[0], argv[i], &num_dests, &dests); - status |= show_accepting(argv[i] + 2, num_dests, dests); - } - else if ((i + 1) < argc && argv[i + 1][0] != '-') - { - i ++; + status |= show_accepting(argv[i], num_dests, dests); + } + else + { + if (num_dests <= 1) + { + cupsFreeDests(num_dests, dests); + num_dests = cupsGetDests(&dests); + + if (num_dests == 0 && (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); + return (1); + } + } + + status |= show_accepting(NULL, num_dests, dests); + } + break; - check_dest(argv[0], argv[i], &num_dests, &dests); + case 'c' : /* Show classes and members */ + op = 'c'; - status |= show_accepting(argv[i], num_dests, dests); - } - else - { - if (num_dests <= 1) + if (opt[1] != '\0') { - cupsFreeDests(num_dests, dests); - num_dests = cupsGetDests(&dests); + check_dest(argv[0], opt + 1, &num_dests, &dests); + + status |= show_classes(opt + 1); + opt += strlen(opt) - 1; + } + else if ((i + 1) < argc && argv[i + 1][0] != '-') + { + i ++; + + check_dest(argv[0], argv[i], &num_dests, &dests); + + status |= show_classes(argv[i]); + } + else + status |= show_classes(NULL); + break; + + case 'd' : /* Show default destination */ + op = 'd'; + + if (num_dests != 1 || !dests[0].is_default) + { + cupsFreeDests(num_dests, dests); + + dests = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); + num_dests = dests ? 1 : 0; if (num_dests == 0 && (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) { - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); + _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); return (1); } } - status |= show_accepting(NULL, num_dests, dests); - } - break; - - case 'c' : /* Show classes and members */ - op = 'c'; - - if (argv[i][2]) - { - check_dest(argv[0], argv[i] + 2, &num_dests, &dests); + show_default(dests); + break; - status |= show_classes(argv[i] + 2); - } - else if ((i + 1) < argc && argv[i + 1][0] != '-') - { - i ++; + case 'f' : /* Show forms */ + op = 'f'; + if (opt[1] != '\0') + { + opt += strlen(opt) - 1; + } + else + { + i ++; + if (i >= argc) + return (1); + } + break; - check_dest(argv[0], argv[i], &num_dests, &dests); + case 'h' : /* Connect to host */ + if (opt[1] != '\0') + { + cupsSetServer(opt + 1); + opt += strlen(opt) - 1; + } + else + { + i ++; - status |= show_classes(argv[i]); - } - else - status |= show_classes(NULL); - break; + if (i >= argc) + { + _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]); + return (1); + } - case 'd' : /* Show default destination */ - op = 'd'; + cupsSetServer(argv[i]); + } + break; - if (num_dests != 1 || !dests[0].is_default) - { - cupsFreeDests(num_dests, dests); + case 'l' : /* Long status or long job status */ + long_status = 2; + break; - dests = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); - num_dests = dests ? 1 : 0; + case 'o' : /* Show jobs by destination */ + op = 'o'; - if (num_dests == 0 && - (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || - cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + if (opt[1]) { - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); - return (1); + check_dest(argv[0], opt + 1, &num_dests, &dests); + + status |= show_jobs(opt + 1, NULL, long_status, ranking, which); + opt += strlen(opt) - 1; } - } + else if ((i + 1) < argc && argv[i + 1][0] != '-') + { + i ++; - show_default(dests); - break; + check_dest(argv[0], argv[i], &num_dests, &dests); - case 'f' : /* Show forms */ - op = 'f'; - if (!argv[i][2]) - i ++; - break; + status |= show_jobs(argv[i], NULL, long_status, ranking, which); + } + else + status |= show_jobs(NULL, NULL, long_status, ranking, which); + break; - case 'h' : /* Connect to host */ - if (argv[i][2]) - cupsSetServer(argv[i] + 2); - else - { - i ++; + case 'p' : /* Show printers */ + op = 'p'; - if (i >= argc) + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - expected hostname after " - "\"-h\" option."), - argv[0]); - return (1); - } + check_dest(argv[0], opt + 1, &num_dests, &dests); - cupsSetServer(argv[i]); - } - break; + status |= show_printers(opt + 1, num_dests, dests, + long_status); + opt += strlen(opt) - 1; + } + else if ((i + 1) < argc && argv[i + 1][0] != '-') + { + i ++; - case 'l' : /* Long status or long job status */ - long_status = 2; - break; + check_dest(argv[0], argv[i], &num_dests, &dests); - case 'o' : /* Show jobs by destination */ - op = 'o'; + status |= show_printers(argv[i], num_dests, dests, long_status); + } + else + { + if (num_dests <= 1) + { + cupsFreeDests(num_dests, dests); + num_dests = cupsGetDests(&dests); + + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); + return (1); + } + } - if (argv[i][2]) - { - check_dest(argv[0], argv[i] + 2, &num_dests, &dests); + status |= show_printers(NULL, num_dests, dests, long_status); + } + break; - status |= show_jobs(argv[i] + 2, NULL, long_status, ranking, - which); - } - else if ((i + 1) < argc && argv[i + 1][0] != '-') - { - i ++; + case 'r' : /* Show scheduler status */ + op = 'r'; - check_dest(argv[0], argv[i], &num_dests, &dests); + show_scheduler(); + break; - status |= show_jobs(argv[i], NULL, long_status, ranking, which); - } - else - status |= show_jobs(NULL, NULL, long_status, ranking, which); - break; + case 's' : /* Show summary */ + op = 's'; - case 'p' : /* Show printers */ - op = 'p'; + if (num_dests <= 1) + { + cupsFreeDests(num_dests, dests); + num_dests = cupsGetDests(&dests); - if (argv[i][2]) - { - check_dest(argv[0], argv[i] + 2, &num_dests, &dests); + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); + return (1); + } + } - status |= show_printers(argv[i] + 2, num_dests, dests, - long_status); - } - else if ((i + 1) < argc && argv[i + 1][0] != '-') - { - i ++; + show_default(cupsGetDest(NULL, NULL, num_dests, dests)); + status |= show_classes(NULL); + status |= show_devices(NULL, num_dests, dests); + break; - check_dest(argv[0], argv[i], &num_dests, &dests); + case 't' : /* Show all info */ + op = 't'; - status |= show_printers(argv[i], num_dests, dests, long_status); - } - else - { - if (num_dests <= 1) + if (num_dests <= 1) { - cupsFreeDests(num_dests, dests); + cupsFreeDests(num_dests, dests); num_dests = cupsGetDests(&dests); if (num_dests == 0 && (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) { - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); + _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); return (1); } } + show_scheduler(); + show_default(cupsGetDest(NULL, NULL, num_dests, dests)); + status |= show_classes(NULL); + status |= show_devices(NULL, num_dests, dests); + status |= show_accepting(NULL, num_dests, dests); status |= show_printers(NULL, num_dests, dests, long_status); - } - break; - - case 'r' : /* Show scheduler status */ - op = 'r'; - - show_scheduler(); - break; - - case 's' : /* Show summary */ - op = 's'; + status |= show_jobs(NULL, NULL, long_status, ranking, which); + break; - if (num_dests <= 1) - { - cupsFreeDests(num_dests, dests); - num_dests = cupsGetDests(&dests); + case 'u' : /* Show jobs by user */ + op = 'u'; - if (num_dests == 0 && - (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || - cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + if (opt[1] != '\0') { - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); - return (1); + status |= show_jobs(NULL, opt + 1, long_status, ranking, which); + opt += strlen(opt) - 1; } - } - - show_default(cupsGetDest(NULL, NULL, num_dests, dests)); - status |= show_classes(NULL); - status |= show_devices(NULL, num_dests, dests); - break; - - case 't' : /* Show all info */ - op = 't'; - - if (num_dests <= 1) - { - cupsFreeDests(num_dests, dests); - num_dests = cupsGetDests(&dests); - - if (num_dests == 0 && - (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || - cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + else if ((i + 1) < argc && argv[i + 1][0] != '-') { - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); - return (1); + i ++; + status |= show_jobs(NULL, argv[i], long_status, ranking, which); } - } - - show_scheduler(); - show_default(cupsGetDest(NULL, NULL, num_dests, dests)); - status |= show_classes(NULL); - status |= show_devices(NULL, num_dests, dests); - status |= show_accepting(NULL, num_dests, dests); - status |= show_printers(NULL, num_dests, dests, long_status); - status |= show_jobs(NULL, NULL, long_status, ranking, which); - break; - - case 'u' : /* Show jobs by user */ - op = 'u'; - - if (argv[i][2]) - status |= show_jobs(NULL, argv[i] + 2, long_status, ranking, - which); - else if ((i + 1) < argc && argv[i + 1][0] != '-') - { - i ++; - status |= show_jobs(NULL, argv[i], long_status, ranking, which); - } - else - status |= show_jobs(NULL, NULL, long_status, ranking, which); - break; + else + status |= show_jobs(NULL, NULL, long_status, ranking, which); + break; - case 'v' : /* Show printer devices */ - op = 'v'; + case 'v' : /* Show printer devices */ + op = 'v'; - if (argv[i][2]) - { - check_dest(argv[0], argv[i] + 2, &num_dests, &dests); + if (opt[1] != '\0') + { + check_dest(argv[0], opt + 1, &num_dests, &dests); - status |= show_devices(argv[i] + 2, num_dests, dests); - } - else if ((i + 1) < argc && argv[i + 1][0] != '-') - { - i ++; + status |= show_devices(opt + 1, num_dests, dests); + opt += strlen(opt) - 1; + } + else if ((i + 1) < argc && argv[i + 1][0] != '-') + { + i ++; - check_dest(argv[0], argv[i], &num_dests, &dests); + check_dest(argv[0], argv[i], &num_dests, &dests); - status |= show_devices(argv[i], num_dests, dests); - } - else - { - if (num_dests <= 1) + status |= show_devices(argv[i], num_dests, dests); + } + else { - cupsFreeDests(num_dests, dests); - num_dests = cupsGetDests(&dests); - - if (num_dests == 0 && - (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || - cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + if (num_dests <= 1) { - _cupsLangPrintf(stderr, - _("%s: Error - add '/version=1.1' to server " - "name."), argv[0]); - return (1); + cupsFreeDests(num_dests, dests); + num_dests = cupsGetDests(&dests); + + if (num_dests == 0 && + (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || + cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) + { + _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); + return (1); + } } - } - status |= show_devices(NULL, num_dests, dests); - } - break; + status |= show_devices(NULL, num_dests, dests); + } + break; - default : - _cupsLangPrintf(stderr, - _("%s: Error - unknown option \"%c\"."), - argv[0], argv[i][1]); - return (1); + default : + _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], argv[i][1]); + return (1); + } } + } else { status |= show_jobs(argv[i], NULL, long_status, ranking, which); op = 'o'; } + } if (!op) status |= show_jobs(NULL, cupsUser(), long_status, ranking, which); -- 2.39.2