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