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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
|
%{
/*-
* Copyright (c) 1988 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)mkmake.y 4.2 (Berkeley) 4/26/91";*/
static char rcsid[] = "$Id: mkmake.y,v 1.2 2000/07/06 08:51:06 deraadt Exp $";
#endif /* not lint */
typedef struct string {
int
hashval,
length;
char
*string;
struct string
*next;
} string_t;
/*
* The deal with these is that they exist on various lists.
*
* First off, they are on a temporary list during the time they
* are in the active focus of the parser.
*
* Secondly, they live on one of three queues:
* 1. Variables
* 2. Targets
* 3. Actions
* (and, we restrict any given one to live on one and only one such list)
*
* Also, they may live on the list of values for someone else's variable,
* or as someone's dependancy.
*/
typedef struct same {
string_t
*string; /* My name */
struct same
*nexttoken, /* Next pointer */
*lasttoken, /* Back pointer */
*depend_list, /* If target, dependancies */
*action_list, /* If target, actions */
*value_list, /* If variable, value list */
*shell_item; /* If a shell variable, current value */
} same_t;
%}
%union {
string_t *string;
same_t *same;
int intval;
}
%start makefile
%token <string> TOKEN QUOTED_STRING
%token <intval> FOR IN DO DONE
%token <intval> MACRO_CHAR NL WHITE_SPACE
%token <intval> ':' '=' '$' '{' '}' ';' '-' '@' '(' ')' ' ' '\t'
%type <same> target target1 assignment assign1 actions action
%type <same> command_list list list_element
%type <same> for_statement maybe_at_minus tokens token
%type <same> maybe_white_space
%type <intval> white_space macro_char
%%
makefile : lines;
lines : line
| lines line
;
line : NL
| assignment
| target_action
;
assignment : assign1 tokens NL
{
assign($1, $2);
}
| assign1 NL
{
assign($1, same_copy(null));
}
;
assign1: token maybe_white_space '=' maybe_white_space
;
target_action: target actions
{
add_targets_actions($1, $2);
}
| target
{
add_targets_actions($1, 0);
}
;
target : target1 tokens NL
{
$$ = add_depends($1, $2);
}
| target1 NL
{
$$ = add_depends($1, same_copy(null));
}
;
target1: tokens maybe_white_space ':' maybe_white_space
{
$$ = ws_merge($1);
}
;
actions: action
| actions action
{
$$ = same_cat(same_cat($1, same_copy(newline)), $2);
}
;
action: white_space command_list NL
{
$$ = $2;
}
| white_space for_statement do command_list semi_colon done NL
{
$$ = do_command($2, $4);
}
;
for_statement: maybe_at_minus FOR white_space token
in tokens semi_colon
{
$$ = for_statement($1, $4, ws_merge(expand_variables($6, 0)));
}
;
in: white_space IN white_space
do: white_space DO white_space
;
done: white_space DONE
;
semi_colon: ';'
;
command_list: list
| '(' list maybe_white_space ')'
{
$$ = same_cat($2, same_copy(cwd_line));
}
;
list: token
| list list_element
{
$$ = same_cat($1, $2);
}
| list white_space list_element
{
$$ = same_cat($1, same_cat(same_copy(blank), $3));
}
;
list_element: token
| semi_colon
{
$$ = same_copy(newline);
}
;
maybe_at_minus: /* empty */
{
$$ = same_copy(null);
}
| '@'
{
char buffer[2];
buffer[0] = $1;
buffer[1] = 0;
$$ = same_item(string_lookup(buffer));
}
| '-'
{
char buffer[2];
buffer[0] = $1;
buffer[1] = 0;
$$ = same_item(string_lookup(buffer));
}
;
tokens : token
| tokens maybe_white_space token
{
$$ = same_cat($1, same_cat($2, $3));
}
;
token: TOKEN
{
$$ = same_item($1);
}
| QUOTED_STRING
{
$$ = same_item($1);
}
| '$' macro_char
{
char buffer[3];
buffer[0] = '$';
buffer[1] = $2;
buffer[2] = 0;
$$ = same_item(string_lookup(buffer));
}
| '$' '$' TOKEN
{
$$ = shell_variable(same_item($3));
}
| MACRO_CHAR
{
$$ = same_char($1);
}
| '$' '{' TOKEN '}'
{
$$ = variable(same_item($3));
}
| '$' '(' TOKEN ')'
{
$$ = variable(same_item($3));
}
| '$' TOKEN
{
$$ = variable(same_item($2));
}
| '-'
{
$$ = same_char('-');
}
| '@'
{
$$ = same_char('@');
}
;
macro_char: MACRO_CHAR
| '@'
;
maybe_white_space:
{
$$ = same_copy(null);
}
| white_space
{
$$ = same_char($1);
}
;
white_space : WHITE_SPACE
| white_space WHITE_SPACE
;
%%
#include <stdio.h>
#include <ctype.h>
static int last_char, last_saved = 0;
static int column = 0, lineno = 1;
static string_t
*strings = 0;
static same_t
*shell_variables = 0,
*shell_special = 0,
*variables = 0,
*targets = 0,
*actions = 0;
static same_t
*null,
*blank,
*cwd_line,
*newline;
extern char *malloc();
static unsigned int
clock = -1;
struct {
same_t *first;
int next;
} visit_stack[20]; /* 20 maximum */
#define visit(what,via) \
(visit_stack[++clock].next = 0, visit_stack[clock].first = via = what)
#define visited(via) (visitcheck(via) || ((via) == 0) \
|| (visit_stack[clock].next && (via == visit_stack[clock].first)))
#define visit_next(via) (visit_stack[clock].next = 1, (via) = (via)->nexttoken)
#define visit_end() (clock--)
yyerror(s)
char *s;
{
fprintf(stderr, "line %d, character %d: %s\n", lineno, column, s);
do_dump();
}
int
visitcheck(same)
same_t *same;
{
if (same->string == 0) {
yyerror("BUG - freed 'same' in use...");
exit(1);
}
return 0;
}
int
string_hashof(string, length)
char *string;
int length;
{
register int i = 0;
while (length--) {
i = (i<<3) + *string ^ ((i>>28)&0x7);
}
return i;
}
int
string_same(s1, s2)
string_t
*s1, *s2;
{
if ((s1->hashval == s2->hashval) && (s1->length == s2->length)
&& (memcmp(s1->string, s2->string, s1->length) == 0)) {
return 1;
} else {
return 0;
}
}
string_t *
string_lookup(string)
char *string;
{
string_t ours;
string_t *ptr;
ours.length = strlen(string);
ours.hashval = string_hashof(string, ours.length);
ours.string = string;
for (ptr = strings; ptr; ptr = ptr->next) {
if (string_same(&ours, ptr)) {
return ptr;
}
}
if ((ptr = (string_t *)malloc(sizeof *ptr)) == 0) {
fprintf(stderr, "No space to add string *%s*!\n", string);
exit(1);
}
ptr->hashval = ours.hashval;
ptr->length = ours.length;
if ((ptr->string = malloc(ours.length+1)) == 0) {
fprintf(stderr, "No space to add literal *%s*!\n", string);
exit(1);
}
memcpy(ptr->string, string, ours.length+1);
ptr->next = strings;
strings = ptr;
return ptr;
}
#define same_singleton(s) ((s)->nexttoken == (s))
same_t *
same_search(list, token)
same_t
*list,
*token;
{
same_t *ptr;
ptr = list;
for (visit(list, ptr); !visited(ptr); visit_next(ptr)) {
string_t *string;
string = ptr->string;
if (string_same(string, token->string)) {
visit_end();
return ptr;
}
}
visit_end();
return 0;
}
same_t *
same_cat(list, tokens)
same_t
*list,
*tokens;
{
same_t *last;
if (tokens == 0) {
return list;
}
if (list) {
last = tokens->lasttoken;
tokens->lasttoken = list->lasttoken;
list->lasttoken = last;
tokens->lasttoken->nexttoken = tokens;
last->nexttoken = list;
return list;
} else {
return tokens;
}
}
same_t *
same_item(string)
string_t *string;
{
same_t *ptr;
if ((ptr = (same_t *)malloc(sizeof *ptr)) == 0) {
fprintf(stderr, "No more space for tokens!\n");
exit(1);
}
memset((char *)ptr, 0, sizeof *ptr);
ptr->nexttoken = ptr->lasttoken = ptr;
ptr->string = string;
return ptr;
}
same_t *
same_copy(same)
same_t *same;
{
same_t *head, *copy;
head = 0;
for (visit(same, copy); !visited(copy); visit_next(copy)) {
same_t *ptr;
ptr = same_item(copy->string);
head = same_cat(head, ptr);
}
visit_end();
return head;
}
same_t *
same_merge(t1, t2)
same_t
*t1,
*t2;
{
if (same_singleton(t1) && same_singleton(t2)) {
int length = strlen(t1->string->string)+strlen(t2->string->string);
char *buffer = malloc(length+1);
same_t *value;
if (buffer == 0) {
yyerror("No space to merge strings in same_merge!");
exit(1);
}
strcpy(buffer, t1->string->string);
strcat(buffer, t2->string->string);
value = same_item(string_lookup(buffer));
free(buffer);
return value;
} else {
yyerror("Internal error - same_merge with non-singletons");
exit(1);
}
}
void
same_free(list)
same_t *list;
{
same_t *token, *ptr;
if (list == 0) {
return;
}
token = list;
do {
ptr = token->nexttoken;
token->string = 0;
(void) free((char *)token);
token = ptr;
} while (token != list);
}
same_t *
same_unlink(token)
same_t
*token;
{
same_t *tmp;
if (token == 0) {
return 0;
}
if ((tmp = token->nexttoken) == token) {
tmp = 0;
}
token->lasttoken->nexttoken = token->nexttoken;
token->nexttoken->lasttoken = token->lasttoken;
token->nexttoken = token->lasttoken = token;
return tmp;
}
void
same_replace(old, new)
same_t
*old,
*new;
{
new->lasttoken->nexttoken = old->nexttoken;
old->nexttoken->lasttoken = new->lasttoken;
new->lasttoken = old->lasttoken;
/* rather than
* old->lasttoken->nexttoken = new
* we update in place (for the case where there isn't anything else)
*/
*old = *new;
}
same_t *
same_char(ch)
char ch;
{
char buffer[2];
buffer[0] = ch;
buffer[1] = 0;
return same_item(string_lookup(buffer));
}
void
add_target(target, actions)
same_t
*target,
*actions;
{
same_t *ptr;
if ((ptr = same_search(targets, target)) == 0) {
targets = same_cat(targets, target);
ptr = target;
} else {
ptr->depend_list = same_cat(ptr->depend_list, target->depend_list);
}
if (actions) {
if (ptr->action_list) {
same_free(ptr->action_list);
}
ptr->action_list = same_copy(actions);
}
}
same_t *
add_targets_actions(target, actions)
same_t
*target,
*actions;
{
same_t *ptr;
if (target == 0) {
return 0;
}
do {
ptr = same_unlink(target);
add_target(target, actions);
target = ptr;
} while (target);
same_free(actions);
return 0;
}
same_t *
add_depends(target, depends)
same_t
*target,
*depends;
{
same_t *original = target;
depends = same_cat(depends, same_copy(blank)); /* Separator */
for (visit(original, target); !visited(target); visit_next(target)) {
target->depend_list = same_cat(target->depend_list, same_copy(depends));
}
visit_end();
same_free(depends);
return original;
}
/*
* We know that variable is a singleton
*/
void
assign(variable, value)
same_t
*variable,
*value;
{
same_t *ptr;
if ((ptr = same_search(variables, variable)) != 0) {
same_free(ptr->value_list);
variables = same_unlink(ptr);
same_free(ptr);
}
variable->value_list = value;
variables = same_cat(variables, variable);
}
same_t *
value_of(variable)
same_t *variable;
{
same_t *ptr = same_search(variables, variable);
if (ptr == 0) {
return same_copy(null);
} else {
return same_copy(ptr->value_list);
}
}
same_t *
expand_variables(token, free)
same_t *token;
int free;
{
same_t *head = 0;
if (!free) {
token = same_copy(token); /* Get our private copy */
}
while (token) {
char *string = token->string->string;
same_t *tmp = same_unlink(token);
if ((string[0] == '$') && (string[1] == '{')) { /* Expand time */
int len = strlen(string);
string[len-1] = 0;
head = same_cat(head, expand_variables(
value_of(same_item(string_lookup(string+2))), 1));
string[len-1] = '}';
} else {
head = same_cat(head, token);
}
token = tmp;
}
return head;
}
same_t *
ws_merge(list)
same_t *list;
{
same_t *newlist = 0, *item;
int what = 0;
while (list) {
switch (what) {
case 0:
if (isspace(list->string->string[0])) {
;
} else {
item = same_item(list->string);
what = 1;
}
break;
case 1:
if (isspace(list->string->string[0])) {
newlist = same_cat(newlist, item);
item = 0;
what = 0;
} else {
item = same_merge(item, same_item(list->string));
what = 1;
}
break;
}
list = same_unlink(list);
}
return same_cat(newlist, item);
}
same_t *
variable(var_name)
same_t *var_name;
{
int length = strlen(var_name->string->string);
same_t *resolved;
char *newname;
if ((newname = malloc(length+1+3)) == 0) {
fprintf("Out of space for a variable name.\n");
exit(1);
}
newname[0] = '$';
newname[1] = '{';
strcpy(newname+2, var_name->string->string);
strcat(newname, "}");
resolved = same_item(string_lookup(newname));
free(newname);
return resolved;
}
same_t *
shell_variable(var_name)
same_t *var_name;
{
int length = strlen(var_name->string->string);
same_t *resolved;
char *newname;
if ((newname = malloc(length+1+2)) == 0) {
fprintf("Out of space for a variable name.\n");
exit(1);
}
newname[0] = '$';
newname[1] = '$';
strcpy(newname+2, var_name->string->string);
resolved = same_item(string_lookup(newname));
free(newname);
return resolved;
}
same_t *
for_statement(special, variable, list)
same_t
*special,
*variable,
*list;
{
variable->shell_item = special;
variable->value_list = list;
return variable;
}
same_t *
do_command(forlist, commands)
same_t
*forlist,
*commands;
{
same_t
*special,
*command_list = 0,
*new_commands,
*tmp,
*shell_item,
*value_list = forlist->value_list;
char
*tmpstr,
*variable_name = forlist->string->string;
special = forlist->shell_item;
if (same_unlink(forlist->shell_item) != 0) {
yyerror("Unexpected second item in special part of do_command");
exit(1);
}
while ((shell_item = value_list) != 0) {
value_list = same_unlink(shell_item);
/* Visit each item in commands. For each shell variable which
* matches ours, replace it with ours.
*/
new_commands = same_copy(commands);
for (visit(new_commands, tmp); !visited(tmp); visit_next(tmp)) {
tmpstr = tmp->string->string;
if ((tmpstr[0] == '$') && (tmpstr[1] == '$')) {
if (strcmp(tmpstr+2, variable_name) == 0) {
same_replace(tmp, same_copy(shell_item));
}
}
}
visit_end();
command_list = same_cat(command_list, new_commands);
}
return same_cat(command_list, same_copy(newline));
}
int
Getchar()
{
if (last_saved) {
last_saved = 0;
return last_char;
} else {
int c;
c = getchar();
switch (c) {
case '\n':
lineno++;
column = 0;
break;
default:
column++;
}
return c;
}
}
int
token_type(string)
char *string;
{
switch (string[0]) {
case 'f':
if (strcmp(string, "for") == 0) {
return FOR;
}
break;
case 'd':
if (string[1] == 'o') {
if (strcmp(string, "do") == 0) {
return DO;
} else if (strcmp(string, "done") == 0) {
return DONE;
}
}
break;
case 'i':
if (strcmp(string, "in") == 0) {
return IN;
}
break;
default:
break;
}
return TOKEN;
}
yylex()
{
#define ret_token(c) if (bufptr != buffer) { \
save(c); \
*bufptr = 0; \
bufptr = buffer; \
yylval.string = string_lookup(buffer); \
return token_type(buffer); \
}
#define save(c) { last_char = c; last_saved = 1; }
#if defined(YYDEBUG)
#define Return(c) if (yydebug) { \
printf("[%d]", c); \
fflush(stdout); \
} \
yyval.intval = c; \
return c;
#else /* defined(YYDEBUG) */
#define Return(y,c) { yylval.intval = c; return y; }
#endif /* defined(YYDEBUG) */
static char buffer[500], *bufptr = buffer;
static int eof_found = 0;
int c;
if (eof_found != 0) {
eof_found++;
if (eof_found > 2) {
fprintf(stderr, "End of file ignored.\n");
exit(1);
}
Return(EOF,0);
}
while ((c = Getchar()) != EOF) {
switch (c) {
case '#':
ret_token(c);
while (((c = Getchar()) != EOF) && (c != '\n')) {
;
}
save(c);
break;
case '<':
case '?':
ret_token(c);
Return(MACRO_CHAR, c);
case '\t':
case ' ':
ret_token(c);
Return(WHITE_SPACE, c);
case '-':
case '@':
case ':':
case ';':
case '=':
case '$':
case '{':
case '}':
case '(':
case ')':
ret_token(c);
Return(c,c);
case '\'':
case '"':
if (bufptr != buffer) {
if (bufptr[-1] == '\\') {
bufptr[-1] = c;
}
break;
} else {
int newc;
ret_token(c);
*bufptr++ = c;
while (((newc = Getchar()) != EOF) && (newc != c)) {
*bufptr++ = newc;
}
*bufptr++ = c;
*bufptr = 0;
bufptr = buffer;
yylval.string = string_lookup(buffer);
return QUOTED_STRING;
}
case '\n':
if (bufptr != buffer) {
if (bufptr[-1] == '\\') {
bufptr--;
if ((c = Getchar()) != '\t') {
yyerror("continuation line doesn't begin with a tab");
save(c);
}
ret_token(c);
Return(WHITE_SPACE, c);
}
}
ret_token(c);
Return(NL, 0);
default:
*bufptr++ = c;
break;
}
}
eof_found = 1;
ret_token(' ');
Return(EOF, 0);
}
main()
{
#define YYDEBUG
extern int yydebug;
null = same_item(string_lookup(""));
newline = same_item(string_lookup("\n"));
blank = same_item(string_lookup(" "));
cwd_line = same_cat(same_copy(newline),
same_cat(same_item(string_lookup("cd ${CWD}")),
same_copy(newline)));
yyparse();
do_dump();
return 0;
}
#if defined(YYDEBUG)
dump_same(same)
same_t *same;
{
same_t *same2;
for (visit(same, same2); !visited(same2); visit_next(same2)) {
printf("%s", same2->string->string);
}
visit_end();
}
#endif /* YYDEBUG */
do_dump()
{
string_t *string;
same_t *same, *same2;
if (yydebug > 1) {
printf("strings...\n");
for (string = strings; string; string = string->next) {
printf("\t%s\n", string->string);
}
}
printf("# variables...\n");
for (visit(variables, same); !visited(same); visit_next(same)) {
printf("%s =\t", same->string->string);
for (visit(same->value_list, same2); !visited(same2);
visit_next(same2)) {
printf("%s", same2->string->string);
}
visit_end();
printf("\n");
}
visit_end();
printf("\n\n#targets...\n");
for (visit(targets, same); !visited(same); visit_next(same)) {
printf("\n%s:\t", same->string->string);
for (visit(same->depend_list, same2); !visited(same2);
visit_next(same2)) {
printf("%s", same2->string->string);
}
visit_end();
printf("\n\t");
for (visit(same->action_list, same2); !visited(same2);
visit_next(same2)) {
printf("%s", same2->string->string);
if (same2->string->string[0] == '\n') {
printf("\t");
}
}
visit_end();
printf("\n");
}
visit_end();
}
|