+static const char *checkpoint_total_format[] = {
+ "R",
+ "W",
+ "D"
+};
+
+static int
+getwidth (FILE *fp)
+{
+ struct winsize ws;
+
+ ws.ws_col = ws.ws_row = 0;
+ if ((ioctl (fileno (fp), TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_col == 0)
+ {
+ const char *col = getenv ("COLUMNS");
+ if (col)
+ return strtol (col, NULL, 10);
+ else
+ return 80;
+ }
+ return ws.ws_col;
+}
+
+static char *
+getarg (const char *input, const char ** endp, char **argbuf, size_t *arglen)
+{
+ if (input[0] == '{')
+ {
+ char *p = strchr (input + 1, '}');
+ if (p)
+ {
+ size_t n = p - input;
+ if (n > *arglen)
+ {
+ *arglen = n;
+ *argbuf = xrealloc (*argbuf, *arglen);
+ }
+ n--;
+ memcpy (*argbuf, input + 1, n);
+ (*argbuf)[n] = 0;
+ *endp = p + 1;
+ return *argbuf;
+ }
+ }
+
+ *endp = input;
+ return NULL;
+}
+
+static int tty_cleanup;
+
+static const char *def_format = "%s: %t: %T%*\r";
+
+static int
+format_checkpoint_string (FILE *fp, size_t len,
+ const char *input, bool do_write,
+ unsigned cpn)