Lines Matching refs:m

385 apprentice_magic_strength(const struct magic *m)  in apprentice_magic_strength()  argument
390 switch (m->type) { in apprentice_magic_strength()
392 if (m->factor_op != FILE_FACTOR_OP_NONE) in apprentice_magic_strength()
415 val += m->vallen * MULT; in apprentice_magic_strength()
420 val += m->vallen * MULT / 2; in apprentice_magic_strength()
425 val += m->vallen * MAX(MULT / m->vallen, 1); in apprentice_magic_strength()
459 (void)fprintf(stderr, "Bad type %d\n", m->type); in apprentice_magic_strength()
463 switch (m->reln) { in apprentice_magic_strength()
484 (void)fprintf(stderr, "Bad relation %c\n", m->reln); in apprentice_magic_strength()
491 switch (m->factor_op) { in apprentice_magic_strength()
495 val += m->factor; in apprentice_magic_strength()
498 val -= m->factor; in apprentice_magic_strength()
501 val *= m->factor; in apprentice_magic_strength()
504 val /= m->factor; in apprentice_magic_strength()
515 if (m->desc[0] == '\0') in apprentice_magic_strength()
548 struct magic *m = &ml->magic[magindex]; in apprentice_list() local
549 if ((m->flag & mode) != mode) { in apprentice_list()
568 apprentice_magic_strength(m), in apprentice_list()
576 set_test_type(struct magic *mstart, struct magic *m) in set_test_type() argument
578 switch (m->type) { in set_test_type()
634 if (file_looks_utf8(m->value.us, (size_t)m->vallen, NULL, in set_test_type()
913 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) argument
915 if (!(m->flag & UNSIGNED)) {
916 switch(m->type) {
973 m->type);
981 string_modifier_check(struct magic_set *ms, struct magic *m) argument
986 if (m->type != FILE_PSTRING && (m->str_flags & PSTRING_LEN) != 0) {
991 switch (m->type) {
994 if (m->str_flags != 0) {
1002 if ((m->str_flags & REGEX_OFFSET_START) != 0) {
1010 if (m->str_range == 0) {
1014 m->str_range = STRING_DEFAULT_RANGE;
1019 if ((m->str_flags & STRING_COMPACT_WHITESPACE) != 0) {
1024 if ((m->str_flags & STRING_COMPACT_OPTIONAL_WHITESPACE) != 0) {
1032 m->type);
1146 struct magic *m; local
1181 me->mp = m = nm;
1184 m = &me->mp[me->cont_count++];
1185 (void)memset(m, 0, sizeof(*m));
1186 m->cont_level = cont_level;
1198 m = safe_emalloc(sizeof(*m), ALLOC_CHUNK, 0);
1199 me->mp = m;
1202 m = me->mp;
1203 (void)memset(m, 0, sizeof(*m));
1204 m->factor_op = FILE_FACTOR_OP_NONE;
1205 m->cont_level = 0;
1208 m->lineno = CAST(uint32_t, lineno);
1212 m->flag |= OFFADD;
1216 m->flag |= INDIR;
1217 if (m->flag & OFFADD)
1218 m->flag = (m->flag & ~OFFADD) | INDIROFFADD;
1222 m->flag |= OFFADD;
1226 if (m->cont_level == 0 && (m->flag & (OFFADD | INDIROFFADD)))
1231 m->offset = (uint32_t)strtoul(l, &t, 0);
1237 if (m->flag & INDIR) {
1238 m->in_type = FILE_LONG;
1239 m->in_offset = 0;
1247 m->in_type = FILE_LELONG;
1250 m->in_type = FILE_BELONG;
1253 m->in_type = FILE_MELONG;
1257 m->in_type = FILE_LESHORT;
1261 m->in_type = FILE_BESHORT;
1267 m->in_type = FILE_BYTE;
1272 m->in_type = FILE_LEDOUBLE;
1277 m->in_type = FILE_BEDOUBLE;
1280 m->in_type = FILE_LEID3;
1283 m->in_type = FILE_BEID3;
1295 m->in_op = 0;
1297 m->in_op |= FILE_OPINVERSE;
1301 m->in_op |= op;
1305 m->in_op |= FILE_OPINDIRECT;
1309 m->in_offset = (int32_t)strtol(l, &t, 0);
1317 ((m->in_op & FILE_OPINDIRECT) && *l++ != ')'))
1325 m->cond = get_cond(l, &l);
1326 if (check_cond(ms, m->cond, cont_level) == -1)
1334 m->flag |= UNSIGNED;
1337 m->type = get_type(l, &l);
1338 if (m->type == FILE_INVALID) {
1351 m->mask_op = 0;
1353 if (!IS_LIBMAGIC_STRING(m->type))
1354 m->mask_op |= FILE_OPINVERSE;
1359 m->str_range = 0;
1360 m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0;
1362 if (!IS_LIBMAGIC_STRING(m->type)) {
1365 m->mask_op |= op;
1368 m->num_mask = file_signextend(ms, m, val);
1384 m->str_range = CAST(uint32_t,
1386 if (m->str_range == 0)
1392 m->str_flags |=
1396 m->str_flags |=
1400 m->str_flags |= STRING_IGNORE_LOWERCASE;
1403 m->str_flags |= STRING_IGNORE_UPPERCASE;
1406 m->str_flags |= REGEX_OFFSET_START;
1409 m->str_flags |= STRING_BINTEST;
1412 m->str_flags |= STRING_TEXTTEST;
1415 if (m->type != FILE_PSTRING)
1417 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_1_LE;
1420 if (m->type != FILE_PSTRING)
1422 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_BE;
1425 if (m->type != FILE_PSTRING)
1427 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_LE;
1430 if (m->type != FILE_PSTRING)
1432 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_BE;
1435 if (m->type != FILE_PSTRING)
1437 m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_LE;
1440 if (m->type != FILE_PSTRING)
1442 m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF;
1457 if (string_modifier_check(ms, m) == -1)
1475 m->reln = *l;
1480 m->reln);
1490 m->reln = *l;
1498 m->reln = *l;
1502 m->reln = '='; /* the default relation */
1505 m->reln = *l;
1513 if (m->reln != 'x' && getvalue(ms, m, &l, action))
1528 m->flag |= NOSPACE;
1532 m->flag |= NOSPACE;
1534 for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); )
1536 if (i == sizeof(m->desc)) {
1537 m->desc[sizeof(m->desc) - 1] = '\0';
1539 file_magwarn(ms, "description `%s' truncated", m->desc);
1547 if (check_format(ms, m) == -1)
1550 m->mimetype[0] = '\0'; /* initialise MIME type to none */
1551 if (m->cont_level == 0)
1566 struct magic *m = &me->mp[0]; local
1568 if (m->factor_op != FILE_FACTOR_OP_NONE) {
1571 m->factor_op, m->factor);
1581 m->factor_op = *l++;
1597 m->factor = (uint8_t)factor;
1598 if (m->factor == 0 && m->factor_op == FILE_FACTOR_OP_DIV) {
1600 m->factor_op, m->factor);
1605 m->factor_op = FILE_FACTOR_OP_NONE;
1606 m->factor = 0;
1619 struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1]; local
1621 if (m->apple[0] != '\0') {
1623 "`%.8s', new type `%s'", m->mimetype, l);
1630 i < sizeof(m->apple); m->apple[i++] = *l++)
1632 if (i == sizeof(m->apple) && *l) {
1654 struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1]; local
1656 if (m->mimetype[0] != '\0') {
1658 " new type `%s'", m->mimetype, l);
1665 i < sizeof(m->mimetype); m->mimetype[i++] = *l++)
1667 if (i == sizeof(m->mimetype)) {
1668 m->mimetype[sizeof(m->mimetype) - 1] = '\0';
1671 SIZE_T_FORMAT "u", m->mimetype, i);
1673 m->mimetype[i] = '\0';
1810 check_format(struct magic_set *ms, struct magic *m) argument
1814 for (ptr = m->desc; *ptr; ptr++)
1824 if (m->type >= file_nformats) {
1829 if (file_formats[m->type] == FILE_FMT_NONE) {
1831 "`%s'", m->desc, file_names[m->type]);
1836 if (check_format_type(ptr, file_formats[m->type]) == -1) {
1843 file_names[m->type], m->desc);
1852 file_names[m->type], m->desc);
1865 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) argument
1867 switch (m->type) {
1874 *p = getstr(ms, m, *p, action == FILE_COMPILE);
1878 m->value.s);
1885 if (m->reln != 'x') {
1888 m->value.f = strtof(*p, &ep);
1890 m->value.f = (float)strtod(*p, &ep);
1898 if (m->reln != 'x') {
1900 m->value.d = strtod(*p, &ep);
1905 if (m->reln != 'x') {
1907 m->value.q = file_signextend(ms, m,
1923 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) argument
1926 char *p = m->value.s;
1927 size_t plen = sizeof(m->value.s);
1961 && (m->type != FILE_REGEX ||
2071 m->vallen = CAST(unsigned char, (p - origp));
2072 if (m->type == FILE_PSTRING)
2073 m->vallen += (unsigned char)file_pstring_length_size(m);
2503 bs1(struct magic *m) argument
2505 m->cont_level = swap2(m->cont_level);
2506 m->offset = swap4((uint32_t)m->offset);
2507 m->in_offset = swap4((uint32_t)m->in_offset);
2508 m->lineno = swap4((uint32_t)m->lineno);
2509 if (IS_LIBMAGIC_STRING(m->type)) {
2510 m->str_range = swap4(m->str_range);
2511 m->str_flags = swap4(m->str_flags);
2514 m->value.q = swap8(m->value.q);
2515 m->num_mask = swap8(m->num_mask);
2520 file_pstring_length_size(const struct magic *m) argument
2522 switch (m->str_flags & PSTRING_LEN) {
2537 file_pstring_get_length(const struct magic *m, const char *s) argument
2541 switch (m->str_flags & PSTRING_LEN) {
2561 if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
2562 len -= file_pstring_length_size(m);