diff --git a/apps/plugins/dict.c b/apps/plugins/dict.c index efaeab2ed3..d3fea1d52d 100644 --- a/apps/plugins/dict.c +++ b/apps/plugins/dict.c @@ -52,7 +52,7 @@ void init_screen(void) } /* for endian problems */ -#ifdef LITTLE_ENDIAN +#ifdef ROCKBOX_BIG_ENDIAN #define readlong(x) x #else long readlong(void* value) @@ -140,7 +140,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { DEBUGF("Not found.\n"); rb->splash(HZ*2, true, "Not found."); - rb->close(fIndex); + rb->close(fIndex); return PLUGIN_OK; } @@ -152,7 +152,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { DEBUGF("Err: Failed to open description file.\n"); rb->splash(HZ*2, true, "Failed to open descriptions."); - rb->close(fIndex); + rb->close(fIndex); return PLUGIN_ERROR; } @@ -187,14 +187,15 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { /* copy one lcd line */ rb->strncpy(output, ptr, display_columns); - output[display_columns] = '\0'; + output[display_columns] = '\0'; - /* unsigned to kill a warning... */ - if((int)rb->strlen(ptr) < display_columns) { - rb->lcd_puts(0, lines, output); + /* typecast to kill a warning... */ + if((int)rb->strlen(ptr) < display_columns) + { + rb->lcd_puts(0, lines, output); lines++; - break; - } + break; + } /* get the last spacechar */ @@ -210,7 +211,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) next = display_columns; } - /* put the line on screen */ + /* put the line on screen */ rb->lcd_puts(0, lines, output); /* get output count */ @@ -240,6 +241,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) } rb->close(fIndex); - rb->close(fData); + rb->close(fData); return PLUGIN_OK; } diff --git a/tools/rdf2binary.c b/tools/rdf2binary.c index 3597efa727..c1c7d1b727 100644 --- a/tools/rdf2binary.c +++ b/tools/rdf2binary.c @@ -30,60 +30,73 @@ 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 */ #define WORDLEN 32 -struct word { - char word[WORDLEN]; - long offset; +struct word +{ + char word[WORDLEN]; + 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() { - FILE *in; - int idx_out, desc_out; - struct word w; - char buf[10000]; - long cur_offset = 0; - - in = fopen("dict.preparsed", "r"); - idx_out = open("dict.index", O_WRONLY | O_CREAT); - desc_out = open("dict.desc", O_WRONLY | O_CREAT); - - if (in == NULL || idx_out < 0 || desc_out < 0) { - fprintf(stderr, "Error: Some files couldn't be opened\n"); - return 1; - } - - while (fgets(buf, sizeof buf, in) != NULL) { - /* It is safe to use strtok here */ - const char *word = strtok(buf, "\t"); - const char *desc = strtok(NULL, "\t"); - - if (word == NULL || desc == NULL) { - fprintf(stderr, "Parse error!\n"); - fprintf(stderr, "word: %s\ndesc: %s\n", word, desc); - - return 2; - } - - /* We will null-terminate the words */ - strncpy(w.word, word, WORDLEN - 1); - w.offset = cur_offset; - write(idx_out, &w, sizeof(struct word)); - - while (1) { - int len = strlen(desc); - cur_offset += len; - write(desc_out, desc, len); - - desc = strtok(NULL, "\t"); - if (desc == NULL) - break ; - - cur_offset++; - write(desc_out, "\n", 1); - - } - } - - return 0; + FILE *in; + int idx_out, desc_out; + struct word w; + char buf[10000]; + long cur_offset = 0; + + in = fopen("dict.preparsed", "r"); + idx_out = open("dict.index", O_WRONLY | O_CREAT); + desc_out = open("dict.desc", O_WRONLY | O_CREAT); + + if (in == NULL || idx_out < 0 || desc_out < 0) + { + fprintf(stderr, "Error: Some files couldn't be opened\n"); + return 1; + } + + while (fgets(buf, sizeof buf, in) != NULL) + { + /* It is safe to use strtok here */ + const char *word = strtok(buf, "\t"); + const char *desc = strtok(NULL, "\t"); + + if (word == NULL || desc == NULL) + { + fprintf(stderr, "Parse error!\n"); + fprintf(stderr, "word: %s\ndesc: %s\n", word, desc); + + return 2; + } + + /* We will null-terminate the words */ + strncpy(w.word, word, WORDLEN - 1); + w.offset = long_to_big_endian(&cur_offset); + write(idx_out, &w, sizeof(struct word)); + + while (1) + { + int len = strlen(desc); + cur_offset += len; + write(desc_out, desc, len); + + desc = strtok(NULL, "\t"); + if (desc == NULL) + break ; + + cur_offset++; + write(desc_out, "\n", 1); + + } + } + + return 0; }