file/src/apprentice.c File Reference

#include "file.h"
#include "magic.h"
#include <stdlib.h>
#include <unistd.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

 FILE_RCSID ("@(#)$Id: apprentice.c,v 1.84 2005/03/25 18:03:18 christos Exp $") private size_t maxmagic=0
private int getvalue (struct magic_set *ms, struct magic *m, char **p)
private int hextoint (int)
private char * getstr (struct magic_set *ms, char *s, char *p, int plen, int *slen)
private int parse (struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, char *l, int action)
private void eatsize (char **p)
private int apprentice_1 (struct magic_set *ms, const char *fn, int action, struct mlist *mlist)
private int apprentice_file (struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, const char *fn, int action)
private void byteswap (struct magic *magic, uint32_t nmagic)
private void bs1 (struct magic *m)
private uint16_t swap2 (uint16_t sv)
private uint32_t swap4 (uint32_t sv)
private char * mkdbname (const char *fn, char *buf, size_t, int)
private int apprentice_map (struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, const char *fn)
private int apprentice_compile (struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, const char *fn)
private int check_format (struct magic_set *ms, struct magic *m)
protected void file_delmagic (struct magic *p, int type, size_t entries)
protected struct mlistfile_apprentice (struct magic_set *ms, const char *fn, int action)
protected uint32_t file_signextend (struct magic_set *ms, struct magic *m, uint32_t v)
protected void file_showstr (FILE *fp, const char *s, size_t len)

Variables

private size_t magicsize = sizeof(struct magic)
private const uint32_t ar []
private 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;}

Referenced by parse().

#define IS_PLAINSTRING (  ) 
Value:
((t) == FILE_STRING || (t) == FILE_PSTRING || \
    (t) == FILE_BESTRING16 || (t) == FILE_LESTRING16)

Referenced by parse().

#define IS_STRING (  ) 
Value:
(IS_PLAINSTRING(t) || (t) == FILE_REGEX || \
    (t) == FILE_SEARCH)

Referenced by bs1(), and parse().

#define LOWCASE (  ) 
Value:
(isupper((unsigned char) (l)) ? \
                        tolower((unsigned char) (l)) : (l))

Referenced by eatsize().

#define MAP_FAILED   (void *) -1

Referenced by apprentice_map().

#define MAP_FILE   0

Referenced by apprentice_map().

#define MAXPATHLEN   1024
#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

private int apprentice_1 ( struct magic_set ms,
const char *  fn,
int  action,
struct mlist mlist 
)
private int apprentice_compile ( struct magic_set ms,
struct magic **  magicp,
uint32_t *  nmagicp,
const char *  fn 
)

Definition at line 1175 of file apprentice.c.

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

Referenced by apprentice_1().

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

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().

private int apprentice_map ( struct magic_set ms,
struct magic **  magicp,
uint32_t *  nmagicp,
const char *  fn 
)
private void bs1 ( struct magic m  ) 
private void byteswap ( struct magic magic,
uint32_t  nmagic 
)

Definition at line 1233 of file apprentice.c.

References bs1().

Referenced by apprentice_map().

private int check_format ( struct magic_set ms,
struct magic m 
)

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().

private void eatsize ( char **  p  ) 

Definition at line 1053 of file apprentice.c.

References LOWCASE.

Referenced by getvalue(), and parse().

protected struct mlist* file_apprentice ( struct magic_set ms,
const char *  fn,
int  action 
) [read]
protected void file_delmagic ( struct magic p,
int  type,
size_t  entries 
)

Definition at line 231 of file apprentice.c.

Referenced by apprentice_1().

FILE_RCSID ( "@(#)$Id: apprentice.  c,
v 1.84 2005/03/25 18:03:18 christos Exp $"   
) [pure virtual]
protected 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().

protected uint32_t file_signextend ( struct magic_set ms,
struct magic m,
uint32_t  v 
)
private char * getstr ( struct magic_set ms,
char *  s,
char *  p,
int  plen,
int *  slen 
)

Definition at line 879 of file apprentice.c.

References file_error(), and hextoint().

private int getvalue ( struct magic_set ms,
struct magic m,
char **  p 
)
private int hextoint ( int  c  ) 

Definition at line 979 of file apprentice.c.

Referenced by getstr().

private char * mkdbname ( const char *  fn,
char *  buf,
size_t  bufsiz,
int  strip 
)

Definition at line 1217 of file apprentice.c.

Referenced by apprentice_compile(), and apprentice_map().

private int parse ( struct magic_set ms,
struct magic **  magicp,
uint32_t *  nmagicp,
char *  l,
int  action 
)
private uint16_t swap2 ( uint16_t  sv  ) 

Definition at line 1244 of file apprentice.c.

Referenced by bs1().

private uint32_t swap4 ( uint32_t  sv  ) 

Definition at line 1258 of file apprentice.c.

Referenced by apprentice_map(), and bs1().


Variable Documentation

private const uint32_t ar[]
Initial value:

Definition at line 1168 of file apprentice.c.

Referenced by luaD_callhook().

private const char ext[] = ".mgc"
private size_t magicsize = sizeof(struct magic)

Definition at line 86 of file apprentice.c.


Generated on 31 Jul 2012 for rpm by  doxygen 1.6.1