#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.53 2003/03/23 21:16:26 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.54 2003/03/24 01:16:28 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
int rv = -1;
int mapped;
- if (action == COMPILE) {
+ if (action == FILE_COMPILE) {
rv = apprentice_file(ms, &magic, &nmagic, fn, action);
if (rv == 0) {
rv = apprentice_compile(ms, &magic, &nmagic, fn,
}
/* parse it */
- if (action == CHECK) /* print silly verbose header for USG compat. */
+ if (action == FILE_CHECK) /* print silly verbose header for USG compat. */
(void) printf("%s\n", hdr);
for (lineno = 1; fgets(line, BUFSIZ, f) != NULL; lineno++) {
* vital. When later compared with the data,
* the sign extension must have happened.
*/
- case BYTE:
+ case FILE_BYTE:
v = (char) v;
break;
- case SHORT:
- case BESHORT:
- case LESHORT:
+ case FILE_SHORT:
+ case FILE_BESHORT:
+ case FILE_LESHORT:
v = (short) v;
break;
- case DATE:
- case BEDATE:
- case LEDATE:
- case LDATE:
- case BELDATE:
- case LELDATE:
- case LONG:
- case BELONG:
- case LELONG:
+ case FILE_DATE:
+ case FILE_BEDATE:
+ case FILE_LEDATE:
+ case FILE_LDATE:
+ case FILE_BELDATE:
+ case FILE_LELDATE:
+ case FILE_LONG:
+ case FILE_BELONG:
+ case FILE_LELONG:
v = (int32_t) v;
break;
- case STRING:
- case PSTRING:
+ case FILE_STRING:
+ case FILE_PSTRING:
break;
- case REGEX:
+ case FILE_REGEX:
break;
default:
if (ms->flags & MAGIC_CHECK)
l = t;
if (m->flag & INDIR) {
- m->in_type = LONG;
+ m->in_type = FILE_LONG;
m->in_offset = 0;
/*
* read [.lbs][+-]nnnnn)
l++;
switch (*l) {
case 'l':
- m->in_type = LELONG;
+ m->in_type = FILE_LELONG;
break;
case 'L':
- m->in_type = BELONG;
+ m->in_type = FILE_BELONG;
break;
case 'h':
case 's':
- m->in_type = LESHORT;
+ m->in_type = FILE_LESHORT;
break;
case 'H':
case 'S':
- m->in_type = BESHORT;
+ m->in_type = FILE_BESHORT;
break;
case 'c':
case 'b':
case 'C':
case 'B':
- m->in_type = BYTE;
+ m->in_type = FILE_BYTE;
break;
default:
if (ms->flags & MAGIC_CHECK)
l++;
}
if (*l == '~') {
- m->in_op = OPINVERSE;
+ m->in_op = FILE_OPINVERSE;
l++;
}
switch (*l) {
case '&':
- m->in_op |= OPAND;
+ m->in_op |= FILE_OPAND;
l++;
break;
case '|':
- m->in_op |= OPOR;
+ m->in_op |= FILE_OPOR;
l++;
break;
case '^':
- m->in_op |= OPXOR;
+ m->in_op |= FILE_OPXOR;
l++;
break;
case '+':
- m->in_op |= OPADD;
+ m->in_op |= FILE_OPADD;
l++;
break;
case '-':
- m->in_op |= OPMINUS;
+ m->in_op |= FILE_OPMINUS;
l++;
break;
case '*':
- m->in_op |= OPMULTIPLY;
+ m->in_op |= FILE_OPMULTIPLY;
l++;
break;
case '/':
- m->in_op |= OPDIVIDE;
+ m->in_op |= FILE_OPDIVIDE;
l++;
break;
case '%':
- m->in_op |= OPMODULO;
+ m->in_op |= FILE_OPMODULO;
l++;
break;
}
/* get type, skip it */
if (strncmp(l, "char", NBYTE)==0) { /* HP/UX compat */
- m->type = BYTE;
+ m->type = FILE_BYTE;
l += NBYTE;
} else if (strncmp(l, "byte", NBYTE)==0) {
- m->type = BYTE;
+ m->type = FILE_BYTE;
l += NBYTE;
} else if (strncmp(l, "short", NSHORT)==0) {
- m->type = SHORT;
+ m->type = FILE_SHORT;
l += NSHORT;
} else if (strncmp(l, "long", NLONG)==0) {
- m->type = LONG;
+ m->type = FILE_LONG;
l += NLONG;
} else if (strncmp(l, "string", NSTRING)==0) {
- m->type = STRING;
+ m->type = FILE_STRING;
l += NSTRING;
} else if (strncmp(l, "date", NDATE)==0) {
- m->type = DATE;
+ m->type = FILE_DATE;
l += NDATE;
} else if (strncmp(l, "beshort", NBESHORT)==0) {
- m->type = BESHORT;
+ m->type = FILE_BESHORT;
l += NBESHORT;
} else if (strncmp(l, "belong", NBELONG)==0) {
- m->type = BELONG;
+ m->type = FILE_BELONG;
l += NBELONG;
} else if (strncmp(l, "bedate", NBEDATE)==0) {
- m->type = BEDATE;
+ m->type = FILE_BEDATE;
l += NBEDATE;
} else if (strncmp(l, "leshort", NLESHORT)==0) {
- m->type = LESHORT;
+ m->type = FILE_LESHORT;
l += NLESHORT;
} else if (strncmp(l, "lelong", NLELONG)==0) {
- m->type = LELONG;
+ m->type = FILE_LELONG;
l += NLELONG;
} else if (strncmp(l, "ledate", NLEDATE)==0) {
- m->type = LEDATE;
+ m->type = FILE_LEDATE;
l += NLEDATE;
} else if (strncmp(l, "pstring", NPSTRING)==0) {
- m->type = PSTRING;
+ m->type = FILE_PSTRING;
l += NPSTRING;
} else if (strncmp(l, "ldate", NLDATE)==0) {
- m->type = LDATE;
+ m->type = FILE_LDATE;
l += NLDATE;
} else if (strncmp(l, "beldate", NBELDATE)==0) {
- m->type = BELDATE;
+ m->type = FILE_BELDATE;
l += NBELDATE;
} else if (strncmp(l, "leldate", NLELDATE)==0) {
- m->type = LELDATE;
+ m->type = FILE_LELDATE;
l += NLELDATE;
} else if (strncmp(l, "regex", NREGEX)==0) {
- m->type = REGEX;
+ m->type = FILE_REGEX;
l += sizeof("regex");
} else {
if (ms->flags & MAGIC_CHECK)
/* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */
/* New and improved: ~ & | ^ + - * / % -- exciting, isn't it? */
if (*l == '~') {
- if (STRING != m->type && PSTRING != m->type)
- m->mask_op = OPINVERSE;
+ if (FILE_STRING != m->type && FILE_PSTRING != m->type)
+ m->mask_op = FILE_OPINVERSE;
++l;
}
switch (*l) {
case '&':
- m->mask_op |= OPAND;
+ m->mask_op |= FILE_OPAND;
++l;
m->mask = file_signextend(ms, m, strtoul(l, &l, 0));
eatsize(&l);
break;
case '|':
- m->mask_op |= OPOR;
+ m->mask_op |= FILE_OPOR;
++l;
m->mask = file_signextend(ms, m, strtoul(l, &l, 0));
eatsize(&l);
break;
case '^':
- m->mask_op |= OPXOR;
+ m->mask_op |= FILE_OPXOR;
++l;
m->mask = file_signextend(ms, m, strtoul(l, &l, 0));
eatsize(&l);
break;
case '+':
- m->mask_op |= OPADD;
+ m->mask_op |= FILE_OPADD;
++l;
m->mask = file_signextend(ms, m, strtoul(l, &l, 0));
eatsize(&l);
break;
case '-':
- m->mask_op |= OPMINUS;
+ m->mask_op |= FILE_OPMINUS;
++l;
m->mask = file_signextend(ms, m, strtoul(l, &l, 0));
eatsize(&l);
break;
case '*':
- m->mask_op |= OPMULTIPLY;
+ m->mask_op |= FILE_OPMULTIPLY;
++l;
m->mask = file_signextend(ms, m, strtoul(l, &l, 0));
eatsize(&l);
break;
case '%':
- m->mask_op |= OPMODULO;
+ m->mask_op |= FILE_OPMODULO;
++l;
m->mask = file_signextend(ms, m, strtoul(l, &l, 0));
eatsize(&l);
break;
case '/':
- if (STRING != m->type && PSTRING != m->type) {
- m->mask_op |= OPDIVIDE;
+ if (FILE_STRING != m->type && FILE_PSTRING != m->type) {
+ m->mask_op |= FILE_OPDIVIDE;
++l;
m->mask = file_signextend(ms, m, strtoul(l, &l, 0));
eatsize(&l);
}
break;
case '!':
- if (m->type != STRING && m->type != PSTRING) {
+ if (m->type != FILE_STRING && m->type != FILE_PSTRING) {
m->reln = *l;
++l;
break;
m->nospflag = 1;
} else
m->nospflag = 0;
- while ((m->desc[i++] = *l++) != '\0' && i<MAXDESC)
+ while ((m->desc[i++] = *l++) != '\0' && i < MAXDESC)
/* NULLBODY */;
#ifndef COMPILE_ONLY
- if (action == CHECK) {
+ if (action == FILE_CHECK) {
file_mdump(m);
}
#endif
{
int slen;
- if (m->type == STRING || m->type == PSTRING || m->type == REGEX) {
+ switch (m->type) {
+ case FILE_STRING:
+ case FILE_PSTRING:
+ case FILE_REGEX:
*p = getstr(ms, *p, m->value.s, sizeof(m->value.s), &slen);
if (*p == NULL)
return -1;
m->vallen = slen;
- } else
+ return 0;
+ default:
if (m->reln != 'x') {
m->value.l = file_signextend(ms, m, strtoul(*p, p, 0));
eatsize(p);
}
- return 0;
+ return 0;
+ }
}
/*
m->cont_level = swap2(m->cont_level);
m->offset = swap4(m->offset);
m->in_offset = swap4(m->in_offset);
- if (m->type != STRING)
+ if (m->type != FILE_STRING)
m->value.l = swap4(m->value.l);
m->mask = swap4(m->mask);
}
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: compress.c,v 1.28 2003/03/23 21:24:07 christos Exp $")
+FILE_RCSID("@(#)$Id: compress.c,v 1.29 2003/03/24 01:16:28 christos Exp $")
#endif
if (file_printf(ms, " (") == -1)
return -1;
ms->flags &= ~MAGIC_COMPRESS;
- if (file_buf(ms, buf, nbytes) == -1) {
+ if (file_buffer(ms, buf, nbytes) == -1) {
ms->flags |= MAGIC_COMPRESS;
return -1;
}
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: file.c,v 1.71 2003/03/23 21:16:26 christos Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.72 2003/03/24 01:16:28 christos Exp $")
#endif /* lint */
++bflag;
break;
case 'c':
- action = CHECK;
+ action = FILE_CHECK;
break;
case 'C':
- action = COMPILE;
+ action = FILE_COMPILE;
break;
case 'd':
flags |= MAGIC_DEBUG;
}
switch(action) {
- case CHECK:
- case COMPILE:
+ case FILE_CHECK:
+ case FILE_COMPILE:
magic = magic_open(flags);
if (magic == NULL) {
(void)fprintf(stderr, "%s: %s\n", progname,
strerror(errno));
return 1;
}
- return action == CHECK ? magic_check(magic, magicfile) :
+ return action == FILE_CHECK ? magic_check(magic, magicfile) :
magic_compile(magic, magicfile);
default:
load(magicfile, flags);
*/
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.47 2003/03/23 21:16:26 christos Exp $
+ * @(#)$Id: file.h,v 1.48 2003/03/24 01:16:28 christos Exp $
*/
#ifndef __file_h__
#define MAGICNO 0xF11E041C
#define VERSIONNO 1
-#define CHECK 1
-#define COMPILE 2
+#define FILE_CHECK 1
+#define FILE_COMPILE 2
#ifndef __GNUC__
#define __attribute__(a)
uint8_t vallen; /* length of string value, if any */
uint8_t type; /* int, short, long or string. */
uint8_t in_type; /* type of indirrection */
-#define BYTE 1
-#define SHORT 2
-#define LONG 4
-#define STRING 5
-#define DATE 6
-#define BESHORT 7
-#define BELONG 8
-#define BEDATE 9
-#define LESHORT 10
-#define LELONG 11
-#define LEDATE 12
-#define PSTRING 13
-#define LDATE 14
-#define BELDATE 15
-#define LELDATE 16
-#define REGEX 17
+#define FILE_BYTE 1
+#define FILE_SHORT 2
+#define FILE_LONG 4
+#define FILE_STRING 5
+#define FILE_DATE 6
+#define FILE_BESHORT 7
+#define FILE_BELONG 8
+#define FILE_BEDATE 9
+#define FILE_LESHORT 10
+#define FILE_LELONG 11
+#define FILE_LEDATE 12
+#define FILE_PSTRING 13
+#define FILE_LDATE 14
+#define FILE_BELDATE 15
+#define FILE_LELDATE 16
+#define FILE_REGEX 17
uint8_t in_op; /* operator for indirection */
uint8_t mask_op; /* operator for mask */
-#define OPAND 1
-#define OPOR 2
-#define OPXOR 3
-#define OPADD 4
-#define OPMINUS 5
-#define OPMULTIPLY 6
-#define OPDIVIDE 7
-#define OPMODULO 8
-#define OPINVERSE 0x80
+#define FILE_OPAND 1
+#define FILE_OPOR 2
+#define FILE_OPXOR 3
+#define FILE_OPADD 4
+#define FILE_OPMINUS 5
+#define FILE_OPMULTIPLY 6
+#define FILE_OPDIVIDE 7
+#define FILE_OPMODULO 8
+#define FILE_OPINVERSE 0x80
int32_t offset; /* offset to magic number */
int32_t in_offset; /* offset from indirection */
union VALUETYPE {
struct stat;
protected char *file_fmttime(long, int);
-protected int file_buf(struct magic_set *, const void *buf, size_t);
+protected int file_buffer(struct magic_set *, const void *buf, size_t);
protected int file_fsmagic(struct magic_set *, const char *, struct stat *);
protected int file_pipe2file(struct magic_set *, int, const void *, size_t);
protected int file_printf(struct magic_set *, const char *, ...);
}
protected int
-file_buf(struct magic_set *ms, const void *buf, size_t nb)
+file_buffer(struct magic_set *ms, const void *buf, size_t nb)
{
int m;
/* try compression stuff */
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: magic.c,v 1.3 2003/03/23 21:24:07 christos Exp $")
+FILE_RCSID("@(#)$Id: magic.c,v 1.4 2003/03/24 01:16:28 christos Exp $")
#endif /* lint */
public int
magic_compile(struct magic_set *ms, const char *magicfile)
{
- struct mlist *ml = file_apprentice(ms, magicfile, COMPILE);
+ struct mlist *ml = file_apprentice(ms, magicfile, FILE_COMPILE);
if(ml == NULL)
return -1;
free_mlist(ml);
public int
magic_check(struct magic_set *ms, const char *magicfile)
{
- struct mlist *ml = file_apprentice(ms, magicfile, CHECK);
+ struct mlist *ml = file_apprentice(ms, magicfile, FILE_CHECK);
if(ml == NULL)
return -1;
free_mlist(ml);
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.41 2003/03/23 21:16:26 christos Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.42 2003/03/24 01:16:28 christos Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
/* Note: type is unsigned */
(m->in_type < SZOF(typ)) ?
typ[m->in_type] : "*bad*");
- if (m->in_op & OPINVERSE)
+ if (m->in_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
(void) fprintf(stderr, "%c%d),",
((m->in_op&0x7F) < SZOF(optyp)) ?
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
/* Note: type is unsigned */
(m->type < SZOF(typ)) ? typ[m->type] : "*bad*");
- if (m->mask_op & OPINVERSE)
+ if (m->mask_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
if (m->mask) {
((m->mask_op&0x7F) < SZOF(optyp)) ?
(void) fputc(optyp[m->mask_op&0x7F], stderr) :
(void) fputc('?', stderr);
- if(STRING != m->type || PSTRING != m->type)
+ if(FILE_STRING != m->type || FILE_PSTRING != m->type)
(void) fprintf(stderr, "%.8x", m->mask);
else {
if (m->mask & STRING_IGNORE_LOWERCASE)
if (m->reln != 'x') {
switch (m->type) {
- case BYTE:
- case SHORT:
- case LONG:
- case LESHORT:
- case LELONG:
- case BESHORT:
- case BELONG:
+ case FILE_BYTE:
+ case FILE_SHORT:
+ case FILE_LONG:
+ case FILE_LESHORT:
+ case FILE_LELONG:
+ case FILE_BESHORT:
+ case FILE_BELONG:
(void) fprintf(stderr, "%d", m->value.l);
break;
- case STRING:
- case PSTRING:
- case REGEX:
+ case FILE_STRING:
+ case FILE_PSTRING:
+ case FILE_REGEX:
file_showstr(stderr, m->value.s, -1);
break;
- case DATE:
- case LEDATE:
- case BEDATE:
+ case FILE_DATE:
+ case FILE_LEDATE:
+ case FILE_BEDATE:
(void)fprintf(stderr, "%s,",
file_fmttime(m->value.l, 1));
break;
- case LDATE:
- case LELDATE:
- case BELDATE:
+ case FILE_LDATE:
+ case FILE_LELDATE:
+ case FILE_BELDATE:
(void)fprintf(stderr, "%s,",
file_fmttime(m->value.l, 0));
break;
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.56 2003/03/23 21:16:26 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.57 2003/03/24 01:16:28 christos Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
switch (m->type) {
- case BYTE:
+ case FILE_BYTE:
v = file_signextend(ms, m, p->b);
if (file_printf(ms, m->desc, (unsigned char) v) == -1)
return -1;
t = m->offset + sizeof(char);
break;
- case SHORT:
- case BESHORT:
- case LESHORT:
+ case FILE_SHORT:
+ case FILE_BESHORT:
+ case FILE_LESHORT:
v = file_signextend(ms, m, p->h);
if (file_printf(ms, m->desc, (unsigned short) v) == -1)
return -1;
t = m->offset + sizeof(short);
break;
- case LONG:
- case BELONG:
- case LELONG:
+ case FILE_LONG:
+ case FILE_BELONG:
+ case FILE_LELONG:
v = file_signextend(ms, m, p->l);
if (file_printf(ms, m->desc, (uint32_t) v) == -1)
return -1;
t = m->offset + sizeof(int32_t);
break;
- case STRING:
- case PSTRING:
+ case FILE_STRING:
+ case FILE_PSTRING:
if (m->reln == '=') {
if (file_printf(ms, m->desc, m->value.s) == -1)
return -1;
}
break;
- case DATE:
- case BEDATE:
- case LEDATE:
+ case FILE_DATE:
+ case FILE_BEDATE:
+ case FILE_LEDATE:
if (file_printf(ms, m->desc, file_fmttime(p->l, 1)) == -1)
return -1;
t = m->offset + sizeof(time_t);
break;
- case LDATE:
- case BELDATE:
- case LELDATE:
+ case FILE_LDATE:
+ case FILE_BELDATE:
+ case FILE_LELDATE:
if (file_printf(ms, m->desc, file_fmttime(p->l, 0)) == -1)
return -1;
t = m->offset + sizeof(time_t);
break;
- case REGEX:
+ case FILE_REGEX:
if (file_printf(ms, m->desc, p->s) == -1)
return -1;
t = m->offset + strlen(p->s);
mconvert(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
{
switch (m->type) {
- case BYTE:
+ case FILE_BYTE:
if (m->mask)
switch (m->mask_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
p->b &= m->mask;
break;
- case OPOR:
+ case FILE_OPOR:
p->b |= m->mask;
break;
- case OPXOR:
+ case FILE_OPXOR:
p->b ^= m->mask;
break;
- case OPADD:
+ case FILE_OPADD:
p->b += m->mask;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
p->b -= m->mask;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
p->b *= m->mask;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
p->b /= m->mask;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
p->b %= m->mask;
break;
}
- if (m->mask_op & OPINVERSE)
+ if (m->mask_op & FILE_OPINVERSE)
p->b = ~p->b;
return 1;
- case SHORT:
+ case FILE_SHORT:
if (m->mask)
switch (m->mask_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
p->h &= m->mask;
break;
- case OPOR:
+ case FILE_OPOR:
p->h |= m->mask;
break;
- case OPXOR:
+ case FILE_OPXOR:
p->h ^= m->mask;
break;
- case OPADD:
+ case FILE_OPADD:
p->h += m->mask;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
p->h -= m->mask;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
p->h *= m->mask;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
p->h /= m->mask;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
p->h %= m->mask;
break;
}
- if (m->mask_op & OPINVERSE)
+ if (m->mask_op & FILE_OPINVERSE)
p->h = ~p->h;
return 1;
- case LONG:
- case DATE:
- case LDATE:
+ case FILE_LONG:
+ case FILE_DATE:
+ case FILE_LDATE:
if (m->mask)
switch (m->mask_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
p->l &= m->mask;
break;
- case OPOR:
+ case FILE_OPOR:
p->l |= m->mask;
break;
- case OPXOR:
+ case FILE_OPXOR:
p->l ^= m->mask;
break;
- case OPADD:
+ case FILE_OPADD:
p->l += m->mask;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
p->l -= m->mask;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
p->l *= m->mask;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
p->l /= m->mask;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
p->l %= m->mask;
break;
}
- if (m->mask_op & OPINVERSE)
+ if (m->mask_op & FILE_OPINVERSE)
p->l = ~p->l;
return 1;
- case STRING:
+ case FILE_STRING:
{
int n;
p->s[n] = '\0';
return 1;
}
- case PSTRING:
+ case FILE_PSTRING:
{
char *ptr1 = p->s, *ptr2 = ptr1 + 1;
int n = *p->s;
p->s[n] = '\0';
return 1;
}
- case BESHORT:
+ case FILE_BESHORT:
p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
if (m->mask)
switch (m->mask_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
p->h &= m->mask;
break;
- case OPOR:
+ case FILE_OPOR:
p->h |= m->mask;
break;
- case OPXOR:
+ case FILE_OPXOR:
p->h ^= m->mask;
break;
- case OPADD:
+ case FILE_OPADD:
p->h += m->mask;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
p->h -= m->mask;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
p->h *= m->mask;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
p->h /= m->mask;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
p->h %= m->mask;
break;
}
- if (m->mask_op & OPINVERSE)
+ if (m->mask_op & FILE_OPINVERSE)
p->h = ~p->h;
return 1;
- case BELONG:
- case BEDATE:
- case BELDATE:
+ case FILE_BELONG:
+ case FILE_BEDATE:
+ case FILE_BELDATE:
p->l = (int32_t)
((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
if (m->mask)
switch (m->mask_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
p->l &= m->mask;
break;
- case OPOR:
+ case FILE_OPOR:
p->l |= m->mask;
break;
- case OPXOR:
+ case FILE_OPXOR:
p->l ^= m->mask;
break;
- case OPADD:
+ case FILE_OPADD:
p->l += m->mask;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
p->l -= m->mask;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
p->l *= m->mask;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
p->l /= m->mask;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
p->l %= m->mask;
break;
}
- if (m->mask_op & OPINVERSE)
+ if (m->mask_op & FILE_OPINVERSE)
p->l = ~p->l;
return 1;
- case LESHORT:
+ case FILE_LESHORT:
p->h = (short)((p->hs[1]<<8)|(p->hs[0]));
if (m->mask)
switch (m->mask_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
p->h &= m->mask;
break;
- case OPOR:
+ case FILE_OPOR:
p->h |= m->mask;
break;
- case OPXOR:
+ case FILE_OPXOR:
p->h ^= m->mask;
break;
- case OPADD:
+ case FILE_OPADD:
p->h += m->mask;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
p->h -= m->mask;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
p->h *= m->mask;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
p->h /= m->mask;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
p->h %= m->mask;
break;
}
- if (m->mask_op & OPINVERSE)
+ if (m->mask_op & FILE_OPINVERSE)
p->h = ~p->h;
return 1;
- case LELONG:
- case LEDATE:
- case LELDATE:
+ case FILE_LELONG:
+ case FILE_LEDATE:
+ case FILE_LELDATE:
p->l = (int32_t)
((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
if (m->mask)
switch (m->mask_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
p->l &= m->mask;
break;
- case OPOR:
+ case FILE_OPOR:
p->l |= m->mask;
break;
- case OPXOR:
+ case FILE_OPXOR:
p->l ^= m->mask;
break;
- case OPADD:
+ case FILE_OPADD:
p->l += m->mask;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
p->l -= m->mask;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
p->l *= m->mask;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
p->l /= m->mask;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
p->l %= m->mask;
break;
}
- if (m->mask_op & OPINVERSE)
+ if (m->mask_op & FILE_OPINVERSE)
p->l = ~p->l;
return 1;
- case REGEX:
+ case FILE_REGEX:
return 1;
default:
file_error(ms, "invalid type %d in mconvert()", m->type);
{
int32_t offset = m->offset;
- if (m->type == REGEX) {
+ if (m->type == FILE_REGEX) {
/*
* offset is interpreted as last line to search,
* (starting at 1), not as bytes-from start-of-file
if (m->flag & INDIR) {
switch (m->in_type) {
- case BYTE:
+ case FILE_BYTE:
if (m->in_offset)
switch (m->in_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
offset = p->b & m->in_offset;
break;
- case OPOR:
+ case FILE_OPOR:
offset = p->b | m->in_offset;
break;
- case OPXOR:
+ case FILE_OPXOR:
offset = p->b ^ m->in_offset;
break;
- case OPADD:
+ case FILE_OPADD:
offset = p->b + m->in_offset;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
offset = p->b - m->in_offset;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
offset = p->b * m->in_offset;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
offset = p->b / m->in_offset;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
offset = p->b % m->in_offset;
break;
}
- if (m->in_op & OPINVERSE)
+ if (m->in_op & FILE_OPINVERSE)
offset = ~offset;
break;
- case BESHORT:
+ case FILE_BESHORT:
if (m->in_offset)
switch (m->in_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
offset = (short)((p->hs[0]<<8)|
(p->hs[1])) &
m->in_offset;
break;
- case OPOR:
+ case FILE_OPOR:
offset = (short)((p->hs[0]<<8)|
(p->hs[1])) |
m->in_offset;
break;
- case OPXOR:
+ case FILE_OPXOR:
offset = (short)((p->hs[0]<<8)|
(p->hs[1])) ^
m->in_offset;
break;
- case OPADD:
+ case FILE_OPADD:
offset = (short)((p->hs[0]<<8)|
(p->hs[1])) +
m->in_offset;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
offset = (short)((p->hs[0]<<8)|
(p->hs[1])) -
m->in_offset;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
offset = (short)((p->hs[0]<<8)|
(p->hs[1])) *
m->in_offset;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
offset = (short)((p->hs[0]<<8)|
(p->hs[1])) /
m->in_offset;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
offset = (short)((p->hs[0]<<8)|
(p->hs[1])) %
m->in_offset;
break;
}
- if (m->in_op & OPINVERSE)
+ if (m->in_op & FILE_OPINVERSE)
offset = ~offset;
break;
- case LESHORT:
+ case FILE_LESHORT:
if (m->in_offset)
switch (m->in_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
offset = (short)((p->hs[1]<<8)|
(p->hs[0])) &
m->in_offset;
break;
- case OPOR:
+ case FILE_OPOR:
offset = (short)((p->hs[1]<<8)|
(p->hs[0])) |
m->in_offset;
break;
- case OPXOR:
+ case FILE_OPXOR:
offset = (short)((p->hs[1]<<8)|
(p->hs[0])) ^
m->in_offset;
break;
- case OPADD:
+ case FILE_OPADD:
offset = (short)((p->hs[1]<<8)|
(p->hs[0])) +
m->in_offset;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
offset = (short)((p->hs[1]<<8)|
(p->hs[0])) -
m->in_offset;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
offset = (short)((p->hs[1]<<8)|
(p->hs[0])) *
m->in_offset;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
offset = (short)((p->hs[1]<<8)|
(p->hs[0])) /
m->in_offset;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
offset = (short)((p->hs[1]<<8)|
(p->hs[0])) %
m->in_offset;
break;
}
- if (m->in_op & OPINVERSE)
+ if (m->in_op & FILE_OPINVERSE)
offset = ~offset;
break;
- case SHORT:
+ case FILE_SHORT:
if (m->in_offset)
switch (m->in_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
offset = p->h & m->in_offset;
break;
- case OPOR:
+ case FILE_OPOR:
offset = p->h | m->in_offset;
break;
- case OPXOR:
+ case FILE_OPXOR:
offset = p->h ^ m->in_offset;
break;
- case OPADD:
+ case FILE_OPADD:
offset = p->h + m->in_offset;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
offset = p->h - m->in_offset;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
offset = p->h * m->in_offset;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
offset = p->h / m->in_offset;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
offset = p->h % m->in_offset;
break;
}
- if (m->in_op & OPINVERSE)
+ if (m->in_op & FILE_OPINVERSE)
offset = ~offset;
break;
- case BELONG:
+ case FILE_BELONG:
if (m->in_offset)
switch (m->in_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) &
m->in_offset;
break;
- case OPOR:
+ case FILE_OPOR:
offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) |
m->in_offset;
break;
- case OPXOR:
+ case FILE_OPXOR:
offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) ^
m->in_offset;
break;
- case OPADD:
+ case FILE_OPADD:
offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) +
m->in_offset;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) -
m->in_offset;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) *
m->in_offset;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
(p->hl[3])) /
m->in_offset;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
offset = (int32_t)((p->hl[0]<<24)|
(p->hl[1]<<16)|
(p->hl[2]<<8)|
m->in_offset;
break;
}
- if (m->in_op & OPINVERSE)
+ if (m->in_op & FILE_OPINVERSE)
offset = ~offset;
break;
- case LELONG:
+ case FILE_LELONG:
if (m->in_offset)
switch (m->in_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) &
m->in_offset;
break;
- case OPOR:
+ case FILE_OPOR:
offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) |
m->in_offset;
break;
- case OPXOR:
+ case FILE_OPXOR:
offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) ^
m->in_offset;
break;
- case OPADD:
+ case FILE_OPADD:
offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) +
m->in_offset;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) -
m->in_offset;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) *
m->in_offset;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
(p->hl[0])) /
m->in_offset;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
offset = (int32_t)((p->hl[3]<<24)|
(p->hl[2]<<16)|
(p->hl[1]<<8)|
m->in_offset;
break;
}
- if (m->in_op & OPINVERSE)
+ if (m->in_op & FILE_OPINVERSE)
offset = ~offset;
break;
- case LONG:
+ case FILE_LONG:
if (m->in_offset)
switch (m->in_op&0x7F) {
- case OPAND:
+ case FILE_OPAND:
offset = p->l & m->in_offset;
break;
- case OPOR:
+ case FILE_OPOR:
offset = p->l | m->in_offset;
break;
- case OPXOR:
+ case FILE_OPXOR:
offset = p->l ^ m->in_offset;
break;
- case OPADD:
+ case FILE_OPADD:
offset = p->l + m->in_offset;
break;
- case OPMINUS:
+ case FILE_OPMINUS:
offset = p->l - m->in_offset;
break;
- case OPMULTIPLY:
+ case FILE_OPMULTIPLY:
offset = p->l * m->in_offset;
break;
- case OPDIVIDE:
+ case FILE_OPDIVIDE:
offset = p->l / m->in_offset;
break;
- case OPMODULO:
+ case FILE_OPMODULO:
offset = p->l % m->in_offset;
break;
/* case TOOMANYSWITCHBLOCKS:
* sleep;
*/
}
- if (m->in_op & OPINVERSE)
+ if (m->in_op & FILE_OPINVERSE)
offset = ~offset;
break;
}
switch (m->type) {
- case BYTE:
+ case FILE_BYTE:
v = p->b;
break;
- case SHORT:
- case BESHORT:
- case LESHORT:
+ case FILE_SHORT:
+ case FILE_BESHORT:
+ case FILE_LESHORT:
v = p->h;
break;
- case LONG:
- case BELONG:
- case LELONG:
- case DATE:
- case BEDATE:
- case LEDATE:
- case LDATE:
- case BELDATE:
- case LELDATE:
+ case FILE_LONG:
+ case FILE_BELONG:
+ case FILE_LELONG:
+ case FILE_DATE:
+ case FILE_BEDATE:
+ case FILE_LEDATE:
+ case FILE_LDATE:
+ case FILE_BELDATE:
+ case FILE_LELDATE:
v = p->l;
break;
- case STRING:
- case PSTRING:
+ case FILE_STRING:
+ case FILE_PSTRING:
{
/*
* What we want here is:
}
break;
}
- case REGEX:
+ case FILE_REGEX:
{
int rc;
regex_t rx;
return -1;
}
- if(m->type != STRING && m->type != PSTRING)
+ if (m->type != FILE_STRING && m->type != FILE_PSTRING)
v = file_signextend(ms, m, v);
switch (m->reln) {