1 /* 2 * Plan9 is defined for plan 9 3 * V9 is defined for 9th edition 4 * Sun is defined for sun-os 5 * Please don't litter the code with ifdefs. The three below (and one in 6 * getflags) should be enough. 7 */ 8 #define Plan9 9 #ifdef Plan9 10 #include <u.h> 11 #include <libc.h> 12 #define NSIG 32 13 #define SIGINT 2 14 #define SIGQUIT 3 15 #endif 16 #ifdef V9 17 #include <signal.h> 18 #include <libc.h> 19 #endif 20 #ifdef Sun 21 #include <signal.h> 22 #endif 23 #define YYMAXDEPTH 500 24 #ifndef PAREN 25 #include "x.tab.h" 26 #endif 27 typedef struct tree tree; 28 typedef struct word word; 29 typedef struct io io; 30 typedef union code code; 31 typedef struct var var; 32 typedef struct list list; 33 typedef struct redir redir; 34 typedef struct thread thread; 35 typedef struct builtin builtin; 36 37 #pragma incomplete word 38 #pragma incomplete io 39 40 struct tree{ 41 int type; 42 int rtype, fd0, fd1; /* details of REDIR PIPE DUP tokens */ 43 char *str; 44 int quoted; 45 int iskw; 46 tree *child[3]; 47 tree *next; 48 }; 49 tree *newtree(void); 50 tree *token(char*, int), *klook(char*), *tree1(int, tree*); 51 tree *tree2(int, tree*, tree*), *tree3(int, tree*, tree*, tree*); 52 tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*); 53 tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*); 54 tree *simplemung(tree*), *heredoc(tree*); 55 void freetree(tree*); 56 tree *cmdtree; 57 /* 58 * The first word of any code vector is a reference count. 59 * Always create a new reference to a code vector by calling codecopy(.). 60 * Always call codefree(.) when deleting a reference. 61 */ 62 union code{ 63 void (*f)(void); 64 int i; 65 char *s; 66 }; 67 68 char *promptstr; 69 int doprompt; 70 71 #define NTOK 8192 72 73 char tok[NTOK]; 74 75 #define APPEND 1 76 #define WRITE 2 77 #define READ 3 78 #define HERE 4 79 #define DUPFD 5 80 #define CLOSE 6 81 #define RDWR 7 82 83 struct var{ 84 char *name; /* ascii name */ 85 word *val; /* value */ 86 int changed; 87 code *fn; /* pointer to function's code vector */ 88 int fnchanged; 89 int pc; /* pc of start of function */ 90 var *next; /* next on hash or local list */ 91 }; 92 var *vlook(char*), *gvlook(char*), *newvar(char*, var*); 93 94 #define NVAR 521 95 96 var *gvar[NVAR]; /* hash for globals */ 97 98 #define new(type) ((type *)emalloc(sizeof(type))) 99 100 void *emalloc(long); 101 void *Malloc(ulong); 102 void efree(void *); 103 104 #define NOFILE 128 /* should come from <param.h> */ 105 106 struct here{ 107 tree *tag; 108 char *name; 109 struct here *next; 110 }; 111 int mypid; 112 113 /* 114 * Glob character escape in strings: 115 * In a string, GLOB must be followed by *?[ or GLOB. 116 * GLOB* matches any string 117 * GLOB? matches any single character 118 * GLOB[...] matches anything in the brackets 119 * GLOBGLOB matches GLOB 120 */ 121 #define GLOB ((char)0x01) 122 /* 123 * onebyte(c), twobyte(c), threebyte(c) 124 * Is c the first character of a one- two- or three-byte utf sequence? 125 */ 126 #define onebyte(c) ((c&0x80)==0x00) 127 #define twobyte(c) ((c&0xe0)==0xc0) 128 #define threebyte(c) ((c&0xf0)==0xe0) 129 130 char **argp; 131 char **args; 132 int nerror; /* number of errors encountered during compilation */ 133 int doprompt; /* is it time for a prompt? */ 134 /* 135 * Which fds are the reading/writing end of a pipe? 136 * Unfortunately, this can vary from system to system. 137 * 9th edition Unix doesn't care, the following defines 138 * work on plan 9. 139 */ 140 #define PRD 0 141 #define PWR 1 142 char Rcmain[], Fdprefix[]; 143 /* 144 * How many dot commands have we executed? 145 * Used to ensure that -v flag doesn't print rcmain. 146 */ 147 int ndot; 148 char *getstatus(void); 149 int lastc; 150 int lastword; 151