+2007-10-20 3:06 Christos Zoulas <christos@zoulas.com>
+
+ * typo in comment, missing ifdef QUICK, remove unneeded code
+ (Charles Longeau)
+
+2007-10-17 3:33 Christos Zoulas <christos@zoulas.com>
+
+ * Fix problem printing -\012 in some entries
+
+ * Separate magic type and encoding flags (Reuben Thomas)
+
2007-10-09 3:55 Christos Zoulas <christos@zoulas.com>
* configure fix for int64 and strndup (Reuben Thomas)
-.\" $File: file.man,v 1.63 2007/01/10 23:00:16 christos Exp $
+.\" $File: file.man,v 1.65 2007/01/25 21:05:46 christos Exp $
.Dd January 8, 2007
.Dt FILE __CSECTION__
.Os
.Sh SYNOPSIS
.Nm
.Op Fl bchikLnNprsvz
+.Op Fl mime-type
+.Op Fl mime-encoding
.Op Fl f Ar namefile
.Op Fl F Ar separator
.Op Fl m Ar magicfiles
.It Fl i , -mime
Causes the file command to output mime type strings rather than the more
traditional human readable ones. Thus it may say
-.Dq text/plain; charset=us-ascii
-rather
-than
+.Dq text/plain charset=us-ascii
+rather than
.Dq ASCII text .
In order for this option to work, file changes the way
it handles files recognized by the command itself (such as many of the
(See
.Dq FILES
section, below).
+.It Fl -mime-type , -mime-encoding
+Like
+.Fl i ,
+but print only the specified element(s).
.It Fl k , -keep-going
Don't stop at the first match, keep going.
.It Fl L , -dereference
Specify an alternate list of files containing magic numbers.
This can be a single file, or a colon-separated list of files.
If a compiled magic file is found alongside, it will be used instead.
-With the
-.Fl i or
+With the
+.Fl i
+or
.Fl "mime"
option, the program adds
.Dq .mime
$ file -i file.c file /dev/{wd0a,hda}
file.c: text/x-c
-file: application/x-executable, dynamically linked (uses shared libs),
- not stripped
+file: application/x-executable
/dev/hda: application/x-not-regular-file
/dev/wd0a: application/x-not-regular-file
.It Dv MAGIC_DEVICES
If the file is a block or character special device, then open the device
and try to look in its contents.
-.It Dv MAGIC_MIME
-Return a mime string, instead of a textual description.
+.It Dv MAGIC_MIME_TYPE
+Return a MIME type string, instead of a textual description.
+.It Dv MAGIC_MIME_ENCODING
+Return a MIME encoding, instead of a textual description.
.It Dv MAGIC_CONTINUE
Return all matches, not just the first.
.It Dv MAGIC_CHECK
.Fn magic_setflags
function, sets the
.Ar flags
-described above.
+described above. Note that using both MIME flags together can also
+return extra information on the charset.
.Pp
The
.Fn magic_check
#endif
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.104 2007/01/19 19:54:39 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.105 2007/05/16 20:51:40 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
rv = apprentice_file(ms, &magic, &nmagic, fn, action);
if (rv != 0)
return -1;
- mapped = 0;
}
mapped = rv;
if (p == NULL)
return;
switch (type) {
+#ifdef QUICK
case 2:
p--;
(void)munmap((void *)p, sizeof(*p) * (entries + 1));
break;
+#endif
case 1:
p--;
/*FALLTHROUGH*/
int longindex;
static const struct option long_options[] =
{
- /* Put long-only options first */
- {"help", 0, 0, 0},
- {"mime-type", 0, 0, 0},
- {"mime-encoding", 0, 0, 0},
-
- {"version", 0, 0, 'v'},
- {"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'},
- {"keep-going", 0, 0, 'k'},
-#ifdef S_IFLNK
- {"dereference", 0, 0, 'L'},
- {"no-dereference", 0, 0, 'h'},
-#endif
- {"magic-file", 1, 0, 'm'},
-#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
- {"preserve-date", 0, 0, 'p'},
-#endif
- {"uncompress", 0, 0, 'z'},
- {"raw", 0, 0, 'r'},
- {"no-buffer", 0, 0, 'n'},
- {"no-pad", 0, 0, 'N'},
- {"special-files", 0, 0, 's'},
- {"compile", 0, 0, 'C'},
- {"print0", 0, 0, '0'},
- {0, 0, 0, 0},
- };
+#define OPT(shortname, longname, opt, doc) \
+ {longname, opt, NULL, shortname},
+#define OPT_LONGONLY(longname, opt, doc) \
+ {longname, opt, NULL, 0},
+#include "file_opts.h"
+#undef OPT
+#undef OPT_LONGONLY
+ {0, 0, NULL, 0}
+};
#endif
static const struct {
case 0:
help();
break;
- case 1:
+ case 10:
flags |= MAGIC_MIME_TYPE;
break;
- case 2:
+ case 11:
flags |= MAGIC_MIME_ENCODING;
break;
}
help(void)
{
(void)puts(
-"Usage: file [OPTION]... [FILE]...\n"
-"Determine file type of FILEs.\n"
-"\n"
-" -m, --magic-file LIST use LIST as a colon-separated list of magic\n"
-" number files\n"
-" -z, --uncompress try to look inside compressed files\n"
-" -b, --brief do not prepend filenames to output lines\n"
-" -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 (--mime-type and\n"
-" --mime-encoding)\n"
-" --mime-type output the MIME type\n"
-" --mime-encoding output the MIME encoding\n"
-" -k, --keep-going don't stop at the first match\n"
-" -L, --dereference causes symlinks to be followed\n"
-" -n, --no-buffer do not buffer output\n"
-" -N, --no-pad do not pad output\n"
-" -p, --preserve-date preserve access times on files\n"
-" -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"
-);
+"Usage: file [OPTION...] [FILE...]\n"
+"Determine file type of FILEs.\n");
+#define OPT(shortname, longname, opt, doc) \
+ printf(" -%c, --" longname doc, shortname);
+#define OPT_LONGONLY(longname, opt, doc) \
+ printf(" --" longname doc);
+#include "file_opts.h"
+#undef OPT
+#undef OPT_LONGONLY
exit(0);
}
#endif
--- /dev/null
+/* $File$ */
+
+/*
+ * Table of command-line options
+ *
+ * The first column specifies the short name, if any, or 0 if none.
+ * The second column specifies the long name.
+ * The third column specifies whether it takes a parameter.
+ * The fourth column is the documentation.
+ *
+ * N.B. The long options' order must correspond to the code in file.c,
+ * and OPTSTRING must be kept up-to-date with the short options.
+ */
+
+OPT_LONGONLY("help", 0, " display this help and exit\n")
+OPT('v', "version", 0, " output version information and exit\n")
+OPT('m', "magic-file", 1, " LIST use LIST as a colon-separated list of magic\n"
+ " number files\n")
+OPT('z', "uncompress", 0, " try to look inside compressed files\n")
+OPT('b', "brief", 0, " do not prepend filenames to output lines\n")
+OPT('c', "checking-printout", 0, " 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")
+OPT('e', "exclude", 1, " TEST exclude TEST from the list of test to be\n"
+ " performed for file. Valid tests are:\n"
+ " ascii, apptype, elf, compress, soft, tar\n")
+OPT('f', "files-from", 1, " FILE read the filenames to be examined from FILE\n")
+OPT('F', "separator", 1, " STRING use string as separator instead of `:'\n")
+OPT('i', "mime", 0, " output MIME type strings (--mime-type and\n"
+ " --mime-encoding)\n")
+OPT_LONGONLY("mime-type", 0, " output the MIME type\n")
+OPT_LONGONLY("mime-encoding", 0, " output the MIME encoding\n")
+OPT('k', "keep-going", 0, " don't stop at the first match\n")
+#ifdef S_IFLNK
+OPT('L', "dereference", 0, " follow symlinks (default)\n")
+OPT('h', "no-dereference", 0, " don't follow symlinks\n")
+#endif
+OPT('n', "no-buffer", 0, " do not buffer output\n")
+OPT('N', "no-pad", 0, " do not pad output\n")
+OPT('0', "print0", 0, " terminate filenames with ASCII NUL\n")
+#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
+OPT('p', "preserve-date", 0, " preserve access times on files\n")
+#endif
+OPT('r', "raw", 0, " don't translate unprintable chars to \\ooo\n")
+OPT('s', "special-files", 0, " treat special (block/char devices) files as\n"
+ " ordinary ones\n")
+OPT('C', "compile", 0, " compile file specified by -m\n")
+OPT('d', "debug", 0, " print debugging messages\n")