Browse code

core: print warning message if number of #!if(n)def is different than of #!endif

- should help discovering if a conditional block is left unclosed

Daniel-Constantin Mierla authored on 14/03/2014 23:12:37
Showing 4 changed files
... ...
@@ -1825,6 +1825,7 @@ static int pp_ifdef_type(int type)
1825 1825
 	}
1826 1826
 
1827 1827
 	pp_ifdef_stack[pp_sptr] = type;
1828
+	pp_ifdef_level_update(1);
1828 1829
 	return 0;
1829 1830
 }
1830 1831
 
... ...
@@ -1867,6 +1868,7 @@ static void pp_else()
1867 1868
 static void pp_endif()
1868 1869
 {
1869 1870
 	pp_sptr--;
1871
+	pp_ifdef_level_update(-1);
1870 1872
 	pp_update_state();
1871 1873
 }
1872 1874
 
... ...
@@ -2083,6 +2083,8 @@ try_again:
2083 2083
 	debug_save = default_core_cfg.debug;
2084 2084
 	if ((yyparse()!=0)||(cfg_errors)){
2085 2085
 		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
2086
+		if (debug_flag) default_core_cfg.debug = debug_save;
2087
+		pp_ifdef_level_check();
2086 2088
 
2087 2089
 		goto error;
2088 2090
 	}
... ...
@@ -2090,6 +2092,7 @@ try_again:
2090 2092
 		fprintf(stderr, "%d config warnings\n", cfg_warnings);
2091 2093
 	}
2092 2094
 	if (debug_flag) default_core_cfg.debug = debug_save;
2095
+	pp_ifdef_level_check();
2093 2096
 	print_rls();
2094 2097
 
2095 2098
 	/* options with higher priority than cfg file */
... ...
@@ -39,6 +39,7 @@ typedef struct _pp_subst_rule {
39 39
 
40 40
 static pp_subst_rule_t *pp_subst_rules_head = NULL;
41 41
 static pp_subst_rule_t *pp_subst_rules_tail = NULL;
42
+static int _pp_ifdef_level = 0;
42 43
 
43 44
 int pp_subst_add(char *data)
44 45
 {
... ...
@@ -200,4 +201,26 @@ int pp_subst_run(char **data)
200 201
 	return 0;
201 202
 }
202 203
 
204
+/**
205
+ *
206
+ */
207
+void pp_ifdef_level_update(int val)
208
+{
209
+	_pp_ifdef_level += val;
210
+}
211
+
212
+/**
213
+ *
214
+ */
215
+void pp_ifdef_level_check(void)
216
+{
217
+	if(_pp_ifdef_level!=0) {
218
+		LM_WARN("different number of preprocessor directives:"
219
+				" N(#!IF[N]DEF) - N(#!ENDIF) = %d\n", _pp_ifdef_level);
220
+	} else {
221
+		LM_DBG("same number of pairing preprocessor directives"
222
+			" #!IF[N]DEF - #!ENDIF\n");
223
+	}
224
+}
225
+
203 226
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -30,6 +30,9 @@ int  pp_define(int len, const char *text);
30 30
 int  pp_define_set(int len, char *text);
31 31
 int  pp_define_set_type(int type);
32 32
 
33
+void pp_ifdef_level_update(int val);
34
+void pp_ifdef_level_check(void);
35
+
33 36
 #endif /*_PPCFG_H_*/
34 37
 
35 38
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */