🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
3 messages
3 total messages Started by John E. Davis Tue, 05 Feb 2013 19:58
Re: my 2nd slrn macro - works sometimes, else "stack underflow"
#253359
Author: John E. Davis
Date: Tue, 05 Feb 2013 19:58
113 lines
4157 bytes
[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
Re: my 2nd slrn macro - works sometimes, else "stack underflow"
#253362
Author: Ignatios Souvatzis
Date: Wed, 06 Feb 2013 08:56
47 lines
2746 bytes
John E. Davis wrote: 
> [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
> <u502sou@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.

Ah, thanks!

> 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. 

I noticed that in the meantime...

> You see it only sometimes because "group_search" does return a value,
> which you leave on the stack.

Ah, ok.

> My suggested changes are below:

> I would rewrite the next three blocks of code:

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

I considered using 'where', but for an article that's cross-posted
to three groups, I'd only ever be able to reach the first, if I
was in another, or the second, if I was in the the first one.

I'd somehow need to rotate the array until cgroup is at the end. 

	-is
Re: my 2nd slrn macro - works sometimes, else "stack underflow"
#253364
Author: Ignatios Souvatzis
Date: Wed, 06 Feb 2013 11:45
71 lines
2814 bytes
Ignatios Souvatzis wrote: 

> I considered using 'where', but for an article that's cross-posted
> to three groups, I'd only ever be able to reach the first, if I
> was in another, or the second, if I was in the the first one.
>
> I'd somehow need to rotate the array until cgroup is at the end. 

Well, not much harder:

#v+
define switchto ()
{
	variable msgid;
	variable cgroup;
	variable groupstr, grouparr, grouplen;
	variable ngroup;
	variable foundit;
	variable foundwhere;

	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");

	% assuming there's only one:
	foundwhere = where(grouparr == cgroup);

	if (length(foundwhere)) {
		foundit = foundwhere[0];

		grouparr = [
		    grouparr[[foundit+1:grouplen-1]],
		    grouparr[[0:foundit]],
		    ];
	}

	foreach ngroup (grouparr) {
		if (group_search(ngroup)) {
			break;
		}
	}

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

Hm. I might want to have an else case:
	if (length(foundwhere)) {
		...as above
	} else {
		grouparr = [grouparr, cgroup];
	}

Else I'd end up in group view if I couldn't get to any group the
article is in.

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

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads