1
0
Fork 0
forked from len0rd/rockbox

Adapted Miika's tool to rockbox coding style *oops*

(And removed some tabs from my own last minute edits in dict.c)

Changed the place of endian conversion form the device to the convertor.
Should speed it up a little.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6397 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Tomas Salfischberger 2005-05-02 16:06:05 +00:00
parent e2f5dba61c
commit 23028f579b
2 changed files with 76 additions and 62 deletions

View file

@ -52,7 +52,7 @@ void init_screen(void)
} }
/* for endian problems */ /* for endian problems */
#ifdef LITTLE_ENDIAN #ifdef ROCKBOX_BIG_ENDIAN
#define readlong(x) x #define readlong(x) x
#else #else
long readlong(void* value) long readlong(void* value)
@ -189,8 +189,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
rb->strncpy(output, ptr, display_columns); rb->strncpy(output, ptr, display_columns);
output[display_columns] = '\0'; output[display_columns] = '\0';
/* unsigned to kill a warning... */ /* typecast to kill a warning... */
if((int)rb->strlen(ptr) < display_columns) { if((int)rb->strlen(ptr) < display_columns)
{
rb->lcd_puts(0, lines, output); rb->lcd_puts(0, lines, output);
lines++; lines++;
break; break;

View file

@ -30,11 +30,20 @@ This tool converts the rdf file to the binary data used in the dict plugin.
/* maximum word lenght, has to be the same in dict.c */ /* maximum word lenght, has to be the same in dict.c */
#define WORDLEN 32 #define WORDLEN 32
struct word { struct word
{
char word[WORDLEN]; char word[WORDLEN];
long offset; long offset;
}; };
/* convert offsets here, not on device. */
long long_to_big_endian (void* value)
{
unsigned char* bytes = (unsigned char*) value;
return (long)bytes[0] | ((long)bytes[1] << 8) |
((long)bytes[2] << 16) | ((long)bytes[3] << 24);
}
int main() int main()
{ {
FILE *in; FILE *in;
@ -47,17 +56,20 @@ int main()
idx_out = open("dict.index", O_WRONLY | O_CREAT); idx_out = open("dict.index", O_WRONLY | O_CREAT);
desc_out = open("dict.desc", O_WRONLY | O_CREAT); desc_out = open("dict.desc", O_WRONLY | O_CREAT);
if (in == NULL || idx_out < 0 || desc_out < 0) { if (in == NULL || idx_out < 0 || desc_out < 0)
{
fprintf(stderr, "Error: Some files couldn't be opened\n"); fprintf(stderr, "Error: Some files couldn't be opened\n");
return 1; return 1;
} }
while (fgets(buf, sizeof buf, in) != NULL) { while (fgets(buf, sizeof buf, in) != NULL)
{
/* It is safe to use strtok here */ /* It is safe to use strtok here */
const char *word = strtok(buf, "\t"); const char *word = strtok(buf, "\t");
const char *desc = strtok(NULL, "\t"); const char *desc = strtok(NULL, "\t");
if (word == NULL || desc == NULL) { if (word == NULL || desc == NULL)
{
fprintf(stderr, "Parse error!\n"); fprintf(stderr, "Parse error!\n");
fprintf(stderr, "word: %s\ndesc: %s\n", word, desc); fprintf(stderr, "word: %s\ndesc: %s\n", word, desc);
@ -66,10 +78,11 @@ int main()
/* We will null-terminate the words */ /* We will null-terminate the words */
strncpy(w.word, word, WORDLEN - 1); strncpy(w.word, word, WORDLEN - 1);
w.offset = cur_offset; w.offset = long_to_big_endian(&cur_offset);
write(idx_out, &w, sizeof(struct word)); write(idx_out, &w, sizeof(struct word));
while (1) { while (1)
{
int len = strlen(desc); int len = strlen(desc);
cur_offset += len; cur_offset += len;
write(desc_out, desc, len); write(desc_out, desc, len);