file/src/apprentice.c File Reference

#include "file.h"
#include "magic.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/param.h>

Include dependency graph for apprentice.c:

Go to the source code of this file.

Data Structures

struct  magic_entry
struct  type_tbl_s

Defines

#define EATAB
#define LOWCASE(l)
#define MAP_FAILED   (void *) -1
#define MAP_FILE   0
#define MAXPATHLEN   1024
#define XX(s)   s, (sizeof(s) - 1)
#define XX_NULL   NULL, 0
#define MULT   10
#define ALLOC_CHUNK   (size_t)10
#define ALLOC_INCR   (size_t)200
#define RET   1

Functions

static const char * rcsid (const char *p)
static int getvalue (struct magic_set *ms, struct magic *m, const char **p, int action)
static int hextoint (int c)
static const char * getstr (struct magic_set *ms, const char *s, char *p, int plen, int *slen, int action)
static int parse (struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, const char *line, size_t lineno, int action)
static void eatsize (const char **p)
static int apprentice_1 (struct magic_set *ms, const char *fn, int action, struct mlist *mlist)
static size_t apprentice_magic_strength (const struct magic *m)
static int apprentice_sort (const void *a, const void *b)
static int apprentice_file (struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, const char *fn, int action)
static void byteswap (struct magic *magic, uint32_t nmagic)
static void bs1 (struct magic *m)
static uint16_t swap2 (uint16_t sv)
static uint32_t swap4 (uint32_t sv)
static uint64_t swap8 (uint64_t sv)
static char * mkdbname (const char *fn, char *buf, size_t bufsiz, int strip)
static int apprentice_map (struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, const char *fn)
static int apprentice_compile (struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, const char *fn)
static int check_format_type (const char *ptr, int type)
static int check_format (struct magic_set *ms, struct magic *m)
static int get_type (const char *l, const char **t)
static void init_file_tables (void)
void file_delmagic (struct magic *p, int type, size_t entries)
mlistfile_apprentice (struct magic_set *ms, const char *fn, int action)
uint64_t file_signextend (struct magic_set *ms, struct magic *m, uint64_t v)
static int string_modifier_check (struct magic_set *ms, struct magic const *m)
static int get_op (char c)
static int get_cond (const char *l, const char **t)
static int check_cond (struct magic_set *ms, int cond, uint32_t cont_level)
void file_showstr (FILE *fp, const char *s, size_t len)

Variables

int file_formats [33]
const size_t file_nformats = 33
const char * file_names [33]
const size_t file_nnames = 33
static size_t maxmagic = 0
static size_t magicsize = sizeof(struct magic)
static struct type_tbl_s type_tbl []
static const uint32_t ar []
static const char ext [] = ".mgc"


Define Documentation

#define ALLOC_CHUNK   (size_t)10

Referenced by parse().

#define ALLOC_INCR   (size_t)200

Referenced by parse().

#define EATAB

Value:

{while (isascii((unsigned char) *l) && \
                      isspace((unsigned char) *l))  ++l;}

Definition at line 52 of file apprentice.c.

Referenced by parse().

#define LOWCASE (  ) 

Value:

(isupper((unsigned char) (l)) ? \
                        tolower((unsigned char) (l)) : (l))

Definition at line 54 of file apprentice.c.

Referenced by eatsize().

#define MAP_FAILED   (void *) -1

Definition at line 67 of file apprentice.c.

Referenced by apprentice_map().

#define MAP_FILE   0

Definition at line 71 of file apprentice.c.

Referenced by apprentice_map().

#define MAXPATHLEN   1024

Definition at line 75 of file apprentice.c.

Referenced by apprentice_compile(), apprentice_map(), Fts_open(), and unwrap().

#define MULT   10

Referenced by apprentice_magic_strength().

#define RET   1

Referenced by apprentice_map().

#define XX (  )     s, (sizeof(s) - 1)

#define XX_NULL   NULL, 0


Function Documentation

static int apprentice_1 ( struct magic_set ms,
const char *  fn,
int  action,
struct mlist mlist 
) [static]

Definition at line 275 of file apprentice.c.

