summaryrefslogtreecommitdiff
path: root/apps/plugins/dict.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/dict.c')
-rw-r--r--apps/plugins/dict.c212
1 files changed, 18 insertions, 194 deletions
diff --git a/apps/plugins/dict.c b/apps/plugins/dict.c
index 8c26292..13fe8e3 100644
--- a/apps/plugins/dict.c
+++ b/apps/plugins/dict.c
@@ -20,11 +20,11 @@
****************************************************************************/
#include "plugin.h"
+#include "lib/simple_viewer.h"
PLUGIN_HEADER
-/* screen info */
-static int display_columns, display_lines;
+#define MIN_DESC_BUF_SIZE 0x400 /* arbitrary minimum size for description */
/* Some lenghts */
#define WORDLEN 32 /* has to be the same in rdf2binary.c */
@@ -44,50 +44,6 @@ struct stWord
long offset;
} STRUCT_PACKED;
-/* A funtion to get width and height etc (from viewer.c) */
-void init_screen(void)
-{
-#ifdef HAVE_LCD_BITMAP
- int w,h;
-
- rb->lcd_getstringsize("o", &w, &h);
- display_lines = LCD_HEIGHT / h;
- display_columns = LCD_WIDTH / w;
-#else
-
- display_lines = 2;
- display_columns = 11;
-#endif
-}
-
-/* global vars for pl_malloc() */
-void *bufptr;
-size_t bufleft;
-
-/* simple function to "allocate" memory in pluginbuffer. */
-void *pl_malloc(size_t size)
-{
- void *ptr;
- ptr = bufptr;
-
- if (bufleft < size)
- {
- return NULL;
- }
- else
- {
- bufptr += size;
- bufleft -= size;
- return ptr;
- }
-}
-
-/* init function for pl_malloc() */
-void pl_malloc_init(void)
-{
- bufptr = rb->plugin_get_buffer(&bufleft);
-}
-
/* for endian problems */
#ifdef ROCKBOX_BIG_ENDIAN
#define reverse(x) x
@@ -102,59 +58,6 @@ long reverse (long N) {
}
#endif
-/* Button definitions */
-#if CONFIG_KEYPAD == PLAYER_PAD
-#define LP_QUIT BUTTON_STOP
-#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
- (CONFIG_KEYPAD == IPOD_3G_PAD) || \
- (CONFIG_KEYPAD == IPOD_1G2G_PAD)
-#define LP_QUIT BUTTON_MENU
-#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
-#define LP_QUIT BUTTON_PLAY
-#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == GIGABEAT_PAD
-#define LP_QUIT BUTTON_POWER
-#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
- (CONFIG_KEYPAD == SANSA_C200_PAD) || \
- (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
- (CONFIG_KEYPAD == SANSA_M200_PAD)
-#define LP_QUIT BUTTON_POWER
-#elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
-#define LP_QUIT (BUTTON_HOME|BUTTON_REPEAT)
-#elif CONFIG_KEYPAD == IRIVER_H10_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == MROBE500_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == MROBE100_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
-#define LP_QUIT BUTTON_BACK
-#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
-#define LP_QUIT BUTTON_RC_REC
-#elif CONFIG_KEYPAD == COWON_D2_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == IAUDIO67_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
-#define LP_QUIT BUTTON_BACK
-#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == ONDAVX747_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == ONDAVX777_PAD
-#define LP_QUIT BUTTON_POWER
-#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
-#define LP_QUIT BUTTON_LEFT
-#elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
-#define LP_QUIT BUTTON_CANCEL
-#elif CONFIG_KEYPAD == MPIO_HD200_PAD
-#define LP_QUIT (BUTTON_REC|BUTTON_PLAY)
-#else
-#define LP_QUIT BUTTON_OFF
-#endif
/* data files */
#define DICT_INDEX PLUGIN_APPS_DIR "/dict.index"
@@ -165,42 +68,32 @@ enum plugin_status plugin_start(const void* parameter)
{
char searchword[WORDLEN]; /* word to search for */
char *description; /* pointer to description buffer */
- char *output; /* pointer to output buffer */
- char *ptr, *space;
struct stWord word; /* the struct to read into */
int fIndex, fData; /* files */
int filesize, high, low, probe;
- int lines, len, outputted, next;
+ char *buffer;
+ size_t buffer_size;
/* plugin stuff */
(void)parameter;
- /* get screen info */
- init_screen();
-
- /* get pl_malloc() buffer ready. */
- pl_malloc_init();
-
- /* init description buffer (size is because we don't have scrolling)*/
- description = (char *)pl_malloc(display_columns * display_lines);
- if (description == NULL)
+ /* allocate buffer. */
+ buffer = rb->plugin_get_buffer(&buffer_size);
+ if (buffer == NULL || buffer_size < MIN_DESC_BUF_SIZE)
{
- DEBUGF("Err: failed to allocate description buffer.");
+ DEBUGF("Err: Failed to allocate buffer.\n");
+ rb->splash(HZ*2, "Failed to allocate buffer.");
return PLUGIN_ERROR;
}
- /* init output buffer */
- output = (char *)pl_malloc(display_columns);
- if (output == NULL)
- {
- DEBUGF("Err: failed to allocate output buffer.");
- return PLUGIN_ERROR;
- }
+ description = buffer;
/* "clear" input buffer */
searchword[0] = '\0';
- rb->kbd_input(searchword, sizeof(searchword)); /* get the word to search */
+ /* get the word to search */
+ if (rb->kbd_input(searchword, sizeof(searchword)) < 0)
+ return PLUGIN_OK; /* input cancelled */
fIndex = rb->open(DICT_INDEX, O_RDONLY); /* index file */
if (fIndex < 0)
@@ -241,13 +134,13 @@ enum plugin_status plugin_start(const void* parameter)
/* read in the word */
rb->lseek(fIndex, sizeof(struct stWord) * low, SEEK_SET);
rb->read(fIndex, &word, sizeof(struct stWord));
+ rb->close(fIndex);
/* Check if we found something */
if (low == -1 || rb->strcasecmp(searchword, word.word) != 0)
{
DEBUGF("Not found.\n");
rb->splash(HZ*2, "Not found.");
- rb->close(fIndex);
return PLUGIN_OK;
}
@@ -259,7 +152,6 @@ enum plugin_status plugin_start(const void* parameter)
{
DEBUGF("Err: Failed to open description file.\n");
rb->splash(HZ*2, "Failed to open descriptions.");
- rb->close(fIndex);
return PLUGIN_ERROR;
}
@@ -267,83 +159,15 @@ enum plugin_status plugin_start(const void* parameter)
rb->lseek(fData, (off_t)reverse(word.offset), SEEK_SET);
/* Read in the description */
- rb->read_line(fData, description, display_columns * display_lines);
+ rb->read_line(fData, description, buffer_size);
/* And print it to debug. */
DEBUGF("Description: %s\n", description);
- /* get pointer to first char */
- ptr = description;
-
- lines = 0;
- outputted = 0;
- len = rb->strlen(description);
-
- /* clear screen */
- rb->lcd_clear_display();
-
- /* for large screens display the searched word. */
- if(display_lines > 4)
- {
- rb->lcd_puts(0, lines, searchword);
- lines++;
- }
-
- /* TODO: Scroll, or just stop when there are to much lines. */
- while (1)
- {
- /* copy one lcd line */
- rb->strlcpy(output, ptr, display_columns + 1);
-
- /* typecast to kill a warning... */
- if((int)rb->strlen(ptr) < display_columns)
- {
- rb->lcd_puts(0, lines, output);
- lines++;
- break;
- }
-
-
- /* get the last spacechar */
- space = rb->strrchr(output, ' ');
-
- if (space != NULL)
- {
- *space = '\0';
- next = (space - (char*)output) + 1;
- }
- else
- {
- next = display_columns;
- }
-
- /* put the line on screen */
- rb->lcd_puts(0, lines, output);
-
- /* get output count */
- outputted += rb->strlen(output);
-
- if (outputted < len)
- {
- /* set pointer to the next part */
- ptr += next;
- lines++;
- }
- else
- {
- break;
- }
- }
- rb->lcd_update();
+ rb->close(fData);
- /* wait for keypress */
- while(rb->button_get(true) != LP_QUIT)
- {
- /* do nothing */
- /* maybe define some keys for navigation here someday. */
- }
+ /* display description. */
+ view_text(searchword, description);
- rb->close(fIndex);
- rb->close(fData);
return PLUGIN_OK;
}