Lines Matching refs:m

633 apprentice_magic_strength(const struct magic *m)  in apprentice_magic_strength()  argument
638 switch (m->type) { in apprentice_magic_strength()
640 if (m->factor_op != FILE_FACTOR_OP_NONE) in apprentice_magic_strength()
663 val += m->vallen * MULT; in apprentice_magic_strength()
668 val += m->vallen * MULT / 2; in apprentice_magic_strength()
673 val += m->vallen * MAX(MULT / m->vallen, 1); in apprentice_magic_strength()
715 (void)fprintf(stderr, "Bad type %d\n", m->type); in apprentice_magic_strength()
719 switch (m->reln) { in apprentice_magic_strength()
740 (void)fprintf(stderr, "Bad relation %c\n", m->reln); in apprentice_magic_strength()
747 switch (m->factor_op) { in apprentice_magic_strength()
751 val += m->factor; in apprentice_magic_strength()
754 val -= m->factor; in apprentice_magic_strength()
757 val *= m->factor; in apprentice_magic_strength()
760 val /= m->factor; in apprentice_magic_strength()
770 if (m->desc[0] == '\0') in apprentice_magic_strength()
803 struct magic *m = &ml->magic[magindex]; in apprentice_list() local
804 if ((m->flag & mode) != mode) { in apprentice_list()
823 apprentice_magic_strength(m), in apprentice_list()
831 set_test_type(struct magic *mstart, struct magic *m) in set_test_type() argument
833 switch (m->type) { in set_test_type()
892 if (file_looks_utf8(m->value.us, (size_t)m->vallen, NULL, in set_test_type()
1262 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1264 if (!(m->flag & UNSIGNED)) { in file_signextend()
1265 switch(m->type) { in file_signextend()
1327 m->type); in file_signextend()
1335 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1340 if (m->type != FILE_PSTRING && (m->str_flags & PSTRING_LEN) != 0) { in string_modifier_check()
1345 switch (m->type) { in string_modifier_check()
1348 if (m->str_flags != 0) { in string_modifier_check()
1356 if ((m->str_flags & REGEX_OFFSET_START) != 0) { in string_modifier_check()
1364 if (m->str_range == 0) { in string_modifier_check()
1368 m->str_range = STRING_DEFAULT_RANGE; in string_modifier_check()
1373 if ((m->str_flags & STRING_COMPACT_WHITESPACE) != 0) { in string_modifier_check()
1378 if ((m->str_flags & STRING_COMPACT_OPTIONAL_WHITESPACE) != 0) { in string_modifier_check()
1386 m->type); in string_modifier_check()
1499 struct magic *m; in parse() local
1530 m = &me->mp[me->cont_count - 1]; in parse()
1531 diff = (int32_t)cont_level - (int32_t)m->cont_level; in parse()
1535 m->cont_level); in parse()
1544 me->mp = m = nm; in parse()
1547 m = &me->mp[me->cont_count++]; in parse()
1548 (void)memset(m, 0, sizeof(*m)); in parse()
1549 m->cont_level = cont_level; in parse()
1551 static const size_t len = sizeof(*m) * ALLOC_CHUNK; in parse()
1554 if ((m = CAST(struct magic *, emalloc(len))) == NULL) { in parse()
1558 me->mp = m; in parse()
1560 (void)memset(m, 0, sizeof(*m)); in parse()
1561 m->factor_op = FILE_FACTOR_OP_NONE; in parse()
1562 m->cont_level = 0; in parse()
1565 m->lineno = CAST(uint32_t, lineno); in parse()
1569 m->flag |= OFFADD; in parse()
1573 m->flag |= INDIR; in parse()
1574 if (m->flag & OFFADD) in parse()
1575 m->flag = (m->flag & ~OFFADD) | INDIROFFADD; in parse()
1579 m->flag |= OFFADD; in parse()
1583 if (m->cont_level == 0 && (m->flag & (OFFADD | INDIROFFADD))) in parse()
1588 m->offset = (uint32_t)strtoul(l, &t, 0); in parse()
1594 if (m->flag & INDIR) { in parse()
1595 m->in_type = FILE_LONG; in parse()
1596 m->in_offset = 0; in parse()
1604 m->in_type = FILE_LELONG; in parse()
1607 m->in_type = FILE_BELONG; in parse()
1610 m->in_type = FILE_MELONG; in parse()
1614 m->in_type = FILE_LESHORT; in parse()
1618 m->in_type = FILE_BESHORT; in parse()
1624 m->in_type = FILE_BYTE; in parse()
1629 m->in_type = FILE_LEDOUBLE; in parse()
1634 m->in_type = FILE_BEDOUBLE; in parse()
1637 m->in_type = FILE_LEID3; in parse()
1640 m->in_type = FILE_BEID3; in parse()
1652 m->in_op = 0; in parse()
1654 m->in_op |= FILE_OPINVERSE; in parse()
1658 m->in_op |= op; in parse()
1662 m->in_op |= FILE_OPINDIRECT; in parse()
1666 m->in_offset = (int32_t)strtol(l, &t, 0); in parse()
1674 ((m->in_op & FILE_OPINDIRECT) && *l++ != ')')) in parse()
1682 m->cond = get_cond(l, &l); in parse()
1683 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
1698 m->type = get_type(type_tbl, l + 1, &l); in parse()
1699 if (m->type == FILE_INVALID) { in parse()
1704 m->type = get_standard_integer_type(l, &l); in parse()
1707 if (m->type != FILE_INVALID) in parse()
1708 m->flag |= UNSIGNED; in parse()
1716 m->type = get_type(type_tbl, l, &l); in parse()
1717 if (m->type == FILE_INVALID) { in parse()
1724 m->type = get_standard_integer_type(l, &l); in parse()
1726 m->type = FILE_STRING; in parse()
1732 if (m->type == FILE_INVALID) { in parse()
1734 m->type = get_type(special_tbl, l, &l); in parse()
1737 if (m->type == FILE_INVALID) { in parse()
1750 m->mask_op = 0; in parse()
1752 if (!IS_LIBMAGIC_STRING(m->type)) in parse()
1753 m->mask_op |= FILE_OPINVERSE; in parse()
1758 m->str_range = 0; in parse()
1759 m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0; in parse()
1761 if (!IS_LIBMAGIC_STRING(m->type)) { in parse()
1764 m->mask_op |= op; in parse()
1767 m->num_mask = file_signextend(ms, m, val); in parse()
1783 m->str_range = CAST(uint32_t, in parse()
1785 if (m->str_range == 0) in parse()
1791 m->str_flags |= in parse()
1795 m->str_flags |= in parse()
1799 m->str_flags |= STRING_IGNORE_LOWERCASE; in parse()
1802 m->str_flags |= STRING_IGNORE_UPPERCASE; in parse()
1805 m->str_flags |= REGEX_OFFSET_START; in parse()
1808 m->str_flags |= STRING_BINTEST; in parse()
1811 m->str_flags |= STRING_TEXTTEST; in parse()
1814 m->str_flags |= STRING_TRIM; in parse()
1817 if (m->type != FILE_PSTRING) in parse()
1819 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_1_LE; in parse()
1822 if (m->type != FILE_PSTRING) in parse()
1824 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_BE; in parse()
1827 if (m->type != FILE_PSTRING) in parse()
1829 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_LE; in parse()
1832 if (m->type != FILE_PSTRING) in parse()
1834 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_BE; in parse()
1837 if (m->type != FILE_PSTRING) in parse()
1839 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_LE; in parse()
1842 if (m->type != FILE_PSTRING) in parse()
1844 m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF; in parse()
1859 if (string_modifier_check(ms, m) == -1) in parse()
1877 m->reln = *l; in parse()
1882 m->reln); in parse()
1892 m->reln = *l; in parse()
1900 m->reln = *l; in parse()
1904 m->reln = '='; /* the default relation */ in parse()
1907 m->reln = *l; in parse()
1915 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
1930 m->flag |= NOSPACE; in parse()
1934 m->flag |= NOSPACE; in parse()
1936 for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); ) in parse()
1938 if (i == sizeof(m->desc)) { in parse()
1939 m->desc[sizeof(m->desc) - 1] = '\0'; in parse()
1941 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
1949 if (check_format(ms, m) == -1) in parse()
1952 m->mimetype[0] = '\0'; /* initialise MIME type to none */ in parse()
1966 struct magic *m = &me->mp[0]; in parse_strength() local
1968 if (m->factor_op != FILE_FACTOR_OP_NONE) { in parse_strength()
1971 m->factor_op, m->factor); in parse_strength()
1981 m->factor_op = *l++; in parse_strength()
1997 m->factor = (uint8_t)factor; in parse_strength()
1998 if (m->factor == 0 && m->factor_op == FILE_FACTOR_OP_DIV) { in parse_strength()
2000 m->factor_op, m->factor); in parse_strength()
2005 m->factor_op = FILE_FACTOR_OP_NONE; in parse_strength()
2006 m->factor = 0; in parse_strength()
2019 struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1]; in parse_apple() local
2021 if (m->apple[0] != '\0') { in parse_apple()
2023 "`%.8s', new type `%s'", m->mimetype, l); in parse_apple()
2030 i < sizeof(m->apple); m->apple[i++] = *l++) in parse_apple()
2032 if (i == sizeof(m->apple) && *l) { in parse_apple()
2054 struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1]; in parse_mime() local
2056 if (m->mimetype[0] != '\0') { in parse_mime()
2058 " new type `%s'", m->mimetype, l); in parse_mime()
2065 i < sizeof(m->mimetype); m->mimetype[i++] = *l++) in parse_mime()
2067 if (i == sizeof(m->mimetype)) { in parse_mime()
2068 m->mimetype[sizeof(m->mimetype) - 1] = '\0'; in parse_mime()
2071 SIZE_T_FORMAT "u", m->mimetype, i); in parse_mime()
2073 m->mimetype[i] = '\0'; in parse_mime()
2213 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2217 for (ptr = m->desc; *ptr; ptr++) in check_format()
2227 if (m->type >= file_nformats) { in check_format()
2232 if (file_formats[m->type] == FILE_FMT_NONE) { in check_format()
2234 "`%s'", m->desc, file_names[m->type]); in check_format()
2239 if (check_format_type(ptr, file_formats[m->type]) == -1) { in check_format()
2246 file_names[m->type], m->desc); in check_format()
2255 file_names[m->type], m->desc); in check_format()
2268 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2270 switch (m->type) { in getvalue()
2279 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2283 m->value.s); in getvalue()
2290 if (m->reln != 'x') { in getvalue()
2293 m->value.f = strtof(*p, &ep); in getvalue()
2295 m->value.f = (float)strtod(*p, &ep); in getvalue()
2303 if (m->reln != 'x') { in getvalue()
2305 m->value.d = strtod(*p, &ep); in getvalue()
2310 if (m->reln != 'x') { in getvalue()
2312 m->value.q = file_signextend(ms, m, in getvalue()
2328 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
2331 char *p = m->value.s; in getstr()
2332 size_t plen = sizeof(m->value.s); in getstr()
2366 && (m->type != FILE_REGEX || in getstr()
2476 m->vallen = CAST(unsigned char, (p - origp)); in getstr()
2477 if (m->type == FILE_PSTRING) in getstr()
2478 m->vallen += (unsigned char)file_pstring_length_size(m); in getstr()
2750 static const size_t m = sizeof(**map->magic); in apprentice_compile() local
2787 assert(nm + sizeof(ar) < m); in apprentice_compile()
2795 len = m * map->nmagic[i]; in apprentice_compile()
2938 bs1(struct magic *m) argument
2940 m->cont_level = swap2(m->cont_level);
2941 m->offset = swap4((uint32_t)m->offset);
2942 m->in_offset = swap4((uint32_t)m->in_offset);
2943 m->lineno = swap4((uint32_t)m->lineno);
2944 if (IS_LIBMAGIC_STRING(m->type)) {
2945 m->str_range = swap4(m->str_range);
2946 m->str_flags = swap4(m->str_flags);
2949 m->value.q = swap8(m->value.q);
2950 m->num_mask = swap8(m->num_mask);
2955 file_pstring_length_size(const struct magic *m) argument
2957 switch (m->str_flags & PSTRING_LEN) {
2972 file_pstring_get_length(const struct magic *m, const char *s) argument
2976 switch (m->str_flags & PSTRING_LEN) {
2996 if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
2997 len -= file_pstring_length_size(m);