-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpl.h
191 lines (168 loc) · 4.14 KB
/
impl.h
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* cdoc
* Copyright (c) 2019 Matthew Veety.
* See LICENSE for details
*/
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <assert.h>
#include <setjmp.h>
#include <stddef.h>
#include <math.h>
#include <ctype.h>
#include <sys/types.h>
// because, you know, i'm a plan 9 programmer
#define nil ((void*)0)
typedef signed char schar;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long uvlong;
typedef long long vlong;
typedef uvlong u64int;
typedef vlong s64int;
typedef uint8_t u8int;
typedef int8_t s8int;
typedef uint16_t u16int;
typedef int16_t s16int;
typedef uintptr_t uintptr;
typedef intptr_t intptr;
typedef uint u32int;
typedef int s32int;
typedef u32int uint32;
typedef s32int int32;
typedef u16int uint16;
typedef s16int int16;
typedef u64int uint64;
typedef s64int int64;
typedef u8int uint8;
typedef s8int int8;
// actual stuff
#define VERSION "release 1"
#define TOKMAX 256
#define MAXARGS 25
#define DBG1(fname, linen) dprintf(2, fname ":" #linen ": ")
#define DBG2(fn, ln) DBG1(fn, ln)
#define DBG(...) if(debugprint){ DBG2( __FILE__ , __LINE__ ); \
dprintf(2, __VA_ARGS__); \
dprintf(2, "\n"); }
typedef struct Docfile Docfile;
typedef struct Docline Docline;
typedef struct Function Function;
typedef struct Token Token;
typedef struct Searchres Searchres;
enum {
TokNone,
TokDocline, // //@ ... \n
TokComment, // // ... \n (ignored)
TokPreproc, // # ... \n
TokComstart, // /* (ignored)
TokComend, // */ (ignored)
TokNumber, // [0-9][0-9a-zA-Z]*
TokString, // "..."
TokLCBracket, // {
TokRCBracket, // }
TokLParen, // (
TokRParen, // )
TokLSBracket, // [
TokRSBracket, // ]
TokSemicolon, // ;
TokSym, // symbols (vars, etc)
TokComma, // ,
TokAsterisk, // *
TokEqual, // =
TokOther, // everything else
};
enum {
TabSpaces,
TabNative,
};
struct Token {
Token *prev;
int type;
int linenum;
char *fname;
char *dat;
Token *next;
};
struct Function {
char *fname;
int linenum;
char *type;
char *name;
int argn;
char *argtypes[MAXARGS];
char *argnames[MAXARGS];
Docline *doclines;
Function *next;
};
struct Docfile {
char *fname;
Docline *globaldocs;
Function *funs;
Docfile *next;
};
struct Docline {
char *fname;
int linenum;
char *dat;
Docline *next;
};
struct Searchres {
Function *fn;
Searchres *next;
};
// util.c
extern volatile int debugprint;
extern void panic(char *s);
extern void error(char *s);
extern void fileerror(char *fname, char *s);
extern void warn(char *s);
extern void *emallocz(uintptr sz);
// toks.c
extern Token *toks;
extern Token *curtok;
extern volatile int EOTpanic;
extern void addtoken(char *str, int type, char *fname, int linenum);
extern Token *getnexttoken(void);
extern Token *getprevtoken(void);
extern Token *getcurtoken(void);
extern Token *getlasttoken(void);
extern void freetoks(Token *tok);
extern char *toktypestring(int typ);
extern void fprinttoken(int fd, char *prefix, Token *tok);
extern void fprintalltoks(int fd, char *prefix);
// lex.l/lex.yy.c
extern void tokfile(int fd, char *fname);
// parse.c
extern Docline *makedocline(Token *tok);
extern Function *makefunction(void);
extern Docfile *makedocfile(char *fname);
// mem.c
extern void freedoclines(Docline *dl);
extern void freefun(Function *fn);
extern void freefuns(Function *fn);
extern void freedocfile(Docfile *df, int recurse);
// printer.c
extern int tabtype;
extern int tabstop;
extern void docfileprinter(int ofd, Docfile *df, int tab, int printfname);
extern void functionprinter(int ofd, Function *fn, int tab, int lastfn);
// files.c
extern void pipefds(int ifd, int ofd);
extern void pipefiles(char *ifile, char *ofile);
extern void readfile(char *ifile);
extern Docfile *processfile(char *ifile, int aifd);
extern void emitdocfile(Docfile *df, char *ofile, int aofd);
extern void cleanup(Docfile *df);
// search.c
extern Searchres *findindocfile(Docfile *df, char *terms);
extern void searchresprinter(int ofd, Searchres *sr, int tab);
extern void allsearchresprinter(int ofd, Searchres *sr, int tab);
// main.c