1: /* $Header: src/sys/tcsh-6.00/RCS/sh.h,v 3.1.1 1996/03/21 19:07:20 christos Exp $ */
   2: /*
   3:  * sh.h: Catch it all globals and includes file!
   4:  */
   5: /*-
   6:  * Copyright (c) 1980, 1991 The Regents of the University of California.
   7:  * All rights reserved.
   8:  *
   9:  * Redistribution and use in source and binary forms, with or without
  10:  * modification, are permitted provided that the following conditions
  11:  * are met:
  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. All advertising materials mentioning features or use of this software
  18:  *    must display the following acknowledgement:
  19:  *	This product includes software developed by the University of
  20:  *	California, Berkeley and its contributors.
  21:  * 4. Neither the name of the University nor the names of its contributors
  22:  *    may be used to endorse or promote products derived from this software
  23:  *    without specific prior written permission.
  24:  *
  25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35:  * SUCH DAMAGE.
  36:  */
  37: #ifndef _h_sh
  38: #define _h_sh
  39: 
  40: 
  41: /*
  42:  * Sanity
  43:  */
  44: #if defined(_POSIX_SOURCE) && !defined(POSIX)
  45: # define POSIX
  46: #endif
  47: 
  48: #if defined(POSIXJOBS) && !defined(BSDJOBS)
  49: # define BSDJOBS
  50: #endif
  51: 
  52: #ifdef SHORT_STRINGS
  53: typedef short Char;
  54: # define SAVE(a) (Strsave(str2short(a)))
  55: #else
  56: typedef char Char;
  57: # define SAVE(a) (strsave(a))
  58: #endif
  59: 
  60: /*
  61:  * If your comp_r complains, then you can either
  62:  * throw it away and get gcc or, use the following define
  63:  * and get rid of the typedef.
  64:  * [The 4.2/3BSD vax comp_r does not like that]
  65:  */
  66: #ifdef SIGVOID
  67: # if defined(vax) && !defined(__GNUC__)
  68: #  define sigret_t void
  69: # else
  70: typedef void sigret_t;
  71: # endif
  72: #else
  73: typedef int sigret_t;
  74: #endif				/* SIGVOID */
  75: 
  76: /*
  77:  * Fundamental definitions which may vary from system to system.
  78:  *
  79:  *	BUFSIZ		The i/o buffering size; also limits word size
  80:  *	MAILINTVL	How often to mailcheck; more often is more expensive
  81:  */
  82: #ifndef BUFSIZ
  83: #define BUFSIZ  1024        /* default buffer size */
  84: #endif				/* BUFSIZ */
  85: 
  86: #define FORKSLEEP   10  /* delay loop on non-interactive fork failure */
  87: #define MAILINTVL   600 /* 10 minutes */
  88: 
  89: /*
  90:  * The shell moves std in/out/diag and the old std input away from units
  91:  * 0, 1, and 2 so that it is easy to set up these standards for invoked
  92:  * commands.
  93:  */
  94: #define FSHTTY  15      /* /dev/tty when manip pgrps */
  95: #define FSHIN   16      /* Preferred desc for shell input */
  96: #define FSHOUT  17      /* ... shell output */
  97: #define FSHDIAG 18      /* ... shell diagnostics */
  98: #define FOLDSTD 19      /* ... old std input */
  99: 
 100: #ifdef PROF
 101: #define xexit(n)    done(n)
 102: #endif
 103: 
 104: #include <sys/types.h>
 105: #ifdef _SEQUENT_
 106: # include <sys/procstats.h>
 107: #endif /* _SEQUENT_ */
 108: #if defined(POSIX) || SVID > 0
 109: # include <sys/times.h>
 110: #endif				/* POSIX || SVID > 0 */
 111: 
 112: #ifdef NLS
 113: # include <locale.h>
 114: #endif
 115: 
 116: #include <sys/param.h>
 117: #include <sys/stat.h>
 118: 
 119: #ifdef BSDTIMES
 120: # include <sys/time.h>
 121: # include <sys/resource.h>
 122: #endif				/* BSDTIMES */
 123: 
 124: #ifndef POSIX
 125: # ifdef TERMIO
 126: #  ifdef _IBMR2
 127:  /* Aix redefines NOFLSH when _BSD_INCLUDES is defined! */
 128: #   undef _BSD
 129: #   undef _BSD_INCLUDES
 130: #  endif				/* _IBMR2 */
 131: #  include <termio.h>
 132: #  ifdef _IBMR2
 133:  /* but we need it.  */
 134: #   define _BSD
 135: #   define _BSD_INCLUDES
 136: #  endif				/* _IBMR2 */
 137: # else
 138: #  include <sgtty.h>
 139: # endif				/* TERMIO */
 140: #else               /* POSIX */
 141: # include <termios.h>
 142: #endif				/* POSIX */
 143: 
 144: #ifdef POSIX
 145: /*
 146:  * We should be using setpgid and setpgid
 147:  * by now, but in some systems we use the
 148:  * old routines...
 149:  */
 150: # define getpgrp __getpgrp
 151: # define setpgrp __setpgrp
 152: # include <unistd.h>
 153: # undef getpgrp
 154: # undef setpgrp
 155: extern int getpgrp();
 156: extern int setpgrp();
 157: 
 158: /*
 159:  * the gcc+protoize version of <stdlib.h>
 160:  * redefines malloc(), so we define the following
 161:  * to avoid it.
 162:  */
 163: # define _GNU_STDLIB_H
 164: # define malloc __malloc
 165: # define free __free
 166: # define calloc __calloc
 167: # define realloc __realloc
 168: # include <stdlib.h>
 169: # undef malloc
 170: # undef free
 171: # undef calloc
 172: # undef realloc
 173: # include <limits.h>
 174: #endif				/* POSIX */
 175: 
 176: #if SVID > 0
 177: # if !defined(pyr) || !defined(aiws)
 178: #  include <time.h>
 179: # endif				/* !aiws || !pyr */
 180: #endif				/* SVID > 0 */
 181: 
 182: #if !(defined(sun) && defined(TERMIO))
 183: # include <sys/ioctl.h>
 184: #endif
 185: 
 186: #if !defined(FIOCLEX) && defined(sun)
 187: # include <sys/filio.h>
 188: #endif				/* !FIOCLEX && sun */
 189: 
 190: 
 191: #include <sys/file.h>
 192: 
 193: #if !defined(O_RDONLY) || !defined(O_NDELAY)
 194: # include <fcntl.h>
 195: #endif
 196: 
 197: #include <errno.h>
 198: 
 199: #include <setjmp.h>
 200: 
 201: #if __STDC__
 202: # include <stdarg.h>
 203: #else
 204: # include <varargs.h>
 205: #endif
 206: 
 207: #ifdef DIRENT
 208: # include <dirent.h>
 209: #else
 210: # include <sys/dir.h>
 211: # define dirent direct
 212: #endif				/* DIRENT */
 213: #ifdef hpux
 214: # include <stdio.h> /* So the fgetpwent() prototypes work */
 215: #endif
 216: #include <pwd.h>
 217: #ifdef BSD
 218: # include <strings.h>
 219: # define strchr(a, b) index(a, b)
 220: # define strrchr(a, b) rindex(a, b)
 221: #else
 222: # include <string.h>
 223: #endif				/* BSD */
 224: 
 225: typedef int bool;
 226: 
 227: #include "sh.types.h"
 228: 
 229: #ifndef lint
 230: typedef ptr_t memalign_t;
 231: #else
 232: typedef union {
 233:     char    am_ch, *am_char_p;
 234:     short   am_sh, *am_short_p;
 235:     int     am_in, *am_int_p;
 236:     long    am_lo, *am_long_p;
 237:     float   am_fl, *am_float_p;
 238:     double  am_do, *am_double_p;
 239: }      *memalign_t;
 240: 
 241: # define malloc     lint_malloc
 242: # define free       lint_free
 243: # define realloc    lint_realloc
 244: # define calloc     lint_calloc
 245: #endif
 246: 
 247: #ifdef SYSMALLOC
 248: # define xmalloc(i)     Malloc(i)
 249: # define xrealloc(p, i) Realloc(p, i)
 250: # define xcalloc(n, s)  Calloc(n, s)
 251: # define xfree(p)       Free(p)
 252: #else
 253: # define xmalloc(i)     malloc(i)
 254: # define xrealloc(p, i) realloc(p, i)
 255: # define xcalloc(n, s)  calloc(n, s)
 256: # define xfree(p)       free(p)
 257: #endif /* SYSMALLOC */
 258: #include "sh.char.h"
 259: #include "sh.err.h"
 260: #include "sh.dir.h"
 261: #include "sh.proc.h"
 262: 
 263: #include "pathnames.h"
 264: 
 265: 
 266: /*
 267:  * C shell
 268:  *
 269:  * Bill Joy, UC Berkeley
 270:  * October, 1978; May 1980
 271:  *
 272:  * Jim Kulp, IIASA, Laxenburg Austria
 273:  * April, 1980
 274:  */
 275: 
 276: #define SIGN_EXTEND_CHAR(a) \
 277:     ((a) & 0x80 ? ((int) (a)) | 0xffffff00 : ((int) a) & 0x000000ff)
 278: 
 279: 
 280: 
 281: #if !defined(MAXNAMLEN) && defined(_D_NAME_MAX)
 282: # define MAXNAMLEN _D_NAME_MAX
 283: #endif				/* MAXNAMLEN */
 284: 
 285: #ifndef MAXHOSTNAMELEN
 286: # define MAXHOSTNAMELEN 255
 287: #endif				/* MAXHOSTNAMELEN */
 288: 
 289: 
 290: 
 291: #define eq(a, b)    (Strcmp(a, b) == 0)
 292: 
 293: /* globone() flags */
 294: #define G_ERROR     0   /* default action: error if multiple words */
 295: #define G_IGNORE    1   /* ignore the rest of the words		   */
 296: #define G_APPEND    2   /* make a sentence by cat'ing the words    */
 297: 
 298: /*
 299:  * Global flags
 300:  */
 301: bool    chkstop;        /* Warned of stopped jobs... allow exit */
 302: 
 303: #ifndef FIOCLEX
 304: bool    didcch;         /* Have closed unused fd's for child */
 305: #endif
 306: 
 307: bool    didfds;         /* Have setup i/o fd's for child */
 308: bool    doneinp;        /* EOF indicator after reset from readc */
 309: bool    exiterr;        /* Exit if error or non-zero exit status */
 310: bool    child;          /* Child shell ... errors cause exit */
 311: bool    haderr;         /* Reset was because of an error */
 312: bool    intty;          /* Input is a tty */
 313: bool    intact;         /* We are interactive... therefore prompt */
 314: bool    justpr;         /* Just print because of :p hist mod */
 315: bool    loginsh;        /* We are a loginsh -> .login/.logout */
 316: bool    neednote;       /* Need to pnotify() */
 317: bool    noexec;         /* Don't execute, just syntax check */
 318: bool    pjobs;          /* want to print jobs if interrupted */
 319: bool    setintr;        /* Set interrupts on/off -> Wait intr... */
 320: bool    timflg;         /* Time the next waited for command */
 321: bool    havhash;        /* path hashing is available */
 322: bool    editing;        /* doing filename expansion and line editing */
 323: bool    bslash_quote;       /* PWP: tcsh-style quoting?  (in sh.c) */
 324: bool    isoutatty;      /* is SHOUT a tty */
 325: bool    isdiagatty;     /* is SHDIAG a tty */
 326: bool    is1atty;        /* is file descriptor 1 a tty (didfds mode) */
 327: bool    is2atty;        /* is file descriptor 2 a tty (didfds mode) */
 328: 
 329: /*
 330:  * Global i/o info
 331:  */
 332: Char   *arginp;         /* Argument input for sh -c and internal `xx` */
 333: int     onelflg;        /* 2 -> need line for -t, 1 -> exit on read */
 334: Char   *ffile;          /* Name of shell file for $0 */
 335: 
 336: extern char *seterr;        /* Error message from scanner/parser */
 337: extern int errno;       /* Error from C library routines */
 338: Char   *shtemp;         /* Temp name for << shell files in /tmp */
 339: 
 340: #ifdef BSDTIMES
 341: struct timeval time0;       /* Time at which the shell started */
 342: struct rusage ru0;
 343: #else
 344: # ifdef _SEQUENT_
 345: tmval_t time0;      /* Time at which the shell started */
 346: struct pro_stats ru0;
 347: # else              /* _SEQUENT_ */
 348: #  ifndef POSIX
 349: time_t  time0;          /* time at which shell started */
 350: #  else             /* POSIX */
 351: clock_t time0;          /* time at which shell started */
 352: #  endif			/* POSIX */
 353: struct tms shtimes;     /* shell and child times for process timing */
 354: # endif				/* _SEQUENT_ */
 355: #endif				/* BSDTIMES */
 356: 
 357: /*
 358:  * Miscellany
 359:  */
 360: Char   *doldol;         /* Character pid for $$ */
 361: int     uid;            /* Invokers uid */
 362: int     gid;            /* Invokers gid */
 363: time_t  chktim;         /* Time mail last checked */
 364: int     shpgrp;         /* Pgrp of shell */
 365: int     tpgrp;          /* Terminal process group */
 366: 
 367: /* If tpgrp is -1, leave tty alone! */
 368: int     opgrp;          /* Initial pgrp and tty pgrp */
 369: 
 370: Char    PromptBuf[256];     /* buffer for the actual printed prompt. this
 371: 				 * is used in tenex.c and sh.c for pegets.c */
 372: 
 373: /*
 374:  * These are declared here because they want to be
 375:  * initialized in sh.init.c (to allow them to be made readonly)
 376:  */
 377: 
 378: extern struct biltins {
 379:     char   *bname;
 380:     void    (*bfunct) ();
 381:     short   minargs, maxargs;
 382: }       bfunc[];
 383: extern int nbfunc;
 384: 
 385: extern struct srch {
 386:     char   *s_name;
 387:     short   s_value;
 388: }       srchn[];
 389: extern int nsrchn;
 390: 
 391: /*
 392:  * To be able to redirect i/o for builtins easily, the shell moves the i/o
 393:  * descriptors it uses away from 0,1,2.
 394:  * Ideally these should be in units which are closed across exec's
 395:  * (this saves work) but for version 6, this is not usually possible.
 396:  * The desired initial values for these descriptors are defined in
 397:  * sh.local.h.
 398:  */
 399: short   SHIN;           /* Cur_ shell input (script) */
 400: short   SHOUT;          /* Shell output */
 401: short   SHDIAG;         /* Diagnostic output... shell errs go here */
 402: short   OLDSTD;         /* Old standard input (def for cmds) */
 403: 
 404: /*
 405:  * Error control
 406:  *
 407:  * Errors in scanning and parsing set up an error message to be printed
 408:  * at the end and complete.  Other errors always cause a reset.
 409:  * Because of source commands and .cshrc we need nested error catches.
 410:  */
 411: 
 412: jmp_buf reslab;
 413: 
 414: /* bugfix by Jak Kirman @ Brown U.: remove the (void) cast here, see sh.c */
 415: #define setexit()   (setjmp(reslab))
 416: #define reset()     longjmp(reslab, 1)
 417:  /* Should use structure assignment here */
 418: #define getexit(a)  copy((char *)(a), (char *)reslab, sizeof reslab)
 419: #define resexit(a)  copy((char *)reslab, ((char *)(a)), sizeof reslab)
 420: 
 421: Char   *gointr;         /* Label for an onintr transfer */
 422: 
 423: sigret_t (*parintr) ();     /* Parents interrupt catch */
 424: sigret_t (*parterm) ();     /* Parents terminate catch */
 425: 
 426: /*
 427:  * Lexical definitions.
 428:  *
 429:  * All lexical space is allocated dynamically.
 430:  * The eighth/sizteenth bit of characters is used to prevent recognition,
 431:  * and eventually stripped.
 432:  */
 433: #define     META        0200
 434: #define     ASCII       0177
 435: #ifdef SHORT_STRINGS
 436: # define    QUOTE       0100000 /* 16nth char bit used for 'ing */
 437: # define    TRIM        0077777 /* Mask to strip quote bit */
 438: # define    UNDER       0040000 /* Underline flag */
 439: # define    BOLD        0020000 /* Bold flag */
 440: # define    STANDOUT    0010000 /* Standout flag */
 441: # define    LITERAL     0004000 /* Literal character flag */
 442: # define    ATTRIBUTES  0074000 /* The bits used for attributes */
 443: # define    CHAR        0000377 /* Mask to mask out the character */
 444: #else
 445: # define    QUOTE       0200    /* Eighth char bit used for 'ing */
 446: # define    TRIM        0177    /* Mask to strip quote bit */
 447: # define    UNDER       0000000 /* No extra bits to do both */
 448: # define    BOLD        0000000 /* Bold flag */
 449: # define    STANDOUT    META    /* Standout flag */
 450: # define    LITERAL     0000000 /* Literal character flag */
 451: # define    ATTRIBUTES  0200    /* The bits used for attributes */
 452: # define    CHAR        0000177 /* Mask to mask out the character */
 453: #endif
 454: 
 455: int     AsciiOnly;      /* If set only 7 bits is expected in characters */
 456: 
 457: /*
 458:  * Each level of input has a buffered input structure.
 459:  * There are one or more blocks of buffered input for each level,
 460:  * exactly one if the input is seekable and tell is available.
 461:  * In other cases, the shell buffers enough blocks to keep all loops
 462:  * in the buffer.
 463:  */
 464: struct Bin {
 465:     off_t   Bfseekp;        /* Seek pointer */
 466:     off_t   Bfbobp;     /* Seekp of beginning of buffers */
 467:     off_t   Bfeobp;     /* Seekp of end of buffers */
 468:     short   Bfblocks;       /* Number of buffer blocks */
 469:     Char  **Bfbuf;      /* The array of buffer blocks */
 470: }       B;
 471: 
 472: #define fseekp  B.Bfseekp
 473: #define fbobp   B.Bfbobp
 474: #define feobp   B.Bfeobp
 475: #define fblocks B.Bfblocks
 476: #define fbuf    B.Bfbuf
 477: 
 478: #define btell() fseekp
 479: 
 480: /*
 481:  * The shell finds commands in loops by reseeking the input
 482:  * For whiles, in particular, it reseeks to the beginning of the
 483:  * line the while was on; hence the while placement restrictions.
 484:  */
 485: off_t   lineloc;
 486: 
 487: bool    cantell;        /* Is current source tellable ? */
 488: 
 489: /*
 490:  * Input lines are parsed into doubly linked circular
 491:  * lists of words of the following form.
 492:  */
 493: struct wordent {
 494:     Char   *word;
 495:     struct wordent *prev;
 496:     struct wordent *next;
 497: };
 498: 
 499: /*
 500:  * During word building, both in the initial lexical phase and
 501:  * when expanding $ variable substitutions, expansion by `!' and `$'
 502:  * must be inhibited when reading ahead in routines which are themselves
 503:  * processing `!' and `$' expansion or after characters such as `\' or in
 504:  * quotations.  The following flags are passed to the getC routines
 505:  * telling them which of these substitutions are appropriate for the
 506:  * next character to be returned.
 507:  */
 508: #define DODOL   1
 509: #define DOEXCL  2
 510: #define DOALL   DODOL|DOEXCL
 511: 
 512: /*
 513:  * Labuf implements a general buffer for lookahead during lexical operations.
 514:  * Text which is to be placed in the input stream can be stuck here.
 515:  * We stick parsed ahead $ constructs during initial input,
 516:  * process id's from `$$', and modified variable values (from qualifiers
 517:  * during expansion in sh.dol.c) here.
 518:  */
 519: Char   *lap;
 520: 
 521: /*
 522:  * Parser structure
 523:  *
 524:  * Each command is parsed to a tree of command structures and
 525:  * flags are set bottom up during this process, to be propagated down
 526:  * as needed during the semantics/exeuction pass (sh.sem.c).
 527:  */
 528: struct command {
 529:     short   t_dtyp;     /* Type of node 		 */
 530: #define NODE_COMMAND    1   /* t_dcom <t_dlef >t_drit	 */
 531: #define NODE_PAREN  2   /* ( t_dspr ) <t_dlef >t_drit	 */
 532: #define NODE_PIPE   3   /* t_dlef | t_drit		 */
 533: #define NODE_LIST   4   /* t_dlef ; t_drit		 */
 534: #define NODE_OR     5   /* t_dlef || t_drit		 */
 535: #define NODE_AND    6   /* t_dlef && t_drit		 */
 536:     short   t_dflg;     /* Flags, e.g. F_AMPERSAND|... 	 */
 537: /* save these when re-doing 	 */
 538: #ifndef apollo
 539: #define F_SAVE  (F_NICE|F_TIME|F_NOHUP)
 540: #else
 541: #define F_SAVE  (F_NICE|F_TIME|F_NOHUP|F_VER)
 542: #endif
 543: #define F_AMPERSAND (1<<0)  /* executes in background	 */
 544: #define F_APPEND    (1<<1)  /* output is redirected >>	 */
 545: #define F_PIPEIN    (1<<2)  /* input is a pipe		 */
 546: #define F_PIPEOUT   (1<<3)  /* output is a pipe		 */
 547: #define F_NOFORK    (1<<4)  /* don't fork, last ()ized cmd	 */
 548: #define F_NOINTERRUPT   (1<<5)  /* should be immune from intr's */
 549: /* spare */
 550: #define F_STDERR    (1<<7)  /* redirect unit 2 with unit 1	 */
 551: #define F_OVERWRITE (1<<8)  /* output was !			 */
 552: #define F_READ      (1<<9)  /* input redirection is <<	 */
 553: #define F_REPEAT    (1<<10) /* reexec aft if, repeat,...	 */
 554: #define F_NICE      (1<<11) /* t_nice is meaningful 	 */
 555: #define F_NOHUP     (1<<12) /* nohup this command 		 */
 556: #define F_TIME      (1<<13) /* time this command 		 */
 557: #ifdef apollo
 558: #define F_VER       (1<<14) /* execute command under SYSTYPE */
 559: #endif
 560:     union {
 561:     Char   *T_dlef;     /* Input redirect word 		 */
 562:     struct command *T_dcar; /* Left part of list/pipe 	 */
 563:     }       L;
 564:     union {
 565:     Char   *T_drit;     /* Output redirect word 	 */
 566:     struct command *T_dcdr; /* Right part of list/pipe 	 */
 567:     }       R;
 568: #define t_dlef  L.T_dlef
 569: #define t_dcar  L.T_dcar
 570: #define t_drit  R.T_drit
 571: #define t_dcdr  R.T_dcdr
 572:     Char  **t_dcom;     /* Command/argument vector 	 */
 573:     struct command *t_dspr; /* Pointer to ()'d subtree 	 */
 574:     short   t_nice;
 575: #ifdef F_VER
 576:     short   t_systype;
 577: #endif
 578: };
 579: 
 580: 
 581: /*
 582:  * The keywords for the parser
 583:  */
 584: #define T_BREAK     0
 585: #define T_BRKSW     1
 586: #define T_CASE      2
 587: #define T_DEFAULT   3
 588: #define T_ELSE      4
 589: #define T_END       5
 590: #define T_ENDIF     6
 591: #define T_ENDSW     7
 592: #define T_EXIT      8
 593: #define T_FOREACH   9
 594: #define T_GOTO      10
 595: #define T_IF        11
 596: #define T_LABEL     12
 597: #define T_LET       13
 598: #define T_SET       14
 599: #define T_SWITCH    15
 600: #define T_TEST      16
 601: #define T_THEN      17
 602: #define T_WHILE     18
 603: 
 604: /*
 605:  * Structure defining the existing while/foreach loops at this
 606:  * source level.  Loops are implemented by seeking back in the
 607:  * input.  For foreach (fe), the word list is attached here.
 608:  */
 609: struct whyle {
 610:     off_t   w_start;        /* Point to restart loop */
 611:     off_t   w_end;      /* End of loop (0 if unknown) */
 612:     Char  **w_fe, **w_fe0;  /* Cur_/initial wordlist for fe */
 613:     Char   *w_fename;       /* Name for fe */
 614:     struct whyle *w_next;   /* Next (more outer) loop */
 615: }      *whyles;
 616: 
 617: /*
 618:  * Variable structure
 619:  *
 620:  * Aliases and variables are stored in AVL balanced binary trees.
 621:  */
 622: struct varent {
 623:     Char  **vec;        /* Array of words which is the value */
 624:     Char   *v_name;     /* Name of variable/alias */
 625:     struct varent *v_link[3];   /* The links, see below */
 626:     int     v_bal;      /* Balance factor */
 627: }       shvhed, aliases;
 628: 
 629: #define v_left      v_link[0]
 630: #define v_right     v_link[1]
 631: #define v_parent    v_link[2]
 632: 
 633: struct varent *adrof1();
 634: 
 635: #define adrof(v)    adrof1(v, &shvhed)
 636: #define value(v)    value1(v, &shvhed)
 637: 
 638: /*
 639:  * The following are for interfacing redo substitution in
 640:  * aliases to the lexical routines.
 641:  */
 642: struct wordent *alhistp;    /* Argument list (first) */
 643: struct wordent *alhistt;    /* Node after last in arg list */
 644: Char  **alvec;          /* The (remnants of) alias vector */
 645: 
 646: /*
 647:  * Filename/command name expansion variables
 648:  */
 649: short   gflag;          /* After tglob -> is globbing needed? */
 650: 
 651: #define MAXVARLEN 30        /* Maximum number of char in a variable name */
 652: 
 653: #ifndef MAXPATHLEN
 654: # define MAXPATHLEN 2048
 655: #endif				/* MAXPATHLEN */
 656: 
 657: #ifndef MAXNAMLEN
 658: # define MAXNAMLEN 512
 659: #endif				/* MAXNAMLEN */
 660: 
 661: /*
 662:  * Variables for filename expansion
 663:  */
 664: extern Char **gargv;        /* Pointer to the (stack) arglist */
 665: extern long gargc;      /* Number args in gargv */
 666: 
 667: /*
 668:  * Variables for command expansion.
 669:  */
 670: extern Char **pargv;        /* Pointer to the argv list space */
 671: extern long pargc;      /* Count of arguments in pargv */
 672: Char   *pargs;          /* Pointer to start current word */
 673: long    pnleft;         /* Number of chars left in pargs */
 674: Char   *pargcp;         /* Cur_ index into pargs */
 675: 
 676: /*
 677:  * History list
 678:  *
 679:  * Each history list entry contains an embedded wordlist
 680:  * from the scanner, a number for the event, and a reference count
 681:  * to aid in discarding old entries.
 682:  *
 683:  * Essentially "invisible" entries are put on the history list
 684:  * when history substitution includes modifiers, and thrown away
 685:  * at the next discarding since their event numbers are very negative.
 686:  */
 687: struct Hist {
 688:     struct wordent Hlex;
 689:     int     Hnum;
 690:     int     Href;
 691:     long    Htime;
 692:     Char   *histline;
 693:     struct Hist *Hnext;
 694: }       Histlist;
 695: 
 696: struct wordent paraml;      /* Cur_ lexical word list */
 697: int     eventno;        /* Next events number */
 698: int     lastev;         /* Last event reference (default) */
 699: 
 700: Char    HIST;           /* history invocation character */
 701: Char    HISTSUB;        /* auto-substitute character */
 702: 
 703: /*
 704:  * strings.h:
 705:  */
 706: #ifndef SHORT_STRINGS
 707: #define Strchr(a, b)        strchr(a, b)
 708: #define Strrchr(a, b)   strrchr(a, b)
 709: #define Strcat(a, b)        strcat(a, b)
 710: #define Strncat(a, b, c)    strncat(a, b, c)
 711: #define Strcpy(a, b)        strcpy(a, b)
 712: #define Strncpy(a, b, c)    strncpy(a, b, c)
 713: #define Strlen(a)       strlen(a)
 714: #define Strcmp(a, b)        strcmp(a, b)
 715: #define Strncmp(a, b, c)    strncmp(a, b, c)
 716: 
 717: #define Strspl(a, b)        strspl(a, b)
 718: #define Strsave(a)      strsave(a)
 719: #define Strend(a)       strend(a)
 720: #define Strstr(a, b)        strstr(a, b)
 721: 
 722: #define str2short(a)        (a)
 723: #define blk2short(a)        saveblk(a)
 724: #define short2blk(a)        saveblk(a)
 725: #define short2str(a)        (a)
 726: #define short2qstr(a)       (a)
 727: #else
 728: #define Strchr(a, b)    s_strchr(a, b)
 729: #define Strrchr(a, b)       s_strrchr(a, b)
 730: #define Strcat(a, b)        s_strcat(a, b)
 731: #define Strncat(a, b, c)    s_scat(a, b, c)
 732: #define Strcpy(a, b)        s_strcpy(a, b)
 733: #define Strncpy(a, b, c)    s_scpy(a, b, c)
 734: #define Strlen(a)       s_strlen(a)
 735: #define Strcmp(a, b)        s_strcmp(a, b)
 736: #define Strncmp(a, b, c)    s_scmp(a, b, c)
 737: 
 738: #define Strspl(a, b)        s_strspl(a, b)
 739: #define Strsave(a)      s_strsave(a)
 740: #define Strend(a)       s_strend(a)
 741: #define Strstr(a, b)        s_strstr(a, b)
 742: #endif
 743: 
 744: #define NOSTR   ((Char *) 0)
 745: /*
 746:  * setname is a macro to save space (see sh.err.c)
 747:  */
 748: char   *bname;
 749: 
 750: #define setname(a)  (bname = (a))
 751: 
 752: #ifdef VFORK
 753: Char   *Vsav;
 754: Char   *Vdp;
 755: Char   *Vexpath;
 756: char  **Vt;
 757: 
 758: #endif				/* VFORK */
 759: 
 760: Char  **evalvec;
 761: Char   *evalp;
 762: 
 763: extern struct mesg {
 764:     char   *iname;      /* name from /usr/include */
 765:     char   *pname;      /* print name */
 766: }       mesg[];
 767: 
 768: /* word_chars is set by default to WORD_CHARS but can be overridden by
 769:    the worchars variable--if unset, reverts to WORD_CHARS */
 770: 
 771: Char   *word_chars;
 772: 
 773: #define WORD_CHARS "*?_-.[]~="  /* default chars besides alnums in words */
 774: 
 775: Char   *STR_SHELLPATH;
 776: 
 777: #ifdef _PATH_BSHELL
 778: Char   *STR_BSHELL;
 779: #endif
 780: Char   *STR_WORD_CHARS;
 781: Char  **STR_environ;
 782: 
 783: /*
 784:  * ANSIisms...
 785:  */
 786: #ifndef __P
 787: # if __STDC__
 788: #  define __P(a) a
 789: # else
 790: #  define __P(a) ()
 791: #  define const
 792: #  define volatile
 793: # endif
 794: #endif
 795: 
 796: #include "tc.h"
 797: #include "sh.decls.h"
 798: 
 799: #endif				/* _h_sh */

