index 86c82db53ed679a284c8b385cd566f963036cea5..41d8123379eec382c30f9e7d9e9bb9c1f09892d2 100644 (file)
--- a/tig.c
+++ b/tig.c
#define ENUM_MAP(name, value) { name, STRING_SIZE(name), value }
#define ENUM_MAP(name, value) { name, STRING_SIZE(name), value }
+static char *
+enum_map_name(const char *name, size_t namelen)
+{
+ static char buf[SIZEOF_STR];
+ int bufpos;
+
+ for (bufpos = 0; bufpos <= namelen; bufpos++) {
+ buf[bufpos] = tolower(name[bufpos]);
+ if (buf[bufpos] == '_')
+ buf[bufpos] = '-';
+ }
+
+ buf[bufpos] = 0;
+ return buf;
+}
+
+#define enum_name(entry) enum_map_name((entry).name, (entry).namelen)
+
static bool
map_enum_do(const struct enum_map *map, size_t map_size, int *value, const char *name)
{
static bool
map_enum_do(const struct enum_map *map, size_t map_size, int *value, const char *name)
{
static char opt_head_rev[SIZEOF_REV] = "";
static char opt_remote[SIZEOF_REF] = "";
static char opt_encoding[20] = "UTF-8";
static char opt_head_rev[SIZEOF_REV] = "";
static char opt_remote[SIZEOF_REF] = "";
static char opt_encoding[20] = "UTF-8";
-static bool opt_utf8 = TRUE;
static char opt_codeset[20] = "UTF-8";
static char opt_codeset[20] = "UTF-8";
-static iconv_t opt_iconv = ICONV_NONE;
+static iconv_t opt_iconv_in = ICONV_NONE;
+static iconv_t opt_iconv_out = ICONV_NONE;
static char opt_search[SIZEOF_STR] = "";
static char opt_cdup[SIZEOF_STR] = "";
static char opt_prefix[SIZEOF_STR] = "";
static char opt_search[SIZEOF_STR] = "";
static char opt_cdup[SIZEOF_STR] = "";
static char opt_prefix[SIZEOF_STR] = "";
} else if (!strcmp(argv[2], "short")) {
opt_date = DATE_SHORT;
return OK;
} else if (!strcmp(argv[2], "short")) {
opt_date = DATE_SHORT;
return OK;
- } else if (parse_bool(&show_date, argv[2])) {
+ } else if (parse_bool(&show_date, argv[2]) == OK) {
opt_date = show_date ? DATE_DEFAULT : DATE_NONE;
opt_date = show_date ? DATE_DEFAULT : DATE_NONE;
+ return OK;
}
return ERR;
}
}
return ERR;
}
draw_chars(struct view *view, enum line_type type, const char *string,
int max_len, bool use_tilde)
{
draw_chars(struct view *view, enum line_type type, const char *string,
int max_len, bool use_tilde)
{
+ static char out_buffer[BUFSIZ * 2];
int len = 0;
int col = 0;
int trimmed = FALSE;
int len = 0;
int col = 0;
int trimmed = FALSE;
if (max_len <= 0)
return 0;
if (max_len <= 0)
return 0;
- if (opt_utf8) {
- len = utf8_length(&string, skip, &col, max_len, &trimmed, use_tilde);
- } else {
- col = len = strlen(string);
- if (len > max_len) {
- if (use_tilde) {
- max_len -= 1;
+ len = utf8_length(&string, skip, &col, max_len, &trimmed, use_tilde);
+
+ set_view_attr(view, type);
+ if (len > 0) {
+ if (opt_iconv_out != ICONV_NONE) {
+ ICONV_CONST char *inbuf = (ICONV_CONST char *) string;
+ size_t inlen = len + 1;
+
+ char *outbuf = out_buffer;
+ size_t outlen = sizeof(out_buffer);
+
+ size_t ret;
+
+ ret = iconv(opt_iconv_out, &inbuf, &inlen, &outbuf, &outlen);
+ if (ret != (size_t) -1) {
+ string = out_buffer;
+ len = sizeof(out_buffer) - outlen;
}
}
- col = len = max_len;
- trimmed = TRUE;
}
}
- }
- set_view_attr(view, type);
- if (len > 0)
waddnstr(view->win, string, len);
waddnstr(view->win, string, len);
+ }
if (trimmed && use_tilde) {
set_view_attr(view, LINE_DELIMITER);
waddch(view->win, '~');
if (trimmed && use_tilde) {
set_view_attr(view, LINE_DELIMITER);
waddch(view->win, '~');
"short"
};
"short"
};
- opt_date = (opt_date + 1) % ARRAY_SIZE(help);
+ *date = (*date + 1) % ARRAY_SIZE(help);
redraw_display(FALSE);
redraw_display(FALSE);
- report("Displaying %s dates", help[opt_date]);
+ report("Displaying %s dates", help[*date]);
}
static void
}
static void
}
for (; (line = io_get(view->pipe, '\n', can_read)); can_read = FALSE) {
}
for (; (line = io_get(view->pipe, '\n', can_read)); can_read = FALSE) {
- if (opt_iconv != ICONV_NONE) {
+ if (opt_iconv_in != ICONV_NONE) {
ICONV_CONST char *inbuf = line;
size_t inlen = strlen(line) + 1;
ICONV_CONST char *inbuf = line;
size_t inlen = strlen(line) + 1;
size_t ret;
size_t ret;
- ret = iconv(opt_iconv, &inbuf, &inlen, &outbuf, &outlen);
+ ret = iconv(opt_iconv_in, &inbuf, &inlen, &outbuf, &outlen);
if (ret != (size_t) -1)
line = out_buffer;
}
if (ret != (size_t) -1)
line = out_buffer;
}
static bool help_keymap_hidden[ARRAY_SIZE(keymap_table)];
static bool help_keymap_hidden[ARRAY_SIZE(keymap_table)];
-static char *
-help_name(char buf[SIZEOF_STR], const char *name, size_t namelen)
-{
- int bufpos;
-
- for (bufpos = 0; bufpos <= namelen; bufpos++) {
- buf[bufpos] = tolower(name[bufpos]);
- if (buf[bufpos] == '_')
- buf[bufpos] = '-';
- }
-
- buf[bufpos] = 0;
- return buf;
-}
-
-#define help_keymap_name(buf, keymap) \
- help_name(buf, keymap_table[keymap].name, keymap_table[keymap].namelen)
-
static bool
help_open_keymap_title(struct view *view, enum keymap keymap)
{
static bool
help_open_keymap_title(struct view *view, enum keymap keymap)
{
- char buf[SIZEOF_STR];
struct line *line;
line = add_line_format(view, LINE_HELP_KEYMAP, "[%c] %s bindings",
help_keymap_hidden[keymap] ? '+' : '-',
struct line *line;
line = add_line_format(view, LINE_HELP_KEYMAP, "[%c] %s bindings",
help_keymap_hidden[keymap] ? '+' : '-',
- help_keymap_name(buf, keymap));
+ enum_name(keymap_table[keymap]));
if (line)
line->other = keymap;
if (line)
line->other = keymap;
}
add_line_format(view, LINE_DEFAULT, " %-25s %-20s %s", key,
}
add_line_format(view, LINE_DEFAULT, " %-25s %-20s %s", key,
- help_name(buf, req_info[i].name, req_info[i].namelen),
- req_info[i].help);
+ enum_name(req_info[i]), req_info[i].help);
}
group = "External commands:";
}
group = "External commands:";
@@ -5304,7 +5310,7 @@ status_run(struct view *view, const char *argv[], char status, enum line_type ty
char *buf;
struct io io = {};
char *buf;
struct io io = {};
- if (!run_io(&io, argv, NULL, IO_RD))
+ if (!run_io(&io, argv, opt_cdup, IO_RD))
return FALSE;
add_line_data(view, NULL, type);
return FALSE;
add_line_data(view, NULL, type);
return run_io(io, staged_argv, opt_cdup, IO_WR);
case LINE_STAT_UNSTAGED:
return run_io(io, staged_argv, opt_cdup, IO_WR);
case LINE_STAT_UNSTAGED:
- return run_io(io, others_argv, opt_cdup, IO_WR);
-
case LINE_STAT_UNTRACKED:
case LINE_STAT_UNTRACKED:
- return run_io(io, others_argv, NULL, IO_WR);
+ return run_io(io, others_argv, opt_cdup, IO_WR);
default:
die("line type %d not handled in switch", type);
default:
die("line type %d not handled in switch", type);
if (!opt_git_dir[0] && request != REQ_VIEW_PAGER)
die("Not a git repository");
if (!opt_git_dir[0] && request != REQ_VIEW_PAGER)
die("Not a git repository");
- if (*opt_encoding && strcasecmp(opt_encoding, "UTF-8"))
- opt_utf8 = FALSE;
+ if (*opt_encoding && strcmp(opt_codeset, "UTF-8")) {
+ opt_iconv_in = iconv_open("UTF-8", opt_encoding);
+ if (opt_iconv_in == ICONV_NONE)
+ die("Failed to initialize character set conversion");
+ }
- if (*opt_codeset && strcmp(opt_codeset, opt_encoding)) {
- opt_iconv = iconv_open(opt_codeset, opt_encoding);
- if (opt_iconv == ICONV_NONE)
+ if (*opt_codeset && strcmp(opt_codeset, "UTF-8")) {
+ opt_iconv_out = iconv_open(opt_codeset, "UTF-8");
+ if (opt_iconv_out == ICONV_NONE)
die("Failed to initialize character set conversion");
}
die("Failed to initialize character set conversion");
}