]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: use more portable initialization syntax
authorJim Meyering <meyering@redhat.com>
Tue, 18 Aug 2009 09:01:00 +0000 (11:01 +0200)
committerJim Meyering <meyering@redhat.com>
Tue, 18 Aug 2009 09:02:36 +0000 (11:02 +0200)
* src/sort.c (find_unit_order): Spell out 256-element static
initializer, rather than relying on C99 syntax.
Required for Forte Developer 7 C 5.4 2002/03/09 on Solaris 10.
Reported by Bernhard Voelker.

src/sort.c

index 62ddd49932c758d37862fa6577402a41b03b2544..832be5a39fb98bf664432bd55fe632a1ccb0fcbd 100644 (file)
@@ -1701,10 +1701,29 @@ check_mixed_SI_IEC (char prefix, struct keyfield *key)
 static int
 find_unit_order (const char *number, struct keyfield *key)
 {
-  static const char orders [UCHAR_LIM] = {
-    ['K']=1, ['M']=2, ['G']=3, ['T']=4, ['P']=5, ['E']=6, ['Z']=7, ['Y']=8,
-    ['k']=1,
-  };
+  static const char orders [UCHAR_LIM] =
+    {
+#if SOME_DAY_WE_WILL_REQUIRE_C99
+      ['K']=1, ['M']=2, ['G']=3, ['T']=4, ['P']=5, ['E']=6, ['Z']=7, ['Y']=8,
+      ['k']=1,
+#else
+      /* Generate the following table with this command:
+         perl -e 'my %a=(k=>1, K=>1, M=>2, G=>3, T=>4, P=>5, E=>6, Z=>7, Y=>8);
+         foreach my $i (0..255) {my $c=chr($i); $a{$c} ||= 0;print "$a{$c}, "}'\
+         |fmt  */
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 3,
+      0, 0, 0, 1, 0, 2, 0, 0, 5, 0, 0, 0, 4, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+#endif
+    };
 
   const unsigned char *p = number;