From e0dfe4832be53987ea5beb5c39e9985d5bc1aa15 Mon Sep 17 00:00:00 2001
From: James Booth
Date: Sun, 8 Feb 2015 00:42:21 +0000
Subject: [PATCH] Added code to generate HTML command reference for website
---
.gitignore | 3 +++
src/command/command.c | 53 +++++++++++++++++++++++++++++++++++++++++++
src/command/command.h | 2 ++
src/main.c | 13 +++++------
4 files changed, 64 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
index 09d5c04d..7f15f3c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -65,3 +65,6 @@ m4/
test.sh
clean-test.sh
callgrind.out.*
+gen_docs.sh
+main_fragment.html
+toc_fragment.html
diff --git a/src/command/command.c b/src/command/command.c
index 9698f0bd..1a673568 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -36,6 +36,7 @@
#include
#include
#include
+#include
#include
#include
@@ -2990,3 +2991,55 @@ _account_autocomplete(const char * const input)
found = autocomplete_param_with_ac(input, "/account", account_ac, TRUE);
return found;
}
+
+static int
+_cmp_command(Command *cmd1, Command *cmd2)
+{
+ return g_strcmp0(cmd1->cmd, cmd2->cmd);
+}
+
+void
+command_docgen(void)
+{
+ GList *cmds = NULL;
+ unsigned int i;
+ for (i = 0; i < ARRAY_SIZE(command_defs); i++) {
+ Command *pcmd = command_defs+i;
+ cmds = g_list_insert_sorted(cmds, pcmd, (GCompareFunc)_cmp_command);
+ }
+
+ FILE *toc_fragment = fopen("toc_fragment.html", "w");
+ FILE *main_fragment = fopen("main_fragment.html", "w");
+
+ fputs("- \n", toc_fragment);
+ fputs("
\n", main_fragment);
+
+ GList *curr = cmds;
+ while (curr) {
+ Command *pcmd = curr->data;
+
+ fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd);
+
+ fprintf(main_fragment, "\n", &pcmd->cmd[1]);
+ fprintf(main_fragment, "%s
\n", pcmd->cmd);
+ fputs("Usage:
\n", main_fragment);
+ fprintf(main_fragment, "%s
\n", pcmd->help.usage);
+
+ fputs("Details:
\n", main_fragment);
+ fputs("", main_fragment);
+ int i = 2;
+ while (pcmd->help.long_help[i] != NULL) {
+ fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
+ }
+ fputs("
\nback to top
\n", main_fragment);
+ fputs("\n", main_fragment);
+
+ curr = g_list_next(curr);
+ }
+
+ fputs("\n", toc_fragment);
+
+ fclose(toc_fragment);
+ fclose(main_fragment);
+ g_list_free(cmds);
+}
\ No newline at end of file
diff --git a/src/command/command.h b/src/command/command.h
index ffbccfa4..8be1143f 100644
--- a/src/command/command.h
+++ b/src/command/command.h
@@ -66,4 +66,6 @@ void cmd_history_append(char *inp);
char *cmd_history_previous(char *inp);
char *cmd_history_next(char *inp);
+void command_docgen(void);
+
#endif
diff --git a/src/main.c b/src/main.c
index f3b6a17f..7ee5affe 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,13 +40,7 @@
#endif
#include "profanity.h"
-
-#ifdef HAVE_LIBOTR
-#include "otr/otr.h"
-#endif
-#include "xmpp/xmpp.h"
-
-#include "ui/ui.h"
+#include "command/command.h"
static gboolean disable_tls = FALSE;
static gboolean version = FALSE;
@@ -56,6 +50,11 @@ static char *account_name = NULL;
int
main(int argc, char **argv)
{
+ if (argc == 2 && g_strcmp0(argv[1], "docgen") == 0 && g_strcmp0(PACKAGE_STATUS, "development") == 0) {
+ command_docgen();
+ return 0;
+ }
+
static GOptionEntry entries[] =
{
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL },