Skip to content

Commit

Permalink
manpages: Document enums
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissie-c committed Mar 12, 2019
1 parent 9e6a7f7 commit da68133
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 14 deletions.
10 changes: 8 additions & 2 deletions libknet/libknet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,10 @@ int knet_link_clear_config(knet_handle_t knet_h, knet_node_id_t host_id, uint8_t
* see also knet_handle_enable_access_lists(3)
*/

/*
/**
* check_type_t
* @brief address type enum for knet access lists
*
* CHECK_TYPE_ADDRESS is the equivalent of a single entry / IP address.
* for example: 10.1.9.3
* and the entry is stored in ss1. ss2 can be NULL.
Expand All @@ -1552,7 +1555,10 @@ typedef enum {
CHECK_TYPE_RANGE
} check_type_t;

/*
/**
* check_acceptreject_t
* @brief enum for accept/reject in knet access lists
*
* accept or reject incoming packets defined in the access list entry
*/

Expand Down
86 changes: 74 additions & 12 deletions man/doxyxml.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Red Hat, Inc. All rights reserved.
* Copyright (C) 2018-2019 Red Hat, Inc. All rights reserved.
*
* Author: Christine Caulfield <ccaulfie@redhat.com>
*
Expand Down Expand Up @@ -61,6 +61,7 @@ struct param_info {
};

struct struct_info {
enum {STRUCTINFO_STRUCT, STRUCTINFO_ENUM} kind;
char *structname;
struct qb_list_head params_list; /* our params */
struct qb_list_head list;
Expand Down Expand Up @@ -245,6 +246,18 @@ static char *get_text(xmlNode *cur_node, char **returntext)
return strdup(buffer);
}

static void read_structname(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, "compoundname") == 0) {
si->structname = strdup((char*)this_tag->children->content);
}
}
}

/* Called from traverse_node() */
static void read_struct(xmlNode *cur_node, void *arg)
{
Expand Down Expand Up @@ -272,7 +285,7 @@ static void read_struct(xmlNode *cur_node, void *arg)
pi = malloc(sizeof(struct param_info));
if (pi) {
snprintf(fullname, sizeof(fullname), "%s%s", name, args);
pi->paramtype = strdup(type);
pi->paramtype = type?strdup(type):strdup("");
pi->paramname = strdup(fullname);
pi->paramdesc = NULL;
qb_list_add_tail(&pi->list, &si->params_list);
Expand Down Expand Up @@ -304,9 +317,10 @@ static int read_structure_from_xml(char *refid, char *name)

si = malloc(sizeof(struct struct_info));
if (si) {
si->kind = STRUCTINFO_STRUCT;
qb_list_init(&si->params_list);
si->structname = strdup(name);
traverse_node(rootdoc, "memberdef", read_struct, si);
traverse_node(rootdoc, "compounddef", read_structname, si);
ret = 0;
qb_map_put(structures_map, refid, si);
}
Expand All @@ -315,13 +329,19 @@ static int read_structure_from_xml(char *refid, char *name)
return ret;
}

/* Reformat pointer params so they look nicer */

static void print_param(FILE *manfile, struct param_info *pi, int field_width, int bold, const char *delimiter)
{
char asterisk = ' ';
char *type = pi->paramtype;

if (pi->paramtype[strlen(pi->paramtype)-1] == '*') {
/* If type is empty (no idea why this manifests as nl<space>...) then
it's an enum and has no type */
if (type[0] == '\n') {
type = strdup("");

/* Reformat pointer params so they look nicer */
} else if (pi->paramtype[strlen(pi->paramtype)-1] == '*') {
asterisk='*';
type = strdup(pi->paramtype);
type[strlen(type)-1] = '\0';
Expand Down Expand Up @@ -359,7 +379,13 @@ static void print_structure(FILE *manfile, char *refid, char *name)
}
}

fprintf(manfile, "struct %s {\n", si->structname);
if (si->kind == STRUCTINFO_STRUCT) {
fprintf(manfile, "struct %s {\n", si->structname);
} else if (si->kind == STRUCTINFO_ENUM) {
fprintf(manfile, "enum %s {\n", si->structname);
} else {
fprintf(manfile, "%s {\n", si->structname);
}

qb_list_for_each(iter, &si->params_list) {
pi = qb_list_entry(iter, struct param_info, list);
Expand Down Expand Up @@ -393,7 +419,8 @@ char *get_texttree(int *type, xmlNode *cur_node, char **returntext)
}

/* The text output is VERY basic and just a check that it's working really */
static void print_text(char *name, char *def, char *brief, char *args, char *detailed, struct qb_list_head *param_list, char *returntext)
static void print_text(char *name, char *def, char *brief, char *args, char *detailed,
struct qb_list_head *param_list, char *returntext)
{
printf(" ------------------ %s --------------------\n", name);
printf("NAME\n");
Expand Down Expand Up @@ -430,7 +457,8 @@ static void man_print_long_string(FILE *manfile, char *text)
}
}

static void print_manpage(char *name, char *def, char *brief, char *args, char *detailed, struct qb_list_head *param_map, char *returntext)
static void print_manpage(char *name, char *def, char *brief, char *args, char *detailed,
struct qb_list_head *param_map, char *returntext)
{
char manfilename[PATH_MAX];
char gendate[64];
Expand Down Expand Up @@ -640,6 +668,41 @@ static void collect_functions(xmlNode *cur_node, void *arg)
}
}

/* Same as traverse_members, but to collect enums. The behave like structures for,
but, for some reason, are in the main XML file rather than their own */
static void collect_enums(xmlNode *cur_node, void *arg)
{
xmlNode *this_tag;
struct struct_info *si;
char *kind;
char *refid = NULL;
char *name = NULL;

if (cur_node->name && strcmp((char *)cur_node->name, "memberdef") == 0) {

kind = get_attr(cur_node, "kind");
if (kind && strcmp(kind, "enum") == 0) {
refid = get_attr(cur_node, "id");

for (this_tag = cur_node->children; this_tag; this_tag = this_tag->next) {
if (this_tag->type == XML_ELEMENT_NODE && strcmp((char *)this_tag->name, "name") == 0) {
name = strdup((char *)this_tag->children->content);
}
}

si = malloc(sizeof(struct struct_info));
if (si) {
si->kind = STRUCTINFO_ENUM;
qb_list_init(&si->params_list);
si->structname = strdup(name);
traverse_node(cur_node, "enumvalue", read_struct, si);
qb_map_put(structures_map, refid, si);
}

}

}
}

static void traverse_members(xmlNode *cur_node, void *arg)
{
Expand Down Expand Up @@ -698,10 +761,6 @@ static void traverse_members(xmlNode *cur_node, void *arg)
}
}

if (kind && strcmp(kind, "typedef") == 0) {
/* Collect typedefs? */
}

if (kind && strcmp(kind, "function") == 0) {

/* Make sure function has a doxygen description */
Expand Down Expand Up @@ -856,6 +915,9 @@ int main(int argc, char *argv[])
/* Collect functions */
traverse_node(rootdoc, "memberdef", collect_functions, NULL);

/* Collect enums */
traverse_node(rootdoc, "memberdef", collect_enums, NULL);

/* print pages */
traverse_node(rootdoc, "memberdef", traverse_members, NULL);

Expand Down

0 comments on commit da68133

Please sign in to comment.