1 /* $Header: /src/pub/tcsh/sh.h,v 3.114 2004/02/21 20:34:25 christos Exp $ */
3 * sh.h: Catch it all globals and includes file!
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 # define EXTERN extern
49 # define IZERO_STRUCT = {0}
50 # endif /* WINNT_NATIVE */
58 # endif /* IZERO_STRUCT */
62 # define INIT_ZERO_STRUCT
63 # define force_read read
64 #endif /*!WINNT_NATIVE */
68 #if defined(_POSIX_SOURCE) && !defined(POSIX)
72 #if defined(POSIXJOBS) && !defined(BSDJOBS)
76 #if defined(POSIXSIGS) && !defined(BSDSIGS)
82 typedef unsigned short uChar;
83 # define SAVE(a) (Strsave(str2short(a)))
86 typedef unsigned char uChar;
87 # define SAVE(a) (strsave(a))
90 /* Elide unused argument warnings */
91 #define USE(a) (void) (a)
93 * If your compiler complains, then you can either
94 * throw it away and get gcc or, use the following define
95 * and get rid of the typedef.
96 * [The 4.2/3BSD vax compiler does not like that]
97 * Both MULTIFLOW and PCC compilers exhbit this bug. -- sterling@netcom.com
100 # if (defined(vax) || defined(uts) || defined(MULTIFLOW) || defined(PCC)) && !defined(__GNUC__)
101 # define sigret_t void
102 # else /* !((vax || uts || MULTIFLOW || PCC) && !__GNUC__) */
103 typedef void sigret_t;
104 # endif /* (vax || uts || MULTIFLOW || PCC) && !__GNUC__ */
106 typedef int sigret_t;
110 * Return true if the path is absolute
112 #if defined(WINNT_NATIVE)
113 # define ABSOLUTEP(p) ((p)[0] == '/' || \
114 (Isalpha((p)[0]) && (p)[1] == ':'))
115 #elif defined(__CYGWIN__)
116 # define ABSOLUTEP(p) ((p)[0] == '/' || \
117 (Isalpha((p)[0]) && (p)[1] == ':' && \
118 ((p)[2] == '\0' || (p)[2] == '/')))
119 #else /* !WINNT_NATIVE && !__CYGWIN__ */
120 # define ABSOLUTEP(p) (*(p) == '/')
121 #endif /* WINNT_NATIVE || __CYGWIN__ */
124 * Fundamental definitions which may vary from system to system.
126 * BUFSIZE The i/o buffering size; also limits word size
127 * MAILINTVL How often to mailcheck; more often is more expensive
132 # define BUFSIZE 4096 /* buffer size should be no less than this */
135 # define BUFSIZE 4096
138 #define FORKSLEEP 10 /* delay loop on non-interactive fork failure */
139 #define MAILINTVL 600 /* 10 minutes */
142 # define INBUFSIZE 2*BUFSIZE /* Num input characters on the command line */
143 #endif /* INBUFSIZE */
147 * What our builtin echo looks like
152 #define BOTH_ECHO (BSD_ECHO|SYSV_ECHO)
156 # define ECHO_STYLE SYSV_ECHO
157 # else /* SYSVREL == 0 */
158 # define ECHO_STYLE BSD_ECHO
159 # endif /* SYSVREL */
160 #endif /* ECHO_STYLE */
163 * The shell moves std in/out/diag and the old std input away from units
164 * 0, 1, and 2 so that it is easy to set up these standards for invoked
167 #define FSHTTY 15 /* /dev/tty when manip pgrps */
168 #define FSHIN 16 /* Preferred desc for shell input */
169 #define FSHOUT 17 /* ... shell output */
170 #define FSHDIAG 18 /* ... shell diagnostics */
171 #define FOLDSTD 19 /* ... old std input */
174 #define xexit(n) done(n)
178 # define word word_t /* sys/types.h defines word.. bad move! */
181 #include <sys/types.h>
188 * Path separator in environment variables
191 # if defined(__EMX__) || defined(WINNT_NATIVE)
195 # endif /* __EMX__ || WINNT_NATIVE */
196 #endif /* !PATHSEP */
198 #if defined(__HP_CXD_SPP) && !defined(__hpux)
199 # include <sys/cnx_stat.h>
201 # define fstat fstat64
202 # define lstat lstat64
203 #endif /* __HP_CXD_SPP && !__hpux */
206 * This macro compares the st_dev field of struct stat. On aix on ibmESA
207 * st_dev is a structure, so comparison does not work.
209 #ifndef DEV_DEV_COMPARE
210 # define DEV_DEV_COMPARE(x,y) ((x) == (y))
211 #endif /* DEV_DEV_COMPARE */
214 # include <sys/procstats.h>
215 #endif /* _SEQUENT_ */
216 #if (defined(POSIX) || SYSVREL > 0) && !defined(WINNT_NATIVE)
217 # include <sys/times.h>
218 #endif /* (POSIX || SYSVREL > 0) && !WINNT_NATIVE */
225 #if !defined(_MINIX) && !defined(_VMS_POSIX) && !defined(WINNT_NATIVE) && !defined(__MVS__)
226 # include <sys/param.h>
227 #endif /* !_MINIX && !_VMS_POSIX && !WINNT_NATIVE && !__MVS__ */
228 #include <sys/stat.h>
230 #if defined(BSDTIMES) || defined(BSDLIMIT)
231 # include <sys/time.h>
232 # if SYSVREL>3 && !defined(SCO) && !defined(sgi) && !defined(SNI) && !defined(sun) && !(defined(__alpha) && defined(__osf__)) && !defined(_SX) && !defined(__MVS__)
233 # include "/usr/ucbinclude/sys/resource.h"
236 # define sysrusage cvxrusage
237 # include <sys/sysinfo.h>
239 # define sysrusage rusage
240 # include <sys/resource.h>
242 # endif /* SYSVREL>3 */
243 #endif /* BSDTIMES */
254 # include <termios.h>
259 # undef TIOCGLTC /* we don't need those, since POSIX has them */
262 # define CSWTCH _POSIX_VDISABLE /* So job control works */
263 # endif /* SYSVREL > 3 */
265 #endif /* WINNT_NATIVE */
268 # include <sys/ttold.h>
269 #endif /* sonyrisc */
271 #if defined(POSIX) && !defined(WINNT_NATIVE)
273 * We should be using setpgid and setpgid
274 * by now, but in some systems we use the
277 # if !defined(__APPLE__)
278 # define getpgrp __getpgrp
279 # define setpgrp __setpgrp
286 * the gcc+protoize version of <stdlib.h>
287 * redefines malloc(), so we define the following
290 # if defined(SYSMALLOC) || defined(linux) || defined(sgi) || defined(_OSD_POSIX)
291 # define NO_FIX_MALLOC
294 # define _GNU_STDLIB_H
295 # define malloc __malloc
297 # define calloc __calloc
298 # define realloc __realloc
304 # endif /* linux || sgi */
306 #endif /* POSIX && !WINNT_NATIVE */
308 #if SYSVREL > 0 || defined(_IBMR2) || defined(_MINIX) || defined(linux)
309 # if !defined(pyr) && !defined(stellar)
312 # define HZ CLOCKS_PER_SEC
314 # endif /* !pyr && !stellar */
315 #endif /* SYSVREL > 0 || _IBMR2 */
317 /* In the following ifdef the DECOSF1 has been commented so that later
318 * versions of DECOSF1 will get TIOCGWINSZ. This might break older versions...
320 #if !((defined(SUNOS4) || defined(_MINIX) /* || defined(DECOSF1) */) && defined(TERMIO))
321 # if !defined(COHERENT) && !defined(_VMS_POSIX) && !defined(WINNT_NATIVE)
322 # include <sys/ioctl.h>
326 #if (defined(__DGUX__) && defined(POSIX)) || defined(DGUX)
328 #define CSWTCH _POSIX_VDISABLE
331 #if (!defined(FIOCLEX) && defined(SUNOS4)) || ((SYSVREL == 4) && !defined(_SEQUENT_) && !defined(SCO) && !defined(_SX)) && !defined(__MVS__)
332 # include <sys/filio.h>
333 #endif /* (!FIOCLEX && SUNOS4) || (SYSVREL == 4 && !_SEQUENT_ && !SCO && !_SX ) */
335 #if !defined(_MINIX) && !defined(COHERENT) && !defined(supermax) && !defined(WINNT_NATIVE) && !defined(IRIS4D)
336 # include <sys/file.h>
337 #endif /* !_MINIX && !COHERENT && !supermax && !WINNT_NATIVE && !defined(IRIS4D) */
339 #if !defined(O_RDONLY) || !defined(O_NDELAY)
343 # define O_LARGEFILE 0
350 #if __STDC__ || defined(FUNCPROTO)
354 # include "mi.varargs.h"
356 # include <varargs.h>
366 # include <sys/dir.h>
368 # define dirent direct
370 #if defined(hpux) || defined(sgi) || defined(OREO) || defined(COHERENT)
371 # include <stdio.h> /* So the fgetpwent() prototypes work */
372 #endif /* hpux || sgi || OREO || COHERENT */
376 #endif /* WINNT_NATIVE */
379 #endif /* PW_SHADOW */
383 #if defined(BSD) && !defined(POSIX)
384 # include <strings.h>
385 # define strchr(a, b) index(a, b)
386 # define strrchr(a, b) rindex(a, b)
392 * IRIX-5.0 has <sys/cdefs.h>, but most system include files do not
393 * include it yet, so we include it here
395 #if defined(sgi) && SYSVREL > 3
396 # include <sys/cdefs.h>
397 #endif /* sgi && SYSVREL > 3 */
401 # undef MAXHOSTNAMELEN /* Busted headers? */
404 # include <netinet/in.h>
405 # include <arpa/inet.h>
406 # include <sys/socket.h>
407 # if (defined(_SS_SIZE) || defined(_SS_MAXSIZE)) && !defined(NO_SS_FAMILY)
408 # if !defined(__APPLE__) /* Damnit, where is getnameinfo() folks? */
412 # endif /* __APPLE__ */
414 # include <sys/uio.h> /* For struct iovec */
415 #endif /* REMOTEHOST */
418 * ANSIisms... These must be *after* the system include and
419 * *before* our includes, so that BSDreno has time to define __P
423 # if __STDC__ || defined(FUNCPROTO)
430 # if !defined(__STDC__)
433 # define volatile /* Apollo 'c' extensions need this */
441 /* exit normally, allowing purify to trace leaks */
446 * If your compiler complains, then you can either
447 * throw it away and get gcc or, use the following define
448 * and get rid of the typedef.
449 * [The 4.2/3BSD vax compiler does not like that]
450 * Both MULTIFLOW and PCC compilers exhbit this bug. -- sterling@netcom.com
452 # if (defined(vax) || defined(uts) || defined(MULTIFLOW) || defined(PCC)) && !defined(__GNUC__)
454 # else /* !((vax || uts || MULTIFLOW || PCC) && !__GNUC__) */
456 # endif /* (vax || uts || MULTIFLOW || PCC) && !__GNUC__ */
470 #include "sh.types.h"
474 extern pid_t getpgrp __P((int));
476 # if (defined(BSD) && !defined(BSD4_4)) || defined(SUNOS4) || defined(IRIS4D) || defined(DGUX)
477 extern pid_t getpgrp __P((int));
478 # else /* !(BSD || SUNOS4 || IRIS4D || DGUX) */
479 extern pid_t getpgrp __P((void));
480 # endif /* BSD || SUNOS4 || IRISD || DGUX */
482 extern pid_t setpgrp __P((pid_t, pid_t));
483 #endif /* !WINNT_NATIVE */
485 typedef sigret_t (*signalfun_t) __P((int));
488 typedef ptr_t memalign_t;
491 char am_char, *am_char_p;
492 short am_short, *am_short_p;
493 int am_int, *am_int_p;
494 long am_long, *am_long_p;
495 float am_float, *am_float_p;
496 double am_double, *am_double_p;
499 # define malloc lint_malloc
500 # define free lint_free
501 # define realloc lint_realloc
502 # define calloc lint_calloc
506 extern memalign_t DebugMalloc __P((unsigned, char *, int));
507 extern memalign_t DebugRealloc __P((ptr_t, unsigned, char *, int));
508 extern memalign_t DebugCalloc __P((unsigned, unsigned, char *, int));
509 extern void DebugFree __P((ptr_t, char *, int));
510 # define xmalloc(i) DebugMalloc(i, __FILE__, __LINE__)
511 # define xrealloc(p, i)((p) ? DebugRealloc(p, i, __FILE__, __LINE__) : \
512 DebugMalloc(i, __FILE__, __LINE__))
513 # define xcalloc(n, s) DebugCalloc(n, s, __FILE__, __LINE__)
514 # define xfree(p) if (p) DebugFree(p, __FILE__, __LINE__)
517 # define xmalloc(i) smalloc(i)
518 # define xrealloc(p, i) srealloc(p, i)
519 # define xcalloc(n, s) scalloc(n, s)
520 # define xfree(p) sfree(p)
522 # define xmalloc(i) malloc(i)
523 # define xrealloc(p, i) realloc(p, i)
524 # define xcalloc(n, s) calloc(n, s)
525 # define xfree(p) free(p)
526 # endif /* SYSMALLOC */
533 #include "pathnames.h"
539 * Bill Joy, UC Berkeley
540 * October, 1978; May 1980
542 * Jim Kulp, IIASA, Laxenburg Austria
546 #if !defined(MAXNAMLEN) && defined(_D_NAME_MAX)
547 # define MAXNAMLEN _D_NAME_MAX
548 #endif /* MAXNAMLEN */
556 #endif /* REMOTEHOST */
558 #ifndef MAXHOSTNAMELEN
559 # if defined(SCO) && (SYSVREL > 3)
560 # include <sys/socket.h>
562 # define MAXHOSTNAMELEN 256
564 #endif /* MAXHOSTNAMELEN */
568 #define eq(a, b) (Strcmp(a, b) == 0)
570 /* globone() flags */
571 #define G_ERROR 0 /* default action: error if multiple words */
572 #define G_IGNORE 1 /* ignore the rest of the words */
573 #define G_APPEND 2 /* make a sentence by cat'ing the words */
578 EXTERN bool chkstop IZERO; /* Warned of stopped jobs... allow exit */
580 #if (defined(FIOCLEX) && defined(FIONCLEX)) || defined(F_SETFD)
581 # define CLOSE_ON_EXEC
583 EXTERN bool didcch IZERO; /* Have closed unused fd's for child */
584 #endif /* (FIOCLEX && FIONCLEX) || F_SETFD */
586 EXTERN bool didfds IZERO; /* Have setup i/o fd's for child */
587 EXTERN bool doneinp IZERO; /* EOF indicator after reset from readc */
588 EXTERN bool exiterr IZERO; /* Exit if error or non-zero exit status */
589 EXTERN bool child IZERO; /* Child shell ... errors cause exit */
590 EXTERN bool haderr IZERO; /* Reset was because of an error */
591 EXTERN bool intty IZERO; /* Input is a tty */
592 EXTERN bool intact IZERO; /* We are interactive... therefore prompt */
593 EXTERN bool justpr IZERO; /* Just print because of :p hist mod */
594 EXTERN bool loginsh IZERO; /* We are a loginsh -> .login/.logout */
595 EXTERN bool neednote IZERO; /* Need to pnotify() */
596 EXTERN bool noexec IZERO; /* Don't execute, just syntax check */
597 EXTERN bool pjobs IZERO; /* want to print jobs if interrupted */
598 EXTERN bool setintr IZERO; /* Set interrupts on/off -> Wait intr... */
599 EXTERN bool timflg IZERO; /* Time the next waited for command */
600 EXTERN bool havhash IZERO; /* path hashing is available */
601 EXTERN bool editing IZERO; /* doing filename expansion and line editing */
602 EXTERN bool noediting IZERO; /* initial $term defaulted to noedit */
603 EXTERN bool bslash_quote IZERO;/* PWP: tcsh-style quoting? (in sh.c) */
604 EXTERN bool isoutatty IZERO; /* is SHOUT a tty */
605 EXTERN bool isdiagatty IZERO;/* is SHDIAG a tty */
606 EXTERN bool is1atty IZERO; /* is file descriptor 1 a tty (didfds mode) */
607 EXTERN bool is2atty IZERO; /* is file descriptor 2 a tty (didfds mode) */
608 EXTERN bool arun IZERO; /* Currently running multi-line-aliases */
609 EXTERN int implicit_cd IZERO;/* implicit cd enabled?(1=enabled,2=verbose) */
610 EXTERN bool inheredoc IZERO; /* Currently parsing a heredoc */
611 EXTERN bool windowchg IZERO; /* We received a window change event */
616 EXTERN Char *arginp IZERO; /* Argument input for sh -c and internal `xx` */
617 EXTERN int onelflg IZERO; /* 2 -> need line for -t, 1 -> exit on read */
618 extern Char *ffile; /* Name of shell file for $0 */
619 extern bool dolzero; /* if $?0 should return true... */
621 extern char *seterr; /* Error message from scanner/parser */
622 #if !defined(BSD4_4) && !defined(__linux__)
623 extern int errno; /* Error from C library routines */
626 EXTERN Char *shtemp IZERO; /* Temp name for << shell files in /tmp */
629 EXTERN struct timeval time0; /* Time at which the shell started */
630 EXTERN struct sysrusage ru0;
633 EXTERN timeval_t time0; /* time at which shell started */
634 EXTERN struct process_stats ru0;
635 # else /* _SEQUENT_ */
637 EXTERN time_t time0; /* time at which shell started */
639 EXTERN clock_t time0; /* time at which shell started */
640 EXTERN clock_t clk_tck;
642 EXTERN struct tms shtimes; /* shell and child times for process timing */
643 # endif /* _SEQUENT_ */
644 EXTERN long seconds0;
645 #endif /* BSDTIMES */
648 # define HZ 100 /* for division into seconds */
654 EXTERN Char *doldol; /* Character pid for $$ */
655 EXTERN int backpid; /* pid of the last background job */
658 * Ideally these should be uid_t, gid_t, pid_t. I cannot do that right now
659 * cause pid's could be unsigned and that would break our -1 flag, and
660 * uid_t and gid_t are not defined in all the systems so I would have to
661 * make special cases for them. In the future...
663 EXTERN int uid, euid, /* Invokers real and effective */
664 gid, egid; /* User and group ids */
665 EXTERN int opgrp, /* Initial pgrp and tty pgrp */
666 shpgrp, /* Pgrp of shell */
667 tpgrp; /* Terminal process group */
668 /* If tpgrp is -1, leave tty alone! */
670 EXTERN Char PromptBuf[INBUFSIZE*2]; /* buffer for the actual printed prompt.
671 * this must be large enough to contain
672 * the input line and the prompt, in
673 * case a correction occurred...
675 EXTERN Char RPromptBuf[INBUFSIZE]; /* buffer for right-hand side prompt */
678 * To be able to redirect i/o for builtins easily, the shell moves the i/o
679 * descriptors it uses away from 0,1,2.
680 * Ideally these should be in units which are closed across exec's
681 * (this saves work) but for version 6, this is not usually possible.
682 * The desired initial values for these descriptors are defined in
685 EXTERN int SHIN IZERO; /* Current shell input (script) */
686 EXTERN int SHOUT IZERO; /* Shell output */
687 EXTERN int SHDIAG IZERO; /* Diagnostic output... shell errs go here */
688 EXTERN int OLDSTD IZERO; /* Old standard input (def for cmds) */
691 #if SYSVREL == 4 && defined(_UTS)
693 * From: fadden@uts.amdahl.com (Andy McFadden)
694 * we need sigsetjmp for UTS4, but not UTS2.1
702 * Errors in scanning and parsing set up an error message to be printed
703 * at the end and complete. Other errors always cause a reset.
704 * Because of source commands and .cshrc we need nested error catches.
707 #ifdef NO_STRUCT_ASSIGNMENT
710 typedef sigjmp_buf jmp_buf_t;
711 /* bugfix by Jak Kirman @ Brown U.: remove the (void) cast here, see sh.c */
712 # define setexit() sigsetjmp(reslab)
713 # define reset() siglongjmp(reslab, 1)
715 typedef jmp_buf jmp_buf_t;
716 /* bugfix by Jak Kirman @ Brown U.: remove the (void) cast here, see sh.c */
717 # define setexit() setjmp(reslab)
718 # define reset() longjmp(reslab, 1)
720 # define getexit(a) (void) memmove((ptr_t)&(a), (ptr_t)&reslab, sizeof(reslab))
721 # define resexit(a) (void) memmove((ptr_t)&reslab, (ptr_t)&(a), sizeof(reslab))
723 # define cpybin(a, b) (void) memmove((ptr_t)&(a), (ptr_t)&(b), sizeof(Bin))
728 typedef struct { sigjmp_buf j; } jmp_buf_t;
729 # define setexit() sigsetjmp(reslab.j)
730 # define reset() siglongjmp(reslab.j, 1)
732 typedef struct { jmp_buf j; } jmp_buf_t;
733 # define setexit() setjmp(reslab.j)
734 # define reset() longjmp(reslab.j, 1)
737 # define getexit(a) (void) ((a) = reslab)
738 # define resexit(a) (void) (reslab = (a))
740 # define cpybin(a, b) (void) ((a) = (b))
742 #endif /* NO_STRUCT_ASSIGNMENT */
744 extern jmp_buf_t reslab;
746 EXTERN Char *gointr; /* Label for an onintr transfer */
748 extern signalfun_t parintr; /* Parents interrupt catch */
749 extern signalfun_t parterm; /* Parents terminate catch */
752 * Lexical definitions.
754 * All lexical space is allocated dynamically.
755 * The eighth/sixteenth bit of characters is used to prevent recognition,
756 * and eventually stripped.
761 # define QUOTE ((Char) 0100000)/* 16nth char bit used for 'ing */
762 # define TRIM 0077777 /* Mask to strip quote bit */
763 # define UNDER 0040000 /* Underline flag */
764 # define BOLD 0020000 /* Bold flag */
765 # define STANDOUT 0010000 /* Standout flag */
766 # define LITERAL 0004000 /* Literal character flag */
767 # define ATTRIBUTES 0074000 /* The bits used for attributes */
768 # define CHAR 0000377 /* Mask to mask out the character */
770 # define QUOTE ((Char) 0200) /* Eighth char bit used for 'ing */
771 # define TRIM 0177 /* Mask to strip quote bit */
772 # define UNDER 0000000 /* No extra bits to do both */
773 # define BOLD 0000000 /* Bold flag */
774 # define STANDOUT META /* Standout flag */
775 # define LITERAL 0000000 /* Literal character flag */
776 # define ATTRIBUTES 0200 /* The bits used for attributes */
777 # define CHAR 0000177 /* Mask to mask out the character */
780 EXTERN int AsciiOnly; /* If set only 7 bits expected in characters */
783 * Each level of input has a buffered input structure.
784 * There are one or more blocks of buffered input for each level,
785 * exactly one if the input is seekable and tell is available.
786 * In other cases, the shell buffers enough blocks to keep all loops
790 off_t Bfseekp; /* Seek pointer */
791 off_t Bfbobp; /* Seekp of beginning of buffers */
792 off_t Bfeobp; /* Seekp of end of buffers */
793 int Bfblocks; /* Number of buffer blocks */
794 Char **Bfbuf; /* The array of buffer blocks */
798 * This structure allows us to seek inside aliases
802 #define TCSH_I_SEEK 0 /* Invalid seek */
803 #define TCSH_A_SEEK 1 /* Alias seek */
804 #define TCSH_F_SEEK 2 /* File seek */
805 #define TCSH_E_SEEK 3 /* Eval seek */
810 #define f_seek fc._f_seek
811 #define c_seek fc._c_seek
815 extern int aret; /* Type of last char returned */
816 #define SEEKEQ(a, b) ((a)->type == (b)->type && \
817 (a)->f_seek == (b)->f_seek && \
818 (a)->a_seek == (b)->a_seek)
820 #define fseekp B.Bfseekp
821 #define fbobp B.Bfbobp
822 #define feobp B.Bfeobp
823 #define fblocks B.Bfblocks
827 * The shell finds commands in loops by reseeking the input
828 * For whiles, in particular, it reseeks to the beginning of the
829 * line the while was on; hence the while placement restrictions.
831 EXTERN struct Ain lineloc;
833 EXTERN bool cantell; /* Is current source tellable ? */
836 * Input lines are parsed into doubly linked circular
837 * lists of words of the following form.
841 struct wordent *prev;
842 struct wordent *next;
846 * During word building, both in the initial lexical phase and
847 * when expanding $ variable substitutions, expansion by `!' and `$'
848 * must be inhibited when reading ahead in routines which are themselves
849 * processing `!' and `$' expansion or after characters such as `\' or in
850 * quotations. The following flags are passed to the getC routines
851 * telling them which of these substitutions are appropriate for the
852 * next character to be returned.
856 #define DOALL DODOL|DOEXCL
859 * Labuf implements a general buffer for lookahead during lexical operations.
860 * Text which is to be placed in the input stream can be stuck here.
861 * We stick parsed ahead $ constructs during initial input,
862 * process id's from `$$', and modified variable values (from qualifiers
863 * during expansion in sh.dol.c) here.
870 * Each command is parsed to a tree of command structures and
871 * flags are set bottom up during this process, to be propagated down
872 * as needed during the semantics/exeuction pass (sh.sem.c).
875 unsigned char t_dtyp; /* Type of node */
876 #define NODE_COMMAND 1 /* t_dcom <t_dlef >t_drit */
877 #define NODE_PAREN 2 /* ( t_dspr ) <t_dlef >t_drit */
878 #define NODE_PIPE 3 /* t_dlef | t_drit */
879 #define NODE_LIST 4 /* t_dlef ; t_drit */
880 #define NODE_OR 5 /* t_dlef || t_drit */
881 #define NODE_AND 6 /* t_dlef && t_drit */
882 unsigned char t_nice; /* Nice value */
884 unsigned char t_systype; /* System environment */
886 unsigned long t_dflg; /* Flags, e.g. F_AMPERSAND|... */
887 /* save these when re-doing */
889 #define F_SAVE (F_NICE|F_TIME|F_NOHUP|F_HUP)
891 #define F_SAVE (F_NICE|F_TIME|F_NOHUP||F_HUP|F_VER)
893 #define F_AMPERSAND (1<<0) /* executes in background */
894 #define F_APPEND (1<<1) /* output is redirected >> */
895 #define F_PIPEIN (1<<2) /* input is a pipe */
896 #define F_PIPEOUT (1<<3) /* output is a pipe */
897 #define F_NOFORK (1<<4) /* don't fork, last ()ized cmd */
898 #define F_NOINTERRUPT (1<<5) /* should be immune from intr's */
900 #define F_STDERR (1<<7) /* redirect unit 2 with unit 1 */
901 #define F_OVERWRITE (1<<8) /* output was ! */
902 #define F_READ (1<<9) /* input redirection is << */
903 #define F_REPEAT (1<<10) /* reexec aft if, repeat,... */
904 #define F_NICE (1<<11) /* t_nice is meaningful */
905 #define F_NOHUP (1<<12) /* nohup this command */
906 #define F_TIME (1<<13) /* time this command */
907 #define F_BACKQ (1<<14) /* command is in `` */
908 #define F_HUP (1<<15) /* hup this command */
910 #define F_VER (1<<16) /* execute command under SYSTYPE */
913 Char *T_dlef; /* Input redirect word */
914 struct command *T_dcar; /* Left part of list/pipe */
917 Char *T_drit; /* Output redirect word */
918 struct command *T_dcdr; /* Right part of list/pipe */
920 #define t_dlef L.T_dlef
921 #define t_dcar L.T_dcar
922 #define t_drit R.T_drit
923 #define t_dcdr R.T_dcdr
924 Char **t_dcom; /* Command/argument vector */
925 struct command *t_dspr; /* Pointer to ()'d subtree */
930 * The keywords for the parser
953 * These are declared here because they want to be
954 * initialized in sh.init.c (to allow them to be made readonly)
957 #if defined(hpux) && defined(__STDC__) && !defined(__GNUC__)
958 /* Avoid hpux ansi mode spurious warnings */
959 typedef void (*bfunc_t) ();
961 typedef void (*bfunc_t) __P((Char **, struct command *));
962 #endif /* hpux && __STDC__ && !__GNUC__ */
964 extern struct biltins {
967 int minargs, maxargs;
971 extern struct biltins nt_bfunc[];
972 extern int nt_nbfunc;
973 #endif /* WINNT_NATIVE*/
982 * Structure defining the existing while/foreach loops at this
983 * source level. Loops are implemented by seeking back in the
984 * input. For foreach (fe), the word list is attached here.
986 EXTERN struct whyle {
987 struct Ain w_start; /* Point to restart loop */
988 struct Ain w_end; /* End of loop (0 if unknown) */
989 Char **w_fe, **w_fe0; /* Current/initial wordlist for fe */
990 Char *w_fename; /* Name for fe */
991 struct whyle *w_next; /* Next (more outer) loop */
997 * Aliases and variables are stored in AVL balanced binary trees.
999 EXTERN struct varent {
1000 Char **vec; /* Array of words which is the value */
1001 Char *v_name; /* Name of variable/alias */
1002 int v_flags; /* Flags */
1004 #define VAR_READONLY 1
1005 #define VAR_READWRITE 2
1006 #define VAR_NOGLOB 4
1007 #define VAR_FIRST 32
1009 struct varent *v_link[3]; /* The links, see below */
1010 int v_bal; /* Balance factor */
1011 } shvhed IZERO_STRUCT, aliases IZERO_STRUCT;
1013 #define v_left v_link[0]
1014 #define v_right v_link[1]
1015 #define v_parent v_link[2]
1017 #define adrof(v) adrof1(v, &shvhed)
1018 #define varval(v) value1(v, &shvhed)
1021 * The following are for interfacing redo substitution in
1022 * aliases to the lexical routines.
1024 EXTERN struct wordent *alhistp IZERO_STRUCT;/* Argument list (first) */
1025 EXTERN struct wordent *alhistt IZERO_STRUCT;/* Node after last in arg list */
1026 EXTERN Char **alvec IZERO_STRUCT,
1027 *alvecp IZERO_STRUCT;/* The (remnants of) alias vector */
1030 * Filename/command name expansion variables
1032 EXTERN int gflag; /* After tglob -> is globbing needed? */
1034 #define MAXVARLEN 30 /* Maximum number of char in a variable name */
1038 #endif /* __CYGWIN__ */
1041 # define MAXPATHLEN 2048
1042 #endif /* MAXPATHLEN */
1045 # define MAXNAMLEN 512
1046 #endif /* MAXNAMLEN */
1052 extern struct limits {
1058 #endif /* !HAVENOLIMIT */
1061 * Variables for filename expansion
1063 extern Char **gargv; /* Pointer to the (stack) arglist */
1064 extern int gargc; /* Number args in gargv */
1067 * Variables for command expansion.
1069 extern Char **pargv; /* Pointer to the argv list space */
1070 EXTERN Char *pargs; /* Pointer to start current word */
1071 EXTERN long pnleft; /* Number of chars left in pargs */
1072 EXTERN Char *pargcp; /* Current index into pargs */
1077 * Each history list entry contains an embedded wordlist
1078 * from the scanner, a number for the event, and a reference count
1079 * to aid in discarding old entries.
1081 * Essentially "invisible" entries are put on the history list
1082 * when history substitution includes modifiers, and thrown away
1083 * at the next discarding since their event numbers are very negative.
1085 EXTERN struct Hist {
1086 struct wordent Hlex;
1092 } Histlist IZERO_STRUCT;
1094 EXTERN struct wordent paraml; /* Current lexical word list */
1095 EXTERN int eventno; /* Next events number */
1096 EXTERN int lastev; /* Last event reference (default) */
1098 EXTERN Char HIST; /* history invocation character */
1099 EXTERN Char HISTSUB; /* auto-substitute character */
1100 EXTERN Char PRCH; /* Prompt symbol for regular users */
1101 EXTERN Char PRCHROOT; /* Prompt symbol for root */
1104 * For operating systems with single case filenames (OS/2)
1106 #ifdef CASE_INSENSITIVE
1107 # define samecase(x) (isupper((unsigned char)(x)) ? \
1108 tolower((unsigned char)(x)) : (x))
1110 # define samecase(x) (x)
1111 #endif /* CASE_INSENSITIVE */
1116 #ifndef SHORT_STRINGS
1117 #define Strchr(a, b) strchr(a, b)
1118 #define Strrchr(a, b) strrchr(a, b)
1119 #define Strcat(a, b) strcat(a, b)
1120 #define Strncat(a, b, c) strncat(a, b, c)
1121 #define Strcpy(a, b) strcpy(a, b)
1122 #define Strncpy(a, b, c) strncpy(a, b, c)
1123 #define Strlen(a) strlen(a)
1124 #define Strcmp(a, b) strcmp(a, b)
1125 #define Strncmp(a, b, c) strncmp(a, b, c)
1126 #define Strcasecmp(a, b) strcasecmp(a, b)
1128 #define Strspl(a, b) strspl(a, b)
1129 #define Strsave(a) strsave(a)
1130 #define Strend(a) strend(a)
1131 #define Strstr(a, b) strstr(a, b)
1133 #define str2short(a) (a)
1134 #define blk2short(a) saveblk(a)
1135 #define short2blk(a) saveblk(a)
1136 #define short2str(a) strip(a)
1138 #define Strchr(a, b) s_strchr(a, b)
1139 #define Strrchr(a, b) s_strrchr(a, b)
1140 #define Strcat(a, b) s_strcat(a, b)
1141 #define Strncat(a, b, c) s_strncat(a, b, c)
1142 #define Strcpy(a, b) s_strcpy(a, b)
1143 #define Strncpy(a, b, c) s_strncpy(a, b, c)
1144 #define Strlen(a) s_strlen(a)
1145 #define Strcmp(a, b) s_strcmp(a, b)
1146 #define Strncmp(a, b, c) s_strncmp(a, b, c)
1147 #define Strcasecmp(a, b) s_strcasecmp(a, b)
1149 #define Strspl(a, b) s_strspl(a, b)
1150 #define Strsave(a) s_strsave(a)
1151 #define Strend(a) s_strend(a)
1152 #define Strstr(a, b) s_strstr(a, b)
1156 * setname is a macro to save space (see sh.err.c)
1160 #define setname(a) (bname = (a))
1165 EXTERN Char *Vexpath;
1169 EXTERN Char **evalvec;
1172 extern struct mesg {
1173 char *iname; /* name from /usr/include */
1174 char *pname; /* print name */
1177 /* word_chars is set by default to WORD_CHARS but can be overridden by
1178 the worchars variable--if unset, reverts to WORD_CHARS */
1180 EXTERN Char *word_chars;
1182 #define WORD_CHARS "*?_-.[]~=" /* default chars besides alnums in words */
1184 EXTERN Char *STR_SHELLPATH;
1187 EXTERN Char *STR_BSHELL;
1189 EXTERN Char *STR_WORD_CHARS;
1190 EXTERN Char **STR_environ IZERO;
1192 extern int dont_free; /* Tell free that we are in danger if we free */
1194 extern Char *INVPTR;
1195 extern Char **INVPPTR;
1197 extern char *progname;
1201 #include "sh.decls.h"
1204 * To print system call errors...
1210 # ifdef NEEDstrerror
1211 extern char *sys_errlist[];
1213 extern int errno, sys_nerr;
1214 # endif /* !linux */
1217 #ifndef WINNT_NATIVE
1218 # ifdef NLS_CATALOGS
1220 # include <locale.h>
1222 # include <localeinfo.h> /* Has this changed ? */
1224 # include <features.h>
1227 /* Who stole my nl_types.h? :-(
1228 * All this stuff is in the man pages, but nowhere else?
1229 * This does not link right now...
1231 typedef void *nl_catd;
1232 extern const char * catgets __P((nl_catd, int, int, const char *));
1233 nl_catd catopen __P((const char *, int));
1234 int catclose __P((nl_catd));
1237 # define gettxt gettxt_ds
1239 # include <nl_types.h>
1244 # ifndef MCLoadBySet
1245 # define MCLoadBySet 0
1247 EXTERN nl_catd catd;
1248 # define CGETS(b, c, d) catgets(catd, b, c, d)
1249 # define CSAVS(b, c, d) strsave(CGETS(b, c, d))
1251 # define CGETS(b, c, d) d
1252 # define CSAVS(b, c, d) d
1254 #else /* WINNT_NATIVE */
1255 # define CGETS(b, c, d) nt_cgets( b, c, d)
1256 # define CSAVS(b, c, d) strsave(CGETS(b, c, d))
1257 #endif /* WINNT_NATIVE */
1264 * Since on some machines characters are unsigned, and the signed
1265 * keyword is not universally implemented, we treat all characters
1266 * as unsigned and sign extend them where we need.
1268 #define SIGN_EXTEND_CHAR(a) (((a) & 0x80) ? ((a) | ~0x7f) : (a))