]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - berkeley/lpq.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / berkeley / lpq.c
index 9356fc1f3de32cf3fa490878cf1a849424c2926d..fb6d12139e4e3baf2bd21803324a897b6d024f35 100644 (file)
@@ -1,27 +1,14 @@
 /*
- * "$Id: lpq.c 7460 2008-04-16 02:19:54Z mike $"
+ * "lpq" command for CUPS.
  *
- *   "lpq" command for CUPS.
+ * Copyright 2007-2016 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2012 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 commands.
- *   show_jobs()    - Show jobs.
- *   show_printer() - Show printer status.
- *   usage()        - Show program usage.
- */
-
-/*
- * Include necessary headers...
+ * 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
+ * missing or damaged, see the license at "http://www.cups.org/".
  */
 
 /*
@@ -52,7 +39,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
 {
   int          i;                      /* Looping var */
   http_t       *http;                  /* Connection to server */
-  const char   *dest,                  /* Desired printer */
+  const char   *opt,                   /* Option pointer */
+               *dest,                  /* Desired printer */
                *user,                  /* Desired user */
                *val;                   /* Environment variable name */
   char         *instance;              /* Printer instance */
@@ -60,8 +48,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
                all,                    /* All printers */
                interval,               /* Reporting interval */
                longstatus;             /* Show file details */
-  int          num_dests;              /* Number of destinations */
-  cups_dest_t  *dests;                 /* Destinations */
+  cups_dest_t  *named_dest;            /* Named destination */
 
 
   _cupsSetLocale(argv);
@@ -77,145 +64,156 @@ main(int  argc,                           /* I - Number of command-line arguments */
   interval   = 0;
   longstatus = 0;
   all        = 0;
-  num_dests  = 0;
-  dests      = NULL;
 
   for (i = 1; i < argc; i ++)
+  {
     if (argv[i][0] == '+')
+    {
       interval = atoi(argv[i] + 1);
+    }
     else if (argv[i][0] == '-')
     {
-      switch (argv[i][1])
+      for (opt = argv[i] + 1; *opt; opt ++)
       {
-        case 'E' : /* Encrypt */
+       switch (*opt)
+       {
+         case 'E' : /* Encrypt */
 #ifdef HAVE_SSL
-           cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
+             cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
 
-           if (http)
-             httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+             if (http)
+               httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
 #else
-            _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."),
-                           argv[0]);
+             _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]);
 #endif /* HAVE_SSL */
-           break;
-
-        case 'U' : /* Username */
-           if (argv[i][2] != '\0')
-             cupsSetUser(argv[i] + 2);
-           else
-           {
-             i ++;
-             if (i >= argc)
+             break;
+
+         case 'U' : /* Username */
+             if (opt[1] != '\0')
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected username after "
-                                 "\"-U\" option."), argv[0]);
-               return (1);
+               cupsSetUser(opt + 1);
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]);
+                 return (1);
+               }
 
-              cupsSetUser(argv[i]);
-           }
-           break;
-
-        case 'P' : /* Printer */
-           if (argv[i][2])
-             dest = argv[i] + 2;
-           else
-           {
-             i ++;
+               cupsSetUser(argv[i]);
+             }
+             break;
 
-             if (i >= argc)
+         case 'P' : /* Printer */
+             if (opt[1] != '\0')
              {
-               httpClose(http);
-               cupsFreeDests(num_dests, dests);
-
-               usage();
+               dest = opt + 1;
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             dest = argv[i];
-           }
+               if (i >= argc)
+               {
+                 httpClose(http);
 
-           if ((instance = strchr(dest, '/')) != NULL)
-             *instance++ = '\0';
+                 usage();
+               }
 
-            http = connect_server(argv[0], http);
+               dest = argv[i];
+             }
 
-            if (num_dests == 0)
-              num_dests = cupsGetDests2(http, &dests);
+             if ((instance = strchr(dest, '/')) != NULL)
+               *instance++ = '\0';
 
-            if (cupsGetDest(dest, instance, num_dests, dests) == NULL)
-           {
-             if (instance)
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - unknown destination \"%s/%s\"."),
-                               argv[0], dest, instance);
-              else
-               _cupsLangPrintf(stderr, _("%s: Unknown destination \"%s\"."),
-                               argv[0], dest);
+             http = connect_server(argv[0], http);
 
-             return (1);
-           }
-           break;
+             if ((named_dest = cupsGetNamedDest(http, dest, instance)) == NULL)
+             {
+               if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+                   cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+                 _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]);
+               else if (instance)
+                 _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s/%s\"."), argv[0], dest, instance);
+               else
+                 _cupsLangPrintf(stderr, _("%s: Unknown destination \"%s\"."), argv[0], dest);
 
-       case 'a' : /* All printers */
-           all = 1;
-           break;
+               return (1);
+             }
 
-        case 'h' : /* Connect to host */
-           if (http)
-           {
-             httpClose(http);
-             http = NULL;
-           }
+             cupsFreeDests(1, named_dest);
+             break;
 
