]> arthur.barton.de Git - netatalk.git/blob - etc/papd/comment.c
prototyping to allow the compiler to do some real argument checking
[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 void compop( void )
23 {
24     struct comstate     *cs;
25
26     cs = comstate;
27     comstate = cs->cs_prev;
28     free( cs );
29 }
30
31 void compush( comment )
32     struct papd_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 int comswitch( comments, handler )
49     struct papd_comment *comments;
50     int                 (*handler)();
51 {
52     struct papd_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 int 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 papd_comment *commatch( start, stop, comments )
90     char                *start, *stop;
91     struct papd_comment comments[];
92 {
93     struct papd_comment *comment;
94
95     for ( comment = comments; comment->c_begin; comment++ ) {
96         if ( comcmp( start, stop, comment->c_begin, comment->c_flags ) == 0 ) {
97             break;
98         }
99     }
100     if ( comment->c_begin ) {
101         return( comment );
102     } else {
103         return( NULL );
104     }
105 }
106
107 char *comtoken( start, stop, pos, delim )
108     char        *start, *stop, *pos, *delim;
109 {
110     if ( pos < start || pos > stop ) {
111         abort();
112     }
113
114     for ( ; pos < stop; pos++ ) {
115         if ( index( delim, *pos )) {
116             break;
117         }
118     }
119     if ( ++pos < stop ) {
120         return( pos );
121     } else {
122         return( NULL );
123     }
124 }