AmendHub

Download:

jcs

/

subtext

/

amendments

/

464

board+main_menu: Add ACTION_BOARD_LIST_BOARDS, fix bug in indexing

Since there may be more than 10 boards now with FTN support, add a
function to list local boards.
 
Fix bug in board_index_sorted_post_ids that was writing a bogus map
when there were no threads.

jcs made amendment 464 about 1 year ago
--- board.c Thu Apr 6 13:47:38 2023 +++ board.c Thu Apr 6 17:48:03 2023 @@ -162,6 +162,102 @@ size_t board_find_post_ids(struct session *s, struct b void board_delete_cached_index(struct board *board); void +board_list_boards(struct session *s) +{ + static struct session_menu_option opts[] = { + { '#', "#", "Enter board number to read" }, + { 'l', "Ll", "List boards" }, + { 'q', "QqXx", "Return to main menu" }, + { '?', "?", "List menu options" }, + }; + static const char prompt_help[] = + "#:View Board L:List Boards Q:Return ?:Help"; + struct board *lboards = NULL, tboard; + size_t nlboards; + char title[] = "List Boards"; + char c; + short an, n, i, j; + bool done, show_list, show_help; + + lboards = xcalloc(sizeof(struct board), db->nboards); + if (lboards == NULL) + return; + + nlboards = 0; + for (n = 0; n < db->nboards; n++) { + if (db->boards[n].ftn_area[0] == '\0') { + memcpy(&lboards[nlboards], &db->boards[n], + sizeof(struct board)); + nlboards++; + } + } + + /* sort by board name */ + for (i = 0; i < nlboards; i++) { + for (j = 0; j < nlboards - i - 1; j++) { + if (strcmp(lboards[j].name, lboards[j + 1].name) > 0) { + tboard = lboards[j]; + lboards[j] = lboards[j + 1]; + lboards[j + 1] = tboard; + } + } + } + + show_list = true; + show_help = false; + done = false; + + snprintf(title, sizeof(title), "Message Boards"); + + while (!done && !s->ending) { + if (show_list) { + session_printf(s, "{{B}}%s{{/B}}\r\n", title); + session_printf(s, "%s # Board Description%s\r\n", + ansi(s, ANSI_BOLD, ANSI_END), ansi(s, ANSI_RESET, ANSI_END)); + session_flush(s); + + for (n = 0; n < nlboards; n++) { + session_printf(s, "%2d %- 13.13s %s\r\n", + n + 1, + lboards[n].name, + lboards[n].description); + } + session_flush(s); + + show_list = false; + } + + c = session_menu(s, title, "Boards", + (char *)prompt_help, opts, nitems(opts), show_help, "Board #", + &an); + show_help = false; + + switch (c) { + case 'l': + show_list = true; + break; + case '#': + if (an < 1 || an > nlboards) { + session_printf(s, "Invalid board\r\n"); + session_flush(s); + break; + } + board_show(s, lboards[an - 1].id, "Boards"); + break; + case '?': + show_help = true; + break; + default: + done = true; + break; + } + } + + if (lboards != NULL) + xfree(&lboards); +} + +void board_list_ftn_areas(struct session *s) { static struct session_menu_option opts[] = { @@ -1446,6 +1542,7 @@ board_index_sorted_post_ids(struct board *board, } } } else { + npost_ids = 0; nthread_ids = bile_ids_by_type(board->bile, BOARD_THREAD_RTYPE, &thread_ids); if (nthread_ids == 0) @@ -1455,7 +1552,6 @@ board_index_sorted_post_ids(struct board *board, if (thread_map == NULL) goto write_out; - npost_ids = 0; for (n = 0; n < nthread_ids; n++) { size = bile_read_alloc(board->bile, BOARD_THREAD_RTYPE, thread_ids[n], &data); --- board.h Tue Mar 14 16:57:15 2023 +++ board.h Thu Apr 6 17:09:27 2023 @@ -87,6 +87,7 @@ struct board_id_time_map { time_t time; }; +void board_list_boards(struct session *s); void board_list_ftn_areas(struct session *s); void board_show(struct session *s, short id, char *prompt_prefix); void board_delete_post(struct board *board, struct board_post *post, --- main_menu.c Tue Mar 14 10:28:06 2023 +++ main_menu.c Thu Apr 6 17:02:59 2023 @@ -136,7 +136,9 @@ main_menu_parse(char *opts, size_t len) } actionid = ACTION_NONE; - if (strcmp(action, "BOARD_LIST_FTN_AREAS") == 0) + if (strcmp(action, "BOARD_LIST_BOARDS") == 0) + actionid = ACTION_BOARD_LIST_BOARDS; + else if (strcmp(action, "BOARD_LIST_FTN_AREAS") == 0) actionid = ACTION_BOARD_LIST_FTN_AREAS; else if (strcmp(action, "BOARD_SHOW_FIRST") == 0) actionid = ACTION_BOARD_SHOW_FIRST; --- main_menu.h Tue Mar 14 10:28:21 2023 +++ main_menu.h Thu Apr 6 17:03:16 2023 @@ -19,6 +19,7 @@ enum main_menu_action { ACTION_NONE = -1, + ACTION_BOARD_LIST_BOARDS, ACTION_BOARD_LIST_FTN_AREAS, ACTION_BOARD_SHOW_FIRST, ACTION_BOARD_SHOW_1, --- session.c Sun Mar 26 10:28:02 2023 +++ session.c Thu Apr 6 17:03:45 2023 @@ -316,6 +316,9 @@ get_another_char: case ACTION_WHOS_ONLINE: session_who(s); break; + case ACTION_BOARD_LIST_BOARDS: + board_list_boards(s); + break; case ACTION_BOARD_LIST_FTN_AREAS: board_list_ftn_areas(s); break;