Skip to content

HTTPS clone URL

Subversion checkout URL

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