From: Christos Zoulas Date: Tue, 8 May 2007 14:41:44 +0000 (+0000) Subject: mention -C in the options X-Git-Tag: FILE5_05~617 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e57eb24bbb1970b3aedd9f7274f7ca063f5fe62;p=file mention -C in the options --- diff --git a/src/file.c b/src/file.c index c00d7aaf..e2045ccc 100644 --- a/src/file.c +++ b/src/file.c @@ -71,7 +71,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$File: file.c,v 1.109 2007/03/15 14:50:34 christos Exp $") +FILE_RCSID("@(#)$File: file.c,v 1.110 2007/05/08 14:41:44 christos Exp $") #endif /* lint */ @@ -128,7 +128,7 @@ main(int argc, char *argv[]) char *home, *usermagic; struct stat sb; static const char hmagic[] = "/.magic"; -#define OPTSTRING "bcCde:f:F:hikLm:nNprsvz0" +#define OPTSTRING "bcCde:f:F:hikLm:nNprstvz0" #ifdef HAVE_GETOPT_LONG int longindex; static const struct option long_options[] = @@ -158,6 +158,7 @@ main(int argc, char *argv[]) {"special-files", 0, 0, 's'}, {"compile", 0, 0, 'C'}, {"print0", 0, 0, '0'}, + {"timing", 0, 0, 't'}, {0, 0, 0, 0}, }; #endif @@ -286,6 +287,9 @@ main(int argc, char *argv[]) case 's': flags |= MAGIC_DEVICES; break; + case 't': + flags |= MAGIC_TIMING; + break; case 'v': (void)fprintf(stdout, "%s-%d.%.2d\n", progname, FILE_VERSION_MAJOR, patchlevel); @@ -576,8 +580,11 @@ help(void) " -r, --raw don't translate unprintable chars to \\ooo\n" " -s, --special-files treat special (block/char devices) files as\n" " ordinary ones\n" +" -t, --timing print debug timing info\n" " --help display this help and exit\n" " --version output version information and exit\n" +"or\n" +" -C, --compile compile file specified by -m\n" ); exit(0); } diff --git a/src/magic.h b/src/magic.h index 39fa2e11..42028601 100644 --- a/src/magic.h +++ b/src/magic.h @@ -40,6 +40,7 @@ #define MAGIC_PRESERVE_ATIME 0x000080 /* Restore access time on exit */ #define MAGIC_RAW 0x000100 /* Don't translate unprintable chars */ #define MAGIC_ERROR 0x000200 /* Handle ENOENT etc as real errors */ +#define MAGIC_TIMING 0x000400 /* Print timing info for each entry */ #define MAGIC_NO_CHECK_COMPRESS 0x001000 /* Don't check for compressed files */ #define MAGIC_NO_CHECK_TAR 0x002000 /* Don't check for tar files */ #define MAGIC_NO_CHECK_SOFT 0x004000 /* Don't check magic entries */ diff --git a/src/softmagic.c b/src/softmagic.c index 6cc0c7dc..d712ec8c 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -38,7 +38,7 @@ #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.97 2007/03/25 03:13:47 christos Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.98 2007/05/08 14:41:44 christos Exp $") #endif /* lint */ private int match(struct magic_set *, struct magic *, uint32_t, @@ -111,13 +111,27 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic, int returnval = 0; /* if a match is found it is set to 1*/ int firstline = 1; /* a flag to print X\n X\n- X */ int printed_something = 0; + struct timeval starttv, curtv; if (file_check_mem(ms, cont_level) == -1) return -1; + starttv.tv_sec = 0; for (magindex = 0; magindex < nmagic; magindex++) { int flush; + if (ms->flags & MAGIC_TIMING) { + (void)gettimeofday(&curtv, NULL); + if (starttv.tv_sec == 0) + starttv = curtv; + else { + struct timeval diff; + timersub(&curtv, &starttv, &diff); + starttv = curtv; + (void)fprintf(stderr, "Took %ld.%ld\n", + (long)diff.tv_sec, (long)diff.tv_usec); + } + } ms->offset = magic[magindex].offset; ms->line = magic[magindex].lineno; @@ -1497,6 +1511,7 @@ magiccheck(struct magic_set *ms, struct magic *m) } else { regmatch_t pmatch[1]; +#undef REG_STARTEND #ifndef REG_STARTEND #define REG_STARTEND 0 size_t l = ms->search.s_len - 1;