📄 mxmldoc.c
字号:
/* * 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... */ 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(" --css filename.css Set CSS stylesheet file"); puts(" --footer footerfile Set footer file"); puts(" --framed basename Generate framed HTML to basename*.html"); puts(" --header headerfile Set header file"); 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( FILE *out, /* I - Output file */ mxml_node_t *description, /* I - Description node */ const char *element, /* I - HTML element, if any */ int summary) /* I - Show summary */{ char text[10240], /* Text for description */ *start, /* Start of code/link */ *ptr; /* Pointer into text */ int col; /* Current column */ if (!description) return; get_text(description, text, sizeof(text)); ptr = strstr(text, "\n\n"); if (summary) { if (ptr) *ptr = '\0'; ptr = text; } else if (!ptr || !ptr[2]) return; else ptr += 2; if (element && *element) fprintf(out, "<%s class=\"%s\">", element, summary ? "description" : "discussion"); else if (!summary) fputs(".PP\n", out); for (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 (!strncmp(ptr, "@code ", 6)) { for (ptr += 6; isspace(*ptr & 255); ptr ++); for (start = ptr, ptr ++; *ptr && *ptr != '@'; ptr ++); if (*ptr) *ptr = '\0'; else ptr --; if (element) fprintf(out, "<code>%s</code>", start); else fprintf(out, "\\fB%s\\fR", start); } else if (!strncmp(ptr, "@link ", 6)) { for (ptr += 6; isspace(*ptr & 255); ptr ++); for (start = ptr, ptr ++; *ptr && *ptr != '@'; ptr ++); if (*ptr) *ptr = '\0'; else ptr --; if (element) fprintf(out, "<a href=\"#%s\"><code>%s</code></a>", start, start); else fprintf(out, "\\fI%s\\fR", start); } else if (element) { if (*ptr == '&') fputs("&", out); else if (*ptr == '<') fputs("<", out); else if (*ptr == '>') fputs(">", out); else if (*ptr == '\"') fputs(""", out); 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(" ", out); } else fprintf(out, "&#x%x;", ch); } else if (*ptr == '\n' && ptr[1] == '\n' && ptr[2] && ptr[2] != '@') { fputs("<br>\n<br>\n", out); ptr ++; } else putc(*ptr, out); } else if (*ptr == '\n' && ptr[1] == '\n' && ptr[2] && ptr[2] != '@') { fputs("\n.PP\n", out); ptr ++; } else { if (*ptr == '\\' || (*ptr == '.' && col == 0)) putc('\\', out); putc(*ptr, out); if (*ptr == '\n') col = 0; else col ++; } } if (element && *element) fprintf(out, "</%s>\n", element); else if (!element) putc('\n', out);}/* * 'write_element()' - Write an element's text nodes. */static voidwrite_element(FILE *out, /* I - Output file */ 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) putc(' ', out); 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))) { fputs("<a href=\"#", out); write_string(out, node->value.text.string, mode); fputs("\">", out); write_string(out, node->value.text.string, mode); fputs("</a>", out); } else write_string(out, node->value.text.string, mode); } if (!strcmp(element->value.element.name, "type") && element->last_child->value.text.string[0] != '*') putc(' ', out);}/* * 'write_file()' - Copy a file to the output. */static voidwrite_file(FILE *out, /* I - Output file */ const char *file) /* I - File to copy */{ FILE *fp; /* Copy file */ char line[8192]; /* Line from file */ if
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -