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