References apprentice_compile(), apprentice_file(), apprentice_map(), FILE_COMPILE, file_delmagic(), file_error(), FILE_MAGICSIZE, file_magwarn(), file_oomem(), magic_set::flags, magic, MAGIC_CHECK, mlist::mapped, mlist::next, and mlist::prev.

Referenced by file_apprentice().

static int apprentice_compile ( struct magic_set ms,
struct magic **  magicp,
uint32_t *  nmagicp,
const char *  fn 
) [static]

Definition at line 1773 of file apprentice.c.

References errno, file_error(), MAXPATHLEN, mkdbname(), O_BINARY, and SEEK_SET.

Referenced by apprentice_1().

static int apprentice_file ( struct magic_set ms,
struct magic **  magicp,
uint32_t *  nmagicp,
const char *  fn,
int  action 
) [static]

Definition at line 552 of file apprentice.c.

References apprentice_sort(), magic::cont_level, errno, magic_set::file, FILE_CHECK, FILE_DEFAULT, file_error(), file_magwarn(), file_oomem(), magic_set::flags, magic_set::line, MAGIC_CHECK, MAXMAGIS, magic_entry::mp, and parse().

Referenced by apprentice_1().

static size_t apprentice_magic_strength ( const struct magic m  )  [static]

Definition at line 428 of file apprentice.c.

References FILE_BEDATE, FILE_BELDATE, FILE_BELONG, FILE_BEQDATE, FILE_BEQLDATE, FILE_BEQUAD, FILE_BESHORT, FILE_BESTRING16, FILE_BYTE, FILE_DATE, FILE_DEFAULT, FILE_LDATE, FILE_LEDATE, FILE_LELDATE, FILE_LELONG, FILE_LEQDATE, FILE_LEQLDATE, FILE_LEQUAD, FILE_LESHORT, FILE_LESTRING16, FILE_LONG, FILE_MEDATE, FILE_MELDATE, FILE_MELONG, FILE_PSTRING, FILE_QDATE, FILE_QLDATE, FILE_QUAD, FILE_REGEX, FILE_SEARCH, FILE_SHORT, FILE_STRING, MULT, magic::reln, magic::type, and magic::vallen.

Referenced by apprentice_sort().

static int apprentice_map ( struct magic_set ms,
struct magic **  magicp,
uint32_t *  nmagicp,
const char *  fn 
) [static]

Definition at line 1677 of file apprentice.c.

References byteswap(), errno, file_badread(), file_error(), file_oomem(), MAGICNO, MAP_FAILED, MAP_FILE, MAXPATHLEN, mkdbname(), O_BINARY, RET, swap4(), and VERSIONNO.

Referenced by apprentice_1().

static int apprentice_sort ( const void *  a,
const void *  b 
) [static]

Definition at line 533 of file apprentice.c.

References apprentice_magic_strength(), and magic_entry::mp.

Referenced by apprentice_file().

static void bs1 ( struct magic m  )  [static]

Definition at line 1892 of file apprentice.c.

References magic::cont_level, magic::in_offset, IS_STRING, magic::lineno, magic::offset, magic::VALUETYPE::q, swap2(), swap4(), swap8(), magic::type, and magic::value.

Referenced by byteswap().

static void byteswap ( struct magic magic,
uint32_t  nmagic 
) [static]

Definition at line 1831 of file apprentice.c.

References bs1(), and magic.

Referenced by apprentice_map().

static int check_cond ( struct magic_set ms,
int  cond,
uint32_t  cont_level 
) [static]

Definition at line 826 of file apprentice.c.

References magic_set::c, COND_ELIF, COND_ELSE, COND_IF, COND_NONE, file_magwarn(), magic_set::flags, magic_set::cont::level_info::last_cond, magic_set::cont::li, and MAGIC_CHECK.

Referenced by parse().

static int check_format ( struct magic_set ms,
struct magic m 
) [static]

Definition at line 1337 of file apprentice.c.

References check_format_type(), magic::desc, file_error(), FILE_FMT_NONE, and magic::type.

Referenced by parse().

static int check_format_type ( const char *  ptr,
int  type 
) [static]

Definition at line 1234 of file apprentice.c.

References FILE_FMT_NUM, FILE_FMT_QUAD, and FILE_FMT_STR.

Referenced by check_format().

static void eatsize ( const char **  p  )  [static]

