summaryrefslogtreecommitdiffstats
path: root/curs_lib.c
diff options
context:
space:
mode:
authorEdmund GRIMLEY EVANS <edmundo@rano.org>2000-08-28 09:38:42 +0000
committerEdmund GRIMLEY EVANS <edmundo@rano.org>2000-08-28 09:38:42 +0000
commitfd6c3f53f9c016155a1dcfbc1dd70fd835d336f3 (patch)
tree5783422284681275c086a6c3096887efbcaba76f /curs_lib.c
parentd5a7673eb772377c22adfb9cfbc1efd9d6239182 (diff)
This patch moves hdr_format_s from hdrline.c to curs_lib.c and renames
it to mutt_format_s. The function is then used in various places in browser.c and recvattach.c where previously there was "%%%ss".
Diffstat (limited to 'curs_lib.c')
-rw-r--r--curs_lib.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/curs_lib.c b/curs_lib.c
index 6e7f4447..7947653d 100644
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -541,6 +541,39 @@ void mutt_format_string (char *dest, size_t destlen,
}
/*
+ * This formats a string rather like
+ * snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
+ * snprintf (dest, destlen, fmt, s);
+ * except that the numbers in the conversion specification refer to
+ * the number of character cells when printed.
+ */
+
+void mutt_format_s (char *dest,
+ size_t destlen,
+ const char *prefix,
+ const char *s)
+{
+ int right_justify = 1;
+ char *p;
+ int min_width;
+ int max_width = INT_MAX;
+
+ if (*prefix == '-')
+ ++prefix, right_justify = 0;
+ min_width = strtol (prefix, &p, 10);
+ if (*p == '.')
+ {
+ prefix = p + 1;
+ max_width = strtol (prefix, &p, 10);
+ if (p <= prefix)
+ max_width = INT_MAX;
+ }
+
+ mutt_format_string (dest, destlen, min_width, max_width,
+ right_justify, ' ', s, mutt_strlen (s));
+}
+
+/*
* mutt_paddstr (n, s) is almost equivalent to
* mutt_format_string (bigbuf, big, n, n, 0, ' ', s, big), addstr (bigbuf)
*/