summaryrefslogtreecommitdiffstats
path: root/generic/regc_cvec.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2002-07-29 10:56:08 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2002-07-29 10:56:08 (GMT)
commit392e6300e2782ea71b0e7e57f97e7b74ced0530b (patch)
treee6c38e79aa2217b6f74c03b96dea9f14f3e29f97 /generic/regc_cvec.c
parent8aac5314070c34799ffa1a70feb28b35584bc49a (diff)
downloadtcl-392e6300e2782ea71b0e7e57f97e7b74ced0530b.zip
tcl-392e6300e2782ea71b0e7e57f97e7b74ced0530b.tar.gz
tcl-392e6300e2782ea71b0e7e57f97e7b74ced0530b.tar.bz2
Fixes for regexp issues raised in [Bug 578363].
Lots of thanks to pvgoran@users.sf.net for tracking them down! Also made the RE files touched meet the Tcl Engineering Guidelines a bit better (they've a long way to go, but this is a start...)
Diffstat (limited to 'generic/regc_cvec.c')
-rw-r--r--generic/regc_cvec.c186
1 files changed, 98 insertions, 88 deletions
diff --git a/generic/regc_cvec.c b/generic/regc_cvec.c
index 86765ea..d2d56fc 100644
--- a/generic/regc_cvec.c
+++ b/generic/regc_cvec.c
@@ -36,26 +36,27 @@
*/
static struct cvec *
newcvec(nchrs, nranges, nmcces)
-int nchrs; /* to hold this many chrs... */
-int nranges; /* ... and this many ranges... */
-int nmcces; /* ... and this many MCCEs */
+ int nchrs; /* to hold this many chrs... */
+ int nranges; /* ... and this many ranges... */
+ int nmcces; /* ... and this many MCCEs */
{
- size_t n;
- size_t nc;
- struct cvec *cv;
+ size_t n;
+ size_t nc;
+ struct cvec *cv;
- nc = (size_t)nchrs + (size_t)nmcces*(MAXMCCE+1) + (size_t)nranges*2;
- n = sizeof(struct cvec) + (size_t)(nmcces-1)*sizeof(chr *) +
- nc*sizeof(chr);
- cv = (struct cvec *)MALLOC(n);
- if (cv == NULL)
- return NULL;
- cv->chrspace = nc;
- cv->chrs = (chr *)&cv->mcces[nmcces]; /* chrs just after MCCE ptrs */
- cv->mccespace = nmcces;
- cv->ranges = cv->chrs + nchrs + nmcces*(MAXMCCE+1);
- cv->rangespace = nranges;
- return clearcvec(cv);
+ nc = (size_t)nchrs + (size_t)nmcces*(MAXMCCE+1) + (size_t)nranges*2;
+ n = sizeof(struct cvec) + (size_t)(nmcces-1)*sizeof(chr *)
+ + nc*sizeof(chr);
+ cv = (struct cvec *)MALLOC(n);
+ if (cv == NULL) {
+ return NULL;
+ }
+ cv->chrspace = nchrs;
+ cv->chrs = (chr *)&cv->mcces[nmcces]; /* chrs just after MCCE ptrs */
+ cv->mccespace = nmcces;
+ cv->ranges = cv->chrs + nchrs + nmcces*(MAXMCCE+1);
+ cv->rangespace = nranges;
+ return clearcvec(cv);
}
/*
@@ -65,20 +66,21 @@ int nmcces; /* ... and this many MCCEs */
*/
static struct cvec *
clearcvec(cv)
-struct cvec *cv;
+ struct cvec *cv; /* character vector */
{
- int i;
+ int i;
- assert(cv != NULL);
- cv->nchrs = 0;
- assert(cv->chrs == (chr *)&cv->mcces[cv->mccespace]);
- cv->nmcces = 0;
- cv->nmccechrs = 0;
- cv->nranges = 0;
- for (i = 0; i < cv->mccespace; i++)
- cv->mcces[i] = NULL;
+ assert(cv != NULL);
+ cv->nchrs = 0;
+ assert(cv->chrs == (chr *)&cv->mcces[cv->mccespace]);
+ cv->nmcces = 0;
+ cv->nmccechrs = 0;
+ cv->nranges = 0;
+ for (i = 0; i < cv->mccespace; i++) {
+ cv->mcces[i] = NULL;
+ }
- return cv;
+ return cv;
}
/*
@@ -87,11 +89,11 @@ struct cvec *cv;
*/
static VOID
addchr(cv, c)
-struct cvec *cv;
-pchr c;
+ struct cvec *cv; /* character vector */
+ pchr c; /* character to add */
{
- assert(cv->nchrs < cv->chrspace - cv->nmccechrs);
- cv->chrs[cv->nchrs++] = (chr)c;
+ assert(cv->nchrs < cv->chrspace - cv->nmccechrs);
+ cv->chrs[cv->nchrs++] = (chr)c;
}
/*
@@ -100,14 +102,14 @@ pchr c;
*/
static VOID
addrange(cv, from, to)
-struct cvec *cv;
-pchr from;
-pchr to;
+ struct cvec *cv; /* character vector */
+ pchr from; /* first character of range */
+ pchr to; /* last character of range */
{
- assert(cv->nranges < cv->rangespace);
- cv->ranges[cv->nranges*2] = (chr)from;
- cv->ranges[cv->nranges*2 + 1] = (chr)to;
- cv->nranges++;
+ assert(cv->nranges < cv->rangespace);
+ cv->ranges[cv->nranges*2] = (chr)from;
+ cv->ranges[cv->nranges*2 + 1] = (chr)to;
+ cv->nranges++;
}
/*
@@ -116,49 +118,55 @@ pchr to;
*/
static VOID
addmcce(cv, startp, endp)
-struct cvec *cv;
-chr *startp; /* beginning of text */
-chr *endp; /* just past end of text */
+ struct cvec *cv; /* character vector */
+ chr *startp; /* beginning of text */
+ chr *endp; /* just past end of text */
{
- int len;
- int i;
- chr *s;
- chr *d;
+ int len;
+ int i;
+ chr *s;
+ chr *d;
- if (startp == NULL && endp == NULL)
- return;
- len = endp - startp;
- assert(len > 0);
- assert(cv->nchrs + len < cv->chrspace - cv->nmccechrs);
- assert(cv->nmcces < cv->mccespace);
- d = &cv->chrs[cv->chrspace - cv->nmccechrs - len - 1];
- cv->mcces[cv->nmcces++] = d;
- for (s = startp, i = len; i > 0; s++, i--)
- *d++ = *s;
- *d++ = 0; /* endmarker */
- assert(d == &cv->chrs[cv->chrspace - cv->nmccechrs]);
- cv->nmccechrs += len + 1;
+ if (startp == NULL && endp == NULL) {
+ return;
+ }
+ len = endp - startp;
+ assert(len > 0);
+ assert(cv->nchrs + len < cv->chrspace - cv->nmccechrs);
+ assert(cv->nmcces < cv->mccespace);
+ d = &cv->chrs[cv->chrspace - cv->nmccechrs - len - 1];
+ cv->mcces[cv->nmcces++] = d;
+ for (s = startp, i = len; i > 0; s++, i--) {
+ *d++ = *s;
+ }
+ *d++ = 0; /* endmarker */
+ assert(d == &cv->chrs[cv->chrspace - cv->nmccechrs]);
+ cv->nmccechrs += len + 1;
}
/*
- haschr - does a cvec contain this chr?
^ static int haschr(struct cvec *, pchr);
*/
-static int /* predicate */
+static int /* predicate */
haschr(cv, c)
-struct cvec *cv;
-pchr c;
+ struct cvec *cv; /* character vector */
+ pchr c; /* character to test for */
{
- int i;
- chr *p;
+ int i;
+ chr *p;
- for (p = cv->chrs, i = cv->nchrs; i > 0; p++, i--)
- if (*p == c)
- return 1;
- for (p = cv->ranges, i = cv->nranges; i > 0; p += 2, i--)
- if (*p <= c && c <= *(p+1))
- return 1;
- return 0;
+ for (p = cv->chrs, i = cv->nchrs; i > 0; p++, i--) {
+ if (*p == c) {
+ return 1;
+ }
+ }
+ for (p = cv->ranges, i = cv->nranges; i > 0; p += 2, i--) {
+ if ((*p <= c) && (c <= *(p+1))) {
+ return 1;
+ }
+ }
+ return 0;
}
/*
@@ -167,23 +175,25 @@ pchr c;
*/
static struct cvec *
getcvec(v, nchrs, nranges, nmcces)
-struct vars *v;
-int nchrs; /* to hold this many chrs... */
-int nranges; /* ... and this many ranges... */
-int nmcces; /* ... and this many MCCEs */
+ struct vars *v; /* context */
+ int nchrs; /* to hold this many chrs... */
+ int nranges; /* ... and this many ranges... */
+ int nmcces; /* ... and this many MCCEs */
{
- if (v->cv != NULL && nchrs <= v->cv->chrspace &&
- nranges <= v->cv->rangespace &&
- nmcces <= v->cv->mccespace)
- return clearcvec(v->cv);
+ if (v->cv != NULL && nchrs <= v->cv->chrspace &&
+ nranges <= v->cv->rangespace && nmcces <= v->cv->mccespace) {
+ return clearcvec(v->cv);
+ }
- if (v->cv != NULL)
- freecvec(v->cv);
- v->cv = newcvec(nchrs, nranges, nmcces);
- if (v->cv == NULL)
- ERR(REG_ESPACE);
+ if (v->cv != NULL) {
+ freecvec(v->cv);
+ }
+ v->cv = newcvec(nchrs, nranges, nmcces);
+ if (v->cv == NULL) {
+ ERR(REG_ESPACE);
+ }
- return v->cv;
+ return v->cv;
}
/*
@@ -192,7 +202,7 @@ int nmcces; /* ... and this many MCCEs */
*/
static VOID
freecvec(cv)
-struct cvec *cv;
+ struct cvec *cv; /* character vector */
{
- FREE(cv);
+ FREE(cv);
}