Skip to content

Commit

Permalink
doxygen2man - Print structure descriptions (where available)
Browse files Browse the repository at this point in the history
Tidy 'description' fields (get rid of superfluous newlines)
and fix a couple of crashes
  • Loading branch information
chrissie-c committed Jul 1, 2020
1 parent 20ff7bc commit f50374f
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions doxygen2man/doxygen2man.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ struct param_info {
struct struct_info {
enum {STRUCTINFO_STRUCT, STRUCTINFO_ENUM} kind;
char *structname;
char *description;
char *brief_description;
struct qb_list_head params_list; /* our params */
struct qb_list_head list;
};
Expand Down Expand Up @@ -176,11 +178,12 @@ static void get_param_info(xmlNode *cur_node, struct qb_list_head *list)
/* This is not robust, and very inflexible */
for (this_tag = cur_node->children; this_tag; this_tag = this_tag->next) {
for (sub_tag = this_tag->children; sub_tag; sub_tag = sub_tag->next) {
if (sub_tag->type == XML_ELEMENT_NODE && strcmp((char *)sub_tag->name, "parameternamelist") == 0) {
if (sub_tag->type == XML_ELEMENT_NODE && strcmp((char *)sub_tag->name, "parameternamelist") == 0 &&
sub_tag->children->next->children) {
paramname = (char*)sub_tag->children->next->children->content;
}
if (sub_tag->type == XML_ELEMENT_NODE && strcmp((char *)sub_tag->name, "parameterdescription") == 0 &&
paramname) {
paramname && sub_tag->children->next->children) {
paramdesc = (char*)sub_tag->children->next->children->content;

/* Add text to the param_map */
Expand Down Expand Up @@ -213,7 +216,6 @@ static char *get_text(xmlNode *cur_node, char **returntext, char **notetext)
if (this_tag->type == XML_TEXT_NODE && strcmp((char *)this_tag->name, "text") == 0) {
if (not_all_whitespace((char*)this_tag->content)) {
strncat(buffer, (char*)this_tag->content, sizeof(buffer)-1);
strncat(buffer, "\n", sizeof(buffer)-1);
}
}
if (this_tag->type == XML_ELEMENT_NODE && strcmp((char *)this_tag->name, "emphasis") == 0) {
Expand Down Expand Up @@ -285,6 +287,27 @@ static void read_structname(xmlNode *cur_node, void *arg)
}
}

static void read_structdesc(xmlNode *cur_node, void *arg)
{
struct struct_info *si=arg;
xmlNode *this_tag;

for (this_tag = cur_node->children; this_tag; this_tag = this_tag->next) {
if (strcmp((char*)this_tag->name, "detaileddescription") == 0) {
char *desc = get_texttree(NULL, this_tag, NULL, NULL);
if (desc) {
si->description = strdup((char*)desc);
}
}
if (strcmp((char*)this_tag->name, "briefdescription") == 0) {
char *brief = get_texttree(NULL, this_tag, NULL, NULL);
if (brief) {
si->brief_description = brief;
}
}
}
}


static void read_headername(xmlNode *cur_node, void *arg)
{
Expand All @@ -310,6 +333,7 @@ static void read_struct(xmlNode *cur_node, void *arg)
char *name = NULL;
const char *args="";


for (this_tag = cur_node->children; this_tag; this_tag = this_tag->next) {
if (strcmp((char*)this_tag->name, "type") == 0) {
type = (char*)this_tag->children->content;
Expand Down Expand Up @@ -368,9 +392,11 @@ static int read_structure_from_xml(const char *refid, const char *name)

si = malloc(sizeof(struct struct_info));
if (si) {
memset(si, 0, sizeof(*si));
si->kind = STRUCTINFO_STRUCT;
qb_list_init(&si->params_list);
traverse_node(rootdoc, "memberdef", read_struct, si);
traverse_node(rootdoc, "compounddef", read_structdesc, si);
traverse_node(rootdoc, "compounddef", read_structname, si);
ret = 0;
qb_map_put(structures_map, refid, si);
Expand Down Expand Up @@ -424,6 +450,13 @@ static void print_structure(FILE *manfile, struct struct_info *si)
fprintf(manfile, ".nf\n");
fprintf(manfile, "\\fB\n");

if (si->brief_description) {
fprintf(manfile, "%s\n", si->brief_description);
}
if (si->description) {
fprintf(manfile, "%s\n", si->description);
}

qb_list_for_each(iter, &si->params_list) {
pi = qb_list_entry(iter, struct param_info, list);
if (strlen(pi->paramtype) > max_param_length) {
Expand Down Expand Up @@ -664,8 +697,8 @@ static void print_manpage(char *name, char *def, char *brief, char *args, char *
}
if (si) {
print_structure(manfile, si);
fprintf(manfile, ".PP\n");
}

}
qb_map_iter_free(map_iter);

Expand Down Expand Up @@ -787,6 +820,7 @@ static void collect_enums(xmlNode *cur_node, void *arg)
if (name) {
si = malloc(sizeof(struct struct_info));
if (si) {
memset(si, 0, sizeof(*si));
si->kind = STRUCTINFO_ENUM;
qb_list_init(&si->params_list);
si->structname = strdup(name);
Expand Down Expand Up @@ -908,7 +942,6 @@ static void traverse_node(xmlNode *parentnode, const char *leafname, void (do_me
xmlNode *cur_node;

for (cur_node = parentnode->children; cur_node; cur_node = cur_node->next) {

if (cur_node->type == XML_ELEMENT_NODE && cur_node->name
&& strcmp((char*)cur_node->name, leafname)==0) {
do_members(cur_node, arg);
Expand Down

0 comments on commit f50374f

Please sign in to comment.