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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Oct 24 17:54:52 CDT 2008


Author: eliel
Date: Fri Oct 24 17:54:52 2008
New Revision: 151893

URL: http://svn.digium.com/view/asterisk?view=rev&rev=151893
Log:
More fixes pointed by Russell (The review board is a great tool)
- Fix naming convention.
- Use a space after a cast.
- Reduce indentention inside loop's when possible.
- Don't forget to check for every malloc result.
- Cast to (const char *) where we are talking about a constant value.
- Move ast_load_documentation() to include/asterisk/_private.h (Init functions should be there when used only inside the core).

Thanks again russellb for the review.

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

Modified: team/group/appdocsxml/include/asterisk/_private.h
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/include/asterisk/_private.h?view=diff&rev=151893&r1=151892&r2=151893
==============================================================================
--- team/group/appdocsxml/include/asterisk/_private.h (original)
+++ team/group/appdocsxml/include/asterisk/_private.h Fri Oct 24 17:54:52 2008
@@ -56,4 +56,10 @@
  */
 int ast_module_reload(const char *name);
 
+/*! \brief Load XML documentation. Provided by pbx.c 
+ *  \retval 1 on error.
+ *  \retval 0 on success. 
+ */
+int ast_load_documentation(void);
+
 #endif /* _ASTERISK__PRIVATE_H */

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=151893&r1=151892&r2=151893
==============================================================================
--- team/group/appdocsxml/include/asterisk/extconf.h (original)
+++ team/group/appdocsxml/include/asterisk/extconf.h Fri Oct 24 17:54:52 2008
@@ -83,7 +83,7 @@
 		AST_STRING_FIELD(arguments);    /*!< Arguments description */
 		AST_STRING_FIELD(seealso);      /*!< See also */
 	);
-	enum doc_src docsrc;			/*!< Where the documentation come from. */
+	enum ast_xmldoc_src docsrc;		/*!< Where the documentation come from. */
 	AST_RWLIST_ENTRY(ast_app) list;		/*!< Next app in list */
 	void *module;			/*!< Module this app belongs to */
 	char name[0];				/*!< Name of the application */

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=151893&r1=151892&r2=151893
==============================================================================
--- team/group/appdocsxml/include/asterisk/pbx.h (original)
+++ team/group/appdocsxml/include/asterisk/pbx.h Fri Oct 24 17:54:52 2008
@@ -74,7 +74,7 @@
 typedef int (*ast_state_cb_type)(char *context, char* id, enum ast_extension_states state, void *data);
 
 /*! \brief From where the documentation come from */
-enum doc_src {
+enum ast_xmldoc_src {
 	AST_XML_DOC,            /*!< From XML documentation */
 	AST_STATIC_DOC          /*!< From application/function registration */
 };
@@ -89,7 +89,7 @@
 		AST_STRING_FIELD(arguments);    /*!< Arguments description */
 		AST_STRING_FIELD(seealso);      /*!< See also */
 	);
-	enum doc_src docsrc;		/*!< Where the documentation come from */
+	enum ast_xmldoc_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 */
 	struct ast_module *mod;         /*!< Module this custom function belongs to */
@@ -1022,9 +1022,6 @@
 int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b);
 unsigned int ast_hashtab_hash_contexts(const void *obj);
 
-/*! \brief Load XML documentation. */
-int ast_load_documentation(void);
-
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=151893&r1=151892&r2=151893
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Fri Oct 24 17:54:52 2008
@@ -766,7 +766,7 @@
 		AST_STRING_FIELD(arguments);	/*!< Arguments description */
 		AST_STRING_FIELD(seealso);	/*!< See also */
 	);
-	enum doc_src docsrc;			/*!< Where the documentation come from. */
+	enum ast_xmldoc_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 */
 	char name[0];				/*!< Name of the application */
@@ -3069,7 +3069,6 @@
 
 	/* check allocated memory. */
 	if (!synopsis || !description || !arguments || !seealso) {
-		ast_cli(a->fd, "Memory allocation failure!\n");
 		ast_free(synopsis);
 		ast_free(description);
 		ast_free(arguments);
@@ -3226,7 +3225,7 @@
 static char *xmldoc_string_wrap(char *text, int columns, int maxdiff)
 {
 	char *tmp, *ret, *t;
-	char *in = (char *)text;
+	char *in = (char *) text;
 	int count = 1, tmplen = 0, i, postbrreallen = 0, postbrlen;
 	char postbr[160];
 	int sep, needtobreak = 0, colmax;
@@ -3583,7 +3582,7 @@
 	ast_xml_node *node = fixnode;
 
 	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *)node->AST_XML_NAME, "argument")) {
+		if (!strcasecmp((const char *) node->AST_XML_NAME, "argument")) {
 			return 1;
 		}
 	}
