#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.273 2018/10/23 18:34:46 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.274 2018/10/24 13:15:35 christos Exp $")
#endif /* lint */
#include "magic.h"
{
uint32_t magindex = 0;
unsigned int cont_level = 0;
- int returnvalv = 0, e; /* if a match is found it is set to 1*/
+ int found_match = 0; /* if a match is found it is set to 1*/
+ int returnvalv = 0, e;
int firstline = 1; /* a flag to print X\n X\n- X */
struct buffer bb;
int print = (ms->flags & MAGIC_NODESC) == 0;
+ /*
+ * returnval can be 0 if a match is found, but there was no
+ * annotation to be printed.
+ */
if (returnval == NULL)
returnval = &returnvalv;
flush = m->reln != '!';
break;
default:
- if (m->type == FILE_INDIRECT)
+ if (m->type == FILE_INDIRECT) {
+ found_match = 1;
*returnval = 1;
+ }
switch (magiccheck(ms, m)) {
case -1:
goto flush;
}
+ if (*m->desc)
+ found_match = 1;
+
if ((e = handle_annotation(ms, m, firstline)) != 0)
{
*need_separator = 1;
return e;
}
- if (*m->desc)
- *returnval = 1;
/*
* If we are going to print something, we'll need to print
* a blank before we print something else.
if (print && *m->desc) {
*need_separator = 1;
*printed_something = 1;
+ *returnval = 1;
if (print_sep(ms, firstline) == -1)
return -1;
if (mprint(ms, m) == -1)
flush = 1;
break;
default:
- if (m->type == FILE_INDIRECT)
+ if (m->type == FILE_INDIRECT) {
+ found_match = 1;
*returnval = 1;
+ }
flush = 0;
break;
}
} else
ms->c.li[cont_level].got_match = 1;
+ if (*m->desc)
+ found_match = 1;
+
if ((e = handle_annotation(ms, m, firstline))
!= 0) {
*need_separator = 1;
*returnval = 1;
return e;
}
- if (*m->desc)
- *returnval = 1;
if (print && *m->desc) {
/*
* This continuation matched. Print
if (file_printf(ms, " ") == -1)
return -1;
}
+ *returnval = 1;
*need_separator = 0;
if (mprint(ms, m) == -1)
return -1;
}
if (*printed_something) {
firstline = 0;
- *returnval = 1;
}
- if ((ms->flags & MAGIC_CONTINUE) == 0 && *returnval) {
+ if ((ms->flags & MAGIC_CONTINUE) == 0 && found_match) {
return *returnval; /* don't keep searching */
}
cont_level = 0;