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

📄 mxmldoc.c

📁 MINIXml 具有 解析、查找、生成、遍历 功能,一般不是太复杂的应用足够了。可贵的是全部实现是标准c,移植很容易。
💻 C
📖 第 1 页 / 共 5 页
字号:
  if ((temp = mxmlFindElement(tree, tree, node->value.element.name,                              "name", nodename, MXML_DESCEND_FIRST)) != NULL)  {   /*    * Copy the scope if needed...    */    if ((scope = mxmlElementGetAttr(temp, "scope")) != NULL &&        mxmlElementGetAttr(node, "scope") == NULL)    {#ifdef DEBUG      fprintf(stderr, "    copying scope %s for %s\n", scope, nodename);#endif /* DEBUG */      mxmlElementSetAttr(node, "scope", scope);    }    mxmlDelete(temp);  } /*  * Add the node into the tree at the proper place...  */  for (temp = tree->child; temp; temp = temp->next)  {#if DEBUG > 1    fprintf(stderr, "        temp=%p\n", temp);#endif /* DEBUG > 1 */    if ((tempname = mxmlElementGetAttr(temp, "name")) == NULL)      continue;#if DEBUG > 1    fprintf(stderr, "        tempname=%p (\"%s\")\n", tempname, tempname);#endif /* DEBUG > 1 */    if (strcmp(nodename, tempname) < 0)      break;  }  if (temp)    mxmlAdd(tree, MXML_ADD_BEFORE, temp, node);  else    mxmlAdd(tree, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, node);}/* * 'update_comment()' - Update a comment node. */static voidupdate_comment(mxml_node_t *parent,	/* I - Parent node */               mxml_node_t *comment)	/* I - Comment node */{  char	*ptr;				/* Pointer into comment */#ifdef DEBUG  fprintf(stderr, "update_comment(parent=%p, comment=%p)\n",          parent, comment);#endif /* DEBUG */ /*  * Range check the input...  */  if (!parent || !comment)    return;  /*  * Update the comment...  */  ptr = comment->value.text.string;  if (*ptr == '\'')  {   /*    * Convert "'name()' - description" to "description".    */    for (ptr ++; *ptr && *ptr != '\''; ptr ++);    if (*ptr == '\'')    {      ptr ++;      while (isspace(*ptr & 255))        ptr ++;      if (*ptr == '-')        ptr ++;      while (isspace(*ptr & 255))        ptr ++;      safe_strcpy(comment->value.text.string, ptr);    }  }  else if (!strncmp(ptr, "I ", 2) || !strncmp(ptr, "O ", 2) ||           !strncmp(ptr, "IO ", 3))  {   /*    * 'Convert "I - description", "IO - description", or "O - description"    * to description + directory attribute.    */    ptr = strchr(ptr, ' ');    *ptr++ = '\0';    if (!strcmp(parent->value.element.name, "argument"))      mxmlElementSetAttr(parent, "direction", comment->value.text.string);    while (isspace(*ptr & 255))      ptr ++;    if (*ptr == '-')      ptr ++;    while (isspace(*ptr & 255))      ptr ++;    safe_strcpy(comment->value.text.string, ptr);  } /*  * Eliminate leading and trailing *'s...  */  for (ptr = comment->value.text.string; *ptr == '*'; ptr ++);  for (; isspace(*ptr & 255); ptr ++);  if (ptr > comment->value.text.string)    safe_strcpy(comment->value.text.string, ptr);  for (ptr = comment->value.text.string + strlen(comment->value.text.string) - 1;       ptr > comment->value.text.string && *ptr == '*';       ptr --)    *ptr = '\0';  for (; ptr > comment->value.text.string && isspace(*ptr & 255); ptr --)    *ptr = '\0';#ifdef DEBUG  fprintf(stderr, "    updated comment = %s\n", comment->value.text.string);#endif /* DEBUG */}/* * 'usage()' - Show program usage... */static voidusage(const char *option)		/* I - Unknown option */{  if (option)    printf("mxmldoc: Bad option \"%s\"!\n\n", option);  puts("Usage: mxmldoc [options] [filename.xml] [source files] >filename.html");  puts("Options:");  puts("    --intro introfile          Set introduction file");  puts("    --man name                 Generate man page");  puts("    --no-output                Do no generate documentation file");  puts("    --section section          Set section name");  puts("    --title title              Set documentation title");  exit(1);}/* * 'write_description()' - Write the description text. */static voidwrite_description(    mxml_node_t *description,		/* I - Description node */    int         mode)			/* I - Output mode */{  char	text[10240],			/* Text for description */	*ptr;				/* Pointer into text */  int	col;				/* Current column */  if (!description)    return;  get_text(description, text, sizeof(text));  for (ptr = text, col = 0; *ptr; ptr ++)  {    if (*ptr == '@' &&        (!strncmp(ptr + 1, "deprecated@", 11) ||         !strncmp(ptr + 1, "since ", 6)))    {      ptr ++;      while (*ptr && *ptr != '@')        ptr ++;      if (!*ptr)        return;    }    else if (mode == OUTPUT_HTML)    {      if (*ptr == '&')        fputs("&amp;", stdout);      else if (*ptr == '<')        fputs("&lt;", stdout);      else if (*ptr == '>')        fputs("&gt;", stdout);      else if (*ptr == '\"')        fputs("&quot;", stdout);      else if (*ptr & 128)      {       /*        * Convert UTF-8 to Unicode constant...        */        int	ch;			/* Unicode character */        ch = *ptr & 255;        if ((ch & 0xe0) == 0xc0)        {          ch = ((ch & 0x1f) << 6) | (ptr[1] & 0x3f);	  ptr ++;        }        else if ((ch & 0xf0) == 0xe0)        {          ch = ((((ch * 0x0f) << 6) | (ptr[1] & 0x3f)) << 6) | (ptr[2] & 0x3f);	  ptr += 2;        }        if (ch == 0xa0)        {         /*          * Handle non-breaking space as-is...	  */          fputs("&nbsp;", stdout);        }        else          printf("&#x%x;", ch);      }      else if (*ptr == '\n' && ptr[1] == '\n' && ptr[2] && ptr[2] != '@')      {        fputs("\n<p>", stdout);        ptr ++;      }      else        putchar(*ptr);    }    else if (*ptr == '\n' && ptr[1] == '\n' && ptr[2] && ptr[2] != '@')    {      puts("\n.PP");      ptr ++;    }    else    {      if (*ptr == '\\' || (*ptr == '.' && col == 0))        putchar('\\');      putchar(*ptr);      if (*ptr == '\n')        col = 0;      else        col ++;    }  }  putchar('\n');}/* * 'write_element()' - Write an element's text nodes. */static voidwrite_element(mxml_node_t *doc,		/* I - Document tree */              mxml_node_t *element,	/* I - Element to write */              int         mode)		/* I - Output mode */{  mxml_node_t	*node;			/* Current node */  if (!element)    return;  for (node = element->child;       node;       node = mxmlWalkNext(node, element, MXML_NO_DESCEND))    if (node->type == MXML_TEXT)    {      if (node->value.text.whitespace)	putchar(' ');      if (mode == OUTPUT_HTML &&          (mxmlFindElement(doc, doc, "class", "name", node->value.text.string,                           MXML_DESCEND) ||	   mxmlFindElement(doc, doc, "enumeration", "name",	                   node->value.text.string, MXML_DESCEND) ||	   mxmlFindElement(doc, doc, "struct", "name", node->value.text.string,                           MXML_DESCEND) ||	   mxmlFindElement(doc, doc, "typedef", "name", node->value.text.string,                           MXML_DESCEND) ||	   mxmlFindElement(doc, doc, "union", "name", node->value.text.string,                           MXML_DESCEND)))      {        printf("<a href='#");        write_string(node->value.text.string, mode);	printf("'>");        write_string(node->value.text.string, mode);	printf("</a>");      }      else        write_string(node->value.text.string, mode);    }}/* * 'write_html()' - Write HTML documentation. */static voidwrite_html(    const char  *section,		/* I - Section */    const char  *title,			/* I - Title */    const char  *introfile,		/* I - Intro file */    mxml_node_t *doc)			/* I - XML documentation */{  int		i;			/* Looping var */  FILE		*fp;			/* File */  char		line[8192];		/* Line from file */  mxml_node_t	*function,		/* Current function */		*scut,			/* Struct/class/union/typedef */		*arg,			/* Current argument */		*description,		/* Description of function/var */		*type;			/* Type for argument */  const char	*name,			/* Name of function/type */		*cname,			/* Class name */		*defval,		/* Default value */		*parent;		/* Parent class */  int		inscope;		/* Variable/method scope */  char		prefix;			/* Prefix character */  static const char * const scopes[] =	/* Scope strings */		{		  "private",		  "protected",		  "public"		}; /*  * Standard header...  */  puts("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" "       "\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"       "<html>");  if (section)    printf("<!-- SECTION: %s -->\n", section);  printf("<head>\n"	 "\t<title>%s</title>\n", title);  if (section)    printf("\t<meta name='keywords' content='%s'>\n", section);  puts("\t<meta name='creator' content='" MXML_VERSION "'>\n"       "\t<style type='text/css'><!--\n"       "\th1, h2, h3, p { font-family: sans-serif; text-align: justify; }\n"       "\ttt, pre a:link, pre a:visited, tt a:link, tt a:visited { font-weight: bold; color: #7f0000; }\n"       "\tpre { font-weight: bold; color: #7f0000; margin-left: 2em; }\n"       "\tspan.info { background: #000000; border: solid thin #000000; "       "color: #ffffff; font-size: 80%; font-style: italic; "       "font-weight: bold; white-space: nowrap; }\n"       "\th3 span.info { float: right; font-size: 100%; }\n"       "\th1.title, h2.title, h3.title { border-bottom: solid 2px #000000; }\n"       "\t--></style>\n"       "</head>\n"       "<body>"); /*  * Intro...  */  if (introfile && (fp = fopen(introfile, "r")) != NULL)  {   /*    * Insert intro file before contents...    */    while (fgets(line, sizeof(line), fp))      fputs(line, stdout);    fclose(fp);  } /*  * Table of contents...  */  puts("<h2 class='title'>Contents</h2>");  puts("<ul>");  if (find_public(doc, doc, "class"))    puts("\t<li><a href='#CLASSES'>Classes</a></li>");  if (find_public(doc, doc, "enumeration"))    puts("\t<li><a href='#ENUMERATIONS'>Enumerations</a></li>");  if (find_public(doc, doc, "function"))    puts("\t<li><a href='#FUNCTIONS'>Functions</a></li>");  if (find_public(doc, doc, "struct"))    puts("\t<li><a href='#STRUCTURES'>Structures</a></li>");  if (find_public(doc, doc, "typedef"))    puts("\t<li><a href='#TYPES'>Types</a></li>");  if (find_public(doc, doc, "union"))    puts("\t<li><a href='#UNIONS'>Unions</a></li>");  if (find_public(doc, doc, "variable"))    puts("\t<li><a href='#VARIABLES'>Variables</a></li>");  puts("</ul>"); /*  * List of classes...  */  if (find_public(doc, doc, "class"))  {    puts("<!-- NEW PAGE -->\n"         "<h2 class='title'><a name='CLASSES'>Classes</a></h2>\n"         "<ul>");    for (scut = find_public(doc, doc, "class");	 scut;	 scut = find_public(scut, doc, "class"))    {      name = mxmlElementGetAttr(scut, "name");      printf("\t<li><a href='#%s'><tt>%s</tt></a> %s</li>\n", name, name,             get_comment_info(mxmlFindElement(scut, scut, "description",	                                      NULL, NULL, MXML_DESCEND_FIRST)));    }    puts("</ul>");    for (scut = find_public(doc, doc, "class");	 scut;	 scut = find_public(scut, doc, "class"))    {      cname       = mxmlElementGetAttr(scut, "name");      description = mxmlFindElement(scut, scut, "description", NULL,                                    NULL, MXML_DESCEND_FIRST);      printf("<!-- NEW PAGE -->\n"             "<h3 class='title'>%s<a name='%s'>%s</a></h3>\n",	     get_comment_info(description), cname, cname);      if (description)      {        fputs("<h4>Description</h4>\n"	      "<p>", stdout);	write_description(description, OUTPUT_HTML);      }      printf("<h4>Definition</h4>\n"             "<p><tt>\n"             "class %s", cname);      if ((parent = mxmlElementGetAttr(scut, "parent")) != NULL)        printf(" %s", parent);      puts("<br>\n{");      for (i = 0; i < 3; i ++)      {        inscope = 0;	for (arg = mxmlFindElement(scut, scut, "variable", "scope", scopes[i],                        	   MXML_DESCEND_FIRST);	     arg;	     arg = mxmlFindElement(arg, scut, "variable", "scope", scopes[i],                        	   MXML_NO_DESCEND))	{          if (!inscope)	  {	    inscope = 1;	    printf("&nbsp;&nbsp;%s:<br>\n", scopes[i]);	  }	  printf("&nbsp;&nbsp;&nbsp;&nbsp;");	  write_element(doc, mxmlFindElement(arg, arg, "type", NULL,                                             NULL, MXML_DESCEND_FIRST),                        OUTPUT_HTML);	  printf(" %s;<br>\n", mxmlElementGetAttr(arg, "name"));	}	for (function = mxmlFindElement(scut, scut, "function", "scope",	                                scopes[i], MXML_DESCEND_FIRST);	     function;	     function = mxmlFindElement(function, scut, "function", "scope",	                                scopes[i], MXML_NO_DESCEND))	{          if (!inscope)	  {	    inscope = 1;	    printf("&nbsp;&nbsp;%s:<br>\n", scopes[i]);	  }          name = mxmlElementGetAttr(function, "name");          printf("&nbsp;&nbsp;&nbsp;&nbsp;");	  arg = mxmlFindElement(function, function, "returnvalue", NULL,                        	NULL, MXML_DESCEND_FIRST);	  if (arg)	  {	    write_element(doc, mxmlFindElement(arg, arg, "type", NULL,                                               NULL, MXML_DESCEND_FIRST),                          O

⌨️ 快捷键说明

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