[svn-commits] eliel: branch group/appdocsxml r151325 - /team/group/appdocsxml/main/pbx.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Oct 20 19:03:50 CDT 2008


Author: eliel
Date: Mon Oct 20 19:03:50 2008
New Revision: 151325

URL: http://svn.digium.com/view/asterisk?view=rev&rev=151325
Log:
Fixes pointed by russellb on the reviewboard.
 - Move every:
	 while (node) { 
		... ;
		node = node->AST_XML_NEXT; 
	}
   to:  for (node = ... ; node; node = node->AST_XML_NEXT) { }
   Making the code more readable.

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=151325&r1=151324&r2=151325
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Mon Oct 20 19:03:50 2008
@@ -3410,7 +3410,7 @@
  */
 static void xmldoc_string_cleanup(const char *text, struct ast_str **output, int lastspaces)
 {
-	char *tmp;
+	int i;
 
 	*output = ast_str_create(1);
 	if (!(*output)) {
@@ -3418,19 +3418,16 @@
 		return;
 	}
 
-	tmp = (char *)text;
-	while (*tmp) {
-		if (*tmp == '\n' || *tmp == '\r') {
-			tmp++;
-			while (*tmp == '\t' || *tmp == '\r' || *tmp == '\n') {
-				tmp++;
+	for (i = 0; i < strlen(text); i++) {
+		if (text[i] == '\n' || text[i] == '\r') {
+			while (text[i+1] == '\t' || text[i+1] == '\r' || text[i+1] == '\n') {
+				i++;
 			}
 			ast_str_append(output, 0, " ");
 			continue;
 		} else {
-			ast_str_append(output, 0, "%c", *tmp);
-		}
-		tmp++;
+			ast_str_append(output, 0, "%c", text[i]);
+		}
 	}
 	/* remove last spaces (we dont want always to remove the trailing spaces). */
 	if (lastspaces) {
@@ -3460,7 +3457,6 @@
 	AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) {
 		/* the core xml documents have priority over thirdparty document. */
 		node = ast_xml_get_root(doctree->doc);
-		node = node->AST_XML_CHILD;
 		while (node) {
 			node = ast_xml_find_element(node, type, "name", name);
 			if (node) {
@@ -3472,7 +3468,6 @@
 				} else if (lang) {
 					ast_xml_free_attr(lang);
 				}
-				node = node->AST_XML_NEXT;
 			}
 		}
 		if (!node || !node->AST_XML_CHILD) {
@@ -3553,12 +3548,10 @@
 {
 	ast_xml_node *node = fixnode;
 
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (!strcasecmp((char *)node->AST_XML_NAME, "argument")) {
 			return 1;
 		}
-		node = node->AST_XML_NEXT;
 	}
 	return 0;
 }
@@ -3606,10 +3599,8 @@
 	}
 
 	/* Get order of evaluation. */
-	node = rootnode->AST_XML_CHILD;
-	while (node) {
+	for (node = rootnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (strcasecmp((char *)node->AST_XML_NAME, childname)) {
-			node = node->AST_XML_NEXT;
 			continue;
 		}
 		required = 0;
@@ -3629,7 +3620,6 @@
 			firstparam = node;
 			reqfinode = required;
 		}
-		node = node->AST_XML_NEXT;
 	}
 
 	if (!hasparams) {
@@ -3640,10 +3630,8 @@
 
 	if (reqfinode && reqlanode) {
 		/* check midnode */
-		node = rootnode->AST_XML_CHILD;
-		while (node) {
+		for (node = rootnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 			if (strcasecmp((char *)node->AST_XML_NAME, childname)) {
-				node = node->AST_XML_NEXT;
 				continue;
 			}
 			if (node != firstparam && node != lastparam) {
@@ -3655,7 +3643,6 @@
 					ast_xml_free_attr(paramtype);
 				}
 			}
-			node = node->AST_XML_NEXT;
 		}
 	}
 
@@ -3674,9 +3661,8 @@
 		xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", (printrootname ? rootname : ""), (printrootname ? "(" : ""));
 	}
 
-	while (node) {
+	for (; node; node = GOTONEXT(reverse, node)) {
 		if (strcasecmp((char *)node->AST_XML_NAME, childname)) {
-			node = GOTONEXT(reverse, node);
 			continue;
 		}
 
@@ -3764,7 +3750,6 @@
 			ast_xml_free_attr(paramname);
 		}
 
-		node = GOTONEXT(reverse, node);
 		paramcount++;
 	}
 
@@ -3803,12 +3788,10 @@
 		return NULL;
 	}
 
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (!strcasecmp((char *)node->AST_XML_NAME, "syntax")) {
 			break;
 		}
-		node = node->AST_XML_NEXT;
 	}
 
 	if (node) {
@@ -3848,8 +3831,7 @@
 
 	ret = 1;
 
-	tmp = node->AST_XML_CHILD;
-	while (tmp) {
+	for (tmp = node->AST_XML_CHILD; tmp; tmp = tmp->AST_XML_NEXT) {
 		/* Get the text inside the <para> element and append it to buffer. */
 		tmptext = ast_xml_get_text(tmp);
 		if (tmptext) {
@@ -3866,7 +3848,6 @@
 				ret = 2;
 			}
 		}
-		tmp = tmp->AST_XML_NEXT;
 	}
 
 	ast_str_append(buffer, 0, "%s", posttabs);
@@ -3904,13 +3885,11 @@
 			}
 
 			/* parse <para> elements inside special tags. */
-			node = node->AST_XML_CHILD;
-			while (node) {
+			for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 				/* 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;
 			}
 
 			if (strlen(special_tags[i].end) > 0) {
@@ -3949,8 +3928,7 @@
 		ast_str_append(buffer, 0, "%s%s%s", tabs, argname, (insideparameter ? "\n" : ""));
 		ast_xml_free_attr(argname);
 
-		node = node->AST_XML_CHILD;
-		while (node) {
+		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;
@@ -3958,7 +3936,6 @@
 				count++;
 				ret = 1;
 			}
-			node = node->AST_XML_NEXT;
 		}
 	}
 
@@ -3984,15 +3961,12 @@
 	struct ast_str *cleanstr = NULL;
 	int ret = 0, printedpara=0;
 
-	tmp = node->AST_XML_CHILD;
-	while (tmp) {
+	for (tmp = node->AST_XML_CHILD; tmp; tmp = tmp->AST_XML_NEXT) {
 		if (xmldoc_parse_para(tmp, (ret ? tabs : ""), "\n", buffer)) {
 			printedpara = 1;
-			tmp = tmp->AST_XML_NEXT;
 			continue;
 		} else if (xmldoc_parse_specialtags(tmp, (ret ? tabs : ""), "\n", buffer)) {
 			printedpara = 1;
-			tmp = tmp->AST_XML_NEXT;
 			continue;
 		}
 
@@ -4021,7 +3995,6 @@
 			}
 			ast_str_append(buffer, 0, "\n");
 		}
-		tmp = tmp->AST_XML_NEXT;
 	}
 
 	return ret;
@@ -4056,16 +4029,14 @@
 	/* use this spacing (add 4 spaces) inside a variablelist node. */
 	ast_asprintf(&vartabs, "%s    ", tabs);
 
-	tmp = node->AST_XML_CHILD;
-	while (tmp) {
+	for (tmp = node->AST_XML_CHILD; tmp; tmp = tmp->AST_XML_NEXT) {
 		/* We can have a <para> element inside the variable list */
 		if ((xmldoc_parse_para(tmp, (ret ? tabs : ""), "\n", buffer))) {
 			ret = 1;
-			tmp = tmp->AST_XML_NEXT;
 			continue;
 		} else if ((xmldoc_parse_specialtags(tmp, (ret ? tabs : ""), "\n", buffer))) {
 			ret = 1;
-			tmp = tmp->AST_XML_NEXT;
+			continue;
 		}
 
 		if (!strcasecmp((char *)tmp->AST_XML_NAME, "variable")) {
@@ -4079,7 +4050,6 @@
 				ret = 1;
 			}
 		}
-		tmp = tmp->AST_XML_NEXT;
 	}
 
 	ast_free(vartabs);
@@ -4112,12 +4082,10 @@
 	}
 
 	/* Find the <see-also> node. */
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (!strcasecmp((char *)node->AST_XML_NAME, "see-also")) {
 			break;
 		}
-		node = node->AST_XML_NEXT;
 	}
 
 	if (!node || !node->AST_XML_CHILD) {
@@ -4132,10 +4100,8 @@
 	}
 
 	/* get into the <see-also> node. */
