diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c old mode 100644 new mode 100755 index f01afbb..ea3f6c7 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -32,12 +32,12 @@ PLUGIN_HEADER #define WRAP_TRIM 44 /* Max number of spaces to trim (arbitrary) */ #define MAX_COLUMNS 64 /* Max displayable string len (over-estimate) */ #define MAX_WIDTH 910 /* Max line length in WIDE mode */ -#define READ_PREV_ZONE 910 /* Arbitrary number less than SMALL_BLOCK_SIZE */ -#define SMALL_BLOCK_SIZE 0x1000 /* 4k: Smallest file chunk we will read */ -#define LARGE_BLOCK_SIZE 0x2000 /* 8k: Preferable size of file chunk to read */ +#define READ_PREV_ZONE (block_size*9/10) /* Arbitrary number less than SMALL_BLOCK_SIZE */ +#define SMALL_BLOCK_SIZE block_size /* 4k: Smallest file chunk we will read */ +#define LARGE_BLOCK_SIZE (block_size << 1) /* 8k: Preferable size of file chunk to read */ #define TOP_SECTOR buffer #define MID_SECTOR (buffer + SMALL_BLOCK_SIZE) -#define BOTTOM_SECTOR (buffer + 2*(SMALL_BLOCK_SIZE)) +#define BOTTOM_SECTOR (buffer + (SMALL_BLOCK_SIZE << 1)) #define SCROLLBAR_WIDTH 6 #define MAX_BOOKMARKED_FILES ((buffer_size/(signed)sizeof(struct bookmarked_file_info))-1) @@ -411,6 +411,7 @@ struct preferences old_prefs; static unsigned char *buffer; static long buffer_size; +static long block_size = 0x1000; static unsigned char line_break[] = {0,0x20,9,0xB,0xC,'-'}; static int display_columns; /* number of (pixel) columns on the display */ static int display_lines; /* number of lines on the display */ @@ -481,6 +482,8 @@ static unsigned char* crop_at_width(const unsigned char* p) while (LINE_IS_NOT_FULL) { oldp = p; + if (BUFFER_OOB(p)) + break; p = get_ucs(p, &ch); ADVANCE_COUNTERS(ch); } @@ -666,7 +669,11 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho next_line++; if (BUFFER_OOB(next_line)) + { + if (BUFFER_EOF() && next_line != cur_line) + return (unsigned char*) next_line; return NULL; + } if (is_short) *is_short = false; @@ -1517,6 +1524,13 @@ enum plugin_status plugin_start(const void* file) /* get the plugin buffer */ buffer = rb->plugin_get_buffer((size_t *)&buffer_size); + if (buffer_size == 0) + { + rb->splash(HZ, "buffer does not allocate !!"); + return PLUGIN_ERROR; + } + block_size = buffer_size / 3; + buffer_size = 3 * block_size; if (!file) return PLUGIN_ERROR;