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