]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - misc/mediasource/extra/fteqcc-src/qccguistuff.c
Rename the compiled fteqcc to fteqcc-win32 (as that's what it is)
[voretournament/voretournament.git] / misc / mediasource / extra / fteqcc-src / qccguistuff.c
1 #include "qcc.h"
2 #include "gui.h"
3
4 //common gui things
5
6 pbool fl_hexen2;
7 pbool fl_autohighlight;
8 pbool fl_compileonstart;
9 pbool fl_showall;
10 pbool fl_log;
11
12 char parameters[16384];
13 char progssrcname[256];
14 char progssrcdir[256];
15
16 int qccpersisthunk = 1;
17 void GoToDefinition(char *name)
18 {
19         QCC_def_t *def;
20         QCC_dfunction_t *fnc;
21
22         char *strip;    //trim whitespace (for convieniance).
23         while (*name <= ' ' && *name)
24                 name++;
25         for (strip = name + strlen(name)-1; *strip; strip++)
26         {
27                 if (*strip <= ' ')
28                         *strip = '\0';
29                 else    //got some part of a word
30                         break;
31         }
32
33         if (!globalstable.numbuckets)
34         {
35                 GUI_DialogPrint("Not found", "You need to compile first.");
36                 return;
37         }
38
39
40         def = QCC_PR_GetDef(NULL, name, NULL, false, 0, false);
41
42         if (def)
43         {
44                 if (def->type->type == ev_function && def->constant)
45                 {
46                         fnc = &functions[((int *)qcc_pr_globals)[def->ofs]];
47                         if (fnc->first_statement>=0 && fnc->s_file)
48                         {
49                                 EditFile(fnc->s_file+strings, statement_linenums[fnc->first_statement]);
50                                 return;
51                         }
52                 }
53                 if (!def->s_file)
54                         GUI_DialogPrint("Not found", "Global definition of var was not specified.");
55                 else
56                         EditFile(def->s_file+strings, def->s_line-1);
57         }
58         else
59                 GUI_DialogPrint("Not found", "Global instance of var was not found.");
60 }
61
62
63
64
65 //this function takes the windows specified commandline and strips out all the options menu items.
66 void GUI_ParseCommandLine(char *args)
67 {
68         int paramlen=0;
69         int l, p;
70         char *next;
71         while(*args)
72         {
73                 while (*args <= ' ' && *args)
74                         args++;
75
76                 for (next = args; *next>' '; next++)
77                         ;
78
79                 strncpy(parameters+paramlen, args, next-args);
80                 parameters[paramlen+next-args] = '\0';
81                 l = strlen(parameters+paramlen)+1;
82
83                 if (!strnicmp(parameters+paramlen, "-O", 2) || !strnicmp(parameters+paramlen, "/O", 2))
84                 {       //strip out all -O
85                         if (parameters[paramlen+2])
86                         {
87                                 if (parameters[paramlen+2] >= '0' && parameters[paramlen+2] <= '3')
88                                 {
89                                         p = parameters[paramlen+2]-'0';
90                                         for (l = 0; optimisations[l].enabled; l++)
91                                         {
92                                                 if (optimisations[l].optimisationlevel<=p)
93                                                         optimisations[l].flags |= FLAG_SETINGUI;
94                                                 else
95                                                         optimisations[l].flags &= ~FLAG_SETINGUI;
96                                         }
97                                 }
98                                 else if (!strncmp(parameters+paramlen+2, "no-", 3))
99                                 {
100                                         if (parameters[paramlen+5])
101                                         {
102                                                 for (p = 0; optimisations[p].enabled; p++)
103                                                         if ((*optimisations[p].abbrev && !strcmp(parameters+paramlen+5, optimisations[p].abbrev)) || !strcmp(parameters+paramlen+5, optimisations[p].fullname))
104                                                         {
105                                                                 optimisations[p].flags &= ~FLAG_SETINGUI;
106                                                                 break;
107                                                         }
108
109                                                 if (!optimisations[p].enabled)
110                                                 {
111                                                         parameters[paramlen+next-args] = ' ';
112                                                         paramlen += l;
113                                                 }
114                                         }
115                                 }
116                                 else
117                                 {
118                                         for (p = 0; optimisations[p].enabled; p++)
119                                                 if ((*optimisations[p].abbrev && !strcmp(parameters+paramlen+2, optimisations[p].abbrev)) || !strcmp(parameters+paramlen+2, optimisations[p].fullname))
120                                                 {
121                                                         optimisations[p].flags |= FLAG_SETINGUI;
122                                                         break;
123                                                 }
124
125                                         if (!optimisations[p].enabled)
126                                         {
127                                                 parameters[paramlen+next-args] = ' ';
128                                                 paramlen += l;
129                                         }
130                                 }
131                         }
132                 }
133 /*
134                 else if (!strnicmp(parameters+paramlen, "-Fno-kce", 8) || !strnicmp(parameters+paramlen, "/Fno-kce", 8))        //keywords stuph
135                 {
136                         fl_nokeywords_coexist = true;
137                 }
138                 else if (!strnicmp(parameters+paramlen, "-Fkce", 5) || !strnicmp(parameters+paramlen, "/Fkce", 5))
139                 {
140                         fl_nokeywords_coexist = false;
141                 }
142                 else if (!strnicmp(parameters+paramlen, "-Facc", 5) || !strnicmp(parameters+paramlen, "/Facc", 5))
143                 {
144                         fl_acc = true;
145                 }
146                 else if (!strnicmp(parameters+paramlen, "-autoproto", 10) || !strnicmp(parameters+paramlen, "/autoproto", 10))
147                 {
148                         fl_autoprototype = true;
149                 }
150 */
151                 else if (!strnicmp(parameters+paramlen, "-showall", 8) || !strnicmp(parameters+paramlen, "/showall", 8))
152                 {
153                         fl_showall = true;
154                 }
155                 else if (!strnicmp(parameters+paramlen, "-ah", 3) || !strnicmp(parameters+paramlen, "/ah", 3))
156                 {
157                         fl_autohighlight = true;
158                 }
159                 else if (!strnicmp(parameters+paramlen, "-ac", 3) || !strnicmp(parameters+paramlen, "/ac", 3))
160                 {
161                         fl_compileonstart = true;
162                 }
163                 else if (!strnicmp(parameters+paramlen, "-log", 4) || !strnicmp(parameters+paramlen, "/log", 4))
164                 {
165                         fl_log = true;
166                 }
167                 else if (!strnicmp(parameters+paramlen, "-srcfile", 8) || !strnicmp(parameters+paramlen, "/srcfile", 8))
168                 {
169                         while (*next == ' ')
170                                 next++;
171                         
172                         l = 0;
173                         while (*next != ' ' && *next)
174                                 progssrcname[l++] = *next++;
175                         progssrcname[l] = 0;
176                 }
177                 else if (!strnicmp(parameters+paramlen, "-T", 2) || !strnicmp(parameters+paramlen, "/T", 2))    //the target
178                 {
179                         if (!strnicmp(parameters+paramlen+2, "h2", 2))
180                         {
181                                 fl_hexen2 = true;
182                         }
183                         else
184                         {
185                                 fl_hexen2 = false;
186                                 parameters[paramlen+next-args] = ' ';
187                                 paramlen += l;
188                         }
189                 }
190                 else
191                 {
192                         parameters[paramlen+next-args] = ' ';
193                         paramlen += l;
194                 }
195
196                 args=next;
197         }
198         if (paramlen)
199                 parameters[paramlen-1] = '\0';
200         else
201                 *parameters = '\0';
202 }
203
204 void GUI_SetDefaultOpts(void)
205 {
206         int i;
207         for (i = 0; compiler_flag[i].enabled; i++)      //enabled is a pointer
208         {
209                 if (compiler_flag[i].flags & FLAG_ASDEFAULT)
210                         compiler_flag[i].flags |= FLAG_SETINGUI;
211                 else
212                         compiler_flag[i].flags &= ~FLAG_SETINGUI;
213         }
214         for (i = 0; optimisations[i].enabled; i++)      //enabled is a pointer
215         {
216                 if (optimisations[i].flags & FLAG_ASDEFAULT)
217                         optimisations[i].flags |= FLAG_SETINGUI;
218                 else
219                         optimisations[i].flags &= ~FLAG_SETINGUI;
220         }
221 }
222
223 void GUI_RevealOptions(void)
224 {
225         int i;
226         for (i = 0; compiler_flag[i].enabled; i++)      //enabled is a pointer
227         {
228                 if (fl_showall && compiler_flag[i].flags & FLAG_HIDDENINGUI)
229                         compiler_flag[i].flags &= ~FLAG_HIDDENINGUI;
230         }
231         for (i = 0; optimisations[i].enabled; i++)      //enabled is a pointer
232         {
233                 if (fl_showall && optimisations[i].flags & FLAG_HIDDENINGUI)
234                         optimisations[i].flags &= ~FLAG_HIDDENINGUI;
235
236                 if (optimisations[i].flags & FLAG_HIDDENINGUI)  //hidden optimisations are disabled as default
237                         optimisations[i].optimisationlevel = 4;
238         }
239 }
240
241
242
243
244 int GUI_BuildParms(char *args, char **argv)
245 {
246         static char param[2048];
247         int paramlen = 0;
248         int argc;
249         char *next;
250         int i;
251
252
253         argc = 1;
254         argv[0] = "fteqcc";
255
256         while(*args)
257         {
258                 while (*args <= ' '&& *args)
259                         args++;
260
261                 for (next = args; *next>' '; next++)
262                         ;
263                 strncpy(param+paramlen, args, next-args);
264                 param[paramlen+next-args] = '\0';
265                 argv[argc++] = param+paramlen;
266                 paramlen += strlen(param+paramlen)+1;
267
268                 args=next;
269         }
270
271         if (fl_hexen2)
272         {
273                 strcpy(param+paramlen, "-Th2");
274                 argv[argc++] = param+paramlen;
275                 paramlen += strlen(param+paramlen)+1;
276         }
277
278         for (i = 0; optimisations[i].enabled; i++)      //enabled is a pointer
279         {
280                 if (optimisations[i].flags & FLAG_SETINGUI)
281                         sprintf(param+paramlen, "-O%s", optimisations[i].abbrev);
282                 else
283                         sprintf(param+paramlen, "-Ono-%s", optimisations[i].abbrev);
284                 argv[argc++] = param+paramlen;
285                 paramlen += strlen(param+paramlen)+1;
286         }
287
288         for (i = 0; compiler_flag[i].enabled; i++)      //enabled is a pointer
289         {
290                 if (compiler_flag[i].flags & FLAG_SETINGUI)
291                         sprintf(param+paramlen, "-F%s", compiler_flag[i].abbrev);
292                 else
293                         sprintf(param+paramlen, "-Fno-%s", compiler_flag[i].abbrev);
294                 argv[argc++] = param+paramlen;
295                 paramlen += strlen(param+paramlen)+1;
296         }
297
298
299 /*      while(*args)
300         {
301                 while (*args <= ' '&& *args)
302                         args++;
303
304                 for (next = args; *next>' '; next++)
305                         ;
306                 strncpy(param+paramlen, args, next-args);
307                 param[paramlen+next-args] = '\0';
308                 argv[argc++] = param+paramlen;
309                 paramlen += strlen(param+paramlen)+1;
310                 args=next;
311         }*/
312
313         if (*progssrcname)
314         {
315                 argv[argc++] = "-srcfile";
316                 argv[argc++] = progssrcname;
317         }
318         if (*progssrcdir)
319         {
320                 argv[argc++] = "-src";
321                 argv[argc++] = progssrcdir;
322         }
323
324         return argc;
325 }