From 99994474a7bad10a122bab2ddbd24b23bb8b4078 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Thu, 21 May 2015 18:25:29 +0000 Subject: [PATCH] Add MAGIC_NODESC for no-description printing. Make name nodes not print description if MAGIC_NODESC --- src/magic.h.in | 1 + src/softmagic.c | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/magic.h.in b/src/magic.h.in index 3e7b10e0..ba7884cb 100644 --- a/src/magic.h.in +++ b/src/magic.h.in @@ -45,6 +45,7 @@ #define MAGIC_APPLE 0x0000800 /* Return the Apple creator/type */ #define MAGIC_EXTENSION 0x1000000 /* Return a /-separated list of * extensions */ +#define MAGIC_NODESC (MAGIC_EXTENSION|MAGIC_MIME|MAGIC_APPLE) #define MAGIC_NO_CHECK_COMPRESS 0x0001000 /* Don't check for compressed files */ #define MAGIC_NO_CHECK_TAR 0x0002000 /* Don't check for tar files */ diff --git a/src/softmagic.c b/src/softmagic.c index c20fdfbe..eccd190a 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.213 2015/02/14 18:43:12 christos Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.214 2015/04/09 20:01:41 christos Exp $") #endif /* lint */ #include "magic.h" @@ -147,7 +147,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic, unsigned int cont_level = 0; int returnvalv = 0, e; /* if a match is found it is set to 1*/ int firstline = 1; /* a flag to print X\n X\n- X */ - int print = (ms->flags & (MAGIC_MIME|MAGIC_APPLE|MAGIC_EXTENSION)) == 0; + int print = (ms->flags & MAGIC_NODESC) == 0; if (returnval == NULL) returnval = &returnvalv; @@ -1674,7 +1674,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, return -1; if (rv == 1) { - if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE|MAGIC_EXTENSION)) == 0 && + if ((ms->flags & MAGIC_NODESC) == 0 && file_printf(ms, F(ms, m, "%u"), offset) == -1) { free(rbuf); return -1; @@ -1711,6 +1711,8 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m, return rv; case FILE_NAME: + if (ms->flags & MAGIC_NODESC) + return 1; if (file_printf(ms, "%s", m->desc) == -1) return -1; return 1; @@ -2152,7 +2154,7 @@ handle_annotation(struct magic_set *ms, struct magic *m) private int print_sep(struct magic_set *ms, int firstline) { - if (ms->flags & MAGIC_MIME) + if (ms->flags & MAGIC_NODESC) return 0; if (firstline) return 0; -- 2.40.0