Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

my 2nd slrn macro - works sometimes, else "stack underflow"

7 views
Skip to first unread message

Ignatios Souvatzis

unread,
Feb 5, 2013, 11:23:03 AM2/5/13
to
This is supposed to cycle through the Newsgroups the current article
was posted to that are available on the server.

I bound this to key w in article-mode. This works sometimes, then changes
to displaying "stack underflow error" and leaving me in the header window
without redisplaying the article.

Both newsgroups are available in the test cases.

Any idea how I'd find out what's wrong?

-is

define switchto ()
{
variable msgid;
variable cgroup;
variable groupstr, grouparr, grouplen;
variable i;
variable foundit;

call("article_bob");

msgid = extract_article_header("Message-ID");

cgroup = current_newsgroup();

groupstr = extract_article_header("Newsgroups");
grouparr = strtok(groupstr, ", \t\n");
grouplen = length(grouparr);

if (is_group_mode() == 0)
call("quit");

for (i=0; i<grouplen; i++) {
if (grouparr[i] == cgroup) {
foundit = i;
break;
}
}

for(i = (foundit+1) mod grouplen;
i != foundit;
i = (i+1) mod grouplen) {
if (group_search(grouparr[i])) {
break;
}
}

if (i == foundit) {
group_search(cgroup);
}

() = select_group();
() = locate_header_by_msgid(msgid, 1);
() = uncollapse_thread();
call("article_bob");
}

--
seal your e-mail: http://www.gnupg.org/

John E. Davis

unread,
Feb 5, 2013, 2:58:24 PM2/5/13
to
[I set the followup-to header to news.software.readers since not all
servers carry alt.lang.s-lang]

On Tue, 5 Feb 2013 17:23:03 +0100, Ignatios Souvatzis <u50...@beverly.kleinbus.org>
wrote:
> This is supposed to cycle through the Newsgroups the current article
> was posted to that are available on the server.
[...]
>
> Any idea how I'd find out what's wrong?

The simplest way is to run slrn using the --debug option. Errors will
be written to the log file.

Your bug is caused by the way you are calling the "uncollapse_thread".
You are treating it as if it returns a value but it returns nothing.
This will generate a stack-underflow error. You see it only sometimes
because "group_search" does return a value, which you leave on the
stack.

My suggested changes are below:

> define switchto ()
>{
> variable msgid;
> variable cgroup;
> variable groupstr, grouparr, grouplen;
> variable i;
> variable foundit;
>
> call("article_bob");
>
> msgid = extract_article_header("Message-ID");
>
> cgroup = current_newsgroup();
>
> groupstr = extract_article_header("Newsgroups");
> grouparr = strtok(groupstr, ", \t\n");
> grouplen = length(grouparr);
>
> if (is_group_mode() == 0)
> call("quit");
>

I would rewrite the next three blocks of code:

> for (i=0; i<grouplen; i++) {
> if (grouparr[i] == cgroup) {
> foundit = i;
> break;
> }
> }
>
> for(i = (foundit+1) mod grouplen;
> i != foundit;
> i = (i+1) mod grouplen) {
> if (group_search(grouparr[i])) {
> break;
> }
> }
>
> if (i == foundit) {
> group_search(cgroup);
> }

more simply as:
#v+
grouparr = [grouparr[where(grouparr != cgroup)], cgroup];
foreach cgroup (grouparr)
if (group_search (cgroup))
break;
#v-
>
> () = select_group();
> () = locate_header_by_msgid(msgid, 1);
> () = uncollapse_thread();

As mentioned earler, the last line should be written as just

uncollapse_thread ();

> call("article_bob");
>}
>

Here is my version of your function:

#v+
define switchto ()
{
variable
msgid = extract_article_header("Message-ID"),
cgroup = current_newsgroup(),
grouparr = strtok (extract_article_header("Newsgroups"), ", \t\n");

if (is_group_mode() == 0)
call("quit");

grouparr = [grouparr[where(grouparr != cgroup)], cgroup];
foreach cgroup (grouparr)
if (group_search (cgroup))
break;

() = select_group();
() = locate_header_by_msgid(msgid, 1);
uncollapse_thread();
call("article_bob");
}
#v-

I hope this helps.
Good luck, --John

Ignatios Souvatzis

unread,
Feb 5, 2013, 12:07:47 PM2/5/13
to
Found it. uncollapse_thread() is Void and may not ()='ed.

-is
0 new messages