]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
New msgfmt option --endianness.
authorBruno Haible <bruno@clisp.org>
Fri, 26 Aug 2005 11:04:53 +0000 (11:04 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:48 +0000 (12:12 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/msgfmt.c
gettext-tools/src/write-mo.c
gettext-tools/src/write-mo.h

index f99e7e841588afeecd12199151358e15124ecca7..eddd89ccd8b5353d5a5218673855ffaa9406d52b 100644 (file)
@@ -1,3 +1,14 @@
+2005-08-23  Bruno Haible  <bruno@clisp.org>
+
+       * write-mo.h (byteswap): New variable.
+       * write-mo.c: Include byteswap.h.
+       (byteswap): New variable.
+       (BSWAP32): New macro.
+       (write_table): If requested, byteswap all 32-bit values before writing
+       them out.
+       * msgfmt.c (long_options): Add --endianness.
+       (main): Accept --endianness argument and set byteswap.
+
 2005-08-08  Bruno Haible  <bruno@clisp.org>
 
        * msginit.c (catalogname_for_locale): Add support for Old English,
index 96dc09732a5a94bdcce1c0e7fea504a24ba63bac..7d6c81e9aeab2e5fc78e61e67fe9969a928cf939 100644 (file)
@@ -178,6 +178,7 @@ static const struct option long_options[] =
   { "csharp", no_argument, NULL, CHAR_MAX + 10 },
   { "csharp-resources", no_argument, NULL, CHAR_MAX + 11 },
   { "directory", required_argument, NULL, 'D' },
+  { "endianness", required_argument, NULL, CHAR_MAX + 13 },
   { "help", no_argument, NULL, 'h' },
   { "java", no_argument, NULL, 'j' },
   { "java2", no_argument, NULL, CHAR_MAX + 5 },
@@ -355,6 +356,20 @@ main (int argc, char *argv[])
       case CHAR_MAX + 12: /* --use-untranslated (undocumented) */
        include_untranslated = true;
        break;
+      case CHAR_MAX + 13: /* --endianness={big|little} */
+       {
+         int endianness;
+
+         if (strcmp (optarg, "big") == 0)
+           endianness = 1;
+         else if (strcmp (optarg, "little") == 0)
+           endianness = 0;
+         else
+           error (EXIT_FAILURE, 0, _("invalid endianness: %s"), optarg);
+
+         byteswap = endianness ^ ENDIANNESS;
+       }
+       break;
       default:
        usage (EXIT_FAILURE);
        break;
index 50d82ec6485e7c0370d835555440687d521c86fd..8fdba911f25dbac2282f85fc1900f45952f820be 100644 (file)
@@ -38,6 +38,7 @@
 #include "gmo.h"
 #include "hash-string.h"
 
+#include "byteswap.h"
 #include "error.h"
 #include "hash.h"
 #include "message.h"
 /* Alignment of strings in resulting .mo file.  */
 size_t alignment;
 
+/* True if writing a .mo file in opposite endianness than the host.  */
+bool byteswap;
+
 /* True if no hash table in .mo is wanted.  */
 bool no_hash_table;
 
 
+/* Destructively changes the byte order of a 32-bit value in memory.  */
+#define BSWAP32(x) (x) = bswap_32 (x)
+
+
 /* Indices into the strings contained in 'struct pre_message' and
    'struct pre_sysdep_message'.  */
 enum
@@ -447,6 +455,24 @@ write_table (FILE *output_file, message_list_ty *mlp)
      compute the offsets of each string, including the proper alignment.  */
 
   /* Write the header out.  */
+  if (byteswap)
+    {
+      BSWAP32 (header.magic);
+      BSWAP32 (header.revision);
+      BSWAP32 (header.nstrings);
+      BSWAP32 (header.orig_tab_offset);
+      BSWAP32 (header.trans_tab_offset);
+      BSWAP32 (header.hash_tab_size);
+      BSWAP32 (header.hash_tab_offset);
+      if (minor_revision >= 1)
+       {
+         BSWAP32 (header.n_sysdep_segments);
+         BSWAP32 (header.sysdep_segments_offset);
+         BSWAP32 (header.n_sysdep_strings);
+         BSWAP32 (header.orig_sysdep_tab_offset);
+         BSWAP32 (header.trans_sysdep_tab_offset);
+       }
+    }
   fwrite (&header, header_size, 1, output_file);
 
   /* Table for original string offsets.  */
@@ -462,6 +488,12 @@ write_table (FILE *output_file, message_list_ty *mlp)
       /* Subtract 1 because of the terminating NUL.  */
       orig_tab[j].length--;
     }
+  if (byteswap)
+    for (j = 0; j < nstrings; j++)
+      {
+       BSWAP32 (orig_tab[j].length);
+       BSWAP32 (orig_tab[j].offset);
+      }
   fwrite (orig_tab, nstrings * sizeof (struct string_desc), 1, output_file);
 
   /* Table for translated string offsets.  */
@@ -476,6 +508,12 @@ write_table (FILE *output_file, message_list_ty *mlp)
       /* Subtract 1 because of the terminating NUL.  */
       trans_tab[j].length--;
     }
