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
|
/* This software is copyrighted as detailed in the LICENSE file. */
/* trn -- threaded readnews program based on rn 4.4
*
* You can request help from: trn-users@lists.sourceforge.net
* Send bugs, suggestions, etc. to: trn-workers@lists.sourceforge.net
*
* Author/Maintainer of trn: trn@blorf.net (Wayne Davison)
* Maintainer of rn: sob@bcm.tmc.edu (Stan Barber)
* Original Author: lwall@sdcrdcf.UUCP (Larry Wall)
*
* History:
* 01/14/83 - rn begun
* 04/08/83 - rn 1.0
* 09/01/83 - rn 2.0
* 05/01/85 - rn 4.3
* 11/01/89 - rn/rrn integration
* 11/25/89 - trn begun
* 07/21/90 - trn 1.0
* 07/04/91 - rn 4.4
* 11/25/91 - trn 2.0
* 07/25/93 - trn 3.0
* ??/??/?? - trn 4.0
*
* strn -- Scan(-mode)/Scoring TRN
*
* Author/Maintainer of strn: caadams@zynet.com (Clifford A. Adams)
*
* Strn history:
* Dec. 90 - "Keyword RN" initial ideas, keyword entry prototype
* 01/16/91 - "Scoring RN" initial design notes
* Late 91 - cleaned up "Semicolon mode" RN patches from Todd Day
* Early 92 - major additions to "STRN"
* Mid 93 - first strn public release (version 0.8)
* Sep. 94 - last beta release (version 0.9.3).
* Late 95 - strn code ported to trn 4.0, universal selector started
* May 96 - strn 1.0 release
*
*/
#include "patchlevel.h"
#include "INTERN.h"
#include "common.h"
#include "EXTERN.h"
#include "list.h"
#include "hash.h"
#include "ngdata.h"
#include "nntpclient.h"
#include "datasrc.h"
#include "nntp.h"
#include "INTERN.h"
#include "trn.h"
#include "EXTERN.h"
#include "term.h"
#include "final.h"
#include "search.h"
#include "addng.h"
#include "ngstuff.h"
#include "rcstuff.h"
#include "env.h"
#include "util.h"
#include "util2.h"
#include "only.h"
#include "ngsrch.h"
#include "help.h"
#include "last.h"
#include "init.h"
#include "intrp.h"
#include "rcln.h"
#include "sw.h"
#include "opt.h"
#include "cache.h"
#include "ng.h"
#include "kfile.h"
#include "rt-select.h"
#ifdef SCAN
#include "scan.h"
#endif /* SCAN */
#include "univ.h"
void
trn_init()
{
;
}
static bool restore_old_newsrc = FALSE;
static bool go_forward = TRUE;
int
main(argc,argv)
int argc;
char* argv[];
{
bool foundany;
char* s;
/* Figure out our executable's name. */
#ifdef MSDOS
strlwr(argv[0]);
if ((s = rindex(argv[0],'\\')) != NULL)
*s = '/';
#endif
if ((s = rindex(argv[0],'/')) == NULL)
s = argv[0];
else
s++;
#if !THREAD_INIT
/* Default to threaded operation if our name starts with a 't' or 's'. */
if (*s == 't' || *s == 's')
use_threads = TRUE;
else
UseNewsSelector = -1;
#endif
if (*s == 's')
is_strn = TRUE;
#ifdef USE_TK /*XXX remove this?*/
if (s[1] == 'k')
UseTk = 1;
else
UseTk = 0;
#endif
foundany = initialize(argc,argv);
if (UseNewsrcSelector) {
multirc_selector();
finalize(0);
}
#ifdef FINDNEWNG
if (find_new_groups()) { /* did we add any new groups? */
foundany = TRUE;
starthere = NULL; /* start ng scan from the top */
}
#endif
if (maxngtodo)
starthere = NULL;
else if (!foundany) { /* nothing to do? */
#ifdef VERBOSE
if (verbose) {
fputs("\
No unread news in subscribed-to newsgroups. To subscribe to a new\n\
newsgroup use the g<newsgroup> command.\n\
",stdout) FLUSH;
termdown(2);
}
#endif
starthere = last_ng;
}
do_multirc();
finalize(0);
/* NOT REACHED */
return 0;
}
void
do_multirc()
{
bool special = FALSE; /* allow newsgroup with no unread news? */
char mode_save = mode;
char gmode_save = gmode;
if (UseUnivSelector) {
char ch;
univ_startup(); /* load startup file */
ch = universal_selector();
if (ch != 'Q') {
/* section copied from bug_out below */
/* now write the newsrc(s) back out */
if (!write_newsrcs(multirc))
restore_old_newsrc = TRUE; /*$$ ask to retry! */
if (restore_old_newsrc)
get_old_newsrcs(multirc);
finalize(0);
}
}
if (UseNewsgroupSelector) {
ng_start_sel:
switch (newsgroup_selector()) {
case Ctl('n'):
use_next_multirc(multirc);
end_only();
goto ng_start_sel;
case Ctl('p'):
use_prev_multirc(multirc);
end_only();
goto ng_start_sel;
case 'q':
goto bug_out;
}
starthere = ngptr;
UseNewsgroupSelector = FALSE;
}
/* loop through all unread news */
restart:
current_ng = first_ng;
for (;;) {
bool retry = FALSE;
if (findlast > 0) {
findlast = -1;
starthere = NULL;
if (lastngname) {
if ((ngptr = find_ng(lastngname)) == NULL)
ngptr = first_ng;
else {
set_ngname(lastngname);
set_toread(ngptr, ST_LAX);
if (ngptr->toread <= TR_NONE)
ngptr = first_ng;
}
}
} else if (starthere) {
ngptr = starthere;
starthere = NULL;
}
else
ngptr = first_ng;
for (;;) { /* for each newsgroup */
if (ngptr == NULL) { /* after the last newsgroup? */
set_mode('r','f');
if (maxngtodo) {
if (retry) {
#ifdef VERBOSE
IF(verbose)
printf("\nRestriction %s%s still in effect.\n",
ngtodo[0], maxngtodo > 1 ? ", etc." : nullstr) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\n(\"Only\" mode.)\n",stdout) FLUSH;
#endif
termdown(2);
} else {
#ifdef VERBOSE
IF(verbose)
fputs("\nNo articles under restriction.", stdout) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\nNo \"only\" articles.",stdout) FLUSH;
#endif
termdown(2);
end_only(); /* release the restriction */
printf("\n%s\n", msg) FLUSH;
termdown(2);
retry = TRUE;
}
}
}
else {
bool shoe_fits; /* newsgroup matches restriction? */
set_mode('r','n');
if (ngptr->toread >= TR_NONE) { /* recalc toread? */
set_ngname(ngptr->rcline);
shoe_fits = inlist(ngname);
if (shoe_fits)
set_toread(ngptr, ST_LAX);
if (paranoid) {
recent_ng = current_ng;
current_ng = ngptr;
cleanup_newsrc(ngptr->rc); /* this may move newsgroups around */
set_ng(current_ng);
}
} else
shoe_fits = TRUE;
if (ngptr->toread < (special? TR_NONE : ng_min_toread)
|| !shoe_fits) { /* unwanted newsgroup? */
if (go_forward)
ngptr = ngptr->next;
else {
ngptr = ngptr->prev;
if (ngptr == NULL) {
ngptr = first_ng->next;
go_forward = 1;
}
}
continue;
}
}
special = FALSE; /* go back to normal mode */
if (ngptr != current_ng) {
recent_ng = current_ng; /* remember previous newsgroup */
current_ng = ngptr; /* remember current newsgroup */
}
reask_newsgroup:
unflush_output(); /* disable any ^O in effect */
if (ngptr == NULL) {
dfltcmd = (retry ? "npq" : "qnp");
#ifdef VERBOSE
IF(verbose)
printf("\n****** End of newsgroups -- what next? [%s] ",
dfltcmd);
ELSE
#endif
#ifdef TERSE
printf("\n**** End -- next? [%s] ", dfltcmd);
#endif
termdown(1);
} else {
ThreadedGroup = (use_threads && !(ngptr->flags&NF_UNTHREADED));
dfltcmd = (UseNewsSelector >= 0
&& ngptr->toread >= (ART_UNREAD)UseNewsSelector? "+ynq":"ynq");
#ifdef VERBOSE
IF(verbose)
printf("\n%s %3ld unread article%s in %s -- read now? [%s] ",
ThreadedGroup? "======" : "******",
(long)ngptr->toread, PLURAL(ngptr->toread),
ngname, dfltcmd);
ELSE
#endif
#ifdef TERSE
printf("\n%s %3ld in %s -- read? [%s] ",
ThreadedGroup? "====" : "****",
(long)ngptr->toread,ngname,dfltcmd);
#endif
termdown(1);
}
fflush(stdout);
reinp_newsgroup:
if (special || (ngptr && ngptr->toread > 0))
retry = TRUE;
switch (input_newsgroup()) {
case ING_ASK:
goto reask_newsgroup;
case ING_INPUT:
case ING_ERASE:
goto reinp_newsgroup;
case ING_ERROR:
printf("\n%s",hforhelp) FLUSH;
termdown(2);
settle_down();
goto reask_newsgroup;
case ING_QUIT:
goto bug_out;
case ING_BREAK:
goto loop_break;
case ING_RESTART:
goto restart;
#ifdef SUPPORT_NNTP
case ING_NOSERVER:
if (multirc)
goto restart;
goto bug_out;
#endif
case ING_SPECIAL:
special = TRUE;
break;
case ING_NORM:
break;
case ING_DISPLAY:
newline();
break;
case ING_MESSAGE:
printf("\n%s\n", msg) FLUSH;
termdown(2);
break;
}
}
loop_break:;
#ifdef SUPPORT_NNTP
check_active_refetch(FALSE);
#endif
}
bug_out:
/* now write the newsrc(s) back out */
if (!write_newsrcs(multirc))
restore_old_newsrc = TRUE; /*$$ ask to retry! */
if (restore_old_newsrc)
get_old_newsrcs(multirc);
set_mode(gmode_save,mode_save);
}
int
input_newsgroup()
{
register char* s;
ing_state = INGS_DIRTY;
eat_typeahead();
getcmd(buf);
if (errno || *buf == '\f') {
newline(); /* if return from stop signal */
return ING_ASK;
}
buf[2] = *buf;
setdef(buf,dfltcmd);
#ifdef VERIFY
printcmd();
#endif
if (ngptr != NULL)
*buf = buf[2];
do_command:
go_forward = TRUE; /* default to forward motion */
switch (*buf) {
case 'P': /* goto previous newsgroup */
case 'p': /* find previous unread newsgroup */
if (!ngptr)
ngptr = last_ng;
else if (ngptr != first_ng)
ngptr = ngptr->prev;
go_forward = FALSE; /* go backward in the newsrc */
ing_state = INGS_CLEAN;
if (*buf == 'P')
return ING_SPECIAL;
break;
case '-':
ngptr = recent_ng; /* recall previous newsgroup */
if (ngptr) {
if (!get_ng(ngptr->rcline,0))
set_ng(current_ng);
addnewbydefault = 0;
}
return ING_SPECIAL;
case 'x':
newline();
in_char("Confirm: exit and abandon newsrc changes?", 'A', "yn");
newline();
if (*buf != 'y')
break;
printf("\nThe abandoned changes are in %s.new.\n",
multirc_name(multirc)) FLUSH;
termdown(2);
restore_old_newsrc = TRUE;
return ING_QUIT;
case 'q': case 'Q': /* quit? */
newline();
return ING_QUIT;
case '^':
if (gmode != 's')
newline();
ngptr = first_ng;
ing_state = INGS_CLEAN;
break;
case 'N': /* goto next newsgroup */
case 'n': /* find next unread newsgroup */
if (ngptr == NULL) {
newline();
return ING_BREAK;
}
ngptr = ngptr->next;
ing_state = INGS_CLEAN;
if (*buf == 'N')
return ING_SPECIAL;
break;
case '1': /* goto 1st newsgroup */
ngptr = first_ng;
ing_state = INGS_CLEAN;
return ING_SPECIAL;
case '$':
ngptr = NULL; /* go past last newsgroup */
ing_state = INGS_CLEAN;
break;
case 'L':
list_newsgroups();
return ING_ASK;
case '/': case '?': /* scan for newsgroup pattern */
#ifdef NGSEARCH
switch (ng_search(buf,TRUE)) {
case NGS_ERROR:
set_ng(current_ng);
return ING_ASK;
case NGS_ABORT:
set_ng(current_ng);
return ING_INPUT;
case NGS_INTR:
#ifdef VERBOSE
IF(verbose)
fputs("\n(Interrupted)\n",stdout) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\n(Intr)\n",stdout) FLUSH;
#endif
termdown(2);
set_ng(current_ng);
return ING_ASK;
case NGS_FOUND:
return ING_SPECIAL;
case NGS_NOTFOUND:
#ifdef VERBOSE
IF(verbose)
fputs("\n\nNot found -- use a or g to add newsgroups\n",
stdout) FLUSH;
ELSE
#endif
#ifdef TERSE
fputs("\n\nNot found\n",stdout) FLUSH;
#endif
termdown(3);
return ING_ASK;
case NGS_DONE:
return ING_ASK;
}
#else
notincl("/");
#endif
break;
case 'm':
#ifndef RELOCATE
notincl("m");
break;
#endif
case 'g': /* goto named newsgroup */
if (!finish_command(FALSE))
return ING_INPUT;
for (s = buf+1; *s == ' '; s++) ; /* skip leading spaces */
#ifdef RELOCATE
if (!*s && *buf == 'm' && ngname && ngptr)
strcpy(s,ngname);
#endif
{
char* _s;
for (_s=s; isdigit(*_s); _s++) ;
if (*_s)
/* found non-digit before hitting end */
set_ngname(s);
else {
int rcnum = atoi(s);
for (ngptr = first_ng; ngptr; ngptr = ngptr->next)
if (ngptr->num == rcnum)
break;
if (!ngptr) {
ngptr = current_ng;
printf("\nOnly %d groups. Try again.\n", newsgroup_cnt) FLUSH;
termdown(2);
return ING_ASK;
}
set_ngname(ngptr->rcline);
}
}
/* try to find newsgroup */
#ifdef RELOCATE
if (!get_ng(ngname,(*buf=='m'?GNG_RELOC:0) | GNG_FUZZY))
#else
if (!get_ng(ngname,GNG_FUZZY))
#endif
ngptr = current_ng; /* if not found, go nowhere */
addnewbydefault = 0;
return ING_SPECIAL;
#ifdef DEBUG
case 'D':
return ING_ASK;
#endif
case '!': /* shell escape */
if (escapade()) /* do command */
return ING_INPUT;
return ING_ASK;
case Ctl('k'): /* edit global KILL file */
edit_kfile();
return ING_ASK;
case Ctl('n'): /* next newsrc list */
end_only();
use_next_multirc(multirc);
goto display_multirc;
case Ctl('p'): /* prev newsrc list */
end_only();
use_prev_multirc(multirc);
display_multirc:
{
NEWSRC* rp;
int len;
for (rp = multirc->first, len = 0; rp && len < 66; rp = rp->next) {
if (rp->flags & RF_ACTIVE) {
sprintf(buf+len, ", %s", rp->datasrc->name);
len += strlen(buf+len);
}
}
if (rp)
strcpy(buf+len, ", ...");
printf("\n\nUsing newsrc group #%d: %s.\n",multirc->num,buf+2);
termdown(3);
return ING_RESTART;
}
case 'c': /* catch up */
#ifdef CATCHUP
if (ngptr) {
ask_catchup();
if (ngptr->toread == TR_NONE)
ngptr = ngptr->next;
}
#else
notincl("c");
#endif
break;
case 't':
if (!use_threads)
printf("\n\nNot running in thread mode.\n");
else if (ngptr && ngptr->toread >= TR_NONE) {
bool read_unthreaded = !(ngptr->flags&NF_UNTHREADED);
ngptr->flags ^= NF_UNTHREADED;
printf("\n\n%s will be read %sthreaded.\n",
ngptr->rcline, read_unthreaded? "un" : nullstr) FLUSH;
set_toread(ngptr, ST_LAX);
}
termdown(3);
return ING_SPECIAL;
case 'u': /* unsubscribe */
if (ngptr && ngptr->toread >= TR_NONE) {/* unsubscribable? */
newline();
printf(unsubto,ngptr->rcline) FLUSH;
termdown(1);
ngptr->subscribechar = NEGCHAR; /* unsubscribe it */
ngptr->toread = TR_UNSUB; /* and make line invisible */
ngptr->rc->flags |= RF_RCCHANGED;
ngptr = ngptr->next; /* do an automatic 'n' */
newsgroup_toread--;
}
break;
case 'h':
univ_help(UHELP_NG);
return ING_ASK;
case 'H': /* help */
help_ng();
return ING_ASK;
case 'A':
if (!ngptr)
break;
reask_abandon:
#ifdef VERBOSE
IF(verbose)
in_char("\nAbandon changes to current newsgroup?", 'B', "yn");
ELSE
#endif
#ifdef TERSE
in_char("\nAbandon?", 'B', "ynh");
#endif
#ifdef VERIFY
printcmd();
#endif
newline();
if (*buf == 'h') {
#ifdef VERBOSE
printf("Type y or SP to abandon the changes to this group since you started trn.\n");
printf("Type n to leave the group as it is.\n");
#else
printf("y or SP to abandon changes to this group.\n");
printf("n to forget it.\n");
#endif
termdown(2);
goto reask_abandon;
} else if (*buf != 'y' && *buf != 'n' && *buf != 'q') {
fputs(hforhelp,stdout) FLUSH;
termdown(1);
settle_down();
goto reask_abandon;
} else if (*buf == 'y')
abandon_ng(ngptr);
return ING_SPECIAL;
case 'a':
#ifndef FINDNEWNG
notincl("a");
return ING_ASK;
#else
/* FALL THROUGH */
#endif
case 'o':
case 'O': {
#ifdef FINDNEWNG
bool doscan = (*buf == 'a');
#endif
if (!finish_command(TRUE)) /* get rest of command */
return ING_INPUT;
*msg = '\0';
end_only();
if (buf[1]) {
bool minusd = instr(buf+1,"-d", TRUE) != NULL;
sw_list(buf+1);
if (minusd)
cwd_check();
#ifdef FINDNEWNG
if (doscan && maxngtodo)
scanactive(TRUE);
#endif
ng_min_toread = *buf == empty_only_char && maxngtodo
? TR_NONE : TR_ONE;
}
ngptr = first_ng; /* simulate ^ */
if (*msg && !maxngtodo)
return ING_MESSAGE;
return ING_DISPLAY;
}
case '&':
if (switcheroo()) /* get rest of command */
return ING_INPUT; /* if rubbed out, try something else */
return ING_ASK;
case 'l': { /* list other newsgroups */
if (!finish_command(TRUE)) /* get rest of command */
return ING_INPUT; /* if rubbed out, try something else */
for (s = buf+1; *s == ' '; s++) ; /* skip leading spaces */
push_only();
if (*s)
sw_list(s);
page_start();
scanactive(FALSE);
pop_only();
return ING_ASK;
}
case '`':
case '\\':
if (gmode == 's')
return ING_ERASE;
ng_start_sel:
UseNewsgroupSelector = TRUE;
switch (newsgroup_selector()) {
case Ctl('n'):
end_only();
use_next_multirc(multirc);
goto ng_start_sel;
case Ctl('p'):
end_only();
use_prev_multirc(multirc);
goto ng_start_sel;
case 'q':
return ING_QUIT;
}
UseNewsgroupSelector = FALSE;
return ING_ASK;
#ifdef SCAN_ART
case ';':
#endif
case 'U': case '+':
case '.': case '=':
case 'y': case 'Y': case '\t': /* do normal thing */
case ' ': case '\r': case '\n':
if (!ngptr) {
fputs("\nNot on a newsgroup.",stdout) FLUSH;
termdown(1);
return ING_ASK;
}
/* CAA: *once*, the char* s was set to an illegal value
* (it seemed to miss all the if statements below)
* Just to be safe, make sure it is legal.
*/
s = nullstr;
if (*buf == '.') { /* start command? */
if (!finish_command(FALSE)) /* get rest of command */
return ING_INPUT;
s = savestr(buf+1); /* do_newsgroup will free it */
}
else if (*buf == '+' || *buf == 'U' || *buf == '='
#ifdef SCAN_ART
|| *buf == ';'
#endif
) {
*buf = lastchar; /* restore 0200 if from a macro */
save_typeahead(buf+1, sizeof buf - 1);
s = savestr(buf);
}
else if (*buf == ' ' || *buf == '\r' || *buf == '\n')
s = nullstr;
else
s = NULL;
redo_newsgroup:
switch (do_newsgroup(s)) {
case NG_NORM:
case NG_NEXT:
case NG_ERROR:
ngptr = ngptr->next;
break;
case NG_ASK:
return ING_ASK;
case NG_SELPRIOR:
*buf = 'p';
goto do_command;
case NG_SELNEXT:
*buf = 'n';
goto do_command;
case NG_MINUS:
ngptr = recent_ng; /* recall previous newsgroup */
return ING_SPECIAL;
#ifdef SUPPORT_NNTP
case NG_NOSERVER:
nntp_server_died(ngptr->rc->datasrc);
return ING_NOSERVER;
#endif
/* CAA extensions */
case NG_GO_ARTICLE:
ngptr = ng_go_ngptr;
s = savestr("y"); /* enter with minimal fuss */
goto redo_newsgroup;
/* later: possible go-to-newsgroup */
}
break;
case ':': /* execute command on selected groups */
if (!ngsel_perform())
return ING_INPUT;
page_line = 1;
newline();
set_ng(current_ng);
return ING_ASK;
case 'v':
newline();
trn_version();
return ING_ASK;
default:
if (*buf == ERASECH || *buf == KILLCH)
return ING_ERASE;
return ING_ERROR;
}
return ING_NORM;
}
#ifdef SUPPORT_NNTP
void
check_active_refetch(force)
bool_int force;
{
DATASRC* dp;
time_t now = time((time_t*)NULL);
for (dp = datasrc_first(); dp && dp->name; dp = datasrc_next(dp)) {
if (!ALLBITS(dp->flags, DF_OPEN | DF_ACTIVE))
continue;
if (dp->act_sf.fp && dp->act_sf.refetch_secs
&& (force || now - dp->act_sf.lastfetch > dp->act_sf.refetch_secs))
actfile_hash(dp);
}
}
#endif
void
trn_version()
{
page_start();
sprintf(msg,"Trn version:%s.\nConfigured for ",patchlevel);
#ifdef SUPPORT_NNTP
# ifdef HAS_LOCAL_SPOOL
strcat(msg,"both NNTP and local news access.\n");
# else
strcat(msg,"NNTP (plus individual local access).\n");
# endif
#else
strcat(msg,"local news access.\n");
#endif
print_lines(msg, NOMARKING);
if (multirc) {
NEWSRC* rp;
newline();
sprintf(msg,"News source group #%d:\n\n", multirc->num);
print_lines(msg, NOMARKING);
for (rp = multirc->first; rp; rp = rp->next) {
if (!(rp->flags & RF_ACTIVE))
continue;
sprintf(msg,"ID %s:\nNewsrc %s.\n",rp->datasrc->name,rp->name);
print_lines(msg, NOMARKING);
#ifdef SUPPORT_NNTP
if (rp->datasrc->flags & DF_REMOTE) {
sprintf(msg,"News from server %s.\n",rp->datasrc->newsid);
print_lines(msg, NOMARKING);
if (rp->datasrc->act_sf.fp) {
if (rp->datasrc->flags & DF_TMPACTFILE)
strcpy(msg,"Copy of remote active file");
else
sprintf(msg,"Local active file: %s",
rp->datasrc->extra_name);
}
else
strcpy(msg,"Dynamic active file");
if (rp->datasrc->act_sf.refetch_secs) {
char* cp = secs2text(rp->datasrc->act_sf.refetch_secs);
if (*cp != 'n')
sprintf(msg+strlen(msg),
" (refetch%s %s)",*cp == 'm'? " if" : ":", cp);
}
strcat(msg,".\n");
}
else
#endif
sprintf(msg,"News from %s.\nLocal active file %s.\n",
rp->datasrc->spool_dir, rp->datasrc->newsid);
print_lines(msg, NOMARKING);
if (rp->datasrc->grpdesc) {
#ifdef SUPPORT_NNTP
if (!rp->datasrc->desc_sf.fp && rp->datasrc->desc_sf.hp)
strcpy(msg,"Dynamic group desc. file");
else if (rp->datasrc->flags & DF_TMPGRPDESC)
strcpy(msg,"Copy of remote group desc. file");
else
#endif
sprintf(msg,"Group desc. file: %s",rp->datasrc->grpdesc);
#ifdef SUPPORT_NNTP
if (rp->datasrc->desc_sf.refetch_secs) {
char* cp = secs2text(rp->datasrc->desc_sf.refetch_secs);
if (*cp != 'n')
sprintf(msg+strlen(msg),
" (refetch%s %s)",*cp == 'm'? " if" : ":", cp);
}
#endif
strcat(msg,".\n");
print_lines(msg, NOMARKING);
}
if (rp->datasrc->flags & DF_TRY_OVERVIEW) {
sprintf(msg,"Overview files from %s.\n",
rp->datasrc->over_dir? rp->datasrc->over_dir
: "the server");
print_lines(msg, NOMARKING);
}
if (rp->datasrc->flags & DF_TRY_THREAD) {
sprintf(msg,"Thread files from %s.\n",
rp->datasrc->thread_dir? rp->datasrc->thread_dir
: "the server");
print_lines(msg, NOMARKING);
}
print_lines("\n", NOMARKING);
}
}
print_lines("\
You can request help from: trn-users@lists.sourceforge.net\n\
Send bug reports, suggestions, etc. to: trn-workers@lists.sourceforge.net\n",
NOMARKING);
}
void
set_ngname(what)
char* what;
{
if (ngname != what) {
ngname_len = strlen(what);
growstr(&ngname,&ngnlen,ngname_len+1);
strcpy(ngname,what);
}
growstr(&ngdir,&ngdlen,ngname_len+1);
strcpy(ngdir,getngdir(ngname));
}
static char* myngdir;
static int ngdirlen = 0;
char*
getngdir(ngnam)
char* ngnam;
{
register char* s;
growstr(&myngdir,&ngdirlen,strlen(ngnam)+1);
strcpy(myngdir,ngnam);
for (s = myngdir; *s; s++)
if (*s == '.')
*s = '/';
return myngdir;
}
|