Lines Matching refs:shp

62 static_fn void chkmail(Shell_t *shp, char *);
82 bool sh_source(Shell_t *shp, Sfio_t *iop, const char *file) { in sh_source() argument
87 if (!file || !*file || (fd = path_open(shp, file, PATHCOMP)) < 0) { in sh_source()
92 shp->st.filename = path_fullname(shp, stkptr(shp->stk, PATH_OFFSET)); in sh_source()
93 exfile(shp, iop, fd); in sh_source()
103 Shell_t *shp; in sh_main() local
114 shp = sh_init(ac, av, userinit); in sh_main()
117 rshflag = sh_isoption(shp, SH_RESTRICTED); in sh_main()
118 if (rshflag) sh_offoption(shp, SH_RESTRICTED); in sh_main()
119 if (sigsetjmp(shp->jmpbuffer->buff, 0)) { in sh_main()
121 sh_reinit(shp, NULL); in sh_main()
122 shp->gd->pid = getpid(); in sh_main()
123 shp->gd->ppid = getppid(); in sh_main()
125 shp->fn_depth = shp->dot_depth = 0; in sh_main()
128 srand(shp->gd->pid & 0x7fff); in sh_main()
130 path_pwd(shp); in sh_main()
132 sh_onoption(shp, SH_BRACEEXPAND); in sh_main()
134 sh_onstate(shp, SH_PROFILE); in sh_main()
135 shp->lex_context->nonstandard = 0; in sh_main()
136 if (shp->gd->ppid == 1) shp->login_sh++; in sh_main()
137 if (shp->login_sh >= 2) sh_onoption(shp, SH_LOGIN_SHELL); in sh_main()
139 if (!sh_isoption(shp, SH_INTERACTIVE) && !sh_isoption(shp, SH_TFLAG) && in sh_main()
140 !sh_isoption(shp, SH_CFLAG) && sh_isoption(shp, SH_SFLAG) && tty_check(0) && in sh_main()
142 sh_onoption(shp, SH_INTERACTIVE); in sh_main()
144 if (sh_isoption(shp, SH_INTERACTIVE)) { in sh_main()
145 sh_onoption(shp, SH_BGNICE); in sh_main()
146 sh_onoption(shp, SH_RC); in sh_main()
148 if (!sh_isoption(shp, SH_RC) && in sh_main()
149 (sh_isoption(shp, SH_BASH) && !sh_isoption(shp, SH_POSIX))) { in sh_main()
150 sh_onoption(shp, SH_RC); in sh_main()
152 for (i = 0; i < elementsof(shp->offoptions.v); i++) { in sh_main()
153 shp->options.v[i] &= ~shp->offoptions.v[i]; in sh_main()
155 if (sh_isoption(shp, SH_INTERACTIVE)) { in sh_main()
162 sh_onoption(shp, SH_MONITOR); in sh_main()
164 job_init(shp, sh_isoption(shp, SH_LOGIN_SHELL)); in sh_main()
165 sh_source(shp, iop, INSTALL_PREFIX "/share/ksh/config.ksh"); in sh_main()
166 if (sh_isoption(shp, SH_LOGIN_SHELL)) { in sh_main()
168 sh_source(shp, iop, e_sysprofile); in sh_main()
169 if (!sh_isoption(shp, SH_NOUSRPROFILE) && !sh_isoption(shp, SH_PRIVILEGED)) { in sh_main()
170 char **files = shp->gd->login_files; in sh_main()
171 while ((name = *files++) && !sh_source(shp, iop, sh_mactry(shp, name))) { in sh_main()
177 path_pwd(shp); in sh_main()
178 if (!sh_isoption(shp, SH_NOEXEC)) { in sh_main()
179 if (!sh_isoption(shp, SH_NOUSRPROFILE) && !sh_isoption(shp, SH_PRIVILEGED) && in sh_main()
180 sh_isoption(shp, SH_RC)) { in sh_main()
182 if (sh_isoption(shp, SH_BASH) && !sh_isoption(shp, SH_POSIX)) { in sh_main()
183 sh_source(shp, iop, e_bash_sysrc); in sh_main()
185 shp, iop, in sh_main()
186 shp->gd->rcfile ? shp->gd->rcfile : sh_mactry(shp, (char *)e_bash_rc)); in sh_main()
190 name = sh_mactry(shp, nv_getval(VAR_ENV)); in sh_main()
192 if (!name || !strmatch(name, "?(.)/./*")) sh_source(shp, iop, e_sysrc); in sh_main()
194 sh_source(shp, iop, name); in sh_main()
198 } else if (sh_isoption(shp, SH_INTERACTIVE) && sh_isoption(shp, SH_PRIVILEGED)) { in sh_main()
199 sh_source(shp, iop, e_suidprofile); in sh_main()
204 if (sh_isoption(shp, SH_XTRACE)) { in sh_main()
206 sh_offoption(shp, SH_XTRACE); in sh_main()
208 if (sh_isoption(shp, SH_NOEXEC)) { in sh_main()
210 sh_offoption(shp, SH_NOEXEC); in sh_main()
212 if (sh_isoption(shp, SH_VERBOSE)) { in sh_main()
214 sh_offoption(shp, SH_VERBOSE); in sh_main()
216 sh_trap(shp, "enum _Bool=(false true) ;", 0); in sh_main()
217 if (i & 1) sh_onoption(shp, SH_XTRACE); in sh_main()
218 if (i & 2) sh_onoption(shp, SH_NOEXEC); in sh_main()
219 if (i & 4) sh_onoption(shp, SH_VERBOSE); in sh_main()
220 shp->st.cmdname = error_info.id = command; in sh_main()
221 sh_offstate(shp, SH_PROFILE); in sh_main()
222 if (rshflag) sh_onoption(shp, SH_RESTRICTED); in sh_main()
224 if (shp->comdiv) { in sh_main()
226 iop = sfnew(NULL, shp->comdiv, strlen(shp->comdiv), 0, SF_STRING | SF_READ); in sh_main()
229 error_info.id = shp->shname; in sh_main()
230 if (sh_isoption(shp, SH_SFLAG)) { in sh_main()
249 if (shp->st.repl_index > 0) av[shp->st.repl_index] = shp->st.repl_arg; in sh_main()
257 shp->st.dolv[0] = av[0]; in sh_main()
261 sh_offoption(shp, SH_VERBOSE); in sh_main()
262 sh_offoption(shp, SH_XTRACE); in sh_main()
271 shp->st.filename = path_fullname(shp, name); in sh_main()
276 if (path_absolute(shp, name, NULL)) { in sh_main()
277 sp = stkptr(shp->stk, PATH_OFFSET); in sh_main()
280 sp = path_absolute(shp, name, NULL); in sh_main()
284 if (fdin >= 0) shp->st.filename = path_fullname(shp, sp); in sh_main()
295 sh_onoption(shp, SH_CFLAG); in sh_main()
296 shp->comdiv = malloc(strlen(name) + 7); in sh_main()
297 name = stpcpy(shp->comdiv, name); in sh_main()
298 if (shp->st.dolc) stpcpy(name, " \"$@\""); in sh_main()
301 if (fdin == 0) fdin = sh_iomovefd(shp, fdin); in sh_main()
303 shp->readscript = shp->shname; in sh_main()
306 shp->comdiv--; in sh_main()
309 fdin = shp->infd; in sh_main()
312 if (sh_isoption(shp, SH_INTERACTIVE)) sh_onstate(shp, SH_INTERACTIVE); in sh_main()
314 exfile(shp, iop, fdin); in sh_main()
315 sh_done(shp, 0); in sh_main()
325 static_fn void exfile(Shell_t *shp, Sfio_t *iop, int fno) { in exfile() argument
332 sh_pushcontext(shp, &buff, SH_JMPERREXIT); in exfile()
334 nv_putval(VAR_sh_file, shp->st.filename, NV_NOFREE); in exfile()
339 shp->fdstatus[r] = shp->fdstatus[fno]; in exfile()
344 shp->fdstatus[fno] |= IOCLEX; in exfile()
345 iop = sh_iostream(shp, fno, fno); in exfile()
352 shp->infd = fno; in exfile()
353 if (sh_isstate(shp, SH_INTERACTIVE)) { in exfile()
355 nv_putval(VAR_PS1, (shp->gd->euserid ? e_stdprompt : e_supprompt), NV_RDONLY); in exfile()
357 sh_sigdone(shp); in exfile()
358 if (sh_histinit(shp)) sh_onoption(shp, SH_HISTORY); in exfile()
360 if (!sh_isstate(shp, SH_PROFILE)) { in exfile()
362 sh_onoption(shp, SH_TRACKALL); in exfile()
364 sh_offstate(shp, SH_INTERACTIVE); in exfile()
365 if (sh_isoption(shp, SH_MONITOR)) sh_onstate(shp, SH_MONITOR); in exfile()
366 sh_offstate(shp, SH_HISTORY); in exfile()
367 sh_offoption(shp, SH_HISTORY); in exfile()
369 states = sh_getstate(shp); in exfile()
373 sh_iorestore(shp, 0, jmpval); in exfile()
374 hist_flush(shp->gd->hist_ptr); in exfile()
375 sfsync(shp->outpool); in exfile()
376 shp->st.execbrk = shp->st.breakcnt = 0; in exfile()
378 if (sh_isstate(shp, SH_PROFILE) && in exfile()
380 sh_setstate(shp, states); in exfile()
383 if (!sh_isoption(shp, SH_INTERACTIVE) || sh_isstate(shp, SH_FORKED) || in exfile()
384 (jmpval > SH_JMPERREXIT && job_close(shp) >= 0)) { in exfile()
385 sh_offstate(shp, SH_INTERACTIVE); in exfile()
386 sh_offstate(shp, SH_MONITOR); in exfile()
389 exitset(shp); in exfile()
401 tcsetpgrp(job.fd, shp->gd->pid); in exfile()
406 sh_setstate(shp, states); in exfile()
407 shp->st.optindex = 1; in exfile()
409 shp->st.loopcnt = 0; in exfile()
410 shp->trapnote = 0; in exfile()
411 shp->intrap = 0; in exfile()
413 shp->inlineno = 1; in exfile()
414 shp->binscript = 0; in exfile()
415 shp->exittrap = 0; in exfile()
416 shp->errtrap = 0; in exfile()
417 shp->end_fn = 0; in exfile()
421 shp->nextprompt = 1; in exfile()
422 sh_freeup(shp); in exfile()
423 stkset(shp->stk, NULL, 0); in exfile()
424 sh_offstate(shp, SH_STOPOK); in exfile()
425 sh_offstate(shp, SH_ERREXIT); in exfile()
426 sh_offstate(shp, SH_VERBOSE); in exfile()
427 sh_offstate(shp, SH_TIMING); in exfile()
428 sh_offstate(shp, SH_GRACE); in exfile()
429 sh_offstate(shp, SH_TTYWAIT); in exfile()
430 if (sh_isoption(shp, SH_VERBOSE)) sh_onstate(shp, SH_VERBOSE); in exfile()
431 sh_onstate(shp, SH_ERREXIT); in exfile()
433 if (sh_isstate(shp, SH_PROFILE)) { in exfile()
434 sh_offstate(shp, SH_INTERACTIVE); in exfile()
435 sh_offstate(shp, SH_ERREXIT); in exfile()
436 sh_offstate(shp, SH_MONITOR); in exfile()
438 if (sh_isstate(shp, SH_INTERACTIVE) && !tdone) { in exfile()
441 sh_offstate(shp, SH_MONITOR); in exfile()
442 if (sh_isoption(shp, SH_MONITOR)) sh_onstate(shp, SH_MONITOR); in exfile()
444 job_walk(shp, sfstderr, job_list, JOB_NFLAG, NULL); in exfile()
451 chkmail(shp, mail); in exfile()
455 if (shp->gd->hist_ptr) hist_eof(shp->gd->hist_ptr); in exfile()
457 shp->timeout = shp->st.tmout; in exfile()
459 if (shp->timeout <= 0 || shp->timeout > READ_TIMEOUT) shp->timeout = READ_TIMEOUT; in exfile()
461 shp->inlineno = 1; in exfile()
463 shp->trapnote = 0; in exfile()
474 if (sh_isstate(shp, SH_INTERACTIVE) && !sferror(iop)) { in exfile()
475 if (--maxtry > 0 && sh_isoption(shp, SH_IGNOREEOF) && !sferror(sfstderr)) { in exfile()
478 if ((shp->fdstatus[fno] & IOTTY)) { in exfile()
483 } else if (job_close(shp) < 0) { in exfile()
494 shp->exitval = shp->savexit; in exfile()
496 if (sh_isstate(shp, SH_INTERACTIVE) && shp->gd->hist_ptr) { in exfile()
498 hist_eof(shp->gd->hist_ptr); in exfile()
501 if (sh_isoption(shp, SH_HISTORY)) sh_onstate(shp, SH_HISTORY); in exfile()
504 t = sh_parse(shp, iop, 0); in exfile()
505 if (!sh_isstate(shp, SH_INTERACTIVE) && !sh_isoption(shp, SH_CFLAG)) { in exfile()
508 shp->readscript = NULL; in exfile()
509 if (sh_isstate(shp, SH_INTERACTIVE) && shp->gd->hist_ptr) hist_flush(shp->gd->hist_ptr); in exfile()
510 sh_offstate(shp, SH_HISTORY); in exfile()
515 shp->st.execbrk = 0; in exfile()
516 sh_exec(shp, t, execflags); in exfile()
517 if (shp->forked) { in exfile()
518 sh_offstate(shp, SH_INTERACTIVE); in exfile()
522 if (sh_isoption(shp, SH_TFLAG) && !sh_isstate(shp, SH_PROFILE)) tdone++; in exfile()
525 sh_popcontext(shp, &buff); in exfile()
526 if (sh_isstate(shp, SH_INTERACTIVE)) { in exfile()
528 job_close(shp); in exfile()
531 siglongjmp(shp->jmplist->buff, jmpval); in exfile()
533 sh_done(shp, 0); in exfile()
536 if (shp->st.filename) { in exfile()
537 free(shp->st.filename); in exfile()
538 shp->st.filename = NULL; in exfile()
543 static_fn void chkmail(Shell_t *shp, char *files) { in chkmail() argument
547 int offset = stktell(shp->stk); in chkmail()
548 char *savstak = stkptr(shp->stk, 0); in chkmail()
570 path_complete(shp, cp, "/*", &arglist); in chkmail()
578 char *save = shp->lastarg; in chkmail()
579 shp->lastarg = cp; in chkmail()
580 errormsg(SH_DICT, 0, sh_mactry(shp, qp ? qp + 1 : (char *)e_mailmsg)); in chkmail()
581 shp->lastarg = save; in chkmail()
598 stkset(shp->stk, savstak, offset); in chkmail()