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