line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gnus::Newsrc; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Gnus::Newsrc - parse ~/.newsrc.eld files |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$newsrc = Gnus::Newsrc->new; |
10
|
|
|
|
|
|
|
($level, $read, $marks, $server, $group_para) = |
11
|
|
|
|
|
|
|
@{$newsrc->alist_hash->{"comp.lang.perl.misc"}}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
The C objects represents the content of the ~/newsrc.eld |
16
|
|
|
|
|
|
|
files that the Gnus newsreader use to store away its state. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
The following methods are provided: |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=over 4 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
680
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
25
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
108
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/); |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
582
|
use Lisp::Reader qw(lisp_read); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
781
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item $newsrc = Gnus::Newsrc->new( [$filename] ) |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
The object constructor takes an optional filename as argument. The |
36
|
|
|
|
|
|
|
file defaults to F<~/.newsrc.eld>. It will read and parse the file |
37
|
|
|
|
|
|
|
and return a reference to a C object. The constructor |
38
|
|
|
|
|
|
|
will croak if the file can't be found or can't be parsed. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new |
43
|
|
|
|
|
|
|
{ |
44
|
1
|
|
|
1
|
1
|
57
|
my($class, $file) = @_; |
45
|
1
|
50
|
|
|
|
5
|
$file = "$ENV{HOME}/.newsrc.eld" unless defined $file; |
46
|
1
|
|
|
|
|
4
|
local($/) = undef; #slurp; |
47
|
1
|
50
|
|
|
|
37
|
open(LISP, $file) || die "Can't open $file: $!"; |
48
|
1
|
|
|
|
|
29
|
my $lisp = ; |
49
|
1
|
|
|
|
|
8
|
close(LISP); |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
2
|
local $Lisp::Reader::SYMBOLS_AS_STRINGS = 1; # gives quicker parsing |
52
|
1
|
|
|
|
|
23
|
my $form = lisp_read($lisp); |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
4
|
my $self = bless {}, $class; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
3
|
for (@$form) { |
57
|
7
|
|
|
|
|
10
|
my($one,$two,$three) = @$_; |
58
|
|
|
|
|
|
|
#print join(" - ", map {$_->name} $one, $two), "\n"; |
59
|
7
|
50
|
|
|
|
9
|
if ($one eq "setq") { |
60
|
7
|
100
|
|
|
|
15
|
if (ref($three) eq "ARRAY") { |
61
|
6
|
|
|
|
|
7
|
my $first = $three->[0]; |
62
|
6
|
50
|
|
|
|
8
|
if ($first eq "quote") { |
63
|
6
|
|
|
|
|
8
|
$three = $three->[1]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
7
|
|
|
|
|
21
|
$self->{$two} = $three; |
67
|
|
|
|
|
|
|
} else { |
68
|
0
|
|
|
|
|
0
|
warn "$_ does not start with (setq symbo ...)\n"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# make the 'gnus-newsrc-alist' into a more perl suitable structure |
73
|
1
|
|
|
|
|
1
|
for (@{$self->{'gnus-newsrc-alist'}}) { |
|
1
|
|
|
|
|
3
|
|
74
|
10
|
|
|
|
|
17
|
my($group, $level, $read, $marks, $server, $para) = @$_; |
75
|
|
|
|
|
|
|
|
76
|
10
|
|
|
|
|
12
|
for ($read, $marks, $para) { |
77
|
30
|
100
|
|
|
|
58
|
$_ = [] unless defined; |
78
|
|
|
|
|
|
|
} |
79
|
10
|
50
|
|
|
|
15
|
$_->[2] = join(",", map {ref($_)?"$_->[0]-$_->[1]":$_} @$read); |
|
11
|
|
|
|
|
51
|
|
80
|
23
|
100
|
|
|
|
62
|
$_->[3] = @$marks ? |
81
|
10
|
100
|
|
|
|
21
|
{ map {shift(@$_) => |
82
|
7
|
|
|
|
|
13
|
join(",", map {ref($_)?"$_->[0]-$_->[1]":$_}@$_)} |
83
|
|
|
|
|
|
|
@$marks |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
: undef; |
86
|
10
|
100
|
|
|
|
21
|
$_->[5] = @$para ? { map { $_->[0] => $_->[1] } @$para } : undef; |
|
6
|
|
|
|
|
20
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# trim trailing undef values |
89
|
10
|
|
66
|
|
|
102
|
pop(@$_) until defined($_->[-1]) || @$_ == 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
11
|
$self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item $newsrc->file_version |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Return the version number found in the file |
100
|
|
|
|
|
|
|
I<(gnus-newsrc-file-version)>. The version number is a string like |
101
|
|
|
|
|
|
|
C<"Gnus v5.5">. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub file_version |
106
|
|
|
|
|
|
|
{ |
107
|
1
|
|
|
1
|
1
|
8
|
shift->{"gnus-newsrc-file-version"}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item $newsrc->last_checked_date |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns a string like C<"Sat Oct 18 14:05:53 1997"> |
115
|
|
|
|
|
|
|
I<(gnus-newsrc-last-checked-date)>. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub last_checked_date |
120
|
|
|
|
|
|
|
{ |
121
|
1
|
|
|
1
|
1
|
8
|
shift->{"gnus-newsrc-last-checked-date"}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item $newsrc->alist |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns a reference to an array that will have one element for each |
129
|
|
|
|
|
|
|
active newsgroup I<(gnus-newsrc-alist)>. Each element is a array with |
130
|
|
|
|
|
|
|
the following values: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$group_name |
133
|
|
|
|
|
|
|
$group_level |
134
|
|
|
|
|
|
|
$read_articles |
135
|
|
|
|
|
|
|
\%marks |
136
|
|
|
|
|
|
|
\@server |
137
|
|
|
|
|
|
|
\%group_parameters |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The C<$read_articles> and C<%marks> values is a string of integer |
140
|
|
|
|
|
|
|
ranges, and it is suitable for initializing a C objects. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub alist |
145
|
|
|
|
|
|
|
{ |
146
|
2
|
|
|
2
|
1
|
8
|
shift->{"gnus-newsrc-alist"}; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item $newsrc->alist_hash |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Returns a reference to a hash indexed by group names. The hash values |
154
|
|
|
|
|
|
|
are the same as the C elements, but the C<$group_name> is |
155
|
|
|
|
|
|
|
missing. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub alist_hash |
160
|
|
|
|
|
|
|
{ |
161
|
1
|
|
|
1
|
1
|
20
|
my $self = shift; |
162
|
1
|
50
|
|
|
|
5
|
unless ($self->{'_alist_hash'}) { |
163
|
1
|
|
|
|
|
1
|
my %ahash; |
164
|
1
|
|
|
|
|
4
|
$self->{'_alist_hash'} = \%ahash; |
165
|
1
|
|
|
|
|
2
|
for (@{$self->alist}) { |
|
1
|
|
|
|
|
4
|
|
166
|
10
|
|
|
|
|
17
|
my @groupinfo = @$_; |
167
|
10
|
|
|
|
|
8
|
my $group = shift @groupinfo; |
168
|
10
|
|
|
|
|
22
|
$ahash{$group} = \@groupinfo; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
1
|
|
|
|
|
4
|
$self->{'_alist_hash'}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item $newsrc->server_alist |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
I<(gnus-server-alist)>. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub server_alist |
183
|
|
|
|
|
|
|
{ |
184
|
0
|
|
|
0
|
1
|
|
shift->{"gnus-server-alist"}; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item $newsrc->killed_list |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
A reference to an array that contains all the killed newsgroups I<(gnus-killed-list)>. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub killed_list |
197
|
|
|
|
|
|
|
{ |
198
|
0
|
|
|
0
|
1
|
|
shift->{"gnus-killed-list"}; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item $newsrc->zombie_list |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
A reference to an array that contains all zombie newsgroups |
206
|
|
|
|
|
|
|
I<(gnus-zombie-list)>. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub zombie_list |
211
|
|
|
|
|
|
|
{ |
212
|
0
|
|
|
0
|
1
|
|
shift->{"gnus-zombie-list"}; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item $newsrc->format_specs |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub format_specs |
222
|
|
|
|
|
|
|
{ |
223
|
0
|
|
|
0
|
1
|
|
shift->{"gnus-format-specs"}; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |
228
|
|
|
|
|
|
|
__END__ |