Commit 7b2c07f9 7b2c07f9701573f679d292423064c18e074c8cad by Sergey Poznyakoff

MH: minor change in folder

* mh/folder.c: Use mu_list_t instead of obstack to keep folder list.
1 parent bd55279a
Showing 1 changed file with 66 additions and 62 deletions
...@@ -28,10 +28,6 @@ ...@@ -28,10 +28,6 @@
28 28
29 #include <dirent.h> 29 #include <dirent.h>
30 30
31 #define obstack_chunk_alloc malloc
32 #define obstack_chunk_free free
33 #include <obstack.h>
34
35 static char doc[] = N_("GNU MH folder")"\v" 31 static char doc[] = N_("GNU MH folder")"\v"
36 N_("Use -help to obtain the list of traditional MH options."); 32 N_("Use -help to obtain the list of traditional MH options.");
37 static char args_doc[] = N_("[ACTION] [MSG]"); 33 static char args_doc[] = N_("[ACTION] [MSG]");
...@@ -243,10 +239,7 @@ struct folder_info ...@@ -243,10 +239,7 @@ struct folder_info
243 size_t others; /* Number of non-message files */ 239 size_t others; /* Number of non-message files */
244 }; 240 };
245 241
246 struct obstack folder_info_stack; /* Memory storage for folder infp */ 242 mu_list_t folder_info_list; /* Memory storage for folder info */
247 struct folder_info *folder_info; /* Finalized array of information
248 structures */
249 size_t folder_info_count; /* Number of the entries in the array */
250 243
251 size_t message_count; /* Total number of messages */ 244 size_t message_count; /* Total number of messages */
252 245
...@@ -255,9 +248,10 @@ int name_prefix_len; /* Length of the mu_path_folder_dir */ ...@@ -255,9 +248,10 @@ int name_prefix_len; /* Length of the mu_path_folder_dir */
255 void 248 void
256 install_folder_info (const char *name, struct folder_info *info) 249 install_folder_info (const char *name, struct folder_info *info)
257 { 250 {
258 info->name = strdup (name) + name_prefix_len; 251 struct folder_info *new_info = xmalloc (sizeof (*new_info));
259 obstack_grow (&folder_info_stack, info, sizeof (*info)); 252 *new_info = *info;
260 folder_info_count++; 253 new_info->name = strdup (new_info->name + name_prefix_len);
254 mu_list_append (folder_info_list, new_info);
261 message_count += info->message_count; 255 message_count += info->message_count;
262 } 256 }
263 257
...@@ -321,7 +315,7 @@ _scan (const char *name, size_t depth) ...@@ -321,7 +315,7 @@ _scan (const char *name, size_t depth)
321 if (fast_mode && depth > 0) 315 if (fast_mode && depth > 0)
322 { 316 {
323 memset (&info, 0, sizeof (info)); 317 memset (&info, 0, sizeof (info));
324 info.name = strdup (name); 318 info.name = name;
325 install_folder_info (name, &info); 319 install_folder_info (name, &info);
326 closedir (dir); 320 closedir (dir);
327 return; 321 return;
...@@ -382,60 +376,69 @@ _scan (const char *name, size_t depth) ...@@ -382,60 +376,69 @@ _scan (const char *name, size_t depth)
382 if (depth > 0) 376 if (depth > 0)
383 install_folder_info (name, &info); 377 install_folder_info (name, &info);
384 } 378 }
385 379
386 static void 380 static int
387 print_all () 381 _folder_info_printer (void *item, void *data)
388 { 382 {
389 struct folder_info *info, *end = folder_info + folder_info_count; 383 struct folder_info *info = item;
384 int len = strlen (info->name);
390 385
391 for (info = folder_info; info < end; info++) 386 if (len < 22)
387 printf ("%22.22s", info->name);
388 else
389 printf ("%s", info->name);
390
391 if (strcmp (info->name, mh_current_folder ()) == 0)
392 printf ("+");
393 else
394 printf (" ");
395
396 if (info->message_count)
392 { 397 {
393 int len = strlen (info->name); 398 printf (ngettext(" has %4lu message (%4lu-%4lu)",
394 if (len < 22) 399 " has %4lu messages (%4lu-%4lu)",
395 printf ("%22.22s", info->name); 400 info->message_count),
396 else 401 (unsigned long) info->message_count,
397 printf ("%s", info->name); 402 (unsigned long) info->min,
398 403 (unsigned long) info->max);
399 if (strcmp (info->name, mh_current_folder ()) == 0) 404 if (info->cur)
400 printf ("+"); 405 printf ("; cur=%4lu", (unsigned long) info->cur);
401 else 406 }
402 printf (" "); 407 else
403 408 {
404 if (info->message_count) 409 printf (_(" has no messages"));
405 { 410 }
406 printf (ngettext(" has %4lu message (%4lu-%4lu)", 411
407 " has %4lu messages (%4lu-%4lu)", 412 if (info->others)
408 info->message_count), 413 {
409 (unsigned long) info->message_count, 414 if (!info->cur)
410 (unsigned long) info->min, 415 printf ("; ");
411 (unsigned long) info->max);
412 if (info->cur)
413 printf ("; cur=%4lu", (unsigned long) info->cur);
414 }
415 else 416 else
416 { 417 printf ("; ");
417 printf (_(" has no messages")); 418 printf (_("(others)"));
418 }
419
420 if (info->others)
421 {
422 if (!info->cur)
423 printf ("; ");
424 else
425 printf ("; ");
426 printf (_("(others)"));
427 }
428 printf (".\n");
429 } 419 }
420 printf (".\n");
421 return 0;
422 }
423
424 static int
425 _folder_name_printer (void *item, void *data)
426 {
427 struct folder_info *info = item;
428 printf ("%s\n", info->name);
429 return 0;
430 } 430 }
431 431
432 static void 432 static void
433 print_fast () 433 print_all ()
434 { 434 {
435 struct folder_info *info, *end = folder_info + folder_info_count; 435 mu_list_foreach (folder_info_list, _folder_info_printer, NULL);
436 }
436 437
437 for (info = folder_info; info < end; info++) 438 static void
438 printf ("%s\n", info->name); 439 print_fast ()
440 {
441 mu_list_foreach (folder_info_list, _folder_name_printer, NULL);
439 } 442 }
440 443
441 static int 444 static int
...@@ -449,7 +452,7 @@ action_print () ...@@ -449,7 +452,7 @@ action_print ()
449 name_prefix_len++; 452 name_prefix_len++;
450 name_prefix_len++; /* skip past the slash */ 453 name_prefix_len++; /* skip past the slash */
451 454
452 obstack_init (&folder_info_stack); 455 mu_list_create (&folder_info_list);
453 456
454 if (show_all) 457 if (show_all)
455 { 458 {
...@@ -462,9 +465,7 @@ action_print () ...@@ -462,9 +465,7 @@ action_print ()
462 free (p); 465 free (p);
463 } 466 }
464 467
465 folder_info = obstack_finish (&folder_info_stack); 468 mu_list_sort (folder_info_list, folder_info_comp);
466 qsort (folder_info, folder_info_count, sizeof (folder_info[0]),
467 folder_info_comp);
468 469
469 if (fast_mode) 470 if (fast_mode)
470 print_fast (); 471 print_fast ();
...@@ -477,13 +478,16 @@ action_print () ...@@ -477,13 +478,16 @@ action_print ()
477 478
478 if (OPTION_IS_SET (print_total)) 479 if (OPTION_IS_SET (print_total))
479 { 480 {
481 size_t folder_count;
482
483 mu_list_count (folder_info_list, &folder_count);
480 printf ("\n%24.24s=", _("TOTAL")); 484 printf ("\n%24.24s=", _("TOTAL"));
481 printf (ngettext ("%4lu message ", "%4lu messages ", 485 printf (ngettext ("%4lu message ", "%4lu messages ",
482 message_count), 486 message_count),
483 (unsigned long) message_count); 487 (unsigned long) message_count);
484 printf (ngettext ("in %4lu folder", "in %4lu folders", 488 printf (ngettext ("in %4lu folder", "in %4lu folders",
485 folder_info_count), 489 folder_count),
486 (unsigned long) folder_info_count); 490 (unsigned long) folder_count);
487 printf ("\n"); 491 printf ("\n");
488 } 492 }
489 } 493 }
......