-           if (argv[i][2] != '\0')
-              cupsSetServer(argv[i] + 2);
-           else
-           {
-             i ++;
+         case 'a' : /* All printers */
+             all = 1;
+             break;
 
-             if (i >= argc)
+         case 'h' : /* Connect to host */
+             if (http)
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected hostname after "
-                                 "\"-h\" option."), argv[0]);
-               return (1);
-              }
+               httpClose(http);
+               http = NULL;
+             }
+
+             if (opt[1] != '\0')
+             {
+               cupsSetServer(opt + 1);
+               opt += strlen(opt) - 1;
+             }
              else
-                cupsSetServer(argv[i]);
-           }
-           break;
+             {
+               i ++;
+
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]);
+                 return (1);
+               }
+               else
+                 cupsSetServer(argv[i]);
+             }
+             break;
 
-       case 'l' : /* Long status */
-           longstatus = 1;
-           break;
+         case 'l' : /* Long status */
+             longstatus = 1;
+             break;
 
-       default :
-           httpClose(http);
-           cupsFreeDests(num_dests, dests);
+         default :
+             httpClose(http);
 
-           usage();
-           break;
+             usage();
+       }
       }
     }
     else if (isdigit(argv[i][0] & 255))
+    {
       id = atoi(argv[i]);
+    }
     else
+    {
       user = argv[i];
+    }
+  }
 
   http = connect_server(argv[0], http);
 
   if (dest == NULL && !all)
   {
-    if (num_dests == 0)
-      num_dests = cupsGetDests2(http, &dests);
-
-    for (i = 0; i < num_dests; i ++)
-      if (dests[i].is_default)
-       dest = dests[i].name;
-
-    if (dest == NULL)
+    if ((named_dest = cupsGetNamedDest(http, NULL, NULL)) == NULL)
     {
+      if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+          cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+      {
+       _cupsLangPrintf(stderr,
+                       _("%s: Error - add '/version=1.1' to server name."),
+                       argv[0]);
+        return (1);
+      }
+
       val = NULL;
 
       if ((dest = getenv("LPDEST")) == NULL)
@@ -231,7 +229,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       else
        val = "LPDEST";
 
-      if (dest && !cupsGetDest(dest, NULL, num_dests, dests))
+      if (dest && val)
        _cupsLangPrintf(stderr,
                        _("%s: Error - %s environment variable names "
                          "non-existent destination \"%s\"."), argv[0], val,
@@ -241,9 +239,10 @@ main(int  argc,                            /* I - Number of command-line arguments */
                        _("%s: Error - no default destination available."),
                        argv[0]);
       httpClose(http);
-      cupsFreeDests(num_dests, dests);
       return (1);
     }
+
+    dest = named_dest->name;
   }
 
  /*
@@ -260,7 +259,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     if (i && interval)
     {
       fflush(stdout);
-      sleep(interval);
+      sleep((unsigned)interval);
     }
     else
       break;
@@ -270,7 +269,6 @@ main(int  argc,                             /* I - Number of command-line arguments */
   * Close the connection to the server and return...
   */
 
-  cupsFreeDests(num_dests, dests);
   httpClose(http);
 
   return (0);
@@ -322,9 +320,6 @@ show_jobs(const char *command,              /* I - Command name */
   ipp_jstate_t jobstate;               /* job-state */
   int          jobid,                  /* job-id */
                jobsize,                /* job-k-octets */
-#ifdef __osf__
-               jobpriority,            /* job-priority */
-#endif /* __osf__ */
                jobcount,               /* Number of jobs */
                jobcopies,              /* Number of copies */
                rank;                   /* Rank of job */
@@ -447,9 +442,6 @@ show_jobs(const char *command,              /* I - Command name */
 
       jobid       = 0;
       jobsize     = 0;
-#ifdef __osf__
-      jobpriority = 50;
-#endif /* __osf__ */
       jobstate    = IPP_JOB_PENDING;
       jobname     = "unknown";
       jobuser     = "unknown";
@@ -466,12 +458,6 @@ show_jobs(const char *command,             /* I - Command name */
            attr->value_tag == IPP_TAG_INTEGER)
          jobsize = attr->values[0].integer;
 
-#ifdef __osf__
-        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") &&
            attr->value_tag == IPP_TAG_ENUM)
          jobstate = (ipp_jstate_t)attr->values[0].integer;
@@ -509,16 +495,9 @@ 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"));
-#else
        _cupsLangPuts(stdout,
                      _("Rank    Owner   Job     File(s)"
                        "                         Total Size"));
-#endif /* __osf__ */
 
       jobcount ++;
 
@@ -559,16 +538,9 @@ show_jobs(const char *command,             /* I - Command name */
                        namestr, 1024.0 * jobsize);
       }
       else
-#ifdef __osf__
-        _cupsLangPrintf(stdout,
-                       _("%-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"),
                        rankstr, jobuser, jobid, jobname, 1024.0 * jobsize);
-#endif /* __osf */
 
       if (attr == NULL)
         break;
@@ -675,8 +647,3 @@ usage(void)
                  "[-l] [+interval]"));
   exit(1);
 }
-
-
-/*
- * End of "$Id: lpq.c 7460 2008-04-16 02:19:54Z mike $".
- */