version 1.17, 2015/08/11 23:17:17 |
version 1.18, 2015/10/05 20:05:52 |
|
|
if (ml->type == MAGIC_TYPE_NONE) |
if (ml->type == MAGIC_TYPE_NONE) |
return (0); |
return (0); |
|
|
if (ml->test_not || ml->test_operator == 'x') |
if (ml->test_not || ml->test_operator == 'x') { |
return (1); |
n = 1; |
|
goto skip; |
|
} |
|
|
n = 2 * MAGIC_STRENGTH_MULTIPLIER; |
n = 2 * MAGIC_STRENGTH_MULTIPLIER; |
switch (ml->type) { |
switch (ml->type) { |
|
|
n -= MAGIC_STRENGTH_MULTIPLIER; |
n -= MAGIC_STRENGTH_MULTIPLIER; |
break; |
break; |
} |
} |
|
|
|
skip: |
|
switch (ml->strength_operator) { |
|
case '+': |
|
n += ml->strength_value; |
|
break; |
|
case '-': |
|
n -= ml->strength_value; |
|
break; |
|
case '*': |
|
n *= ml->strength_value; |
|
break; |
|
case '/': |
|
n /= ml->strength_value; |
|
break; |
|
} |
return (n <= 0 ? 1 : n); |
return (n <= 0 ? 1 : n); |
} |
} |
|
|
|
|
RB_GENERATE(magic_tree, magic_line, node, magic_compare); |
RB_GENERATE(magic_tree, magic_line, node, magic_compare); |
|
|
static void |
static void |
|
magic_adjust_strength(struct magic *m, u_int at, struct magic_line *ml, |
|
char *line) |
|
{ |
|
char *cp, *s; |
|
int64_t value; |
|
|
|
cp = line + (sizeof "!:strength") - 1; |
|
while (isspace((u_char)*cp)) |
|
cp++; |
|
s = cp; |
|
|
|
cp = strchr(s, '#'); |
|
if (cp != NULL) |
|
*cp = '\0'; |
|
cp = s; |
|
|
|
if (strchr("+-*/", *s) == NULL) { |
|
magic_warnm(m, at, "invalid strength operator: %s", s); |
|
return; |
|
} |
|
ml->strength_operator = *cp++; |
|
|
|
while (isspace((u_char)*cp)) |
|
cp++; |
|
cp = magic_strtoll(cp, &value); |
|
while (cp != NULL && isspace((u_char)*cp)) |
|
cp++; |
|
if (cp == NULL || *cp != '\0' || value < 0 || value > 255) { |
|
magic_warnm(m, at, "invalid strength value: %s", s); |
|
return; |
|
} |
|
ml->strength_value = value; |
|
} |
|
|
|
static void |
magic_set_mimetype(struct magic *m, u_int at, struct magic_line *ml, char *line) |
magic_set_mimetype(struct magic *m, u_int at, struct magic_line *ml, char *line) |
{ |
{ |
char *mimetype, *cp; |
char *mimetype, *cp; |
|
|
|
|
if (strncmp (line, "!:mime", 6) == 0) { |
if (strncmp (line, "!:mime", 6) == 0) { |
magic_set_mimetype(m, at, ml, line); |
magic_set_mimetype(m, at, ml, line); |
|
continue; |
|
} |
|
if (strncmp (line, "!:strength", 10) == 0) { |
|
magic_adjust_strength(m, at, ml, line); |
continue; |
continue; |
} |
} |
if (strncmp (line, "!:", 2) == 0) { |
if (strncmp (line, "!:", 2) == 0) { |