Annotation of coherent/d/bin/sh/sh.h, revision 1.1.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: 
                     63: /*
                     64:  * Node.
                     65:  */
                     66: typedef        struct  node {
                     67:        int     n_type;                 /* Type of node */
                     68:        struct  node *n_next;           /* Pointer to next */
                     69:        union   {
                     70:                struct  node *nu_auxp;  /* Auxiliary pointer */
                     71:                char    *nu_strp;       /* Pointer to string */
                     72:        } n_u;
                     73: } NODE;
                     74: #define        n_auxp  n_u.nu_auxp
                     75: #define        n_strp  n_u.nu_strp
                     76: 
                     77: /*
                     78:  * Flags in variables.
                     79:  */
                     80: #define VEXP   001                     /* Variable is exported */
                     81: #define VRDO   002                     /* Read only */
                     82: #define VSET   004                     /* Variable is used by shell */
                     83: 
                     84: /*
                     85:  * Enviroment list and variable structure.
                     86:  */
                     87: typedef        struct  var {
                     88:        int     v_flag;                 /* Flags */
                     89:        struct  var *v_next;            /* Pointer to next entry */
                     90:        char    *v_strp;                /* Pointer to string */
                     91: } VAR;
                     92: 
                     93: /*
                     94:  * Buffer structure.
                     95:  */
                     96: typedef        struct  buf {
                     97:        struct  buf *b_next;            /* Pointer to next */
                     98:        int     b_size;                 /* Size of buffer */
                     99: } BUF;
                    100: 
                    101: /*
                    102:  * Per executing command data structure.
                    103:  * Used for break/continue.
                    104:  */
                    105: typedef        struct  con {
                    106:        struct  con *c_next;            /* Pointer to next */
                    107:        NODE    *c_node;                /* Node which created this control */
                    108:        BUF     **c_bpp;                /* Current free buffer */
                    109:        jmp_buf c_envl;                 /* Enviroment list */
                    110: } CON;
                    111: 
                    112: /*
                    113:  * Session types.
                    114:  */
                    115: #define SINIT  0       /* Initial session */
                    116: #define SARGS  1       /* String */
                    117: #define SARGV  2       /* Vector of strings */
                    118: #define SFILE  3       /* File name */
                    119: #define SSTR   4       /* Open stream */
                    120: 
                    121: /*
                    122:  * Per session information structure.
                    123:  */
                    124: typedef struct ses {
                    125:        struct  ses     *s_next;
                    126:        int             s_type;
                    127:        int             s_flag;
                    128:        NODE            *s_node;
                    129:        CON             *s_con;
                    130:        BUF             **s_bpp;
                    131:        jmp_buf         s_envl;
                    132:        char            *s_strp;
                    133:        char            **s_argv;
                    134:        FILE            *s_ifp;
                    135: } SES;
                    136: 
                    137: /*
                    138:  * Session long jump codes
                    139:  */
                    140: #define RSET   0       /* Initial setjmp call */
                    141: #define REOF   1       /* parse matched start */
                    142: #define RCMD   2       /* parse matched command line */
                    143: #define RERR   3       /* parse matched error */
                    144: #define RINT   4       /* Interrupt recovery */
                    145: #define RNOSBRK        5       /* no more memory from alloc */
                    146: #define RSYSER 6       /* system returned -1 */
                    147: #define RUABORT        7       /* user requested error abort */
                    148: #define RUEXITS        8       /* user requested exit command */
                    149: #define RBRKCON        9       /* break or continue beyond program */
                    150: #define RNOWAY 10      /* Shell assertion failed */
                    151: 
                    152: /*
                    153:  * Interrupt recovery and set contexts.
                    154:  * Used to determine recovery action and default signals.
                    155:  */
                    156: #define IRDY   0       /* In session */
                    157: #define        ILEX    1       /* Parse in progress */
                    158: #define ICMD   2       /* Prior to next command execution */
                    159: #define IEVAL  3       /* Command evaluation in progress */
                    160: #define IBACK  4       /* Background process */
                    161: #define IFORK  5       /* Child after fork */
                    162: #define IPROF  6       /* Reading /etc/profile for login */
                    163: 
                    164: /*
                    165:  * Evaluation contexts.
                    166:  */
                    167: #define EWORD  0       /* Evaluate $N, `cmd`, strip quotes */
                    168: #define EHERE  1       /* Evaluate $N, `cmd`, ignore quotes */
                    169: #define EARGS  2       /* Evaluete $N, `cmd`, strip quotes, *?[, blanks */
                    170: #define EPATT  3       /* Evaluate for pattern match */
                    171: 
                    172: /*
                    173:  * Global variables.
                    174:  *     Run time and set time flags.
                    175:  */
                    176: extern         char    shflags[];              /* Flag array */
                    177: extern char    shfnams[];              /* Flag name array */
                    178: 
                    179: #define eflag  shflags[0]              /* Exit on non-zero status */
                    180: #define kflag  shflags[1]              /* All assignments into environ */
                    181: #define nflag  shflags[2]              /* Do not execute commands */
                    182: #define pflag  shflags[3]              /* Unknown */
                    183: #define tflag  shflags[4]              /* Exit after read/exec one command */
                    184: #define uflag  shflags[5]              /* Unset variables are errors */
                    185: #define vflag  shflags[6]              /* Print input as read */
                    186: #define xflag  shflags[7]              /* Print commands as executed */
                    187: 
                    188: #define cflag  shflags[8]              /* Execute argument as command */
                    189: #define iflag  shflags[9]              /* Be interactive shell */
                    190: #define rflag  shflags[10]             /* Restricted shell */
                    191: #define sflag  shflags[11]             /* input<&0, output>&2 */
                    192: 
                    193: #define lgnflag        shflags[12]             /* Login shell */
                    194: #define no1flag        shflags[13]             /* Invoked shell */
                    195: #define bckflag        shflags[14]             /* Background process */
                    196: #define nllflag shflags[15]            /* Forked shell */
                    197: #define cmdflag        shflags[16]             /* Command file processor */
                    198: 
                    199: /* Shell status housekeeping */
                    200: extern jmp_buf restart;                /* Restart execution context */
                    201: extern int     sargc;                  /* Argument count to shell */
                    202: extern char    *sarg0;                 /* Name shell called with */
                    203: extern char    **sargv;                /* Argument vector to shell */
                    204: extern char    **senvp;                /* Environment vector to shell */
                    205: extern char    **sargp;                /* Current argument to shell */
                    206: extern char    *scmdp;                 /* Path/filename of command file */
                    207: extern int     nargc;                  /* New argument count, for command */
                    208: extern char    **nargv;                /* New argument vector, for command */
                    209: extern char    **nenvp;                /* New environment, for command */
                    210: extern char    **niovp;                /* Io redirection, for command */
                    211: extern NODE     *nctlp;                /* Control node, for command */
                    212: extern SES     *sesp;                  /* Current session structure */
                    213: extern int     yyline;                 /* Yacc command line counter */
                    214: extern int     shpid;                  /* Shell's process id */
                    215: extern int     slret;                  /* Exit status of last command */
                    216: extern int     sback;                  /* Pid of last background command */
                    217: extern int     spipe;                  /* Pid of last pipe process */
                    218: extern int     ufmask;                 /* File creation mask */
                    219: /* Other internal flags. */
                    220: extern int     comflag;                /* Command line is complete?? */
                    221: extern int     errflag;                /* Set by call to printe */
                    222: extern int     keyflag;                /* Look for keyword in next word */
                    223: extern int     noeflag;                /* Turn off errors */
                    224: extern int     prpflag;                /* Do prompt before next read */
                    225: extern int     readflag;               /* Doing read command? */
                    226: /* Parameters used by shell. */
                    227: extern char    *vhome;                 /* Home directory */
                    228: extern char    *vpath;                 /* Search pathname */
                    229: extern char    *vmail;                 /* Mail file */
                    230: extern char    *vps1;                  /* Prompt string 1 */
                    231: extern char    *vps2;                  /* Prompt string 2 */
                    232: extern char    *vifs;                  /* Internal field seperators */
                    233: extern char    *vshell;                /* Shell to use */
                    234: /* Shell data */
                    235: extern char    strt[STRSIZE];          /* String buffer */
                    236: extern char    *strp;                  /* Pointer in string buffer */
                    237: extern VAR     *varp;                  /* Pointer to shell variables */
                    238: extern char    *dstack[DSTACKN];       /* Directory stack */
                    239: extern int     dstkp;                  /* Directory stack pointer */
                    240: 
                    241: /* Tables */
                    242: extern char    lextab[];               /* Character type table */
                    243: /* Data external to shell */
                    244: extern int     errno;                  /* System call error number */
                    245: extern char    *signame[];             /* Wait status message table */
                    246: 
                    247: /*
                    248:  * Functions.
                    249:  */
                    250: extern char    *shtmp();               /* in main.c */
                    251: extern char    *salloc();              /* in alloc.c */
                    252: extern char    *balloc();              /* in alloc.c */
                    253: extern char    *duplstr();             /* in alloc.c */
                    254: extern char    **makargl();            /* in alloc.c */
                    255: extern char    **addargl();            /* in alloc.c */
                    256: extern BUF     **savebuf();            /* in alloc.c */
                    257: extern char    **vdupl();              /* in alloc.c */
                    258: extern char    *gany();                /* in glob.c */
                    259: extern int     sigintr();              /* in trap.c */
                    260: extern VAR     *findvar();             /* in var.c */
                    261: extern VAR     *setsvar();             /* in var.c */
                    262: extern VAR     *flagvar();             /* in var.c */
                    263: extern VAR     *assnvar();             /* in var.c */
                    264: extern char    *convvar();             /* in var.c */
                    265: extern char    **envlvar();            /* in var.c */
                    266: extern char    *_getwd();              /* in /lib/libc.a */
                    267: #define        index(cp, c)    strchr((cp), (c))
                    268: #define        rindex(cp, c)   strrchr((cp), (c))
                    269: 
                    270: /* 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.