From e72e1b5e84b76761878f3099f772597b6a23f558 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 15 Dec 2003 16:39:44 +0000 Subject: O(1) key-func mapping in i_read_key git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1410 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/bbs.c | 146 +++++++++++++++++++++++++++++++++++++++++------------------ mbbsd/mail.c | 106 +++++++++++++++++++++++++++++++++++-------- mbbsd/read.c | 12 ++--- 3 files changed, 191 insertions(+), 73 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 49f62ae2..11bd6a1a 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -2457,56 +2457,112 @@ change_counting(int ent, fileheader_t * fhdr, char *direct) /* ----------------------------------------------------- */ /* 看板功能表 */ /* ----------------------------------------------------- */ -struct onekey_t read_comms[] = { - {KEY_TAB, board_digest}, - {'B', bh_title_edit}, - {'b', b_notes}, - {'C', board_etc}, - {'c', cite_post}, - {'D', del_range}, - {'d', del_post}, - {'E', edit_post}, -#ifndef NO_GAMBLE - {'f', join_gamble}, - {Ctrl('G'), hold_gamble}, +/* onekey_size was defined in ../include/pttstruct.h, as ((int)'z') */ +onekey_t read_comms[] = { + NULL, // Ctrl('A') 1 + NULL, // Ctrl('B') + NULL, // Ctrl('C') + NULL, // Ctrl('D') + NULL, // Ctrl('E') + NULL, // Ctrl('F') + NULL, // Ctrl('G') + NULL, // Ctrl('H') + board_digest, // Ctrl('I') KEY_TAB 9 + NULL, // Ctrl('J') + NULL, // Ctrl('K') + NULL, // Ctrl('L') + NULL, // Ctrl('M') +#ifdef BMCHS + change_counting, // Ctrl('N') +#else + NULL, // Ctrl('N') +#endif + do_post_openbid, // Ctrl('O') + do_post, // Ctrl('P') + NULL, // Ctrl('Q') + NULL, // Ctrl('R') + NULL, // Ctrl('S') + NULL, // Ctrl('T') + NULL, // Ctrl('U') + do_post_vote, // Ctrl('V') + whereami, // Ctrl('W') + NULL, // Ctrl('X') + NULL, // Ctrl('Y') + NULL, // Ctrl('Z') 26 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, // 'A' 65 + bh_title_edit, // 'B' + board_etc, // 'C' + del_range, // 'D' + edit_post, // 'E' + NULL, // 'F' +#ifdef NO_GAMBLE + NULL, // 'G' +#else + hold_gamble, // 'G' #endif - {'g', good_post}, + #ifdef BMCHS - {'H', change_hidden}, - {Ctrl('N'), change_counting}, + change_hidden, // 'H' +#else + NULL, // 'H' +#endif + b_changerecommend, // 'I' + NULL, // 'J' + b_water_edit, // 'K' + solve_post, // 'L' + b_vote_maintain, // 'M' + NULL, // 'N' + b_post_note, // 'O' + NULL, // 'P' + view_postmoney, // 'Q' + b_results, // 'R' + sequential_read, // 'S' + edit_title, // 'T' + NULL, // 'U' + b_vote, // 'V' + b_notes_edit, // 'W' + recommend, // 'X' + recommend_cancel, // 'Y' + NULL, // 'Z' 90 + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, // 'a' 97 + b_notes, // 'b' + cite_post, // 'c' + del_post, // 'd' + NULL, // 'e' +#ifdef NO_GAMBLE + NULL, // 'f' +#else + join_gamble, // 'f' #endif - {'h', b_help}, - {'I', b_changerecommend}, - {'i', b_posttype}, - {'K', b_water_edit}, - {'L', solve_post}, - {'M', b_vote_maintain}, - {'m', mark_post}, - {'O', b_post_note}, - {'o', can_vote_edit}, - {'Q', view_postmoney}, - {'R', b_results}, - {'r', read_post}, - {'S', sequential_read}, - {'s', do_select}, - {'T', edit_title}, + good_post, // 'g' + b_help, // 'h' + b_posttype, // 'i' + NULL, // 'j' + NULL, // 'k' + NULL, // 'l' + mark_post, // 'm' + NULL, // 'n' + can_vote_edit, // 'o' + NULL, // 'p' + NULL, // 'q' + read_post, // 'r' + do_select, // 's' + NULL, // 't' #ifdef OUTJOBSPOOL - {'u', tar_addqueue}, + tar_addqueue, // 'u' +#else + NULL, // 'u' #endif - {'V', b_vote}, - {'v', visable_list_edit}, - {'W', b_notes_edit}, - {'w', b_call_in}, - {'X', recommend}, - {'x', cross_post}, - {'Y', recommend_cancel}, - {'y', reply_post}, - {'z', b_man}, - {Ctrl('P'), do_post}, - {Ctrl('O'), do_post_openbid}, - {Ctrl('V'), do_post_vote}, - {Ctrl('W'), whereami}, - {'\0', NULL} + visable_list_edit, // 'v' + b_call_in, // 'w' + cross_post, // 'x' + reply_post, // 'y' + b_man, // 'z' 122 }; int diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 1a323a57..8db98d2a 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -1353,28 +1353,94 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } #endif -static struct onekey_t mail_comms[] = { - {'z', mail_man}, - {'c', mail_cite}, - {'s', mail_save}, - {'d', mail_del}, - {'D', del_range}, - {'r', mail_read}, - {'R', mail_reply}, - {'E', mail_edit}, - {'m', mail_mark}, - {'O', mail_nooutmail}, - {'T', edit_title}, - {'x', m_forward}, - {'X', mail_cross_post}, - {Ctrl('G'), built_mail_index}, /* 修信箱 */ - {'y', multi_reply}, - {Ctrl('I'), m_idle}, - {'h', m_help}, +static onekey_t mail_comms[] = { + NULL, // Ctrl('A') 1 + NULL, // Ctrl('B') + NULL, // Ctrl('C') + NULL, // Ctrl('D') + NULL, // Ctrl('E') + NULL, // Ctrl('F') + built_mail_index, // Ctrl('G') + NULL, // Ctrl('H') + m_idle, // Ctrl('I') KEY_TAB 9 + NULL, // Ctrl('J') + NULL, // Ctrl('K') + NULL, // Ctrl('L') + NULL, // Ctrl('M') + NULL, // Ctrl('N') + NULL, // Ctrl('O') + NULL, // Ctrl('P') + NULL, // Ctrl('Q') + NULL, // Ctrl('R') + NULL, // Ctrl('S') + NULL, // Ctrl('T') + NULL, // Ctrl('U') + NULL, // Ctrl('V') + NULL, // Ctrl('W') + NULL, // Ctrl('X') + NULL, // Ctrl('Y') + NULL, // Ctrl('Z') 26 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, // 'A' 65 + NULL, // 'B' + NULL, // 'C' + del_range, // 'D' + mail_edit, // 'E' + NULL, // 'F' + NULL, // 'G' + NULL, // 'H' + NULL, // 'I' + NULL, // 'J' + NULL, // 'K' + NULL, // 'L' + NULL, // 'M' + NULL, // 'N' + mail_nooutmail, // 'O' + NULL, // 'P' + NULL, // 'Q' + mail_reply, // 'R' + NULL, // 'S' + edit_title, // 'T' + NULL, // 'U' + NULL, // 'V' + NULL, // 'W' + mail_cross_post, // 'X' + NULL, // 'Y' + NULL, // 'Z' 90 + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, // 'a' 97 + NULL, // 'b' + mail_cite, // 'c' + mail_del, // 'd' + NULL, // 'e' + NULL, // 'f' + NULL, // 'g' + m_help, // 'h' + NULL, // 'i' + NULL, // 'j' + NULL, // 'k' + NULL, // 'l' + mail_mark, // 'm' + NULL, // 'n' + NULL, // 'o' + NULL, // 'p' + NULL, // 'q' + mail_read, // 'r' + mail_save, // 's' + NULL, // 't' #ifdef OUTJOBSPOOL - {'u', mail_waterball}, + mail_waterball, // 'u' +#else + NULL, // 'u' #endif - {'\0', NULL} + NULL, // 'v' + NULL, // 'w' + m_forward, // 'x' + multi_reply, // 'y' + mail_man, // 'z' 122 }; int diff --git a/mbbsd/read.c b/mbbsd/read.c index bcb596af..fd28bcea 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -581,7 +581,7 @@ select_read(keeploc_t * locmem, int sr_mode) static int i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) { - int i, mode = DONOTHING; + int mode = DONOTHING; switch (ch) { case 'q': @@ -783,13 +783,9 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) default: if( ch == 'h' && currmode & (MODE_ETC | MODE_DIGEST) ) return DONOTHING; - for (i = 0; rcmdlist[i].fptr; i++) { - if (rcmdlist[i].key == ch) { - mode = (*(rcmdlist[i].fptr)) (locmem->crs_ln, - &headers[locmem->crs_ln - - locmem->top_ln], currdirect); - break; - } + if (ch > 0 && ch < onekey_size) { + mode = (*(rcmdlist[ch - 1]))(locmem->crs_ln, &headers[locmem->crs_ln - locmem->top_ln], currdirect); + break; } } return mode; -- cgit v1.2.3