/*
+ * $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 <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
+#include <errno.h>
/* Forward Declarations */
int pexecv(char *path, char *argv[]);
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;
}
#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 ) {
if ( width == 0 ) {
width = 80;
}
-#endif ZEROWIDTH
+#endif /* ZEROWIDTH */
break;
case 'l' :
default :
syslog( LOG_ERR, "bad option: %c", c );
exit( 2 );
-#endif notdef
+#endif /* notdef */
}
}
if ( ac - optind > 1 ) {
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 */
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++;
papargv[ 5 ] = _PATH_PAGECOUNT;
papargv[ 6 ] = 0;
}
-#endif FUCKED
+#endif /* FUCKED */
} else {
papargv[ 2 ] = "-c";
papargv[ 3 ] = "-E";
}
if (( c = pexecv( pappath, papargv )) < 0 ) {
- syslog( LOG_ERR, "%s: %m", pappath );
+ syslog( LOG_ERR, "%s: %s", pappath, strerror(errno) );
exit( 2 );
}
children++;
*/
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 );
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 );
}
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 ));
break;
}
if ( write( 1, "\031", 1 ) != 1 ) {
- syslog( LOG_ERR, "write: %m" );
+ syslog( LOG_ERR, "write: %s", strerror(errno) );
return( 1 );
}
ctl = 0;
} else {
if ( ctl == 1 ) {
if ( write( 1, "\031", 1 ) != 1 ) {
- syslog( LOG_ERR, "write: %m" );
+ syslog( LOG_ERR, "write: %s", strerror(errno) );
return( 1 );
}
}
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 ) {
}
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 ) {
/* 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 ) {
}
} 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;