1*50a5715bSkre /* $NetBSD: eval.h,v 1.24 2024/08/03 03:05:58 kre Exp $ */ 249f0ad86Scgd 361f28255Scgd /*- 437ed7877Sjtc * Copyright (c) 1991, 1993 537ed7877Sjtc * The Regents of the University of California. All rights reserved. 661f28255Scgd * 761f28255Scgd * This code is derived from software contributed to Berkeley by 861f28255Scgd * Kenneth Almquist. 961f28255Scgd * 1061f28255Scgd * Redistribution and use in source and binary forms, with or without 1161f28255Scgd * modification, are permitted provided that the following conditions 1261f28255Scgd * are met: 1361f28255Scgd * 1. Redistributions of source code must retain the above copyright 1461f28255Scgd * notice, this list of conditions and the following disclaimer. 1561f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright 1661f28255Scgd * notice, this list of conditions and the following disclaimer in the 1761f28255Scgd * documentation and/or other materials provided with the distribution. 18b5b29542Sagc * 3. Neither the name of the University nor the names of its contributors 1961f28255Scgd * may be used to endorse or promote products derived from this software 2061f28255Scgd * without specific prior written permission. 2161f28255Scgd * 2261f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2361f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2461f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2561f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2661f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2761f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2861f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2961f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3061f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3161f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3261f28255Scgd * SUCH DAMAGE. 3361f28255Scgd * 3407bae7edSchristos * @(#)eval.h 8.2 (Berkeley) 5/4/95 3561f28255Scgd */ 3661f28255Scgd 374498b1feSmatt extern const char *commandname; /* currently executing command */ 3861f28255Scgd extern int exitstatus; /* exit status of last command */ 39c02b3bbdSchristos extern int back_exitstatus; /* exit status of backquoted command */ 4061f28255Scgd extern struct strlist *cmdenviron; /* environment for builtin command */ 4161f28255Scgd 4261f28255Scgd 4361f28255Scgd struct backcmd { /* result of evalbackcmd */ 4461f28255Scgd int fd; /* file descriptor to read from */ 4561f28255Scgd char *buf; /* buffer */ 4661f28255Scgd int nleft; /* number of chars in buffer */ 4761f28255Scgd struct job *jp; /* job structure for command */ 4861f28255Scgd }; 4961f28255Scgd 50*50a5715bSkre void evalstring(const char *, int); 5161f28255Scgd union node; /* BLETCH for ansi C */ 52c02b3bbdSchristos void evaltree(union node *, int); 53c02b3bbdSchristos void evalbackcmd(union node *, struct backcmd *); 5461f28255Scgd 55e2f17f9aSkre const char *syspath(void); 56e2f17f9aSkre 5761f28255Scgd /* in_function returns nonzero if we are currently evaluating a function */ 5801f35fccSchristos int in_function(void); /* return non-zero, if evaluating a function */ 59f9382bcaSchristos 60f9382bcaSchristos /* reasons for skipping commands (see comment on breakcmd routine) */ 6101f35fccSchristos enum skipstate { 6201f35fccSchristos SKIPNONE = 0, /* not skipping */ 6301f35fccSchristos SKIPBREAK, /* break */ 6401f35fccSchristos SKIPCONT, /* continue */ 6501f35fccSchristos SKIPFUNC, /* return in a function */ 6601f35fccSchristos SKIPFILE /* return in a dot command */ 6701f35fccSchristos }; 6801f35fccSchristos 6913fc5c1bSkre struct skipsave { 7013fc5c1bSkre enum skipstate state; /* skipping or not */ 7113fc5c1bSkre int count; /* when break or continue, how many */ 7213fc5c1bSkre }; 7313fc5c1bSkre 7401f35fccSchristos enum skipstate current_skipstate(void); 7513fc5c1bSkre void save_skipstate(struct skipsave *); 7613fc5c1bSkre void restore_skipstate(const struct skipsave *); 7701f35fccSchristos void stop_skipping(void); /* reset internal skipping state to SKIPNONE */ 784084f829Skre int set_dot_funcnest(int); 7901f35fccSchristos 8001f35fccSchristos /* 8101f35fccSchristos * Only for use by reset() in init.c! 8201f35fccSchristos */ 8301f35fccSchristos void reset_eval(void); 848a99e51dSkre 858a99e51dSkre /* flags in argument to evaltree */ 868a99e51dSkre #define EV_EXIT 0x01 /* exit after evaluating tree */ 878a99e51dSkre #define EV_TESTED 0x02 /* exit status is checked; ignore -e flag */ 888a99e51dSkre #define EV_BACKCMD 0x04 /* command executing within back quotes */ 89