2 * Copyright (c) 1995 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
13 #include <sys/syslog.h>
14 #include <sys/types.h>
15 #include <sys/param.h>
17 #include <netatalk/at.h>
18 #include <atalk/atp.h>
23 struct ppd_font *ppd_fonts = NULL;
25 struct ppd_feature ppd_features[] = {
26 { "*LanguageLevel", 0 },
33 { "*ColorDevice", 0 },
35 { "*TTRasterizer", 0 },
56 return read_ppd( printer->p_ppdfile, 0 );
60 struct ppdent *getppdent( stream )
63 static char buf[ 1024 ];
64 static struct ppdent ppdent;
67 ppdent.pe_main = ppdent.pe_option = ppdent.pe_translation =
68 ppdent.pe_value = NULL;
70 while (( p = fgets( buf, sizeof( buf ), stream )) != NULL ) {
71 if ( *p != '*' ) { /* main key word */
74 if ( p[ strlen( p ) - 1 ] != '\n' ) {
75 syslog( LOG_ERR, "getppdent: line too long" );
80 while ( (*p != ' ') && (*p != '\t') && (*p != ':') && (*p != '\n') ) {
83 if ( (*( q + 1 ) == '%') || (*( q + 1 ) == '?') ) { /* comments & queries */
89 ppdent.pe_option = ppdent.pe_translation = ppdent.pe_value = NULL;
93 if ( *p != ':' ) { /* option key word */
96 while ( (*p == ' ') || (*p == '\t') ) {
101 while ( (*p != ':') && (*p != '/') && (*p != '\n') ) {
109 ppdent.pe_option = q;
110 if ( *p == '/' ) { /* translation string */
113 while ( *p != ':' && *p != '\n' ) {
120 ppdent.pe_translation = q;
122 ppdent.pe_translation = NULL;
127 while ( (*p == ' ') || (*p == '\t') ) {
133 while ( *p != '\n' ) {
145 int read_ppd( file, fcnt )
151 struct ppd_feature *pfe;
152 struct ppd_font *pfo;
155 syslog( LOG_ERR, "read_ppd: %s: Too many files!", file );
159 if (( ppdfile = fopen( file, "r" )) == NULL ) {
160 syslog( LOG_ERR, "read_ppd %s: %m", file );
164 while (( pe = getppdent( ppdfile )) != NULL ) {
166 if ( strcmp( pe->pe_main, "*Include" ) == 0 ) {
167 read_ppd( pe->pe_value, fcnt + 1 );
172 if ( strcmp( pe->pe_main, "*Font" ) == 0 ) {
173 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
174 if ( strcmp( pfo->pd_font, pe->pe_option ) == 0 ) {
182 if (( pfo = (struct ppd_font *)malloc( sizeof( struct ppd_font )))
184 syslog( LOG_ERR, "malloc: %m" );
188 (char *)malloc( strlen( pe->pe_option ) + 1 )) == NULL ) {
189 syslog( LOG_ERR, "malloc: %m" );
192 strcpy( pfo->pd_font, pe->pe_option );
193 pfo->pd_next = ppd_fonts;
200 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
201 if ( strcmp( pe->pe_main, pfe->pd_name ) == 0 ) {
205 if ( pfe->pd_name && (pfe->pd_value == NULL) ) {
206 if (( pfe->pd_value =
207 (char *)malloc( strlen( pe->pe_value ) + 1 )) == NULL ) {
208 syslog( LOG_ERR, "malloc: %m" );
212 strcpy( pfe->pd_value, pe->pe_value );
221 struct ppd_font *ppd_font( font )
224 struct ppd_font *pfo;
227 if ( ! ppd_inited ) {
232 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
233 if ( strcmp( pfo->pd_font, font ) == 0 ) {
240 struct ppd_feature *ppd_feature( feature, len )
244 struct ppd_feature *pfe;
245 char ppd_feature_main[ 256 ];
250 if ( ! ppd_inited ) {
255 for ( end = feature + len, p = feature, q = ppd_feature_main;
256 (p <= end) && (*p != '\n') && (*p != '\r'); p++, q++ ) {
264 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
265 if ( (strcmp( pfe->pd_name, ppd_feature_main ) == 0) && pfe->pd_value ) {