Alexandre Julliard : wmc: Windows file formats are always little-endian.

Alexandre Julliard julliard at winehq.org
Thu Nov 11 16:01:28 CST 2021


Module: wine
Branch: master
Commit: af046fe6361e414a7ed8917656540c0ee014815a
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=af046fe6361e414a7ed8917656540c0ee014815a

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Nov 11 17:36:56 2021 +0100

wmc: Windows file formats are always little-endian.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 tools/wmc/mcl.c      |  2 +-
 tools/wmc/utils.c    | 21 ++++++++-------------
 tools/wmc/utils.h    |  2 --
 tools/wmc/wmc.c      | 40 +---------------------------------------
 tools/wmc/wmc.h      |  1 -
 tools/wmc/wmc.man.in |  3 ---
 tools/wmc/wmctypes.h | 12 ------------
 7 files changed, 10 insertions(+), 71 deletions(-)

diff --git a/tools/wmc/mcl.c b/tools/wmc/mcl.c
index 0d7b50027c5..df058476129 100644
--- a/tools/wmc/mcl.c
+++ b/tools/wmc/mcl.c
@@ -239,7 +239,7 @@ static int fill_inputbuffer(void)
     case INPUT_UNICODE:
         len += fread( inputbuffer + len, sizeof(WCHAR), INPUTBUFFER_SIZE - len, yyin );
         if (!len) break;
-        if (swapped) for (i = 0; i < len; i++) inputbuffer[i] = BYTESWAP_WORD( inputbuffer[i] );
+        if (swapped) for (i = 0; i < len; i++) inputbuffer[i] = (inputbuffer[i] << 8) | (inputbuffer[i] >> 8);
         ninputbuffer = len;
         return 1;
     case INPUT_UNKNOWN:
diff --git a/tools/wmc/utils.c b/tools/wmc/utils.c
index d9d803413da..80e9cf0c96b 100644
--- a/tools/wmc/utils.c
+++ b/tools/wmc/utils.c
@@ -439,7 +439,6 @@ WCHAR *codepage_to_unicode( int codepage, const char *src, int srclen, int *dstl
  * Function for writing to a memory buffer.
  */
 
-int byte_swapped = 0;
 unsigned char *output_buffer;
 size_t output_buffer_pos;
 size_t output_buffer_size;
@@ -470,13 +469,6 @@ void flush_output_buffer( const char *name )
     free( output_buffer );
 }
 
