home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / z / zsh220.zip / zsh2.2 / src / zsh.h < prev    next >
C/C++ Source or Header  |  1992-05-11  |  32KB  |  1,545 lines

  1. /*
  2.  *
  3.  * zsh.h - standard header file
  4.  *
  5.  * This file is part of zsh, the Z shell.
  6.  *
  7.  * This software is Copyright 1992 by Paul Falstad
  8.  *
  9.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  10.  * use this software as long as: there is no monetary profit gained
  11.  * specifically from the use or reproduction of this software, it is not
  12.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  13.  * included prominently in any copy made. 
  14.  *
  15.  * The author make no claims as to the fitness or correctness of this software
  16.  * for any use whatsoever, and it is provided as is. Any use of this software
  17.  * is at the user's own risk. 
  18.  *
  19.  */
  20.  
  21. #include "config.h"
  22.  
  23. #include <stdio.h>
  24. #include <ctype.h>
  25.  
  26. #ifdef HAS_STRING
  27. #include <string.h>
  28. #else
  29. #include <strings.h>
  30. #endif
  31.  
  32. #ifdef HAS_LOCALE
  33. #include <locale.h>
  34. #endif
  35.  
  36. #ifdef HAS_STDLIB
  37. #include <stdlib.h>
  38. #endif
  39.  
  40. #ifdef SYSV
  41. #include <sys/bsdtypes.h>
  42. #define _POSIX_SOURCE
  43. #include <sys/limits.h>
  44. #include <sys/sioctl.h>
  45. #define MAXPATHLEN PATH_MAX
  46. #define lstat stat
  47. extern int gethostname();
  48. #define sigmask(m) m
  49. #include <sys/dirent.h>
  50. #else
  51. #include <sys/types.h>        /* this is the key to the whole thing */
  52. #endif
  53.  
  54. #ifdef _IBMR2
  55. #undef _BSD   /* union wait SUCKS! */
  56. #include <sys/wait.h>
  57. #define _BSD
  58. #else
  59. #include <sys/wait.h>
  60. #endif
  61.  
  62. #include <sys/time.h>
  63.  
  64. #ifndef SYSV
  65. #include <sys/resource.h>
  66. #endif
  67.  
  68. #include <sys/file.h>
  69. #include <signal.h>
  70.  
  71. #ifdef TERMIO
  72. #define VDISABLEVAL -1
  73. #define TIO 1
  74. #include <sys/termio.h>
  75. #else
  76. #ifdef TERMIOS
  77. #define VDISABLEVAL 0
  78. #define TIO 1
  79. #include <termios.h>
  80. #else
  81. #include <sgtty.h>
  82. #endif
  83. #endif
  84.  
  85. #ifdef SYSV
  86. #undef TIOCGWINSZ
  87. #endif
  88.  
  89. #include <sys/param.h>
  90. #include <sys/times.h>
  91.  
  92. #ifdef SYSV
  93. #undef _POSIX_SOURCE
  94. #endif
  95.  
  96. #ifdef __hp9000s800
  97. #include <sys/bsdtty.h>
  98. #endif
  99.  
  100. #ifndef sun
  101. #include <sys/ioctl.h>
  102. #else
  103. #include <sys/filio.h>
  104. #endif
  105.  
  106. #define VERSIONSTR "zsh v2.2.0"
  107.  
  108. #if 0 /* __STDC__ */
  109. #include <unistd.h>
  110. #include <fcntl.h>
  111. #include <stat.h>
  112. #define DCLPROTO(X) X
  113. #undef NULL
  114. #define NULL ((void *)0)
  115. #else /* not __STDC__ */
  116. #include <sys/stat.h>
  117. #define DCLPROTO(X) ()
  118. #ifndef NULL
  119. #define NULL 0
  120. #endif
  121. #endif /* __STDC__ */
  122.  
  123. #ifdef QDEBUG
  124. #define DCLPROTO(X) X
  125. #endif
  126.  
  127. #define DEFWORDCHARS "*?_-.[]~=/&;!#$%^(){}<>"
  128. #define DEFTIMEFMT "%E real  %U user  %S system  %P %J"
  129. #ifdef UTMP_HOST
  130. #define DEFWATCHFMT "%n has %a %l from %m."
  131. #else
  132. #define DEFWATCHFMT "%n has %a %l."
  133. #endif
  134.  
  135. #ifdef GLOBALS
  136. #define EXTERN
  137. #else
  138. #define EXTERN extern
  139. #endif
  140.  
  141. #ifdef HAS_STRING
  142. #define killpg(pgrp,sig) kill(-(pgrp),sig)
  143. #endif
  144.  
  145. #ifndef F_OK
  146. #define F_OK 00
  147. #define R_OK 04
  148. #define W_OK 02
  149. #define X_OK 01
  150. #endif
  151.  
  152. #include "zle.h"
  153.  
  154. /* size of job list */
  155.  
  156. #define MAXJOB 80
  157.  
  158. /* memory allocation routines - changed with permalloc()/heapalloc() */
  159.  
  160. vptr (*alloc)DCLPROTO((int));
  161. vptr (*ncalloc)DCLPROTO((int));
  162.  
  163. #define addhnode(A,B,C,D) Addhnode(A,B,C,D,1)
  164. #define addhperm(A,B,C,D) Addhnode(A,B,C,D,0)
  165.  
  166. /* character tokens */
  167.  
  168. #define ALPOP            ((char) 0x81)
  169. #define HISTSPACE        ((char) 0x83)
  170. #define Pound            ((char) 0x84)
  171. #define String            ((char) 0x85)
  172. #define Hat                ((char) 0x86)
  173. #define Star            ((char) 0x87)
  174. #define Inpar            ((char) 0x88)
  175. #define Outpar            ((char) 0x89)
  176. #define Qstring        ((char) 0x8a)
  177. #define Equals            ((char) 0x8b)
  178. #define Bar                ((char) 0x8c)
  179. #define Inbrace        ((char) 0x8d)
  180. #define Outbrace        ((char) 0x8e)
  181. #define Inbrack        ((char) 0x8f)
  182. #define Outbrack        ((char) 0x90)
  183. #define Tick            ((char) 0x91)
  184. #define Inang            ((char) 0x92)
  185. #define Outang            ((char) 0x93)
  186. #define Quest            ((char) 0x94)
  187. #define Tilde            ((char) 0x95)
  188. #define Qtick            ((char) 0x96)
  189. #define Comma            ((char) 0x97)
  190. #define Nularg            ((char) 0x98)
  191.  
  192. /* chars that need to be quoted if meant literally */
  193.  
  194. #define SPECCHARS "#$^*()$=|{}[]`<>?~;&!\n\t \\\'\""
  195.  
  196. /* ALPOP in the form of a string */
  197.  
  198. #define ALPOPS " \201"
  199. #define HISTMARK "\201"
  200.  
  201. #define SEPER 1
  202. #define NEWLIN 2
  203. #define LEXERR 3
  204. #define SEMI 4
  205. #define DSEMI 5
  206. #define AMPER 6
  207. #define INPAR 7
  208. #define INBRACE 8
  209. #define OUTPAR 9
  210. #define DBAR 10
  211. #define DAMPER 11
  212. #define BANG 12
  213. #define OUTBRACE 13
  214. #define OUTANG 14
  215. #define OUTANGBANG 15
  216. #define DOUTANG 16
  217. #define DOUTANGBANG 17
  218. #define INANG 18
  219. #define DINANG 19
  220. #define DINANGDASH 20
  221. #define INANGAMP 21
  222. #define OUTANGAMP 22
  223. #define OUTANGAMPBANG 23
  224. #define DOUTANGAMP 24
  225. #define DOUTANGAMPBANG 25
  226. #define TRINANG 26
  227. #define BAR 27
  228. #define BARAMP 28
  229. #define DINBRACK 29
  230. #define DOUTBRACK 30
  231. #define STRING 31
  232. #define ENVSTRING 32
  233. #define ENVARRAY 33
  234. #define ENDINPUT 34
  235. #define INOUTPAR 35
  236. #define DO 36
  237. #define DONE 37
  238. #define ESAC 38
  239. #define THEN 39
  240. #define ELIF 40
  241. #define ELSE 41
  242. #define FI 42
  243. #define FOR 43
  244. #define CASE 44
  245. #define IF 45
  246. #define WHILE 46
  247. #define FUNC 47
  248. #define REPEAT 48
  249. #define TIME 49
  250. #define UNTIL 50
  251. #define EXEC 51
  252. #define COMMAND 52
  253. #define SELECT 53
  254. #define COPROC 54
  255. #define NOGLOB 55
  256. #define DASH 56
  257. #define NOCORRECT 57
  258. #define FOREACH 58
  259. #define ZEND 59
  260.  
  261. #define WRITE 0
  262. #define WRITENOW 1
  263. #define APP 2
  264. #define APPNOW 3
  265. #define MERGEOUT 4
  266. #define MERGEOUTNOW 5
  267. #define ERRAPP 6
  268. #define ERRAPPNOW 7
  269. #define READ 8
  270. #define HEREDOC 9
  271. #define HEREDOCDASH 10
  272. #define HERESTR 11
  273. #define MERGE 12
  274. #define CLOSE 13
  275. #define INPIPE 14
  276. #define OUTPIPE 15
  277. #define NONE 16
  278.  
  279. #ifdef GLOBALS
  280. int redirtab[TRINANG-OUTANG+1] = {
  281.     WRITE,
  282.     WRITENOW,
  283.     APP,
  284.     APPNOW,
  285.     READ,
  286.     HEREDOC,
  287.     HEREDOCDASH,
  288.     MERGE,
  289.     MERGEOUT,
  290.     MERGEOUTNOW,
  291.     ERRAPP,
  292.     ERRAPPNOW,
  293.     HERESTR,
  294. };
  295. #else
  296. int redirtab[TRINANG-OUTANG+1];
  297. #endif
  298.  
  299. #define IS_READFD(X) ((X)>=READ && (X)<=MERGE)
  300. #define IS_REDIROP(X) ((X)>=OUTANG && (X)<=TRINANG)
  301. #define IS_ERROR_REDIR(X) ((X)>=MERGEOUT && (X)<=ERRAPPNOW)
  302. #define UN_ERROR_REDIR(X) ((X)-MERGEOUT+WRITE)
  303.  
  304. #define FD_WORD   -1
  305. #define FD_COPROC -2
  306. #define FD_CLOSE  -3
  307.  
  308. EXTERN char **environ;
  309.  
  310. typedef struct hashtab *Hashtab;
  311. typedef struct hashnode *Hashnode;
  312. typedef struct schedcmd *Schedcmd;
  313. typedef struct alias *Alias;
  314. typedef struct process *Process;
  315. typedef struct job *Job;
  316. typedef struct value *Value;
  317. typedef struct arrind *Arrind;
  318. typedef struct varasg *Varasg;
  319. typedef struct param *Param;
  320. typedef struct cmdnam *Cmdnam;
  321. typedef struct cond *Cond;
  322. typedef struct cmd *Cmd;
  323. typedef struct pline *Pline;
  324. typedef struct sublist *Sublist;
  325. typedef struct list *List;
  326. typedef struct lklist *Lklist;
  327. typedef struct lknode *Lknode;
  328. typedef struct comp *Comp;
  329. typedef struct redir *Redir;
  330. typedef struct complist *Complist;
  331. typedef struct heap *Heap;
  332. typedef struct histent *Histent;
  333. typedef struct hp *Hp;
  334. typedef struct compctl *Compctl;
  335. typedef void (*FFunc)DCLPROTO((vptr));
  336. typedef vptr (*VFunc)DCLPROTO((vptr));
  337. typedef void (*HFunc)DCLPROTO((char *,char *));
  338.  
  339. /* linked list abstract data type */
  340.  
  341. struct lknode;
  342. struct lklist;
  343.  
  344. struct lknode {
  345.    Lknode next,last;
  346.    vptr dat;
  347.    };
  348. struct lklist {
  349.    Lknode first,last;
  350.    };
  351.  
  352. #define addnode(X,Y) insnode(X,(X)->last,Y)
  353. #define full(X) ((X)->first != NULL)
  354. #define firstnode(X) ((X)->first)
  355. #define getaddrdata(X) (&((X)->dat))
  356. #define getdata(X) ((X)->dat)
  357. #define setdata(X,Y) ((X)->dat = (Y))
  358. #define lastnode(X) ((X)->last)
  359. #define nextnode(X) ((X)->next)
  360. #define prevnode(X) ((X)->last)
  361. #define peekfirst(X) ((X)->first->dat)
  362. #define pushnode(X,Y) insnode(X,(Lknode) X,Y)
  363. #define incnode(X) (X = nextnode(X))
  364. #define gethistent(X) (histentarr+((X)%histentct))
  365.  
  366. /* node structure for syntax trees */
  367.  
  368. /* struct list, struct sublist, struct pline, etc.  all fit the form
  369.     of this structure and are used interchangably
  370. */
  371.  
  372. struct node {
  373.     int data[4];            /* arbitrary integer data */
  374.     vptr ptrs[4];            /* arbitrary pointer data */
  375.     int types[4];            /* what ptrs[] are pointing to */
  376.     int type;                /* node type */
  377.     };
  378.  
  379. #define N_LIST 0
  380. #define N_SUBLIST 1
  381. #define N_PLINE 2
  382. #define N_CMD 3
  383. #define N_REDIR 4
  384. #define N_COND 5
  385. #define N_FOR 6
  386. #define N_CASE 7
  387. #define N_IF 8
  388. #define N_WHILE 9
  389. #define N_VARASG 10
  390. #define N_COUNT 11
  391.  
  392. /* values for types[4] */
  393.  
  394. #define NT_EMPTY 0
  395. #define NT_NODE  1
  396. #define NT_STR   2
  397. #define NT_LIST  4
  398. #define NT_MALLOC 8
  399.  
  400. /* tree element for lists */
  401.  
  402. struct list {
  403.     int type;
  404.     int ifil[3];        /* to fit struct node */
  405.    Sublist left;
  406.    List right;
  407.    };
  408.  
  409. #define SYNC 0        /* ; */
  410. #define ASYNC 1    /* & */
  411. #define TIMED 2
  412.  
  413. /* tree element for sublists */
  414.  
  415. struct sublist {
  416.     int type;
  417.     int flags;            /* see PFLAGs below */
  418.     int ifil[2];
  419.     Pline left;
  420.     Sublist right;
  421.     };
  422.  
  423. #define ORNEXT 10        /* || */
  424. #define ANDNEXT 11    /* && */
  425.  
  426. #define PFLAG_NOT 1            /* ! ... */
  427. #define PFLAG_COPROC 32        /* coproc ... */
  428.  
  429. /* tree element for pipes */
  430.  
  431. struct pline {
  432.     int type;
  433.     int ifil[3];
  434.    Cmd left;
  435.    Pline right;
  436.    };
  437.  
  438. #define END        0    /* pnode *right is null */
  439. #define PIPE    1    /* pnode *right is the rest of the pipeline */
  440.  
  441. /* tree element for commands */
  442.  
  443. struct cmd {
  444.     int type;
  445.     int flags;                /* see CFLAGs below */
  446.     int ifil[2];
  447.    Lklist args;            /* command & argmument List (char *'s) */
  448.     union {
  449.        List list;            /* for SUBSH/CURSH/SHFUNC */
  450.         struct forcmd *forcmd;
  451.         struct casecmd *casecmd;
  452.         struct ifcmd *ifcmd;
  453.         struct whilecmd *whilecmd;
  454.         Sublist pline;
  455.         Cond cond;
  456.         } u;
  457.    Lklist redir;            /* i/o redirections (struct redir *'s) */
  458.     Lklist vars;            /* param assignments (struct varasg *'s) */
  459.    };
  460.  
  461. #define SIMPLE 0
  462. #define SUBSH 1
  463. #define CURSH 2
  464. #define ZCTIME 3
  465. #define FUNCDEF 4
  466. #define CFOR 5
  467. #define CWHILE 6
  468. #define CREPEAT 7
  469. #define CIF 8
  470. #define CCASE 9
  471. #define CSELECT 10
  472. #define COND 11
  473.  
  474. #define CFLAG_EXEC 1            /* exec ... */
  475. #define CFLAG_COMMAND 2        /* command ... */
  476. #define CFLAG_NOGLOB 4     /* noglob ... */
  477. #define CFLAG_DASH 8            /* - ... */
  478.  
  479. /* tree element for redirection lists */
  480.  
  481. struct redir {
  482.     int type,fd1,fd2,ifil;
  483.     char *name;
  484.    };
  485.  
  486. /* tree element for conditionals */
  487.  
  488. struct cond {
  489.     int type;        /* can be cond_type, or a single letter (-a, -b, ...) */
  490.     int ifil[3];
  491.     vptr left,right,vfil[2];
  492.     int types[4],typ;    /* from struct node.  DO NOT REMOVE */
  493.     };
  494.  
  495. #define COND_NOT 0
  496. #define COND_AND 1
  497. #define COND_OR 2
  498. #define COND_STREQ 3
  499. #define COND_STRNEQ 4
  500. #define COND_STRLT 5
  501. #define COND_STRGTR 6
  502. #define COND_NT 7
  503. #define COND_OT 8
  504. #define COND_EF 9
  505. #define COND_EQ 10
  506. #define COND_NE 11
  507. #define COND_LT 12
  508. #define COND_GT 13
  509. #define COND_LE 14
  510. #define COND_GE 15
  511.  
  512. struct forcmd {        /* for/select */
  513.                             /* Cmd->args contains list of words to loop thru */
  514.     int inflag;            /* if there is an in ... clause */
  515.     int ifil[3];
  516.     char *name;            /* parameter to assign values to */
  517.     List list;            /* list to look through for each name */
  518.     };
  519. struct casecmd {
  520.                             /* Cmd->args contains word to test */
  521.     int ifil[4];
  522.     struct casecmd *next;
  523.     char *pat;
  524.     List list;                    /* list to execute */
  525.     };
  526.  
  527. /*
  528.  
  529.     a command like "if foo then bar elif baz then fubar else fooble"
  530.     generates a tree like:
  531.  
  532.     struct ifcmd a = { next =  &b,  ifl = "foo", thenl = "bar" }
  533.     struct ifcmd b = { next =  &c,  ifl = "baz", thenl = "fubar" }
  534.     struct ifcmd c = { next = NULL, ifl = NULL, thenl = "fooble" }
  535.  
  536. */
  537.  
  538. struct ifcmd {
  539.     int ifil[4];
  540.     struct ifcmd *next;
  541.     List ifl;
  542.     List thenl;
  543.     };
  544.  
  545. struct whilecmd {
  546.     int cond;        /* 0 for while, 1 for until */
  547.     int ifil[3];
  548.     List cont;        /* condition */
  549.     List loop;        /* list to execute until condition met */
  550.     };
  551.  
  552. /* structure used for multiple i/o redirection */
  553. /* one for each fd open */
  554.  
  555. struct multio {
  556.     int ct;                /* # of redirections on this fd */
  557.     int rflag;            /* 0 if open for reading, 1 if open for writing */
  558.     int pipe;            /* fd of pipe if ct > 1 */
  559.     int fds[NOFILE];    /* list of src/dests redirected to/from this fd */
  560.    }; 
  561.  
  562. /* node used in command path hash table (cmdnamtab) */
  563.  
  564. struct cmdnam 
  565. {
  566.     struct hashnode *next; int canfree; char *nam; /* hash data */
  567.     int type,flags;
  568.     union {
  569.         char *nam;        /* full pathname if type != BUILTIN */
  570.         int binnum;        /* func to exec if type == BUILTIN */
  571.         List list;        /* list to exec if type == SHFUNC */
  572.         } u;
  573.     char **pcomp;        /* location in path for EXCMD's */
  574.     };
  575.  
  576. #define EXCMD 0
  577. #define BUILTIN 2
  578. #define SHFUNC 3
  579. #define DISABLED 4
  580. #define ISEXCMD(X) ((X)==EXCMD)
  581.  
  582. /* node used in parameter hash table (paramtab) */
  583.  
  584. struct param {
  585.     struct hashnode *next; int canfree; char *nam; /* hash data */
  586.     union {
  587.         char **arr;        /* value if declared array */
  588.         char *str;        /* value if declared string (scalar) */
  589.         long val;        /* value if declared integer */
  590.         } u;
  591.     union {                /* functions to call to set value */
  592.         void (*cfn)DCLPROTO((Param,char *));
  593.         void (*ifn)DCLPROTO((Param,long));
  594.         void (*afn)DCLPROTO((Param,char **));
  595.         } sets;
  596.     union {                /* functions to call to get value */
  597.         char *(*cfn)DCLPROTO((Param));
  598.         long (*ifn)DCLPROTO((Param));
  599.         char **(*afn)DCLPROTO((Param));
  600.         } gets;
  601.     int ct;                /* output base or field width */
  602.     int flags;
  603.     vptr data;            /* used by getfns */
  604.     char *env;            /* location in environment, if exported */
  605.     char *ename;        /* name of corresponding environment var */
  606.     };
  607.  
  608. #define PMFLAG_s 0        /* scalar */
  609. #define PMFLAG_L 1        /* left justify and remove leading blanks */
  610. #define PMFLAG_R 2        /* right justify and fill with leading blanks */
  611. #define PMFLAG_Z 4        /* right justify and fill with leading zeros */
  612. #define PMFLAG_i 8        /* integer */
  613. #define PMFLAG_l 16        /* all lower case */
  614. #define PMFLAG_u 32        /* all upper case */
  615. #define PMFLAG_r 64        /* readonly */
  616. #define PMFLAG_t 128        /* tagged */
  617. #define PMFLAG_x 256        /* exported */
  618. #define PMFLAG_A 512        /* array */
  619. #define PMFLAG_SPECIAL    1024
  620. #define PMTYPE (PMFLAG_i|PMFLAG_A)
  621. #define pmtype(X) ((X)->flags & PMTYPE)
  622.  
  623. /* variable assignment tree element */
  624.  
  625. struct varasg {
  626.     int type;            /* nonzero means array */
  627.     int ifil[3];
  628.     char *name;
  629.     char *str;            /* should've been a union here.  oh well */
  630.     Lklist arr;
  631.     };
  632.  
  633. /* lvalue for variable assignment/expansion */
  634.  
  635. struct value {
  636.     int isarr;
  637.     struct param *pm;        /* parameter node */
  638.     int a;                    /* first element of array slice, or -1 */
  639.     int b;                    /* last element of array slice, or -1 */
  640.     };
  641.  
  642. struct fdpair {
  643.     int fd1,fd2;
  644.     };
  645.  
  646. /* tty state structure */
  647.  
  648. struct ttyinfo {
  649. #ifdef TERMIOS
  650.     struct termios tio;
  651. #else
  652. #ifdef TERMIO
  653.     struct termio tio;
  654. #else
  655.     struct sgttyb sgttyb;
  656.     int lmodes;
  657.     struct tchars tchars;
  658.     struct ltchars ltchars;
  659. #endif
  660. #endif
  661. #ifdef TIOCGWINSZ
  662.     struct winsize winsize;
  663. #endif
  664.     };
  665.  
  666. EXTERN struct ttyinfo savedttyinfo;
  667.  
  668. /* entry in job table */
  669.  
  670. struct job {
  671.     long gleader;                    /* process group leader of this job */
  672.     int stat;
  673.     char *pwd;                        /* current working dir of shell when
  674.                                             this job was spawned */
  675.     struct process *procs;        /* list of processes */
  676.     Lklist filelist;                /* list of files to delete when done */
  677.     };
  678.  
  679. #define STAT_CHANGED 1        /* status changed and not reported */
  680. #define STAT_STOPPED 2        /* all procs stopped or exited */
  681. #define STAT_TIMED 4            /* job is being timed */
  682. #define STAT_DONE 8
  683. #define STAT_LOCKED 16        /* shell is finished creating this job,
  684.                                         may be deleted from job table */
  685. #define STAT_INUSE 64        /* this job entry is in use */
  686.  
  687. #define SP_RUNNING -1        /* fake statusp for running jobs */
  688.  
  689. #ifndef RUSAGE_CHILDREN
  690. #undef HAS_RUSAGE
  691. #endif
  692.  
  693. struct timeinfo {
  694. #ifdef HAS_RUSAGE
  695.     struct rusage ru;
  696. #else
  697.     long ut, st;
  698. #endif
  699. };
  700.  
  701. /* node in job process lists */
  702.  
  703. #define JOBTEXTSIZE 80
  704.  
  705. struct process {
  706.     struct process *next;
  707.     long pid;
  708.     char text[JOBTEXTSIZE];        /* text to print when 'jobs' is run */
  709.     int statusp;                    /* return code from wait3() */
  710.     struct timeinfo ti;
  711.     time_t bgtime;                    /* time job was spawned */
  712.     time_t endtime;                /* time job exited */
  713.     };
  714.  
  715. /* node in alias hash table */
  716.  
  717. struct alias {
  718.     struct hashnode *next; int canfree; char *nam; /* hash data */
  719.     char *text;            /* expansion of alias */
  720.     int cmd;                /* one for regular aliases,
  721.                                 zero for global aliases,
  722.                                 negative for reserved words */
  723.     int inuse;            /* alias is being expanded */
  724.     };
  725.  
  726. /* node in sched list */
  727.  
  728. struct schedcmd {
  729.     struct schedcmd *next;
  730.     char *cmd;        /* command to run */
  731.     time_t time;    /* when to run it */
  732.     };
  733.  
  734. #define MAXAL 20    /* maximum number of aliases expanded at once */
  735.  
  736. /* hash table node */
  737.  
  738. struct hashnode {
  739.     struct hashnode *next;
  740.     int canfree;        /* nam is free()able */
  741.     char *nam;
  742.     };
  743.  
  744. /* hash table */
  745.  
  746. struct hashtab {
  747.     int hsize;                            /* size of nodes[] */
  748.     int ct;                                /* # of elements */
  749.     struct hashnode **nodes;        /* array of size hsize */
  750.     };
  751.  
  752. /* history entry */
  753.  
  754. struct histent {
  755.     char *lex;            /* lexical history line */
  756.     char *lit;            /* literal history line */
  757.     time_t stim;        /* command started time (datestamp) */
  758.     time_t ftim;        /* command finished time */
  759.     };
  760.  
  761. /* completion control */
  762.  
  763. struct compctl {
  764.     struct hashnode *next; int canfree; char *nam; /* hash data */
  765.     int mask;
  766.     char *keyvar;
  767.     };
  768.  
  769. #define CC_FILES        1
  770. #define CC_COMMPATH    2
  771. #define CC_HOSTS        4
  772. #define CC_OPTIONS    8
  773. #define CC_VARS        16
  774. #define CC_BINDINGS    32
  775. #define CC_USRKEYS   64
  776.  
  777. extern char *sys_errlist[];
  778. extern int errno;
  779.  
  780. /* values in opts[] array */
  781.  
  782. #define OPT_INVALID 1    /* opt is invalid, like -$ */
  783. #define OPT_UNSET 0
  784. #define OPT_SET 2
  785.  
  786. /* the options */
  787.  
  788. struct option {
  789.     char *name;
  790.     char id;            /* corresponding letter */
  791.     };
  792.  
  793. #define CORRECT '0'
  794. #define NOCLOBBER '1'
  795. #define NOBADPATTERN '2'
  796. #define NONOMATCH '3'
  797. #define GLOBDOTS '4'
  798. #define NOTIFY '5'
  799. #define BGNICE '6'
  800. #define IGNOREEOF '7'
  801. #define MARKDIRS '8'
  802. #define AUTOLIST '9'
  803. #define NOBEEP 'B'
  804. #define PRINTEXITVALUE 'C'
  805. #define PUSHDTOHOME 'D'
  806. #define PUSHDSILENT 'E'
  807. #define NOGLOBOPT 'F'
  808. #define NULLGLOB 'G'
  809. #define RMSTARSILENT 'H'
  810. #define IGNOREBRACES 'I'
  811. #define AUTOCD 'J'
  812. #define NOBANGHIST 'K'
  813. #define SUNKEYBOARDHACK 'L'
  814. #define SINGLELINEZLE 'M'
  815. #define AUTOPUSHD 'N'
  816. #define CORRECTALL 'O'
  817. #define RCEXPANDPARAM 'P'
  818. #define PATHDIRS 'Q'
  819. #define LONGLISTJOBS 'R'
  820. #define RECEXACT 'S'
  821. #define CDABLEVARS 'T'
  822. #define MAILWARNING 'U'
  823. #define NOPROMPTCR 'V'
  824. #define AUTORESUME 'W'
  825. #define LISTTYPES 'X'
  826. #define MENUCOMPLETE 'Y'
  827. #define USEZLE 'Z'
  828. #define ALLEXPORT 'a'
  829. #define ERREXIT 'e'
  830. #define NORCS 'f'
  831. #define HISTIGNORESPACE 'g'
  832. #define HISTIGNOREDUPS 'h'
  833. #define INTERACTIVE 'i'
  834. #define HISTLIT 'j'
  835. #define INTERACTIVECOMMENTS 'k'
  836. #define LOGINSHELL 'l'
  837. #define MONITOR 'm'
  838. #define NOEXEC 'n'
  839. #define SHINSTDIN 's'
  840. #define NOUNSET 'u'
  841. #define VERBOSE 'v'
  842. #define CHASELINKS 'w'
  843. #define XTRACE 'x'
  844. #define SHWORDSPLIT 'y'
  845. #define MENUCOMPLETEBEEP '\2'
  846. #define HISTNOSTORE '\3'
  847. #define EXTENDEDGLOB '\5'
  848. #define GLOBCOMPLETE '\6'
  849. #define CSHJUNKIEQUOTES '\7'
  850. #define PUSHDMINUS '\10'
  851. #define CSHJUNKIELOOPS '\11'
  852. #define RCQUOTES '\12'
  853. #define KSHOPTIONPRINT '\13'
  854. #define NOSHORTLOOPS '\14'
  855. #define LASTMENU '\15'
  856. #define AUTOMENU '\16'
  857. #define HISTVERIFY '\17'
  858. #define NOLISTBEEP '\20'
  859. #define NOHUP '\21'
  860. #define NOEQUALS '\22'
  861. #define CSHNULLGLOB '\23'
  862. #define HASHCMDS '\24'
  863. #define HASHDIRS '\25'
  864. #define NUMERICGLOBSORT '\26'
  865. #define BRACECCL '\27'
  866. #define HASHLISTALL '\30'
  867. #define OVERSTRIKE '\31'
  868. #define NOHISTBEEP '\32'
  869. #define PUSHDIGNOREDUPS '\33'
  870. #define AUTOREMOVESLASH '\34'
  871.  
  872. #ifndef GLOBALS
  873. extern struct option optns[];
  874. #else
  875. struct option optns[] = {
  876.     "correct",CORRECT,
  877.     "noclobber",NOCLOBBER,
  878.     "nobadpattern",NOBADPATTERN,
  879.     "nonomatch",NONOMATCH,
  880.     "globdots",GLOBDOTS,
  881.     "notify",NOTIFY,
  882.     "bgnice",BGNICE,
  883.     "ignoreeof",IGNOREEOF,
  884.     "markdirs",MARKDIRS,
  885.     "autolist",AUTOLIST,
  886.     "nobeep",NOBEEP,
  887.     "printexitvalue",PRINTEXITVALUE,
  888.     "pushdtohome",PUSHDTOHOME,
  889.     "pushdsilent",PUSHDSILENT,
  890.     "noglob",NOGLOBOPT,
  891.     "nullglob",NULLGLOB,
  892.     "rmstarsilent",RMSTARSILENT,
  893.     "ignorebraces",IGNOREBRACES,
  894.     "braceccl",BRACECCL,
  895.     "autocd",AUTOCD,
  896.     "nobanghist",NOBANGHIST,
  897.     "sunkeyboardhack",SUNKEYBOARDHACK,
  898.     "singlelinezle",SINGLELINEZLE,
  899.     "autopushd",AUTOPUSHD,
  900.     "correctall",CORRECTALL,
  901.     "rcexpandparam",RCEXPANDPARAM,
  902.     "pathdirs",PATHDIRS,
  903.     "longlistjobs",LONGLISTJOBS,
  904.     "recexact",RECEXACT,
  905.     "cdablevars",CDABLEVARS,
  906.     "mailwarning",MAILWARNING,
  907.     "nopromptcr",NOPROMPTCR,
  908.     "autoresume",AUTORESUME,
  909.     "listtypes",LISTTYPES,
  910.     "menucomplete",MENUCOMPLETE,
  911.     "zle",USEZLE,
  912.     "allexport",ALLEXPORT,
  913.     "errexit",ERREXIT,
  914.     "norcs",NORCS,
  915.     "histignorespace",HISTIGNORESPACE,
  916.     "histignoredups",HISTIGNOREDUPS,
  917.     "interactive",INTERACTIVE,
  918.     "histlit",HISTLIT,
  919.     "interactivecomments",INTERACTIVECOMMENTS,
  920.     "login",LOGINSHELL,
  921.     "monitor",MONITOR,
  922.     "noexec",NOEXEC,
  923.     "shinstdin",SHINSTDIN,
  924.     "nounset",NOUNSET,
  925.     "verbose",VERBOSE,
  926.     "chaselinks",CHASELINKS,
  927.     "xtrace",XTRACE,
  928.     "shwordsplit",SHWORDSPLIT,
  929.     "menucompletebeep",MENUCOMPLETEBEEP,
  930.     "histnostore",HISTNOSTORE,
  931.     "extendedglob",EXTENDEDGLOB,
  932.     "globcomplete",GLOBCOMPLETE,
  933.     "cshjunkiequotes",CSHJUNKIEQUOTES,
  934.     "pushdminus",PUSHDMINUS,
  935.     "cshjunkieloops",CSHJUNKIELOOPS,
  936.     "rcquotes",RCQUOTES,
  937.     "noshortloops",NOSHORTLOOPS,
  938.     "lastmenu",LASTMENU,
  939.     "automenu",AUTOMENU,
  940.     "histverify",HISTVERIFY,
  941.     "nolistbeep",NOLISTBEEP,
  942.     "nohup",NOHUP,
  943.     "noequals",NOEQUALS,
  944.     "kshoptionprint",KSHOPTIONPRINT,
  945.     "cshnullglob",CSHNULLGLOB,
  946.     "hashcmds",HASHCMDS,
  947.     "hashdirs",HASHDIRS,
  948.     "numericglobsort",NUMERICGLOBSORT,
  949.     "hashlistall",HASHLISTALL,
  950.     "overstrike",OVERSTRIKE,
  951.     "nohistbeep",NOHISTBEEP,
  952.     "pushdignoredups",PUSHDIGNOREDUPS,
  953.     "autoremoveslash",AUTOREMOVESLASH,
  954.     NULL,0
  955. };
  956. #endif
  957.  
  958. #define ALSTAT_MORE 1    /* last alias ended with ' ' */
  959. #define ALSTAT_JUNK 2    /* don't put word in history List */
  960.  
  961. #undef isset
  962. #define isset(X) (opts[X])
  963. #define unset(X) (!opts[X])
  964. #define interact (isset(INTERACTIVE))
  965. #define jobbing (isset(MONITOR))
  966. #define nointr() signal(SIGINT,SIG_IGN)
  967. #define islogin (isset(LOGINSHELL))
  968.  
  969. #ifndef _IBMR2
  970. #undef WIFSTOPPED
  971. #undef WIFSIGNALED
  972. #undef WIFEXITED
  973. #undef WEXITSTATUS
  974. #undef WTERMSIG
  975. #undef WSTOPSIG
  976. #undef WCOREDUMPED
  977.  
  978. #define WIFSTOPPED(X) (((X)&0377)==0177)
  979. #define WIFSIGNALED(X) (((X)&0377)!=0&&((X)&0377)!=0177)
  980. #define WIFEXITED(X) (((X)&0377)==0)
  981. #define WEXITSTATUS(X) (((X)>>8)&0377)
  982. #define WTERMSIG(X) ((X)&0177)
  983. #define WSTOPSIG(X) (((X)>>8)&0377)
  984. #endif
  985. #define WCOREDUMPED(X) ((X)&0200)
  986.  
  987. #ifndef S_ISBLK
  988. #define    _IFMT        0170000
  989. #define    _IFDIR    0040000
  990. #define    _IFCHR    0020000
  991. #define    _IFBLK    0060000
  992. #define    _IFREG    0100000
  993. #define    _IFIFO    0010000
  994. #define    S_ISBLK(m)    (((m)&_IFMT) == _IFBLK)
  995. #define    S_ISCHR(m)    (((m)&_IFMT) == _IFCHR)
  996. #define    S_ISDIR(m)    (((m)&_IFMT) == _IFDIR)
  997. #define    S_ISFIFO(m)    (((m)&_IFMT) == _IFIFO)
  998. #define    S_ISREG(m)    (((m)&_IFMT) == _IFREG)
  999. #endif
  1000.  
  1001. #ifndef S_ISSOCK
  1002. #ifndef _IFMT
  1003. #define _IFMT 0170000
  1004. #endif
  1005. #define    _IFLNK    0120000
  1006. #define    _IFSOCK    0140000
  1007. #define    S_ISLNK(m)    (((m)&_IFMT) == _IFLNK)
  1008. #define    S_ISSOCK(m)    (((m)&_IFMT) == _IFSOCK)
  1009. #endif
  1010.  
  1011. #if S_IFIFO == S_IFSOCK
  1012. #undef S_IFIFO
  1013. #endif
  1014.  
  1015. #ifndef S_IFIFO
  1016. #define NO_FIFOS
  1017. #endif
  1018.  
  1019. /* buffered shell input for non-interactive shells */
  1020.  
  1021. EXTERN FILE *bshin;
  1022.  
  1023. /* NULL-terminated arrays containing path, cdpath, etc. */
  1024.  
  1025. EXTERN char **path,**cdpath,**fpath,**watch,**mailpath;
  1026. EXTERN char **manpath,**tildedirs,**fignore;
  1027. EXTERN char **hosts;
  1028.  
  1029. /* named directories */
  1030.  
  1031. EXTERN char **userdirs,**usernames;
  1032.  
  1033. /* size of userdirs[], # of userdirs */
  1034.  
  1035. EXTERN int userdirsz,userdirct;
  1036.  
  1037. EXTERN char *mailfile;
  1038.  
  1039. EXTERN char *yytext;
  1040.  
  1041. /* error/break flag */
  1042.  
  1043. EXTERN int errflag;
  1044.  
  1045. EXTERN char *tokstr;
  1046. EXTERN int tok, tokfd;
  1047.  
  1048. /* lexical analyzer error flag */
  1049.  
  1050. EXTERN int lexstop;
  1051.  
  1052. /* suppress error messages */
  1053.  
  1054. EXTERN int noerrs;
  1055.  
  1056. /* current history event number */
  1057.  
  1058. EXTERN int curhist;
  1059.  
  1060. /* if != 0, this is the first line of the command */
  1061.  
  1062. EXTERN int isfirstln;
  1063.  
  1064. /* if != 0, this is the first char of the command (not including
  1065.     white space */
  1066.  
  1067. EXTERN int isfirstch;
  1068.  
  1069. /* number of history entries */
  1070.  
  1071. EXTERN int histentct;
  1072.  
  1073. /* array of history entries */
  1074.  
  1075. EXTERN Histent histentarr;
  1076.  
  1077. /* capacity of history lists */
  1078.  
  1079. EXTERN int histsiz,lithistsiz;
  1080.  
  1081. /* if = 1, we have performed history substitution on the current line
  1082.      if = 2, we have used the 'p' modifier */
  1083.  
  1084. EXTERN int histdone;
  1085.  
  1086. /* default event (usually curhist-1, that is, "!!") */
  1087.  
  1088. EXTERN int defev;
  1089.  
  1090. /* != 0 if we are about to read a command word */
  1091.  
  1092. EXTERN int incmdpos;
  1093.  
  1094. /* != 0 if we are in the middle of a [[ ... ]] */
  1095.  
  1096. EXTERN int incond;
  1097.  
  1098. /* != 0 if we are after a redirection (for ctxtlex only) */
  1099.  
  1100. EXTERN int inredir;
  1101.  
  1102. /* != 0 if we are about to read a case pattern */
  1103.  
  1104. EXTERN int incasepat;
  1105.  
  1106. /* != 0 if we just read FUNCTION */
  1107.  
  1108. EXTERN int infunc;
  1109.  
  1110. /* != 0 if we just read a newline */
  1111.  
  1112. EXTERN int isnewlin;
  1113.  
  1114. /* the lists of history events */
  1115.  
  1116. EXTERN Lklist histlist,lithistlist;
  1117.  
  1118. /* the directory stack */
  1119.  
  1120. EXTERN Lklist dirstack;
  1121.  
  1122. /* the zle buffer stack */
  1123.  
  1124. EXTERN Lklist bufstack;
  1125.  
  1126. /* the input queue (stack?)
  1127.  
  1128.     inbuf    = start of buffer
  1129.     inbufptr = location in buffer (= inbuf for a FULL buffer)
  1130.                                             (= inbuf+inbufsz for an EMPTY buffer)
  1131.     inbufct  = # of chars in buffer (inbufptr+inbufct == inbuf+inbufsz)
  1132.     inbufsz  = max size of buffer
  1133. */
  1134.  
  1135. EXTERN char *inbuf,*inbufptr;
  1136. EXTERN int inbufct,inbufsz;
  1137.  
  1138. EXTERN char *ifs;        /* $IFS */
  1139.  
  1140. EXTERN char *oldpwd;    /* $OLDPWD */
  1141.  
  1142. EXTERN char *underscore; /* $_ */
  1143.  
  1144. /* != 0 if this is a subshell */
  1145.  
  1146. EXTERN int subsh;
  1147.  
  1148. /* # of break levels */
  1149.  
  1150. EXTERN int breaks;
  1151.  
  1152. /* != 0 if we have a return pending */
  1153.  
  1154. EXTERN int retflag;
  1155.  
  1156. /* how far we've hashed the PATH so far */
  1157.  
  1158. EXTERN char **pathchecked;
  1159.  
  1160. /* # of nested loops we are in */
  1161.  
  1162. EXTERN int loops;
  1163.  
  1164. /* # of continue levels */
  1165.  
  1166. EXTERN int contflag;
  1167.  
  1168. /* the job we are working on */
  1169.  
  1170. EXTERN int thisjob;
  1171.  
  1172. /* the current job (+) */
  1173.  
  1174. EXTERN int curjob;
  1175.  
  1176. /* the previous job (-) */
  1177.  
  1178. EXTERN int prevjob;
  1179.  
  1180. /* hash table containing the aliases and reserved words */
  1181.  
  1182. EXTERN Hashtab aliastab;
  1183.  
  1184. /* hash table containing the parameters */
  1185.  
  1186. EXTERN Hashtab paramtab;
  1187.  
  1188. /* hash table containing the builtins/shfuncs/hashed commands */
  1189.  
  1190. EXTERN Hashtab cmdnamtab;
  1191.  
  1192. /* hash table containing the zle multi-character bindings */
  1193.  
  1194. EXTERN Hashtab xbindtab;
  1195.  
  1196. /* hash table for completion info for commands */
  1197.  
  1198. EXTERN Hashtab compctltab;
  1199.  
  1200. /* default completion infos */
  1201.  
  1202. EXTERN struct compctl cc_compos, cc_default;
  1203.  
  1204. /* the job table */
  1205.  
  1206. EXTERN struct job jobtab[MAXJOB];
  1207.  
  1208. /* shell timings */
  1209.  
  1210. #ifndef HAS_RUSAGE
  1211. EXTERN struct tms shtms;
  1212. #endif
  1213.  
  1214. /* the list of sched jobs pending */
  1215.  
  1216. EXTERN struct schedcmd *schedcmds;
  1217.  
  1218. /* the last l for s/l/r/ history substitution */
  1219.  
  1220. EXTERN char *hsubl;
  1221.  
  1222. /* the last r for s/l/r/ history substitution */
  1223.  
  1224. EXTERN char *hsubr;
  1225.  
  1226. EXTERN char *username;    /* $USERNAME */
  1227. EXTERN char *logname;    /* $LOGNAME */
  1228. EXTERN long lastval;        /* $? */
  1229. EXTERN long baud;            /* $BAUD */
  1230. EXTERN long columns;        /* $COLUMNS */
  1231. EXTERN long lines;        /* $LINES */
  1232. EXTERN long reporttime; /* $REPORTTIME */
  1233.  
  1234. /* input fd from the coprocess */
  1235.  
  1236. EXTERN int coprocin;
  1237.  
  1238. /* output fd from the coprocess */
  1239.  
  1240. EXTERN int coprocout;
  1241.  
  1242. EXTERN long mailcheck;    /* $MAILCHECK */
  1243. EXTERN long logcheck;    /* $LOGCHECK */
  1244.  
  1245. /* the last time we checked mail */
  1246.  
  1247. EXTERN time_t lastmailcheck;
  1248.  
  1249. /* the last time we checked the people in the WATCH variable */
  1250.  
  1251. EXTERN time_t lastwatch;
  1252.  
  1253. /* the last time we did the periodic() shell function */
  1254.  
  1255. EXTERN time_t lastperiod;
  1256.  
  1257. /* $SECONDS = time(NULL) - shtimer */
  1258.  
  1259. EXTERN time_t shtimer;
  1260.  
  1261. EXTERN long mypid;        /* $$ */
  1262. EXTERN long lastpid;        /* $! */
  1263. EXTERN long ppid;            /* $PPID */
  1264.  
  1265. /* the process group of the shell */
  1266.  
  1267. EXTERN long mypgrp;
  1268.  
  1269. EXTERN char *pwd;            /* $PWD */
  1270. EXTERN char *optarg;        /* $OPTARG */
  1271. EXTERN long zoptind;        /* $OPTIND */
  1272. EXTERN char *prompt;        /* $PROMPT */
  1273. EXTERN char *rprompt;    /* $RPROMPT */
  1274. EXTERN char *prompt2;    /* etc. */
  1275. EXTERN char *prompt3;
  1276. EXTERN char *prompt4;
  1277. EXTERN char *sprompt;
  1278. EXTERN char *timefmt;
  1279. EXTERN char *watchfmt;
  1280. EXTERN char *wordchars;
  1281. EXTERN char *fceditparam;
  1282. EXTERN char *tmpprefix;
  1283. EXTERN char *rstring, *Rstring;
  1284. EXTERN char *postedit;
  1285.  
  1286. EXTERN char *argzero;    /* $0 */
  1287.  
  1288. EXTERN char *hackzero;
  1289.  
  1290. /* the hostname */
  1291.  
  1292. EXTERN char *hostnam;
  1293.  
  1294. EXTERN char *home;        /* $HOME */
  1295. EXTERN char **pparams;    /* $argv */
  1296.  
  1297. /* the default command for null commands */
  1298.  
  1299. EXTERN char *nullcmd;
  1300. EXTERN char *readnullcmd;
  1301.  
  1302. /* the List of local variables we have to destroy */
  1303.  
  1304. EXTERN Lklist locallist;
  1305.  
  1306. /* the shell input fd */
  1307.  
  1308. EXTERN int SHIN;
  1309.  
  1310. /* the shell tty fd */
  1311.  
  1312. EXTERN int SHTTY;
  1313.  
  1314. /* the stack of aliases we are expanding */
  1315.  
  1316. EXTERN struct alias *alstack[MAXAL];
  1317.  
  1318. /* the alias stack pointer; also, the number of aliases currently
  1319.      being expanded */
  1320.  
  1321. EXTERN int alstackind;
  1322.  
  1323. /* != 0 means we are reading input from a string */
  1324.  
  1325. EXTERN int strin;
  1326.  
  1327. /* period between periodic() commands, in seconds */
  1328.  
  1329. EXTERN long period;
  1330.  
  1331. /* != 0 means history substitution is turned off */
  1332.  
  1333. EXTERN int stophist;
  1334.  
  1335. EXTERN int lithist;
  1336.  
  1337. /* this line began with a space, so junk it if HISTIGNORESPACE is on */
  1338.  
  1339. EXTERN int spaceflag;
  1340.  
  1341. /* don't do spelling correction */
  1342.  
  1343. EXTERN int nocorrect;
  1344.  
  1345. /* != 0 means we have removed the current event from the history List */
  1346.  
  1347. EXTERN int histremmed;
  1348.  
  1349. /* the options; e.g. if opts['a'] == OPT_SET, -a is turned on */
  1350.  
  1351. EXTERN int opts[128];
  1352.  
  1353. EXTERN long lineno;        /* LINENO */
  1354. EXTERN long listmax;        /* LISTMAX */
  1355. EXTERN long savehist;    /* SAVEHIST */
  1356. EXTERN long shlvl;        /* SHLVL */
  1357. EXTERN long tmout;        /* TMOUT */
  1358. EXTERN long dirstacksize;    /* DIRSTACKSIZE */
  1359.  
  1360. /* != 0 means we have called execlist() and then intend to exit(),
  1361.      so don't fork if not necessary */
  1362.  
  1363. EXTERN int exiting;
  1364.  
  1365. EXTERN int lastbase;        /* last input base we used */
  1366.  
  1367. /* the limits for child processes */
  1368.  
  1369. #ifdef RLIM_INFINITY
  1370. EXTERN struct rlimit limits[RLIM_NLIMITS];
  1371. #endif
  1372.  
  1373. /* the current word in the history List */
  1374.  
  1375. EXTERN char *hlastw;
  1376.  
  1377. /* pointer into the history line */
  1378.  
  1379. EXTERN char *hptr;
  1380.  
  1381. /* the current history line */
  1382.  
  1383. EXTERN char *hline;
  1384.  
  1385. /* the termcap buffer */
  1386.  
  1387. EXTERN char termbuf[1024];
  1388.  
  1389. /* $TERM */
  1390.  
  1391. EXTERN char *term;
  1392.  
  1393. /* != 0 if this $TERM setup is usable */
  1394.  
  1395. EXTERN int termok;
  1396.  
  1397. /* flag for CSHNULLGLOB */
  1398.  
  1399. EXTERN int badcshglob;
  1400.  
  1401. /* max size of hline */
  1402.  
  1403. EXTERN int hlinesz;
  1404.  
  1405. /* the alias expansion status - if == ALSTAT_MORE, we just finished
  1406.     expanding an alias ending with a space */
  1407.  
  1408. EXTERN int alstat;
  1409.  
  1410. /* we have printed a 'you have stopped (running) jobs.' message */
  1411.  
  1412. EXTERN int stopmsg;
  1413.  
  1414. /* the default tty state */
  1415.  
  1416. EXTERN struct ttyinfo shttyinfo;
  1417.  
  1418. /* $TTY */
  1419.  
  1420. EXTERN char *ttystrname;
  1421.  
  1422. /* 1 if ttyctl -f has been executed */
  1423.  
  1424. EXTERN int ttyfrozen;
  1425.  
  1426. /* list of memory heaps */
  1427.  
  1428. EXTERN Lklist heaplist;
  1429.  
  1430. /* != 0 if we are allocating in the heaplist */
  1431.  
  1432. EXTERN int useheap;
  1433.  
  1434. #include "signals.h"
  1435.  
  1436. #ifdef GLOBALS
  1437.  
  1438. /* signal names */
  1439. char **sigptr = sigs;
  1440.  
  1441. /* tokens */
  1442. char *ztokens = "#$^*()$=|{}[]`<>?~`,";
  1443.  
  1444. #else
  1445. extern char *ztokens,**sigptr;
  1446. #endif
  1447.  
  1448. #define SIGERR (SIGCOUNT+1)
  1449. #define SIGDEBUG (SIGCOUNT+2)
  1450. #define VSIGCOUNT (SIGCOUNT+3)
  1451. #define SIGEXIT 0
  1452.  
  1453. /* signals that are trapped = 1, signals ignored =2 */
  1454.  
  1455. EXTERN int sigtrapped[VSIGCOUNT];
  1456.  
  1457. /* trap functions for each signal */
  1458.  
  1459. EXTERN List sigfuncs[VSIGCOUNT];
  1460.  
  1461. /* $HISTCHARS */
  1462.  
  1463. EXTERN char bangchar,hatchar,hashchar;
  1464.  
  1465. EXTERN int eofseen;
  1466.  
  1467. /* we are parsing a line sent to use by the editor */
  1468.  
  1469. EXTERN int zleparse;
  1470.  
  1471. EXTERN int wordbeg;
  1472.  
  1473. EXTERN int parbegin;
  1474.  
  1475. /* interesting termcap strings */
  1476.  
  1477. #define TCCLEARSCREEN 0
  1478. #define TCLEFT 1
  1479. #define TCMULTLEFT 2
  1480. #define TCRIGHT 3
  1481. #define TCMULTRIGHT 4
  1482. #define TCUP 5
  1483. #define TCMULTUP 6
  1484. #define TCDOWN 7
  1485. #define TCMULTDOWN 8
  1486. #define TCDEL 9
  1487. #define TCMULTDEL 10
  1488. #define TCINS 11
  1489. #define TCMULTINS 12
  1490. #define TCCLEAREOD 13
  1491. #define TCCLEAREOL 14
  1492. #define TCINSLINE 15
  1493. #define TCDELLINE 16
  1494. #define TC_COUNT 17
  1495.  
  1496. /* lengths of each string */
  1497.  
  1498. EXTERN int tclen[TC_COUNT];
  1499.  
  1500. EXTERN char *tcstr[TC_COUNT];
  1501.  
  1502. #ifdef GLOBALS
  1503.  
  1504. /* names of the strings we want */
  1505.  
  1506. char *tccapnams[TC_COUNT] = {
  1507.     "cl","le","LE","nd","RI","up","UP","do",
  1508.     "DO","dc","DC","ic","IC","cd","ce","al","dl"
  1509.     };
  1510.  
  1511. #else
  1512. extern char *tccapnams[TC_COUNT];
  1513. #endif
  1514.  
  1515. #define tccan(X) (!!tclen[X])
  1516.  
  1517. #define HISTFLAG_DONE   1
  1518. #define HISTFLAG_NOEXEC 2
  1519. #define HISTFLAG_RECALL 4
  1520.  
  1521. #include "ztype.h"
  1522. #include "funcs.h"
  1523.  
  1524. #ifdef HAS_SETPGID
  1525. #define setpgrp setpgid
  1526. #endif
  1527.  
  1528. #define _INCLUDE_POSIX_SOURCE
  1529. #define _INCLUDE_XOPEN_SOURCE
  1530. #define _INCLUDE_HPUX_SOURCE
  1531.  
  1532. #ifdef SV_BSDSIG
  1533. #define SV_INTERRUPT SV_BSDSIG
  1534. #endif
  1535.  
  1536. #ifdef HAS_SIGRELSE
  1537. #define blockchld() sighold(SIGCHLD)
  1538. #define unblockchld() sigrelse(SIGCHLD)
  1539. #define chldsuspend() sigpause(SIGCHLD)
  1540. #else
  1541. #define blockchld() sigblock(sigmask(SIGCHLD))
  1542. #define unblockchld() sigsetmask(0)
  1543. #define chldsuspend() sigpause(0)
  1544. #endif
  1545.