Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 616 lines (610 sloc) 19.231 kb
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
1 /*
2 quIRC - simple terminal-based IRC client
4e3364b @ec429 Nudge copyright year to 2013
authored
3 Copyright (C) 2010-13 Edward Cree
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
4
5 See quirc.c for license information
6 genconfig.c: generate various bits of config-parsing code from a cdl file
7 */
8
9 // TODO: refactor this quite a lot, it's a mess
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdbool.h>
14 #include <string.h>
15 #include <unistd.h>
ebc74a9 Refactored string buffers to new strbuf.h, shared with the gen* progs.
ec429 authored
16 #include "strbuf.h"
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
17
18 typedef struct
19 {
20 enum {INT, BOOL} type;
21 char *cname;
22 int value;
23 int min,max;
24 char *rc_name;
25 char *cmdline_name;
26 char *set_name;
27 char *set_msg;
28 enum {SET, LEVEL, BOOLEAN} set_type;
29 }
30 ent;
31
32 int main(int argc, char **argv)
33 {
34 if(argc!=2)
35 {
36 fprintf(stderr, "usage: genconfig <outtype>\n");
37 return(EXIT_FAILURE);
38 }
39 int otype;
40 if(strcmp(argv[1], "config_globals.h")==0)
41 otype=0;
42 else if(strcmp(argv[1], "config_check.c")==0)
43 otype=1;
44 else if(strcmp(argv[1], "config_def.c")==0)
45 otype=2;
46 else if(strcmp(argv[1], "config_rcread.c")==0)
47 otype=3;
48 else if(strcmp(argv[1], "config_pargs.c")==0)
49 otype=4;
50 else if(strcmp(argv[1], "config_set.c")==0)
51 otype=5;
52 else if(strcmp(argv[1], "config_need.c")==0)
53 otype=6;
f5e7385 Generated options list for --help output
ec429 authored
54 else if(strcmp(argv[1], "config_help.c")==0)
55 otype=7;
76d7bce HTML Reference table for the genconfig stuff (/set, rc, cmdline options)
ec429 authored
56 else if(strcmp(argv[1], "config_ref.htm")==0)
57 otype=8;
c217817 @ec429 Fix Issue #20: dependency files confusing genconfig
authored
58 else if(strcmp(argv[1], "config_h.d")==0)
59 return(0); // an empty file will do
73db7f3 @ec429 Try again with Issue #20; we need to handle the _c.d as well
authored
60 else if(strcmp(argv[1], "config_c.d")==0)
61 return(0); // an empty file will do
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
62 else
63 {
64 fprintf(stderr, "genconfig: unrecognised outtype '%s'\n", argv[1]);
65 return(EXIT_FAILURE);
66 }
67 int nents=0;
68 ent *ents=NULL;
69 while(!feof(stdin))
70 {
71 char *line=fgetl(stdin);
72 if(!*line)
73 {
74 free(line);
75 continue;
76 }
77 int nent=nents++;
78 ents=realloc(ents, nents*sizeof(ent));
79 if(!ents)
80 {
81 perror("genconfig: realloc");
82 return(EXIT_FAILURE);
83 }
84 char *p=line;
85 int tocolon=strcspn(p, ":");
86 if(strncmp(p, "int", tocolon)==0)
87 ents[nent].type=INT;
88 else if(strncmp(p, "bool", tocolon)==0)
89 ents[nent].type=BOOL;
90 else
91 {
92 fprintf(stderr, "genconfig: unrecognised type %.*s\n", tocolon, p);
93 return(EXIT_FAILURE);
94 }
95 p+=tocolon;
96 if(!*p)
97 {
98 fprintf(stderr, "genconfig: premature end of line %u\n", nents);
99 return(EXIT_FAILURE);
100 }
101 p++;tocolon=strcspn(p, ":");
102 ents[nent].cname=malloc(tocolon+1);
103 if(!ents[nent].cname)
104 {
105 perror("genconfig: malloc");
106 return(EXIT_FAILURE);
107 }
108 strncpy(ents[nent].cname, p, tocolon);
109 ents[nent].cname[tocolon]=0;
110 p+=tocolon;
111 if(!*p)
112 {
113 fprintf(stderr, "genconfig: premature end of line %u (%s)\n", nents, ents[nent].cname);
114 return(EXIT_FAILURE);
115 }
116 p++;tocolon=strcspn(p, ":");
117 if(tocolon)
118 {
119 char *value=malloc(tocolon+1);
120 if(!value)
121 {
122 perror("genconfig: malloc");
123 return(EXIT_FAILURE);
124 }
125 strncpy(value, p, tocolon);
126 value[tocolon]=0;
03bb3ce config: fix bug with boolean constants in .cdl file
ec429 authored
127 switch(ents[nent].type)
128 {
129 case INT:
130 if(!sscanf(value, "%d", &ents[nent].value)) ents[nent].value=-1;
131 break;
132 case BOOL:
133 if(strcmp(value, "true")==0)
134 ents[nent].value=1;
135 else if(strcmp(value, "false")==0)
136 ents[nent].value=0;
137 else if(!sscanf(value, "%d", &ents[nent].value))
138 ents[nent].value=1; // default to true
139 break;
140 }
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
141 free(value);
142 p+=tocolon;
143 }
144 else
145 {
146 ents[nent].value=-1;
147 }
148 if(!*p)
149 {
150 fprintf(stderr, "genconfig: premature end of line %u (%s)\n", nents, ents[nent].cname);
151 return(EXIT_FAILURE);
152 }
153 p++;tocolon=strcspn(p, ":");
154 if(tocolon)
155 {
156 char *min=malloc(tocolon+1);
157 if(!min)
158 {
159 perror("genconfig: malloc");
160 return(EXIT_FAILURE);
161 }
162 strncpy(min, p, tocolon);
163 min[tocolon]=0;
164 if(!sscanf(min, "%d", &ents[nent].min)) ents[nent].min=-1;
165 free(min);
166 p+=tocolon;
167 }
168 else
169 {
170 ents[nent].min=-1;
171 }
172 if(!*p)
173 {
174 fprintf(stderr, "genconfig: premature end of line %u (%s)\n", nents, ents[nent].cname);
175 return(EXIT_FAILURE);
176 }
177 p++;tocolon=strcspn(p, ":");
178 if(tocolon)
179 {
180 char *max=malloc(tocolon+1);
181 if(!max)
182 {
183 perror("genconfig: malloc");
184 return(EXIT_FAILURE);
185 }
186 strncpy(max, p, tocolon);
187 max[tocolon]=0;
188 if(!sscanf(max, "%d", &ents[nent].max)) ents[nent].max=-1;
189 free(max);
190 p+=tocolon;
191 }
192 else
193 {
194 ents[nent].max=-1;
195 }
196 if(!*p)
197 {
198 fprintf(stderr, "genconfig: premature end of line %u (%s)\n", nents, ents[nent].cname);
199 return(EXIT_FAILURE);
200 }
201 p++;tocolon=strcspn(p, ":");
202 if(tocolon)
203 {
204 ents[nent].rc_name=malloc(tocolon+1);
205 if(!ents[nent].rc_name)
206 {
207 perror("genconfig: malloc");
208 return(EXIT_FAILURE);
209 }
210 strncpy(ents[nent].rc_name, p, tocolon);
211 ents[nent].rc_name[tocolon]=0;
212 p+=tocolon;
213 }
214 else
215 {
216 ents[nent].rc_name=NULL;
217 }
218 if(!*p)
219 {
220 fprintf(stderr, "genconfig: premature end of line %u (%s)\n", nents, ents[nent].cname);
221 return(EXIT_FAILURE);
222 }
223 p++;tocolon=strcspn(p, ":");
224 if(tocolon)
225 {
226 ents[nent].cmdline_name=malloc(tocolon+1);
227 if(!ents[nent].cmdline_name)
228 {
229 perror("genconfig: malloc");
230 return(EXIT_FAILURE);
231 }
232 strncpy(ents[nent].cmdline_name, p, tocolon);
233 ents[nent].cmdline_name[tocolon]=0;
234 p+=tocolon;
235 }
236 else
237 {
238 ents[nent].cmdline_name=NULL;
239 }
240 if(!*p)
241 {
242 fprintf(stderr, "genconfig: premature end of line %u (%s)\n", nents, ents[nent].cname);
243 return(EXIT_FAILURE);
244 }
245 p++;tocolon=strcspn(p, ":");
246 if(tocolon)
247 {
248 ents[nent].set_name=malloc(tocolon+1);
249 if(!ents[nent].set_name)
250 {
251 perror("genconfig: malloc");
252 return(EXIT_FAILURE);
253 }
254 strncpy(ents[nent].set_name, p, tocolon);
255 ents[nent].set_name[tocolon]=0;
256 p+=tocolon;
257 }
258 else
259 {
260 ents[nent].set_name=NULL;
261 }
262 if(!*p)
263 {
264 fprintf(stderr, "genconfig: premature end of line %u (%s)\n", nents, ents[nent].cname);
265 return(EXIT_FAILURE);
266 }
267 p++;tocolon=strcspn(p, ":");
268 if(strncmp(p, "SET", tocolon)==0)
269 ents[nent].set_type=SET;
270 else if(strncmp(p, "LEVEL", tocolon)==0)
271 ents[nent].set_type=LEVEL;
272 else if(strncmp(p, "BOOLEAN", tocolon)==0)
273 ents[nent].set_type=BOOLEAN;
274 else
275 {
276 fprintf(stderr, "genconfig: unrecognised set_type %.*s in line %u (%s)\n", tocolon, p, nents, ents[nent].cname);
277 return(EXIT_FAILURE);
278 }
279 p+=tocolon;
280 if(!*p)
281 {
282 fprintf(stderr, "genconfig: premature end of line %u (%s)\n", nents, ents[nent].cname);
283 return(EXIT_FAILURE);
284 }
285 p++;tocolon=strcspn(p, ":");
286 if(tocolon)
287 {
288 ents[nent].set_msg=malloc(tocolon+1);
289 if(!ents[nent].set_msg)
290 {
291 perror("genconfig: malloc");
292 return(EXIT_FAILURE);
293 }
294 strncpy(ents[nent].set_msg, p, tocolon);
295 ents[nent].set_msg[tocolon]=0;
296 }
297 else
298 {
299 ents[nent].set_msg=NULL;
300 }
301 free(line);
302 }
76d7bce HTML Reference table for the genconfig stuff (/set, rc, cmdline options)
ec429 authored
303 if(otype==8)
304 printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\
305 <html xmlns=\"http://www.w3.org/1999/xhtml\">\n\
306 <head>\n\
307 \t<title>quIRC: configuration reference</title>\n\
308 \t<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8;\" />\n\
309 \t<link rel=\"stylesheet\" href=\"readme.css\" />\n\t<style type=\"text/css\">\n\
310 \t\ttt {margin-left:4em;}\n\
311 \t\ttd {border:1px solid; border-color:#1f273f; padding:2px;}\n\
312 \t\t.int {background-color:#376f4f; color:black;}\n\
313 \t\t.bool {background-color:#374f6f; color:black;}\n\
314 \t\t.na {background-color:#2f2f37; color:#7f7f9f};\n\
315 \t</style>\n\
316 </head>\n\
317 <body>\n\
318 <div id=\"title\">\n\
319 <h1>quIRC: reference</h1>\n\
320 <h5>A reference table for quIRC's configuration options, and how to set them.<br>\n\
321 Generated by <small>genconfig</small></h5>\n\
322 </div><!--#title-->\n\
323 <div id=\"key\">\n\
324 <h2>Key to Columns</h2>\n\
325 <dl>\n\
326 <dt>name</dt>\n\
327 \t<dd>The internal name of the setting.</dd>\n\
328 <dt>type</dt>\n\
329 \t<dd>The setting's type, either <span class=\"int\">INT</span> (integer) or <span class=\"bool\">BOOL</span> (boolean).</dd>\n\
330 <dt>default</dt>\n\
331 \t<dd>The setting's default value.</dd>\n\
332 <dt>rc</dt>\n\
333 \t<dd>The setting's name in the rc file (typically ~/.quirc/rc), if settable there.</dd>\n\
334 <dt>cmdline</dt>\n\
335 \t<dd>The setting's name on the command line, if settable there.</dd>\n\
336 <dt>/set</dt>\n\
337 \t<dd>The name to use with the /set command. If the setting is an <span class=\"int\">INT</span>, use <small>/set &lt;name&gt; &lt;value&gt;</small>; omitting <small>&lt;value&gt;</small> sets to the default value. If the setting is a <span class=\"bool\">BOOL</span>, use <small>/set &lt;name&gt;</small> to enable, and <small>/set no-&lt;name&gt;</small> to disable (you can also use other forms, such as supplying a <small>&lt;value&gt;</small> of + or 1 to enable and - or 0 to disable).</dd>\n\
338 <dt>description</dt>\n\
339 \t<dd>A short description of the setting, as used in messages produced by /set.</dd>\n\
340 </dl>\n\
341 </div><!--#key-->\n\
342 <div id=\"table\">\n\
343 <table style=\"border:1px solid;\">\n\
344 <tr style=\"text-align:center\"><td>name</td><td>type</td><td>default</td><td>rc</td><td>cmdline</td><td>/set</td><td>description</td></tr>\n");
345 else
346 printf("/* Generated by genconfig */\n");
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
347 switch(otype)
348 {
349 case 1:
350 printf("int conf_check(void)\n{\n");
351 break;
352 }
353 int i;
354 bool first=true;
355 for(i=0;i<nents;i++)
356 {
357 switch(otype)
358 {
359 case 0:
360 switch(ents[i].type)
361 {
362 case INT:
363 printf("unsigned int ");
364 break;
365 case BOOL:
366 printf("bool ");
367 break;
368 default:
369 fprintf(stderr, "Unsupported type %d in %s\n", ents[i].type, ents[i].cname);
370 return(EXIT_FAILURE);
371 }
372 printf("%s; // %s\n", ents[i].cname, ents[i].set_msg);
373 break;
374 case 1:
375 switch(ents[i].type)
376 {
377 case INT:
378 if(ents[i].min>0)
379 {
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
380 printf("\tif(%s<%d)\n\t{\n\t\tatr_failsafe(&s_buf, STA, \"%s set to minimum %d\", \"init: \");\n\t\t%s=%d;\n\t}\n", ents[i].cname, ents[i].min, ents[i].set_name, ents[i].min, ents[i].cname, ents[i].min);
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
381 }
382 if(ents[i].max!=-1)
383 {
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
384 printf("\tif(%s>%d)\n\t{\n\t\tatr_failsafe(&s_buf, STA, \"%s set to maximum %d\", \"init: \");\n\t\t%s=%d;\n\t}\n", ents[i].cname, ents[i].max, ents[i].set_name, ents[i].max, ents[i].cname, ents[i].max);
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
385 }
386 break;
387 case BOOL:
388 break;
389 default:
390 fprintf(stderr, "Unsupported type %d in %s\n", ents[i].type, ents[i].cname);
391 return(EXIT_FAILURE);
392 }
393 break;
394 case 2:
395 printf("\t%s=%d;\n", ents[i].cname, ents[i].value);
396 break;
397 case 3:
398 if(ents[i].rc_name)
399 {
400 switch(ents[i].type)
401 {
402 case BOOL:
403 case INT:
0275d65 config: more permissive of the 'no-foo' form in rc file
ec429 authored
404 if((ents[i].set_type==BOOLEAN)||(ents[i].set_type==LEVEL))
405 {
406 printf("\t\t\telse if(strcmp(cmd, \"no-%s\")==0)\n", ents[i].rc_name);
407 printf("\t\t\t\t%s=false;\n", ents[i].cname);
408 }
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
409 printf("\t\t\telse if(strcmp(cmd, \"%s\")==0)\n", ents[i].rc_name);
410 printf("\t\t\t{\n");
411 printf("\t\t\t\tunsigned int value;\n");
412 printf("\t\t\t\tif(rest&&sscanf(rest, \"%%u\", &value))\n");
413 printf("\t\t\t\t\t%s=value;\n", ents[i].cname);
414 printf("\t\t\t\telse\n");
415 if(ents[i].type==BOOL)
416 printf("\t\t\t\t\t%s=true;\n", ents[i].cname);
417 else
418 {
419 printf("\t\t\t\t{\n");
e184c8b Ring-buffer for debug messages. Complicated (see full message).
ec429 authored
420 printf("\t\t\t\t\tatr_failsafe(&s_buf, ERR, \"Malformed rc entry for %s (value not numeric)\", \"init: \");\n", ents[i].rc_name);
421 printf("\t\t\t\t\tatr_failsafe(&s_buf, ERR, rest, \"init: \");\n");
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
422 printf("\t\t\t\t}\n");
423 }
424 printf("\t\t\t}\n");
425 break;
426 default:
427 fprintf(stderr, "Unsupported type %d in %s\n", ents[i].type, ents[i].cname);
428 return(EXIT_FAILURE);
429 }
430 }
431 break;
432 case 4:
433 if(ents[i].cmdline_name)
434 {
435 switch(ents[i].type)
436 {
437 case BOOL:
438 printf("\t\telse if(strcmp(argv[arg], \"--%s\")==0)\n", ents[i].cmdline_name);
439 printf("\t\t\t%s=true;\n", ents[i].cname);
440 printf("\t\telse if(strcmp(argv[arg], \"--no-%s\")==0)\n", ents[i].cmdline_name);
441 printf("\t\t\t%s=false;\n", ents[i].cname);
442 break;
443 case INT:
020eb42 Fix warnings on Fedora (size_t, %zu and friends)
ec429 authored
444 printf("\t\telse if(strncmp(argv[arg], \"--%s=\", %zu)==0)\n", ents[i].cmdline_name, strlen(ents[i].cmdline_name)+3);
445 printf("\t\t\tsscanf(argv[arg]+%zu, \"%%u\", &%s);\n", strlen(ents[i].cmdline_name)+3, ents[i].cname);
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
446 break;
447 }
448 }
449 break;
450 case 5:
451 if(ents[i].set_name)
452 {
453 printf("\t\t\t\t");
454 if(!first) printf("else ");
455 first=false;
42b7022 Better handling of boolean options (genconfig); added input clock (/s…
ec429 authored
456 printf("if(strcmp(opt, \"%s\")==0)\n", ents[i].set_name);
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
457 printf("\t\t\t\t{\n");
42b7022 Better handling of boolean options (genconfig); added input clock (/s…
ec429 authored
458 if(ents[i].set_type==BOOLEAN)
459 {
460 printf("\t\t\t\t\tif(val)\n");
461 printf("\t\t\t\t\t{\n");
462 printf("\t\t\t\t\t\tif(isdigit(*val))\n");
463 printf("\t\t\t\t\t\t{\n");
464 printf("\t\t\t\t\t\t\tunsigned int value;\n");
465 printf("\t\t\t\t\t\t\tsscanf(val, \"%%u\", &value);\n");
466 printf("\t\t\t\t\t\t\t%s=value;\n", ents[i].cname);
467 printf("\t\t\t\t\t\t}\n");
468 printf("\t\t\t\t\t\telse if(strcmp(val, \"+\")==0)\n");
469 printf("\t\t\t\t\t\t{\n");
470 printf("\t\t\t\t\t\t\t%s=true;\n", ents[i].cname);
471 printf("\t\t\t\t\t\t}\n");
472 printf("\t\t\t\t\t\telse if(strcmp(val, \"-\")==0)\n");
473 printf("\t\t\t\t\t\t{\n");
474 printf("\t\t\t\t\t\t\t%s=false;\n", ents[i].cname);
475 printf("\t\t\t\t\t\t}\n");
476 printf("\t\t\t\t\t\telse\n");
477 printf("\t\t\t\t\t\t{\n");
30c1746 Implemented priorities (so quiet mode & debug are retroactive)
ec429 authored
478 printf("\t\t\t\t\t\t\tadd_to_buffer(cbuf, ERR, NORMAL, 0, false, \"option '%s' is boolean, use only 0/1 or -/+ to set\", \"/set: \");\n", ents[i].set_name);
42b7022 Better handling of boolean options (genconfig); added input clock (/s…
ec429 authored
479 printf("\t\t\t\t\t\t}\n");
480 printf("\t\t\t\t\t}\n");
481 printf("\t\t\t\t\telse\n");
482 printf("\t\t\t\t\t\t%s=true;\n", ents[i].cname);
483 }
484 else
485 {
486 printf("\t\t\t\t\tif(val)\n");
487 printf("\t\t\t\t\t{\n");
488 printf("\t\t\t\t\t\tunsigned int value;\n");
489 printf("\t\t\t\t\t\tsscanf(val, \"%%u\", &value);\n");
490 printf("\t\t\t\t\t\t%s=value;\n", ents[i].cname);
491 printf("\t\t\t\t\t}\n");
492 printf("\t\t\t\t\telse\n");
493 printf("\t\t\t\t\t\t%s=%d;\n", ents[i].cname, ents[i].value);
5eea39e genconfig: fix bug with /set out-of-range values
ec429 authored
494 if(ents[i].min>0)
495 {
496 printf("\t\t\t\t\tif(%s<%d)\n", ents[i].cname, ents[i].min);
497 printf("\t\t\t\t\t\t%s=%d;\n", ents[i].cname, ents[i].min);
498 }
499 if(ents[i].max>=0)
500 {
501 printf("\t\t\t\t\tif(%s>%d)\n", ents[i].cname, ents[i].max);
502 printf("\t\t\t\t\t\t%s=%d;\n", ents[i].cname, ents[i].max);
503 }
42b7022 Better handling of boolean options (genconfig); added input clock (/s…
ec429 authored
504 }
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
505 switch(ents[i].set_type)
506 {
507 case BOOLEAN:
30c1746 Implemented priorities (so quiet mode & debug are retroactive)
ec429 authored
508 printf("\t\t\t\t\tif(%s)\n", ents[i].cname);
509 printf("\t\t\t\t\t\tadd_to_buffer(cbuf, STA, QUIET, 0, false, \"%s enabled\", \"/set: \");\n", ents[i].set_msg);
510 printf("\t\t\t\t\telse\n");
511 printf("\t\t\t\t\t\tadd_to_buffer(cbuf, STA, QUIET, 0, false, \"%s disabled\", \"/set: \");\n", ents[i].set_msg);
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
512 break;
513 case LEVEL:
30c1746 Implemented priorities (so quiet mode & debug are retroactive)
ec429 authored
514 printf("\t\t\t\t\tif(%s)\n", ents[i].cname);
515 printf("\t\t\t\t\t{\n");
516 printf("\t\t\t\t\t\tchar lmsg[%zu];\n", strlen(ents[i].set_msg)+32);
517 printf("\t\t\t\t\t\tsprintf(lmsg, \"%s level %%u enabled\", %s);\n", ents[i].set_msg, ents[i].cname);
518 printf("\t\t\t\t\t\tadd_to_buffer(cbuf, STA, QUIET, 0, false, lmsg, \"/set: \");\n");
519 printf("\t\t\t\t\t}\n");
520 printf("\t\t\t\t\telse\n");
521 printf("\t\t\t\t\t\tadd_to_buffer(cbuf, STA, QUIET, 0, false, \"%s disabled\", \"/set: \");\n", ents[i].set_msg);
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
522 break;
523 case SET:
30c1746 Implemented priorities (so quiet mode & debug are retroactive)
ec429 authored
524 printf("\t\t\t\t\tchar smsg[%zu];\n", strlen(ents[i].set_msg)+24);
525 printf("\t\t\t\t\tsprintf(smsg, \"%s set to %%u\", %s);\n", ents[i].set_msg, ents[i].cname);
526 printf("\t\t\t\t\tadd_to_buffer(cbuf, STA, QUIET, 0, false, smsg, \"/set: \");\n");
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
527 break;
528 }
3d938cf Timestamp display (/set ts <level>, /set utc)
ec429 authored
529 printf("\t\t\t\t\tint buf;\n");
530 printf("\t\t\t\t\tfor(buf=0;buf<nbufs;buf++)\n");
531 printf("\t\t\t\t\t\tbufs[buf].dirty=true;\n");
532 printf("\t\t\t\t\tredraw_buffer();\n");
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
533 printf("\t\t\t\t}\n");
534 if((ents[i].set_type==BOOLEAN)||(ents[i].set_type==LEVEL))
535 {
536 printf("\t\t\t\telse if(strcmp(opt, \"no-%s\")==0)\n", ents[i].set_name);
537 printf("\t\t\t\t{\n");
538 printf("\t\t\t\t\t%s=0;\n", ents[i].cname);
30c1746 Implemented priorities (so quiet mode & debug are retroactive)
ec429 authored
539 printf("\t\t\t\t\tadd_to_buffer(cbuf, STA, QUIET, 0, false, \"%s disabled\", \"/set: \");\n", ents[i].set_msg);
3d938cf Timestamp display (/set ts <level>, /set utc)
ec429 authored
540 printf("\t\t\t\t\tint buf;\n");
541 printf("\t\t\t\t\tfor(buf=0;buf<nbufs;buf++)\n");
542 printf("\t\t\t\t\t\tbufs[buf].dirty=true;\n");
543 printf("\t\t\t\t\tredraw_buffer();\n");
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
544 printf("\t\t\t\t}\n");
545 }
546 }
547 break;
548 case 6:
a98d517 genconfig: fix bug with "(null)" in config_need.c
ec429 authored
549 if(ents[i].rc_name)
550 {
551 printf("\t\t\tif(strcmp(cmd, \"%s\")==0) need=false;\n", ents[i].rc_name);
552 if((ents[i].set_type==BOOLEAN)||(ents[i].set_type==LEVEL))
553 printf("\t\t\tif(strcmp(cmd, \"no-%s\")==0) need=false;\n", ents[i].rc_name);
554 }
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
555 break;
f5e7385 Generated options list for --help output
ec429 authored
556 case 7:
557 if(ents[i].cmdline_name)
558 {
559 int j;
560 switch(ents[i].type)
561 {
562 case BOOL:
563 printf("\t\t\tfprintf(stderr, \"\\t--[no-]%s", ents[i].cmdline_name);
564 for(j=strlen(ents[i].cmdline_name);j<25;j++)
565 putchar(' ');
566 break;
567 case INT:
568 if((ents[i].min!=-1)&&(ents[i].max!=-1))
569 {
570 printf("\t\t\tfprintf(stderr, \"\\t--%s=<%d to %d>", ents[i].cmdline_name, ents[i].min, ents[i].max);
571 for(j=strlen(ents[i].cmdline_name);j<21;j++)
572 putchar(' ');
573 }
574 else
575 {
576 printf("\t\t\tfprintf(stderr, \"\\t--%s=<numeric>", ents[i].cmdline_name);
577 for(j=strlen(ents[i].cmdline_name);j<20;j++)
578 putchar(' ');
579 }
580 break;
581 }
76d7bce HTML Reference table for the genconfig stuff (/set, rc, cmdline options)
ec429 authored
582 printf(": %s\\n\");\n", ents[i].set_msg);
583 }
584 break;
585 case 8:
586 switch(ents[i].type)
587 {
588 case BOOL:
589 printf("<tr><td>%s</td><td><span class=\"bool\">BOOL</span></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", ents[i].cname, ents[i].value?"true":"false", ents[i].rc_name?ents[i].rc_name:"<span class=\"na\">[N/A]</span>", ents[i].cmdline_name?ents[i].cmdline_name:"<span class=\"na\">[N/A]</span>", ents[i].set_name?ents[i].set_name:"<span class=\"na\">[N/A]</span>", ents[i].set_msg?ents[i].set_msg:"<span class=\"na\">[N/A]</span>");
590 break;
591 case INT:
592 printf("<tr><td>%s</td><td><span class=\"int\">INT</span></td><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", ents[i].cname, ents[i].value, ents[i].rc_name?ents[i].rc_name:"<span class=\"na\">[N/A]</span>", ents[i].cmdline_name?ents[i].cmdline_name:"<span class=\"na\">[N/A]</span>", ents[i].set_name?ents[i].set_name:"<span class=\"na\">[N/A]</span>", ents[i].set_msg?ents[i].set_msg:"<span class=\"na\">[N/A]</span>");
593 break;
594 default:
595 printf("<tr><td>%s</td><td><em>(unknown type)</em></td><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", ents[i].cname, ents[i].value, ents[i].rc_name?ents[i].rc_name:"<span class=\"na\">[N/A]</span>", ents[i].cmdline_name?ents[i].cmdline_name:"<span class=\"na\">[N/A]</span>", ents[i].set_name?ents[i].set_name:"<span class=\"na\">[N/A]</span>", ents[i].set_msg?ents[i].set_msg:"<span class=\"na\">[N/A]</span>");
596 break;
f5e7385 Generated options list for --help output
ec429 authored
597 }
598 break;
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
599 default:
600 fprintf(stderr, "genconfig: otype %d not implemented!\n", otype);
601 return(EXIT_FAILURE);
602 break;
603 }
604 }
605 switch(otype)
606 {
607 case 1:
608 printf("\treturn(0);\n}\n");
609 break;
76d7bce HTML Reference table for the genconfig stuff (/set, rc, cmdline options)
ec429 authored
610 case 8:
611 printf("</table>\n</div><!--#table-->\n</body>\n</html>\n");
612 break;
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
613 }
ebc74a9 Refactored string buffers to new strbuf.h, shared with the gen* progs.
ec429 authored
614 return(0);
de4ae60 config: generate much of the config code from a concise descriptions …
ec429 authored
615 }
Something went wrong with that request. Please try again.