-	node = node->AST_XML_CHILD;
-	while (node) {	
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (strcasecmp((char *)node->AST_XML_NAME, "ref")) {
-			node = node->AST_XML_NEXT;
 			continue;
 		}
 
@@ -4158,7 +4124,6 @@
 			}
 			ast_xml_free_attr(typename);
 		}
-		node = node->AST_XML_NEXT;
 	}
 
 	output = ast_strdup(outputstr->str);
@@ -4179,14 +4144,12 @@
 	ast_xml_node *node = fixnode;
 	int ret = 0;
 
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if ((xmldoc_parse_para(node, (ret ? tabs : " - "), "\n", buffer))) {
 			ret = 1;
 		} else if ((xmldoc_parse_specialtags(node, (ret ? tabs : " - "), "\n", buffer))) {
 			ret = 1;
 		}
-		node = node->AST_XML_NEXT;
 	}
 	return ret;
 }
@@ -4204,10 +4167,8 @@
 	ast_xml_attr *enumname;
 	int ret = 0;
 
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (strcasecmp((char *)node->AST_XML_NAME, "enum")) {
-			node = node->AST_XML_NEXT;
 			continue;
 		}
 
@@ -4223,7 +4184,6 @@
 				ast_str_append(buffer, 0, "\n");
 			}
 		}
