]> arthur.barton.de Git - netatalk.git/blobdiff - etc/psf/psf.c
remove most sparse warning 'symbol 'xxx' was not declared. Should it be static?'
[netatalk.git] / etc / psf / psf.c
index e92c56fe288950f14eeeeaf687b9f6e418362258..7498b93de74bdd1104f5c7ea999142191b2f9974 100644 (file)
@@ -1,9 +1,9 @@
 /*
+ * $Id: psf.c,v 1.11 2009-10-14 01:38:28 didg Exp $
+ *
  * Copyright (c) 1990,1995 Regents of The University of Michigan.
  * All Rights Reserved. See COPYRIGHT.
- */
-
-/*
+ *
  * PostScript Filter, psf.
  *
  * Handles both PostScript files and text files.  Files with the
  * a troff or dvi to PostScript converter.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #define FUCKED
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
 #include <sys/time.h>
+
+/* POSIX.1 sys/wait.h check */
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif /* HAVE_SYS_WAIT_H */
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
+#endif /* ! WEXITSTATUS */
+#ifndef WIFEXITED
+#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif /* ! WIFEXITED */
+
 #include <sys/file.h>
-#include <sys/syslog.h>
+#include <syslog.h>
 #include <atalk/paths.h>
 #include <stdio.h>
-#include <strings.h>
+#include <stdlib.h>
+#include <string.h>
 #include <ctype.h>
 #include <signal.h>
+#include <errno.h>
+
+/* Forward Declarations */
+int pexecv(char *path, char *argv[]);
+int copyio();
+int textps();
 
-char           psapath[] = _PATH_PSA;
-char           *psaargv[] = { "psa", 0, 0, 0, 0 };
+static char            psapath[] = _PATH_PSA;
+static char            *psaargv[] = { "psa", 0, 0, 0, 0 };
 
 /*
  * If we're not doing accounting, we just call pap as below.
@@ -40,23 +65,23 @@ char                *psaargv[] = { "psa", 0, 0, 0, 0 };
  * arg 4.  The second time, we call it with "-c" in arg 2, pagecount.ps
  * in arg 3, and 0 in arg 4.
  */
-char           pappath[] = _PATH_PAP;
-char           *papargv[] = { "pap", "-sstatus", 0, 0, 0, 0, 0, 0 };
+static char            pappath[] = _PATH_PAP;
+static char            *papargv[] = { "pap", "-sstatus", 0, 0, 0, 0, 0, 0 };
 
-char           revpath[] = _PATH_PSORDER;
-char           *revargv[] = { "psorder", "-d", 0 };
+static char            revpath[] = _PATH_PSORDER;
+static char            *revargv[] = { "psorder", "-d", 0 };
 
-char           *filtargv[] = { 0, 0, 0 };
+static char            *filtargv[] = { 0, 0, 0 };
 
-char           inbuf[ 1024 * 8 ];
-int            inlen;
+static char            inbuf[ 1024 * 8 ];
+static int             inlen;
 
-FILE           *acctfile = NULL;
-int            literal;
-int            width = 80, length = 66, indent = 0;
-char           *prog, *name, *host;
+static FILE            *acctfile = NULL;
+static int             literal;
+static int             width = 80, length = 66, indent = 0;
+static char            *prog, *name, *host;
 
