diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-02-12 16:47:56 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-02-12 17:59:06 +0200 |
commit | f06fcc848fa5a5b15d170bf5cc34986ed6164621 (patch) | |
tree | 399b822af71efe9240bb9352465f8ab32bbc7c68 | |
parent | 133e104d9efac43c0cf243207c2c5eaf0343bced (diff) | |
download | vmod-variable-f06fcc848fa5a5b15d170bf5cc34986ed6164621.tar.gz vmod-variable-f06fcc848fa5a5b15d170bf5cc34986ed6164621.tar.bz2 |
Rename batchset to regset
-rw-r--r-- | src/variable.c | 27 | ||||
-rw-r--r-- | src/variable.vcc | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/regset.at (renamed from tests/batchset.at) | 6 | ||||
-rw-r--r-- | tests/testsuite.at | 2 |
5 files changed, 18 insertions, 21 deletions
diff --git a/src/variable.c b/src/variable.c index 9442b6b..667cfc0 100644 --- a/src/variable.c +++ b/src/variable.c | |||
@@ -614,14 +614,13 @@ bref_expand(const char *str, const char *input, pcre *re, | |||
614 | *rptr = 0; | 614 | *rptr = 0; |
615 | 615 | ||
616 | return rbase; | 616 | return rbase; |
617 | } | 617 | } |
618 | 618 | ||
619 | VCL_VOID | 619 | VCL_VOID |
620 | vmod_batchset(VARIABLE_CTX ctx, | 620 | vmod_regset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING rxs, VCL_STRING input) |
621 | VCL_STRING vars, VCL_STRING rxs, VCL_STRING input) | ||
622 | { | 621 | { |
623 | struct symtab *vt = get_symtab(ctx); | 622 | struct symtab *vt = get_symtab(ctx); |
624 | struct vardef *head = NULL, *tail = NULL, *def; | 623 | struct vardef *head = NULL, *tail = NULL, *def; |
625 | size_t count = 0; | 624 | size_t count = 0; |
626 | size_t n; | 625 | size_t n; |
627 | const char *v = vars; | 626 | const char *v = vars; |
@@ -635,13 +634,13 @@ vmod_batchset(VARIABLE_CTX ctx, | |||
635 | int *ovector; | 634 | int *ovector; |
636 | int i; | 635 | int i; |
637 | int rc; | 636 | int rc; |
638 | pcre *re; | 637 | pcre *re; |
639 | 638 | ||
640 | if (!vars || !rxs || !input) { | 639 | if (!vars || !rxs || !input) { |
641 | log_error("variable.batchset: bad arguments: vars=%s, rxs=%s, input=%s", | 640 | log_error("variable.regset: bad arguments: vars=%s, rxs=%s, input=%s", |
642 | S(vars), S(rxs), S(input)); | 641 | S(vars), S(rxs), S(input)); |
643 | return; | 642 | return; |
644 | } | 643 | } |
645 | 644 | ||
646 | while (*v) { | 645 | while (*v) { |
647 | char const *nameptr = v; | 646 | char const *nameptr = v; |
@@ -696,13 +695,13 @@ vmod_batchset(VARIABLE_CTX ctx, | |||
696 | memcpy(def->repl, replptr, repllen); | 695 | memcpy(def->repl, replptr, repllen); |
697 | def->repl[repllen] = 0; | 696 | def->repl[repllen] = 0; |
698 | } | 697 | } |
699 | 698 | ||
700 | re = pcre_compile(rxs, cflags, &error_ptr, &error_offset, NULL); | 699 | re = pcre_compile(rxs, cflags, &error_ptr, &error_offset, NULL); |
701 | if (!re) { | 700 | if (!re) { |
702 | log_error("variable.batchset: %s: compilation failed near %s: %s", | 701 | log_error("variable.regset: %s: compilation failed near %s: %s", |
703 | rxs, rxs + error_offset, error_ptr); | 702 | rxs, rxs + error_offset, error_ptr); |
704 | vardef_free(head); | 703 | vardef_free(head); |
705 | return; | 704 | return; |
706 | } | 705 | } |
707 | 706 | ||
708 | rc = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &n); | 707 | rc = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &n); |
@@ -710,64 +709,62 @@ vmod_batchset(VARIABLE_CTX ctx, | |||
710 | log_error("pcre_fullinfo() failed: %d", rc); | 709 | log_error("pcre_fullinfo() failed: %d", rc); |
711 | vardef_free(head); | 710 | vardef_free(head); |
712 | return; | 711 | return; |
713 | } | 712 | } |
714 | 713 | ||
715 | if (n < count) { | 714 | if (n < count) { |
716 | log_error("variable.batchset: %s: too few subexpressions to satisfy %s", | 715 | log_error("variable.regset: %s: too few subexpressions to satisfy %s", |
717 | rxs, vars); | 716 | rxs, vars); |
718 | vardef_free(head); | 717 | vardef_free(head); |
719 | return; | 718 | return; |
720 | } | 719 | } |
721 | 720 | ||
722 | ovsize = (count + 1) * 3; | 721 | ovsize = (count + 1) * 3; |
723 | ovector = calloc(ovsize, sizeof(*ovector)); | 722 | ovector = calloc(ovsize, sizeof(*ovector)); |
724 | 723 | ||
725 | rc = pcre_exec(re, 0, input, strlen(input), 0, 0, ovector, ovsize); | 724 | rc = pcre_exec(re, 0, input, strlen(input), 0, 0, ovector, ovsize); |
726 | if (rc <= 0) { | 725 | if (rc <= 0) { |
727 | if (rc == 0) | 726 | if (rc != PCRE_ERROR_NOMATCH) |
728 | log_error("matched, but too many substrings"); | 727 | log_error("variable.regset: pcre_exec failed: %d", rc); |
729 | else | ||
730 | /*FIXME*/; | ||
731 | vardef_free(head); | 728 | vardef_free(head); |
732 | return; | 729 | return; |
733 | } | 730 | } |
734 | 731 | ||
735 | for (def = head; def; def = def->next, i++) { | 732 | for (def = head; def; def = def->next, i++) { |
736 | char *s = bref_expand(def->repl, input, re, ovsize, ovector); | 733 | char *s = bref_expand(def->repl, input, re, ovsize, ovector); |
737 | 734 | ||
738 | switch (def->type) { | 735 | switch (def->type) { |
739 | case variable_string: | 736 | case variable_string: |
740 | value.s = (char*)s; | 737 | value.s = (char*)s; |
741 | break; | 738 | break; |
742 | case variable_int: | 739 | case variable_int: |
743 | errno = 0; | 740 | errno = 0; |
744 | lval = strtol(s, &p, 10); | 741 | lval = strtol(s, &p, 10); |
745 | if (*p) { | 742 | if (*p) { |
746 | log_error("variable.batchset: %s(%s)#%d: not an integer", rxs, input, i); | 743 | log_error("variable.regset: %s(%s)#%d: not an integer", rxs, input, i); |
747 | value.i = 0; | 744 | value.i = 0; |
748 | } else if (errno) { | 745 | } else if (errno) { |
749 | log_error("variable.batchset: %s(%s)#%d: %s", | 746 | log_error("variable.regset: %s(%s)#%d: %s", |
750 | rxs, input, i, strerror(errno)); | 747 | rxs, input, i, strerror(errno)); |
751 | value.i = 0; | 748 | value.i = 0; |
752 | } else if (lval < INT_MIN || lval > INT_MAX) { | 749 | } else if (lval < INT_MIN || lval > INT_MAX) { |
753 | log_error("variable.batchset: %s(%s)#%d: value out of range", | 750 | log_error("variable.regset: %s(%s)#%d: value out of range", |
754 | rxs, input, i); | 751 | rxs, input, i); |
755 | value.i = 0; | 752 | value.i = 0; |
756 | } else | 753 | } else |
757 | value.i = lval; | 754 | value.i = lval; |
758 | free(s); | 755 | free(s); |
759 | break; | 756 | break; |
760 | case variable_real: | 757 | case variable_real: |
761 | errno = 0; | 758 | errno = 0; |
762 | value.r = strtod(s, &p); | 759 | value.r = strtod(s, &p); |
763 | if (*p) { | 760 | if (*p) { |
764 | log_error("variable.batchset: %s(%s)#%d: not a valid number", rxs, input, i); | 761 | log_error("variable.regset: %s(%s)#%d: not a valid number", rxs, input, i); |
765 | value.r = 0; | 762 | value.r = 0; |
766 | } else if (errno) { | 763 | } else if (errno) { |
767 | log_error("variable.batchset: %s(%s)#%d: %s", | 764 | log_error("variable.regset: %s(%s)#%d: %s", |
768 | rxs, input, i, strerror(errno)); | 765 | rxs, input, i, strerror(errno)); |
769 | value.r = 0; | 766 | value.r = 0; |
770 | } | 767 | } |
771 | free(s); | 768 | free(s); |
772 | break; | 769 | break; |
773 | 770 | ||
diff --git a/src/variable.vcc b/src/variable.vcc index b8eb8e2..7fca518 100644 --- a/src/variable.vcc +++ b/src/variable.vcc | |||
@@ -30,8 +30,8 @@ $Function VOID set_duration(STRING, DURATION) | |||
30 | $Function DURATION get_duration(STRING) | 30 | $Function DURATION get_duration(STRING) |
31 | $Function VOID clear() | 31 | $Function VOID clear() |
32 | 32 | ||
33 | $Function INT defined(STRING) | 33 | $Function INT defined(STRING) |
34 | $Function STRING type_of(STRING) | 34 | $Function STRING type_of(STRING) |
35 | $Function VOID undef(STRING) | 35 | $Function VOID undef(STRING) |
36 | $Function VOID batchset(STRING, STRING, STRING) | 36 | $Function VOID regset(STRING, STRING, STRING) |
37 | 37 | ||
diff --git a/tests/Makefile.am b/tests/Makefile.am index 1a81bea..99769ae 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am | |||
@@ -38,20 +38,20 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac | |||
38 | ## ------------ ## | 38 | ## ------------ ## |
39 | ## Test suite. ## | 39 | ## Test suite. ## |
40 | ## ------------ ## | 40 | ## ------------ ## |
41 | 41 | ||
42 | TESTSUITE_AT = \ | 42 | TESTSUITE_AT = \ |
43 | testsuite.at\ | 43 | testsuite.at\ |
44 | batchset.at\ | ||
45 | complex.at\ | 44 | complex.at\ |
46 | clear.at\ | 45 | clear.at\ |
47 | defined.at\ | 46 | defined.at\ |
48 | duration.at\ | 47 | duration.at\ |
49 | gstring.at\ | 48 | gstring.at\ |
50 | int.at\ | 49 | int.at\ |
51 | real.at\ | 50 | real.at\ |
51 | regset.at\ | ||
52 | string.at\ | 52 | string.at\ |
53 | type_of.at\ | 53 | type_of.at\ |
54 | undef.at | 54 | undef.at |
55 | 55 | ||
56 | TESTSUITE = $(srcdir)/testsuite | 56 | TESTSUITE = $(srcdir)/testsuite |
57 | M4=m4 | 57 | M4=m4 |
diff --git a/tests/batchset.at b/tests/regset.at index 506fe78..cc92578 100644 --- a/tests/batchset.at +++ b/tests/regset.at | |||
@@ -11,18 +11,18 @@ | |||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | # GNU General Public License for more details. | 12 | # GNU General Public License for more details. |
13 | # | 13 | # |
14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
15 | # along with vmod-variable. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with vmod-variable. If not, see <http://www.gnu.org/licenses/>. |