Index: xc/programs/Xserver/Xprint/Init.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/Xprint/Init.c,v retrieving revision 1.4 diff -u -2 -0 -r1.4 Init.c --- xc/programs/Xserver/Xprint/Init.c 15 May 2004 14:43:05 -0000 1.4 +++ xc/programs/Xserver/Xprint/Init.c 12 Jun 2004 01:59:06 -0000 @@ -1,29 +1,30 @@ /* $Xorg: Init.c,v 1.5 2001/03/07 17:31:33 pookie Exp $ */ /* (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 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the names of the copyright holders shall not be used in advertising or otherwise to promote the sale, use or other @@ -228,40 +229,41 @@ InitializePsDriver, &PsValidatePoolsRec, (pVFunc) NULL, PSPixmapFormats, NUMPSFORMATS }, #endif }; /* * The printerDb variable points to a list of PrinterDbEntry structs * which map printer names with screen numbers and driver names. */ typedef struct _printerDbEntry { struct _printerDbEntry *next; char *name; char *qualifier; int screenNum; char *driverName; + char *desc; } PrinterDbEntry, *PrinterDbPtr; static PrinterDbPtr printerDb = (PrinterDbPtr)NULL; /* * The nameMap is a list used in initializing the attribute store * for each printer. The list is freed once the printerDb is built * and the attribute stores for all printers have been initialized. */ typedef struct _nameMapEntry { struct _nameMapEntry *next; char *name; char *qualifier; } NameMapEntry, *NameMapPtr; static NameMapPtr nameMap = (NameMapPtr)NULL; /* * The driverMap is a list which provides the mapping between driver names * and screen numbers. It is built and used @@ -433,90 +435,115 @@ return ; } } *dimensionsFunc = 0; *pValRec = 0; return; } static void FreePrinterDb(void) { PrinterDbPtr pCurEntry, pNextEntry; for(pCurEntry = printerDb, pNextEntry = (PrinterDbPtr)NULL; pCurEntry != (PrinterDbPtr)NULL; pCurEntry = pNextEntry) { 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. */ xfree(pCurEntry); } printerDb = (PrinterDbPtr)NULL; } /* * AddPrinterDbName allocates an entry in the printerDb list, and * initializes the "name". It returns TRUE if the element was * successfully added, and FALSE if an allocation error ocurred. * 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) { pEntry->next = (PrinterDbPtr)NULL; printerDb = pEntry; } else { pEntry->next = printerDb; printerDb = pEntry; } return TRUE; } static int 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); return num_printers; } /* * FreeNameMap frees all remaining memory associated with the nameMap. */ static void FreeNameMap(void) { NameMapPtr pEntry, pTmp; for(pEntry = nameMap, pTmp = (NameMapPtr)NULL; pEntry != (NameMapPtr)NULL; pEntry = pTmp) { if(pEntry->name != (char *)NULL) xfree(pEntry->name); @@ -622,40 +649,69 @@ "xp-ddx-identifier"); if(pEntry->driverName == (char *)NULL || strlen(pEntry->driverName) == 0 || GetInitFunc(pEntry->driverName) == (Bool(*)())NULL) { if (pEntry->driverName && (strlen(pEntry->driverName) != 0)) { ErrorF("Xp Extension: Can't load driver %s\n", pEntry->driverName); ErrorF(" init function missing\n"); } pEntry->driverName = defaultDriver; XpAddPrinterAttribute(pEntry->name, (pEntry->qualifier != (char *)NULL)? pEntry->qualifier : pEntry->name, "*xp-ddx-identifier", pEntry->driverName); } } } +/* + * 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) + { + char *descAttr = (char*)XpGetPrinterAttribute(pEntry->name, + "descriptor"); + if( +#ifdef XPFILE_CANNOT_OVERRIDE_MODEL_CONFIG + ( (descAttr == (char *)NULL) || (*descAttr == 0) ) && +#endif /* XPFILE_CANNOT_OVERRIDE_MODEL_CONFIG */ + (pEntry->desc != NULL) ) + { + XpAddPrinterAttribute(pEntry->name, + (pEntry->qualifier != (char *)NULL)? + pEntry->qualifier : pEntry->name, + "*descriptor", pEntry->desc); + } + } +} + static char * MbStrchr( char *str, int ch) { size_t mbCurMax = MB_CUR_MAX; wchar_t targetChar, curChar; char tmpChar; int i, numBytes, byteLen; if(mbCurMax <= 1) return strchr(str, ch); tmpChar = (char)ch; mbtowc(&targetChar, &tmpChar, mbCurMax); for(i = 0, numBytes = 0, byteLen = strlen(str); i < byteLen; i += numBytes) { numBytes = mbtowc(&curChar, &str[i], mbCurMax); if(curChar == targetChar) return &str[i]; } return (char *)NULL; @@ -743,41 +799,41 @@ else freeConfigFileName = FALSE; if(configFileName != (char *)NULL && access(configFileName, R_OK) == 0) { char line[256]; FILE *fp = fopen(configFileName, "r"); while(fgets(line, 256, fp) != (char *)NULL) { char *tok, *ptr; if((tok = strtok(line, " \t\012")) != (char *)NULL) { if(tok[0] == (char)'#') continue; if(strcmp(tok, "Printer") == 0) { while((tok = strtok((char *)NULL, " \t")) != (char *)NULL) { if(ptr = MbStrchr(tok, '\012')) *ptr = (char)'\0'; - AddPrinterDbName(tok); + AddPrinterDbName(tok, NULL); } } else if(strcmp(tok, "Map") == 0) { char *name, *qualifier; if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL) continue; name = strdup(tok); if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL) { xfree(name); continue; } qualifier = strdup(tok); AddNameMap(name, qualifier); } else if(strcmp(tok, "Augment_Printer_List") == 0) { if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL) @@ -832,40 +888,41 @@ fprintf(stderr, "BuildPrinterDb: using '%s'.\n", spooler_type->name); #endif /* DEBUG_gisburn */ break; } } free(spnamelist); } MergeNameMap(); FreeNameMap(); /* Create the attribute stores for all printers */ CreatePrinterAttrs(); /* * Find the drivers for each printers, and store the driver names * in the printerDb */ StoreDriverNames(); + StoreDescriptors(); if(freeConfigFileName) { xfree(configFileName); configFileName = (char *)NULL; } return printerDb; } static void FreeDriverMap(DriverMapPtr driverMap) { DriverMapPtr pCurEntry, pNextEntry; for(pCurEntry = driverMap, pNextEntry = (DriverMapPtr)NULL; pCurEntry != (DriverMapPtr)NULL; pCurEntry = pNextEntry) { pNextEntry = pCurEntry->next; if(pCurEntry->driverName != (char *)NULL) Index: xc/programs/Xserver/Xprint/spooler.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/Xprint/spooler.c,v retrieving revision 1.2 diff -u -2 -0 -r1.2 spooler.c --- xc/programs/Xserver/Xprint/spooler.c 23 Apr 2004 18:57:32 -0000 1.2 +++ xc/programs/Xserver/Xprint/spooler.c 12 Jun 2004 01:59:06 -0000 @@ -1,24 +1,25 @@ /* $Xorg: spooler.c,v 1.1 2003/09/14 1:19:56 gisburn Exp $ */ /* Copyright (c) 2003-2004 Roland Mainz +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 in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the names of the copyright holders shall not be used in advertising or otherwise to promote the sale, use or other @@ -100,76 +101,85 @@ #define LIST_QUEUES_SYSV \ "PATH=\"${PATH}:/usr/bin:/usr/sbin:/bin:/sbin\"\n" \ "export PATH\n" \ \ "which_tool()\n" \ "{\n" \ " echo \"${PATH}\" | tr \":\" \"\n\" | while read i ; do ls -1ad \"${i}/${1}\" 2>/dev/null ; done\n" \ "}\n" \ \ "(\n" \ "WHICH_LPSTAT=\"`which_tool lpstat`\"\n" \ \ "if [ \"`which_tool nawk`\" != \"\" ] ; then\n" \ " NAWK=\"nawk\"\n" \ "else\n" \ " NAWK=\"awk\"\n" \ "fi\n" \ \ "[ \"${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 '" \ " $2 == \"for\" " \ " { " \ " 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 * print queues and submit print jobs */ 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; XpSpoolerTypePtr XpSpoolerNameToXpSpoolerType(char *name) { XpSpoolerTypePtr curr = xpstm; while( curr->name != NULL ) { if( !strcasecmp(name, curr->name) ) return curr; curr++; } return NULL; } static char *spooler_namelist = NULL; Index: xc/programs/Xserver/Xprint/spooler.h =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/Xprint/spooler.h,v retrieving revision 1.2 diff -u -2 -0 -r1.2 spooler.h --- xc/programs/Xserver/Xprint/spooler.h 23 Apr 2004 18:57:32 -0000 1.2 +++ xc/programs/Xserver/Xprint/spooler.h 12 Jun 2004 01:59:06 -0000 @@ -1,27 +1,28 @@ #ifndef SPOOLER_H #define SPOOLER_H 1 /* $Xorg: spooler.h,v 1.1 2003/09/14 1:19:56 gisburn Exp $ */ /* Copyright (c) 2003-2004 Roland Mainz +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 in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the names of the copyright holders shall not be used in advertising or otherwise to promote the sale, use or other