file/src/apprentice.c File Reference

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

Go to the source code of this file.

Defines

#define EATAB
#define LOWCASE(l)
#define MAP_FAILED   (void *) -1
#define MAP_FILE   0
#define MAXPATHLEN   1024
#define IS_PLAINSTRING(t)
#define IS_STRING(t)
#define ALLOC_INCR   200
#define NBYTE   4
#define NSHORT   5
#define NLONG   4
#define NSTRING   6
#define NDATE   4
#define NBESHORT   7
#define NBELONG   6
#define NBEDATE   6
#define NLESHORT   7
#define NLELONG   6
#define NLEDATE   6
#define NPSTRING   7
#define NLDATE   5
#define NBELDATE   7
#define NLELDATE   7
#define NREGEX   5
#define NBESTRING16   10
#define NLESTRING16   10
#define NSEARCH   6
#define RET   1

Functions

static const char * rcsid (const char *p)
static int getvalue (struct magic_set *ms, struct magic *m, char **p)
static int hextoint (int)
static char * getstr (struct magic_set *ms, char *s, char *p, int plen, int *slen)
static int parse (struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, char *l, int action)
static void eatsize (char **p)
static int apprentice_1 (struct magic_set *ms, const char *fn, int action, struct mlist *mlist)
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 char * mkdbname (const char *fn, char *buf, size_t, int)
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 (struct magic_set *ms, struct magic *m)
void file_delmagic (struct magic *p, int type, size_t entries)
mlistfile_apprentice (struct magic_set *ms, const char *fn, int action)
uint32_t file_signextend (struct magic_set *ms, struct magic *m, uint32_t v)
void file_showstr (FILE *fp, const char *s, size_t len)

Variables

static size_t maxmagic = 0
static size_t magicsize = sizeof(struct magic)
static const uint32_t ar []
static const char ext [] = ".mgc"


Define Documentation

#define ALLOC_INCR   200

Referenced by parse().

#define EATAB

Value:

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

Definition at line 51 of file apprentice.c.

Referenced by parse().

#define IS_PLAINSTRING (  ) 

Value:

((t) == FILE_STRING || (t) == FILE_PSTRING || \
    (t) == FILE_BESTRING16 || (t) == FILE_LESTRING16)

Definition at line 77 of file apprentice.c.

Referenced by parse().

#define IS_STRING (  ) 

Value:

(IS_PLAINSTRING(t) || (t) == FILE_REGEX || \
    (t) == FILE_SEARCH)

Definition at line 80 of file apprentice.c.

Referenced by bs1(), and parse().

#define LOWCASE (  ) 

Value:

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

Definition at line 53 of file apprentice.c.

Referenced by eatsize().

#define MAP_FAILED   (void *) -1

Definition at line 66 of file apprentice.c.

Referenced by apprentice_map().

#define MAP_FILE   0

Definition at line 70 of file apprentice.c.

Referenced by apprentice_map().

#define MAXPATHLEN   1024

Definition at line 74 of file apprentice.c.

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

#define NBEDATE   6

Referenced by parse().

#define NBELDATE   7

Referenced by parse().

#define NBELONG   6

Referenced by parse().

#define NBESHORT   7

Referenced by parse().

#define NBESTRING16   10

Referenced by parse().

#define NBYTE   4

Referenced by parse().

#define NDATE   4

Referenced by parse().

#define NLDATE   5

Referenced by parse().

#define NLEDATE   6

Referenced by parse().

#define NLELDATE   7

Referenced by parse().

#define NLELONG   6

Referenced by parse().

#define NLESHORT   7

Referenced by parse().

#define NLESTRING16   10

Referenced by parse().

#define NLONG   4

Referenced by parse().

#define NPSTRING   7

Referenced by parse().

#define NREGEX   5

Referenced by parse().

#define NSEARCH   6

Referenced by parse().

#define NSHORT   5

Referenced by parse().

#define NSTRING   6

Referenced by parse().

#define RET   1

Referenced by apprentice_map().


Function Documentation

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

Definition at line 168 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, 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 1175 of file apprentice.c.

References errno, file_error(), MAXPATHLEN, mkdbname(), 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 319 of file apprentice.c.

References errno, magic_set::file, FILE_CHECK, file_error(), file_oomem(), magic_set::line, MAXMAGIS, and parse().

Referenced by apprentice_1().

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

Definition at line 1079 of file apprentice.c.

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

Referenced by apprentice_1().

static void bs1 ( struct magic m  )  [static]

Definition at line 1274 of file apprentice.c.

References magic::cont_level, magic::in_offset, IS_STRING, magic::VALUETYPE::l, magic::mask, magic::offset, swap2(), swap4(), magic::type, and magic::value.

Referenced by byteswap().

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