Defined functions

sigret_t defined in line 424; never used

Defined variables

STR_BSHELL defined in line 778; used 2 times
STR_SHELLPATH defined in line 775; used 4 times
STR_WORD_CHARS defined in line 780; used 3 times
Vdp defined in line 754; used 5 times
Vexpath defined in line 755; used 6 times
Vsav defined in line 753; used 5 times
Vt defined in line 756; used 7 times
alhistp defined in line 642; used 8 times
alhistt defined in line 643; used 3 times
alvec defined in line 644; used 7 times
arginp defined in line 332; used 17 times
bname defined in line 748; used 13 times
cantell defined in line 487; used 7 times
chktim defined in line 363; never used
doldol defined in line 360; used 3 times
ffile defined in line 334; used 4 times
gid defined in line 362; used 3 times
gointr defined in line 421; used 16 times
havhash defined in line 321; used 8 times
intact defined in line 313; used 5 times
is1atty defined in line 326; used 6 times
is2atty defined in line 327; used 4 times
lap defined in line 519; used 12 times
lastev defined in line 698; used 6 times
lineloc defined in line 485; used 1 times
neednote defined in line 316; used 3 times
noexec defined in line 317; used 7 times
onelflg defined in line 333; used 14 times
opgrp defined in line 368; used 5 times
paraml defined in line 696; used 21 times
pargcp defined in line 674; used 4 times
pargs defined in line 672; used 4 times
pjobs defined in line 318; used 4 times
pnleft defined in line 673; used 3 times
reslab defined in line 412; used 6 times
ru0 defined in line 346; used 6 times
shpgrp defined in line 364; used 13 times
shtemp defined in line 338; used 2 times
shtimes defined in line 353; used 4 times
time0 defined in line 349; used 9 times
timflg defined in line 320; used 2 times
whyles defined in line 615; used 37 times
word_chars defined in line 771; used 3 times

