]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - berkeley/lpq.c
Update svn:keyword properties.
[thirdparty/cups.git] / berkeley / lpq.c
index 43f01c6203a5f697cd926cfa7ca1a8f5f0e2f6a1..dcce2c0ed952edd8c78be16ea9c58432b8e07983 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: lpq.c 5638 2006-06-06 20:08:13Z mike $"
+ * "$Id$"
  *
- *   "lpq" command for the Common UNIX Printing System (CUPS).
+ *   "lpq" command for CUPS.
  *
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   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:
  *
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/string.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
-#include <cups/debug.h>
+#include <cups/cups-private.h>
 
 
 /*
@@ -53,7 +39,7 @@ static http_t *connect_server(const char *, http_t *);
 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);
+static void    usage(void) __attribute__((noreturn));
 
 
 /*
@@ -76,9 +62,10 @@ main(int  argc,                              /* I - Number of command-line arguments */
                longstatus;             /* Show file details */
   int          num_dests;              /* Number of destinations */
   cups_dest_t  *dests;                 /* Destinations */
-  cups_lang_t  *language;              /* Language */
 
 
+  _cupsSetLocale(argv);
+
  /*
   * Check for command-line options...
   */
@@ -90,8 +77,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
   interval   = 0;
   longstatus = 0;
   all        = 0;
-  language   = cupsLangDefault();
   num_dests  = 0;
+  dests      = NULL;
 
   for (i = 1; i < argc; i ++)
     if (argv[i][0] == '+')
@@ -107,8 +94,7 @@ main(int  argc,                              /* I - Number of command-line arguments */
            if (http)
              httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
 #else
-            _cupsLangPrintf(stderr,
-                           _("%s: Sorry, no encryption support compiled in!\n"),
+            _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."),
                            argv[0]);
 #endif /* HAVE_SSL */
            break;
@@ -123,15 +109,14 @@ main(int  argc,                           /* I - Number of command-line arguments */
              {
                _cupsLangPrintf(stderr,
                                _("%s: Error - expected username after "
-                                 "\'-U\' option!\n"),
-                               argv[0]);
+                                 "\"-U\" option."), argv[0]);
                return (1);
              }
 
               cupsSetUser(argv[i]);
            }
            break;
-           
+
         case 'P' : /* Printer */
            if (argv[i][2])
              dest = argv[i] + 2;
@@ -143,7 +128,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
              {
                httpClose(http);
                cupsFreeDests(num_dests, dests);
-               
+
                usage();
              }
 
@@ -162,11 +147,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
            {
              if (instance)
                _cupsLangPrintf(stderr,
-                               _("%s: Error - unknown destination \"%s/%s\"!\n"),
+                               _("%s: Error - unknown destination \"%s/%s\"."),
                                argv[0], dest, instance);
               else
-               _cupsLangPrintf(stderr,
-                               _("%s: Unknown destination \"%s\"!\n"),
+               _cupsLangPrintf(stderr, _("%s: Unknown destination \"%s\"."),
                                argv[0], dest);
 
              return (1);
@@ -194,8 +178,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
              {
                _cupsLangPrintf(stderr,
                                _("%s: Error - expected hostname after "
-                                 "\'-h\' option!\n"),
-                               argv[0]);
+                                 "\"-h\" option."), argv[0]);
                return (1);
               }
              else
@@ -250,12 +233,12 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
       if (dest && !cupsGetDest(dest, NULL, num_dests, dests))
        _cupsLangPrintf(stderr,
-                       _("%s: error - %s environment variable names "
-                         "non-existent destination \"%s\"!\n"),
-                       argv[0], val, dest);
+                       _("%s: Error - %s environment variable names "
+                         "non-existent destination \"%s\"."), argv[0], val,
+                       dest);
       else
        _cupsLangPrintf(stderr,
-                       _("%s: error - no default destination available.\n"),
+                       _("%s: Error - no default destination available."),
                        argv[0]);
       httpClose(http);
       cupsFreeDests(num_dests, dests);
