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