示例#1
0
文件: mod_say_zh.c 项目: gujun/sscore
static switch_status_t zh_say_money(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	char sbuf[16] = "";			/* enough for 999,999,999,999.99 (w/o the commas or leading $) */
	char *dollars = NULL;
	char *cents = NULL;

	if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	dollars = sbuf;

	if ((cents = strchr(sbuf, '.'))) {
		*cents++ = '\0';
		if (strlen(cents) > 2) {
			cents[2] = '\0';
		}
	}

	/* If positive sign - skip over" */
	if (sbuf[0] == '+') {
		dollars++;
	}

	/* If negative say "negative" */
	if (sbuf[0] == '-') {
		say_file("currency/negative.wav");
		dollars++;
	}

	/* Say dollar amount */
	zh_say_general_count(session, dollars, say_args, args);
	say_file("currency/dollar.wav");

	/* Say cents */
	if (cents) {
		zh_say_general_count(session, cents, say_args, args);
	} else {
		say_file("digits/0.wav");
	}
	say_file("currency/cent.wav");

	return SWITCH_STATUS_SUCCESS;
}
示例#2
0
static switch_status_t zh_CN_say_money(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args)
{
	char sbuf[16] = "";			/* enough for 999,999,999,999.99 (w/o the commas or leading $) */
	char dbuf[16] = "";			/* enough for digits/x.wav */
	char *yuan = NULL;
	char *rest = NULL;
	int i;

	if (strlen(tosay) > 15 || !switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)-1)) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
		return SWITCH_STATUS_GENERR;
	}

	yuan = sbuf;

	if ((rest = strchr(sbuf, '.'))) {
		*rest++ = '\0';
	}

	/* If positive sign - skip over" */
	if (sbuf[0] == '+') {
		yuan++;
	}

	/* If negative say "negative" */
	if (sbuf[0] == '-') {
		say_file("currency/negative.wav");
		yuan++;
	}

	/* Say dollar amount */
	zh_say_general_count(session, yuan, say_args, args);
	say_file("currency/yuan.wav");

	if (!rest) return SWITCH_STATUS_SUCCESS;

	/* Say cents */
	for (i=0; *rest; i++, rest++) {
	sprintf(dbuf, "digits/%c.wav", *rest);
		say_file(dbuf);
		if (i == 0) {
			say_file("currency/jiao.wav");
		} else if (i == 1) {
			say_file("currency/fen.wav");
		} else if (i == 2) {
			say_file("currency/li.wav");
		}  /* else just say the rest of digits */
	}

	return SWITCH_STATUS_SUCCESS;
}