frm: minor cleanup.
* frm/common.c (select_message, msg_index): Remove; use action data instead. (action): Use action data to get the selection function and message index. (frm_scan): Pass these data in action closure.
Showing
1 changed file
with
16 additions
and
17 deletions
... | @@ -405,16 +405,15 @@ get_personal (mu_header_t hdr, const char *field, char **personal) | ... | @@ -405,16 +405,15 @@ get_personal (mu_header_t hdr, const char *field, char **personal) |
405 | return status; | 405 | return status; |
406 | } | 406 | } |
407 | 407 | ||
408 | /* Observer action used to perform mailbox scanning. See the comment | 408 | /* Observer action is used to perform mailbox scanning. See the comment |
409 | to frm_scan below. | 409 | to frm_scan below. */ |
410 | 410 | ||
411 | FIXME: The observer action paradygm does not allow for making | 411 | struct frm_action_closure |
412 | procedure-data closure, as it should. So, for the time being | 412 | { |
413 | the following static variables are used instead: */ | 413 | frm_select_t select_message; /* Message selection function */ |
414 | 414 | size_t msg_index; /* Index (1-based) of the current | |
415 | static frm_select_t select_message; /* Message selection function */ | 415 | message */ |
416 | static size_t msg_index; /* Index (1-based) of the current | 416 | }; |
417 | message */ | ||
418 | 417 | ||
419 | /* Observable action is being called on discovery of each message. */ | 418 | /* Observable action is being called on discovery of each message. */ |
420 | /* FIXME: The format of the display is poorly done, please correct. */ | 419 | /* FIXME: The format of the display is poorly done, please correct. */ |
... | @@ -422,7 +421,8 @@ static int | ... | @@ -422,7 +421,8 @@ static int |
422 | action (mu_observer_t o, size_t type, void *data, void *action_data) | 421 | action (mu_observer_t o, size_t type, void *data, void *action_data) |
423 | { | 422 | { |
424 | int status; | 423 | int status; |
425 | 424 | struct frm_action_closure *clos = action_data; | |
425 | |||
426 | switch (type) | 426 | switch (type) |
427 | { | 427 | { |
428 | case MU_EVT_MESSAGE_ADD: | 428 | case MU_EVT_MESSAGE_ADD: |
... | @@ -432,17 +432,17 @@ action (mu_observer_t o, size_t type, void *data, void *action_data) | ... | @@ -432,17 +432,17 @@ action (mu_observer_t o, size_t type, void *data, void *action_data) |
432 | mu_header_t hdr = NULL; | 432 | mu_header_t hdr = NULL; |
433 | mu_attribute_t attr = NULL; | 433 | mu_attribute_t attr = NULL; |
434 | 434 | ||
435 | msg_index++; | 435 | clos->msg_index++; |
436 | 436 | ||
437 | mu_mailbox_get_message (mbox, msg_index, &msg); | 437 | mu_mailbox_get_message (mbox, clos->msg_index, &msg); |
438 | mu_message_get_attribute (msg, &attr); | 438 | mu_message_get_attribute (msg, &attr); |
439 | mu_message_get_header (msg, &hdr); | 439 | mu_message_get_header (msg, &hdr); |
440 | 440 | ||
441 | if (!select_message (msg_index, msg)) | 441 | if (!clos->select_message (clos->msg_index, msg)) |
442 | break; | 442 | break; |
443 | 443 | ||
444 | if (show_number) | 444 | if (show_number) |
445 | format_field ("%4lu:", (u_long) msg_index); | 445 | format_field ("%4lu:", (u_long) clos->msg_index); |
446 | 446 | ||
447 | if (show_to) | 447 | if (show_to) |
448 | { | 448 | { |
... | @@ -570,12 +570,11 @@ frm_scan (char *mailbox_name, frm_select_t fun, size_t *total) | ... | @@ -570,12 +570,11 @@ frm_scan (char *mailbox_name, frm_select_t fun, size_t *total) |
570 | { | 570 | { |
571 | mu_observer_t observer; | 571 | mu_observer_t observer; |
572 | mu_observable_t observable; | 572 | mu_observable_t observable; |
573 | 573 | struct frm_action_closure closure = { fun, 0 }; | |
574 | select_message = fun; | ||
575 | msg_index = 0; | ||
576 | 574 | ||
577 | mu_observer_create (&observer, mbox); | 575 | mu_observer_create (&observer, mbox); |
578 | mu_observer_set_action (observer, action, mbox); | 576 | mu_observer_set_action (observer, action, mbox); |
577 | mu_observer_set_action_data (observer, &closure, mbox); | ||
579 | mu_mailbox_get_observable (mbox, &observable); | 578 | mu_mailbox_get_observable (mbox, &observable); |
580 | mu_observable_attach (observable, MU_EVT_MESSAGE_ADD, observer); | 579 | mu_observable_attach (observable, MU_EVT_MESSAGE_ADD, observer); |
581 | 580 | ... | ... |
-
Please register or sign in to post a comment