Lines Matching refs:ms

109 private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
386 apprentice_1(struct magic_set *ms, const char *fn, int action) in apprentice_1() argument
393 file_error(ms, 0, "magic element size %lu != %lu", in apprentice_1()
400 map = apprentice_load(ms, fn, action); in apprentice_1()
403 return apprentice_compile(ms, map, fn); in apprentice_1()
406 map = apprentice_map(ms, fn); in apprentice_1()
409 if (ms->flags & MAGIC_CHECK) in apprentice_1()
410 file_magwarn(ms, "using regular magic file `%s'", fn); in apprentice_1()
411 map = apprentice_load(ms, fn, action); in apprentice_1()
418 if (add_mlist(ms->mlist[i], map, i) == -1) { in apprentice_1()
419 file_oomem(ms, sizeof(*ml)); in apprentice_1()
428 apprentice_list(ms->mlist[i], BINTEST); in apprentice_1()
430 apprentice_list(ms->mlist[i], TEXTTEST); in apprentice_1()
438 file_ms_free(struct magic_set *ms) in file_ms_free() argument
441 if (ms == NULL) in file_ms_free()
444 mlist_free(ms->mlist[i]); in file_ms_free()
445 if (ms->o.pbuf) { in file_ms_free()
446 efree(ms->o.pbuf); in file_ms_free()
448 if (ms->o.buf) { in file_ms_free()
449 efree(ms->o.buf); in file_ms_free()
451 if (ms->c.li) { in file_ms_free()
452 efree(ms->c.li); in file_ms_free()
454 efree(ms); in file_ms_free()
460 struct magic_set *ms; in file_ms_alloc() local
463 if ((ms = CAST(struct magic_set *, ecalloc((size_t)1, in file_ms_alloc()
467 if (magic_setflags(ms, flags) == -1) { in file_ms_alloc()
472 ms->o.buf = ms->o.pbuf = NULL; in file_ms_alloc()
473 len = (ms->c.len = 10) * sizeof(*ms->c.li); in file_ms_alloc()
475 if ((ms->c.li = CAST(struct level_info *, emalloc(len))) == NULL) in file_ms_alloc()
478 ms->event_flags = 0; in file_ms_alloc()
479 ms->error = -1; in file_ms_alloc()
481 ms->mlist[i] = NULL; in file_ms_alloc()
482 ms->file = "unknown"; in file_ms_alloc()
483 ms->line = 0; in file_ms_alloc()
484 return ms; in file_ms_alloc()
486 efree(ms); in file_ms_alloc()
541 file_apprentice(struct magic_set *ms, const char *fn, int action) in file_apprentice() argument
558 mlist_free(ms->mlist[i]); in file_apprentice()
559 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
560 file_oomem(ms, sizeof(*ms->mlist[i])); in file_apprentice()
564 return apprentice_1(ms, fn, action); in file_apprentice()
568 file_oomem(ms, strlen(fn)); in file_apprentice()
573 mlist_free(ms->mlist[i]); in file_apprentice()
574 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
575 file_oomem(ms, sizeof(*ms->mlist[i])); in file_apprentice()
579 mlist_free(ms->mlist[i]); in file_apprentice()
594 file_err = apprentice_1(ms, fn, action); in file_apprentice()
603 mlist_free(ms->mlist[i]); in file_apprentice()
604 ms->mlist[i] = NULL; in file_apprentice()
606 file_error(ms, 0, "could not find any valid magic files!"); in file_apprentice()
614 mlist_free(ms->mlist[i]); in file_apprentice()
615 ms->mlist[i] = NULL; in file_apprentice()
624 file_error(ms, 0, "Invalid action %d", action); in file_apprentice()
910 addentry(struct magic_set *ms, struct magic_entry *me, in addentry() argument
921 file_oomem(ms, sizeof(*mp) * maxmagic[i]); in addentry()
937 load_1(struct magic_set *ms, int action, const char *fn, int *errs, in load_1() argument
950 ms->file = fn; in load_1()
959 file_error(ms, errno, "cannot read magic file `%s'", in load_1()
967 …for (ms->line = 1; (line = php_stream_get_line(stream, buffer , BUFSIZ, &len)) != NULL; ms->line++… in load_1()
989 file_error(ms, 0, in load_1()
995 file_error(ms, 0, in load_1()
1001 if ((*bang[i].fun)(ms, &me, in load_1()
1011 switch (parse(ms, &me, line, lineno, action)) { in load_1()
1015 (void)addentry(ms, &me, mentry, mentrycount); in load_1()
1024 (void)addentry(ms, &me, mentry, mentrycount); in load_1()
1040 set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in set_text_binary() argument
1051 if ((ms->flags & MAGIC_DEBUG) == 0) in set_text_binary()
1073 set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme) in set_last_default() argument
1084 ms->line = me[i].mp->lineno; in set_last_default()
1085 file_magwarn(ms, in set_last_default()
1094 coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in coalesce_entries() argument
1105 file_oomem(ms, slen); in coalesce_entries()
1131 apprentice_load(struct magic_set *ms, const char *fn, int action) in apprentice_load() argument
1146 ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */ in apprentice_load()
1149 file_oomem(ms, sizeof(*map)); in apprentice_load()
1181 file_oomem(ms, in apprentice_load()
1196 file_oomem(ms, mlen); in apprentice_load()
1207 load_1(ms, action, filearr[i], &errs, mentry, in apprentice_load()
1213 load_1(ms, action, fn, &errs, mentry, mentrycount); in apprentice_load()
1224 i = set_text_binary(ms, mentry[j], mentrycount[j], i); in apprentice_load()
1233 set_last_default(ms, mentry[j], mentrycount[j]); in apprentice_load()
1236 if (coalesce_entries(ms, mentry[j], mentrycount[j], in apprentice_load()
1262 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1325 if (ms->flags & MAGIC_CHECK) in file_signextend()
1326 file_magwarn(ms, "cannot happen: m->type=%d\n", in file_signextend()
1335 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1337 if ((ms->flags & MAGIC_CHECK) == 0) in string_modifier_check()
1341 file_magwarn(ms, in string_modifier_check()
1349 file_magwarn(ms, in string_modifier_check()
1357 file_magwarn(ms, in string_modifier_check()
1365 file_magwarn(ms, in string_modifier_check()
1374 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1379 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1385 file_magwarn(ms, "coding error: m->type=%d\n", in string_modifier_check()
1445 check_cond(struct magic_set *ms, int cond, uint32_t cont_level) in check_cond() argument
1448 last_cond = ms->c.li[cont_level].last_cond; in check_cond()
1453 if (ms->flags & MAGIC_CHECK) in check_cond()
1454 file_magwarn(ms, "syntax error: `if'"); in check_cond()
1462 if (ms->flags & MAGIC_CHECK) in check_cond()
1463 file_magwarn(ms, "syntax error: `elif'"); in check_cond()
1471 if (ms->flags & MAGIC_CHECK) in check_cond()
1472 file_magwarn(ms, "syntax error: `else'"); in check_cond()
1483 ms->c.li[cont_level].last_cond = last_cond; in check_cond()
1492 parse(struct magic_set *ms, struct magic_entry *me, const char *line, in parse() argument
1517 if (file_check_mem(ms, cont_level) == -1) in parse()
1523 file_magerror(ms, "No current entry for continuation"); in parse()
1527 file_magerror(ms, "Continuations present with 0 count"); in parse()
1533 file_magwarn(ms, "New continuation level %u is more " in parse()
1541 file_oomem(ms, sizeof(*nm) * cnt); in parse()
1555 file_oomem(ms, len); in parse()
1584 if (ms->flags & MAGIC_CHECK) in parse()
1585 file_magwarn(ms, "relative offset at level 0"); in parse()
1590 if (ms->flags & MAGIC_CHECK) in parse()
1591 file_magwarn(ms, "offset `%s' invalid", l); in parse()
1643 if (ms->flags & MAGIC_CHECK) in parse()
1644 file_magwarn(ms, in parse()
1668 if (ms->flags & MAGIC_CHECK) in parse()
1669 file_magwarn(ms, in parse()
1675 if (ms->flags & MAGIC_CHECK) in parse()
1676 file_magwarn(ms, in parse()
1683 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
1738 if (ms->flags & MAGIC_CHECK) in parse()
1739 file_magwarn(ms, "type `%s' invalid", l); in parse()
1754 else if (ms->flags & MAGIC_CHECK) in parse()
1755 file_magwarn(ms, "'~' invalid for string types"); in parse()
1767 m->num_mask = file_signextend(ms, m, val); in parse()
1779 (ms->flags & MAGIC_CHECK)) in parse()
1780 file_magwarn(ms, in parse()
1786 file_magwarn(ms, in parse()
1848 if (ms->flags & MAGIC_CHECK) in parse()
1849 file_magwarn(ms, in parse()
1859 if (string_modifier_check(ms, m) == -1) in parse()
1863 if (ms->flags & MAGIC_CHECK) in parse()
1864 file_magwarn(ms, "invalid string op: %c", *t); in parse()
1880 if (ms->flags & MAGIC_CHECK) { in parse()
1881 file_magwarn(ms, "%c= not supported", in parse()
1915 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
1940 if (ms->flags & MAGIC_CHECK) in parse()
1941 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
1948 if (ms->flags & MAGIC_CHECK) { in parse()
1949 if (check_format(ms, m) == -1) in parse()
1961 parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_strength() argument
1969 file_magwarn(ms, in parse_strength()
1984 file_magwarn(ms, "Unknown factor op `%c'", *l); in parse_strength()
1990 file_magwarn(ms, "Too large factor `%lu'", factor); in parse_strength()
1994 file_magwarn(ms, "Bad factor `%s'", l); in parse_strength()
1999 file_magwarn(ms, "Cannot have factor op `%c' and factor %u", in parse_strength()
2015 parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_apple() argument
2022 file_magwarn(ms, "Current entry already has a APPLE type " in parse_apple()
2034 if (ms->flags & MAGIC_CHECK) in parse_apple()
2035 file_magwarn(ms, "APPLE type `%s' truncated %" in parse_apple()
2050 parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_mime() argument
2057 file_magwarn(ms, "Current entry already has a MIME type `%s'," in parse_mime()
2069 if (ms->flags & MAGIC_CHECK) in parse_mime()
2070 file_magwarn(ms, "MIME type `%s' truncated %" in parse_mime()
2213 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2228 file_magwarn(ms, "Internal error inconsistency between " in check_format()
2233 file_magwarn(ms, "No format string for `%s' with description " in check_format()
2244 file_magwarn(ms, "Printf format `%c' is not valid for type " in check_format()
2252 file_magwarn(ms, in check_format()
2268 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2279 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2281 if (ms->flags & MAGIC_CHECK) in getvalue()
2282 file_magwarn(ms, "cannot get string from `%s'", 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
2342 file_error(ms, 0, "string too long: `%s'", origs); in getstr()
2350 file_magwarn(ms, "incomplete escape"); in getstr()
2355 file_magwarn(ms, in getstr()
2369 file_magwarn(ms, "no " in getstr()
2374 file_magwarn(ms, in getstr()
2590 apprentice_map(struct magic_set *ms, const char *fn) in apprentice_map() argument
2605 file_oomem(ms, sizeof(*map)); in apprentice_map()
2624 dbname = mkdbname(ms, fn, 0); in apprentice_map()
2639 file_error(ms, errno, "cannot stat `%s'", dbname); in apprentice_map()
2644 file_error(ms, 0, "file `%s' is too small", dbname); in apprentice_map()
2650 file_oomem(ms, map->len); in apprentice_map()
2654 file_badread(ms); in apprentice_map()
2667 file_error(ms, 0, "bad magic in `%s'", dbname); in apprentice_map()
2678 file_error(ms, 0, "File %d.%d supports only version %d magic " in apprentice_map()
2696 file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu", in apprentice_map()
2714 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", in apprentice_map()
2747 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) in apprentice_compile() argument
2760 dbname = mkdbname(ms, fn, 0); in apprentice_compile()
2773 file_error(ms, errno, "cannot open `%s'", dbname); in apprentice_compile()
2778 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
2783 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
2790 file_error(ms, errno, "error seeking `%s'", dbname); in apprentice_compile()
2797 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
2817 mkdbname(struct magic_set *ms, const char *fn, int strip) argument
2842 if (ms->flags & MAGIC_MIME) {
2849 ms->flags &= MAGIC_MIME_TYPE;
2858 ms->flags &= MAGIC_MIME_TYPE;
3003 file_magicfind(struct magic_set *ms, const char *name, struct mlist *v) argument
3008 mlist = ms->mlist[1];