2 * Copyright (c) 1995 Regents of The University of Michigan.
3 * All Rights Reserved. See COPYRIGHT.
9 #include <sys/syslog.h>
10 #include <sys/types.h>
11 #include <sys/param.h>
13 #include <netatalk/at.h>
14 #include <atalk/atp.h>
19 struct ppd_font *ppd_fonts = NULL;
21 struct ppd_feature ppd_features[] = {
22 { "*LanguageLevel", 0 },
29 { "*ColorDevice", 0 },
31 { "*TTRasterizer", 0 },
47 struct ppd_feature *pfe;
51 fprintf( stderr, "Usage:\t%s ppdfile\n", av[ 0 ] );
55 read_ppd( av[ 1 ], 0 );
56 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
57 printf( "Font: %s\n", pfo->pd_font );
59 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
60 printf( "Feature: %s %s\n", pfe->pd_name, pfe->pd_value );
76 read_ppd( printer->p_ppdfile, 0 );
83 static char buf[ 1024 ];
84 static struct ppdent ppdent;
87 ppdent.pe_main = ppdent.pe_option = ppdent.pe_translation =
88 ppdent.pe_value = NULL;
90 while (( p = fgets( buf, sizeof( buf ), stream )) != NULL ) {
91 if ( *p != '*' ) { /* main key word */
94 if ( p[ strlen( p ) - 1 ] != '\n' ) {
95 syslog( LOG_ERR, "getppdent: line too long" );
100 while ( *p != ' ' && *p != '\t' && *p != ':' && *p != '\n' ) {
103 if ( *( q + 1 ) == '%' || *( q + 1 ) == '?' ) { /* comments & queries */
109 ppdent.pe_option = ppdent.pe_translation = ppdent.pe_value = NULL;
113 if ( *p != ':' ) { /* option key word */
116 while ( *p == ' ' || *p == '\t' ) {
121 while ( *p != ':' && *p != '/' && *p != '\n' ) {
129 ppdent.pe_option = q;
130 if ( *p == '/' ) { /* translation string */
133 while ( *p != ':' && *p != '\n' ) {
140 ppdent.pe_translation = q;
142 ppdent.pe_translation = NULL;
147 while ( *p == ' ' || *p == '\t' ) {
156 while ( *p != '"' && *p != '\n' ) {
167 while ( *p != '\n' ) {
179 read_ppd( file, fcnt )
185 struct ppd_feature *pfe;
186 struct ppd_font *pfo;
189 syslog( LOG_ERR, "read_ppd: %s: Too many files!", file );
193 if (( ppdfile = fopen( file, "r" )) == NULL ) {
194 syslog( LOG_ERR, "read_ppd %s: %m", file );
198 while (( pe = getppdent( ppdfile )) != NULL ) {
200 if ( strcmp( pe->pe_main, "*Include" ) == 0 ) {
201 read_ppd( pe->pe_value, fcnt + 1 );
206 if ( strcmp( pe->pe_main, "*Font" ) == 0 ) {
207 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
208 if ( strcmp( pfo->pd_font, pe->pe_option ) == 0 ) {
216 if (( pfo = (struct ppd_font *)malloc( sizeof( struct ppd_font )))
218 syslog( LOG_ERR, "malloc: %m" );
222 (char *)malloc( strlen( pe->pe_option ) + 1 )) == NULL ) {
223 syslog( LOG_ERR, "malloc: %m" );
226 strcpy( pfo->pd_font, pe->pe_option );
227 pfo->pd_next = ppd_fonts;
234 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
235 if ( strcmp( pe->pe_main, pfe->pd_name ) == 0 ) {
239 if ( pfe->pd_name && pfe->pd_value == NULL ) {
240 if (( pfe->pd_value =
241 (char *)malloc( strlen( pe->pe_value ) + 1 )) == NULL ) {
242 syslog( LOG_ERR, "malloc: %m" );
246 strcpy( pfe->pd_value, pe->pe_value );
259 struct ppd_font *pfo;
261 if ( ! ppd_inited ) {
265 for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
266 if ( strcmp( pfo->pd_font, font ) == 0 ) {
274 ppd_feature( feature, len )
278 struct ppd_feature *pfe;
282 if ( ! ppd_inited ) {
286 for ( end = feature + len, p = feature, q = main;
287 p <= end && *p != '\n' && *p != '\r'; p++, q++ ) {
295 for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
296 if ( strcmp( pfe->pd_name, main ) == 0 && pfe->pd_value ) {