- else if (*patt>='0' && *patt<='9') {
-regmatch_t *match=matches+(*patt-'0');
- if (match->rm_so==-1
- || match->rm_eo==-1) {
- fprintf(ERRH1"Trying to substitute '%c' but no \"matches\" entry not set for \"%s\""WHERE1,
- ERRH2,*patt,item->text,WHERE2);
- exit(EXIT_FAILURE);
- }
- if (match->rm_so>match->rm_eo) {
- fprintf(ERRH1"Trying to substitute '%c' start>end (%d>%d) for \"%s\""WHERE1,
- ERRH2,*patt,match->rm_so,match->rm_eo,item->text,WHERE2);
- exit(EXIT_FAILURE);
- }
- start=src+match->rm_so; end=src+match->rm_eo;
+ else
+ *dst++=*patt;
+ }
+ }
+ else {
+ if (!item)
+ return src;
+ i=regexec(&modistructs[m].regex,src,LENGTH(matches),matches,0);
+ if (i==REG_NOMATCH) {
+ willprep=0;
+ break;
+ }
+ if (i) {
+ fprintf(ERRH1"regexec() failed for \"%s\""ERRNO1,ERRH2,item->text,ERRNO2);
+ exit(EXIT_FAILURE);
+ }
+ willprep=1;
+ if (verbose) printf("matched: %s -> %s\n",item->text,modistructs[m].dst);
+ pattpos=PATT_START; patt=NULL;
+ while (pattpos!=PATT_TERM) {
+ switch (pattpos) {
+ case PATT_START:
+ start=src;
+ end=src+matches->rm_so;
+ pattpos=PATT_MID; patt=modistructs[m].dst;
+ break;
+ case PATT_MID:
+ if (!*patt) {
+ pattpos=PATT_END; patt=NULL;
+ continue;
+ }
+ else if (*patt=='@') {
+ start=src; end=src+strlen(src);
+ }
+ else if (*patt>='0' && *patt<='9') {
+ regmatch_t *match=matches+(*patt-'0');
+ if (match->rm_so==-1
+ || match->rm_eo==-1) {
+ fprintf(ERRH1"Trying to substitute '%c' but no \"matches\" entry not set for \"%s\""WHERE1,
+ ERRH2,*patt,item->text,WHERE2);
+ exit(EXIT_FAILURE);
+ }
+ if (match->rm_so>match->rm_eo) {
+ fprintf(ERRH1"Trying to substitute '%c' start>end (%d>%d) for \"%s\""WHERE1,
+ ERRH2,*patt,match->rm_so,match->rm_eo,item->text,WHERE2);
+ exit(EXIT_FAILURE);
+ }
+ start=src+match->rm_so; end=src+match->rm_eo;
+ }
+ else {
+ start=patt; end=patt+1;
+ }
+ patt++;
+ break;
+ case PATT_END:
+ start=src+matches->rm_eo;
+ end=src+strlen(src);
+ pattpos=PATT_TERM; /* assumed: patt=NULL; */
+ break;
+ default:
+ assert(0);