summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 24b5b3e)
raw | patch | inline | side by side (parent: 24b5b3e)
author | Jonas Fonseca <fonseca@diku.dk> | |
Wed, 31 May 2006 20:14:34 +0000 (22:14 +0200) | ||
committer | Jonas Fonseca <fonseca@antimatter.localdomain> | |
Wed, 31 May 2006 20:14:34 +0000 (22:14 +0200) |
tig.c | patch | blob | history |
index decc4348c6a67e2aed5c8173d5232732044c9d3e..22943f09f408bb41fc0b418f15895edff5f9c53a 100644 (file)
--- a/tig.c
+++ b/tig.c
/* Buffering */
unsigned long lines; /* Total number of lines */
struct line *line; /* Line index */
+ unsigned long line_size;/* Total number of allocated lines */
unsigned int digits; /* Number of digits in the lines member. */
/* Loading */
return TRUE;
}
+static struct line *
+realloc_lines(struct view *view, size_t line_size)
+{
+ struct line *tmp = realloc(view->line, sizeof(*view->line) * line_size);
+
+ if (!tmp)
+ return NULL;
+
+ view->line = tmp;
+ view->line_size = line_size;
+ return view->line;
+}
+
static bool
update_view(struct view *view)
{
char buffer[BUFSIZ];
char *line;
- struct line *tmp;
/* The number of lines to read. If too low it will cause too much
* redrawing (and possible flickering), if too high responsiveness
* will suffer. */
if (view->offset + view->height >= view->lines)
redraw_from = view->lines - view->offset;
- tmp = realloc(view->line, sizeof(*view->line) * (view->lines + lines));
- if (!tmp)
+ if (!realloc_lines(view, view->lines + lines))
goto alloc_error;
- view->line = tmp;
-
while ((line = fgets(buffer, sizeof(buffer), view->pipe))) {
int linelen = strlen(line);