diff options
Diffstat (limited to 'src/apprentice.c')
-rw-r--r-- | src/apprentice.c | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/apprentice.c b/src/apprentice.c index c421b2ac..8b12853a 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -46,7 +46,7 @@ #endif #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.106 2007/10/23 19:58:59 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.107 2007/11/08 00:31:37 christos Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -188,6 +188,12 @@ static const struct type_tbl_s { { XX("qldate"), FILE_QLDATE, FILE_FMT_STR }, { XX("leqldate"), FILE_LEQLDATE, FILE_FMT_STR }, { XX("beqldate"), FILE_BEQLDATE, FILE_FMT_STR }, + { XX("float"), FILE_FLOAT, FILE_FMT_FLOAT }, + { XX("befloat"), FILE_BEFLOAT, FILE_FMT_FLOAT }, + { XX("lefloat"), FILE_LEFLOAT, FILE_FMT_FLOAT }, + { XX("double"), FILE_DOUBLE, FILE_FMT_DOUBLE }, + { XX("bedouble"), FILE_BEDOUBLE, FILE_FMT_DOUBLE }, + { XX("ledouble"), FILE_LEDOUBLE, FILE_FMT_DOUBLE }, { XX_NULL, FILE_INVALID, FILE_FMT_NONE }, # undef XX # undef XX_NULL @@ -432,6 +438,9 @@ apprentice_magic_strength(const struct magic *m) case FILE_LELDATE: case FILE_BELDATE: case FILE_MELDATE: + case FILE_FLOAT: + case FILE_BEFLOAT: + case FILE_LEFLOAT: val += 4 * MULT; break; @@ -444,6 +453,9 @@ apprentice_magic_strength(const struct magic *m) case FILE_QLDATE: case FILE_LEQLDATE: case FILE_BEQLDATE: + case FILE_DOUBLE: + case FILE_BEDOUBLE: + case FILE_LEDOUBLE: val += 8 * MULT; break; @@ -647,6 +659,9 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) case FILE_BELONG: case FILE_LELONG: case FILE_MELONG: + case FILE_FLOAT: + case FILE_BEFLOAT: + case FILE_LEFLOAT: v = (int32_t) v; break; case FILE_QUAD: @@ -658,6 +673,9 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) case FILE_BEQLDATE: case FILE_LEQDATE: case FILE_LEQLDATE: + case FILE_DOUBLE: + case FILE_BEDOUBLE: + case FILE_LEDOUBLE: v = (int64_t) v; break; case FILE_STRING: @@ -960,6 +978,16 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, case 'B': m->in_type = FILE_BYTE; break; + case 'e': + case 'f': + case 'g': + m->in_type = FILE_LEDOUBLE; + break; + case 'E': + case 'F': + case 'G': + m->in_type = FILE_BEDOUBLE; + break; default: if (ms->flags & MAGIC_CHECK) file_magwarn(ms, @@ -1253,6 +1281,31 @@ check_format_type(const char *ptr, int type) return -1; } + case FILE_FMT_FLOAT: + case FILE_FMT_DOUBLE: + if (*ptr == '-') + ptr++; + if (*ptr == '.') + ptr++; + while (isdigit((unsigned char)*ptr)) ptr++; + if (*ptr == '.') + ptr++; + while (isdigit((unsigned char)*ptr)) ptr++; + + switch (*ptr++) { + case 'e': + case 'E': + case 'f': + case 'F': + case 'g': + case 'G': + return 0; + + default: + return -1; + } + + case FILE_FMT_STR: if (*ptr == '-') ptr++; @@ -1359,6 +1412,24 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) } m->vallen = slen; return 0; + case FILE_FLOAT: + case FILE_BEFLOAT: + case FILE_LEFLOAT: + if (m->reln != 'x') { + char *ep; + m->value.f = strtof(*p, &ep); + *p = ep; + } + return 0; + case FILE_DOUBLE: + case FILE_BEDOUBLE: + case FILE_LEDOUBLE: + if (m->reln != 'x') { + char *ep; + m->value.d = strtod(*p, &ep); + *p = ep; + } + return 0; default: if (m->reln != 'x') { char *ep; |