mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Make matcher_t and parse_t compilable
These two old-test/regex utils are usable for testing output of regex processing at core level. For getting them usable configure need to create Makefile. This is currently disable by default.
This commit is contained in:
parent
b2bd4e2d8d
commit
0fad905483
@ -1,6 +1,6 @@
|
||||
#
|
||||
# Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
||||
# Copyright (C) 2004 Red Hat, Inc. All rights reserved.
|
||||
# Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved.
|
||||
#
|
||||
# This file is part of LVM2.
|
||||
#
|
||||
@ -15,7 +15,6 @@
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
top_builddir = @top_builddir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
SOURCES=\
|
||||
parse_t.c \
|
||||
@ -27,9 +26,12 @@ TARGETS=\
|
||||
|
||||
include $(top_builddir)/make.tmpl
|
||||
|
||||
parse_t: parse_t.o $(top_builddir)/lib/liblvm.a
|
||||
$(CC) -o parse_t parse_t.o -L$(top_builddir)/lib -llvm
|
||||
INCLUDES += -I$(top_srcdir)/libdm
|
||||
DM_DEPS = $(top_builddir)/libdm/libdevmapper.so
|
||||
DM_LIBS = -ldevmapper $(LIBS)
|
||||
|
||||
matcher_t: matcher_t.o $(top_builddir)/lib/liblvm.a
|
||||
$(CC) -o matcher_t matcher_t.o -L$(top_builddir)/lib -llvm
|
||||
parse_t: parse_t.o $(DM_DEPS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ parse_t.o $(DM_LIBS)
|
||||
|
||||
matcher_t: matcher_t.o $(DM_DEPS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ matcher_t.o $(DM_LIBS)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
||||
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is part of LVM2.
|
||||
*
|
||||
@ -13,7 +13,7 @@
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "matcher.h"
|
||||
#include "libdevmapper.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -31,7 +31,7 @@ static int _read_spec(const char *file, char ***regex, int *nregex)
|
||||
char buffer[1024], *start, *ptr;
|
||||
FILE *fp = fopen(file, "r");
|
||||
int asize = 100;
|
||||
char **rx = dbg_malloc(sizeof(*rx) * asize);
|
||||
char **rx = dm_malloc(sizeof(*rx) * asize);
|
||||
int nr = 0;
|
||||
|
||||
if (!fp)
|
||||
@ -60,7 +60,7 @@ static int _read_spec(const char *file, char ***regex, int *nregex)
|
||||
return 0;
|
||||
}
|
||||
|
||||
rx[nr] = dbg_malloc((ptr - start) + 1);
|
||||
rx[nr] = dm_malloc((ptr - start) + 1);
|
||||
strncpy(rx[nr], start, ptr - start);
|
||||
rx[nr][ptr - start] = '\0';
|
||||
nr++;
|
||||
@ -81,12 +81,12 @@ static void _free_regex(char **regex, int nregex)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < nregex; i++)
|
||||
dbg_free(regex[i]);
|
||||
dm_free(regex[i]);
|
||||
|
||||
dbg_free(regex);
|
||||
dm_free(regex);
|
||||
}
|
||||
|
||||
static void _scan_input(struct matcher *m, char **regex)
|
||||
static void _scan_input(struct dm_regex *m, char **regex)
|
||||
{
|
||||
char buffer[256], *ptr;
|
||||
int r;
|
||||
@ -95,7 +95,7 @@ static void _scan_input(struct matcher *m, char **regex)
|
||||
if ((ptr = strchr(buffer, '\n')))
|
||||
*ptr = '\0';
|
||||
|
||||
r = matcher_run(m, buffer);
|
||||
r = dm_regex_match(m, buffer);
|
||||
|
||||
if (r >= 0)
|
||||
printf("%s : %s\n", buffer, regex[r]);
|
||||
@ -105,39 +105,41 @@ static void _scan_input(struct matcher *m, char **regex)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct dm_pool *mem;
|
||||
struct matcher *scanner;
|
||||
struct dm_regex *scanner;
|
||||
char **regex;
|
||||
int nregex;
|
||||
int ret = 0;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage : %s <pattern_file>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
init_log(stderr);
|
||||
init_debug(_LOG_DEBUG);
|
||||
dm_log_init_verbose(_LOG_DEBUG);
|
||||
|
||||
if (!(mem = dm_pool_create(10 * 1024))) {
|
||||
if (!(mem = dm_pool_create("match_regex", 10 * 1024))) {
|
||||
fprintf(stderr, "Couldn't create pool\n");
|
||||
exit(2);
|
||||
ret = 2;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!_read_spec(argv[1], ®ex, &nregex)) {
|
||||
fprintf(stderr, "Couldn't read the lex specification\n");
|
||||
exit(3);
|
||||
ret = 3;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(scanner = matcher_create(mem, (const char **) regex, nregex))) {
|
||||
if (!(scanner = dm_regex_create(mem, (const char **)regex, nregex))) {
|
||||
fprintf(stderr, "Couldn't build the lexer\n");
|
||||
exit(4);
|
||||
ret = 4;
|
||||
goto err;
|
||||
}
|
||||
|
||||
_scan_input(scanner, regex);
|
||||
_free_regex(regex, nregex);
|
||||
|
||||
err:
|
||||
dm_pool_destroy(mem);
|
||||
|
||||
dump_memory();
|
||||
fin_log();
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
||||
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is part of LVM2.
|
||||
*
|
||||
@ -13,8 +13,8 @@
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include "../../lib/regex/parse_rx.h"
|
||||
/* hack - using unexported internal function */
|
||||
#include "regex/parse_rx.c"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
@ -50,7 +50,7 @@ static void _pretty_print(struct rx_node *rx, int depth)
|
||||
case CHARSET:
|
||||
printf("Charset : ");
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (bit(rx->charset, i) && isprint(i))
|
||||
if (dm_bit(rx->charset, i) && isprint(i))
|
||||
printf("%c", (char) i);
|
||||
}
|
||||
break;
|
||||
@ -67,7 +67,6 @@ static void _pretty_print(struct rx_node *rx, int depth)
|
||||
_pretty_print(rx->right, depth + 1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct dm_pool *mem;
|
||||
@ -78,15 +77,15 @@ int main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
init_log(stderr);
|
||||
init_debug(_LOG_INFO);
|
||||
dm_log_init_verbose(_LOG_DEBUG);
|
||||
|
||||
if (!(mem = dm_pool_create(1024))) {
|
||||
if (!(mem = dm_pool_create("parse_regex", 1024))) {
|
||||
fprintf(stderr, "Couldn't create pool\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!(rx = rx_parse_str(mem, argv[1]))) {
|
||||
dm_pool_destroy(mem);
|
||||
fprintf(stderr, "Couldn't parse regex\n");
|
||||
exit(1);
|
||||
}
|
||||
@ -94,7 +93,5 @@ int main(int argc, char **argv)
|
||||
_pretty_print(rx, 0);
|
||||
dm_pool_destroy(mem);
|
||||
|
||||
dump_memory();
|
||||
fin_log();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user