~ubuntu-branches/ubuntu/precise/netatalk/precise

« back to all changes in this revision

Viewing changes to etc/papd/magics.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Rittau
  • Date: 2004-01-19 12:43:49 UTC
  • Revision ID: james.westby@ubuntu.com-20040119124349-es563jbp0hk0ae51
Tags: upstream-1.6.4
ImportĀ upstreamĀ versionĀ 1.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: magics.c,v 1.10 2002/09/29 23:29:13 sibaz Exp $
 
3
 *
 
4
 * Copyright (c) 1990,1994 Regents of The University of Michigan.
 
5
 * All Rights Reserved.  See COPYRIGHT.
 
6
 */
 
7
 
 
8
#ifdef HAVE_CONFIG_H
 
9
#include "config.h"
 
10
#endif /* HAVE_CONFIG_H */
 
11
 
 
12
#include <atalk/logger.h>
 
13
#include <sys/param.h>
 
14
#include <stdio.h>
 
15
#include <string.h>
 
16
#include <stdlib.h>
 
17
 
 
18
#include <netatalk/at.h>
 
19
 
 
20
#include "file.h"
 
21
#include "comment.h"
 
22
#include "lp.h"
 
23
 
 
24
int ps( infile, outfile, sat )
 
25
    struct papfile      *infile, *outfile;
 
26
    struct sockaddr_at  *sat;
 
27
{
 
28
    char                        *start;
 
29
    int                         linelength, crlflength;
 
30
    struct papd_comment         *comment;
 
31
 
 
32
    for (;;) {
 
33
        if ( (comment = compeek()) ) {
 
34
            switch( (*comment->c_handler)( infile, outfile, sat )) {
 
35
            case CH_DONE :
 
36
                continue;
 
37
 
 
38
            case CH_MORE :
 
39
                return( CH_MORE );
 
40
 
 
41
            default :
 
42
                return( CH_ERROR );
 
43
            }
 
44
 
 
45
        } else {
 
46
            switch ( markline( infile, &start, &linelength, &crlflength )) {
 
47
            case 0 :
 
48
                /* eof on infile */
 
49
                outfile->pf_state |= PF_EOF;
 
50
                lp_close();
 
51
                return( 0 );
 
52
 
 
53
            case -1 :
 
54
                return( 0 );
 
55
            }
 
56
 
 
57
            if ( infile->pf_state & PF_BOT ) {
 
58
                if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
 
59
                    compush( comment );
 
60
                    continue;   /* top of for (;;) */
 
61
                }
 
62
                infile->pf_state &= ~PF_BOT;
 
63
 
 
64
                /* set up spool file */
 
65
                if ( lp_open( outfile, sat ) < 0 ) {
 
66
                    LOG(log_error, logtype_papd, "lp_open failed" );
 
67
                    spoolerror( outfile, "Ignoring job." );
 
68
                }
 
69
            }
 
70
 
 
71
            /* write to file */
 
72
            lp_write( start, linelength + crlflength );
 
73
            CONSUME( infile, linelength + crlflength );
 
74
        }
 
75
    }
 
76
}
 
77
 
 
78
int cm_psquery( in, out, sat )
 
79
    struct papfile      *in, *out;
 
80
    struct sockaddr_at  *sat;
 
81
{
 
82
    struct papd_comment *comment;
 
83
    char                *start;
 
84
    int                 linelength, crlflength;
 
85
 
 
86
    for (;;) {
 
87
        switch ( markline( in, &start, &linelength, &crlflength )) {
 
88
        case 0 :
 
89
            /* eof on infile */
 
90
            out->pf_state |= PF_EOF;
 
91
            compop();
 
92
            return( CH_DONE );
 
93
 
 
94
        case -1 :
 
95
            return( CH_MORE );
 
96
        }
 
97
 
 
98
        if ( in->pf_state & PF_BOT ) {
 
99
            in->pf_state &= ~PF_BOT;
 
100
        } else {
 
101
            if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
 
102
                compush( comment );
 
103
                return( CH_DONE );
 
104
            }
 
105
        }
 
106
 
 
107
        CONSUME( in, linelength + crlflength );
 
108
    }
 
