Article View: news.software.readers
Article #42940Re: [slrn] Could extract_article_header() return # of lines?
From: Dawn Owens-Nicholson
Date: Sun, 30 Aug 1998 00:00
Date: Sun, 30 Aug 1998 00:00
100 lines
4712 bytes
4712 bytes
Lloyd Zusman <ljz@asfast.com> wrote:
> Hmmm ... how would I do that? Here's some sample code that
> illustrates how I'm traversing all the articles in a given newsgroup.
You could make a wrapper for extract_article_header() that will work around
the bugs or include similar code in your function, I'll demonstrate both
ways. The workaround has a bug -- if the cursor is not at the visible
article, there's no way to figure out what article is showing
(extract_article_header()'s job is to show info like this for the article at
the cursor), so this will punt and show you the current article. It's not a
low-bandwidth workaround, but if you use extract_article_header("Lines") a
lot and you're on a high-speed connection to your news server, this might be
easier to spot and alter when extract_article_header() is fixed.
The workaround:
% Bugfix for slrn's extract_article_header() % -*- slang -*-
%
% Fixes extract_article_header() for known problem areas:
% Message-ID -- remove leading (and trailing, if any) whitespace.
% Lines -- return as an integer after selecting/deselecting article.
define bugfix_extract_article_header (header)
{
if (is_group_mode ())
error (_function_name () + "doesn\'t work in group mode");
% Most times, extract_article_header() works okay, so we record it...
variable retval = extract_article_header (header);
switch (header) % ...other times, we fix it.
{ case ("Message-ID") : return (strtrim (retval)); }
{ case ("Lines") :
variable article_was_visible = is_article_visible ();
call ("select_article");
!if (article_was_visible) call ("hide_article");
return (integer (strtrim (extract_article_header (header))));
}
{ return (retval); } % ...and return it unmodified.
}
For "Message-ID:" return the message-ID without the leading whitespace. For
"Lines:" return the number of lines as an integer (it makes more sense to me
that you'd want that). You could use this by substituting
"bugfix_extract_article_header" where you use "extract_article_header".
When the function is fixed, restore your code to the way it should be.
Or you can put this in your code:
> %%% Sample only ...
> define article_mode_hook ()
> {
> call( "header_bob" );
> uncollapse_threads();
>
variable article_was_visible = 0; % for recording some state
> do
> {
> %%% What do I do here to make each article the
> %%% 'most recently read' article?
% Find out if the article was visible
article_was_visible = is_article_visible ();
% Select the article, then conditionally hide it.
call ("scroll_dn"); % select the article (unhide)
!if (article_was_visible) % conditionally hide article
call ("hide_article");
> variable stringLines = extract_article_header( "Lines" );
> variable integerLines = integer( strtrim( stringLines ) );
>
> %%% At this point, `stringLines' is the empty string and
> %%% `integerLines' is zero.
% Now, stringLines should be "74" (for instance) and
% integerLines should be 74.
>
> variable stringFrom = extract_article_header( "From" );
>
> %%% At this point, `stringFrom' contains the text from
> %%% the appropriate "From:" line.
>
> } while ( header_down( 1 ) );
>
> collapse_threads();
> call( "header_bob" );
> }
By the way, the "variable" calls inside the loop will fail in S-Lang 1.x if
the do-while loop executes more than once--you'll be declaring a variable
that already exists and that's an error in S-Lang. You'll need to move
those declarations before the loop. What you've got works in S-Lang prior
to 1.x, however. I don't know what version of S-Lang you're using, so I
thought I'd mention it.
Hope this helps!
Technical Details
Message-ID:
<slrn6ujg18.89l.bluemoon@ux6.cso.uiuc.edu>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mailReferences:
<slrn6uha35.l0.ljz@sunspot.tiac.net> <slrn6uj1m0.ff1.bluemoon@ux6.cso.uiuc.edu> <lt1zpypadr.fsf@asfast.com>Show Full Headers
Complete Article Headers
Message-ID: <slrn6ujg18.89l.bluemoon@ux6.cso.uiuc.edu> Subject: Re: [slrn] Could extract_article_header() return # of lines? Date: Sun, 30 Aug 1998 00:00:00 +0000 From: bluemoon@ux6.cso.uiuc.edu (Dawn Owens-Nicholson) References: <slrn6uha35.l0.ljz@sunspot.tiac.net> <slrn6uj1m0.ff1.bluemoon@ux6.cso.uiuc.edu> <lt1zpypadr.fsf@asfast.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail X-Deja-AN: 386240880 Organization: University of Illinois at Urbana-Champaign Newsgroups: news.software.readers