home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / Shells / tcsh / Source / sh.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  27.6 KB  |  994 lines

  1. /* $Header: /u/christos/src/tcsh-6.03/RCS/sh.h,v 3.47 1992/11/13 08:47:03 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. #include "config.h"
  41.  
  42. #ifndef EXTERN
  43. # define EXTERN extern
  44. #endif /* EXTERN */
  45. /*
  46.  * Sanity
  47.  */
  48. #if defined(_POSIX_SOURCE) && !defined(POSIX)
  49. # define POSIX
  50. #endif 
  51.  
  52. #if defined(POSIXJOBS) && !defined(BSDJOBS)
  53. # define BSDJOBS
  54. #endif 
  55.  
  56. #if defined(POSIXSIGS) && !defined(BSDSIGS)
  57. # define BSDSIGS
  58. #endif
  59.  
  60. #ifdef SHORT_STRINGS
  61. typedef short Char;
  62. # define SAVE(a) (Strsave(str2short(a)))
  63. #else
  64. typedef char Char;
  65. # define SAVE(a) (strsave(a))
  66. #endif 
  67.  
  68. #ifdef PURIFY
  69. /* Re-define those, cause purify might use them */
  70. # define xprintf     printf
  71. # define xsprintf    sprintf
  72. # define xvprintf    vprintf
  73. /* exit normally, allowing purify to trace leaks */
  74. # define _exit        exit
  75. #endif /* PURIFY */
  76.  
  77. /*
  78.  * If your compiler complains, then you can either
  79.  * throw it away and get gcc or, use the following define
  80.  * and get rid of the typedef.
  81.  * [The 4.2/3BSD vax compiler does not like that]
  82.  */
  83. #ifdef SIGVOID
  84. # if (defined(vax) || defined(uts)) && !defined(__GNUC__)
  85. #  define sigret_t void
  86. # else
  87. typedef void sigret_t;
  88. # endif 
  89. #else
  90. typedef int sigret_t;
  91. #endif /* SIGVOID */
  92.  
  93.  
  94. /*
  95.  * Fundamental definitions which may vary from system to system.
  96.  *
  97.  *    BUFSIZE        The i/o buffering size; also limits word size
  98.  *    MAILINTVL    How often to mailcheck; more often is more expensive
  99.  */
  100. #ifdef BUFSIZE
  101. # if       BUFSIZE < 1024
  102. #  undef   BUFSIZE
  103. #  define  BUFSIZE    1024    /* buffer size should be no less than this */
  104. # endif
  105. #else
  106. # define   BUFSIZE    1024
  107. #endif /* BUFSIZE */
  108.  
  109. #define FORKSLEEP    10    /* delay loop on non-interactive fork failure */
  110. #define    MAILINTVL    600    /* 10 minutes */
  111.  
  112. #ifndef INBUFSIZE
  113. # define INBUFSIZE    2*BUFSIZE /* Num input characters on the command line */
  114. #endif /* INBUFSIZE */
  115.  
  116.  
  117. /*
  118.  * What our builtin echo looks like
  119.  */
  120. #define NONE_ECHO    0
  121. #define BSD_ECHO    1
  122. #define SYSV_ECHO    2
  123. #define BOTH_ECHO    (BSD_ECHO|SYSV_ECHO)
  124.  
  125. #ifndef ECHO_STYLE
  126. # if SYSVREL > 0
  127. #  define ECHO_STYLE SYSV_ECHO
  128. # else /* SYSVREL == 0 */
  129. #  define ECHO_STYLE BSD_ECHO
  130. # endif /* SYSVREL */
  131. #endif /* ECHO_STYLE */
  132.  
  133. /*
  134.  * The shell moves std in/out/diag and the old std input away from units
  135.  * 0, 1, and 2 so that it is easy to set up these standards for invoked
  136.  * commands.
  137.  */
  138. #define    FSHTTY    15        /* /dev/tty when manip pgrps */
  139. #define    FSHIN    16        /* Preferred desc for shell input */
  140. #define    FSHOUT    17        /* ... shell output */
  141. #define    FSHDIAG    18        /* ... shell diagnostics */
  142. #define    FOLDSTD    19        /* ... old std input */
  143.  
  144. #ifdef PROF
  145. #define    xexit(n)    done(n)
  146. #endif 
  147.  
  148. #ifdef cray
  149. # define word word_t           /* sys/types.h defines word.. bad move! */
  150. #endif
  151.  
  152. #include <sys/types.h>
  153.  
  154. #ifdef cray
  155. # undef word
  156. #endif 
  157.  
  158. /* 
  159.  * Path separator in environment variables
  160.  */
  161. #ifndef PATHSEP
  162. # ifdef __EMX__
  163. #  define PATHSEP ';'
  164. # else /* unix */
  165. #  define PATHSEP ':'
  166. # endif /* __EMX__ */
  167. #endif /* !PATHSEP */
  168.  
  169. /*
  170.  * This macro compares the st_dev field of struct stat. On aix on ibmESA
  171.  * st_dev is a structure, so comparison does not work. 
  172.  */
  173. #ifndef DEV_DEV_COMPARE
  174. # define DEV_DEV_COMPARE(x,y)   ((x) == (y))
  175. #endif /* DEV_DEV_COMPARE */
  176.  
  177. #ifdef _SEQUENT_
  178. # include <sys/procstats.h>
  179. #endif /* _SEQUENT_ */
  180. #if defined(POSIX) || SYSVREL > 0
  181. # include <sys/times.h>
  182. #endif /* POSIX || SYSVREL > 0 */
  183.  
  184. #ifdef NLS
  185. # include <locale.h>
  186. #endif 
  187.  
  188. #if !defined(_MINIX) && !defined(_VMS_POSIX)
  189. #include <sys/param.h>
  190. #endif /* _MINIX && vmsposix atp */
  191. #include <sys/stat.h>
  192.  
  193. #if defined(BSDTIMES) || defined(BSDLIMIT)
  194. # include <sys/time.h>
  195. # if SYSVREL>3 && !defined(sgi)
  196. #  include "/usr/ucbinclude/sys/resource.h"
  197. # else
  198. #  include <sys/resource.h>
  199. # endif /* SYSVREL>3 */
  200. #endif /* BSDTIMES */
  201.  
  202. #ifndef POSIX
  203. # ifdef TERMIO
  204. #  include <termio.h>
  205. # else /* SGTTY */
  206. #  include <sgtty.h>
  207. # endif /* TERMIO */
  208. #else /* POSIX */
  209. # include <termios.h>
  210. # if SYSVREL > 3
  211. #  undef TIOCGLTC    /* we don't need those, since POSIX has them */
  212. #  undef TIOCSLTC
  213. #  undef CSWTCH
  214. #  define CSWTCH _POSIX_VDISABLE    /* So job control works */
  215. # endif /* SYSVREL > 3 */
  216. #endif /* POSIX */
  217. #ifdef DGUX
  218. #  undef CSWTCH
  219. #  define CSWTCH _POSIX_VDISABLE    /* So job control works */
  220. #endif /* DGUX */
  221.  
  222. #ifdef sonyrisc
  223. # include <sys/ttold.h>
  224. #endif /* sonyrisc */
  225.  
  226. #ifdef POSIX
  227. /*
  228.  * We should be using setpgid and setpgid
  229.  * by now, but in some systems we use the
  230.  * old routines...
  231.  */
  232. # define getpgrp __getpgrp
  233. # define setpgrp __setpgrp
  234. # include <unistd.h>
  235. # undef getpgrp
  236. # undef setpgrp
  237. extern int getpgrp();
  238. extern int setpgrp();
  239.  
  240. /*
  241.  * the gcc+protoize version of <stdlib.h>
  242.  * redefines malloc(), so we define the following
  243.  * to avoid it.
  244.  */
  245. # ifdef linux
  246. #  define NO_FIX_MALLOC
  247. #  include <stdlib.h>
  248. # else /* linux */
  249. #  define _GNU_STDLIB_H
  250. #  define malloc __malloc
  251. #  define free __free
  252. #  define calloc __calloc
  253. #  define realloc __realloc
  254. #  include <stdlib.h>
  255. #  undef malloc
  256. #  undef free
  257. #  undef calloc
  258. #  undef realloc
  259. # endif /* linux */
  260. # include <limits.h>
  261. #endif /* POSIX */
  262.  
  263. #if SYSVREL > 0 || defined(_IBMR2) || defined(_MINIX)
  264. # if !defined(pyr) && !defined(stellar)
  265. #  include <time.h>
  266. #  ifdef _MINIX
  267. #   define HZ CLOCKS_PER_SEC
  268. #  endif /* _MINIX */
  269. # endif /* !pyr && !stellar */
  270. #endif /* SYSVREL > 0 ||  _IBMR2 */
  271.  
  272. #if !((defined(SUNOS4) || defined(_MINIX)) && defined(TERMIO))
  273. # if !defined(COHERENT) && !defined(_VMS_POSIX)
  274. #  include <sys/ioctl.h>
  275. # endif
  276. #endif 
  277.  
  278. #if !defined(FIOCLEX) && defined(SUNOS4)
  279. # include <sys/filio.h>
  280. #endif /* !FIOCLEX && SUNOS4 */
  281.  
  282. #if !defined(_MINIX) && !defined(COHERENT)
  283. # include <sys/file.h>
  284. #endif    /* !_MINIX && !COHERENT */
  285.  
  286. #if !defined(O_RDONLY) || !defined(O_NDELAY)
  287. # include <fcntl.h>
  288. #endif 
  289.  
  290. #include <errno.h>
  291.  
  292. #include <setjmp.h>
  293.  
  294. #if __STDC__
  295. # include <stdarg.h>
  296. #else
  297. #ifdef    _MINIX
  298. # include "mi.varargs.h"
  299. #else
  300. # include <varargs.h>
  301. #endif    /* _MINIX */
  302. #endif 
  303.  
  304. #ifdef DIRENT
  305. # include <dirent.h>
  306. #else
  307. # ifdef hp9000s500
  308. #  include <ndir.h>
  309. # else
  310. #  include <sys/dir.h>
  311. # endif
  312. # define dirent direct
  313. #endif /* DIRENT */
  314. #if defined(hpux) || defined(sgi) || defined(OREO) || defined(COHERENT)
  315. # include <stdio.h>    /* So the fgetpwent() prototypes work */
  316. #endif /* hpux || sgi || OREO || COHERENT */
  317. #include <pwd.h>
  318. #ifdef PW_SHADOW
  319. # include <shadow.h>
  320. #endif /* PW_SHADOW */
  321. #ifdef PW_AUTH
  322. # include <auth.h>
  323. #endif /* PW_AUTH */
  324. #ifdef BSD
  325. # include <strings.h>
  326. # define strchr(a, b) index(a, b)
  327. # define strrchr(a, b) rindex(a, b)
  328. #else
  329. # include <string.h>
  330. #endif /* BSD */
  331.  
  332. /*
  333.  * IRIX-5.0 has <sys/cdefs.h>, but most system include files do not
  334.  * include it yet, so we include it here
  335.  */
  336. #if defined(sgi) && SYSVREL > 3
  337. # include <sys/cdefs.h>
  338. #endif /* sgi && SYSVREL > 3 */
  339.  
  340. /*
  341.  * ANSIisms... These must be *after* the system include and 
  342.  * *before* our includes, so that BSDreno has time to define __P
  343.  */
  344. #ifndef __P
  345. # if __STDC__
  346. #  define __P(a) a
  347. # else
  348. #  define __P(a) ()
  349. #  define const
  350. #  ifndef apollo
  351. #   define volatile    /* Apollo 'c' extensions need this */
  352. #  endif /* apollo */
  353. # endif 
  354. #endif 
  355.  
  356.  
  357. typedef int bool;
  358.  
  359. #include "sh.types.h"
  360.  
  361. #ifndef lint
  362. typedef ptr_t memalign_t;
  363. #else
  364. typedef union {
  365.     char    am_char, *am_char_p;
  366.     short   am_short, *am_short_p;
  367.     int     am_int, *am_int_p;
  368.     long    am_long, *am_long_p;
  369.     float   am_float, *am_float_p;
  370.     double  am_double, *am_double_p;
  371. }      *memalign_t;
  372.  
  373. # define malloc        lint_malloc
  374. # define free        lint_free
  375. # define realloc    lint_realloc
  376. # define calloc        lint_calloc
  377. #endif 
  378.  
  379. #ifdef MDEBUG
  380. extern memalign_t    DebugMalloc    __P((unsigned, char *, int));
  381. extern memalign_t    DebugRealloc    __P((ptr_t, unsigned, char *, int));
  382. extern memalign_t    DebugCalloc    __P((unsigned, unsigned, char *, int));
  383. extern void        DebugFree    __P((ptr_t, char *, int));
  384. # define xmalloc(i)      DebugMalloc(i, __FILE__, __LINE__)
  385. # define xrealloc(p, i)((p) ? DebugRealloc(p, i, __FILE__, __LINE__) : \
  386.                   DebugMalloc(i, __FILE__, __LINE__))
  387. # define xcalloc(n, s)    DebugCalloc(n, s, __FILE__, __LINE__)
  388. # define xfree(p)        if (p) DebugFree(p, __FILE__, __LINE__)
  389. #else
  390. # ifdef SYSMALLOC
  391. #  define xmalloc(i)        smalloc(i)
  392. #  define xrealloc(p, i)    srealloc(p, i)
  393. #  define xcalloc(n, s)        scalloc(n, s)
  394. #  define xfree(p)        sfree(p)
  395. # else
  396. #  define xmalloc(i)          malloc(i)
  397. #  define xrealloc(p, i)    realloc(p, i)
  398. #  define xcalloc(n, s)        calloc(n, s)
  399. #  define xfree(p)            free(p)
  400. # endif /* SYSMALLOC */
  401. #endif /* MDEBUG */
  402. #include "sh.char.h"
  403. #include "sh.err.h"
  404. #include "sh.dir.h"
  405. #include "sh.proc.h"
  406.  
  407. #include "pathnames.h"
  408.  
  409.  
  410. /*
  411.  * C shell
  412.  *
  413.  * Bill Joy, UC Berkeley
  414.  * October, 1978; May 1980
  415.  *
  416.  * Jim Kulp, IIASA, Laxenburg Austria
  417.  * April, 1980
  418.  */
  419.  
  420. #if !defined(MAXNAMLEN) && defined(_D_NAME_MAX)
  421. # define MAXNAMLEN _D_NAME_MAX
  422. #endif /* MAXNAMLEN */
  423.  
  424. #ifndef MAXHOSTNAMELEN
  425. # define MAXHOSTNAMELEN    255
  426. #endif /* MAXHOSTNAMELEN */
  427.  
  428.  
  429.  
  430. #define    eq(a, b)    (Strcmp(a, b) == 0)
  431.  
  432. /* globone() flags */
  433. #define G_ERROR        0    /* default action: error if multiple words */
  434. #define G_IGNORE    1    /* ignore the rest of the words           */
  435. #define G_APPEND    2    /* make a sentence by cat'ing the words    */
  436.  
  437. /*
  438.  * Global flags
  439.  */
  440. EXTERN bool    chkstop;        /* Warned of stopped jobs... allow exit */
  441.  
  442. #if (defined(FIOCLEX) && defined(FIONCLEX)) || defined(F_SETFD)
  443. # define CLOSE_ON_EXEC
  444. #else
  445. EXTERN bool    didcch;        /* Have closed unused fd's for child */
  446. #endif /* (FIOCLEX && FIONCLEX) || F_SETFD */
  447.  
  448. EXTERN bool    didfds;        /* Have setup i/o fd's for child */
  449. EXTERN bool    doneinp;        /* EOF indicator after reset from readc */
  450. EXTERN bool    exiterr;        /* Exit if error or non-zero exit status */
  451. EXTERN bool    child;        /* Child shell ... errors cause exit */
  452. EXTERN bool    haderr;        /* Reset was because of an error */
  453. EXTERN bool    intty;        /* Input is a tty */
  454. EXTERN bool    intact;        /* We are interactive... therefore prompt */
  455. EXTERN bool    justpr;        /* Just print because of :p hist mod */
  456. EXTERN bool    loginsh;        /* We are a loginsh -> .login/.logout */
  457. EXTERN bool    neednote;    /* Need to pnotify() */
  458. EXTERN bool    noexec;        /* Don't execute, just syntax check */
  459. EXTERN bool    pjobs;        /* want to print jobs if interrupted */
  460. EXTERN bool    setintr;        /* Set interrupts on/off -> Wait intr... */
  461. EXTERN bool    timflg;        /* Time the next waited for command */
  462. EXTERN bool    havhash;        /* path hashing is available */
  463. EXTERN bool    editing;        /* doing filename expansion and line editing */
  464. EXTERN bool    bslash_quote;    /* PWP: tcsh-style quoting?  (in sh.c) */
  465. EXTERN bool    isoutatty;    /* is SHOUT a tty */
  466. EXTERN bool    isdiagatty;    /* is SHDIAG a tty */
  467. EXTERN bool    is1atty;        /* is file descriptor 1 a tty (didfds mode) */
  468. EXTERN bool    is2atty;        /* is file descriptor 2 a tty (didfds mode) */
  469.  
  470. /*
  471.  * Global i/o info
  472.  */
  473. EXTERN Char   *arginp;        /* Argument input for sh -c and internal `xx` */
  474. EXTERN int     onelflg;        /* 2 -> need line for -t, 1 -> exit on read */
  475. extern Char   *ffile;        /* Name of shell file for $0 */
  476.  
  477. extern char *seterr;        /* Error message from scanner/parser */
  478. extern int errno;        /* Error from C library routines */
  479. EXTERN Char   *shtemp;        /* Temp name for << shell files in /tmp */
  480.  
  481. #ifdef BSDTIMES
  482. EXTERN struct timeval time0;    /* Time at which the shell started */
  483. EXTERN struct rusage ru0;
  484. #else
  485. # ifdef _SEQUENT_
  486. EXTERN timeval_t time0;        /* time at which shell started */
  487. EXTERN struct process_stats ru0;
  488. # else /* _SEQUENT_ */
  489. #  ifndef POSIX
  490. EXTERN time_t  time0;        /* time at which shell started */
  491. #  else    /* POSIX */
  492. EXTERN clock_t time0;        /* time at which shell started */
  493. EXTERN clock_t clk_tck;
  494. #  endif /* POSIX */
  495. EXTERN struct tms shtimes;    /* shell and child times for process timing */
  496. # endif /* _SEQUENT_ */
  497. #endif /* BSDTIMES */
  498.  
  499. #ifndef HZ
  500. # define HZ    100        /* for division into seconds */
  501. #endif
  502.  
  503. /*
  504.  * Miscellany
  505.  */
  506. EXTERN Char   *doldol;        /* Character pid for $$ */
  507. EXTERN int     backpid;        /* pid of the last background job */
  508.  
  509. /*
  510.  * Ideally these should be uid_t, gid_t, pid_t. I cannot do that right now
  511.  * cause pid's could be unsigned and that would break our -1 flag, and 
  512.  * uid_t and gid_t are not defined in all the systems so I would have to
  513.  * make special cases for them. In the future...
  514.  */
  515. EXTERN int     uid, euid,     /* Invokers real and effective */
  516.            gid, egid;    /* User and group ids */
  517. EXTERN int     opgrp,        /* Initial pgrp and tty pgrp */
  518.                shpgrp,        /* Pgrp of shell */
  519.                tpgrp;        /* Terminal process group */
  520.                 /* If tpgrp is -1, leave tty alone! */
  521.  
  522. EXTERN Char    PromptBuf[INBUFSIZE*2]; /* buffer for the actual printed prompt.
  523.                        * this must be large enough to contain
  524.                        * the input line and the prompt, in
  525.                        * case a correction occured...
  526.                        */
  527.  
  528. /*
  529.  * To be able to redirect i/o for builtins easily, the shell moves the i/o
  530.  * descriptors it uses away from 0,1,2.
  531.  * Ideally these should be in units which are closed across exec's
  532.  * (this saves work) but for version 6, this is not usually possible.
  533.  * The desired initial values for these descriptors are defined in
  534.  * sh.local.h.
  535.  */
  536. EXTERN int   SHIN;        /* Current shell input (script) */
  537. EXTERN int   SHOUT;        /* Shell output */
  538. EXTERN int   SHDIAG;        /* Diagnostic output... shell errs go here */
  539. EXTERN int   OLDSTD;        /* Old standard input (def for cmds) */
  540.  
  541. /*
  542.  * Error control
  543.  *
  544.  * Errors in scanning and parsing set up an error message to be printed
  545.  * at the end and complete.  Other errors always cause a reset.
  546.  * Because of source commands and .cshrc we need nested error catches.
  547.  */
  548.  
  549. #ifdef NO_STRUCT_ASSIGNMENT
  550.  
  551. typedef jmp_buf jmp_buf_t;
  552.  
  553. /* bugfix by Jak Kirman @ Brown U.: remove the (void) cast here, see sh.c */
  554. # define setexit()  setjmp(reslab)
  555. # define reset()    longjmp(reslab, 1)
  556. # define getexit(a) (void) memmove((ptr_t)(a), (ptr_t)reslab, sizeof(reslab))
  557. # define resexit(a) (void) memmove((ptr_t)reslab, ((ptr_t)(a)), sizeof(reslab))
  558.  
  559. #else
  560.  
  561. typedef struct { jmp_buf j; } jmp_buf_t;
  562.  
  563. # define setexit()  setjmp(reslab.j)
  564. # define reset()    longjmp(reslab.j, 1)
  565. # define getexit(a) ((a) = reslab)
  566. # define resexit(a) (reslab = (a))
  567.  
  568. #endif    /* NO_STRUCT_ASSIGNMENT */
  569.  
  570. extern jmp_buf_t reslab;
  571.  
  572. EXTERN Char   *gointr;        /* Label for an onintr transfer */
  573.  
  574. EXTERN sigret_t (*parintr) ();    /* Parents interrupt catch */
  575. EXTERN sigret_t (*parterm) ();    /* Parents terminate catch */
  576.  
  577. /*
  578.  * Lexical definitions.
  579.  *
  580.  * All lexical space is allocated dynamically.
  581.  * The eighth/sixteenth bit of characters is used to prevent recognition,
  582.  * and eventually stripped.
  583.  */
  584. #define        META        0200
  585. #define        ASCII        0177
  586. #ifdef SHORT_STRINGS
  587. # define    QUOTE     ((Char)    0100000)/* 16nth char bit used for 'ing */
  588. # define    TRIM        0077777    /* Mask to strip quote bit */
  589. # define    UNDER        0040000    /* Underline flag */
  590. # define    BOLD        0020000    /* Bold flag */
  591. # define    STANDOUT    0010000    /* Standout flag */
  592. # define    LITERAL        0004000    /* Literal character flag */
  593. # define    ATTRIBUTES    0074000    /* The bits used for attributes */
  594. # define    CHAR        0000377    /* Mask to mask out the character */
  595. #else
  596. # define    QUOTE     ((Char)    0200)    /* Eighth char bit used for 'ing */
  597. # define    TRIM        0177    /* Mask to strip quote bit */
  598. # define    UNDER        0000000    /* No extra bits to do both */
  599. # define    BOLD        0000000    /* Bold flag */
  600. # define    STANDOUT    META    /* Standout flag */
  601. # define    LITERAL        0000000    /* Literal character flag */
  602. # define    ATTRIBUTES    0200    /* The bits used for attributes */
  603. # define    CHAR        0000177    /* Mask to mask out the character */
  604. #endif 
  605.  
  606. EXTERN int     AsciiOnly;    /* If set only 7 bits expected in characters */
  607.  
  608. /*
  609.  * Each level of input has a buffered input structure.
  610.  * There are one or more blocks of buffered input for each level,
  611.  * exactly one if the input is seekable and tell is available.
  612.  * In other cases, the shell buffers enough blocks to keep all loops
  613.  * in the buffer.
  614.  */
  615. EXTERN struct Bin {
  616.     off_t   Bfseekp;        /* Seek pointer */
  617.     off_t   Bfbobp;        /* Seekp of beginning of buffers */
  618.     off_t   Bfeobp;        /* Seekp of end of buffers */
  619.     int     Bfblocks;        /* Number of buffer blocks */
  620.     Char  **Bfbuf;        /* The array of buffer blocks */
  621. }       B;
  622.  
  623. /*
  624.  * This structure allows us to seek inside aliases
  625.  */
  626. struct Ain {
  627.     int type;
  628. #define I_SEEK -1        /* Invalid seek */
  629. #define A_SEEK    0        /* Alias seek */
  630. #define F_SEEK    1        /* File seek */
  631. #define E_SEEK    2        /* Eval seek */
  632.     off_t f_seek;
  633.     Char **a_seek;
  634. } ;
  635.  
  636. extern int aret;        /* Type of last char returned */
  637. #define SEEKEQ(a, b) ((a)->type == (b)->type && \
  638.               (a)->f_seek == (b)->f_seek && \
  639.               (a)->a_seek == (b)->a_seek)
  640.  
  641. #define    fseekp    B.Bfseekp
  642. #define    fbobp    B.Bfbobp
  643. #define    feobp    B.Bfeobp
  644. #define    fblocks    B.Bfblocks
  645. #define    fbuf    B.Bfbuf
  646.  
  647. /*
  648.  * The shell finds commands in loops by reseeking the input
  649.  * For whiles, in particular, it reseeks to the beginning of the
  650.  * line the while was on; hence the while placement restrictions.
  651.  */
  652. EXTERN struct Ain lineloc;
  653.  
  654. EXTERN bool    cantell;        /* Is current source tellable ? */
  655.  
  656. /*
  657.  * Input lines are parsed into doubly linked circular
  658.  * lists of words of the following form.
  659.  */
  660. struct wordent {
  661.     Char   *word;
  662.     struct wordent *prev;
  663.     struct wordent *next;
  664. };
  665.  
  666. /*
  667.  * During word building, both in the initial lexical phase and
  668.  * when expanding $ variable substitutions, expansion by `!' and `$'
  669.  * must be inhibited when reading ahead in routines which are themselves
  670.  * processing `!' and `$' expansion or after characters such as `\' or in
  671.  * quotations.  The following flags are passed to the getC routines
  672.  * telling them which of these substitutions are appropriate for the
  673.  * next character to be returned.
  674.  */
  675. #define    DODOL    1
  676. #define    DOEXCL    2
  677. #define    DOALL    DODOL|DOEXCL
  678.  
  679. /*
  680.  * Labuf implements a general buffer for lookahead during lexical operations.
  681.  * Text which is to be placed in the input stream can be stuck here.
  682.  * We stick parsed ahead $ constructs during initial input,
  683.  * process id's from `$$', and modified variable values (from qualifiers
  684.  * during expansion in sh.dol.c) here.
  685.  */
  686. EXTERN Char   *lap;
  687.  
  688. /*
  689.  * Parser structure
  690.  *
  691.  * Each command is parsed to a tree of command structures and
  692.  * flags are set bottom up during this process, to be propagated down
  693.  * as needed during the semantics/exeuction pass (sh.sem.c).
  694.  */
  695. struct command {
  696.     short   t_dtyp;        /* Type of node          */
  697. #define    NODE_COMMAND    1    /* t_dcom <t_dlef >t_drit     */
  698. #define    NODE_PAREN    2    /* ( t_dspr ) <t_dlef >t_drit     */
  699. #define    NODE_PIPE    3    /* t_dlef | t_drit         */
  700. #define    NODE_LIST    4    /* t_dlef ; t_drit         */
  701. #define    NODE_OR        5    /* t_dlef || t_drit         */
  702. #define    NODE_AND    6    /* t_dlef && t_drit         */
  703.     short   t_dflg;        /* Flags, e.g. F_AMPERSAND|...      */
  704. /* save these when re-doing      */
  705. #ifndef apollo
  706. #define    F_SAVE    (F_NICE|F_TIME|F_NOHUP)    
  707. #else
  708. #define    F_SAVE    (F_NICE|F_TIME|F_NOHUP|F_VER)
  709. #endif 
  710. #define    F_AMPERSAND    (1<<0)    /* executes in background     */
  711. #define    F_APPEND    (1<<1)    /* output is redirected >>     */
  712. #define    F_PIPEIN    (1<<2)    /* input is a pipe         */
  713. #define    F_PIPEOUT    (1<<3)    /* output is a pipe         */
  714. #define    F_NOFORK    (1<<4)    /* don't fork, last ()ized cmd     */
  715. #define    F_NOINTERRUPT    (1<<5)    /* should be immune from intr's */
  716. /* spare */
  717. #define    F_STDERR    (1<<7)    /* redirect unit 2 with unit 1     */
  718. #define    F_OVERWRITE    (1<<8)    /* output was !             */
  719. #define    F_READ        (1<<9)    /* input redirection is <<     */
  720. #define    F_REPEAT    (1<<10)    /* reexec aft if, repeat,...     */
  721. #define    F_NICE        (1<<11)    /* t_nice is meaningful      */
  722. #define    F_NOHUP        (1<<12)    /* nohup this command          */
  723. #define    F_TIME        (1<<13)    /* time this command          */
  724. #define F_BACKQ        (1<<14)    /* command is in ``         */
  725. #ifdef apollo
  726. #define F_VER        (1<<15)    /* execute command under SYSTYPE */
  727. #endif 
  728.     union {
  729.     Char   *T_dlef;        /* Input redirect word          */
  730.     struct command *T_dcar;    /* Left part of list/pipe      */
  731.     }       L;
  732.     union {
  733.     Char   *T_drit;        /* Output redirect word      */
  734.     struct command *T_dcdr;    /* Right part of list/pipe      */
  735.     }       R;
  736. #define    t_dlef    L.T_dlef
  737. #define    t_dcar    L.T_dcar
  738. #define    t_drit    R.T_drit
  739. #define    t_dcdr    R.T_dcdr
  740.     Char  **t_dcom;        /* Command/argument vector      */
  741.     struct command *t_dspr;    /* Pointer to ()'d subtree      */
  742.     short   t_nice;
  743. #ifdef F_VER
  744.     short   t_systype;
  745. #endif 
  746. };
  747.  
  748.  
  749. /*
  750.  * The keywords for the parser
  751.  */
  752. #define    TC_BREAK    0
  753. #define    TC_BRKSW    1
  754. #define    TC_CASE        2
  755. #define    TC_DEFAULT     3
  756. #define    TC_ELSE        4
  757. #define    TC_END        5
  758. #define    TC_ENDIF    6
  759. #define    TC_ENDSW    7
  760. #define    TC_EXIT        8
  761. #define    TC_FOREACH    9
  762. #define    TC_GOTO        10
  763. #define    TC_IF        11
  764. #define    TC_LABEL    12
  765. #define    TC_LET        13
  766. #define    TC_SET        14
  767. #define    TC_SWITCH    15
  768. #define    TC_TEST        16
  769. #define    TC_THEN        17
  770. #define    TC_WHILE    18
  771.  
  772. /*
  773.  * These are declared here because they want to be
  774.  * initialized in sh.init.c (to allow them to be made readonly)
  775.  */
  776.  
  777. extern struct biltins {
  778.     char   *bname;
  779. #if defined(hpux) && defined(__STDC__) && !defined(__GNUC__)
  780.     /* Avoid hpux ansi mode spurious warnings */
  781.     void    (*bfunct) ();
  782. #else
  783.     void    (*bfunct) __P((Char **, struct command *));
  784. #endif /* hpux && __STDC__ && !__GNUC__ */
  785.     int     minargs, maxargs;
  786. }       bfunc[];
  787. extern int nbfunc;
  788.  
  789. extern struct srch {
  790.     char   *s_name;
  791.     int     s_value;
  792. }       srchn[];
  793. extern int nsrchn;
  794.  
  795. /*
  796.  * Structure defining the existing while/foreach loops at this
  797.  * source level.  Loops are implemented by seeking back in the
  798.  * input.  For foreach (fe), the word list is attached here.
  799.  */
  800. EXTERN struct whyle {
  801.     struct Ain   w_start;    /* Point to restart loop */
  802.     struct Ain   w_end;        /* End of loop (0 if unknown) */
  803.     Char  **w_fe, **w_fe0;    /* Current/initial wordlist for fe */
  804.     Char   *w_fename;        /* Name for fe */
  805.     struct whyle *w_next;    /* Next (more outer) loop */
  806. }      *whyles;
  807.  
  808. /*
  809.  * Variable structure
  810.  *
  811.  * Aliases and variables are stored in AVL balanced binary trees.
  812.  */
  813. EXTERN struct varent {
  814.     Char  **vec;        /* Array of words which is the value */
  815.     Char   *v_name;        /* Name of variable/alias */
  816.     struct varent *v_link[3];    /* The links, see below */
  817.     int     v_bal;        /* Balance factor */
  818. }       shvhed, aliases;
  819.  
  820. #define v_left        v_link[0]
  821. #define v_right        v_link[1]
  822. #define v_parent    v_link[2]
  823.  
  824. #define adrof(v)    adrof1(v, &shvhed)
  825. #define value(v)    value1(v, &shvhed)
  826.  
  827. /*
  828.  * The following are for interfacing redo substitution in
  829.  * aliases to the lexical routines.
  830.  */
  831. EXTERN struct wordent *alhistp;    /* Argument list (first) */
  832. EXTERN struct wordent *alhistt;    /* Node after last in arg list */
  833. EXTERN Char  **alvec, *alvecp;    /* The (remnants of) alias vector */
  834.  
  835. /*
  836.  * Filename/command name expansion variables
  837.  */
  838. EXTERN int   gflag;        /* After tglob -> is globbing needed? */
  839.  
  840. #define MAXVARLEN 30        /* Maximum number of char in a variable name */
  841.  
  842. #ifndef MAXPATHLEN
  843. # define MAXPATHLEN 2048
  844. #endif /* MAXPATHLEN */
  845.  
  846. #ifndef MAXNAMLEN
  847. # define MAXNAMLEN 512
  848. #endif /* MAXNAMLEN */
  849.  
  850. #ifndef HAVENOLIMIT
  851. /*
  852.  * resource limits
  853.  */
  854. extern struct limits {
  855.     int     limconst;
  856.     char   *limname;
  857.     int     limdiv;
  858.     char   *limscale;
  859. } limits[];
  860. #endif /* !HAVENOLIMIT */
  861.  
  862. /*
  863.  * Variables for filename expansion
  864.  */
  865. extern Char **gargv;        /* Pointer to the (stack) arglist */
  866. extern long gargc;        /* Number args in gargv */
  867.  
  868. /*
  869.  * Variables for command expansion.
  870.  */
  871. extern Char **pargv;        /* Pointer to the argv list space */
  872. EXTERN Char   *pargs;        /* Pointer to start current word */
  873. EXTERN long    pnleft;        /* Number of chars left in pargs */
  874. EXTERN Char   *pargcp;        /* Current index into pargs */
  875.  
  876. /*
  877.  * History list
  878.  *
  879.  * Each history list entry contains an embedded wordlist
  880.  * from the scanner, a number for the event, and a reference count
  881.  * to aid in discarding old entries.
  882.  *
  883.  * Essentially "invisible" entries are put on the history list
  884.  * when history substitution includes modifiers, and thrown away
  885.  * at the next discarding since their event numbers are very negative.
  886.  */
  887. EXTERN struct Hist {
  888.     struct wordent Hlex;
  889.     int     Hnum;
  890.     int     Href;
  891.     time_t  Htime;
  892.     Char   *histline;
  893.     struct Hist *Hnext;
  894. }       Histlist;
  895.  
  896. EXTERN struct wordent paraml;    /* Current lexical word list */
  897. EXTERN int     eventno;        /* Next events number */
  898. EXTERN int     lastev;        /* Last event reference (default) */
  899.  
  900. EXTERN Char    HIST;        /* history invocation character */
  901. EXTERN Char    HISTSUB;        /* auto-substitute character */
  902.  
  903. /*
  904.  * To print system call errors...
  905.  */
  906. #ifndef linux
  907. extern char *sys_errlist[];
  908. extern int errno, sys_nerr;
  909. #endif /* !linux */
  910.  
  911. /*
  912.  * strings.h:
  913.  */
  914. #ifndef SHORT_STRINGS
  915. #define Strchr(a, b)          strchr(a, b)
  916. #define Strrchr(a, b)      strrchr(a, b)
  917. #define Strcat(a, b)          strcat(a, b)
  918. #define Strncat(a, b, c)     strncat(a, b, c)
  919. #define Strcpy(a, b)          strcpy(a, b)
  920. #define Strncpy(a, b, c)     strncpy(a, b, c)
  921. #define Strlen(a)        strlen(a)
  922. #define Strcmp(a, b)        strcmp(a, b)
  923. #define Strncmp(a, b, c)    strncmp(a, b, c)
  924.  
  925. #define Strspl(a, b)        strspl(a, b)
  926. #define Strsave(a)        strsave(a)
  927. #define Strend(a)        strend(a)
  928. #define Strstr(a, b)        strstr(a, b)
  929.  
  930. #define str2short(a)         (a)
  931. #define blk2short(a)         saveblk(a)
  932. #define short2blk(a)         saveblk(a)
  933. #define short2str(a)         strip(a)
  934. #else
  935. #define Strchr(a, b)       s_strchr(a, b)
  936. #define Strrchr(a, b)         s_strrchr(a, b)
  937. #define Strcat(a, b)          s_strcat(a, b)
  938. #define Strncat(a, b, c)     s_strncat(a, b, c)
  939. #define Strcpy(a, b)          s_strcpy(a, b)
  940. #define Strncpy(a, b, c)    s_strncpy(a, b, c)
  941. #define Strlen(a)        s_strlen(a)
  942. #define Strcmp(a, b)        s_strcmp(a, b)
  943. #define Strncmp(a, b, c)    s_strncmp(a, b, c)
  944.  
  945. #define Strspl(a, b)        s_strspl(a, b)
  946. #define Strsave(a)        s_strsave(a)
  947. #define Strend(a)        s_strend(a)
  948. #define Strstr(a, b)        s_strstr(a, b)
  949. #endif 
  950.  
  951. /*
  952.  * setname is a macro to save space (see sh.err.c)
  953.  */
  954. EXTERN char   *bname;
  955.  
  956. #define    setname(a)    (bname = (a))
  957.  
  958. #ifdef VFORK
  959. EXTERN Char   *Vsav;
  960. EXTERN Char   *Vdp;
  961. EXTERN Char   *Vexpath;
  962. EXTERN char  **Vt;
  963. #endif /* VFORK */
  964.  
  965. EXTERN Char  **evalvec;
  966. EXTERN Char   *evalp;
  967.  
  968. extern struct mesg {
  969.     char   *iname;        /* name from /usr/include */
  970.     char   *pname;        /* print name */
  971. }       mesg[];
  972.  
  973. /* word_chars is set by default to WORD_CHARS but can be overridden by
  974.    the worchars variable--if unset, reverts to WORD_CHARS */
  975.  
  976. EXTERN Char   *word_chars;
  977.  
  978. #define WORD_CHARS "*?_-.[]~="    /* default chars besides alnums in words */
  979.  
  980. EXTERN Char   *STR_SHELLPATH;
  981.  
  982. #ifdef _PATH_BSHELL
  983. EXTERN Char   *STR_BSHELL;
  984. #endif 
  985. EXTERN Char   *STR_WORD_CHARS;
  986. EXTERN Char  **STR_environ;
  987.  
  988. extern int     dont_free;    /* Tell free that we are in danger if we free */
  989.  
  990. #include "tc.h"
  991. #include "sh.decls.h"
  992.  
  993. #endif /* _h_sh */
  994.