sh.h revision 65b0c20e9bbaf87a200ce20a4decf18585e61a25
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley Software License Agreement
* specifies the terms and conditions for redistribution.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h> /* MB_xxx, mbxxx(), wcxxx() etc. */
#include <limits.h>
#include <sys/ucontext.h>
#include <errno.h>
#include <setjmp.h>
#include <sys/resource.h>
#include "sh.local.h"
#include "sh.char.h"
/*
* MAXHOSTNAMELEN is defined in param.h under SunOS
*/
#define MAXHOSTNAMELEN 64
#ifdef MBCHAR
#if !defined(MB_LEN_MAX) || !defined(MB_CUR_MAX)
#endif
#else
#if !defined(MB_LEN_MAX)
#define MB_LEN_MAX 1
#endif
#if !defined(MB_CUR_MAX)
#define MB_CUR_MAX 1
#endif
#endif
#ifndef MBCHAR /* Let's replace the ANSI functions with our own macro
* for efficiency!
*/
#endif /* !MBCHAR */
/*
* C shell
*
* Bill Joy, UC Berkeley
* October, 1978; May 1980
*
* Jim Kulp, IIASA, Laxenburg Austria
* April, 1980
*/
/*
* If we are setting the $cwd variable becuz we did a
* cd, chdir, pushd, popd command, then set didchdir to
* 1. This prevents globbing down when setting $cwd.
* However, if the user set $cwd, we want the globbing
* done; so, didchdir would be equal to 0 in that case.
*/
int didchdir;
typedef char bool;
/*
* tchar (Tagged CHARacter) is a place holder to keep a QUOTE bit and
* a character.
* For European language handling, lower 8 bits of tchar is used
* to store a character. For other languages, especially Asian, 16 bits
* are used to store a character.
* Following typedef's assume short int is a 16-bit entity and long int is
* a 32-bit entity.
* The QUOTE bit tells whether the character is subject to further
* interpretation such as history substitution, file mathing, command
* subsitution. TRIM is a mask to strip off the QUOTE bit.
*/
#ifdef MBCHAR /* For multibyte character handling. */
typedef long int tchar;
#define QUOTE 0x80000000
#define TRIM 0x7fffffff
#else /* !MBCHAR */ /* European language requires only 8 bits. */
typedef unsigned short int tchar;
#define QUOTE 0x8000
#define TRIM 0x00ff
#endif /* !MBCHAR */
/*
* Global flags
*/
bool chkstop; /* Warned of stopped jobs... allow exit */
bool didfds; /* Have setup i/o fd's for child */
bool doneinp; /* EOF indicator after reset from readc */
bool exiterr; /* Exit if error or non-zero exit status */
bool child; /* Child shell ... errors cause exit */
bool haderr; /* Reset was because of an error */
bool intty; /* Input is a tty */
bool cflg; /* invoked with -c option */
bool intact; /* We are interactive... therefore prompt */
bool justpr; /* Just print because of :p hist mod */
bool loginsh; /* We are a loginsh -> .login/.logout */
bool neednote; /* Need to pnotify() */
bool noexec; /* Don't execute, just syntax check */
bool pjobs; /* want to print jobs if interrupted */
bool pfcshflag; /* set to 0 for pfcsh */
bool timflg; /* Time the next waited for command */
bool havhash; /* path hashing is available */
bool havhash2; /* cdpath hashing is available */
#ifdef FILEC
bool filec; /* doing filename expansion */
#endif
/*
* Global i/o info
*/
int onelflg; /* 2 -> need line for -t, 1 -> exit on read */
/*
* Miscellany
*/
int uid; /* Invokers uid */
int shpgrp; /* Pgrp of shell */
int tpgrp; /* Terminal process group */
/* If tpgrp is -1, leave tty alone! */
int opgrp; /* Initial pgrp and tty pgrp */
int oldisc; /* Initial line discipline or -1 */
/*
* These are declared here because they want to be
* initialized in sh.init.c (to allow them to be made readonly)
*/
extern struct biltins {
int (*bfunct)();
} bfunc[];
extern int nbfunc;
extern struct srch {
short s_value;
} srchn[];
extern int nsrchn;
/*
* To be able to redirect i/o for builtins easily, the shell moves the i/o
* descriptors it uses away from 0,1,2.
* Ideally these should be in units which are closed across exec's
* (this saves work) but for version 6, this is not usually possible.
* The desired initial values for these descriptors are defined in
* sh.local.h.
*/
short SHIN; /* Current shell input (script) */
short SHOUT; /* Shell output */
short SHDIAG; /* Diagnostic output... shell errs go here */
short OLDSTD; /* Old standard input (def for cmds) */
/*
* Error control
*
* Errors in scanning and parsing set up an error message to be printed
* at the end and complete. Other errors always cause a reset.
* Because of source commands and .cshrc we need nested error catches.
*/
/* Should use structure assignment here */
void (*parintr)(); /* Parents interrupt catch */
void (*parterm)(); /* Parents terminate catch */
/*
* Each level of input has a buffered input structure.
* There are one or more blocks of buffered input for each level,
* exactly one if the input is seekable and tell is available.
* In other cases, the shell buffers enough blocks to keep all loops
* in the buffer.
*/
struct Bin {
short Bfblocks; /* Number of buffer blocks */
} B;
#ifndef btell
#endif
/*
* The shell finds commands in loops by reseeking the input
* For whiles, in particular, it reseeks to the beginning of the
* line the while was on; hence the while placement restrictions.
*/
#ifdef TELL
bool cantell; /* Is current source tellable ? */
#endif
/*
* Input lines are parsed into doubly linked circular
* lists of words of the following form.
*/
struct wordent {
};
/*
* During word building, both in the initial lexical phase and
* when expanding $ variable substitutions, expansion by `!' and `$'
* must be inhibited when reading ahead in routines which are themselves
* processing `!' and `$' expansion or after characters such as `\' or in
* quotations. The following flags are passed to the getC routines
* telling them which of these substitutions are appropriate for the
* next character to be returned.
*/
#define DODOL 1
#define DOEXCL 2
/*
* Labuf implements a general buffer for lookahead during lexical operations.
* Text which is to be placed in the input stream can be stuck here.
* We stick parsed ahead $ constructs during initial input,
* process id's from `$$', and modified variable values (from qualifiers
* during expansion in sh.dol.c) here.
*/
/*
* Parser structure
*
* Each command is parsed to a tree of command structures and
* flags are set bottom up during this process, to be propagated down
*/
struct command {
short t_dtyp; /* Type of node */
short t_dflg; /* Flags, e.g. FAND|... */
union {
} L;
union {
} R;
char *cfname; /* char pathname for execv */
char **cargs; /* char arg vec for execv */
short t_nice;
};
/* spare */
/*
* The keywords for the parser
*/
#define ZBREAK 0
#define ZBRKSW 1
#define ZCASE 2
#define ZDEFAULT 3
#define ZELSE 4
#define ZEND 5
#define ZENDIF 6
#define ZENDSW 7
#define ZEXIT 8
#define ZFOREACH 9
#define ZGOTO 10
#define ZIF 11
#define ZLABEL 12
#define ZLET 13
#define ZSET 14
#define ZSWITCH 15
#define ZTEST 16
#define ZTHEN 17
#define ZWHILE 18
/*
* source level. Loops are implemented by seeking back in the
* input. For foreach (fe), the word list is attached here.
*/
struct whyle {
} *whyles;
/*
* Variable structure
*
* Aliases and variables are stored in AVL balanced binary trees.
*/
struct varent {
int v_bal; /* Balance factor */
/*
* MAX_VAR_LEN - maximum variable name defined by csh man page to be 20
*/
#define MAX_VAR_LEN 20
/*
* MAX_VREF_LEN - maximum variable reference $name[...]
* it can be as big as a csh word, which is 1024
*/
#define MAX_VREF_LEN 1024
/*
* The following are for interfacing redo substitution in
* aliases to the lexical routines.
*/
/*
*/
short gflag; /* After tglob -> is globbing needed? */
/*
* A reasonable limit on number of arguments would seem to be
* the maximum number of characters in an arg list / 6.
*
* XXX: With the new VM system, NCARGS has become enormous, making
* it impractical to allocate arrays with NCARGS / 6 entries on
* the stack. The proper fix is to revamp code elsewhere (in
* command line arguments. In the meantime, we simply fall back
* on using the old value of NCARGS.
*/
#ifdef notyet
#else /* notyet */
#endif /* notyet */
/*
* Variables for filename expansion
*/
long gargc; /* Number args in gargv */
long gnleft;
/*
* Variables for command expansion.
*/
long pargc; /* Count of arguments in pargv */
long pnleft; /* Number of chars left in pargs */
/*
* History list
*
* Each history list entry contains an embedded wordlist
* from the scanner, a number for the event, and a reference count
* to aid in discarding old entries.
*
* Essentially "invisible" entries are put on the history list
* when history substitution includes modifiers, and thrown away
* at the next discarding since their event numbers are very negative.
*/
struct Hist {
int Hnum;
int Href;
} Histlist;
int eventno; /* Next events number */
int lastev; /* Last event reference (default) */
extern void xfree(void *);
extern void bferr(char *) __NORETURN;
extern void error() __NORETURN;
extern void exitstat(void) __NORETURN;
extern char **blkspl_(char **, char **);
extern void pintr(void);
extern void pchild(void);
/*
* setname is a macro to copy the path in bname. (see sh.err.c)
* Here we are dynamically reallocating the bname to the new length
* to store the new path
*/
#define setname(a) { \
}
#ifdef VFORK
#endif
/* Conversion functions between char and tchar strings. */
char *tstostr(/* char * , tchar * */);
#ifndef NULL
#define NULL 0
#endif
/*
* Xhash is an array of HSHSIZ bits (HSHSIZ / 8 chars), which are used
* to hash execs. If it is allocated (havhash true), then to tell
* whether ``name'' is (possibly) present in the i'th component
* of the variable path, you look at the bit in xhash indexed by
* hash(hashname("name"), i). This is setup automatically
* after .login is executed, and recomputed whenever ``path'' is
* changed.
* The two part hash function is designed to let texec() call the
* more expensive hashname() only once and the simple hash() several
* times (once for each path component checked).
* Byte size is assumed to be 8.
*/
#define HSHMUL 243
/*
* The following two arrays are used for caching. xhash
* is for caching path variable and xhash2 is for cdpath
* variable.
*/
#ifdef VFORK
#endif