diff options
author | jlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2006-01-26 21:39:43 +0000 |
---|---|---|
committer | jlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2006-01-26 21:39:43 +0000 |
commit | fa73b22906f71080fa5056485d8204612717adac (patch) | |
tree | f2f23b68c20d1fc9a85301527690aca5efa382df /berkeley | |
parent | 4a09f02d10d679af0b04d36c25f0dcb518e432a4 (diff) | |
download | cups-fa73b22906f71080fa5056485d8204612717adac.tar.gz |
Load cups into easysw/current.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@13 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'berkeley')
-rw-r--r-- | berkeley/lpc.c | 41 | ||||
-rw-r--r-- | berkeley/lpq.c | 263 | ||||
-rw-r--r-- | berkeley/lpr.c | 236 | ||||
-rw-r--r-- | berkeley/lprm.c | 117 |
4 files changed, 355 insertions, 302 deletions
diff --git a/berkeley/lpc.c b/berkeley/lpc.c index 4b80a618d..5edbeafb7 100644 --- a/berkeley/lpc.c +++ b/berkeley/lpc.c @@ -1,5 +1,5 @@ /* - * "$Id: lpc.c 4906 2006-01-10 20:53:28Z mike $" + * "$Id: lpc.c 4948 2006-01-19 03:23:41Z mike $" * * "lpc" command for the Common UNIX Printing System (CUPS). * @@ -85,7 +85,7 @@ main(int argc, /* I - Number of command-line arguments */ * Do the command prompt thing... */ - printf("lpc> "); + _cupsLangPuts(stdout, _("lpc> ")); while (fgets(line, sizeof(line), stdin) != NULL) { /* @@ -113,7 +113,7 @@ main(int argc, /* I - Number of command-line arguments */ * Nothing left, just show a prompt... */ - printf("lpc> "); + _cupsLangPuts(stdout, _("lpc> ")); continue; } @@ -149,7 +149,7 @@ main(int argc, /* I - Number of command-line arguments */ * Put another prompt out to the user... */ - printf("lpc> "); + _cupsLangPuts(stdout, _("lpc> ")); } } @@ -197,7 +197,7 @@ do_command(http_t *http, /* I - HTTP connection to server */ else if (!compare_strings(command, "help", 1) || !strcmp(command, "?")) show_help(params); else - _cupsLangPrintf(stdout, cupsLangDefault(), + _cupsLangPrintf(stdout, _("%s is not implemented by the CUPS version of lpc.\n"), command); } @@ -212,20 +212,17 @@ show_help(const char *command) /* I - Command to describe or NULL */ { if (!command) { - _cupsLangPrintf(stdout, cupsLangDefault(), + _cupsLangPrintf(stdout, _("Commands may be abbreviated. Commands are:\n" "\n" "exit help quit status ?\n")); } else if (!compare_strings(command, "help", 1) || !strcmp(command, "?")) - _cupsLangPrintf(stdout, cupsLangDefault(), - _("help\t\tget help on commands\n")); + _cupsLangPrintf(stdout, _("help\t\tget help on commands\n")); else if (!compare_strings(command, "status", 4)) - _cupsLangPrintf(stdout, cupsLangDefault(), - _("status\t\tshow status of daemon and queue\n")); + _cupsLangPrintf(stdout, _("status\t\tshow status of daemon and queue\n")); else - _cupsLangPrintf(stdout, cupsLangDefault(), - _("?Invalid help command unknown\n")); + _cupsLangPrintf(stdout, _("?Invalid help command unknown\n")); } @@ -474,7 +471,7 @@ show_status(http_t *http, /* I - HTTP connection to server */ printf("%s:\n", printer); if (!strncmp(device, "file:", 5)) - _cupsLangPrintf(stdout, language, + _cupsLangPrintf(stdout, _("\tprinter is on device \'%s\' speed -1\n"), device + 5); else @@ -486,28 +483,28 @@ show_status(http_t *http, /* I - HTTP connection to server */ if ((delimiter = strchr(device, ':')) != NULL ) { *delimiter = '\0'; - _cupsLangPrintf(stdout, language, + _cupsLangPrintf(stdout, _("\tprinter is on device \'%s\' speed -1\n"), device); } } if (accepting) - _cupsLangPuts(stdout, language, _("\tqueuing is enabled\n")); + _cupsLangPuts(stdout, _("\tqueuing is enabled\n")); else - _cupsLangPuts(stdout, language, _("\tqueuing is disabled\n")); + _cupsLangPuts(stdout, _("\tqueuing is disabled\n")); if (pstate != IPP_PRINTER_STOPPED) - _cupsLangPuts(stdout, language, _("\tprinting is enabled\n")); + _cupsLangPuts(stdout, _("\tprinting is enabled\n")); else - _cupsLangPuts(stdout, language, _("\tprinting is disabled\n")); + _cupsLangPuts(stdout, _("\tprinting is disabled\n")); if (jobcount == 0) - _cupsLangPuts(stdout, language, _("\tno entries\n")); + _cupsLangPuts(stdout, _("\tno entries\n")); else - _cupsLangPrintf(stdout, language, _("\t%d entries\n"), jobcount); + _cupsLangPrintf(stdout, _("\t%d entries\n"), jobcount); - _cupsLangPuts(stdout, language, _("\tdaemon present\n")); + _cupsLangPuts(stdout, _("\tdaemon present\n")); } if (attr == NULL) @@ -520,5 +517,5 @@ show_status(http_t *http, /* I - HTTP connection to server */ /* - * End of "$Id: lpc.c 4906 2006-01-10 20:53:28Z mike $". + * End of "$Id: lpc.c 4948 2006-01-19 03:23:41Z mike $". */ diff --git a/berkeley/lpq.c b/berkeley/lpq.c index a5e009171..6fd1dfc91 100644 --- a/berkeley/lpq.c +++ b/berkeley/lpq.c @@ -1,5 +1,5 @@ /* - * "$Id: lpq.c 4906 2006-01-10 20:53:28Z mike $" + * "$Id: lpq.c 4948 2006-01-19 03:23:41Z mike $" * * "lpq" command for the Common UNIX Printing System (CUPS). * @@ -49,9 +49,9 @@ * Local functions... */ -static int show_jobs(http_t *, const char *, const char *, const int, - const int); -static void show_printer(http_t *, const char *); +static int show_jobs(const char *, http_t *, const char *, + const char *, const int, const int); +static void show_printer(const char *, http_t *, const char *); static void usage(void); @@ -60,24 +60,24 @@ static void usage(void); */ int -main(int argc, /* I - Number of command-line arguments */ - char *argv[]) /* I - Command-line arguments */ +main(int argc, /* I - Number of command-line arguments */ + char *argv[]) /* I - Command-line arguments */ { - int i; /* Looping var */ - http_t *http; /* Connection to server */ - const char *dest, /* Desired printer */ - *user, /* Desired user */ - *val; /* Environment variable name */ - char *instance; /* Printer instance */ - int id, /* Desired job ID */ - all, /* All printers */ - interval, /* Reporting interval */ - longstatus; /* Show file details */ - int num_dests; /* Number of destinations */ - cups_dest_t *dests; /* Destinations */ - cups_lang_t *language; /* Language */ + int i; /* Looping var */ + http_t *http; /* Connection to server */ + const char *dest, /* Desired printer */ + *user, /* Desired user */ + *val; /* Environment variable name */ + char *instance; /* Printer instance */ + int id, /* Desired job ID */ + all, /* All printers */ + interval, /* Reporting interval */ + longstatus; /* Show file details */ + int num_dests; /* Number of destinations */ + cups_dest_t *dests; /* Destinations */ + cups_lang_t *language; /* Language */ #ifdef HAVE_SSL - http_encryption_t encryption; /* Encryption? */ + http_encryption_t encryption; /* Encryption? */ #endif /* HAVE_SSL */ @@ -90,8 +90,7 @@ main(int argc, /* I - Number of command-line arguments */ if ((http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption())) == NULL) { - _cupsLangPuts(stderr, language, - _("lpq: Unable to contact server!\n")); + _cupsLangPrintf(stderr, _("%s: Unable to contact server!\n"), argv[0]); return (1); } @@ -121,12 +120,31 @@ main(int argc, /* I - Number of command-line arguments */ if (http) httpEncryption(http, encryption); #else - _cupsLangPrintf(stderr, language, + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support compiled in!\n"), argv[0]); #endif /* HAVE_SSL */ break; + case 'U' : /* Username */ + if (argv[i][2] != '\0') + cupsSetUser(argv[i] + 2); + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, + _("%s: Error - expected username after " + "\'-U\' option!\n"), + argv[0]); + return (1); + } + + cupsSetUser(argv[i]); + } + break; + case 'P' : /* Printer */ if (argv[i][2]) dest = argv[i] + 2; @@ -151,12 +169,13 @@ main(int argc, /* I - Number of command-line arguments */ if (cupsGetDest(dest, instance, num_dests, dests) == NULL) { if (instance) - _cupsLangPrintf(stderr, language, - _("lpq: Unknown destination \"%s/%s\"!\n"), - dest, instance); + _cupsLangPrintf(stderr, + _("%s: Error - unknown destination \"%s/%s\"!\n"), + argv[0], dest, instance); else - _cupsLangPrintf(stderr, language, - _("lpq: Unknown destination \"%s\"!\n"), dest); + _cupsLangPrintf(stderr, + _("%s: Unknown destination \"%s\"!\n"), + argv[0], dest); return (1); } @@ -166,6 +185,29 @@ main(int argc, /* I - Number of command-line arguments */ all = 1; break; + case 'h' : /* Connect to host */ + if (http != NULL) + httpClose(http); + + if (argv[i][2] != '\0') + cupsSetServer(argv[i] + 2); + else + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, + _("%s: Error - expected hostname after " + "\'-h\' option!\n"), + argv[0]); + return (1); + } + else + cupsSetServer(argv[i]); + } + break; + case 'l' : /* Long status */ longstatus = 1; break; @@ -207,13 +249,14 @@ main(int argc, /* I - Number of command-line arguments */ val = "LPDEST"; if (dest && !cupsGetDest(dest, NULL, num_dests, dests)) - _cupsLangPrintf(stderr, language, - _("lp: error - %s environment variable names " + _cupsLangPrintf(stderr, + _("%s: error - %s environment variable names " "non-existent destination \"%s\"!\n"), - val, dest); + argv[0], val, dest); else - _cupsLangPuts(stderr, language, - _("lpq: error - no default destination available.\n")); + _cupsLangPrintf(stderr, + _("%s: error - no default destination available.\n"), + argv[0]); httpClose(http); cupsFreeDests(num_dests, dests); return (1); @@ -227,9 +270,9 @@ main(int argc, /* I - Number of command-line arguments */ for (;;) { if (dest) - show_printer(http, dest); + show_printer(argv[0], http, dest); - i = show_jobs(http, dest, user, id, longstatus); + i = show_jobs(argv[0], http, dest, user, id, longstatus); if (i && interval) { @@ -255,33 +298,33 @@ main(int argc, /* I - Number of command-line arguments */ * 'show_jobs()' - Show jobs. */ -static int /* O - Number of jobs in queue */ -show_jobs(http_t *http, /* I - HTTP connection to server */ - const char *dest, /* I - Destination */ - const char *user, /* I - User */ - const int id, /* I - Job ID */ - const int longstatus)/* I - 1 if long report desired */ +static int /* O - Number of jobs in queue */ +show_jobs(const char *command, /* I - Command name */ + http_t *http, /* I - HTTP connection to server */ + const char *dest, /* I - Destination */ + const char *user, /* I - User */ + const int id, /* I - Job ID */ + const int longstatus) /* I - 1 if long report desired */ { - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - ipp_attribute_t *attr; /* Current attribute */ - cups_lang_t *language; /* Default language */ - const char *jobdest, /* Pointer into job-printer-uri */ - *jobuser, /* Pointer to job-originating-user-name */ - *jobname; /* Pointer to job-name */ - ipp_jstate_t jobstate; /* job-state */ - int jobid, /* job-id */ - jobsize, /* job-k-octets */ + ipp_t *request, /* IPP Request */ + *response; /* IPP Response */ + ipp_attribute_t *attr; /* Current attribute */ + const char *jobdest, /* Pointer into job-printer-uri */ + *jobuser, /* Pointer to job-originating-user-name */ + *jobname; /* Pointer to job-name */ + ipp_jstate_t jobstate; /* job-state */ + int jobid, /* job-id */ + jobsize, /* job-k-octets */ #ifdef __osf__ - jobpriority, /* job-priority */ + jobpriority, /* job-priority */ #endif /* __osf__ */ - jobcount, /* Number of jobs */ - jobcopies, /* Number of copies */ - rank; /* Rank of job */ - char resource[1024]; /* Resource string */ - char rankstr[255]; /* Rank string */ - char namestr[1024]; /* Job name string */ - static const char *ranks[10] =/* Ranking strings */ + jobcount, /* Number of jobs */ + jobcopies, /* Number of copies */ + rank; /* Rank of job */ + char resource[1024]; /* Resource string */ + char rankstr[255]; /* Rank string */ + char namestr[1024]; /* Job name string */ + static const char *ranks[10] = /* Ranking strings */ { "th", "st", @@ -311,18 +354,7 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ * job-uri or printer-uri */ - request = ippNew(); - - request->request.op.operation_id = id ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS; - request->request.op.request_id = 1; - - language = cupsLangDefault(); - - attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, - "attributes-charset", NULL, cupsLangEncoding(language)); - - attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, - "attributes-natural-language", NULL, language->language); + request = ippNewRequest(id ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS); if (dest == NULL) { @@ -360,8 +392,7 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ { if (response->request.status.status_code > IPP_OK_CONFLICT) { - _cupsLangPrintf(stderr, language, _("lpq: get-jobs failed: %s\n"), - ippErrorString(response->request.status.status_code)); + _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString()); ippDelete(response); return (0); } @@ -401,38 +432,38 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ while (attr != NULL && attr->group_tag == IPP_TAG_JOB) { - if (strcmp(attr->name, "job-id") == 0 && + if (!strcmp(attr->name, "job-id") && attr->value_tag == IPP_TAG_INTEGER) jobid = attr->values[0].integer; - if (strcmp(attr->name, "job-k-octets") == 0 && + if (!strcmp(attr->name, "job-k-octets") && attr->value_tag == IPP_TAG_INTEGER) jobsize = attr->values[0].integer; #ifdef __osf__ - if (strcmp(attr->name, "job-priority") == 0 && + if (!strcmp(attr->name, "job-priority") && attr->value_tag == IPP_TAG_INTEGER) jobpriority = attr->values[0].integer; #endif /* __osf__ */ - if (strcmp(attr->name, "job-state") == 0 && + if (!strcmp(attr->name, "job-state") && attr->value_tag == IPP_TAG_ENUM) jobstate = (ipp_jstate_t)attr->values[0].integer; - if (strcmp(attr->name, "job-printer-uri") == 0 && + if (!strcmp(attr->name, "job-printer-uri") && attr->value_tag == IPP_TAG_URI) if ((jobdest = strrchr(attr->values[0].string.text, '/')) != NULL) jobdest ++; - if (strcmp(attr->name, "job-originating-user-name") == 0 && + if (!strcmp(attr->name, "job-originating-user-name") && attr->value_tag == IPP_TAG_NAME) jobuser = attr->values[0].string.text; - if (strcmp(attr->name, "job-name") == 0 && + if (!strcmp(attr->name, "job-name") && attr->value_tag == IPP_TAG_NAME) jobname = attr->values[0].string.text; - if (strcmp(attr->name, "copies") == 0 && + if (!strcmp(attr->name, "copies") && attr->value_tag == IPP_TAG_INTEGER) jobcopies = attr->values[0].integer; @@ -453,11 +484,11 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ if (!longstatus && jobcount == 0) #ifdef __osf__ - _cupsLangPuts(stdout, language, + _cupsLangPuts(stdout, _("Rank Owner Pri Job Files" " Total Size\n")); #else - _cupsLangPuts(stdout, language, + _cupsLangPuts(stdout, _("Rank Owner Job File(s)" " Total Size\n")); #endif /* __osf__ */ @@ -487,7 +518,7 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ if (longstatus) { - _cupsLangPuts(stdout, language, ""); + _cupsLangPuts(stdout, "\n"); if (jobcopies > 1) snprintf(namestr, sizeof(namestr), "%d copies of %s", jobcopies, @@ -495,19 +526,19 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ else strlcpy(namestr, jobname, sizeof(namestr)); - _cupsLangPrintf(stdout, language, _("%s: %-33.33s [job %d localhost]\n"), + _cupsLangPrintf(stdout, _("%s: %-33.33s [job %d localhost]\n"), jobuser, rankstr, jobid); - _cupsLangPrintf(stdout, language, _(" %-39.39s %.0f bytes\n"), + _cupsLangPrintf(stdout, _(" %-39.39s %.0f bytes\n"), namestr, 1024.0 * jobsize); } else #ifdef __osf__ - _cupsLangPrintf(stdout, language, + _cupsLangPrintf(stdout, _("%-6s %-10.10s %-4d %-10d %-27.27s %.0f bytes\n"), rankstr, jobuser, jobpriority, jobid, jobname, 1024.0 * jobsize); #else - _cupsLangPrintf(stdout, language, + _cupsLangPrintf(stdout, _("%-7s %-7.7s %-7d %-31.31s %.0f bytes\n"), rankstr, jobuser, jobid, jobname, 1024.0 * jobsize); #endif /* __osf */ @@ -520,13 +551,12 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ } else { - _cupsLangPrintf(stderr, language, _("lpq: get-jobs failed: %s\n"), - ippErrorString(cupsLastError())); + _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString()); return (0); } if (jobcount == 0) - _cupsLangPuts(stdout, language, _("no entries\n")); + _cupsLangPuts(stdout, _("no entries\n")); return (jobcount); } @@ -537,16 +567,15 @@ show_jobs(http_t *http, /* I - HTTP connection to server */ */ static void -show_printer(http_t *http, /* I - HTTP connection to server */ - const char *dest) /* I - Destination */ +show_printer(const char *command, /* I - Command name */ + http_t *http, /* I - HTTP connection to server */ + const char *dest) /* I - Destination */ { - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - ipp_attribute_t *attr; /* Current attribute */ - cups_lang_t *language; /* Default language */ - ipp_pstate_t state; /* Printer state */ - char uri[HTTP_MAX_URI]; - /* Printer URI */ + ipp_t *request, /* IPP Request */ + *response; /* IPP Response */ + ipp_attribute_t *attr; /* Current attribute */ + ipp_pstate_t state; /* Printer state */ + char uri[HTTP_MAX_URI]; /* Printer URI */ if (http == NULL) @@ -561,18 +590,7 @@ show_printer(http_t *http, /* I - HTTP connection to server */ * printer-uri */ - request = ippNew(); - - request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES; - request->request.op.request_id = 1; - - language = cupsLangDefault(); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, - "attributes-charset", NULL, cupsLangEncoding(language)); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, - "attributes-natural-language", NULL, language->language); + request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES); httpAssembleURIf(uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s", dest); @@ -587,9 +605,7 @@ show_printer(http_t *http, /* I - HTTP connection to server */ { if (response->request.status.status_code > IPP_OK_CONFLICT) { - _cupsLangPrintf(stderr, language, - _("lpq: get-printer-attributes failed: %s\n"), - ippErrorString(response->request.status.status_code)); + _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString()); ippDelete(response); return; } @@ -602,23 +618,21 @@ show_printer(http_t *http, /* I - HTTP connection to server */ switch (state) { case IPP_PRINTER_IDLE : - _cupsLangPrintf(stdout, language, _("%s is ready\n"), dest); + _cupsLangPrintf(stdout, _("%s is ready\n"), dest); break; case IPP_PRINTER_PROCESSING : - _cupsLangPrintf(stdout, language, _("%s is ready and printing\n"), + _cupsLangPrintf(stdout, _("%s is ready and printing\n"), dest); break; case IPP_PRINTER_STOPPED : - _cupsLangPrintf(stdout, language, _("%s is not ready\n"), dest); + _cupsLangPrintf(stdout, _("%s is not ready\n"), dest); break; } ippDelete(response); } else - _cupsLangPrintf(stderr, language, - _("lpq: get-printer-attributes failed: %s\n"), - ippErrorString(cupsLastError())); + _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString()); } @@ -629,12 +643,13 @@ show_printer(http_t *http, /* I - HTTP connection to server */ static void usage(void) { - _cupsLangPuts(stderr, cupsLangDefault(), - _("Usage: lpq [-P dest] [-l] [+interval]\n")); + _cupsLangPuts(stderr, + _("Usage: lpq [-P dest] [-U username] [-h hostname[:port]] " + "[-l] [+interval]\n")); exit(1); } /* - * End of "$Id: lpq.c 4906 2006-01-10 20:53:28Z mike $". + * End of "$Id: lpq.c 4948 2006-01-19 03:23:41Z mike $". */ diff --git a/berkeley/lpr.c b/berkeley/lpr.c index 58c9202f4..c909892e3 100644 --- a/berkeley/lpr.c +++ b/berkeley/lpr.c @@ -1,5 +1,5 @@ /* - * "$Id: lpr.c 4906 2006-01-10 20:53:28Z mike $" + * "$Id: lpr.c 4974 2006-01-25 07:04:33Z mike $" * * "lpr" command for the Common UNIX Printing System (CUPS). * @@ -64,31 +64,33 @@ char tempfile[1024]; /* Temporary file for printing from stdin */ */ int -main(int argc, /* I - Number of command-line arguments */ - char *argv[]) /* I - Command-line arguments */ +main(int argc, /* I - Number of command-line arguments */ + char *argv[]) /* I - Command-line arguments */ { - int i, j; /* Looping var */ - int job_id; /* Job ID */ - char ch; /* Option character */ - char *printer, /* Destination printer or class */ - *instance; /* Instance */ - const char *title, /* Job title */ - *val; /* Environment variable name */ - int num_copies; /* Number of copies per file */ - int num_files; /* Number of files to print */ - const char *files[1000]; /* Files to print */ - int num_dests; /* Number of destinations */ - cups_dest_t *dests, /* Destinations */ - *dest; /* Selected destination */ - int num_options; /* Number of options */ - cups_option_t *options; /* Options */ - int deletefile; /* Delete file after print? */ - char buffer[8192]; /* Copy buffer */ - int temp; /* Temporary file descriptor */ - cups_lang_t *language; /* Language information */ + int i, j; /* Looping var */ + int job_id; /* Job ID */ + char ch; /* Option character */ + char *printer, /* Destination printer or class */ + *instance; /* Instance */ + const char *title, /* Job title */ + *val; /* Environment variable name */ + int num_copies; /* Number of copies per file */ + int num_files; /* Number of files to print */ + const char *files[1000]; /* Files to print */ + int num_dests; /* Number of destinations */ + cups_dest_t *dests, /* Destinations */ + *dest; /* Selected destination */ + int num_options; /* Number of options */ + cups_option_t *options; /* Options */ + int deletefile; /* Delete file after print? */ + char buffer[8192]; /* Copy buffer */ + ssize_t bytes; /* Bytes copied */ + off_t filesize; /* Size of temp file */ + int temp; /* Temporary file descriptor */ + cups_lang_t *language; /* Language information */ #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) - struct sigaction action; /* Signal action */ - struct sigaction oldaction; /* Old signal action */ + struct sigaction action; /* Signal action */ + struct sigaction oldaction; /* Old signal action */ #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ @@ -110,12 +112,51 @@ main(int argc, /* I - Number of command-line arguments */ #ifdef HAVE_SSL cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); #else - _cupsLangPrintf(stderr, language, + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support compiled in!\n"), argv[0]); #endif /* HAVE_SSL */ break; + case 'U' : /* Username */ + if (argv[i][2] != '\0') + cupsSetUser(argv[i] + 2); + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, + _("%s: Error - expected username after " + "\'-U\' option!\n"), + argv[0]); + return (1); + } + + cupsSetUser(argv[i]); + } + break; + + case 'H' : /* Connect to host */ + if (argv[i][2] != '\0') + cupsSetServer(argv[i] + 2); + else + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, + _("%s: Error - expected hostname after " + "\'-H\' option!\n"), + 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 */ @@ -128,9 +169,9 @@ main(int argc, /* I - Number of command-line arguments */ if (i >= argc) { - _cupsLangPrintf(stderr, language, - _("lpr: error - expected value after -%c " - "option!\n"), ch); + _cupsLangPrintf(stderr, + _("%s: Error - expected value after \'-%c\' " + "option!\n"), argv[0], ch); return (1); } } @@ -142,9 +183,10 @@ main(int argc, /* I - Number of command-line arguments */ case 'n' : /* Ditroff */ case 't' : /* Troff */ case 'v' : /* Raster image */ - _cupsLangPrintf(stderr, language, - _("lpr: warning - \'%c\' format modifier not " - "supported - output may not be correct!\n"), ch); + _cupsLangPrintf(stderr, + _("%s: Warning - \'%c\' format modifier not " + "supported - output may not be correct!\n"), + argv[0], ch); break; case 'o' : /* Option */ @@ -155,9 +197,10 @@ main(int argc, /* I - Number of command-line arguments */ i ++; if (i >= argc) { - _cupsLangPuts(stderr, language, - _("lpr: error - expected option=value after " - "-o option!\n")); + _cupsLangPrintf(stderr, + _("%s: error - expected option=value after " + "\'-o\' option!\n"), + argv[0]); return (1); } @@ -170,20 +213,28 @@ main(int argc, /* I - Number of command-line arguments */ break; case 'p' : /* Prettyprint */ - num_options = cupsAddOption("prettyprint", "", num_options, &options); + num_options = cupsAddOption("prettyprint", "", num_options, + &options); break; case 'h' : /* Suppress burst page */ - num_options = cupsAddOption("job-sheets", "none", num_options, &options); + num_options = cupsAddOption("job-sheets", "none", num_options, + &options); break; case 's' : /* Don't use symlinks */ break; case 'm' : /* Mail on completion */ - _cupsLangPuts(stderr, language, - _("lpr: warning - email notification is not " - "currently supported!\n")); + { + char email[1024]; /* EMail address */ + + + snprintf(email, sizeof(email), "mailto:%s@%s", cupsUser(), + httpGetHostname(buffer, sizeof(buffer))); + num_options = cupsAddOption("notify-recipient", email, + num_options, &options); + } break; case 'q' : /* Queue file but don't print */ @@ -203,9 +254,10 @@ main(int argc, /* I - Number of command-line arguments */ i ++; if (i >= argc) { - _cupsLangPuts(stderr, language, - _("lpr: error - expected destination after -P " - "option!\n")); + _cupsLangPrintf(stderr, + _("%s: Error - expected destination after " + "\'-P\' option!\n"), + argv[0]); return (1); } @@ -221,7 +273,8 @@ main(int argc, /* I - Number of command-line arguments */ if ((dest = cupsGetDest(printer, instance, num_dests, dests)) != NULL) { 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); @@ -236,9 +289,10 @@ main(int argc, /* I - Number of command-line arguments */ i ++; if (i >= argc) { - _cupsLangPuts(stderr, language, - _("lpr: error - expected copy count after -# " - "option!\n")); + _cupsLangPrintf(stderr, + _("%s: Error - expected copy count after " + "\'-#\' option!\n"), + argv[0]); return (1); } @@ -259,9 +313,9 @@ main(int argc, /* I - Number of command-line arguments */ i ++; if (i >= argc) { - _cupsLangPrintf(stderr, language, - _("lpr: error - expected name after -%c " - "option!\n"), ch); + _cupsLangPrintf(stderr, + _("%s: Error - expected name after \'-%c\' " + "option!\n"), argv[0], ch); return (1); } @@ -269,28 +323,10 @@ main(int argc, /* I - Number of command-line arguments */ } break; - case 'U' : /* User */ - if (argv[i][2] != '\0') - cupsSetUser(argv[i] + 2); - else - { - i ++; - if (i >= argc) - { - _cupsLangPuts(stderr, language, - _("lpr: error - expected username after -U " - "option!\n")); - return (1); - } - - cupsSetUser(argv[i]); - } - break; - default : - _cupsLangPrintf(stderr, language, - _("lpr: error - unknown option \'%c\'!\n"), - argv[i][1]); + _cupsLangPrintf(stderr, + _("%s: Error - unknown option \'%c\'!\n"), + argv[0], argv[i][1]); return (1); } else if (num_files < 1000) @@ -301,9 +337,9 @@ main(int argc, /* I - Number of command-line arguments */ if (access(argv[i], R_OK) != 0) { - _cupsLangPrintf(stderr, language, - _("lpr: error - unable to access \"%s\" - %s\n"), - argv[i], strerror(errno)); + _cupsLangPrintf(stderr, + _("%s: Error - unable to access \"%s\" - %s\n"), + argv[0], argv[i], strerror(errno)); return (1); } @@ -319,8 +355,9 @@ main(int argc, /* I - Number of command-line arguments */ } } else - _cupsLangPrintf(stderr, language, - _("lpr: error - too many files - \"%s\"\n"), argv[i]); + _cupsLangPrintf(stderr, + _("%s: Error - too many files - \"%s\"\n"), + argv[0], argv[i]); /* * See if we have any files to print; if not, print from stdin... */ @@ -360,16 +397,18 @@ main(int argc, /* I - Number of command-line arguments */ val = "LPDEST"; if (printer && !cupsGetDest(printer, NULL, num_dests, dests)) - _cupsLangPrintf(stderr, language, - _("lpr: error - %s environment variable names " + _cupsLangPrintf(stderr, + _("%s: Error - %s environment variable names " "non-existent destination \"%s\"!\n"), - val, printer); + argv[0], val, printer); else if (cupsLastError() == IPP_NOT_FOUND) - _cupsLangPuts(stderr, language, - _("lpr: error - no default destination available.\n")); + _cupsLangPrintf(stderr, + _("%s: Error - no default destination available.\n"), + argv[0]); else - _cupsLangPuts(stderr, language, - _("lpr: error - scheduler not responding!\n")); + _cupsLangPrintf(stderr, + _("%s: Error - scheduler not responding!\n"), + argv[0]); return (1); } @@ -417,32 +456,33 @@ main(int argc, /* I - Number of command-line arguments */ if ((temp = cupsTempFd(tempfile, sizeof(tempfile))) < 0) { - _cupsLangPrintf(stderr, language, - _("lpr: error - unable to create temporary file " + _cupsLangPrintf(stderr, + _("%s: Error - unable to create temporary file " "\"%s\" - %s\n"), - tempfile, strerror(errno)); + argv[0], tempfile, strerror(errno)); return (1); } - while ((i = read(0, buffer, sizeof(buffer))) > 0) - if (write(temp, buffer, i) < 0) + while ((bytes = read(0, buffer, sizeof(buffer))) > 0) + if (write(temp, buffer, bytes) < 0) { - _cupsLangPrintf(stderr, language, - _("lpr: error - unable to write to temporary file " + _cupsLangPrintf(stderr, + _("%s: Error - unable to write to temporary file " "\"%s\" - %s\n"), - tempfile, strerror(errno)); + argv[0], tempfile, strerror(errno)); close(temp); unlink(tempfile); return (1); } - i = lseek(temp, 0, SEEK_CUR); + filesize = lseek(temp, 0, SEEK_CUR); close(temp); - if (i == 0) + if (filesize <= 0) { - _cupsLangPuts(stderr, language, - _("lpr: error - stdin is empty, so no job has been sent.\n")); + _cupsLangPrintf(stderr, + _("%s: Error - stdin is empty, so no job has been sent.\n"), + argv[0]); unlink(tempfile); return (1); } @@ -457,9 +497,7 @@ main(int argc, /* I - Number of command-line arguments */ if (job_id < 1) { - _cupsLangPrintf(stderr, language, - _("lpr: error - unable to print file: %s\n"), - ippErrorString(cupsLastError())); + _cupsLangPrintf(stderr, "%s: %s\n", argv[0], cupsLastErrorString()); return (1); } @@ -473,7 +511,7 @@ main(int argc, /* I - Number of command-line arguments */ */ void -sighandler(int s) /* I - Signal number */ +sighandler(int s) /* I - Signal number */ { /* * Remove the temporary file we're using to print from stdin... @@ -491,5 +529,5 @@ sighandler(int s) /* I - Signal number */ /* - * End of "$Id: lpr.c 4906 2006-01-10 20:53:28Z mike $". + * End of "$Id: lpr.c 4974 2006-01-25 07:04:33Z mike $". */ diff --git a/berkeley/lprm.c b/berkeley/lprm.c index f6fe9fc6b..8497ff532 100644 --- a/berkeley/lprm.c +++ b/berkeley/lprm.c @@ -1,5 +1,5 @@ /* - * "$Id: lprm.c 4906 2006-01-10 20:53:28Z mike $" + * "$Id: lprm.c 4948 2006-01-19 03:23:41Z mike $" * * "lprm" command for the Common UNIX Printing System (CUPS). * @@ -84,7 +84,7 @@ main(int argc, /* I - Number of command-line arguments */ if ((http = httpConnectEncrypt(cupsServer(), ippPort(), encryption)) == NULL) { - _cupsLangPuts(stderr, language, _("lprm: Unable to contact server!\n")); + _cupsLangPuts(stderr, _("lprm: Unable to contact server!\n")); cupsFreeDests(num_dests, dests); return (1); } @@ -103,7 +103,7 @@ main(int argc, /* I - Number of command-line arguments */ httpEncryption(http, encryption); #else - _cupsLangPrintf(stderr, language, + _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support compiled in!\n"), argv[0]); #endif /* HAVE_SSL */ @@ -123,17 +123,61 @@ main(int argc, /* I - Number of command-line arguments */ if (cupsGetDest(dest, NULL, num_dests, dests) == NULL) { - _cupsLangPrintf(stderr, language, - _("lprm: Unknown destination \"%s\"!\n"), dest); + _cupsLangPrintf(stderr, + _("%s: Error - unknown destination \"%s\"!\n"), + argv[0], dest); cupsFreeDests(num_dests, dests); httpClose(http); return(1); } break; + case 'U' : /* Username */ + if (argv[i][2] != '\0') + cupsSetUser(argv[i] + 2); + else + { + i ++; + if (i >= argc) + { + _cupsLangPrintf(stderr, + _("%s: Error - expected username after " + "\'-U\' option!\n"), + argv[0]); + return (1); + } + + cupsSetUser(argv[i]); + } + break; + + case 'h' : /* Connect to host */ + if (http != NULL) + httpClose(http); + + if (argv[i][2] != '\0') + cupsSetServer(argv[i] + 2); + else + { + i ++; + + if (i >= argc) + { + _cupsLangPrintf(stderr, + _("%s: Error - expected hostname after " + "\'-h\' option!\n"), + argv[0]); + return (1); + } + else + cupsSetServer(argv[i]); + } + break; + default : - _cupsLangPrintf(stderr, language, - _("lprm: Unknown option \'%c\'!\n"), argv[i][1]); + _cupsLangPrintf(stderr, + _("%s: Error - unknown option \'%c\'!\n"), + argv[0], argv[i][1]); cupsFreeDests(num_dests, dests); httpClose(http); return (1); @@ -151,7 +195,7 @@ main(int argc, /* I - Number of command-line arguments */ op = IPP_CANCEL_JOB; job_id = atoi(argv[i]); } - else if (strcmp(argv[i], "-") == 0) + else if (!strcmp(argv[i], "-")) { /* * Cancel all jobs @@ -175,16 +219,7 @@ main(int argc, /* I - Number of command-line arguments */ * [requesting-user-name] */ - request = ippNew(); - - request->request.op.operation_id = op; - request->request.op.request_id = 1; - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, - "attributes-charset", NULL, cupsLangEncoding(language)); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, - "attributes-natural-language", NULL, language->language); + request = ippNewRequest(op); if (dest) { @@ -214,43 +249,12 @@ main(int argc, /* I - Number of command-line arguments */ else response = cupsDoRequest(http, request, "/jobs/"); - if (response != NULL) - { - switch (response->request.status.status_code) - { - case IPP_NOT_FOUND : - _cupsLangPuts(stderr, language, - _("lprm: Job or printer not found!\n")); - break; - case IPP_NOT_AUTHORIZED : - _cupsLangPuts(stderr, language, - _("lprm: Not authorized to lprm job(s)!\n")); - break; - case IPP_FORBIDDEN : - _cupsLangPrintf(stderr, language, - _("lprm: You don't own job ID %d!\n"), job_id); - break; - default : - if (response->request.status.status_code > IPP_OK_CONFLICT) - _cupsLangPuts(stderr, language, - _("lprm: Unable to lprm job(s)!\n")); - break; - } - - if (response->request.status.status_code > IPP_OK_CONFLICT) - { - ippDelete(response); - cupsFreeDests(num_dests, dests); - httpClose(http); - return (1); - } - - ippDelete(response); - } - else + ippDelete(response); + + if (cupsLastError() > IPP_OK_CONFLICT) { - _cupsLangPuts(stderr, language, - _("lprm: Unable to cancel job(s)!\n")); + _cupsLangPrintf(stderr, "%s: %s\n", argv[0], cupsLastErrorString()); + cupsFreeDests(num_dests, dests); httpClose(http); return (1); @@ -265,8 +269,7 @@ main(int argc, /* I - Number of command-line arguments */ if (response == NULL) if (!cupsCancelJob(dest, 0)) { - _cupsLangPuts(stderr, language, - _("lprm: Unable to cancel job(s)!\n")); + _cupsLangPrintf(stderr, "%s: %s\n", argv[0], cupsLastErrorString()); cupsFreeDests(num_dests, dests); httpClose(http); return (1); @@ -280,5 +283,5 @@ main(int argc, /* I - Number of command-line arguments */ /* - * End of "$Id: lprm.c 4906 2006-01-10 20:53:28Z mike $". + * End of "$Id: lprm.c 4948 2006-01-19 03:23:41Z mike $". */ |