2 * $Id: ppd.c,v 1.9.8.1.2.5 2009-01-21 02:32:16 didg Exp $
4 * Copyright (c) 1995 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
16 #include <atalk/logger.h>
17 #include <sys/types.h>
18 #include <sys/param.h>
20 #include <netatalk/at.h>
21 #include <atalk/atp.h>
26 struct ppd_font *ppd_fonts = NULL;
28 struct ppd_feature ppd_features[] = {
29 { "*LanguageLevel", 0 },
32 { "*FreeVM", "33554432" },
40 { "*ColorDevice", 0 },
42 { "*TTRasterizer", 0 },
63 return read_ppd( printer->p_ppdfile, 0 );
68 /* quick and ugly hack to be able to read
69 ppd files with Mac line ending */
70 static char* my_fgets(buf, bufsize, stream)
75 int p; /* uninitialized, OK 310105 */
78 while (count < (bufsize - 1) && EOF != (p=fgetc(stream))) {
81 if ( p == '\r' || p == '\n')
85 if (p == EOF && count == 0)
88 /* translate line endings */
89 if ( buf[count - 1] == '\r')
90 buf[count - 1] = '\n';
96 static struct ppdent *getppdent( stream )
99 static char buf[ 1024 ];
100 static struct ppdent ppdent;
103 ppdent.pe_main = ppdent.pe_option = ppdent.pe_translation =
104 ppdent.pe_value = NULL;
106 while (( p = my_fgets( buf, sizeof( buf ), stream )) != NULL ) {
107 if ( *p != '*' ) { /* main key word */
110 if ( p[ strlen( p ) - 1 ] != '\n') {
111 LOG(log_error, logtype_papd, "getppdent: line too long" );
116 while ( (*p != ' ') && (*p != '\t') && (*p != ':') && (*p != '\n') ) {
119 if ( (*( q + 1 ) == '%') || (*( q + 1 ) == '?') ) { /* comments & queries */
125 ppdent.pe_option = ppdent.pe_translation = ppdent.pe_value = NULL;
129 if ( *p != ':' ) { /* option key word */
132 while ( (*p == ' ') || (*p == '\t') ) {
137 while ( (*p != ':') && (*p != '/') && (*p != '\n') ) {
145 ppdent.pe_option = q;
146 if ( *p == '/' ) { /* translation string */
149 while ( *p != ':' && *p != '\n' ) {
156 ppdent.pe_translation = q;
158 ppdent.pe_translation = NULL;
163 while ( (*p == ' ') || (*p == '\t') ) {
169 while ( *p != '\n' ) {
181 int read_ppd( file, fcnt )
187 struct ppd_feature *pfe;
188 struct ppd_font *pfo;
191 LOG(log_error, logtype_papd, "read_ppd: %s: Too many files!", file );
195 if (( ppdfile = fopen( file, "r" )) == NULL ) {
196 LOG(log_error, logtype_papd, "read_ppd %s: %s", file, strerror(errno) );
200 while (( pe = getppdent( ppdfile )) != NULL ) {
202 if ( strcmp( pe->pe_main, "*Include" ) == 0 ) {
203 read_ppd( pe->pe_value, fcnt + 1 );
208 if ( strcmp( pe->pe_main, "*Font" ) == 0 && pe->pe_option ) {
209 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
210 if ( strcmp( pfo->pd_font, pe->pe_option ) == 0 ) {
218 if (( pfo = (struct ppd_font *)malloc( sizeof( struct ppd_font )))
220 LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
224 (char *)malloc( strlen( pe->pe_option ) + 1 )) == NULL ) {
225 LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
228 strcpy( pfo->pd_font, pe->pe_option );
229 pfo->pd_next = ppd_fonts;
236 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
237 if ( strcmp( pe->pe_main, pfe->pd_name ) == 0 ) {
241 if ( pfe->pd_name && pe->pe_value ) {
242 if (( pfe->pd_value =
243 (char *)malloc( strlen( pe->pe_value ) + 1 )) == NULL ) {
244 LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
248 strcpy( pfe->pd_value, pe->pe_value );
257 struct ppd_font *ppd_font( font )
260 struct ppd_font *pfo;
263 if ( ! ppd_inited ) {
268 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
269 if ( strcmp( pfo->pd_font, font ) == 0 ) {
276 struct ppd_feature *ppd_feature( feature, len )
280 struct ppd_feature *pfe;
281 char ppd_feature_main[ 256 ];
286 if ( ! ppd_inited ) {
291 for ( end = feature + len, p = feature, q = ppd_feature_main;
292 (p <= end) && (*p != '\n') && (*p != '\r'); p++, q++ ) {
300 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
301 if ( (strcmp( pfe->pd_name, ppd_feature_main ) == 0) && pfe->pd_value ) {