-void put_data( const void *data, size_t size )
-{
-    check_output_buffer_space( size );
-    memcpy( output_buffer + output_buffer_pos, data, size );
-    output_buffer_pos += size;
-}
-
 void put_byte( unsigned char val )
 {
     check_output_buffer_space( 1 );
@@ -485,15 +477,18 @@ void put_byte( unsigned char val )
 
 void put_word( unsigned short val )
 {
-    if (byte_swapped) val = (val << 8) | (val >> 8);
-    put_data( &val, sizeof(val) );
+    check_output_buffer_space( 2 );
+    output_buffer[output_buffer_pos++] = val;
+    output_buffer[output_buffer_pos++] = val >> 8;
 }
 
 void put_dword( unsigned int val )
 {
-    if (byte_swapped)
-        val = ((val << 24) | ((val << 8) & 0x00ff0000) | ((val >> 8) & 0x0000ff00) | (val >> 24));
-    put_data( &val, sizeof(val) );
+    check_output_buffer_space( 4 );
+    output_buffer[output_buffer_pos++] = val;
+    output_buffer[output_buffer_pos++] = val >> 8;
+    output_buffer[output_buffer_pos++] = val >> 16;
+    output_buffer[output_buffer_pos++] = val >> 24;
 }
 
 void align_output( unsigned int align )
diff --git a/tools/wmc/utils.h b/tools/wmc/utils.h
index 3a8010d77cc..4a4bef37ee8 100644
--- a/tools/wmc/utils.h
+++ b/tools/wmc/utils.h
@@ -43,14 +43,12 @@ WCHAR *codepage_to_unicode( int codepage, const char *src, int srclen, int *dstl
 
 /* buffer management */
 
-extern int byte_swapped;
 extern unsigned char *output_buffer;
 extern size_t output_buffer_pos;
 extern size_t output_buffer_size;
 
 extern void init_output_buffer(void);
 extern void flush_output_buffer( const char *name );
-extern void put_data( const void *data, size_t size );
 extern void put_byte( unsigned char val );
 extern void put_word( unsigned short val );
 extern void put_dword( unsigned int val );
diff --git a/tools/wmc/wmc.c b/tools/wmc/wmc.c
index 2993d3c5ef7..2d3dcaf328c 100644
--- a/tools/wmc/wmc.c
+++ b/tools/wmc/wmc.c
@@ -37,14 +37,6 @@
 
 static const char usage[] =
 	"Usage: wmc [options...] [inputfile.mc]\n"
-	"   -B x                       Set output byte-order x={n[ative], l[ittle], b[ig]}\n"
-	"                              (default is n[ative] which equals "
-#ifdef WORDS_BIGENDIAN
-	"big"
-#else
-	"little"
-#endif
-	"-endian)\n"
 	"   -c                         Set 'custom-bit' in values\n"
 	"   -d                         Use decimal values in output\n"
 	"   -D                         Set debug flag\n"
@@ -70,11 +62,6 @@ static const char version_string[] =
 	"Copyright 2000 Bertho A. Stultiens\n"
 	;
 
-/*
- * The output byte-order of resources (set with -B)
- */
-int byteorder = WMC_BO_NATIVE;
-
 /*
  * Custom bit (bit 29) in output values must be set (-c option)
  */
@@ -136,7 +123,7 @@ enum long_options_values
     LONG_OPT_NLS_DIR = 1,
 };
 
-static const char short_options[] = "B:cdDhH:io:O:P:uUvVW";
+static const char short_options[] = "cdDhH:io:O:P:uUvVW";
 static const struct long_option long_options[] =
 {
 	{ "help", 0, 'h' },
@@ -190,25 +177,6 @@ static void option_callback( int optc, char *optarg )
 {
     switch(optc)
     {
-    case 'B':
-        switch(optarg[0])
-        {
-        case 'n':
-        case 'N':
-            byteorder = WMC_BO_NATIVE;
-            break;
-        case 'l':
-        case 'L':
-            byteorder = WMC_BO_LITTLE;
-            break;
-        case 'b':
-        case 'B':
-            byteorder = WMC_BO_BIG;
-            break;
-        default:
-            error("Byteordering must be n[ative], l[ittle] or b[ig]\n");
-        }
-        break;
     case 'c':
         custombit = 1;
         break;
@@ -347,12 +315,6 @@ int main(int argc,char *argv[])
 		exit(1);
 	}
 
-#ifdef WORDS_BIGENDIAN
-	byte_swapped = (byteorder == WMC_BO_LITTLE);
-#else
-	byte_swapped = (byteorder == WMC_BO_BIG);
-#endif
-
         switch (output_format)
         {
         case FORMAT_RC:
diff --git a/tools/wmc/wmc.h b/tools/wmc/wmc.h
index e9736103fe3..1939cb8c084 100644
--- a/tools/wmc/wmc.h
+++ b/tools/wmc/wmc.h
@@ -39,7 +39,6 @@
 
 extern int pedantic;
 extern int leave_case;
-extern int byteorder;
 extern int decimal;
 extern int custombit;
 extern int unicodein;
diff --git a/tools/wmc/wmc.man.in b/tools/wmc/wmc.man.in
index 123af446a5e..bfa0a19a314 100644
--- a/tools/wmc/wmc.man.in
+++ b/tools/wmc/wmc.man.in
@@ -22,9 +22,6 @@ with \fB-o\fR, then \fBwmc\fR will write the output to \fIinputfile.{rc,h}\fR.
 The outputfile is named \fIwmc.tab.{rc,h}\fR if no inputfile was given.
 .SH OPTIONS
 .TP
-.BI \-B\  x
-Set output byte-order x={n[ative], l[ittle], b[ig]}. Default is n[ative].
-.TP
 .B \-c
 Set 'custom-bit' in message-code values.
 .TP
diff --git a/tools/wmc/wmctypes.h b/tools/wmc/wmctypes.h
index 116ace20545..12227f2d7aa 100644
--- a/tools/wmc/wmctypes.h
+++ b/tools/wmc/wmctypes.h
@@ -25,18 +25,6 @@
 #include "windef.h"
 #include "winbase.h"
 
-/* Byteordering defines */
-#define WMC_BO_NATIVE	0x00
-#define WMC_BO_LITTLE	0x01
-#define WMC_BO_BIG	0x02
-
-#define WMC_LOBYTE(w)		((WORD)(w) & 0xff)
-#define WMC_HIBYTE(w)		(((WORD)(w) >> 8) & 0xff)
-#define WMC_LOWORD(d)		((DWORD)(d) & 0xffff)
-#define WMC_HIWORD(d)		(((DWORD)(d) >> 16) & 0xffff)
-#define BYTESWAP_WORD(w)	((WORD)(((WORD)WMC_LOBYTE(w) << 8) + (WORD)WMC_HIBYTE(w)))
-#define BYTESWAP_DWORD(d)	((DWORD)(((DWORD)BYTESWAP_WORD(WMC_LOWORD(d)) << 16) + ((DWORD)BYTESWAP_WORD(WMC_HIWORD(d)))))
-
 /*
  * Tokenizer types
  */




More information about the wine-cvs mailing list