Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/nmake/dump.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1984-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* make dump and trace routines
26
*/
27
28
#include "make.h"
29
30
static int dumpall; /* don't be selective */
31
32
/*
33
* list a rule name in re-readable form
34
*/
35
36
static void
37
dumpname(register Sfio_t* sp, register Rule_t* r, char* sep)
38
{
39
register char* s;
40
register char* t;
41
register int paren;
42
int quote;
43
44
if (!dumpall && state.list)
45
{
46
s = (r->property & P_state) || (r->dynamic & D_alias) ? r->name : unbound(r);
47
for (t = s, paren = 0; *t && (paren || !istype(*t, C_TERMINAL)); t++)
48
if (*t == '(')
49
paren++;
50
else if (*t == ')')
51
paren--;
52
if (quote = (*t || t == s))
53
sfputc(sp, '"');
54
for (; *s; s++)
55
{
56
switch (*s)
57
{
58
case '"':
59
if (quote)
60
sfputc(sp, '\\');
61
break;
62
case '$':
63
if (*(s + 1) == '(')
64
sfputc(sp, '$');
65
break;
66
}
67
sfputc(sp, *s);
68
}
69
if (quote)
70
sfputc(sp, '"');
71
}
72
else
73
{
74
if (*r->name)
75
sfputr(sp, r->name, -1);
76
else
77
{
78
sfputc(sp, '"');
79
sfputc(sp, '"');
80
}
81
if (!(r->property & P_state) && r->uname)
82
sfprintf(sp, "==%s", r->uname);
83
}
84
#if DEBUG
85
if (state.test & 0x00004000)
86
sfprintf(sp, "@%p", r);
87
#endif
88
sfputr(sp, sep, -1);
89
}
90
91
/*
92
* list a single rule and its attributes
93
*/
94
95
static int
96
listrule(const char* s, char* v, void* h)
97
{
98
register Rule_t* r = (Rule_t*)v;
99
register List_t* p;
100
register int n;
101
register Sfio_t* sp = (Sfio_t*)h;
102
103
if (!dumpall && state.list && (r->name != s ||
104
!(r->property & (P_accept|P_after|P_always|P_archive|P_before|P_command|P_force|P_foreground|P_functional|P_ignore|P_immediate|P_implicit|P_joint|P_local|P_make|P_multiple|P_operator|P_parameter|P_read|P_repeat|P_target|P_terminal|P_use|P_virtual)) && !((r->property & P_attribute) && r->attribute) && !r->semaphore))
105
return 0;
106
sfputc(sp, '\n');
107
dumpname(sp, r, " : ");
108
if (dumpall || !state.list)
109
{
110
if ((r->property & P_staterule) && isaltstate(r->name))
111
sfputr(sp, "cancel=", -1);
112
sfprintf(sp, "[%s] ", timestr(r->time));
113
}
114
if (!(r->property & P_attribute))
115
{
116
if (r->attribute)
117
for (p = internal.attribute->prereqs; p; p = p->next)
118
if (r->attribute & p->rule->attribute)
119
sfputr(sp, p->rule->name, ' ');
120
if (r->scan)
121
for (p = internal.scan->prereqs; p; p = p->next)
122
if (p->rule->scan == r->scan)
123
{
124
sfputr(sp, p->rule->name, ' ');
125
break;
126
}
127
}
128
if (dumpall || !state.list)
129
{
130
if (r->property & P_state)
131
{
132
if (r->property & P_staterule)
133
{
134
if (!isaltstate(r->name))
135
sfprintf(sp, "event=[%s] ", timestr(r->event));
136
}
137
else if (r->property & P_statevar)
138
sfputr(sp, "statevar", ' ');
139
else
140
sfputr(sp, "state", ' ');
141
}
142
if (r->view > r->preview)
143
sfprintf(sp, "view=%c/%c ", VIEWOFFSET + r->view, VIEWOFFSET + r->preview);
144
else if (r->view)
145
sfprintf(sp, "view=%c ", VIEWOFFSET + r->view);
146
else if (r->preview && r->preview <= state.maxview)
147
sfprintf(sp, "preview=%c ", VIEWOFFSET + r->preview);
148
if (r->action && !*r->action)
149
sfputr(sp, "null", ' ');
150
if (r->must)
151
sfprintf(sp, "must=%d ", r->must);
152
if (r->semaphore)
153
sfprintf(sp, "semaphore=%d ", r->semaphore - 1);
154
155
if (r->property & P_archive)
156
sfputr(sp, "archive", ' ');
157
if (r->property & P_accept)
158
sfputr(sp, "accept", ' ');
159
if (r->active)
160
sfputr(sp, "active", ' ');
161
if (r->property & P_after)
162
sfputr(sp, "after", ' ');
163
if (r->property & P_always)
164
sfputr(sp, "always", ' ');
165
if (r->property & P_attribute)
166
{
167
if (r->attribute)
168
sfprintf(sp, "attribute=0x%08x ", r->attribute);
169
else if (r->scan)
170
sfprintf(sp, "scan=%d ", r->scan);
171
else
172
sfputr(sp, "attribute", ' ');
173
}
174
if (r->property & P_before)
175
sfputr(sp, "before", ' ');
176
if (r->property & P_command)
177
sfputr(sp, "command", ' ');
178
if (r->property & P_dontcare)
179
sfputr(sp, "dontcare", ' ');
180
if (r->property & P_force)
181
sfputr(sp, "force", ' ');
182
if (r->property & P_foreground)
183
sfputr(sp, "foreground", ' ');
184
if (r->property & P_functional)
185
sfputr(sp, "functional", ' ');
186
if (r->property & P_ignore)
187
sfputr(sp, "ignore", ' ');
188
if (r->property & P_immediate)
189
sfputr(sp, "immediate", ' ');
190
if (r->property & P_implicit)
191
sfputr(sp, "implicit", ' ');
192
if (r->property & P_internal)
193
sfputr(sp, "internal", ' ');
194
if (r->property & P_joint)
195
sfputr(sp, "joint", ' ');
196
if (r->property & P_local)
197
sfputr(sp, "local", ' ');
198
if (r->property & P_make)
199
sfputr(sp, "make", ' ');
200
if (r->property & P_metarule)
201
sfputr(sp, "metarule", ' ');
202
if (r->property & P_multiple)
203
sfputr(sp, "multiple", ' ');
204
if (r->property & P_operator)
205
sfputr(sp, "operator", ' ');
206
if (r->property & P_parameter)
207
sfputr(sp, "parameter", ' ');
208
if (r->property & P_read)
209
sfputr(sp, "read", ' ');
210
if (r->property & P_readonly)
211
sfputr(sp, "readonly", ' ');
212
if (r->property & P_repeat)
213
sfputr(sp, "repeat", ' ');
214
if (r->property & P_target)
215
sfputr(sp, "target", ' ');
216
if (r->property & P_terminal)
217
sfputr(sp, "terminal", ' ');
218
if (r->property & P_use)
219
sfputr(sp, "use", ' ');
220
if (r->property & P_virtual)
221
sfputr(sp, "virtual", ' ');
222
223
if (r->dynamic & D_alias)
224
sfputr(sp, "alias", ' ');
225
if (r->dynamic & D_aliaschanged)
226
sfputr(sp, "aliaschanged", ' ');
227
#if BINDINDEX
228
if (r->dynamic & D_bindindex)
229
sfputr(sp, "bindindex", ' ');
230
#endif
231
if (r->dynamic & D_built)
232
sfputr(sp, "built", ' ');
233
if (r->dynamic & D_cached)
234
sfputr(sp, "cached", ' ');
235
if (r->dynamic & D_compiled)
236
sfputr(sp, "compiled", ' ');
237
if (r->dynamic & D_context)
238
sfputr(sp, "context", ' ');
239
if (r->dynamic & D_dynamic)
240
sfputr(sp, "dynamic", ' ');
241
if (r->dynamic & D_entries)
242
sfputr(sp, "entries", ' ');
243
if (r->dynamic & D_garbage)
244
sfputr(sp, "garbage", ' ');
245
if (r->dynamic & D_global)
246
sfputr(sp, "global", ' ');
247
if (r->dynamic & D_hasafter)
248
sfputr(sp, "hasafter", ' ');
249
if (r->dynamic & D_hasbefore)
250
sfputr(sp, "hasbefore", ' ');
251
if (r->dynamic & D_hasmake)
252
sfputr(sp, "hasmake", ' ');
253
if (r->dynamic & D_hasscope)
254
sfputr(sp, "hasscope", ' ');
255
if (r->dynamic & D_hassemaphore)
256
sfputr(sp, "hassemaphore", ' ');
257
if (r->dynamic & D_index)
258
sfputr(sp, "index", ' ');
259
if (r->dynamic & D_intermediate)
260
sfputr(sp, "intermediate", ' ');
261
if (r->dynamic & D_lower)
262
sfputr(sp, "lower", ' ');
263
if (r->dynamic & D_lowres)
264
sfputr(sp, "lowres", ' ');
265
if (r->dynamic & D_member)
266
sfputr(sp, "member", ' ');
267
if (r->dynamic & D_membertoo)
268
sfputr(sp, "membertoo", ' ');
269
if (r->dynamic & D_regular)
270
sfputr(sp, "regular", ' ');
271
if (r->dynamic & D_same)
272
sfputr(sp, "same", ' ');
273
if (r->dynamic & D_scanned)
274
sfputr(sp, "scanned", ' ');
275
if (r->dynamic & D_scope)
276
sfputr(sp, "scope", ' ');
277
if (r->dynamic & D_select0)
278
sfputr(sp, "select0", ' ');
279
if (r->dynamic & D_select1)
280
sfputr(sp, "select1", ' ');
281
if (r->dynamic & D_source)
282
sfputr(sp, "source", ' ');
283
if (r->dynamic & D_triggered)
284
sfputr(sp, "triggered", ' ');
285
if ((r->property & (P_state|P_statevar)) == P_state)
286
sfputr(sp, "state", -1);
287
else if (!(r->dynamic & D_bound))
288
sfputr(sp, "unbound", -1);
289
else
290
switch (r->status)
291
{
292
case NOTYET:
293
break;
294
case UPDATE:
295
sfputr(sp, "UPDATE", -1);
296
break;
297
case MAKING:
298
sfputr(sp, "MAKING", -1);
299
break;
300
case TOUCH:
301
sfputr(sp, "TOUCH", -1);
302
break;
303
case EXISTS:
304
sfputr(sp, "EXISTS", -1);
305
break;
306
case IGNORE:
307
sfputr(sp, "IGNORE", -1);
308
break;
309
case FAILED:
310
sfputr(sp, "FAILED", -1);
311
break;
312
case OLDRULE:
313
sfputr(sp, "OLDRULE", -1);
314
break;
315
#if DEBUG
316
default:
317
sfprintf(sp, "STATUS=%d", r->status);
318
break;
319
#endif
320
}
321
if (r->mark)
322
{
323
sfputr(sp, " |mark", '|');
324
if (r->mark & M_bind)
325
sfputr(sp, "bind", '|');
326
if (r->mark & M_compile)
327
sfputr(sp, "compile", '|');
328
if (r->mark & M_directory)
329
sfputr(sp, "directory", '|');
330
if (r->mark & M_generate)
331
sfputr(sp, "generate", '|');
332
if (r->mark & M_mark)
333
sfputr(sp, "mark", '|');
334
if (r->mark & M_metarule)
335
sfputr(sp, "metarule", '|');
336
if (r->mark & M_scan)
337
sfputr(sp, "scan", '|');
338
if (r->mark & M_waiting)
339
sfputr(sp, "waiting", '|');
340
}
341
sfputc(sp, '\n');
342
}
343
else
344
{
345
if (r->property & P_accept)
346
sfputr(sp, internal.accept->name, ' ');
347
if (r->property & P_after)
348
sfputr(sp, internal.after->name, ' ');
349
if (r->property & P_always)
350
sfputr(sp, internal.always->name, ' ');
351
if (r->property & P_attribute)
352
{
353
if (r->attribute)
354
sfputr(sp, internal.attribute->name, ' ');
355
else if (r->scan)
356
sfputr(sp, internal.scan->name, ' ');
357
}
358
if (r->property & P_before)
359
sfputr(sp, internal.before->name, ' ');
360
if (r->property & P_force)
361
sfputr(sp, internal.force->name, ' ');
362
if (r->property & P_foreground)
363
sfputr(sp, internal.foreground->name, ' ');
364
if (r->property & P_functional)
365
sfputr(sp, internal.functional->name, ' ');
366
if (r->property & P_joint)
367
sfputr(sp, internal.joint->name, ' ');
368
if (r->property & P_make)
369
sfputr(sp, internal.make->name, ' ');
370
if (r->property & P_multiple)
371
sfputr(sp, internal.multiple->name, ' ');
372
if (r->action && !*r->action)
373
sfputr(sp, internal.null->name, ' ');
374
if (r->property & P_archive)
375
sfputr(sp, internal.archive->name, ' ');
376
if (r->property & P_command)
377
sfputr(sp, internal.command->name, ' ');
378
if (r->property & P_ignore)
379
sfputr(sp, internal.ignore->name, ' ');
380
if (r->property & P_immediate)
381
sfputr(sp, internal.immediate->name, ' ');
382
if (r->property & P_implicit)
383
sfputr(sp, internal.implicit->name, ' ');
384
if (r->property & P_local)
385
sfputr(sp, internal.local->name, ' ');
386
if (r->property & P_operator)
387
sfputr(sp, internal.op->name, ' ');
388
if (r->property & P_parameter)
389
sfputr(sp, internal.parameter->name, ' ');
390
if (r->property & P_repeat)
391
sfputr(sp, internal.repeat->name, ' ');
392
if (r->semaphore)
393
for (n = r->semaphore - 1; n; n--)
394
sfputr(sp, internal.semaphore->name, ' ');
395
if (r->property & P_terminal)
396
sfputr(sp, internal.terminal->name, ' ');
397
if ((r->property & (P_metarule|P_use))
398
== P_use) sfputr(sp, internal.use->name, ' ');
399
if (r->property & P_virtual)
400
sfputr(sp, internal.virt->name, ' ');
401
}
402
if (p = r->prereqs)
403
{
404
if (dumpall || !state.list)
405
sfputr(sp, " prerequisites:", ' ');
406
for (; p; p = p->next)
407
dumpname(sp, p->rule, " ");
408
sfputc(sp, '\n');
409
}
410
else if (!dumpall && state.list)
411
sfputc(sp, '\n');
412
if (r->action && *r->action)
413
{
414
if (dumpall || !state.list)
415
sfputr(sp, " action:", '\n');
416
dumpaction(sp, NiL, r->action, "\t");
417
}
418
if ((dumpall || !state.list) && (r->property & P_statevar) && r->statedata)
419
sfprintf(sp, " state: %s\n", r->statedata);
420
return 0;
421
}
422
423
/*
424
* list a single variable and its value
425
*/
426
427
static int
428
listvar(const char* s, char* u, void* h)
429
{
430
register Var_t* v = (Var_t*)u;
431
register char* t;
432
register char* q;
433
register Sfio_t* sp = (Sfio_t*)h;
434
435
if (dumpall || !(v->property & V_import) && (!state.list || !isintvar(v->name)))
436
{
437
if (!dumpall && state.list)
438
{
439
for (q = (char*)s; istype(*q, C_ID1|C_ID2); q++);
440
if (*q)
441
q = "\"";
442
}
443
else
444
q = null;
445
sfprintf(sp, "%s%s%s ", q, s, q);
446
#if DEBUG
447
if (state.test & 0x00004000)
448
sfprintf(sp, "@%p ", v);
449
#endif
450
if (dumpall || !state.list)
451
{
452
sfputr(sp, "[", ' ');
453
if (v->property & V_append)
454
sfputr(sp, "append", ' ');
455
if (v->property & V_auxiliary)
456
sfputr(sp, "auxiliary", ' ');
457
if (v->property & V_builtin)
458
sfputr(sp, "builtin", ' ');
459
if (v->property & V_free)
460
sfputr(sp, "free", ' ');
461
if (v->property & V_frozen)
462
sfputr(sp, "frozen", ' ');
463
if (v->property & V_functional)
464
sfputr(sp, "functional", ' ');
465
if (v->property & V_import)
466
sfputr(sp, "import", ' ');
467
if (v->property & V_local_D)
468
sfputr(sp, "local_D", ' ');
469
if (v->property & V_local_E)
470
sfputr(sp, "local_E", ' ');
471
if (v->property & V_oldvalue)
472
{
473
sfputr(sp, "oldvalue", -1);
474
if (t = getold(s))
475
sfprintf(sp, "=`%s'", t);
476
sfputc(sp, ' ');
477
}
478
if (v->property & V_readonly)
479
sfputr(sp, "readonly", ' ');
480
if (v->property & V_restored)
481
sfputr(sp, "restored", ' ');
482
if (v->property & V_retain)
483
sfputr(sp, "retain", ' ');
484
if (v->property & V_scan)
485
sfputr(sp, "scan", ' ');
486
if (v->property & V_scope)
487
sfputr(sp, "scope", ' ');
488
sfputr(sp, "]", ' ');
489
}
490
sfprintf(sp, "= %s", t = v->value);
491
if ((v->property & V_auxiliary) && (v = auxiliary(v->name, 0)))
492
{
493
if (!dumpall && state.list)
494
sfprintf(sp, "\n%s%s%s ", q, s, q);
495
else if (*t)
496
sfputc(sp, ' ');
497
sfprintf(sp, "&= %s", v->value);
498
}
499
sfputc(sp, '\n');
500
}
501
return 0;
502
}
503
504
/*
505
* dump rules and variables
506
*/
507
508
void
509
dump(Sfio_t* sp, int verbose)
510
{
511
static int dumping;
512
513
if (!dumping++)
514
{
515
if (state.vardump || state.ruledump)
516
state.list = 0;
517
if (verbose)
518
hashdump(NiL, (error_info.trace <= -20) ? HASH_BUCKET : 0);
519
if (state.list)
520
sfprintf(sp, "/* %s */\n\n", version);
521
if (!dumpall && (state.list || state.vardump))
522
{
523
sfprintf(sp, "\n/* Variables */\n\n");
524
hashwalk(table.var, 0, listvar, sp);
525
}
526
if (!dumpall && (state.list || state.ruledump))
527
{
528
sfprintf(sp, "\n/* Rules */\n");
529
hashwalk(table.rule, 0, listrule, sp);
530
}
531
sfsync(sp);
532
dumping--;
533
}
534
}
535
536
/*
537
* dump regression prefix,name,value
538
*/
539
540
void
541
dumpregress(register Sfio_t* sp, const char* prefix, const char* name, register char* value)
542
{
543
register int c;
544
register int n;
545
int* rp;
546
char* bp;
547
char* np;
548
549
static int index;
550
551
sfprintf(sp, "%s%s %s ", state.mam.label, prefix, name ? name : "-");
552
n = -1;
553
if (value)
554
for (;;)
555
{
556
switch (c = *value++)
557
{
558
case 0:
559
break;
560
case '\n':
561
sfprintf(sp, "\n%s%s %s ", state.mam.label, prefix, name ? name : "-");
562
n = 1;
563
continue;
564
case '\t':
565
c = ' ';
566
/*FALLTHROUGH*/
567
case ' ':
568
if (n < 0 || *value == ' ' || *value == '\t' || *value == 0 || *value == '\n')
569
continue;
570
/*FALLTHROUGH*/
571
case '\'':
572
case '"':
573
case '=':
574
case ':':
575
sfputc(sp, c);
576
n = 1;
577
continue;
578
case '/':
579
if (n)
580
{
581
bp = np = value - 1;
582
for (;;)
583
{
584
switch (*value++)
585
{
586
case ' ':
587
case '\t':
588
case '\n':
589
case '\'':
590
case '"':
591
case ':':
592
case 0:
593
break;
594
case '/':
595
np = value - 1;
596
/*FALLTHROUGH*/
597
default:
598
continue;
599
}
600
break;
601
}
602
c = *--value;
603
*value = 0;
604
if (strmatch(np, "*.*"))
605
{
606
*value = c;
607
c = *(value = np);
608
*value = 0;
609
}
610
if (!(rp = getreg(bp)))
611
{
612
rp = newof(0, int, 1, 0);
613
*rp = ++index;
614
putreg(0, rp);
615
}
616
sfprintf(sp, "${PATH_%d}", *rp);
617
*value = c;
618
n = 0;
619
}
620
else
621
sfputc(sp, c);
622
continue;
623
case '-':
624
case '+':
625
sfputc(sp, c);
626
if (n)
627
{
628
if (!(c = *value++))
629
break;
630
sfputc(sp, c);
631
n = isalnum(c) ? 1 : 0;
632
}
633
continue;
634
default:
635
sfputc(sp, c);
636
n = 0;
637
continue;
638
}
639
break;
640
}
641
sfputc(sp, '\n');
642
}
643
644
/*
645
* dump an action placing prefix at the beginning of each line
646
*/
647
648
void
649
dumpaction(Sfio_t* sp, const char* name, register char* action, register const char* prefix)
650
{
651
register char* s;
652
char* mamlabel;
653
char* sep;
654
655
if (prefix)
656
{
657
mamlabel = null;
658
name = null;
659
sep = null;
660
}
661
else
662
{
663
if (state.mam.regress)
664
{
665
dumpregress(sp, "exec", name, action);
666
return;
667
}
668
if (state.mam.out)
669
{
670
mamlabel = state.mam.label;
671
prefix = "exec";
672
if (!name)
673
name = "-";
674
sep = " ";
675
}
676
else
677
{
678
while (isspace(*action))
679
action++;
680
if (!*action)
681
return;
682
mamlabel = null;
683
prefix = "+";
684
name = null;
685
sep = null;
686
}
687
}
688
for (;;)
689
{
690
if (s = strchr(action, '\n'))
691
*s = 0;
692
sfprintf(sp, "%s%s %s%s%s\n", mamlabel, prefix, name, sep, action);
693
if (!s)
694
break;
695
*s++ = '\n';
696
action = s;
697
}
698
sfsync(sp);
699
}
700
701
/*
702
* dump variable info
703
*/
704
705
void
706
dumpvar(Sfio_t* sp, register Var_t* v)
707
{
708
dumpall++;
709
listvar(v->name, (char*)v, sp);
710
sfsync(sp);
711
dumpall--;
712
}
713
714
/*
715
* dump rule info
716
*/
717
718
void
719
dumprule(Sfio_t* sp, register Rule_t* r)
720
{
721
register int i;
722
register Rule_t* z;
723
724
dumpall++;
725
z = 0;
726
while ((r->dynamic & D_alias) && r != z)
727
{
728
listrule(r->name, (char*)r, sp);
729
z = r;
730
if (!(r = getrule(unbound(r))))
731
r = z;
732
}
733
if (r != z)
734
listrule(r->name, (char*)r, sp);
735
if (!(r->property & P_state))
736
for (i = RULE; i <= STATERULES; i++)
737
if (z = staterule(i, r, NiL, -1))
738
listrule(z->name, (char*)z, sp);
739
sfsync(sp);
740
dumpall--;
741
}
742
743