about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c53
-rw-r--r--src/command/command.h2
-rw-r--r--src/main.c13
3 files changed, 61 insertions, 7 deletions
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 <errno.h>
 #include <limits.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 
 #include <glib.h>
@@ -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("<ul><li><ul><li>\n", toc_fragment);
+    fputs("<hr>\n", main_fragment);
+
+    GList *curr = cmds;
+    while (curr) {
+        Command *pcmd = curr->data;
+
+        fprintf(toc_fragment, "<a href=\"#%s\">%s</a>,\n", &pcmd->cmd[1], pcmd->cmd);
+
+        fprintf(main_fragment, "<a name=\"%s\"></a>\n", &pcmd->cmd[1]);
+        fprintf(main_fragment, "<h4>%s</h4>\n", pcmd->cmd);
+        fputs("<p>Usage:</p>\n", main_fragment);
+        fprintf(main_fragment, "<p><pre><code>%s</code></pre></p>\n", pcmd->help.usage);
+
+        fputs("<p>Details:</p>\n", main_fragment);
+        fputs("<p><pre><code>", main_fragment);
+        int i = 2;
+        while (pcmd->help.long_help[i] != NULL) {
+            fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
+        }
+        fputs("</code></pre></p>\n<a href=\"#top\"><h5>back to top</h5></a><br><hr>\n", main_fragment);
+        fputs("\n", main_fragment);
+
+        curr = g_list_next(curr);
+    }
+
+    fputs("</ul></ul>\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 },