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 1867
 static void pp_endif()
1868 1868
 {
1869 1869
 	pp_sptr--;
1870
+	pp_ifdef_level_update(-1);
1870 1871
 	pp_update_state();
1871 1872
 }
1872 1873
 
... ...
@@ -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 2090
 		fprintf(stderr, "%d config warnings\n", cfg_warnings);
2091 2091
 	}
2092 2092
 	if (debug_flag) default_core_cfg.debug = debug_save;
2093
+	pp_ifdef_level_check();
2093 2094
 	print_rls();
2094 2095
 
2095 2096
 	/* 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 200
 	return 0;
201 201
 }
202 202
 
203
+/**
204
+ *
205
+ */
206
+void pp_ifdef_level_update(int val)
207
+{
208
+	_pp_ifdef_level += val;
209
+}
210
+
211
+/**
212
+ *
213
+ */
214
+void pp_ifdef_level_check(void)
215
+{
216
+	if(_pp_ifdef_level!=0) {
217
+		LM_WARN("different number of preprocessor directives:"
218
+				" N(#!IF[N]DEF) - N(#!ENDIF) = %d\n", _pp_ifdef_level);
219
+	} else {
220
+		LM_DBG("same number of pairing preprocessor directives"
221
+			" #!IF[N]DEF - #!ENDIF\n");
222
+	}
223
+}
224
+
203 225
 /* 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: */