summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-12-19 22:49:04 -0500
committerTavian Barnes <tavianator@tavianator.com>2018-12-19 22:49:04 -0500
commit201b3345f6880d2c8400259b1b0cedec4f885460 (patch)
tree0469f99c0aa096373502cd069cc35163e1370c67 /parse.c
parent2342fce556e158d2dd5bbdc4b4b5eff8b79b9feb (diff)
downloadbfs-201b3345f6880d2c8400259b1b0cedec4f885460.tar.xz
parse: Fix probabilities when -types are duplicated
-type f,f does not have more than a 100% probability of success.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/parse.c b/parse.c
index 80660fd..54d1a88 100644
--- a/parse.c
+++ b/parse.c
@@ -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;