summaryrefslogtreecommitdiff
path: root/web/noweb/src/c/match.nw
blob: 2d015a8a133c860404d280612034756d28a8cc66 (plain)
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
\subsection{Code to recognize [[noweb]] markup on input}
We recognize the input using matching functions, which can find [[@begin]],
[[@end]], and other useful information.
<<header>>=
extern int is_keyword(char *line, char *keyword);
extern int is_begin(char *line, char *type);
extern int is_end(char *line, char *type);
extern int is_index(char *line, char *type);
<<*>>=
static char rcsid[] = "$Id: match.nw,v 1.21 2008/10/06 01:03:05 nr Exp nr $";
static char rcsname[] = "$Name: v2_12 $";
#include <string.h>
#include "match.h"
static int matches(char *line, char *search) {
    (void)rcsid; /* avoid a warning */
    (void)rcsname; /* avoid a warning */
    return !strncmp(line,search,strlen(search));
}
@ 
On 24 March 1996, I changed this to accept zero as a terminator
because I strip newlines in the prettyprinter.
Too bad if we just got worse at detecting bogus filters.
<<*>>=
int is_keyword(char *line, char *keyword) {
    char low_at_sign = '@';
    return *line==low_at_sign && matches(line+1,keyword) && 
           (line[strlen(keyword)+1]==' ' || line[strlen(keyword)+1]=='\n' ||
            line[strlen(keyword)+1]=='\0');
}
int is_begin(char *line, char *type) {
    return is_keyword(line,"begin") && matches(line+1+6,type);
}
int is_end(char *line, char *type) {
    return is_keyword(line,"end") && matches (line+1+4,type);
}
int is_index(char *line, char *type) {
    return is_keyword(line,"index") && matches(line+1+6,type);
}