From 001860ce7856e20b890d8adf425c899540a5d5d3 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Tue, 9 May 2017 22:10:59 -0400 Subject: 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 --- apps/plugins/puzzles/help.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 apps/plugins/puzzles/help.c (limited to 'apps/plugins/puzzles/help.c') 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 @@ +#include "help.h" +#include "lib/simple_viewer.h" + +void full_help(const char *name) +{ + int ch_num = -1; + /* search the help text for a chapter with this name */ + for(int ch = 0; ch < help_numchapters; ++ch) + { + char *str = help_text + help_chapteroffsets[ch]; + char *ptr = strchr(str, ':') + 1; + const char *namep = name; + if(*ptr++ != ' ') + continue; + + while(*ptr == *namep && *ptr && *namep) + { + ptr++; + namep++; + } + if(*namep == '\0' && (*ptr == '\n' || *ptr == ' ')) /* full match */ + { + ch_num = ch; + break; + } + } + if(ch_num < 0) + { + rb->splashf(HZ * 2, "No topic found for `%s' (REPORT ME!)", name); + return; + } + char *buf = smalloc(help_maxlen + 1); + rb->memset(buf, 0, help_maxlen + 1); + if(ch_num < help_numchapters - 1) + { + /* safe to look ahead */ + memcpy(buf, help_text + help_chapteroffsets[ch_num], help_chapteroffsets[ch_num + 1] - help_chapteroffsets[ch_num]); + } + else + rb->strlcpy(buf, help_text + help_chapteroffsets[ch_num], help_maxlen + 1); + + rb->lcd_set_foreground(LCD_WHITE); + unsigned old_bg = rb->lcd_get_background(); + rb->lcd_set_background(LCD_BLACK); + view_text(name, buf); + rb->lcd_set_background(old_bg); + sfree(buf); +} -- cgit v1.2.3