2005-05-02 15:03:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Tomas Salfischberger
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-05-02 15:03:46 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
|
|
|
|
2005-05-02 15:03:46 +00:00
|
|
|
/* screen info */
|
|
|
|
static int display_columns, display_lines;
|
|
|
|
|
|
|
|
/* Some lenghts */
|
|
|
|
#define WORDLEN 32 /* has to be the same in rdf2binary.c */
|
|
|
|
|
2005-06-05 14:21:51 +00:00
|
|
|
/* Struct packing */
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define STRUCT_PACKED __attribute__((packed))
|
|
|
|
#else
|
|
|
|
#define STRUCT_PACKED
|
|
|
|
#pragma pack (push, 2)
|
|
|
|
#endif
|
|
|
|
|
2005-05-02 15:03:46 +00:00
|
|
|
/* The word struct :) */
|
|
|
|
struct stWord
|
|
|
|
{
|
|
|
|
char word[WORDLEN];
|
|
|
|
long offset;
|
2005-06-05 14:21:51 +00:00
|
|
|
} STRUCT_PACKED;
|
2005-05-02 15:03:46 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
}
|
|
|
|
|
2005-05-02 23:09:21 +00:00
|
|
|
/* global vars for pl_malloc() */
|
|
|
|
void *bufptr;
|
2010-05-07 19:27:42 +00:00
|
|
|
size_t bufleft;
|
2005-05-02 23:09:21 +00:00
|
|
|
|
|
|
|
/* simple function to "allocate" memory in pluginbuffer. */
|
2010-05-07 19:27:42 +00:00
|
|
|
void *pl_malloc(size_t size)
|
2005-05-02 23:09:21 +00:00
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
ptr = bufptr;
|
|
|
|
|
|
|
|
if (bufleft < size)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bufptr += size;
|
2008-08-19 12:16:04 +00:00
|
|
|
bufleft -= size;
|
2005-05-02 23:09:21 +00:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init function for pl_malloc() */
|
|
|
|
void pl_malloc_init(void)
|
|
|
|
{
|
2010-05-07 19:27:42 +00:00
|
|
|
bufptr = rb->plugin_get_buffer(&bufleft);
|
2005-05-02 23:09:21 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 15:03:46 +00:00
|
|
|
/* for endian problems */
|
2005-05-02 16:06:05 +00:00
|
|
|
#ifdef ROCKBOX_BIG_ENDIAN
|
2005-06-05 14:21:51 +00:00
|
|
|
#define reverse(x) x
|
2005-05-02 15:03:46 +00:00
|
|
|
#else
|
2005-06-05 14:21:51 +00:00
|
|
|
long reverse (long N) {
|
|
|
|
unsigned char B[4];
|
|
|
|
B[0] = (N & 0x000000FF) >> 0;
|
|
|
|
B[1] = (N & 0x0000FF00) >> 8;
|
|
|
|
B[2] = (N & 0x00FF0000) >> 16;
|
|
|
|
B[3] = (N & 0xFF000000) >> 24;
|
|
|
|
return ((B[0] << 24) | (B[1] << 16) | (B[2] << 8) | (B[3] << 0));
|
2005-05-02 15:03:46 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Button definitions */
|
|
|
|
#if CONFIG_KEYPAD == PLAYER_PAD
|
|
|
|
#define LP_QUIT BUTTON_STOP
|
2006-02-24 20:54:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
|
2007-07-27 09:57:27 +00:00
|
|
|
(CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
|
2005-12-14 01:31:37 +00:00
|
|
|
#define LP_QUIT BUTTON_MENU
|
2006-01-12 00:35:50 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
|
|
|
#define LP_QUIT BUTTON_PLAY
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
|
2006-01-18 11:09:06 +00:00
|
|
|
#define LP_QUIT BUTTON_POWER
|
2006-02-24 15:42:52 +00:00
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_PAD
|
2007-05-19 23:38:09 +00:00
|
|
|
#define LP_QUIT BUTTON_POWER
|
2007-09-20 10:49:48 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
|
2009-01-04 23:33:15 +00:00
|
|
|
(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)
|
2009-04-10 17:28:26 +00:00
|
|
|
#define LP_QUIT (BUTTON_HOME|BUTTON_REPEAT)
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define LP_QUIT BUTTON_POWER
|
2007-10-23 15:40:51 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE500_PAD
|
|
|
|
#define LP_QUIT BUTTON_POWER
|
2008-03-01 22:55:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE100_PAD
|
|
|
|
#define LP_QUIT BUTTON_POWER
|
2008-02-17 12:23:02 +00:00
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
|
|
|
|
#define LP_QUIT BUTTON_BACK
|
2008-03-22 10:24:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
#define LP_QUIT BUTTON_RC_REC
|
2009-12-15 20:51:41 +00:00
|
|
|
#elif CONFIG_KEYPAD == COWON_D2_PAD
|
2008-03-22 22:03:34 +00:00
|
|
|
#define LP_QUIT BUTTON_POWER
|
2008-10-07 16:38:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO67_PAD
|
|
|
|
#define LP_QUIT BUTTON_POWER
|
2008-12-04 21:28:56 +00:00
|
|
|
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
|
|
|
|
#define LP_QUIT BUTTON_BACK
|
2009-01-24 22:41:55 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
|
|
|
|
#define LP_QUIT BUTTON_POWER
|
2009-12-02 01:56:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
|
|
|
|
#define LP_QUIT BUTTON_POWER
|
2009-04-07 23:41:44 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDAVX747_PAD
|
|
|
|
#define LP_QUIT BUTTON_POWER
|
2009-08-31 21:11:32 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDAVX777_PAD
|
|
|
|
#define LP_QUIT BUTTON_POWER
|
2009-08-04 03:08:32 +00:00
|
|
|
#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
|
|
|
|
#define LP_QUIT BUTTON_LEFT
|
2010-02-11 22:40:17 +00:00
|
|
|
#elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
|
|
|
|
#define LP_QUIT BUTTON_CANCEL
|
2010-04-26 21:40:00 +00:00
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD200_PAD
|
|
|
|
#define LP_QUIT (BUTTON_REC|BUTTON_PLAY)
|
2005-05-02 15:03:46 +00:00
|
|
|
#else
|
|
|
|
#define LP_QUIT BUTTON_OFF
|
|
|
|
#endif
|
|
|
|
|
2005-06-05 14:21:51 +00:00
|
|
|
/* data files */
|
2009-05-27 20:31:07 +00:00
|
|
|
#define DICT_INDEX PLUGIN_APPS_DIR "/dict.index"
|
|
|
|
#define DICT_DESC PLUGIN_APPS_DIR "/dict.desc"
|
2005-06-05 14:21:51 +00:00
|
|
|
|
2005-05-02 15:03:46 +00:00
|
|
|
/* the main plugin function */
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2005-05-02 15:03:46 +00:00
|
|
|
{
|
|
|
|
char searchword[WORDLEN]; /* word to search for */
|
2005-05-02 23:09:21 +00:00
|
|
|
char *description; /* pointer to description buffer */
|
|
|
|
char *output; /* pointer to output buffer */
|
2005-05-02 15:03:46 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
/* plugin stuff */
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
/* get screen info */
|
|
|
|
init_screen();
|
|
|
|
|
2005-05-02 23:09:21 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
DEBUGF("Err: failed to allocate description 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;
|
|
|
|
}
|
|
|
|
|
2005-05-02 15:03:46 +00:00
|
|
|
/* "clear" input buffer */
|
|
|
|
searchword[0] = '\0';
|
|
|
|
|
|
|
|
rb->kbd_input(searchword, sizeof(searchword)); /* get the word to search */
|
|
|
|
|
2005-06-05 14:21:51 +00:00
|
|
|
fIndex = rb->open(DICT_INDEX, O_RDONLY); /* index file */
|
2005-05-02 15:03:46 +00:00
|
|
|
if (fIndex < 0)
|
|
|
|
{
|
|
|
|
DEBUGF("Err: Failed to open index file.\n");
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*2, "Failed to open index.");
|
2005-05-02 15:03:46 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
filesize = rb->filesize(fIndex); /* get filesize */
|
|
|
|
|
|
|
|
DEBUGF("Filesize: %d bytes = %d words \n", filesize,
|
2007-03-17 10:50:58 +00:00
|
|
|
(filesize / (int)sizeof(struct stWord)));
|
2005-05-02 15:03:46 +00:00
|
|
|
|
|
|
|
/* for the searching algorithm */
|
|
|
|
high = filesize / sizeof( struct stWord );
|
|
|
|
low = -1;
|
|
|
|
|
|
|
|
while (high - low > 1)
|
|
|
|
{
|
|
|
|
probe = (high + low) / 2;
|
|
|
|
|
|
|
|
/* Jump to word pointed by probe, and read it. */
|
|
|
|
rb->lseek(fIndex, sizeof(struct stWord) * probe, SEEK_SET);
|
|
|
|
rb->read(fIndex, &word, sizeof(struct stWord));
|
|
|
|
|
|
|
|
/* jump according to the found word. */
|
|
|
|
if (rb->strcasecmp(searchword, word.word) < 0)
|
|
|
|
{
|
|
|
|
high = probe;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
low = probe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read in the word */
|
|
|
|
rb->lseek(fIndex, sizeof(struct stWord) * low, SEEK_SET);
|
|
|
|
rb->read(fIndex, &word, sizeof(struct stWord));
|
|
|
|
|
|
|
|
/* Check if we found something */
|
|
|
|
if (low == -1 || rb->strcasecmp(searchword, word.word) != 0)
|
|
|
|
{
|
|
|
|
DEBUGF("Not found.\n");
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*2, "Not found.");
|
2005-05-02 16:06:05 +00:00
|
|
|
rb->close(fIndex);
|
2005-05-02 15:03:46 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-17 09:54:28 +00:00
|
|
|
DEBUGF("Found %s at offset %ld\n", word.word, reverse(word.offset));
|
2005-05-02 15:03:46 +00:00
|
|
|
|
|
|
|
/* now open the description file */
|
2005-06-05 14:21:51 +00:00
|
|
|
fData = rb->open(DICT_DESC, O_RDONLY);
|
2005-05-02 15:03:46 +00:00
|
|
|
if (fData < 0)
|
|
|
|
{
|
|
|
|
DEBUGF("Err: Failed to open description file.\n");
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*2, "Failed to open descriptions.");
|
2005-05-02 16:06:05 +00:00
|
|
|
rb->close(fIndex);
|
2005-05-02 15:03:46 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* seek to the right offset */
|
2005-06-05 14:21:51 +00:00
|
|
|
rb->lseek(fData, (off_t)reverse(word.offset), SEEK_SET);
|
2005-05-02 15:03:46 +00:00
|
|
|
|
|
|
|
/* Read in the description */
|
2005-05-02 23:09:21 +00:00
|
|
|
rb->read_line(fData, description, display_columns * display_lines);
|
2005-05-02 15:03:46 +00:00
|
|
|
|
|
|
|
/* 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 */
|
2009-07-14 13:57:45 +00:00
|
|
|
rb->strlcpy(output, ptr, display_columns + 1);
|
2005-05-02 15:03:46 +00:00
|
|
|
|
2005-05-02 16:06:05 +00:00
|
|
|
/* typecast to kill a warning... */
|
|
|
|
if((int)rb->strlen(ptr) < display_columns)
|
|
|
|
{
|
|
|
|
rb->lcd_puts(0, lines, output);
|
2005-05-02 15:03:46 +00:00
|
|
|
lines++;
|
2005-05-02 16:06:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-05-02 15:03:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* get the last spacechar */
|
|
|
|
space = rb->strrchr(output, ' ');
|
|
|
|
|
|
|
|
if (space != NULL)
|
|
|
|
{
|
|
|
|
*space = '\0';
|
|
|
|
next = (space - (char*)output) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
next = display_columns;
|
|
|
|
}
|
|
|
|
|
2005-05-02 16:06:05 +00:00
|
|
|
/* put the line on screen */
|
2005-05-02 15:03:46 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
/* wait for keypress */
|
|
|
|
while(rb->button_get(true) != LP_QUIT)
|
|
|
|
{
|
|
|
|
/* do nothing */
|
|
|
|
/* maybe define some keys for navigation here someday. */
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->close(fIndex);
|
2005-05-02 16:06:05 +00:00
|
|
|
rb->close(fData);
|
2005-05-02 15:03:46 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|