1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 7*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 8*7c478bd9Sstevel@tonic-gate 9*7c478bd9Sstevel@tonic-gate /* 10*7c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 11*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley Software License Agreement 12*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 13*7c478bd9Sstevel@tonic-gate */ 14*7c478bd9Sstevel@tonic-gate 15*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 16*7c478bd9Sstevel@tonic-gate 17*7c478bd9Sstevel@tonic-gate #include "sh.h" 18*7c478bd9Sstevel@tonic-gate #include "sh.tconst.h" 19*7c478bd9Sstevel@tonic-gate 20*7c478bd9Sstevel@tonic-gate /* 21*7c478bd9Sstevel@tonic-gate * C shell 22*7c478bd9Sstevel@tonic-gate */ 23*7c478bd9Sstevel@tonic-gate 24*7c478bd9Sstevel@tonic-gate extern int doalias(); 25*7c478bd9Sstevel@tonic-gate extern int dobg(); 26*7c478bd9Sstevel@tonic-gate extern int dobreak(); 27*7c478bd9Sstevel@tonic-gate extern int dochngd(); 28*7c478bd9Sstevel@tonic-gate extern int docontin(); 29*7c478bd9Sstevel@tonic-gate extern int dodirs(); 30*7c478bd9Sstevel@tonic-gate extern int doecho(); 31*7c478bd9Sstevel@tonic-gate extern int doelse(); 32*7c478bd9Sstevel@tonic-gate extern int doend(); 33*7c478bd9Sstevel@tonic-gate extern int doendif(); 34*7c478bd9Sstevel@tonic-gate extern int doendsw(); 35*7c478bd9Sstevel@tonic-gate extern int doeval(); 36*7c478bd9Sstevel@tonic-gate extern int doexit(); 37*7c478bd9Sstevel@tonic-gate extern int dofg(); 38*7c478bd9Sstevel@tonic-gate extern int doforeach(); 39*7c478bd9Sstevel@tonic-gate extern int doglob(); 40*7c478bd9Sstevel@tonic-gate extern int dogoto(); 41*7c478bd9Sstevel@tonic-gate extern int dohash(); 42*7c478bd9Sstevel@tonic-gate extern int dorehash(); 43*7c478bd9Sstevel@tonic-gate extern int dohist(); 44*7c478bd9Sstevel@tonic-gate extern int doif(); 45*7c478bd9Sstevel@tonic-gate extern int dojobs(); 46*7c478bd9Sstevel@tonic-gate extern int dokill(); 47*7c478bd9Sstevel@tonic-gate extern int dolet(); 48*7c478bd9Sstevel@tonic-gate extern int dolimit(); 49*7c478bd9Sstevel@tonic-gate extern int dologin(); 50*7c478bd9Sstevel@tonic-gate extern int dologout(); 51*7c478bd9Sstevel@tonic-gate #ifdef NEWGRP 52*7c478bd9Sstevel@tonic-gate extern int donewgrp(); 53*7c478bd9Sstevel@tonic-gate #endif 54*7c478bd9Sstevel@tonic-gate extern int donice(); 55*7c478bd9Sstevel@tonic-gate extern int donotify(); 56*7c478bd9Sstevel@tonic-gate extern int donohup(); 57*7c478bd9Sstevel@tonic-gate extern int doonintr(); 58*7c478bd9Sstevel@tonic-gate extern int dopopd(); 59*7c478bd9Sstevel@tonic-gate extern int dopushd(); 60*7c478bd9Sstevel@tonic-gate extern int dorepeat(); 61*7c478bd9Sstevel@tonic-gate extern int doset(); 62*7c478bd9Sstevel@tonic-gate extern int dosetenv(); 63*7c478bd9Sstevel@tonic-gate extern int dosource(); 64*7c478bd9Sstevel@tonic-gate extern int dostop(); 65*7c478bd9Sstevel@tonic-gate extern int dosuspend(); 66*7c478bd9Sstevel@tonic-gate extern int doswbrk(); 67*7c478bd9Sstevel@tonic-gate extern int doswitch(); 68*7c478bd9Sstevel@tonic-gate extern int dotime(); 69*7c478bd9Sstevel@tonic-gate extern int dounlimit(); 70*7c478bd9Sstevel@tonic-gate extern int doumask(); 71*7c478bd9Sstevel@tonic-gate extern int dowait(); 72*7c478bd9Sstevel@tonic-gate extern int dowhile(); 73*7c478bd9Sstevel@tonic-gate extern int dozip(); 74*7c478bd9Sstevel@tonic-gate extern int execash(); 75*7c478bd9Sstevel@tonic-gate extern int goodbye(); 76*7c478bd9Sstevel@tonic-gate #ifdef VFORK 77*7c478bd9Sstevel@tonic-gate extern int hashstat(); 78*7c478bd9Sstevel@tonic-gate #endif 79*7c478bd9Sstevel@tonic-gate extern int shift(); 80*7c478bd9Sstevel@tonic-gate #ifdef OLDMALLOC 81*7c478bd9Sstevel@tonic-gate extern int showall(); 82*7c478bd9Sstevel@tonic-gate #endif 83*7c478bd9Sstevel@tonic-gate extern int unalias(); 84*7c478bd9Sstevel@tonic-gate extern int dounhash(); 85*7c478bd9Sstevel@tonic-gate extern int unset(); 86*7c478bd9Sstevel@tonic-gate extern int dounsetenv(); 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate #define INF 1000 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate struct biltins bfunc[] = { 91*7c478bd9Sstevel@tonic-gate S_AT, dolet, 0, INF, 92*7c478bd9Sstevel@tonic-gate S_alias, doalias, 0, INF, 93*7c478bd9Sstevel@tonic-gate #ifdef OLDMALLOC 94*7c478bd9Sstevel@tonic-gate S_alloc, showall, 0, 1, 95*7c478bd9Sstevel@tonic-gate #endif 96*7c478bd9Sstevel@tonic-gate S_bg, dobg, 0, INF, 97*7c478bd9Sstevel@tonic-gate S_break, dobreak, 0, 0, 98*7c478bd9Sstevel@tonic-gate S_breaksw, doswbrk, 0, 0, 99*7c478bd9Sstevel@tonic-gate #ifdef IIASA 100*7c478bd9Sstevel@tonic-gate S_bye, goodbye, 0, 0, 101*7c478bd9Sstevel@tonic-gate #endif 102*7c478bd9Sstevel@tonic-gate S_case, dozip, 0, 1, 103*7c478bd9Sstevel@tonic-gate S_cd, dochngd, 0, 1, 104*7c478bd9Sstevel@tonic-gate S_chdir, dochngd, 0, 1, 105*7c478bd9Sstevel@tonic-gate S_continue, docontin, 0, 0, 106*7c478bd9Sstevel@tonic-gate S_default, dozip, 0, 0, 107*7c478bd9Sstevel@tonic-gate S_dirs, dodirs, 0, 1, 108*7c478bd9Sstevel@tonic-gate S_echo, doecho, 0, INF, 109*7c478bd9Sstevel@tonic-gate S_else, doelse, 0, INF, 110*7c478bd9Sstevel@tonic-gate S_end, doend, 0, 0, 111*7c478bd9Sstevel@tonic-gate S_endif, dozip, 0, 0, 112*7c478bd9Sstevel@tonic-gate S_endsw, dozip, 0, 0, 113*7c478bd9Sstevel@tonic-gate S_eval, doeval, 0, INF, 114*7c478bd9Sstevel@tonic-gate S_exec, execash, 1, INF, 115*7c478bd9Sstevel@tonic-gate S_exit, doexit, 0, INF, 116*7c478bd9Sstevel@tonic-gate S_fg, dofg, 0, INF, 117*7c478bd9Sstevel@tonic-gate S_foreach, doforeach, 3, INF, 118*7c478bd9Sstevel@tonic-gate #ifdef IIASA 119*7c478bd9Sstevel@tonic-gate S_gd, dopushd, 0, 1, 120*7c478bd9Sstevel@tonic-gate #endif 121*7c478bd9Sstevel@tonic-gate S_glob, doglob, 0, INF, 122*7c478bd9Sstevel@tonic-gate S_goto, dogoto, 1, 1, 123*7c478bd9Sstevel@tonic-gate #ifdef VFORK 124*7c478bd9Sstevel@tonic-gate S_hashstat, hashstat, 0, 0, 125*7c478bd9Sstevel@tonic-gate #endif 126*7c478bd9Sstevel@tonic-gate S_history, dohist, 0, 2, 127*7c478bd9Sstevel@tonic-gate S_if, doif, 1, INF, 128*7c478bd9Sstevel@tonic-gate S_jobs, dojobs, 0, 1, 129*7c478bd9Sstevel@tonic-gate S_kill, dokill, 1, INF, 130*7c478bd9Sstevel@tonic-gate S_limit, dolimit, 0, 3, 131*7c478bd9Sstevel@tonic-gate S_login, dologin, 0, 1, 132*7c478bd9Sstevel@tonic-gate S_logout, dologout, 0, 0, 133*7c478bd9Sstevel@tonic-gate #ifdef NEWGRP 134*7c478bd9Sstevel@tonic-gate S_newgrp, donewgrp, 1, 1, 135*7c478bd9Sstevel@tonic-gate #endif 136*7c478bd9Sstevel@tonic-gate S_nice, donice, 0, INF, 137*7c478bd9Sstevel@tonic-gate S_nohup, donohup, 0, INF, 138*7c478bd9Sstevel@tonic-gate S_notify, donotify, 0, INF, 139*7c478bd9Sstevel@tonic-gate S_onintr, doonintr, 0, 2, 140*7c478bd9Sstevel@tonic-gate S_popd, dopopd, 0, 1, 141*7c478bd9Sstevel@tonic-gate S_pushd, dopushd, 0, 1, 142*7c478bd9Sstevel@tonic-gate #ifdef IIASA 143*7c478bd9Sstevel@tonic-gate S_rd, dopopd, 0, 1, 144*7c478bd9Sstevel@tonic-gate #endif 145*7c478bd9Sstevel@tonic-gate S_rehash, dorehash, 0, 0, 146*7c478bd9Sstevel@tonic-gate S_repeat, dorepeat, 2, INF, 147*7c478bd9Sstevel@tonic-gate S_set, doset, 0, INF, 148*7c478bd9Sstevel@tonic-gate S_setenv, dosetenv, 0, 2, 149*7c478bd9Sstevel@tonic-gate S_shift, shift, 0, 1, 150*7c478bd9Sstevel@tonic-gate S_source, dosource, 1, 2, 151*7c478bd9Sstevel@tonic-gate S_stop, dostop, 1, INF, 152*7c478bd9Sstevel@tonic-gate S_suspend, dosuspend, 0, 0, 153*7c478bd9Sstevel@tonic-gate S_switch, doswitch, 1, INF, 154*7c478bd9Sstevel@tonic-gate S_time, dotime, 0, INF, 155*7c478bd9Sstevel@tonic-gate S_umask, doumask, 0, 1, 156*7c478bd9Sstevel@tonic-gate S_unalias, unalias, 1, INF, 157*7c478bd9Sstevel@tonic-gate S_unhash, dounhash, 0, 0, 158*7c478bd9Sstevel@tonic-gate S_unlimit, dounlimit, 0, INF, 159*7c478bd9Sstevel@tonic-gate S_unset, unset, 1, INF, 160*7c478bd9Sstevel@tonic-gate S_unsetenv, dounsetenv, 1, INF, 161*7c478bd9Sstevel@tonic-gate S_wait, dowait, 0, 0, 162*7c478bd9Sstevel@tonic-gate S_while, dowhile, 1, INF, 163*7c478bd9Sstevel@tonic-gate }; 164*7c478bd9Sstevel@tonic-gate int nbfunc = sizeof bfunc / sizeof *bfunc; 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate #define ZBREAK 0 167*7c478bd9Sstevel@tonic-gate #define ZBRKSW 1 168*7c478bd9Sstevel@tonic-gate #define ZCASE 2 169*7c478bd9Sstevel@tonic-gate #define ZDEFAULT 3 170*7c478bd9Sstevel@tonic-gate #define ZELSE 4 171*7c478bd9Sstevel@tonic-gate #define ZEND 5 172*7c478bd9Sstevel@tonic-gate #define ZENDIF 6 173*7c478bd9Sstevel@tonic-gate #define ZENDSW 7 174*7c478bd9Sstevel@tonic-gate #define ZEXIT 8 175*7c478bd9Sstevel@tonic-gate #define ZFOREACH 9 176*7c478bd9Sstevel@tonic-gate #define ZGOTO 10 177*7c478bd9Sstevel@tonic-gate #define ZIF 11 178*7c478bd9Sstevel@tonic-gate #define ZLABEL 12 179*7c478bd9Sstevel@tonic-gate #define ZLET 13 180*7c478bd9Sstevel@tonic-gate #define ZSET 14 181*7c478bd9Sstevel@tonic-gate #define ZSWITCH 15 182*7c478bd9Sstevel@tonic-gate #define ZTEST 16 183*7c478bd9Sstevel@tonic-gate #define ZTHEN 17 184*7c478bd9Sstevel@tonic-gate #define ZWHILE 18 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate struct srch srchn[] = { 187*7c478bd9Sstevel@tonic-gate S_AT, ZLET, 188*7c478bd9Sstevel@tonic-gate S_break, ZBREAK, 189*7c478bd9Sstevel@tonic-gate S_breaksw, ZBRKSW, 190*7c478bd9Sstevel@tonic-gate S_case, ZCASE, 191*7c478bd9Sstevel@tonic-gate S_default, ZDEFAULT, 192*7c478bd9Sstevel@tonic-gate S_else, ZELSE, 193*7c478bd9Sstevel@tonic-gate S_end, ZEND, 194*7c478bd9Sstevel@tonic-gate S_endif, ZENDIF, 195*7c478bd9Sstevel@tonic-gate S_endsw, ZENDSW, 196*7c478bd9Sstevel@tonic-gate S_exit, ZEXIT, 197*7c478bd9Sstevel@tonic-gate S_foreach, ZFOREACH, 198*7c478bd9Sstevel@tonic-gate S_goto, ZGOTO, 199*7c478bd9Sstevel@tonic-gate S_if, ZIF, 200*7c478bd9Sstevel@tonic-gate S_label, ZLABEL, 201*7c478bd9Sstevel@tonic-gate S_set, ZSET, 202*7c478bd9Sstevel@tonic-gate S_switch, ZSWITCH, 203*7c478bd9Sstevel@tonic-gate S_while, ZWHILE 204*7c478bd9Sstevel@tonic-gate }; 205*7c478bd9Sstevel@tonic-gate int nsrchn = sizeof srchn / sizeof *srchn; 206*7c478bd9Sstevel@tonic-gate 207