summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/help.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2017-05-09 22:10:59 -0400
committerFranklin Wei <git@fwei.tk>2017-05-16 16:45:39 -0400
commit001860ce7856e20b890d8adf425c899540a5d5d3 (patch)
tree61df98408207d85a05e29cfca1edb91ec6cb4d4a /apps/plugins/puzzles/help.c
parent7482b821753ac226806439fecec4f9ff504c0e90 (diff)
downloadrockbox-001860ce7856e20b890d8adf425c899540a5d5d3.tar.gz
rockbox-001860ce7856e20b890d8adf425c899540a5d5d3.zip
puzzles: full help system
- embeds the upstream halibut documentation for plugin use - currently every plugin has a copy of the help text, but in the future a centralized system using overlays might be better Change-Id: Idb6eb9accc2fa786a4c6bc2b704e7cf5fd3f78dd
Diffstat (limited to 'apps/plugins/puzzles/help.c')
-rw-r--r--apps/plugins/puzzles/help.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/apps/plugins/puzzles/help.c b/apps/plugins/puzzles/help.c
new file mode 100644
index 0000000000..13ca7eaa8a
--- /dev/null
+++ b/apps/plugins/puzzles/help.c
@@ -0,0 +1,48 @@
1#include "help.h"
2#include "lib/simple_viewer.h"
3
4void full_help(const char *name)
5{
6 int ch_num = -1;
7 /* search the help text for a chapter with this name */
8 for(int ch = 0; ch < help_numchapters; ++ch)
9 {
10 char *str = help_text + help_chapteroffsets[ch];
11 char *ptr = strchr(str, ':') + 1;
12 const char *namep = name;
13 if(*ptr++ != ' ')
14 continue;
15
16 while(*ptr == *namep && *ptr && *namep)
17 {
18 ptr++;
19 namep++;
20 }
21 if(*namep == '\0' && (*ptr == '\n' || *ptr == ' ')) /* full match */
22 {
23 ch_num = ch;
24 break;
25 }
26 }
27 if(ch_num < 0)
28 {
29 rb->splashf(HZ * 2, "No topic found for `%s' (REPORT ME!)", name);
30 return;
31 }
32 char *buf = smalloc(help_maxlen + 1);
33 rb->memset(buf, 0, help_maxlen + 1);
34 if(ch_num < help_numchapters - 1)
35 {
36 /* safe to look ahead */
37 memcpy(buf, help_text + help_chapteroffsets[ch_num], help_chapteroffsets[ch_num + 1] - help_chapteroffsets[ch_num]);
38 }
39 else
40 rb->strlcpy(buf, help_text + help_chapteroffsets[ch_num], help_maxlen + 1);
41
42 rb->lcd_set_foreground(LCD_WHITE);
43 unsigned old_bg = rb->lcd_get_background();
44 rb->lcd_set_background(LCD_BLACK);
45 view_text(name, buf);
46 rb->lcd_set_background(old_bg);
47 sfree(buf);
48}