forked from len0rd/rockbox
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
This commit is contained in:
parent
7482b82175
commit
001860ce78
6 changed files with 2879 additions and 15 deletions
|
@ -1,6 +1,9 @@
|
|||
rockbox.c
|
||||
rbwrappers.c
|
||||
rbmalloc.c
|
||||
help.c
|
||||
helpcontent.c
|
||||
|
||||
src/combi.c
|
||||
src/divvy.c
|
||||
src/drawing.c
|
||||
|
|
52
apps/plugins/puzzles/genhelp.sh
Executable file
52
apps/plugins/puzzles/genhelp.sh
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
# usage: ./genhelp.sh > helpcontent.sh
|
||||
#
|
||||
# expects halibut to be installed in $PATH:
|
||||
# http://www.chiark.greenend.org.uk/~sgtatham/halibut
|
||||
|
||||
halibut --text src/puzzles.but
|
||||
|
||||
# preprocess the input
|
||||
|
||||
# strip leading whitespace
|
||||
cat puzzles.txt | awk '{$1=$1; print}' > puzzles.txt.tmp
|
||||
|
||||
# cut at "Appendix A"
|
||||
cat puzzles.txt.tmp | awk 'BEGIN { a=1; } /Appendix A/ { a = 0; } a==1' > puzzles.txt
|
||||
|
||||
rm puzzles.txt.tmp
|
||||
|
||||
cat <<EOF
|
||||
/* auto-generated by genhelp.sh */
|
||||
/* DO NOT EDIT! */
|
||||
const int help_chapteroffsets[] = {
|
||||
EOF
|
||||
|
||||
# generate chapter offset list
|
||||
cat puzzles.txt | awk 'BEGIN { x = -1; n = 0; } /#Chapter/ { if($0 !~ / 1:/ && $0 !~ / 2:/) { if( x == -1 ) { x = n; } print n - x","; }} {n += length($0) + 1; if(x >= 0 && $0 !~ /Chapter/ && substr($0, 1, 1) == "#") n += 1;}'
|
||||
|
||||
cat <<EOF
|
||||
};
|
||||
|
||||
const char help_text[] =
|
||||
EOF
|
||||
|
||||
# get starting byte offset
|
||||
start=`cat puzzles.txt | awk 'BEGIN { x = -1; n = 0; } /#Chapter/ { if($0 !~ / 1:/ && $0 !~ / 2:/) { if( x == -1 ) { x = n; print x + 1; } print n - x","; }} {n += length($0) + 1; if(x >= 0 && $0 !~ /Chapter/ && substr($0, 1, 1) == "#") n += 1;}' | head -n 1`
|
||||
|
||||
# generate content
|
||||
cat puzzles.txt | tail -c +$start | awk '{gsub(/\\/,"\\\\"); if($0 !~ /Chapter/ && substr($0, 1, 1) == "#") begin = "\\n"; else begin = ""; last = substr($0, length($0), 1); if(length($0) == 0 || last == "|" || last == "-" || (term == "\\n" && last == "3")) term="\\n"; else term = " "; print "\"" begin $0 term "\"";}'
|
||||
|
||||
cat <<EOF
|
||||
;
|
||||
|
||||
EOF
|
||||
|
||||
# length of longest chapter (not including null)
|
||||
maxlen=`cat puzzles.txt | awk 'BEGIN { x = -1; n = 0; } /#Chapter/ { if($0 !~ / 1:/ && $0 !~ / 2:/) { if( x == -1 ) { x = n; } print n - x","; }} {n += length($0) + 1; if(x >= 0 && $0 !~ /Chapter/ && substr($0, 1, 1) == "#") n += 1;}' | awk 'BEGIN { max = 0; last = 0; } { if($0 - last > max) max = $0 - last; last = $0; } END { print max }'`
|
||||
|
||||
# remember number of chapters
|
||||
num=`cat puzzles.txt | awk 'BEGIN { x = -1; n = 0; } /#Chapter/ { if($0 !~ / 1:/ && $0 !~ / 2:/) { if( x == -1 ) { x = n; } print n - x","; }} {n += length($0) + 1; if(x >= 0 && $0 !~ /Chapter/ && substr($0, 1, 1) == "#") n += 1;}' | wc -l`
|
||||
|
||||
echo "const int help_maxlen = "$maxlen";"
|
||||
echo "const int help_numchapters = "$num";"
|
48
apps/plugins/puzzles/help.c
Normal file
48
apps/plugins/puzzles/help.c
Normal file
|
@ -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);
|
||||
}
|
7
apps/plugins/puzzles/help.h
Normal file
7
apps/plugins/puzzles/help.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* defined in helpcontent.c */
|
||||
|
||||
extern int help_chapteroffsets[], help_maxlen, help_numchapters;
|
||||
extern const char help_text[];
|
||||
|
||||
/* in help.c */
|
||||
void full_help(const char *name);
|
2767
apps/plugins/puzzles/helpcontent.c
Normal file
2767
apps/plugins/puzzles/helpcontent.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1099,11 +1099,6 @@ static void quick_help(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void full_help(void)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
static void init_default_settings(void)
|
||||
{
|
||||
settings.slowmo_factor = 1;
|
||||
|
@ -1219,11 +1214,7 @@ static int pausemenu_cb(int action, const struct menu_item_ex *this_item)
|
|||
return ACTION_EXIT_MENUITEM;
|
||||
break;
|
||||
case 7:
|
||||
#ifdef FOR_REAL
|
||||
return ACTION_EXIT_MENUITEM;
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
case 8:
|
||||
#ifdef COMBINED
|
||||
/* audio buf is used, so no playback */
|
||||
|
@ -1354,7 +1345,7 @@ static int pause_menu(void)
|
|||
quick_help();
|
||||
break;
|
||||
case 7:
|
||||
full_help();
|
||||
full_help(midend_which_game(me)->name);
|
||||
break;
|
||||
case 8:
|
||||
playback_control(NULL);
|
||||
|
@ -1815,11 +1806,7 @@ static int mainmenu_cb(int action, const struct menu_item_ex *this_item)
|
|||
return ACTION_EXIT_MENUITEM;
|
||||
break;
|
||||
case 3:
|
||||
#ifdef FOR_REAL
|
||||
return ACTION_EXIT_MENUITEM;
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
case 4:
|
||||
#ifdef COMBINED
|
||||
/* audio buf is used, so no playback */
|
||||
|
@ -1934,7 +1921,7 @@ enum plugin_status plugin_start(const void *param)
|
|||
quick_help();
|
||||
break;
|
||||
case 3:
|
||||
full_help();
|
||||
full_help(midend_which_game(me)->name);
|
||||
break;
|
||||
case 4:
|
||||
playback_control(NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue