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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 13 15:05:09 CDT 2008


Author: eliel
Date: Wed Aug 13 15:05:08 2008
New Revision: 137495

URL: http://svn.digium.com/view/asterisk?view=rev&rev=137495
Log:
Implement xmldoc_string_cleanup() to remove \\t && '' && \\r after a \\n.
And skip blanks at the beginning.


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=137495&r1=137494&r2=137495
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Wed Aug 13 15:05:08 2008
@@ -2796,6 +2796,51 @@
 #ifdef XML_DOCUMENTATION
 
 /*! \internal
+ *  \brief Cleanup spaces and tabs after a \n.
+ *  \param text String to be cleaned up.
+ *  \retval NULL on error.
+ *  \retval A malloc'ed string with the output.
+ */
+static char *xmldoc_string_cleanup(const char *text)
+{
+	int retlen=0, c;
+	char *rettmp, *rettext, *tmp;
+
+	/* Alloc a buffer of at least the same size as 'text' */
+	if (!text || !(rettmp = calloc(1, strlen(text) + 1))) {
+		return NULL;
+	}
+
+	tmp = ast_skip_blanks(text);
+	while (*tmp) {
+		if (*tmp == '\n' || *tmp == '\r') {
+			tmp++;
+			c = 0;
+			while (*tmp == ' ' || *tmp == '\t' || *tmp == '\r' || *tmp == '\n') {
+				tmp++, c++;
+			}
+			if (c) {
+				rettmp[retlen++] = ' ';
+			}
+			continue;
+		} else {
+			rettmp[retlen++] = *tmp;
+		}
+		tmp++;
+	}
+
+	if (!(rettext = ast_malloc(retlen + 1))) {
+		ast_free(rettmp);
+		return NULL;
+	}
+
+	strcpy(rettext, rettmp);
+	ast_free(rettmp);
+
+	return rettext;
+}
+
+/*! \internal
  *  \brief Get the application/function node for 'name' application/function with language 'language'
  *         if we don't find any, get the first application with 'name' no matter which language with.
  *  \param doc XML documentation tree structure.
@@ -3081,6 +3126,7 @@
 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;
 
 	if (!node || !node->AST_XML_CHILD) {
 		return 0;
@@ -3094,7 +3140,10 @@
 	tmptext = ast_xml_get_text(node);
 	if (tmptext) {
 		*buffer = ast_realloc(*buffer, *len + strlen(tmptext) + strlen(tabs) + strlen(posttabs) + 1);
-		*len += sprintf(*buffer + *len, "%s%s%s", tabs, tmptext, posttabs);
+		/* Strip \n etc. */
+		cleantext = xmldoc_string_cleanup(tmptext);
+		*len += sprintf(*buffer + *len, "%s%s%s", tabs, cleantext, posttabs);
+		ast_free(cleantext);
 		ast_xml_free_text(tmptext);
 	}
 
@@ -3213,7 +3262,7 @@
 static char *xmldoc_get_formatted(ast_xml_node *node, int raw_output)
 {
 	ast_xml_node *tmp;
-	char *ret = NULL;
+	char *ret = NULL, *notcleanret;
 	int len = 0;
 
 	if (!node || !node->AST_XML_CHILD) {
@@ -3221,7 +3270,9 @@
 	}
 
 	if (raw_output) {
-		ret = ast_xml_get_text(node);
+		notcleanret = ast_xml_get_text(node);
+		ret = xmldoc_string_cleanup(notcleanret);
+		ast_xml_free_text(notcleanret);
 	} else {
 		tmp = node->AST_XML_CHILD;
 		while (tmp) {




More information about the asterisk-commits mailing list