summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorTomas Salfischberger <tomas@rockbox.org>2005-05-02 16:06:05 +0000
committerTomas Salfischberger <tomas@rockbox.org>2005-05-02 16:06:05 +0000
commit23028f579b011601b2c9e7d37868d4e1b577d910 (patch)
treecba7df08a348baa576e7c09900bc97252a989205 /tools
parente2f5dba61c77d83b42676b0572f89d876007a019 (diff)
downloadrockbox-23028f579b011601b2c9e7d37868d4e1b577d910.tar.gz
rockbox-23028f579b011601b2c9e7d37868d4e1b577d910.zip
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
Diffstat (limited to 'tools')
-rw-r--r--tools/rdf2binary.c115
1 files changed, 64 insertions, 51 deletions
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;
}