Changeset 5713
When converting an arg to a number remember it may have an exponent
Comitted by:
mjagdis
Date:
Jun 04 2010 * 23:11 (about 1 year ago)
Affected files:
callweaver/trunk/funcs/func_core.c (unified diff)
| r5680 | r5713 | |
|---|---|---|
| 21 | 21 | * \brief Core functions |
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | #include <ctype.h> | |
| 25 | #include <errno.h> | |
| 26 | #include <fenv.h> | |
| 27 | #include <math.h> | |
| 24 | 28 | #include <stdio.h> |
| 25 | 29 | #include <stdlib.h> |
| 30 | #include <string.h> | |
| 26 | 31 | #include <unistd.h> |
| 27 | #include <string.h> | |
| 28 | #include <ctype.h> | |
| 29 | #include <errno.h> | |
| 30 | 32 | |
| 31 | 33 | #include "callweaver.h" |
| 32 | 34 | |
| --- | --- | |
| 67 | 69 | }); |
| 68 | 70 | |
| 69 | 71 | |
| 72 | static int argtol(const char *arg, long double scale) | |
| 73 | { | |
| 74 | long double secs; | |
| 75 | char *end; | |
| 76 | int res = 0; | |
| 77 | ||
| 78 | secs = strtold(arg, &end); | |
| 79 | if (!*end && !isnan(secs)) { | |
| 80 | res = INT_MAX; | |
| 81 | ||
| 82 | if (!isinf(secs)) { | |
| 83 | feclearexcept(FE_ALL_EXCEPT); | |
| 84 | errno = 0; | |
| 85 | res = lroundl(secs * scale); | |
| 86 | if (errno || fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_UNDERFLOW)) | |
| 87 | res = 0; | |
| 88 | else if (fetestexcept(FE_OVERFLOW)) | |
| 89 | res = INT_MAX; | |
| 90 | } | |
| 91 | } | |
| 92 | ||
| 93 | return res; | |
| 94 | } | |
| 95 | ||
| 96 | ||
| 70 | 97 | static void wait_for_hangup(struct cw_channel *chan, char *s) |
| 71 | 98 | { |
| 72 | 99 | struct cw_frame *f; |
| 73 | 100 | int waittime; |
| 74 | 101 | |
| 75 | if (!s || !strlen(s) || (sscanf(s, "%d", &waittime) != 1) || (waittime < 0)) | |
| 76 | waittime = -1; | |
| 77 | if (waittime > -1) | |
| 78 | cw_safe_sleep(chan, waittime * 1000); | |
| 102 | if (s && s[0] && (waittime = argtol(s, 1000)) >= 0) | |
| 103 | cw_safe_sleep(chan, waittime); | |
| 79 | 104 | else { |
| 80 | 105 | while (cw_waitfor(chan, -1) >= 0 && (f = cw_read(chan))) |
| 81 | 106 | cw_fr_free(f); |
| --- | --- | |
| 302 | 327 | |
| 303 | 328 | static int pbx_builtin_answer(struct cw_channel *chan, int argc, char **argv, struct cw_dynstr *result) |
| 304 | 329 | { |
| 305 | int delay = (argc > 0 ? atoi(argv[0]) : 0); | |
| 330 | int delay = (argc > 0 && argv[0][0] ? argtol(argv[0], 1) : 0); | |
| 306 | 331 | int res; |
| 307 | ||
| 332 | ||
| 308 | 333 | CW_UNUSED(result); |
| 309 | 334 | |
| 310 | 335 | if (chan->_state == CW_STATE_UP) |
| --- | --- | |
| 482 | 507 | |
| 483 | 508 | static int pbx_builtin_wait(struct cw_channel *chan, int argc, char **argv, struct cw_dynstr *result) |
| 484 | 509 | { |
| 485 | double ms; | |
| 510 | int res = 0; | |
| 486 | 511 | |
| 487 | CW_UNUSED(result); | |
| 512 | CW_UNUSED(result); | |
| 488 | 513 | |
| 489 | /* Wait for "n" seconds */ | |
| 490 | if (argc > 0 && (ms = atof(argv[0]))) | |
| 491 | return cw_safe_sleep(chan, (int)(ms * 1000.0)); | |
| 492 | return 0; | |
| 514 | /* Wait for "n" seconds */ | |
| 515 | if (argc > 0 && argv[0][0]) | |
| 516 | res = cw_safe_sleep(chan, argtol(argv[0], 1000)); | |
| 517 | ||
| 518 | return 0; | |
| 493 | 519 | } |
| 494 | 520 | |
| 495 | 521 | static int pbx_builtin_waitexten(struct cw_channel *chan, int argc, char **argv, struct cw_dynstr *result) |
![Home changeset 5713 [home]](/images/logo.png?1180520111)

RSS Feeds