Lines Matching defs:ms

118 private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
181 struct magic_set *ms;
194 if ((ms = magic_open(MAGIC_CHECK)) == NULL) {
198 ret = magic_compile(ms, argv[1]) == -1 ? 1 : 0;
200 (void)fprintf(stderr, "%s: %s\n", progname, magic_error(ms));
201 magic_close(ms);
430 apprentice_1(struct magic_set *ms, const char *fn, int action)
439 file_error(ms, 0, "magic element size %lu != %lu",
446 map = apprentice_load(ms, fn, action);
449 return apprentice_compile(ms, map, fn);
453 map = apprentice_map(ms, fn);
455 if (ms->flags & MAGIC_CHECK)
456 file_magwarn(ms, "using regular magic file `%s'", fn);
457 map = apprentice_load(ms, fn, action);
463 if (add_mlist(ms->mlist[i], map, i) == -1) {
464 file_oomem(ms, sizeof(*ml));
473 apprentice_list(ms->mlist[i], BINTEST);
475 apprentice_list(ms->mlist[i], TEXTTEST);
481 mlist_free(ms->mlist[i]);
482 ms->mlist[i] = NULL;
491 file_ms_free(struct magic_set *ms)
494 if (ms == NULL)
497 mlist_free(ms->mlist[i]);
498 free(ms->o.pbuf);
499 free(ms->o.buf);
500 free(ms->c.li);
501 free(ms);
507 struct magic_set *ms;
510 if ((ms = CAST(struct magic_set *, calloc((size_t)1,
514 if (magic_setflags(ms, flags) == -1) {
519 ms->o.buf = ms->o.pbuf = NULL;
520 len = (ms->c.len = 10) * sizeof(*ms->c.li);
522 if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL)
525 ms->event_flags = 0;
526 ms->error = -1;
528 ms->mlist[i] = NULL;
529 ms->file = "unknown";
530 ms->line = 0;
531 ms->indir_max = FILE_INDIR_MAX;
532 ms->name_max = FILE_NAME_MAX;
533 ms->elf_shnum_max = FILE_ELF_SHNUM_MAX;
534 ms->elf_phnum_max = FILE_ELF_PHNUM_MAX;
535 ms->elf_notes_max = FILE_ELF_NOTES_MAX;
536 ms->regex_max = FILE_REGEX_MAX;
537 ms->bytes_max = FILE_BYTES_MAX;
538 return ms;
540 free(ms);
607 buffer_apprentice(struct magic_set *ms, struct magic **bufs,
617 if (ms->mlist[0] != NULL)
618 file_reset(ms);
623 mlist_free(ms->mlist[i]);
624 if ((ms->mlist[i] = mlist_alloc()) == NULL) {
625 file_oomem(ms, sizeof(*ms->mlist[i]));
631 map = apprentice_buf(ms, bufs[i], sizes[i]);
636 if (add_mlist(ms->mlist[j], map, j) == -1) {
637 file_oomem(ms, sizeof(*ml));
646 mlist_free(ms->mlist[i]);
647 ms->mlist[i] = NULL;
655 file_apprentice(struct magic_set *ms, const char *fn, int action)
661 if (ms->mlist[0] != NULL)
662 file_reset(ms);
670 file_oomem(ms, strlen(fn));
675 mlist_free(ms->mlist[i]);
676 if ((ms->mlist[i] = mlist_alloc()) == NULL) {
677 file_oomem(ms, sizeof(*ms->mlist[i]));
679 mlist_free(ms->mlist[i]);
680 ms->mlist[i] = NULL;
694 file_err = apprentice_1(ms, fn, action);
703 mlist_free(ms->mlist[i]);
704 ms->mlist[i] = NULL;
706 file_error(ms, 0, "could not find any valid magic files!");
718 mlist_free(ms->mlist[i]);
719 ms->mlist[i] = NULL;
730 file_error(ms, 0, "Invalid action %d", action);
1074 addentry(struct magic_set *ms, struct magic_entry *me,
1085 file_oomem(ms, sizeof(*mp) * mset[i].max);
1101 load_1(struct magic_set *ms, int action, const char *fn, int *errs,
1109 FILE *f = fopen(ms->file = fn, "r");
1112 file_error(ms, errno, "cannot read magic file `%s'",
1120 for (ms->line = 1; (len = getline(&line, &llen, f)) != -1;
1121 ms->line++) {
1143 file_error(ms, 0,
1149 file_error(ms, 0,
1155 if ((*bang[i].fun)(ms, &me,
1165 switch (parse(ms, &me, line, lineno, action)) {
1169 (void)addentry(ms, &me, mset);
1178 (void)addentry(ms, &me, mset);
1195 set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
1206 if ((ms->flags & MAGIC_DEBUG) == 0)
1228 set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme)
1239 ms->line = me[i].mp->lineno;
1240 file_magwarn(ms,
1249 coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
1260 file_oomem(ms, slen);
1286 apprentice_load(struct magic_set *ms, const char *fn, int action)
1299 ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */
1304 file_oomem(ms, sizeof(*map));
1322 file_oomem(ms,
1338 file_oomem(ms, mlen);
1350 load_1(ms, action, filearr[i], &errs, mset);
1355 load_1(ms, action, fn, &errs, mset);
1366 i = set_text_binary(ms, mset[j].me, mset[j].count, i);
1376 set_last_default(ms, mset[j].me, mset[j].count);
1379 if (coalesce_entries(ms, mset[j].me, mset[j].count,
1401 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
1466 if (ms->flags & MAGIC_CHECK)
1467 file_magwarn(ms, "cannot happen: m->type=%d\n",
1476 string_modifier_check(struct magic_set *ms, struct magic *m)
1478 if ((ms->flags & MAGIC_CHECK) == 0)
1483 file_magwarn(ms,
1491 file_magwarn(ms,
1499 file_magwarn(ms,
1507 file_magwarn(ms,
1516 file_magwarn(ms, "'/%c' not allowed on regex\n",
1521 file_magwarn(ms, "'/%c' not allowed on regex\n",
1527 file_magwarn(ms, "coding error: m->type=%d\n",
1587 check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
1590 last_cond = ms->c.li[cont_level].last_cond;
1595 if (ms->flags & MAGIC_CHECK)
1596 file_magwarn(ms, "syntax error: `if'");
1604 if (ms->flags & MAGIC_CHECK)
1605 file_magwarn(ms, "syntax error: `elif'");
1613 if (ms->flags & MAGIC_CHECK)
1614 file_magwarn(ms, "syntax error: `else'");
1625 ms->c.li[cont_level].last_cond = last_cond;
1631 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)
1641 if (ms->flags & MAGIC_CHECK)
1642 file_magwarn(ms, "indirect modifier `%c' "
1652 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp,
1663 m->num_mask = file_signextend(ms, m, val);
1669 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)
1681 if (have_range && (ms->flags & MAGIC_CHECK))
1682 file_magwarn(ms, "multiple ranges");
1686 file_magwarn(ms, "zero range");
1751 if (ms->flags & MAGIC_CHECK)
1752 file_magwarn(ms, "string modifier `%c' "
1760 if (string_modifier_check(ms, m) == -1)
1773 parse(struct magic_set *ms, struct magic_entry *me, const char *line,
1798 if (file_check_mem(ms, cont_level) == -1)
1804 file_magerror(ms, "No current entry for continuation");
1808 file_magerror(ms, "Continuations present with 0 count");
1814 file_magwarn(ms, "New continuation level %u is more "
1822 file_oomem(ms, sizeof(*nm) * cnt);
1836 file_oomem(ms, len);
1865 if (ms->flags & MAGIC_CHECK)
1866 file_magwarn(ms, "relative offset at level 0");
1873 if (ms->flags & MAGIC_CHECK)
1874 file_magwarn(ms, "offset `%s' invalid", l);
1928 if (ms->flags & MAGIC_CHECK)
1929 file_magwarn(ms,
1953 if (ms->flags & MAGIC_CHECK)
1954 file_magwarn(ms,
1962 if (ms->flags & MAGIC_CHECK)
1963 file_magwarn(ms,
1972 if (check_cond(ms, m->cond, cont_level) == -1)
2027 if (ms->flags & MAGIC_CHECK)
2028 file_magwarn(ms, "type `%s' invalid", l);
2039 else if (ms->flags & MAGIC_CHECK)
2040 file_magwarn(ms, "'~' invalid for string types");
2050 if (ms->flags & MAGIC_CHECK)
2051 file_magwarn(ms,
2058 r = parse_indirect_modifier(ms, m, &l);
2060 r = parse_string_modifier(ms, m, &l);
2064 parse_op_modifier(ms, m, &l, op);
2079 if (ms->flags & MAGIC_CHECK) {
2080 file_magwarn(ms, "%c= not supported",
2114 if (m->reln != 'x' && getvalue(ms, m, &l, action))
2119 * #define offsetcheck {if (offset > ms->bytes_max -1)
2139 if (ms->flags & MAGIC_CHECK)
2140 file_magwarn(ms, "description `%s' truncated", m->desc);
2147 if (ms->flags & MAGIC_CHECK) {
2148 if (check_format(ms, m) == -1)
2165 parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line)
2173 file_magwarn(ms,
2179 file_magwarn(ms, "%s: Strength setting is not supported in "
2193 file_magwarn(ms, "Unknown factor op `%c'", *l);
2199 file_magwarn(ms, "Too large factor `%lu'", factor);
2203 file_magwarn(ms, "Bad factor `%s'", l);
2208 file_magwarn(ms, "Cannot have factor op `%c' and factor %u",
2226 parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
2236 file_magwarn(ms, "Current entry already has a %s type "
2242 file_magwarn(ms, "Current entry does not yet have a "
2254 if (ms->flags & MAGIC_CHECK)
2255 file_magwarn(ms, "%s type `%s' truncated %"
2259 file_magwarn(ms, "%s type `%s' has bad char '%c'",
2268 file_magerror(ms, "Bad magic entry '%s'", line);
2277 parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line)
2281 return parse_extra(ms, me, line,
2290 parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line)
2294 return parse_extra(ms, me, line,
2304 parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line)
2308 return parse_extra(ms, me, line,
2507 check_format(struct magic_set *ms, struct magic *m)
2523 file_magwarn(ms, "Internal error inconsistency between "
2528 file_magwarn(ms, "No format string for `%s' with description "
2539 file_magwarn(ms, "Printf format is %s for type "
2547 file_magwarn(ms,
2563 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
2575 *p = getstr(ms, m, *p, action == FILE_COMPILE);
2577 if (ms->flags & MAGIC_CHECK)
2578 file_magwarn(ms, "cannot get string from `%s'",
2586 if (ms->flags & MAGIC_CHECK)
2587 file_regerror(&rx, rc, ms);
2623 m->value.q = file_signextend(ms, m,
2641 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
2655 file_error(ms, 0, "string too long: `%s'", origs);
2663 file_magwarn(ms, "incomplete escape");
2669 file_magwarn(ms,
2683 file_magwarn(ms, "no "
2688 file_magwarn(ms,
2904 apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)
2909 file_oomem(ms, sizeof(*map));
2915 if (check_buffer(ms, map, "buffer") != 0) {
2927 apprentice_map(struct magic_set *ms, const char *fn)
2936 file_oomem(ms, sizeof(*map));
2941 dbname = mkdbname(ms, fn, 0);
2949 file_error(ms, errno, "cannot stat `%s'", dbname);
2953 file_error(ms, 0, "file `%s' is too %s", dbname,
2963 file_error(ms, errno, "cannot map `%s'", dbname);
2969 file_oomem(ms, map->len);
2973 file_badread(ms);
2981 if (check_buffer(ms, map, dbname) != 0)
2985 file_error(ms, errno, "cannot mprotect `%s'", dbname);
3002 check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
3012 file_error(ms, 0, "bad magic in `%s'", dbname);
3023 file_error(ms, 0, "File %s supports only version %d magic "
3030 file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not "
3047 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u",
3061 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
3075 dbname = mkdbname(ms, fn, 1);
3082 file_error(ms, errno, "cannot open `%s'", dbname);
3091 file_error(ms, errno, "error writing `%s'", dbname);
3098 file_error(ms, errno, "error writing `%s'", dbname);
3117 mkdbname(struct magic_set *ms, const char *fn, int strip)
3141 if (ms->flags & MAGIC_MIME) {
3145 ms->flags &= MAGIC_MIME_TYPE;
3155 ms->flags &= MAGIC_MIME_TYPE;
3301 file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
3306 mlist = ms->mlist[1];