summaryrefslogtreecommitdiff
path: root/usr.bin/file/print.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/file/print.c')
-rw-r--r--usr.bin/file/print.c113
1 files changed, 76 insertions, 37 deletions
diff --git a/usr.bin/file/print.c b/usr.bin/file/print.c
index 11bd3781bf6..438aaa00712 100644
--- a/usr.bin/file/print.c
+++ b/usr.bin/file/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.13 2007/09/14 14:29:20 chl Exp $ */
+/* $OpenBSD: print.c,v 1.14 2008/05/08 01:40:56 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -42,7 +42,7 @@
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.13 2007/09/14 14:29:20 chl Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.14 2008/05/08 01:40:56 chl Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@@ -51,52 +51,59 @@ FILE_RCSID("@(#)$Id: print.c,v 1.13 2007/09/14 14:29:20 chl Exp $")
protected void
file_mdump(struct magic *m)
{
- private const char *typ[] = { "invalid", "byte", "short", "invalid",
- "long", "string", "date", "beshort",
- "belong", "bedate", "leshort", "lelong",
- "ledate", "pstring", "ldate", "beldate",
- "leldate", "regex" };
- private const char optyp[] = { '@', '&', '|', '^', '+', '-',
- '*', '/', '%' };
- (void) fputc('[', stderr);
- (void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
+ private const char optyp[] = { FILE_OPS };
+
+ (void) fprintf(stderr, "[%u", m->lineno);
+ (void) fprintf(stderr, ">>>>>>>> %u" + 8 - (m->cont_level & 7),
m->offset);
if (m->flag & INDIR) {
(void) fprintf(stderr, "(%s,",
/* Note: type is unsigned */
- (m->in_type < SZOF(typ)) ?
- typ[m->in_type] : "*bad*");
+ (m->in_type < file_nnames) ?
+ file_names[m->in_type] : "*bad*");
if (m->in_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
- (void) fprintf(stderr, "%c%d),",
- ((m->in_op&0x7F) < SZOF(optyp)) ?
- optyp[m->in_op&0x7F] : '?',
+ (void) fprintf(stderr, "%c%u),",
+ ((m->in_op & FILE_OPS_MASK) < SZOF(optyp)) ?
+ optyp[m->in_op & FILE_OPS_MASK] : '?',
m->in_offset);
}
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
/* Note: type is unsigned */
- (m->type < SZOF(typ)) ? typ[m->type] : "*bad*");
+ (m->type < file_nnames) ? file_names[m->type] : "*bad*");
if (m->mask_op & FILE_OPINVERSE)
(void) fputc('~', stderr);
- if (m->mask) {
- if ((m->mask_op & 0x7F) < SZOF(optyp))
- fputc(optyp[m->mask_op&0x7F], stderr);
- else
- fputc('?', stderr);
- if(FILE_STRING != m->type || FILE_PSTRING != m->type)
- (void) fprintf(stderr, "%.8x", m->mask);
- else {
- if (m->mask & STRING_IGNORE_LOWERCASE)
- (void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
- if (m->mask & STRING_COMPACT_BLANK)
+
+ if (IS_STRING(m->type)) {
+ if (m->str_flags) {
+ (void) fputc('/', stderr);
+ if (m->str_flags & STRING_COMPACT_BLANK)
(void) fputc(CHAR_COMPACT_BLANK, stderr);
- if (m->mask & STRING_COMPACT_OPTIONAL_BLANK)
+ if (m->str_flags & STRING_COMPACT_OPTIONAL_BLANK)
(void) fputc(CHAR_COMPACT_OPTIONAL_BLANK,
- stderr);
+ stderr);
+ if (m->str_flags & STRING_IGNORE_LOWERCASE)
+ (void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
+ if (m->str_flags & STRING_IGNORE_UPPERCASE)
+ (void) fputc(CHAR_IGNORE_UPPERCASE, stderr);
+ if (m->str_flags & REGEX_OFFSET_START)
+ (void) fputc(CHAR_REGEX_OFFSET_START, stderr);
+ }
+ if (m->str_count)
+ (void) fprintf(stderr, "/%u", m->str_count);
+ }
+ else {
+ if ((m->mask_op & FILE_OPS_MASK) < SZOF(optyp))
+ (void) fputc(optyp[m->mask_op & FILE_OPS_MASK], stderr);
+ else
+ (void) fputc('?', stderr);
+
+ if (m->num_mask) {
+ (void) fprintf(stderr, "%.8llx",
+ (unsigned long long)m->num_mask);
}
}
-
(void) fprintf(stderr, ",%c", m->reln);
if (m->reln != 'x') {
@@ -106,27 +113,54 @@ file_mdump(struct magic *m)
case FILE_LONG:
case FILE_LESHORT:
case FILE_LELONG:
+ case FILE_MELONG:
case FILE_BESHORT:
case FILE_BELONG:
(void) fprintf(stderr, "%d", m->value.l);
break;
- case FILE_STRING:
+ case FILE_BEQUAD:
+ case FILE_LEQUAD:
+ case FILE_QUAD:
+ (void) fprintf(stderr, "%lld",
+ (unsigned long long)m->value.q);
+ break;
case FILE_PSTRING:
+ case FILE_STRING:
case FILE_REGEX:
- file_showstr(stderr, m->value.s, ~0U);
+ case FILE_BESTRING16:
+ case FILE_LESTRING16:
+ case FILE_SEARCH:
+ file_showstr(stderr, m->value.s, (size_t)m->vallen);
break;
case FILE_DATE:
case FILE_LEDATE:
case FILE_BEDATE:
+ case FILE_MEDATE:
(void)fprintf(stderr, "%s,",
file_fmttime(m->value.l, 1));
break;
case FILE_LDATE:
case FILE_LELDATE:
case FILE_BELDATE:
+ case FILE_MELDATE:
(void)fprintf(stderr, "%s,",
file_fmttime(m->value.l, 0));
break;
+ case FILE_QDATE:
+ case FILE_LEQDATE:
+ case FILE_BEQDATE:
+ (void)fprintf(stderr, "%s,",
+ file_fmttime((uint32_t)m->value.q, 1));
+ break;
+ case FILE_QLDATE:
+ case FILE_LEQLDATE:
+ case FILE_BEQLDATE:
+ (void)fprintf(stderr, "%s,",
+ file_fmttime((uint32_t)m->value.q, 0));
+ break;
+ case FILE_DEFAULT:
+ /* XXX - do anything here? */
+ break;
default:
(void) fputs("*bad*", stderr);
break;
@@ -138,7 +172,7 @@ file_mdump(struct magic *m)
/*VARARGS*/
protected void
-file_magwarn(const char *f, ...)
+file_magwarn(struct magic_set *ms, const char *f, ...)
{
va_list va;
va_start(va, f);
@@ -146,13 +180,14 @@ file_magwarn(const char *f, ...)
/* cuz we use stdout for most, stderr here */
(void) fflush(stdout);
- (void) fprintf(stderr, "WARNING: ");
+ (void) fprintf(stderr, "%s, %lu: Warning ", ms->file,
+ (unsigned long)ms->line);
(void) vfprintf(stderr, f, va);
va_end(va);
- fputc('\n', stderr);
+ (void) fputc('\n', stderr);
}
-protected char *
+protected const char *
file_fmttime(uint32_t v, int local)
{
char *pp;
@@ -171,6 +206,8 @@ file_fmttime(uint32_t v, int local)
struct tm *tm1;
(void)time(&now);
tm1 = localtime(&now);
+ if (tm1 == NULL)
+ return "*Invalid time*";
daylight = tm1->tm_isdst;
}
#endif /* HAVE_TM_ISDST */
@@ -178,6 +215,8 @@ file_fmttime(uint32_t v, int local)
if (daylight)
t += 3600;
tm = gmtime(&t);
+ if (tm == NULL)
+ return "*Invalid time*";
pp = asctime(tm);
}