Changeset 1198 for trunk/src/kash/parser.c
- Timestamp:
- Oct 6, 2007, 11:19:19 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/parser.c
r809 r1198 171 171 n2->type = NBACKGND; 172 172 } else { 173 n3 = (union node *)stalloc( sizeof (struct nredir));173 n3 = (union node *)stalloc(psh, sizeof (struct nredir)); 174 174 n3->type = NBACKGND; 175 175 n3->nredir.n = n2; … … 182 182 } 183 183 else { 184 n3 = (union node *)stalloc( sizeof (struct nbinary));184 n3 = (union node *)stalloc(psh, sizeof (struct nbinary)); 185 185 n3->type = NSEMI; 186 186 n3->nbinary.ch1 = n1; … … 239 239 } 240 240 n2 = pipeline(); 241 n3 = (union node *)stalloc( sizeof (struct nbinary));241 n3 = (union node *)stalloc(psh, sizeof (struct nbinary)); 242 242 n3->type = t; 243 243 n3->nbinary.ch1 = n1; … … 263 263 n1 = command(); 264 264 if (readtoken() == TPIPE) { 265 pipenode = (union node *)stalloc( sizeof (struct npipe));265 pipenode = (union node *)stalloc(psh, sizeof (struct npipe)); 266 266 pipenode->type = NPIPE; 267 267 pipenode->npipe.backgnd = 0; 268 lp = (struct nodelist *)stalloc( sizeof (struct nodelist));268 lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist)); 269 269 pipenode->npipe.cmdlist = lp; 270 270 lp->n = n1; 271 271 do { 272 272 prev = lp; 273 lp = (struct nodelist *)stalloc( sizeof (struct nodelist));273 lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist)); 274 274 lp->n = command(); 275 275 prev->next = lp; … … 280 280 tokpushback++; 281 281 if (negate) { 282 n2 = (union node *)stalloc( sizeof (struct nnot));282 n2 = (union node *)stalloc(psh, sizeof (struct nnot)); 283 283 n2->type = NNOT; 284 284 n2->nnot.com = n1; … … 320 320 switch (readtoken()) { 321 321 case TIF: 322 n1 = (union node *)stalloc( sizeof (struct nif));322 n1 = (union node *)stalloc(psh, sizeof (struct nif)); 323 323 n1->type = NIF; 324 324 n1->nif.test = list(0); … … 328 328 n2 = n1; 329 329 while (readtoken() == TELIF) { 330 n2->nif.elsepart = (union node *)stalloc( sizeof (struct nif));330 n2->nif.elsepart = (union node *)stalloc(psh, sizeof (struct nif)); 331 331 n2 = n2->nif.elsepart; 332 332 n2->type = NIF; … … 349 349 case TUNTIL: { 350 350 int got; 351 n1 = (union node *)stalloc( sizeof (struct nbinary));351 n1 = (union node *)stalloc(psh, sizeof (struct nbinary)); 352 352 n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL; 353 353 n1->nbinary.ch1 = list(0); … … 365 365 if (readtoken() != TWORD || quoteflag || ! goodname(wordtext)) 366 366 synerror("Bad for loop variable"); 367 n1 = (union node *)stalloc( sizeof (struct nfor));367 n1 = (union node *)stalloc(psh, sizeof (struct nfor)); 368 368 n1->type = NFOR; 369 369 n1->nfor.var = wordtext; … … 371 371 app = ≈ 372 372 while (readtoken() == TWORD) { 373 n2 = (union node *)stalloc( sizeof (struct narg));373 n2 = (union node *)stalloc(psh, sizeof (struct narg)); 374 374 n2->type = NARG; 375 375 n2->narg.text = wordtext; … … 385 385 static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, 386 386 '@', '=', '\0'}; 387 n2 = (union node *)stalloc( sizeof (struct narg));387 n2 = (union node *)stalloc(psh, sizeof (struct narg)); 388 388 n2->type = NARG; 389 389 n2->narg.text = argvars; … … 411 411 break; 412 412 case TCASE: 413 n1 = (union node *)stalloc( sizeof (struct ncase));413 n1 = (union node *)stalloc(psh, sizeof (struct ncase)); 414 414 n1->type = NCASE; 415 415 if (readtoken() != TWORD) 416 416 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)); 418 418 n2->type = NARG; 419 419 n2->narg.text = wordtext; … … 427 427 checkkwd = 2, readtoken(); 428 428 do { 429 *cpp = cp = (union node *)stalloc( sizeof (struct nclist));429 *cpp = cp = (union node *)stalloc(psh, sizeof (struct nclist)); 430 430 cp->type = NCLIST; 431 431 app = &cp->nclist.pattern; 432 432 for (;;) { 433 *app = ap = (union node *)stalloc( sizeof (struct narg));433 *app = ap = (union node *)stalloc(psh, sizeof (struct narg)); 434 434 ap->type = NARG; 435 435 ap->narg.text = wordtext; … … 465 465 break; 466 466 case TLP: 467 n1 = (union node *)stalloc( sizeof (struct nredir));467 n1 = (union node *)stalloc(psh, sizeof (struct nredir)); 468 468 n1->type = NSUBSHELL; 469 469 n1->nredir.n = list(0); … … 511 511 if (redir) { 512 512 if (n1->type != NSUBSHELL) { 513 n2 = (union node *)stalloc( sizeof (struct nredir));513 n2 = (union node *)stalloc(psh, sizeof (struct nredir)); 514 514 n2->type = NREDIR; 515 515 n2->nredir.n = n1; … … 521 521 checkneg: 522 522 if (negate) { 523 n2 = (union node *)stalloc( sizeof (struct nnot));523 n2 = (union node *)stalloc(psh, sizeof (struct nnot)); 524 524 n2->type = NNOT; 525 525 n2->nnot.com = n1; … … 561 561 for (;;) { 562 562 if (readtoken() == TWORD) { 563 n = (union node *)stalloc( sizeof (struct narg));563 n = (union node *)stalloc(psh, sizeof (struct narg)); 564 564 n->type = NARG; 565 565 n->narg.text = wordtext; … … 590 590 *app = NULL; 591 591 *rpp = NULL; 592 n = (union node *)stalloc( sizeof (struct ncmd));592 n = (union node *)stalloc(psh, sizeof (struct ncmd)); 593 593 n->type = NCMD; 594 594 n->ncmd.backgnd = 0; … … 598 598 checkneg: 599 599 if (negate) { 600 n2 = (union node *)stalloc( sizeof (struct nnot));600 n2 = (union node *)stalloc(psh, sizeof (struct nnot)); 601 601 n2->type = NNOT; 602 602 n2->nnot.com = n; … … 612 612 union node *n; 613 613 614 n = (union node *)stalloc( sizeof (struct narg));614 n = (union node *)stalloc(psh, sizeof (struct narg)); 615 615 n->type = NARG; 616 616 n->narg.next = NULL; … … 697 697 readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, 698 698 here->eofmark, here->striptabs); 699 n = (union node *)stalloc( sizeof (struct narg));699 n = (union node *)stalloc(psh, sizeof (struct narg)); 700 700 n->narg.type = NARG; 701 701 n->narg.next = NULL; … … 953 953 parenlevel = 0; 954 954 955 STARTSTACKSTR( out);955 STARTSTACKSTR(psh, out); 956 956 loop: { /* for each line, until end of word */ 957 957 #if ATTY … … 967 967 CHECKEND(); /* set c to PEOF if at end of here document */ 968 968 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 */ 970 970 switch(syntax[c]) { 971 971 case CNL: /* '\n' */ 972 972 if (syntax == BASESYNTAX) 973 973 goto endword; /* exit outer loop */ 974 USTPUTC( c, out);974 USTPUTC(psh, c, out); 975 975 plinno++; 976 976 if (doprompt) … … 981 981 goto loop; /* continue outer loop */ 982 982 case CWORD: 983 USTPUTC( c, out);983 USTPUTC(psh, c, out); 984 984 break; 985 985 case CCTL: 986 986 if (eofmark == NULL || ISDBLQUOTE()) 987 USTPUTC( CTLESC, out);988 USTPUTC( c, out);987 USTPUTC(psh, CTLESC, out); 988 USTPUTC(psh, c, out); 989 989 break; 990 990 case CBACK: /* backslash */ 991 991 c = pgetc(); 992 992 if (c == PEOF) { 993 USTPUTC( '\\', out);993 USTPUTC(psh, '\\', out); 994 994 pungetc(); 995 995 break; … … 1006 1006 c != '`' && c != '$' && 1007 1007 (c != '"' || eofmark != NULL)) 1008 USTPUTC( '\\', out);1008 USTPUTC(psh, '\\', out); 1009 1009 if (SQSYNTAX[c] == CCTL) 1010 USTPUTC( CTLESC, out);1010 USTPUTC(psh, CTLESC, out); 1011 1011 else if (eofmark == NULL) { 1012 USTPUTC( CTLQUOTEMARK, out);1013 USTPUTC( c, out);1012 USTPUTC(psh, CTLQUOTEMARK, out); 1013 USTPUTC(psh, c, out); 1014 1014 if (varnest != 0) 1015 USTPUTC( CTLQUOTEEND, out);1015 USTPUTC(psh, CTLQUOTEEND, out); 1016 1016 break; 1017 1017 } 1018 USTPUTC( c, out);1018 USTPUTC(psh, c, out); 1019 1019 break; 1020 1020 case CSQUOTE: 1021 1021 if (syntax != SQSYNTAX) { 1022 1022 if (eofmark == NULL) 1023 USTPUTC( CTLQUOTEMARK, out);1023 USTPUTC(psh, CTLQUOTEMARK, out); 1024 1024 quotef = 1; 1025 1025 syntax = SQSYNTAX; … … 1029 1029 varnest == 0) { 1030 1030 /* Ignore inside quoted here document */ 1031 USTPUTC( c, out);1031 USTPUTC(psh, c, out); 1032 1032 break; 1033 1033 } … … 1038 1038 syntax = BASESYNTAX; 1039 1039 if (varnest != 0) 1040 USTPUTC( CTLQUOTEEND, out);1040 USTPUTC(psh, CTLQUOTEEND, out); 1041 1041 } 1042 1042 break; … … 1045 1045 varnest == 0) { 1046 1046 /* Ignore inside here document */ 1047 USTPUTC( c, out);1047 USTPUTC(psh, c, out); 1048 1048 break; 1049 1049 } … … 1056 1056 syntax = DQSYNTAX; 1057 1057 SETDBLQUOTE(); 1058 USTPUTC( CTLQUOTEMARK, out);1058 USTPUTC(psh, CTLQUOTEMARK, out); 1059 1059 } 1060 1060 break; … … 1064 1064 if (ISDBLQUOTE()) { 1065 1065 if (varnest != 0) 1066 USTPUTC( CTLQUOTEEND, out);1066 USTPUTC(psh, CTLQUOTEEND, out); 1067 1067 syntax = BASESYNTAX; 1068 1068 CLRDBLQUOTE(); … … 1070 1070 syntax = DQSYNTAX; 1071 1071 SETDBLQUOTE(); 1072 USTPUTC( CTLQUOTEMARK, out);1072 USTPUTC(psh, CTLQUOTEMARK, out); 1073 1073 } 1074 1074 break; … … 1079 1079 if (varnest > 0 && !ISDBLQUOTE()) { 1080 1080 varnest--; 1081 USTPUTC( CTLENDVAR, out);1081 USTPUTC(psh, CTLENDVAR, out); 1082 1082 } else { 1083 USTPUTC( c, out);1083 USTPUTC(psh, c, out); 1084 1084 } 1085 1085 break; 1086 1086 case CLP: /* '(' in arithmetic */ 1087 1087 parenlevel++; 1088 USTPUTC( c, out);1088 USTPUTC(psh, c, out); 1089 1089 break; 1090 1090 case CRP: /* ')' in arithmetic */ 1091 1091 if (parenlevel > 0) { 1092 USTPUTC( c, out);1092 USTPUTC(psh, c, out); 1093 1093 --parenlevel; 1094 1094 } else { 1095 1095 if (pgetc() == ')') { 1096 1096 if (--arinest == 0) { 1097 USTPUTC( CTLENDARI, out);1097 USTPUTC(psh, CTLENDARI, out); 1098 1098 syntax = prevsyntax; 1099 1099 if (syntax == DQSYNTAX) … … 1102 1102 CLRDBLQUOTE(); 1103 1103 } else 1104 USTPUTC( ')', out);1104 USTPUTC(psh, ')', out); 1105 1105 } else { 1106 1106 /* … … 1109 1109 */ 1110 1110 pungetc(); 1111 USTPUTC( ')', out);1111 USTPUTC(psh, ')', out); 1112 1112 } 1113 1113 } … … 1121 1121 if (varnest == 0) 1122 1122 goto endword; /* exit outer loop */ 1123 USTPUTC( c, out);1123 USTPUTC(psh, c, out); 1124 1124 } 1125 1125 c = pgetc_macro(); … … 1136 1136 synerror("Missing '}'"); 1137 1137 } 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); 1141 1141 if (eofmark == NULL) { 1142 1142 if ((c == '>' || c == '<') … … 1152 1152 quoteflag = quotef; 1153 1153 backquotelist = bqlist; 1154 grabstackblock( len);1154 grabstackblock(psh, len); 1155 1155 wordtext = out; 1156 1156 if (dblquotep != NULL) … … 1203 1203 union node *np; 1204 1204 1205 np = (union node *)stalloc( sizeof (struct nfile));1205 np = (union node *)stalloc(psh, sizeof (struct nfile)); 1206 1206 if (c == '>') { 1207 1207 np->nfile.fd = 1; … … 1222 1222 case '<': 1223 1223 if (sizeof (struct nfile) != sizeof (struct nhere)) { 1224 np = (union node *)stalloc( sizeof (struct nhere));1224 np = (union node *)stalloc(psh, sizeof (struct nhere)); 1225 1225 np->nfile.fd = 0; 1226 1226 } 1227 1227 np->type = NHERE; 1228 heredoc = (struct heredoc *)stalloc( sizeof (struct heredoc));1228 heredoc = (struct heredoc *)stalloc(psh, sizeof (struct heredoc)); 1229 1229 heredoc->here = np; 1230 1230 if ((c = pgetc()) == '-') { … … 1271 1271 c = pgetc(); 1272 1272 if (c != '(' && c != OPENBRACE && !is_name(c) && !is_special(c)) { 1273 USTPUTC( '$', out);1273 USTPUTC(psh, '$', out); 1274 1274 pungetc(); 1275 1275 } else if (c == '(') { /* $(command) or $((arith)) */ … … 1281 1281 } 1282 1282 } 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); 1286 1286 subtype = VSNORMAL; 1287 1287 if (c == OPENBRACE) { … … 1298 1298 if (is_name(c)) { 1299 1299 do { 1300 STPUTC( c, out);1300 STPUTC(psh, c, out); 1301 1301 c = pgetc(); 1302 1302 } while (is_in_name(c)); 1303 1303 } else if (is_digit(c)) { 1304 1304 do { 1305 USTPUTC( c, out);1305 USTPUTC(psh, c, out); 1306 1306 c = pgetc(); 1307 1307 } while (is_digit(c)); 1308 1308 } 1309 1309 else if (is_special(c)) { 1310 USTPUTC( c, out);1310 USTPUTC(psh, c, out); 1311 1311 c = pgetc(); 1312 1312 } … … 1314 1314 badsub: synerror("Bad substitution"); 1315 1315 1316 STPUTC( '=', out);1316 STPUTC(psh, '=', out); 1317 1317 flags = 0; 1318 1318 if (subtype == 0) { … … 1347 1347 if (ISDBLQUOTE() || arinest) 1348 1348 flags |= VSQUOTE; 1349 *(stackblock( ) + typeloc) = subtype | flags;1349 *(stackblock(psh) + typeloc) = subtype | flags; 1350 1350 if (subtype != VSNORMAL) { 1351 1351 varnest++; … … 1391 1391 INTOFF; 1392 1392 str = NULL; 1393 savelen = out - stackblock( );1393 savelen = out - stackblock(psh); 1394 1394 if (savelen > 0) { 1395 1395 str = ckmalloc(savelen); 1396 memcpy(str, stackblock( ), savelen);1396 memcpy(str, stackblock(psh), savelen); 1397 1397 } 1398 1398 savehandler = handler; … … 1409 1409 1410 1410 1411 STARTSTACKSTR(p out);1411 STARTSTACKSTR(psh, pout); 1412 1412 for (;;) { 1413 1413 if (needprompt) { … … 1436 1436 if (pc != '\\' && pc != '`' && pc != '$' 1437 1437 && (!ISDBLQUOTE() || pc != '"')) 1438 STPUTC( '\\', pout);1438 STPUTC(psh, '\\', pout); 1439 1439 break; 1440 1440 … … 1452 1452 break; 1453 1453 } 1454 STPUTC(p c, pout);1454 STPUTC(psh, pc, pout); 1455 1455 } 1456 1456 done: 1457 STPUTC( '\0', pout);1458 psavelen = pout - stackblock( );1457 STPUTC(psh, '\0', pout); 1458 psavelen = pout - stackblock(psh); 1459 1459 if (psavelen > 0) { 1460 pstr = grabstackstr(p out);1460 pstr = grabstackstr(psh, pout); 1461 1461 setinputstring(pstr, 1); 1462 1462 } … … 1465 1465 while (*nlpp) 1466 1466 nlpp = &(*nlpp)->next; 1467 *nlpp = (struct nodelist *)stalloc( sizeof (struct nodelist));1467 *nlpp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist)); 1468 1468 (*nlpp)->next = NULL; 1469 1469 parsebackquote = oldstyle; … … 1492 1492 tokpushback = 0; 1493 1493 } 1494 while (stackblocksize( ) <= savelen)1495 growstackblock( );1496 STARTSTACKSTR( out);1494 while (stackblocksize(psh) <= savelen) 1495 growstackblock(psh); 1496 STARTSTACKSTR(psh, out); 1497 1497 if (str) { 1498 1498 memcpy(out, str, savelen); 1499 STADJUST( savelen, out);1499 STADJUST(psh, savelen, out); 1500 1500 INTOFF; 1501 1501 ckfree(str); … … 1506 1506 handler = savehandler; 1507 1507 if (arinest || ISDBLQUOTE()) 1508 USTPUTC( CTLBACKQ | CTLQUOTE, out);1508 USTPUTC(psh, CTLBACKQ | CTLQUOTE, out); 1509 1509 else 1510 USTPUTC( CTLBACKQ, out);1510 USTPUTC(psh, CTLBACKQ, out); 1511 1511 if (oldstyle) 1512 1512 goto parsebackq_oldreturn; … … 1523 1523 prevsyntax = syntax; 1524 1524 syntax = ARISYNTAX; 1525 USTPUTC( CTLARI, out);1525 USTPUTC(psh, CTLARI, out); 1526 1526 if (ISDBLQUOTE()) 1527 USTPUTC( '"',out);1527 USTPUTC(psh, '"',out); 1528 1528 else 1529 USTPUTC( ' ',out);1529 USTPUTC(psh, ' ',out); 1530 1530 } else { 1531 1531 /* … … 1533 1533 * parenthesis, which should be equivalent 1534 1534 */ 1535 USTPUTC( '(', out);1535 USTPUTC(psh, '(', out); 1536 1536 } 1537 1537 goto parsearith_return;
Note:
See TracChangeset
for help on using the changeset viewer.