Blob


1 #include <utf.h>
2 #include <fmt.h>
3 #include <setjmp.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <bio.h>
8 #include <regexp9.h>
9 #include <time.h>
11 #define uchar _mkuchar
12 #define ushort _mkushort
13 #define uint _mkuint
14 #define ulong _mkulong
15 #define vlong _mkvlong
16 #define uvlong _mkuvlong
18 #define nil ((void*)0)
20 typedef unsigned char uchar;
21 typedef unsigned short ushort;
22 typedef unsigned int uint;
23 typedef unsigned long ulong;
25 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
27 #define OREAD O_RDONLY
28 #define OWRITE O_WRONLY
29 #define ORDWR O_RDWR
30 #define USED(x) if(x);else
31 #define remove unlink
32 #define seek lseek
33 #define exits(s) exit((s) && ((char*)s)[0] ? 1 : 0)
34 #define create(name, mode, perm) creat(name, perm)
35 #define ERRMAX 256
37 #undef assert
38 #define assert mkassert
39 extern Biobuf bout;
41 typedef struct Bufblock
42 {
43 struct Bufblock *next;
44 char *start;
45 char *end;
46 char *current;
47 } Bufblock;
49 typedef struct Word
50 {
51 char *s;
52 struct Word *next;
53 } Word;
55 typedef struct Envy
56 {
57 char *name;
58 Word *values;
59 } Envy;
61 extern Envy *envy;
63 typedef struct Rule
64 {
65 char *target; /* one target */
66 Word *tail; /* constituents of targets */
67 char *recipe; /* do it ! */
68 short attr; /* attributes */
69 short line; /* source line */
70 char *file; /* source file */
71 Word *alltargets; /* all the targets */
72 int rule; /* rule number */
73 Reprog *pat; /* reg exp goo */
74 char *prog; /* to use in out of date */
75 struct Rule *chain; /* hashed per target */
76 struct Rule *next;
77 } Rule;
79 extern Rule *rules, *metarules, *patrule;
81 /* Rule.attr */
82 #define META 0x0001
83 #define UNUSED 0x0002
84 #define UPD 0x0004
85 #define QUIET 0x0008
86 #define VIR 0x0010
87 #define REGEXP 0x0020
88 #define NOREC 0x0040
89 #define DEL 0x0080
90 #define NOVIRT 0x0100
92 #define NREGEXP 10
94 typedef struct Arc
95 {
96 short flag;
97 struct Node *n;
98 Rule *r;
99 char *stem;
100 char *prog;
101 char *match[NREGEXP];
102 struct Arc *next;
103 } Arc;
105 /* Arc.flag */
106 #define TOGO 1
108 typedef struct Node
110 char *name;
111 long time;
112 unsigned short flags;
113 Arc *prereqs;
114 struct Node *next; /* list for a rule */
115 } Node;
117 /* Node.flags */
118 #define VIRTUAL 0x0001
119 #define CYCLE 0x0002
120 #define READY 0x0004
121 #define CANPRETEND 0x0008
122 #define PRETENDING 0x0010
123 #define NOTMADE 0x0020
124 #define BEINGMADE 0x0040
125 #define MADE 0x0080
126 #define MADESET(n,m) n->flags = (n->flags&~(NOTMADE|BEINGMADE|MADE))|(m)
127 #define PROBABLE 0x0100
128 #define VACUOUS 0x0200
129 #define NORECIPE 0x0400
130 #define DELETE 0x0800
131 #define NOMINUSE 0x1000
133 typedef struct Job
135 Rule *r; /* master rule for job */
136 Node *n; /* list of node targets */
137 char *stem;
138 char **match;
139 Word *p; /* prerequistes */
140 Word *np; /* new prerequistes */
141 Word *t; /* targets */
142 Word *at; /* all targets */
143 int nproc; /* slot number */
144 struct Job *next;
145 } Job;
146 extern Job *jobs;
148 typedef struct Symtab
150 short space;
151 char *name;
152 void *value;
153 struct Symtab *next;
154 } Symtab;
156 enum {
157 S_VAR, /* variable -> value */
158 S_TARGET, /* target -> rule */
159 S_TIME, /* file -> time */
160 S_PID, /* pid -> products */
161 S_NODE, /* target name -> node */
162 S_AGG, /* aggregate -> time */
163 S_BITCH, /* bitched about aggregate not there */
164 S_NOEXPORT, /* var -> noexport */
165 S_OVERRIDE, /* can't override */
166 S_OUTOFDATE, /* n1\377n2 -> 2(outofdate) or 1(not outofdate) */
167 S_MAKEFILE, /* target -> node */
168 S_MAKEVAR, /* dumpable mk variable */
169 S_EXPORTED, /* var -> current exported value */
170 S_WESET, /* variable; we set in the mkfile */
171 S_INTERNAL /* an internal mk variable (e.g., stem, target) */
172 };
174 extern int debug;
175 extern int nflag, tflag, iflag, kflag, aflag, mflag;
176 extern int mkinline;
177 extern char *infile;
178 extern int nreps;
179 extern char *explain;
180 extern char *termchars;
181 extern int IWS;
182 extern char *shell;
183 extern char *shellname;
184 extern char *shflags;
186 #define SYNERR(l) (fprint(2, "mk: %s:%d: syntax error; ", infile, ((l)>=0)?(l):mkinline))
187 #define RERR(r) (fprint(2, "mk: %s:%d: rule error; ", (r)->file, (r)->line))
188 #define NAMEBLOCK 1000
189 #define BIGBLOCK 20000
191 #define SEP(c) (((c)==' ')||((c)=='\t')||((c)=='\n'))
192 #define WORDCHR(r) ((r) > ' ' && !utfrune("!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", (r)))
194 #define DEBUG(x) (debug&(x))
195 #define D_PARSE 0x01
196 #define D_GRAPH 0x02
197 #define D_EXEC 0x04
199 #define LSEEK(f,o,p) seek(f,o,p)
201 #define PERCENT(ch) (((ch) == '%') || ((ch) == '&'))
203 #include "fns.h"