-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypolist.l
104 lines (88 loc) · 2.77 KB
/
typolist.l
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
%option noinput nounput noyywrap nodefault prefix="typolist_" outfile="lex.yy.c"
%top {
/*
* This file is part of typoscan.
*
* typoscan is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any
* later version.
*
* typoscan is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public
* License along with typoscan. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <pcre.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "error.h"
#include "typoscan.h"
static char *bufptr, regexbuf [65536];
}
%x IN_REGEX
%%
\<Typo(\ +[a-z0-9]+=\"[^"]*\")*\ +find=\" BUF_INIT(regex); BEGIN(IN_REGEX);
<IN_REGEX>{
\" {
BUF_NUL(regex);
/* Copy regular expression string. */
char *s = strdup (regexbuf);
if (!s)
error (EXIT_FAILURE, errno, "out of memory");
if (regexcount == regexalloccount)
{
regexalloccount += 1000;
regexes = regexes ? realloc (regexes, sizeof (*regexes) * regexalloccount)
: malloc (sizeof (*regexes) * regexalloccount);
if (!regexes)
error (EXIT_FAILURE, errno, "out of memory");
}
const char *errstr;
int erroffset;
pcre *re = pcre_compile (regexbuf, 0, &errstr, &erroffset, NULL);
if (!re)
{
if (run_verbose)
error (0, 0, "Warning: Couldn't compile pattern, ignoring '%s': %d/%s\n", regexbuf, erroffset, errstr);
}
else
{
/* fprintf (stderr, "Adding regex \"%s\".\n", currentdepot); */
regexes [regexcount].regex = re;
regexes [regexcount].extra = pcre_study (regexes [regexcount].regex, 0, &errstr);
if (!regexes [regexcount].extra && run_verbose)
error (0, 0, "Warning2: Couldn't study pattern '%s': %s", s, errstr);
regexes [regexcount].s = s;
regexcount++;
}
BEGIN(INITIAL);
}
.|\n BUF_ADD(regex, *yytext);
}
<*>.|\n /* ignore */
%%
int typolist_scan_buffer (char *buf, size_t size)
{
typolist__scan_bytes (buf, size);
regexes = NULL;
regexalloccount = regexcount = 0;
while (typolist_lex ());
return 0;
}
int typolist_scan_file (FILE *f)
{
typolist_in = f;
regexes = NULL;
regexalloccount = regexcount = 0;
while (typolist_lex ());
return 0;
}