|
2 | 2 | #include "common/parsing.h" |
3 | 3 |
|
4 | 4 | #include <ctype.h> |
5 | | -#include <inttypes.h> |
6 | 5 |
|
7 | 6 | #ifdef _WIN32 |
8 | 7 | #pragma GCC diagnostic push |
@@ -60,56 +59,6 @@ void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty) |
60 | 59 | ffStrbufAppendF(pretty, ".%u", version->patch); |
61 | 60 | } |
62 | 61 |
|
63 | | -static void parseSize(FFstrbuf* result, uint64_t bytes, uint32_t base, const char** prefixes) |
64 | | -{ |
65 | | - double size = (double) bytes; |
66 | | - uint8_t counter = 0; |
67 | | - |
68 | | - while(size >= base && counter < instance.config.display.sizeMaxPrefix && prefixes[counter + 1]) |
69 | | - { |
70 | | - size /= base; |
71 | | - counter++; |
72 | | - } |
73 | | - |
74 | | - if(counter == 0) |
75 | | - ffStrbufAppendF(result, "%" PRIu64 " %s", bytes, prefixes[0]); |
76 | | - else |
77 | | - ffStrbufAppendF(result, "%.*f %s", instance.config.display.sizeNdigits, size, prefixes[counter]); |
78 | | -} |
79 | | - |
80 | | -void ffParseSize(uint64_t bytes, FFstrbuf* result) |
81 | | -{ |
82 | | - switch (instance.config.display.sizeBinaryPrefix) |
83 | | - { |
84 | | - case FF_SIZE_BINARY_PREFIX_TYPE_IEC: |
85 | | - parseSize(result, bytes, 1024, (const char*[]) {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", NULL}); |
86 | | - break; |
87 | | - case FF_SIZE_BINARY_PREFIX_TYPE_SI: |
88 | | - parseSize(result, bytes, 1000, (const char*[]) {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", NULL}); |
89 | | - break; |
90 | | - case FF_SIZE_BINARY_PREFIX_TYPE_JEDEC: |
91 | | - parseSize(result, bytes, 1024, (const char*[]) {"B", "KB", "MB", "GB", "TB", NULL}); |
92 | | - break; |
93 | | - default: |
94 | | - parseSize(result, bytes, 1024, (const char*[]) {"B", NULL}); |
95 | | - break; |
96 | | - } |
97 | | -} |
98 | | - |
99 | | -bool ffParseFrequency(uint32_t mhz, FFstrbuf* result) |
100 | | -{ |
101 | | - if (mhz == 0) |
102 | | - return false; |
103 | | - |
104 | | - int8_t ndigits = instance.config.display.freqNdigits; |
105 | | - |
106 | | - if (ndigits >= 0) |
107 | | - ffStrbufAppendF(result, "%.*f GHz", ndigits, mhz / 1000.); |
108 | | - else |
109 | | - ffStrbufAppendF(result, "%u MHz", (unsigned) mhz); |
110 | | - return true; |
111 | | -} |
112 | | - |
113 | 62 | void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4) |
114 | 63 | { |
115 | 64 | if(gtk2->length > 0 && gtk3->length > 0 && gtk4->length > 0) |
@@ -190,61 +139,6 @@ void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, co |
190 | 139 | } |
191 | 140 | } |
192 | 141 |
|
193 | | -void ffParseDuration(uint64_t totalSeconds, FFstrbuf* result) |
194 | | -{ |
195 | | - if(totalSeconds < 60) |
196 | | - { |
197 | | - ffStrbufAppendF(result, "%u second", (unsigned) totalSeconds); |
198 | | - if (totalSeconds != 1) |
199 | | - ffStrbufAppendC(result, 's'); |
200 | | - return; |
201 | | - } |
202 | | - |
203 | | - uint32_t seconds = (uint32_t) (totalSeconds % 60); |
204 | | - totalSeconds /= 60; |
205 | | - if (seconds >= 30) |
206 | | - totalSeconds++; |
207 | | - |
208 | | - uint32_t minutes = (uint32_t) (totalSeconds % 60); |
209 | | - totalSeconds /= 60; |
210 | | - uint32_t hours = (uint32_t) (totalSeconds % 24); |
211 | | - totalSeconds /= 24; |
212 | | - uint32_t days = (uint32_t) totalSeconds; |
213 | | - |
214 | | - if(days > 0) |
215 | | - { |
216 | | - ffStrbufAppendF(result, "%u day", days); |
217 | | - |
218 | | - if(days > 1) |
219 | | - ffStrbufAppendC(result, 's'); |
220 | | - |
221 | | - if(days >= 100) |
222 | | - ffStrbufAppendS(result, "(!)"); |
223 | | - |
224 | | - if(hours > 0 || minutes > 0) |
225 | | - ffStrbufAppendS(result, ", "); |
226 | | - } |
227 | | - |
228 | | - if(hours > 0) |
229 | | - { |
230 | | - ffStrbufAppendF(result, "%u hour", hours); |
231 | | - |
232 | | - if(hours > 1) |
233 | | - ffStrbufAppendC(result, 's'); |
234 | | - |
235 | | - if(minutes > 0) |
236 | | - ffStrbufAppendS(result, ", "); |
237 | | - } |
238 | | - |
239 | | - if(minutes > 0) |
240 | | - { |
241 | | - ffStrbufAppendF(result, "%u min", minutes); |
242 | | - |
243 | | - if(minutes > 1) |
244 | | - ffStrbufAppendC(result, 's'); |
245 | | - } |
246 | | -} |
247 | | - |
248 | 142 | #ifdef _WIN32 |
249 | 143 | #pragma GCC diagnostic pop |
250 | 144 | #endif |
0 commit comments