+  if (byteswap)
+    for (j = 0; j < nstrings; j++)
+      {
+       BSWAP32 (trans_tab[j].length);
+       BSWAP32 (trans_tab[j].offset);
+      }
   fwrite (trans_tab, nstrings * sizeof (struct string_desc), 1, output_file);
 
   /* Skip this part when no hash table is needed.  */
@@ -514,6 +552,9 @@ write_table (FILE *output_file, message_list_ty *mlp)
        }
 
       /* Write the hash table out.  */
+      if (byteswap)
+       for (j = 0; j < hash_tab_size; j++)
+         BSWAP32 (hash_tab[j]);
       fwrite (hash_tab, hash_tab_size * sizeof (nls_uint32), 1, output_file);
 
       free (hash_tab);
@@ -540,6 +581,12 @@ write_table (FILE *output_file, message_list_ty *mlp)
          offset += sysdep_segments_tab[i].length;
        }
 
+      if (byteswap)
+       for (i = 0; i < n_sysdep_segments; i++)
+         {
+           BSWAP32 (sysdep_segments_tab[i].length);
+           BSWAP32 (sysdep_segments_tab[i].offset);
+         }
       fwrite (sysdep_segments_tab,
              n_sysdep_segments * sizeof (struct sysdep_segment), 1,
              output_file);
@@ -564,6 +611,9 @@ write_table (FILE *output_file, message_list_ty *mlp)
                            * sizeof (struct segment_pair);
            }
          /* Write the table for original/translated sysdep string offsets.  */
+         if (byteswap)
+           for (j = 0; j < n_sysdep_strings; j++)
+             BSWAP32 (sysdep_tab[j]);
          fwrite (sysdep_tab, n_sysdep_strings * sizeof (nls_uint32), 1,
                  output_file);
        }
@@ -596,6 +646,15 @@ write_table (FILE *output_file, message_list_ty *mlp)
                str->segments[pre->segmentcount].segsize += msg->id_plural_len;
                offset += msg->id_plural_len;
              }
+           if (byteswap)
+             {
+               BSWAP32 (str->offset);
+               for (i = 0; i <= pre->segmentcount; i++)
+                 {
+                   BSWAP32 (str->segments[i].segsize);
+                   BSWAP32 (str->segments[i].sysdepref);
+                 }
+             }
            fwrite (str,
                    sizeof (struct sysdep_string)
                    + pre->segmentcount * sizeof (struct segment_pair),
index d180a78f8b1c8319e827134aed9d41f5d6525cb1..f3c27bc1a040d92c80d308de9b625421a3f3c927 100644 (file)
@@ -1,5 +1,5 @@
 /* Writing binary .mo files.
-   Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2003, 2005 Free Software Foundation, Inc.
    Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, April 1995.
 
    This program is free software; you can redistribute it and/or modify
@@ -27,6 +27,9 @@
 /* Alignment of strings in resulting .mo file.  */
 extern DLL_VARIABLE size_t alignment;
 
+/* True if writing a .mo file in opposite endianness than the host.  */
+extern DLL_VARIABLE bool byteswap;
+
 /* True if no hash table in .mo is wanted.  */
 extern DLL_VARIABLE bool no_hash_table;