case 's':
if (folder->ff->local)
{
- mutt_pretty_size(fn, sizeof(fn), folder->ff->size);
+ mutt_str_pretty_size(fn, sizeof(fn), folder->ff->size);
snprintf(fmt, sizeof(fmt), "%%%ss", prec);
snprintf(buf, buflen, fmt, fn);
}
case 'l': /* approx length of current message in bytes */
snprintf(fmt, sizeof(fmt), "%%%ss", prec);
- mutt_pretty_size(tmp, sizeof(tmp), menu ? cum_attachs_size(menu) : 0);
+ mutt_str_pretty_size(tmp, sizeof(tmp), menu ? cum_attachs_size(menu) : 0);
snprintf(buf, buflen, fmt, tmp);
break;
if (progress->size)
{
if (progress->flags & MUTT_PROGRESS_SIZE)
- mutt_pretty_size(progress->sizestr, sizeof(progress->sizestr), progress->size);
+ mutt_str_pretty_size(progress->sizestr, sizeof(progress->sizestr), progress->size);
else
snprintf(progress->sizestr, sizeof(progress->sizestr), "%zu", progress->size);
}
if (progress->flags & MUTT_PROGRESS_SIZE)
{
pos = pos / (progress->inc << 10) * (progress->inc << 10);
- mutt_pretty_size(posstr, sizeof(posstr), pos);
+ mutt_str_pretty_size(posstr, sizeof(posstr), pos);
}
else
snprintf(posstr, sizeof(posstr), "%ld", pos);
static void print_part_line(struct State *s, struct Body *b, int n)
{
char length[5];
- mutt_pretty_size(length, sizeof(length), b->length);
+ mutt_str_pretty_size(length, sizeof(length), b->length);
state_mark_attach(s);
char *charset = mutt_param_get("charset", b->parameter);
if (n != 0)
length = mutt_param_get("length", b->parameter);
if (length)
{
- mutt_pretty_size(pretty_size, sizeof(pretty_size), strtol(length, NULL, 10));
+ mutt_str_pretty_size(pretty_size, sizeof(pretty_size), strtol(length, NULL, 10));
state_printf(s, _("(size %s bytes) "), pretty_size);
}
state_puts(_("has been deleted --]\n"), s);
case 'c':
colorlen = add_index_color(buf, buflen, flags, MT_COLOR_INDEX_SIZE);
- mutt_pretty_size(tmp, sizeof(tmp), (long) hdr->content->length);
+ mutt_str_pretty_size(tmp, sizeof(tmp), (long) hdr->content->length);
mutt_format_s(buf + colorlen, buflen - colorlen, prec, tmp);
add_index_color(buf + colorlen, buflen - colorlen, flags, MT_COLOR_INDEX);
break;
p++;
return p;
}
+
+/**
+ * mutt_str_pretty_size - Display an abbreviated size, e.g. 3.4K
+ * @param buf Buffer for the result
+ * @param buflen Length of the buffer
+ * @param num Number to abbreviate
+ */
+void mutt_str_pretty_size(char *buf, size_t buflen, size_t num)
+{
+ if (num < 1000)
+ {
+ snprintf(buf, buflen, "%d", (int) num);
+ }
+ else if (num < 10189) /* 0.1K - 9.9K */
+ {
+ snprintf(buf, buflen, "%3.1fK", (num < 103) ? 0.1 : (num / 1024.0));
+ }
+ else if (num < 1023949) /* 10K - 999K */
+ {
+ /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
+ snprintf(buf, buflen, "%zuK", (num + 51) / 1024);
+ }
+ else if (num < 10433332) /* 1.0M - 9.9M */
+ {
+ snprintf(buf, buflen, "%3.1fM", num / 1048576.0);
+ }
+ else /* 10M+ */
+ {
+ /* (10433332 + 52428) / 1048576 = 10 */
+ snprintf(buf, buflen, "%zuM", (num + 52428) / 1048576);
+ }
+}
size_t mutt_str_lws_len(const char *s, size_t n);
size_t mutt_str_lws_rlen(const char *s, size_t n);
const char *mutt_str_next_word(const char *s);
+void mutt_str_pretty_size(char *buf, size_t buflen, size_t num);
void mutt_str_remove_trailing_ws(char *s);
void mutt_str_replace(char **p, const char *s);
const char *mutt_str_rstrnstr(const char *haystack, size_t haystack_length, const char *needle);
}
}
-void mutt_pretty_size(char *s, size_t len, size_t n)
-{
- if (n < 1000)
- snprintf(s, len, "%d", (int) n);
- else if (n < 10189) /* 0.1K - 9.9K */
- snprintf(s, len, "%3.1fK", (n < 103) ? 0.1 : n / 1024.0);
- else if (n < 1023949) /* 10K - 999K */
- {
- /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
- snprintf(s, len, "%zuK", (n + 51) / 1024);
- }
- else if (n < 10433332) /* 1.0M - 9.9M */
- snprintf(s, len, "%3.1fM", n / 1048576.0);
- else /* 10M+ */
- {
- /* (10433332 + 52428) / 1048576 = 10 */
- snprintf(s, len, "%zuM", (n + 52428) / 1048576);
- }
-}
-
void mutt_expand_file_fmt(char *dest, size_t destlen, const char *fmt, const char *src)
{
char tmp[LONG_STRING];
void mutt_prepare_envelope(struct Envelope *env, int final);
void mutt_unprepare_envelope(struct Envelope *env);
void mutt_pretty_mailbox(char *s, size_t buflen);
-void mutt_pretty_size(char *s, size_t len, size_t n);
void mutt_pipe_message(struct Header *h);
void mutt_print_message(struct Header *h);
void mutt_query_exit(void);
if (!optional)
{
- mutt_pretty_size(tmp, sizeof(tmp), l);
+ mutt_str_pretty_size(tmp, sizeof(tmp), l);
mutt_format_s(buf, buflen, prec, tmp);
}
else if (l == 0)
if (!optional)
{
snprintf(fmt, sizeof(fmt), "%%%ss", prec);
- mutt_pretty_size(tmp, sizeof(tmp), Context ? Context->size : 0);
+ mutt_str_pretty_size(tmp, sizeof(tmp), Context ? Context->size : 0);
snprintf(buf, buflen, fmt, tmp);
}
else if (!Context || !Context->size)
if (!optional)
{
snprintf(fmt, sizeof(fmt), "%%%ss", prec);
- mutt_pretty_size(tmp, sizeof(tmp), Context ? Context->vsize : 0);
+ mutt_str_pretty_size(tmp, sizeof(tmp), Context ? Context->vsize : 0);
snprintf(buf, buflen, fmt, tmp);
}
else if (!Context || !Context->pattern)