summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-08-28 21:46:27 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-08-28 21:46:27 +0000
commitbc2b74b0fb1fca37b95a28ad89bae12bd95ed951 (patch)
treecae3106759a3a6e0a96e05a348abcd8c6f2baa00 /apps/plugins
parentcf2ce17d0998e3cdcb055b4ffceafe8c94cd66a0 (diff)
downloadrockbox-bc2b74b0fb1fca37b95a28ad89bae12bd95ed951.tar.gz
rockbox-bc2b74b0fb1fca37b95a28ad89bae12bd95ed951.zip
properties: remove some text buffers
use lcd_putsf() remove filesize2string, instead get the "logarithm" (rounded towards zero) and use the this value to compute the size displayed and the unit prefix (nothing/k/m/g) also use struct initializer in dir_properties() git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27923 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/properties.c70
1 files changed, 32 insertions, 38 deletions
diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c
index 2e34a4e048..b8a982e908 100644
--- a/apps/plugins/properties.c
+++ b/apps/plugins/properties.c
@@ -39,25 +39,17 @@ char str_duration[32];
39 39
40int num_properties; 40int num_properties;
41 41
42static char* filesize2string(long long size, char* pstr, int len) 42static const char human_size_prefix[4] = { '\0', 'K', 'M', 'G' };
43static unsigned human_size_log(long long size)
43{ 44{
44 /* margin set at 10K boundary: 10239 B +1 => 10 KB 45 const size_t n = sizeof(human_size_prefix)/sizeof(human_size_prefix[0]);
45 routine below is 200 bytes smaller than cascaded if/else :) 46
46 not using build-in function because of huge values (long long) */ 47 unsigned i;
47 const char* kgb[4] = { "B", "KB", "MB", "GB" }; 48 /* margin set at 10K boundary: 10239 B +1 => 10 KB */
48 int i = 0; 49 for(i=0; i < n-1 && size >= 10*1024; i++)
49 while(true)
50 {
51 if((size < 10240) || (i > 2))
52 {
53 /* depends on the order in the above array */
54 rb->snprintf(pstr, len, "%ld %s", (long)size, kgb[i]);
55 break;
56 }
57 size >>= 10; /* div by 1024 */ 50 size >>= 10; /* div by 1024 */
58 i++; 51
59 } 52 return i;
60 return pstr;
61} 53}
62 54
63static bool file_properties(char* selected_file) 55static bool file_properties(char* selected_file)
@@ -79,12 +71,13 @@ static bool file_properties(char* selected_file)
79 { 71 {
80 if(!rb->strcmp(entry->d_name, selected_file+dirlen)) 72 if(!rb->strcmp(entry->d_name, selected_file+dirlen))
81 { 73 {
82 rb->snprintf(str_dirname, sizeof str_dirname, "Path: %s", 74 unsigned log;
83 tstr); 75 rb->snprintf(str_dirname, sizeof str_dirname, "Path: %s", tstr);
84 rb->snprintf(str_filename, sizeof str_filename, "Name: %s", 76 rb->snprintf(str_filename, sizeof str_filename, "Name: %s",
85 selected_file+dirlen); 77 selected_file+dirlen);
86 rb->snprintf(str_size, sizeof str_size, "Size: %s", 78 log = human_size_log(entry->size);
87 filesize2string(entry->size, tstr, sizeof tstr)); 79 rb->snprintf(str_size, sizeof str_size, "Size: %ld %cB",
80 entry->size >> (log*10), human_size_prefix[log]);
88 rb->snprintf(str_date, sizeof str_date, "Date: %04d/%02d/%02d", 81 rb->snprintf(str_date, sizeof str_date, "Date: %04d/%02d/%02d",
89 ((entry->wrtdate >> 9 ) & 0x7F) + 1980, /* year */ 82 ((entry->wrtdate >> 9 ) & 0x7F) + 1980, /* year */
90 ((entry->wrtdate >> 5 ) & 0x0F), /* month */ 83 ((entry->wrtdate >> 5 ) & 0x0F), /* month */
@@ -145,8 +138,6 @@ typedef struct {
145 unsigned int dc; 138 unsigned int dc;
146 unsigned int fc; 139 unsigned int fc;
147 long long bc; 140 long long bc;
148 char tstr[64];
149 char tstr2[64];
150} DPS; 141} DPS;
151 142
152static bool _dir_properties(DPS* dps) 143static bool _dir_properties(DPS* dps)
@@ -173,6 +164,8 @@ static bool _dir_properties(DPS* dps)
173 164
174 if (entry->attribute & ATTR_DIRECTORY) 165 if (entry->attribute & ATTR_DIRECTORY)
175 { 166 {
167 unsigned log;
168
176 if (!rb->strcmp((char *)entry->d_name, ".") || 169 if (!rb->strcmp((char *)entry->d_name, ".") ||
177 !rb->strcmp((char *)entry->d_name, "..")) 170 !rb->strcmp((char *)entry->d_name, ".."))
178 continue; /* skip these */ 171 continue; /* skip these */
@@ -182,13 +175,11 @@ static bool _dir_properties(DPS* dps)
182 rb->lcd_puts(0,0,"SCANNING..."); 175 rb->lcd_puts(0,0,"SCANNING...");
183 rb->lcd_puts(0,1,dps->dirname); 176 rb->lcd_puts(0,1,dps->dirname);
184 rb->lcd_puts(0,2,entry->d_name); 177 rb->lcd_puts(0,2,entry->d_name);
185 rb->snprintf(dps->tstr, 64, "Directories: %d", dps->dc); 178 rb->lcd_putsf(0,3,"Directories: %d", dps->dc);
186 rb->lcd_puts(0,3,dps->tstr); 179 rb->lcd_putsf(0,4,"Files: %d", dps->fc);
187 rb->snprintf(dps->tstr, 64, "Files: %d", dps->fc); 180 log = human_size_log(dps->bc);
188 rb->lcd_puts(0,4,dps->tstr); 181 rb->lcd_putsf(0,5,"Size: %lld %cB", dps->bc >> (10*log),
189 rb->snprintf(dps->tstr, 64, "Size: %s", 182 human_size_prefix[log]);
190 filesize2string(dps->bc, dps->tstr2, 64));
191 rb->lcd_puts(0,5,dps->tstr);
192 rb->lcd_update(); 183 rb->lcd_update();
193 184
194 /* recursion */ 185 /* recursion */
@@ -209,21 +200,24 @@ static bool _dir_properties(DPS* dps)
209 200
210static bool dir_properties(char* selected_file) 201static bool dir_properties(char* selected_file)
211{ 202{
212 DPS dps; 203 unsigned log;
213 char tstr[64]; 204 DPS dps = {
205 .len = MAX_PATH,
206 .dc = 0,
207 .fc = 0,
208 .bc = 0,
209 };
214 rb->strlcpy(dps.dirname, selected_file, MAX_PATH); 210 rb->strlcpy(dps.dirname, selected_file, MAX_PATH);
215 dps.len = MAX_PATH; 211
216 dps.dc = 0;
217 dps.fc = 0;
218 dps.bc = 0;
219 if(false == _dir_properties(&dps)) 212 if(false == _dir_properties(&dps))
220 return false; 213 return false;
221 214
222 rb->strlcpy(str_dirname, selected_file, MAX_PATH); 215 rb->strlcpy(str_dirname, selected_file, MAX_PATH);
223 rb->snprintf(str_dircount, sizeof str_dircount, "Subdirs: %d", dps.dc); 216 rb->snprintf(str_dircount, sizeof str_dircount, "Subdirs: %d", dps.dc);
224 rb->snprintf(str_filecount, sizeof str_filecount, "Files: %d", dps.fc); 217 rb->snprintf(str_filecount, sizeof str_filecount, "Files: %d", dps.fc);
225 rb->snprintf(str_size, sizeof str_size, "Size: %s", 218 log = human_size_log(dps.bc);
226 filesize2string(dps.bc, tstr, sizeof tstr)); 219 rb->snprintf(str_size, sizeof str_size, "Size: %lld %cB",
220 dps.bc >> (log*10), human_size_prefix[log]);
227 num_properties = 4; 221 num_properties = 4;
228 return true; 222 return true;
229} 223}