diff options
author | Tomas Salfischberger <tomas@rockbox.org> | 2005-06-05 14:21:51 +0000 |
---|---|---|
committer | Tomas Salfischberger <tomas@rockbox.org> | 2005-06-05 14:21:51 +0000 |
commit | b3c417b3aadb7305a4602ba80358cc7cec3bfe6a (patch) | |
tree | 53f1dc41f80379ca64215c7ba73ff25a029b1919 /apps | |
parent | 1cae074668603fd9a27e0b428bbe4823bdaab74a (diff) | |
download | rockbox-b3c417b3aadb7305a4602ba80358cc7cec3bfe6a.tar.gz rockbox-b3c417b3aadb7305a4602ba80358cc7cec3bfe6a.zip |
(1) Replaced endian code, this is a little more readable.
(2) Made dict files more configurable (and relative to the rockbox path)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6570 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/dict.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/apps/plugins/dict.c b/apps/plugins/dict.c index 95d49b01de..441f7400b3 100644 --- a/apps/plugins/dict.c +++ b/apps/plugins/dict.c | |||
@@ -27,12 +27,20 @@ static int display_columns, display_lines; | |||
27 | /* Some lenghts */ | 27 | /* Some lenghts */ |
28 | #define WORDLEN 32 /* has to be the same in rdf2binary.c */ | 28 | #define WORDLEN 32 /* has to be the same in rdf2binary.c */ |
29 | 29 | ||
30 | /* Struct packing */ | ||
31 | #ifdef __GNUC__ | ||
32 | #define STRUCT_PACKED __attribute__((packed)) | ||
33 | #else | ||
34 | #define STRUCT_PACKED | ||
35 | #pragma pack (push, 2) | ||
36 | #endif | ||
37 | |||
30 | /* The word struct :) */ | 38 | /* The word struct :) */ |
31 | struct stWord | 39 | struct stWord |
32 | { | 40 | { |
33 | char word[WORDLEN]; | 41 | char word[WORDLEN]; |
34 | long offset; | 42 | long offset; |
35 | }; | 43 | } STRUCT_PACKED; |
36 | 44 | ||
37 | /* A funtion to get width and height etc (from viewer.c) */ | 45 | /* A funtion to get width and height etc (from viewer.c) */ |
38 | void init_screen(void) | 46 | void init_screen(void) |
@@ -79,13 +87,15 @@ void pl_malloc_init(void) | |||
79 | 87 | ||
80 | /* for endian problems */ | 88 | /* for endian problems */ |
81 | #ifdef ROCKBOX_BIG_ENDIAN | 89 | #ifdef ROCKBOX_BIG_ENDIAN |
82 | #define readlong(x) x | 90 | #define reverse(x) x |
83 | #else | 91 | #else |
84 | long readlong(void* value) | 92 | long reverse (long N) { |
85 | { | 93 | unsigned char B[4]; |
86 | unsigned char* bytes = (unsigned char*) value; | 94 | B[0] = (N & 0x000000FF) >> 0; |
87 | return (long)bytes[0] | ((long)bytes[1] << 8) | | 95 | B[1] = (N & 0x0000FF00) >> 8; |
88 | ((long)bytes[2] << 16) | ((long)bytes[3] << 24); | 96 | B[2] = (N & 0x00FF0000) >> 16; |
97 | B[3] = (N & 0xFF000000) >> 24; | ||
98 | return ((B[0] << 24) | (B[1] << 16) | (B[2] << 8) | (B[3] << 0)); | ||
89 | } | 99 | } |
90 | #endif | 100 | #endif |
91 | 101 | ||
@@ -96,6 +106,10 @@ long readlong(void* value) | |||
96 | #define LP_QUIT BUTTON_OFF | 106 | #define LP_QUIT BUTTON_OFF |
97 | #endif | 107 | #endif |
98 | 108 | ||
109 | /* data files */ | ||
110 | #define DICT_INDEX ROCKBOX_DIR "/dict.index" | ||
111 | #define DICT_DESC ROCKBOX_DIR "/dict.desc" | ||
112 | |||
99 | /* the main plugin function */ | 113 | /* the main plugin function */ |
100 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 114 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
101 | { | 115 | { |
@@ -140,7 +154,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
140 | 154 | ||
141 | rb->kbd_input(searchword, sizeof(searchword)); /* get the word to search */ | 155 | rb->kbd_input(searchword, sizeof(searchword)); /* get the word to search */ |
142 | 156 | ||
143 | fIndex = rb->open("/.rockbox/dict.index", O_RDONLY); /* index file */ | 157 | fIndex = rb->open(DICT_INDEX, O_RDONLY); /* index file */ |
144 | if (fIndex < 0) | 158 | if (fIndex < 0) |
145 | { | 159 | { |
146 | DEBUGF("Err: Failed to open index file.\n"); | 160 | DEBUGF("Err: Failed to open index file.\n"); |
@@ -189,10 +203,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
189 | return PLUGIN_OK; | 203 | return PLUGIN_OK; |
190 | } | 204 | } |
191 | 205 | ||
192 | DEBUGF("Found %s at offset %d\n", word.word, readlong(&word.offset)); | 206 | DEBUGF("Found %s at offset %d\n", word.word, reverse(word.offset)); |
193 | 207 | ||
194 | /* now open the description file */ | 208 | /* now open the description file */ |
195 | fData = rb->open("/.rockbox/dict.desc", O_RDONLY); | 209 | fData = rb->open(DICT_DESC, O_RDONLY); |
196 | if (fData < 0) | 210 | if (fData < 0) |
197 | { | 211 | { |
198 | DEBUGF("Err: Failed to open description file.\n"); | 212 | DEBUGF("Err: Failed to open description file.\n"); |
@@ -202,7 +216,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
202 | } | 216 | } |
203 | 217 | ||
204 | /* seek to the right offset */ | 218 | /* seek to the right offset */ |
205 | rb->lseek(fData, (off_t)readlong(&word.offset), SEEK_SET); | 219 | rb->lseek(fData, (off_t)reverse(word.offset), SEEK_SET); |
206 | 220 | ||
207 | /* Read in the description */ | 221 | /* Read in the description */ |
208 | rb->read_line(fData, description, display_columns * display_lines); | 222 | rb->read_line(fData, description, display_columns * display_lines); |