move two functions up in tog.c; avoids forward-declaration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
diff --git a/tog/tog.c b/tog/tog.c
index f2f94c3..1869ae4 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -83,8 +83,6 @@ show_diff_view(struct got_object *, struct got_object *,
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)
{
@@ -94,6 +92,81 @@ 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)
{
@@ -776,80 +849,6 @@ parse_next_line(FILE *f, size_t *len)
}
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)
{