diff options
Diffstat (limited to 'contrib/file/file.c')
-rw-r--r-- | contrib/file/file.c | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/contrib/file/file.c b/contrib/file/file.c index f3fae24..0cd55ff 100644 --- a/contrib/file/file.c +++ b/contrib/file/file.c @@ -71,7 +71,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: file.c,v 1.104 2006/11/25 17:28:54 christos Exp $") +FILE_RCSID("@(#)$File: file.c,v 1.111 2007/05/08 14:44:18 christos Exp $") #endif /* lint */ @@ -81,7 +81,7 @@ FILE_RCSID("@(#)$Id: file.c,v 1.104 2006/11/25 17:28:54 christos Exp $") #define SYMLINKFLAG "" #endif -# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz0] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n" +# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n" #ifndef MAXPATHLEN #define MAXPATHLEN 512 @@ -122,13 +122,13 @@ private void load(const char *, int); int main(int argc, char *argv[]) { - int c; + int c, i; int action = 0, didsomefiles = 0, errflg = 0; int flags = 0; char *home, *usermagic; struct stat sb; static const char hmagic[] = "/.magic"; -#define OPTSTRING "bcCdf:F:hikLm:nNprsvz0" +#define OPTSTRING "bcCde:f:F:hikLm:nNprsvz0" #ifdef HAVE_GETOPT_LONG int longindex; static const struct option long_options[] = @@ -138,6 +138,7 @@ main(int argc, char *argv[]) {"brief", 0, 0, 'b'}, {"checking-printout", 0, 0, 'c'}, {"debug", 0, 0, 'd'}, + {"exclude", 1, 0, 'e' }, {"files-from", 1, 0, 'f'}, {"separator", 1, 0, 'F'}, {"mime", 0, 0, 'i'}, @@ -161,6 +162,21 @@ main(int argc, char *argv[]) }; #endif + static const struct { + const char *name; + int value; + } nv[] = { + { "apptype", MAGIC_NO_CHECK_APPTYPE }, + { "ascii", MAGIC_NO_CHECK_ASCII }, + { "compress", MAGIC_NO_CHECK_COMPRESS }, + { "elf", MAGIC_NO_CHECK_ELF }, + { "fortran", MAGIC_NO_CHECK_FORTRAN }, + { "soft", MAGIC_NO_CHECK_SOFT }, + { "tar", MAGIC_NO_CHECK_TAR }, + { "tokens", MAGIC_NO_CHECK_TOKENS }, + { "troff", MAGIC_NO_CHECK_TROFF }, + }; + #ifdef LC_CTYPE /* makes islower etc work for other langs */ (void)setlocale(LC_CTYPE, ""); @@ -223,6 +239,17 @@ main(int argc, char *argv[]) case 'd': flags |= MAGIC_DEBUG|MAGIC_CHECK; break; + case 'e': + for (i = 0; i < sizeof(nv) / sizeof(nv[0]); i++) + if (strcmp(nv[i].name, optarg) == 0) + break; + + if (i == sizeof(nv) / sizeof(nv[0])) + errflg++; + else + flags |= nv[i].value; + break; + case 'f': if(action) usage(); @@ -333,7 +360,7 @@ private void /*ARGSUSED*/ load(const char *m, int flags) { - if (magic) + if (magic || m == NULL) return; magic = magic_open(flags); if (magic == NULL) { @@ -404,7 +431,7 @@ process(const char *inname, int wid) if (wid > 0 && !bflag) { (void)printf("%s", std_in ? "/dev/stdin" : inname); if (nulsep) - (void)puts('\0'); + (void)putc('\0', stdout); else (void)printf("%s", separator); (void)printf("%*s ", @@ -535,6 +562,9 @@ help(void) " -c, --checking-printout print the parsed form of the magic file, use in\n" " conjunction with -m to debug a new magic file\n" " before installing it\n" +" -e, --exclude exclude test from the list of test to be\n" +" performed for file. Valid tests are:\n" +" ascii, apptype, elf, compress, soft, tar\n" " -f, --files-from FILE read the filenames to be examined from FILE\n" " -F, --separator string use string as separator instead of `:'\n" " -i, --mime output mime type strings\n" @@ -546,8 +576,12 @@ 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" +"or\n" " --help display this help and exit\n" +"or\n" " --version output version information and exit\n" +"or\n" +" -C, --compile compile file specified by -m\n" ); exit(0); } |