1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
|
/* $Id: rt-select.c,v 3.0 1992/12/14 00:14:12 davison Trn $
*/
/* The authors make no claims as to the fitness or correctness of this software
* for any use whatsoever, and it is provided as is. Any use of this software
* is at the user's own risk.
*/
#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;
/* CAA hacks: xterm mouse support */
static char *sel_mouse_save;
void
sel_go_line(line)
int line;
{
int i;
for (i = 0; i < sel_item_cnt; i++) {
if (sel_items[i].line > line)
break;
}
if (i > 0)
i--;
sel_item_index = i;
}
void
sel_do_mouse(button,x,y)
int button; /* 0: button1 1: button2 2: button3 3: release */
int x,y;
{
switch (button) {
case 0:
case 1:
if (!y)
sel_mouse_save = "<";
else if (y >= sel_last_line)
sel_mouse_save = (button == 0)? " " : ">";
else {
sel_go_line(y);
if (button == 0)
sel_mouse_save = ".";
}
break;
case 2:
/* move forward or backwards a page:
* if cursor in top half: backwards
* if cursor in bottom half: forwards
*/
if (y<(LINES/2))
sel_mouse_save = "<";
else
sel_mouse_save = ">";
break;
case 3:
/* do range stuff here later? */
break;
}
}
void
sel_mouse()
{
int x,y;
int button;
sel_mouse_save = Nullch;
read_tty(buf,1);
button = (int)(buf[0]);
read_tty(buf,1);
x = (int)(buf[0])-33;
read_tty(buf,1);
y = (int)(buf[0])-33;
sel_do_mouse(button&3,x,y);
/* get the button-up event */
while (1) {
getcmd(buf);
if (*buf == 3) /* got the button-up */
break;
/* otherwise just eat any other keystrokes */
}
/* interpret the button-up event */
read_tty(buf,1);
button = (int)(buf[0]);
read_tty(buf,1);
x = (int)(buf[0])-33;
read_tty(buf,1);
y = (int)(buf[0])-33;
sel_do_mouse(button&3,x,y);
if (sel_mouse_save)
pushstring(sel_mouse_save,0);
}
/* 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.
*/
char
do_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';
art = lastart+1;
sel_rereading = (cmd == 'U');
clear_on_stop = TRUE;
empty_ok = FALSE;
set_sel_mode(cmd);
xmouse_on();
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(FILL_LAST_PAGE);
sel_item_index = 0;
*promptbuf = '\0';
disp_status_line = FALSE;
if (added_articles) {
register long i = added_articles, j;
register ARTICLE *ap = article_ptr(lastart - i + 1);
for (j = 0; j < added_articles; j++, ap++) {
if (ap->flags & AF_READ)
i--;
}
if (i == added_articles)
sprintf(promptbuf, "** %ld new article%s arrived ** ",
(long)added_articles, added_articles == 1? nullstr : "s");
else
sprintf(promptbuf, "** %ld of %ld new articles unread ** ",
i, (long)added_articles);
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) {
empty_complaint();
sel_ret = 'q';
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);
interp(buf, sizeof buf, mailcall);
sprintf(promptbuf, "%s-- %s %s (%s%s order) -- %s", buf,
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);
if (*buf == ' ')
setdef(buf, sel_at_end? &end_char : &page_char);
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;
}
/* CAA: hack for mouse support */
if (ch == Ctl('c')) {
sel_mouse();
goto position_selector;
}
if (ch == '-') {
got_dash = 1;
if (!can_home)
putchar('-'), fflush(stdout);
goto reinp_selector;
}
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 != 0);
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();
xmouse_off();
return sel_ret;
}
static void
sel_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 int
sel_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('^'):
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)
sp->flags &= ~SF_VISIT;
selected_count = 0;
sp = (SUBJECT*)sel_items[sel_item_index].ptr;
switch (sel_mode) {
case SM_THREAD:
deselect_thread(sp->thread);
select_thread(sp->thread, 0);
break;
case SM_SUBJECT:
deselect_subject(sp);
select_subject(sp, 0);
break;
case SM_ARTICLE:
deselect_article((ARTICLE*)sp);
select_article((ARTICLE*)sp, 0);
break;
}
return DS_QUIT;
}
case '\r': case '\n':
if (!selected_count) {
if (sel_rereading || sel_items[sel_item_index].sel != 2) {
register SUBJECT *sp = (SUBJECT*)sel_items[sel_item_index].ptr;
switch (sel_mode) {
case SM_THREAD:
select_thread(sp->thread, 0);
break;
case SM_SUBJECT:
select_subject(sp, 0);
break;
case SM_ARTICLE:
select_article((ARTICLE*)sp, 0);
break;
}
}
}
return DS_QUIT;
case 'Z': case '\t':
return DS_QUIT;
case 'q': case 'Q':
return DS_QUIT;
case Ctl('Q'): case '\033': case '+':
sel_ret = '+';
return DS_QUIT;
case 'N': case 'P':
return DS_QUIT;
case 'L':
if (!*++display_mode)
display_mode = select_order;
return DS_DISPLAY;
case 'Y':
if (!dmcount) {
sprintf(buf,"No marked articles to yank back.");
return DS_STATUS;
}
yankback();
sel_line++;
if (!sel_rereading)
sel_cleanup();
disp_status_line = TRUE;
count_subjects(CS_NORM);
sel_page_sp = Nullsubj;
sel_page_app = Null(ARTICLE**);
init_pages(PRESERVE_PAGE);
return DS_DISPLAY;
case 'U':
sel_cleanup();
sel_rereading = !sel_rereading;
sel_page_sp = Nullsubj;
sel_page_app = Null(ARTICLE**);
if (!cache_range(sel_rereading? absfirst : firstart, lastart))
sel_rereading = !sel_rereading;
empty_ok = TRUE;
return DS_RESTART;
case '=':
if (!sel_rereading)
sel_cleanup();
if (sel_mode == SM_ARTICLE) {
set_selector(sel_threadmode, sel_threadsort);
sel_page_sp = sel_page_app[0]->subj;
} else {
set_selector(SM_ARTICLE, sel_artsort);
sel_page_app = 0;
}
count_subjects(CS_NORM);
sel_item_index = 0;
init_pages(FILL_LAST_PAGE);
return DS_DISPLAY;
case 'S':
if (!sel_rereading)
sel_cleanup();
erase_eol(); /* erase the prompt */
reask_output:
in_char("Selector mode: Threads, Subjects, Articles?", 'o', "tsa");
#ifdef VERIFY
printcmd();
#endif
if (*buf == 'h') {
#ifdef VERBOSE
IF(verbose)
fputs("\n\
Type t or SP to display/select thread groups (threads the group, if needed).\n\
Type s to display/select subject groups.\n\
Type a to display/select individual articles.\n\
Type q to leave things as they are.\n\n\
",stdout) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\n\
t or SP selects thread groups (threads the group too).\n\
s selects subject groups.\n\
a selects individual articles.\n\
q does nothing.\n\n\
",stdout) FLUSH;
#endif
clean_screen = FALSE;
goto reask_output;
} else if (*buf == 'q') {
if (can_home) {
carriage_return();
erase_eol();
}
return DS_ASK;
}
set_sel_mode(*buf);
count_subjects(CS_NORM);
init_pages(FILL_LAST_PAGE);
return DS_DISPLAY;
case 'O':
if (!sel_rereading)
sel_cleanup();
erase_eol(); /* erase the prompt */
reask_sort:
if (sel_mode == SM_ARTICLE)
in_char("Order by Date, Subject, Author, Number, subject-date Groups?",
'q', "dsangDSANG");
else
in_char("Order by Date, Subject, or Count?", 'q', "dscDSC");
#ifdef VERIFY
printcmd();
#endif
if (*buf == 'h') {
#ifdef VERBOSE
IF(verbose) {
fputs("\n\
Type d or SP to order the displayed items by date.\n\
Type s to order the items by subject.\n\
",stdout) FLUSH;
if (sel_mode == SM_ARTICLE)
fputs("\
Type a to order the items by author.\n\
Type n to order the items by number.\n\
Type g to order the items in subject-groups by date.\n\
",stdout) FLUSH;
else
fputs("\
Type c to order the items by article-count.\n\
",stdout) FLUSH;
fputs("\
Typing your selection in upper case it will reverse the selected order.\n\
Type q to leave things as they are.\n\n\
",stdout) FLUSH;
}
ELSE
#endif
#ifdef TERSE
{
fputs("\n\
d or SP sorts by date.\n\
s sorts by subject.\n\
",stdout) FLUSH;
if (sel_mode == SM_ARTICLE)
fputs("\
a sorts by author.\n\
g sorts in subject-groups by date.\n\
",stdout) FLUSH;
else
fputs("\
c sorts by article-count.\n\
",stdout) FLUSH;
fputs("\
Upper case reverses the sort.\n\
q does nothing.\n\n\
",stdout) FLUSH;
}
#endif
clean_screen = FALSE;
goto reask_sort;
} else if (*buf == 'q') {
if (can_home) {
carriage_return();
erase_eol();
}
return DS_ASK;
}
set_sel_sort(*buf);
count_subjects(CS_NORM);
sel_page_sp = Nullsubj;
sel_page_app = Null(ARTICLE**);
init_pages(FILL_LAST_PAGE);
return DS_DISPLAY;
case 'R':
if (!sel_rereading)
sel_cleanup();
sel_direction *= -1;
count_subjects(CS_NORM);
sel_page_sp = Nullsubj;
sel_page_app = Null(ARTICLE**);
init_pages(FILL_LAST_PAGE);
return DS_DISPLAY;
case 'E':
if (!sel_rereading)
sel_cleanup();
sel_exclusive = !sel_exclusive;
count_subjects(CS_NORM);
sel_page_sp = Nullsubj;
sel_page_app = Null(ARTICLE**);
init_pages(FILL_LAST_PAGE);
empty_ok = TRUE;
sel_item_index = 0;
return DS_DISPLAY;
case 'X': case 'D': case 'J':
if (!sel_rereading) {
if (sel_mode == SM_ARTICLE) {
register ARTICLE *ap, **app, **limit;
limit = artptr_list + artptr_list_size;
if (ch == 'D')
app = sel_page_app;
else
app = artptr_list;
for (;;) {
ap = *app;
if ((!(ap->flags & AF_SEL) ^ (ch == 'J'))
|| (ap->flags & AF_DEL))
if (!sel_exclusive || (ap->flags & AF_INCLUDED))
set_read(ap);
app++;
if (app >= limit || (ch == 'D' && app == sel_next_app))
break;
}
} else {
register SUBJECT *sp;
if (ch == 'D')
sp = sel_page_sp;
else
sp = first_subject;
for (;;) {
if (((!(sp->flags & SF_SEL) ^ (ch == 'J')) && sp->misc)
|| (sp->flags & SF_DEL)) {
if (!sel_exclusive || (sp->flags & SF_INCLUDED))
kill_subject(sp, ch=='J'? KF_ALL : KF_UNSELECTED);
}
sp = sp->next;
if (!sp || (ch == 'D' && sp == sel_next_sp))
break;
}
}
count_subjects(CS_UNSELECT);
if (article_count
&& (ch == 'J' || (ch == 'D' && !selected_count))) {
init_pages(FILL_LAST_PAGE);
sel_item_index = 0;
return DS_DISPLAY;
}
if (artptr_list && article_count)
sort_articles();
return DS_QUIT;
} else if (ch == 'J') {
register SUBJECT *sp;
for (sp = first_subject; sp; sp = sp->next)
deselect_subject(sp);
selected_subj_cnt = selected_count = 0;
return DS_DISPLAY;
}
return DS_QUIT;
case 'T':
if (!ThreadedGroup) {
sprintf(buf,"Group is not threaded.");
return DS_STATUS;
}
/* FALL THROUGH */
case 'A':
erase_eol(); /* erase the prompt */
if (sel_mode == SM_ARTICLE)
artp = (ARTICLE*)sel_items[sel_item_index].ptr;
else {
register SUBJECT *sp = (SUBJECT*)sel_items[sel_item_index].ptr;
if (sel_mode == SM_THREAD) {
while (!sp->misc)
sp = sp->thread_link;
}
artp = sp->articles;
}
art = article_num(artp);
/* This call executes the action too */
switch (ask_memorize(ch)) {
case 'j': case ',':
count_subjects(sel_rereading ? CS_NORM : CS_UNSELECT);
init_pages(PRESERVE_PAGE);
sprintf(buf,"Kill memorized.");
disp_status_line = TRUE;
return DS_DISPLAY;
case '.':
sprintf(buf,"Selection memorized.");
disp_status_line = TRUE;
return DS_DISPLAY;
case '+':
sprintf(buf,"Selection memorized.");
disp_status_line = TRUE;
return DS_UPDATE;
case 'c': case 'C':
sprintf(buf,"Auto-commands cleared.");
disp_status_line = TRUE;
return DS_DISPLAY;
case 'q':
return DS_DISPLAY;
case 'Q':
break;
}
if (can_home) {
carriage_return();
erase_eol();
}
return DS_ASK;
case Ctl('k'):
xmouse_off();
edit_kfile();
xmouse_on();
return DS_DISPLAY;
case ':':
if (sel_mode == SM_ARTICLE)
artp = (ARTICLE*)sel_items[sel_item_index].ptr;
else {
register SUBJECT *sp = (SUBJECT*)sel_items[sel_item_index].ptr;
if (sel_mode == SM_THREAD) {
while (!sp->misc)
sp = sp->thread_link;
}
artp = sp->articles;
}
art = article_num(artp);
/* FALL THROUGH */
case '/': case '&': case '!':
erase_eol(); /* erase the prompt */
if (!finish_command(TRUE)) { /* get rest of command */
if (clean_screen)
return DS_ASK;
goto extend_done;
}
if (ch == '&' || ch == '!') {
xmouse_off();
one_command = TRUE;
perform(buf, FALSE);
one_command = FALSE;
putchar('\n') FLUSH;
clean_screen = FALSE;
xmouse_on();
} else {
int sel_art_save = selected_count;
if (ch == ':') {
clean_screen = (thread_perform() == 2) && clean_screen;
if (!sel_rereading) {
register SUBJECT *sp;
for (sp = first_subject; sp; sp = sp->next) {
if (sp->flags & SF_DEL) {
sp->flags = 0;
if (sel_mode == SM_THREAD)
kill_thread(sp->thread, KF_UNSELECTED);
else
kill_subject(sp, KF_UNSELECTED);
}
}
}
} else {
/* Force the search to begin at absfirst or firstart,
** depending upon whether they specified the 'r' option.
*/
art = lastart+1;
page_line = 1;
switch (art_search(buf, sizeof buf, FALSE)) {
case SRCH_ERROR:
case SRCH_ABORT:
case SRCH_INTR:
fputs("\nInterrupted\n", stdout) FLUSH;
break;
case SRCH_DONE:
case SRCH_SUBJDONE:
fputs("Done\n", stdout) FLUSH;
break;
case SRCH_NOTFOUND:
fputs("\nNot found.\n", stdout) FLUSH;
break;
case SRCH_FOUND:
break;
}
clean_screen = FALSE;
}
/* Recount, in case something has changed. */
count_subjects(sel_rereading ? CS_NORM : CS_UNSELECT);
init_pages(PRESERVE_PAGE);
sel_item_index = 0;
sel_art_save -= selected_count;
if (sel_art_save) {
putchar('\n');
if (sel_art_save < 0) {
fputs("S", stdout);
sel_art_save *= -1;
} else
fputs("Des", stdout);
printf("elected %d article%s.",
sel_art_save, sel_art_save == 1 ? nullstr : "s");
clean_screen = FALSE;
}
if (!clean_screen)
putchar('\n') FLUSH;
}/* if !& else :/ */
if (clean_screen) {
carriage_return();
up_line();
erase_eol();
return DS_ASK;
}
extend_done:
if ((ch = pause_getcmd())) {
got_cmd:
if (ch > 0) {
/* try to optimize the screen update for some commands. */
if (!index(sel_chars, ch)
&& (index("<+>^$!?&:;/hDEJLNOPqQRSUXYZ\n\r\t\033", ch)
|| ch == Ctl('k'))) {
buf[0] = sel_ret = ch;
buf[1] = FINISHCMD;
goto do_command;
}
pushchar(ch | 0200);
}
}
return DS_DISPLAY;
case 'c':
erase_eol(); /* erase the prompt */
if ((ch = ask_catchup()) == 'y' || ch == 'u') {
count_subjects(CS_UNSELECT);
if (ch != 'u' && article_count) {
sel_page_sp = Nullsubj;
sel_page_app = Null(ARTICLE**);
init_pages(FILL_LAST_PAGE);
return DS_DISPLAY;
}
sel_ret = 'Z';
return DS_QUIT;
}
if (ch != 'N')
return DS_DISPLAY;
if (can_home) {
carriage_return();
erase_eol();
}
return DS_ASK;
case 'h': case '?':
putchar('\n');
if ((ch = help_select()) || (ch = pause_getcmd()))
goto got_cmd;
return DS_DISPLAY;
default:
sprintf(buf,"Type ? for help.");
settle_down();
if (clean_screen)
return DS_STATUS;
printf("\n%s\n",buf);
goto extend_done;
}
}
static void
empty_complaint()
{
clear_on_stop = FALSE;
putchar('\n');
if (sel_rereading) {
#ifdef VERBOSE
IF (verbose)
fputs("\nNo articles to set unread.\n", stdout);
ELSE
#endif
#ifdef TERSE
fputs("\nNo articles.\n", stdout) FLUSH;
#endif
sel_rereading = 0;
sel_mask = AF_SEL;
} else {
#ifdef VERBOSE
IF (verbose)
fputs("\nNo unread articles to select.", stdout);
ELSE
#endif
#ifdef TERSE
fputs("\nNo unread articles.", stdout);
#endif
putchar('\n'); /* let "them" FLUSH */
}
selected_only = FALSE;
art = curr_art;
artp = curr_artp;
}
|