From d931ce7fd88640b5b0fda7ff4627061694484429 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 29 Aug 2011 19:57:05 +0200 Subject: [PATCH] adding command line tool for checking an regex --- Makefile | 3 ++- filter-check.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 filter-check.c diff --git a/Makefile b/Makefile index 8e53c40..65064b0 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CC = gcc LDFLAGS = -lxml2 -lcurl -lpcre CFLAGS = -g -Wall -O2 -I/usr/include/libxml2 -PROGRAMS = dlight dlight-compile dlight-read-config +PROGRAMS = dlight dlight-compile dlight-read-config dlight-filter-check all : $(PROGRAMS) @@ -13,6 +13,7 @@ install : $(PROGRAMS) dlight : dlight.o env.o http.o rss.o lockfile.o filter.o cconf.o dlhist.o error.o dlight-compile : compile.o env.o lockfile.o filter.o cconf.o error.o dlight-read-config : read-config.o env.o cconf.o error.o +dlight-filter-check: filter-check.o filter.o error.o dlight-% : %.o $(CC) $(LDFLAGS) -o $@ $^ diff --git a/filter-check.c b/filter-check.c new file mode 100644 index 0000000..4b329ab --- /dev/null +++ b/filter-check.c @@ -0,0 +1,40 @@ +/* filter-check.c + * + * Copyright (C) 2011 Henrik Hautakoski + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include +#include "error.h" +#include "filter.h" + +const char *usagestr = "dlight-filter-check "; + +int main(int argc, char **argv) { + + if (argc < 3) + usage(usagestr); + + if (!filter_check_syntax(argv[1])) + return 0; + + if (filter_match(argv[1], argv[2])) { + puts("match"); + } else { + puts("nomatch"); + } + return 0; +} \ No newline at end of file