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