Defined struct's

Bin defined in line 464; used 2 times
Hist defined in line 687; used 44 times
command defined in line 528; used 110 times
mesg defined in line 763; used 2 times
srch defined in line 385; used 6 times
varent defined in line 622; used 142 times
whyle defined in line 609; used 20 times
wordent defined in line 493; used 266 times

Defined typedef's

Char defined in line 53; used 1418 times
bool defined in line 225; used 158 times
memalign_t defined in line 230; used 19 times

Defined macros

ATTRIBUTES defined in line 451; used 2 times
BOLD defined in line 448; used 11 times
BUFSIZ defined in line 83; used 1 times
  • in line 82
DOALL defined in line 510; used 5 times
DODOL defined in line 508; used 8 times
DOEXCL defined in line 509; used 13 times
FOLDSTD defined in line 98; used 3 times
FORKSLEEP defined in line 86; used 1 times
FSHDIAG defined in line 97; used 6 times
FSHIN defined in line 95; used 4 times
FSHOUT defined in line 96; used 6 times
F_NICE defined in line 554; used 8 times
F_NOHUP defined in line 555; used 6 times
F_OVERWRITE defined in line 551; used 2 times
F_PIPEIN defined in line 545; used 6 times
F_PIPEOUT defined in line 546; used 9 times
F_REPEAT defined in line 553; used 5 times
F_SAVE defined in line 541; used 1 times
F_TIME defined in line 556; used 5 times
F_VER defined in line 558; used 8 times
G_APPEND defined in line 296; used 1 times
G_IGNORE defined in line 295; used 2 times
MAILINTVL defined in line 87; used 3 times
MAXHOSTNAMELEN defined in line 286; used 1 times
MAXNAMLEN defined in line 658; used 2 times
MAXPATHLEN defined in line 654; used 7 times
NODE_AND defined in line 535; used 3 times
NODE_LIST defined in line 533; used 3 times
NODE_OR defined in line 534; used 2 times
NODE_PAREN defined in line 531; used 4 times
NODE_PIPE defined in line 532; used 1 times
SIGN_EXTEND_CHAR defined in line 276; used 1 times
Strend defined in line 740; used 5 times
Strncat defined in line 731; never used
Strstr defined in line 741; used 2 times
T_BREAK defined in line 584; used 7 times
T_BRKSW defined in line 585; used 4 times
T_CASE defined in line 586; used 1 times
T_DEFAULT defined in line 587; used 1 times
T_ELSE defined in line 588; used 4 times
T_END defined in line 589; used 1 times
T_ENDIF defined in line 590; used 1 times
T_ENDSW defined in line 591; used 1 times
T_EXIT defined in line 592; used 1 times
T_FOREACH defined in line 593; used 2 times
T_GOTO defined in line 594; used 8 times
T_IF defined in line 595; used 5 times
T_LABEL defined in line 596; used 1 times
T_LET defined in line 597; used 1 times
T_SET defined in line 598; used 1 times
T_SWITCH defined in line 599; used 8 times
T_TEST defined in line 600; never used
T_THEN defined in line 601; never used
T_WHILE defined in line 602; used 2 times
UNDER defined in line 447; used 13 times
WORD_CHARS defined in line 773; used 1 times
_BSD defined in line 134; used 1 times
_BSD_INCLUDES defined in line 135; used 1 times
_GNU_STDLIB_H defined in line 163; never used
__P defined in line 790; used 304 times
_h_sh defined in line 38; used 1 times
  • in line 37
blk2short defined in line 723; used 3 times
btell defined in line 478; used 8 times
calloc defined in line 244; used 2 times
const defined in line 791; never used
dirent defined in line 211; never used
fblocks defined in line 475; used 9 times
fbobp defined in line 473; used 5 times
fbuf defined in line 476; used 18 times
free defined in line 242; used 2 times
fseekp defined in line 472; used 22 times
getpgrp defined in line 150; used 2 times
malloc defined in line 241; used 2 times
realloc defined in line 243; used 2 times
setpgrp defined in line 151; used 2 times
short2qstr defined in line 726; used 1 times
short2str defined in line 725; used 201 times
sigret_t defined in line 68; never used
strchr defined in line 219; used 3 times
strrchr defined in line 220; used 3 times
v_left defined in line 629; used 29 times
v_parent defined in line 631; used 20 times
v_right defined in line 630; used 32 times
volatile defined in line 792; never used
xfree defined in line 256; used 164 times

Usage of this include

sh.h used 45 times
Last modified: 1996-03-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 121
Valid CSS Valid XHTML 1.0 Strict