Browse code

core: evalute define expressions in config for --cfg-print option

Daniel-Constantin Mierla authored on 10/11/2020 14:56:00
Showing 1 changed files
... ...
@@ -119,6 +119,7 @@
119 119
 	static void pp_ifdef();
120 120
 	static void pp_else();
121 121
 	static void pp_endif();
122
+	static void ksr_print_cfg_part(char *text);
122 123
 
123 124
 %}
124 125
 
... ...
@@ -1283,32 +1284,55 @@ IMPORTFILE      "import_file"
1283 1284
 											}
1284 1285
 											sr_cfg_compat=SR_COMPAT_MAX;}
1285 1286
 
1286
-<INITIAL>{PREP_START}{DEFINE}{EAT_ABLE}+	{	count(); pp_define_set_type(0);
1287
+<INITIAL,CFGPRINTMODE>{PREP_START}{DEFINE}{EAT_ABLE}+	{	count();
1288
+											ksr_print_cfg_part(yytext);
1289
+											pp_define_set_type(0);
1287 1290
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1288
-<INITIAL>{PREP_START}{TRYDEF}{EAT_ABLE}+	{	count(); pp_define_set_type(1);
1291
+<INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEF}{EAT_ABLE}+	{	count();
1292
+											ksr_print_cfg_part(yytext);
1293
+											pp_define_set_type(1);
1289 1294
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1290
-<INITIAL>{PREP_START}{REDEF}{EAT_ABLE}+	{	count(); pp_define_set_type(2);
1295
+<INITIAL,CFGPRINTMODE>{PREP_START}{REDEF}{EAT_ABLE}+	{	count();
1296
+											ksr_print_cfg_part(yytext);
1297
+											pp_define_set_type(2);
1291 1298
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1292 1299
 <DEFINE_ID>{ID}{MINUS}          {	count();
1300
+									ksr_print_cfg_part(yytext);
1293 1301
 									LM_CRIT(
1294 1302
 										"error at %s line %d: '-' not allowed\n",
1295 1303
 										(finame)?finame:"cfg", line);
1296 1304
 									exit(-1);
1297 1305
 								}
1298 1306
 <DEFINE_ID>{ID}                 {	count();
1307
+									ksr_print_cfg_part(yytext);
1299 1308
 									if (pp_define(yyleng, yytext)) return 1;
1300 1309
 									state = DEFINE_EOL_S; BEGIN(DEFINE_EOL); }
1301
-<DEFINE_EOL>{EAT_ABLE}			{	count(); }
1310
+<DEFINE_EOL>{EAT_ABLE}			{	count(); ksr_print_cfg_part(yytext); }
1302 1311
 <DEFINE_EOL>{CR}				{	count();
1303
-									state = INITIAL; BEGIN(INITIAL); }
1312
+									ksr_print_cfg_part(yytext);
1313
+									state = INITIAL;
1314
+									if(ksr_cfg_print_mode == 1) {
1315
+										BEGIN(CFGPRINTMODE);
1316
+									} else {
1317
+										BEGIN(INITIAL);
1318
+									}
1319
+								}
1304 1320
 <DEFINE_EOL>.                   {	count();
1321
+									ksr_print_cfg_part(yytext);
1305 1322
 									addstr(&s_buf, yytext, yyleng);
1306 1323
 									state = DEFINE_DATA_S; BEGIN(DEFINE_DATA); }
1307
-<DEFINE_DATA>\\{CR}		{	count(); } /* eat the escaped CR */
1324
+<DEFINE_DATA>\\{CR}		{	count(); ksr_print_cfg_part(yytext); } /* eat the escaped CR */
1308 1325
 <DEFINE_DATA>{CR}		{	count();
1326
+							ksr_print_cfg_part(yytext);
1309 1327
 							if (pp_define_set(strlen(s_buf.s), s_buf.s)) return 1;
1310 1328
 							memset(&s_buf, 0, sizeof(s_buf));
1311
-							state = INITIAL; BEGIN(INITIAL); }
1329
+							state = INITIAL;
1330
+							if(ksr_cfg_print_mode == 1) {
1331
+								BEGIN(CFGPRINTMODE);
1332
+							} else {
1333
+								BEGIN(INITIAL);
1334
+							}
1335
+						}
1312 1336
 <DEFINE_DATA>.          {	count();
1313 1337
 							addstr(&s_buf, yytext, yyleng); }
1314 1338
 
... ...
@@ -1454,6 +1478,12 @@ IMPORTFILE      "import_file"
1454 1478
 
1455 1479
 %%
1456 1480
 
1481
+static void ksr_print_cfg_part(char *text)
1482
+{
1483
+	if(ksr_cfg_print_mode == 1) {
1484
+		printf("%s", text);
1485
+	}
1486
+}
1457 1487
 
1458 1488
 static char* addchar(struct str_buf* dst, char c)
1459 1489
 {