1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-07-01 02:08:54 +03:00

b2/: regexec puts first substring into pmatch[1] and not pmatch[0]

Also clean up the hard-coded number of matches.
This commit is contained in:
Werner Almesberger 2012-05-22 13:46:44 -03:00
parent 3d2eca34ff
commit 148d5e85ac
2 changed files with 10 additions and 7 deletions

View File

@ -26,7 +26,7 @@
#include "subex.h"
#define FIELDS 10
#define FIELDS 10 /* fields in KiCad schematics */
static const char *fn = NULL, *f[FIELDS];
@ -116,11 +116,11 @@ static char *compose(const struct chunk *c,
append(&res, &res_len, s);
break;
}
if (match[n-1].rm_so == -1)
if (match[n].rm_so == -1)
break;
len = match[n-1].rm_eo-match[n-1].rm_so;
len = match[n].rm_eo-match[n].rm_so;
tmp = alloc_size(len);
memcpy(tmp, s+match[n-1].rm_so, len);
memcpy(tmp, s+match[n].rm_so, len);
tmp[len] = 0;
tmp2 = canonicalize(tmp, units ? units[n-1] : 0);
append(&res, &res_len, tmp2);
@ -160,7 +160,7 @@ static int do_match_1(const char *var, const regex_t *re,
*val = var_lookup(in, var);
if (!*val)
return -1;
return regexec(re, *val, 10, match, 0);
return regexec(re, *val, NMATCH, match, 0);
}
@ -186,7 +186,7 @@ static const struct subst *recurse_sub(const struct subst *sub,
const regmatch_t *match, const char *units, struct param **out)
{
const struct subst *jump;
regmatch_t m_tmp[10];
regmatch_t m_tmp[NMATCH];
const char *var, *val;
char *tmp;

View File

@ -20,6 +20,9 @@
#include "relop.h"
#define NMATCH 10 /* $0 (not used), $1...$9 */
enum chunk_type {
ct_string,
ct_var,
@ -52,7 +55,7 @@ struct subst {
const char *src;
regex_t re;
struct subst *block;
char units[10];
char units[NMATCH-1];
int parens; /* number of parentheses */
} match;
struct {