summaryrefslogtreecommitdiff
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
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
-rw-r--r--apps/plugins/dict.c23
-rw-r--r--tools/rdf2binary.c115
2 files changed, 76 insertions, 62 deletions
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)
52} 52}
53 53
54/* for endian problems */ 54/* for endian problems */
55#ifdef LITTLE_ENDIAN 55#ifdef ROCKBOX_BIG_ENDIAN
56#define readlong(x) x 56#define readlong(x) x
57#else 57#else
58long readlong(void* value) 58long readlong(void* value)
@@ -140,7 +140,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
140 { 140 {
141 DEBUGF("Not found.\n"); 141 DEBUGF("Not found.\n");
142 rb->splash(HZ*2, true, "Not found."); 142 rb->splash(HZ*2, true, "Not found.");
143 rb->close(fIndex); 143 rb->close(fIndex);
144 return PLUGIN_OK; 144 return PLUGIN_OK;
145 } 145 }
146 146
@@ -152,7 +152,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
152 { 152 {
153 DEBUGF("Err: Failed to open description file.\n"); 153 DEBUGF("Err: Failed to open description file.\n");
154 rb->splash(HZ*2, true, "Failed to open descriptions."); 154 rb->splash(HZ*2, true, "Failed to open descriptions.");
155 rb->close(fIndex); 155 rb->close(fIndex);
156 return PLUGIN_ERROR; 156 return PLUGIN_ERROR;
157 } 157 }
158 158
@@ -187,14 +187,15 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
187 { 187 {
188 /* copy one lcd line */ 188 /* copy one lcd line */
189 rb->strncpy(output, ptr, display_columns); 189 rb->strncpy(output, ptr, display_columns);
190 output[display_columns] = '\0'; 190 output[display_columns] = '\0';
191 191
192 /* unsigned to kill a warning... */ 192 /* typecast to kill a warning... */
193 if((int)rb->strlen(ptr) < display_columns) { 193 if((int)rb->strlen(ptr) < display_columns)
194 rb->lcd_puts(0, lines, output); 194 {
195 rb->lcd_puts(0, lines, output);
195 lines++; 196 lines++;
196 break; 197 break;
197 } 198 }
198 199
199 200
200 /* get the last spacechar */ 201 /* get the last spacechar */
@@ -210,7 +211,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
210 next = display_columns; 211 next = display_columns;
211 } 212 }
212 213
213 /* put the line on screen */ 214 /* put the line on screen */
214 rb->lcd_puts(0, lines, output); 215 rb->lcd_puts(0, lines, output);
215 216
216 /* get output count */ 217 /* get output count */
@@ -240,6 +241,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
240 } 241 }
241 242
242 rb->close(fIndex); 243 rb->close(fIndex);
243 rb->close(fData); 244 rb->close(fData);
244 return PLUGIN_OK; 245 return PLUGIN_OK;
245} 246}
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.
30/* maximum word lenght, has to be the same in dict.c */ 30/* maximum word lenght, has to be the same in dict.c */
31#define WORDLEN 32 31#define WORDLEN 32
32 32
33struct word { 33struct word
34 char word[WORDLEN]; 34{
35 long offset; 35 char word[WORDLEN];
36 long offset;
36}; 37};
37 38
39/* convert offsets here, not on device. */
40long long_to_big_endian (void* value)
41{
42 unsigned char* bytes = (unsigned char*) value;
43 return (long)bytes[0] | ((long)bytes[1] << 8) |
44 ((long)bytes[2] << 16) | ((long)bytes[3] << 24);
45}
46
38int main() 47int main()
39{ 48{
40 FILE *in; 49 FILE *in;
41 int idx_out, desc_out; 50 int idx_out, desc_out;
42 struct word w; 51 struct word w;
43 char buf[10000]; 52 char buf[10000];
44 long cur_offset = 0; 53 long cur_offset = 0;
45 54
46 in = fopen("dict.preparsed", "r"); 55 in = fopen("dict.preparsed", "r");
47 idx_out = open("dict.index", O_WRONLY | O_CREAT); 56 idx_out = open("dict.index", O_WRONLY | O_CREAT);
48 desc_out = open("dict.desc", O_WRONLY | O_CREAT); 57 desc_out = open("dict.desc", O_WRONLY | O_CREAT);
49 58
50 if (in == NULL || idx_out < 0 || desc_out < 0) { 59 if (in == NULL || idx_out < 0 || desc_out < 0)
51 fprintf(stderr, "Error: Some files couldn't be opened\n"); 60 {
52 return 1; 61 fprintf(stderr, "Error: Some files couldn't be opened\n");
53 } 62 return 1;
54 63 }
55 while (fgets(buf, sizeof buf, in) != NULL) { 64
56 /* It is safe to use strtok here */ 65 while (fgets(buf, sizeof buf, in) != NULL)
57 const char *word = strtok(buf, "\t"); 66 {
58 const char *desc = strtok(NULL, "\t"); 67 /* It is safe to use strtok here */
59 68 const char *word = strtok(buf, "\t");
60 if (word == NULL || desc == NULL) { 69 const char *desc = strtok(NULL, "\t");
61 fprintf(stderr, "Parse error!\n"); 70
62 fprintf(stderr, "word: %s\ndesc: %s\n", word, desc); 71 if (word == NULL || desc == NULL)
63 72 {
64 return 2; 73 fprintf(stderr, "Parse error!\n");
65 } 74 fprintf(stderr, "word: %s\ndesc: %s\n", word, desc);
66 75
67 /* We will null-terminate the words */ 76 return 2;
68 strncpy(w.word, word, WORDLEN - 1); 77 }
69 w.offset = cur_offset; 78
70 write(idx_out, &w, sizeof(struct word)); 79 /* We will null-terminate the words */
71 80 strncpy(w.word, word, WORDLEN - 1);
72 while (1) { 81 w.offset = long_to_big_endian(&cur_offset);
73 int len = strlen(desc); 82 write(idx_out, &w, sizeof(struct word));
74 cur_offset += len; 83
75 write(desc_out, desc, len); 84 while (1)
76 85 {
77 desc = strtok(NULL, "\t"); 86 int len = strlen(desc);
78 if (desc == NULL) 87 cur_offset += len;
79 break ; 88 write(desc_out, desc, len);
80 89
81 cur_offset++; 90 desc = strtok(NULL, "\t");
82 write(desc_out, "\n", 1); 91 if (desc == NULL)
83 92 break ;
84 } 93
85 } 94 cur_offset++;
86 95 write(desc_out, "\n", 1);
87 return 0; 96
97 }
98 }
99
100 return 0;
88} 101}
89 102