2 * $Id: ppd.c,v 1.6 2001-06-25 20:13:45 rufustfirefly Exp $
4 * Copyright (c) 1995 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
15 #include <sys/syslog.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 },
35 { "*ColorDevice", 0 },
37 { "*TTRasterizer", 0 },
58 return read_ppd( printer->p_ppdfile, 0 );
62 struct ppdent *getppdent( stream )
65 static char buf[ 1024 ];
66 static struct ppdent ppdent;
69 ppdent.pe_main = ppdent.pe_option = ppdent.pe_translation =
70 ppdent.pe_value = NULL;
72 while (( p = fgets( buf, sizeof( buf ), stream )) != NULL ) {
73 if ( *p != '*' ) { /* main key word */
76 if ( p[ strlen( p ) - 1 ] != '\n' ) {
77 syslog( LOG_ERR, "getppdent: line too long" );
82 while ( (*p != ' ') && (*p != '\t') && (*p != ':') && (*p != '\n') ) {
85 if ( (*( q + 1 ) == '%') || (*( q + 1 ) == '?') ) { /* comments & queries */
91 ppdent.pe_option = ppdent.pe_translation = ppdent.pe_value = NULL;
95 if ( *p != ':' ) { /* option key word */
98 while ( (*p == ' ') || (*p == '\t') ) {
103 while ( (*p != ':') && (*p != '/') && (*p != '\n') ) {
111 ppdent.pe_option = q;
112 if ( *p == '/' ) { /* translation string */
115 while ( *p != ':' && *p != '\n' ) {
122 ppdent.pe_translation = q;
124 ppdent.pe_translation = NULL;
129 while ( (*p == ' ') || (*p == '\t') ) {
135 while ( *p != '\n' ) {
147 int read_ppd( file, fcnt )
153 struct ppd_feature *pfe;
154 struct ppd_font *pfo;
157 syslog( LOG_ERR, "read_ppd: %s: Too many files!", file );
161 if (( ppdfile = fopen( file, "r" )) == NULL ) {
162 syslog( LOG_ERR, "read_ppd %s: %m", file );
166 while (( pe = getppdent( ppdfile )) != NULL ) {
168 if ( strcmp( pe->pe_main, "*Include" ) == 0 ) {
169 read_ppd( pe->pe_value, fcnt + 1 );
174 if ( strcmp( pe->pe_main, "*Font" ) == 0 ) {
175 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
176 if ( strcmp( pfo->pd_font, pe->pe_option ) == 0 ) {
184 if (( pfo = (struct ppd_font *)malloc( sizeof( struct ppd_font )))
186 syslog( LOG_ERR, "malloc: %m" );
190 (char *)malloc( strlen( pe->pe_option ) + 1 )) == NULL ) {
191 syslog( LOG_ERR, "malloc: %m" );
194 strcpy( pfo->pd_font, pe->pe_option );
195 pfo->pd_next = ppd_fonts;
202 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
203 if ( strcmp( pe->pe_main, pfe->pd_name ) == 0 ) {
207 if ( pfe->pd_name && (pfe->pd_value == NULL) ) {
208 if (( pfe->pd_value =
209 (char *)malloc( strlen( pe->pe_value ) + 1 )) == NULL ) {
210 syslog( LOG_ERR, "malloc: %m" );
214 strcpy( pfe->pd_value, pe->pe_value );
223 struct ppd_font *ppd_font( font )
226 struct ppd_font *pfo;
229 if ( ! ppd_inited ) {
234 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
235 if ( strcmp( pfo->pd_font, font ) == 0 ) {
242 struct ppd_feature *ppd_feature( feature, len )
246 struct ppd_feature *pfe;
247 char ppd_feature_main[ 256 ];
252 if ( ! ppd_inited ) {
257 for ( end = feature + len, p = feature, q = ppd_feature_main;
258 (p <= end) && (*p != '\n') && (*p != '\r'); p++, q++ ) {
266 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
267 if ( (strcmp( pfe->pd_name, ppd_feature_main ) == 0) && pfe->pd_value ) {