#ifndef lint
static char *moduleid =
- "@(#)$Header: /home/glen/git/file/cvs/file/src/apprentice.c,v 1.8 1987/11/06 21:14:34 ian Exp $";
+ "@(#)$Header: /home/glen/git/file/cvs/file/src/apprentice.c,v 1.9 1990/10/03 17:52:59 ian Exp $";
#endif /* lint */
#define MAXSTR 500
if (nd+1 >= MAXMAGIS){
if (warned++ == 0)
warning(
-"magic table overflow - increase MAXMAGIS beyond %d in file/apprentice.c\n",
+"magic table overflow - increase MAXMAGIS beyond %d in file/file.h\n",
MAXMAGIS);
return -1;
}
warning("type %s invalid", l);
return -1;
}
+ if (*l == '&') {
+ ++l;
+ m->mask = strtol(l, &l, 0);
+ } else
+ m->mask = 0L;
EATAB;
- if (*l == '>' || *l == '<' || *l == '&' || *l == '=') {
+ if (*l == '>' || *l == '<' || *l == '='
+ || (m->type != STRING && (*l == '&' || *l == '^' || *l == 'x'))) {
m->reln = *l;
++l;
} else
* TODO finish this macro and start using it!
* #define offsetcheck {if (offset > HOWMANY-1) warning("offset too big"); }
*/
- switch(m->type) {
- /*
- * Do not remove the casts below. They are vital.
- * When later compared with the data, the sign extension must
- * have happened.
- */
- case BYTE:
- m->value.l = (char) strtol(l,&l,0);
- break;
- case SHORT:
- m->value.l = (short) strtol(l,&l,0);
- break;
- case LONG:
- m->value.l = (long) strtol(l,&l,0);
- break;
- case STRING:
+ if (m->type == STRING) {
l = getstr(l, m->value.s, sizeof(m->value.s), &slen);
m->vallen = slen;
- break;
- default:
- warning("can't happen: m->type=%d\n", m->type);
- return -1;
+ } else {
+ if (m->reln != 'x') {
+ switch(m->type) {
+ /*
+ * Do not remove the casts below. They are vital.
+ * When later compared with the data, the sign
+ * extension must have happened.
+ */
+ case BYTE:
+ m->value.l = (char) strtol(l,&l,0);
+ break;
+ case SHORT:
+ m->value.l = (short) strtol(l,&l,0);
+ break;
+ case LONG:
+ m->value.l = (long) strtol(l,&l,0);
+ break;
+ default:
+ warning("can't happen: m->type=%d\n", m->type);
+ return -1;
+ }
+ }
}
/*
{
char *origs = s, *origp = p;
char *pmax = p + plen - 1;
- register char c;
+ register int c;
register int val;
while((c = *s++) != '\0') {
- if (isspace(c)) break;
+ if (isspace(c))
+ break;
if (p >= pmax) {
fprintf(stderr, "String too long: %s\n", origs);
break;
#ifndef lint
static char *moduleid =
- "@(#)$Header: /home/glen/git/file/cvs/file/src/softmagic.c,v 1.7 1987/11/06 11:25:31 ian Exp $";
+ "@(#)$Header: /home/glen/git/file/cvs/file/src/softmagic.c,v 1.8 1990/10/03 17:53:10 ian Exp $";
#endif /* lint */
extern char *progname;
char *s;
{
register union VALUETYPE *p = (union VALUETYPE *)(s+m->offset);
+ register long v;
char *pp, *strchr();
- switch (m->type) {
- case BYTE:
- (void) printf(m->desc, p->b);
- break;
- case SHORT:
- (void) printf(m->desc, p->h);
- break;
- case LONG:
- (void) printf(m->desc, p->l);
- break;
- case STRING:
+ if (m->type == STRING) {
if ((pp=strchr(p->s, '\n')) != NULL)
*pp = '\0';
(void) printf(m->desc, p->s);
- break;
- default:
- warning("invalid m->type (%d) in mprint()", m->type);
+ } else {
+ switch (m->type) {
+ case BYTE:
+ v = p->b; break;
+ case SHORT:
+ v = p->h; break;
+ case LONG:
+ v = p->l; break;
+ default:
+ warning("invalid m->type (%d) in mprint()", m->type);
+ v = 0L;
+ }
+ if (m->mask != 0)
+ v &= m->mask;
+ (void) printf(m->desc, v);
}
}
return 0;
}
+ if (m->mask != 0L)
+ v &= m->mask;
+
switch (m->reln) {
case '=':
return v == l;
case '<':
return v < l;
case '&':
- return v & l;
+ return (v & l) == l;
+ case '^':
+ return (v & l) != l;
+ case 'x':
+ return 1;
default:
warning("mcheck: can't happen: invalid relation %d", m->reln);
return 0;