mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-23 01:41:53 +02:00
b2/subst.c: use vstring for modified regexp
This commit is contained in:
parent
4e39ca2e31
commit
9681d44ca4
22
b2/subst.c
22
b2/subst.c
@ -19,6 +19,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "vstring.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include "subst.h"
|
#include "subst.h"
|
||||||
|
|
||||||
@ -37,21 +38,28 @@ static struct subst *alloc_subst(enum subst_type type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *prepare_re(const char *re)
|
||||||
|
{
|
||||||
|
char *res = NULL;
|
||||||
|
int res_len = 0;
|
||||||
|
|
||||||
|
append_char(&res, &res_len, '^');
|
||||||
|
append(&res, &res_len, re);
|
||||||
|
append_char(&res, &res_len, '$');
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct subst *subst_match(const char *src, const char *re)
|
struct subst *subst_match(const char *src, const char *re)
|
||||||
{
|
{
|
||||||
char error[1000];
|
char error[1000];
|
||||||
struct subst *sub;
|
struct subst *sub;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int err, len;
|
int err;
|
||||||
|
|
||||||
sub = alloc_subst(st_match);
|
sub = alloc_subst(st_match);
|
||||||
sub->u.match.src = src;
|
sub->u.match.src = src;
|
||||||
len = strlen(re);
|
tmp = prepare_re(re);
|
||||||
tmp = alloc_size(len+3);
|
|
||||||
tmp[0] = '^';
|
|
||||||
memcpy(tmp+1, re, len);
|
|
||||||
tmp[len+1] = '$';
|
|
||||||
tmp[len+2] = 0;
|
|
||||||
err = regcomp(&sub->u.match.re, tmp, REG_EXTENDED);
|
err = regcomp(&sub->u.match.re, tmp, REG_EXTENDED);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user