]> arthur.barton.de Git - netatalk.git/blobdiff - etc/papd/ppd.c
replace remaining %m printf glibc extension with %s strerror(errno)
[netatalk.git] / etc / papd / ppd.c
index c0a4e59bc63cd9620595b31279304ab9cead52bb..c4f7c69f88691d55a0953089abad4d08d90c7a35 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ppd.c,v 1.6 2001-06-25 20:13:45 rufustfirefly Exp $
+ * $Id: ppd.c,v 1.9.8.1.2.3 2008-11-14 10:04:52 didg Exp $
  *
  * Copyright (c) 1995 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -12,7 +12,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/syslog.h>
+#include <errno.h>
+#include <atalk/logger.h>
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/time.h>
@@ -27,7 +28,11 @@ struct ppd_font              *ppd_fonts = NULL;
 struct ppd_feature     ppd_features[] = {
     { "*LanguageLevel",        0 },
     { "*PSVersion",    0 },
+#ifdef HAVE_CUPS
+    { "*FreeVM",       "33554432" },
+#else
     { "*FreeVM",       0 },
+#endif
     { "*Product",      0 },
     { "*PCFileName",   0 },
     { "*ModelName",    0 },
@@ -59,6 +64,35 @@ int ppd_init()
 }
 #endif /* SHOWPPD */
 
+
+/* quick and ugly hack to be able to read
+   ppd files with Mac line ending */
+static char* my_fgets(buf, bufsize, stream) 
+    char   *buf;
+    size_t bufsize;
+    FILE   *stream;
+{
+    int p;           /* uninitialized, OK 310105 */
+    size_t count = 0;
+    while (count < bufsize && 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;
+}
+
 struct ppdent *getppdent( stream )
     FILE       *stream;
 {
@@ -69,12 +103,12 @@ 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' ) {
-           syslog( LOG_ERR, "getppdent: line too long" );
+       if ( p[ strlen( p ) - 1 ] != '\n' && p[ strlen( p ) - 1 ] != '\r') {
+           LOG(log_error, logtype_papd, "getppdent: line too long" );
            continue;
        }
 
@@ -154,12 +188,12 @@ int read_ppd( file, fcnt )
     struct ppd_font    *pfo;
 
     if ( fcnt > 20 ) {
-       syslog( LOG_ERR, "read_ppd: %s: Too many files!", file );
+       LOG(log_error, logtype_papd, "read_ppd: %s: Too many files!", file );
        return( -1 );
     }
 
     if (( ppdfile = fopen( file, "r" )) == NULL ) {
-       syslog( LOG_ERR, "read_ppd %s: %m", file );
+       LOG(log_error, logtype_papd, "read_ppd %s: %s", file, strerror(errno) );
        return( -1 );
     }
 
@@ -183,12 +217,12 @@ int read_ppd( file, fcnt )
 
            if (( pfo = (struct ppd_font *)malloc( sizeof( struct ppd_font )))
                    == NULL ) {
-               syslog( LOG_ERR, "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 ) {
-               syslog( LOG_ERR, "malloc: %m" );
+               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
                exit( 1 );
            }
            strcpy( pfo->pd_font, pe->pe_option );
@@ -204,10 +238,10 @@ int read_ppd( file, fcnt )
                break;
            }
        }
-       if ( pfe->pd_name && (pfe->pd_value == NULL) ) {
+       if ( pfe->pd_name ) { /*&& (pfe->pd_value == NULL) ) { */
            if (( pfe->pd_value =
                    (char *)malloc( strlen( pe->pe_value ) + 1 )) == NULL ) {
-               syslog( LOG_ERR, "malloc: %m" );
+               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
                exit( 1 );
            }