Browse code

core: added #!substdefs

- similar to substdef but the defined value will be enclosed in double
quotes

Daniel-Constantin Mierla authored on 06/07/2011 13:17:12
Showing 4 changed files
... ...
@@ -563,6 +563,7 @@ EAT_ABLE	[\ \t\b\r]
563 563
 /* pre-processing blocks */
564 564
 SUBST       subst
565 565
 SUBSTDEF    substdef
566
+SUBSTDEFS   substdefs
566 567
 
567 568
 /* include files */
568 569
 INCLUDEFILE     "include_file"
... ...
@@ -1245,6 +1246,7 @@ IMPORTFILE      "import_file"
1245 1245
 
1246 1246
 <INITIAL>{PREP_START}{SUBST}	{ count();  return SUBST;}
1247 1247
 <INITIAL>{PREP_START}{SUBSTDEF}	{ count();  return SUBSTDEF;}
1248
+<INITIAL>{PREP_START}{SUBSTDEFS}	{ count();  return SUBSTDEFS;}
1248 1249
 
1249 1250
 <INITIAL,IFDEF_SKIP>{PREP_START}{IFDEF}{EAT_ABLE}+    { count();
1250 1251
 								if (pp_ifdef_type(1)) return 1;
... ...
@@ -563,6 +563,7 @@ extern char *finame;
563 563
 /*pre-processor*/
564 564
 %token SUBST
565 565
 %token SUBSTDEF
566
+%token SUBSTDEFS
566 567
 
567 568
 /* operators, C like precedence */
568 569
 %right EQUAL
... ...
@@ -1969,8 +1970,10 @@ event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
1969 1969
 preprocess_stm:
1970 1970
 	SUBST STRING { if(pp_subst_add($2)<0) YYERROR; }
1971 1971
 	| SUBST error { yyerror("invalid subst preprocess statement"); }
1972
-	| SUBSTDEF STRING { if(pp_substdef_add($2)<0) YYERROR; }
1972
+	| SUBSTDEF STRING { if(pp_substdef_add($2, 0)<0) YYERROR; }
1973 1973
 	| SUBSTDEF error { yyerror("invalid substdef preprocess statement"); }
1974
+	| SUBSTDEFS STRING { if(pp_substdef_add($2, 1)<0) YYERROR; }
1975
+	| SUBSTDEFS error { yyerror("invalid substdefs preprocess statement"); }
1974 1976
 	;
1975 1977
 
1976 1978
 /*exp:	rval_expr
... ...
@@ -81,7 +81,7 @@ int pp_subst_add(char *data)
81 81
 	return 0;
82 82
 }
83 83
 
84
-int pp_substdef_add(char *data)
84
+int pp_substdef_add(char *data, int mode)
85 85
 {
86 86
 	char c;
87 87
 	char *p;
... ...
@@ -131,17 +131,31 @@ found_regexp:
131 131
 found_repl:
132 132
 	defvalue.len = p - defvalue.s;
133 133
 
134
+	pp_define_set_type(0);
134 135
 	if(pp_define(defname.len, defname.s)<0) {
135 136
 		LM_ERR("cannot set define name\n");
136 137
 		goto error;
137 138
 	}
139
+	if(mode==1) {
140
+		/* define the value enclosed in double quotes */
141
+		*(defvalue.s-1) = '"';
142
+		defvalue.s[defvalue.len] = '"';
143
+		defvalue.s--;
144
+		defvalue.len += 2;
145
+	}
138 146
 	if(pp_define_set(defvalue.len, defvalue.s)<0) {
139 147
 		LM_ERR("cannot set define value\n");
140 148
 		goto error;
141 149
 	}
150
+	if(mode==1) {
151
+		defvalue.s++;
152
+		defvalue.len -= 2;
153
+		*(defvalue.s-1) = c;
154
+		defvalue.s[defvalue.len] = c;
155
+	}
142 156
 
143
-	LM_DBG("### added substdef: [%.*s]=[%.*s]\n", defname.len, defname.s,
144
-			defvalue.len, defvalue.s);
157
+	LM_DBG("### added substdef: [%.*s]=[%.*s] (%d)\n", defname.len, defname.s,
158
+			defvalue.len, defvalue.s, mode);
145 159
 
146 160
 	return 0;
147 161
 
... ...
@@ -23,7 +23,7 @@
23 23
 #define _PPCFG_H_
24 24
 
25 25
 int pp_subst_add(char *data);
26
-int pp_substdef_add(char *data);
26
+int pp_substdef_add(char *data, int mode);
27 27
 int pp_subst_run(char **data);
28 28
 
29 29
 int  pp_define(int len, const char *text);