Browse code

Use parse_repl from within subst_parser function.

The code now in parse_repl function was originally hardwired into the
subst_parser function, we moved the code into a separate function and
now just call the function from subst_parser.

Jan Janak authored on 08/03/2009 03:20:23
Showing 1 changed files
... ...
@@ -211,7 +211,6 @@ struct subst_expr* subst_parser(str* subst)
211 211
 	char* repl_end;
212 212
 	struct replace_with rw[MAX_REPLACE_WITH];
213 213
 	int rw_no;
214
-	int escape;
215 214
 	int cflags; /* regcomp flags */
216 215
 	int replace_all;
217 216
 	struct subst_expr* se;
... ...
@@ -250,91 +249,16 @@ struct subst_expr* subst_parser(str* subst)
250 249
 	goto error;
251 250
 found_re:
252 251
 	re_end=p;
253
-	p++;
254
-	/* parse replacement */
255
-	repl=p;
256
-	rw_no=0;
257
-	max_pmatch=0;
258
-	escape=0;
259
-	for(;p<end; p++){
260
-		if (escape){
261
-			escape=0;
262
-			switch (*p){
263
-				/* special char escapes */
264
-				case '\\':
265
-					rw[rw_no].size=2;
266
-					rw[rw_no].offset=(p-1)-repl;
267
-					rw[rw_no].type=REPLACE_CHAR;
268
-					rw[rw_no].u.c='\\';
269
-					break;
270
-				case 'n':
271
-					rw[rw_no].size=2;
272
-					rw[rw_no].offset=(p-1)-repl;
273
-					rw[rw_no].type=REPLACE_CHAR;
274
-					rw[rw_no].u.c='\n';
275
-					break;
276
-				case 'r':
277
-					rw[rw_no].size=2;
278
-					rw[rw_no].offset=(p-1)-repl;
279
-					rw[rw_no].type=REPLACE_CHAR;
280
-					rw[rw_no].u.c='\r';
281
-					break;
282
-				case 't':
283
-					rw[rw_no].size=2;
284
-					rw[rw_no].offset=(p-1)-repl;
285
-					rw[rw_no].type=REPLACE_CHAR;
286
-					rw[rw_no].u.c='\t';
287
-					break;
288
-				/* special sip msg parts escapes */
289
-				case 'u':
290
-					rw[rw_no].size=2;
291
-					rw[rw_no].offset=(p-1)-repl;
292
-					rw[rw_no].type=REPLACE_URI;
293
-					break;
294
-				/* re matches */
295
-				case '0': /* allow 0, too, reference to the whole match */
296
-				case '1':
297
-				case '2':
298
-				case '3':
299
-				case '4':
300
-				case '5':
301
-				case '6':
302
-				case '7':
303
-				case '8':
304
-				case '9':
305
-					rw[rw_no].size=2;
306
-					rw[rw_no].offset=(p-1)-repl;
307
-					rw[rw_no].type=REPLACE_NMATCH;
308
-					rw[rw_no].u.nmatch=(*p)-'0';/* 0 is the whole matched str*/
309
-					if (max_pmatch<rw[rw_no].u.nmatch) 
310
-						max_pmatch=rw[rw_no].u.nmatch;
311
-					break;
312
-				default: /* just print current char */
313
-					if (*p!=c){
314
-						LOG(L_WARN, "subst_parser: WARNING: \\%c unknown"
315
-								" escape in %.*s\n", *p, subst->len, subst->s);
316
-					}
317
-					rw[rw_no].size=2;
318
-					rw[rw_no].offset=(p-1)-repl;
319
-					rw[rw_no].type=REPLACE_CHAR;
320
-					rw[rw_no].u.c=*p;
321
-					break;
322
-			}
323
-			rw_no++;
324
-			if (rw_no>=MAX_REPLACE_WITH){
325
-				LOG(L_ERR, "ERROR: subst_parser: too many escapes in the"
326
-							" replace part %.*s\n", subst->len, subst->s);
327
-				goto error;
328
-			}
329
-		}else if (*p=='\\') escape=1;
330
-		else  if (*p==c) goto found_repl;
252
+	if (end < (p + 2)) {
253
+		ERR("subst_parser: String too short\n");
254
+		goto error;
331 255
 	}
332
-	LOG(L_ERR, "ERROR: subst_parser: missing separator: %.*s\n", subst->len, 
333
-			subst->s);
334
-	goto error;
335
-found_repl:
336
-	repl_end=p;
256
+	repl=p+1;
257
+	if ((rw_no = parse_repl(rw, &p, end, &max_pmatch, WITH_SEP)) < 0)
258
+		goto error;
259
+	repl_end = p;
337 260
 	p++;
261
+	
338 262
 	/* parse flags */
339 263
 	for(;p<end; p++){
340 264
 		switch(*p){