head 1.1; branch 1.1.1; access; symbols ISELECT_1_4_0:1.1.1.2 ISELECT_1_3_1:1.1.1.2 ISELECT_1_3_0:1.1.1.2 ISELECT_1_2_0:1.1.1.2 ISELECT_1_1_0:1.1.1.2 ISELECT_1_0_4:1.1.1.1 vendor:1.1.1; locks; strict; comment @# @; 1.1 date 97.12.29.08.01.02; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 97.12.29.08.01.02; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 98.04.05.16.38.17; author rse; state Exp; branches; next ; desc @@ 1.1 log @Initial revision @ text @#!/sw/bin/perl ## ## MetaTIN -- a TIN frontend for better USENET NetNews reading ## Copyright (c) 1996-1997 Ralf S. Engelschall, All Rights Reserved. ## use IO::Socket; sub existsgroup { local ($host, $group) = @@_; local ($NNTP); $NNTP = new IO::Socket::INET( 'PeerAddr' => $host, 'PeerPort' => 'nntp', 'Proto' => 'tcp', 'Timeout' => 120 ); $NNTP->autoflush(1); $NNTP->getline(); # greating $NNTP->print("mode reader\r\n"); $NNTP->getline(); # greating $NNTP->print("group $group\r\n"); $rc = $NNTP->getline(); # greating $rc =~ m|^(\d+) .+|; $rc = $1; $NNTP->print("quit\r\n"); $NNTP->close(); return ($rc == 211 ? 1 : 0); } # determine homedir of caller $HOME = $ENV{'HOME'}; # the files we operate on $newsrc = "$HOME/.mtinrc"; $newsrcwork = "$HOME/.newsrc"; # function to get the topics out of the annotated newsrc sub NEWSRC_GetTopics { local (%NewsgroupTopic) = (); $cnt = 1; open(FP, "<$newsrc"); while () { next if m|^[ \t]*#.*$|; next if m|^[ \t]*$|; if (m|^%%T[ \t]+(.*)$|) { $topic_tag = $1; $topic_name = ""; $newsgroups_sub = 0; $newsgroups_unsub = 0; next; } if (m|^%%N[ \t]+(.*)$|) { $topic_name = $1; next; } if (m|^[a-zA-Z0-9-.]+!.*$|) { $newsgroups_unsub++; next; } if (m|^[a-zA-Z0-9-.]+:.*$|) { $newsgroups_sub++; next; } if (m|^%%E[ \t]*$|) { $key = sprintf("%02d-%s", $cnt, $topic_tag); $NewsgroupTopic{$key} = "$topic_name%%$newsgroups_sub%%$newsgroups_unsub"; $cnt++; } } close(FP); return (%NewsgroupTopic); } sub NEWSRC_GetTopicPart { local($tag) = @@_[0]; local($buffer); local($save); open(FP, "<$newsrc"); $save = 0; while () { next if m|^[ \t]*#.*$|; next if m|^[ \t]*$|; if (m|^%%T[ \t]+(.+)[ \t]*$|) { if ("$1" eq "$tag") { $save = 1; } } if (m|^%%E.*$|) { $save = 0; } if ($save) { next if m|^%%.*|; $buffer .= $_; } } close(FP); return($buffer); } sub NEWSRC_SetTopicPart { local($tag, $buffer) = @@_; local($save); open(FPI, "<$newsrc"); open(FPO, ">${newsrc}.n"); $set = 0; $ignore = 0; while () { if (m|^%%N.*$|) { print FPO $_; next; } if (m|^%%T[ \t]+(.+)[ \t]*$|) { if ("$1" eq "$tag") { $set = 1; $ignore = 0; print FPO $_; next; } } if (m|^%%E.*$|) { $set = 0; $ignore = 0; print FPO $_; next; } if ($set) { if ($ignore == 0) { print FPO "$buffer"; $ignore = 1; } } else { print FPO "$_"; } } close(FPI); close(FPO); system("mv $newsrc ${newsrc}.bak"); system("mv ${newsrc}.n $newsrc"); } %NewsgroupTopic = &NEWSRC_GetTopics(); $clusters = 0; foreach $key (sort(keys(%NewsgroupTopic))) { $clusters++; } $itemlist = "'' "; $itemlist .= "'Available Clusters: $clusters, Newsserver: $ENV{NNTPSERVER}' "; $itemlist .= "'' "; $n = 1; foreach $key (sort(keys(%NewsgroupTopic))) { $NewsgroupTopic{$key} =~ m|^(.+)%%(.+)%%(.+)$|; ($name, $countsub, $countunsub) = ($1, $2, $3); $key =~ s|^\d+-||; $itemlist .= sprintf("'%2d %3d %-15s %-50s %%%%S:%s%%%%' ", $n, $countsub, $key, $name, $key); $n++; } $itemlist .= "'' "; $itemlist .= "'_____________________________________________________' "; $itemlist .= "'' "; $itemlist .= "'Help: , .......... browse cluster list' "; $itemlist .= "' , ..... select cluster (run TIN)' "; $itemlist .= "' q, ............. quit' "; $result = "/tmp/mtin.$$.tmp"; $quit = 0; $pos = 4; while ($quit ne 1) { # run the fullscreen menu via iSelect $rc = system("iselect -p$pos -P -n 'MetaTIN 1.0.0' -t 'USENET Newsgroup Clusters' $itemlist >$result"); $tag = `cat $result`; if ($tag eq '') { $quit = 1; next; } $tag =~ s|\n$||; $tag =~ m|^(\d+):(.*)|; ($pos, $tag) = ($1, $2); # copy topic from .mtinrc to newsrc $buffer = &NEWSRC_GetTopicPart($tag); open(FP, ">$newsrcwork"); print FP $buffer; close(FP); # run TIN on the newsrc system("clear"); system("tin -r -q -f $newsrcwork"); # copy changed topic back to .mtinrc $buffer = ""; open(FP, "<$newsrcwork"); while () { #if (m|^([^ \t:!\n]+)|) { # if (not &existsgroup("$ENV{'NNTPSERVER'}", "$1")) { # print STDERR "WARNING! group $1 not exists - REMOVED\n"; # next; # } #} $buffer .= $_; } close(FP); &NEWSRC_SetTopicPart($tag, $buffer); } unlink($result); ##EOF## @ 1.1.1.1 log @Import iSelect 1.0.4 @ text @@ 1.1.1.2 log @Import iSelect 1.1.0 @ text @d162 1 a162 1 $itemlist .= sprintf("'%2d %3d %-15s %-50s ' ", $n, $countsub, $key, $name, $key); @