[sr-dev] git:master: core: new param -A to add cfg preprocesor directives

Daniel-Constantin Mierla miconda at gmail.com
Wed Jul 28 00:04:40 CEST 2010



On 7/27/10 11:53 PM, Daniel-Constantin Mierla wrote:
> Module: sip-router
> Branch: master
> Commit: 95dec431421ce9f809f3a15f4c6407fff2d401a7
> URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=95dec431421ce9f809f3a15f4c6407fff2d401a7
>
> Author: Daniel-Constantin Mierla<miconda at gmail.com>
> Committer: Daniel-Constantin Mierla<miconda at gmail.com>
> Date:   Tue Jul 27 23:46:48 2010 +0200
>
> core: new param -A to add cfg preprocesor directives
>
> - defines can be specified from command line with option -A
> - these defines are available from begining of parsing the config
> - examples:
> 	- '-A WITH_AUTH' is like having '#!define WITH_AUTH' at top of cfg
> 	- '-A LISTENIP=127.0.0.1' is like '#!define LISTENIP=127.0.0.1'
>    

errata, the correct second example is:

	- '-A LISTENIP=127.0.0.1' is like '#!define LISTENIP 127.0.0.1'

in config is no '=' between define ID and value.

Daniel

> ---
>
>   cfg.lex |    6 ++----
>   main.c  |   28 ++++++++++++++++++++++++++--
>   ppcfg.h |    3 +++
>   3 files changed, 31 insertions(+), 6 deletions(-)
>
> diff --git a/cfg.lex b/cfg.lex
> index 564cb56..804b9e6 100644
> --- a/cfg.lex
> +++ b/cfg.lex
> @@ -166,8 +166,6 @@
>   		struct sr_yy_fname *next;
>   	} *sr_yy_fname_list = 0;
>
> -	static int  pp_define(int len, const char * text);
> -	static int  pp_define_set(int len, char * text);
>   	static str  *pp_define_get(int len, const char * text);
>   	static int  pp_ifdef_type(int pos);
>   	static void pp_ifdef_var(int len, const char * text);
> @@ -1614,7 +1612,7 @@ static int pp_lookup(int len, const char * text)
>   	return -1;
>   }
>
> -static int pp_define(int len, const char * text)
> +int pp_define(int len, const char * text)
>   {
>   	if (pp_num_defines == MAX_DEFINES) {
>   		LOG(L_CRIT, "ERROR: too many defines -- adjust MAX_DEFINES\n");
> @@ -1636,7 +1634,7 @@ static int pp_define(int len, const char * text)
>   	return 0;
>   }
>
> -static int  pp_define_set(int len, char *text)
> +int  pp_define_set(int len, char *text)
>   {
>   	if(len<=0) {
>   		LOG(L_DBG, "no define value - ignoring\n");
> diff --git a/main.c b/main.c
> index 5b0c476..cc6f137 100644
> --- a/main.c
> +++ b/main.c
> @@ -183,6 +183,7 @@
>   #include "basex.h" /* init */
>   #include "pvapi_init.h" /* init */
>   #include "pv_core.h" /* register core pvars */
> +#include "ppcfg.h"
>
>   #ifdef DEBUG_DMALLOC
>   #include<dmalloc.h>
> @@ -246,7 +247,8 @@ Options:\n\
>       -G file      Create a pgid file\n\
>       -O nr        Script optimization level (debugging option)\n\
>       -a mode      Auto aliases mode: enable with yes or on,\n\
> -                  disable with no or off\n"
> +                  disable with no or off\n\
> +    -A define    Add config pre-processor define (e.g., -A WITH_AUTH)\n"
>   #ifdef STATS
>   "    -s file     File to which statistics is dumped (disabled otherwise)\n"
>   #endif
> @@ -1649,6 +1651,7 @@ int main(int argc, char** argv)
>   	struct timeval tval;
>   	fd_set fds;
>   	int res;
> +	char *p;
>
>   	/*init*/
>   	time(&up_since);
> @@ -1667,7 +1670,7 @@ int main(int argc, char** argv)
>   		"DBG_MSG_QA enabled, ser may exit abruptly\n");
>   #endif
>
> -	options=  ":f:cm:dVhEb:l:L:n:vrRDTN:W:w:t:u:g:P:G:SQ:O:a:"
> +	options=  ":f:cm:dVhEb:l:L:n:vrRDTN:W:w:t:u:g:P:G:SQ:O:a:A:"
>   #ifdef STATS
>   		"s:"
>   #endif
> @@ -1749,6 +1752,26 @@ int main(int argc, char** argv)
>   					/* user needed for possible shm. pre-init */
>   					user=optarg;
>   					break;
> +			case 'A':
> +					p = strchr(optarg, '=');
> +					if(p) {
> +						*p = '\0';
> +					}
> +					if(pp_define(strlen(optarg), optarg)<0) {
> +						fprintf(stderr, "error at define param: -A %s\n",
> +								optarg);
> +						goto error;
> +					}
> +					if(p) {
> +						*p = '=';
> +						p++;
> +						if(pp_define_set(strlen(p), p)<0) {
> +							fprintf(stderr, "error at define value: -A %s\n",
> +								optarg);
> +							goto error;
> +						}
> +					}
> +					break;
>   			case 'b':
>   			case 'l':
>   			case 'n':
> @@ -1864,6 +1887,7 @@ try_again:
>   			case 'V':
>   			case 'h':
>   			case 'O':
> +			case 'A':
>   					break;
>   			case 'E':
>   					log_stderr=1;	// use in both getopt switches
> diff --git a/ppcfg.h b/ppcfg.h
> index c8ff4fa..c3a01f4 100644
> --- a/ppcfg.h
> +++ b/ppcfg.h
> @@ -25,6 +25,9 @@
>   int pp_subst_add(char *data);
>   int pp_subst_run(char **data);
>
> +int  pp_define(int len, const char * text);
> +int  pp_define_set(int len, char * text);
> +
>   #endif /*_PPCFG_H_*/
>
>   /* vi: set ts=4 sw=4 tw=79:ai:cindent: */
>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
>    

-- 
Daniel-Constantin Mierla
http://www.asipto.com/




More information about the sr-dev mailing list