Definition at line 1651 of file apprentice.c.

References LOWCASE.

Referenced by getvalue(), and parse().

struct mlist* file_apprentice ( struct magic_set ms,
const char *  fn,
int  action 
)

Definition at line 359 of file apprentice.c.

References apprentice_1(), file_error(), file_oomem(), magic_set::flags, getenv(), init_file_tables(), MAGIC, MAGIC_MIME, mime, and PATHSEP.

Referenced by magic_check(), magic_compile(), and magic_load().

void file_delmagic ( struct magic p,
int  type,
size_t  entries 
)

Definition at line 336 of file apprentice.c.

Referenced by apprentice_1(), and free_mlist().

void file_showstr ( FILE *  fp,
const char *  s,
size_t  len 
)

Definition at line 1592 of file apprentice.c.

Referenced by file_mdump(), and mdebug().

uint64_t file_signextend ( struct magic_set ms,
struct magic m,
uint64_t  v 
)

Definition at line 663 of file apprentice.c.

References FILE_BEDATE, FILE_BELDATE, FILE_BELONG, FILE_BEQDATE, FILE_BEQLDATE, FILE_BEQUAD, FILE_BESHORT, FILE_BESTRING16, FILE_BYTE, FILE_DATE, FILE_DEFAULT, FILE_LDATE, FILE_LEDATE, FILE_LELDATE, FILE_LELONG, FILE_LEQDATE, FILE_LEQLDATE, FILE_LEQUAD, FILE_LESHORT, FILE_LESTRING16, FILE_LONG, file_magwarn(), FILE_MEDATE, FILE_MELDATE, FILE_MELONG, FILE_PSTRING, FILE_QDATE, FILE_QLDATE, FILE_QUAD, FILE_REGEX, FILE_SEARCH, FILE_SHORT, FILE_STRING, magic::flag, magic_set::flags, MAGIC_CHECK, magic::type, and UNSIGNED.

Referenced by getvalue(), magiccheck(), mprint(), and parse().

static int get_cond ( const char *  l,
const char **  t 
) [static]

Definition at line 797 of file apprentice.c.

References cond(), COND_ELIF, COND_ELSE, COND_IF, and COND_NONE.

Referenced by parse().

static int get_op ( char  c  )  [static]

Definition at line 770 of file apprentice.c.

References FILE_OPADD, FILE_OPAND, FILE_OPDIVIDE, FILE_OPMINUS, FILE_OPMODULO, FILE_OPMULTIPLY, FILE_OPOR, and FILE_OPXOR.

Referenced by parse().

static int get_type ( const char *  l,
const char **  t 
) [static]

Definition at line 235 of file apprentice.c.

References type_tbl_s::len, type_tbl_s::name, and type_tbl.

Referenced by parse().

static const char * getstr ( struct magic_set ms,
const char *  s,
char *  p,
int  plen,
int *  slen,
int  action 
) [static]

Definition at line 1431 of file apprentice.c.

References FILE_COMPILE, file_error(), file_magwarn(), and hextoint().

static int getvalue ( struct magic_set ms,
struct magic m,
const char **  p,
int  action 
) [static]

Definition at line 1392 of file apprentice.c.

References eatsize(), FILE_BESTRING16, FILE_LESTRING16, file_magwarn(), FILE_PSTRING, FILE_REGEX, FILE_SEARCH, file_signextend(), FILE_STRING, magic_set::flags, getstr, MAGIC_CHECK, magic::VALUETYPE::q, magic::reln, magic::VALUETYPE::s, magic::type, magic::vallen, and magic::value.

Referenced by parse().

static int hextoint ( int  c  )  [static]

Definition at line 1574 of file apprentice.c.

Referenced by getstr().

static void init_file_tables ( void   )  [static]

Definition at line 251 of file apprentice.c.

References FILE_NAMES_SIZE, type_tbl_s::format, type_tbl_s::name, type_tbl_s::type, and type_tbl.

Referenced by file_apprentice().

static char * mkdbname ( const char *  fn,
char *  buf,
size_t  bufsiz,
int  strip 
) [static]

Definition at line 1815 of file apprentice.c.

References snprintf().

Referenced by apprentice_compile(), and apprentice_map().

