]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpstat.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / systemv / lpstat.c
index 4dde8ad10898740f253fab50236161113a3b402d..96d4acc85756a0bb129888c5e0d874ef3285587c 100644 (file)
@@ -1,30 +1,10 @@
 /*
- * "$Id$"
+ * "lpstat" command for CUPS.
  *
- *   "lpstat" command for CUPS.
+ * Copyright 2007-2017 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2013 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- *   main()           - Parse options and show status information.
- *   check_dest()     - Verify that the named destination(s) exists.
- *   match_list()     - Match a name from a list of comma or space-separated
- *                      names.
- *   show_accepting() - Show acceptance status.
- *   show_classes()   - Show printer classes.
- *   show_default()   - Show default destination.
- *   show_devices()   - Show printer devices.
- *   show_jobs()      - Show active print jobs.
- *   show_printers()  - Show printers.
- *   show_scheduler() - Show scheduler status.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -64,6 +44,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? */
@@ -87,395 +68,429 @@ 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 (*opt)
+       {
+         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';
+             show_default(dests);
+             break;
 
-           if (argv[i][2])
-           {
-              check_dest(argv[0], argv[i] + 2, &num_dests, &dests);
+         case 'e' : /* List destinations */
+             {
+                cups_dest_t *temp = NULL, *dest;
+                int j, num_temp = cupsGetDests(&temp);
+
+                op = 'e';
+
+                for (j = num_temp, dest = temp; j > 0; j --, dest ++)
+                {
+                  if (dest->instance)
+                    printf("%s/%s", dest->name, dest->instance);
+                  else
+                    fputs(dest->name, stdout);
+
+                  if (long_status)
+                  {
+                    const char *printer_uri_supported = cupsGetOption("printer-uri-supported", dest->num_options, dest->options);
+                    const char *printer_is_temporary = cupsGetOption("printer-is-temporary", dest->num_options, dest->options);
+                    const char *type = "network";
+
+                    if (printer_is_temporary && !strcmp(printer_is_temporary, "true"))
+                      type = "temporary";
+                    else if (printer_uri_supported)
+                      type = "permanent";
+
+                    printf(" %s %s %s\n", type, printer_uri_supported ? printer_uri_supported : "none", cupsGetOption("device-uri", dest->num_options, dest->options));
+                  }
+                  else
+                    putchar('\n');
+                }
+
+                cupsFreeDests(num_temp, temp);
+              }
+              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);
@@ -560,7 +575,7 @@ check_dest(const char  *command,    /* I  - Command name */
 
     for (pptr = printer; !isspace(*dptr & 255) && *dptr != ',' && *dptr;)
     {
-      if ((pptr - printer) < (sizeof(printer) - 1))
+      if ((size_t)(pptr - printer) < (sizeof(printer) - 1))
         *pptr++ = *dptr++;
       else
       {
@@ -663,7 +678,6 @@ show_accepting(const char  *printers,       /* I - Destinations */
                *message;               /* Printer device URI */
   int          accepting;              /* Accepting requests? */
   time_t       ptime;                  /* Printer state time */
-  struct tm    *pdate;                 /* Printer state date & time */
   char         printer_state_time[255];/* Printer state time */
   static const char *pattrs[] =                /* Attributes we need for printers... */
                {
@@ -786,8 +800,7 @@ show_accepting(const char  *printers,       /* I - Destinations */
 
       if (match_list(printers, printer))
       {
-        pdate = localtime(&ptime);
-        strftime(printer_state_time, sizeof(printer_state_time), "%c", pdate);
+        _cupsStrDate(printer_state_time, sizeof(printer_state_time), ptime);
 
         if (accepting)
          _cupsLangPrintf(stdout, _("%s accepting requests since %s"),
@@ -1230,52 +1243,6 @@ show_devices(const char  *printers,      /* I - Destinations */
 
       if (match_list(printers, printer))
       {
-#ifdef __osf__ /* Compaq/Digital like to do it their own way... */
-        char   scheme[HTTP_MAX_URI],   /* Components of printer URI */
-               username[HTTP_MAX_URI],
-               hostname[HTTP_MAX_URI],
-               resource[HTTP_MAX_URI];
-       int     port;
-
-
-        if (device == NULL)
-       {
-         httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
-                         username, sizeof(username), hostname,
-                         sizeof(hostname), &port, resource, sizeof(resource));
-          _cupsLangPrintf(stdout,
-                         _("Output for printer %s is sent to remote "
-                           "printer %s on %s"),
-                         printer, strrchr(resource, '/') + 1, hostname);
-        }
-        else if (!strncmp(device, "file:", 5))
-          _cupsLangPrintf(stdout,
-                         _("Output for printer %s is sent to %s"),
-                         printer, device + 5);
-        else
-          _cupsLangPrintf(stdout,
-                         _("Output for printer %s is sent to %s"),
-                         printer, device);
-
-        for (i = 0; i < num_dests; i ++)
-         if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance)
-         {
-            if (device == NULL)
-              _cupsLangPrintf(stdout,
-                             _("Output for printer %s/%s is sent to "
-                               "remote printer %s on %s"),
-                             printer, dests[i].instance,
-                             strrchr(resource, '/') + 1, hostname);
-            else if (!strncmp(device, "file:", 5))
-              _cupsLangPrintf(stdout,
-                             _("Output for printer %s/%s is sent to %s"),
-                             printer, dests[i].instance, device + 5);
-            else
-              _cupsLangPrintf(stdout,
-                             _("Output for printer %s/%s is sent to %s"),
-                             printer, dests[i].instance, device);
-         }
-#else
         if (device == NULL)
           _cupsLangPrintf(stdout, _("device for %s: %s"),
                          printer, uri);
@@ -1287,6 +1254,7 @@ show_devices(const char  *printers,       /* I - Destinations */
                          printer, device);
 
         for (i = 0; i < num_dests; i ++)
+        {
          if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance)
          {
             if (device == NULL)
@@ -1299,7 +1267,7 @@ show_devices(const char  *printers,       /* I - Destinations */
               _cupsLangPrintf(stdout, _("device for %s/%s: %s"),
                              printer, dests[i].instance, device);
          }
-#endif /* __osf__ */
+       }
       }
 
       if (attr == NULL)
@@ -1331,13 +1299,12 @@ show_jobs(const char *dests,            /* I - Destinations */
                *reasons;               /* Job state reasons attribute */
   const char   *dest,                  /* Pointer into job-printer-uri */
                *username,              /* Pointer to job-originating-user-name */
-               *title,                 /* Pointer to job-name */
-               *message;               /* Pointer to job-printer-state-message */
+               *message,               /* Pointer to job-printer-state-message */
+               *time_at;               /* time-at-xxx attribute name to use */
   int          rank,                   /* Rank in queue */
                jobid,                  /* job-id */
                size;                   /* job-k-octets */
   time_t       jobtime;                /* time-at-creation */
-  struct tm    *jobdate;               /* Date & time */
   char         temp[255],              /* Temporary buffer */
                date[255];              /* Date buffer */
   static const char *jattrs[] =                /* Attributes we need for jobs... */
@@ -1349,7 +1316,8 @@ show_jobs(const char *dests,              /* I - Destinations */
                  "job-printer-state-message",
                  "job-printer-uri",
                  "job-state-reasons",
-                 "time-at-creation"
+                 "time-at-creation",
+                 "time-at-completed"
                };
 
 
@@ -1415,6 +1383,13 @@ show_jobs(const char *dests,             /* I - Destinations */
     * Loop through the job list and display them...
     */
 
+    if (!strcmp(which, "aborted") ||
+        !strcmp(which, "canceled") ||
+        !strcmp(which, "completed"))
+      time_at = "time-at-completed";
+    else
+      time_at = "time-at-creation";
+
     rank = -1;
 
     for (attr = response->attrs; attr != NULL; attr = attr->next)
@@ -1438,7 +1413,6 @@ show_jobs(const char *dests,              /* I - Destinations */
       username = NULL;
       dest     = NULL;
       jobtime  = 0;
-      title    = "no title";
       message  = NULL;
       reasons  = NULL;
 
@@ -1450,8 +1424,7 @@ show_jobs(const char *dests,              /* I - Destinations */
         else if (!strcmp(attr->name, "job-k-octets") &&
                 attr->value_tag == IPP_TAG_INTEGER)
          size = attr->values[0].integer;
-        else if (!strcmp(attr->name, "time-at-creation") &&
-                attr->value_tag == IPP_TAG_INTEGER)
+        else if (!strcmp(attr->name, time_at) && attr->value_tag == IPP_TAG_INTEGER)
          jobtime = attr->values[0].integer;
         else if (!strcmp(attr->name, "job-printer-state-message") &&
                 attr->value_tag == IPP_TAG_TEXT)
@@ -1465,9 +1438,6 @@ show_jobs(const char *dests,              /* I - Destinations */
         else if (!strcmp(attr->name, "job-originating-user-name") &&
                 attr->value_tag == IPP_TAG_NAME)
          username = attr->values[0].string.text;
-        else if (!strcmp(attr->name, "job-name") &&
-                attr->value_tag == IPP_TAG_NAME)
-         title = attr->values[0].string.text;
         else if (!strcmp(attr->name, "job-state-reasons") &&
                 attr->value_tag == IPP_TAG_KEYWORD)
          reasons = attr;
@@ -1495,62 +1465,42 @@ show_jobs(const char *dests,            /* I - Destinations */
 
       if (match_list(dests, dest) && match_list(users, username))
       {
-        jobdate = localtime(&jobtime);
         snprintf(temp, sizeof(temp), "%s-%d", dest, jobid);
 
-        if (long_status == 3)
-       {
-        /*
-         * Show the consolidated output format for the SGI tools...
-         */
-
-         if (!strftime(date, sizeof(date), "%b %d %H:%M", jobdate))
-           strlcpy(date, "Unknown", sizeof(date));
+       _cupsStrDate(date, sizeof(date), jobtime);
 
-         _cupsLangPrintf(stdout, "%s;%s;%d;%s;%s",
-                         temp, username ? username : "unknown",
-                         size, title ? title : "unknown", date);
-       }
+       if (ranking)
+         _cupsLangPrintf(stdout, "%3d %-21s %-13s %8.0f %s",
+                         rank, temp, username ? username : "unknown",
+                         1024.0 * size, date);
        else
+         _cupsLangPrintf(stdout, "%-23s %-13s %8.0f   %s",
+                         temp, username ? username : "unknown",
+                         1024.0 * size, date);
+       if (long_status)
        {
-         if (!strftime(date, sizeof(date), "%c", jobdate))
-           strlcpy(date, "Unknown", sizeof(date));
-
-          if (ranking)
-           _cupsLangPrintf(stdout, "%3d %-21s %-13s %8.0f %s",
-                           rank, temp, username ? username : "unknown",
-                           1024.0 * size, date);
-          else
-           _cupsLangPrintf(stdout, "%-23s %-13s %8.0f   %s",
-                           temp, username ? username : "unknown",
-                           1024.0 * size, date);
-          if (long_status)
-          {
-           if (message)
-             _cupsLangPrintf(stdout, _("\tStatus: %s"), message);
-
-           if (reasons)
-           {
-             char      alerts[1024],   /* Alerts string */
-                       *aptr;          /* Pointer into alerts string */
+         if (message)
+           _cupsLangPrintf(stdout, _("\tStatus: %s"), message);
 
-             for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
-             {
-               if (i)
-                 snprintf(aptr, sizeof(alerts) - (aptr - alerts), " %s",
-                          reasons->values[i].string.text);
-                else
-                 strlcpy(alerts, reasons->values[i].string.text,
-                         sizeof(alerts));
-
-               aptr += strlen(aptr);
-             }
+         if (reasons)
+         {
+           char        alerts[1024],   /* Alerts string */
+                     *aptr;            /* Pointer into alerts string */
 
-             _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts);
+           for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
+           {
+             if (i)
+               snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
+             else
+               strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
+
+             aptr += strlen(aptr);
            }
 
-           _cupsLangPrintf(stdout, _("\tqueued for %s"), dest);
+           _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts);
          }
+
+         _cupsLangPrintf(stdout, _("\tqueued for %s"), dest);
        }
       }
 
@@ -1593,7 +1543,6 @@ show_printers(const char  *printers,      /* I - Destinations */
   ipp_pstate_t pstate;                 /* Printer state */
   cups_ptype_t ptype;                  /* Printer type */
   time_t       ptime;                  /* Printer state time */
-  struct tm    *pdate;                 /* Printer state date & time */
   int          jobid;                  /* Job ID of current job */
   char         printer_uri[HTTP_MAX_URI],
                                        /* Printer URI */
@@ -1823,7 +1772,7 @@ show_printers(const char  *printers,      /* I - Destinations */
                jobid = jobattr->values[0].integer;
               else if (!strcmp(jobattr->name, "job-state") &&
                       jobattr->value_tag == IPP_TAG_ENUM)
-               jobstate = jobattr->values[0].integer;
+               jobstate = (ipp_jstate_t)jobattr->values[0].integer;
            }
 
             if (jobstate != IPP_JOB_PROCESSING)
@@ -1837,26 +1786,21 @@ show_printers(const char  *printers,    /* I - Destinations */
         * Display it...
        */
 
-        pdate = localtime(&ptime);
-        strftime(printer_state_time, sizeof(printer_state_time), "%c", pdate);
+        _cupsStrDate(printer_state_time, sizeof(printer_state_time), ptime);
 
         switch (pstate)
        {
          case IPP_PRINTER_IDLE :
-             _cupsLangPrintf(stdout,
-                             _("printer %s is idle.  enabled since %s"),
-                             printer, printer_state_time);
+             if (ippContainsString(reasons, "hold-new-jobs"))
+               _cupsLangPrintf(stdout, _("printer %s is holding new jobs.  enabled since %s"), printer, printer_state_time);
+             else
+               _cupsLangPrintf(stdout, _("printer %s is idle.  enabled since %s"), printer, printer_state_time);
              break;
          case IPP_PRINTER_PROCESSING :
-             _cupsLangPrintf(stdout,
-                             _("printer %s now printing %s-%d.  "
-                               "enabled since %s"),
-                             printer, printer, jobid, printer_state_time);
+             _cupsLangPrintf(stdout, _("printer %s now printing %s-%d.  enabled since %s"), printer, printer, jobid, printer_state_time);
              break;
          case IPP_PRINTER_STOPPED :
-             _cupsLangPrintf(stdout,
-                             _("printer %s disabled since %s -"),
-                             printer, printer_state_time);
+             _cupsLangPrintf(stdout, _("printer %s disabled since %s -"), printer, printer_state_time);
              break;
        }
 
@@ -1888,11 +1832,9 @@ show_printers(const char  *printers,     /* I - Destinations */
            for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
            {
              if (i)
-               snprintf(aptr, sizeof(alerts) - (aptr - alerts), " %s",
-                        reasons->values[i].string.text);
+               snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
              else
-               strlcpy(alerts, reasons->values[i].string.text,
-                       sizeof(alerts));
+               strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
 
              aptr += strlen(aptr);
            }
@@ -1918,11 +1860,7 @@ show_printers(const char  *printers,     /* I - Destinations */
          {
            _cupsLangPuts(stdout, _("\tConnection: direct"));
 
-           if (make_model && strstr(make_model, "System V Printer"))
-             _cupsLangPrintf(stdout,
-                             _("\tInterface: %s/interfaces/%s"),
-                             cg->cups_serverroot, printer);
-           else if (make_model && !strstr(make_model, "Raw Printer"))
+           if (make_model && !strstr(make_model, "Raw Printer"))
              _cupsLangPrintf(stdout,
                              _("\tInterface: %s/ppd/%s.ppd"),
                              cg->cups_serverroot, printer);
@@ -2014,11 +1952,9 @@ show_printers(const char  *printers,     /* I - Destinations */
                for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
                {
                  if (i)
-                   snprintf(aptr, sizeof(alerts) - (aptr - alerts), " %s",
-                            reasons->values[i].string.text);
+                   snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
                  else
-                   strlcpy(alerts, reasons->values[i].string.text,
-                           sizeof(alerts));
+                   strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
 
                  aptr += strlen(aptr);
                }
@@ -2043,11 +1979,7 @@ show_printers(const char  *printers,     /* I - Destinations */
              {
                _cupsLangPuts(stdout, _("\tConnection: direct"));
 
-               if (make_model && strstr(make_model, "System V Printer"))
-                 _cupsLangPrintf(stdout,
-                                 _("\tInterface: %s/interfaces/%s"),
-                                 cg->cups_serverroot, printer);
-               else if (make_model && !strstr(make_model, "Raw Printer"))
+               if (make_model && !strstr(make_model, "Raw Printer"))
                  _cupsLangPrintf(stdout,
                                  _("\tInterface: %s/ppd/%s.ppd"),
                                  cg->cups_serverroot, printer);
@@ -2116,8 +2048,3 @@ show_scheduler(void)
   else
     _cupsLangPuts(stdout, _("scheduler is not running"));
 }
-
-
-/*
- * End of "$Id$".
- */