Changeset 3456 for trunk/src/kash/parser.c
- Timestamp:
- Sep 14, 2020, 2:03:45 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/parser.c
r3449 r3456 41 41 #endif 42 42 43 #define SH_MEMALLOC_NO_STACK 43 44 #include <stdlib.h> 45 #include <assert.h> 44 46 45 47 #include "shell.h" … … 129 131 parsecmd(shinstance *psh, int interact) 130 132 { 133 union node *ret; 131 134 int t; 135 TRACE2((psh, "parsecmd(%d)\n", interact)); 132 136 133 137 psh->tokpushback = 0; … … 144 148 return NULL; 145 149 psh->tokpushback++; 146 return list(psh, 1); 150 ret = list(psh, 1); 151 #if 0 /*def DEBUG*/ 152 TRACE2((psh, "parsecmd(%d) returns:\n", interact)); 153 showtree(psh, ret); 154 #endif 155 return ret; 147 156 } 148 157 … … 167 176 n2->type = NBACKGND; 168 177 } else { 169 n3 = (union node *)stalloc(psh, sizeof (struct nredir));178 n3 = pstallocnode(psh, sizeof (struct nredir)); 170 179 n3->type = NBACKGND; 171 180 n3->nredir.n = n2; … … 178 187 } 179 188 else { 180 n3 = (union node *)stalloc(psh, sizeof (struct nbinary));189 n3 = pstallocnode(psh, sizeof (struct nbinary)); 181 190 n3->type = NSEMI; 182 191 n3->nbinary.ch1 = n1; … … 235 244 } 236 245 n2 = pipeline(psh); 237 n3 = (union node *)stalloc(psh, sizeof (struct nbinary));246 n3 = pstallocnode(psh, sizeof (struct nbinary)); 238 247 n3->type = t; 239 248 n3->nbinary.ch1 = n1; … … 259 268 n1 = command(psh); 260 269 if (readtoken(psh) == TPIPE) { 261 pipenode = (union node *)stalloc(psh, sizeof (struct npipe));270 pipenode = pstallocnode(psh, sizeof (struct npipe)); 262 271 pipenode->type = NPIPE; 263 272 pipenode->npipe.backgnd = 0; 264 lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));273 lp = pstalloclist(psh); 265 274 pipenode->npipe.cmdlist = lp; 266 275 lp->n = n1; 267 276 do { 268 277 prev = lp; 269 lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));278 lp = pstalloclist(psh); 270 279 lp->n = command(psh); 271 280 prev->next = lp; … … 276 285 psh->tokpushback++; 277 286 if (negate) { 278 n2 = (union node *)stalloc(psh, sizeof (struct nnot));287 n2 = pstallocnode(psh, sizeof (struct nnot)); 279 288 n2->type = NNOT; 280 289 n2->nnot.com = n1; … … 316 325 switch (readtoken(psh)) { 317 326 case TIF: 318 n1 = (union node *)stalloc(psh, sizeof (struct nif));327 n1 = pstallocnode(psh, sizeof (struct nif)); 319 328 n1->type = NIF; 320 329 n1->nif.test = list(psh, 0); … … 324 333 n2 = n1; 325 334 while (readtoken(psh) == TELIF) { 326 n2->nif.elsepart = (union node *)stalloc(psh, sizeof (struct nif));335 n2->nif.elsepart = pstallocnode(psh, sizeof (struct nif)); 327 336 n2 = n2->nif.elsepart; 328 337 n2->type = NIF; … … 345 354 case TUNTIL: { 346 355 int got; 347 n1 = (union node *)stalloc(psh, sizeof (struct nbinary));356 n1 = pstallocnode(psh, sizeof (struct nbinary)); 348 357 n1->type = (psh->lasttoken == TWHILE)? NWHILE : NUNTIL; 349 358 n1->nbinary.ch1 = list(psh, 0); … … 361 370 if (readtoken(psh) != TWORD || psh->quoteflag || ! goodname(psh->wordtext)) 362 371 synerror(psh, "Bad for loop variable"); 363 n1 = (union node *)stalloc(psh, sizeof (struct nfor));372 n1 = pstallocnode(psh, sizeof (struct nfor)); 364 373 n1->type = NFOR; 365 374 n1->nfor.var = psh->wordtext; … … 367 376 app = ≈ 368 377 while (readtoken(psh) == TWORD) { 369 n2 = (union node *)stalloc(psh, sizeof (struct narg));378 n2 = pstallocnode(psh, sizeof (struct narg)); 370 379 n2->type = NARG; 371 380 n2->narg.text = psh->wordtext; … … 381 390 static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, 382 391 '@', '=', '\0'}; 383 n2 = (union node *)stalloc(psh, sizeof (struct narg));392 n2 = pstallocnode(psh, sizeof (struct narg)); 384 393 n2->type = NARG; 385 394 n2->narg.text = argvars; … … 407 416 break; 408 417 case TCASE: 409 n1 = (union node *)stalloc(psh, sizeof (struct ncase));418 n1 = pstallocnode(psh, sizeof (struct ncase)); 410 419 n1->type = NCASE; 411 420 if (readtoken(psh) != TWORD) 412 421 synexpect(psh, TWORD); 413 n1->ncase.expr = n2 = (union node *)stalloc(psh, sizeof (struct narg));422 n1->ncase.expr = n2 = pstallocnode(psh, sizeof (struct narg)); 414 423 n2->type = NARG; 415 424 n2->narg.text = psh->wordtext; … … 423 432 psh->checkkwd = 2, readtoken(psh); 424 433 do { 425 *cpp = cp = (union node *)stalloc(psh, sizeof (struct nclist));434 *cpp = cp = pstallocnode(psh, sizeof (struct nclist)); 426 435 cp->type = NCLIST; 427 436 app = &cp->nclist.pattern; 428 437 for (;;) { 429 *app = ap = (union node *)stalloc(psh, sizeof (struct narg));438 *app = ap = pstallocnode(psh, sizeof (struct narg)); 430 439 ap->type = NARG; 431 440 ap->narg.text = psh->wordtext; … … 461 470 break; 462 471 case TLP: 463 n1 = (union node *)stalloc(psh, sizeof (struct nredir));472 n1 = pstallocnode(psh, sizeof (struct nredir)); 464 473 n1->type = NSUBSHELL; 465 474 n1->nredir.n = list(psh, 0); … … 507 516 if (redir) { 508 517 if (n1->type != NSUBSHELL) { 509 n2 = (union node *)stalloc(psh, sizeof (struct nredir));518 n2 = pstallocnode(psh, sizeof (struct nredir)); 510 519 n2->type = NREDIR; 511 520 n2->nredir.n = n1; … … 517 526 checkneg: 518 527 if (negate) { 519 n2 = (union node *)stalloc(psh, sizeof (struct nnot));528 n2 = pstallocnode(psh, sizeof (struct nnot)); 520 529 n2->type = NNOT; 521 530 n2->nnot.com = n1; … … 557 566 for (;;) { 558 567 if (readtoken(psh) == TWORD) { 559 n = (union node *)stalloc(psh, sizeof (struct narg));568 n = pstallocnode(psh, sizeof (struct narg)); 560 569 n->type = NARG; 561 570 n->narg.text = psh->wordtext; … … 586 595 *app = NULL; 587 596 *rpp = NULL; 588 n = (union node *)stalloc(psh, sizeof (struct ncmd));597 n = pstallocnode(psh, sizeof (struct ncmd)); 589 598 n->type = NCMD; 590 599 n->ncmd.backgnd = 0; … … 594 603 checkneg: 595 604 if (negate) { 596 n2 = (union node *)stalloc(psh, sizeof (struct nnot));605 n2 = pstallocnode(psh, sizeof (struct nnot)); 597 606 n2->type = NNOT; 598 607 n2->nnot.com = n; … … 608 617 union node *n; 609 618 610 n = (union node *)stalloc(psh, sizeof (struct narg));619 n = pstallocnode(psh, sizeof (struct narg)); 611 620 n->type = NARG; 612 621 n->narg.next = NULL; … … 693 702 readtoken1(psh, pgetc(psh), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, 694 703 here->eofmark, here->striptabs); 695 n = (union node *)stalloc(psh, sizeof (struct narg));704 n = pstallocnode(psh, sizeof (struct narg)); 696 705 n->narg.type = NARG; 697 706 n->narg.next = NULL; … … 911 920 int c = firstc; 912 921 char *out; 913 int len;914 922 char line[EOFMARKLEN + 1]; 915 923 struct nodelist *bqlist; … … 950 958 #endif 951 959 952 STARTSTACKSTR(psh, out);960 PSTARTSTACKSTR(psh, out); 953 961 loop: { /* for each line, until end of word */ 954 962 #if ATTY … … 964 972 CHECKEND(); /* set c to PEOF if at end of here document */ 965 973 for (;;) { /* until end of line or end of word */ 966 CHECKSTRSPACE(psh, 4, out); /* permit 4 calls to USTPUTC*/974 PSTCHECKSTRSPACE(psh, 4+1, out); /* permit 4 calls to PSTUPUTC, pluss terminator */ 967 975 switch(syntax[c]) { 968 976 case CNL: /* '\n' */ 969 977 if (syntax == BASESYNTAX) 970 978 goto endword; /* exit outer loop */ 971 USTPUTC(psh, c, out);979 PSTUPUTC(psh, c, out); 972 980 psh->plinno++; 973 981 if (psh->doprompt) … … 978 986 goto loop; /* continue outer loop */ 979 987 case CWORD: 980 USTPUTC(psh, c, out);988 PSTUPUTC(psh, c, out); 981 989 break; 982 990 case CCTL: 983 991 if (eofmark == NULL || ISDBLQUOTE()) 984 USTPUTC(psh, CTLESC, out);985 USTPUTC(psh, c, out);992 PSTUPUTC(psh, CTLESC, out); 993 PSTUPUTC(psh, c, out); 986 994 break; 987 995 case CBACK: /* backslash */ 988 996 c = pgetc(psh); 989 997 if (c == PEOF) { 990 USTPUTC(psh, '\\', out);998 PSTUPUTC(psh, '\\', out); 991 999 pungetc(psh); 992 1000 break; … … 1003 1011 c != '`' && c != '$' && 1004 1012 (c != '"' || eofmark != NULL)) 1005 USTPUTC(psh, '\\', out);1013 PSTUPUTC(psh, '\\', out); 1006 1014 if (SQSYNTAX[c] == CCTL) 1007 USTPUTC(psh, CTLESC, out);1015 PSTUPUTC(psh, CTLESC, out); 1008 1016 else if (eofmark == NULL) { 1009 USTPUTC(psh, CTLQUOTEMARK, out);1010 USTPUTC(psh, c, out);1017 PSTUPUTC(psh, CTLQUOTEMARK, out); 1018 PSTUPUTC(psh, c, out); 1011 1019 if (varnest != 0) 1012 USTPUTC(psh, CTLQUOTEEND, out);1020 PSTUPUTC(psh, CTLQUOTEEND, out); 1013 1021 break; 1014 1022 } 1015 USTPUTC(psh, c, out);1023 PSTUPUTC(psh, c, out); 1016 1024 break; 1017 1025 case CSQUOTE: 1018 1026 if (syntax != SQSYNTAX) { 1019 1027 if (eofmark == NULL) 1020 USTPUTC(psh, CTLQUOTEMARK, out);1028 PSTUPUTC(psh, CTLQUOTEMARK, out); 1021 1029 quotef = 1; 1022 1030 syntax = SQSYNTAX; … … 1026 1034 varnest == 0) { 1027 1035 /* Ignore inside quoted here document */ 1028 USTPUTC(psh, c, out);1036 PSTUPUTC(psh, c, out); 1029 1037 break; 1030 1038 } … … 1035 1043 syntax = BASESYNTAX; 1036 1044 if (varnest != 0) 1037 USTPUTC(psh, CTLQUOTEEND, out);1045 PSTUPUTC(psh, CTLQUOTEEND, out); 1038 1046 } 1039 1047 break; … … 1042 1050 varnest == 0) { 1043 1051 /* Ignore inside here document */ 1044 USTPUTC(psh, c, out);1052 PSTUPUTC(psh, c, out); 1045 1053 break; 1046 1054 } … … 1053 1061 syntax = DQSYNTAX; 1054 1062 SETDBLQUOTE(); 1055 USTPUTC(psh, CTLQUOTEMARK, out);1063 PSTUPUTC(psh, CTLQUOTEMARK, out); 1056 1064 } 1057 1065 break; … … 1061 1069 if (ISDBLQUOTE()) { 1062 1070 if (varnest != 0) 1063 USTPUTC(psh, CTLQUOTEEND, out);1071 PSTUPUTC(psh, CTLQUOTEEND, out); 1064 1072 syntax = BASESYNTAX; 1065 1073 CLRDBLQUOTE(); … … 1067 1075 syntax = DQSYNTAX; 1068 1076 SETDBLQUOTE(); 1069 USTPUTC(psh, CTLQUOTEMARK, out);1077 PSTUPUTC(psh, CTLQUOTEMARK, out); 1070 1078 } 1071 1079 break; … … 1076 1084 if (varnest > 0 && !ISDBLQUOTE()) { 1077 1085 varnest--; 1078 USTPUTC(psh, CTLENDVAR, out);1086 PSTUPUTC(psh, CTLENDVAR, out); 1079 1087 } else { 1080 USTPUTC(psh, c, out);1088 PSTUPUTC(psh, c, out); 1081 1089 } 1082 1090 break; 1083 1091 case CLP: /* '(' in arithmetic */ 1084 1092 parenlevel++; 1085 USTPUTC(psh, c, out);1093 PSTUPUTC(psh, c, out); 1086 1094 break; 1087 1095 case CRP: /* ')' in arithmetic */ 1088 1096 if (parenlevel > 0) { 1089 USTPUTC(psh, c, out);1097 PSTUPUTC(psh, c, out); 1090 1098 --parenlevel; 1091 1099 } else { 1092 1100 if (pgetc(psh) == ')') { 1093 1101 if (--arinest == 0) { 1094 USTPUTC(psh, CTLENDARI, out);1102 PSTUPUTC(psh, CTLENDARI, out); 1095 1103 syntax = prevsyntax; 1096 1104 if (syntax == DQSYNTAX) … … 1099 1107 CLRDBLQUOTE(); 1100 1108 } else 1101 USTPUTC(psh, ')', out);1109 PSTUPUTC(psh, ')', out); 1102 1110 } else { 1103 1111 /* … … 1106 1114 */ 1107 1115 pungetc(psh); 1108 USTPUTC(psh, ')', out);1116 PSTUPUTC(psh, ')', out); 1109 1117 } 1110 1118 } … … 1118 1126 if (varnest == 0) 1119 1127 goto endword; /* exit outer loop */ 1120 USTPUTC(psh, c, out);1128 PSTUPUTC(psh, c, out); 1121 1129 } 1122 1130 c = pgetc_macro(psh); … … 1133 1141 synerror(psh, "Missing '}'"); 1134 1142 } 1135 USTPUTC(psh, '\0', out); 1136 len = (int)(out - stackblock(psh)); 1137 out = stackblock(psh); 1143 PSTUPUTC(psh, '\0', out); 1138 1144 if (eofmark == NULL) { 1145 size_t len = (size_t)(out - PSTBLOCK(psh)); 1146 char *start = PSTBLOCK(psh); 1139 1147 if ((c == '>' || c == '<') 1140 1148 && quotef == 0 1141 1149 && len <= 2 1142 && (*out == '\0' || is_digit(*out))) { 1150 && (*start == '\0' || is_digit(*start))) { 1151 out = start; 1143 1152 PARSEREDIR(); 1144 1153 return psh->lasttoken = TREDIR; … … 1149 1158 psh->quoteflag = quotef; 1150 1159 psh->backquotelist = bqlist; 1151 grabstackblock(psh, len); 1152 psh->wordtext = out; 1160 psh->wordtext = pstgrabstr(psh, out); 1153 1161 if (dblquotep != NULL) 1154 1162 ckfree(psh, dblquotep); … … 1203 1211 (void)dummy; 1204 1212 1205 np = (union node *)stalloc(psh, sizeof (struct ndup));1213 np = pstallocnode(psh, sizeof (struct ndup)); 1206 1214 if (c == '>') { 1207 1215 np->nfile.fd = 1; … … 1222 1230 case '<': 1223 1231 np->type = NHERE; 1224 psh->heredoc = (struct heredoc *) stalloc(psh, sizeof (struct heredoc));1232 psh->heredoc = (struct heredoc *)pstalloc(psh, sizeof (struct heredoc)); 1225 1233 psh->heredoc->here = np; 1226 1234 if ((c = pgetc(psh)) == '-') { … … 1267 1275 c = pgetc(psh); 1268 1276 if (c != '(' && c != OPENBRACE && !is_name(c) && !is_special(c)) { 1269 USTPUTC(psh, '$', out);1277 PSTUPUTC(psh, '$', out); 1270 1278 pungetc(psh); 1271 1279 } else if (c == '(') { /* $(command) or $((arith)) */ … … 1277 1285 } 1278 1286 } else { 1279 USTPUTC(psh, CTLVAR, out);1280 typeloc = (int)(out - stackblock(psh));1281 USTPUTC(psh, VSNORMAL, out);1287 PSTUPUTC(psh, CTLVAR, out); 1288 typeloc = (int)(out - PSTBLOCK(psh)); 1289 PSTUPUTC(psh, VSNORMAL, out); 1282 1290 subtype = VSNORMAL; 1283 1291 if (c == OPENBRACE) { … … 1294 1302 if (is_name(c)) { 1295 1303 do { 1296 STPUTC(psh, c, out);1304 PSTPUTC(psh, c, out); 1297 1305 c = pgetc(psh); 1298 1306 } while (is_in_name(c)); 1299 1307 } else if (is_digit(c)) { 1300 1308 do { 1301 USTPUTC(psh, c, out);1309 PSTUPUTC(psh, c, out); 1302 1310 c = pgetc(psh); 1303 1311 } while (is_digit(c)); 1304 1312 } 1305 1313 else if (is_special(c)) { 1306 USTPUTC(psh, c, out);1314 PSTUPUTC(psh, c, out); 1307 1315 c = pgetc(psh); 1308 1316 } 1309 else 1310 badsub: synerror(psh, "Bad substitution"); 1311 1312 STPUTC(psh, '=', out); 1317 else { 1318 badsub: 1319 synerror(psh, "Bad substitution"); 1320 } 1321 1322 PSTPUTC(psh, '=', out); 1313 1323 flags = 0; 1314 1324 if (subtype == 0) { … … 1343 1353 if (ISDBLQUOTE() || arinest) 1344 1354 flags |= VSQUOTE; 1345 *( stackblock(psh) + typeloc) = subtype | flags;1355 *(PSTBLOCK(psh) + typeloc) = subtype | flags; 1346 1356 if (subtype != VSNORMAL) { 1347 1357 varnest++; … … 1387 1397 INTOFF; 1388 1398 str = NULL; 1389 savelen = (int)(out - stackblock(psh));1399 savelen = (int)(out - PSTBLOCK(psh)); 1390 1400 if (savelen > 0) { 1391 1401 str = ckmalloc(psh, savelen); 1392 memcpy(str, stackblock(psh), savelen);1402 memcpy(str, PSTBLOCK(psh), savelen); 1393 1403 } 1394 1404 savehandler = psh->handler; … … 1405 1415 1406 1416 1407 STARTSTACKSTR(psh, pout);1417 PSTARTSTACKSTR(psh, pout); 1408 1418 for (;;) { 1409 1419 if (psh->needprompt) { … … 1425 1435 * If eating a newline, avoid putting 1426 1436 * the newline into the new character 1427 * stream (via the STPUTC after the1437 * stream (via the PSTPUTC after the 1428 1438 * switch). 1429 1439 */ … … 1431 1441 } 1432 1442 if (pc != '\\' && pc != '`' && pc != '$' && (!ISDBLQUOTE() || pc != '"')) 1433 STPUTC(psh, '\\', pout);1443 PSTPUTC(psh, '\\', pout); 1434 1444 break; 1435 1445 … … 1447 1457 break; 1448 1458 } 1449 STPUTC(psh, pc, pout);1459 PSTPUTC(psh, pc, pout); 1450 1460 } 1451 1461 done: 1452 STPUTC(psh, '\0', pout);1453 psavelen = (int)(pout - stackblock(psh));1454 if (psavelen > 0) { 1455 pstr = grabstackstr(psh, pout);1456 setinputstring(psh, pstr, 1 );1462 PSTPUTC(psh, '\0', pout); 1463 psavelen = (int)(pout - PSTBLOCK(psh)); 1464 if (psavelen > 0) { /** @todo nonsensical test? */ 1465 pstr = pstgrabstr(psh, pout); 1466 setinputstring(psh, pstr, 1 /*push*/); 1457 1467 } 1458 1468 } … … 1460 1470 while (*nlpp) 1461 1471 nlpp = &(*nlpp)->next; 1462 *nlpp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));1472 *nlpp = pstalloclist(psh); 1463 1473 (*nlpp)->next = NULL; 1464 1474 psh->parsebackquote = oldstyle; … … 1487 1497 psh->tokpushback = 0; 1488 1498 } 1489 while (stackblocksize(psh) <= savelen) 1490 growstackblock(psh); 1491 STARTSTACKSTR(psh, out); 1499 PSTARTSTACKSTR(psh, out); 1492 1500 if (str) { 1493 memcpy(out, str, savelen); 1494 STADJUST(psh, savelen, out); 1501 PSTPUTSTRN(psh, str, savelen, out); 1495 1502 INTOFF; 1496 1503 ckfree(psh, str); … … 1501 1508 psh->handler = savehandler; 1502 1509 if (arinest || ISDBLQUOTE()) 1503 USTPUTC(psh, CTLBACKQ | CTLQUOTE, out);1510 PSTUPUTC(psh, CTLBACKQ | CTLQUOTE, out); 1504 1511 else 1505 USTPUTC(psh, CTLBACKQ, out);1512 PSTUPUTC(psh, CTLBACKQ, out); 1506 1513 if (oldstyle) 1507 1514 goto parsebackq_oldreturn; … … 1518 1525 prevsyntax = syntax; 1519 1526 syntax = ARISYNTAX; 1520 USTPUTC(psh, CTLARI, out);1527 PSTUPUTC(psh, CTLARI, out); 1521 1528 if (ISDBLQUOTE()) 1522 USTPUTC(psh, '"',out);1529 PSTUPUTC(psh, '"',out); 1523 1530 else 1524 USTPUTC(psh, ' ',out);1531 PSTUPUTC(psh, ' ',out); 1525 1532 } else { 1526 1533 /* … … 1528 1535 * parenthesis, which should be equivalent 1529 1536 */ 1530 USTPUTC(psh, '(', out);1537 PSTUPUTC(psh, '(', out); 1531 1538 } 1532 1539 goto parsearith_return; … … 1788 1795 struct nodelist **ppnext = &ret; 1789 1796 while (src) { 1790 struct nodelist *dst = stalloc(psh, sizeof(*dst));1797 struct nodelist *dst = pstalloclist(psh); 1791 1798 dst->next = NULL; 1792 1799 *ppnext = dst; … … 1818 1825 case NWHILE: 1819 1826 case NUNTIL: 1820 ret = (union node *)stalloc(psh, sizeof(src->nbinary));1827 ret = pstallocnode(psh, sizeof(src->nbinary)); 1821 1828 ret->nbinary.type = type; 1822 1829 ret->nbinary.ch1 = copyparsetree(psh, src->nbinary.ch1); … … 1825 1832 1826 1833 case NCMD: 1827 ret = (union node *)stalloc(psh, sizeof(src->ncmd));1834 ret = pstallocnode(psh, sizeof(src->ncmd)); 1828 1835 ret->ncmd.type = NCMD; 1829 1836 ret->ncmd.backgnd = src->ncmd.backgnd; … … 1833 1840 1834 1841 case NPIPE: 1835 ret = (union node *)stalloc(psh, sizeof(src->npipe));1842 ret = pstallocnode(psh, sizeof(src->npipe)); 1836 1843 ret->npipe.type = NPIPE; 1837 1844 ret->npipe.backgnd = src->ncmd.backgnd; … … 1842 1849 case NBACKGND: 1843 1850 case NSUBSHELL: 1844 ret = (union node *)stalloc(psh, sizeof(src->nredir));1851 ret = pstallocnode(psh, sizeof(src->nredir)); 1845 1852 ret->nredir.type = type; 1846 1853 ret->nredir.n = copyparsetree(psh, src->nredir.n); … … 1849 1856 1850 1857 case NIF: 1851 ret = (union node *)stalloc(psh, sizeof(src->nif));1858 ret = pstallocnode(psh, sizeof(src->nif)); 1852 1859 ret->nif.type = NIF; 1853 1860 ret->nif.test = copyparsetree(psh, src->nif.test); … … 1857 1864 1858 1865 case NFOR: 1859 ret = (union node *)stalloc(psh, sizeof(src->nfor));1866 ret = pstallocnode(psh, sizeof(src->nfor)); 1860 1867 ret->nfor.type = NFOR; 1861 1868 ret->nfor.args = copyparsetree(psh, src->nfor.args); 1862 1869 ret->nfor.body = copyparsetree(psh, src->nfor.body); 1863 ret->nfor.var = stsavestr(psh, src->nfor.var);1870 ret->nfor.var = pstsavestr(psh, src->nfor.var); 1864 1871 break; 1865 1872 1866 1873 case NCASE: 1867 ret = (union node *)stalloc(psh, sizeof(src->ncase));1874 ret = pstallocnode(psh, sizeof(src->ncase)); 1868 1875 ret->ncase.type = NCASE; 1869 1876 ret->ncase.expr = copyparsetree(psh, src->ncase.expr); … … 1872 1879 1873 1880 case NCLIST: 1874 ret = (union node *)stalloc(psh, sizeof(src->nclist));1881 ret = pstallocnode(psh, sizeof(src->nclist)); 1875 1882 ret->nclist.type = NCLIST; 1876 1883 ret->nclist.next = copyparsetree(psh, src->nclist.next); … … 1881 1888 case NDEFUN: 1882 1889 case NARG: 1883 ret = (union node *)stalloc(psh, sizeof(src->narg));1890 ret = pstallocnode(psh, sizeof(src->narg)); 1884 1891 ret->narg.type = type; 1885 1892 ret->narg.next = copyparsetree(psh, src->narg.next); 1886 ret->narg.text = stsavestr(psh, src->narg.text);1893 ret->narg.text = pstsavestr(psh, src->narg.text); 1887 1894 ret->narg.backquote = copynodelist(psh, src->narg.backquote); 1888 1895 break; … … 1893 1900 case NFROMTO: 1894 1901 case NAPPEND: 1895 ret = (union node *)stalloc(psh, sizeof(src->nfile));1902 ret = pstallocnode(psh, sizeof(src->nfile)); 1896 1903 ret->nfile.type = type; 1897 1904 ret->nfile.fd = src->nfile.fd; … … 1902 1909 case NTOFD: 1903 1910 case NFROMFD: 1904 ret = (union node *)stalloc(psh, sizeof(src->ndup));1911 ret = pstallocnode(psh, sizeof(src->ndup)); 1905 1912 ret->ndup.type = type; 1906 1913 ret->ndup.fd = src->ndup.fd; … … 1912 1919 case NHERE: 1913 1920 case NXHERE: 1914 ret = (union node *)stalloc(psh, sizeof(src->nhere));1921 ret = pstallocnode(psh, sizeof(src->nhere)); 1915 1922 ret->nhere.type = type; 1916 1923 ret->nhere.fd = src->nhere.fd; … … 1920 1927 1921 1928 case NNOT: 1922 ret = (union node *)stalloc(psh, sizeof(src->nnot));1929 ret = pstallocnode(psh, sizeof(src->nnot)); 1923 1930 ret->nnot.type = NNOT; 1924 1931 ret->nnot.com = copyparsetree(psh, src->nnot.com);
Note:
See TracChangeset
for help on using the changeset viewer.