-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimprove_chunk
78 lines (66 loc) · 1.8 KB
/
improve_chunk
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
+ in text.c:
int
Open_Text_Third_Pass(const struct text *txt) {
last_tk_cnt = 0;
last_nl_cnt = 1;
lex_nl_cnt = 1;
lex_tk_cnt = 0;
return Open_Stream(txt->tx_fname);
}
+ in text.h:
extern int Open_Text_Third_Pass(const struct text *txt);
+ in pass3.c:
#include "stream.h"
#include "lang.h"
/* CHUNK IMPROVEMENT */
static void
improve_chunk(const struct chunk *cnk) {
/* Open_Text_Second_Pass() initializes lex_nl_cnt and lex_tk_cnt */
if (!Open_Text_Third_Pass(cnk->ch_text)) {
fprintf(stderr, ">>>> File %s disappeared <<<<\n",
cnk->ch_text->tx_fname
);
return;
}
const struct position *pos_f = &cnk->ch_first;
const struct position *pos_l = &cnk->ch_last;
while (Next_Stream_Token_Obtained()) {
if (Token_EQ(lex_token, End_Of_Line)) continue;
if (pos_f->ps_tk_cnt == lex_tk_cnt-1
&& pos_f->ps_nl_cnt != lex_nl_cnt
) {
fprintf(stderr, "fname= %s\n", cnk->ch_text->tx_fname);
fprintf(stderr, "> pos_f->ps_tk_cnt= %d\n",
pos_f->ps_tk_cnt);
fprintf(stderr,
"@pos_f->ps_tk_cnt= %d, lex_tk_cnt-1= %d\n",
pos_f->ps_tk_cnt, lex_tk_cnt-1
);
fprintf(stderr,
"%c pos_f->ps_nl_cnt= %d, lex_nl_cnt= %d\n",
(pos_f->ps_nl_cnt == lex_nl_cnt ? '=' : 'X'),
pos_f->ps_nl_cnt, lex_nl_cnt
);
}
if (pos_l->ps_tk_cnt == lex_tk_cnt-1
&& pos_l->ps_nl_cnt != lex_nl_cnt
) {
fprintf(stderr, "fname= %s\n", cnk->ch_text->tx_fname);
fprintf(stderr, "> pos_l->ps_tk_cnt= %d\n",
pos_l->ps_tk_cnt);
fprintf(stderr,
"@pos_l->ps_tk_cnt= %d, lex_tk_cnt-1= %d\n",
pos_l->ps_tk_cnt, lex_tk_cnt-1
);
fprintf(stderr,
"%c pos_l->ps_nl_cnt= %d, lex_nl_cnt= %d\n",
(pos_l->ps_nl_cnt == lex_nl_cnt ? '=' : 'X'),
pos_l->ps_nl_cnt, lex_nl_cnt
);
}
}
Close_Stream();
}
in print_run():
improve_chunk(cnk0);
improve_chunk(cnk1);