Skip to content

Commit

Permalink
doxygen2man: Add option to read copyright line from the header file
Browse files Browse the repository at this point in the history
This should help make builds reproducible.

I tried various methods of getting the date, using 'git' is no use as
it could be run from a tarball, using the file date doesn't work either
so this seems a reasonable compromise.
  • Loading branch information
chrissie-c committed Sep 7, 2020
1 parent d01a9e0 commit 1b8aed9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dist_man_MANS = man8/qb-blackbox.8
if HAVE_DOXYGEN
if BUILD_MAN

doxygen2man_flags = -q -i qb/ -o man3/ -m -g -P -H "libqb Programmer's Manual" -p LIBQB
doxygen2man_flags = -q -i qb/ -o man3/ -m -g -P -H "libqb Programmer's Manual" -p LIBQB -c -O ../include/qb

man3_MANS = \
man3/qb_array_create_2.3 \
Expand Down
46 changes: 43 additions & 3 deletions doxygen2man/doxygen2man.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ static int print_man = 0;
static int print_params = 0;
static int print_general = 0;
static int num_functions = 0;
static int quiet=0;
static int quiet = 0;
static int use_header_copyright = 0;
static const char *man_section="3";
static const char *package_name="Package";
static const char *header="Programmer's Manual";
Expand All @@ -57,6 +58,8 @@ static const char *xml_file;
static const char *manpage_date = NULL;
static const char *headerfile = NULL;
static const char *header_prefix = "";
static const char *header_src_dir = "./";
static char header_copyright[256] = "\0";
static long manpage_year = LONG_MIN;
static long start_year = 2010;
static struct qb_list_head params_list;
Expand Down Expand Up @@ -763,7 +766,11 @@ 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) %4ld-%4ld %s, Inc. All rights reserved.\n", start_year, manpage_year, company);
if (header_copyright[0] == 'C') {
fprintf(manfile, "%s", header_copyright); /* String already contains trailing NL */
} else {
fprintf(manfile, "Copyright (C) %4ld-%4ld %s, Inc. All rights reserved.\n", start_year, manpage_year, company);
}
fclose(manfile);

/* Free the params & retval info */
Expand Down Expand Up @@ -993,6 +1000,8 @@ static void usage(char *name)
printf(" -m Write man page files to <output dir>\n");
printf(" -P Print PARAMS section\n");
printf(" -g Print general man page for the whole header file\n");
printf(" -c Use the Copyright date from the header file (if one can be found)\n");
printf(" -O <dir> Directory for the orignal header file. Often needed by -c above\n");
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");
Expand Down Expand Up @@ -1029,7 +1038,7 @@ int main(int argc, char *argv[])
int opt;
char xml_filename[PATH_MAX];

while ( (opt = getopt_long(argc, argv, "H:amqgPD:Y:s:S:d:o:p:f:I:i:C:h?", NULL, NULL)) != EOF)
while ( (opt = getopt_long(argc, argv, "H:amqgcPD:Y:s:S:d:o:p:f:I:i:C:O:h?", NULL, NULL)) != EOF)
{
switch(opt)
{
Expand All @@ -1050,6 +1059,9 @@ int main(int argc, char *argv[])
case 'q':
quiet = 1;
break;
case 'c':
use_header_copyright = 1;
break;
case 'I':
headerfile = optarg;
break;
Expand Down Expand Up @@ -1089,6 +1101,9 @@ int main(int argc, char *argv[])
case 'o':
output_dir = optarg;
break;
case 'O':
header_src_dir = optarg;
break;
case '?':
case 'h':
usage(argv[0]);
Expand Down Expand Up @@ -1126,7 +1141,32 @@ int main(int argc, char *argv[])
/* Get our header file name */
if (!headerfile) {
traverse_node(rootdoc, "compounddef", read_headername, &headerfile);

if (use_header_copyright) {
/* And get the copyright line from this file if we can */
char file_path[PATH_MAX];
char file_line[256];
FILE *hfile;
int lineno = 0;

snprintf(file_path, sizeof(file_path), "%s/%s", header_src_dir, headerfile);
hfile = fopen(file_path, "r");
if (hfile) {
/* Don't look too far, this should be at the top */
while (!feof(hfile) && (lineno++ < 10)) {
if (fgets(file_line, sizeof(file_line)-1, hfile)) {
if (strncmp(file_line, " * Copyright", 12) == 0) {
/* Keep the NL at the end of the buffer, it save us printing one */
strncpy(header_copyright, file_line+3, sizeof(header_copyright)-1);
break;
}
}
}
fclose(hfile);
}
}
}

/* Default to *something* if it all goes wrong */
if (!headerfile) {
headerfile = "unknown.h";
Expand Down

0 comments on commit 1b8aed9

Please sign in to comment.