Annotation of researchv9/libc/gen/regsub.c, revision 1.1

1.1     ! root        1: #include "regprog.h"
        !             2: 
        !             3: /* substitute into one string using the matches from the last regexec() */
        !             4: extern void
        !             5: regsub (sp, dp, mp, ms)
        !             6:        char *sp;       /* source string */
        !             7:        char *dp;       /* destination string */
        !             8:        regsubexp *mp;  /* subexpression elements */
        !             9:        int ms;         /* number of elements pointed to by mp */
        !            10: {
        !            11:        char *ssp;
        !            12:        register int i;
        !            13: 
        !            14:        while (*sp != '\0') {
        !            15:                if (*sp == '\\') {
        !            16:                        switch (*++sp) {
        !            17:                        case '0':
        !            18:                        case '1':
        !            19:                        case '2':
        !            20:                        case '3':
        !            21:                        case '4':
        !            22:                        case '5':
        !            23:                        case '6':
        !            24:                        case '7':
        !            25:                        case '8':
        !            26:                        case '9':
        !            27:                                i = *sp-'0';
        !            28:                                if (mp[i].sp != NULL && mp!=NULL && ms>i)
        !            29:                                        for (ssp = mp[i].sp;
        !            30:                                             ssp < mp[i].ep;
        !            31:                                             ssp++)
        !            32:                                                *dp++ = *ssp;
        !            33:                                break;
        !            34:                        case '\\':
        !            35:                                *dp++ = '\\';
        !            36:                                break;
        !            37:                        case '\0':
        !            38:                                sp--;
        !            39:                                break;
        !            40:                        default:
        !            41:                                *dp++ = *sp;
        !            42:                                break;
        !            43:                        }
        !            44:                } else if (*sp == '&') {                                
        !            45:                        if (mp[0].sp != NULL && mp!=NULL && ms>0)
        !            46:                        if (mp[0].sp != NULL)
        !            47:                                for (ssp = mp[0].sp;
        !            48:                                     ssp < mp[0].ep; ssp++)
        !            49:                                        *dp++ = *ssp;
        !            50:                } else
        !            51:                        *dp++ = *sp;
        !            52:                sp++;
        !            53:        }
        !            54:        *dp = '\0';
        !            55: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.