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

📄 mxmldoc.c

📁 MINIXml 具有 解析、查找、生成、遍历 功能,一般不是太复杂的应用足够了。可贵的是全部实现是标准c,移植很容易。
💻 C
📖 第 1 页 / 共 5 页
字号:
		  else        	    mxmlNewText(comment, 0, buffer);#ifdef DEBUG		  fprintf(stderr, "C comment: <<<< %s >>>\n", buffer);#endif /* DEBUG */		  state = STATE_NONE;		  break;		}	    default :	        if (ch == ' ' && bufptr == buffer)		  break;	        if (bufptr < (buffer + sizeof(buffer) - 1))		  *bufptr++ = ch;		break;          }          break;      case STATE_CXX_COMMENT :		/* Inside a C++ comment */          if (ch == '\n')	  {	    state = STATE_NONE;	    *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 */	    }	    if (variable)	    {              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)	    {              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)	    {              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));	      }	    }	    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              mxmlNewText(comment, 0, buffer);#ifdef DEBUG	    fprintf(stderr, "C++ comment: <<<< %s >>>\n", buffer);#endif /* DEBUG */	  }	  else if (ch == ' ' && bufptr == buffer)	    break;	  else if (bufptr < (buffer + sizeof(buffer) - 1))	    *bufptr++ = ch;          break;      case STATE_STRING :		/* Inside a string constant */	  *bufptr++ = ch;          if (ch == '\\')	    *bufptr++ = getc(fp);	  else if (ch == '\"')	  {	    *bufptr = '\0';	    if (type)	      mxmlNewText(type, type->child != NULL, buffer);	    state = STATE_NONE;	  }          break;      case STATE_CHARACTER :		/* Inside a character constant */	  *bufptr++ = ch;          if (ch == '\\')	    *bufptr++ = getc(fp);	  else if (ch == '\'')	  {	    *bufptr = '\0';	    if (type)	      mxmlNewText(type, type->child != NULL, buffer);	    state = STATE_NONE;	  }          break;      case STATE_IDENTIFIER :		/* Inside a keyword or identifier */	  if (isalnum(ch) || ch == '_' || ch == '[' || ch == ']' ||	      (ch == ',' && (parens > 1 || (type && !enumeration && !function))) ||	      ch == ':' || ch == '.' || ch == '~')	  {	    if (bufptr < (buffer + sizeof(buffer) - 1))	      *bufptr++ = ch;	  }	  else	  {	    ungetc(ch, fp);	    *bufptr = '\0';	    state   = STATE_NONE;#ifdef DEBUG            fprintf(stderr, "    braces=%d, type=%p, type->child=%p, buffer=\"%s\"\n",	            braces, type, type ? type->child : NULL, buffer);#endif /* DEBUG */            if (!braces)	    {	      if (!type || !type->child)	      {		if (!strcmp(tree->value.element.name, "class"))		{		  if (!strcmp(buffer, "public") ||	              !strcmp(buffer, "public:"))		  {		    scope = "public";#ifdef DEBUG		    fputs("    scope = public\n", stderr);#endif /* DEBUG */		    break;		  }		  else if (!strcmp(buffer, "private") ||	                   !strcmp(buffer, "private:"))		  {		    scope = "private";#ifdef DEBUG		    fputs("    scope = private\n", stderr);#endif /* DEBUG */		    break;		  }		  else if (!strcmp(buffer, "protected") ||	                   !strcmp(buffer, "protected:"))		  {		    scope = "protected";#ifdef DEBUG		    fputs("    scope = protected\n", stderr);#endif /* DEBUG */		    break;		  }		}	      }	      if (!type)                type = mxmlNewElement(MXML_NO_PARENT, "type");#ifdef DEBUG              fprintf(stderr, "    function=%p (%s), type->child=%p, ch='%c', parens=%d\n",	              function,		      function ? mxmlElementGetAttr(function, "name") : "null",	              type->child, ch, parens);#endif /* DEBUG */              if (!function && ch == '(')	      {	        if (type->child &&		    !strcmp(type->child->value.text.string, "extern"))		{		 /*		  * Remove external declarations...		  */		  mxmlDelete(type);		  type = NULL;		  break;		}	        if (type->child &&		    !strcmp(type->child->value.text.string, "static") &&		    !strcmp(tree->value.element.name, "mxmldoc"))		{		 /*		  * Remove static functions...		  */		  mxmlDelete(type);		  type = NULL;		  break;		}	        function = mxmlNewElement(MXML_NO_PARENT, "function");		if ((bufptr = strchr(buffer, ':')) != NULL && bufptr[1] == ':')		{		  *bufptr = '\0';		  bufptr += 2;		  if ((fstructclass =		           mxmlFindElement(tree, tree, "class", "name", buffer,		                           MXML_DESCEND_FIRST)) == NULL)		    fstructclass =		        mxmlFindElement(tree, tree, "struct", "name", buffer,		                        MXML_DESCEND_FIRST);		}		else		  bufptr = buffer;		mxmlElementSetAttr(function, "name", bufptr);		if (scope)		  mxmlElementSetAttr(function, "scope", scope);#ifdef DEBUG                fprintf(stderr, "function: %s\n", buffer);		fprintf(stderr, "    scope = %s\n", scope ? scope : "(null)");		fprintf(stderr, "    comment = %p\n", comment);		fprintf(stderr, "    child = (%p) %s\n",		        comment->child,			comment->child ?			    comment->child->value.text.string : "(null)");		fprintf(stderr, "    last_child = (%p) %s\n",		        comment->last_child,			comment->last_child ?			    comment->last_child->value.text.string : "(null)");#endif /* DEBUG */                if (type->last_child &&		    strcmp(type->last_child->value.text.string, "void"))		{                  returnvalue = mxmlNewElement(function, "returnvalue");		  mxmlAdd(returnvalue, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type);		  description = mxmlNewElement(returnvalue, "description");#ifdef DEBUG		  fputs("    adding comment to returnvalue...\n", stderr);#endif /* DEBUG */		  update_comment(returnvalue, comment->last_child);		  mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,		          comment->last_child);                }		else		  mxmlDelete(type);		description = mxmlNewElement(function, "description");#ifdef DEBUG		  fputs("    adding comment to function...\n", stderr);#endif /* DEBUG */		update_comment(function, comment->last_child);		mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,		        comment->last_child);		type = NULL;	      }	      else if (function && ((ch == ')' && parens == 1) || ch == ','))	      {	       /*	        * Argument definition...		*/                if (strcmp(buffer, "void"))		{	          mxmlNewText(type, type->child != NULL &&		                    type->last_child->value.text.string[0] != '(' &&				    type->last_child->value.text.string[0] != '*',			      buffer);#ifdef DEBUG                  fprintf(stderr, "Argument: <<<< %s >>>\n", buffer);#endif /* DEBUG */	          variable = add_variable(function, "argument", type);		}		else		  mxmlDelete(type);		type = NULL;	      }              else if (type->child && !function && (ch == ';' || ch == ','))	      {#ifdef DEBUG	        fprintf(stderr, "    got semicolon, typedefnode=%p, structclass=%p\n",		        typedefnode, structclass);#endif /* DEBUG */	        if (typedefnode || structclass)		{#ifdef DEBUG                  fprintf(stderr, "Typedef/struct/class: <<<< %s >>>>\n", buffer);#endif /* DEBUG */		  if (typedefnode)		  {		    mxmlElementSetAttr(typedefnode, "name", buffer);                    sort_node(tree, typedefnode);		  }		  if (structclass && !mxmlElementGetAttr(structclass, "name"))		  {#ifdef DEBUG		    fprintf(stderr, "setting struct/class name to %s!\n",		            type->last_child->value.text.string);#endif /* DEBUG */		    mxmlElementSetAttr(structclass, "name", buffer);		    sort_node(tree, structclass);		    structclass = NULL;		  }		  if (typedefnode)		    mxmlAdd(typedefnode, MXML_ADD_BEFORE, MXML_ADD_TO_PARENT,		            type);                  else		    mxmlDelete(type);		  type        = NULL;		  typedefnode = NULL;		}		else if (type->child &&		         !strcmp(type->child->value.text.string, "typedef"))		{		 /*		  * Simple typedef...		  */#ifdef DEBUG                  fprintf(stderr, "Typedef: <<<< %s >>>\n", buffer);#endif /* DEBUG */		  typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef");		  mxmlElementSetAttr(typedefnode, "name", buffer);		  mxmlDelete(type->child);                  sort_node(tree, typedefnode);                  if (type->child)		    type->child->value.text.whitespace = 0;		  mxmlAdd(typedefnode, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type);		  type = NULL;		}		else if (!parens)		{		 /*	          * Variable definition...		  */	          if (type->child &&		      !strcmp(type->child->value.text.string, "static") &&		      !strcmp(tree->value.element.name, "mxmldoc"))		  {		   /*		    * Remove static functions...		    */		    mxmlDelete(type);		    type = NULL;		    break;		  }	          mxmlNewText(type, type->child != NULL &&		                    type->last_child->value.text.string[0] != '(' &&				    type->last_child->value.text.string[0] != '*',			      buffer);#ifdef DEBUG                  fprintf(stderr, "Variable: <<<< %s >>>>\n", buffer);                  fprintf(stderr, "    scope = %s\n", scope ? scope : "(null)");#endif /* DEBUG */	          variable = add_variable(MXML_NO_PARENT, "variable", type);		  type     = NULL;		  sort_node(tree, variable);		  if (scope)		    mxmlElementSetAttr(variable, "scope", scope);		}              }	      else              {#ifdef DEBUG                fprintf(stderr, "Identifier: <<<< %s >>>>\n", buffer);#endif /* DEBUG */	        mxmlNewText(type, type->child != NULL &&		                  type->last_child->value.text.string[0] != '(' &&				  type->last_child->value.text.string[0] != '*',			    buffer);	      }	    }	    else if (enumeration && !isdigit(buffer[0] & 255))	    {#ifdef DEBUG	      fprintf(stderr, "Constant: <<<< %s >>>\n", buffer);#endif /* DEBUG */	      constant = mxmlNewElement(MXML_NO_PARENT, "constant");	      mxmlElementSetAttr(constant, "name", buffer);	      sort_node(enumeration, constant);	    }	    else if (type)	    {	      mxmlDelete(type);	      type = NULL;	    }	  }          break;    }#if DEBUG > 1    if (state != oldstate)    {      fprintf(stderr, "    changed states from %s to %s on receipt of character '%c'...\n",              states[oldstate], states[state], oldch);      fprintf(stderr, "    variable = %p\n", variable);      if (type)      {        fputs("    type =", stderr);        for (temp = type->child; temp; temp = temp->next)	  fprintf(stderr, " \"%s\"", temp->value.text.string);	fputs("\n", stderr);      }    }#endif /* DEBUG > 1 */  }  mxmlDelete(comment); /*  * All done, return with no errors...  */  return (0);}/* * 'sort_node()' - Insert a node sorted into a tree. */static voidsort_node(mxml_node_t *tree,		/* I - Tree to sort into */          mxml_node_t *node)		/* I - Node to add */{  mxml_node_t	*temp;			/* Current node */  const char	*tempname,		/* Name of current node */		*nodename,		/* Name of node */		*scope;			/* Scope */#if DEBUG > 1  fprintf(stderr, "    sort_node(tree=%p, node=%p)\n", tree, node);#endif /* DEBUG > 1 */ /*  * Range check input...  */  if (!tree || !node || node->parent == tree)    return; /*  * Get the node name...  */  if ((nodename = mxmlElementGetAttr(node, "name")) == NULL)    return;  if (nodename[0] == '_')    return;				/* Hide private names */#if DEBUG > 1  fprintf(stderr, "        nodename=%p (\"%s\")\n", nodename, nodename);#endif /* DEBUG > 1 */ /*  * Delete any existing definition at this level, if one exists...  */

⌨️ 快捷键说明

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