~peter-pearse/ubuntu/oneiric/bogofilter/prop001

« back to all changes in this revision

Viewing changes to src/bogotune.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2008-06-18 23:45:23 UTC
  • mfrom: (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: james.westby@ubuntu.com-20080618234523-7yoaxiatb0fz1f5j
Tags: upstream-1.1.7
ImportĀ upstreamĀ versionĀ 1.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: bogotune.c,v 1.233 2006/07/04 11:42:38 relson Exp $ */
 
1
/* $Id: bogotune.c 6718 2008-04-26 12:51:10Z relson $ */
2
2
 
3
3
/*****************************************************************************
4
4
 
54
54
 
55
55
#include "bogoconfig.h"
56
56
#include "bogoreader.h"
 
57
#include "bool.h"
57
58
#include "collect.h"
58
59
#include "datastore.h"
59
60
#include "longoptions.h"
144
145
 
145
146
static bool    esf_flag = true;         /* test ESF factors if true */
146
147
static bool    exit_zero = false;       /* non-error exits zero */
147
 
static char   *bogolex_file = NULL;     /* non-NULL if creating msg-count output */
 
148
static const char *bogolex_file = NULL; /* non-NULL if creating msg-count output */
148
149
static word_t *w_msg_count;
149
150
 
150
151
static uint message_count;
187
188
bool fMakeCheck = false;        /* allows quick & dirty regression testing */
188
189
uint cMakeCheck =    50;        /* ... for 50 cycles */
189
190
 
 
191
const char *logtag = NULL;
 
192
const char *spam_header_place = "";
 
193
 
190
194
/* Function Declarations */
191
195
 
192
 
static void process_bogotune_arg(int option);
193
 
 
194
196
/* Function Definitions */
195
197
 
196
198
static void bt_trap(void) {}
197
199
 
 
200
static bool get_bool(const char *name, const char *arg)
 
201
{
 
202
    bool b = str_to_bool(arg);
 
203
    if (DEBUG_CONFIG(2))
 
204
        fprintf(dbgout, "%s -> %s\n", name,
 
205
                b ? "Yes" : "No");
 
206
    return b;
 
207
}
 
208
 
198
209
static int get_cnt(double fst, double lst, double amt)
199
210
{
200
211
    int cnt = (fabs(lst - fst) + EPS) / (fabs(amt) - EPS) + 1;
710
721
 
711
722
static void print_msgcount_entry(const char *token, uint bad, uint good)
712
723
{
713
 
    printf( "\"%s\" %u %u\n", token, bad, good);
 
724
    printf("\"%s\" %u %u\n", token, bad, good);
714
725
}
715
726
 
716
727
static void write_msgcount_file(wordhash_t *wh)
738
749
    return;
739
750
}
740
751
 
741
 
static uint read_mailbox(char *arg, mlhead_t *msgs)
 
752
static uint read_mailbox(const char *arg, mlhead_t *msgs)
742
753
{
743
754
    if (verbose) {
744
755
        printf("Reading %s\n", arg);
961
972
        int option_index = 0;
962
973
        int this_option_optind = optind ? optind : 1;
963
974
        const char *name;
 
975
        const char *val;
964
976
 
965
977
        option = getopt_long(argc, argv, OPTIONS,
966
978
                             longopts_bogotune, &option_index);
970
982
 
971
983
        name = (option_index == 0) ? argv[this_option_optind] : longopts_bogotune[option_index].name;
972
984
 
973
 
        process_bogotune_arg(option);
 
985
        val = optarg;
 
986
        process_arg(option, NULL, val, PR_NONE, PASS_1_CLI);
974
987
    }
975
988
 
976
989
    if (ds_flag == DS_NONE)     /* default is "wordlist on disk" */
994
1007
    return count;
995
1008
}
996
1009
 
997
 
static void process_bogotune_arg(int option)
 
1010
int process_arg(int option, const char *name, const char *val, priority_t precedence, arg_pass_t pass)
998
1011
{
999
1012
    static int lastmode = -1;
1000
1013
 
 
1014
    (void) name;        /* suppress compiler warning */
 
1015
    (void) precedence;  /* suppress compiler warning */
 
1016
    (void) pass;        /* suppress compiler warning */
 
1017
 
1001
1018
    if (option == 1) {
1002
1019
        /* If getopt's RETURN_IN_ORDER behavior */
1003
1020
        switch (lastmode) {
1013
1030
 
1014
1031
    switch (option) {
1015
1032
    case 'c':
1016
 
        read_config_file(optarg, false, false, PR_CFG_USER, longopts_bogotune);
1017
 
        /* FALLTHROUGH */
 
1033
        read_config_file(val, false, false, PR_CFG_USER, longopts_bogotune);
 
1034
        /*@fallthrough@*/
 
1035
        /* fall through to suppress reading config files */
 
1036
 
1018
1037
    case 'C':
1019
1038
        suppress_config_file = true;
1020
1039
        break;
 
1040
 
1021
1041
    case 'd':
1022
 
        ds_path = xstrdup(optarg);
 
1042
        ds_path = xstrdup(val);
1023
1043
        ds_flag = (ds_flag == DS_NONE) ? DS_DSK : DS_ERR;
1024
1044
        break;
 
1045
 
1025
1046
    case 'D':
1026
1047
        ds_flag = (ds_flag == DS_NONE) ? DS_RAM : DS_ERR;
1027
1048
        break;
 
1049
 
1028
1050
    case 'e':
1029
1051
        exit_zero = true;
1030
1052
        break;
 
1053
 
1031
1054
    case 'E':
1032
1055
        esf_flag ^= true;
1033
1056
        break;
 
1057
 
1034
1058
    case 'M':
1035
 
        bogolex_file = optarg;
 
1059
        bogolex_file = val;
1036
1060
        break;
 
1061
 
1037
1062
    case 'n':
1038
1063
        lastmode = 'n';
1039
 
        filelist_add(ham_files, optarg);
 
1064
        filelist_add(ham_files, val);
1040
1065
        break;
 
1066
 
1041
1067
    case 'q':
1042
1068
        quiet = true;
1043
1069
        break;
 
1070
 
1044
1071
    case 'r':
1045
 
        user_robx = atof(optarg);
 
1072
        user_robx = atof(val);
1046
1073
        break;
 
1074
 
1047
1075
    case 's':
1048
1076
        lastmode = 's';
1049
 
        filelist_add(spam_files, optarg);
 
1077
        filelist_add(spam_files, val);
1050
1078
        break;
 
1079
 
1051
1080
#ifdef  TEST
1052
1081
    case 't':
1053
1082
        test += 1;
1054
1083
        break;
1055
1084
#endif
1056
1085
    case 'T':
1057
 
        coerced_target = atoi(optarg);
 
1086
        coerced_target = atoi(val);
1058
1087
        break;
 
1088
 
1059
1089
    case 'v':
1060
1090
        verbose += 1;
1061
1091
        break;
 
1092
 
1062
1093
    case 'V':
1063
1094
        print_version();
1064
1095
        exit(EX_OK);
 
1096
 
1065
1097
    case 'x':
1066
 
        if (strcmp(optarg, "MakeCheck") == 0)
 
1098
        if (strcmp(val, "MakeCheck") == 0)
1067
1099
            fMakeCheck = true;
1068
1100
        else
1069
 
            set_debug_mask( optarg );
 
1101
            set_debug_mask(val);
1070
1102
        break;
1071
1103
 
1072
1104
    case O_MAX_TOKEN_LEN:
1073
 
        max_token_len = atoi(optarg);
 
1105
        max_token_len = atoi(val);
1074
1106
        break;
1075
1107
 
1076
1108
    case O_MIN_TOKEN_LEN:
1077
 
        min_token_len = atoi(optarg);
 
1109
        min_token_len = atoi(val);
1078
1110
        break;
1079
1111
 
1080
1112
    case O_MAX_MULTI_TOKEN_LEN:
1081
 
        max_multi_token_len=atoi(optarg);
 
1113
        max_multi_token_len=atoi(val);
1082
1114
        break;
1083
1115
 
1084
1116
    case O_MULTI_TOKEN_COUNT:
1085
 
        multi_token_count=atoi(optarg);
 
1117
        multi_token_count=atoi(val);
 
1118
        break;
 
1119
 
 
1120
    case O_BLOCK_ON_SUBNETS:
 
1121
        block_on_subnets = get_bool(name, val);
 
1122
        break;
 
1123
 
 
1124
    case O_REPLACE_NONASCII_CHARACTERS:
 
1125
        replace_nonascii_characters = get_bool(name, val);
1086
1126
        break;
1087
1127
 
1088
1128
    default:
1089
1129
        help();
1090
1130
        exit(EX_ERROR);
1091
1131
    }
 
1132
 
 
1133
    return 0;
1092
1134
}
1093
1135
 
1094
1136
static double get_robx(void)