-		node = node->AST_XML_NEXT;
 	}
 	return ret;
 }
@@ -4239,14 +4199,13 @@
  */
 static int xmldoc_parse_option(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
 {
-	ast_xml_node *node = fixnode;
+	ast_xml_node *node;
 	int ret = 0;
 	char *optiontabs;
 
 	ast_asprintf(&optiontabs, "%s    ", tabs);
 
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (!strcasecmp((char *)node->AST_XML_NAME, "argument")) {
 			/* if this is the first data appended to buffer, print a \n*/
 			if (!ret && node->AST_XML_CHILD) {
@@ -4256,7 +4215,6 @@
 			if (xmldoc_parse_argument(node, 0, NULL, optiontabs, buffer)) {
 				ret = 1;
 			}
-			node = node->AST_XML_NEXT;
 			continue;
 		}
 
@@ -4269,8 +4227,6 @@
 		xmldoc_parse_variablelist(node, optiontabs, buffer);
 
 		xmldoc_parse_enumlist(node, optiontabs, buffer);
-
-		node = node->AST_XML_NEXT;
 	}
 	ast_free(optiontabs);
 
@@ -4286,28 +4242,24 @@
  */
 static void xmldoc_parse_optionlist(ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
 {
-	ast_xml_node *node = fixnode;
+	ast_xml_node *node;
 	ast_xml_attr *optname;
 	char *optionsyntax;
 
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = fixnode->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		/* Start appending every option tag. */
 		if (strcasecmp((char *)node->AST_XML_NAME, "option")) {
-			node = node->AST_XML_NEXT;
 			continue;
 		}
 
 		/* Get the option name. */
 		optname = ast_xml_get_attribute(node, "name");
 		if (!optname) {
-			node = node->AST_XML_NEXT;
 			continue;
 		}
 
 		optionsyntax = xmldoc_build_syntax(node, optname, "argument", 0, 1);
 		if (!optionsyntax) {
-			node = node->AST_XML_NEXT;
 			continue;
 		}
 
@@ -4316,8 +4268,6 @@
 		if (!xmldoc_parse_option(node, tabs, buffer)) {
 			ast_str_append(buffer, 0, "\n");
 		}
-
-		node = node->AST_XML_NEXT;
 	}
 }
 
@@ -4353,8 +4303,7 @@
 
 	ast_asprintf(&internaltabs, "%s    ", tabs);
 
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (!strcasecmp((char *)node->AST_XML_NAME, "optionlist")) {
 			xmldoc_parse_optionlist(node, internaltabs, buffer);
 		} else if (!strcasecmp((char *)node->AST_XML_NAME, "enumlist")) {
@@ -4368,13 +4317,10 @@
 				printed = 1;
 			}
 			xmldoc_parse_para(node, internaltabs, "\n", buffer);
-			node = node->AST_XML_NEXT;
 			continue;
 		} else if ((xmldoc_parse_specialtags(node, internaltabs, "\n", buffer))) {
-			node = node->AST_XML_NEXT;
 			continue;
 		}
-		node = node->AST_XML_NEXT;
 	}
 	ast_free(internaltabs);
 }
@@ -4404,12 +4350,10 @@
 	}
 
 	/* Find the syntax field. */
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		if (!strcasecmp((char *)node->AST_XML_NAME, "syntax")) {
 			break;
 		}
-		node = node->AST_XML_NEXT;
 	}
 
 	if (!node || !node->AST_XML_CHILD) {
@@ -4417,10 +4361,8 @@
 		return NULL;
 	}
 
-	node = node->AST_XML_CHILD;
-	while (node) {
+	for (node = node->AST_XML_CHILD; node; node = node->AST_XML_NEXT) {
 		xmldoc_parse_parameter(node, "", &ret);
-		node = node->AST_XML_NEXT;
 	}
 
 	if (ret->used > 0) {
@@ -4457,20 +4399,16 @@
 		xmldoc_string_cleanup(ast_skip_blanks(notcleanret), &ret, 0);
 		ast_xml_free_text(tmpstr);
 	} else {
-		tmp = node->AST_XML_CHILD;
-		while (tmp) {
+		for (tmp = node->AST_XML_CHILD; tmp; tmp = tmp->AST_XML_NEXT) {
 			/* if found, parse a <para> element. */
 			if (xmldoc_parse_para(tmp, "", "\n", &ret)) {
-				tmp = tmp->AST_XML_NEXT;
 				continue;
 			} else if (xmldoc_parse_specialtags(tmp, "", "\n", &ret)) {
-				tmp = tmp->AST_XML_NEXT;
 				continue;
 			}
 			/* if found, parse a <variablelist> element. */
 			xmldoc_parse_variablelist(tmp, "", &ret);
 			xmldoc_parse_enumlist(tmp, "    ", &ret);
-			tmp = tmp->AST_XML_NEXT;
 		}
 		/* remove last '\n' */
 		if (ret->str[ret->used-1] == '\n') {




More information about the svn-commits mailing list