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