diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-05-24 15:56:14 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-05-31 00:37:48 +0200 |
commit | 384ef099209f92afb0af0c48756731a105da23f5 (patch) | |
tree | c7cb1a0147fd6b2a3889f912aa13e3f83ed192db /openbsc/contrib | |
parent | 1d54c40dd64ec4fcbaee913b1c020f4b65209a81 (diff) |
nat: Add a test utility for the number rewriting
Diffstat (limited to 'openbsc/contrib')
-rw-r--r-- | openbsc/contrib/nat/test_regexp.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/openbsc/contrib/nat/test_regexp.c b/openbsc/contrib/nat/test_regexp.c new file mode 100644 index 000000000..808a703ca --- /dev/null +++ b/openbsc/contrib/nat/test_regexp.c @@ -0,0 +1,30 @@ +/* make test_regexp */ +#include <sys/types.h> +#include <regex.h> +#include <stdio.h> + + +int main(int argc, char **argv) +{ + regex_t reg; + regmatch_t matches[2]; + + if (argc != 4) { + printf("Invoke with: test_regexp REGEXP REPLACE NR\n"); + return -1; + } + + if (regcomp(®, argv[1], REG_EXTENDED) != 0) { + fprintf(stderr, "Regexp '%s' is not valid.\n", argv[1]); + return -1; + } + + if (regexec(®, argv[3], 2, matches, 0) == 0 && matches[1].rm_eo != -1) + printf("New Number: %s%s\n", argv[2], &argv[3][matches[1].rm_so]); + else + printf("No match.\n"); + + regfree(®); + + return 0; +} |