]> arthur.barton.de Git - netatalk.git/blob - etc/papd/comment.c
implemented config.h
[netatalk.git] / etc / papd / comment.c
1 /*
2  * Copyright (c) 1990,1994 Regents of The University of Michigan.
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <sys/syslog.h>
11 #include <sys/param.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16 #include "comment.h"
17
18 struct comstate *comstate;
19
20 char    *comcont = "%%+";
21
22 compop()
23 {
24     struct comstate     *cs;
25
26     cs = comstate;
27     comstate = cs->cs_prev;
28     free( cs );
29 }
30
31 compush( comment )
32     struct comment      *comment;
33 {
34     struct comstate     *cs;
35
36     if (( cs = (struct comstate *)malloc( sizeof( struct comstate ))) ==
37             NULL ) {
38         syslog( LOG_ERR, "malloc: %m" );
39         exit( 1 );
40     }
41
42     cs->cs_comment = comment;
43     cs->cs_prev = comstate;
44     cs->cs_flags = 0;
45     comstate = cs;
46 }
47
48 comswitch( comments, handler )
49     struct comment      *comments;
50     int                 (*handler)();
51 {
52     struct comment      *c, *comment = NULL;
53
54     for ( c = comments; c->c_begin; c++ ) {
55         if ( c->c_handler == handler ) {
56             comment = c;
57         }
58     }
59     if ( comment == NULL || comment->c_handler != handler ) {
60         syslog( LOG_ERR, "comswitch: can't find handler!" );
61         return( -1 );
62     }
63     compop();
64     compush( comment );
65     return( 0 );
66 }
67
68 comcmp( start, stop, str, how )
69     char        *start, *stop, *str;
70     int         how;
71 {
72     int         cc, len;
73
74     len = stop - start;
75     cc = strlen( str );
76     if ( how & C_FULL ) {
77         if ( cc == len & strncmp( str, start, cc ) == 0 ) {
78             return( 0 );
79         }
80     } else {
81         if ( cc <= len && strncmp( str, start, cc ) == 0 ) {
82             return( 0 );
83         }
84     }
85
86     return( 1 );
87 }
88
89     struct comment *
90 commatch( start, stop, comments )
91     char                *start, *stop;
92     struct comment      comments[];
93 {
94     struct comment      *comment;
95
96     for ( comment = comments; comment->c_begin; comment++ ) {
97         if ( comcmp( start, stop, comment->c_begin, comment->c_flags ) == 0 ) {
98             break;
99         }
100     }
101     if ( comment->c_begin ) {
102         return( comment );
103     } else {
104         return( NULL );
105     }
106 }
107
108     char *
109 comtoken( start, stop, pos, delim )
110     char        *start, *stop, *pos, *delim;
111 {
112     if ( pos < start || pos > stop ) {
113         abort();
114     }
115
116     for ( ; pos < stop; pos++ ) {
117         if ( index( delim, *pos )) {
118             break;
119         }
120     }
121     if ( ++pos < stop ) {
122         return( pos );
123     } else {
124         return( NULL );
125     }
126 }