]> arthur.barton.de Git - netatalk.git/blobdiff - etc/psf/psf.c
replaced all #include <sys/syslog.h> with #include <syslog.h>
[netatalk.git] / etc / psf / psf.c
index e7dd5d567356601196dbb57cbe8511c85f6b07b1..d70c2e79e78d08f766bded82c74df8b7d902c976 100644 (file)
@@ -1,9 +1,9 @@
 /*
+ * $Id: psf.c,v 1.7 2002-01-03 17:49:39 sibaz 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
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#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 };
@@ -70,14 +91,14 @@ struct papersize {
     { 80, 70, 8.27, 11.69 },                   /* A4 */
 };
 
-main( ac, av ) 
+int main( ac, av ) 
     int                ac;
     char       **av;
 {
     int                        c, rc, children = 0;
 #ifdef FUCKED
     int                        psafileno, multiconn = 0, waitidle = 0, waitidle2 = 0;
-#endif FUCKED
+#endif /* FUCKED */
     int                        status;
     extern char                *optarg;
     extern int         optind, opterr;
@@ -90,9 +111,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 ) {
@@ -113,7 +134,7 @@ main( ac, av )
            if ( width == 0 ) {
                width = 80;
            }
-#endif ZEROWIDTH
+#endif /* ZEROWIDTH */
            break;
 
        case 'l' :
@@ -140,7 +161,7 @@ main( ac, av )
        default :
            syslog( LOG_ERR, "bad option: %c", c );
            exit( 2 );
-#endif notdef
+#endif /* notdef */
        }
     }
     if ( ac - optind > 1 ) {
@@ -157,13 +178,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 */
@@ -181,7 +202,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++;
@@ -230,7 +251,7 @@ restart:
                papargv[ 5 ] = _PATH_PAGECOUNT;
                papargv[ 6 ] = 0;
            }
-#endif FUCKED
+#endif /* FUCKED */
        } else {
            papargv[ 2 ] = "-c";
            papargv[ 3 ] = "-E";
@@ -238,7 +259,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++;
@@ -251,7 +272,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 );
@@ -265,7 +286,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 );
@@ -303,26 +324,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 ));
@@ -347,7 +368,7 @@ restart:
     exit( rc );
 }
 
-copyio()
+int copyio()
 {
     /* implement the FSM needed to do the suspend. Note that
      * the last characters will be \031\001 so don't worry
@@ -357,7 +378,7 @@ copyio()
      */
     struct timeval     tv;
     fd_set             fdset;
-    int                        ctl = 0, i;
+    int                        ctl = 0;
 
 notdone:
     do {
@@ -375,7 +396,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;
@@ -388,7 +409,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 );
                }
            }
@@ -403,7 +424,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 ) {
@@ -424,13 +445,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 ) {
@@ -461,7 +482,7 @@ char                pspro[] = "\
 /EP { SV restore showpage } bind def\n\
 %%EndProlog\n";
 
-textps()
+int textps()
 {
     struct papersize   papersize;
     int                        state = 0, line = 0, col = 0, npages = 0, rc, i;
@@ -500,7 +521,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 ) {
@@ -625,7 +646,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;
@@ -655,7 +676,7 @@ out:
  * Manipulates file descriptors 0, 1, and 2, such that the new child
  * is reading from the parent's output.
  */
-pexecv( path, argv )
+int pexecv( path, argv )
     char       *path, *argv[];
 {
     int                fd[ 2 ], c;