diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2018-12-19 22:49:04 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2018-12-19 22:49:04 -0500 |
commit | 201b3345f6880d2c8400259b1b0cedec4f885460 (patch) | |
tree | 0469f99c0aa096373502cd069cc35163e1370c67 | |
parent | 2342fce556e158d2dd5bbdc4b4b5eff8b79b9feb (diff) | |
download | bfs-201b3345f6880d2c8400259b1b0cedec4f885460.tar.xz |
parse: Fix probabilities when -types are duplicated
-type f,f does not have more than a 100% probability of success.
-rw-r--r-- | parse.c | 40 |
1 files changed, 24 insertions, 16 deletions
@@ -2174,38 +2174,41 @@ static struct expr *parse_type(struct parser_state *state, int x, int arg2) { const char *c = expr->sdata; while (true) { + enum bftw_typeflag type; + double type_prob; + switch (*c) { case 'b': - types |= BFTW_BLK; - probability += 0.00000721183; + type = BFTW_BLK; + type_prob = 0.00000721183; break; case 'c': - types |= BFTW_CHR; - probability += 0.0000499855; + type = BFTW_CHR; + type_prob = 0.0000499855; break; case 'd': - types |= BFTW_DIR; - probability += 0.114475; + type = BFTW_DIR; + type_prob = 0.114475; break; case 'D': - types |= BFTW_DOOR; - probability += 0.000001; + type = BFTW_DOOR; + type_prob = 0.000001; break; case 'p': - types |= BFTW_FIFO; - probability += 0.00000248684; + type = BFTW_FIFO; + type_prob = 0.00000248684; break; case 'f': - types |= BFTW_REG; - probability += 0.859772; + type = BFTW_REG; + type_prob = 0.859772; break; case 'l': - types |= BFTW_LNK; - probability += 0.0256816; + type = BFTW_LNK; + type_prob = 0.0256816; break; case 's': - types |= BFTW_SOCK; - probability += 0.0000116881; + type = BFTW_SOCK; + type_prob = 0.0000116881; break; case '\0': @@ -2221,6 +2224,11 @@ static struct expr *parse_type(struct parser_state *state, int x, int arg2) { goto fail; } + if (!(types & type)) { + types |= type; + probability += type_prob; + } + ++c; if (*c == '\0') { break; |