Module: sip-router
Branch: master
Commit: 713a0a1f068f9eb45a76dfe012b7f0ce6319221a
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=713a0a1…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sat Mar 15 00:12:37 2014 +0100
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
---
cfg.lex | 2 ++
main.c | 3 +++
ppcfg.c | 23 +++++++++++++++++++++++
ppcfg.h | 3 +++
4 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/cfg.lex b/cfg.lex
index 8e60c1e..50e7983 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -1825,6 +1825,7 @@ static int pp_ifdef_type(int type)
}
pp_ifdef_stack[pp_sptr] = type;
+ pp_ifdef_level_update(1);
return 0;
}
@@ -1867,6 +1868,7 @@ static void pp_else()
static void pp_endif()
{
pp_sptr--;
+ pp_ifdef_level_update(-1);
pp_update_state();
}
diff --git a/main.c b/main.c
index 05d431e..dbabaf0 100644
--- a/main.c
+++ b/main.c
@@ -2083,6 +2083,8 @@ try_again:
debug_save = default_core_cfg.debug;
if ((yyparse()!=0)||(cfg_errors)){
fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
+ if (debug_flag) default_core_cfg.debug = debug_save;
+ pp_ifdef_level_check();
goto error;
}
@@ -2090,6 +2092,7 @@ try_again:
fprintf(stderr, "%d config warnings\n", cfg_warnings);
}
if (debug_flag) default_core_cfg.debug = debug_save;
+ pp_ifdef_level_check();
print_rls();
/* options with higher priority than cfg file */
diff --git a/ppcfg.c b/ppcfg.c
index 7b01562..63549ac 100644
--- a/ppcfg.c
+++ b/ppcfg.c
@@ -39,6 +39,7 @@ typedef struct _pp_subst_rule {
static pp_subst_rule_t *pp_subst_rules_head = NULL;
static pp_subst_rule_t *pp_subst_rules_tail = NULL;
+static int _pp_ifdef_level = 0;
int pp_subst_add(char *data)
{
@@ -200,4 +201,26 @@ int pp_subst_run(char **data)
return 0;
}
+/**
+ *
+ */
+void pp_ifdef_level_update(int val)
+{
+ _pp_ifdef_level += val;
+}
+
+/**
+ *
+ */
+void pp_ifdef_level_check(void)
+{
+ if(_pp_ifdef_level!=0) {
+ LM_WARN("different number of preprocessor directives:"
+ " N(#!IF[N]DEF) - N(#!ENDIF) = %d\n", _pp_ifdef_level);
+ } else {
+ LM_DBG("same number of pairing preprocessor directives"
+ " #!IF[N]DEF - #!ENDIF\n");
+ }
+}
+
/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
diff --git a/ppcfg.h b/ppcfg.h
index b806daf..d940f86 100644
--- a/ppcfg.h
+++ b/ppcfg.h
@@ -30,6 +30,9 @@ int pp_define(int len, const char *text);
int pp_define_set(int len, char *text);
int pp_define_set_type(int type);
+void pp_ifdef_level_update(int val);
+void pp_ifdef_level_check(void);
+
#endif /*_PPCFG_H_*/
/* vi: set ts=4 sw=4 tw=79:ai:cindent: */