r4904: sync up with 3.0 for 3.0.11pre2
[Samba.git] / source / printing / print_svid.c
blob3a7c9356344b3844ab35adab672841aa690f2b56
1 /*
2 * Copyright (C) 1997-1998 by Norm Jacobs, Colorado Springs, Colorado, USA
3 * Copyright (C) 1997-1998 by Sun Microsystem, Inc.
4 * All Rights Reserved
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)
35 #include "includes.h"
37 #ifdef SYSV
38 BOOL sysv_cache_reload(void)
40 char **lines;
41 int i;
43 DEBUG(5, ("reloading sysv printcap cache\n"));
45 if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL)
46 return False;
48 for (i = 0; lines[i]; i++) {
49 char *name, *tmp;
50 char *buf = lines[i];
52 /* eat "system/device for " */
53 if (((tmp = strchr_m(buf, ' ')) == NULL) ||
54 ((tmp = strchr_m(++tmp, ' ')) == NULL))
55 continue;
58 * In case we're only at the "for ".
61 if(!strncmp("for ", ++tmp, 4)) {
62 tmp=strchr_m(tmp, ' ');
63 tmp++;
66 /* Eat whitespace. */
68 while(*tmp == ' ')
69 ++tmp;
72 * On HPUX there is an extra line that can be ignored.
73 * d.thibadeau 2001/08/09
75 if(!strncmp("remote to", tmp, 9))
76 continue;
78 name = tmp;
80 /* truncate the ": ..." */
81 if ((tmp = strchr_m(name, ':')) != NULL)
82 *tmp = '\0';
84 /* add it to the cache */
85 if (!pcap_cache_add(name, NULL)) {
86 file_lines_free(lines);
87 return False;
91 file_lines_free(lines);
92 return True;
95 #else
96 /* this keeps fussy compilers happy */
97 void print_svid_dummy(void);
98 void print_svid_dummy(void) {}
99 #endif