[asterisk-commits] russell: trunk r84172 - /trunk/main/say.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 1 10:17:15 CDT 2007


Author: russell
Date: Mon Oct  1 10:17:15 2007
New Revision: 84172

URL: http://svn.digium.com/view/asterisk?view=rev&rev=84172
Log:
Simplify code by using the -= and %= operators.

(closes issue #10848)
Reported by: opticron
Patches: 
      saymod.diff uploaded by opticron (license 267)

Modified:
    trunk/main/say.c

Modified: trunk/main/say.c
URL: http://svn.digium.com/view/asterisk/trunk/main/say.c?view=diff&rev=84172&r1=84171&r2=84172
==============================================================================
--- trunk/main/say.c (original)
+++ trunk/main/say.c Mon Oct  1 10:17:15 2007
@@ -500,25 +500,25 @@
 			num = 0;
 		} else	if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-			num -= ((num / 10) * 10);
+			num %= 10;
 		} else {
 			if (num < 1000){
 				snprintf(fn, sizeof(fn), "digits/%d", (num/100));
 				playh++;
-				num -= ((num / 100) * 100);
+				num %= 100;
 			} else {
 				if (num < 1000000) { /* 1,000,000 */
 					res = ast_say_number_full_en(chan, num / 1000, ints, language, audiofd, ctrlfd);
 					if (res)
 						return res;
-					num = num % 1000;
+					num %= 1000;
 					snprintf(fn, sizeof(fn), "digits/thousand");
 				} else {
 					if (num < 1000000000) {	/* 1,000,000,000 */
 						res = ast_say_number_full_en(chan, num / 1000000, ints, language, audiofd, ctrlfd);
 						if (res)
 							return res;
-						num = num % 1000000;
+						num %= 1000000;
 						snprintf(fn, sizeof(fn), "digits/million");
 					} else {
 						ast_debug(1, "Number '%d' is too big for me\n", num);
@@ -604,7 +604,7 @@
 			num = 0;
 		} else if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-			num -= ((num / 10) * 10);
+			num %= 10;
 		} else if (num < 1000) {
 			hundered = num / 100;
 			if ( hundered == 1 ) {
@@ -943,7 +943,7 @@
 			num = 0;
 		} else if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-			num -= ((num / 10) * 10);
+			num %= 10;
 		} else if (num < 1000) {
 			int hundreds = num / 100;
 			snprintf(fn, sizeof(fn), "digits/%d", (num / 100));
@@ -957,7 +957,7 @@
 			if (res)
 				return res;
 			snprintf(fn, sizeof(fn), "digits/thousand");
-			num = num % 1000;
+			num %= 1000;
 			if (num && num < 100)
 				playa++;
 		} else 	if (num < 1000000000) {
@@ -966,7 +966,7 @@
 				if (res)
 					return res;
 				snprintf(fn, sizeof(fn), "digits/million");
-				num = num % 1000000;
+				num %= 1000000;
 				if (num && num < 100)
 					playa++;
 		} else {
@@ -1033,7 +1033,7 @@
 			num = 0;
 		} else if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num/10)*10);
