2 * $Id: ppd.c,v 1.9.8.1.2.1 2005-01-31 17:01:07 didg Exp $
4 * Copyright (c) 1995 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
15 #include <atalk/logger.h>
16 #include <sys/types.h>
17 #include <sys/param.h>
19 #include <netatalk/at.h>
20 #include <atalk/atp.h>
25 struct ppd_font *ppd_fonts = NULL;
27 struct ppd_feature ppd_features[] = {
28 { "*LanguageLevel", 0 },
31 { "*FreeVM", "33554432" },
39 { "*ColorDevice", 0 },
41 { "*TTRasterizer", 0 },
62 return read_ppd( printer->p_ppdfile, 0 );
67 /* quick and ugly hack to be able to read
68 ppd files with Mac line ending */
69 static char* my_fgets(buf, bufsize, stream)
74 char p; /* uninitialized, OK 310105 */
77 while (count < bufsize && EOF != (p=fgetc(stream))) {
80 if ( p == '\r' || p == '\n')
84 if (p == EOF && count == 0)
87 /* translate line endings */
88 if ( buf[count - 1] == '\r')
89 buf[count - 1] = '\n';
95 struct ppdent *getppdent( stream )
98 static char buf[ 1024 ];
99 static struct ppdent ppdent;
102 ppdent.pe_main = ppdent.pe_option = ppdent.pe_translation =
103 ppdent.pe_value = NULL;
105 while (( p = my_fgets( buf, sizeof( buf ), stream )) != NULL ) {
106 if ( *p != '*' ) { /* main key word */
109 if ( p[ strlen( p ) - 1 ] != '\n' && p[ strlen( p ) - 1 ] != '\r') {
110 LOG(log_error, logtype_papd, "getppdent: line too long" );
115 while ( (*p != ' ') && (*p != '\t') && (*p != ':') && (*p != '\n') ) {
118 if ( (*( q + 1 ) == '%') || (*( q + 1 ) == '?') ) { /* comments & queries */
124 ppdent.pe_option = ppdent.pe_translation = ppdent.pe_value = NULL;
128 if ( *p != ':' ) { /* option key word */
131 while ( (*p == ' ') || (*p == '\t') ) {
136 while ( (*p != ':') && (*p != '/') && (*p != '\n') ) {
144 ppdent.pe_option = q;
145 if ( *p == '/' ) { /* translation string */
148 while ( *p != ':' && *p != '\n' ) {
155 ppdent.pe_translation = q;
157 ppdent.pe_translation = NULL;
162 while ( (*p == ' ') || (*p == '\t') ) {
168 while ( *p != '\n' ) {
180 int read_ppd( file, fcnt )
186 struct ppd_feature *pfe;
187 struct ppd_font *pfo;
190 LOG(log_error, logtype_papd, "read_ppd: %s: Too many files!", file );
194 if (( ppdfile = fopen( file, "r" )) == NULL ) {
195 LOG(log_error, logtype_papd, "read_ppd %s: %m", file );
199 while (( pe = getppdent( ppdfile )) != NULL ) {
201 if ( strcmp( pe->pe_main, "*Include" ) == 0 ) {
202 read_ppd( pe->pe_value, fcnt + 1 );
207 if ( strcmp( pe->pe_main, "*Font" ) == 0 ) {
208 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
209 if ( strcmp( pfo->pd_font, pe->pe_option ) == 0 ) {
217 if (( pfo = (struct ppd_font *)malloc( sizeof( struct ppd_font )))
219 LOG(log_error, logtype_papd, "malloc: %m" );
223 (char *)malloc( strlen( pe->pe_option ) + 1 )) == NULL ) {
224 LOG(log_error, logtype_papd, "malloc: %m" );
227 strcpy( pfo->pd_font, pe->pe_option );
228 pfo->pd_next = ppd_fonts;
235 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
236 if ( strcmp( pe->pe_main, pfe->pd_name ) == 0 ) {
240 if ( pfe->pd_name ) { /*&& (pfe->pd_value == NULL) ) { */
241 if (( pfe->pd_value =
242 (char *)malloc( strlen( pe->pe_value ) + 1 )) == NULL ) {
243 LOG(log_error, logtype_papd, "malloc: %m" );
247 strcpy( pfe->pd_value, pe->pe_value );
256 struct ppd_font *ppd_font( font )
259 struct ppd_font *pfo;
262 if ( ! ppd_inited ) {
267 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
268 if ( strcmp( pfo->pd_font, font ) == 0 ) {
275 struct ppd_feature *ppd_feature( feature, len )
279 struct ppd_feature *pfe;
280 char ppd_feature_main[ 256 ];
285 if ( ! ppd_inited ) {
290 for ( end = feature + len, p = feature, q = ppd_feature_main;
291 (p <= end) && (*p != '\n') && (*p != '\r'); p++, q++ ) {
299 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
300 if ( (strcmp( pfe->pd_name, ppd_feature_main ) == 0) && pfe->pd_value ) {