From 7752eac905db0de271c9fb14c2d67b5641418d60 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 5 Jan 2007 17:09:29 +0000 Subject: [PATCH] simplify en_say_money to not have to use math fuctions, as we have it in char already and need to keep it that way for later. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3913 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/say/mod_say_en/mod_say_en.c | 37 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/mod/say/mod_say_en/mod_say_en.c b/src/mod/say/mod_say_en/mod_say_en.c index 950dd3e65e..49215fedb4 100644 --- a/src/mod/say/mod_say_en/mod_say_en.c +++ b/src/mod/say/mod_say_en/mod_say_en.c @@ -402,45 +402,46 @@ static switch_status_t en_say_money(switch_core_session_t *session, { switch_channel_t *channel; - char sbuf[16] = ""; // enuf for 999,999,999,999.99 (w/o the commas) - - double amt, dollars, cents; + char sbuf[16] = ""; /* enuough for 999,999,999,999.99 (w/o the commas or leading $) */ + char *dollars = NULL; + char *cents = NULL; assert(session != NULL); channel = switch_core_session_get_channel(session); assert(channel != NULL); - if (!(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 15) { + if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } - amt = atof(tosay); //convert to double - cents = modf(fabs(amt), &dollars); // split dollars and cents + dollars = sbuf; + + if ((cents = strchr(sbuf, '.'))) { + *cents++ = '\0'; + } - // If negative say "negative" (or "minus") - if (amt < 0.0) { + /* If negative say "negative" */ + if (sbuf[0] == '-') { say_file("negative.wav"); - // say_file("minus.wav"); + dollars++; } - // Say dollar amount - snprintf(sbuf, sizeof(sbuf), "%.0f", dollars); - en_say_general_count(session, sbuf, type, method, args); - if (dollars == 1.0) { + /* Say dollar amount */ + en_say_general_count(session, dollars, type, method, args); + if (atoi(dollars) == 1) { say_file("dollar.wav"); } else { say_file("dollars.wav"); } - // Say "and" + /* Say "and" */ say_file("and.wav"); - // Say cents - snprintf(sbuf, sizeof(sbuf), "%.0f", cents); - en_say_general_count(session, sbuf, type, method, args); - if (cents == 1.0) { + /* Say cents */ + en_say_general_count(session, cents, type, method, args); + if (atoi(cents) == 1) { say_file("cent.wav"); } else {