summaryrefslogtreecommitdiff
path: root/ffprobe.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-01-18 19:27:53 +0100
committerStefano Sabatini <stefasab@gmail.com>2012-01-20 13:27:41 +0100
commit58b10b4c7ea568a7829a62be889e89aaa26da734 (patch)
tree9a3d9ad1ed418d7058868e3ae5dbed8b89ba3ec2 /ffprobe.c
parent72092188ef702ad215042bf464b8f2452f119e56 (diff)
ffprobe: factorize common code in value_string()
Diffstat (limited to 'ffprobe.c')
-rw-r--r--ffprobe.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/ffprobe.c b/ffprobe.c
index 169b99590f..bd88267ca4 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -102,11 +102,13 @@ static char *value_string(char *buf, int buf_size, struct unit_value uv)
hours = mins / 60;
mins %= 60;
snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
- } else if (use_value_prefix) {
- const char *prefix_string;
- long long int index;
+ } else {
+ const char *prefix_string = "";
int l;
+ if (use_value_prefix) {
+ long long int index;
+
if (uv.unit == unit_byte_str && use_byte_value_binary_prefix) {
index = (long long int) (log(vald)/log(2)) / 10;
index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);
@@ -118,18 +120,14 @@ static char *value_string(char *buf, int buf_size, struct unit_value uv)
vald /= pow(10, index * 3);
prefix_string = decimal_unit_prefixes[index];
}
+ }
- if (show_float || vald != (long long int)vald) l = snprintf(buf, buf_size, "%.3f", vald);
- else l = snprintf(buf, buf_size, "%lld", (long long int)vald);
- snprintf(buf+l, buf_size-l, "%s%s%s", prefix_string || show_value_unit ? " " : "",
+ if (show_float || (use_value_prefix && vald != (long long int)vald))
+ l = snprintf(buf, buf_size, "%.3f", vald);
+ else
+ l = snprintf(buf, buf_size, "%lld", (long long int)vald);
+ snprintf(buf+l, buf_size-l, "%s%s%s", *prefix_string || show_value_unit ? " " : "",
prefix_string, show_value_unit ? uv.unit : "");
- } else {
- int l;
-
- if (show_float) l = snprintf(buf, buf_size, "%.3f", vald);
- else l = snprintf(buf, buf_size, "%lld", (long long int)vald);
- snprintf(buf+l, buf_size-l, "%s%s", show_value_unit ? " " : "",
- show_value_unit ? uv.unit : "");
}
return buf;