------- Init.c ------- --- /tmp/sccs.gNaGTT Sat May 22 13:02:08 2004 +++ Init.c Sat May 22 12:57:54 2004 @@ -2,7 +2,7 @@ /* (c) Copyright 1996 Hewlett-Packard Company (c) Copyright 1996 International Business Machines Corp. -(c) Copyright 1996 Sun Microsystems, Inc. +(c) Copyright 1996,2000 Sun Microsystems, Inc. (c) Copyright 1996 Novell, Inc. (c) Copyright 1996 Digital Equipment Corp. (c) Copyright 1996 Fujitsu Limited @@ -159,6 +159,10 @@ * list of available printers on the system. These string definitions * are taken from the file PrintSubSys.C within the code for the * dtprintinfo program. + * + * The output is assumed to be a list of printers, one per line, with + * each line consisting of the printer name, followed optionally by \t + * and a text "description". */ #ifdef AIXV4 const char *LIST_QUEUES = "lsallq | grep -v '^bsh$' | sort"; @@ -192,6 +196,15 @@ const char *LIST_QUEUES = "LANG=C lpc status | grep -v '^\t' | " "sed -e /:/s/// | sort"; #else +#if defined(sun) && defined(SVR4) +const char *LIST_QUEUES = "LANG=C lpget -k description " + "`lpstat -v " + "| nawk '$2 == \"for\" { x = match($3, /:/); print substr($3, 1,x-1) }' " + "| sort` " + "| nawk -F: ' NF == 2 { name=$1 } " + " NF == 1 { sub(\"^.*description\\( - undefined|=\\)\",\"\"); " + " printf \"%s\\t%s\\n\", name, $1 } '"; +#else const char *LIST_QUEUES = "LANG=C lpstat -v | " "nawk '" " $2 == \"for\" " @@ -204,6 +217,7 @@ #endif #endif #endif +#endif #ifdef XPRASTERDDX @@ -341,6 +355,7 @@ char *qualifier; int screenNum; char *driverName; + char *desc; } PrinterDbEntry, *PrinterDbPtr; static PrinterDbPtr printerDb = (PrinterDbPtr)NULL; @@ -480,6 +495,8 @@ 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. @@ -496,13 +513,15 @@ * XXX AddPrinterDbName needs to check for (and not add) duplicate names. */ static Bool -AddPrinterDbName(name) +AddPrinterDbName(name,desc) 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) @@ -524,13 +543,23 @@ { FILE *fp; char name[256]; + 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); + desc = strchr(name, '\t'); + + if (desc) { + *(desc++) = '\0'; + if (*desc == '\0') { + desc = NULL; + } + } + name[namelen - 1] = (char)'\0'; /* strip the \n */ + AddPrinterDbName(name,desc); } pclose(fp); } @@ -670,6 +699,32 @@ } } +/* + * 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( ( (descAttr == (char *)NULL) || (*descAttr == 0) ) + && (pEntry->desc != NULL) ) + { + XpAddPrinterAttribute(pEntry->name, + (pEntry->qualifier != (char *)NULL)? + pEntry->qualifier : pEntry->name, + "*descriptor", pEntry->desc); + } + } +} + char * MbStrchr( char *str, @@ -791,7 +846,7 @@ { if(ptr = MbStrchr(tok, '\012')) *ptr = (char)'\0'; - AddPrinterDbName(tok); + AddPrinterDbName(tok,NULL); } } else if(strcmp(tok, "Map") == 0) @@ -844,6 +899,7 @@ * in the printerDb */ StoreDriverNames(); + StoreDescriptors(); if(freeConfigFileName) {