mirror of
https://salsa.debian.org/ha-team/libqb
synced 2026-08-12 13:04:57 +00:00
doxygen2man - Lots of new features & fixes for parsing libqb manpages (#402)
doxygen2man: Lots of fixes and features a) Make it quieter in normal operation b) add options for hard coded things (like company name) c) handle typedef members of structures d) tidy function pointers in structs e) get header file name from the XML or commandline d) Add support for @ref tags in description e) add support for @note annotations f) Don't print (null) if there is no @brief description g) Add include prefix option h) use strncat rather than strcat
This commit is contained in:
parent
b2acdea2a8
commit
59a16df610
@ -36,8 +36,8 @@ Write man page files to <output dir>
|
||||
.B -P
|
||||
Print PARAMS section
|
||||
.TP
|
||||
.B -s <s>
|
||||
Write man pages into section <s> <default 3)
|
||||
.B -s <n>
|
||||
Write man pages into section <n> (default 3)
|
||||
.TP
|
||||
.B -p <package>
|
||||
Use <package> name. default <Package>
|
||||
@ -45,12 +45,24 @@ Use <package> name. default <Package>
|
||||
.B -H <header>
|
||||
Set header (default \"Programmer's Manual\")
|
||||
.TP
|
||||
.B -I <include>
|
||||
Set the include filename (defaults to the one in the XML file or unknown.h)
|
||||
.TP
|
||||
.B -i <prefix>
|
||||
Set the prefix for header files (eg qb/) if the are installed a subdir of /usr/include
|
||||
.TP
|
||||
.B -C <company>
|
||||
Set the company name in the copyright (default Red Hat)
|
||||
.TP
|
||||
.B -D <date>
|
||||
Date to print at top of man pages (format not checked, default: today)
|
||||
.TP
|
||||
.B -Y <year>
|
||||
Year to print at end of copyright line (default: today's year)
|
||||
.TP
|
||||
.B -S <year>
|
||||
Year to print at start of copyright line (default: 2010)
|
||||
.TP
|
||||
.B -o <dir>
|
||||
Write all man pages to <dir> (default .)
|
||||
.TP
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#define _XOPEN_SOURCE_EXTENDED
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
@ -43,14 +44,19 @@ static int print_ascii = 1;
|
||||
static int print_man = 0;
|
||||
static int print_params = 0;
|
||||
static int num_functions = 0;
|
||||
static int quiet=0;
|
||||
static const char *man_section="3";
|
||||
static const char *package_name="Package";
|
||||
static const char *header="Programmer's Manual";
|
||||
static const char *company="Red Hat";
|
||||
static const char *output_dir="./";
|
||||
static const char *xml_dir = "./xml/";
|
||||
static const char *xml_file;
|
||||
static const char *manpage_date = NULL;
|
||||
static const char *headerfile = NULL;
|
||||
static const char *header_prefix = "";
|
||||
static long manpage_year = LONG_MIN;
|
||||
static long start_year = 2010;
|
||||
static struct qb_list_head params_list;
|
||||
static struct qb_list_head retval_list;
|
||||
static qb_map_t *function_map;
|
||||
@ -72,7 +78,7 @@ struct struct_info {
|
||||
struct qb_list_head list;
|
||||
};
|
||||
|
||||
static char *get_texttree(int *type, xmlNode *cur_node, char **returntext);
|
||||
static char *get_texttree(int *type, xmlNode *cur_node, char **returntext, char **notetext);
|
||||
static void traverse_node(xmlNode *parentnode, const char *leafname, void (do_members(xmlNode*, void*)), void *arg);
|
||||
|
||||
static void free_paraminfo(struct param_info *pi)
|
||||
@ -112,12 +118,12 @@ static char *get_child(xmlNode *node, const char *tag)
|
||||
refid = NULL;
|
||||
for (child = this_node->children; child; child = child->next) {
|
||||
if (child->content) {
|
||||
strcat(buffer, (char *)child->content);
|
||||
strncat(buffer, (char *)child->content, sizeof(buffer)-1);
|
||||
}
|
||||
|
||||
if ((strcmp( (char*)child->name, "ref") == 0)) {
|
||||
if (child->children->content) {
|
||||
strcat(buffer,(char *)child->children->content);
|
||||
strncat(buffer,(char *)child->children->content, sizeof(buffer)-1);
|
||||
}
|
||||
refid = get_attr(child, "refid");
|
||||
}
|
||||
@ -194,7 +200,7 @@ static void get_param_info(xmlNode *cur_node, struct qb_list_head *list)
|
||||
}
|
||||
}
|
||||
|
||||
static char *get_text(xmlNode *cur_node, char **returntext)
|
||||
static char *get_text(xmlNode *cur_node, char **returntext, char **notetext)
|
||||
{
|
||||
xmlNode *this_tag;
|
||||
xmlNode *sub_tag;
|
||||
@ -204,24 +210,35 @@ static char *get_text(xmlNode *cur_node, char **returntext)
|
||||
for (this_tag = cur_node->children; this_tag; this_tag = this_tag->next) {
|
||||
if (this_tag->type == XML_TEXT_NODE && strcmp((char *)this_tag->name, "text") == 0) {
|
||||
if (not_all_whitespace((char*)this_tag->content)) {
|
||||
strcat(buffer, (char*)this_tag->content);
|
||||
strcat(buffer, "\n");
|
||||
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) {
|
||||
if (print_man) {
|
||||
strcat(buffer, "\\fB");
|
||||
strncat(buffer, "\\fB", sizeof(buffer)-1);
|
||||
}
|
||||
strcat(buffer, (char*)this_tag->children->content);
|
||||
strncat(buffer, (char*)this_tag->children->content, sizeof(buffer)-1);
|
||||
if (print_man) {
|
||||
strcat(buffer, "\\fR");
|
||||
strncat(buffer, "\\fR", sizeof(buffer)-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (this_tag->type == XML_ELEMENT_NODE && strcmp((char *)this_tag->name, "ref") == 0) {
|
||||
if (print_man) {
|
||||
strncat(buffer, "\\fI", sizeof(buffer)-1);
|
||||
}
|
||||
strncat(buffer, (char*)this_tag->children->content, sizeof(buffer)-1);
|
||||
if (print_man) {
|
||||
strncat(buffer, "\\fR", sizeof(buffer)-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (this_tag->type == XML_ELEMENT_NODE && strcmp((char *)this_tag->name, "itemizedlist") == 0) {
|
||||
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, "listitem") == 0) {
|
||||
strcat(buffer, (char*)sub_tag->children->children->content);
|
||||
strcat(buffer, "\n");
|
||||
strncat(buffer, (char*)sub_tag->children->children->content, sizeof(buffer)-1);
|
||||
strncat(buffer, "\n", sizeof(buffer)-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -231,11 +248,14 @@ static char *get_text(xmlNode *cur_node, char **returntext)
|
||||
char *tmp;
|
||||
|
||||
kind = get_attr(this_tag, "kind");
|
||||
tmp = get_text(this_tag->children, NULL);
|
||||
tmp = get_text(this_tag->children, NULL, NULL);
|
||||
|
||||
if (returntext && strcmp(kind, "return") == 0) {
|
||||
*returntext = tmp;
|
||||
}
|
||||
if (notetext && strcmp(kind, "note") == 0) {
|
||||
*notetext = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if (this_tag->type == XML_ELEMENT_NODE && strcmp((char *)this_tag->name, "parameterlist") == 0) {
|
||||
@ -263,6 +283,20 @@ static void read_structname(xmlNode *cur_node, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void read_headername(xmlNode *cur_node, void *arg)
|
||||
{
|
||||
char **h_file = 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) {
|
||||
*h_file = strdup((char*)this_tag->children->content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Called from traverse_node() */
|
||||
static void read_struct(xmlNode *cur_node, void *arg)
|
||||
{
|
||||
@ -276,10 +310,14 @@ static void read_struct(xmlNode *cur_node, void *arg)
|
||||
|
||||
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 ;
|
||||
type = (char*)this_tag->children->content;
|
||||
/* If type is NULL then look for a ref - it's probably an external struct or typedef */
|
||||
if (type == NULL) {
|
||||
type = get_child(this_tag, "ref");
|
||||
}
|
||||
}
|
||||
if (strcmp((char*)this_tag->name, "name") == 0) {
|
||||
name = (char*)this_tag->children->content ;
|
||||
name = (char*)this_tag->children->content;
|
||||
}
|
||||
if (this_tag->children && strcmp((char*)this_tag->name, "argsstring") == 0) {
|
||||
args = (char*)this_tag->children->content;
|
||||
@ -298,16 +336,22 @@ static void read_struct(xmlNode *cur_node, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
static int read_structure_from_xml(char *refid, char *name)
|
||||
static int read_structure_from_xml(const char *refid, const char *name)
|
||||
{
|
||||
char fname[PATH_MAX];
|
||||
xmlNode *rootdoc;
|
||||
xmlDocPtr doc;
|
||||
struct struct_info *si;
|
||||
struct stat st;
|
||||
int ret = -1;
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/%s.xml", xml_dir, refid);
|
||||
|
||||
/* Don't call into libxml if the file does not exist - saves unwanted error messages */
|
||||
if (stat(fname, &st) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
doc = xmlParseFile(fname);
|
||||
if (doc == NULL) {
|
||||
fprintf(stderr, "Error: unable to open xml file for %s\n", refid);
|
||||
@ -352,6 +396,12 @@ static void print_param(FILE *manfile, struct param_info *pi, int field_width, i
|
||||
asterisks="**";
|
||||
type[typelength-2] = '\0';
|
||||
}
|
||||
|
||||
/* Tidy function pointers */
|
||||
if (typelength > 1 && pi->paramtype[typelength-2] == '(') {
|
||||
asterisks="(*";
|
||||
type[typelength-2] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(manfile, " %s%-*s%s%s\\fI%s\\fP%s\n",
|
||||
@ -363,46 +413,41 @@ static void print_param(FILE *manfile, struct param_info *pi, int field_width, i
|
||||
}
|
||||
}
|
||||
|
||||
static void print_structure(FILE *manfile, char *refid, char *name)
|
||||
static void print_structure(FILE *manfile, struct struct_info *si)
|
||||
{
|
||||
struct struct_info *si;
|
||||
struct param_info *pi;
|
||||
struct qb_list_head *iter;
|
||||
unsigned int max_param_length=0;
|
||||
|
||||
/* If it's not been read in - go and look for it */
|
||||
si = qb_map_get(structures_map, refid);
|
||||
if (!si) {
|
||||
if (!read_structure_from_xml(refid, name)) {
|
||||
si = qb_map_get(structures_map, refid);
|
||||
fprintf(manfile, ".nf\n");
|
||||
fprintf(manfile, "\\fB\n");
|
||||
|
||||
qb_list_for_each(iter, &si->params_list) {
|
||||
pi = qb_list_entry(iter, struct param_info, list);
|
||||
if (strlen(pi->paramtype) > max_param_length) {
|
||||
max_param_length = strlen(pi->paramtype);
|
||||
}
|
||||
}
|
||||
|
||||
if (si) {
|
||||
qb_list_for_each(iter, &si->params_list) {
|
||||
pi = qb_list_entry(iter, struct param_info, list);
|
||||
if (strlen(pi->paramtype) > max_param_length) {
|
||||
max_param_length = strlen(pi->paramtype);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
print_param(manfile, pi, max_param_length, 0,";");
|
||||
}
|
||||
fprintf(manfile, "};\n");
|
||||
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);
|
||||
print_param(manfile, pi, max_param_length, 0,";");
|
||||
}
|
||||
fprintf(manfile, "};\n");
|
||||
|
||||
fprintf(manfile, "\\fP\n");
|
||||
fprintf(manfile, ".fi\n");
|
||||
}
|
||||
|
||||
char *get_texttree(int *type, xmlNode *cur_node, char **returntext)
|
||||
char *get_texttree(int *type, xmlNode *cur_node, char **returntext, char **notetext)
|
||||
{
|
||||
xmlNode *this_tag;
|
||||
char *tmp = NULL;
|
||||
@ -411,9 +456,9 @@ char *get_texttree(int *type, xmlNode *cur_node, char **returntext)
|
||||
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, "para") == 0) {
|
||||
tmp = get_text(this_tag, returntext);
|
||||
strcat(buffer, tmp);
|
||||
strcat(buffer, "\n");
|
||||
tmp = get_text(this_tag, returntext, notetext);
|
||||
strncat(buffer, tmp, sizeof(buffer)-1);
|
||||
strncat(buffer, "\n", sizeof(buffer)-1);
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
@ -427,13 +472,18 @@ 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)
|
||||
struct qb_list_head *param_list, char *returntext, char *notetext)
|
||||
{
|
||||
printf(" ------------------ %s --------------------\n", name);
|
||||
printf("NAME\n");
|
||||
printf(" %s - %s\n", name, brief);
|
||||
if (brief) {
|
||||
printf(" %s - %s\n", name, brief);
|
||||
} else {
|
||||
printf(" %s\n", name);
|
||||
}
|
||||
|
||||
printf("SYNOPSIS\n");
|
||||
printf(" #include <%s%s>\n", header_prefix, headerfile);
|
||||
printf(" %s %s\n\n", name, args);
|
||||
|
||||
printf("DESCRIPTION\n");
|
||||
@ -443,6 +493,10 @@ static void print_text(char *name, char *def, char *brief, char *args, char *det
|
||||
printf("RETURN VALUE\n");
|
||||
printf(" %s\n", returntext);
|
||||
}
|
||||
if (notetext) {
|
||||
printf("NOTE\n");
|
||||
printf(" %s\n", notetext);
|
||||
}
|
||||
}
|
||||
|
||||
/* Print a long string with para marks in it. */
|
||||
@ -465,7 +519,7 @@ 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)
|
||||
struct qb_list_head *param_map, char *returntext, char *notetext)
|
||||
{
|
||||
char manfilename[PATH_MAX];
|
||||
char gendate[64];
|
||||
@ -516,6 +570,12 @@ static void print_manpage(char *name, char *def, char *brief, char *args, char *
|
||||
qb_list_for_each(iter, ¶ms_list) {
|
||||
pi = qb_list_entry(iter, struct param_info, list);
|
||||
|
||||
/* It's mainly macros that break this,
|
||||
* macros need more work
|
||||
*/
|
||||
if (!pi->paramtype) {
|
||||
pi->paramtype = strdup("");
|
||||
}
|
||||
if ((strlen(pi->paramtype) < LINE_LENGTH) &&
|
||||
(strlen(pi->paramtype) > max_param_type_len)) {
|
||||
max_param_type_len = strlen(pi->paramtype);
|
||||
@ -535,11 +595,15 @@ static void print_manpage(char *name, char *def, char *brief, char *args, char *
|
||||
fprintf(manfile, ".TH %s %s %s \"%s\" \"%s\"\n", name, man_section, dateptr, package_name, header);
|
||||
|
||||
fprintf(manfile, ".SH NAME\n");
|
||||
fprintf(manfile, "%s \\- %s\n", name, brief);
|
||||
if (brief) {
|
||||
fprintf(manfile, "%s \\- %s\n", name, brief);
|
||||
} else {
|
||||
fprintf(manfile, "%s\n", name);
|
||||
}
|
||||
|
||||
fprintf(manfile, ".SH SYNOPSIS\n");
|
||||
fprintf(manfile, ".nf\n");
|
||||
fprintf(manfile, ".B #include <libknet.h>\n");
|
||||
fprintf(manfile, ".B #include <%s%s>\n", header_prefix, headerfile);
|
||||
fprintf(manfile, ".sp\n");
|
||||
fprintf(manfile, "\\fB%s\\fP(\n", def);
|
||||
|
||||
@ -568,17 +632,31 @@ static void print_manpage(char *name, char *def, char *brief, char *args, char *
|
||||
man_print_long_string(manfile, detailed);
|
||||
|
||||
if (qb_map_count_get(used_structures_map)) {
|
||||
fprintf(manfile, ".SH STRUCTURES\n");
|
||||
int first_struct = 1;
|
||||
|
||||
map_iter = qb_map_iter_create(used_structures_map);
|
||||
for (p = qb_map_iter_next(map_iter, &data); p; p = qb_map_iter_next(map_iter, &data)) {
|
||||
fprintf(manfile, ".nf\n");
|
||||
fprintf(manfile, "\\fB\n");
|
||||
struct struct_info *si;
|
||||
const char *refid = p;
|
||||
char *refname = data;
|
||||
|
||||
print_structure(manfile, (char*)p, (char *)data);
|
||||
/* If it's not been read in - go and look for it */
|
||||
si = qb_map_get(structures_map, refid);
|
||||
if (!si) {
|
||||
if (!read_structure_from_xml(refid, refname)) {
|
||||
si = qb_map_get(structures_map, refid);
|
||||
}
|
||||
}
|
||||
|
||||
/* Only print header if the struct files exist - sometimes they don't */
|
||||
if (si && first_struct) {
|
||||
fprintf(manfile, ".SH STRUCTURES\n");
|
||||
first_struct = 0;
|
||||
}
|
||||
if (si) {
|
||||
print_structure(manfile, si);
|
||||
}
|
||||
|
||||
fprintf(manfile, "\\fP\n");
|
||||
fprintf(manfile, ".fi\n");
|
||||
}
|
||||
qb_map_iter_free(map_iter);
|
||||
|
||||
@ -589,6 +667,10 @@ static void print_manpage(char *name, char *def, char *brief, char *args, char *
|
||||
fprintf(manfile, ".SH RETURN VALUE\n");
|
||||
man_print_long_string(manfile, returntext);
|
||||
}
|
||||
if (notetext) {
|
||||
fprintf(manfile, ".SH NOTE\n");
|
||||
man_print_long_string(manfile, notetext);
|
||||
}
|
||||
|
||||
qb_list_for_each(iter, &retval_list) {
|
||||
pi = qb_list_entry(iter, struct param_info, list);
|
||||
@ -621,7 +703,7 @@ static void print_manpage(char *name, char *def, char *brief, char *args, char *
|
||||
fprintf(manfile, ".hy\n");
|
||||
fprintf(manfile, ".SH \"COPYRIGHT\"\n");
|
||||
fprintf(manfile, ".PP\n");
|
||||
fprintf(manfile, "Copyright (C) 2010-%4ld Red Hat, Inc. All rights reserved.\n", manpage_year);
|
||||
fprintf(manfile, "Copyright (C) %4ld-%4ld %s, Inc. All rights reserved.\n", start_year, manpage_year, company);
|
||||
fclose(manfile);
|
||||
|
||||
/* Free the params & retval info */
|
||||
@ -719,6 +801,7 @@ static void traverse_members(xmlNode *cur_node, void *arg)
|
||||
char *brief = NULL;
|
||||
char *detailed = NULL;
|
||||
char *returntext = NULL;
|
||||
char *notetext = NULL;
|
||||
int type;
|
||||
|
||||
kind=def=args=name=NULL;
|
||||
@ -738,7 +821,7 @@ static void traverse_members(xmlNode *cur_node, void *arg)
|
||||
name = strdup((char *)this_tag->children->content);
|
||||
|
||||
if (this_tag->type == XML_ELEMENT_NODE && strcmp((char *)this_tag->name, "briefdescription") == 0) {
|
||||
brief = get_texttree(&type, this_tag, &returntext);
|
||||
brief = get_texttree(&type, this_tag, &returntext, ¬etext);
|
||||
if (brief) {
|
||||
/*
|
||||
* apparently brief text contains extra trailing space and 2 \n.
|
||||
@ -748,7 +831,7 @@ static void traverse_members(xmlNode *cur_node, void *arg)
|
||||
}
|
||||
}
|
||||
if (this_tag->type == XML_ELEMENT_NODE && strcmp((char *)this_tag->name, "detaileddescription") == 0) {
|
||||
detailed = get_texttree(&type, this_tag, &returntext);
|
||||
detailed = get_texttree(&type, this_tag, &returntext, ¬etext);
|
||||
}
|
||||
/* Get all the params */
|
||||
if (this_tag->type == XML_ELEMENT_NODE && strcmp((char *)this_tag->name, "param") == 0) {
|
||||
@ -769,14 +852,17 @@ static void traverse_members(xmlNode *cur_node, void *arg)
|
||||
/* Make sure function has a doxygen description */
|
||||
if (!detailed) {
|
||||
fprintf(stderr, "No doxygen description for function '%s' - please fix this\n", name);
|
||||
exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (print_man) {
|
||||
print_manpage(name, def, brief, args, detailed, ¶ms_list, returntext);
|
||||
if (!quiet) {
|
||||
printf("Printing manpage for %s\n", name);
|
||||
}
|
||||
print_manpage(name, def, brief, args, detailed, ¶ms_list, returntext, notetext);
|
||||
}
|
||||
else {
|
||||
print_text(name, def, brief, args, detailed, ¶ms_list, returntext);
|
||||
print_text(name, def, brief, args, detailed, ¶ms_list, returntext, notetext);
|
||||
}
|
||||
|
||||
}
|
||||
@ -830,22 +916,40 @@ static void usage(char *name)
|
||||
printf(" -s <s> Write man pages into section <s> <default 3)\n");
|
||||
printf(" -p <package> Use <package> name. default <Package>\n");
|
||||
printf(" -H <header> Set header (default \"Programmer's Manual\"\n");
|
||||
printf(" -I <include> Set include filename (default taken from xml)\n");
|
||||
printf(" -i <prefix> Prefix for include files. eg qb/ (default \"\")\n");
|
||||
printf(" -C <company> Company name in copyright (defaults to Red Hat)\n");
|
||||
printf(" -D <date> Date to print at top of man pages (format not checked, default: today)\n");
|
||||
printf(" -S <year> Start year to print at end of copyright line (default: 2010)\n");
|
||||
printf(" -Y <year> Year to print at end of copyright line (default: today's year)\n");
|
||||
printf(" -o <dir> Write all man pages to <dir> (default .)\n");
|
||||
printf(" -d <dir> Directory for XML files (./xml/)\n");
|
||||
printf(" -h Print this usage text\n");
|
||||
}
|
||||
|
||||
static long get_year(char *optionarg, char optionchar)
|
||||
{
|
||||
long year = strtol(optionarg, NULL, 10);
|
||||
/*
|
||||
* Don't make too many assumptions about the year. I was on call at the
|
||||
* 2000 rollover. #experience
|
||||
*/
|
||||
if (year == LONG_MIN || year == LONG_MAX ||
|
||||
year < 1900) {
|
||||
fprintf(stderr, "Value passed to -%c is not a valid year number\n", optionchar);
|
||||
return 0;
|
||||
}
|
||||
return year;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
xmlNode *rootdoc;
|
||||
xmlDocPtr doc;
|
||||
int quiet=0;
|
||||
int opt;
|
||||
char xml_filename[PATH_MAX];
|
||||
|
||||
while ( (opt = getopt_long(argc, argv, "H:amPD:Y:s:d:o:p:f:h?", NULL, NULL)) != EOF)
|
||||
while ( (opt = getopt_long(argc, argv, "H:amqPD:Y:s:S:d:o:p:f:I:i:C:h?", NULL, NULL)) != EOF)
|
||||
{
|
||||
switch(opt)
|
||||
{
|
||||
@ -860,9 +964,27 @@ int main(int argc, char *argv[])
|
||||
case 'P':
|
||||
print_params = 1;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = 1;
|
||||
break;
|
||||
case 'I':
|
||||
headerfile = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
header_prefix = optarg;
|
||||
break;
|
||||
case 'C':
|
||||
company = optarg;
|
||||
break;
|
||||
case 's':
|
||||
man_section = optarg;
|
||||
break;
|
||||
case 'S':
|
||||
start_year = get_year(optarg, 'S');
|
||||
if (start_year == 0) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
xml_dir = optarg;
|
||||
break;
|
||||
@ -870,14 +992,8 @@ int main(int argc, char *argv[])
|
||||
manpage_date = optarg;
|
||||
break;
|
||||
case 'Y':
|
||||
manpage_year = strtol(optarg, NULL, 10);
|
||||
/*
|
||||
* Don't make too many assumptions about the year. I was on call at the
|
||||
* 2000 rollover. #experience
|
||||
*/
|
||||
if (manpage_year == LONG_MIN || manpage_year == LONG_MAX ||
|
||||
manpage_year < 1900) {
|
||||
fprintf(stderr, "Value passed to -Y is not a valid year number\n");
|
||||
manpage_year = get_year(optarg, 'Y');
|
||||
if (manpage_year == 0) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
@ -906,7 +1022,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "reading xml ... ");
|
||||
printf("reading %s ... ", xml_file);
|
||||
}
|
||||
|
||||
snprintf(xml_filename, sizeof(xml_filename), "%s/%s", xml_dir, xml_file);
|
||||
@ -922,7 +1038,16 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
if (!quiet)
|
||||
fprintf(stderr, "done.\n");
|
||||
printf("done.\n");
|
||||
|
||||
/* Get our header file name */
|
||||
if (!headerfile) {
|
||||
traverse_node(rootdoc, "compounddef", read_headername, &headerfile);
|
||||
}
|
||||
/* Default to *something* if it all goes wrong */
|
||||
if (!headerfile) {
|
||||
headerfile = "unknown.h";
|
||||
}
|
||||
|
||||
qb_list_init(¶ms_list);
|
||||
qb_list_init(&retval_list);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user