[asterisk-commits] russell: trunk r72928 - /trunk/main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 2 13:45:51 CDT 2007


Author: russell
Date: Mon Jul  2 13:45:50 2007
New Revision: 72928

URL: http://svn.digium.com/view/asterisk?view=rev&rev=72928
Log:
Add a CLI command to dump the built-in manager action documentation

Modified:
    trunk/main/manager.c

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=72928&r1=72927&r2=72928
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Mon Jul  2 13:45:50 2007
@@ -491,6 +491,73 @@
 	return ret;
 }
 
+#ifdef AST_DEVMODE
+static char *handle_manager_dump_actiondocs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct manager_action *action;
+	FILE *f;
+	char *action_name = NULL;
+	const char *fn = "/tmp/ast_manager_actiondocs.tex";
+	struct ast_str *authority = ast_str_alloca(80);
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "manager dump actiondocs";
+		e->usage =
+			"Usage: manager dump actiondocs [action]\n"
+			"       Dump manager action documentation to /tmp/ast_manager_actiondocs.tex.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc == e->args + 1)
+		action_name = 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 \"manager dump actiondocs\" CLI command.  Any manual edits will be lost.\n");
+
+	ast_rwlock_rdlock(&actionlock);
+	for (action = first_action; action; action = action->next) {
+		if (action_name && strcasecmp(action->action, action_name))
+			continue;
+
+		fprintf(f, "\\section{%s}\n"
+				"\\subsection{Synopsis}\n"
+				"\\begin{verbatim}\n"
+				"%s\n"
+				"\\end{verbatim}\n"
+				"\\subsection{Authority}\n"
+				"\\begin{verbatim}\n"
+				"%s\n"
+				"\\end{verbatim}\n"
+				"\\subsection{Description}\n"
+				"\\begin{verbatim}\n"
+				"%s\n"
+				"\\end{verbatim}\n\n\n", 
+				action->action, action->synopsis, 
+				authority_to_str(action->authority, &authority),
+				action->description);
+
+		if (action_name)
+			break;
+	}
+	ast_rwlock_unlock(&actionlock);
+
+	fclose(f);
+
+	ast_cli(a->fd, "Documentation has been dumped to %s\n", fn);
+
+	return CLI_SUCCESS;
+}
+#endif /* AST_DEVMODE */
+
 static int handle_showmancmd(int fd, int argc, char *argv[])
 {
 	struct manager_action *cur;
@@ -708,6 +775,10 @@
 	{ { "manager", "debug", NULL },
 	handle_mandebug, "Show, enable, disable debugging of the manager code",
 	"Usage: manager debug [on|off]\n	Show, enable, disable debugging of the manager code.\n", NULL, NULL },
+
+#ifdef AST_DEVMODE
+	NEW_CLI(handle_manager_dump_actiondocs, "Dump manager action documentation in LaTeX format"),
+#endif
 };
 
 /*




More information about the asterisk-commits mailing list