From owner-svn-src-head@FreeBSD.ORG Thu Jun 11 17:32:38 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0179A3B3; Thu, 11 Jun 2015 17:32:37 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E397E1F31; Thu, 11 Jun 2015 17:32:37 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5BHWblx092738; Thu, 11 Jun 2015 17:32:37 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t5BHWbbo092735; Thu, 11 Jun 2015 17:32:37 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201506111732.t5BHWbbo092735@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Thu, 11 Jun 2015 17:32:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284277 - in head/contrib/file: . src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jun 2015 17:32:38 -0000 Author: delphij Date: Thu Jun 11 17:32:36 2015 New Revision: 284277 URL: https://svnweb.freebsd.org/changeset/base/284277 Log: MFV r284276: Fix long options. Reported by: jkim MFC after: 13 days Modified: head/contrib/file/ChangeLog head/contrib/file/src/file.c head/contrib/file/src/file_opts.h Directory Properties: head/contrib/file/ (props changed) Modified: head/contrib/file/ChangeLog ============================================================================== --- head/contrib/file/ChangeLog Thu Jun 11 17:30:31 2015 (r284276) +++ head/contrib/file/ChangeLog Thu Jun 11 17:32:36 2015 (r284277) @@ -1,3 +1,6 @@ +2015-06-11 8:52 Christos Zoulas + + * redo long option encoding to fix off-by-one in 5.23 2015-06-10 13:50 Christos Zoulas Modified: head/contrib/file/src/file.c ============================================================================== --- head/contrib/file/src/file.c Thu Jun 11 17:30:31 2015 (r284276) +++ head/contrib/file/src/file.c Thu Jun 11 17:32:36 2015 (r284277) @@ -89,10 +89,15 @@ private int /* Global command-line opt private const char *separator = ":"; /* Default field separator */ private const struct option long_options[] = { +#define OPT_HELP 1 +#define OPT_APPLE 2 +#define OPT_EXTENSIONS 3 +#define OPT_MIME_TYPE 4 +#define OPT_MIME_ENCODING 5 #define OPT(shortname, longname, opt, doc) \ {longname, opt, NULL, shortname}, -#define OPT_LONGONLY(longname, opt, doc) \ - {longname, opt, NULL, 0}, +#define OPT_LONGONLY(longname, opt, doc, id) \ + {longname, opt, NULL, id}, #include "file_opts.h" #undef OPT #undef OPT_LONGONLY @@ -182,24 +187,20 @@ main(int argc, char *argv[]) while ((c = getopt_long(argc, argv, OPTSTRING, long_options, &longindex)) != -1) switch (c) { - case 0 : - switch (longindex) { - case 0: - help(); - break; - case 10: - flags |= MAGIC_APPLE; - break; - case 11: - flags |= MAGIC_EXTENSION; - break; - case 12: - flags |= MAGIC_MIME_TYPE; - break; - case 13: - flags |= MAGIC_MIME_ENCODING; - break; - } + case OPT_HELP: + help(); + break; + case OPT_APPLE: + flags |= MAGIC_APPLE; + break; + case OPT_EXTENSIONS: + flags |= MAGIC_EXTENSION; + break; + case OPT_MIME_TYPE: + flags |= MAGIC_MIME_TYPE; + break; + case OPT_MIME_ENCODING: + flags |= MAGIC_MIME_ENCODING; break; case '0': nulsep = 1; @@ -595,7 +596,7 @@ help(void) #define OPT(shortname, longname, opt, doc) \ fprintf(stdout, " -%c, --" longname, shortname), \ docprint(doc); -#define OPT_LONGONLY(longname, opt, doc) \ +#define OPT_LONGONLY(longname, opt, doc, id) \ fprintf(stdout, " --" longname), \ docprint(doc); #include "file_opts.h" Modified: head/contrib/file/src/file_opts.h ============================================================================== --- head/contrib/file/src/file_opts.h Thu Jun 11 17:30:31 2015 (r284276) +++ head/contrib/file/src/file_opts.h Thu Jun 11 17:32:36 2015 (r284277) @@ -12,7 +12,7 @@ * switch statement! */ -OPT_LONGONLY("help", 0, " display this help and exit\n") +OPT_LONGONLY("help", 0, " display this help and exit\n", OPT_HELP) 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") @@ -29,10 +29,10 @@ OPT('f', "files-from", 1, " FILE re 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("apple", 0, " output the Apple CREATOR/TYPE\n") -OPT_LONGONLY("extension", 0, " output a slash-separated list of extnsions\n") -OPT_LONGONLY("mime-type", 0, " output the MIME type\n") -OPT_LONGONLY("mime-encoding", 0, " output the MIME encoding\n") +OPT_LONGONLY("apple", 0, " output the Apple CREATOR/TYPE\n", OPT_APPLE) +OPT_LONGONLY("extension", 0, " output a slash-separated list of extensions\n", OPT_EXTENSIONS) +OPT_LONGONLY("mime-type", 0, " output the MIME type\n", OPT_MIME_TYPE) +OPT_LONGONLY("mime-encoding", 0, " output the MIME encoding\n", OPT_MIME_ENCODING) OPT('k', "keep-going", 0, " don't stop at the first match\n") OPT('l', "list", 0, " list magic strength\n") #ifdef S_IFLNK