mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Added code to generate HTML command reference for website
This commit is contained in:
parent
bec95afc8b
commit
e0dfe4832b
3
.gitignore
vendored
3
.gitignore
vendored
@ -65,3 +65,6 @@ m4/
|
||||
test.sh
|
||||
clean-test.sh
|
||||
callgrind.out.*
|
||||
gen_docs.sh
|
||||
main_fragment.html
|
||||
toc_fragment.html
|
||||
|
@ -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);
|
||||
}
|
@ -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
|
||||
|
13
src/main.c
13
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 },
|
||||
|
Loading…
Reference in New Issue
Block a user