]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpstat.c
Merge changes from CUPS 1.4svn-r7932.
[thirdparty/cups.git] / systemv / lpstat.c
index 316617382989d3e1febdf45b1a9e8c3f114970ed..35b76226eed301fd27972029f29d2bee9498b9a6 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: lpstat.c 181 2006-06-22 20:01:18Z jlovell $"
+ * "$Id: lpstat.c 7620 2008-06-06 17:24:22Z mike $"
  *
  *   "lpstat" command for the Common UNIX Printing System (CUPS).
  *
+ *   Copyright 2007-2008 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:
  *
@@ -85,41 +76,8 @@ main(int  argc,                              /* I - Number of command-line arguments */
   char         op;                     /* Last operation on command-line */
 
 
- /*
-  * Set the locale so that times, etc. are displayed properly.
-  *
-  * Unfortunately, while we need the localized time value, we *don't*
-  * want to use the localized charset for the time value, so we need
-  * to set LC_TIME to the locale name with .UTF-8 on the end (if
-  * the locale includes a character set specifier...)
-  */
-
-  setlocale(LC_ALL, "");
-
-#ifdef LC_TIME
-  {
-    const char *lc_time;               /* Current LC_TIME value */
-    char       new_lc_time[255],       /* New LC_TIME value */
-               *charset;               /* Pointer to character set */
-
-    if ((lc_time = setlocale(LC_TIME, NULL)) == NULL)
-      lc_time = setlocale(LC_ALL, NULL);
-
-    if (lc_time)
-    {
-      strlcpy(new_lc_time, lc_time, sizeof(new_lc_time));
-      if ((charset = strchr(new_lc_time, '.')) == NULL)
-        charset = new_lc_time + strlen(new_lc_time);
-
-      strlcpy(charset, ".UTF-8", sizeof(new_lc_time) - (charset - new_lc_time));
-    }
-    else
-      strcpy(new_lc_time, "C");
+  _cupsSetLocale(argv);
 
-    setlocale(LC_TIME, new_lc_time);
-  }
-#endif /* LC_TIME */
-  
  /*
   * Parse command-line options...
   */
@@ -154,6 +112,13 @@ main(int  argc,                            /* I - Number of command-line arguments */
 #endif /* HAVE_SSL */
            break;
 
+       case 'H' : /* Show server and port */
+           if (cupsServer()[0] == '/')
+             _cupsLangPrintf(stdout, "%s\n", cupsServer());
+           else
+             _cupsLangPrintf(stdout, "%s:%d\n", cupsServer(), ippPort());
+            break;
+
         case 'P' : /* Show paper types */
            op = 'P';
            break;
@@ -1430,9 +1395,11 @@ show_jobs(http_t     *http,              /* I - HTTP connection to server */
           int        ranking,          /* I - Show job ranking? */
          const char *which)            /* I - Show which jobs? */
 {
+  int          i;                      /* Looping var */
   ipp_t                *request,               /* IPP Request */
                *response;              /* IPP Response */
-  ipp_attribute_t *attr;               /* Current attribute */
+  ipp_attribute_t *attr,               /* Current attribute */
+               *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 */
@@ -1453,7 +1420,8 @@ show_jobs(http_t     *http,               /* I - HTTP connection to server */
                  "job-name",
                  "time-at-creation",
                  "job-printer-uri",
-                 "job-originating-user-name"
+                 "job-originating-user-name",
+                 "job-state-reasons"
                };
 
 
@@ -1528,6 +1496,7 @@ show_jobs(http_t     *http,               /* I - HTTP connection to server */
       dest     = NULL;
       jobtime  = 0;
       title    = "no title";
+      reasons  = NULL;
 
       while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
       {
@@ -1556,6 +1525,10 @@ show_jobs(http_t     *http,              /* I - HTTP connection to server */
            attr->value_tag == IPP_TAG_NAME)
          title = attr->values[0].string.text;
 
+        if (!strcmp(attr->name, "job-state-reasons") &&
+           attr->value_tag == IPP_TAG_KEYWORD)
+         reasons = attr;
+
         attr = attr->next;
       }
 
@@ -1698,7 +1671,17 @@ show_jobs(http_t     *http,              /* I - HTTP connection to server */
                            temp, username ? username : "unknown",
                            1024.0 * size, date);
           if (long_status)
+          {
+           if (reasons)
+           {
+             _cupsLangPuts(stdout, _("\tAlerts:"));
+             for (i = 0; i < reasons->num_values; i ++)
+               _cupsLangPrintf(stdout, " %s",
+                               reasons->values[i].string.text);
+             _cupsLangPuts(stdout, "\n");
+           }
            _cupsLangPrintf(stdout, _("\tqueued for %s\n"), dest);
+         }
        }
       }
 
@@ -1729,7 +1712,7 @@ show_printers(http_t      *http,  /* I - HTTP connection to server */
              cups_dest_t *dests,       /* I - User-defined destinations */
               int         long_status) /* I - Show long status? */
 {
-  int          i;                      /* Looping var */
+  int          i, j;                   /* Looping vars */
   ipp_t                *request,               /* IPP Request */
                *response,              /* IPP Response */
                *jobs;                  /* IPP Get Jobs response */
@@ -2003,22 +1986,30 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
            * Get the current active job on this queue...
            */
 
+            ipp_jstate_t jobstate = IPP_JOB_PENDING;
            jobid = 0;
 
            for (jobattr = jobs->attrs; jobattr; jobattr = jobattr->next)
            {
              if (!jobattr->name)
-               continue;
+             {
+               if (jobstate == IPP_JOB_PROCESSING)
+                 break;
+               else
+                 continue;
+              }
 
              if (!strcmp(jobattr->name, "job-id") &&
                  jobattr->value_tag == IPP_TAG_INTEGER)
                jobid = jobattr->values[0].integer;
               else if (!strcmp(jobattr->name, "job-state") &&
-                      jobattr->value_tag == IPP_TAG_ENUM &&
-                      jobattr->values[0].integer == IPP_JOB_PROCESSING)
-               break;
+                      jobattr->value_tag == IPP_TAG_ENUM)
+               jobstate = jobattr->values[0].integer;
            }
 
+            if (jobstate != IPP_JOB_PROCESSING)
+             jobid = 0;
+
             ippDelete(jobs);
          }
         }
