Ignore:
Timestamp:
Oct 6, 2007, 11:19:19 PM (18 years ago)
Author:
bird
Message:

moving globals into shinstance...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/parser.c

    r809 r1198  
    171171                                n2->type = NBACKGND;
    172172                        } else {
    173                                 n3 = (union node *)stalloc(sizeof (struct nredir));
     173                                n3 = (union node *)stalloc(psh, sizeof (struct nredir));
    174174                                n3->type = NBACKGND;
    175175                                n3->nredir.n = n2;
     
    182182                }
    183183                else {
    184                         n3 = (union node *)stalloc(sizeof (struct nbinary));
     184                        n3 = (union node *)stalloc(psh, sizeof (struct nbinary));
    185185                        n3->type = NSEMI;
    186186                        n3->nbinary.ch1 = n1;
     
    239239                }
    240240                n2 = pipeline();
    241                 n3 = (union node *)stalloc(sizeof (struct nbinary));
     241                n3 = (union node *)stalloc(psh, sizeof (struct nbinary));
    242242                n3->type = t;
    243243                n3->nbinary.ch1 = n1;
     
    263263        n1 = command();
    264264        if (readtoken() == TPIPE) {
    265                 pipenode = (union node *)stalloc(sizeof (struct npipe));
     265                pipenode = (union node *)stalloc(psh, sizeof (struct npipe));
    266266                pipenode->type = NPIPE;
    267267                pipenode->npipe.backgnd = 0;
    268                 lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
     268                lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));
    269269                pipenode->npipe.cmdlist = lp;
    270270                lp->n = n1;
    271271                do {
    272272                        prev = lp;
    273                         lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
     273                        lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));
    274274                        lp->n = command();
    275275                        prev->next = lp;
     
    280280        tokpushback++;
    281281        if (negate) {
    282                 n2 = (union node *)stalloc(sizeof (struct nnot));
     282                n2 = (union node *)stalloc(psh, sizeof (struct nnot));
    283283                n2->type = NNOT;
    284284                n2->nnot.com = n1;
     
    320320        switch (readtoken()) {
    321321        case TIF:
    322                 n1 = (union node *)stalloc(sizeof (struct nif));
     322                n1 = (union node *)stalloc(psh, sizeof (struct nif));
    323323                n1->type = NIF;
    324324                n1->nif.test = list(0);
     
    328328                n2 = n1;
    329329                while (readtoken() == TELIF) {
    330                         n2->nif.elsepart = (union node *)stalloc(sizeof (struct nif));
     330                        n2->nif.elsepart = (union node *)stalloc(psh, sizeof (struct nif));
    331331                        n2 = n2->nif.elsepart;
    332332                        n2->type = NIF;
     
    349349        case TUNTIL: {
    350350                int got;
    351                 n1 = (union node *)stalloc(sizeof (struct nbinary));
     351                n1 = (union node *)stalloc(psh, sizeof (struct nbinary));
    352352                n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL;
    353353                n1->nbinary.ch1 = list(0);
     
    365365                if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
    366366                        synerror("Bad for loop variable");
    367                 n1 = (union node *)stalloc(sizeof (struct nfor));
     367                n1 = (union node *)stalloc(psh, sizeof (struct nfor));
    368368                n1->type = NFOR;
    369369                n1->nfor.var = wordtext;
     
    371371                        app = ≈
    372372                        while (readtoken() == TWORD) {
    373                                 n2 = (union node *)stalloc(sizeof (struct narg));
     373                                n2 = (union node *)stalloc(psh, sizeof (struct narg));
    374374                                n2->type = NARG;
    375375                                n2->narg.text = wordtext;
     
    385385                        static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE,
    386386                                                                   '@', '=', '\0'};
    387                         n2 = (union node *)stalloc(sizeof (struct narg));
     387                        n2 = (union node *)stalloc(psh, sizeof (struct narg));
    388388                        n2->type = NARG;
    389389                        n2->narg.text = argvars;
     
    411411                break;
    412412        case TCASE:
    413                 n1 = (union node *)stalloc(sizeof (struct ncase));
     413                n1 = (union node *)stalloc(psh, sizeof (struct ncase));
    414414                n1->type = NCASE;
    415415                if (readtoken() != TWORD)
    416416                        synexpect(TWORD);
    417                 n1->ncase.expr = n2 = (union node *)stalloc(sizeof (struct narg));
     417                n1->ncase.expr = n2 = (union node *)stalloc(psh, sizeof (struct narg));
    418418                n2->type = NARG;
    419419                n2->narg.text = wordtext;
     
    427427                checkkwd = 2, readtoken();
    428428                do {
    429                         *cpp = cp = (union node *)stalloc(sizeof (struct nclist));
     429                        *cpp = cp = (union node *)stalloc(psh, sizeof (struct nclist));
    430430                        cp->type = NCLIST;
    431431                        app = &cp->nclist.pattern;
    432432                        for (;;) {
    433                                 *app = ap = (union node *)stalloc(sizeof (struct narg));
     433                                *app = ap = (union node *)stalloc(psh, sizeof (struct narg));
    434434                                ap->type = NARG;
    435435                                ap->narg.text = wordtext;
     
    465465                break;
    466466        case TLP:
    467                 n1 = (union node *)stalloc(sizeof (struct nredir));
     467                n1 = (union node *)stalloc(psh, sizeof (struct nredir));
    468468                n1->type = NSUBSHELL;
    469469                n1->nredir.n = list(0);
     
    511511        if (redir) {
    512512                if (n1->type != NSUBSHELL) {
    513                         n2 = (union node *)stalloc(sizeof (struct nredir));
     513                        n2 = (union node *)stalloc(psh, sizeof (struct nredir));
    514514                        n2->type = NREDIR;
    515515                        n2->nredir.n = n1;
     
    521521checkneg:
    522522        if (negate) {
    523                 n2 = (union node *)stalloc(sizeof (struct nnot));
     523                n2 = (union node *)stalloc(psh, sizeof (struct nnot));
    524524                n2->type = NNOT;
    525525                n2->nnot.com = n1;
     
    561561        for (;;) {
    562562                if (readtoken() == TWORD) {
    563                         n = (union node *)stalloc(sizeof (struct narg));
     563                        n = (union node *)stalloc(psh, sizeof (struct narg));
    564564                        n->type = NARG;
    565565                        n->narg.text = wordtext;
     
    590590        *app = NULL;
    591591        *rpp = NULL;
    592         n = (union node *)stalloc(sizeof (struct ncmd));
     592        n = (union node *)stalloc(psh, sizeof (struct ncmd));
    593593        n->type = NCMD;
    594594        n->ncmd.backgnd = 0;
     
    598598checkneg:
    599599        if (negate) {
    600                 n2 = (union node *)stalloc(sizeof (struct nnot));
     600                n2 = (union node *)stalloc(psh, sizeof (struct nnot));
    601601                n2->type = NNOT;
    602602                n2->nnot.com = n;
     
    612612        union node *n;
    613613
    614         n = (union node *)stalloc(sizeof (struct narg));
     614        n = (union node *)stalloc(psh, sizeof (struct narg));
    615615        n->type = NARG;
    616616        n->narg.next = NULL;
     
    697697                readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
    698698                                here->eofmark, here->striptabs);
    699                 n = (union node *)stalloc(sizeof (struct narg));
     699                n = (union node *)stalloc(psh, sizeof (struct narg));
    700700                n->narg.type = NARG;
    701701                n->narg.next = NULL;
     
    953953        parenlevel = 0;
    954954
    955         STARTSTACKSTR(out);
     955        STARTSTACKSTR(psh, out);
    956956        loop: { /* for each line, until end of word */
    957957#if ATTY
     
    967967                CHECKEND();     /* set c to PEOF if at end of here document */
    968968                for (;;) {      /* until end of line or end of word */
    969                         CHECKSTRSPACE(4, out);  /* permit 4 calls to USTPUTC */
     969                        CHECKSTRSPACE(psh, 4, out);     /* permit 4 calls to USTPUTC */
    970970                        switch(syntax[c]) {
    971971                        case CNL:       /* '\n' */
    972972                                if (syntax == BASESYNTAX)
    973973                                        goto endword;   /* exit outer loop */
    974                                 USTPUTC(c, out);
     974                                USTPUTC(psh, c, out);
    975975                                plinno++;
    976976                                if (doprompt)
     
    981981                                goto loop;              /* continue outer loop */
    982982                        case CWORD:
    983                                 USTPUTC(c, out);
     983                                USTPUTC(psh, c, out);
    984984                                break;
    985985                        case CCTL:
    986986                                if (eofmark == NULL || ISDBLQUOTE())
    987                                         USTPUTC(CTLESC, out);
    988                                 USTPUTC(c, out);
     987                                        USTPUTC(psh, CTLESC, out);
     988                                USTPUTC(psh, c, out);
    989989                                break;
    990990                        case CBACK:     /* backslash */
    991991                                c = pgetc();
    992992                                if (c == PEOF) {
    993                                         USTPUTC('\\', out);
     993                                        USTPUTC(psh, '\\', out);
    994994                                        pungetc();
    995995                                        break;
     
    10061006                                    c != '`' && c != '$' &&
    10071007                                    (c != '"' || eofmark != NULL))
    1008                                         USTPUTC('\\', out);
     1008                                        USTPUTC(psh, '\\', out);
    10091009                                if (SQSYNTAX[c] == CCTL)
    1010                                         USTPUTC(CTLESC, out);
     1010                                        USTPUTC(psh, CTLESC, out);
    10111011                                else if (eofmark == NULL) {
    1012                                         USTPUTC(CTLQUOTEMARK, out);
    1013                                         USTPUTC(c, out);
     1012                                        USTPUTC(psh, CTLQUOTEMARK, out);
     1013                                        USTPUTC(psh, c, out);
    10141014                                        if (varnest != 0)
    1015                                                 USTPUTC(CTLQUOTEEND, out);
     1015                                                USTPUTC(psh, CTLQUOTEEND, out);
    10161016                                        break;
    10171017                                }
    1018                                 USTPUTC(c, out);
     1018                                USTPUTC(psh, c, out);
    10191019                                break;
    10201020                        case CSQUOTE:
    10211021                                if (syntax != SQSYNTAX) {
    10221022                                        if (eofmark == NULL)
    1023                                                 USTPUTC(CTLQUOTEMARK, out);
     1023                                                USTPUTC(psh, CTLQUOTEMARK, out);
    10241024                                        quotef = 1;
    10251025                                        syntax = SQSYNTAX;
     
    10291029                                    varnest == 0) {
    10301030                                        /* Ignore inside quoted here document */
    1031                                         USTPUTC(c, out);
     1031                                        USTPUTC(psh, c, out);
    10321032                                        break;
    10331033                                }
     
    10381038                                        syntax = BASESYNTAX;
    10391039                                        if (varnest != 0)
    1040                                                 USTPUTC(CTLQUOTEEND, out);
     1040                                                USTPUTC(psh, CTLQUOTEEND, out);
    10411041                                }
    10421042                                break;
     
    10451045                                    varnest == 0) {
    10461046                                        /* Ignore inside here document */
    1047                                         USTPUTC(c, out);
     1047                                        USTPUTC(psh, c, out);
    10481048                                        break;
    10491049                                }
     
    10561056                                                syntax = DQSYNTAX;
    10571057                                                SETDBLQUOTE();
    1058                                                 USTPUTC(CTLQUOTEMARK, out);
     1058                                                USTPUTC(psh, CTLQUOTEMARK, out);
    10591059                                        }
    10601060                                        break;
     
    10641064                                if (ISDBLQUOTE()) {
    10651065                                        if (varnest != 0)
    1066                                                 USTPUTC(CTLQUOTEEND, out);
     1066                                                USTPUTC(psh, CTLQUOTEEND, out);
    10671067                                        syntax = BASESYNTAX;
    10681068                                        CLRDBLQUOTE();
     
    10701070                                        syntax = DQSYNTAX;
    10711071                                        SETDBLQUOTE();
    1072                                         USTPUTC(CTLQUOTEMARK, out);
     1072                                        USTPUTC(psh, CTLQUOTEMARK, out);
    10731073                                }
    10741074                                break;
     
    10791079                                if (varnest > 0 && !ISDBLQUOTE()) {
    10801080                                        varnest--;
    1081                                         USTPUTC(CTLENDVAR, out);
     1081                                        USTPUTC(psh, CTLENDVAR, out);
    10821082                                } else {
    1083                                         USTPUTC(c, out);
     1083                                        USTPUTC(psh, c, out);
    10841084                                }
    10851085                                break;
    10861086                        case CLP:       /* '(' in arithmetic */
    10871087                                parenlevel++;
    1088                                 USTPUTC(c, out);
     1088                                USTPUTC(psh, c, out);
    10891089                                break;
    10901090                        case CRP:       /* ')' in arithmetic */
    10911091                                if (parenlevel > 0) {
    1092                                         USTPUTC(c, out);
     1092                                        USTPUTC(psh, c, out);
    10931093                                        --parenlevel;
    10941094                                } else {
    10951095                                        if (pgetc() == ')') {
    10961096                                                if (--arinest == 0) {
    1097                                                         USTPUTC(CTLENDARI, out);
     1097                                                        USTPUTC(psh, CTLENDARI, out);
    10981098                                                        syntax = prevsyntax;
    10991099                                                        if (syntax == DQSYNTAX)
     
    11021102                                                                CLRDBLQUOTE();
    11031103                                                } else
    1104                                                         USTPUTC(')', out);
     1104                                                        USTPUTC(psh, ')', out);
    11051105                                        } else {
    11061106                                                /*
     
    11091109                                                 */
    11101110                                                pungetc();
    1111                                                 USTPUTC(')', out);
     1111                                                USTPUTC(psh, ')', out);
    11121112                                        }
    11131113                                }
     
    11211121                                if (varnest == 0)
    11221122                                        goto endword;   /* exit outer loop */
    1123                                 USTPUTC(c, out);
     1123                                USTPUTC(psh, c, out);
    11241124                        }
    11251125                        c = pgetc_macro();
     
    11361136                synerror("Missing '}'");
    11371137        }
    1138         USTPUTC('\0', out);
    1139         len = out - stackblock();
    1140         out = stackblock();
     1138        USTPUTC(psh, '\0', out);
     1139        len = out - stackblock(psh);
     1140        out = stackblock(psh);
    11411141        if (eofmark == NULL) {
    11421142                if ((c == '>' || c == '<')
     
    11521152        quoteflag = quotef;
    11531153        backquotelist = bqlist;
    1154         grabstackblock(len);
     1154        grabstackblock(psh, len);
    11551155        wordtext = out;
    11561156        if (dblquotep != NULL)
     
    12031203        union node *np;
    12041204
    1205         np = (union node *)stalloc(sizeof (struct nfile));
     1205        np = (union node *)stalloc(psh, sizeof (struct nfile));
    12061206        if (c == '>') {
    12071207                np->nfile.fd = 1;
     
    12221222                case '<':
    12231223                        if (sizeof (struct nfile) != sizeof (struct nhere)) {
    1224                                 np = (union node *)stalloc(sizeof (struct nhere));
     1224                                np = (union node *)stalloc(psh, sizeof (struct nhere));
    12251225                                np->nfile.fd = 0;
    12261226                        }
    12271227                        np->type = NHERE;
    1228                         heredoc = (struct heredoc *)stalloc(sizeof (struct heredoc));
     1228                        heredoc = (struct heredoc *)stalloc(psh, sizeof (struct heredoc));
    12291229                        heredoc->here = np;
    12301230                        if ((c = pgetc()) == '-') {
     
    12711271        c = pgetc();
    12721272        if (c != '(' && c != OPENBRACE && !is_name(c) && !is_special(c)) {
    1273                 USTPUTC('$', out);
     1273                USTPUTC(psh, '$', out);
    12741274                pungetc();
    12751275        } else if (c == '(') {  /* $(command) or $((arith)) */
     
    12811281                }
    12821282        } else {
    1283                 USTPUTC(CTLVAR, out);
    1284                 typeloc = out - stackblock();
    1285                 USTPUTC(VSNORMAL, out);
     1283                USTPUTC(psh, CTLVAR, out);
     1284                typeloc = out - stackblock(psh);
     1285                USTPUTC(psh, VSNORMAL, out);
    12861286                subtype = VSNORMAL;
    12871287                if (c == OPENBRACE) {
     
    12981298                if (is_name(c)) {
    12991299                        do {
    1300                                 STPUTC(c, out);
     1300                                STPUTC(psh, c, out);
    13011301                                c = pgetc();
    13021302                        } while (is_in_name(c));
    13031303                } else if (is_digit(c)) {
    13041304                        do {
    1305                                 USTPUTC(c, out);
     1305                                USTPUTC(psh, c, out);
    13061306                                c = pgetc();
    13071307                        } while (is_digit(c));
    13081308                }
    13091309                else if (is_special(c)) {
    1310                         USTPUTC(c, out);
     1310                        USTPUTC(psh, c, out);
    13111311                        c = pgetc();
    13121312                }
     
    13141314badsub:                 synerror("Bad substitution");
    13151315
    1316                 STPUTC('=', out);
     1316                STPUTC(psh, '=', out);
    13171317                flags = 0;
    13181318                if (subtype == 0) {
     
    13471347                if (ISDBLQUOTE() || arinest)
    13481348                        flags |= VSQUOTE;
    1349                 *(stackblock() + typeloc) = subtype | flags;
     1349                *(stackblock(psh) + typeloc) = subtype | flags;
    13501350                if (subtype != VSNORMAL) {
    13511351                        varnest++;
     
    13911391        INTOFF;
    13921392        str = NULL;
    1393         savelen = out - stackblock();
     1393        savelen = out - stackblock(psh);
    13941394        if (savelen > 0) {
    13951395                str = ckmalloc(savelen);
    1396                 memcpy(str, stackblock(), savelen);
     1396                memcpy(str, stackblock(psh), savelen);
    13971397        }
    13981398        savehandler = handler;
     
    14091409
    14101410
    1411                 STARTSTACKSTR(pout);
     1411                STARTSTACKSTR(psh, pout);
    14121412                for (;;) {
    14131413                        if (needprompt) {
     
    14361436                                if (pc != '\\' && pc != '`' && pc != '$'
    14371437                                    && (!ISDBLQUOTE() || pc != '"'))
    1438                                         STPUTC('\\', pout);
     1438                                        STPUTC(psh, '\\', pout);
    14391439                                break;
    14401440
     
    14521452                                break;
    14531453                        }
    1454                         STPUTC(pc, pout);
     1454                        STPUTC(psh, pc, pout);
    14551455                }
    14561456done:
    1457                 STPUTC('\0', pout);
    1458                 psavelen = pout - stackblock();
     1457                STPUTC(psh, '\0', pout);
     1458                psavelen = pout - stackblock(psh);
    14591459                if (psavelen > 0) {
    1460                         pstr = grabstackstr(pout);
     1460                        pstr = grabstackstr(psh, pout);
    14611461                        setinputstring(pstr, 1);
    14621462                }
     
    14651465        while (*nlpp)
    14661466                nlpp = &(*nlpp)->next;
    1467         *nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
     1467        *nlpp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));
    14681468        (*nlpp)->next = NULL;
    14691469        parsebackquote = oldstyle;
     
    14921492                tokpushback = 0;
    14931493        }
    1494         while (stackblocksize() <= savelen)
    1495                 growstackblock();
    1496         STARTSTACKSTR(out);
     1494        while (stackblocksize(psh) <= savelen)
     1495                growstackblock(psh);
     1496        STARTSTACKSTR(psh, out);
    14971497        if (str) {
    14981498                memcpy(out, str, savelen);
    1499                 STADJUST(savelen, out);
     1499                STADJUST(psh, savelen, out);
    15001500                INTOFF;
    15011501                ckfree(str);
     
    15061506        handler = savehandler;
    15071507        if (arinest || ISDBLQUOTE())
    1508                 USTPUTC(CTLBACKQ | CTLQUOTE, out);
     1508                USTPUTC(psh, CTLBACKQ | CTLQUOTE, out);
    15091509        else
    1510                 USTPUTC(CTLBACKQ, out);
     1510                USTPUTC(psh, CTLBACKQ, out);
    15111511        if (oldstyle)
    15121512                goto parsebackq_oldreturn;
     
    15231523                prevsyntax = syntax;
    15241524                syntax = ARISYNTAX;
    1525                 USTPUTC(CTLARI, out);
     1525                USTPUTC(psh, CTLARI, out);
    15261526                if (ISDBLQUOTE())
    1527                         USTPUTC('"',out);
     1527                        USTPUTC(psh, '"',out);
    15281528                else
    1529                         USTPUTC(' ',out);
     1529                        USTPUTC(psh, ' ',out);
    15301530        } else {
    15311531                /*
     
    15331533                 * parenthesis, which should be equivalent
    15341534                 */
    1535                 USTPUTC('(', out);
     1535                USTPUTC(psh, '(', out);
    15361536        }
    15371537        goto parsearith_return;
Note: See TracChangeset for help on using the changeset viewer.