[asterisk-commits] eliel: branch group/appdocsxml r150128 - /team/group/appdocsxml/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 16 11:21:08 CDT 2008


Author: eliel
Date: Thu Oct 16 11:21:08 2008
New Revision: 150128

URL: http://svn.digium.com/view/asterisk?view=rev&rev=150128
Log:
Stop using static strings like "   " and pass tabs within the parameters of the
function.
Also "simplify" some parts of the code adding inline conditionals instead of big blocks of ifs.

Modified:
    team/group/appdocsxml/main/pbx.c

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=150128&r1=150127&r2=150128
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Thu Oct 16 11:21:08 2008
@@ -3892,14 +3892,9 @@
 			/* parse <para> elements inside special tags. */
 			node = node->AST_XML_CHILD;
 			while (node) {
-				if (count > 0) {
-					if (xmldoc_parse_para(node, tabs, posttabs, buffer) == 2) {
-						ret = 2;
-					}
-				} else {
-					if (xmldoc_parse_para(node, "", posttabs, buffer) == 2) {
-						ret = 2;
-					}
+				/* first <para> just print it without tabs at the begining. */
+				if (xmldoc_parse_para(node, (!count ? "" : tabs), posttabs, buffer) == 2) {
+					ret = 2;
 				}
 				node = node->AST_XML_NEXT;
 			}
@@ -3943,22 +3938,12 @@
 
 		node = node->AST_XML_CHILD;
 		while (node) {
-			if (count > 0) {
-				if (xmldoc_parse_para(node, (insideparameter ? paramtabs : tabs), "\n", buffer) == 2) {
-					count++;
-					ret = 1;
-				} else if (xmldoc_parse_specialtags(node, (insideparameter ? paramtabs : tabs), "\n", buffer) == 2) {
-					count++;
-					ret = 1;
-				}
-			} else {
-				if (xmldoc_parse_para(node, (insideparameter ? paramtabs : " - "), "\n", buffer) == 2) {
-					count++;
-					ret = 1;
-				} else if (xmldoc_parse_specialtags(node, (insideparameter ? paramtabs : " - "), "\n", buffer) == 2) {
-					count++;
-					ret = 1;
-				}
+			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;
 			}
 			node = node->AST_XML_NEXT;
 		}
@@ -4244,18 +4229,23 @@
 /*! \internal
  *  \brief Parse an <option> node.
  *  \param fixnode An ast_xml pointer to the <option> node.
+ *  \param tabs A string to be appended at the begining of each line being added to the
+ *              buffer string. 
  *  \param buffer The output buffer.
  *  \retval 0 if no option node is parsed.
  *  \retval 1 if an option node is parsed.
  */
-static int xmldoc_parse_option(ast_xml_node *fixnode, struct ast_str **buffer)
+static int xmldoc_parse_option(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
 {
 	ast_xml_node *node = fixnode;
 	int ret = 0;
+	char *optiontabs;
 
 	if (!node || !node->AST_XML_CHILD) {
 		return ret;
 	}
+
+	ast_asprintf(&optiontabs, "%s    ", tabs);
 
 	node = node->AST_XML_CHILD;
 	while (node) {
@@ -4264,22 +4254,22 @@
 				/* print \n */
 				ast_str_append(buffer, 0, "\n");
 			}
-			if (xmldoc_parse_argument(node, 0, NULL, "        ", buffer)) {
+			if (xmldoc_parse_argument(node, 0, NULL, optiontabs, buffer)) {
 				ret = 1;
 			}
 			node = node->AST_XML_NEXT;
 			continue;
 		}
 
-		if (xmldoc_parse_para(node, (ret ? "    " :  ""), "\n", buffer)) {
+		if (xmldoc_parse_para(node, (ret ? tabs :  ""), "\n", buffer)) {
 			ret = 1;
-		} else if (xmldoc_parse_specialtags(node, (ret ? "    " :  ""), "\n", buffer)) {
+		} else if (xmldoc_parse_specialtags(node, (ret ? tabs :  ""), "\n", buffer)) {
 			ret = 1;
 		}
 		
-		xmldoc_parse_variablelist(node, "        ", buffer);
+		xmldoc_parse_variablelist(node, optiontabs, buffer);
 		
-		xmldoc_parse_enumlist(node, "        ", buffer);
+		xmldoc_parse_enumlist(node, optiontabs, buffer);
 
 		node = node->AST_XML_NEXT;	
 	}
@@ -4290,9 +4280,11 @@
 /*! \internal
  *  \brief Parse an <optionlist> element from the xml documentation.
  *  \param fixnode Pointer to the optionlist xml node.
+ *  \param tabs A string to be appended at the begining of each line being added to the
+ *              buffer string. 
  *  \param buffer Output buffer to put what is inside the optionlist tag.
  */
-static void xmldoc_parse_optionlist(ast_xml_node *fixnode, struct ast_str **buffer)
+static void xmldoc_parse_optionlist(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
 {
 	ast_xml_node *node = fixnode;
 	ast_xml_attr *optname;
@@ -4323,28 +4315,31 @@
 			continue;
 		}
 
-		ast_str_append(buffer, 0, "    %s: ", optionsyntax);
-
-		if (!xmldoc_parse_option(node, buffer)) {
+		ast_str_append(buffer, 0, "%s%s: ", tabs, optionsyntax);
+
+		if (!xmldoc_parse_option(node, tabs, buffer)) {
 			ast_str_append(buffer, 0, "\n");
 		}
 
 		node = node->AST_XML_NEXT;
 	}
-
-	return;
 }
 
 /*! \internal
  *  \brief Parse a 'parameter' tag inside a syntax element.
  *  \param fixnode A pointer to the 'parameter' xml node.
+ *  \param tabs A string to be appended at the beginning of each line being printed inside
+ *              'buffer'.
  *  \param buffer String buffer to put values found inside the parameter element.
  */
-static void xmldoc_parse_parameter(ast_xml_node *fixnode, struct ast_str **buffer)
+static void xmldoc_parse_parameter(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
 {
 	ast_xml_attr *paramname;
 	ast_xml_node *node = fixnode;
 	int hasarguments, printed = 0;
+	char *internaltabs;
+	
+	ast_asprintf(&internaltabs, "%s    ", tabs);
 
 	if (!node || !node->AST_XML_CHILD || strcasecmp((char *)node->AST_XML_NAME, "parameter")) {
 		return;
@@ -4366,11 +4361,11 @@
 	node = node->AST_XML_CHILD;
 	while (node) {
 		if (!strcasecmp((char *)node->AST_XML_NAME, "optionlist")) {
-			xmldoc_parse_optionlist(node, buffer);
+			xmldoc_parse_optionlist(node, internaltabs, buffer);
 		} else if (!strcasecmp((char *)node->AST_XML_NAME, "enumlist")) {
-			xmldoc_parse_enumlist(node, "    ", buffer);
+			xmldoc_parse_enumlist(node, internaltabs, buffer);
 		} else if (!strcasecmp((char *)node->AST_XML_NAME, "argument")) {
-			xmldoc_parse_argument(node, 1, "    ", (!hasarguments ? "        " : ""), buffer);
+			xmldoc_parse_argument(node, 1, internaltabs, (!hasarguments ? "        " : ""), buffer);
 		} else if (!strcasecmp((char *)node->AST_XML_NAME, "para")) {
 			if (!printed) {
 				if (paramname) {
@@ -4381,10 +4376,10 @@
 					return;
 				}		
 			}	
-			xmldoc_parse_para(node, "    ", "\n", buffer);
+			xmldoc_parse_para(node, internaltabs, "\n", buffer);
 			node = node->AST_XML_NEXT;
 			continue;
-		} else if ((xmldoc_parse_specialtags(node, "    ", "\n", buffer))) {
+		} else if ((xmldoc_parse_specialtags(node, internaltabs, "\n", buffer))) {
 			node = node->AST_XML_NEXT;
 			continue;
 		}
@@ -4435,7 +4430,7 @@
 
 	node = node->AST_XML_CHILD;
 	while (node) {
-		xmldoc_parse_parameter(node, &ret);
+		xmldoc_parse_parameter(node, "", &ret);
 		node = node->AST_XML_NEXT;
 	}
 




More information about the asterisk-commits mailing list