Lines Matching refs:lp
116 #define pushlevel(lp,c,s) ((lp->lexd.level>=lp->lexd.lex_max?stack_grow(lp):1) &&\ argument
117 ((lp->lexd.lex_match[lp->lexd.level++]=lp->lexd.lastc),\
118 lp->lexd.lastc=(((s)<<CHAR_BIT)|(c))))
119 #define oldmode(lp) (lp->lexd.lastc>>CHAR_BIT) argument
120 #define endchar(lp) (lp->lexd.lastc&0xff) argument
121 #define setchar(lp,c) (lp->lexd.lastc = ((lp->lexd.lastc&~0xff)|(c))) argument
122 #define poplevel(lp) (lp->lexd.lastc=lp->lexd.lex_match[--lp->lexd.level]) argument
139 static void refvar(Lex_t *lp, int type) in refvar() argument
141 register Shell_t *shp = lp->sh; in refvar()
143 off_t off = (fcseek(0)-(type+1))-(lp->lexd.first?lp->lexd.first:fcfirst()); in refvar()
145 if(lp->lexd.first) in refvar()
147 off = (fcseek(0)-(type+1)) - lp->lexd.first; in refvar()
148 …r=kiaentity(lp,lp->lexd.first+lp->lexd.kiaoff+type,off-lp->lexd.kiaoff,'v',-1,-1,lp->current,'v',0… in refvar()
155 if(lp->lexd.kiaoff < offset) in refvar()
160 n = stktell(stkp)-lp->lexd.kiaoff; in refvar()
161 begin = stkptr(stkp,lp->lexd.kiaoff); in refvar()
166 begin = fcfirst()+(type+lp->lexd.kiaoff-offset); in refvar()
167 n = off-lp->lexd.kiaoff; in refvar()
170 r=kiaentity(lp,begin,n,'v',-1,-1,lp->current,'v',0,""); in refvar()
173 sfprintf(lp->kiatmp,"p;%..64d;v;%..64d;%d;%d;r;\n",lp->current,r,shp->inlineno,shp->inlineno); in refvar()
183 register Lex_t *lp = (Lex_t*)context; in lex_advance() local
184 register Shell_t *shp = lp->sh; in lex_advance()
198 if(lp->lexd.nocopy) in lex_advance()
200 if(lp->lexd.dolparen && lp->lexd.docword) in lex_advance()
202 int n = size - (lp->lexd.docend-(char*)buff); in lex_advance()
203 sfwrite(shp->strbuf,lp->lexd.docend,n); in lex_advance()
204 lp->lexd.docextra += n; in lex_advance()
206 if(lp->lexd.first) in lex_advance()
208 size -= (lp->lexd.first-(char*)buff); in lex_advance()
209 buff = lp->lexd.first; in lex_advance()
210 if(!lp->lexd.noarg) in lex_advance()
211 lp->arg = (struct argnod*)stkseek(stkp,ARGVAL); in lex_advance()
213 lp->lexd.kiaoff += ARGVAL; in lex_advance()
216 if(size>0 && (lp->arg||lp->lexd.noarg)) in lex_advance()
219 lp->lexd.first = 0; in lex_advance()
227 static int lexfill(Lex_t *lp) in lexfill() argument
233 savelex = *lp; in lexfill()
234 ap = lp->arg; in lexfill()
237 lp->arg = ap; in lexfill()
238 docextra = lp->lexd.docextra; in lexfill()
239 lp->lex = savelex.lex; in lexfill()
240 lp->lexd = savelex.lexd; in lexfill()
242 lp->lexd.first = 0; in lexfill()
243 aok= lp->aliasok; in lexfill()
244 ap = lp->arg; in lexfill()
245 memcpy(lp, &savelex, offsetof(Lex_t,lexd)); in lexfill()
246 lp->arg = ap; in lexfill()
247 lp->aliasok = aok; in lexfill()
248 if(lp->lexd.docword && docextra) in lexfill()
250 lp->lexd.docextra = docextra; in lexfill()
251 lp->lexd.docend = fcseek(0)-1; in lexfill()
259 Lex_t *sh_lexopen(Lex_t *lp, Shell_t *sp, int mode) in sh_lexopen() argument
261 if(!lp) in sh_lexopen()
263 lp = (Lex_t*)newof(0,Lex_t,1,0); in sh_lexopen()
264 lp->sh = sp; in sh_lexopen()
266 fcnotify(lex_advance,lp); in sh_lexopen()
267 lp->lex.intest = lp->lex.incase = lp->lex.skipword = lp->lexd.warn = 0; in sh_lexopen()
268 lp->comp_assign = 0; in sh_lexopen()
269 lp->lex.reservok = 1; in sh_lexopen()
271 lp->lexd.warn=1; in sh_lexopen()
274 lp->lexd.noarg = lp->lexd.level= lp->lexd.dolparen = lp->lexd.balance = 0; in sh_lexopen()
275 lp->lexd.nocopy = lp->lexd.docword = lp->lexd.nest = lp->lexd.paren = 0; in sh_lexopen()
276 lp->lexd.lex_state = lp->lexd.lastc=0; in sh_lexopen()
278 lp->comsub = 0; in sh_lexopen()
279 return(lp); in sh_lexopen()
284 int sh_lex(Lex_t *lp) in sh_lex() argument
286 Shell_t *shp = lp->sh; in sh_lex()
292 if(tok==0 && (flag=lp->arg->argflag)) in sh_lex()
302 macro, split, expand, fmttoken(lp,tok,tokstr)); in sh_lex()
313 int sh_lex(Lex_t* lp) in sh_lex() argument
315 register Shell_t *shp = lp->sh; in sh_lex()
319 int inlevel=lp->lexd.level, assignment=0, ingrave=0; in sh_lex()
324 if(lp->lexd.paren) in sh_lex()
326 lp->lexd.paren = 0; in sh_lex()
327 return(lp->token=LPAREN); in sh_lex()
329 if(lp->lex.incase) in sh_lex()
330 lp->assignok = 0; in sh_lex()
332 lp->assignok |= lp->lex.reservok; in sh_lex()
333 if(lp->comp_assign==2) in sh_lex()
334 lp->comp_assign = lp->lex.reservok = 0; in sh_lex()
335 lp->lexd.arith = (lp->lexd.nest==1); in sh_lex()
336 if(lp->lexd.nest) in sh_lex()
338 pushlevel(lp,lp->lexd.nest,ST_NONE); in sh_lex()
339 lp->lexd.nest = 0; in sh_lex()
340 mode = lp->lexd.lex_state; in sh_lex()
342 else if(lp->lexd.docword) in sh_lex()
346 lp->lexd.docword++; in sh_lex()
347 lp->digits=(c=='#'?3:1); in sh_lex()
351 lp->digits=2; in sh_lex()
352 lp->lexd.docword=0; in sh_lex()
357 if(!lp->lexd.dolparen) in sh_lex()
359 lp->arg = 0; in sh_lex()
361 lp->lexd.first = fcseek(0); in sh_lex()
363 lp->lexd.first = 0; in sh_lex()
365 lp->lastline = lp->sh->inlineno; in sh_lex()
378 if((n=lexfill(lp)) > 0) in sh_lex()
395 lp->token = -1; in sh_lex()
396 sh_syntax(lp); in sh_lex()
401 return(lp->token=EOFSYM); in sh_lex()
402 if(mode >ST_NORM && lp->lexd.level>0) in sh_lex()
404 switch(c=endchar(lp)) in sh_lex()
412 mode = oldmode(lp); in sh_lex()
413 poplevel(lp); in sh_lex()
426 lp->lexd.balance = c; in sh_lex()
431 lp->lasttok = c; in sh_lex()
432 lp->token = EOFSYM; in sh_lex()
433 sh_syntax(lp); in sh_lex()
435 lp->lexd.balance = c; in sh_lex()
440 lp->lex.reservok = !lp->lex.intest; in sh_lex()
441 if((n=lp->lexd.nocopy) && lp->lexd.dolparen) in sh_lex()
442 lp->lexd.nocopy--; in sh_lex()
446 if(c<=0 || lp->heredoc) in sh_lex()
454 lp->lexd.nocopy = n; in sh_lex()
456 return(lp->token=EOFSYM); in sh_lex()
462 if(lp->heredoc) in sh_lex()
464 if(!lp->lexd.dolparen) in sh_lex()
465 lp->lexd.nocopy++; in sh_lex()
467 if(here_copy(lp,lp->heredoc)<=0 && lp->lasttok) in sh_lex()
469 lp->lasttok = IODOCSYM; in sh_lex()
470 lp->token = EOFSYM; in sh_lex()
471 lp->lastline = c; in sh_lex()
472 sh_syntax(lp); in sh_lex()
474 if(!lp->lexd.dolparen) in sh_lex()
475 lp->lexd.nocopy--; in sh_lex()
476 lp->heredoc = 0; in sh_lex()
478 lp->lex.reservok = !lp->lex.intest; in sh_lex()
479 lp->lex.skipword = 0; in sh_lex()
483 lp->lex.last_quote = 0; in sh_lex()
488 lp->comp_assign = 0; in sh_lex()
489 return(lp->token='\n'); in sh_lex()
492 if(lp->lex.incase<=TEST_RE) in sh_lex()
495 if(inlevel+1==lp->lexd.level) in sh_lex()
497 if(lp->lex.intest) in sh_lex()
507 if(lp->lex.testop2) in sh_lex()
508 lp->lex.testop2 = 0; in sh_lex()
511 lp->digits = (c=='>'); in sh_lex()
512 lp->lex.skipword = 1; in sh_lex()
513 lp->aliasok = lp->lex.reservok; in sh_lex()
514 lp->lex.reservok = 0; in sh_lex()
519 lp->lex.reservok = !lp->lex.intest; in sh_lex()
522 if(!lp->lexd.dolparen) in sh_lex()
523 lp->lex.incase = 0; in sh_lex()
524 return(lp->token=c); in sh_lex()
526 lp->lex.testop1 = lp->lex.intest; in sh_lex()
535 lp->lexd.docword=1; in sh_lex()
538 lp->lexd.nest=1; in sh_lex()
539 lp->lastline = shp->inlineno; in sh_lex()
540 lp->lexd.lex_state = ST_NESTED; in sh_lex()
542 return(sh_lex(lp)); in sh_lex()
547 return(lp->token=c); in sh_lex()
552 if(!sh_isoption(SH_BASH) && !lp->nonstandard) in sh_lex()
554 lp->nonstandard = 1; in sh_lex()
557 lp->digits = -1; in sh_lex()
570 lp->lex.reservok = 1; in sh_lex()
571 lp->lex.skipword = 0; in sh_lex()
577 lp->digits = 1; in sh_lex()
582 lp->token = c = IORDWRSYMT; in sh_lex()
583 if(lp->inexec) in sh_lex()
584 sh_syntax(lp); in sh_lex()
595 if(lp->inexec) in sh_lex()
597 lp->token = c; in sh_lex()
598 sh_syntax(lp); in sh_lex()
606 lp->lex.incase = (c==BREAKCASESYM || c==FALLTHRUSYM); in sh_lex()
610 if(lp->lexd.warn && (n=fcpeek(0))!=RPAREN && n!=' ' && n!='\t') in sh_lex()
614 if(c==LPAREN && lp->comp_assign && !lp->lex.intest && !lp->lex.incase) in sh_lex()
615 lp->comp_assign = 2; in sh_lex()
617 lp->comp_assign = 0; in sh_lex()
618 return(lp->token=c); in sh_lex()
644 ap = lp->arg; in sh_lex()
652 lp->arg = ap; in sh_lex()
656 lp->lexd.first = 0; in sh_lex()
664 else if(mode==ST_NESTED && lp->lexd.warn && in sh_lex()
665 endchar(lp)==RBRACE && in sh_lex()
672 if(!lp->lex.skipword) in sh_lex()
673 lp->lex.reservok *= 2; in sh_lex()
677 if(!lp->lexd.dolparen) in sh_lex()
678 lp->lexd.first = fcseek(0)-LEN; in sh_lex()
679 else if(lp->lexd.docword) in sh_lex()
680 lp->lexd.docend = fcseek(0)-LEN; in sh_lex()
689 if(c=='~' && n==LPAREN && lp->lex.incase) in sh_lex()
690 lp->lex.incase = TEST_RE; in sh_lex()
710 if(!lp->lexd.dolparen) in sh_lex()
711 lp->lexd.first = fcseek(0); in sh_lex()
712 else if(lp->lexd.docword) in sh_lex()
713 lp->lexd.docend = fcseek(0); in sh_lex()
714 if(c=='[' && lp->assignok>=SH_ASSIGN) in sh_lex()
723 if(oldmode(lp)==ST_NONE && !lp->lexd.noarg) /* in ((...)) */ in sh_lex()
735 if(endchar(lp)!='$') in sh_lex()
737 if(oldmode(lp)==ST_QUOTE) /* $' within "" or `` */ in sh_lex()
739 if(lp->lexd.warn) in sh_lex()
746 if(lp->lexd.warn && lp->lex.last_quote && shp->inlineno > lp->lastline) in sh_lex()
747 errormsg(SH_DICT,ERROR_warn(0),e_lexlongquote,lp->lastline,lp->lex.last_quote); in sh_lex()
748 lp->lex.last_quote = 0; in sh_lex()
749 lp->lastline = shp->inlineno; in sh_lex()
751 pushlevel(lp,'\'',mode); in sh_lex()
756 else if(shp->inlineno > lp->lastline) in sh_lex()
757 lp->lex.last_quote = '\''; in sh_lex()
758 mode = oldmode(lp); in sh_lex()
759 poplevel(lp); in sh_lex()
763 if(endchar(lp)=='$') in sh_lex()
771 if(lp->lexd.warn && (mode!=ST_QUOTE || endchar(lp)!='`')) in sh_lex()
778 if(oldmode(lp)==ST_NONE && lp->lexd.arith) /* in ((...)) */ in sh_lex()
789 if(lp->lexd.warn && lp->lex.last_quote && shp->inlineno > lp->lastline) in sh_lex()
790 errormsg(SH_DICT,ERROR_warn(0),e_lexlongquote,lp->lastline,lp->lex.last_quote); in sh_lex()
791 lp->lex.last_quote=0; in sh_lex()
792 lp->lastline = shp->inlineno; in sh_lex()
793 pushlevel(lp,c,mode); in sh_lex()
799 else if((n=endchar(lp))==c) in sh_lex()
801 if(shp->inlineno > lp->lastline) in sh_lex()
802 lp->lex.last_quote = c; in sh_lex()
803 mode = oldmode(lp); in sh_lex()
804 poplevel(lp); in sh_lex()
814 if(lp->lexd.first) in sh_lex()
815 lp->lexd.kiaoff = fcseek(0)-lp->lexd.first; in sh_lex()
817 lp->lexd.kiaoff = stktell(stkp)+fcseek(0)-fcfirst(); in sh_lex()
819 pushlevel(lp,'$',mode); in sh_lex()
825 mode = oldmode(lp); in sh_lex()
826 poplevel(lp); in sh_lex()
828 wordflags |= comsub(lp,c); in sh_lex()
831 if((n=endchar(lp)) == '$') in sh_lex()
835 mode = oldmode(lp); in sh_lex()
836 poplevel(lp); in sh_lex()
842 if(lp->kiafile) in sh_lex()
843 refvar(lp,0); in sh_lex()
845 if(lp->lexd.warn && c==LBRACT && !lp->lex.intest && !lp->lexd.arith && oldmode(lp)!= ST_NESTED) in sh_lex()
848 mode = oldmode(lp); in sh_lex()
849 poplevel(lp); in sh_lex()
875 if(endchar(lp)==RBRACE) in sh_lex()
877 setchar(lp,c); in sh_lex()
882 if(c=='.' && endchar(lp)=='$') in sh_lex()
887 switch(endchar(lp)) in sh_lex()
894 mode = oldmode(lp); in sh_lex()
895 poplevel(lp); in sh_lex()
908 setchar(lp,RBRACE); in sh_lex()
920 setchar(lp,'0'); in sh_lex()
922 setchar(lp,'!'); in sh_lex()
934 if((n=endchar(lp)) == '$') in sh_lex()
939 mode = oldmode(lp); in sh_lex()
940 poplevel(lp); in sh_lex()
941 if((n = endchar(lp)) != '`') in sh_lex()
943 pushlevel(lp,RBRACE,mode); in sh_lex()
946 setchar(lp,RBRACE); in sh_lex()
950 if(oldmode(lp)==ST_QUOTE || oldmode(lp)==ST_NONE) in sh_lex()
967 if(lp->kiafile) in sh_lex()
968 refvar(lp,1); in sh_lex()
981 lp->token = n; in sh_lex()
982 sh_syntax(lp); in sh_lex()
984 else if(lp->lexd.warn) in sh_lex()
992 if((c=endchar(lp)) == '$') in sh_lex()
996 setchar(lp,RBRACE); in sh_lex()
1006 n = endchar(lp); in sh_lex()
1007 mode = oldmode(lp); in sh_lex()
1008 poplevel(lp); in sh_lex()
1011 lp->token = c; in sh_lex()
1012 sh_syntax(lp); in sh_lex()
1016 if(lp->lexd.warn && c!='/' && sh_lexstates[ST_NORM][c]!=S_BREAK && (c!='"' || mode==ST_QUOTE)) in sh_lex()
1024 if(lp->lexd.warn && endchar(lp)==RBRACE) in sh_lex()
1028 pushlevel(lp,RPAREN,mode); in sh_lex()
1033 if(lp->lexd.level <= inlevel) in sh_lex()
1035 if(lp->lexd.level==inlevel+1 && lp->lex.incase>=TEST_RE && !lp->lex.intest) in sh_lex()
1040 n = endchar(lp); in sh_lex()
1057 if(lp->lexd.warn && n==RBRACE) in sh_lex()
1063 if(lp->lexd.warn) in sh_lex()
1067 mode = oldmode(lp); in sh_lex()
1068 poplevel(lp); in sh_lex()
1077 if(mode==ST_NONE && !lp->lexd.dolparen) in sh_lex()
1079 lp->lex.reservok = 1; in sh_lex()
1080 lp->lex.skipword = 0; in sh_lex()
1081 return(lp->token=EXPRSYM); in sh_lex()
1085 if(lp->lexd.warn) in sh_lex()
1087 if(!(state=lp->lexd.first)) in sh_lex()
1090 if(lp->arg) in sh_lex()
1092 lp->arg = (struct argnod*)stkfreeze(stkp,1); in sh_lex()
1093 setupalias(lp,lp->arg->argval,NIL(Namval_t*)); in sh_lex()
1095 lp->lexd.paren = 1; in sh_lex()
1097 return(lp->token=LPAREN); in sh_lex()
1103 lp->token = c; in sh_lex()
1104 sh_syntax(lp); in sh_lex()
1110 assignment = lp->assignok; in sh_lex()
1123 if(lp->lex.reservok && !lp->lex.incase) in sh_lex()
1136 if((n=endchar(lp))==RBRACT || n==RPAREN || in sh_lex()
1138 (oldmode(lp)==ST_NONE) || in sh_lex()
1139 (mode==ST_NAME && (lp->assignok||lp->lexd.level))) in sh_lex()
1151 pushlevel(lp,RBRACT,mode); in sh_lex()
1161 if(lp->lexd.dolparen) in sh_lex()
1163 if(mode==ST_BEGIN && (lp->lex.reservok||lp->comsub)) in sh_lex()
1171 return(lp->token=c); in sh_lex()
1177 if(lp->comsub && c==RBRACE) in sh_lex()
1178 return(lp->token=c); in sh_lex()
1181 isfirst = (lp->lexd.first&&fcseek(0)==lp->lexd.first+1); in sh_lex()
1188 else if(lp->lex.reservok) in sh_lex()
1191 if(lp->lex.reservok && state[n]==S_BREAK && isfirst) in sh_lex()
1194 && !lp->lex.incase && !lp->lex.intest in sh_lex()
1195 && !lp->lex.skipword) in sh_lex()
1210 if(lp->lex.incase==TEST_RE) in sh_lex()
1212 lp->lex.incase++; in sh_lex()
1213 pushlevel(lp,RPAREN,ST_NORM); in sh_lex()
1217 pushlevel(lp,RPAREN,mode); in sh_lex()
1227 lp->comp_assign = 0; in sh_lex()
1234 if(lp->lexd.nocopy) in sh_lex()
1236 lp->lexd.balance = 0; in sh_lex()
1239 if(lp->lexd.dolparen) in sh_lex()
1241 lp->lexd.balance = 0; in sh_lex()
1242 if(lp->lexd.docword) in sh_lex()
1243 nested_here(lp); in sh_lex()
1244 lp->lexd.message = (wordflags&ARG_MESSAGE); in sh_lex()
1245 return(lp->token=0); in sh_lex()
1247 if(!(state=lp->lexd.first)) in sh_lex()
1250 if(!lp->arg) in sh_lex()
1251 lp->arg = (struct argnod*)stkseek(stkp,ARGVAL); in sh_lex()
1255 if(lp->lexd.balance) in sh_lex()
1257 sfputc(stkp,lp->lexd.balance); in sh_lex()
1258 lp->lexd.balance = 0; in sh_lex()
1264 lp->lexd.first=0; in sh_lex()
1271 c = sh_lex(lp); in sh_lex()
1272 lp->digits = (n-'0'); in sh_lex()
1277 else if(n==RBRACE && lp->comsub) in sh_lex()
1278 return(lp->token=n); in sh_lex()
1285 …else if(n>2 && state[0]=='{' && state[n-1]=='}' && !lp->lex.intest && !lp->lex.incase && (c=='<' |… in sh_lex()
1290 lp->arg = (struct argnod*)stkfreeze(stkp,1); in sh_lex()
1291 return(lp->token=IOVNAME); in sh_lex()
1300 lp->arg = (struct argnod*)stkfreeze(stkp,1); in sh_lex()
1301 lp->lex.reservok = 1; in sh_lex()
1302 return(lp->token=LABLSYM); in sh_lex()
1304 if(assignment || (lp->lex.intest&&!lp->lex.incase) || mode==ST_NONE) in sh_lex()
1316 lp->arg = sh_endword(shp,2); in sh_lex()
1319 lp->arg = sh_endword(shp,1); in sh_lex()
1323 if(c==0 || (c&(ARG_MAC|ARG_EXP)) || (lp->lexd.warn && !lp->lexd.docword)) in sh_lex()
1325 lp->arg = (struct argnod*)stkfreeze(stkp,1); in sh_lex()
1326 lp->arg->argflag = (c?c:ARG_RAW); in sh_lex()
1329 lp->arg = sh_endword(shp,-1); in sh_lex()
1331 lp->arg = sh_endword(shp,0); in sh_lex()
1332 state = lp->arg->argval; in sh_lex()
1333 lp->comp_assign = assignment; in sh_lex()
1335 lp->arg->argflag |= ARG_ASSIGN; in sh_lex()
1336 else if(!lp->lex.skipword) in sh_lex()
1337 lp->assignok = 0; in sh_lex()
1338 lp->arg->argchn.cp = 0; in sh_lex()
1339 lp->arg->argnxt.ap = 0; in sh_lex()
1341 return(lp->token=EXPRSYM); in sh_lex()
1342 if(lp->lex.intest) in sh_lex()
1344 if(lp->lex.testop1) in sh_lex()
1346 lp->lex.testop1 = 0; in sh_lex()
1350 if(lp->lexd.warn && state[1]=='a') in sh_lex()
1352 lp->digits = state[1]; in sh_lex()
1353 lp->token = TESTUNOP; in sh_lex()
1357 lp->lex.testop1 = 1; in sh_lex()
1358 lp->token = '!'; in sh_lex()
1362 lp->lex.testop2 = 1; in sh_lex()
1363 lp->token = 0; in sh_lex()
1365 return(lp->token); in sh_lex()
1367 lp->lex.incase = 0; in sh_lex()
1372 lp->lex.testop2 = lp->lex.intest = 0; in sh_lex()
1373 lp->lex.reservok = 1; in sh_lex()
1374 lp->token = ETESTSYM; in sh_lex()
1375 return(lp->token); in sh_lex()
1378 if(lp->lexd.warn && state[1]==0) in sh_lex()
1382 if(lp->lex.testop2) in sh_lex()
1384 if(lp->lexd.warn && (c&TEST_ARITH)) in sh_lex()
1387 lp->lex.incase = 1; in sh_lex()
1389 lp->lex.incase = TEST_RE; in sh_lex()
1390 lp->lex.testop2 = 0; in sh_lex()
1391 lp->digits = c; in sh_lex()
1392 lp->token = TESTBINOP; in sh_lex()
1393 return(lp->token); in sh_lex()
1398 return(lp->token=0); in sh_lex()
1401 if(lp->lex.reservok /* && !lp->lex.incase*/ && n<=2) in sh_lex()
1407 if(lp->lexd.warn && c=='{' && lp->lex.incase==2) in sh_lex()
1409 if(lp->lex.incase==1 && c==RBRACE) in sh_lex()
1410 lp->lex.incase = 0; in sh_lex()
1411 return(lp->token=c); in sh_lex()
1413 else if(!lp->lex.incase && c==LBRACT && state[1]==LBRACT) in sh_lex()
1415 lp->lex.intest = lp->lex.testop1 = 1; in sh_lex()
1416 lp->lex.testop2 = lp->lex.reservok = 0; in sh_lex()
1417 return(lp->token=BTESTSYM); in sh_lex()
1421 if(!lp->lex.skipword) in sh_lex()
1423 if(n>1 && lp->lex.reservok==1 && mode==ST_NAME && in sh_lex()
1426 if(lp->lex.incase) in sh_lex()
1428 if(lp->lex.incase >1) in sh_lex()
1429 lp->lex.incase = 1; in sh_lex()
1431 lp->lex.incase = 0; in sh_lex()
1437 lp->lex.skipword = 1; in sh_lex()
1438 lp->lex.incase = 2*(c==CASESYM); in sh_lex()
1441 lp->lex.skipword = 0; in sh_lex()
1443 lp->lex.reservok = 0; in sh_lex()
1453 return(lp->token=c); in sh_lex()
1455 if(!(wordflags&ARG_QUOTED) && (lp->lex.reservok||lp->aliasok)) in sh_lex()
1459 if(!lp->lex.incase && !assignment && fcpeek(0)!=LPAREN && in sh_lex()
1467 setupalias(lp,state,np); in sh_lex()
1469 lp->lex.reservok = 1; in sh_lex()
1470 lp->assignok |= lp->lex.reservok; in sh_lex()
1471 return(sh_lex(lp)); in sh_lex()
1474 lp->lex.reservok = 0; in sh_lex()
1476 lp->lex.skipword = lp->lexd.docword = 0; in sh_lex()
1477 return(lp->token=c); in sh_lex()
1483 static int comsub(register Lex_t *lp, int endtok) in comsub() argument
1486 register int line=lp->sh->inlineno; in comsub()
1488 int off, messages=0, assignok=lp->assignok, csub; in comsub()
1490 save = lp->lex; in comsub()
1491 csub = lp->comsub; in comsub()
1492 sh_lexopen(lp,lp->sh,1); in comsub()
1493 lp->lexd.dolparen++; in comsub()
1494 lp->lex.incase=0; in comsub()
1495 pushlevel(lp,0,0); in comsub()
1496 lp->comsub = (endtok==LBRACE); in comsub()
1497 off = fcseek(0) - lp->lexd.first; in comsub()
1498 if(sh_lex(lp)==endtok) in comsub()
1500 if(endtok==LPAREN && fcseek(0)==lp->lexd.first) in comsub()
1503 lp->lexd.paren = 0; in comsub()
1525 lp->lex.incase=1; in comsub()
1527 lp->lex.incase=0; in comsub()
1532 if(c==RBRACE && lp->lex.incase) in comsub()
1533 lp->lex.incase=0; in comsub()
1534 switch(c=sh_lex(lp)) in comsub()
1537 if(endtok==LBRACE && !lp->lex.incase) in comsub()
1539 lp->comsub = 0; in comsub()
1547 lp->comsub = (count==1); in comsub()
1551 if(endtok==LPAREN && !lp->lex.incase) in comsub()
1555 if(lp->lex.incase) in comsub()
1556 lp->lex.incase=0; in comsub()
1561 lp->lastline = line; in comsub()
1562 lp->lasttok = endtok; in comsub()
1563 sh_syntax(lp); in comsub()
1569 lp->lexd.docextra = 0; in comsub()
1570 sh_lex(lp); in comsub()
1573 lp->lex.reservok = 0; in comsub()
1574 messages |= lp->lexd.message; in comsub()
1584 lp->lex.reservok = 1; in comsub()
1589 poplevel(lp); in comsub()
1590 lp->comsub = csub; in comsub()
1591 lp->lastline = line; in comsub()
1592 lp->lexd.dolparen--; in comsub()
1593 lp->lex = save; in comsub()
1594 lp->assignok = (endchar(lp)==RBRACT?assignok:0); in comsub()
1602 static void nested_here(register Lex_t *lp) in nested_here() argument
1606 struct argnod *arg = lp->arg; in nested_here()
1607 Stk_t *stkp = lp->sh->stk; in nested_here()
1611 n = fcseek(0)-lp->lexd.docend; in nested_here()
1612 iop = newof(0,struct ionod,1,lp->lexd.docextra+n+ARGVAL); in nested_here()
1613 iop->iolst = lp->heredoc; in nested_here()
1615 if(lp->lexd.docextra) in nested_here()
1617 sfseek(lp->sh->strbuf,(Sfoff_t)0, SEEK_SET); in nested_here()
1618 sfmove(lp->sh->strbuf,stkp,lp->lexd.docextra,-1); in nested_here()
1620 sfwrite(stkp,lp->lexd.docend,n); in nested_here()
1621 lp->arg = sh_endword(lp->sh,0); in nested_here()
1623 strcpy(iop->ioname,lp->arg->argval); in nested_here()
1625 if(lp->lexd.docword>1) in nested_here()
1627 lp->heredoc = iop; in nested_here()
1628 lp->arg = arg; in nested_here()
1629 lp->lexd.docword = 0; in nested_here()
1641 void sh_lexskip(Lex_t *lp,int close, register int copy, int state) in sh_lexskip() argument
1644 lp->lexd.nest = close; in sh_lexskip()
1645 lp->lexd.lex_state = state; in sh_lexskip()
1646 lp->lexd.noarg = 1; in sh_lexskip()
1648 fcnotify(lex_advance,lp); in sh_lexskip()
1650 lp->lexd.nocopy++; in sh_lexskip()
1651 sh_lex(lp); in sh_lexskip()
1652 lp->lexd.noarg = 0; in sh_lexskip()
1655 fcnotify(0,lp); in sh_lexskip()
1656 if(!(cp=lp->lexd.first)) in sh_lexskip()
1659 sfwrite(lp->sh->stk,cp,copy); in sh_lexskip()
1662 lp->lexd.nocopy--; in sh_lexskip()
1695 static int here_copy(Lex_t *lp,register struct ionod *iop) in here_copy() argument
1700 register Sfio_t *sp=lp->sh->heredocs, *funlog; in here_copy()
1702 if(funlog=lp->sh->funlog) in here_copy()
1706 lp->sh->funlog = 0; in here_copy()
1709 here_copy(lp,iop->iolst); in here_copy()
1750 if(!lp->lexd.dolparen && (c=(fcseek(0)-1)-bufp)) in here_copy()
1757 if((c=lexfill(lp))<=0) in here_copy()
1777 lp->sh->inlineno++; in here_copy()
1780 if(!lp->lexd.dolparen) in here_copy()
1817 if(!lp->lexd.dolparen && (c=cp-bufp)) in here_copy()
1823 if((c=lexfill(lp))<=0) in here_copy()
1838 lp->sh->inlineno++; in here_copy()
1841 if(!lp->lexd.dolparen && (n=cp-bufp)) in here_copy()
1846 lp->sh->inlineno--; in here_copy()
1859 if(!lp->lexd.dolparen && nsave>0) in here_copy()
1891 lp->sh->inlineno++; in here_copy()
1892 if(!lp->lexd.dolparen && (n=(fcseek(0)-bufp)-n)>=0) in here_copy()
1912 lp->sh->funlog = funlog; in here_copy()
1913 if(lp->lexd.dolparen) in here_copy()
1923 static char *fmttoken(Lex_t *lp, register int sym, char *tok) in fmttoken() argument
1929 return(lp->arg?lp->arg->argval:"?"); in fmttoken()
1930 if(lp->lex.intest && lp->arg && *lp->arg->argval) in fmttoken()
1931 return(lp->arg->argval); in fmttoken()
1983 void sh_syntax(Lex_t *lp) in sh_syntax() argument
1985 register Shell_t *shp = lp->sh; in sh_syntax()
1988 register int tok = lp->token; in sh_syntax()
1991 if((tok==EOFSYM) && lp->lasttok) in sh_syntax()
1993 tok = lp->lasttok; in sh_syntax()
1997 lp->lastline = shp->inlineno; in sh_syntax()
1998 tokstr = fmttoken(lp,tok,tokbuf); in sh_syntax()
2010 shp->inlineno = lp->inlineno; in sh_syntax()
2011 shp->st.firstline = lp->firstline; in sh_syntax()
2017 errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax1,lp->lastline,tokstr,cp); in sh_syntax()
2307 Lex_t *lp; member
2328 register Lex_t *lp; in alias_exceptf() local
2331 lp = ap->lp; in alias_exceptf()
2350 lp->aliasok = 1; in alias_exceptf()
2363 static void setupalias(Lex_t *lp, const char *string,Namval_t *np) in setupalias() argument
2368 ap->lp = lp; in setupalias()
2373 if(lp->kiafile) in setupalias()
2376 r=kiaentity(lp,nv_name(np),-1,'p',0,0,lp->current,'a',0,""); in setupalias()
2377 …sfprintf(lp->kiatmp,"p;%..64d;p;%..64d;%d;%d;e;\n",lp->current,r,lp->sh->inlineno,lp->sh->inlineno… in setupalias()
2387 lp->lexd.nocopy++; in setupalias()
2393 lp->lexd.nocopy--; in setupalias()
2399 static int stack_grow(Lex_t *lp) in stack_grow() argument
2401 lp->lexd.lex_max += STACK_ARRAY; in stack_grow()
2402 if(lp->lexd.lex_match) in stack_grow()
2403 lp->lexd.lex_match = (int*)realloc((char*)lp->lexd.lex_match,sizeof(int)*lp->lexd.lex_max); in stack_grow()
2405 lp->lexd.lex_match = (int*)malloc(sizeof(int)*STACK_ARRAY); in stack_grow()
2406 return(lp->lexd.lex_match!=0); in stack_grow()