summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7b99a34)
raw | patch | inline | side by side (parent: 7b99a34)
author | Jonas Fonseca <fonseca@diku.dk> | |
Wed, 31 May 2006 21:16:38 +0000 (23:16 +0200) | ||
committer | Jonas Fonseca <fonseca@antimatter.localdomain> | |
Wed, 31 May 2006 21:16:38 +0000 (23:16 +0200) |
tig.c | patch | blob | history |
index 1192c2307a1fe5d85c5f20b3a2247bfbfa19555d..1f428a2f40ee0d692b6d2ac163192ce8a685f0ef 100644 (file)
--- a/tig.c
+++ b/tig.c
return name;
}
+static bool
+string_nformat(char *buf, size_t bufsize, int *bufpos, const char *fmt, ...)
+{
+ va_list args;
+ int pos = bufpos ? *bufpos : 0;
+
+ va_start(args, fmt);
+ pos += vsnprintf(buf + pos, bufsize - pos, fmt, args);
+ va_end(args);
+
+ if (bufpos)
+ *bufpos = pos;
+
+ return pos >= bufsize ? FALSE : TRUE;
+}
+
+#define string_format(buf, fmt, args...) \
+ string_nformat(buf, sizeof(buf), NULL, fmt, args)
+
+#define string_format_from(buf, from, fmt, args...) \
+ string_nformat(buf, sizeof(buf), from, fmt, args)
/* Shell quoting
*
config_lineno = 0;
config_errors = FALSE;
- if (!home ||
- snprintf(buf, sizeof(buf), "%s/.tigrc", home) >= sizeof(buf))
+ if (!home || !string_format(buf, "%s/.tigrc", home))
return ERR;
/* It's ok that the file doesn't exist. */
} else {
const char *format = view->cmd_env ? view->cmd_env : view->cmd_fmt;
- if (snprintf(view->cmd, sizeof(view->cmd), format,
- id, id, id, id, id) >= sizeof(view->cmd))
+ if (!string_format(view->cmd, format, id, id, id, id, id))
return FALSE;
}
return;
do {
- char *begin = "", *end = "";
+ struct ref *ref = refs[refpos];
+ char *fmt = ref->tag ? "%s[%s]" : "%s%s";
- if (refs[refpos]->tag) {
- begin = "[";
- end = "]";
- }
-
- bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos,
- "%s%s%s%s", sep, begin, refs[refpos]->name,
- end);
- if (bufpos >= sizeof(buf))
- break;
+ if (!string_format_from(buf, &bufpos, fmt, sep, ref->name))
+ return;
sep = ", ";
} while (refs[refpos++]->next);
- if (!bufpos ||
- bufpos >= sizeof(buf) ||
- !realloc_lines(view, view->line_size + 1))
+ if (!realloc_lines(view, view->line_size + 1))
return;
line = &view->line[view->lines];
if (!seq)
seq = "'?'";
- pos += snprintf(buf + pos, sizeof(buf) - pos, "%s%s", sep, seq);
- if (pos >= sizeof(buf))
+ if (!string_format_from(buf, &pos, "%s%s", sep, seq))
return "Too many keybindings!";
sep = ", ";
}
}
key = get_key(req_info[i].request);
- if (snprintf(buf, sizeof(buf), "%-25s %s", key, req_info[i].help)
- >= sizeof(buf))
+ if (string_format(buf, "%-25s %s", key, req_info[i].help))
continue;
pager_read(view, NULL, buf);