]>
git.saurik.com Git - apple/libinfo.git/blob - gen.subproj/printerdb.c
26bde6218c3306f20b3ef89c46e7a4305e822f9a
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * /etc/printcap reader (in case NetInfo is not running)
26 * Copyright (C) 1989 by NeXT, Inc.
31 #include <printerdb.h>
34 static char *getline(FILE *);
35 static int emptyfield(char *);
44 for (i
= 0; ent
->pe_name
[i
]; i
++) {
45 free(ent
->pe_name
[i
]);
49 for (i
= 0; i
< ent
->pe_nprops
; i
++) {
50 free(ent
->pe_prop
[i
].pp_key
);
51 free(ent
->pe_prop
[i
].pp_value
);
74 pf
= fopen("/etc/printcap", "r");
86 *target
= malloc(sizeof(char *) * 2);
88 *target
= realloc(*target
, sizeof(char *) * (which
+ 2));
90 (*target
)[which
] = strdup(name
);
91 (*target
)[which
+ 1] = NULL
;
96 prdb_property
**target
,
102 *target
= malloc(sizeof(prop
));
104 *target
= realloc(*target
, (which
+ 1) * sizeof(prop
));
106 (*target
)[which
] = prop
;
133 } while (*line
== 0);
135 end
= index(where
, ':');
140 if (ent
.pe_name
!= NULL
) {
141 _prdb_free_ent(&ent
);
144 p
= index(where
, '|');
145 if (p
!= NULL
&& (end
== NULL
|| p
< end
)) {
147 pename_insert(&ent
.pe_name
, where
, which
++);
150 pename_insert(&ent
.pe_name
, where
, which
);
157 end
= index(where
, ':');
161 hash
= index(where
, '#');
162 equal
= index(where
, '=');
163 if (hash
!= NULL
&& (end
== NULL
|| hash
< end
)) {
165 prop
.pp_key
= strdup(where
);
167 prop
.pp_value
= strdup(hash
);
168 peprop_insert(&ent
.pe_prop
, prop
, which
++);
169 } else if (equal
!= NULL
&& (end
== NULL
||
172 prop
.pp_key
= strdup(where
);
173 prop
.pp_value
= strdup(equal
);
174 peprop_insert(&ent
.pe_prop
, prop
, which
++);
175 } else if (!emptyfield(where
)) {
176 prop
.pp_key
= strdup(where
);
177 prop
.pp_value
= strdup("");
178 peprop_insert(&ent
.pe_prop
, prop
, which
++);
186 ent
.pe_nprops
= which
;
198 for (i
= 0; ent
->pe_name
[i
] != NULL
; i
++) {
199 if (strcmp(ent
->pe_name
[i
], name
) == 0) {
217 while ((ent
= _old_prdb_get())) {
218 if (prmatch(ent
, prname
)) {
240 while (more
&& fgets(line
, sizeof(line
), f
)) {
241 inclen
= strlen(line
);
242 if (line
[inclen
- 1] == '\n') {
243 line
[inclen
- 1] = 0;
250 res
= malloc(inclen
+ 1);
252 res
= realloc(res
, len
+ inclen
+ 1);
254 if (line
[inclen
- 1] == '\\') {
255 line
[inclen
- 1] = 0;
260 bcopy(line
, res
+ len
, inclen
);
273 if (*line
!= ' ' && *line
!= '\t') {