summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0b26677)
raw | patch | inline | side by side (parent: 0b26677)
author | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 3 Feb 2009 11:50:52 +0000 (12:50 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 3 Feb 2009 14:34:58 +0000 (15:34 +0100) |
tig.c | patch | blob | history |
index 53b2fdbf3dff95872a09c1e17dbc0ba0702ba1bd..ffeaa857dc39d70797018027d17ebd4a2c02c048 100644 (file)
--- a/tig.c
+++ b/tig.c
#define string_add(dst, from, src) \
string_ncopy_do(dst + (from), sizeof(dst) - (from), src, sizeof(src))
+static size_t
+string_expand_length(const char *line, int tabsize)
+{
+ size_t size, pos;
+
+ for (pos = 0; line[pos]; pos++) {
+ if (line[pos] == '\t' && tabsize > 0)
+ size += tabsize - (size % tabsize);
+ else
+ size++;
+ }
+ return size;
+}
+
+static void
+string_expand(char *dst, size_t dstlen, const char *src, int tabsize)
+{
+ size_t size, pos;
+
+ for (size = pos = 0; size < dstlen - 1 && src[pos]; pos++) {
+ if (src[pos] == '\t') {
+ size_t expanded = tabsize - (size % tabsize);
+
+ if (expanded + size >= dstlen - 1)
+ expanded = dstlen - size - 1;
+ memcpy(dst + size, " ", expanded);
+ size += expanded;
+ } else {
+ dst[size++] = src[pos];
+ }
+ }
+
+ dst[size] = 0;
+}
+
static char *
chomp_string(char *name)
{
static bool
pager_draw(struct view *view, struct line *line, unsigned int lineno)
{
- char *text = line->data;
+ char text[SIZEOF_STR];
if (opt_line_number && draw_lineno(view, lineno))
return TRUE;
+ string_expand(text, sizeof(text), line->data, opt_tab_size);
draw_text(view, line->type, text, TRUE);
return TRUE;
}
return FALSE;
} else {
- size_t linelen = strlen(line);
+ size_t linelen = string_expand_length(line, opt_tab_size);
struct blame *blame = malloc(sizeof(*blame) + linelen);
+ if (!blame)
+ return FALSE;
+
blame->commit = NULL;
- strncpy(blame->text, line, linelen);
- blame->text[linelen] = 0;
+ string_expand(blame->text, linelen + 1, line, opt_tab_size);
return add_line_data(view, blame, LINE_BLAME_ID) != NULL;
}
}
/* FIXME: More graceful handling of titles; append "..." to
* shortened titles, etc. */
- string_ncopy(commit->title, line, strlen(line));
+ string_expand(commit->title, sizeof(commit->title), line, 1);
view->line[view->lines - 1].dirty = 1;
}