File: mtin

package info (click to toggle)
iselect 1.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 872 kB
  • sloc: sh: 3,353; ansic: 2,074; perl: 485; makefile: 109
file content (216 lines) | stat: -rwxr-xr-x 5,241 bytes parent folder | download | duplicates (10)
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
#!/usr/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 (<FP>) {
        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 (<FP>) {
        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 (<FPI>) {
        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: <up>,<down> .......... browse cluster list' ";
$itemlist .= "'      <return>,<right> ..... select cluster (run TIN)' ";
$itemlist .= "'      q,<left> ............. 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 (<FP>) {
        #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##