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

📄 mxmldoc.c

📁 适用于嵌入式系统的XML解析库, 规模比libxml2小得多.
💻 C
📖 第 1 页 / 共 5 页
字号:
  */  variable = mxmlNewElement(parent, name); /*  * Check for a default value...  */  for (node = type->child; node; node = node->next)    if (!strcmp(node->value.text.string, "="))      break;  if (node)  {   /*    * Default value found, copy it and add as a "default" attribute...    */    for (bufptr = buffer; node; bufptr += strlen(bufptr))    {      if (node->value.text.whitespace && bufptr > buffer)	*bufptr++ = ' ';      strcpy(bufptr, node->value.text.string);      next = node->next;      mxmlDelete(node);      node = next;    }    mxmlElementSetAttr(variable, "default", buffer);  } /*  * Extract the argument/variable name...  */  if (type->last_child->value.text.string[0] == ')')  {   /*    * Handle "type (*name)(args)"...    */    for (node = type->child; node; node = node->next)      if (node->value.text.string[0] == '(')	break;    for (bufptr = buffer; node; bufptr += strlen(bufptr))    {      if (node->value.text.whitespace && bufptr > buffer)	*bufptr++ = ' ';      strcpy(bufptr, node->value.text.string);      next = node->next;      mxmlDelete(node);      node = next;    }  }  else  {   /*    * Handle "type name"...    */    strcpy(buffer, type->last_child->value.text.string);    mxmlDelete(type->last_child);  } /*  * Set the name...  */  mxmlElementSetAttr(variable, "name", buffer); /*  * Add the remaining type information to the variable node...  */  mxmlAdd(variable, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type); /*  * Add new new variable node...  */  return (variable);}/* * 'find_public()' - Find a public function, type, etc. */static mxml_node_t *			/* I - Found node or NULL */find_public(mxml_node_t *node,		/* I - Current node */            mxml_node_t *top,		/* I - Top node */            const char  *name)		/* I - Name of element */{  mxml_node_t	*description,		/* Description node */		*comment;		/* Comment node */  for (node = mxmlFindElement(node, top, name, NULL, NULL,                              node == top ? MXML_DESCEND_FIRST :			                    MXML_NO_DESCEND);       node;       node = mxmlFindElement(node, top, name, NULL, NULL, MXML_NO_DESCEND))  {   /*    * Get the description for this node...    */    description = mxmlFindElement(node, node, "description", NULL, NULL,                                  MXML_DESCEND_FIRST);   /*    * A missing or empty description signals a private node...    */    if (!description)      continue;   /*    * Look for @private@ in the comment text...    */    for (comment = description->child; comment; comment = comment->next)      if ((comment->type == MXML_TEXT &&           strstr(comment->value.text.string, "@private@")) ||          (comment->type == MXML_OPAQUE &&           strstr(comment->value.opaque, "@private@")))        break;    if (!comment)    {     /*      * No @private@, so return this node...      */      return (node);    }  } /*  * If we get here, there are no (more) public nodes...  */  return (NULL);}/* * 'get_comment_info()' - Get info from comment. */static char *				/* O - Info from comment */get_comment_info(    mxml_node_t *description)		/* I - Description node */{  char		text[10240],		/* Description text */		since[255],		/* @since value */		*ptr;			/* Pointer into text */  static char	info[1024];		/* Info string */  if (!description)    return ("");  get_text(description, text, sizeof(text));  for (ptr = strchr(text, '@'); ptr; ptr = strchr(ptr + 1, '@'))  {    if (!strncmp(ptr, "@deprecated@", 12))      return ("<span class=\"info\">&nbsp;DEPRECATED&nbsp;</span>");    else if (!strncmp(ptr, "@since ", 7))    {      strncpy(since, ptr + 7, sizeof(since) - 1);      since[sizeof(since) - 1] = '\0';      if ((ptr = strchr(since, '@')) != NULL)        *ptr = '\0';      snprintf(info, sizeof(info), "<span class=\"info\">&nbsp;%s&nbsp;</span>", since);      return (info);    }  }  return ("");}/* * 'get_text()' - Get the text for a node. */static char *				/* O - Text in node */get_text(mxml_node_t *node,		/* I - Node to get */         char        *buffer,		/* I - Buffer */	 int         buflen)		/* I - Size of buffer */{  char		*ptr,			/* Pointer into buffer */		*end;			/* End of buffer */  int		len;			/* Length of node */  mxml_node_t	*current;		/* Current node */  ptr = buffer;  end = buffer + buflen - 1;  for (current = node->child; current && ptr < end; current = current->next)  {    if (current->type == MXML_TEXT)    {      if (current->value.text.whitespace)        *ptr++ = ' ';      len = (int)strlen(current->value.text.string);      if (len > (int)(end - ptr))        len = (int)(end - ptr);      memcpy(ptr, current->value.text.string, len);      ptr += len;    }    else if (current->type == MXML_OPAQUE)    {      len = (int)strlen(current->value.opaque);      if (len > (int)(end - ptr))        len = (int)(end - ptr);      memcpy(ptr, current->value.opaque, len);      ptr += len;    }  }  *ptr = '\0';  return (buffer);}/* * 'load_cb()' - Set the type of child nodes. */static mxml_type_t			/* O - Node type */load_cb(mxml_node_t *node)		/* I - Node */{  if (!strcmp(node->value.element.name, "description"))    return (MXML_OPAQUE);  else    return (MXML_TEXT);}/* * 'new_documentation()' - Create a new documentation tree. */static mxml_node_t *			/* O - New documentation */new_documentation(mxml_node_t **mxmldoc)/* O - mxmldoc node */{  mxml_node_t	*doc;			/* New documentation */ /*  * Create an empty XML documentation file...  */  doc = mxmlNewXML(NULL);  *mxmldoc = mxmlNewElement(doc, "mxmldoc");  mxmlElementSetAttr(*mxmldoc, "xmlns", "http://www.easysw.com");  mxmlElementSetAttr(*mxmldoc, "xmlns:xsi",                     "http://www.w3.org/2001/XMLSchema-instance");  mxmlElementSetAttr(*mxmldoc, "xsi:schemaLocation",                     "http://www.minixml.org/mxmldoc.xsd");  return (doc);}/* * 'safe_strcpy()' - Copy a string allowing for overlapping strings. */static voidsafe_strcpy(char       *dst,		/* I - Destination string */            const char *src)		/* I - Source string */{  while (*src)    *dst++ = *src++;  *dst = '\0';}/* * 'scan_file()' - Scan a source file. */static int				/* O - 0 on success, -1 on error */scan_file(const char  *filename,	/* I - Filename */          FILE        *fp,		/* I - File to scan */          mxml_node_t *tree)		/* I - Function tree */{  int		state,			/* Current parser state */		braces,			/* Number of braces active */		parens;			/* Number of active parenthesis */  int		ch;			/* Current character */  char		buffer[65536],		/* String buffer */		*bufptr;		/* Pointer into buffer */  const char	*scope;			/* Current variable/function scope */  mxml_node_t	*comment,		/* <comment> node */		*constant,		/* <constant> node */		*enumeration,		/* <enumeration> node */		*function,		/* <function> node */		*fstructclass,		/* function struct/class node */		*structclass,		/* <struct> or <class> node */		*typedefnode,		/* <typedef> node */		*variable,		/* <variable> or <argument> node */		*returnvalue,		/* <returnvalue> node */		*type,			/* <type> node */		*description,		/* <description> node */		*node,			/* Current node */		*next;			/* Next node */#if DEBUG > 1  mxml_node_t	*temp;			/* Temporary node */  int		oldstate,		/* Previous state */		oldch;			/* Old character */  static const char *states[] =		/* State strings */		{		  "STATE_NONE",		  "STATE_PREPROCESSOR",		  "STATE_C_COMMENT",		  "STATE_CXX_COMMENT",		  "STATE_STRING",		  "STATE_CHARACTER",		  "STATE_IDENTIFIER"		};#endif /* DEBUG > 1 */#ifdef DEBUG  fprintf(stderr, "scan_file(filename=\"%s\", fp=%p, tree=%p)\n", filename,          fp, tree);#endif /* DEBUG */ /*  * Initialize the finite state machine...  */  state        = STATE_NONE;  braces       = 0;  parens       = 0;  bufptr       = buffer;  comment      = mxmlNewElement(MXML_NO_PARENT, "temp");  constant     = NULL;  enumeration  = NULL;  function     = NULL;  variable     = NULL;  returnvalue  = NULL;  type         = NULL;  description  = NULL;  typedefnode  = NULL;  structclass  = NULL;  fstructclass = NULL;  if (!strcmp(tree->value.element.name, "class"))    scope = "private";  else    scope = NULL; /*  * Read until end-of-file...  */  while ((ch = getc(fp)) != EOF)  {#if DEBUG > 1    oldstate = state;    oldch    = ch;#endif /* DEBUG > 1 */    switch (state)    {      case STATE_NONE :			/* No state - whitespace, etc. */          switch (ch)	  {	    case '/' :			/* Possible C/C++ comment */	        ch     = getc(fp);		bufptr = buffer;		if (ch == '*')		  state = STATE_C_COMMENT;		else if (ch == '/')		  state = STATE_CXX_COMMENT;		else		{		  ungetc(ch, fp);		  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 '#' :			/* Preprocessor */#ifdef DEBUG	        fputs("    #preprocessor...\n", stderr);#endif /* DEBUG */	        state = STATE_PREPROCESSOR;		break;            case '\'' :			/* Character constant */	        state = STATE_CHARACTER;		bufptr = buffer;		*bufptr++ = ch;		break;            case '\"' :			/* String constant */	        state = STATE_STRING;		bufptr = buffer;		*bufptr++ = ch;		break;            case '{' :#ifdef DEBUG	        fprintf(stderr, "    open brace, function=%p, type=%p...\n",		        function, type);                if (type)                  fprintf(stderr, "    type->child=\"%s\"...\n",		          type->child->value.text.string);#endif /* DEBUG */	        if (function)		{		  if (fstructclass)		  {		    sort_node(fstructclass, function);		    fstructclass = NULL;		  }		  else		    sort_node(tree, function);		  function = NULL;		}		else if (type && type->child &&		         ((!strcmp(type->child->value.text.string, "typedef") &&			   type->child->next &&			   (!strcmp(type->child->next->value.text.string, "struct") ||			    !strcmp(type->child->next->value.text.string, "union") ||			    !strcmp(type->child->next->value.text.string, "class"))) ||			  !strcmp(type->child->value.text.string, "union") ||			  !strcmp(type->child->value.text.string, "struct") ||			  !strcmp(type->child->value.text.string, "class")))		{		 /*		  * Start of a class or structure...		  */		  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;			  structclass = mxmlNewElement(MXML_NO_PARENT,		                               type->child->value.text.string);#ifdef DEBUG                  fprintf(stderr, "%c%s: <<<< %s >>>\n",		          toupper(type->child->value.text.string[0]),			  type->child->value.text.string + 1,			  type->child->next ?			      type->child->next->value.text.string : "(noname)");                  fputs("    type =", stderr);                  for (node = type->child; node; node = node->next)		    fprintf(stderr, " \"%s\"", node->value.text.string);		  putc('\n', stderr);                  fprintf(stderr, "    scope = %s\n", scope ? scope : "(null)");#endif /* DEBUG */                  if (type->child->next)		  {		    mxmlElementSetAttr(structclass, "name",		                       type->child->next->value.text.string);		    sort_node(tree, structclass);		  }                  if (typedefnode && type->child)		    type->child->value.text.whitespace = 0;                  else if (structclass && type->child &&		           type->child->next && type->child->next->next)		  {		    for (bufptr = buffer, node = type->child->next->next;		         node;			 bufptr += strlen(bufptr))		    {		      if (node->value.text.whitespace && bufptr > buffer)			*bufptr++ = ' ';		      strcpy(bufptr, node->value.text.string);		      next = node->next;		      mxmlDelete(node);		      node = next;		    }		    mxmlElementSetAttr(structclass, "parent", buffer);		    mxmlDelete(type);		    type = NULL;		  }		  else		  {		    mxmlDelete(type);		    type = NULL;		  }		  if (typedefnode && comment->last_child)		  {		   /*		    * Copy comment for typedef as well as class/struct/union...		    */		    mxmlNewText(comment, 0,

⌨️ 快捷键说明

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