From 5e99a791e62d77e99b3e313947b8c1f00587a7e6 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 4 Dec 2020 17:29:31 +0100 Subject: Create cmd to generate man pages for prof commands `profanity mangen` will create for each command (`/account`, `/roster`) an own manpage (`profanity-account.1`, `profanity-roster.1`) See https://github.com/profanity-im/profanity/issues/1444 Needs some polishing formatting wise. --- src/command/cmd_defs.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 53c42bae..e12fdb8a 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2833,3 +2833,70 @@ command_docgen(void) printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); g_list_free(cmds); } + +void +command_mangen(void) +{ + GList* cmds = NULL; + + for (unsigned int i = 0; i < ARRAY_SIZE(command_defs); i++) { + Command* pcmd = command_defs + i; + cmds = g_list_insert_sorted(cmds, pcmd, (GCompareFunc)_cmp_command); + } + + mkdir_recursive("docs"); + + GList* curr = cmds; + while (curr) { + Command* pcmd = curr->data; + + char* filename = NULL; + if (asprintf(&filename, "docs/profanity-%s.1", &pcmd->cmd[1]) == -1) { + // TODO: error + return; + } + FILE* manpage = fopen(filename, "w"); + free(filename); + + fputs(".TH man 1 \"2020-07-01\" \""PACKAGE_VERSION"\" \"Profanity XMPP client\"\n", manpage); + fputs(".SH NAME\n", manpage); + fprintf(manpage, "%s\n", pcmd->cmd); + + fputs("\n.SH DESCRIPTION\n", manpage); + fprintf(manpage, "%s\n", pcmd->help.desc); + + fputs("\n.SH SYNOPSIS\n", manpage); + int i = 0; + while (pcmd->help.synopsis[i]) { + fprintf(manpage, "%s\n", pcmd->help.synopsis[i]); + fputs("\n.BR\n", manpage); + i++; + } + + if (pcmd->help.args[0][0] != NULL) { + fputs("\n.SH ARGUMENTS\n", manpage); + for (i = 0; pcmd->help.args[i][0] != NULL; i++) { + fprintf(manpage, "%s\n", pcmd->help.args[i][0]); + fprintf(manpage, "%s\n", pcmd->help.args[i][1]); + fputs("\n.BR\n", manpage); + } + } + + if (pcmd->help.examples[0] != NULL) { + fputs("\n.SH EXAMPLES\n", manpage); + int i = 0; + while (pcmd->help.examples[i]) { + fprintf(manpage, "%s\n", pcmd->help.examples[i]); + fputs("\n.BR\n", manpage); + i++; + } + } + + curr = g_list_next(curr); + + fclose(manpage); + } + + printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); + g_list_free(cmds); +} -- cgit 1.4.1-2-gfad0 From b1d0d6d0c35cdef01dcc07c914ec8a2a42a32586 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 7 Dec 2020 16:38:29 +0100 Subject: man: formate arguments properly --- src/command/cmd_defs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index e12fdb8a..4ea9d107 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2876,9 +2876,8 @@ command_mangen(void) if (pcmd->help.args[0][0] != NULL) { fputs("\n.SH ARGUMENTS\n", manpage); for (i = 0; pcmd->help.args[i][0] != NULL; i++) { - fprintf(manpage, "%s\n", pcmd->help.args[i][0]); - fprintf(manpage, "%s\n", pcmd->help.args[i][1]); - fputs("\n.BR\n", manpage); + fprintf(manpage, ".PP\n%s\n", pcmd->help.args[i][0]); + fprintf(manpage, ".RS 4\n%s\n.RE\n", pcmd->help.args[i][1]); } } -- cgit 1.4.1-2-gfad0 From c833bd7feaaaec3f9a5e8e48bba3df7aa521189f Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 7 Dec 2020 16:45:17 +0100 Subject: Break lines differently in example and synopsis section --- src/command/cmd_defs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 4ea9d107..beaabac7 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2869,7 +2869,7 @@ command_mangen(void) int i = 0; while (pcmd->help.synopsis[i]) { fprintf(manpage, "%s\n", pcmd->help.synopsis[i]); - fputs("\n.BR\n", manpage); + fputs("\n.LP\n", manpage); i++; } @@ -2886,7 +2886,7 @@ command_mangen(void) int i = 0; while (pcmd->help.examples[i]) { fprintf(manpage, "%s\n", pcmd->help.examples[i]); - fputs("\n.BR\n", manpage); + fputs("\n.LP\n", manpage); i++; } } -- cgit 1.4.1-2-gfad0 From 377a7b8e83f6d96e66801cc381f783bd14fd49ca Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 7 Dec 2020 16:58:09 +0100 Subject: Generate date for manpage --- src/command/cmd_defs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index beaabac7..fba0e89e 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2846,6 +2846,16 @@ command_mangen(void) mkdir_recursive("docs"); + char* header = NULL; + GDateTime *now = g_date_time_new_now_local(); + gchar *date = g_date_time_format(now, "%F"); + if (asprintf(&header, ".TH man 1 \"%s\" \""PACKAGE_VERSION"\" \"Profanity XMPP client\"\n", date) == -1) { + // TODO: error + return; + } + g_date_time_unref(now); + g_free(date); + GList* curr = cmds; while (curr) { Command* pcmd = curr->data; @@ -2858,7 +2868,7 @@ command_mangen(void) FILE* manpage = fopen(filename, "w"); free(filename); - fputs(".TH man 1 \"2020-07-01\" \""PACKAGE_VERSION"\" \"Profanity XMPP client\"\n", manpage); + fprintf(manpage, "%s\n", header); fputs(".SH NAME\n", manpage); fprintf(manpage, "%s\n", pcmd->cmd); @@ -2891,11 +2901,12 @@ command_mangen(void) } } - curr = g_list_next(curr); - fclose(manpage); + curr = g_list_next(curr); } printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); + + free(header); g_list_free(cmds); } -- cgit 1.4.1-2-gfad0 From 1bbdaec8e7eb3d4f6ef3238c9365e2ea49618123 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 7 Dec 2020 17:25:22 +0100 Subject: Print man page arguments bold --- src/command/cmd_defs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/command/cmd_defs.c') diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index fba0e89e..51772a27 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2886,7 +2886,7 @@ command_mangen(void) if (pcmd->help.args[0][0] != NULL) { fputs("\n.SH ARGUMENTS\n", manpage); for (i = 0; pcmd->help.args[i][0] != NULL; i++) { - fprintf(manpage, ".PP\n%s\n", pcmd->help.args[i][0]); + fprintf(manpage, ".PP\n\\fB%s\\fR\n", pcmd->help.args[i][0]); fprintf(manpage, ".RS 4\n%s\n.RE\n", pcmd->help.args[i][1]); } } -- cgit 1.4.1-2-gfad0