]> arthur.barton.de Git - netatalk.git/blobdiff - etc/papd/magics.c
replaced all #include <sys/syslog.h> with #include <syslog.h>
[netatalk.git] / etc / papd / magics.c
index dea2c009ab0f8db842e8fd796107bcc4e397fa49..f9180ae7ea9642be2984d68341de9ef936f0469f 100644 (file)
@@ -1,25 +1,37 @@
 /*
+ * $Id: magics.c,v 1.8 2002-01-03 17:49:39 sibaz Exp $
+ *
  * Copyright (c) 1990,1994 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
  */
 
-#include <sys/syslog.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <syslog.h>
 #include <sys/param.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
+
+#include <netatalk/at.h>
 
 #include "file.h"
 #include "comment.h"
+#include "lp.h"
 
-ps( infile, outfile )
+int ps( infile, outfile, sat )
     struct papfile     *infile, *outfile;
+    struct sockaddr_at *sat;
 {
-    char                       *start, *stop;
-    struct comment             *comment;
+    char                       *start;
+    int                                linelength, crlflength;
+    struct papd_comment                *comment;
 
     for (;;) {
-       if ( comment = compeek()) {
-           switch( (*comment->c_handler)( infile, outfile )) {
+       if ( (comment = compeek()) ) {
+           switch( (*comment->c_handler)( infile, outfile, sat )) {
            case CH_DONE :
                continue;
 
@@ -31,7 +43,7 @@ ps( infile, outfile )
            }
 
        } else {
-           switch ( markline( &start, &stop, infile )) {
+           switch ( markline( infile, &start, &linelength, &crlflength )) {
            case 0 :
                /* eof on infile */
                outfile->pf_state |= PF_EOF;
@@ -43,35 +55,36 @@ ps( infile, outfile )
            }
 
            if ( infile->pf_state & PF_BOT ) {
-               if (( comment = commatch( start, stop, magics )) != NULL ) {
+               if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
                    compush( comment );
                    continue;   /* top of for (;;) */
                }
                infile->pf_state &= ~PF_BOT;
 
                /* set up spool file */
-               if ( lp_open( outfile ) < 0 ) {
+               if ( lp_open( outfile, sat ) < 0 ) {
                    syslog( LOG_ERR, "lp_open failed" );
                    spoolerror( outfile, "Ignoring job." );
                }
            }
 
            /* write to file */
-           *stop = '\n';
-           lp_write( start, stop - start + 1 );
-           consumetomark( start, stop, infile );
+           lp_write( start, linelength + crlflength );
+           CONSUME( infile, linelength + crlflength );
        }
     }
 }
 
-cm_psquery( in, out )
+int cm_psquery( in, out, sat )
     struct papfile     *in, *out;
+    struct sockaddr_at *sat;
 {
-    struct comment     *comment;
-    char               *start, *stop;
+    struct papd_comment        *comment;
+    char               *start;
+    int                        linelength, crlflength;
 
     for (;;) {
-       switch ( markline( &start, &stop, in )) {
+       switch ( markline( in, &start, &linelength, &crlflength )) {
        case 0 :
            /* eof on infile */
            out->pf_state |= PF_EOF;
@@ -85,24 +98,26 @@ cm_psquery( in, out )
        if ( in->pf_state & PF_BOT ) {
            in->pf_state &= ~PF_BOT;
        } else {
-           if (( comment = commatch( start, stop, queries )) != NULL ) {
+           if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
                compush( comment );
                return( CH_DONE );
            }
        }
 
-       consumetomark( start, stop, in );
+       CONSUME( in, linelength + crlflength );
     }
 }
 
-cm_psadobe( in, out )
+int cm_psadobe( in, out, sat )
     struct papfile     *in, *out;
+    struct sockaddr_at *sat;
 {
-    char               *start, *stop;
-    struct comment     *comment = compeek();
+    char               *start;
+    int                        linelength, crlflength;
+    struct papd_comment        *comment = compeek();
 
     for (;;) {
-       switch ( markline( &start, &stop, in )) {
+       switch ( markline( in, &start, &linelength, &crlflength )) {
        case 0 :
            /* eof on infile */
            out->pf_state |= PF_EOF;
@@ -115,32 +130,33 @@ cm_psadobe( in, out )
 
        if ( in->pf_state & PF_BOT ) {
            in->pf_state &= ~PF_BOT;
-           if ( lp_open( out ) < 0 ) {
+           if ( lp_open( out, sat ) < 0 ) {
                syslog( LOG_ERR, "lp_open failed" );
                spoolerror( out, "Ignoring job." );
            }
        } else {
-           if (( comment = commatch( start, stop, headers )) != NULL ) {
+           if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
                compush( comment );
                return( CH_DONE );
            }
        }
 
-       *stop = '\n';
-       lp_write( start, stop - start + 1 );
-       consumetomark( start, stop, in );
+       lp_write( start, linelength + crlflength );
+       CONSUME( in, linelength + crlflength );
     }
 }
 
 char   *Query = "Query";
 
-cm_psswitch( in, out )
+int cm_psswitch( in, out, sat )
     struct papfile     *in, *out;
+    struct sockaddr_at *sat;
 {
     char               *start, *stop, *p;
-    struct comment     *comment = compeek();
+    int                        linelength, crlflength;
+    struct papd_comment        *comment = compeek();
 
-    switch ( markline( &start, &stop, in )) {
+    switch ( markline( in, &start, &linelength, &crlflength )) {
     case 0 :
        /* eof on infile */
        out->pf_state |= PF_EOF;
@@ -151,6 +167,7 @@ cm_psswitch( in, out )
        return( CH_MORE );
     }
 
+    stop = start + linelength;
     for ( p = start; p < stop; p++ ) {
        if ( *p == ' ' || *p == '\t' ) {
            break;
@@ -177,7 +194,7 @@ cm_psswitch( in, out )
     return( CH_DONE );
 }
 
-struct comment magics[] = {
+struct papd_comment    magics[] = {
     { "%!PS-Adobe-3.0 Query",  0,                      cm_psquery, C_FULL },
     { "%!PS-Adobe-3.0",                0,                      cm_psadobe, C_FULL },
     { "%!PS-Adobe-",           0,                      cm_psswitch,    0 },