435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
1 |
/*
|
2 |
* Parser routines called from yacc code (gram.y)
|
|
435.1.2
by Matthew Fuller
Leave some comments on these files to point at their minor redundancy |
3 |
*
|
4 |
* This is very similar to the meaning of parse_be.c; the two may be
|
|
5 |
* merged at some point.
|
|
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
6 |
*/
|
7 |
||
8 |
#include "ctwm.h" |
|
9 |
||
10 |
#include <stdio.h> |
|
11 |
#include <string.h> |
|
12 |
#include <strings.h> |
|
13 |
||
528.1.63
by Matthew Fuller
#if 0 out the old function #define's in parse.h, and add |
14 |
#include "functions_defs.h" |
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
15 |
#include "util.h" |
16 |
#include "screen.h" |
|
17 |
#include "parse.h" |
|
18 |
#include "parse_be.h" |
|
19 |
#include "parse_yacc.h" |
|
538.1.3
by Matthew Fuller
Rename the decorations*.h to win_decorations*.h. |
20 |
#include "win_decorations_init.h" |
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
21 |
|
492.2.33
by Matthew Fuller
Do some more cleanup of headers including headers. |
22 |
#include "gram.tab.h" |
23 |
||
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
24 |
char *Action = ""; |
25 |
char *Name = ""; |
|
26 |
MenuRoot *root, *pull = NULL; |
|
27 |
||
28 |
int cont = 0; |
|
29 |
int mods = 0; |
|
30 |
unsigned int mods_used = (ShiftMask | ControlMask | Mod1Mask); |
|
31 |
||
32 |
||
33 |
void yyerror(char *s) |
|
34 |
{
|
|
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
35 |
twmrc_error_prefix(); |
36 |
fprintf(stderr, "error in input file: %s\n", s ? s : ""); |
|
492.2.97
by Matthew Fuller
bool-ify flags and return values related to config file parsing. |
37 |
ParseError = true; |
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
38 |
}
|
39 |
||
40 |
void InitGramVariables(void) |
|
41 |
{
|
|
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
42 |
mods = 0; |
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
43 |
}
|
44 |
||
45 |
void RemoveDQuote(char *str) |
|
46 |
{
|
|
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
47 |
char *i, *o; |
48 |
int n; |
|
49 |
int count; |
|
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
50 |
|
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
51 |
for(i = str + 1, o = str; *i && *i != '\"'; o++) { |
52 |
if(*i == '\\') { |
|
53 |
switch(*++i) { |
|
54 |
case 'n': |
|
55 |
*o = '\n'; |
|
56 |
i++; |
|
57 |
break; |
|
58 |
case 'b': |
|
59 |
*o = '\b'; |
|
60 |
i++; |
|
61 |
break; |
|
62 |
case 'r': |
|
63 |
*o = '\r'; |
|
64 |
i++; |
|
65 |
break; |
|
66 |
case 't': |
|
67 |
*o = '\t'; |
|
68 |
i++; |
|
69 |
break; |
|
70 |
case 'f': |
|
71 |
*o = '\f'; |
|
72 |
i++; |
|
73 |
break; |
|
74 |
case '0': |
|
75 |
if(*++i == 'x') { |
|
76 |
goto hex; |
|
77 |
}
|
|
78 |
else { |
|
79 |
--i; |
|
80 |
}
|
|
81 |
case '1': |
|
82 |
case '2': |
|
83 |
case '3': |
|
84 |
case '4': |
|
85 |
case '5': |
|
86 |
case '6': |
|
87 |
case '7': |
|
88 |
n = 0; |
|
89 |
count = 0; |
|
90 |
while(*i >= '0' && *i <= '7' && count < 3) { |
|
91 |
n = (n << 3) + (*i++ - '0'); |
|
92 |
count++; |
|
93 |
}
|
|
94 |
*o = n; |
|
95 |
break; |
|
96 |
hex: |
|
97 |
case 'x': |
|
98 |
n = 0; |
|
99 |
count = 0; |
|
100 |
while(i++, count++ < 2) { |
|
101 |
if(*i >= '0' && *i <= '9') { |
|
102 |
n = (n << 4) + (*i - '0'); |
|
103 |
}
|
|
104 |
else if(*i >= 'a' && *i <= 'f') { |
|
105 |
n = (n << 4) + (*i - 'a') + 10; |
|
106 |
}
|
|
107 |
else if(*i >= 'A' && *i <= 'F') { |
|
108 |
n = (n << 4) + (*i - 'A') + 10; |
|
109 |
}
|
|
110 |
else { |
|
111 |
break; |
|
112 |
}
|
|
113 |
}
|
|
114 |
*o = n; |
|
115 |
break; |
|
116 |
case '\n': |
|
117 |
i++; /* punt */ |
|
118 |
o--; /* to account for o++ at end of loop */ |
|
119 |
break; |
|
120 |
case '\"': |
|
121 |
case '\'': |
|
122 |
case '\\': |
|
123 |
default: |
|
124 |
*o = *i++; |
|
125 |
break; |
|
126 |
}
|
|
127 |
}
|
|
128 |
else { |
|
129 |
*o = *i++; |
|
130 |
}
|
|
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
131 |
}
|
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
132 |
*o = '\0'; |
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
133 |
}
|
134 |
||
135 |
MenuRoot *GetRoot(char *name, char *fore, char *back) |
|
136 |
{
|
|
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
137 |
MenuRoot *tmp; |
138 |
||
139 |
tmp = FindMenuRoot(name); |
|
140 |
if(tmp == NULL) { |
|
141 |
tmp = NewMenuRoot(name); |
|
142 |
}
|
|
143 |
||
144 |
if(fore) { |
|
492.2.105
by Matthew Fuller
Switch some temp vars holding Scr->FirstTime over to bool. |
145 |
bool save; |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
146 |
|
147 |
save = Scr->FirstTime; |
|
492.2.104
by Matthew Fuller
Massive rewrite of various struct Screen config params that are |
148 |
Scr->FirstTime = true; |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
149 |
GetColor(COLOR, &tmp->highlight.fore, fore); |
150 |
GetColor(COLOR, &tmp->highlight.back, back); |
|
151 |
Scr->FirstTime = save; |
|
152 |
}
|
|
153 |
||
154 |
return tmp; |
|
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
155 |
}
|
156 |
||
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
157 |
void GotButton(int butt, int func) |
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
158 |
{
|
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
159 |
int i; |
160 |
MenuItem *item; |
|
161 |
||
162 |
for(i = 0; i < NUM_CONTEXTS; i++) { |
|
163 |
if((cont & (1 << i)) == 0) { |
|
164 |
continue; |
|
165 |
}
|
|
166 |
||
167 |
if(func == F_MENU) { |
|
168 |
pull->prev = NULL; |
|
492.2.80
by Matthew Fuller
Mechanical replacement of inline "(sometype *)0" constructs with NULL, |
169 |
AddFuncButton(butt, i, mods, func, pull, NULL); |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
170 |
}
|
171 |
else { |
|
437
by Matthew Fuller
Anyplace looking for a char * will find NULL as acceptable as (char |
172 |
root = GetRoot(TWM_ROOT, NULL, NULL); |
173 |
item = AddToMenu(root, "x", Action, NULL, func, NULL, NULL); |
|
492.2.80
by Matthew Fuller
Mechanical replacement of inline "(sometype *)0" constructs with NULL, |
174 |
AddFuncButton(butt, i, mods, func, NULL, item); |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
175 |
}
|
176 |
}
|
|
177 |
||
178 |
Action = ""; |
|
179 |
pull = NULL; |
|
180 |
cont = 0; |
|
181 |
mods_used |= mods; |
|
182 |
mods = 0; |
|
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
183 |
}
|
184 |
||
185 |
void GotKey(char *key, int func) |
|
186 |
{
|
|
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
187 |
int i; |
188 |
||
189 |
for(i = 0; i < NUM_CONTEXTS; i++) { |
|
190 |
if((cont & (1 << i)) == 0) { |
|
191 |
continue; |
|
192 |
}
|
|
193 |
||
194 |
if(func == F_MENU) { |
|
195 |
pull->prev = NULL; |
|
196 |
if(!AddFuncKey(key, i, mods, func, pull, Name, Action)) { |
|
197 |
break; |
|
198 |
}
|
|
199 |
}
|
|
492.2.80
by Matthew Fuller
Mechanical replacement of inline "(sometype *)0" constructs with NULL, |
200 |
else if(!AddFuncKey(key, i, mods, func, NULL, Name, Action)) { |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
201 |
break; |
202 |
}
|
|
203 |
}
|
|
204 |
||
205 |
Action = ""; |
|
206 |
pull = NULL; |
|
207 |
cont = 0; |
|
208 |
mods_used |= mods; |
|
209 |
mods = 0; |
|
210 |
}
|
|
211 |
||
212 |
||
488.1.130
by Matthew Fuller
GotTitleButton's arg is only literal, and passed through to a |
213 |
void GotTitleButton(char *bitmapname, int func, bool rightside) |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
214 |
{
|
488.1.129
by Matthew Fuller
The append arg here is only used in boolean conditions, and only |
215 |
if(!CreateTitleButton(bitmapname, func, Action, pull, rightside, true)) { |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
216 |
twmrc_error_prefix(); |
217 |
fprintf(stderr, |
|
218 |
"unable to create %s titlebutton \"%s\"\n", |
|
219 |
rightside ? "right" : "left", bitmapname); |
|
220 |
}
|
|
221 |
Action = ""; |
|
222 |
pull = NULL; |
|
223 |
}
|
|
224 |
||
522.1.3
by Matthew Fuller
const-ify and comment some of these checker funcs for parsing. |
225 |
|
226 |
/* Check f.warptoscreen arg */
|
|
492.2.57
by Matthew Fuller
Simple bool conversions. |
227 |
bool
|
522.1.3
by Matthew Fuller
const-ify and comment some of these checker funcs for parsing. |
228 |
CheckWarpScreenArg(const char *s) |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
229 |
{
|
522.1.3
by Matthew Fuller
const-ify and comment some of these checker funcs for parsing. |
230 |
/* next/prev/back are valid */
|
522.1.4
by Matthew Fuller
Pull some extraneous spaces. |
231 |
if(strcasecmp(s, WARPSCREEN_NEXT) == 0 || |
232 |
strcasecmp(s, WARPSCREEN_PREV) == 0 || |
|
233 |
strcasecmp(s, WARPSCREEN_BACK) == 0) { |
|
492.2.57
by Matthew Fuller
Simple bool conversions. |
234 |
return true; |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
235 |
}
|
236 |
||
522.1.3
by Matthew Fuller
const-ify and comment some of these checker funcs for parsing. |
237 |
/* Or if the whole thing is numeric, it's valid too */
|
511.1.3
by Matthew Fuller
Brace these 1- (or 0-, depending on how you count) loops while I'm |
238 |
for(; *s && Isascii(*s) && Isdigit(*s); s++) { |
511.1.1
by Matthew Fuller
Cleanup some ancient lint SUPPRESS statements, and make empty loop |
239 |
/* nada */; |
511.1.3
by Matthew Fuller
Brace these 1- (or 0-, depending on how you count) loops while I'm |
240 |
}
|
492.2.57
by Matthew Fuller
Simple bool conversions. |
241 |
return (*s ? false : true); |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
242 |
}
|
243 |
||
244 |
||
522.1.3
by Matthew Fuller
const-ify and comment some of these checker funcs for parsing. |
245 |
/* f.warptoring arg */
|
492.2.57
by Matthew Fuller
Simple bool conversions. |
246 |
bool
|
522.1.3
by Matthew Fuller
const-ify and comment some of these checker funcs for parsing. |
247 |
CheckWarpRingArg(const char *s) |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
248 |
{
|
522.1.4
by Matthew Fuller
Pull some extraneous spaces. |
249 |
if(strcasecmp(s, WARPSCREEN_NEXT) == 0 || |
250 |
strcasecmp(s, WARPSCREEN_PREV) == 0) { |
|
492.2.57
by Matthew Fuller
Simple bool conversions. |
251 |
return true; |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
252 |
}
|
253 |
||
492.2.57
by Matthew Fuller
Simple bool conversions. |
254 |
return false; |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
255 |
}
|
256 |
||
257 |
||
522.1.3
by Matthew Fuller
const-ify and comment some of these checker funcs for parsing. |
258 |
/* f.colormap arg */
|
492.2.57
by Matthew Fuller
Simple bool conversions. |
259 |
bool
|
522.1.3
by Matthew Fuller
const-ify and comment some of these checker funcs for parsing. |
260 |
CheckColormapArg(const char *s) |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
261 |
{
|
262 |
if(strcasecmp(s, COLORMAP_NEXT) == 0 || |
|
263 |
strcasecmp(s, COLORMAP_PREV) == 0 || |
|
264 |
strcasecmp(s, COLORMAP_DEFAULT) == 0) { |
|
492.2.57
by Matthew Fuller
Simple bool conversions. |
265 |
return true; |
435.1.3
by Matthew Fuller
Now that this code is out of the gram.y, run a make indent over it. |
266 |
}
|
267 |
||
492.2.57
by Matthew Fuller
Simple bool conversions. |
268 |
return false; |
435.1.1
by Matthew Fuller
Pull the static code out of gram.y and into a seaprate parse_yacc.c. |
269 |
}
|