2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * /etc/printcap reader (in case NetInfo is not running)
27 * Copyright (C) 1989 by NeXT, Inc.
31 #include <printerdb.h>
33 #define strdup(x) strcpy(malloc(strlen(x) + 1), x)
35 extern size_t strlen(const char *);
36 extern char *index(const char *, int);
37 extern char *strcpy(char *, const char *);
38 extern int strcmp(const char *, const char*);
39 extern void *bcopy(void *, void *, unsigned);
42 static char *getline(FILE *);
43 static int emptyfield(char *);
52 for (i
= 0; ent
->pe_name
[i
]; i
++) {
53 free(ent
->pe_name
[i
]);
57 for (i
= 0; i
< ent
->pe_nprops
; i
++) {
58 free(ent
->pe_prop
[i
].pp_key
);
59 free(ent
->pe_prop
[i
].pp_value
);
82 pf
= fopen("/etc/printcap", "r");
94 *target
= malloc(sizeof(char *) * 2);
96 *target
= realloc(*target
, sizeof(char *) * (which
+ 2));
98 (*target
)[which
] = strdup(name
);
99 (*target
)[which
+ 1] = NULL
;
104 prdb_property
**target
,
110 *target
= malloc(sizeof(prop
));
112 *target
= realloc(*target
, (which
+ 1) * sizeof(prop
));
114 (*target
)[which
] = prop
;
141 } while (*line
== 0);
143 end
= index(where
, ':');
148 if (ent
.pe_name
!= NULL
) {
149 _prdb_free_ent(&ent
);
152 p
= index(where
, '|');
153 if (p
!= NULL
&& (end
== NULL
|| p
< end
)) {
155 pename_insert(&ent
.pe_name
, where
, which
++);
158 pename_insert(&ent
.pe_name
, where
, which
);
165 end
= index(where
, ':');
169 hash
= index(where
, '#');
170 equal
= index(where
, '=');
171 if (hash
!= NULL
&& (end
== NULL
|| hash
< end
)) {
173 prop
.pp_key
= strdup(where
);
175 prop
.pp_value
= strdup(hash
);
176 peprop_insert(&ent
.pe_prop
, prop
, which
++);
177 } else if (equal
!= NULL
&& (end
== NULL
||
180 prop
.pp_key
= strdup(where
);
181 prop
.pp_value
= strdup(equal
);
182 peprop_insert(&ent
.pe_prop
, prop
, which
++);
183 } else if (!emptyfield(where
)) {
184 prop
.pp_key
= strdup(where
);
185 prop
.pp_value
= strdup("");
186 peprop_insert(&ent
.pe_prop
, prop
, which
++);
194 ent
.pe_nprops
= which
;
206 for (i
= 0; ent
->pe_name
[i
] != NULL
; i
++) {
207 if (strcmp(ent
->pe_name
[i
], name
) == 0) {
225 while ((ent
= _old_prdb_get())) {
226 if (prmatch(ent
, prname
)) {
248 while (more
&& fgets(line
, sizeof(line
), f
)) {
249 inclen
= strlen(line
);
250 if (line
[inclen
- 1] == '\n') {
251 line
[inclen
- 1] = 0;
258 res
= malloc(inclen
+ 1);
260 res
= realloc(res
, len
+ inclen
+ 1);
262 if (line
[inclen
- 1] == '\\') {
263 line
[inclen
- 1] = 0;
268 bcopy(line
, res
+ len
, inclen
);
281 if (*line
!= ' ' && *line
!= '\t') {