[asterisk-commits] eliel: branch group/appdocsxml r139073 - in /team/group/appdocsxml: include/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 20 12:03:39 CDT 2008


Author: eliel
Date: Wed Aug 20 12:03:38 2008
New Revision: 139073

URL: http://svn.digium.com/view/asterisk?view=rev&rev=139073
Log:
- Added a new 'arguments' member of ast_app and ast_custom_function.
- When running 'core show application <appname>' show the arguments list. (Not full implemented yet).
- Cleanup xmldoc_parse_para with not needed/used argument.
- Declare not implemented functions:
            xmldoc_parse_optionlist()
            xmldoc_parse_argument()
- Implement xmldoc_parse_parameter().
- Implement xmldoc_build_arguments().


Modified:
    team/group/appdocsxml/include/asterisk/extconf.h
    team/group/appdocsxml/include/asterisk/pbx.h
    team/group/appdocsxml/main/pbx.c

Modified: team/group/appdocsxml/include/asterisk/extconf.h
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/include/asterisk/extconf.h?view=diff&rev=139073&r1=139072&r2=139073
==============================================================================
--- team/group/appdocsxml/include/asterisk/extconf.h (original)
+++ team/group/appdocsxml/include/asterisk/extconf.h Wed Aug 20 12:03:38 2008
@@ -85,6 +85,7 @@
 	char *synopsis;				/*!< Synopsis text for 'show applications' */
 	char *description;			/*!< Description (help text) for 'show application &lt;name&gt;' */
 	char *syntax;				/*!< Syntax text for 'core show applications' */
+	char *arguments;			/*!< Arguments description */
 	enum doc_src docsrc;			/*!< Where the documentation come from. */
 	AST_RWLIST_ENTRY(ast_app) list;		/*!< Next app in list */
 	void *module;			/*!< Module this app belongs to */

Modified: team/group/appdocsxml/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/include/asterisk/pbx.h?view=diff&rev=139073&r1=139072&r2=139073
==============================================================================
--- team/group/appdocsxml/include/asterisk/pbx.h (original)
+++ team/group/appdocsxml/include/asterisk/pbx.h Wed Aug 20 12:03:38 2008
@@ -84,6 +84,7 @@
 	char *synopsis;		/*!< Short description for "show functions" */
 	char *desc;		/*!< Help text that explains it all */
 	char *syntax;		/*!< Syntax description */
+	char *arguments;	/*!< Arguments description */
 	enum doc_src docsrc;		/*!< Where the documentation come from */
 	int (*read)(struct ast_channel *, const char *, char *, char *, size_t);	/*!< Read function, if read is supported */
 	int (*write)(struct ast_channel *, const char *, char *, const char *);		/*!< Write function, if write is supported */

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=139073&r1=139072&r2=139073
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Wed Aug 20 12:03:38 2008
@@ -229,6 +229,7 @@
 	char *synopsis;				/*!< Synopsis text for 'show applications' */
 	char *description;			/*!< Description (help text) for 'show application &lt;name&gt;' */
 	char *syntax;				/*!< Syntax text for 'core show applications' */
+	char *arguments;			/*!< Arguments description */
 	enum doc_src docsrc;			/*!< Where the documentation come from. */
 	AST_RWLIST_ENTRY(ast_app) list;		/*!< Next app in list */
 	struct ast_module *module;		/*!< Module this app belongs to */
@@ -2681,10 +2682,10 @@
 {
 	struct ast_custom_function *acf;
 	/* Maximum number of characters added by terminal coloring is 22 */
-	char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40];
+	char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40], argtitle[40];
 	char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL;
-	char stxtitle[40], *syntax = NULL;
-	int synopsis_size, description_size, syntax_size;
+	char stxtitle[40], *syntax = NULL, *arguments = NULL;
+	int synopsis_size, description_size, syntax_size, arguments_size;
 	char *ret = NULL;
 	int which = 0;
 	int wordlen;
@@ -2738,14 +2739,24 @@
 		syntax_size = strlen("Not available") + 23;
 	syntax = alloca(syntax_size);
 
