/*
- * "$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:
*
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...
*/
#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;
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 */
"job-name",
"time-at-creation",
"job-printer-uri",
- "job-originating-user-name"
+ "job-originating-user-name",
+ "job-state-reasons"
};
dest = NULL;
jobtime = 0;
title = "no title";
+ reasons = NULL;
while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
{
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;
}
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);
+ }
}
}
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 */
* 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);
}
}
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");
}
}
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
{
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");
}
}
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
{
/*
- * 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 $".
*/