summaryrefslogtreecommitdiff
path: root/apps/plugins/text_editor.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_editor.c')
-rw-r--r--apps/plugins/text_editor.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c
index e54935265c..f18e7134e3 100644
--- a/apps/plugins/text_editor.c
+++ b/apps/plugins/text_editor.c
@@ -21,19 +21,16 @@
21#include "plugin.h" 21#include "plugin.h"
22#include "lib/playback_control.h" 22#include "lib/playback_control.h"
23 23
24#if PLUGIN_BUFFER_SIZE > 0x45000
25#define MAX_CHARS 0x40000 /* 256 kiB */
26#else
27#define MAX_CHARS 0x6000 /* 24 kiB */
28#endif
29#define MAX_LINE_LEN 2048 24#define MAX_LINE_LEN 2048
30PLUGIN_HEADER 25PLUGIN_HEADER
31 26
32static char buffer[MAX_CHARS]; 27static unsigned char *buffer;
33static int char_count = 0; 28static size_t buffer_size;
29static size_t char_count = 0;
34static int line_count = 0; 30static int line_count = 0;
35static int last_action_line = 0; 31static int last_action_line = 0;
36static int last_char_index = 0; 32static int last_char_index = 0;
33static bool audio_buf = false;
37 34
38#define ACTION_INSERT 0 35#define ACTION_INSERT 0
39#define ACTION_GET 1 36#define ACTION_GET 1
@@ -73,7 +70,7 @@ char* _do_action(int action, char* str, int line)
73 { 70 {
74 case ACTION_INSERT: 71 case ACTION_INSERT:
75 len = rb->strlen(str)+1; 72 len = rb->strlen(str)+1;
76 if ( char_count+ len > MAX_CHARS ) 73 if ( char_count+ len > buffer_size )
77 return NULL; 74 return NULL;
78 rb->memmove(&buffer[c+len],&buffer[c],char_count-c); 75 rb->memmove(&buffer[c+len],&buffer[c],char_count-c);
79 rb->strcpy(&buffer[c],str); 76 rb->strcpy(&buffer[c],str);
@@ -97,7 +94,7 @@ char* _do_action(int action, char* str, int line)
97 return NULL; 94 return NULL;
98 len = rb->strlen(&buffer[c])+1; 95 len = rb->strlen(&buffer[c])+1;
99 lennew = rb->strlen(str)+1; 96 lennew = rb->strlen(str)+1;
100 if ( char_count+ lennew-len > MAX_CHARS ) 97 if ( char_count+ lennew-len > buffer_size )
101 return NULL; 98 return NULL;
102 rb->memmove(&buffer[c+lennew],&buffer[c+len],char_count-c-len); 99 rb->memmove(&buffer[c+lennew],&buffer[c+len],char_count-c-len);
103 rb->strcpy(&buffer[c],str); 100 rb->strcpy(&buffer[c],str);
@@ -272,7 +269,10 @@ int do_item_menu(int cur_sel, char* copy_buffer)
272 ret = MENU_RET_SAVE; 269 ret = MENU_RET_SAVE;
273 break; 270 break;
274 case 6: /* playback menu */ 271 case 6: /* playback menu */
275 playback_control(NULL); 272 if (!audio_buf)
273 playback_control(NULL);
274 else
275 rb->splash(HZ, "Cannot restart playback");
276 ret = MENU_RET_NO_UPDATE; 276 ret = MENU_RET_NO_UPDATE;
277 break; 277 break;
278 default: 278 default:
@@ -336,6 +336,7 @@ enum plugin_status plugin_start(const void* parameter)
336#if LCD_DEPTH > 1 336#if LCD_DEPTH > 1
337 rb->lcd_set_backdrop(NULL); 337 rb->lcd_set_backdrop(NULL);
338#endif 338#endif
339 buffer = rb->plugin_get_buffer(&buffer_size);
339 340
340#ifdef HAVE_ADJUSTABLE_CPU_FREQ 341#ifdef HAVE_ADJUSTABLE_CPU_FREQ
341 rb->cpu_boost(1); 342 rb->cpu_boost(1);
@@ -358,6 +359,11 @@ enum plugin_status plugin_start(const void* parameter)
358 if (c && !rb->strcmp(c, ".colours")) 359 if (c && !rb->strcmp(c, ".colours"))
359 edit_colors_file = true; 360 edit_colors_file = true;
360#endif 361#endif
362 if (buffer_size <= (size_t)rb->filesize(fd) + 0x400)
363 {
364 buffer = rb->plugin_get_audio_buffer(&buffer_size);
365 audio_buf = true;
366 }
361 /* read in the file */ 367 /* read in the file */
362 while (rb->read_line(fd,temp_line,MAX_LINE_LEN) > 0) 368 while (rb->read_line(fd,temp_line,MAX_LINE_LEN) > 0)
363 { 369 {
@@ -487,7 +493,10 @@ enum plugin_status plugin_start(const void* parameter)
487 case 0: 493 case 0:
488 break; 494 break;
489 case 1: 495 case 1:
490 playback_control(NULL); 496 if (!audio_buf)
497 playback_control(NULL);
498 else
499 rb->splash(HZ, "Cannot restart playback");
491 break; 500 break;
492 case 2: //save to disk 501 case 2: //save to disk
493 if(save_changes(1)) 502 if(save_changes(1))