summaryrefslogtreecommitdiff
path: root/Xprint
diff options
context:
space:
mode:
authorRoland Mainz <roland.mainz@nrubsig.org>2004-06-24 06:26:27 +0000
committerRoland Mainz <roland.mainz@nrubsig.org>2004-06-24 06:26:27 +0000
commitad6b9644a39343437967b4c3b2442dbd47508443 (patch)
tree5a7990ab5a3db7a82cb79ea51f5623c79b98d179 /Xprint
parent884908a63c624585c9b5fcf22d565236298c2916 (diff)
Fix for http://xprint.freedesktop.org/bugzilla/show_bug.cgi?id=660 : Fix
for the issue that GetPrinterList does not return printer descriptions on Solaris. The patch implements a framework which allows the printer enumerator scripts to pass additional printer attributes to the information pool (currently only "xp-printerattr.descriptor" is implemented).
Diffstat (limited to 'Xprint')
-rw-r--r--Xprint/Init.c65
-rw-r--r--Xprint/spooler.c48
2 files changed, 87 insertions, 26 deletions
diff --git a/Xprint/Init.c b/Xprint/Init.c
index 77d5edd0c..cd16847ee 100644
--- a/Xprint/Init.c
+++ b/Xprint/Init.c
@@ -2,11 +2,12 @@
/*
(c) Copyright 1996 Hewlett-Packard Company
(c) Copyright 1996 International Business Machines Corp.
-(c) Copyright 1996 Sun Microsystems, Inc.
+(c) Copyright 1996-2004 Sun Microsystems, Inc.
(c) Copyright 1996 Novell, Inc.
(c) Copyright 1996 Digital Equipment Corp.
(c) Copyright 1996 Fujitsu Limited
(c) Copyright 1996 Hitachi, Ltd.
+(c) Copyright 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -245,6 +246,7 @@ typedef struct _printerDbEntry {
char *qualifier;
int screenNum;
char *driverName;
+ char *desc;
} PrinterDbEntry, *PrinterDbPtr;
static PrinterDbPtr printerDb = (PrinterDbPtr)NULL;
@@ -456,6 +458,8 @@ FreePrinterDb(void)
pNextEntry = pCurEntry->next;
if(pCurEntry->name != (char *)NULL)
xfree(pCurEntry->name);
+ if(pCurEntry->desc != (char *)NULL)
+ xfree(pCurEntry->desc);
/*
* We don't free the driver name, because it's expected to simply
* be a pointer into the xrm database.
@@ -472,12 +476,13 @@ FreePrinterDb(void)
* XXX AddPrinterDbName needs to check for (and not add) duplicate names.
*/
static Bool
-AddPrinterDbName(char *name)
+AddPrinterDbName(char *name, char *desc)
{
PrinterDbPtr pEntry = (PrinterDbPtr)xalloc(sizeof(PrinterDbEntry));
if(pEntry == (PrinterDbPtr)NULL) return FALSE;
- pEntry->name = strdup(name);
+ pEntry->name = (name != NULL) ? strdup(name) : NULL;
+ pEntry->desc = (desc != NULL) ? strdup(desc) : NULL;
pEntry->qualifier = (char *)NULL;
if(printerDb == (PrinterDbPtr)NULL)
@@ -499,13 +504,35 @@ AugmentPrinterDb(const char *command)
FILE *fp;
char name[256];
int num_printers = 0; /* Number of printers we found */
+ size_t namelen;
+ char *desc = NULL;
fp = popen(command, "r");
/* XXX is a 256 character limit overly restrictive for printer names? */
- while(fgets(name, 256, fp) != (char *)NULL && strlen(name))
+ while(fgets(name, 256, fp) != (char *)NULL && (namelen=strlen(name)))
{
- name[strlen(name) - 1] = (char)'\0'; /* strip the \n */
- AddPrinterDbName(name);
+ char *option = name;
+
+ name[namelen-1] = (char)'\0'; /* strip the \n */
+
+#define XP_DESCRIPTOR "xp-printerattr.descriptor="
+#define XP_DESCRIPTOR_LEN (sizeof(XP_DESCRIPTOR)-1)
+ while (option = strchr(option, '\t')) {
+ option++; /* Skip the '\t' */
+ if (!strncmp(option, XP_DESCRIPTOR, XP_DESCRIPTOR_LEN)) {
+ *(option-1) = '\0'; /* Kill the '\t' (only if we found a valid option) */
+ option += XP_DESCRIPTOR_LEN;
+ if (*option != '\0') {
+ desc = option;
+ }
+ }
+ else
+ {
+ /* Unknown option */
+ ErrorF("AugmentPrinterDb: Unknown option '%s'\n", option);
+ }
+ }
+ AddPrinterDbName(name, desc);
num_printers++;
}
pclose(fp);
@@ -645,6 +672,29 @@ StoreDriverNames(void)
}
}
+/*
+ * StoreDescriptors - queries the attribute store for the descriptor.
+ * if the descriptor is not in the attribute database, then the descriptor
+ * from the printerDb is store in the attribute store for the printer.
+ */
+static void
+StoreDescriptors()
+{
+ PrinterDbPtr pEntry;
+
+ for(pEntry = printerDb; pEntry != (PrinterDbPtr)NULL;
+ pEntry = pEntry->next)
+ {
+ if (pEntry->desc != NULL)
+ {
+ XpAddPrinterAttribute(pEntry->name,
+ (pEntry->qualifier != (char *)NULL)?
+ pEntry->qualifier : pEntry->name,
+ "*descriptor", pEntry->desc);
+ }
+ }
+}
+
static char *
MbStrchr(
char *str,
@@ -766,7 +816,7 @@ BuildPrinterDb(void)
{
if(ptr = MbStrchr(tok, '\012'))
*ptr = (char)'\0';
- AddPrinterDbName(tok);
+ AddPrinterDbName(tok, NULL);
}
}
else if(strcmp(tok, "Map") == 0)
@@ -855,6 +905,7 @@ BuildPrinterDb(void)
* in the printerDb
*/
StoreDriverNames();
+ StoreDescriptors();
if(freeConfigFileName)
{
diff --git a/Xprint/spooler.c b/Xprint/spooler.c
index a9983fc17..8dbb4625a 100644
--- a/Xprint/spooler.c
+++ b/Xprint/spooler.c
@@ -2,6 +2,7 @@
/* $Xorg: spooler.c,v 1.1 2003/09/14 1:19:56 gisburn Exp $ */
/*
Copyright (c) 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
+Copyright (c) 2004 Sun Microsystems, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -117,7 +118,15 @@ copyright holders.
\
"[ \"${WHICH_LPSTAT}\" != \"\" ] && (LANG=C lpstat -v | ${NAWK} ' $2 == \"for\" { x = match($3, /:/); print substr($3, 1, x-1) }')\n" \
") | egrep -v -i \" |^all$\" | sort | uniq"
-
+
+#define LIST_QUEUES_SOLARIS "LANG=C lpget -k description " \
+ "`lpstat -v " \
+ "| nawk '$2 == \"for\" { x = match($3, /:/); print substr($3, 1,x-1) }' " \
+ "| sort -u` " \
+ "| nawk -F: ' NF == 2 { name=$1 } " \
+ " NF == 1 { sub(\"^.*description\\( - undefined|=\\)\",\"\"); " \
+ " printf \"%sxp-printerattr.descriptor=%s\\n\", name, $1 } '"
+
#define LIST_QUEUES_OTHER \
"LANG=C lpstat -v | " \
"nawk '" \
@@ -126,11 +135,12 @@ copyright holders.
" x = match($3, /:/); " \
" print substr($3, 1, x-1)" \
" }' | sort | uniq"
-
-#define DEFAULT_SPOOL_COMMAND_HPUX "/usr/bin/lp -d %printer-name% -o raw -n %copy-count% -t %job-name% %options%"
-#define DEFAULT_SPOOL_COMMAND_BSD "/usr/bin/lpr -P %printer-name% -#%copy-count% -T %job-name% %options%"
-#define DEFAULT_SPOOL_COMMAND_SYSV "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
-#define DEFAULT_SPOOL_COMMAND_OTHER "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
+
+#define DEFAULT_SPOOL_COMMAND_HPUX "/usr/bin/lp -d %printer-name% -o raw -n %copy-count% -t %job-name% %options%"
+#define DEFAULT_SPOOL_COMMAND_BSD "/usr/bin/lpr -P %printer-name% -#%copy-count% -T %job-name% %options%"
+#define DEFAULT_SPOOL_COMMAND_SYSV "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
+#define DEFAULT_SPOOL_COMMAND_SOLARIS "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
+#define DEFAULT_SPOOL_COMMAND_OTHER "/usr/bin/lp -d %printer-name% -n %copy-count% -t %job-name% %options%"
/* List of spooler types and the commands used to enumerate
@@ -138,21 +148,21 @@ copyright holders.
XpSpoolerType xpstm[] =
{
/* OS-specific spoolers */
- { "aix", LIST_QUEUES_AIX4, DEFAULT_SPOOL_COMMAND_OTHER },
- { "aix4", LIST_QUEUES_AIX4, DEFAULT_SPOOL_COMMAND_OTHER },
- { "bsd", LIST_QUEUES_BSD, DEFAULT_SPOOL_COMMAND_BSD },
- { "osf", LIST_QUEUES_OSF, DEFAULT_SPOOL_COMMAND_OTHER },
- { "solaris", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
- { "sysv", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
- { "uxp", LIST_QUEUES_UXP, DEFAULT_SPOOL_COMMAND_OTHER },
+ { "aix", LIST_QUEUES_AIX4, DEFAULT_SPOOL_COMMAND_OTHER },
+ { "aix4", LIST_QUEUES_AIX4, DEFAULT_SPOOL_COMMAND_OTHER },
+ { "bsd", LIST_QUEUES_BSD, DEFAULT_SPOOL_COMMAND_BSD },
+ { "osf", LIST_QUEUES_OSF, DEFAULT_SPOOL_COMMAND_OTHER },
+ { "solaris", LIST_QUEUES_SOLARIS, DEFAULT_SPOOL_COMMAND_SOLARIS },
+ { "sysv", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
+ { "uxp", LIST_QUEUES_UXP, DEFAULT_SPOOL_COMMAND_OTHER },
/* crossplatform spoolers */
- { "cups", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
- { "lprng", LIST_QUEUES_BSD, DEFAULT_SPOOL_COMMAND_BSD },
+ { "cups", LIST_QUEUES_SYSV, DEFAULT_SPOOL_COMMAND_SYSV },
+ { "lprng", LIST_QUEUES_BSD, DEFAULT_SPOOL_COMMAND_BSD },
/* misc */
- { "other", LIST_QUEUES_OTHER, DEFAULT_SPOOL_COMMAND_OTHER },
- { "none", NULL, NULL },
- { NULL, NULL, NULL }
-};
+ { "other", LIST_QUEUES_OTHER, DEFAULT_SPOOL_COMMAND_OTHER },
+ { "none", NULL, NULL },
+ { NULL, NULL, NULL }
+};
/* Used by Init.c and attributes.c */
XpSpoolerTypePtr spooler_type = NULL;