Home | History | Annotate | Line # | Download | only in ksh
sh.h revision 1.24
      1 /*	$NetBSD: sh.h,v 1.24 2017/06/22 23:42:35 kamil Exp $	*/
      2 
      3 /*
      4  * Public Domain Bourne/Korn shell
      5  */
      6 
      7 /* $Id: sh.h,v 1.24 2017/06/22 23:42:35 kamil Exp $ */
      8 
      9 #include "config.h"	/* system and option configuration info */
     10 
     11 #ifdef HAVE_PROTOTYPES
     12 # define	ARGS(args)	args	/* prototype declaration */
     13 #else
     14 # define	ARGS(args)	()	/* K&R declaration */
     15 #endif
     16 
     17 /* Start of common headers */
     18 
     19 #include <stdio.h>
     20 #include <sys/types.h>
     21 #include <setjmp.h>
     22 #include <stddef.h>
     23 #include <stdlib.h>
     24 #include <unistd.h>
     25 #include <string.h>
     26 
     27 #ifdef HAVE_PROTOTYPES
     28 # include <stdarg.h>
     29 # define SH_VA_START(va, argn) va_start(va, argn)
     30 #else
     31 # include <varargs.h>
     32 # define SH_VA_START(va, argn) va_start(va)
     33 #endif /* HAVE_PROTOTYPES */
     34 
     35 #include <errno.h>
     36 #include <fcntl.h>
     37 
     38 #ifndef O_ACCMODE
     39 # define O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)
     40 #endif /* !O_ACCMODE */
     41 
     42 #ifndef F_OK 	/* access() arguments */
     43 # define F_OK 0
     44 # define X_OK 1
     45 # define W_OK 2
     46 # define R_OK 4
     47 #endif /* !F_OK */
     48 
     49 #ifndef SEEK_SET
     50 # ifdef L_SET
     51 #  define SEEK_SET L_SET
     52 #  define SEEK_CUR L_INCR
     53 #  define SEEK_END L_XTND
     54 # else /* L_SET */
     55 #  define SEEK_SET 0
     56 #  define SEEK_CUR 1
     57 #  define SEEK_END 2
     58 # endif /* L_SET */
     59 #endif /* !SEEK_SET */
     60 
     61 /* Some machines (eg, FreeBSD 1.1.5) define CLK_TCK in limits.h
     62  * (ksh_limval.h assumes limits has been included, if available)
     63  */
     64 #include <limits.h>
     65 
     66 #include <signal.h>
     67 #ifdef	NSIG
     68 # define SIGNALS	NSIG
     69 #else
     70 # ifdef	_MINIX
     71 #  define SIGNALS	(_NSIG+1) /* _NSIG is # of signals used, excluding 0. */
     72 # else
     73 #  ifdef _SIGMAX	/* QNX */
     74 #   define SIGNALS	_SIGMAX
     75 #  else /* _SIGMAX */
     76 #   define SIGNALS	32
     77 #  endif /* _SIGMAX */
     78 # endif	/* _MINIX */
     79 #endif	/* NSIG */
     80 #ifndef SIGCHLD
     81 # define SIGCHLD SIGCLD
     82 #endif
     83 /* struct sigaction.sa_flags is set to KSH_SA_FLAGS.  Used to ensure
     84  * system calls are interrupted
     85  */
     86 #ifdef SA_INTERRUPT
     87 # define KSH_SA_FLAGS	SA_INTERRUPT
     88 #else /* SA_INTERRUPT */
     89 # define KSH_SA_FLAGS	0
     90 #endif /* SA_INTERRUPT */
     91 
     92 typedef	RETSIGTYPE (*handler_t) ARGS((int));	/* signal handler */
     93 
     94 #ifdef USE_FAKE_SIGACT
     95 # include "sigact.h"			/* use sjg's fake sigaction() */
     96 #endif
     97 
     98 #ifdef HAVE_PATHS_H
     99 # include <paths.h>
    100 #endif /* HAVE_PATHS_H */
    101 #ifdef _PATH_DEFPATH
    102 # define DEFAULT__PATH _PATH_DEFPATH
    103 #else /* _PATH_DEFPATH */
    104 # define DEFAULT__PATH DEFAULT_PATH
    105 #endif /* _PATH_DEFPATH */
    106 
    107 #ifndef HAVE_KILLPG
    108 # define killpg(p, s)	kill(-(p), (s))
    109 #endif /* !HAVE_KILLPG */
    110 
    111 /* Special cases for execve(2) */
    112 # if defined(OS_ISC) && defined(_POSIX_SOURCE)
    113 /* Kludge for ISC 3.2 (and other versions?) so programs will run correctly.  */
    114 #  define ksh_execve(p, av, ev, flags) \
    115 				do { \
    116 					__setostype(0); \
    117 					execve(p, av, ev); \
    118 					__setostype(1); \
    119 				} while (0)
    120 # else /* OS_ISC && _POSIX */
    121 #  define ksh_execve(p, av, ev, flags)	execve(p, av, ev)
    122 # endif /* OS_ISC && _POSIX */
    123 
    124 /* this is a hang-over from older versions of the os2 port */
    125 #define ksh_dupbase(fd, base) fcntl(fd, F_DUPFD, base)
    126 
    127 #ifdef HAVE_SIGSETJMP
    128 # define ksh_sigsetjmp(env,sm)	sigsetjmp((env), (sm))
    129 # define ksh_siglongjmp(env,v)	siglongjmp((env), (v))
    130 # define ksh_jmp_buf		sigjmp_buf
    131 #else /* HAVE_SIGSETJMP */
    132 # ifdef HAVE__SETJMP
    133 #  define ksh_sigsetjmp(env,sm)	_setjmp(env)
    134 #  define ksh_siglongjmp(env,v)	_longjmp((env), (v))
    135 # else /* HAVE__SETJMP */
    136 #  define ksh_sigsetjmp(env,sm)	setjmp(env)
    137 #  define ksh_siglongjmp(env,v)	longjmp((env), (v))
    138 # endif /* HAVE__SETJMP */
    139 # define ksh_jmp_buf		jmp_buf
    140 #endif /* HAVE_SIGSETJMP */
    141 
    142 #ifndef HAVE_DUP2
    143 extern int dup2 ARGS((int, int));
    144 #endif /* !HAVE_DUP2 */
    145 
    146 /* Find a integer type that is at least 32 bits (or die) - SIZEOF_* defined
    147  * by autoconf (assumes an 8 bit byte, but I'm not concerned).
    148  * NOTE: INT32 may end up being more than 32 bits.
    149  */
    150 #if SIZEOF_INT >= 4
    151 # define INT32	int
    152 #else /* SIZEOF_INT */
    153 # if SIZEOF_LONG >= 4
    154 #  define INT32	long
    155 # else /* SIZEOF_LONG */
    156    #error cannot find 32 bit type...
    157 # endif /* SIZEOF_LONG */
    158 #endif /* SIZEOF_INT */
    159 
    160 /* end of common headers */
    161 
    162 /* Stop gcc and lint from complaining about possibly uninitialized variables */
    163 #if defined(__GNUC__) || defined(lint)
    164 # define UNINITIALIZED(var)	var = 0
    165 #else
    166 # define UNINITIALIZED(var)	var
    167 #endif /* GNUC || lint */
    168 
    169 /* some useful #defines */
    170 #ifdef EXTERN
    171 # define I__(i) = i
    172 #else
    173 # define I__(i)
    174 # define EXTERN extern
    175 # define EXTERN_DEFINED
    176 #endif
    177 
    178 #ifndef EXECSHELL
    179 /* shell to exec scripts (see also $SHELL initialization in main.c) */
    180 #  define EXECSHELL	"/bin/sh"
    181 #  define EXECSHELL_STR	"EXECSHELL"
    182 #endif
    183 
    184 /* ISABSPATH() means path is fully and completely specified,
    185  * ISROOTEDPATH() means a .. as the first component is a no-op,
    186  * ISRELPATH() means $PWD can be tacked on to get an absolute path.
    187  *
    188  * OS		Path		ISABSPATH	ISROOTEDPATH	ISRELPATH
    189  * unix		/foo		yes		yes		no
    190  * unix		foo		no		no		yes
    191  * unix		../foo		no		no		yes
    192  */
    193 # define PATHSEP        ':'
    194 # define DIRSEP         '/'
    195 # define DIRSEPSTR      "/"
    196 # define ISDIRSEP(c)    ((c) == '/')
    197 # define ISABSPATH(s)	ISDIRSEP((s)[0])
    198 # define ISRELPATH(s)	(!ISABSPATH(s))
    199 # define ISROOTEDPATH(s) ISABSPATH(s)
    200 # define FILECHCONV(c)	c
    201 # define FILECMP(s1, s2) strcmp(s1, s2)
    202 # define FILENCMP(s1, s2, n) strncmp(s1, s2, n)
    203 # define ksh_strchr_dirsep(p)   strchr(p, DIRSEP)
    204 # define ksh_strrchr_dirsep(p)  strrchr(p, DIRSEP)
    205 
    206 typedef int bool_t;
    207 #define	FALSE	0
    208 #define	TRUE	1
    209 
    210 #define	NELEM(a) (sizeof(a) / sizeof((a)[0]))
    211 #define	sizeofN(type, n) (sizeof(type) * (n))
    212 #define	BIT(i)	(1<<(i))	/* define bit in flag */
    213 
    214 /* Table flag type - needs > 16 and < 32 bits */
    215 typedef INT32 Tflag;
    216 
    217 #define	NUFILE	32		/* Number of user-accessible files */
    218 #define	FDBASE	10		/* First file usable by Shell */
    219 
    220 /* you're not going to run setuid shell scripts, are you? */
    221 #define	eaccess(path, mode)	access(path, mode)
    222 
    223 /* Make MAGIC a char that might be printed to make bugs more obvious, but
    224  * not a char that is used often.  Also, can't use the high bit as it causes
    225  * portability problems (calling strchr(x, 0x80|'x') is error prone).
    226  */
    227 #define	MAGIC		(7)	/* prefix for *?[!{,} during expand */
    228 #define ISMAGIC(c)	((unsigned char)(c) == MAGIC)
    229 #define	NOT		'!'	/* might use ^ (ie, [!...] vs [^..]) */
    230 
    231 #define	LINE	1024		/* input line size */
    232 #define	PATH	1024		/* pathname size (todo: PATH_MAX/pathconf()) */
    233 #define ARRAYMAX 1023		/* max array index */
    234 
    235 EXTERN	const char *kshname;	/* $0 */
    236 EXTERN	pid_t	kshpid;		/* $$, shell pid */
    237 EXTERN	pid_t	procpid;	/* pid of executing process */
    238 EXTERN	uid_t	ksheuid;	/* effective uid of shell */
    239 EXTERN	int	exstat;		/* exit status */
    240 EXTERN	int	subst_exstat;	/* exit status of last $(..)/`..` */
    241 EXTERN	const char *safe_prompt; /* safe prompt if PS1 substitution fails */
    242 
    243 /*
    244  * Area-based allocation built on malloc/free
    245  */
    246 typedef struct Area {
    247 	struct link *freelist;	/* free list */
    248 } Area;
    249 
    250 EXTERN	Area	aperm;		/* permanent object space */
    251 #define	APERM	&aperm
    252 #define	ATEMP	&e->area
    253 
    254 #ifdef MEM_DEBUG
    255 # include "chmem.h" /* a debugging front end for malloc et. al. */
    256 #endif /* MEM_DEBUG */
    257 
    258 #ifdef KSH_DEBUG
    259 # define kshdebug_init()	kshdebug_init_()
    260 # define kshdebug_printf(a)	kshdebug_printf_ a
    261 # define kshdebug_dump(a)	kshdebug_dump_ a
    262 #else /* KSH_DEBUG */
    263 # define kshdebug_init()
    264 # define kshdebug_printf(a)
    265 # define kshdebug_dump(a)
    266 #endif /* KSH_DEBUG */
    267 
    268 /*
    269  * parsing & execution environment
    270  */
    271 EXTERN	struct env {
    272 	short	type;			/* environment type - see below */
    273 	short	flags;			/* EF_* */
    274 	Area	area;			/* temporary allocation area */
    275 	struct	block *loc;		/* local variables and functions */
    276 	short  *savefd;			/* original redirected fd's */
    277 	struct	env *oenv;		/* link to previous environment */
    278 	ksh_jmp_buf jbuf;		/* long jump back to env creator */
    279 	struct temp *temps;		/* temp files */
    280 } *e;
    281 
    282 /* struct env.type values */
    283 #define	E_NONE	0		/* dummy environment */
    284 #define	E_PARSE	1		/* parsing command # */
    285 #define	E_FUNC	2		/* executing function # */
    286 #define	E_INCL	3		/* including a file via . # */
    287 #define	E_EXEC	4		/* executing command tree */
    288 #define	E_LOOP	5		/* executing for/while # */
    289 #define	E_ERRH	6		/* general error handler # */
    290 /* # indicates env has valid jbuf (see unwind()) */
    291 
    292 /* struct env.flag values */
    293 #define EF_FUNC_PARSE	BIT(0)	/* function being parsed */
    294 #define EF_BRKCONT_PASS	BIT(1)	/* set if E_LOOP must pass break/continue on */
    295 #define EF_FAKE_SIGDIE	BIT(2)	/* hack to get info from unwind to quitenv */
    296 
    297 /* Do breaks/continues stop at env type e? */
    298 #define STOP_BRKCONT(t)	((t) == E_NONE || (t) == E_PARSE \
    299 			 || (t) == E_FUNC || (t) == E_INCL)
    300 /* Do returns stop at env type e? */
    301 #define STOP_RETURN(t)	((t) == E_FUNC || (t) == E_INCL)
    302 
    303 /* values for ksh_siglongjmp(e->jbuf, 0) */
    304 #define LRETURN	1		/* return statement */
    305 #define	LEXIT	2		/* exit statement */
    306 #define LERROR	3		/* errorf() called */
    307 #define LLEAVE	4		/* untrappable exit/error */
    308 #define LINTR	5		/* ^C noticed */
    309 #define	LBREAK	6		/* break statement */
    310 #define	LCONTIN	7		/* continue statement */
    311 #define LSHELL	8		/* return to interactive shell() */
    312 #define LAEXPR	9		/* error in arithmetic expression */
    313 
    314 /* option processing */
    315 #define OF_CMDLINE	0x01	/* command line */
    316 #define OF_SET		0x02	/* set builtin */
    317 #define OF_SPECIAL	0x04	/* a special variable changing */
    318 #define OF_INTERNAL	0x08	/* set internally by shell */
    319 #define OF_ANY		(OF_CMDLINE | OF_SET | OF_SPECIAL | OF_INTERNAL)
    320 
    321 struct option {
    322     const char	*name;	/* long name of option */
    323     char	c;	/* character flag (if any) */
    324     short	flags;	/* OF_* */
    325 };
    326 extern const struct option goptions[];
    327 
    328 /*
    329  * flags (the order of these enums MUST match the order in misc.c(options[]))
    330  */
    331 enum sh_flag {
    332 	FEXPORT = 0,	/* -a: export all */
    333 #ifdef BRACE_EXPAND
    334 	FBRACEEXPAND,	/* enable {} globbing */
    335 #endif
    336 	FBGNICE,	/* bgnice */
    337 	FCOMMAND,	/* -c: (invocation) execute specified command */
    338 #ifdef EMACS
    339 	FEMACS,		/* emacs command editing */
    340 	FEMACSUSEMETA,	/* use 8th bit as meta */
    341 #endif
    342 	FERREXIT,	/* -e: quit on error */
    343 #ifdef EMACS
    344 	FGMACS,		/* gmacs command editing */
    345 #endif
    346 	FIGNOREEOF,	/* eof does not exit */
    347 	FTALKING,	/* -i: interactive */
    348 	FKEYWORD,	/* -k: name=value anywhere */
    349 	FLOGIN,		/* -l: a login shell */
    350 	FMARKDIRS,	/* mark dirs with / in file name completion */
    351 	FMONITOR,	/* -m: job control monitoring */
    352 	FNOCLOBBER,	/* -C: don't overwrite existing files */
    353 	FNOEXEC,	/* -n: don't execute any commands */
    354 	FNOGLOB,	/* -f: don't do file globbing */
    355 	FNOHUP,		/* -H: don't kill running jobs when login shell exits */
    356 	FNOLOG,		/* don't save functions in history (ignored) */
    357 #ifdef	JOBS
    358 	FNOTIFY,	/* -b: asynchronous job completion notification */
    359 #endif
    360 	FNOUNSET,	/* -u: using an unset var is an error */
    361 	FPHYSICAL,	/* -o physical: don't do logical cd's/pwd's */
    362 	FPOSIX,		/* -o posix: be posixly correct */
    363 	FPRIVILEGED,	/* -p: use suid_profile */
    364 	FRESTRICTED,	/* -r: restricted shell */
    365 	FSTDIN,		/* -s: (invocation) parse stdin */
    366 	FTRACKALL,	/* -h: create tracked aliases for all commands */
    367 	FVERBOSE,	/* -v: echo input */
    368 #ifdef VI
    369 	FVI,		/* vi command editing */
    370 	FVIRAW,		/* always read in raw mode (ignored) */
    371 	FVISHOW8,	/* display chars with 8th bit set as is (versus M-) */
    372 	FVITABCOMPLETE,	/* enable tab as file name completion char */
    373 	FVIESCCOMPLETE,	/* enable ESC as file name completion in command mode */
    374 #endif
    375 	FXTRACE,	/* -x: execution trace */
    376 	FTALKING_I,	/* (internal): initial shell was interactive */
    377 	FNFLAGS /* (place holder: how many flags are there) */
    378 };
    379 
    380 #define Flag(f)	(shell_flags[(int) (f)])
    381 
    382 EXTERN	char shell_flags [FNFLAGS];
    383 
    384 EXTERN	char	null [] I__("");	/* null value for variable */
    385 EXTERN	char	space [] I__(" ");
    386 EXTERN	char	newline [] I__("\n");
    387 EXTERN	char	slash [] I__("/");
    388 
    389 enum temp_type {
    390     TT_HEREDOC_EXP,	/* expanded heredoc */
    391     TT_HIST_EDIT	/* temp file used for history editing (fc -e) */
    392 };
    393 typedef enum temp_type Temp_type;
    394 /* temp/heredoc files.  The file is removed when the struct is freed. */
    395 struct temp {
    396 	struct temp	*next;
    397 	struct shf	*shf;
    398 	int		pid;		/* pid of process parsed here-doc */
    399 	Temp_type	type;
    400 	char		*name;
    401 };
    402 
    403 /*
    404  * stdio and our IO routines
    405  */
    406 
    407 #define shl_spare	(&shf_iob[0])	/* for c_read()/c_print() */
    408 #define shl_stdout	(&shf_iob[1])
    409 #define shl_out		(&shf_iob[2])
    410 EXTERN int shl_stdout_ok;
    411 
    412 /*
    413  * trap handlers
    414  */
    415 typedef struct trap {
    416 	int	signal;		/* signal number */
    417 	const char *name;	/* short name */
    418 	const char *mess;	/* descriptive name */
    419 	char   *trap;		/* trap command */
    420 	int	volatile set;	/* trap pending */
    421 	int	flags;		/* TF_* */
    422 	handler_t cursig;	/* current handler (valid if TF_ORIG_* set) */
    423 	handler_t shtrap;	/* shell signal handler */
    424 } Trap;
    425 
    426 /* values for Trap.flags */
    427 #define TF_SHELL_USES	BIT(0)	/* shell uses signal, user can't change */
    428 #define TF_USER_SET	BIT(1)	/* user has (tried to) set trap */
    429 #define TF_ORIG_IGN	BIT(2)	/* original action was SIG_IGN */
    430 #define TF_ORIG_DFL	BIT(3)	/* original action was SIG_DFL */
    431 #define TF_EXEC_IGN	BIT(4)	/* restore SIG_IGN just before exec */
    432 #define TF_EXEC_DFL	BIT(5)	/* restore SIG_DFL just before exec */
    433 #define TF_DFL_INTR	BIT(6)	/* when received, default action is LINTR */
    434 #define TF_TTY_INTR	BIT(7)	/* tty generated signal (see j_waitj) */
    435 #define TF_CHANGED	BIT(8)	/* used by runtrap() to detect trap changes */
    436 #define TF_FATAL	BIT(9)	/* causes termination if not trapped */
    437 
    438 /* values for setsig()/setexecsig() flags argument */
    439 #define SS_RESTORE_MASK	0x3	/* how to restore a signal before an exec() */
    440 #define SS_RESTORE_CURR	0	/* leave current handler in place */
    441 #define SS_RESTORE_ORIG	1	/* restore original handler */
    442 #define SS_RESTORE_DFL	2	/* restore to SIG_DFL */
    443 #define SS_RESTORE_IGN	3	/* restore to SIG_IGN */
    444 #define SS_FORCE	BIT(3)	/* set signal even if original signal ignored */
    445 #define SS_USER		BIT(4)	/* user is doing the set (ie, trap command) */
    446 #define SS_SHTRAP	BIT(5)	/* trap for internal use (CHLD,ALRM,WINCH) */
    447 
    448 #define SIGEXIT_	0	/* for trap EXIT */
    449 #define SIGERR_		SIGNALS	/* for trap ERR */
    450 
    451 EXTERN	int volatile trap;	/* traps pending? */
    452 EXTERN	int volatile intrsig;	/* pending trap interrupts executing command */
    453 EXTERN	int volatile fatal_trap;/* received a fatal signal */
    454 extern	Trap	sigtraps[SIGNALS+1];
    455 
    456 #ifdef KSH
    457 /*
    458  * TMOUT support
    459  */
    460 /* values for ksh_tmout_state */
    461 enum tmout_enum {
    462 		TMOUT_EXECUTING	= 0,	/* executing commands */
    463 		TMOUT_READING,		/* waiting for input */
    464 		TMOUT_LEAVING		/* have timed out */
    465 	};
    466 EXTERN unsigned int ksh_tmout;
    467 EXTERN enum tmout_enum ksh_tmout_state I__(TMOUT_EXECUTING);
    468 #endif /* KSH */
    469 
    470 /* For "You have stopped jobs" message */
    471 EXTERN int really_exit;
    472 
    473 /*
    474  * fast character classes
    475  */
    476 #define	C_ALPHA	 BIT(0)		/* a-z_A-Z */
    477 #define	C_DIGIT	 BIT(1)		/* 0-9 */
    478 #define	C_LEX1	 BIT(2)		/* \0 \t\n|&;<>() */
    479 #define	C_VAR1	 BIT(3)		/* *@#!$-? */
    480 #define	C_IFSWS	 BIT(4)		/* \t \n (IFS white space) */
    481 #define	C_SUBOP1 BIT(5)		/* "=-+?" */
    482 #define	C_SUBOP2 BIT(6)		/* "#%" */
    483 #define	C_IFS	 BIT(7)		/* $IFS */
    484 #define	C_QUOTE	 BIT(8)		/*  \n\t"#$&'()*;<>?[\`| (needing quoting) */
    485 
    486 extern	short ctypes [];
    487 
    488 #define	ctype(c, t)	!!(ctypes[(unsigned char)(c)]&(t))
    489 #define	letter(c)	ctype(c, C_ALPHA)
    490 #define	digit(c)	ctype(c, C_DIGIT)
    491 #define	letnum(c)	ctype(c, C_ALPHA|C_DIGIT)
    492 
    493 EXTERN int ifs0 I__(' ');	/* for "$*" */
    494 
    495 /* Argument parsing for built-in commands and getopts command */
    496 
    497 /* Values for Getopt.flags */
    498 #define GF_ERROR	BIT(0)	/* call errorf() if there is an error */
    499 #define GF_PLUSOPT	BIT(1)	/* allow +c as an option */
    500 #define GF_NONAME	BIT(2)	/* don't print argv[0] in errors */
    501 
    502 /* Values for Getopt.info */
    503 #define GI_MINUS	BIT(0)	/* an option started with -... */
    504 #define GI_PLUS		BIT(1)	/* an option started with +... */
    505 #define GI_MINUSMINUS	BIT(2)	/* arguments were ended with -- */
    506 
    507 typedef struct {
    508 	int		optind;
    509 	int		uoptind;/* what user sees in $OPTIND */
    510 	char		*optarg;
    511 	int		flags;	/* see GF_* */
    512 	int		info;	/* see GI_* */
    513 	unsigned int	p;	/* 0 or index into argv[optind - 1] */
    514 	char		buf[2];	/* for bad option OPTARG value */
    515 } Getopt;
    516 
    517 EXTERN Getopt builtin_opt;	/* for shell builtin commands */
    518 EXTERN Getopt user_opt;		/* parsing state for getopts builtin command */
    519 
    520 #ifdef KSH
    521 /* This for co-processes */
    522 
    523 typedef INT32 Coproc_id; /* something that won't (realisticly) wrap */
    524 struct coproc {
    525 	int	read;		/* pipe from co-process's stdout */
    526 	int	readw;		/* other side of read (saved temporarily) */
    527 	int	write;		/* pipe to co-process's stdin */
    528 	Coproc_id id;		/* id of current output pipe */
    529 	int	njobs;		/* number of live jobs using output pipe */
    530 	void    *job;           /* 0 or job of co-process using input pipe */
    531 };
    532 EXTERN struct coproc coproc;
    533 #endif /* KSH */
    534 
    535 /* Used in jobs.c and by coprocess stuff in exec.c */
    536 #ifdef JOB_SIGS
    537 EXTERN sigset_t		sm_default, sm_sigchld;
    538 #endif /* JOB_SIGS */
    539 
    540 extern char ksh_version[];
    541 
    542 /* name of called builtin function (used by error functions) */
    543 EXTERN char	*builtin_argv0;
    544 EXTERN Tflag	builtin_flag;	/* flags of called builtin (SPEC_BI, etc.) */
    545 
    546 /* current working directory, and size of memory allocated for same */
    547 EXTERN char	*current_wd;
    548 EXTERN int	current_wd_size;
    549 
    550 #ifdef EDIT
    551 /* Minimum required space to work with on a line - if the prompt leaves less
    552  * space than this on a line, the prompt is truncated.
    553  */
    554 # define MIN_EDIT_SPACE	7
    555 /* Minimum allowed value for x_cols: 2 for prompt, 3 for " < " at end of line
    556  */
    557 # define MIN_COLS	(2 + MIN_EDIT_SPACE + 3)
    558 EXTERN	int	x_cols I__(80);	/* tty columns */
    559 #else
    560 # define x_cols 80		/* for pr_menu(exec.c) */
    561 #endif
    562 
    563 /* These to avoid bracket matching problems */
    564 #define OPAREN	'('
    565 #define CPAREN	')'
    566 #define OBRACK	'['
    567 #define CBRACK	']'
    568 #define OBRACE	'{'
    569 #define CBRACE	'}'
    570 
    571 /* Determine the location of the system (common) profile */
    572 #ifndef KSH_SYSTEM_PROFILE
    573 # ifdef __NeXT
    574 #  define KSH_SYSTEM_PROFILE "/etc/profile.std"
    575 # else /* __NeXT */
    576 #  define KSH_SYSTEM_PROFILE "/etc/profile"
    577 # endif /* __NeXT */
    578 #endif /* KSH_SYSTEM_PROFILE */
    579 
    580 /* Used by v_evaluate() and setstr() to control action when error occurs */
    581 #define KSH_UNWIND_ERROR	0	/* unwind the stack (longjmp) */
    582 #define KSH_RETURN_ERROR	1	/* return 1/0 for success/failure */
    583 
    584 #include "shf.h"
    585 #include "table.h"
    586 #include "tree.h"
    587 #include "expand.h"
    588 #include "lex.h"
    589 #include "proto.h"
    590 
    591 /* be sure not to interfere with anyone else's idea about EXTERN */
    592 #ifdef EXTERN_DEFINED
    593 # undef EXTERN_DEFINED
    594 # undef EXTERN
    595 #endif
    596 #undef I__
    597