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