+	if (acf->arguments)
+		arguments_size = strlen(acf->arguments) + 23;
+	else
+		arguments_size = strlen("Not available") + 23;
+	arguments = alloca(arguments_size);
+
 	snprintf(info, 64 + AST_MAX_APP, "\n  -= Info about function '%s' =- \n\n", acf->name);
 	term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22);
 	term_color(stxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
+	term_color(argtitle, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
 	term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
 	term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
 	term_color(syntax,
 		   acf->syntax ? acf->syntax : "Not available",
 		   COLOR_CYAN, 0, syntax_size);
+	term_color(arguments,
+		   acf->arguments ? acf->arguments : "Not available",
+		   COLOR_CYAN, 0, arguments_size);
 	term_color(synopsis,
 		   acf->synopsis ? acf->synopsis : "Not available",
 		   COLOR_CYAN, 0, synopsis_size);
@@ -2753,7 +2764,8 @@
 		   acf->desc ? acf->desc : "Not available",
 		   COLOR_CYAN, 0, description_size);
 
-	ast_cli(a->fd,"%s%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, syntitle, synopsis, destitle, description);
+	ast_cli(a->fd,"%s%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, argtitle, arguments, 
+		syntitle, synopsis, destitle, description);
 
 	return CLI_SUCCESS;
 }
@@ -3282,11 +3294,10 @@
  *  \param buffer This must be NULL or an ast_malloc'ed buffer. It will be used
  *         to store the result (if already has something it will be appended to the current
  *         string).
- *  \param predatalen TODO
  *  \retval 1 on succes.
  *  \retval 0 on error.
  */
-static int xmldoc_parse_para(ast_xml_node *node, const char *tabs, const char *posttabs, int *len, char **buffer, int predatalen)
+static int xmldoc_parse_para(ast_xml_node *node, const char *tabs, const char *posttabs, int *len, char **buffer)
 {
 	ast_xml_text *tmptext;
 	char *cleantext;
@@ -3313,6 +3324,126 @@
 	}
 
 	return 1;
+}
+
+/*! \internal
+ *  \brief Parse an <optionlist> element from the xml documentation.
+ *  \param buffer Output buffer to put what is inside the optionlist tag.
+ *  \param len Length of the passed 'buffer', it will be incremented if something
+ *  is appended into buffer.
+ *  \param node Pointer to the optionlist xml node.
+ */
+static void xmldoc_parse_optionlist(char **buffer, int *len, ast_xml_node *node)
+{
+	return;
+}
+
+/*! \internal
+ *  \brief Parse an <argument> element from the xml documentation.
+ *  \param buffer Output buffer to put values found inside the <argument> element.
+ *  \param len Output buffer length (will be modified if data is appended to buffer).
+ *  \param node Pointer to the 'argument' xml node.
+ */
+static void xmldoc_parse_argument(char **buffer, int *len, ast_xml_node *node)
+{
+	return;
+}
+
+/*! \internal
+ *  \brief Parse a 'parameter' tag inside a syntax element.
+ *  \param buffer String buffer to put values found inside the parameter element.
+ *  \param len Buffer length (will be modified if data is appended to buffer).
+ *  \param node A pointer to the 'parameter' xml node.
+ */
+static void xmldoc_parse_parameter(char **buffer, int *len, ast_xml_node *node)
+{
+	ast_xml_attr *paramname;
+
+	if (!node || !node->AST_XML_CHILD || strcasecmp((char *)node->AST_XML_NAME, "parameter")) {
+		return;
+	}
+
+	paramname = ast_xml_get_attribute(node, "name");
+	if (paramname) {
+		*buffer = ast_realloc(*buffer, *len + strlen(paramname) + 2);
+		if (!*buffer) {
+			return;
+		}
+		*len += sprintf (*buffer + *len, "%s\n", paramname);
+		ast_xml_free_attr(paramname);
+	} else {
+		return;
+	}
+
+	return;
+	node = node->AST_XML_CHILD;
+	while (node) {
+		if (!strcasecmp((char *)node->AST_XML_NAME, "optionlist")) {
+			xmldoc_parse_optionlist(buffer, len, node);
+			node = node->AST_XML_NEXT;
+			continue;
+		}
+		if (!strcasecmp((char *)node->AST_XML_NAME, "argument")) {
+			xmldoc_parse_argument(buffer, len, node);
+			node = node->AST_XML_NEXT;
+			continue;
+		}
+		if ((xmldoc_parse_para(node, "", "", len, buffer))) {
+			node = node->AST_XML_NEXT;
+			continue;
+		}
+			
+		node = node->AST_XML_NEXT;
+	}
+
+
+}
+
+/*! \internal
+ *  \brief Generate the [arguments] tag based on type of node 'application' or
+ *         'function' and name.
+ *  \param type 'application' or 'function' ? 
+ *  \param name Name of the application or function to build the 'arguments' tag.
+ *  \retval NULL on error.
+ *  \retval Output buffer with the [arguments] tag content.
+ */
+static char *xmldoc_build_arguments(const char *type, const char *name)
+{
+	ast_xml_node *node;
+	char *ret = NULL;
+	int len = 0;
+	
+	if (ast_strlen_zero(type) || ast_strlen_zero(name)) {
+		return NULL;
+	}
+
+	node = xmldoc_get_node(documentation_tree, type, name, documentation_language);
+	
+	if (!node || !node->AST_XML_CHILD) {
+		return NULL;
+	}
+
+	/* Find the syntax field. */
+	node = node->AST_XML_CHILD;
+	while (node) {
+		if (!strcasecmp((char *)node->AST_XML_NAME, "syntax")) {
+			break;
+		}
+		node = node->AST_XML_NEXT;
+	}
+	
+	if (!node || !node->AST_XML_CHILD) {
+		/* We couldn't find the syntax node. */
+		return NULL;
+	}
+
+	node = node->AST_XML_CHILD;
+	while (node) {
+		xmldoc_parse_parameter(&ret, &len, node);
+		node = node->AST_XML_NEXT;
+	}
+
+	return ret;
 }
 
 /*! \internal
@@ -3339,7 +3470,7 @@
 
 	tmp = node->AST_XML_CHILD;
 	while (tmp) {
-		if (xmldoc_parse_para(tmp, "", "", len, buffer, varnamelen + 8 - (varnamelen % 8))) {
+		if (xmldoc_parse_para(tmp, "", "", len, buffer)) {
 			tmp = tmp->AST_XML_NEXT;
 			continue;
 		}
@@ -3401,7 +3532,7 @@
 	tmp = node->AST_XML_CHILD;
 	while (tmp) {
 		/* We can have a <para> element inside the variable list ?? */
