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 #undef NSIG
13 #undef SIGINT
14 #undef SIGQUIT
15 #define NSIG 32
16 #define SIGINT 2
17 #define SIGQUIT 3
18 #endif
19 #ifdef V9
20 #include <signal.h>
21 #include <libc.h>
22 #endif
23 #ifdef Sun
24 #include <signal.h>
25 #endif
26 #define YYMAXDEPTH 500
27 #ifndef PAREN
28 #ifndef YYMAJOR
29 #include "x.tab.h"
30 #endif
31 #endif
33 #undef pipe /* so that /dev/fd works */
34 #define searchpath rcsearchpath /* avoid new libc function */
36 /* some systems define a global "var", "thread" */
37 #undef var
38 #define var rcvar
39 #undef thread
40 #define thread rcthread
42 typedef struct tree tree;
43 typedef struct word word;
44 typedef struct io io;
45 typedef union code code;
46 typedef struct var var;
47 typedef struct list list;
48 typedef struct redir redir;
49 typedef struct thread thread;
50 typedef struct builtin builtin;
52 struct tree{
53 int type;
54 int rtype, fd0, fd1; /* details of REDIR PIPE DUP tokens */
55 char *str;
56 int quoted;
57 int iskw;
58 tree *child[3];
59 tree *next;
60 };
61 tree *newtree(void);
62 tree *token(char*, int), *klook(char*), *tree1(int, tree*);
63 tree *tree2(int, tree*, tree*), *tree3(int, tree*, tree*, tree*);
64 tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*);
65 tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*);
66 tree *simplemung(tree*), *heredoc(tree*);
67 void freetree(tree*);
68 tree *cmdtree;
69 /*
70 * The first word of any code vector is a reference count.
71 * Always create a new reference to a code vector by calling codecopy(.).
72 * Always call codefree(.) when deleting a reference.
73 */
74 union code{
75 void (*f)(void);
76 int i;
77 char *s;
78 };
79 char *promptstr;
80 #define NTOK 8192
81 char tok[NTOK];
82 #define APPEND 1
83 #define WRITE 2
84 #define READ 3
85 #define HERE 4
86 #define DUPFD 5
87 #define CLOSE 6
88 #define RDWR 7
89 struct var{
90 char *name; /* ascii name */
91 word *val; /* value */
92 int changed;
93 code *fn; /* pointer to function's code vector */
94 int fnchanged;
95 int pc; /* pc of start of function */
96 var *next; /* next on hash or local list */
97 void (*changefn)(var*);
98 };
99 var *vlook(char*), *gvlook(char*), *newvar(char*, var*);
100 #define NVAR 521
101 var *gvar[NVAR]; /* hash for globals */
102 #define new(type) ((type *)emalloc(sizeof(type)))
103 char *emalloc(long);
104 void *Malloc(ulong);
105 void efree(char*);
106 #define NOFILE 128 /* should come from <param.h> */
107 struct here{
108 tree *tag;
109 char *name;
110 struct here *next;
111 };
112 int mypid;
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 #define fourbyte(c) ((c&0xf8)==0xf0)
131 char **argp;
132 char **args;
133 int nerror; /* number of errors encountered during compilation */
134 extern int doprompt; /* is it time for a prompt? */
135 /*
136 * Which fds are the reading/writing end of a pipe?
137 * Unfortunately, this can vary from system to system.
138 * 9th edition Unix doesn't care, the following defines
139 * work on plan 9.
140 */
141 #define PRD 0
142 #define PWR 1
143 extern char *Rcmain(), Fdprefix[];
144 #define register
145 /*
146 * How many dot commands have we executed?
147 * Used to ensure that -v flag doesn't print rcmain.
148 */
149 int ndot;
150 char *getstatus(void);
151 int lastc;
152 int lastword;
153 int kidpid;