diff options
author | Anon Ymous <ljt@astron.com> | 2007-01-16 14:58:48 +0000 |
---|---|---|
committer | Anon Ymous <ljt@astron.com> | 2007-01-16 14:58:48 +0000 |
commit | c8347a4974b932aa1bdbfeca0de913d73f40b49a (patch) | |
tree | 2517fc69a1509ec4f79fa87f815f63b2694e7d5f /src/print.c | |
parent | 88c95fbc52458d2f5b8413f789c3afd63d5423b4 (diff) | |
download | file-git-c8347a4974b932aa1bdbfeca0de913d73f40b49a.tar.gz |
1) Add a "default" type to print a message if nothing previously
matched at that level or since the last default at that level. This
is useful for setting up switch-like statements. It can also be used
to do if/else constructions without a redundant second test.
2) Fix the "x" special case test so that one can test for that string
with "=x".
3) Allow "search" to search the entire buffer if the "/N" search count
is missing.
4) Make "regex" work! It now starts its search at the specified
offset and takes an (optional) "/N" line count to specify the search
range; otherwise it searches to the end of the file. The match is now
grabbed correctly for format strings and the offset set to the end of
the match.
5) Add a "/s" flag to "regex" and "search" to set the offset to the
start of the match. By default the offset is set to the end of the
match, as it is with other tests. This is mostly useful for "regex".
6) Make "search", "string" and "pstring" use the same file_strncmp()
routine so that they support the same flags; "bestring16" and
"lestring16" call the same routine, but with flags = 0. Also add a
"/C" flag (in analogy to "/c") to ignore the case on uppercase
(lowercase) characters in the test string.
7) Strict adherence to C style string escapes. A warnings are
printed when compiling. Note: previously "\a" was incorrectly
translated to 'a' instead of an <alert> (i.e., BELL, typically 0x07).
8) Make this compile with "-Wall -Wextra" and all the warning flags
used with WARNS=4 in the NetBSD source. Also make it pass lint.
9) Many "cleanups" and hopefully not too many new bugs!
Diffstat (limited to 'src/print.c')
-rw-r--r-- | src/print.c | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/src/print.c b/src/print.c index d2a7bf84..6b019eba 100644 --- a/src/print.c +++ b/src/print.c @@ -41,7 +41,7 @@ #include <time.h> #ifndef lint -FILE_RCSID("@(#)$File: print.c,v 1.57 2007/01/12 17:38:28 christos Exp $") +FILE_RCSID("@(#)$File: print.c,v 1.58 2007/01/16 14:58:48 ljt Exp $") #endif /* lint */ #define SZOF(a) (sizeof(a) / sizeof(a[0])) @@ -64,8 +64,8 @@ file_mdump(struct magic *m) 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] : '?', + ((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" : "", @@ -73,25 +73,36 @@ file_mdump(struct magic *m) (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, "%.8llx", - (unsigned long long)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') { @@ -146,6 +157,9 @@ file_mdump(struct magic *m) (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; @@ -169,7 +183,7 @@ file_magwarn(struct magic_set *ms, const char *f, ...) (unsigned long)ms->line); (void) vfprintf(stderr, f, va); va_end(va); - fputc('\n', stderr); + (void) fputc('\n', stderr); } protected const char * |