109
}
 
110
 
 
111
int cm_psadobe( in, out, sat )
 
112
    struct papfile      *in, *out;
 
113
    struct sockaddr_at  *sat;
 
114
{
 
115
    char                *start;
 
116
    int                 linelength, crlflength;
 
117
    struct papd_comment *comment = compeek();
 
118
 
 
119
    for (;;) {
 
120
        switch ( markline( in, &start, &linelength, &crlflength )) {
 
121
        case 0 :
 
122
            /* eof on infile */
 
123
            out->pf_state |= PF_EOF;
 
124
            compop();
 
125
            return( CH_DONE );
 
126
 
 
127
        case -1 :
 
128
            return( CH_MORE );
 
129
        }
 
130
 
 
131
        if ( in->pf_state & PF_BOT ) {
 
132
            in->pf_state &= ~PF_BOT;
 
133
            if ( lp_open( out, sat ) < 0 ) {
 
134
                LOG(log_error, logtype_papd, "lp_open failed" );
 
135
                spoolerror( out, "Ignoring job." );
 
136
            }
 
137
        } else {
 
138
            if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
 
139
                compush( comment );
 
140
                return( CH_DONE );
 
141
            }
 
142
        }
 
143
 
 
144
        lp_write( start, linelength + crlflength );
 
145
        CONSUME( in, linelength + crlflength );
 
146
    }
 
147
}
 
148
 
 
149
char    *Query = "Query";
 
150
 
 
151
int cm_psswitch( in, out, sat )
 
152
    struct papfile      *in, *out;
 
153
    struct sockaddr_at  *sat;
 
154
{
 
155
    char                *start, *stop, *p;
 
156
    int                 linelength, crlflength;
 
157
    struct papd_comment *comment = compeek();
 
158
 
 
159
    switch ( markline( in, &start, &linelength, &crlflength )) {
 
160
    case 0 :
 
161
        /* eof on infile */
 
162
        out->pf_state |= PF_EOF;
 
163
        compop();
 
164
        return( 0 );
 
165
 
 
166
    case -1 :
 
167
        return( CH_MORE );
 
168
    }
 
169
 
 
170
    stop = start + linelength;
 
171
    for ( p = start; p < stop; p++ ) {
 
172
        if ( *p == ' ' || *p == '\t' ) {
 
173
            break;
 
174
        }
 
175
    }
 
176
    for ( ; p < stop; p++ ) {
 
177
        if ( *p != ' ' && *p != '\t' ) {
 
178
            break;
 
179
        }
 
180
    }
 
181
 
 
182
    if ( stop - p >= strlen( Query ) &&
 
183
            strncmp( p, Query, strlen( Query )) == 0 ) {
 
184
        if ( comswitch( magics, cm_psquery ) < 0 ) {
 
185
            LOG(log_error, logtype_papd, "cm_psswitch: can't find psquery!" );
 
186
            exit( 1 );
 
187
        }
 
188
    } else {
 
189
        if ( comswitch( magics, cm_psadobe ) < 0 ) {
 
190
            LOG(log_error, logtype_papd, "cm_psswitch: can't find psadobe!" );
 
191
            exit( 1 );
 
192
        }
 
193
    }
 
194
    return( CH_DONE );
 
195
}
 
196
 
 
197
struct papd_comment     magics[] = {
 
198
    { "%!PS-Adobe-3.0 Query",   0,                      cm_psquery, C_FULL },
 
199
    { "%!PS-Adobe-3.0",         0,                      cm_psadobe, C_FULL },
 
200
    { "%!PS-Adobe-",            0,                      cm_psswitch,    0 },
 
201
    { 0 },
 
202
};