Annotation of researchv10no/cmd/sno/sno3.c, revision 1.1.1.1

1.1       root        1: /*     @(#)sno3.c      1.1     */
                      2: #include "sno.h"
                      3: 
                      4: /*
                      5:  * sno3
                      6:  */
                      7: 
                      8: 
                      9: int
                     10: bextend (str, last)
                     11:        struct node *str, *last;
                     12: {
                     13:        register struct node *a, *s;
                     14:        register int b;
                     15:        struct node *cc;
                     16:        int c, d;
                     17: 
                     18:        s = str;
                     19:        if ((cc = s->p1) == 0)
                     20:                goto bad;
                     21:        b = d = 0;
                     22:        a = s->p2;
                     23:        if (a == 0) {
                     24:                a = cc;
                     25:                goto eb2;
                     26:        }
                     27: eb1:
                     28:        if (a == last)
                     29:                goto bad;
                     30:        a = a->p1;
                     31: eb2:
                     32:        d++;
                     33:        c = class (a->ch);
                     34:        if (c == 1) { /* rp */
                     35:                if (b == 0)
                     36:                        goto bad;
                     37:                b--;
                     38:                goto eb3;
                     39:        }
                     40:        if (c == 2) { /* lp */
                     41:                b++;
                     42:                goto eb1;
                     43:        }
                     44: eb3:
                     45:        if (b == 0) {
                     46:                s->p2= a;
                     47:                return (d);
                     48:        }
                     49:        goto eb1;
                     50: bad:
                     51:        return (0);
                     52: }
                     53: 
                     54: int
                     55: ubextend (str, last)
                     56:        struct node *str, *last;
                     57: {
                     58:        register struct node *a, *b, *s;
                     59: 
                     60:        s = str;
                     61:        a = s->p1;
                     62:        if (a == 0)
                     63:                goto bad;
                     64:        b = s->p2;
                     65:        if (b == 0)
                     66:                goto good;
                     67:        if (b == last)
                     68:                goto bad;
                     69:        a = b->p1;
                     70: good:
                     71:        s->p2 = a;
                     72:        return (1);
                     73: bad:
                     74:        return (0);
                     75: }
                     76: 
                     77: struct node *
                     78: search (arg, r)
                     79:        struct node *arg, *r;
                     80: {
                     81:        struct node *list, *back, *str,
                     82:                *etc, *next, *last, *base, *e;
                     83:        register struct node *a, *b, *var;
                     84:        int c, d;
                     85: 
                     86:        a = arg->p2;
                     87:        list = base = salloc();
                     88:        last = next = 0;
                     89:        goto badv1;
                     90: badvanc:
                     91:        a = a->p1;
                     92:        if (a->typ == 0) {
                     93:                list->p1 = 0;
                     94:                if (rfail == 1) {
                     95:                        a = 0;
                     96:                        goto fail;
                     97:                }
                     98:                list = base;
                     99:                if (r == 0)
                    100:                        next = last = 0;
                    101:                else {
                    102:                        next = r->p1;
                    103:                        last = r->p2;
                    104:                }
                    105:                goto adv1;
                    106:        }
                    107:        b = salloc();
                    108:        list->p1 = b;
                    109:        list = b;
                    110: badv1:
                    111:        list->p2 = back = salloc();
                    112:        back->p1 = last;
                    113:        b = a->p2;
                    114:        c = a->typ;
                    115:        list->typ = c;
                    116:        if (c < 2) {
                    117:                back->p2 = eval (b, 1);
                    118:                goto badvanc;
                    119:        }
                    120:        last = list;
                    121:        str = salloc();
                    122:        etc = salloc();
                    123:        back->p2 = var = salloc();
                    124:        var->typ = b->typ;
                    125:        var->p1 = str;
                    126:        var->p2 = etc;
                    127:        e = b->p1;
                    128:        if (e == 0)
                    129:                etc->p1 = 0;
                    130:        else
                    131:                etc->p1 = eval (e, 0);
                    132:        e = b->p2;
                    133:        if (e == 0)
                    134:                etc->p2 = 0;
                    135:        else {
                    136:                e = eval (e, 1);
                    137:                etc->p2 = (struct node *) strbin (e);
                    138:                delete (e);
                    139:        }
                    140:        goto badvanc;
                    141: 
                    142: retard:
                    143:        a = back->p1;
                    144:        if (a == 0) {
                    145:                rfail = 1;
                    146:                goto fail;
                    147:        }
                    148:        list = a;
                    149:        back = list->p2;
                    150:        var = back->p2;
                    151:        str = var->p1;
                    152:        etc = var->p2;
                    153:        if (etc->p2)
                    154:                goto retard;
                    155:        if (var->typ == 1) {
                    156:                if (bextend (str, last) == 0)
                    157:                        goto retard;
                    158:                goto adv0;
                    159:        }
                    160:        if (ubextend (str, last) == 0)
                    161:                goto retard;
                    162: adv0:
                    163:        a = str->p2;
                    164: adv01:
                    165:        if (a == last)
                    166:                next = 0;
                    167:        else
                    168:                next = a->p1;
                    169: advanc:
                    170:        a = list->p1;
                    171:        if (a == 0) {
                    172:                a = salloc();
                    173:                if (r == 0) {
                    174:                        a->p1 = a->p2 = 0;
                    175:                        goto fail;
                    176:                }
                    177:                b = r->p1;
                    178:                a->p1 = b;
                    179:                if (next == 0) {
                    180:                        a->p2 = r->p2;
                    181:                        goto fail;
                    182:                }
                    183:                while (1) {
                    184:                        e = b->p1;
                    185:                        if (e == next) {
                    186:                                a->p2 = b;
                    187:                                goto fail;
                    188:                        }
                    189:                        b = e;
                    190:                }
                    191:        }
                    192:        list = a;
                    193: adv1:
                    194:        back = list->p2;
                    195:        var = back->p2;
                    196:        d = list->typ;
                    197:        if (d < 2) {
                    198:                if (var == 0)
                    199:                        goto advanc;
                    200:                if (next == 0)
                    201:                        goto retard;
                    202:                a = next;
                    203:                b = var->p1;
                    204:                e = var->p2;
                    205:                while (1) {
                    206:                        if (a->ch != b->ch)
                    207:                                goto retard;
                    208:                        if (b == e)
                    209:                                goto adv01;
                    210:                        if (a == last)
                    211:                                goto retard;
                    212:                        a = a->p1;
                    213:                        b = b->p1;
                    214:                }
                    215:        }
                    216:        str = var->p1;
                    217:        etc = var->p2;
                    218:        str->p1 = next;
                    219:        str->p2 = 0;
                    220:        c = (int) etc->p2;
                    221:        if (var->typ == 1) {
                    222:                d = bextend (str, last);
                    223:                if (d == 0)
                    224:                        goto retard;
                    225:                if (c == 0)
                    226:                        goto adv0;
                    227:                while (1) {
                    228:                        c -= d;
                    229:                        if (c == 0)
                    230:                                goto adv0;
                    231:                        if (c < 0)
                    232:                                goto retard;
                    233:                        d = bextend (str, last);
                    234:                        if (d == 0)
                    235:                                goto retard;
                    236:                }
                    237:        }
                    238:        if (c == 0) {
                    239:                if (d==3 && next!=0) {
                    240:                        str->p2 = last;
                    241:                        goto adv0;
                    242:                }
                    243:                goto advanc;
                    244:        }
                    245:        while (c--)
                    246:                if (ubextend (str, last) == 0)
                    247:                        goto retard;
                    248:        goto adv0;
                    249: 
                    250: fail:
                    251:        list = base;
                    252:        goto f1;
                    253: fadv:
                    254:        sfree (back);
                    255:        b = list->p1;
                    256:        sfree (list);
                    257:        if (b == 0)
                    258:                return (a);
                    259:        list = b;
                    260: f1:
                    261:        back = list->p2;
                    262:        var = back->p2;
                    263:        if (list->typ < 2) {
                    264:                delete (var);
                    265:                goto fadv;
                    266:        }
                    267:        str = var->p1;
                    268:        etc = var->p2;
                    269:        if (a != 0 && etc->p1 != 0) {
                    270:                if (str->p2 == 0) {
                    271:                        sfree (str);
                    272:                        str = 0;
                    273:                }
                    274:                assign (etc->p1, copy (str));
                    275:        }
                    276:        if (str)
                    277:                sfree (str);
                    278:        sfree (etc);
                    279:        sfree (var);
                    280:        goto fadv;
                    281: }

unix.superglobalmegacorp.com

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