summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer/tv_reader.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_viewer/tv_reader.c')
-rw-r--r--apps/plugins/text_viewer/tv_reader.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/apps/plugins/text_viewer/tv_reader.c b/apps/plugins/text_viewer/tv_reader.c
index 6dc66ef567..4e91af9f98 100644
--- a/apps/plugins/text_viewer/tv_reader.c
+++ b/apps/plugins/text_viewer/tv_reader.c
@@ -135,7 +135,6 @@ void tv_seek(off_t offset, int whence)
135static void tv_change_preferences(const struct tv_preferences *oldp) 135static void tv_change_preferences(const struct tv_preferences *oldp)
136{ 136{
137 unsigned char bom[BOM_SIZE]; 137 unsigned char bom[BOM_SIZE];
138 const struct tv_preferences *prefs = tv_get_preferences();
139 int cur_start_file_pos = start_file_pos; 138 int cur_start_file_pos = start_file_pos;
140 off_t cur_file_pos = file_pos + buf_pos; 139 off_t cur_file_pos = file_pos + buf_pos;
141 140
@@ -145,21 +144,21 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
145 start_file_pos = 0; 144 start_file_pos = 0;
146 145
147 /* open the new file */ 146 /* open the new file */
148 if (oldp == NULL || rb->strcmp(oldp->file_name, prefs->file_name)) 147 if (oldp == NULL || rb->strcmp(oldp->file_name, preferences->file_name))
149 { 148 {
150 if (fd >= 0) 149 if (fd >= 0)
151 rb->close(fd); 150 rb->close(fd);
152 151
153 fd = rb->open(prefs->file_name, O_RDONLY); 152 fd = rb->open(preferences->file_name, O_RDONLY);
154 if (fd < 0) 153 if (fd < 0)
155 return; 154 return;
156 } 155 }
157 156
158 /* 157 /*
159 * When a file is UTF-8 file with BOM, if prefs.encoding is UTF-8, 158 * When a file is UTF-8 file with BOM, if encoding is UTF-8,
160 * then file size decreases only BOM_SIZE. 159 * then file size decreases only BOM_SIZE.
161 */ 160 */
162 if (prefs->encoding == UTF_8) 161 if (preferences->encoding == UTF_8)
163 { 162 {
164 rb->lseek(fd, 0, SEEK_SET); 163 rb->lseek(fd, 0, SEEK_SET);
165 rb->read(fd, bom, BOM_SIZE); 164 rb->read(fd, bom, BOM_SIZE);
@@ -171,16 +170,20 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
171 tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET); 170 tv_seek(cur_file_pos + cur_start_file_pos - start_file_pos, SEEK_SET);
172} 171}
173 172
174bool tv_init_reader(unsigned char *buf, size_t bufsize, size_t *used_size) 173bool tv_init_reader(void)
175{ 174{
176 if (bufsize < 2 * TV_MIN_BLOCK_SIZE) 175 size_t size;
176
177 /* get the plugin buffer */
178 reader_buffer = rb->plugin_get_buffer(&size);
179
180 if (size < 2 * TV_MIN_BLOCK_SIZE)
177 return false; 181 return false;
178 182
179 reader_buffer = buf; 183 block_size = size / 2;
180 block_size = bufsize / 2;
181 buffer_size = 2 * block_size; 184 buffer_size = 2 * block_size;
182 *used_size = buffer_size;
183 tv_add_preferences_change_listner(tv_change_preferences); 185 tv_add_preferences_change_listner(tv_change_preferences);
186
184 return true; 187 return true;
185} 188}
186 189