-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrpg.c
230 lines (214 loc) · 5.07 KB
/
strpg.c
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "strpg.h"
#include "strawk/mt19937-64.h"
#include "threads.h"
#include "cmd.h"
#include "drw.h"
#include "layout.h"
#include "fs.h"
#include "ui.h"
int gottagofast = 0;
typedef struct Input Input;
struct Input{
int type;
char *path;
};
static Input *files;
void
xsrand(u64int s)
{
init_genrand64(s);
}
float
xfrand(void)
{
return genrand64_real2(); /* [0,1) */
}
u32int
xlrand(void)
{
return genrand64_int63() & (1ULL<<32)-1;
}
u32int
xnrand(u32int lim)
{
return genrand64_int64() % lim;
}
void
quit(void)
{
sysquit();
}
static void
load(void)
{
Input *in, *end;
for(in=files, end=in+dylen(files); in!=end; in++){
switch(in->type){
/* defer anything that must be loaded after the graph(s) */
case FFlayout:
pushcmd("importlayout(\"%s\")", in->path);
break;
case FFcsv:
pushcmd("readcsv(\"%s\")", in->path);
break;
default:
if(loadfs(in->path, in->type) < 0)
sysfatal("could not load file %s: %s", in->path, error());
break;
}
}
flushcmd();
dyfree(files);
}
static void
pushfile(char *file, int type)
{
Input in;
if(file == nil || type == FFdead || type >= FFnil){
warn("invalid input file\n");
return;
}
if(access(file, AREAD) < 0)
sysfatal("could not load file %s: %s", file, error());
in = (Input){type, file};
dypush(files, in);
}
static void
help(void)
{
warn("usage: %s [-AHMWZbhvw] [-f FILE] [-l ALG] [-n FILE] [-t N] [-c FILE] FILE\n", argv0);
warn(
"-b White-on-black color theme\n"
"-c FILE Load tags from csv FILE\n"
"-f FILE Load layout from FILE\n"
"-h Print usage information and exit\n"
"-l ALG Set layouting algorithm (default: pfr)\n"
"-n FILE Run layouting headless, saving to FILE periodically\n"
"-t N Set number of layouting threads (1-1024, default: 4)\n"
"-v Print version and exit\n"
"-w Do not wait for all files to load to start layouting\n"
"-A Disable transparency (for performance)\n"
"-H Enable Hi-DPI mode\n"
"-M Enable 4x multisample anti-aliasing (MSAA)\n"
"-Z Minimize node depth (z-axis) offsets in 2d layouts\n"
"-W Do not suppress warning messages\n"
"ALG may be one of:\n"
" fr Parallelized variant of Fruchterman-Reingold (default)\n"
" 3d Experimental 3d version of the above\n"
);
quit();
}
static void
usage(void)
{
sysfatal("usage: %s [-AHMWZbhvw] [-f FILE] [-l ALG] [-n FILE] [-t N] [-c FILE] FILE", argv0);
}
static void
parseargs(int argc, char **argv)
{
int type;
char *s;
type = FFgfa;
ARGBEGIN{
case 'A': drawing.flags |= DFnoalpha; break;
case 'D':
s = EARGF(usage());
if(strcmp(s, "all") == 0)
debug |= Debugtheworld;
else if(strcmp(s, "awk") == 0)
debug |= Debugawk;
else if(strcmp(s, "cmd") == 0)
debug |= Debugcmd;
else if(strcmp(s, "coarse") == 0)
debug |= Debugcoarse;
else if(strcmp(s, "draw") == 0)
debug |= Debugdraw;
else if(strcmp(s, "extmem") == 0)
debug |= Debugextmem;
else if(strcmp(s, "fs") == 0)
debug |= Debugfs;
else if(strcmp(s, "graph") == 0)
debug |= Debuggraph;
else if(strcmp(s, "layout") == 0)
debug |= Debuglayout;
else if(strcmp(s, "load") == 0)
debug |= Debugload | Debugperf;
else if(strcmp(s, "meta") == 0)
debug |= Debugmeta;
else if(strcmp(s, "perf") == 0)
debug |= Debugperf;
else if(strcmp(s, "render") == 0)
debug |= Debugrender;
else if(strcmp(s, "strawk") == 0)
debug |= Debugstrawk;
else{
warn("unknown debug component %s\n", s);
usage();
}
break;
case 'H': drawing.flags |= DFhidpi; break;
case 'M': drawing.flags |= DFmsaa; break;
case 'W': debug |= Debuginfo; break;
case 'Z': drawing.flags |= DFnodepth; break;
case 'b': drawing.flags |= DFhaxx0rz; break;
case 'c': pushfile(EARGF(usage()), FFcsv); break;
case 'f': pushfile(EARGF(usage()), FFlayout); break;
case 'h': help(); break;
case 'l':
s = EARGF(usage());
if(strcmp(s, "fr") == 0)
deflayout = LLpfr;
else if(strcmp(s, "3d") == 0)
deflayout = LLpfr3d;
else
sysfatal("unknown layout type");
break;
case 'n':
pushcmd("layfile=\"%s\"", EARGF(usage()));
drawing.flags |= DFnope;
break;
case 't':
nlaythreads = atoi(EARGF(usage()));
if(nlaythreads <= 0 || nlaythreads > 1024){
warn("invalid number of threads %d ∉ [1,1024]\n", nlaythreads);
usage();
}
break;
case 'v':
print(VERSION "\n");
quit();
case 'w': gottagofast = 1; break;
default: usage();
}ARGEND
if(*argv == nil)
help();
for(; *argv!=nil; argv++)
pushfile(*argv, type);
}
/* note: npe already sets mainstacksize higher before renaming main */
int
main(int argc, char **argv)
{
init_genrand64(time(nil));
initsys();
initlog();
initlayout();
initcmd(); /* fork repl before starting other threads */
parseargs(argc, argv);
initdrw(); /* load default drawing state before files override it */
initfs();
load();
if(drawing.flags & DFnope || debug & Debugload)
for(;;){
sleep(10);
if(drawing.flags & DFnope){
pushcmd("exportlayout(layfile)");
flushcmd();
}
}
initui();
waitforit();
evloop();
quit();
return 0;
}