diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-07-02 17:11:53 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-07-02 17:11:53 +0000 |
commit | 1a7671c64ec297c214b5333328dd88a3a90995df (patch) | |
tree | f393f9f7b15a11311cdf53257133fed7065eed60 | |
parent | cf783d670fae753465cfef41ba947c1774e7a55d (diff) |
Add "core dump funcdocs" CLI command
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@72922 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | main/pbx.c | 84 |
1 files changed, 82 insertions, 2 deletions
diff --git a/main/pbx.c b/main/pbx.c index 6d36fb66a..0d3ebb3a3 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -3154,7 +3154,7 @@ static int handle_show_application(int fd, int argc, char *argv[]) } #ifdef AST_DEVMODE -static char *handle_core_dumpappdocs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +static char *handle_core_dump_appdocs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_app *app; FILE *f; @@ -3210,6 +3210,85 @@ static char *handle_core_dumpappdocs(struct ast_cli_entry *e, int cmd, struct as return CLI_SUCCESS; } + +static void funcdocs_write_section(FILE *f, const char *name) +{ + char *section, *cur; + + cur = section = alloca(strlen(name) * 2 + 1); + + for (; *name; name++) { + if (*name == '_') + *cur++ = '\\'; + *cur++ = *name; + } + *cur = '\0'; + + fprintf(f, "\\section{%s}\n", section); +} + +static char *handle_core_dump_funcdocs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + struct ast_custom_function *acf; + FILE *f; + char *funcname = NULL; + const char *fn = "/tmp/ast_funcdocs.tex"; + + switch (cmd) { + case CLI_INIT: + e->command = "core dump funcdocs"; + e->usage = + "Usage: core dump funcdocs [function]\n" + " Dump Application documentation to /tmp/ast_funcdocs.tex.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc == e->args + 1) + funcname = a->argv[e->args]; + else if (a->argc != e->args) + return CLI_SHOWUSAGE; + + if (!(f = fopen(fn, "w+"))) { + ast_cli(a->fd, "Unable to open %s for writing!\n", fn); + return CLI_FAILURE; + } + + fprintf(f, "%% This file is automatically generated by the \"core dump funcdocs\" CLI command. Any manual edits will be lost.\n"); + + AST_RWLIST_RDLOCK(&acf_root); + AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) { + if (funcname && strcasecmp(acf->name, funcname)) + continue; + + funcdocs_write_section(f, acf->name); + + fprintf(f, "\\subsection{Syntax}\n" + "\\begin{verbatim}\n" + "%s\n" + "\\end{verbatim}\n" + "\\subsection{Synopsis}\n" + "\\begin{verbatim}\n" + "%s\n" + "\\end{verbatim}\n" + "\\subsection{Description}\n" + "\\begin{verbatim}\n" + "%s\n" + "\\end{verbatim}\n\n\n", + acf->syntax, acf->synopsis, acf->desc); + + if (funcname) + break; + } + AST_RWLIST_UNLOCK(&acf_root); + + fclose(f); + + ast_cli(a->fd, "Documentation has been dumped to %s\n", fn); + + return CLI_SUCCESS; +} #endif /*! \brief handle_show_hints: CLI support for listing registered dial plan hints */ @@ -3879,7 +3958,8 @@ static struct ast_cli_entry pbx_cli[] = { show_application_help, complete_show_application }, #ifdef AST_DEVMODE - NEW_CLI(handle_core_dumpappdocs, "Dump application documentation in LaTeX format"), + NEW_CLI(handle_core_dump_appdocs, "Dump application documentation in LaTeX format"), + NEW_CLI(handle_core_dump_funcdocs, "Dump function documentation in LaTeX format"), #endif { { "core", "set", "global", NULL }, |