@@ -309,7 +292,7 @@ connect_server(const char *command, /* I - Command name */
 
     if (http == NULL)
     {
-      _cupsLangPrintf(stderr, _("%s: Unable to connect to server\n"), command);
+      _cupsLangPrintf(stderr, _("%s: Unable to connect to server."), command);
       exit(1);
     }
   }
@@ -348,7 +331,18 @@ show_jobs(const char *command,             /* I - Command name */
   char         resource[1024];         /* Resource string */
   char         rankstr[255];           /* Rank string */
   char         namestr[1024];          /* Job name string */
-  static const char *ranks[10] =       /* Ranking strings */
+  static const char * const jobattrs[] =/* Job attributes we want to see */
+               {
+                 "copies",
+                 "job-id",
+                 "job-k-octets",
+                 "job-name",
+                 "job-originating-user-name",
+                 "job-printer-uri",
+                 "job-priority",
+                 "job-state"
+               };
+  static const char * const ranks[10] =        /* Ranking strings */
                {
                  "th",
                  "st",
@@ -363,8 +357,8 @@ show_jobs(const char *command,              /* I - Command name */
                };
 
 
-  DEBUG_printf(("show_jobs(%08x, %08x, %08x, %d, %d)\n", http, dest, user, id,
-                longstatus));
+  DEBUG_printf(("show_jobs(http=%p, dest=%p, user=%p, id=%d, longstatus%d)\n",
+                http, dest, user, id, longstatus));
 
   if (http == NULL)
     return (0);
@@ -376,21 +370,19 @@ show_jobs(const char *command,            /* I - Command name */
   *    attributes-charset
   *    attributes-natural-language
   *    job-uri or printer-uri
+  *    requested-attributes
+  *    requesting-user-name
   */
 
   request = ippNewRequest(id ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS);
 
-  if (dest == NULL)
+  if (id)
   {
-    if (id)
-      sprintf(resource, "ipp://localhost/jobs/%d", id);
-    else
-      strcpy(resource, "ipp://localhost/jobs");
-
+    snprintf(resource, sizeof(resource), "ipp://localhost/jobs/%d", id);
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
                  NULL, resource);
   }
-  else
+  else if (dest)
   {
     httpAssembleURIf(HTTP_URI_CODING_ALL, resource, sizeof(resource), "ipp",
                      NULL, "localhost", 0, "/printers/%s", dest);
@@ -398,6 +390,9 @@ show_jobs(const char *command,              /* I - Command name */
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                  NULL, resource);
   }
+  else
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+                 NULL, "ipp://localhost/");
 
   if (user)
   {
@@ -405,6 +400,13 @@ show_jobs(const char *command,             /* I - Command name */
                  "requesting-user-name", NULL, user);
     ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
   }
+  else
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+                 "requesting-user-name", NULL, cupsUser());
+
+  ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+                "requested-attributes",
+                (int)(sizeof(jobattrs) / sizeof(jobattrs[0])), NULL, jobattrs);
 
  /*
   * Do the request and get back a response...
@@ -416,7 +418,7 @@ show_jobs(const char *command,              /* I - Command name */
   {
     if (response->request.status.status_code > IPP_OK_CONFLICT)
     {
-      _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString());
+      _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
       ippDelete(response);
       return (0);
     }
@@ -449,8 +451,8 @@ show_jobs(const char *command,              /* I - Command name */
       jobpriority = 50;
 #endif /* __osf__ */
       jobstate    = IPP_JOB_PENDING;
-      jobname     = "untitled";
-      jobuser     = NULL;
+      jobname     = "unknown";
+      jobuser     = "unknown";
       jobdest     = NULL;
       jobcopies   = 1;
 
@@ -509,12 +511,13 @@ show_jobs(const char *command,            /* I - Command name */
       if (!longstatus && jobcount == 0)
 #ifdef __osf__
        _cupsLangPuts(stdout,
+                     /* TRANSLATORS: Pri is job priority. */
                      _("Rank   Owner      Pri  Job        Files"
-                       "                       Total Size\n"));
+                       "                       Total Size"));
 #else
        _cupsLangPuts(stdout,
                      _("Rank    Owner   Job     File(s)"
-                       "                         Total Size\n"));
+                       "                         Total Size"));
 #endif /* __osf__ */
 
       jobcount ++;
