subtle "algorithm" definition issue.
David Relson
relson at osagesoftware.com
Sun Nov 3 19:48:58 CET 2002
At 01:13 PM 11/3/02, Matthias Andree wrote:
>Hi,
>
>I've tried to clean up the source a bit, and I found that bogofilter.h
>contained a definition of the algorithm variable. I don't think this is
>right, and removing it indeed revealed a problem: bogoutil needs the
>algorithm, but never initializes it properly.
>
>Change this line in bogofilter.h
>
>enum algorithm { AL_GRAHAM, AL_ROBINSON } algorithm;
>
>to
>
>enum algorithm { AL_GRAHAM = 1, AL_ROBINSON };
>
>You'll then find that bogoutil no longer compiles, and the necessary
>dependency flow is intricate.
>
>wordlists.c:setup_lists calls init_list with GOOD_BIAS, which itself
>depends on algorithm:
>
>bogofilter.h:18:
>#define GOOD_BIAS (algorithm == AL_GRAHAM ? GRAHAM_GOOD_BIAS :
>ROBINSON_GOOD_BIAS)
>
>I'm unsure how the interfaces must be changed to make this clear. I
>wondered if I should just add enum algorithm algorithm = AL_GRAHAM; to
>bogoutil, but that does not look right to me.
>
>Opinions appreciated.
Matthias,
The statement in bogofilter.h wasn't intended to declare the variable. It
probably should be the enum statement in your change. However, when I do
that, I see that global variable "algorithm" is used in programs
bogofilter, bogoutil, configtest, and debugtest. Bogofilter has at least
one other global variable that I see declared in the main routines of
several programs, i.e. run_type.
This, and the implementation of config.c, leads to the broader questions:
Where do global variables belong?
Where do variables for configuration options belong?
The answer that comes to mind first is:
create a globals.c to hold run_type, algorithm, etc.
use config.c as the home for configuration options.
I suspect some variables fit both categories (config and global). I doubt
there'll be any code in globals.c, so maybe it shouldn't even
exist. Perhaps we should put them all in config.c.
David
More information about the bogofilter-dev
mailing list