RIP BOOL. Convert BOOL -> bool. I found a few interesting
[samba.git] / source3 / printing / print_aix.c
1 /* 
2    AIX-specific printcap loading
3    Copyright (C) Jean-Pierre.Boulard@univ-rennes1.fr      1996
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20  * This module implements AIX-specific printcap loading.  Most of the code
21  * here was originally provided by Jean-Pierre.Boulard@univ-rennes1.fr in
22  * the Samba 1.9.14 release, and was formerly contained in pcap.c.  It has
23  * been moved here and condensed as part of a larger effort to clean up and
24  * simplify the printcap code.    -- Rob Foehl, 2004/12/06
25  */
26
27 #include "includes.h"
28
29 #ifdef AIX
30 bool aix_cache_reload(void)
31 {
32         int iEtat;
33         XFILE *pfile;
34         char *line = NULL, *p;
35         pstring name, comment;
36
37         *name = 0;
38         *comment = 0;
39
40         DEBUG(5, ("reloading aix printcap cache\n"));
41
42         if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
43                 DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
44                 return False;
45         }
46
47         iEtat = 0;
48         /* scan qconfig file for searching <printername>:       */
49         for (;(line = fgets_slash(NULL, sizeof(pstring), pfile)); safe_free(line)) {
50                 if (*line == '*' || *line == 0)
51                         continue;
52
53                 switch (iEtat) {
54                 case 0: /* locate an entry */
55                         if (*line == '\t' || *line == ' ')
56                                 continue;
57
58                         if ((p = strchr_m(line, ':'))) {
59                                 *p = '\0';
60                                 p = strtok(line, ":");
61                                 if (strcmp(p, "bsh") != 0) {
62                                         pstrcpy(name, p);
63                                         iEtat = 1;
64                                         continue;
65                                 }
66                          }
67                          break;
68
69                 case 1: /* scanning device stanza */
70                         if (*line == '*' || *line == 0)
71                                 continue;
72
73                         if (*line != '\t' && *line != ' ') {
74                                 /* name is found without stanza device  */
75                                 /* probably a good printer ???          */
76                                 iEtat = 0;
77                                 if (!pcap_cache_add(name, NULL)) {
78                                         safe_free(line);
79                                         x_fclose(pfile);
80                                         return False;
81                                 }
82                                 continue;
83                         }
84                         
85                         if (strstr_m(line, "backend")) {
86                                 /* it's a device, not a virtual printer */
87                                 iEtat = 0;
88                         } else if (strstr_m(line, "device")) {
89                                 /* it's a good virtual printer */
90                                 iEtat = 0;
91                                 if (!pcap_cache_add(name, NULL)) {
92                                         safe_free(line);
93                                         x_fclose(pfile);
94                                         return False;
95                                 }
96                                 continue;
97                         }
98                         break;
99                 }
100         }
101
102         x_fclose(pfile);
103         return True;
104 }
105
106 #else
107 /* this keeps fussy compilers happy */
108  void print_aix_dummy(void);
109  void print_aix_dummy(void) {}
110 #endif /* AIX */