Fixed scanning of folders and producing the output.
Showing
1 changed file
with
54 additions
and
55 deletions
... | @@ -254,51 +254,49 @@ _scan (const char *name, int depth) | ... | @@ -254,51 +254,49 @@ _scan (const char *name, int depth) |
254 | info.name = strdup (name); | 254 | info.name = strdup (name); |
255 | while ((entry = readdir (dir))) | 255 | while ((entry = readdir (dir))) |
256 | { | 256 | { |
257 | switch (entry->d_name[0]) | 257 | if (entry->d_name[0] == '.') |
258 | { | 258 | { |
259 | case '.': | ||
260 | if (strcmp (entry->d_name, mh_seq_name) == 0) | 259 | if (strcmp (entry->d_name, mh_seq_name) == 0) |
261 | read_seq_file (&info, name, entry->d_name); | 260 | read_seq_file (&info, name, entry->d_name); |
262 | break; | 261 | } |
263 | 262 | else if (entry->d_name[0] != ',') | |
264 | case ',': | 263 | { |
265 | continue; | ||
266 | |||
267 | case '0':case '1':case '2':case '3':case '4': | ||
268 | case '5':case '6':case '7':case '8':case '9': | ||
269 | uid = strtoul (entry->d_name, &p, 10); | ||
270 | if (*p) | ||
271 | info.others++; | ||
272 | else | ||
273 | { | ||
274 | info.message_count++; | ||
275 | if (info.min == 0 || uid < info.min) | ||
276 | info.min = uid; | ||
277 | if (uid > info.max) | ||
278 | info.max = uid; | ||
279 | } | ||
280 | break; | ||
281 | |||
282 | default: | ||
283 | asprintf (&p, "%s/%s", name, entry->d_name); | 264 | asprintf (&p, "%s/%s", name, entry->d_name); |
284 | if (stat (p, &st) < 0) | 265 | if (stat (p, &st) < 0) |
285 | { | 266 | mh_error ("can't stat %s: %s", p, strerror (errno)); |
286 | mh_error ("can't stat %s: %s", p, strerror (errno)); | ||
287 | info.others++; | ||
288 | } | ||
289 | else if (S_ISDIR (st.st_mode)) | 267 | else if (S_ISDIR (st.st_mode)) |
290 | { | 268 | { |
269 | info.others++; | ||
291 | _scan (p, depth+1); | 270 | _scan (p, depth+1); |
292 | } | 271 | } |
293 | else | 272 | else |
294 | /* Invalid entry. */ | 273 | { |
295 | info.others++; | 274 | char *endp; |
296 | free (p); | 275 | uid = strtoul (entry->d_name, &endp, 10); |
276 | if (*endp) | ||
277 | info.others++; | ||
278 | else | ||
279 | { | ||
280 | info.message_count++; | ||
281 | if (info.min == 0 || uid < info.min) | ||
282 | info.min = uid; | ||
283 | if (uid > info.max) | ||
284 | info.max = uid; | ||
285 | } | ||
286 | } | ||
297 | } | 287 | } |
298 | 288 | } | |
289 | |||
290 | if (info.cur) | ||
291 | { | ||
292 | asprintf (&p, "%s/%lu", name, (unsigned long) info.cur); | ||
293 | if (stat (p, &st) < 0 || !S_ISREG (st.st_mode)) | ||
294 | info.cur = 0; | ||
295 | free (p); | ||
299 | } | 296 | } |
300 | closedir (dir); | 297 | closedir (dir); |
301 | install_folder_info (name, &info); | 298 | if (depth > 0) |
299 | install_folder_info (name, &info); | ||
302 | } | 300 | } |
303 | 301 | ||
304 | static void | 302 | static void |
... | @@ -309,39 +307,41 @@ print_all () | ... | @@ -309,39 +307,41 @@ print_all () |
309 | for (info = folder_info; info < end; info++) | 307 | for (info = folder_info; info < end; info++) |
310 | { | 308 | { |
311 | int len = strlen (info->name); | 309 | int len = strlen (info->name); |
312 | printf ("%s", info->name); | 310 | if (len < 22) |
311 | printf ("%22.22s", info->name); | ||
312 | else | ||
313 | printf ("%s", info->name); | ||
314 | |||
313 | if (strcmp (info->name, current_folder) == 0) | 315 | if (strcmp (info->name, current_folder) == 0) |
314 | { | 316 | printf ("+"); |
315 | printf ("+"); | 317 | else |
316 | len++; | 318 | printf (" "); |
317 | } | 319 | |
318 | |||
319 | for (; len < 20; len++) | ||
320 | putchar (' '); | ||
321 | |||
322 | if (info->message_count) | 320 | if (info->message_count) |
323 | { | 321 | { |
324 | printf (" has %4lu messages (%4lu-%4lu)", | 322 | printf (info->message_count == 1 ? |
323 | " has %4lu message (%4lu-%4lu)" : | ||
324 | " has %4lu messages (%4lu-%4lu)", | ||
325 | (unsigned long) info->message_count, | 325 | (unsigned long) info->message_count, |
326 | (unsigned long) info->min, | 326 | (unsigned long) info->min, |
327 | (unsigned long) info->max); | 327 | (unsigned long) info->max); |
328 | if (info->cur) | 328 | if (info->cur) |
329 | printf ("; cur=%4lu", (unsigned long) info->cur); | 329 | printf ("; cur=%4lu", (unsigned long) info->cur); |
330 | |||
331 | if (info->others) | ||
332 | { | ||
333 | if (!info->cur) | ||
334 | printf ("; "); | ||
335 | else | ||
336 | printf ("; "); | ||
337 | printf ("(others)"); | ||
338 | } | ||
339 | printf (".\n"); | ||
340 | } | 330 | } |
341 | else | 331 | else |
342 | { | 332 | { |
343 | printf (" has no messages.\n"); | 333 | printf (" has no messages"); |
334 | } | ||
335 | |||
336 | if (info->others) | ||
337 | { | ||
338 | if (!info->cur) | ||
339 | printf ("; "); | ||
340 | else | ||
341 | printf ("; "); | ||
342 | printf ("(others)"); | ||
344 | } | 343 | } |
344 | printf (".\n"); | ||
345 | } | 345 | } |
346 | } | 346 | } |
347 | 347 | ||
... | @@ -374,7 +374,6 @@ action_print () | ... | @@ -374,7 +374,6 @@ action_print () |
374 | if (show_all) | 374 | if (show_all) |
375 | { | 375 | { |
376 | _scan (mu_path_folder_dir, 0); | 376 | _scan (mu_path_folder_dir, 0); |
377 | folder_info_count--; /* do not count folder directory */ | ||
378 | } | 377 | } |
379 | else | 378 | else |
380 | { | 379 | { |
... | @@ -398,7 +397,7 @@ action_print () | ... | @@ -398,7 +397,7 @@ action_print () |
398 | print_all (); | 397 | print_all (); |
399 | 398 | ||
400 | if (print_total) | 399 | if (print_total) |
401 | printf ("%24.24s=%4lu messages in %4lu folders\n", | 400 | printf ("\n%24.24s=%4lu messages in %4lu folders\n", |
402 | "TOTAL", | 401 | "TOTAL", |
403 | (unsigned long) message_count, | 402 | (unsigned long) message_count, |
404 | (unsigned long) folder_info_count); | 403 | (unsigned long) folder_info_count); | ... | ... |
-
Please register or sign in to post a comment