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