@@ -2072,9 +2063,9 @@ show_printers(http_t      *http,  /* I - HTTP connection to server */
          if (reasons)
          {
            _cupsLangPuts(stdout, _("\tAlerts:"));
-           for (i = 0; i < reasons->num_values; i ++)
+           for (j = 0; j < reasons->num_values; j ++)
              _cupsLangPrintf(stdout, " %s",
-                             reasons->values[i].string.text);
+                             reasons->values[j].string.text);
            _cupsLangPuts(stdout, "\n");
          }
        }
@@ -2110,16 +2101,16 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
           if (allowed)
          {
            _cupsLangPuts(stdout, _("\tUsers allowed:\n"));
-           for (i = 0; i < allowed->num_values; i ++)
+           for (j = 0; j < allowed->num_values; j ++)
              _cupsLangPrintf(stdout, "\t\t%s\n",
-                             allowed->values[i].string.text);
+                             allowed->values[j].string.text);
          }
          else if (denied)
          {
            _cupsLangPuts(stdout, _("\tUsers denied:\n"));
-           for (i = 0; i < denied->num_values; i ++)
+           for (j = 0; j < denied->num_values; j ++)
              _cupsLangPrintf(stdout, "\t\t%s\n",
-                             denied->values[i].string.text);
+                             denied->values[j].string.text);
          }
          else
          {
@@ -2185,9 +2176,9 @@ show_printers(http_t      *http,  /* I - HTTP connection to server */
              if (reasons)
              {
                _cupsLangPuts(stdout, _("\tAlerts:"));
-               for (i = 0; i < reasons->num_values; i ++)
+               for (j = 0; j < reasons->num_values; j ++)
                  _cupsLangPrintf(stdout, " %s",
-                                 reasons->values[i].string.text);
+                                 reasons->values[j].string.text);
                _cupsLangPuts(stdout, "\n");
              }
            }
@@ -2223,16 +2214,16 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
               if (allowed)
              {
                _cupsLangPuts(stdout, _("\tUsers allowed:\n"));
-               for (i = 0; i < allowed->num_values; i ++)
+               for (j = 0; j < allowed->num_values; j ++)
                  _cupsLangPrintf(stdout, "\t\t%s\n",
-                                 allowed->values[i].string.text);
+                                 allowed->values[j].string.text);
              }
              else if (denied)
              {
                _cupsLangPuts(stdout, _("\tUsers denied:\n"));
-               for (i = 0; i < denied->num_values; i ++)
+               for (j = 0; j < denied->num_values; j ++)
                  _cupsLangPrintf(stdout, "\t\t%s\n",
-                                 denied->values[i].string.text);
+                                 denied->values[j].string.text);
              }
              else
              {
@@ -2282,5 +2273,5 @@ show_scheduler(http_t *http)      /* I - HTTP connection to server */
 
 
 /*
- * End of "$Id: lpstat.c 181 2006-06-22 20:01:18Z jlovell $".
+ * End of "$Id: lpstat.c 7620 2008-06-06 17:24:22Z mike $".
  */