summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aa16138)
raw | patch | inline | side by side (parent: aa16138)
author | Jonas Fonseca <fonseca@diku.dk> | |
Thu, 15 Jan 2009 13:44:40 +0000 (14:44 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Thu, 15 Jan 2009 14:57:46 +0000 (15:57 +0100) |
tig.c | patch | blob | history |
index 4eafe767a7d894084e4d302e7a471dc801aa0545..725bc2eda7da956e0f2d04cf4fa61f628661982b 100644 (file)
--- a/tig.c
+++ b/tig.c
return data ? add_line_data(view, data, type) : NULL;
}
+static struct line *
+add_line_format(struct view *view, enum line_type type, const char *fmt, ...)
+{
+ char buf[SIZEOF_STR];
+ va_list args;
+
+ va_start(args, fmt);
+ if (vsnprintf(buf, sizeof(buf), fmt, args) >= sizeof(buf))
+ buf[0] = 0;
+ va_end(args);
+
+ return buf[0] ? add_line_text(view, buf, type) : NULL;
+}
/*
* View opening
static bool
help_open(struct view *view)
{
- char buf[BUFSIZ];
int lines = ARRAY_SIZE(req_info) + 2;
int i;
if (!*key)
key = "(no key defined)";
- if (!string_format(buf, " %-25s %s", key, req_info[i].help))
- continue;
-
- add_line_text(view, buf, LINE_DEFAULT);
+ add_line_format(view, LINE_DEFAULT, " %-25s %s",
+ key, req_info[i].help);
}
if (run_requests) {
argc ? " " : "", req->argv[argc]))
return REQ_NONE;
- if (!string_format(buf, " %-10s %-14s `%s`",
- keymap_table[req->keymap].name, key, cmd))
- continue;
-
- add_line_text(view, buf, LINE_DEFAULT);
+ add_line_format(view, LINE_DEFAULT, " %-10s %-14s `%s`",
+ keymap_table[req->keymap].name, key, cmd);
}
return TRUE;
tree_read(struct view *view, char *text)
{
size_t textlen = text ? strlen(text) : 0;
- char buf[SIZEOF_STR];
unsigned long pos;
enum line_type type;
- bool first_read = view->lines == 0;
if (!text)
return TRUE;
type = text[STRING_SIZE("100644 ")] == 't'
? LINE_TREE_DIR : LINE_TREE_FILE;
- if (first_read) {
- /* Add path info line */
- if (!string_format(buf, "Directory path /%s", opt_path) ||
- !add_line_text(view, buf, LINE_DEFAULT))
- return FALSE;
-
- /* Insert "link" to parent directory. */
- if (*opt_path) {
- if (!string_format(buf, TREE_UP_FORMAT, view->ref) ||
- !add_line_text(view, buf, LINE_TREE_DIR))
- return FALSE;
- }
- }
+ if (view->lines == 0 &&
+ !add_line_format(view, LINE_DEFAULT, "Directory path /%s", opt_path))
+ return FALSE;
/* Strip the path part ... */
if (*opt_path) {
if (pathlen > striplen)
memmove(path, path + striplen,
pathlen - striplen + 1);
+
+ /* Insert "link" to parent directory. */
+ if (view->lines == 1 &&
+ !add_line_format(view, LINE_TREE_DIR, TREE_UP_FORMAT, view->ref))
+ return FALSE;
}
/* Skip "Directory ..." and ".." line. */