Changeset: d37d902aad63 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d37d902aad63 Modified Files: clients/Tests/exports.stable.out monetdb5/modules/mal/pcre.c Branch: default Log Message:
A little cleanup of the pcre module. diffs (truncated from 544 to 300 lines): diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -1836,7 +1836,6 @@ str OPTvectorOid(Client cntxt, MalBlkPtr str OPTwrapper(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); str PCREcompile_wrap(pcre **res, str *pattern); str PCREexec_wrap(bit *res, pcre *pattern, str *s); -str PCREfromstr(str instr, int *l, pcre **val); str PCREilike2(bit *ret, str *s, str *pat); str PCREilike3(bit *ret, str *s, str *pat, str *esc); str PCREilike_join_pcre(int *l, int *r, int *b, int *pat, str *esc); @@ -1861,10 +1860,8 @@ str PCREpatindex(int *ret, str *pat, str str PCREquote(str *r, str *v); str PCREreplace_bat_wrap(int *res, int *or, str *pat, str *repl, str *flags); str PCREreplace_wrap(str *res, str *or, str *pat, str *repl, str *flags); -str PCREselect(int *res, str *pattern, int *bid, bit *ignore); str PCREselectDef(int *res, str *pattern, int *bid); str PCREsql2pcre(str *ret, str *pat, str *esc); -str PCREuselect(int *res, str *pattern, int *bid, bit *ignore); str PCREuselectDef(int *res, str *pattern, int *bid); str PQdequeue_anymax(int *ret, int *bid); str PQdequeue_anymin(int *ret, int *bid); @@ -2901,7 +2898,7 @@ str partitionRef; str passRef; str pcreRef; void pcre_del(Heap *h, var_t *index); -int pcre_fromstr(str instr, int *l, pcre **val); +int pcre_fromstr(const char *instr, int *l, pcre **val); BUN pcre_hash(pcre *b); void pcre_heap(Heap *heap, size_t capacity); str pcre_init(void); diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c --- a/monetdb5/modules/mal/pcre.c +++ b/monetdb5/modules/mal/pcre.c @@ -26,7 +26,7 @@ * (release 4.x) corresponds approximately with Perl 5.8, including support * for UTF-8 encoded strings. However, this support has to be * explicitly enabled; it is not the default. - * + * * ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre */ #include "monetdb_config.h" @@ -49,28 +49,25 @@ #include <pcre.h> pcre_export str PCREquote(str *r, str *v); -pcre_export str PCREselect(int *res, str *pattern, int *bid, bit *ignore); -pcre_export str PCREuselect(int *res, str *pattern, int *bid, bit *ignore); pcre_export str PCREmatch(bit *ret, str *val, str *pat); pcre_export str PCREimatch(bit *ret, str *val, str *pat); pcre_export str PCREindex(int *ret, pcre *pat, str *val); pcre_export str PCREpatindex(int *ret, str *pat, str *val); -pcre_export str PCREfromstr(str instr, int *l, pcre ** val); pcre_export str PCREreplace_wrap(str *res, str *or, str *pat, str *repl, str *flags); pcre_export str PCREreplace_bat_wrap(int *res, int *or, str *pat, str *repl, str *flags); -pcre_export str PCREcompile_wrap(pcre ** res, str *pattern); -pcre_export str PCREexec_wrap(bit *res, pcre * pattern, str *s); -pcre_export int pcre_tostr(str *tostr, int *l, pcre * p); -pcre_export int pcre_fromstr(str instr, int *l, pcre ** val); -pcre_export int pcre_nequal(pcre * l, pcre * r); -pcre_export BUN pcre_hash(pcre * b); -pcre_export pcre * pcre_null(void); +pcre_export str PCREcompile_wrap(pcre **res, str *pattern); +pcre_export str PCREexec_wrap(bit *res, pcre *pattern, str *s); +pcre_export int pcre_tostr(str *tostr, int *l, pcre *p); +pcre_export int pcre_fromstr(const char *instr, int *l, pcre **val); +pcre_export int pcre_nequal(pcre *l, pcre *r); +pcre_export BUN pcre_hash(pcre *b); +pcre_export pcre *pcre_null(void); pcre_export void pcre_del(Heap *h, var_t *index); -pcre_export int pcre_length(pcre * p); +pcre_export int pcre_length(pcre *p); pcre_export void pcre_heap(Heap *heap, size_t capacity); -pcre_export var_t pcre_put(Heap *h, var_t *bun, pcre * val); +pcre_export var_t pcre_put(Heap *h, var_t *bun, pcre *val); pcre_export str PCREsql2pcre(str *ret, str *pat, str *esc); pcre_export str PCRElike3(bit *ret, str *s, str *pat, str *esc); pcre_export str PCRElike2(bit *ret, str *s, str *pat); @@ -258,7 +255,7 @@ re_uselect(RE *pattern, BAT *strs, int i if (ignore) { BATloop(strs, p, q) { - str s = BUNtail(strsi, p); + const char *s = BUNtail(strsi, p); if (re_match_ignore(s, pattern) && BUNfastins(r, BUNhead(strsi, p), NULL) == NULL) { @@ -268,7 +265,7 @@ re_uselect(RE *pattern, BAT *strs, int i } } else { BATloop(strs, p, q) { - str s = BUNtail(strsi, p); + const char *s = BUNtail(strsi, p); if (re_match_no_ignore(s, pattern) && BUNfastins(r, BUNhead(strsi, p), NULL) == NULL) { @@ -305,14 +302,14 @@ re_select(RE *pattern, BAT *strs, int ig if (ignore) { BATloop(strs, p, q) { - str s = BUNtail(strsi, p); + const char *s = BUNtail(strsi, p); if (re_match_ignore(s, pattern)) BUNins(r, BUNhead(strsi, p), s, FALSE); } } else { BATloop(strs, p, q) { - str s = BUNtail(strsi, p); + const char *s = BUNtail(strsi, p); if (re_match_no_ignore(s, pattern)) BUNins(r, BUNhead(strsi, p), s, FALSE); @@ -357,7 +354,7 @@ my_pcre_free(void *blk) } static str -pcre_compile_wrap(pcre ** res, str pattern, bit insensitive) +pcre_compile_wrap(pcre **res, const char *pattern, bit insensitive) { pcre *r; const char err[BUFSIZ], *err_p = err; @@ -375,29 +372,6 @@ pcre_compile_wrap(pcre ** res, str patte return MAL_SUCCEED; } -static str -pcre_exec_wrap(bit *res, pcre * pattern, str s) -{ - if (pcre_exec(m2p(pattern), NULL, s, (int) strlen(s), 0, 0, NULL, 0) >= 0) { - *res = TRUE; - return MAL_SUCCEED; - } - *res = FALSE; - throw(MAL, "pcre.exec", OPERATION_FAILED); -} - -static str -pcre_index(int *res, pcre * pattern, str s) -{ - int v[2]; - - v[0] = v[1] = *res = 0; - if (pcre_exec(m2p(pattern), NULL, s, (int) strlen(s), 0, 0, v, 2) >= 0) { - *res = v[1]; - } - return MAL_SUCCEED; -} - /* these two defines are copies from gdk_select.c */ /* scan select loop with candidates */ @@ -555,7 +529,7 @@ re_likesubselect(BAT **bnp, BAT *b, BAT assert(anti == 0 || anti == 1); bn = BATnew(TYPE_void, TYPE_oid, s ? BATcount(s) : BATcount(b)); - if (bn == NULL) + if (bn == NULL) throw(MAL, "pcre.likesubselect", MAL_MALLOC_FAIL); off = b->hseqbase - BUNfirst(b); @@ -646,7 +620,7 @@ re_likesubselect(BAT **bnp, BAT *b, BAT } static str -pcre_select(BAT **res, str pattern, BAT *strs, bit insensitive) +pcre_select(BAT **res, const char *pattern, BAT *strs, bit insensitive) { BATiter strsi = bat_iterator(strs); const char err[BUFSIZ], *err_p = err; @@ -667,7 +641,7 @@ pcre_select(BAT **res, str pattern, BAT pattern, errpos, err_p); } BATloop(strs, p, q) { - str s = BUNtail(strsi, p); + const char *s = BUNtail(strsi, p); if (pcre_exec(re, NULL, s, (int) strlen(s), 0, 0, NULL, 0) >= 0) { BUNins(r, BUNhead(strsi, p), s, FALSE); @@ -680,7 +654,7 @@ pcre_select(BAT **res, str pattern, BAT } static str -pcre_uselect(BAT **res, str pattern, BAT *strs, bit insensitive) +pcre_uselect(BAT **res, const char *pattern, BAT *strs, bit insensitive) { BATiter strsi = bat_iterator(strs); const char err[BUFSIZ], *err_p = err; @@ -709,7 +683,7 @@ pcre_uselect(BAT **res, str pattern, BAT throw(MAL, "pcre_uselect", OPERATION_FAILED "pcre compile of pattern (%s) failed with\n'%s'.", pattern, err_p); BATloop(strs, p, q) { - str s = BUNtail(strsi, p); + const char *s = BUNtail(strsi, p); int l = (int) strlen(s); if (pcre_exec(re, pe, s, l, 0, 0, NULL, 0) >= 0 && @@ -736,12 +710,12 @@ pcre_uselect(BAT **res, str pattern, BAT #define MAX_NR_CAPTURES 1024 /* Maximal number of captured substrings in one original string */ static str -pcre_replace(str *res, str origin_str, str pattern, str replacement, str flags) +pcre_replace(str *res, const char *origin_str, const char *pattern, const char *replacement, const char *flags) { const char err[BUFSIZ], *err_p = err, *err_p2 = err; pcre *pcre_code = NULL; pcre_extra *extra; - str tmpres; + char *tmpres; int i, j, k, len, errpos = 0, offset = 0; int compile_options = PCRE_UTF8, exec_options = PCRE_NOTEMPTY; int *ovector, ovecsize; @@ -843,7 +817,7 @@ pcre_replace(str *res, str origin_str, s } static str -pcre_replace_bat(BAT **res, BAT *origin_strs, str pattern, str replacement, str flags) +pcre_replace_bat(BAT **res, BAT *origin_strs, const char *pattern, const char *replacement, const char *flags) { BATiter origin_strsi = bat_iterator(origin_strs); const char err[BUFSIZ], *err_p = err, *err_p2 = err; @@ -856,7 +830,8 @@ pcre_replace_bat(BAT **res, BAT *origin_ int *ovector, ovecsize; int len_origin_str, len_replacement = (int) strlen(replacement); int capture_offsets[MAX_NR_CAPTURES * 2], ncaptures = 0, len_del = 0; - str origin_str, replaced_str; + const char *origin_str; + char *replaced_str; for (i = 0; i < (int)strlen(flags); i++) { if (flags[i] == 'e') { @@ -969,7 +944,7 @@ pcre_init(void) } static str -pcre_match_with_flags(bit *ret, str val, str pat, str flags) +pcre_match_with_flags(bit *ret, const char *val, const char *pat, const char *flags) { const char err[BUFSIZ], *err_p = err; int errpos = 0; @@ -1014,30 +989,8 @@ pcre_match_with_flags(bit *ret, str val, return MAL_SUCCEED; } -static int -pcre_quote(str *res, str s) -{ - str p; - - *res = p = GDKmalloc(strlen(s) * 2 + 1); /* certainly long enough */ - if (p == NULL) - return GDK_FAIL; - /* quote all non-alphanumeric ASCII characters (i.e. leave - non-ASCII and alphanumeric alone) */ - while (*s) { - if (!((*s & 0x80) != 0 || - ('a' <= *s && *s <= 'z') || - ('A' <= *s && *s <= 'Z') || - ('0' <= *s && *s <= '9'))) - *p++ = '\\'; - *p++ = *s++; - } - *p = 0; - return GDK_SUCCEED; -} - int -pcre_tostr(str *tostr, int *l, pcre * p) +pcre_tostr(str *tostr, int *l, pcre *p) { (void) tostr; (void) l; @@ -1046,7 +999,7 @@ pcre_tostr(str *tostr, int *l, pcre * p) } int -pcre_fromstr(str instr, int *l, pcre ** val) +pcre_fromstr(const char *instr, int *l, pcre **val) { (void) instr; (void) l; @@ -1055,7 +1008,7 @@ pcre_fromstr(str instr, int *l, pcre ** } int -pcre_nequal(pcre * l, pcre * r) +pcre_nequal(pcre *l, pcre *r) { if (l != r) return 0; @@ -1064,7 +1017,7 @@ pcre_nequal(pcre * l, pcre * r) } BUN -pcre_hash(pcre * b) +pcre_hash(pcre *b) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list