|
|
1.1 ! root 1: #include "regprog.h" ! 2: #define NULL 0 ! 3: ! 4: /* substitute into one string using the matches from the last regexec() */ ! 5: extern void ! 6: regsub (progp, sp, dp) ! 7: Prog *progp; /* context of substitution */ ! 8: char *sp; /* source string */ ! 9: char *dp; /* destination string */ ! 10: { ! 11: char *ssp; ! 12: ! 13: while (*sp != '\0') { ! 14: if (*sp == '\\') { ! 15: switch (*++sp) { ! 16: case '0': ! 17: case '1': ! 18: case '2': ! 19: case '3': ! 20: case '4': ! 21: case '5': ! 22: case '6': ! 23: case '7': ! 24: case '8': ! 25: case '9': ! 26: if (progp->se.startp[*sp-'0'] != NULL) ! 27: for (ssp = progp->se.startp[*sp-'0']; ! 28: ssp < progp->se.endp[*sp-'0']; ! 29: ssp++) ! 30: *dp++ = *ssp; ! 31: break; ! 32: case '\\': ! 33: *dp++ = '\\'; ! 34: break; ! 35: case '\0': ! 36: sp--; ! 37: break; ! 38: default: ! 39: *dp++ = *sp; ! 40: break; ! 41: } ! 42: } else if (*sp == '&') { ! 43: if (progp->se.startp[0] != NULL) ! 44: for (ssp = progp->se.startp[0]; ! 45: ssp < progp->se.endp[0]; ssp++) ! 46: *dp++ = *ssp; ! 47: } else ! 48: *dp++ = *sp; ! 49: sp++; ! 50: } ! 51: *dp = '\0'; ! 52: } ! 53: ! 54: #ifdef DEBUG ! 55: regdump(subp) ! 56: Subexp *subp; ! 57: { ! 58: int i; ! 59: char *cp; ! 60: ! 61: printf ("matches are:\n"); ! 62: for (i = 0; i < NSUBEXP; i++) { ! 63: if (subp->startp[i] != NULL) { ! 64: printf("\t(%d) ", i); ! 65: for (cp = subp->startp[i]; cp < subp->endp[i]; cp++) ! 66: putchar(*cp); ! 67: putchar('\n'); ! 68: } ! 69: } ! 70: } ! 71: #endif DEBUG
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.