commit - bb737323d9adbea8d1538f2d6d5246521b0ebd29
commit + 963b370f7700cff85517f5c097cffb9a55553006
blob - f2f94c39fb2a6f58db6b80933ff5029882d30637
blob + 1869ae4abd7d09e1fa6d34d1828179fe2f13366c
--- tog/tog.c
+++ tog/tog.c
static const struct got_error *
show_log_view(struct got_object_id *, struct got_repository *);
-static const struct got_error *format_line(wchar_t **, int *, char *, int);
-
__dead static void
usage_log(void)
{
exit(1);
}
+/* Create newly allocated wide-character string equivalent to a byte string. */
static const struct got_error *
+mbs2ws(wchar_t **ws, size_t *wlen, const char *s)
+{
+ const struct got_error *err = NULL;
+
+ *ws = NULL;
+ *wlen = mbstowcs(NULL, s, 0);
+ if (*wlen == (size_t)-1)
+ return got_error_from_errno();
+
+ *ws = calloc(*wlen + 1, sizeof(*ws));
+ if (*ws == NULL)
+ return got_error_from_errno();
+
+ if (mbstowcs(*ws, s, *wlen) != *wlen)
+ err = got_error_from_errno();
+
+ if (err) {
+ free(*ws);
+ *ws = NULL;
+ *wlen = 0;
+ }
+ return err;
+}
+
+/* Format a line for display, ensuring that it won't overflow a width limit. */
+static const struct got_error *
+format_line(wchar_t **wlinep, int *widthp, char *line, int wlimit)
+{
+ const struct got_error *err = NULL;
+ int cols = 0;
+ wchar_t *wline = NULL;
+ size_t wlen;
+ int i;
+
+ *wlinep = NULL;
+
+ err = mbs2ws(&wline, &wlen, line);
+ if (err)
+ return err;
+
+ i = 0;
+ while (i < wlen && cols <= wlimit) {
+ int width = wcwidth(wline[i]);
+ switch (width) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ cols += width;
+ break;
+ case -1:
+ if (wline[i] == L'\t')
+ cols += TABSIZE;
+ break;
+ default:
+ err = got_error_from_errno();
+ goto done;
+ }
+ if (cols <= COLS) {
+ i++;
+ if (widthp)
+ *widthp = cols;
+ }
+ }
+ wline[i] = L'\0';
+done:
+ if (err)
+ free(wline);
+ else
+ *wlinep = wline;
+ return err;
+}
+
+static const struct got_error *
draw_commit(struct got_commit_object *commit, struct got_object_id *id)
{
const struct got_error *err = NULL;
}
static const struct got_error *
-mbs2ws(wchar_t **ws, size_t *wlen, const char *s)
-{
- const struct got_error *err = NULL;
-
- *ws = NULL;
- *wlen = mbstowcs(NULL, s, 0);
- if (*wlen == (size_t)-1)
- return got_error_from_errno();
-
- *ws = calloc(*wlen + 1, sizeof(*ws));
- if (*ws == NULL)
- return got_error_from_errno();
-
- if (mbstowcs(*ws, s, *wlen) != *wlen)
- err = got_error_from_errno();
-
- if (err) {
- free(*ws);
- *ws = NULL;
- *wlen = 0;
- }
- return err;
-}
-
-/* Format a line for display, ensuring that it won't overflow a width limit. */
-static const struct got_error *
-format_line(wchar_t **wlinep, int *widthp, char *line, int wlimit)
-{
- const struct got_error *err = NULL;
- int cols = 0;
- wchar_t *wline = NULL;
- size_t wlen;
- int i;
-
- *wlinep = NULL;
-
- err = mbs2ws(&wline, &wlen, line);
- if (err)
- return err;
-
- i = 0;
- while (i < wlen && cols <= wlimit) {
- int width = wcwidth(wline[i]);
- switch (width) {
- case 0:
- break;
- case 1:
- case 2:
- cols += width;
- break;
- case -1:
- if (wline[i] == L'\t')
- cols += TABSIZE;
- break;
- default:
- err = got_error_from_errno();
- goto done;
- }
- if (cols <= COLS) {
- i++;
- if (widthp)
- *widthp = cols;
- }
- }
- wline[i] = L'\0';
-done:
- if (err)
- free(wline);
- else
- *wlinep = wline;
- return err;
-}
-
-static const struct got_error *
draw_diff(FILE *f, int *first_displayed_line, int *last_displayed_line,
int *eof, int max_lines)
{