-			num -= ((num/10)*10);
+			num %= 10;
 			if (num)
 				playa++;
 		} else if (num == 100) {
@@ -1045,16 +1045,16 @@
 		} else {
 			if (num < 1000) {
 				snprintf(fn, sizeof(fn), "digits/%d", (num/100)*100);
-				num -= ((num/100)*100);
+				num %= 100;
 			} else if (num < 2000) {
-				num = num % 1000;
+				num %= 1000;
 				snprintf(fn, sizeof(fn), "digits/thousand");
 			} else {
 				if (num < 1000000) {
 					res = ast_say_number_full_es(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
 					if (res)
 						return res;
-					num = num % 1000;
+					num %= 1000;
 					snprintf(fn, sizeof(fn), "digits/thousand");
 				} else {
 					if (num < 2147483640) {
@@ -1069,7 +1069,7 @@
 								return res;
 							snprintf(fn, sizeof(fn), "digits/millions");
 						}
-						num = num % 1000000;
+						num %= 1000000;
 					} else {
 						ast_debug(1, "Number '%d' is too big for me\n", num);
 						res = -1;
@@ -1367,31 +1367,31 @@
 			num = 0;
 		} else if (num < 20) {
 			snprintf(fn, sizeof(fn), "digits/10en");
-			num = (num - 10);
+			num -= 10;
 		} else if (num < 30) {
 			snprintf(fn, sizeof(fn), "digits/20on");
-			num = (num - 20);
+			num -= 20;
 		} else	if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-			num -= ((num / 10) * 10);
+			num %= 10;
 		} else {
 			if (num < 1000){
 				snprintf(fn, sizeof(fn), "digits/%d", (num/100));
 				playh++;
-				num -= ((num / 100) * 100);
+				num %= 100;
 			} else {
 				if (num < 1000000) { /* 1,000,000 */
 					res = ast_say_number_full_hu(chan, num / 1000, ints, language, audiofd, ctrlfd);
 					if (res)
 						return res;
-					num = num % 1000;
+					num %= 1000;
 					snprintf(fn, sizeof(fn), "digits/thousand");
 				} else {
 					if (num < 1000000000) {	/* 1,000,000,000 */
 						res = ast_say_number_full_hu(chan, num / 1000000, ints, language, audiofd, ctrlfd);
 						if (res)
 							return res;
-						num = num % 1000000;
+						num %= 1000000;
 						snprintf(fn, sizeof(fn), "digits/million");
 					} else {
 						ast_debug(1, "Number '%d' is too big for me\n", num);
@@ -1512,7 +1512,7 @@
 				num = 0;
 			} else if (num < 100) {
 				snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-				num -= ((num / 10) * 10);
+				num %= 10;
 			} else {
 				if (num < 1000) {
 					if ((num / 100) > 1) {
@@ -1521,7 +1521,7 @@
 					} else {
 						snprintf(fn, sizeof(fn), "digits/hundred");
 					}
-					num -= ((num / 100) * 100);
+					num %= 100;
 				} else {
 					if (num < 1000000) { /* 1,000,000 */
 						if ((num/1000) > 1)
@@ -1529,7 +1529,7 @@
 						if (res)
 							return res;
 						tempnum = num;
-						num = num % 1000;
+						num %= 1000;
 						if ((tempnum / 1000) < 2)
 							snprintf(fn, sizeof(fn), "digits/thousand");
 						else /* for 1000 it says mille, for >1000 (eg 2000) says mila */
@@ -1541,7 +1541,7 @@
 							if (res)
 								return res;
 							tempnum = num;
-							num = num % 1000000;
+							num %= 1000000;
 							if ((tempnum / 1000000) < 2)
 								snprintf(fn, sizeof(fn), "digits/million");
 							else
@@ -1606,35 +1606,35 @@
 		} else if (num < 200) {
 			/* hundred, not one-hundred */
 			ast_copy_string(fn, "digits/hundred", sizeof(fn));
-			num -= ((num / 100) * 100);
+			num %= 100;
 		} else if (num < 1000) {
 			snprintf(fn, sizeof(fn), "digits/%d", num / 100);
 			playh++;
-			num -= ((num / 100) * 100);
+			num %= 100;
 		} else {
 			if (num < 1100) {
 				/* thousand, not one-thousand */
-				num = num % 1000;
+				num %= 1000;
 				ast_copy_string(fn, "digits/thousand", sizeof(fn));
 			} else if (num < 10000)	{ /* 1,100 to 9,9999 */
 				res = ast_say_number_full_nl(chan, num / 100, ints, language, audiofd, ctrlfd);
 				if (res)
 					return res;
-				num = num % 100;
+				num %= 100;
 				ast_copy_string(fn, "digits/hundred", sizeof(fn));
 			} else {
 				if (num < 1000000) { /* 1,000,000 */
 					res = ast_say_number_full_nl(chan, num / 1000, ints, language, audiofd, ctrlfd);
 					if (res)
 						return res;
-					num = num % 1000;
+					num %= 1000;
 					snprintf(fn, sizeof(fn), "digits/thousand");
 				} else {
 					if (num < 1000000000) { /* 1,000,000,000 */
 						res = ast_say_number_full_nl(chan, num / 1000000, ints, language, audiofd, ctrlfd);
 						if (res)
 							return res;
-						num = num % 1000000;
+						num %= 1000000;
 						snprintf(fn, sizeof(fn), "digits/million");
 					} else {
 						ast_debug(1, "Number '%d' is too big for me\n", num);
@@ -1702,7 +1702,7 @@
 			num = 0;
 		} else if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-			num -= ((num / 10) * 10);
+			num %= 10;
 		} else if (num < 1000) {
 			int hundreds = num / 100;
 			if (hundreds == 1)
@@ -1719,7 +1719,7 @@
 			if (res)
 				return res;
 			snprintf(fn, sizeof(fn), "digits/thousand");
-			num = num % 1000;
+			num %= 1000;
 			if (num && num < 100)
 				playa++;
 		} else 	if (num < 1000000000) {
@@ -1728,7 +1728,7 @@
 				if (res)
 					return res;
 				snprintf(fn, sizeof(fn), "digits/million");
-				num = num % 1000000;
+				num %= 1000000;
 				if (num && num < 100)
 					playa++;
 		} else {
@@ -2170,7 +2170,7 @@
 			num = 0;
 		} else if (num < 100) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-			num -= ((num / 10) * 10);
+			num %= 10;
 		} else if (num == 1 && cn == -1) {	/* En eller ett? */
 		 	snprintf(fn, sizeof(fn), "digits/1N");
 			num = 0;
@@ -2178,14 +2178,14 @@
 			if (num < 1000){
 				snprintf(fn, sizeof(fn), "digits/%d", (num/100));
 				playh++;
-				num -= ((num / 100) * 100);
+				num %= 100;
 			} else {
 				if (num < 1000000) { /* 1,000,000 */
 					res = ast_say_number_full_se(chan, num / 1000, ints, language, options, audiofd, ctrlfd);
 					if (res) {
 						return res;
 					}
-					num = num % 1000;
+					num %= 1000;
 					snprintf(fn, sizeof(fn), "digits/thousand");
 				} else {
 					if (num < 1000000000) {	/* 1,000,000,000 */
@@ -2193,7 +2193,7 @@
 						if (res) {
 							return res;
 						}
-						num = num % 1000000;
+						num %= 1000000;
 						snprintf(fn, sizeof(fn), "digits/million");
 					} else {
 						ast_debug(1, "Number '%d' is too big for me\n", num);
@@ -2240,25 +2240,25 @@
 				num = 0;
 			} else	if (num < 100) {
 				snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-				num -= ((num / 10) * 10);
+				num %= 10;
 			} else {
 				if (num < 1000){
 					snprintf(fn, sizeof(fn), "digits/%d", (num/100));
 					playh++;
-					num -= ((num / 100) * 100);
+					num %= 100;
 				} else {
 					if (num < 1000000) { /* 1,000,000 */
 						res = ast_say_number_full_tw(chan, num / 1000, ints, language, audiofd, ctrlfd);
 						if (res)
 							return res;
-						num = num % 1000;
+						num %= 1000;
 						snprintf(fn, sizeof(fn), "digits/thousand");
 					} else {
 						if (num < 1000000000) {	/* 1,000,000,000 */
 							res = ast_say_number_full_tw(chan, num / 1000000, ints, language, audiofd, ctrlfd);
 							if (res)
 								return res;
-							num = num % 1000000;
+							num %= 1000000;
 							snprintf(fn, sizeof(fn), "digits/million");
 						} else {
 							ast_debug(1, "Number '%d' is too big for me\n", num);
@@ -2411,35 +2411,35 @@
 				num = 0;
 			} else {
 				snprintf(fn, sizeof(fn), "digits/%d", (num / 10) * 10);
-				num -= ((num / 10) * 10);
+				num %= 10;
 			}
 		} else if (num < 1000) {
 			snprintf(fn, sizeof(fn), "digits/%d", (num/100));
 			playh++;
-			num -= ((num / 100) * 100);
+			num %= 100;
 		} else if (num < 10000) { /* 10,000 */
 			res = ast_say_number_full_th(chan, num / 1000, ints, language, audiofd, ctrlfd);
 			if (res)
 				return res;
-			num = num % 1000;
+			num %= 1000;
 			snprintf(fn, sizeof(fn), "digits/pan");
 		} else if (num < 100000) { /* 100,000 */
 			res = ast_say_number_full_th(chan, num / 10000, ints, language, audiofd, ctrlfd);
 			if (res)
 				return res;
-			num = num % 10000;
+			num %= 10000;
 			snprintf(fn, sizeof(fn), "digits/muan");
 		} else if (num < 1000000) { /* 1,000,000 */
 			res = ast_say_number_full_th(chan, num / 100000, ints, language, audiofd, ctrlfd);
 			if (res)
 				return res;
-			num = num % 100000;
+			num %= 100000;
 			snprintf(fn, sizeof(fn), "digits/san");
 		} else {
 			res = ast_say_number_full_th(chan, num / 1000000, ints, language, audiofd, ctrlfd);
 			if (res)
 				return res;
-			num = num % 1000000;
+			num %= 1000000;
 			snprintf(fn, sizeof(fn), "digits/larn");
 		}
 		if (!res) {
@@ -6727,18 +6727,18 @@
 		} else if (num <= 100) {
 			/* 13 < num <= 100  */
 			snprintf(fn, sizeof(fn), "digits/%d", (num /10) * 10);
-			num -= ((num / 10) * 10); 
+			num %= 10; 
 		} else if (num < 200) {
 			/* 100 < num < 200 */
 			snprintf(fn, sizeof(fn), "digits/hundred-100");
-			num -= ((num / 100) * 100);
+			num %= 100;
 		}else if (num < 1000) {
 			/* 200 < num < 1000 */
 			snprintf(fn, sizeof(fn), "digits/hundred-%d", (num/100)*100);
-			num -= ((num / 100) * 100);
+			num %= 100;
 		}else if (num < 2000){
 			snprintf(fn, sizeof(fn), "digits/xilia");
-			num -= ((num / 1000) * 1000);
+			num %= 1000;
 		}
 		else {
 			/* num >  1000 */ 
@@ -6746,14 +6746,14 @@
 				res = ast_say_number_full_gr(chan, (num / 1000), ints, chan->language, audiofd, ctrlfd);
 				if (res)
 					return res;
-				num = num % 1000;
+				num %= 1000;
 				snprintf(fn, sizeof(fn), "digits/thousands");
 			}  else {
 				if (num < 1000000000) { /* 1,000,000,000 */
 					res = ast_say_number_full_gr(chan, (num / 1000000), ints, chan->language ,audiofd, ctrlfd);
 					if (res)
 						return res;
-					num = num % 1000000;
+					num %= 1000000;
 					snprintf(fn, sizeof(fn), "digits/millions");
 				} else {
 					ast_debug(1, "Number '%d' is too big for me\n", num);




More information about the asterisk-commits mailing list