static int parse ( struct magic_set ms,
struct magic_entry **  mentryp,
uint32_t *  nmentryp,
const char *  line,
size_t  lineno,
int  action 
) [static]

Definition at line 875 of file apprentice.c.

References ALLOC_CHUNK, ALLOC_INCR, CHAR_COMPACT_BLANK, CHAR_COMPACT_OPTIONAL_BLANK, CHAR_IGNORE_LOWERCASE, CHAR_IGNORE_UPPERCASE, CHAR_REGEX_OFFSET_START, check_cond(), check_format(), magic::cond, magic_entry::cont_count, magic::cont_level, magic::desc, EATAB, eatsize(), FILE_BELONG, FILE_BESHORT, FILE_BYTE, FILE_CHECK, file_check_mem(), file_error(), FILE_INVALID, FILE_LELONG, FILE_LESHORT, FILE_LONG, file_magwarn(), file_mdump(), FILE_MELONG, file_oomem(), FILE_OPDIVIDE, FILE_OPINDIRECT, FILE_OPINVERSE, file_signextend(), magic::flag, get_cond(), get_op(), get_type(), getvalue(), magic::in_offset, magic::in_op, magic::in_type, INDIR, INDIROFFADD, IS_STRING, magic::lineno, MAGIC_CHECK, magic::mask_op, magic_entry::max_count, magic_entry::mp, magic::nospflag, OFFADD, magic::offset, REGEX_OFFSET_START, magic::reln, STRING_COMPACT_BLANK, STRING_COMPACT_OPTIONAL_BLANK, STRING_IGNORE_LOWERCASE, STRING_IGNORE_UPPERCASE, string_modifier_check(), strtoul, magic::type, and UNSIGNED.

Referenced by apprentice_file().

static const char* rcsid ( const char *  p  )  [static]

Definition at line 49 of file apprentice.c.

static int string_modifier_check ( struct magic_set ms,
struct magic const *  m 
) [static]

Definition at line 724 of file apprentice.c.

References CHAR_COMPACT_BLANK, CHAR_COMPACT_OPTIONAL_BLANK, CHAR_REGEX_OFFSET_START, FILE_BESTRING16, FILE_LESTRING16, file_magwarn(), FILE_PSTRING, FILE_REGEX, FILE_SEARCH, FILE_STRING, magic_set::flags, MAGIC_CHECK, REGEX_OFFSET_START, STRING_COMPACT_BLANK, STRING_COMPACT_OPTIONAL_BLANK, and magic::type.

Referenced by parse().

static uint16_t swap2 ( uint16_t  sv  )  [static]

Definition at line 1842 of file apprentice.c.

Referenced by bs1().

static uint32_t swap4 ( uint32_t  sv  )  [static]

Definition at line 1856 of file apprentice.c.

Referenced by apprentice_map(), and bs1().

static uint64_t swap8 ( uint64_t  sv  )  [static]

Definition at line 1872 of file apprentice.c.

Referenced by bs1().


Variable Documentation

const uint32_t ar[] [static]

Initial value:

 {
     0xF11E041C ,  4 
}

Definition at line 1766 of file apprentice.c.

Referenced by freeAttrRec(), luaD_callhook(), nullAttrRec(), and parseForAttr().

const char ext[] = ".mgc" [static]

Definition at line 1810 of file apprentice.c.

Referenced by findTag(), hdr_subscript(), init_rpm(), rcsid(), rpmDisplayQueryTags(), rpmecFree(), and rpmecNew().

int file_formats[33]

Definition at line 85 of file apprentice.c.

const char* file_names[33]

Definition at line 89 of file apprentice.c.

Referenced by file_mdump().

const size_t file_nformats = 33

Definition at line 87 of file apprentice.c.

const size_t file_nnames = 33

Definition at line 91 of file apprentice.c.

Referenced by file_mdump().

size_t magicsize = sizeof(struct magic) [static]

Definition at line 96 of file apprentice.c.

size_t maxmagic = 0 [static]

Definition at line 94 of file apprentice.c.

struct type_tbl_s type_tbl[] [static]

Referenced by get_type(), and init_file_tables().


Generated on Fri Aug 31 10:38:37 2007 for rpm by  doxygen 1.5.1