Browse code

core: use defines for types of preprocessor defs

Daniel-Constantin Mierla authored on 20/09/2022 08:52:42
Showing 5 changed files
... ...
@@ -1329,15 +1329,15 @@ IMPORTFILE      "import_file"
1329 1329
 
1330 1330
 <INITIAL,CFGPRINTMODE>{PREP_START}{DEFINE}{EAT_ABLE}+	{	count();
1331 1331
 											ksr_cfg_print_part(yytext);
1332
-											pp_define_set_type(0);
1332
+											pp_define_set_type(KSR_PPDEF_DEFINE);
1333 1333
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1334 1334
 <INITIAL,CFGPRINTMODE>{PREP_START}{TRYDEF}{EAT_ABLE}+	{	count();
1335 1335
 											ksr_cfg_print_part(yytext);
1336
-											pp_define_set_type(1);
1336
+											pp_define_set_type(KSR_PPDEF_TRYDEF);
1337 1337
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1338 1338
 <INITIAL,CFGPRINTMODE>{PREP_START}{REDEF}{EAT_ABLE}+	{	count();
1339 1339
 											ksr_cfg_print_part(yytext);
1340
-											pp_define_set_type(2);
1340
+											pp_define_set_type(KSR_PPDEF_REDEF);
1341 1341
 											state = DEFINE_S; BEGIN(DEFINE_ID); }
1342 1342
 <DEFINE_ID>{ID}{MINUS}          {	count();
1343 1343
 									ksr_cfg_print_part(yytext);
... ...
@@ -1665,7 +1665,7 @@ static void ksr_cfg_print_define_module(char *modpath, int modpathlen)
1665 1665
 	}
1666 1666
 	memcpy(defmod, "MOD_", 4);
1667 1667
 	memcpy(defmod+4, modname.s, modname.len);
1668
-	pp_define_set_type(0);
1668
+	pp_define_set_type(KSR_PPDEF_DEFINE);
1669 1669
 	if(pp_define(modname.len + 4, defmod)<0) {
1670 1670
 		printf("\n# ***** ERROR: unable to set cfg define for module: %s\n",
1671 1671
 				modpath);
... ...
@@ -2067,11 +2067,11 @@ int pp_define(int len, const char *text)
2067 2067
 	pp_define_index = -1;
2068 2068
 	ppos = pp_lookup(len, text);
2069 2069
 	if(ppos >= 0) {
2070
-		if(pp_define_type==1) {
2070
+		if(pp_define_type==KSR_PPDEF_TRYDEF) {
2071 2071
 			LM_DBG("ignoring - already defined: %.*s\n", len, text);
2072 2072
 			pp_define_index = -2;
2073 2073
 			return 0;
2074
-		} else if(pp_define_type==2) {
2074
+		} else if(pp_define_type==KSR_PPDEF_REDEF) {
2075 2075
 			LM_DBG("redefining: %.*s\n", len, text);
2076 2076
 			pp_define_index = ppos;
2077 2077
 			if(pp_defines[ppos].value.s != NULL) {
... ...
@@ -2187,7 +2187,7 @@ int pp_define_env(const char *text, int len, int qmode, int vmode)
2187 2187
 	}
2188 2188
 	defvalue.len = strlen(defvalue.s);
2189 2189
 
2190
-	pp_define_set_type(0);
2190
+	pp_define_set_type(KSR_PPDEF_DEFINE);
2191 2191
 	if(pp_define(defname.len, defname.s)<0) {
2192 2192
 		LM_ERR("cannot set define name [%s]\n", (char*)text);
2193 2193
 		return -1;
... ...
@@ -169,7 +169,7 @@ found_regexp:
169 169
 found_repl:
170 170
 	defvalue.len = p - defvalue.s;
171 171
 
172
-	pp_define_set_type(0);
172
+	pp_define_set_type(KSR_PPDEF_DEFINE);
173 173
 	if(pp_define(defname.len, defname.s)<0) {
174 174
 		LM_ERR("cannot set define name\n");
175 175
 		goto error;
... ...
@@ -305,7 +305,7 @@ void pp_define_core(void)
305 305
 		LM_ERR("failed to build define token\n");
306 306
 		return;
307 307
 	}
308
-	pp_define_set_type(0);
308
+	pp_define_set_type(KSR_PPDEF_DEFINE);
309 309
 	if(pp_define(strlen(defval), defval)<0) {
310 310
 		LM_ERR("unable to set cfg define: %s\n", defval);
311 311
 		return;
... ...
@@ -317,7 +317,7 @@ void pp_define_core(void)
317 317
 		LM_ERR("failed to build define token\n");
318 318
 		return;
319 319
 	}
320
-	pp_define_set_type(0);
320
+	pp_define_set_type(KSR_PPDEF_DEFINE);
321 321
 	if(pp_define(strlen(defval), defval)<0) {
322 322
 		LM_ERR("unable to set cfg define: %s\n", defval);
323 323
 		return;
... ...
@@ -329,14 +329,14 @@ void pp_define_core(void)
329 329
 		LM_ERR("failed to build define token\n");
330 330
 		return;
331 331
 	}
332
-	pp_define_set_type(0);
332
+	pp_define_set_type(KSR_PPDEF_DEFINE);
333 333
 	if(pp_define(strlen(defval), defval)<0) {
334 334
 		LM_ERR("unable to set cfg define: %s\n", defval);
335 335
 		return;
336 336
 	}
337 337
 
338 338
 	strcpy(p, "_VERSION");
339
-	pp_define_set_type(0);
339
+	pp_define_set_type(KSR_PPDEF_DEFINE);
340 340
 	if(pp_define(strlen(defval), defval)<0) {
341 341
 		LM_ERR("unable to set cfg define: %s\n", defval);
342 342
 		return;
... ...
@@ -27,9 +27,14 @@
27 27
 
28 28
 #define KSR_PPDEF_NORMAL (0)     /* define normal value */
29 29
 #define KSR_PPDEF_QUOTED (1<<0)  /* define quoted value */
30
+
30 31
 #define KSR_PPDEF_VALREQ (0)     /* define with value required (defenv) */
31 32
 #define KSR_PPDEF_VALTRY (1<<0)  /* define only if value exists (trydefenv) */
32 33
 
34
+#define KSR_PPDEF_DEFINE  0
35
+#define KSR_PPDEF_TRYDEF  1
36
+#define KSR_PPDEF_REDEF   2
37
+
33 38
 typedef struct ksr_ppdefine {
34 39
 	str name;
35 40
 	str value;
... ...
@@ -321,7 +321,7 @@ static int register_module(module_exports_t* e, char* path, void* handle)
321 321
 	}
322 322
 	strcpy(defmod, "MOD_");
323 323
 	strcat(defmod, mod->exports.name);
324
-	pp_define_set_type(0);
324
+	pp_define_set_type(KSR_PPDEF_DEFINE);
325 325
 	if(pp_define(strlen(defmod), defmod)<0) {
326 326
 		LM_ERR("unable to set cfg define for module: %s\n",
327 327
 				mod->exports.name);
... ...
@@ -2286,7 +2286,7 @@ int main(int argc, char** argv)
2286 2286
 					} else {
2287 2287
 						tmp_len = strlen(optarg);
2288 2288
 					}
2289
-					pp_define_set_type(0);
2289
+					pp_define_set_type(KSR_PPDEF_DEFINE);
2290 2290
 					if(pp_define(tmp_len, optarg)<0) {
2291 2291
 						fprintf(stderr, "error at define param: -A %s\n",
2292 2292
 								optarg);