chiark
/
gitweb
/
~mdw
/
disorder
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of git.distorted.org.uk:~mdw/publish/public-git/disorder
[disorder]
/
lib
/
regsub.c
diff --git
a/lib/regsub.c
b/lib/regsub.c
index 6345725aecea79ab2ba4104a227351dc0403dfff..d83a2ae11cdf4c9f5bc35182113c65c7bcd7c95c 100644
(file)
--- a/
lib/regsub.c
+++ b/
lib/regsub.c
@@
-2,28
+2,25
@@
* This file is part of DisOrder
* Copyright (C) 2004, 2005, 2007, 20008 Richard Kettlewell
*
* This file is part of DisOrder
* Copyright (C) 2004, 2005, 2007, 20008 Richard Kettlewell
*
- * This program is free software
;
you can redistribute it and/or modify
+ * This program is free software
:
you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation
; either version 2
of the License, or
+ * the Free Software Foundation
, either version 3
of the License, or
* (at your option) any later version.
* (at your option) any later version.
- *
- * This program 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
- * General Public License for more details.
- *
+ *
+ * This program 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
+ * G
NU G
eneral Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
+/** @file lib/regsub.c
+ * @brief Regexp substitution
+ */
+#include "common.h"
-#include <config.h>
-#include "types.h"
-
-#include <string.h>
-#include <pcre.h>
-
+#include "regexp.h"
#include "regsub.h"
#include "mem.h"
#include "vector.h"
#include "regsub.h"
#include "mem.h"
#include "vector.h"
@@
-32,9
+29,9
@@
#define PREMATCH (-1) /* fictitious pre-match substring */
#define POSTMATCH (-2) /* fictitious post-match substring */
#define PREMATCH (-1) /* fictitious pre-match substring */
#define POSTMATCH (-2) /* fictitious post-match substring */
-static inline
in
t substring_start(const char attribute((unused)) *subject,
-
const in
t *ovector,
-
in
t n) {
+static inline
size_
t substring_start(const char attribute((unused)) *subject,
+
const size_
t *ovector,
+
size_
t n) {
switch(n) {
case PREMATCH: return 0;
case POSTMATCH: return ovector[1];
switch(n) {
case PREMATCH: return 0;
case POSTMATCH: return ovector[1];
@@
-42,9
+39,9
@@
static inline int substring_start(const char attribute((unused)) *subject,
}
}
}
}
-static inline
in
t substring_end(const char *subject,
-
const in
t *ovector,
-
in
t n) {
+static inline
size_
t substring_end(const char *subject,
+
const size_
t *ovector,
+
size_
t n) {
switch(n) {
case PREMATCH: return ovector[0];
case POSTMATCH: return strlen(subject);
switch(n) {
case PREMATCH: return ovector[0];
case POSTMATCH: return strlen(subject);
@@
-54,8
+51,8
@@
static inline int substring_end(const char *subject,
static void transform_append(struct dynstr *d,
const char *subject,
static void transform_append(struct dynstr *d,
const char *subject,
- const
in
t *ovector,
-
in
t n) {
+ const
size_
t *ovector,
+
size_
t n) {
int start = substring_start(subject, ovector, n);
int end = substring_end(subject, ovector, n);
int start = substring_start(subject, ovector, n);
int end = substring_end(subject, ovector, n);
@@
-66,9
+63,9
@@
static void transform_append(struct dynstr *d,
static void replace_core(struct dynstr *d,
const char *subject,
const char *replace,
static void replace_core(struct dynstr *d,
const char *subject,
const char *replace,
-
in
t rc,
- const
in
t *ovector) {
-
in
t substr;
+
size_
t rc,
+ const
size_
t *ovector) {
+
size_
t substr;
while(*replace) {
if(*replace == '$')
while(*replace) {
if(*replace == '$')
@@
-115,20
+112,21
@@
int regsub_compile_options(unsigned flags) {
int options = 0;
if(flags & REGSUB_CASE_INDEPENDENT)
int options = 0;
if(flags & REGSUB_CASE_INDEPENDENT)
- options |=
PCRE
_CASELESS;
+ options |=
RXF
_CASELESS;
return options;
}
return options;
}
-const char *regsub(const pcre *re, const char *subject, const char *replace,
- unsigned flags) {
- int rc, ovector[99], matches;
+const char *regsub(const regexp *re, const char *subject,
+ const char *replace, unsigned flags) {
+ int rc, matches;
+ size_t ovector[99];
struct dynstr d;
dynstr_init(&d);
matches = 0;
/* find the next match */
struct dynstr d;
dynstr_init(&d);
matches = 0;
/* find the next match */
- while((rc =
pcre_exec(re, 0
, subject, strlen(subject), 0,
-
0, ovector, sizeof ovector / sizeof (int
))) > 0) {
+ while((rc =
regexp_match(re
, subject, strlen(subject), 0,
+
ovector, sizeof ovector / sizeof (ovector[0]
))) > 0) {
/* text just before the match */
if(!(flags & REGSUB_REPLACE))
transform_append(&d, subject, ovector, PREMATCH);
/* text just before the match */
if(!(flags & REGSUB_REPLACE))
transform_append(&d, subject, ovector, PREMATCH);
@@
-144,8
+142,8
@@
const char *regsub(const pcre *re, const char *subject, const char *replace,
if(!(flags & REGSUB_GLOBAL))
break;
}
if(!(flags & REGSUB_GLOBAL))
break;
}
- if(rc <= 0 && rc !=
PCRE_ERRO
R_NOMATCH) {
-
error(0, "pcre_exec
returned %d, subject '%s'", rc, subject);
+ if(rc <= 0 && rc !=
RXER
R_NOMATCH) {
+
disorder_error(0, "regexp_match
returned %d, subject '%s'", rc, subject);
return 0;
}
if((flags & REGSUB_MUST_MATCH) && matches == 0)
return 0;
}
if((flags & REGSUB_MUST_MATCH) && matches == 0)