Magellan Linux

Contents of /trunk/file/patches/file-5.23-fix-bug-with-long-options.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2583 - (show annotations) (download)
Thu Jun 18 06:44:53 2015 UTC (8 years, 10 months ago) by niro
File size: 3969 byte(s)
-fix option parsing bug
1 From 21f9d5f0e0340ada998f7f9d316368c7167a4afa Mon Sep 17 00:00:00 2001
2 From: Christos Zoulas <christos@zoulas.com>
3 Date: Thu, 11 Jun 2015 12:52:32 +0000
4 Subject: [PATCH] Fix bug with long options and explicitly number them to avoid
5 this in the future.
6
7 ---
8 src/file.c | 45 +++++++++++++++++++++++----------------------
9 src/file_opts.h | 10 +++++-----
10 2 files changed, 28 insertions(+), 27 deletions(-)
11
12 diff --git a/src/file.c b/src/file.c
13 index f60dde0..c700f66 100644
14 --- a/src/file.c
15 +++ b/src/file.c
16 @@ -89,10 +89,15 @@ private int /* Global command-line options */
17
18 private const char *separator = ":"; /* Default field separator */
19 private const struct option long_options[] = {
20 +#define OPT_HELP 1
21 +#define OPT_APPLE 2
22 +#define OPT_EXTENSIONS 3
23 +#define OPT_MIME_TYPE 4
24 +#define OPT_MIME_ENCODING 5
25 #define OPT(shortname, longname, opt, doc) \
26 {longname, opt, NULL, shortname},
27 -#define OPT_LONGONLY(longname, opt, doc) \
28 - {longname, opt, NULL, 0},
29 +#define OPT_LONGONLY(longname, opt, doc, id) \
30 + {longname, opt, NULL, id},
31 #include "file_opts.h"
32 #undef OPT
33 #undef OPT_LONGONLY
34 @@ -182,24 +187,20 @@ main(int argc, char *argv[])
35 while ((c = getopt_long(argc, argv, OPTSTRING, long_options,
36 &longindex)) != -1)
37 switch (c) {
38 - case 0 :
39 - switch (longindex) {
40 - case 0:
41 - help();
42 - break;
43 - case 10:
44 - flags |= MAGIC_APPLE;
45 - break;
46 - case 11:
47 - flags |= MAGIC_EXTENSION;
48 - break;
49 - case 12:
50 - flags |= MAGIC_MIME_TYPE;
51 - break;
52 - case 13:
53 - flags |= MAGIC_MIME_ENCODING;
54 - break;
55 - }
56 + case OPT_HELP:
57 + help();
58 + break;
59 + case OPT_APPLE:
60 + flags |= MAGIC_APPLE;
61 + break;
62 + case OPT_EXTENSIONS:
63 + flags |= MAGIC_EXTENSION;
64 + break;
65 + case OPT_MIME_TYPE:
66 + flags |= MAGIC_MIME_TYPE;
67 + break;
68 + case OPT_MIME_ENCODING:
69 + flags |= MAGIC_MIME_ENCODING;
70 break;
71 case '0':
72 nulsep = 1;
73 @@ -595,7 +596,7 @@ help(void)
74 #define OPT(shortname, longname, opt, doc) \
75 fprintf(stdout, " -%c, --" longname, shortname), \
76 docprint(doc);
77 -#define OPT_LONGONLY(longname, opt, doc) \
78 +#define OPT_LONGONLY(longname, opt, doc, id) \
79 fprintf(stdout, " --" longname), \
80 docprint(doc);
81 #include "file_opts.h"
82 diff --git a/src/file_opts.h b/src/file_opts.h
83 index 036505f..2e30d06 100644
84 --- a/src/file_opts.h
85 +++ b/src/file_opts.h
86 @@ -12,7 +12,7 @@
87 * switch statement!
88 */
89
90 -OPT_LONGONLY("help", 0, " display this help and exit\n")
91 +OPT_LONGONLY("help", 0, " display this help and exit\n", OPT_HELP)
92 OPT('v', "version", 0, " output version information and exit\n")
93 OPT('m', "magic-file", 1, " LIST use LIST as a colon-separated list of magic\n"
94 " number files\n")
95 @@ -29,10 +29,10 @@ OPT('f', "files-from", 1, " FILE read the filenames to be examined from FIL
96 OPT('F', "separator", 1, " STRING use string as separator instead of `:'\n")
97 OPT('i', "mime", 0, " output MIME type strings (--mime-type and\n"
98 " --mime-encoding)\n")
99 -OPT_LONGONLY("apple", 0, " output the Apple CREATOR/TYPE\n")
100 -OPT_LONGONLY("extension", 0, " output a slash-separated list of extnsions\n")
101 -OPT_LONGONLY("mime-type", 0, " output the MIME type\n")
102 -OPT_LONGONLY("mime-encoding", 0, " output the MIME encoding\n")
103 +OPT_LONGONLY("apple", 0, " output the Apple CREATOR/TYPE\n", OPT_APPLE)
104 +OPT_LONGONLY("extension", 0, " output a slash-separated list of extensions\n", OPT_EXTENSIONS)
105 +OPT_LONGONLY("mime-type", 0, " output the MIME type\n", OPT_MIME_TYPE)
106 +OPT_LONGONLY("mime-encoding", 0, " output the MIME encoding\n", OPT_MIME_ENCODING)
107 OPT('k', "keep-going", 0, " don't stop at the first match\n")
108 OPT('l', "list", 0, " list magic strength\n")
109 #ifdef S_IFLNK