X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fpapd%2Fppd.c;h=f16469289f9a4af9af93cba62fad839025affefe;hb=cb8de5b604041071f3454dd8df97295544caba59;hp=dcaea66fc91f8bc8b25868cb1959dd9741b194a4;hpb=a4dd261e90b2e3a6dae1ce17ff344b2315f4e098;p=netatalk.git diff --git a/etc/papd/ppd.c b/etc/papd/ppd.c index dcaea66f..f1646928 100644 --- a/etc/papd/ppd.c +++ b/etc/papd/ppd.c @@ -1,5 +1,5 @@ /* - * $Id: ppd.c,v 1.9 2002-09-29 23:29:14 sibaz Exp $ + * $Id: ppd.c,v 1.17 2009-10-14 02:24:05 didg Exp $ * * Copyright (c) 1995 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -25,17 +26,21 @@ struct ppd_font *ppd_fonts = NULL; struct ppd_feature ppd_features[] = { - { "*LanguageLevel", 0 }, - { "*PSVersion", 0 }, - { "*FreeVM", 0 }, - { "*Product", 0 }, - { "*PCFileName", 0 }, - { "*ModelName", 0 }, - { "*NickName", 0 }, - { "*ColorDevice", 0 }, - { "*FaxSupport", 0 }, - { "*TTRasterizer", 0 }, - { 0, 0 }, + { "*LanguageLevel", NULL }, + { "*PSVersion", NULL }, +#ifdef HAVE_CUPS + { "*FreeVM", "33554432" }, +#else + { "*FreeVM", NULL }, +#endif + { "*Product", NULL }, + { "*PCFileName", NULL }, + { "*ModelName", NULL }, + { "*NickName", NULL }, + { "*ColorDevice", NULL }, + { "*FaxSupport", NULL }, + { "*TTRasterizer", NULL }, + { NULL, NULL }, }; struct ppdent { @@ -46,21 +51,47 @@ struct ppdent { }; #ifndef SHOWPPD -int ppd_inited = 0; +static int ppd_inited; -int ppd_init() +static void ppd_init(void) { - if ( ppd_inited ) { - return( -1 ); - } + if (ppd_inited) + return; + ppd_inited++; - return read_ppd( printer->p_ppdfile, 0 ); + if (printer->p_ppdfile) + read_ppd( printer->p_ppdfile, 0 ); } #endif /* SHOWPPD */ -struct ppdent *getppdent( stream ) - FILE *stream; + +/* quick and ugly hack to be able to read + ppd files with Mac line ending */ +static char* my_fgets(char *buf, size_t bufsize, FILE *stream) +{ + int p; /* uninitialized, OK 310105 */ + size_t count = 0; + + while (count < (bufsize - 1) && EOF != (p=fgetc(stream))) { + buf[count] = p; + count++; + if ( p == '\r' || p == '\n') + break; + } + + if (p == EOF && count == 0) + return NULL; + + /* translate line endings */ + if ( buf[count - 1] == '\r') + buf[count - 1] = '\n'; + + buf[count] = 0; + return buf; +} + +static struct ppdent *getppdent( FILE *stream) { static char buf[ 1024 ]; static struct ppdent ppdent; @@ -69,11 +100,11 @@ struct ppdent *getppdent( stream ) ppdent.pe_main = ppdent.pe_option = ppdent.pe_translation = ppdent.pe_value = NULL; - while (( p = fgets( buf, sizeof( buf ), stream )) != NULL ) { + while (( p = my_fgets( buf, sizeof( buf ), stream )) != NULL ) { if ( *p != '*' ) { /* main key word */ continue; } - if ( p[ strlen( p ) - 1 ] != '\n' ) { + if ( p[ strlen( p ) - 1 ] != '\n') { LOG(log_error, logtype_papd, "getppdent: line too long" ); continue; } @@ -144,9 +175,7 @@ struct ppdent *getppdent( stream ) return( NULL ); } -int read_ppd( file, fcnt ) - char *file; - int fcnt; +int read_ppd(char *file, int fcnt) { FILE *ppdfile; struct ppdent *pe; @@ -159,7 +188,7 @@ int read_ppd( file, fcnt ) } if (( ppdfile = fopen( file, "r" )) == NULL ) { - LOG(log_error, logtype_papd, "read_ppd %s: %m", file ); + LOG(log_error, logtype_papd, "read_ppd %s: %s", file, strerror(errno) ); return( -1 ); } @@ -171,7 +200,7 @@ int read_ppd( file, fcnt ) } /* *Font */ - if ( strcmp( pe->pe_main, "*Font" ) == 0 ) { + if ( strcmp( pe->pe_main, "*Font" ) == 0 && pe->pe_option ) { for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) { if ( strcmp( pfo->pd_font, pe->pe_option ) == 0 ) { break; @@ -183,12 +212,12 @@ int read_ppd( file, fcnt ) if (( pfo = (struct ppd_font *)malloc( sizeof( struct ppd_font ))) == NULL ) { - LOG(log_error, logtype_papd, "malloc: %m" ); + LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) ); exit( 1 ); } if (( pfo->pd_font = (char *)malloc( strlen( pe->pe_option ) + 1 )) == NULL ) { - LOG(log_error, logtype_papd, "malloc: %m" ); + LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) ); exit( 1 ); } strcpy( pfo->pd_font, pe->pe_option ); @@ -204,10 +233,10 @@ int read_ppd( file, fcnt ) break; } } - if ( pfe->pd_name && (pfe->pd_value == NULL) ) { + if ( pfe->pd_name && pe->pe_value ) { if (( pfe->pd_value = (char *)malloc( strlen( pe->pe_value ) + 1 )) == NULL ) { - LOG(log_error, logtype_papd, "malloc: %m" ); + LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) ); exit( 1 ); } @@ -220,8 +249,7 @@ int read_ppd( file, fcnt ) return( 0 ); } -struct ppd_font *ppd_font( font ) - char *font; +struct ppd_font *ppd_font( char *font) { struct ppd_font *pfo; @@ -239,9 +267,7 @@ struct ppd_font *ppd_font( font ) return( NULL ); } -struct ppd_feature *ppd_feature( feature, len ) - const char *feature; - int len; +struct ppd_feature *ppd_feature( const char *feature, int len) { struct ppd_feature *pfe; char ppd_feature_main[ 256 ]; @@ -254,6 +280,9 @@ struct ppd_feature *ppd_feature( feature, len ) } #endif /* SHOWPPD */ + if (len > sizeof(ppd_feature_main) -1) + return( NULL ); + for ( end = feature + len, p = feature, q = ppd_feature_main; (p <= end) && (*p != '\n') && (*p != '\r'); p++, q++ ) { *q = *p;