Blob


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