Annotation of coherent/b/bin/sh_B4_420/sh.h, revision 1.1

1.1     ! root        1: /*
        !             2:  * sh/sh.h
        !             3:  * Bourne shell.
        !             4:  * Header file.
        !             5:  */
        !             6: 
        !             7: #include <stdio.h>
        !             8: #include <setjmp.h>
        !             9: #include <string.h>
        !            10: 
        !            11: #define STRSIZE        2000                    /* Maximum length of single token */
        !            12: #define IALSIZE        8                       /* Initial argument list size */
        !            13: #define        DSTACKN 30                      /* Directory stack depth */
        !            14: #define NOTREACHED     return
        !            15: 
        !            16: /*
        !            17:  * Masks for looking up lextab.
        !            18:  */
        !            19: #define MNQUO  0001            /* Special in argument */
        !            20: #define MDQUO  0002            /* Special in double quotes */
        !            21: #define MHERE  0004            /* Special in here document */
        !            22: #define MRVAR  (MBVAR|MDIGI)           /* Valid in regular variable name */
        !            23: #define MSVAR  0010            /* Valid in special variable name */
        !            24: #define MDIGI  0020            /* Is an ascii digit */
        !            25: #define MBVAR  0040            /* Valid 1st char in regular var name */
        !            26: #define MNAME  0100            /* Does not start a name */
        !            27: #define MGLOB  0200            /* Must call glob */
        !            28: 
        !            29: /*
        !            30:  * Determine if a character is a member of the given class.
        !            31:  * (This depends of the fact that EOF == -1).
        !            32:  */
        !            33: #define class(c, m)    (c>=EOF && c<=0177 && (lextab[1+c]&m))
        !            34: 
        !            35: /*
        !            36:  * Types of nodes.
        !            37:  */
        !            38: #define NNULL  0                       /* Null */
        !            39: #define NFOR   1                       /* For */
        !            40: #define NCASE  2                       /* Case */
        !            41: #define NWHILE 3                       /* While */
        !            42: #define NUNTIL 4                       /* Until */
        !            43: #define NIF    5                       /* If */
        !            44: #define NELSE  6                       /* Else */
        !            45: #define NCOMS  7                       /* Command sequence */
        !            46: #define NLIST  8                       /* Command list */
        !            47: #define NBACK  9                       /* Background process */
        !            48: #define NPIPE  10                      /* Pipe */
        !            49: #define NPARN  11                      /* New shell */
        !            50: #define NBRAC  12                      /* Command group */
        !            51: #define NANDF  13                      /* Logical and operator */
        !            52: #define NORF   14                      /* Logical or operator */
        !            53: #define NARGS  15                      /* Argument string */
        !            54: #define NIORS  16                      /* Redirection of io */
        !            55: #define NASSG  17                      /* Assignment keyword */
        !            56: #define NFOR2  18                      /* Second part for, in list scan */
        !            57: #define NCASE2 19                      /* Second part case, command */
        !            58: #define NCASE3 20                      /* Third part case, pattern */
        !            59: #define NCTRL  21                      /* Control statement in list */
        !            60: #define NRPIPE 22                      /* Named pipe for read */
        !            61: #define NWPIPE 23                      /* Named pipe for write */
        !            62: #define        NFUNC   24                      /* Shell function */
        !            63: #define        NRET    25                      /* Return */
        !            64: 
        !            65: /*
        !            66:  * Node.
        !            67:  */
        !            68: typedef        struct  node {
        !            69:        int     n_type;                 /* Type of node */
        !            70:        struct  node *n_next;           /* Pointer to next */
        !            71:        union {
        !            72:                struct  node *nu_auxp;  /* Auxiliary pointer */
        !            73:                char    *nu_strp;       /* Pointer to string */
        !            74:        } n_u;
        !            75: } NODE;
        !            76: #define        n_auxp  n_u.nu_auxp
        !            77: #define        n_strp  n_u.nu_strp
        !            78: 
        !            79: /*
        !            80:  * Flags in variables.
        !            81:  */
        !            82: #define VEXP   001                     /* Variable is exported */
        !            83: #define VRDO   002                     /* Read only */
        !            84: #define VSET   004                     /* Variable is used by shell */
        !            85: 
        !            86: /*
        !            87:  * Enviroment list and variable structure.
        !            88:  */
        !            89: typedef        struct  var {
        !            90:        int     v_flag;                 /* Flags */
        !            91:        struct  var *v_next;            /* Pointer to next entry */
        !            92:        char    *v_strp;                /* Pointer to string */
        !            93: } VAR;
        !            94: 
        !            95: /*
        !            96:  * Buffer structure.
        !            97:  */
        !            98: typedef        struct  buf {
        !            99:        struct  buf *b_next;            /* Pointer to next */
        !           100:        int     b_size;                 /* Size of buffer */
        !           101: } BUF;
        !           102: 
        !           103: /*
        !           104:  * Per executing command data structure.
        !           105:  * Used for break/continue.
        !           106:  */
        !           107: typedef        struct  con {
        !           108:        struct  con *c_next;            /* Pointer to next */
        !           109:        NODE    *c_node;                /* Node which created this control */
        !           110:        BUF     **c_bpp;                /* Current free buffer */
        !           111:        jmp_buf c_envl;                 /* Enviroment list */
        !           112: } CON;
        !           113: 
        !           114: /*
        !           115:  * Session types.
        !           116:  */
        !           117: #define SINIT  0       /* Initial session */
        !           118: #define SARGS  1       /* String */
        !           119: #define SARGV  2       /* Vector of strings */
        !           120: #define SFILE  3       /* File name */
        !           121: #define SSTR   4       /* Open stream */
        !           122: 
        !           123: /*
        !           124:  * Per session information structure.
        !           125:  */
        !           126: typedef struct ses {
        !           127:        struct  ses     *s_next;
        !           128:        int             s_type;
        !           129:        int             s_flag;
        !           130:        NODE            *s_node;
        !           131:        CON             *s_con;
        !           132:        BUF             **s_bpp;
        !           133:        jmp_buf         s_envl;
        !           134:        char            *s_strp;
        !           135:        char            **s_argv;
        !           136:        FILE            *s_ifp;
        !           137: } SES;
        !           138: 
        !           139: /*
        !           140:  * Session long jump codes
        !           141:  */
        !           142: #define RSET   0       /* Initial setjmp call */
        !           143: #define REOF   1       /* parse matched start */
        !           144: #define RCMD   2       /* parse matched command line */
        !           145: #define RERR   3       /* parse matched error */
        !           146: #define RINT   4       /* Interrupt recovery */
        !           147: #define RNOSBRK        5       /* no more memory from alloc */
        !           148: #define RSYSER 6       /* system returned -1 */
        !           149: #define RUABORT        7       /* user requested error abort */
        !           150: #define RUEXITS        8       /* user requested exit command */
        !           151: #define RBRKCON        9       /* break or continue beyond program */
        !           152: #define RNOWAY 10      /* Shell assertion failed */
        !           153: 
        !           154: /*
        !           155:  * Interrupt recovery and set contexts.
        !           156:  * Used to determine recovery action and default signals.
        !           157:  */
        !           158: #define IRDY   0       /* In session */
        !           159: #define        ILEX    1       /* Parse in progress */
        !           160: #define ICMD   2       /* Prior to next command execution */
        !           161: #define IEVAL  3       /* Command evaluation in progress */
        !           162: #define IBACK  4       /* Background process */
        !           163: #define IFORK  5       /* Child after fork */
        !           164: #define IPROF  6       /* Reading /etc/profile for login */
        !           165: 
        !           166: /*
        !           167:  * Evaluation contexts.
        !           168:  */
        !           169: #define EWORD  0       /* Evaluate $N, `cmd`, strip quotes */
        !           170: #define EHERE  1       /* Evaluate $N, `cmd`, ignore quotes */
        !           171: #define EARGS  2       /* Evaluete $N, `cmd`, strip quotes, *?[, blanks */
        !           172: #define EPATT  3       /* Evaluate for pattern match */
        !           173: 
        !           174: 
        !           175: /*
        !           176:  * NB: Here-document processing in shell functions places extra demands on
        !           177:  * the management of temporary files. When a shell function is interned, any
        !           178:  * here documents created within the function are turned into temporary
        !           179:  * files which must persist for the life of the function (ie, until the
        !           180:  * shell exits or the function is removed via "unset -f").
        !           181:  *
        !           182:  * The following data structure is intended to allow the temporary-file
        !           183:  * context to be managed in the manner required. A pointer to a list of these
        !           184:  * structures is stored in the function definition, taken from the global
        !           185:  * list of temporary files when a function is defined.
        !           186:  *
        !           187:  * Related functions:
        !           188:  *     def_sh_fn (nodep)
        !           189:  *             Captures the current temporary-file context and attaches it
        !           190:  *             to the shell function being defined.
        !           191:  *     remember_temp (filename)
        !           192:  *             Adds a filename to the current global list of temporary
        !           193:  *             files (copies filename to private buffer).
        !           194:  *     capture_temp ()
        !           195:  *             Detaches the global list of temporary files and returns
        !           196:  *             the list to the caller.
        !           197:  *     unlink_temp (templist)
        !           198:  *             Walks over the list of temporary files, unlinking the files
        !           199:  *             and deallocating the list nodes.
        !           200:  *     forget_temp (templist)
        !           201:  *             Deallocates the memory for the list of temporary files.
        !           202:  */
        !           203: 
        !           204: typedef struct temp_file TEMP_FILE;
        !           205: 
        !           206: struct temp_file {
        !           207:        TEMP_FILE     * tf_next;
        !           208:        char          * tf_name;
        !           209: };
        !           210: 
        !           211: 
        !           212: /*
        !           213:  * Shell functions.
        !           214:  */
        !           215: typedef struct shfunc {
        !           216:        struct  shfunc  *fn_link;
        !           217:        int             fn_hash;
        !           218:        char            *fn_name;
        !           219:        NODE            *fn_body;
        !           220:        TEMP_FILE     * fn_temp;
        !           221: } SHFUNC;
        !           222: 
        !           223: 
        !           224: /*
        !           225:  * NB : The shell is required to permit redirections of built-ins and special
        !           226:  * built-in operations in such a way that they are not run in subshells (since
        !           227:  * they have to affect the top-level environment). To permit this, the
        !           228:  * redirection code makes duplicates of file descriptors it overwrites and
        !           229:  * records all the information necessary to reverse the effect of the
        !           230:  * redirections on the global environment. This structure holds the "undo"
        !           231:  * information. Note that "ru_newfd" may be set to -1 if the fd that was
        !           232:  * redirected did not originally refer to an open file.
        !           233:  *
        !           234:  * Related functions:
        !           235:  *     redirect (iovp, undo)
        !           236:  *             The "undo" argument is an optional pointer to the head of a
        !           237:  *             list of REDIR_UNDO entries.
        !           238:  *     redirundo (undo)
        !           239:  *             Processes a list of REDIR_UNDO entries.
        !           240:  */
        !           241: 
        !           242: typedef struct redir_undo REDIR_UNDO;
        !           243: 
        !           244: struct redir_undo {
        !           245:        REDIR_UNDO    * ru_next;        /* link to next undo item */
        !           246:        int             ru_oldfd;       /* fd changed by redirection */
        !           247:        int             ru_newfd;       /* duplicate of original fd */
        !           248: };
        !           249: 
        !           250: 
        !           251: /*
        !           252:  * Flags for controlling collect () in lex.c
        !           253:  */
        !           254: 
        !           255: enum {
        !           256:        CONSUME_BACKSLASH,      /*
        !           257:                                 * Allow back-slash quoting of anything and
        !           258:                                 * consume the backslashes.
        !           259:                                 */
        !           260:        BACKSLASH_END,          /*
        !           261:                                 * Recognise backslash-quoting of the end
        !           262:                                 * character, but retain the backslash.
        !           263:                                 */
        !           264:        NO_BACKSLASH,           /* backslashes are ordinary */
        !           265:        NO_ERRORS               /* backslashes are ordinary, silent errors */
        !           266: };
        !           267:                                
        !           268: 
        !           269: /*
        !           270:  * Global variables.
        !           271:  *     Run time and set time flags.
        !           272:  */
        !           273: extern         char    shflags[];              /* Flag array */
        !           274: extern char    shfnams[];              /* Flag name array */
        !           275: 
        !           276: #define eflag  shflags[0]              /* Exit on non-zero status */
        !           277: #define kflag  shflags[1]              /* All assignments into environ */
        !           278: #define nflag  shflags[2]              /* Do not execute commands */
        !           279: #define pflag  shflags[3]              /* Unknown */
        !           280: #define tflag  shflags[4]              /* Exit after read/exec one command */
        !           281: #define uflag  shflags[5]              /* Unset variables are errors */
        !           282: #define vflag  shflags[6]              /* Print input as read */
        !           283: #define xflag  shflags[7]              /* Print commands as executed */
        !           284: 
        !           285: #define cflag  shflags[8]              /* Execute argument as command */
        !           286: #define iflag  shflags[9]              /* Be interactive shell */
        !           287: #define rflag  shflags[10]             /* Restricted shell */
        !           288: #define sflag  shflags[11]             /* input<&0, output>&2 */
        !           289: 
        !           290: #define lgnflag        shflags[12]             /* Login shell */
        !           291: #define no1flag        shflags[13]             /* Invoked shell */
        !           292: #define bckflag        shflags[14]             /* Background process */
        !           293: #define nllflag shflags[15]            /* Forked shell */
        !           294: #define cmdflag        shflags[16]             /* Command file processor */
        !           295: 
        !           296: /* Shell status housekeeping */
        !           297: extern jmp_buf restart;                /* Restart execution context */
        !           298: extern SHFUNC  *sh_fnp;                /* User-defined shell function list */
        !           299: extern int     in_sh_fn;               /* Executing shell function */
        !           300: extern int     ret_done;               /* "return" executed */
        !           301: extern int     sargc;                  /* Argument count to shell */
        !           302: extern char    *sarg0;                 /* Name shell called with */
        !           303: extern char    **sargv;                /* Argument vector to shell */
        !           304: extern char    **senvp;                /* Environment vector to shell */
        !           305: extern char    **sargp;                /* Current argument to shell */
        !           306: extern char    *scmdp;                 /* Path/filename of command file */
        !           307: extern int     nargc;                  /* New argument count, for command */
        !           308: extern char    **nargv;                /* New argument vector, for command */
        !           309: extern char    **nenvp;                /* New environment, for command */
        !           310: extern char    **niovp;                /* Io redirection, for command */
        !           311: extern NODE     *nctlp;                /* Control node, for command */
        !           312: extern SES     *sesp;                  /* Current session structure */
        !           313: extern int     yyline;                 /* Yacc command line counter */
        !           314: extern int     shpid;                  /* Shell's process id */
        !           315: extern int     slret;                  /* Exit status of last command */
        !           316: extern int     sback;                  /* Pid of last background command */
        !           317: extern int     spipe;                  /* Pid of last pipe process */
        !           318: extern int     ufmask;                 /* File creation mask */
        !           319: /* Other internal flags. */
        !           320: extern int     comflag;                /* Command line is complete?? */
        !           321: extern int     errflag;                /* Set by call to printe */
        !           322: extern int     keyflag;                /* Look for keyword in next word */
        !           323: extern int     noeflag;                /* Turn off errors */
        !           324: extern int     prpflag;                /* Do prompt before next read */
        !           325: extern int     readflag;               /* Doing read command? */
        !           326: /* Parameters used by shell. */
        !           327: extern char    *vhome;                 /* Home directory */
        !           328: extern char    *vpath;                 /* Search pathname */
        !           329: extern char    *vmail;                 /* Mail file */
        !           330: extern char    *vps1;                  /* Prompt string 1 */
        !           331: extern char    *vps2;                  /* Prompt string 2 */
        !           332: extern char    *vifs;                  /* Internal field seperators */
        !           333: extern char    *vshell;                /* Shell to use */
        !           334: /* Shell data */
        !           335: extern char    strt[STRSIZE];          /* String buffer */
        !           336: extern char    *strp;                  /* Pointer in string buffer */
        !           337: extern VAR     *varp;                  /* Pointer to shell variables */
        !           338: extern char    *dstack[DSTACKN];       /* Directory stack */
        !           339: extern int     dstkp;                  /* Directory stack pointer */
        !           340: 
        !           341: /* Tables */
        !           342: extern char    lextab[];               /* Character type table */
        !           343: /* Data external to shell */
        !           344: extern int     errno;                  /* System call error number */
        !           345: extern char    *signame[];             /* Wait status message table */
        !           346: 
        !           347: /*
        !           348:  * Functions.
        !           349:  */
        !           350: extern char    *shtmp();               /* in main.c */
        !           351: extern char    *salloc();              /* in alloc.c */
        !           352: extern char    *balloc();              /* in alloc.c */
        !           353: extern char    *duplstr();             /* in alloc.c */
        !           354: extern char    **makargl();            /* in alloc.c */
        !           355: extern char    **addargl();            /* in alloc.c */
        !           356: extern BUF     **savebuf();            /* in alloc.c */
        !           357: extern char    **vdupl();              /* in alloc.c */
        !           358: extern char    *gany();                /* in glob.c */
        !           359: extern int     sigintr();              /* in trap.c */
        !           360: extern VAR     *findvar();             /* in var.c */
        !           361: extern VAR     *setsvar();             /* in var.c */
        !           362: extern VAR     *flagvar();             /* in var.c */
        !           363: extern VAR     *assnvar();             /* in var.c */
        !           364: extern char    *convvar();             /* in var.c */
        !           365: extern char    **envlvar();            /* in var.c */
        !           366: extern char    *_getwd();              /* in /lib/libc.a */
        !           367: #define        index(cp, c)    strchr((cp), (c))
        !           368: #define        rindex(cp, c)   strrchr((cp), (c))
        !           369: 
        !           370: /* NB: new stuff for shell functions */
        !           371: extern TEMP_FILE     * capture_temp ();        /* main.c */
        !           372: extern void            unlink_temp ();         /* main.c */
        !           373: extern void            cleanup_shell_fns ();   /* exec3.c */
        !           374: 
        !           375: #ifdef ALLOC_DEBUG
        !           376: struct alloc_debug {
        !           377:        char          * name;
        !           378:        int             count;
        !           379:        int             maxcount;
        !           380: };
        !           381: # define       ALLOC_COUNT(x)          struct alloc_debug x##debug = { #x };
        !           382: # define       ALLOC_ALLOC(x)          alloc_alloc (& x##debug);
        !           383: # define       ALLOC_FREE(x)           x##debug.count --;
        !           384: #
        !           385: #else
        !           386: # define       ALLOC_COUNT(x)
        !           387: # define       ALLOC_ALLOC(x)
        !           388: # define       ALLOC_FREE(x)
        !           389: #endif
        !           390: 
        !           391: /* end of sh/sh.h */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.