65 static int acf_sprintf(
struct ast_channel *chan,
const char *cmd,
char *data,
char *buf,
size_t len)
67 #define SPRINTF_FLAG 0
68 #define SPRINTF_WIDTH 1
69 #define SPRINTF_PRECISION 2
70 #define SPRINTF_LENGTH 3
71 #define SPRINTF_CONVERSION 4
72 int i,
state = -1, argcount = 0;
73 char *formatstart = NULL, *bufptr = buf;
74 char formatbuf[256] =
"";
85 for (i = 0; arg.format[i]; i++) {
88 if (strchr(
"#0- +'I", arg.format[i]))
90 state = SPRINTF_WIDTH;
92 if (arg.format[i] >=
'0' && arg.format[i] <=
'9')
96 if (arg.format[i] ==
'.') {
97 state = SPRINTF_PRECISION;
99 state = SPRINTF_LENGTH;
103 case SPRINTF_PRECISION:
104 if (arg.format[i] >=
'0' && arg.format[i] <=
'9')
106 state = SPRINTF_LENGTH;
108 if (strchr(
"hl", arg.format[i])) {
109 if (arg.format[i + 1] == arg.format[i])
111 state = SPRINTF_CONVERSION;
113 }
else if (strchr(
"Lqjzt", arg.format[i])) {
114 state = SPRINTF_CONVERSION;
117 state = SPRINTF_CONVERSION;
118 case SPRINTF_CONVERSION:
119 if (strchr(
"diouxXc", arg.format[i])) {
124 formatbuf[&arg.format[i] - formatstart + 1] =
'\0';
127 if (arg.var[argcount]) {
128 if (sscanf(arg.var[argcount++],
"%30d", &tmpi) != 1) {
129 ast_log(LOG_ERROR,
"Argument '%s' is not an integer number for format '%s'\n", arg.var[argcount - 1], formatbuf);
133 ast_log(LOG_ERROR,
"SPRINTF() has more format specifiers than arguments!\n");
138 snprintf(bufptr, buf + len - bufptr, formatbuf, tmpi);
141 bufptr = strchr(buf,
'\0');
142 }
else if (strchr(
"eEfFgGaA", arg.format[i])) {
147 formatbuf[&arg.format[i] - formatstart + 1] =
'\0';
150 if (arg.var[argcount]) {
151 if (sscanf(arg.var[argcount++],
"%30lf", &tmpd) != 1) {
152 ast_log(LOG_ERROR,
"Argument '%s' is not a floating point number for format '%s'\n", arg.var[argcount - 1], formatbuf);
156 ast_log(LOG_ERROR,
"SPRINTF() has more format specifiers than arguments!\n");
161 snprintf(bufptr, buf + len - bufptr, formatbuf, tmpd);
164 bufptr = strchr(buf,
'\0');
165 }
else if (arg.format[i] ==
's') {
170 formatbuf[&arg.format[i] - formatstart + 1] =
'\0';
173 snprintf(bufptr, buf + len - bufptr, formatbuf, arg.var[argcount++]);
176 bufptr = strchr(buf,
'\0');
177 }
else if (arg.format[i] ==
'%') {
179 *bufptr++ = arg.format[i];
185 formatbuf[&arg.format[i] - formatstart + 1] =
'\0';
187 ast_log(LOG_ERROR,
"Format type not supported: '%s' with argument '%s'\n", formatbuf, arg.var[argcount++]);
193 if (arg.format[i] ==
'%') {
194 state = SPRINTF_FLAG;
195 formatstart = &arg.format[i];
199 *bufptr++ = arg.format[i];
214 static int unload_module(
void)
223 static int load_module(
void)
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
General Asterisk PBX channel definitions.
Data structure associated with a custom dialplan function.
Core PBX routines and definitions.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.
#define AST_APP_ARG(name)
Define an application argument.