⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mxmldoc.c

📁 适用于嵌入式系统的XML解析库, 规模比libxml2小得多.
💻 C
📖 第 1 页 / 共 5 页
字号:
		                comment->last_child->value.text.string);		    description = mxmlNewElement(typedefnode, "description");#ifdef DEBUG		    fputs("    duplicating comment for typedef...\n", stderr);#endif /* DEBUG */		    update_comment(typedefnode, comment->last_child);		    mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,		            comment->last_child);		  }		  description = mxmlNewElement(structclass, "description");#ifdef DEBUG		  fprintf(stderr, "    adding comment to %s...\n",		          structclass->value.element.name);#endif /* DEBUG */		  update_comment(structclass, comment->last_child);		  mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,		          comment->last_child);                  if (scan_file(filename, fp, structclass))		  {		    mxmlDelete(comment);		    return (-1);		  }#ifdef DEBUG                  fputs("    ended typedef...\n", stderr);#endif /* DEBUG */                  structclass = NULL;                  break;                }		else if (type && type->child && type->child->next &&		         (!strcmp(type->child->value.text.string, "enum") ||			  (!strcmp(type->child->value.text.string, "typedef") &&			   !strcmp(type->child->next->value.text.string, "enum"))))                {		 /*		  * Enumeration type...		  */		  if (!strcmp(type->child->value.text.string, "typedef"))		  {#ifdef DEBUG                    fputs("    starting typedef...\n", stderr);#endif /* DEBUG */		    typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef");		    mxmlDelete(type->child);		  }		  else		    typedefnode = NULL;			  enumeration = mxmlNewElement(MXML_NO_PARENT, "enumeration");#ifdef DEBUG                  fprintf(stderr, "Enumeration: <<<< %s >>>\n",			  type->child->next ?			      type->child->next->value.text.string : "(noname)");#endif /* DEBUG */                  if (type->child->next)		  {		    mxmlElementSetAttr(enumeration, "name",		                       type->child->next->value.text.string);		    sort_node(tree, enumeration);		  }                  if (typedefnode && type->child)		    type->child->value.text.whitespace = 0;                  else		  {		    mxmlDelete(type);		    type = NULL;		  }		  if (typedefnode && comment->last_child)		  {		   /*		    * Copy comment for typedef as well as class/struct/union...		    */		    mxmlNewText(comment, 0,		                comment->last_child->value.text.string);		    description = mxmlNewElement(typedefnode, "description");#ifdef DEBUG		    fputs("    duplicating comment for typedef...\n", stderr);#endif /* DEBUG */		    update_comment(typedefnode, comment->last_child);		    mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,		            comment->last_child);		  }		  description = mxmlNewElement(enumeration, "description");#ifdef DEBUG		  fputs("    adding comment to enumeration...\n", stderr);#endif /* DEBUG */		  update_comment(enumeration, comment->last_child);		  mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,		          comment->last_child);		}		else if (type && type->child &&		         !strcmp(type->child->value.text.string, "extern"))                {                  if (scan_file(filename, fp, tree))		  {		    mxmlDelete(comment);		    return (-1);		  }                }		else if (type)		{		  mxmlDelete(type);		  type = NULL;		}	        braces ++;		function = NULL;		variable = NULL;		break;            case '}' :#ifdef DEBUG	        fputs("    close brace...\n", stderr);#endif /* DEBUG */                if (structclass)		  scope = NULL;                enumeration = NULL;		constant    = NULL;		structclass = NULL;	        if (braces > 0)		  braces --;		else		{		  mxmlDelete(comment);		  return (0);		}		break;            case '(' :		if (type)		{#ifdef DEBUG                  fputs("Identifier: <<<< ( >>>\n", stderr);#endif /* DEBUG */		  mxmlNewText(type, 0, "(");		}	        parens ++;		break;            case ')' :		if (type && parens)		{#ifdef DEBUG                  fputs("Identifier: <<<< ) >>>\n", stderr);#endif /* DEBUG */		  mxmlNewText(type, 0, ")");		}                if (function && type && !parens)		{		 /*		  * Check for "void" argument...		  */		  if (type->child && type->child->next)		    variable = add_variable(function, "argument", type);		  else		    mxmlDelete(type);		  type = NULL;		}	        if (parens > 0)		  parens --;		break;	    case ';' :#ifdef DEBUG                fputs("Identifier: <<<< ; >>>\n", stderr);		fprintf(stderr, "    function=%p, type=%p\n", function, type);#endif /* DEBUG */	        if (function)		{		  if (!strcmp(tree->value.element.name, "class"))		  {#ifdef DEBUG		    fputs("    ADDING FUNCTION TO CLASS\n", stderr);#endif /* DEBUG */		    sort_node(tree, function);		  }		  else		    mxmlDelete(function);		  function = NULL;		  variable = NULL;		}		if (type)		{		 /*		  * See if we have a function typedef...		  */		  if (type->child &&		      !strcmp(type->child->value.text.string, "typedef"))		  {		   /*		    * Yes, add it!		    */		    typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef");		    for (node = type->child->next; node; node = node->next)		      if (!strcmp(node->value.text.string, "("))			break;                    if (node)		    {		      for (node = node->next; node; node = node->next)			if (strcmp(node->value.text.string, "*"))			  break;                    }                    if (node)		    {		      mxmlElementSetAttr(typedefnode, "name",		                         node->value.text.string);                      sort_node(tree, typedefnode);		      mxmlDelete(type->child);		      mxmlDelete(node);                      if (type->child)			type->child->value.text.whitespace = 0;		      mxmlAdd(typedefnode, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,		              type);		      type = NULL;		      break;		    }		  }		  		  mxmlDelete(type);		  type = NULL;		}		break;	    case ':' :		if (type)		{#ifdef DEBUG                  fputs("Identifier: <<<< : >>>\n", stderr);#endif /* DEBUG */		  mxmlNewText(type, 1, ":");		}		break;	    case '*' :		if (type)		{#ifdef DEBUG                  fputs("Identifier: <<<< * >>>\n", stderr);#endif /* DEBUG */                  ch = type->last_child->value.text.string[0];		  mxmlNewText(type, isalnum(ch) || ch == '_', "*");		}		break;	    case ',' :		if (type && !enumeration)		{#ifdef DEBUG                  fputs("Identifier: <<<< , >>>\n", stderr);#endif /* DEBUG */		  mxmlNewText(type, 0, ",");		}		break;	    case '&' :		if (type)		{#ifdef DEBUG                  fputs("Identifier: <<<< & >>>\n", stderr);#endif /* DEBUG */		  mxmlNewText(type, 1, "&");		}		break;	    case '+' :		if (type)		{#ifdef DEBUG                  fputs("Identifier: <<<< + >>>\n", stderr);#endif /* DEBUG */                  ch = type->last_child->value.text.string[0];		  mxmlNewText(type, isalnum(ch) || ch == '_', "+");		}		break;	    case '-' :		if (type)		{#ifdef DEBUG                  fputs("Identifier: <<<< - >>>\n", stderr);#endif /* DEBUG */                  ch = type->last_child->value.text.string[0];		  mxmlNewText(type, isalnum(ch) || ch == '_', "-");		}		break;	    case '=' :		if (type)		{#ifdef DEBUG                  fputs("Identifier: <<<< = >>>\n", stderr);#endif /* DEBUG */                  ch = type->last_child->value.text.string[0];		  mxmlNewText(type, isalnum(ch) || ch == '_', "=");		}		break;            default :			/* Other */	        if (isalnum(ch) || ch == '_' || ch == '.' || ch == ':' || ch == '~')		{		  state     = STATE_IDENTIFIER;		  bufptr    = buffer;		  *bufptr++ = ch;		}		break;          }          break;      case STATE_PREPROCESSOR :		/* Preprocessor directive */          if (ch == '\n')	    state = STATE_NONE;	  else if (ch == '\\')	    getc(fp);          break;      case STATE_C_COMMENT :		/* Inside a C comment */          switch (ch)	  {	    case '\n' :	        while ((ch = getc(fp)) != EOF)		  if (ch == '*')		  {		    ch = getc(fp);		    if (ch == '/')		    {		      *bufptr = '\0';        	      if (comment->child != comment->last_child)		      {#ifdef DEBUG			fprintf(stderr, "    removing comment %p, last comment %p...\n",				comment->child, comment->last_child);#endif /* DEBUG */			mxmlDelete(comment->child);#ifdef DEBUG			fprintf(stderr, "    new comment %p, last comment %p...\n",				comment->child, comment->last_child);#endif /* DEBUG */		      }#ifdef DEBUG                      fprintf(stderr,		              "    processing comment, variable=%p, "		              "constant=%p, typedefnode=%p, tree=\"%s\"\n",		              variable, constant, typedefnode,			      tree->value.element.name);#endif /* DEBUG */		      if (variable)		      {		        if (strstr(buffer, "@private@"))			{			 /*			  * Delete private variables...			  */			  mxmlDelete(variable);			}			else			{			  description = mxmlNewElement(variable, "description");#ifdef DEBUG			  fputs("    adding comment to variable...\n", stderr);#endif /* DEBUG */			  update_comment(variable,					 mxmlNewText(description, 0, buffer));                        }			variable = NULL;		      }		      else if (constant)		      {		        if (strstr(buffer, "@private@"))			{			 /*			  * Delete private constants...			  */			  mxmlDelete(constant);			}			else			{			  description = mxmlNewElement(constant, "description");#ifdef DEBUG			  fputs("    adding comment to constant...\n", stderr);#endif /* DEBUG */			  update_comment(constant,					 mxmlNewText(description, 0, buffer));			}			constant = NULL;		      }		      else if (typedefnode)		      {		        if (strstr(buffer, "@private@"))			{			 /*			  * Delete private typedefs...			  */			  mxmlDelete(typedefnode);			  if (structclass)			  {			    mxmlDelete(structclass);			    structclass = NULL;			  }			  if (enumeration)			  {			    mxmlDelete(enumeration);			    enumeration = NULL;			  }			}			else			{			  description = mxmlNewElement(typedefnode, "description");#ifdef DEBUG			  fprintf(stderr, "    adding comment to typedef %s...\n",				  mxmlElementGetAttr(typedefnode, "name"));#endif /* DEBUG */			  update_comment(typedefnode,					 mxmlNewText(description, 0, buffer));			  if (structclass)			  {			    description = mxmlNewElement(structclass, "description");			    update_comment(structclass,					   mxmlNewText(description, 0, buffer));			  }			  else if (enumeration)			  {			    description = mxmlNewElement(enumeration, "description");			    update_comment(enumeration,					   mxmlNewText(description, 0, buffer));			  }			}			typedefnode = NULL;		      }		      else if (strcmp(tree->value.element.name, "mxmldoc") &&		               !mxmlFindElement(tree, tree, "description",			                        NULL, NULL, MXML_DESCEND_FIRST))                      {        		description = mxmlNewElement(tree, "description");#ifdef DEBUG			fputs("    adding comment to parent...\n", stderr);#endif /* DEBUG */			update_comment(tree,			               mxmlNewText(description, 0, buffer));		      }		      else		      {#ifdef DEBUG		        fprintf(stderr, "    before adding comment, child=%p, last_child=%p\n",			        comment->child, comment->last_child);#endif /* DEBUG */        		mxmlNewText(comment, 0, buffer);#ifdef DEBUG		        fprintf(stderr, "    after adding comment, child=%p, last_child=%p\n",			        comment->child, comment->last_child);#endif /* DEBUG */                      }#ifdef DEBUG		      fprintf(stderr, "C comment: <<<< %s >>>\n", buffer);#endif /* DEBUG */		      state = STATE_NONE;		      break;		    }		    else		      ungetc(ch, fp);		  }		  else if (ch == '\n' && bufptr > buffer &&		           bufptr < (buffer + sizeof(buffer) - 1))		    *bufptr++ = ch;		  else if (!isspace(ch))		    break;		if (ch != EOF)		  ungetc(ch, fp);                if (bufptr > buffer && bufptr < (buffer + sizeof(buffer) - 1))		  *bufptr++ = '\n';		break;	    case '/' :	        if (ch == '/' && bufptr > buffer && bufptr[-1] == '*')		{		  while (bufptr > buffer &&		         (bufptr[-1] == '*' || isspace(bufptr[-1] & 255)))		    bufptr --;		  *bufptr = '\0';        	  if (comment->child != comment->last_child)		  {#ifdef DEBUG		    fprintf(stderr, "    removing comment %p, last comment %p...\n",			    comment->child, comment->last_child);#endif /* DEBUG */		    mxmlDelete(comment->child);#ifdef DEBUG		    fprintf(stderr, "    new comment %p, last comment %p...\n",			    comment->child, comment->last_child);#endif /* DEBUG */		  }#ifdef DEBUG                  fprintf(stderr,		          "    processing comment, variable=%p, "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -