2 * Copyright (C) 1997-1998 by Norm Jacobs, Colorado Springs, Colorado, USA
3 * Copyright (C) 1997-1998 by Sun Microsystem, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * This module implements support for gathering and comparing available
23 * printer information on a SVID or XPG4 compliant system. It does this
24 * through the use of the SVID/XPG4 command "lpstat(1)".
26 * The expectations is that execution of the command "lpstat -v" will
27 * generate responses in the form of:
29 * device for serial: /dev/term/b
30 * system for fax: server
31 * system for color: server (as printer chroma)
40 extern int DEBUGLEVEL;
42 typedef struct printer {
46 static printer_t *printers = NULL;
48 static void populate_printers(void)
52 if ((fp = popen("/usr/bin/lpstat -v", "r")) != NULL) {
55 while (fgets(buf, sizeof (buf), fp) != NULL) {
59 /* eat "system/device for " */
60 if (((tmp = strchr(buf, ' ')) == NULL) ||
61 ((tmp = strchr(++tmp, ' ')) == NULL))
65 * In case we're only at the "for ".
68 if(!strncmp("for ",++tmp,4))
75 /* truncate the ": ..." */
76 if ((tmp = strchr(name, ':')) != NULL)
79 /* add it to the cache */
80 if ((ptmp = malloc(sizeof (*ptmp))) != NULL) {
82 if((ptmp->name = strdup(name)) == NULL)
83 DEBUG(0,("populate_printers: malloc fail in strdup !\n"));
84 ptmp->next = printers;
87 DEBUG(0,("populate_printers: malloc fail for ptmp\n"));
92 DEBUG(0,( "Unable to run lpstat!\n"));
98 * provide the equivalent of pcap_printer_fn() for SVID/XPG4 conforming
99 * systems. It was unclear why pcap_printer_fn() was tossing names longer
100 * than 8 characters. I suspect that its a protocol limit, but amazingly
101 * names longer than 8 characters appear to work with my test
102 * clients (Win95/NT).
104 void sysv_printer_fn(void (*fn)(char *, char *))
108 if (printers == NULL)
110 for (tmp = printers; tmp != NULL; tmp = tmp->next)
116 * provide the equivalent of pcap_printername_ok() for SVID/XPG4 conforming
119 int sysv_printername_ok(char *name)
123 if (printers == NULL)
125 for (tmp = printers; tmp != NULL; tmp = tmp->next)
126 if (strcmp(tmp->name, name) == 0)
132 /* this keeps fussy compilers happy */
133 void print_svid_dummy(void);
134 void print_svid_dummy(void) {}