@@ -524,7 +527,7 @@ show_jobs(const char *command,              /* I - Command name */
       */
 
       if (jobstate == IPP_JOB_PROCESSING)
-       strcpy(rankstr, "active");
+       strlcpy(rankstr, "active", sizeof(rankstr));
       else
       {
        /*
@@ -550,20 +553,20 @@ show_jobs(const char *command,            /* I - Command name */
        else
          strlcpy(namestr, jobname, sizeof(namestr));
 
-        _cupsLangPrintf(stdout, _("%s: %-33.33s [job %d localhost]\n"),
+        _cupsLangPrintf(stdout, _("%s: %-33.33s [job %d localhost]"),
                        jobuser, rankstr, jobid);
-        _cupsLangPrintf(stdout, _("        %-39.39s %.0f bytes\n"),
+        _cupsLangPrintf(stdout, _("        %-39.39s %.0f bytes"),
                        namestr, 1024.0 * jobsize);
       }
       else
 #ifdef __osf__
         _cupsLangPrintf(stdout,
-                       _("%-6s %-10.10s %-4d %-10d %-27.27s %.0f bytes\n"),
+                       _("%-6s %-10.10s %-4d %-10d %-27.27s %.0f bytes"),
                        rankstr, jobuser, jobpriority, jobid, jobname,
                        1024.0 * jobsize);
 #else
         _cupsLangPrintf(stdout,
-                       _("%-7s %-7.7s %-7d %-31.31s %.0f bytes\n"),
+                       _("%-7s %-7.7s %-7d %-31.31s %.0f bytes"),
                        rankstr, jobuser, jobid, jobname, 1024.0 * jobsize);
 #endif /* __osf */
 
@@ -575,12 +578,12 @@ show_jobs(const char *command,            /* I - Command name */
   }
   else
   {
-    _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString());
+    _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
     return (0);
   }
 
   if (jobcount == 0)
-    _cupsLangPuts(stdout, _("no entries\n"));
+    _cupsLangPuts(stdout, _("no entries"));
 
   return (jobcount);
 }
@@ -629,7 +632,7 @@ show_printer(const char *command,   /* I - Command name */
   {
     if (response->request.status.status_code > IPP_OK_CONFLICT)
     {
-      _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString());
+      _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
       ippDelete(response);
       return;
     }
@@ -642,21 +645,21 @@ show_printer(const char *command, /* I - Command name */
     switch (state)
     {
       case IPP_PRINTER_IDLE :
-          _cupsLangPrintf(stdout, _("%s is ready\n"), dest);
+          _cupsLangPrintf(stdout, _("%s is ready"), dest);
          break;
       case IPP_PRINTER_PROCESSING :
-          _cupsLangPrintf(stdout, _("%s is ready and printing\n"),
+          _cupsLangPrintf(stdout, _("%s is ready and printing"),
                          dest);
          break;
       case IPP_PRINTER_STOPPED :
-          _cupsLangPrintf(stdout, _("%s is not ready\n"), dest);
+          _cupsLangPrintf(stdout, _("%s is not ready"), dest);
          break;
     }
 
     ippDelete(response);
   }
   else
-    _cupsLangPrintf(stderr, "%s: %s\n", command, cupsLastErrorString());
+    _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
 }
 
 
@@ -669,11 +672,11 @@ usage(void)
 {
   _cupsLangPuts(stderr,
                 _("Usage: lpq [-P dest] [-U username] [-h hostname[:port]] "
-                 "[-l] [+interval]\n"));
+                 "[-l] [+interval]"));
   exit(1);
 }
 
 
 /*
- * End of "$Id: lpq.c 5638 2006-06-06 20:08:13Z mike $".
+ * End of "$Id$".
  */