From b104759ad671a1ae92f2768de02f1dbbe5f4cb12 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 11 Nov 2008 10:12:01 +0100 Subject: added small regex check tool to repository This is intended for debugging and considered worth preserving. However, it has not (yet) been added to the build diag tools as it is not considered important enough. --- tools/regexp.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tools/regexp.c (limited to 'tools/regexp.c') diff --git a/tools/regexp.c b/tools/regexp.c new file mode 100644 index 00000000..c8e4c681 --- /dev/null +++ b/tools/regexp.c @@ -0,0 +1,72 @@ +/* A simple regular expression checker for rsyslog test and debug. + * Regular expressions have shown to turn out to be a hot support topic. + * While I have done an online tool at http://www.rsyslog.com/tool-regex + * there are still some situations where one wants to check against the + * actual clib api calls. This is what this small test program does, + * it takes its command line arguments (re first, then sample data) and + * pushes them into the API and then shows the result. This should be + * considered the ultimate reference for any questions arising. + * + * Copyright 2008 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog 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. + * + * Rsyslog 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 Rsyslog. If not, see . + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + regex_t preg; + size_t nmatch = 10; + regmatch_t pmatch[10]; + char *pstr; + int i; + + if(argc != 3) { + fprintf(stderr, "usage: regex regexp sample-data\n"); + exit(1); + } + + pstr = strdup(argv[2]); /* get working copy */ + + i = regcomp(&preg, argv[1], REG_EXTENDED); + printf("regcomp returns %d\n", i); + i = regexec(&preg, pstr, nmatch, pmatch, 0); + printf("regexec returns %d\n", i); + if(i == REG_NOMATCH) { + printf("found no match!\n"); + return 1; + } + + printf("returned substrings:\n"); + for(i = 0 ; i < 10 ; i++) { + printf("%d: so %d, eo %d", i, pmatch[i].rm_so, pmatch[i].rm_eo); + if(pmatch[i].rm_so != -1) { + int j; + printf(", text: '"); + for(j = pmatch[i].rm_so ; j < pmatch[i].rm_eo ; ++j) + putchar(pstr[j]); + putchar('\''); + } + putchar('\n'); + } + return 0; +} -- cgit v1.2.3 From cd8c6abcc8cea54924e55dffe820364ad98a40df Mon Sep 17 00:00:00 2001 From: Yann Droneaud Date: Thu, 4 Mar 2010 08:00:39 +0100 Subject: Includes "config.h" before any other header. For consistency, ./configure generated "config.h" must be the first header include through out the project. Signed-off-by: Rainer Gerhards --- tools/regexp.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/regexp.c') diff --git a/tools/regexp.c b/tools/regexp.c index c8e4c681..e8bba4f4 100644 --- a/tools/regexp.c +++ b/tools/regexp.c @@ -26,6 +26,7 @@ * * A copy of the GPL can be found in the file "COPYING" in this distribution. */ +#include "config.h" #include #include #include -- cgit v1.2.3