From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Tue, 28 Jan 2014 13:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 16578@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.139091561326711 (code B ref -1); Tue, 28 Jan 2014 13:27:01 +0000 Received: (at submit) by debbugs.gnu.org; 28 Jan 2014 13:26:53 +0000 Received: from localhost ([127.0.0.1]:38758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W88gn-0006wk-12 for submit@debbugs.gnu.org; Tue, 28 Jan 2014 08:26:53 -0500 Received: from eggs.gnu.org ([208.118.235.92]:42792) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W88gk-0006wb-CP for submit@debbugs.gnu.org; Tue, 28 Jan 2014 08:26:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W88gf-0003yW-GP for submit@debbugs.gnu.org; Tue, 28 Jan 2014 08:26:49 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:37598) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W88gf-0003yS-D1 for submit@debbugs.gnu.org; Tue, 28 Jan 2014 08:26:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W88ga-0008U8-Rf for bug-coreutils@gnu.org; Tue, 28 Jan 2014 08:26:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W88gZ-0003we-QB for bug-coreutils@gnu.org; Tue, 28 Jan 2014 08:26:40 -0500 Received: from bacon.lysator.liu.se ([2001:6b0:17:f0a0::ce]:51918) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W88gZ-0003uH-E5 for bug-coreutils@gnu.org; Tue, 28 Jan 2014 08:26:39 -0500 Received: from bacon.lysator.liu.se (localhost [127.0.0.1]) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5) with ESMTP id s0SCsl6G019526 for ; Tue, 28 Jan 2014 13:54:47 +0100 (MET) Received: (from nisse@localhost) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5/Submit) id s0SCsleM019525; Tue, 28 Jan 2014 13:54:47 +0100 (MET) X-Authentication-Warning: bacon.lysator.liu.se: nisse set sender to nisse@lysator.liu.se using -f From: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) Date: Tue, 28 Jan 2014 13:54:47 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (usg-unix-v) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by bacon.lysator.liu.se id s0SCsl6G019526 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.3 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.3 (----) For the "od" program, it would be nice with a flag to specify the endianness for all types which are larger than a byte. Possible alternatives could be "big endian", "little endian", "native endian". And for floats, besides endianness, it would be nice to be able to specify native format or ieee format, for systems where these are different. Regards, /Niels --=20 Niels M=F6ller. PGP-encrypted email is preferred. Keyid C0B98E26. Internet email is subject to wholesale government surveillance. From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 29 Jan 2014 21:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Niels =?UTF-8?Q?M=C3=B6ller?= Cc: 16578@debbugs.gnu.org Received: via spool by 16578-submit@debbugs.gnu.org id=B16578.13910318899161 (code B ref 16578); Wed, 29 Jan 2014 21:45:02 +0000 Received: (at 16578) by debbugs.gnu.org; 29 Jan 2014 21:44:49 +0000 Received: from localhost ([127.0.0.1]:40715 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W8cwC-0002Ne-Cb for submit@debbugs.gnu.org; Wed, 29 Jan 2014 16:44:48 -0500 Received: from mail6.vodafone.ie ([213.233.128.184]:4935) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W8cw8-0002NT-Qz for 16578@debbugs.gnu.org; Wed, 29 Jan 2014 16:44:45 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApMBACd16VJtTv4m/2dsb2JhbAANTL4igwaBHIMZAQEBAwEyAUYFCwsNCwkWDwkDAgECAUUGDQEHAQGHeQ2pfaAoF45/B4Q4AQOUQIpYjlw Received: from unknown (HELO [192.168.1.79]) ([109.78.254.38]) by mail3.vodafone.ie with ESMTP; 29 Jan 2014 21:44:42 +0000 Message-ID: <52E97649.6010905@draigBrady.com> Date: Wed, 29 Jan 2014 21:44:41 +0000 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 References: In-Reply-To: X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 01/28/2014 12:54 PM, Niels Möller wrote: > For the "od" program, it would be nice with a flag to specify the > endianness for all types which are larger than a byte. Possible > alternatives could be "big endian", "little endian", "native endian". I agree this would be useful and easy enough to add. I suppose the interface would be --endian=little|big We could augment that with specific byte order spec, but those two are probably enough. > And for floats, besides endianness, it would be nice to be able to > specify native format or ieee format, for systems where these are > different. That's a bit less useful I think and harder to implement. We say this in the info docs: "Almost all modern systems use IEEE-754 floating point, and it is typically portable to assume IEEE-754 behavior these days." thanks, Pádraig. From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Fri, 31 Jan 2014 06:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 16578@debbugs.gnu.org Received: via spool by 16578-submit@debbugs.gnu.org id=B16578.139115142725956 (code B ref 16578); Fri, 31 Jan 2014 06:58:01 +0000 Received: (at 16578) by debbugs.gnu.org; 31 Jan 2014 06:57:07 +0000 Received: from localhost ([127.0.0.1]:42241 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W982E-0006ka-2Q for submit@debbugs.gnu.org; Fri, 31 Jan 2014 01:57:06 -0500 Received: from bacon.lysator.liu.se ([130.236.254.206]:40896) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W982A-0006k9-O9 for 16578@debbugs.gnu.org; Fri, 31 Jan 2014 01:57:04 -0500 Received: from bacon.lysator.liu.se (localhost [127.0.0.1]) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5) with ESMTP id s0V6v1Ov018809; Fri, 31 Jan 2014 07:57:01 +0100 (MET) Received: (from nisse@localhost) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5/Submit) id s0V6v0vk018804; Fri, 31 Jan 2014 07:57:00 +0100 (MET) X-Authentication-Warning: bacon.lysator.liu.se: nisse set sender to nisse@lysator.liu.se using -f From: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) References: <52E97649.6010905@draigBrady.com> Date: Fri, 31 Jan 2014 07:57:00 +0100 In-Reply-To: <52E97649.6010905@draigBrady.com> ("=?UTF-8?Q?P=C3=A1draig?= Brady"'s message of "Wed, 29 Jan 2014 21:44:41 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (usg-unix-v) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.2 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.2 (/) Pádraig Brady writes: > On 01/28/2014 12:54 PM, Niels Möller wrote: >> For the "od" program, it would be nice with a flag to specify the >> endianness for all types which are larger than a byte. Possible >> alternatives could be "big endian", "little endian", "native endian". > > I agree this would be useful and easy enough to add. > I suppose the interface would be --endian=little|big Maybe I can have a look at what it takes. >> And for floats, besides endianness, it would be nice to be able to >> specify native format or ieee format, for systems where these are >> different. > > That's a bit less useful I think and harder to implement. I agree that's a bit more obscure. So I understand if you don't want to do that until there's some concrete usecase. Endianness for float types should be easier, I hope. Regards, /Niels -- Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26. Internet email is subject to wholesale government surveillance. From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Fri, 31 Jan 2014 08:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 16578@debbugs.gnu.org Received: via spool by 16578-submit@debbugs.gnu.org id=B16578.139115790121604 (code B ref 16578); Fri, 31 Jan 2014 08:45:01 +0000 Received: (at 16578) by debbugs.gnu.org; 31 Jan 2014 08:45:01 +0000 Received: from localhost ([127.0.0.1]:42344 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W99id-0005cL-Oa for submit@debbugs.gnu.org; Fri, 31 Jan 2014 03:45:00 -0500 Received: from bacon.lysator.liu.se ([130.236.254.206]:43262) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W99ia-0005c9-D2 for 16578@debbugs.gnu.org; Fri, 31 Jan 2014 03:44:57 -0500 Received: from bacon.lysator.liu.se (localhost [127.0.0.1]) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5) with ESMTP id s0V8is5F021950; Fri, 31 Jan 2014 09:44:54 +0100 (MET) Received: (from nisse@localhost) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5/Submit) id s0V8islU021949; Fri, 31 Jan 2014 09:44:54 +0100 (MET) X-Authentication-Warning: bacon.lysator.liu.se: nisse set sender to nisse@lysator.liu.se using -f From: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) References: <52E97649.6010905@draigBrady.com> Date: Fri, 31 Jan 2014 09:44:54 +0100 In-Reply-To: ("Niels =?UTF-8?Q?M=C3=B6ller?="'s message of "Fri, 31 Jan 2014 07:57:00 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (usg-unix-v) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.2 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.2 (/) nisse@lysator.liu.se (Niels Möller) writes: > Pádraig Brady writes: >> I agree this would be useful and easy enough to add. >> I suppose the interface would be --endian=little|big > > Maybe I can have a look at what it takes. Below is a crude patch (missing: usage message, tests cases, docs, translation). I think it should work fine for floats too. I see no obvious and more beautiful way to do it. (And I think I have copyright assignment papers for coreutils in place, since work on factor some year ago). Regards, /Niels diff --git a/src/od.c b/src/od.c index 514fe50..a71e302 100644 --- a/src/od.c +++ b/src/od.c @@ -259,13 +259,16 @@ static enum size_spec integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1]; #define MAX_FP_TYPE_SIZE sizeof (long double) static enum size_spec fp_type_size[MAX_FP_TYPE_SIZE + 1]; +bool input_swap; + static char const short_options[] = "A:aBbcDdeFfHhIij:LlN:OoS:st:vw::Xx"; /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum { - TRADITIONAL_OPTION = CHAR_MAX + 1 + TRADITIONAL_OPTION = CHAR_MAX + 1, + ENDIAN_OPTION, }; static struct option const long_options[] = @@ -278,6 +281,7 @@ static struct option const long_options[] = {"strings", optional_argument, NULL, 'S'}, {"traditional", no_argument, NULL, TRADITIONAL_OPTION}, {"width", optional_argument, NULL, 'w'}, + {"endian", required_argument, NULL, ENDIAN_OPTION }, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, @@ -406,7 +410,21 @@ N (size_t fields, size_t blank, void const *block, \ { \ int next_pad = pad * (i - 1) / fields; \ int adjusted_width = pad_remaining - next_pad + width; \ - T x = *p++; \ + T x; \ + if (input_swap && sizeof(T) > 1) \ + { \ + int j; \ + union { \ + T x; \ + char b[sizeof(T)]; \ + } u; \ + for (j = 0; j < sizeof(T); j++) \ + u.b[j] = ((const char *) p)[sizeof(T) - 1 - j]; \ + x = u.x; \ + } \ + else \ + x = *p; \ + p++; \ ACTION; \ pad_remaining = next_pad; \ } \ @@ -1664,6 +1682,24 @@ main (int argc, char **argv) traditional = true; break; + case ENDIAN_OPTION: + if (!strcmp (optarg, "big")) + { +#if !WORDS_BIGENDIAN + input_swap = true; +#endif + } + else if (!strcmp (optarg, "little")) + { +#if WORDS_BIGENDIAN + input_swap = true; +#endif + } + else + error (EXIT_FAILURE, 0, + _("bad argument '%s' for --endian option"), optarg); + break; + /* The next several cases map the traditional format specification options to the corresponding modern format specs. GNU od accepts any combination of old- and -- Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26. Internet email is subject to wholesale government surveillance. From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Sun, 02 Feb 2014 01:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Niels =?UTF-8?Q?M=C3=B6ller?= Cc: 16578@debbugs.gnu.org Received: via spool by 16578-submit@debbugs.gnu.org id=B16578.1391304019679 (code B ref 16578); Sun, 02 Feb 2014 01:21:01 +0000 Received: (at 16578) by debbugs.gnu.org; 2 Feb 2014 01:20:19 +0000 Received: from localhost ([127.0.0.1]:45523 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W9ljO-0000As-MJ for submit@debbugs.gnu.org; Sat, 01 Feb 2014 20:20:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:4241) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W9ljM-0000Ak-CX for 16578@debbugs.gnu.org; Sat, 01 Feb 2014 20:20:17 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s121KEBB032739 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 1 Feb 2014 20:20:14 -0500 Received: from [10.36.116.21] (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s121KCdE016130 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sat, 1 Feb 2014 20:20:13 -0500 Message-ID: <52ED9D4B.8000009@draigBrady.com> Date: Sun, 02 Feb 2014 02:20:11 +0100 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 References: <52E97649.6010905@draigBrady.com> In-Reply-To: X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) On 01/31/2014 09:44 AM, Niels Möller wrote: > nisse@lysator.liu.se (Niels Möller) writes: > >> Pádraig Brady writes: >>> I agree this would be useful and easy enough to add. >>> I suppose the interface would be --endian=little|big >> >> Maybe I can have a look at what it takes. > > Below is a crude patch (missing: usage message, tests cases, docs, > translation). I think it should work fine for floats too. I see no > obvious and more beautiful way to do it. > > (And I think I have copyright assignment papers for coreutils in place, > since work on factor some year ago). > > Regards, > /Niels > > diff --git a/src/od.c b/src/od.c > index 514fe50..a71e302 100644 > --- a/src/od.c > +++ b/src/od.c > @@ -259,13 +259,16 @@ static enum size_spec integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1]; > #define MAX_FP_TYPE_SIZE sizeof (long double) > static enum size_spec fp_type_size[MAX_FP_TYPE_SIZE + 1]; > > +bool input_swap; > + > static char const short_options[] = "A:aBbcDdeFfHhIij:LlN:OoS:st:vw::Xx"; > > /* For long options that have no equivalent short option, use a > non-character as a pseudo short option, starting with CHAR_MAX + 1. */ > enum > { > - TRADITIONAL_OPTION = CHAR_MAX + 1 > + TRADITIONAL_OPTION = CHAR_MAX + 1, > + ENDIAN_OPTION, > }; > > static struct option const long_options[] = > @@ -278,6 +281,7 @@ static struct option const long_options[] = > {"strings", optional_argument, NULL, 'S'}, > {"traditional", no_argument, NULL, TRADITIONAL_OPTION}, > {"width", optional_argument, NULL, 'w'}, > + {"endian", required_argument, NULL, ENDIAN_OPTION }, > > {GETOPT_HELP_OPTION_DECL}, > {GETOPT_VERSION_OPTION_DECL}, > @@ -406,7 +410,21 @@ N (size_t fields, size_t blank, void const *block, \ > { \ > int next_pad = pad * (i - 1) / fields; \ > int adjusted_width = pad_remaining - next_pad + width; \ > - T x = *p++; \ > + T x; \ > + if (input_swap && sizeof(T) > 1) \ > + { \ > + int j; \ > + union { \ > + T x; \ > + char b[sizeof(T)]; \ > + } u; \ > + for (j = 0; j < sizeof(T); j++) \ > + u.b[j] = ((const char *) p)[sizeof(T) - 1 - j]; \ > + x = u.x; \ > + } \ > + else \ > + x = *p; \ > + p++; \ > ACTION; \ > pad_remaining = next_pad; \ > } \ > @@ -1664,6 +1682,24 @@ main (int argc, char **argv) > traditional = true; > break; > > + case ENDIAN_OPTION: > + if (!strcmp (optarg, "big")) > + { > +#if !WORDS_BIGENDIAN > + input_swap = true; > +#endif > + } > + else if (!strcmp (optarg, "little")) > + { > +#if WORDS_BIGENDIAN > + input_swap = true; > +#endif > + } > + else > + error (EXIT_FAILURE, 0, > + _("bad argument '%s' for --endian option"), optarg); > + break; > + > /* The next several cases map the traditional format > specification options to the corresponding modern format > specs. GNU od accepts any combination of old- and That looks good. I'll adjust slightly to use XARGMATCH and add some docs/tests. I'm travelling at the moment but merge this soon. thanks! Pádraig. From unknown Sun Jun 15 08:53:32 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) Subject: bug#16578: closed (Re: bug#16578: Wish: Support for non-native endianness in od) Message-ID: References: <52F6A940.7040701@draigBrady.com> X-Gnu-PR-Message: they-closed 16578 X-Gnu-PR-Package: coreutils Reply-To: 16578@debbugs.gnu.org Date: Sat, 08 Feb 2014 22:02:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1391896923-27042-1" This is a multi-part message in MIME format... ------------=_1391896923-27042-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #16578: Wish: Support for non-native endianness in od which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 16578@debbugs.gnu.org. --=20 16578: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D16578 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1391896923-27042-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 16578-done) by debbugs.gnu.org; 8 Feb 2014 22:01:49 +0000 Received: from localhost ([127.0.0.1]:58295 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCFy6-00071Y-2c for submit@debbugs.gnu.org; Sat, 08 Feb 2014 17:01:49 -0500 Received: from mail1.vodafone.ie ([213.233.128.43]:39879) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCFy0-00071K-KM for 16578-done@debbugs.gnu.org; Sat, 08 Feb 2014 17:01:44 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQBAHao9lJtTZAw/2dsb2JhbAANTINEwC+BH4MZAQEBBHkQCw0EAQIBAgEJFg8JAwIBAgE3BggGDQEFAgEBBRGHcKgJoTAXjmwRBwYDhC8Ejj+CAIEyglGFG4U+hXGIbQ Received: from unknown (HELO [192.168.1.79]) ([109.77.144.48]) by mail1.vodafone.ie with ESMTP; 08 Feb 2014 22:01:37 +0000 Message-ID: <52F6A940.7040701@draigBrady.com> Date: Sat, 08 Feb 2014 22:01:36 +0000 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: =?ISO-8859-1?Q?Niels_M=F6ller?= Subject: Re: bug#16578: Wish: Support for non-native endianness in od References: <52E97649.6010905@draigBrady.com> <52ED9D4B.8000009@draigBrady.com> In-Reply-To: <52ED9D4B.8000009@draigBrady.com> X-Enigmail-Version: 1.6 Content-Type: multipart/mixed; boundary="------------060000030701070400050708" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 16578-done Cc: 16578-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) This is a multi-part message in MIME format. --------------060000030701070400050708 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit On 02/02/2014 01:20 AM, Pádraig Brady wrote: > On 01/31/2014 09:44 AM, Niels Möller wrote: >> nisse@lysator.liu.se (Niels Möller) writes: >> >>> Pádraig Brady writes: >>>> I agree this would be useful and easy enough to add. >>>> I suppose the interface would be --endian=little|big >>> >>> Maybe I can have a look at what it takes. >> >> Below is a crude patch (missing: usage message, tests cases, docs, >> translation). I think it should work fine for floats too. I see no >> obvious and more beautiful way to do it. >> >> (And I think I have copyright assignment papers for coreutils in place, >> since work on factor some year ago). >> >> Regards, >> /Niels >> >> diff --git a/src/od.c b/src/od.c >> index 514fe50..a71e302 100644 >> --- a/src/od.c >> +++ b/src/od.c >> @@ -259,13 +259,16 @@ static enum size_spec integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1]; >> #define MAX_FP_TYPE_SIZE sizeof (long double) >> static enum size_spec fp_type_size[MAX_FP_TYPE_SIZE + 1]; >> >> +bool input_swap; >> + >> static char const short_options[] = "A:aBbcDdeFfHhIij:LlN:OoS:st:vw::Xx"; >> >> /* For long options that have no equivalent short option, use a >> non-character as a pseudo short option, starting with CHAR_MAX + 1. */ >> enum >> { >> - TRADITIONAL_OPTION = CHAR_MAX + 1 >> + TRADITIONAL_OPTION = CHAR_MAX + 1, >> + ENDIAN_OPTION, >> }; >> >> static struct option const long_options[] = >> @@ -278,6 +281,7 @@ static struct option const long_options[] = >> {"strings", optional_argument, NULL, 'S'}, >> {"traditional", no_argument, NULL, TRADITIONAL_OPTION}, >> {"width", optional_argument, NULL, 'w'}, >> + {"endian", required_argument, NULL, ENDIAN_OPTION }, >> >> {GETOPT_HELP_OPTION_DECL}, >> {GETOPT_VERSION_OPTION_DECL}, >> @@ -406,7 +410,21 @@ N (size_t fields, size_t blank, void const *block, \ >> { \ >> int next_pad = pad * (i - 1) / fields; \ >> int adjusted_width = pad_remaining - next_pad + width; \ >> - T x = *p++; \ >> + T x; \ >> + if (input_swap && sizeof(T) > 1) \ >> + { \ >> + int j; \ >> + union { \ >> + T x; \ >> + char b[sizeof(T)]; \ >> + } u; \ >> + for (j = 0; j < sizeof(T); j++) \ >> + u.b[j] = ((const char *) p)[sizeof(T) - 1 - j]; \ >> + x = u.x; \ >> + } \ >> + else \ >> + x = *p; \ >> + p++; \ >> ACTION; \ >> pad_remaining = next_pad; \ >> } \ >> @@ -1664,6 +1682,24 @@ main (int argc, char **argv) >> traditional = true; >> break; >> >> + case ENDIAN_OPTION: >> + if (!strcmp (optarg, "big")) >> + { >> +#if !WORDS_BIGENDIAN >> + input_swap = true; >> +#endif >> + } >> + else if (!strcmp (optarg, "little")) >> + { >> +#if WORDS_BIGENDIAN >> + input_swap = true; >> +#endif >> + } >> + else >> + error (EXIT_FAILURE, 0, >> + _("bad argument '%s' for --endian option"), optarg); >> + break; >> + >> /* The next several cases map the traditional format >> specification options to the corresponding modern format >> specs. GNU od accepts any combination of old- and > > That looks good. > I'll adjust slightly to use XARGMATCH and add some docs/tests. > I'm travelling at the moment but merge this soon. Attached in the patch I intend to push in your name. I changed the option handling to reuse the XARGMATCH functionality. Also I changed things slightly so as the last --endian option specified wins. Previously we only set the input_swap variable to true, never to false. On a related point I set the input_swap global to be static. I also added docs to usage() and the texinfo file, and added a test. BTW I checked if there was any speed difference with the new code. I wasn't expecting this to be a bottleneck, and true enough there is only a marginal change. The new code is consistently a little _faster_ though on my i3-2310M which is a bit surprising. $ truncate -s1G od.in $ time od.old -tx8 od.in 5.05 elapsed $ time od.new -tx8 --endian=bug od.in 4.97 elapsed My hunch is there is more pretching happening in the new version, but can't check on this system due to: $ perf stat -e L1-dcache-prefetches:u true L1-dcache-prefetches:u For kicks I put in bswap_{16,32,64}() calls which are guaranteed available by gnulib, but replaced with architecture specific asm on this system, and the speed regressed back to that of od.old. thanks, Pádraig. --------------060000030701070400050708 Content-Type: text/x-patch; name="od--endian.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="od--endian.patch" >From 9069a82ce4b1411a2f56c8bf458a8d8d74e3a7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Fri, 31 Jan 2014 17:39:52 +0100 Subject: [PATCH] od: add an --endian option to control byte swapping * src/od.c (main): Handle the new --endian option, taking "little" and "big" as parameters. (usage): Describe the new option. (PRINT_FIELDS): Adjust to swap bytes if required. * tests/misc/od-endian.sh: A new test to verify the byte swapping operations for hex (ints) and floats for all sizes between 1 and 16 inclusive. * test/local.mk: Reference the new test. * doc/coreutils.texi (od invocation): Describe the new option. * NEWS: Mention the new feature. --- NEWS | 5 ++++ doc/coreutils.texi | 10 ++++++++ src/od.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-- tests/local.mk | 1 + tests/misc/od-endian.sh | 38 ++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 3 deletions(-) create mode 100755 tests/misc/od-endian.sh diff --git a/NEWS b/NEWS index e091d18..0da82ac 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,11 @@ GNU coreutils NEWS -*- outline -*- it would display an error, requiring --no-dereference to avoid the issue. [bug introduced in coreutils-5.3.0] +** New features + + od accepts a new option: --endian=TYPE to handle inputs with different byte + orders, or to provide consistent output on systems with disparate endianness. + ** Improvements stat and tail work better with HFS+ and HFSX. stat -f --format=%T now reports diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 35e7bd9..3269291 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -1868,6 +1868,16 @@ none (do not print offsets). The default is octal. +@item --endian=@var{order} +@opindex --endian +@cindex byte-swapping +@cindex endianness +Reorder input bytes, to handle inputs with differing byte orders, +or to provide consistent output independent of the endian convention +of the current system. Swapping is performed according to the +specified @option{--type} size and endian @var{order}, which can be +@samp{little} or @samp{big}. + @item -j @var{bytes} @itemx --skip-bytes=@var{bytes} @opindex -j diff --git a/src/od.c b/src/od.c index 514fe50..2784ea7 100644 --- a/src/od.c +++ b/src/od.c @@ -23,6 +23,7 @@ #include #include #include "system.h" +#include "argmatch.h" #include "error.h" #include "ftoastr.h" #include "quote.h" @@ -259,13 +260,37 @@ static enum size_spec integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1]; #define MAX_FP_TYPE_SIZE sizeof (long double) static enum size_spec fp_type_size[MAX_FP_TYPE_SIZE + 1]; +#ifndef WORDS_BIGENDIAN +# define WORDS_BIGENDIAN 0 +#endif + +/* Use native endianess by default. */ +static bool input_swap; + static char const short_options[] = "A:aBbcDdeFfHhIij:LlN:OoS:st:vw::Xx"; /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum { - TRADITIONAL_OPTION = CHAR_MAX + 1 + TRADITIONAL_OPTION = CHAR_MAX + 1, + ENDIAN_OPTION, +}; + +enum endian_type +{ + endian_little, + endian_big +}; + +static char const *const endian_args[] = +{ + "little", "big", NULL +}; + +static enum endian_type const endian_types[] = +{ + endian_little, endian_big }; static struct option const long_options[] = @@ -278,6 +303,7 @@ static struct option const long_options[] = {"strings", optional_argument, NULL, 'S'}, {"traditional", no_argument, NULL, TRADITIONAL_OPTION}, {"width", optional_argument, NULL, 'w'}, + {"endian", required_argument, NULL, ENDIAN_OPTION }, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, @@ -318,6 +344,7 @@ suffixes may be . for octal and b for multiply by 512.\n\ fputs (_("\ -A, --address-radix=RADIX output format for file offsets; RADIX is one\n\ of [doxn], for Decimal, Octal, Hex or None\n\ + --endian={big|little} swap input bytes according the specified order\n\ -j, --skip-bytes=BYTES skip BYTES input bytes first\n\ "), stdout); fputs (_("\ @@ -400,13 +427,27 @@ N (size_t fields, size_t blank, void const *block, \ char const *FMT_STRING, int width, int pad) \ { \ T const *p = block; \ - uintmax_t i; \ + uintmax_t i; \ int pad_remaining = pad; \ for (i = fields; blank < i; i--) \ { \ int next_pad = pad * (i - 1) / fields; \ int adjusted_width = pad_remaining - next_pad + width; \ - T x = *p++; \ + T x; \ + if (input_swap && sizeof (T) > 1) \ + { \ + int j; \ + union { \ + T x; \ + char b[sizeof (T)]; \ + } u; \ + for (j = 0; j < sizeof (T); j++) \ + u.b[j] = ((const char *) p)[sizeof (T) - 1 - j]; \ + x = u.x; \ + } \ + else \ + x = *p; \ + p++; \ ACTION; \ pad_remaining = next_pad; \ } \ @@ -1664,6 +1705,18 @@ main (int argc, char **argv) traditional = true; break; + case ENDIAN_OPTION: + switch (XARGMATCH ("--endian", optarg, endian_args, endian_types)) + { + case endian_big: + input_swap = ! WORDS_BIGENDIAN; + break; + case endian_little: + input_swap = WORDS_BIGENDIAN; + break; + } + break; + /* The next several cases map the traditional format specification options to the corresponding modern format specs. GNU od accepts any combination of old- and diff --git a/tests/local.mk b/tests/local.mk index 9d556f6..815dc6f 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -239,6 +239,7 @@ all_tests = \ tests/misc/xstrtol.pl \ tests/tail-2/pid.sh \ tests/misc/od.pl \ + tests/misc/od-endian.sh \ tests/misc/od-float.sh \ tests/misc/mktemp.pl \ tests/misc/arch.sh \ diff --git a/tests/misc/od-endian.sh b/tests/misc/od-endian.sh new file mode 100755 index 0000000..79dbc84 --- /dev/null +++ b/tests/misc/od-endian.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# verify that od --endian works properly + +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ od + +in='0123456789abcdef' + +in_swapped() { printf '%s' "$in" | sed "s/.\{$1\}/&\\n/g" | rev | tr -d '\n'; } + +for e in little big; do + test $e = little && eo=big || eo=little + for s in 1 2 4 8 16; do + for t in x; do + od -t $t$s --endian=$e /dev/null > /dev/null 2>&1 || continue + printf '%s' "$in" | od -An -t $t$s --endian=$e > out1 + in_swapped "$s" | od -An -t $t$s --endian=$eo > out2 + compare out1 out2 || fail=1 + done + done +done + +Exit $fail -- 1.7.7.6 --------------060000030701070400050708-- ------------=_1391896923-27042-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 28 Jan 2014 13:26:53 +0000 Received: from localhost ([127.0.0.1]:38758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W88gn-0006wk-12 for submit@debbugs.gnu.org; Tue, 28 Jan 2014 08:26:53 -0500 Received: from eggs.gnu.org ([208.118.235.92]:42792) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W88gk-0006wb-CP for submit@debbugs.gnu.org; Tue, 28 Jan 2014 08:26:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W88gf-0003yW-GP for submit@debbugs.gnu.org; Tue, 28 Jan 2014 08:26:49 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:37598) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W88gf-0003yS-D1 for submit@debbugs.gnu.org; Tue, 28 Jan 2014 08:26:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W88ga-0008U8-Rf for bug-coreutils@gnu.org; Tue, 28 Jan 2014 08:26:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W88gZ-0003we-QB for bug-coreutils@gnu.org; Tue, 28 Jan 2014 08:26:40 -0500 Received: from bacon.lysator.liu.se ([2001:6b0:17:f0a0::ce]:51918) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W88gZ-0003uH-E5 for bug-coreutils@gnu.org; Tue, 28 Jan 2014 08:26:39 -0500 Received: from bacon.lysator.liu.se (localhost [127.0.0.1]) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5) with ESMTP id s0SCsl6G019526 for ; Tue, 28 Jan 2014 13:54:47 +0100 (MET) Received: (from nisse@localhost) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5/Submit) id s0SCsleM019525; Tue, 28 Jan 2014 13:54:47 +0100 (MET) X-Authentication-Warning: bacon.lysator.liu.se: nisse set sender to nisse@lysator.liu.se using -f From: nisse@lysator.liu.se (Niels =?iso-8859-1?Q?M=F6ller?=) To: bug-coreutils@gnu.org Subject: Wish: Support for non-native endianness in od Date: Tue, 28 Jan 2014 13:54:47 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (usg-unix-v) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by bacon.lysator.liu.se id s0SCsl6G019526 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.3 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.3 (----) For the "od" program, it would be nice with a flag to specify the endianness for all types which are larger than a byte. Possible alternatives could be "big endian", "little endian", "native endian". And for floats, besides endianness, it would be nice to be able to specify native format or ieee format, for systems where these are different. Regards, /Niels --=20 Niels M=F6ller. PGP-encrypted email is preferred. Keyid C0B98E26. Internet email is subject to wholesale government surveillance. ------------=_1391896923-27042-1-- From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: Jim Meyering Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Sun, 09 Feb 2014 01:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 16578@debbugs.gnu.org, =?UTF-8?Q?P=C3=A1draig?= Brady , nisse@lysator.liu.se Cc: 16578-done@debbugs.gnu.org Received: via spool by 16578-submit@debbugs.gnu.org id=B16578.139190902614358 (code B ref 16578); Sun, 09 Feb 2014 01:24:02 +0000 Received: (at 16578) by debbugs.gnu.org; 9 Feb 2014 01:23:46 +0000 Received: from localhost ([127.0.0.1]:58427 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCJ7a-0003jQ-CE for submit@debbugs.gnu.org; Sat, 08 Feb 2014 20:23:46 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:58672) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCJ7X-0003jC-1Q; Sat, 08 Feb 2014 20:23:44 -0500 Received: by mail-pa0-f42.google.com with SMTP id kl14so4728193pab.29 for ; Sat, 08 Feb 2014 17:23:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=z2ZAtmxG94zNfo0ydPpv29l1xO9Jm4v8z0I0YbvpA/M=; b=ffMQSDNqDQBpSMIJ+v8+xRRTG/gKHqz3DNknbM0LGWREMIS1cRk+ipXuKctoJ8S9bo RJNDngSMle6VwBWE8NUnDSJ+h83Q3NRwLt90Ugqqhn/ASavMjRjSGAE8z38h/QiAI0cH jwQuTxk9YZBX0NdtsBvyWrJkSqbT9kqK/sWV1Nogu5k5ov1EZARn8jIIWVC5Azu+aLjw MswYRP0XqcZPEEd0GaAFihbi/LE5OhJ20OPUy31xDe1hdPXnVB9aZDOTs8w+NMDqL6m4 3uXOml727YZ/XkR4LoTV+DLU30FpIJJQkB3FXPx9aI+4gfnm6CjaSwzIW891SoeJjStg S6GQ== X-Received: by 10.68.7.66 with SMTP id h2mr28640003pba.91.1391909021985; Sat, 08 Feb 2014 17:23:41 -0800 (PST) MIME-Version: 1.0 Received: by 10.68.201.231 with HTTP; Sat, 8 Feb 2014 17:23:21 -0800 (PST) In-Reply-To: <52F6A940.7040701@draigBrady.com> References: <52E97649.6010905@draigBrady.com> <52ED9D4B.8000009@draigBrady.com> <52F6A940.7040701@draigBrady.com> From: Jim Meyering Date: Sat, 8 Feb 2014 17:23:21 -0800 X-Google-Sender-Auth: g4MgPg7YJM2l2Iziq8NZpktKcPU Message-ID: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On Sat, Feb 8, 2014 at 2:01 PM, P=E1draig Brady wrote: >>> + if (input_swap && sizeof(T) > 1) = \ >>> + { = \ >>> + int j; = \ The new patch looks complete. Thanks to both of you. One nit: please change the type of "j" here (identical in attached) to be unsigned, to match that of the upper bound. >>> + union { = \ >>> + T x; = \ >>> + char b[sizeof(T)]; = \ >>> + } u; = \ >>> + for (j =3D 0; j < sizeof(T); j++) = \ >>> + u.b[j] =3D ((const char *) p)[sizeof(T) - 1 - j]; = \ Re this function in the new test, > +in_swapped() { printf '%s' "$in" | sed "s/.\{$1\}/&\\n/g" | rev | tr -d = '\n'; } That would be our first use of "rev". Is it ubiquitous enough to depend on? From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Sun, 09 Feb 2014 08:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 16578-done@debbugs.gnu.org Received: via spool by 16578-done@debbugs.gnu.org id=D16578.139193535016790 (code D ref 16578); Sun, 09 Feb 2014 08:43:01 +0000 Received: (at 16578-done) by debbugs.gnu.org; 9 Feb 2014 08:42:30 +0000 Received: from localhost ([127.0.0.1]:59224 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCPy9-0004Mj-Ix for submit@debbugs.gnu.org; Sun, 09 Feb 2014 03:42:30 -0500 Received: from bacon.lysator.liu.se ([130.236.254.206]:47746) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCPy5-0004MZ-U2 for 16578-done@debbugs.gnu.org; Sun, 09 Feb 2014 03:42:27 -0500 Received: from bacon.lysator.liu.se (localhost [127.0.0.1]) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5) with ESMTP id s198gOEV016186; Sun, 9 Feb 2014 09:42:24 +0100 (MET) Received: (from nisse@localhost) by bacon.lysator.liu.se (8.14.5+Sun/8.14.5/Submit) id s198gNDX016185; Sun, 9 Feb 2014 09:42:23 +0100 (MET) X-Authentication-Warning: bacon.lysator.liu.se: nisse set sender to nisse@lysator.liu.se using -f From: nisse@lysator.liu.se (Niels =?UTF-8?Q?M=C3=B6ller?=) References: <52E97649.6010905@draigBrady.com> <52ED9D4B.8000009@draigBrady.com> <52F6A940.7040701@draigBrady.com> Date: Sun, 09 Feb 2014 09:42:23 +0100 In-Reply-To: <52F6A940.7040701@draigBrady.com> ("=?UTF-8?Q?P=C3=A1draig?= Brady"'s message of "Sat, 08 Feb 2014 22:01:36 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (usg-unix-v) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.1 (/) Pádraig Brady writes: > Attached in the patch I intend to push in your name. Nice. > I also added docs to usage() and the texinfo file, and added a test. I don't quite understand how the test works, but as far as I see, it doesn't test floats? So that's inconsistent with the commit message. > BTW I checked if there was any speed difference with the new code. > I wasn't expecting this to be a bottleneck, and true enough > there is only a marginal change. The new code is consistently > a little _faster_ though on my i3-2310M which is a bit surprising. Odd. But performance of x86 is usually pretty hard to predict by just looking at the source or assembly code. I was hoping that in the non-swapped case, the false conditional if (input_swap && sizeof(T) > 1) should be very friendly to the branch predictor, and hence almost free. Jim Meyering writes: > One nit: please change the type of "j" here (identical in attached) > to be unsigned, to match that of the upper bound. Makes sense. In my own projects, I tend to use unsigned int for loop counts whereever I don't need to iterate over any negative values. But my impression is that most others prefer to use signed int for everything which doesn't rely on mod 2^n arithmetic, so that's why I made j signed here. > That would be our first use of "rev". Is it ubiquitous enough to depend on? It appears *not* to be available on my closest solaris box. While on my gnu/linux system, it's provided by util-linux. For the test, I guess rev could be implemented something like while read line printf "%s" line | tr -d '\n' | sed 's/./.\n/' | tac | tr -d '\n' echo done Maybe rev should be provided by coreutils, similarly to tac? I'd prefer not to think about the unicode issues for rev, though... Regards, /Niels -- Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26. Internet email is subject to wholesale government surveillance. From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Sun, 09 Feb 2014 11:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Niels =?UTF-8?Q?M=C3=B6ller?= Cc: 16578@debbugs.gnu.org Received: via spool by 16578-submit@debbugs.gnu.org id=B16578.13919456901786 (code B ref 16578); Sun, 09 Feb 2014 11:35:01 +0000 Received: (at 16578) by debbugs.gnu.org; 9 Feb 2014 11:34:50 +0000 Received: from localhost ([127.0.0.1]:59334 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCSev-0000Sj-9X for submit@debbugs.gnu.org; Sun, 09 Feb 2014 06:34:49 -0500 Received: from mail4.vodafone.ie ([213.233.128.170]:9419) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCSes-0000SZ-Ln for 16578@debbugs.gnu.org; Sun, 09 Feb 2014 06:34:47 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApMBAEBn91JtTXJs/2dsb2JhbAANTINEwBiBHYMZAQEBAwEyAUYFCwsNCwkWDwkDAgECAUUGDQEFAgEBh3kNCKdJoR8Xjn0HhDgEnxuOXg Received: from unknown (HELO [192.168.1.79]) ([109.77.114.108]) by mail3.vodafone.ie with ESMTP; 09 Feb 2014 11:34:44 +0000 Message-ID: <52F767D3.3040407@draigBrady.com> Date: Sun, 09 Feb 2014 11:34:43 +0000 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 References: <52E97649.6010905@draigBrady.com> <52ED9D4B.8000009@draigBrady.com> <52F6A940.7040701@draigBrady.com> In-Reply-To: X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 02/09/2014 08:42 AM, Niels Möller wrote: > Pádraig Brady writes: > >> Attached in the patch I intend to push in your name. > > Nice. > >> I also added docs to usage() and the texinfo file, and added a test. > > I don't quite understand how the test works, but as far as I see, it > doesn't test floats? So that's inconsistent with the commit message. Oops, I removed an 'f' while developing. Added that back now which also gets sizes up to 16 tested. >> BTW I checked if there was any speed difference with the new code. >> I wasn't expecting this to be a bottleneck, and true enough >> there is only a marginal change. The new code is consistently >> a little _faster_ though on my i3-2310M which is a bit surprising. > > Odd. But performance of x86 is usually pretty hard to predict by just > looking at the source or assembly code. I was hoping that in the > non-swapped case, the false conditional > > if (input_swap && sizeof(T) > 1) > > should be very friendly to the branch predictor, and hence almost free. > > Jim Meyering writes: > >> One nit: please change the type of "j" here (identical in attached) >> to be unsigned, to match that of the upper bound. > > Makes sense. In my own projects, I tend to use unsigned int for loop > counts whereever I don't need to iterate over any negative values. But > my impression is that most others prefer to use signed int for > everything which doesn't rely on mod 2^n arithmetic, so that's why I > made j signed here. done >> That would be our first use of "rev". Is it ubiquitous enough to depend on? Ugh good point. > It appears *not* to be available on my closest solaris box. While on my > gnu/linux system, it's provided by util-linux. For the test, I guess rev > could be implemented something like > > while read line > printf "%s" line | tr -d '\n' | sed 's/./.\n/' | tac | tr -d '\n' > echo > done I went with: rev() { while read line; do printf '%s' "$line" | sed 's/./&\n/g' | tac | paste -s -d '' done } > Maybe rev should be provided by coreutils, similarly to tac? I'd prefer > not to think about the unicode issues for rev, though... I think so too. It's not Linux specific and we've previously mentioned rev in alternative for adding various functionality to coreutils. Thanks to both of you for the review! I've now pushed: http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=b370924c Pádraig. From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Mon, 10 Feb 2014 02:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 16578@debbugs.gnu.org, P@draigBrady.com, nisse@lysator.liu.se Received: via spool by 16578-submit@debbugs.gnu.org id=B16578.13919975572388 (code B ref 16578); Mon, 10 Feb 2014 02:00:02 +0000 Received: (at 16578) by debbugs.gnu.org; 10 Feb 2014 01:59:17 +0000 Received: from localhost ([127.0.0.1]:32920 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCg9U-0000cS-GT for submit@debbugs.gnu.org; Sun, 09 Feb 2014 20:59:16 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:48266) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCg9Q-0000cE-LC for 16578@debbugs.gnu.org; Sun, 09 Feb 2014 20:59:13 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 3C7F839E8016; Sun, 9 Feb 2014 17:59:11 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lPgGB9zvAnGV; Sun, 9 Feb 2014 17:59:10 -0800 (PST) Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 8E67239E8014; Sun, 9 Feb 2014 17:59:10 -0800 (PST) Message-ID: <52F8326E.5020706@cs.ucla.edu> Date: Sun, 09 Feb 2014 17:59:10 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 References: <52E97649.6010905@draigBrady.com> <52ED9D4B.8000009@draigBrady.com> <52F6A940.7040701@draigBrady.com> In-Reply-To: <52F6A940.7040701@draigBrady.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -2.9 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.9 (--) Pádraig Brady wrote: > $ time od.new -tx8 --endian=bug od.in > 4.97 elapsed If you really used "--endian=bug" and there was no diagnostic, then there must have been a bug. :-) From unknown Sun Jun 15 08:53:32 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16578: Wish: Support for non-native endianness in od Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Mon, 10 Feb 2014 02:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16578 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Paul Eggert Cc: nisse@lysator.liu.se, 16578@debbugs.gnu.org Received: via spool by 16578-submit@debbugs.gnu.org id=B16578.139199819419226 (code B ref 16578); Mon, 10 Feb 2014 02:10:02 +0000 Received: (at 16578) by debbugs.gnu.org; 10 Feb 2014 02:09:54 +0000 Received: from localhost ([127.0.0.1]:32935 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCgJm-0004yo-Ax for submit@debbugs.gnu.org; Sun, 09 Feb 2014 21:09:54 -0500 Received: from mail4.vodafone.ie ([213.233.128.170]:5608) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCgJk-0004nH-1Z for 16578@debbugs.gnu.org; Sun, 09 Feb 2014 21:09:52 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQBAMsz+FJtTXJs/2dsb2JhbAANTA6DNoNYvEqBHYMZAQEBBCMPAUYQCw0LAgIFFAILAgIJAwIBAgFFBg0BBwEBiAamcXagNxeBKY1UB4JvgUkBA58bjh8/ Received: from unknown (HELO [192.168.1.79]) ([109.77.114.108]) by mail3.vodafone.ie with ESMTP; 10 Feb 2014 02:09:51 +0000 Message-ID: <52F834ED.8070400@draigBrady.com> Date: Mon, 10 Feb 2014 02:09:49 +0000 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 References: <52E97649.6010905@draigBrady.com> <52ED9D4B.8000009@draigBrady.com> <52F6A940.7040701@draigBrady.com> <52F8326E.5020706@cs.ucla.edu> In-Reply-To: <52F8326E.5020706@cs.ucla.edu> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 02/10/2014 01:59 AM, Paul Eggert wrote: > Pádraig Brady wrote: >> $ time od.new -tx8 --endian=bug od.in >> 4.97 elapsed > > If you really used "--endian=bug" and there was no diagnostic, then there must have been a bug. :-) Ha! I retyped incorrectly rather than copy/pasted. I can confirm the params are checked correctly: $ od -tx8 --endian=bug od.in od: invalid argument ‘bug’ for ‘--endian’ Valid arguments are: - ‘little’ - ‘big’ Try 'src/od --help' for more information.