]>
git.saurik.com Git - apple/libinfo.git/blob - gen.subproj/printerdb.c
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.
30 #include <printerdb.h>
32 #define strdup(x) strcpy(malloc(strlen(x) + 1), x)
34 extern size_t strlen(const char *);
35 extern char *index(const char *, int);
36 extern char *strcpy(char *, const char *);
37 extern int strcmp(const char *, const char*);
38 extern void *bcopy(void *, void *, unsigned);
41 static char *getline(FILE *);
42 static int emptyfield(char *);
51 for (i
= 0; ent
->pe_name
[i
]; i
++) {
52 free(ent
->pe_name
[i
]);
56 for (i
= 0; i
< ent
->pe_nprops
; i
++) {
57 free(ent
->pe_prop
[i
].pp_key
);
58 free(ent
->pe_prop
[i
].pp_value
);
81 pf
= fopen("/etc/printcap", "r");
93 *target
= malloc(sizeof(char *) * 2);
95 *target
= realloc(*target
, sizeof(char *) * (which
+ 2));
97 (*target
)[which
] = strdup(name
);
98 (*target
)[which
+ 1] = NULL
;
103 prdb_property
**target
,
109 *target
= malloc(sizeof(prop
));
111 *target
= realloc(*target
, (which
+ 1) * sizeof(prop
));
113 (*target
)[which
] = prop
;
140 } while (*line
== 0);
142 end
= index(where
, ':');
147 if (ent
.pe_name
!= NULL
) {
148 _prdb_free_ent(&ent
);
151 p
= index(where
, '|');
152 if (p
!= NULL
&& (end
== NULL
|| p
< end
)) {
154 pename_insert(&ent
.pe_name
, where
, which
++);
157 pename_insert(&ent
.pe_name
, where
, which
);
164 end
= index(where
, ':');
168 hash
= index(where
, '#');
169 equal
= index(where
, '=');
170 if (hash
!= NULL
&& (end
== NULL
|| hash
< end
)) {
172 prop
.pp_key
= strdup(where
);
174 prop
.pp_value
= strdup(hash
);
175 peprop_insert(&ent
.pe_prop
, prop
, which
++);
176 } else if (equal
!= NULL
&& (end
== NULL
||
179 prop
.pp_key
= strdup(where
);
180 prop
.pp_value
= strdup(equal
);
181 peprop_insert(&ent
.pe_prop
, prop
, which
++);
182 } else if (!emptyfield(where
)) {
183 prop
.pp_key
= strdup(where
);
184 prop
.pp_value
= strdup("");
185 peprop_insert(&ent
.pe_prop
, prop
, which
++);
193 ent
.pe_nprops
= which
;
205 for (i
= 0; ent
->pe_name
[i
] != NULL
; i
++) {
206 if (strcmp(ent
->pe_name
[i
], name
) == 0) {
224 while ((ent
= _old_prdb_get())) {
225 if (prmatch(ent
, prname
)) {
247 while (more
&& fgets(line
, sizeof(line
), f
)) {
248 inclen
= strlen(line
);
249 if (line
[inclen
- 1] == '\n') {
250 line
[inclen
- 1] = 0;
257 res
= malloc(inclen
+ 1);
259 res
= realloc(res
, len
+ inclen
+ 1);
261 if (line
[inclen
- 1] == '\\') {
262 line
[inclen
- 1] = 0;
267 bcopy(line
, res
+ len
, inclen
);
280 if (*line
!= ' ' && *line
!= '\t') {