]> granicus.if.org Git - file/commitdiff
From Reuben Thomas:
authorChristos Zoulas <christos@zoulas.com>
Tue, 23 Oct 2007 19:58:59 +0000 (19:58 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 23 Oct 2007 19:58:59 +0000 (19:58 +0000)
- split mime into mime-type and mime-encoding
- fix usage string to be auto-generated from the options.

ChangeLog
doc/file.man
doc/libmagic.man
src/apprentice.c
src/file.c
src/file_opts.h [new file with mode: 0644]

index 40ca1da6f19bfc9c1a5163114e0046cefcdce4c6..c550afdd80e94a1fb3ec9849a26984871c98d6df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,15 @@
 
+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)
index 1d863a35061b84a7925c171778c49d963f18711e..fb2e1cb5dba80573c814b862cd1de09a3572a43b 100644 (file)
@@ -1,4 +1,4 @@
-.\" $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
@@ -8,6 +8,8 @@
 .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
@@ -226,9 +228,8 @@ is not defined.
 .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
@@ -238,6 +239,10 @@ file.
 (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
@@ -251,8 +256,9 @@ is defined.
 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
@@ -447,8 +453,7 @@ $ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
 
 $ 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
 
index eafa22647b75c97afc2fd58b5c69a36be558d30a..61e8f27e3d11307d2ab0b136da8bf0bb9db663a4 100644 (file)
@@ -87,8 +87,10 @@ If the file is compressed, unpack it and look at the contents.
 .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
@@ -164,7 +166,8 @@ The
 .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
index afdd237b41d53af470ca22d66dcc3bfb6a1f188d..155bf6e86c7b34ed109167af462c8bb67aaa3aba 100644 (file)
@@ -46,7 +46,7 @@
 #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) && \
@@ -261,7 +261,6 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
                rv = apprentice_file(ms, &magic, &nmagic, fn, action);
                if (rv != 0)
                        return -1;
-               mapped = 0;
        }
 
        mapped = rv;
@@ -296,10 +295,12 @@ file_delmagic(struct magic *p, int type, size_t entries)
        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*/
index e6dc6eb46ff9966cc8131f8b72288ccfc1ec1d69..557adb16a1305cccd4c5157a496c6a1b06e370f0 100644 (file)
@@ -133,37 +133,15 @@ main(int argc, char *argv[])
        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 {
@@ -228,10 +206,10 @@ main(int argc, char *argv[])
                        case 0:
                                help();
                                break;
-                       case 1:
+                       case 10:
                                flags |= MAGIC_MIME_TYPE;
                                break;
-                       case 2:
+                       case 11:
                                flags |= MAGIC_MIME_ENCODING;
                                break;
                        }
@@ -564,40 +542,15 @@ private void
 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
diff --git a/src/file_opts.h b/src/file_opts.h
new file mode 100644 (file)
index 0000000..f46cf99
--- /dev/null
@@ -0,0 +1,48 @@
+/* $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")