[augeas-devel] [PATCH] Test program to play with locale dependency of re_match
David Lutterkort
lutter at redhat.com
Sat Jan 31 01:08:36 UTC 2009
---
.gitignore | 1 +
src/Makefile.am | 5 +++
src/reloc.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 107 insertions(+), 0 deletions(-)
create mode 100644 src/reloc.c
diff --git a/.gitignore b/.gitignore
index caabf4c..bd864d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,6 +33,7 @@ src/parser.[ch]
src/lexer.[ch]
src/augtool
src/augparse
+src/reloc
tests/fatest
*.aux
*.dvi
diff --git a/src/Makefile.am b/src/Makefile.am
index 32fca89..057b673 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,8 @@ noinst_LTLIBRARIES = liblexer.la
bin_PROGRAMS = augtool augparse
+noinst_PROGRAMS = reloc
+
include_HEADERS = augeas.h fa.h
libaugeas_la_SOURCES = augeas.h augeas.c pathx.c \
@@ -40,6 +42,9 @@ libfa_la_LDFLAGS = -version-info $(LIBFA_VERSION_INFO)
liblexer_la_SOURCES = lexer.l
liblexer_la_CFLAGS = $(AM_CFLAGS) -Wno-error
+reloc_SOURCES = reloc.c
+reloc_LDADD = $(GNULIB)
+
# Generate datadir.h. AUGEAS_LENS_DIR in internal.h depends on
# the value of DATADIR
internal.h: datadir.h
diff --git a/src/reloc.c b/src/reloc.c
new file mode 100644
index 0000000..cf4a107
--- /dev/null
+++ b/src/reloc.c
@@ -0,0 +1,101 @@
+/*
+ * reloc.c:
+ *
+ * Copyright (C) 2007 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: David Lutterkort <dlutter at redhat.com>
+ */
+
+#include <config.h>
+
+#include <regex.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+static const char *const escape_chars = "\"\a\b\t\n\v\f\r\\";
+static const char *const escape_names = "\"abtnvfr\\";
+
+static char *unescape(const char *s) {
+ size_t size;
+ const char *n;
+ char *result, *t;
+ int i;
+
+ size = 0;
+ for (i=0; i < strlen(s); i++, size++)
+ if (s[i] == '\\' && strchr(escape_names, s[i+1]) != NULL) {
+ i += 1;
+ }
+
+ result = calloc(size + 1, 1);
+ if (result == NULL) {
+ fprintf(stderr, "Out of memory");
+ exit(EXIT_FAILURE);
+ }
+
+ for (i = 0, t = result; i < strlen(s); i++, size++) {
+ if (s[i] == '\\' && (n = strchr(escape_names, s[i+1])) != NULL) {
+ *t++ = escape_chars[n - escape_names];
+ i += 1;
+ } else {
+ *t++ = s[i];
+ }
+ }
+ return result;
+}
+
+int main(int argc, char **argv) {
+ char *pat;
+ struct re_pattern_buffer *re;
+ int count;
+
+ setlocale(LC_ALL, "");
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s regexp string\n", argv[0]);
+ return 1;
+ }
+
+ pat = unescape(argv[1]);
+ re = calloc(1, sizeof(*re));
+ if (re == NULL) {
+ fprintf(stderr, "Allocation failed\n");
+ return 1;
+ }
+
+ re_syntax_options = RE_SYNTAX_POSIX_MINIMAL_EXTENDED & ~(RE_DOT_NEWLINE);
+ const char *c =
+ re_compile_pattern(argv[1], strlen(argv[1]), re);
+
+ if (c != NULL) {
+ fprintf(stderr, "invalid regexp /%s/: %s", argv[1], c);
+ return 1;
+ }
+
+ count = re_match(re, argv[2], strlen(argv[2]), 0, NULL);
+ printf("re_match: %d\n", count);
+}
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
--
1.6.0.6
More information about the augeas-devel
mailing list