summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-11-07 14:48:23 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-11-07 14:48:23 +0000
commit740b1c8401ec6139449ab717b83232afcb60620b (patch)
tree883acb0cafd3ca057290fd14884812d52467f034
parenta250bc91a29211e4792f2098769363a820b16823 (diff)
downloadmailutils-740b1c8401ec6139449ab717b83232afcb60620b.tar.gz
mailutils-740b1c8401ec6139449ab717b83232afcb60620b.tar.bz2
Added to the repository
-rw-r--r--libsieve/.cvsignore9
-rw-r--r--libsieve/Makefile.am36
-rw-r--r--libsieve/sieve.h30
-rw-r--r--libsieve/sieve.l398
-rw-r--r--libsieve/sieve.y119
-rw-r--r--libsieve/sv.c41
-rw-r--r--libsieve/util.c37
7 files changed, 670 insertions, 0 deletions
diff --git a/libsieve/.cvsignore b/libsieve/.cvsignore
new file mode 100644
index 000000000..91f5ca920
--- /dev/null
+++ b/libsieve/.cvsignore
@@ -0,0 +1,9 @@
1Makefile.in
2Makefile
3.deps
4.libs
5.gdbinit
6*.la
7*.lo
8*.output
9*.tab.[ch]
diff --git a/libsieve/Makefile.am b/libsieve/Makefile.am
new file mode 100644
index 000000000..4ce0bd5d6
--- /dev/null
+++ b/libsieve/Makefile.am
@@ -0,0 +1,36 @@
1# This file is part of GNU Mailutils
2# Copyright (C) 2000,2001,2002 Free Software Foundation
3# See file COPYING in the distribution root directory for copying conditions.
4
5INCLUDES = -I${top_srcdir}/include -I${top_srcdir}/lib
6YLWRAP = $(SHELL) $(top_srcdir)/scripts/ylwrap
7AM_YFLAGS = -dtv
8
9lib_LTLIBRARIES = libsieve.la
10
11noinst_PROGRAMS = sv
12
13libsieve_la_SOURCES = sieve-gram.c sieve-gram.h sieve-lex.c util.c
14sv_SOURCES = sv.c
15sv_LDADD = ./libsieve.la ../mailbox/libmailbox.la
16noinst_HEADERS = sieve.h
17
18BUILT_SOURCES= \
19 sieve-gram.c sieve-gram.h \
20 sieve-lex.c
21
22MAINTAINERCLEANFILES=$(BUILT_SOURCES)
23
24EXTRA_DIST = sieve.y sieve.l
25
26sieve-lex.c: $(srcdir)/sieve.l sieve-gram.h
27 $(YLWRAP) "$(LEX) $(AM_LEXFLAGS) $(LEXFLAGS)" \
28 $(srcdir)/sieve.l lex.yy.c sieve-lex.c \
29 -- -yy sieve_yy
30
31sieve-gram.c sieve-gram.h: $(srcdir)/sieve.y
32 $(YLWRAP) "$(YACC) $(AM_YFLAGS) $(YFLAGS)" $(srcdir)/sieve.y \
33 y.tab.c sieve-gram.c y.tab.h sieve-gram.h y.output y.output \
34 -- -yy sieve_yy
35
36
diff --git a/libsieve/sieve.h b/libsieve/sieve.h
new file mode 100644
index 000000000..68c631f94
--- /dev/null
+++ b/libsieve/sieve.h
@@ -0,0 +1,30 @@
1/* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18#include <sys/types.h>
19
20#define sieve_error mu_error
21
22extern char *sieve_filename;
23extern int sieve_line_num;
24extern int sieve_yydebug;
25
26void *sieve_alloc (size_t size);
27
28int sieve_open_source (const char *name);
29
30int sieve_parse (const char *name);
diff --git a/libsieve/sieve.l b/libsieve/sieve.l
new file mode 100644
index 000000000..4e1d10dbb
--- /dev/null
+++ b/libsieve/sieve.l
@@ -0,0 +1,398 @@
1%{
2/* GNU mailutils - a suite of utilities for electronic mail
3 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18
19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include <sys/file.h>
27#include <sys/stat.h>
28#include <errno.h>
29#include <sieve.h>
30#include <sieve-gram.h>
31
32
33char *sieve_filename;
34int sieve_line_num;
35ino_t sieve_source_inode;
36
37#ifdef FLEX_SCANNER
38#define xinput() (yyin ? getc(yyin) : EOF)
39#undef YY_INPUT
40#define YY_INPUT(buf,result,max_size) do { \
41 int i; \
42 for (i = 0; i < max_size; i++) { \
43 int ch = xinput(); \
44 if (ch == EOF) \
45 break; \
46 buf[i] = ch; \
47 } \
48 result = i; \
49} while (0)
50#define LEX_BUFFER_STATE YY_BUFFER_STATE
51#define SET_BUFFER_STATE(s) do { \
52 (s) = YY_CURRENT_BUFFER; \
53 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); \
54} while (0)
55#define RESTORE_BUFFER_STATE(s) do { \
56 yy_delete_buffer(YY_CURRENT_BUFFER); \
57 yy_switch_to_buffer(s); \
58} while (0)
59
60#else
61/* AT&T Lex */
62
63static void lex_set_buffer __P((FILE *fp));
64static void lex_delete_buffer __P((LEX_BUFFER_STATE buf));
65static int xinput __P((void));
66static int xunput __P((void));
67
68#undef unput
69#define unput(c) xunput(c)
70#undef input
71#define input() xinput()
72
73#define LEX_BUF_SIZE 16384
74#define LEX_PUTBACK_SIZE 32
75
76typedef struct {
77 FILE *yyin;
78 char *buffer;
79 size_t bufsize;
80 size_t level;
81 char *ptr;
82 char *putback;
83 size_t pb_size;
84 size_t pb_level;
85} LEX_BUFFER_STATE;
86LEX_BUFFER_STATE current_buffer;
87
88#define SET_BUFFER_STATE(s) do { \
89 (s) = current_buffer; \
90 lex_set_buffer(yyin); \
91} while (0)
92#define RESTORE_BUFFER_STATE(s) do { \
93 lex_delete_buffer(current_buffer); \
94 current_buffer = (s); \
95 yyin = current_buffer.yyin; \
96} while (0)
97
98void
99lex_set_buffer (FILE *fp)
100{
101 char *buf;
102 size_t size;
103
104 for (size = LEX_BUF_SIZE; size > 1; size /= 2)
105 if (buf = malloc (size))
106 break;
107
108 if (!buf)
109 {
110 sieve_error ("not enough memory");
111 abort ();
112 }
113
114 current_buffer.yyin = yyin;
115 current_buffer.buffer = buf;
116 current_buffer.bufsize = size;
117 current_buffer.level = 0;
118 current_buffer.ptr = current_buffer.buffer;
119 current_buffer.pb_size = current_buffer.pb_level = 0;
120 current_buffer.putback = NULL;
121}
122
123void
124lex_delete_buffer (LEX_BUFFER_STATE buf)
125{
126 free (buf.buffer);
127 if (buf.putback)
128 free (buf.putback);
129}
130
131int
132xinput ()
133{
134 if (!yyin)
135 return EOF;
136
137 if (current_buffer.pb_level)
138 return current_buffer.putback[--current_buffer.pb_level];
139
140 if (current_buffer.level <= 0)
141 {
142 int n;
143
144 if (feof (yyin))
145 return 0;