--- lmtp2nntp_config.c 2002/02/14 11:03:52 1.49
+++ lmtp2nntp_config.c 2002/02/14 15:11:08 1.50
@@ -35,10 +35,11 @@
#include "lmtp2nntp_argz.h"
/* third party (linked in) */
+#include "l2.h"
+#include "pcre.h"
+#include "popt.h"
#include "str.h"
#include "val.h"
-#include "popt.h"
-#include "l2.h"
/* library version check (compile-time) */
#define STR_VERSION_HEX_REQ 0x009206
@@ -1003,6 +1004,76 @@
catch (ex)
rethrow;
+//void testpcre(void)
+{
+ char *szRegex;
+ pcre *pcreRegex;
+ pcre_extra *pcreExtra;
+ const char *szError;
+ int nErrorOffset;
+ int iCheck;
+ int opt;
+ char *buf;
+ int buf_size;
+#define OVECSIZE 30
+ int ovec[OVECSIZE];
+ int i;
+ const char **cpList;
+
+ // 0 1 2
+ // 012345678901234567890
+ buf = "In-Reply-To: MailTo: Tom & Jerry";
+ buf_size = strlen(buf);
+ szRegex = "(To|Cc|Bcc):.*(Tom|Snoopy).+&(.*)";
+ fprintf(stderr, "DEBUG: 0 1 2 3 4\n");
+ fprintf(stderr, "DEBUG: 01234567890123456789012345678901234567890\n");
+ fprintf(stderr, "DEBUG: buf =\"%s\"\n", buf);
+ fprintf(stderr, "DEBUG: szRegex=\"%s\"\n", szRegex);
+ /*
+ buf = "In-Reply-To: MailTo: Tom & Jerry";
+ szRegex = "(To|Cc|Bcc):.*(Tom|Snoopy).+&(.*)";
+ iCheck=4 [0]="To: MailTo: Tom & Jerry" [1]="To" [2]="Tom" [3]=" Jerry"
+ */
+
+ /* compile regular expression into finite state machine */
+ opt = 0;
+ // opt |= PCRE_CASELESS;
+ // opt |= PCRE_ANCHORED;
+ if ((pcreRegex = pcre_compile(szRegex, opt, &szError, &nErrorOffset, NULL)) == NULL) {
+ fprintf(stderr, "DEBUG: \"%s\" '%c'\n", szError, szRegex[nErrorOffset]);
+ throw(0,0,0);
+ }
+ /* study finite state machine for more performance */
+ pcreExtra = pcre_study(pcreRegex, 0, &szError);
+ if (szError != NULL) {
+ free(pcreRegex);
+ pcreRegex = NULL;
+ fprintf(stderr, "DEBUG: \"%s\"\n", szError);
+ throw(0,0,0);
+ }
+
+ /* apply filter */
+ iCheck = pcre_exec(pcreRegex, pcreExtra, buf, buf_size, 0, 0, ovec, OVECSIZE);
+ fprintf(stderr, "DEBUG: iCheck=%d\n", iCheck);
+ for (i = 0; i < iCheck; i++)
+ fprintf(stderr, "DEBUG: ovec[%d]=%3d, ovec[%d]=%3d\n", 2*i, ovec[2*i], 2*i+1, ovec[2*i+1]);
+
+
+ pcre_get_substring_list(buf, ovec, iCheck, &cpList);
+ if (cpList != NULL)
+ for (i = 0; i < iCheck; i++)
+ fprintf(stderr, "DEBUG: list[%d]=\"%s\"\n", i, cpList[i] == NULL ? "(NULL)" : cpList[i]);
+
+ /* destroy channel configuration */
+ if (cpList != NULL)
+ pcre_free_substring_list(cpList);
+ if (pcreRegex != NULL)
+ free(pcreRegex);
+ if (pcreExtra != NULL)
+ free(pcreExtra);
+
+}
+
CUS:
return;
}
|