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