mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-21 12:30:41 +00:00
Merged revisions 72933 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r72933 | murf | 2007-07-02 14:16:31 -0600 (Mon, 02 Jul 2007) | 1 line support for floating point numbers added to ast_expr2 $\[...\] exprs. Fixes bug 9508, where the expr code fails with fp numbers. The MATH function returns fp numbers by default, so this fix is considered necessary. ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@72940 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -24,12 +24,29 @@
|
||||
|
||||
#include "asterisk.h"
|
||||
|
||||
#ifndef STANDALONE
|
||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef STANDALONE
|
||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#else
|
||||
#ifndef __USE_ISOC99
|
||||
#define __USE_ISOC99 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __USE_ISOC99
|
||||
#define FP___PRINTF "%.16Lg"
|
||||
#define FP___FMOD fmodl
|
||||
#define FP___STRTOD strtold
|
||||
#define FP___TYPE long double
|
||||
#else
|
||||
#define FP___PRINTF "%.8g"
|
||||
#define FP___FMOD fmod
|
||||
#define FP___STRTOD strtod
|
||||
#define FP___TYPE double
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
@@ -48,14 +65,14 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#include "asterisk/strings.h"
|
||||
|
||||
enum valtype {
|
||||
AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
|
||||
AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
|
||||
} ;
|
||||
|
||||
struct val {
|
||||
enum valtype type;
|
||||
union {
|
||||
char *s;
|
||||
quad_t i;
|
||||
FP___TYPE i; /* long double or just double if it's a bad day */
|
||||
} u;
|
||||
} ;
|
||||
|
||||
@@ -140,7 +157,7 @@ static char *expr2_token_subst(char *mess);
|
||||
\"[^"]*\" {SET_COLUMNS; SET_STRING; return TOKEN;}
|
||||
|
||||
[\n] {/* what to do with eol */}
|
||||
[0-9]+ {
|
||||
[0-9]+(\.[0-9]+)? {
|
||||
SET_COLUMNS;
|
||||
/* the original behavior of the expression parser was
|
||||
* to bring in numbers as a numeric string
|
||||
@@ -235,10 +252,10 @@ int ast_expr(char *expr, char *buf, int length)
|
||||
return_value = 1;
|
||||
}
|
||||
} else {
|
||||
if (io.val->type == AST_EXPR_integer) {
|
||||
if (io.val->type == AST_EXPR_number) {
|
||||
int res_length;
|
||||
|
||||
res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i);
|
||||
res_length = snprintf(buf, length, FP___PRINTF, io.val->u.i);
|
||||
return_value = (res_length <= length) ? res_length : length;
|
||||
} else {
|
||||
#if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE_AEL)
|
||||
|
Reference in New Issue
Block a user