1 | %{ |
---|
2 | #include "bellcore-copyright.h" |
---|
3 | #include "mit-copyright.h" |
---|
4 | #include "track.h" |
---|
5 | extern FILE *yyin, *yyout; |
---|
6 | char linebuf[1024]; |
---|
7 | char wordbuf[256]; |
---|
8 | char *wordp; |
---|
9 | int wordcnt = 0; |
---|
10 | Entry* e = &entries[ 0]; |
---|
11 | %} |
---|
12 | %token ARROW WHITESPACE COLON BACKSLASH NEWLINE BACKNEW BANG WORD GEXCEPT ENDOFFILE |
---|
13 | %% |
---|
14 | sublist : opt_space header entrylist |
---|
15 | { |
---|
16 | entnum = 0; /* signifies to printmsg() that parse is complete. */ |
---|
17 | } |
---|
18 | ; |
---|
19 | header : |
---|
20 | { |
---|
21 | clear_ent(); |
---|
22 | entrycnt = 1; |
---|
23 | e = clear_ent(); |
---|
24 | } |
---|
25 | | GEXCEPT opt_space COLON except COLON opt_space |
---|
26 | { |
---|
27 | savestr( &e->fromfile, "GLOBAL_EXCEPTIONS"); |
---|
28 | |
---|
29 | /* cram compiled-in default exceptions onto lists: |
---|
30 | */ |
---|
31 | while ( wordp = next_def_except()) { |
---|
32 | if ( file_pat( wordp)) |
---|
33 | add_list_elt( re_conv( wordp), DONT_TRACK, &e->patterns); |
---|
34 | else add_list_elt( wordp, DONT_TRACK, LIST( e->names)); |
---|
35 | } |
---|
36 | /* XXX: global names should match both entry-children and |
---|
37 | * should match occurences which are deep in an entry. |
---|
38 | * it's ok to use linebuf for this, |
---|
39 | * because we've processed linebuf's contents already. |
---|
40 | */ |
---|
41 | for ( wordp = TEXT( e->names.table); wordp; |
---|
42 | wordp = TEXT( NEXT( wordp))) { |
---|
43 | strcpy( linebuf, "*/"); |
---|
44 | strcat( linebuf, wordp); |
---|
45 | add_list_elt( re_conv( linebuf), DONT_TRACK, &e->patterns); |
---|
46 | } |
---|
47 | if ( e->names.table) { /* lie, to make extra-roomy global table */ |
---|
48 | e->names.shift *= 8; |
---|
49 | list2hashtable( &e->names); |
---|
50 | } |
---|
51 | entrycnt++; |
---|
52 | e = clear_ent(); |
---|
53 | } |
---|
54 | ; |
---|
55 | entrylist : |
---|
56 | | entrylist entry opt_space |
---|
57 | ; |
---|
58 | entry: linkmark fromname COLON toname COLON cmpname COLON except COLON shellcmd |
---|
59 | { |
---|
60 | if ( e->names.table) list2hashtable( &e->names); |
---|
61 | entrycnt++; |
---|
62 | e = clear_ent(); |
---|
63 | } |
---|
64 | ; |
---|
65 | linkmark : |
---|
66 | | BANG opt_space |
---|
67 | { |
---|
68 | sprintf( errmsg, "followlink isn't supported.\n"); |
---|
69 | do_gripe(); |
---|
70 | /* e->followlink = 1; */ |
---|
71 | } |
---|
72 | ; |
---|
73 | fromname: WORD opt_space |
---|
74 | { |
---|
75 | char *r = wordbuf; |
---|
76 | while ( '/' == *r) r++; |
---|
77 | savestr(&e->fromfile,r); |
---|
78 | KEYCPY( e->sortkey, r); |
---|
79 | e->keylen = strlen( r); |
---|
80 | doreset(); |
---|
81 | } |
---|
82 | ; |
---|
83 | toname : opt_space |
---|
84 | { |
---|
85 | char *defname; |
---|
86 | |
---|
87 | defname = e->followlink ? |
---|
88 | resolve( e->fromfile, fromroot) : |
---|
89 | e->fromfile; |
---|
90 | |
---|
91 | savestr( &e->tofile, defname); |
---|
92 | doreset(); |
---|
93 | } |
---|
94 | | opt_word |
---|
95 | { |
---|
96 | char *r = wordbuf; |
---|
97 | while ( '/' == *r) r++; |
---|
98 | if ( ! e->followlink) |
---|
99 | savestr(&e->tofile,r); |
---|
100 | else savestr(&e->tofile, |
---|
101 | resolve( r, toroot)); |
---|
102 | doreset(); |
---|
103 | } |
---|
104 | ; |
---|
105 | cmpname : opt_space |
---|
106 | { |
---|
107 | char *defname, *root; |
---|
108 | |
---|
109 | if ( writeflag) { |
---|
110 | defname = e->fromfile; |
---|
111 | root = fromroot; |
---|
112 | } |
---|
113 | else { |
---|
114 | defname = e->tofile; |
---|
115 | root = toroot; |
---|
116 | } |
---|
117 | |
---|
118 | if ( e->followlink) |
---|
119 | defname = resolve( defname, root); |
---|
120 | |
---|
121 | savestr( &e->cmpfile, defname); |
---|
122 | |
---|
123 | doreset(); |
---|
124 | } |
---|
125 | | opt_word |
---|
126 | { |
---|
127 | char *r = wordbuf; |
---|
128 | while ( '/' == *r) r++; |
---|
129 | if ( ! e->followlink) |
---|
130 | savestr(&e->cmpfile,r); |
---|
131 | else savestr(&e->cmpfile, |
---|
132 | resolve( r, writeflag ? fromroot |
---|
133 | : toroot)); |
---|
134 | doreset(); |
---|
135 | } |
---|
136 | ; |
---|
137 | except : opt_space |
---|
138 | | opt_space exlist opt_space |
---|
139 | { |
---|
140 | doreset(); |
---|
141 | } |
---|
142 | ; |
---|
143 | exlist: exceptword |
---|
144 | | exlist opt_space exceptword |
---|
145 | ; |
---|
146 | exceptword: WORD |
---|
147 | { |
---|
148 | wordp = wordbuf; /* XXX lex returns longest match. */ |
---|
149 | wordcnt = DONT_TRACK; /* ->foo will thus come here. */ |
---|
150 | if ( ! strncmp( wordp, "->", 2)) { |
---|
151 | wordp += 2; |
---|
152 | wordcnt = FORCE_LINK; |
---|
153 | } |
---|
154 | if ( file_pat( wordp)) |
---|
155 | add_list_elt( re_conv( wordp), wordcnt, &e->patterns); |
---|
156 | else add_list_elt( wordp, wordcnt, LIST( e->names)); |
---|
157 | } |
---|
158 | | ARROW opt_space WORD |
---|
159 | { |
---|
160 | /* set force_links bit, add to e->names. |
---|
161 | */ |
---|
162 | if ( file_pat( wordbuf)) |
---|
163 | add_list_elt( re_conv( wordbuf), FORCE_LINK, &e->patterns); |
---|
164 | else add_list_elt( wordbuf, FORCE_LINK, LIST( e->names)); |
---|
165 | } |
---|
166 | ; |
---|
167 | shellcmd: nullcmd NEWLINE |
---|
168 | { |
---|
169 | savestr(&e->cmdbuf,""); |
---|
170 | doreset(); |
---|
171 | } |
---|
172 | | nullcmd shline NEWLINE |
---|
173 | { |
---|
174 | savestr(&e->cmdbuf,linebuf); |
---|
175 | doreset(); |
---|
176 | } |
---|
177 | ; |
---|
178 | nullcmd: |
---|
179 | | nullcmd WHITESPACE |
---|
180 | | nullcmd BACKNEW |
---|
181 | ; |
---|
182 | shline: black |
---|
183 | | shline black |
---|
184 | | shline WHITESPACE |
---|
185 | | shline BACKNEW |
---|
186 | ; |
---|
187 | black: WORD |
---|
188 | | COLON |
---|
189 | | BANG |
---|
190 | | BACKSLASH |
---|
191 | ; |
---|
192 | opt_word: opt_space WORD opt_space |
---|
193 | ; |
---|
194 | opt_space: |
---|
195 | | opt_space opt_ele |
---|
196 | ; |
---|
197 | opt_ele : NEWLINE | WHITESPACE |
---|
198 | ; |
---|
199 | %% |
---|
200 | |
---|
201 | yyerror(s) |
---|
202 | char *s; |
---|
203 | { |
---|
204 | if ( parseflag) justshow(); |
---|
205 | sprintf(errmsg,"parser error -- '%s'.\n bad element was near: %s\n", |
---|
206 | s, wordbuf); |
---|
207 | do_panic(); |
---|
208 | } |
---|
209 | #include "lex.yy.c" |
---|