Browse code

script parsing: if (non-int) not any longer an error

An if expression that does not evaluate to int is not any longer
considered a parse error. It will generate a warning, but sr will
start.
This allows backward compatible if (@select) or if($avp).

Andrei Pelinescu-Onciul authored on 05/05/2009 17:19:54
Showing 2 changed files
... ...
@@ -1858,13 +1858,13 @@ action:
1858 1858
 	;
1859 1859
 if_cmd:
1860 1860
 	IF rval_expr stm	{
1861
-		if (rval_expr_int_check($2)==0){
1861
+		if (rval_expr_int_check($2)>=0){
1862 1862
 			warn_ct_rve($2, "if");
1863 1863
 		}
1864 1864
 		$$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0);
1865 1865
 	}
1866 1866
 	| IF rval_expr stm ELSE stm	{ 
1867
-		if (rval_expr_int_check($2)==0){
1867
+		if (rval_expr_int_check($2)>=0){
1868 1868
 			warn_ct_rve($2, "if");
1869 1869
 		}
1870 1870
 		$$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5); 
... ...
@@ -2806,7 +2806,8 @@ static void warn_at(struct cfg_pos* p, char* format, ...)
2806 2806
 	vsnprintf(s, sizeof(s), format, ap);
2807 2807
 	va_end(ap);
2808 2808
 	if (p->e_line!=p->s_line)
2809
-		LOG(L_WARN, "warning in config file, from line %d, column %d to line %d, column %d: %s\n",
2809
+		LOG(L_WARN, "warning in config file, from line %d, column %d to"
2810
+					" line %d, column %d: %s\n",
2810 2811
 					p->s_line, p->s_col, p->e_line, p->e_col, s);
2811 2812
 	else if (p->s_col!=p->e_col)
2812 2813
 		LOG(L_WARN, "warning in config file, line %d, column %d-%d: %s\n",
... ...
@@ -2828,7 +2829,8 @@ static void yyerror_at(struct cfg_pos* p, char* format, ...)
2828 2828
 	vsnprintf(s, sizeof(s), format, ap);
2829 2829
 	va_end(ap);
2830 2830
 	if (p->e_line!=p->s_line)
2831
-		LOG(L_CRIT, "parse error in config file, from line %d, column %d to line %d, column %d: %s\n",
2831
+		LOG(L_CRIT, "parse error in config file, from line %d, column %d"
2832
+					" to line %d, column %d: %s\n",
2832 2833
 					p->s_line, p->s_col, p->e_line, p->e_col, s);
2833 2834
 	else if (p->s_col!=p->e_col)
2834 2835
 		LOG(L_CRIT, "parse error in config file, line %d, column %d-%d: %s\n",
... ...
@@ -2948,7 +2950,7 @@ static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
2948 2948
 /** check if the expression is an int.
2949 2949
  * if the expression does not evaluate to an int return -1 and
2950 2950
  * log an error.
2951
- * @return 0 on success, -1 on error */
2951
+ * @return 0 success, no warnings; 1 success but warnings; -1 on error */
2952 2952
 static int rval_expr_int_check(struct rval_expr *rve)
2953 2953
 {
2954 2954
 	struct rval_expr* bad_rve;
... ...
@@ -2967,8 +2969,9 @@ static int rval_expr_int_check(struct rval_expr *rve)
2967 2967
 			yyerror("BUG: unexpected null \"bad\" expression\n");
2968 2968
 		return -1;
2969 2969
 	}else if (type!=RV_INT && type!=RV_NONE){
2970
-		yyerror_at(&rve->fpos, "invalid expression type, int expected\n");
2971
-		return -1;
2970
+		warn_at(&rve->fpos, "non-int expression (you might want to use"
2971
+				" casts)\n");
2972
+		return 1;
2972 2973
 	}
2973 2974
 	return 0;
2974 2975
 }
... ...
@@ -712,12 +712,16 @@ int fix_actions(struct action* a)
712 712
 									rve->fpos.s_line, rve->fpos.s_col);
713 713
 						return E_UNSPEC;
714 714
 					}
715
+					/* it's not an error anymore to have non-int in an if,
716
+					   only a script warning (to allow backward compat. stuff
717
+					   like if (@ruri) 
715 718
 					if (rve_type!=RV_INT && rve_type!=RV_NONE){
716 719
 						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
717 720
 								" bad type, integer expected\n",
718 721
 								rve->fpos.s_line, rve->fpos.s_col);
719 722
 						return E_UNSPEC;
720 723
 					}
724
+					*/
721 725
 					if ((ret=fix_rval_expr((void**)&rve))<0)
722 726
 						return ret;
723 727
 				}