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