Definition at line 1233 of file apprentice.c.

References bs1(), and magic.

Referenced by apprentice_map().

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

Definition at line 786 of file apprentice.c.

References magic::desc, FILE_FORMAT_NAME, FILE_FORMAT_STRING, file_magwarn(), and magic::type.

Referenced by parse().

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

Definition at line 1053 of file apprentice.c.

References LOWCASE.

Referenced by getvalue(), and parse().

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

Definition at line 254 of file apprentice.c.

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

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

Definition at line 231 of file apprentice.c.

Referenced by apprentice_1().

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

Definition at line 997 of file apprentice.c.

Referenced by file_mdump(), and mdebug().

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

Definition at line 374 of file apprentice.c.

References FILE_BEDATE, FILE_BELDATE, FILE_BELONG, FILE_BESHORT, FILE_BESTRING16, FILE_BYTE, FILE_DATE, FILE_LDATE, FILE_LEDATE, FILE_LELDATE, FILE_LELONG, FILE_LESHORT, FILE_LESTRING16, FILE_LONG, file_magwarn(), FILE_PSTRING, FILE_REGEX, FILE_SEARCH, FILE_SHORT, FILE_STRING, magic::flag, magic_set::flags, magic::type, and UNSIGNED.

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

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

Definition at line 879 of file apprentice.c.

References file_error(), and hextoint().

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

Definition at line 842 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::VALUETYPE::l, magic::reln, magic::VALUETYPE::s, strtoul, magic::type, magic::vallen, and magic::value.

Referenced by parse().

static int hextoint ( int   )  [static]

Definition at line 979 of file apprentice.c.

Referenced by getstr().

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

Definition at line 1217 of file apprentice.c.

References snprintf().

Referenced by apprentice_compile(), and apprentice_map().

static int parse ( struct magic_set ms,
struct magic **  magicp,
uint32_t *  nmagicp,
char *  l,
int  action 
) [static]

Definition at line 422 of file apprentice.c.

References ALLOC_INCR, CHAR_COMPACT_BLANK, CHAR_COMPACT_OPTIONAL_BLANK, CHAR_IGNORE_LOWERCASE, check_format(), magic::cont_level, magic::desc, EATAB, eatsize(), FILE_BEDATE, FILE_BELDATE, FILE_BELONG, FILE_BESHORT, FILE_BESTRING16, FILE_BYTE, FILE_CHECK, FILE_DATE, FILE_LDATE, FILE_LEDATE, FILE_LELDATE, FILE_LELONG, FILE_LESHORT, FILE_LESTRING16, FILE_LONG, file_magwarn(), file_mdump(), file_oomem(), FILE_OPADD, FILE_OPAND, FILE_OPDIVIDE, FILE_OPINDIRECT, FILE_OPINVERSE, FILE_OPMINUS, FILE_OPMODULO, FILE_OPMULTIPLY, FILE_OPOR, FILE_OPS, FILE_OPXOR, FILE_PSTRING, FILE_REGEX, FILE_SEARCH, FILE_SHORT, file_signextend(), FILE_STRING, magic::flag, magic_set::flags, getvalue(), magic::in_offset, magic::in_op, magic::in_type, INDIR, INDIROFFADD, IS_PLAINSTRING, IS_STRING, magic::mask, magic::mask_op, MAXDESC, NBEDATE, NBELDATE, NBELONG, NBESHORT, NBESTRING16, NBYTE, NDATE, NLDATE, NLEDATE, NLELDATE, NLELONG, NLESHORT, NLESTRING16, NLONG, magic::nospflag, NPSTRING, NREGEX, NSEARCH, NSHORT, NSTRING, OFFADD, magic::offset, magic::reln, STRING_COMPACT_BLANK, STRING_COMPACT_OPTIONAL_BLANK, STRING_IGNORE_LOWERCASE, strtoul, magic::type, and UNSIGNED.

Referenced by apprentice_file().

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

Definition at line 48 of file apprentice.c.

static uint16_t swap2 ( uint16_t  sv  )  [static]

Definition at line 1244 of file apprentice.c.

Referenced by bs1().

static uint32_t swap4 ( uint32_t  sv  )  [static]

Definition at line 1258 of file apprentice.c.

Referenced by apprentice_map(), and bs1().


Variable Documentation

const uint32_t ar[] [static]

Initial value:

 {
     0xF11E041C ,  2 
}

Definition at line 1168 of file apprentice.c.

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

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

Definition at line 1212 of file apprentice.c.

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

size_t magicsize = sizeof(struct magic) [static]

Definition at line 86 of file apprentice.c.

size_t maxmagic = 0 [static]

Definition at line 84 of file apprentice.c.


Generated on Fri Oct 12 08:44:55 2007 for rpm by  doxygen 1.5.2