-struct papersize {
+static struct papersize {
     int                width;
     int                length;
    float       win;
@@ -66,14 +91,12 @@ struct papersize {
     { 80, 70, 8.27, 11.69 },                   /* A4 */
 };
 
-main( ac, av ) 
-    int                ac;
-    char       **av;
+int main( int ac, char **av)
 {
     int                        c, rc, children = 0;
 #ifdef FUCKED
-    int                        psafileno, multiconn = 0, waitidle = 0, waitidle2 = 0;
-#endif FUCKED
+    int                        psafileno = 0, multiconn = 0, waitidle = 0, waitidle2 = 0;
+#endif /* FUCKED */
     int                        status;
     extern char                *optarg;
     extern int         optind, opterr;
@@ -86,9 +109,9 @@ main( ac, av )
     }
 #ifdef ultrix
     openlog( prog, LOG_PID );
-#else ultrix
+#else /* ultrix */
     openlog( prog, LOG_PID, LOG_LPR );
-#endif ultrix
+#endif /* ultrix */
 
     while (( c = getopt( ac, av, "P:C:D:F:L:J:x:y:n:h:w:l:i:c" )) != EOF ) {
        switch ( c ) {
@@ -109,7 +132,7 @@ main( ac, av )
            if ( width == 0 ) {
                width = 80;
            }
-#endif ZEROWIDTH
+#endif /* ZEROWIDTH */
            break;
 
        case 'l' :
@@ -136,7 +159,7 @@ main( ac, av )
        default :
            syslog( LOG_ERR, "bad option: %c", c );
            exit( 2 );
-#endif notdef
+#endif /* notdef */
        }
     }
     if ( ac - optind > 1 ) {
@@ -153,13 +176,13 @@ main( ac, av )
     if ( index( prog, 'm' )) {
        multiconn++;
     }
-#endif FUCKED
+#endif /* FUCKED */
 
     syslog( LOG_INFO, "starting for %s", name ? name : "?" );
 
 restart:
     if (( inlen = read( 0, inbuf, sizeof( inbuf ))) < 0 ) {
-       syslog( LOG_ERR, "read: %m" );
+       syslog( LOG_ERR, "read: %s", strerror(errno) );
        exit( 1 );
     }
     if ( inlen == 0 ) {        /* nothing to be done */
@@ -177,7 +200,7 @@ restart:
        psaargv[ 2 ] = name;
        psaargv[ 3 ] = host;
        if (( c = pexecv( psapath, psaargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %m", psapath );
+           syslog( LOG_ERR, "%s: %s", psapath, strerror(errno) );
            exit( 2 );
        }
        children++;
@@ -226,7 +249,7 @@ restart:
                papargv[ 5 ] = _PATH_PAGECOUNT;
                papargv[ 6 ] = 0;
            }
-#endif FUCKED
+#endif /* FUCKED */
        } else {
            papargv[ 2 ] = "-c";
            papargv[ 3 ] = "-E";
@@ -234,7 +257,7 @@ restart:
        }
 
        if (( c = pexecv( pappath, papargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %m", pappath );
+           syslog( LOG_ERR, "%s: %s", pappath, strerror(errno) );
            exit( 2 );
        }
        children++;
@@ -247,7 +270,7 @@ restart:
      */
     if ( strstr( prog, "rev" ) != NULL ) {
        if (( c = pexecv( revpath, revargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %m", revpath );
+           syslog( LOG_ERR, "%s: %s", revpath, strerror(errno) );
            exit( 2 );
        }
        syslog( LOG_INFO, "sending to rev[%d]", c );
@@ -261,7 +284,7 @@ restart:
     if ( *prog != 'i' && *prog != 'o' && *( prog + 1 ) == 'f' ) {
        filtargv[ 0 ] = filtargv[ 1 ] = prog;
        if (( c = pexecv( _PATH_PSFILTER, filtargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %m", _PATH_PSFILTER );
+           syslog( LOG_ERR, "%s: %s", _PATH_PSFILTER, strerror(errno) );
            exit( 2 );
        }
        syslog( LOG_INFO, "external filter[%d]", c );
@@ -299,26 +322,26 @@ restart:
        }
 
        if (( c = pexecv( pappath, papargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %m", pappath );
+           syslog( LOG_ERR, "%s: %s", pappath, strerror(errno) );
            exit( 2 );
        }
        children++;
        syslog( LOG_INFO, "pagecount with pap[%d]", c );
     }
-#endif FUCKED
+#endif /* FUCKED */
 
     if ( children ) {
        close( 1 );
     }
     while ( children ) {
        if (( c = wait3( &status, 0, 0 )) < 0 ) {
-           syslog( LOG_ERR, "wait3: %m" );
+           syslog( LOG_ERR, "wait3: %s", strerror(errno) );
            exit( 1 );
        }
        if ( WIFEXITED( status )) {
 #ifndef WEXITSTATUS
 #define WEXITSTATUS(x) ((x).w_status)
-#endif WEXITSTATUS
+#endif /* WEXITSTATUS */
            if ( WEXITSTATUS( status ) != 0 ) {
                syslog( LOG_ERR, "%d died with %d", c, WEXITSTATUS( status ));
                exit( WEXITSTATUS( status ));
@@ -343,7 +366,7 @@ restart:
     exit( rc );
 }
 
-copyio()
+int copyio(void)
 {
     /* implement the FSM needed to do the suspend. Note that
      * the last characters will be \031\001 so don't worry
@@ -353,7 +376,7 @@ copyio()
      */
     struct timeval     tv;
     fd_set             fdset;
-    int                        ctl = 0, i;
+    int                        ctl = 0;
 
 notdone:
     do {
@@ -371,7 +394,7 @@ notdone:
                    break;
                }
                if ( write( 1, "\031", 1 ) != 1 ) {
-                   syslog( LOG_ERR, "write: %m" );
+                   syslog( LOG_ERR, "write: %s", strerror(errno) );
                    return( 1 );
                }
                ctl = 0;
@@ -384,7 +407,7 @@ notdone:
        } else {
            if ( ctl == 1 ) {
                if ( write( 1, "\031", 1 ) != 1 ) {
-                   syslog( LOG_ERR, "write: %m" );
+                   syslog( LOG_ERR, "write: %s", strerror(errno) );
                    return( 1 );
                }
            }
@@ -399,7 +422,7 @@ notdone:
 
        inlen -= ctl;
        if (( inlen > 0 ) && ( write( 1, inbuf, inlen ) != inlen )) {
-           syslog( LOG_ERR, "write: %m" );
+           syslog( LOG_ERR, "write: %s", strerror(errno) );
            return( 1 );
        }
        if ( ctl == 2 ) {
@@ -420,13 +443,13 @@ notdone:
     }
 
     if ( inlen < 0 ) {
-       syslog( LOG_ERR, "read: %m" );
+       syslog( LOG_ERR, "read: %s", strerror(errno) );
        return( 1 );
     }
 
     if ( ctl == 1 ) {
        if ( write( 1, "\031", 1 ) != 1 ) {
-           syslog( LOG_ERR, "write: %m" );
+           syslog( LOG_ERR, "write: %s", strerror(errno) );
            return( 1 );
        }
     } else if ( ctl == 2 ) {
@@ -435,10 +458,10 @@ notdone:
     return( 0 );
 }
 
-char           *font = "Courier";
-int            point = 11;
+static char            *font = "Courier";
+static int             point = 11;
 
-char           pspro[] = "\
+static char            pspro[] = "\
 /GSV save def                                          % global VM\n\
 /SP {\n\
        /SV save def                                    % save vmstate\n\
@@ -457,10 +480,11 @@ char              pspro[] = "\
 /EP { SV restore showpage } bind def\n\
 %%EndProlog\n";
 
-textps()
+int textps(void)
 {
     struct papersize   papersize;
-    int                        state = 0, line = 0, col = 0, npages = 0, rc, i;
+    int                        state = 0, line = 0, col = 0, npages = 0, rc;
+    unsigned int       i;
     char               *p, *end;
 
 #define elements(x)    (sizeof(x)/sizeof((x)[0]))
@@ -496,7 +520,7 @@ textps()
                    /* output postscript prologue: */
                    if ( write( 1, pspro, sizeof( pspro ) - 1 ) !=
                            sizeof( pspro ) - 1 ) {
-                       syslog( LOG_ERR, "write prologue: %m" );
+                       syslog( LOG_ERR, "write prologue: %s", strerror(errno) );
                        return( 1 );
                    }
                    if ( name && host ) {
@@ -511,12 +535,24 @@ textps()
                state |= ST_PAGE;
            }
            if ( state & ST_CONTROL && *p != '\001' ) {
+               /* It is a very bad thing to toss a job because it contains
+                * unprintable characters.  Instead, we will convert them to
+                * question marks.  This is adapted from a solution described
+                * by Werner Eugster <eugster@giub.unibe.ch> on his ApplePrint
+                * webpage (http://www.giub.unibe.ch/~eugster/appleprint.html).
+                *
+                * Note that this is rather ugly code.  The same change is
+                * applied identically at two different locations in this file.
+                * It would be better someday to combine the two.
+                */
                if ( !literal ) {
-                   fprintf( stderr, "unprintable character (0x%x)!\n",
-                           (unsigned char)031 );
-                   return( 2 );        /* Toss job */
+                       fprintf( stderr,
+                               "unprintable character (0x%x) converted to ?!\n",
+                               (unsigned char)*p );
+                       putchar( '?' ); /* Replace unprintable char with a question mark. */
+               } else {
+                       printf( "\\%o", (unsigned char)031 );
                }
-               printf( "\\%o", (unsigned char)031 );
                state &= ~ST_CONTROL;
                col++;
            }
@@ -606,11 +642,13 @@ textps()
                }
                if ( !isascii( *p ) || !isprint( *p )) {
                    if ( !literal ) {
-                       fprintf( stderr, "unprintable character (0x%x)!\n",
-                               (unsigned char)*p );
-                       return( 2 );    /* Toss job */
+                        fprintf( stderr,
+                           "unprintable character (0x%x) converted to ?!\n",
+                           (unsigned char)*p );
+                       putchar( '?' ); /* Replace unprintable char with a question mark. */
+                   } else {
+                       printf( "\\%o", (unsigned char)*p );
                    }
-                   printf( "\\%o", (unsigned char)*p );
                } else {
                    putchar( *p );
                }
@@ -621,7 +659,7 @@ textps()
        }
     } while (( inlen = read( 0, inbuf, sizeof( inbuf ))) > 0 );
     if ( inlen < 0 ) {
-       syslog( LOG_ERR, "read: %m" );
+       syslog( LOG_ERR, "read: %s", strerror(errno) );
        return( 1 );
     }
     rc = 0;
@@ -651,8 +689,7 @@ out:
  * Manipulates file descriptors 0, 1, and 2, such that the new child
  * is reading from the parent's output.
  */
-pexecv( path, argv )
-    char       *path, *argv[];
+int pexecv( char *path, char *argv[])
 {
     int                fd[ 2 ], c;