-		if ((xmldoc_parse_para(tmp, "", "", len, buffer, 0))) {
+		if ((xmldoc_parse_para(tmp, "", "", len, buffer))) {
 			tmp = tmp->AST_XML_NEXT;
 			continue;
 		}
@@ -3449,7 +3580,7 @@
 		tmp = node->AST_XML_CHILD;
 		while (tmp) {
 			/* if found, parse a <para> element. */
-			if (xmldoc_parse_para(tmp, "", "\n", &len, &ret, 0)) {
+			if (xmldoc_parse_para(tmp, "", "\n", &len, &ret)) {
 				tmp = tmp->AST_XML_NEXT;
 				continue;
 			}
@@ -3527,6 +3658,7 @@
 		acf->synopsis = xmldoc_get_field("function", acf->name, "synopsis", 1);
 		acf->desc = xmldoc_get_field("function", acf->name, "description", 0);
 		acf->syntax = xmldoc_build_syntax("function", acf->name);
+		acf->arguments = xmldoc_build_arguments("function", acf->name);
 		acf->docsrc = AST_XML_DOC;
 	}
 #endif
@@ -5239,6 +5371,7 @@
 		tmp->synopsis = xmldoc_get_field("application", app, "synopsis", 1);
 		tmp->description = xmldoc_get_field("application", app, "description", 0);
 		tmp->syntax = xmldoc_build_syntax("application", app);
+		tmp->arguments = xmldoc_build_arguments("application", app);
 		tmp->docsrc = AST_XML_DOC;
 	} else {
 #endif
@@ -5409,9 +5542,9 @@
 		for (app = 3; app < a->argc; app++) {
 			if (!strcasecmp(aa->name, a->argv[app])) {
 				/* Maximum number of characters added by terminal coloring is 22 */
-				char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40], stxtitle[40];
-				char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL, *syntax = NULL;
-				int synopsis_size, description_size, syntax_size;
+				char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40], stxtitle[40], argtitle[40];
+				char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL, *syntax = NULL, *arguments = NULL;
+				int synopsis_size, description_size, syntax_size, arguments_size;
 
 				no_registered_app = 0;
 
@@ -5433,10 +5566,17 @@
 					syntax_size = strlen("Not available") + 23;
 				syntax = alloca(syntax_size);
 
+				if (aa->arguments)
+					arguments_size = strlen(aa->arguments) + 23;
+				else
+					arguments_size = strlen("Not available") + 23;
+				arguments = alloca(arguments_size);
+
 				if (synopsis && description) {
 					snprintf(info, 64 + AST_MAX_APP, "\n  -= Info about application '%s' =- \n\n", aa->name);
 					term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22);
 					term_color(stxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
+					term_color(argtitle, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
 					term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
 					term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
 					term_color(synopsis,
@@ -5448,16 +5588,22 @@
 					term_color(syntax,
 									aa->syntax ? aa->syntax : "Not available",
 									COLOR_CYAN, 0, syntax_size);
-
-					ast_cli(a->fd,"%s%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, syntitle, synopsis, destitle, description);
+					term_color(arguments,
+									aa->arguments ? aa->arguments : "Not available",
+									COLOR_CYAN, 0, arguments_size);
+
+					ast_cli(a->fd,"%s%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, argtitle, 
+						arguments, syntitle, synopsis, destitle, description);
 				} else {
 					/* ... one of our applications, show info ...*/
 					ast_cli(a->fd,"\n  -= Info about application '%s' =- \n\n"
 						"[Syntax]\n  %s\n\n"
+						"[Arguments]\n%s\n\n"
 						"[Synopsis]\n  %s\n\n"
 						"[Description]\n%s\n",
 						aa->name,
 						aa->syntax ? aa->syntax : "Not available",
+						aa->arguments ? aa->arguments : "Not available",
 						aa->synopsis ? aa->synopsis : "Not available",
 						aa->description ? aa->description : "Not available");
 				}




More information about the asterisk-commits mailing list