@@ -3634,13 +3633,13 @@
 
 	/* Get order of evaluation. */
 	for (node = rootnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (strcasecmp((const char *)node->AST_XML_NAME, childname)) {
+		if (strcasecmp((const char *) node->AST_XML_NAME, childname)) {
 			continue;
 		}
 		required = 0;
 		hasparams = 1;
 		if ((paramtype = ast_xml_get_attribute(node, "required"))) {
-			if (ast_true((char *)paramtype)) {
+			if (ast_true((const char *) paramtype)) {
 				required = 1;
 			}
 			ast_xml_free_attr(paramtype);
@@ -3665,12 +3664,12 @@
 	if (reqfinode && reqlanode) {
 		/* check midnode */
 		for (node = rootnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-			if (strcasecmp((const char *)node->AST_XML_NAME, childname)) {
+			if (strcasecmp((const char *) node->AST_XML_NAME, childname)) {
 				continue;
 			}
 			if (node != firstparam && node != lastparam) {
 				if ((paramtype = ast_xml_get_attribute(node, "required"))) {
-					if (!ast_true((char *)paramtype)) {
+					if (!ast_true((const char *) paramtype)) {
 						optmidnode = 1;
 						break;
 					}
@@ -3696,7 +3695,7 @@
 	}
 
 	for (; node; node = GOTONEXT(reverse, node)) {
-		if (strcasecmp((const char *)node->AST_XML_NAME, childname)) {
+		if (strcasecmp((const char *) node->AST_XML_NAME, childname)) {
 			continue;
 		}
 
@@ -3823,7 +3822,7 @@
 	}
 
 	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *)node->AST_XML_NAME, "syntax")) {
+		if (!strcasecmp((const char *) node->AST_XML_NAME, "syntax")) {
 			break;
 		}
 	}
@@ -3857,7 +3856,7 @@
 		return ret;
 	}
 
-	if (strcasecmp((const char *)node->AST_XML_NAME, "para")) {
+	if (strcasecmp((const char *) node->AST_XML_NAME, "para")) {
 		return ret;
 	}
 
@@ -3873,7 +3872,7 @@
 			xmldoc_string_cleanup(tmptext, &tmpstr, 0);
 			ast_xml_free_text(tmptext);
 			if (tmpstr) {
-				if (strcasecmp((const char *)tmp->AST_XML_NAME, "text")) {
+				if (strcasecmp((const char *) tmp->AST_XML_NAME, "text")) {
 					ast_str_append(buffer, 0, "<%s>%s</%s>", tmp->AST_XML_NAME, tmpstr->str, tmp->AST_XML_NAME);
 				} else {
 					ast_str_append(buffer, 0, "%s", tmpstr->str);
@@ -3909,7 +3908,7 @@
 	}
 
 	for (i = 0; i < ARRAY_LEN(special_tags); i++) {
-		if (!strcasecmp((const char *)node->AST_XML_NAME, special_tags[i].tagname)) {
+		if (!strcasecmp((const char *) node->AST_XML_NAME, special_tags[i].tagname)) {
 			ret = 1;
 			/* This is a special tag. */
 
@@ -3958,18 +3957,19 @@
 
 	/* Print the argument names */
 	argname = ast_xml_get_attribute(node, "name");
-	if (argname) {
-		ast_str_append(buffer, 0, "%s%s%s", tabs, argname, (insideparameter ? "\n" : ""));
-		ast_xml_free_attr(argname);
-
-		for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-			if (xmldoc_parse_para(node, (insideparameter ? paramtabs : (!count ? " - " : tabs)), "\n", buffer) == 2) {
-				count++;
-				ret = 1;
-			} else if (xmldoc_parse_specialtags(node, (insideparameter ? paramtabs : (!count ? " - " : tabs)), "\n", buffer) == 2) {
-				count++;
-				ret = 1;
-			}
+	if (!argname) {
+		return 0;
+	}
+	ast_str_append(buffer, 0, "%s%s%s", tabs, argname, (insideparameter ? "\n" : ""));
+	ast_xml_free_attr(argname);
+
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
+		if (xmldoc_parse_para(node, (insideparameter ? paramtabs : (!count ? " - " : tabs)), "\n", buffer) == 2) {
+			count++;
+			ret = 1;
+		} else if (xmldoc_parse_specialtags(node, (insideparameter ? paramtabs : (!count ? " - " : tabs)), "\n", buffer) == 2) {
+			count++;
+			ret = 1;
 		}
 	}
 
@@ -4004,31 +4004,34 @@
 			continue;
 		}
 
-		if (!strcasecmp((const char *)tmp->AST_XML_NAME, "value")) {
-			if (!printedpara) {
-				ast_str_append(buffer, 0, "\n");
-				printedpara = 1;
-			}
-			/* Parse each <value name='valuename'>desciption</value> */
-			valname = ast_xml_get_attribute(tmp, "name");
-			if (valname) {
-				ret = 1;
-				ast_str_append(buffer, 0, "%s<value>%s</value>", tabs, valname);
-				ast_xml_free_attr(valname);
-			}
-			tmptext = ast_xml_get_text(tmp);
-			/* Check inside this node for any explanation about its meaning. */
-			if (tmptext) {
-				/* Cleanup text. */
-				xmldoc_string_cleanup(tmptext, &cleanstr, 1);
-				ast_xml_free_text(tmptext);
-				if (cleanstr && cleanstr->used > 0) {
-					ast_str_append(buffer, 0, ":%s", cleanstr->str);
-				}
-				ast_free(cleanstr);
-			}
+		if (strcasecmp((const char *) tmp->AST_XML_NAME, "value")) {
+			continue;
+		}
+
+		/* Parse a <value> tag only. */
+		if (!printedpara) {
 			ast_str_append(buffer, 0, "\n");
-		}
+			printedpara = 1;
+		}
+		/* Parse each <value name='valuename'>desciption</value> */
+		valname = ast_xml_get_attribute(tmp, "name");
+		if (valname) {
+			ret = 1;
+			ast_str_append(buffer, 0, "%s<value>%s</value>", tabs, valname);
+			ast_xml_free_attr(valname);
+		}
+		tmptext = ast_xml_get_text(tmp);
+		/* Check inside this node for any explanation about its meaning. */
+		if (tmptext) {
+			/* Cleanup text. */
+			xmldoc_string_cleanup(tmptext, &cleanstr, 1);
+			ast_xml_free_text(tmptext);
+			if (cleanstr && cleanstr->used > 0) {
+				ast_str_append(buffer, 0, ":%s", cleanstr->str);
+			}
+			ast_free(cleanstr);
+		}
+		ast_str_append(buffer, 0, "\n");
 	}
 
 	return ret;
@@ -4056,7 +4059,7 @@
 		return ret;
 	}
 
-	if (strcasecmp((const char *)node->AST_XML_NAME, "variablelist")) {
+	if (strcasecmp((const char *) node->AST_XML_NAME, "variablelist")) {
 		return ret;
 	}
 
@@ -4075,7 +4078,7 @@
 			continue;
 		}
 
-		if (!strcasecmp((const char *)tmp->AST_XML_NAME, "variable")) {
+		if (!strcasecmp((const char *) tmp->AST_XML_NAME, "variable")) {
 			/* Store the variable name in buffer. */
 			varname = ast_xml_get_attribute(tmp, "name");
 			if (varname) {
@@ -4120,7 +4123,7 @@
 
 	/* Find the <see-also> node. */
 	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *)node->AST_XML_NAME, "see-also")) {
+		if (!strcasecmp((const char *) node->AST_XML_NAME, "see-also")) {
 			break;
 		}
 	}
@@ -4138,7 +4141,7 @@
 
 	/* get into the <see-also> node. */
 	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (strcasecmp((const char *)node->AST_XML_NAME, "ref")) {
+		if (strcasecmp((const char *) node->AST_XML_NAME, "ref")) {
 			continue;
 		}
 
@@ -4207,7 +4210,7 @@
 	int ret = 0;
 
 	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (strcasecmp((const char *)node->AST_XML_NAME, "enum")) {
+		if (strcasecmp((const char *) node->AST_XML_NAME, "enum")) {
 			continue;
 		}
 
@@ -4247,7 +4250,7 @@
 		return ret;
 	}
 	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *)node->AST_XML_NAME, "argument")) {
+		if (!strcasecmp((const char *) node->AST_XML_NAME, "argument")) {
 			/* if this is the first data appended to buffer, print a \n*/
 			if (!ret && node->AST_XML_CHILD) {
 				/* print \n */
@@ -4289,7 +4292,7 @@
 
 	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		/* Start appending every option tag. */
-		if (strcasecmp((const char *)node->AST_XML_NAME, "option")) {
+		if (strcasecmp((const char *) node->AST_XML_NAME, "option")) {
 			continue;
 		}
 
@@ -4326,7 +4329,7 @@
 	int hasarguments, printed = 0;
 	char *internaltabs;
 
-	if (strcasecmp((const char *)node->AST_XML_NAME, "parameter")) {
+	if (strcasecmp((const char *) node->AST_XML_NAME, "parameter")) {
 		return;
 	}
 
@@ -4348,13 +4351,13 @@
 	}
 
 	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *)node->AST_XML_NAME, "optionlist")) {
+		if (!strcasecmp((const char *) node->AST_XML_NAME, "optionlist")) {
 			xmldoc_parse_optionlist(node, internaltabs, buffer);
-		} else if (!strcasecmp((const char *)node->AST_XML_NAME, "enumlist")) {
+		} else if (!strcasecmp((const char *) node->AST_XML_NAME, "enumlist")) {
 			xmldoc_parse_enumlist(node, internaltabs, buffer);
-		} else if (!strcasecmp((const char *)node->AST_XML_NAME, "argument")) {
+		} else if (!strcasecmp((const char *) node->AST_XML_NAME, "argument")) {
 			xmldoc_parse_argument(node, 1, internaltabs, (!hasarguments ? "        " : ""), buffer);
-		} else if (!strcasecmp((const char *)node->AST_XML_NAME, "para")) {
+		} else if (!strcasecmp((const char *) node->AST_XML_NAME, "para")) {
 			if (!printed) {
 				ast_str_append(buffer, 0, "%s\n", paramname);
 				ast_xml_free_attr(paramname);
@@ -4395,7 +4398,7 @@
 
 	/* Find the syntax field. */
 	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
-		if (!strcasecmp((const char *)node->AST_XML_NAME, "syntax")) {
+		if (!strcasecmp((const char *) node->AST_XML_NAME, "syntax")) {
 			break;
 		}
 	}
@@ -6577,7 +6580,7 @@
 #ifdef XML_DOCUMENTATION
 				if (syntax) {
 #else
-				if (syntax && description && arguments && synopsis) {
+				if (syntax && description && arguments && synopsis && seealso) {
 #endif
 					snprintf(info, sizeof(info), "\n  -= Info about application '%s' =- \n\n", aa->name);
 					term_color(infotitle, info, COLOR_MAGENTA, 0, sizeof(infotitle));

Modified: team/group/appdocsxml/main/xml.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/xml.c?view=diff&rev=151893&r1=151892&r2=151893
==============================================================================
--- team/group/appdocsxml/main/xml.c (original)
+++ team/group/appdocsxml/main/xml.c Fri Oct 24 17:54:52 2008
@@ -103,7 +103,7 @@
 void ast_xml_free_text(ast_xml_text *text)
 {
 	if (text) {
-		xmlFree((char *)text);
+		xmlFree((char *) text);
 	}
 }
 
@@ -135,21 +135,21 @@
 
 	for (cur = root_node; cur; cur = cur->next) {
 		/* Check if the name matchs */
-		if (!strcmp((char *)cur->name, name)) {
-			/* We need to check for a specific attribute name? */
-			if (attrname && attrvalue) {
-				/* Get the attribute, we need to compare it. */
-				if ((attr = ast_xml_get_attribute(cur, attrname))) {
-					/* does attribute name/value matches? */
-					if (!strcmp(attr, attrvalue)) {
-						ast_xml_free_attr(attr);
-						return cur;
-					}
-					ast_xml_free_attr(attr);
-				}
-			} else {
+		if (strcmp((const char *) cur->name, name)) {
+			continue;
+		}
+		/* We need to check for a specific attribute name? */
+		if (!attrname || !attrvalue) {
+			return cur;
+		}
+		/* Get the attribute, we need to compare it. */
+		if ((attr = ast_xml_get_attribute(cur, attrname))) {
+			/* does attribute name/value matches? */
+			if (!strcmp(attr, attrvalue)) {
+				ast_xml_free_attr(attr);
 				return cur;
 			}
+			ast_xml_free_attr(attr);
 		}
 	}
 
@@ -162,7 +162,7 @@
 		return NULL;
 	}
 
-	return (const char *)xmlNodeGetContent(node);
+	return (const char *) xmlNodeGetContent(node);
 }
 
 #endif /* defined(HAVE_LIBXML2) && !defined(AST_XML_IMPLEMENTATION) */




More information about the asterisk-commits mailing list