📄 rt-select.c
字号:
/* $Id: rt-select.c,v 3.0 1992/12/14 00:14:12 davison Trn $*/#include "EXTERN.h"#include "common.h"#include "trn.h"#include "term.h"#include "final.h"#include "util.h"#include "help.h"#include "cache.h"#include "bits.h"#include "artsrch.h"#include "ng.h"#include "ngdata.h"#include "ngstuff.h"#include "kfile.h"#include "rthread.h"#include "rt-page.h"#include "rt-util.h"#include "INTERN.h"#include "rt-select.h"/* When display mode is 'l', each author gets a separate line; when 's', no** authors are displayed.*/char *display_mode = select_order;char sel_disp_char[] = { ' ', '+', '-', '*' };static char sel_ret;static bool empty_ok;static bool disp_status_line;static bool clean_screen;/* Display a menu of threads/subjects/articles for the user to choose from.** If "cmd" is '+' we display all the unread items and allow the user to mark** them as selected and perform various commands upon them. If "cmd" is 'U'** the list consists of previously-read items for the user to mark as unread.*/chardo_selector(cmd)char_int cmd;{ register int j; int got_dash; int ch, action; char page_char, end_char; char promptbuf[80]; char oldmode = mode; char *in_select; mode = 't'; sel_rereading = (cmd == 'U'); clear_on_stop = TRUE; empty_ok = FALSE; set_sel_mode(cmd); if (!cache_range(sel_rereading? absfirst : firstart, lastart)) { sel_ret = '+'; goto sel_exit; } start_selector: /* Setup for selecting articles to read or set unread */ if (sel_rereading) { page_char = '>'; end_char = 'Z'; sel_page_app = Null(ARTICLE**); sel_page_sp = Nullsubj; sel_mask = AF_DELSEL; } else { page_char = page_select; end_char = end_select; if (curr_artp) { sel_last_ap = curr_artp; sel_last_sp = curr_artp->subj; } sel_mask = AF_SEL; } selected_only = TRUE; count_subjects(cmd ? CS_UNSEL_STORE : CS_NORM); /* If nothing to display, we're done. */ if (!article_count && !empty_ok) { empty_complaint(); sel_ret = '+'; goto sel_exit; } init_pages(); sel_item_index = 0; *promptbuf = '\0'; disp_status_line = FALSE; if (added_articles > 0) { sprintf(promptbuf, "** %ld new article%s arrived ** ", (long)added_articles, added_articles == 1? nullstr : "s"); disp_status_line = TRUE; } added_articles = 0; if (cmd && selected_count) { sprintf(promptbuf+strlen(promptbuf), "%ld article%s selected.", (long)selected_count, selected_count == 1? " is" : "s are"); disp_status_line = TRUE; } cmd = 0;display_selector: /* Present a page of items to the user */ display_page(); /* Check if there is really anything left to display. */ if (!sel_item_cnt && !empty_ok) { /*TODO: this may not be needed anymore */ empty_complaint(); sel_ret = '+'; goto sel_exit; } empty_ok = FALSE; if (sel_item_index >= sel_item_cnt) sel_item_index = 0; if (disp_status_line) { printf("\n%s", promptbuf); if (can_home) { carriage_return(); goto_line(sel_last_line+1, sel_last_line); } else putchar('\n'); }reask_selector: /* Prompt the user */#ifdef MAILCALL setmail(FALSE);#endif if (sel_at_end) sprintf(cmd_buf, "%s [%c%c] --", (!sel_prior_arts? "All" : "Bot"), end_char, page_char); else sprintf(cmd_buf, "%s%ld%% [%c%c] --", (!sel_prior_arts? "Top " : nullstr), (long)((sel_prior_arts+sel_page_arts)*100 / sel_total_arts), page_char, end_char); sprintf(promptbuf, "%s-- %s %s (%s%s order) -- %s", mailcall, sel_exclusive? "SELECTED" : "Select", sel_mode_string, sel_direction<0? "reverse " : nullstr, sel_sort_string, cmd_buf);#ifdef CLEAREOL if (erase_screen && can_home_clear) clear_rest();#endif standout(); fputs(promptbuf, stdout); un_standout(); if (can_home) carriage_return(); sel_line = sel_last_line;position_selector: got_dash = 0; if (can_home) goto_line(sel_line, sel_items[sel_item_index].line); sel_line = sel_items[sel_item_index].line;reinp_selector: /* Grab some commands from the user */ fflush(stdout); eat_typeahead(); spin_char = sel_chars[sel_item_index]; cache_until_key(); spin_char = ' ';#ifdef CONDSUB getcmd(buf); ch = *buf;#else getcmd(cmd_buf); /* If no conditionals, don't allow macros */ buf[0] = ch = *cmd_buf; buf[1] = FINISHCMD;#endif if (errno) ch = Ctl('l'); if (disp_status_line) { if (can_home) { goto_line(sel_line, sel_last_line+1); erase_eol(); sel_line = sel_last_line+1; } disp_status_line = FALSE; } if (ch == '-') { got_dash = 1; if (!can_home) putchar('-'), fflush(stdout); goto reinp_selector; } if (ch == ' ') { if (sel_at_end) ch = end_char; else ch = page_char; } in_select = index(sel_chars, ch); if (in_select) { j = in_select - sel_chars; if (j >= sel_item_cnt) { dingaling(); goto position_selector; } else if (got_dash) ; else if (sel_items[j].sel == 1) action = (sel_rereading ? 'k' : '-'); else action = '+'; } else if (ch == '*' && sel_mode == SM_ARTICLE) { register ARTICLE *ap = (ARTICLE*)sel_items[sel_item_index].ptr; if (sel_items[sel_item_index].sel) deselect_subject(ap->subj); else select_subject(ap->subj, 0); update_page(); goto position_selector; } else if (ch == 'y' || ch == '.' || ch == '*') { j = sel_item_index; if (sel_items[j].sel == 1) action = (sel_rereading ? 'k' : '-'); else action = '+'; } else if (ch == 'k' || ch == 'j' || ch == ',') { j = sel_item_index; action = 'k'; } else if (ch == 'm' || ch == '\\') { j = sel_item_index; action = '-'; } else if (ch == 'M') { j = sel_item_index; action = 'M'; } else if (ch == '@') { sel_item_index = 0; j = sel_item_cnt-1; got_dash = 1; action = '@'; } else if (ch == '[' || ch == 'p') { if (--sel_item_index < 0) sel_item_index = sel_item_cnt ? sel_item_cnt-1 : 0; goto position_selector; } else if (ch == ']' || ch == 'n') { if (++sel_item_index >= sel_item_cnt) sel_item_index = 0; goto position_selector; } else { sel_ret = ch; switch (sel_command(ch)) { case DS_POS: if (!clean_screen) goto display_selector; goto position_selector; case DS_ASK: if (!clean_screen) goto display_selector; goto reask_selector; case DS_DISPLAY: ds_display: if (disp_status_line) strcpy(promptbuf, buf); goto display_selector; case DS_UPDATE: if (!clean_screen) goto ds_display; if (disp_status_line) { printf("\n%s",buf); if (can_home) { carriage_return(); up_line(); erase_eol(); } } update_page(); if (can_home) { goto_line(sel_line, sel_last_line); sel_line = sel_last_line; } goto reask_selector; case DS_RESTART: goto start_selector; case DS_QUIT: sel_cleanup(); if (!output_chase_phrase) putchar('\n') FLUSH; goto sel_exit; case DS_STATUS: disp_status_line = TRUE; if (!clean_screen) { strcpy(promptbuf, buf); goto display_selector; } if (can_home) { goto_line(sel_line, sel_last_line+1); sel_line = sel_last_line+1; } else putchar('\n'); fputs(buf, stdout); if (can_home) carriage_return(); else putchar('\n'); goto position_selector; } } /* The user manipulated one of the letters -- handle it. */ if (!got_dash) sel_item_index = j; else { if (j < sel_item_index) { ch = sel_item_index-1; sel_item_index = j; j = ch; } } if (++j == sel_item_cnt) j = 0; do { register int sel = sel_items[sel_item_index].sel; register SUBJECT *sp = (SUBJECT*)sel_items[sel_item_index].ptr; if (can_home) { goto_line(sel_line, sel_items[sel_item_index].line); sel_line = sel_items[sel_item_index].line; } if (action == '@') { if (sel == 2) ch = (sel_rereading ? '+' : ' '); else if (sel_rereading) ch = 'k'; else if (sel == 1) ch = '-'; else ch = '+'; } else ch = action; switch (ch) { case '+': if (sel_mode == SM_THREAD) select_thread(sp->thread, 0); else if (sel_mode == SM_SUBJECT) select_subject(sp, 0); else select_article((ARTICLE*)sp, 0); output_sel(1); break; case '-': case 'k': case 'M': { bool sel_reread_save = sel_rereading; if (ch == 'M') { if (sel_mode == SM_ARTICLE) delay_unmark((ARTICLE*)sp); else { register ARTICLE *ap; if (sel_mode == SM_THREAD) { for (ap = first_art(sp); ap; ap = next_art(ap)) if (!(ap->flags & AF_READ) ^ sel_rereading) delay_unmark(ap); } else { for (ap = sp->articles; ap; ap = ap->subj_next) if (!(ap->flags & AF_READ) ^ sel_rereading) delay_unmark(ap); } } } if (ch == '-') sel_rereading = FALSE; else sel_rereading = TRUE; if (sel_mode == SM_THREAD) deselect_thread(sp->thread); else if (sel_mode == SM_SUBJECT) deselect_subject(sp); else deselect_article((ARTICLE*)sp); sel_rereading = sel_reread_save; output_sel(ch == '-'? 0 : 2); break; } } fflush(stdout); if (++sel_item_index == sel_item_cnt) sel_item_index = 0; if (can_home) carriage_return(); } while (sel_item_index != j); goto position_selector;sel_exit: if (sel_rereading) { sel_rereading = 0; sel_mask = AF_SEL; } if (sel_mode != SM_ARTICLE || sel_sort == SS_GROUPS || sel_sort == SS_SUBJECT) { if (artptr_list) { free((char*)artptr_list); artptr_list = sel_page_app = Null(ARTICLE**); sort_subjects(); } artptr = Null(ARTICLE**);#ifdef ARTSEARCH if (!ThreadedGroup) srchahead = -1;#endif }#ifdef ARTSEARCH else srchahead = 0;#endif selected_only = (selected_count || !article_count); if (sel_ret != '#') count_subjects(sel_ret == '+'? CS_RESELECT : CS_UNSELECT); clear_on_stop = FALSE; mode = oldmode; if (sel_ret == '+') { art = curr_art; artp = curr_artp; } else top_article(); return sel_ret;}static voidsel_cleanup(){ if (sel_rereading) { /* Turn selections into unread selected articles. Let ** count_subjects() fix the counts after we're through. */ register SUBJECT *sp; sel_last_ap = Nullart; sel_last_sp = Nullsubj; for (sp = first_subject; sp; sp = sp->next) unkill_subject(sp); } else { if (sel_mode == SM_ARTICLE) { register ARTICLE *ap; register ART_NUM an; for (an=absfirst, ap=article_ptr(an); an<=lastart; an++, ap++) { if (ap->flags & AF_DEL) { ap->flags &= ~AF_DEL; set_read(ap); } } } else { register SUBJECT *sp; for (sp = first_subject; sp; sp = sp->next) { if (sp->flags & SF_DEL) { sp->flags &= ~SF_DEL; if (sel_mode == SM_THREAD) kill_thread(sp->thread, KF_UNSELECTED); else kill_subject(sp, KF_UNSELECTED); } } } }}static intsel_command(ch)char_int ch;{ if (can_home) goto_line(sel_line, sel_last_line); sel_line = sel_last_line; clean_screen = TRUE; do_command: output_chase_phrase = TRUE; switch (ch) { case '>': sel_item_index = 0; if (next_page()) return DS_DISPLAY; return DS_POS; case '<': sel_item_index = 0; if (prev_page()) return DS_DISPLAY; return DS_POS; case '^': case Ctl('r'): sel_item_index = 0; if (first_page()) return DS_DISPLAY; return DS_POS; case '$': sel_item_index = 0; if (last_page()) return DS_DISPLAY; return DS_POS; case Ctl('l'): return DS_DISPLAY; case Ctl('f'): erase_eol(); /* erase the prompt */#ifdef MAILCALL setmail(TRUE); /* force a mail check */#endif return DS_ASK; case '#': { register SUBJECT *sp; for (sp = first_subject; sp; sp = sp->next)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -