Fix macro formatting (bug #3275)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4710 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2005-01-08 18:45:13 +00:00
parent 51cab9e7cc
commit 3a49a959ca

View File

@@ -36,20 +36,21 @@ static char *tdesc = "Extension Macros";
static char *descrip = static char *descrip =
" Macro(macroname|arg1|arg2...): Executes a macro using the context\n" " Macro(macroname|arg1|arg2...): Executes a macro using the context\n"
"'macro-<macroname>', jumping to the 's' extension of that context and\n" "'macro-<macroname>', jumping to the 's' extension of that context and\n"
"executing each step, then returning when the steps end. The calling\n" "executing each step, then returning when the steps end. \n"
"extension, context, and priority are stored in ${MACRO_EXTEN}, \n" "The calling extension, context, and priority are stored in ${MACRO_EXTEN}, \n"
"${MACRO_CONTEXT} and ${MACRO_PRIORITY} respectively. Arguments become\n" "${MACRO_CONTEXT} and ${MACRO_PRIORITY} respectively. Arguments become\n"
"${ARG1}, ${ARG2}, etc in the macro context. Macro returns -1 if\n" "${ARG1}, ${ARG2}, etc in the macro context.\n"
"any step in the macro returns -1, and 0 otherwise. If you Goto out\n" "If you Goto out of the Macro context, the Macro will terminate and control\n"
"of the Macro context, the Macro will terminate and control will be return\n" "will be returned at the location of the Goto.\n"
"at the location of the Goto. Otherwise if ${MACRO_OFFSET} is set at\n" "Macro returns -1 if any step in the macro returns -1, and 0 otherwise.\n"
"termination, Macro will attempt to continue at priority\n" "If ${MACRO_OFFSET} is set at termination, Macro will attempt to continue\n"
"MACRO_OFFSET + N + 1 if such a step exists, and N + 1 otherwise.\n"; "at priority MACRO_OFFSET + N + 1 if such a step exists, and N + 1 otherwise.\n";
static char *if_descrip = static char *if_descrip =
" MacroIf(<expr>?label_a[|arg1][:label_b[|arg1]]):\n" " MacroIf(<expr>?macroname_a[|arg1][:macroname_b[|arg1]])\n"
"Executes macro defined in <label_a> if <expr> is true\n" "Executes macro defined in <macroname_a> if <expr> is true\n"
"(otherwise <label_b> if provided)\n"; "(otherwise <macroname_b> if provided)\n"
"Arguments and return values as in application macro()\n";
static char *exit_descrip = static char *exit_descrip =
" MacroExit():\n" " MacroExit():\n"
@@ -95,7 +96,7 @@ static int macro_exec(struct ast_channel *chan, void *data)
struct localuser *u; struct localuser *u;
if (!data || ast_strlen_zero(data)) { if (!data || ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Invalid Macro incantation\n"); ast_log(LOG_WARNING, "Macro() requires arguments. See \"show application macro\" for help.\n");
return 0; return 0;
} }
@@ -129,20 +130,24 @@ static int macro_exec(struct ast_channel *chan, void *data)
argc = 1; argc = 1;
/* Save old macro variables */ /* Save old macro variables */
save_macro_exten = pbx_builtin_getvar_helper(chan, "MACRO_EXTEN"); save_macro_exten = pbx_builtin_getvar_helper(chan, "MACRO_EXTEN");
if (save_macro_exten) save_macro_exten = strdup(save_macro_exten); if (save_macro_exten)
save_macro_exten = strdup(save_macro_exten);
pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", oldexten); pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", oldexten);
save_macro_context = pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT"); save_macro_context = pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT");
if (save_macro_context) save_macro_context = strdup(save_macro_context); if (save_macro_context)
save_macro_context = strdup(save_macro_context);
pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", oldcontext); pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", oldcontext);
save_macro_priority = pbx_builtin_getvar_helper(chan, "MACRO_PRIORITY"); save_macro_priority = pbx_builtin_getvar_helper(chan, "MACRO_PRIORITY");
if (save_macro_priority) save_macro_priority = strdup(save_macro_priority); if (save_macro_priority)
save_macro_priority = strdup(save_macro_priority);
snprintf(pc, sizeof(pc), "%d", oldpriority); snprintf(pc, sizeof(pc), "%d", oldpriority);
pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", pc); pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", pc);
save_macro_offset = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"); save_macro_offset = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET");
if (save_macro_offset) save_macro_offset = strdup(save_macro_offset); if (save_macro_offset)
save_macro_offset = strdup(save_macro_offset);
pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", NULL); pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", NULL);
/* Setup environment for new run */ /* Setup environment for new run */
@@ -216,11 +221,14 @@ out:
/* Restore macro variables */ /* Restore macro variables */
pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", save_macro_exten); pbx_builtin_setvar_helper(chan, "MACRO_EXTEN", save_macro_exten);
if (save_macro_exten) free(save_macro_exten); if (save_macro_exten)
free(save_macro_exten);
pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", save_macro_context); pbx_builtin_setvar_helper(chan, "MACRO_CONTEXT", save_macro_context);
if (save_macro_context) free(save_macro_context); if (save_macro_context)
free(save_macro_context);
pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", save_macro_priority); pbx_builtin_setvar_helper(chan, "MACRO_PRIORITY", save_macro_priority);
if (save_macro_priority) free(save_macro_priority); if (save_macro_priority)
free(save_macro_priority);
if (setmacrocontext) { if (setmacrocontext) {
chan->macrocontext[0] = '\0'; chan->macrocontext[0] = '\0';
chan->macroexten[0] = '\0'; chan->macroexten[0] = '\0';
@@ -247,7 +255,8 @@ out:
} }
pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", save_macro_offset); pbx_builtin_setvar_helper(chan, "MACRO_OFFSET", save_macro_offset);
if (save_macro_offset) free(save_macro_offset); if (save_macro_offset)
free(save_macro_offset);
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
return res; return res;
} }
@@ -286,6 +295,7 @@ int unload_module(void)
{ {
STANDARD_HANGUP_LOCALUSERS; STANDARD_HANGUP_LOCALUSERS;
ast_unregister_application(if_app); ast_unregister_application(if_app);
ast_unregister_application(exit_app);
return ast_unregister_application(app); return ast_unregister_application(app);
} }