From 8f6a22fb6cb4dcaf80049a7c82973251ffd07f80 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Wed, 2 Oct 2013 18:45:05 +0200
Subject: Convert existing patch to patchset format.


diff --git a/arcread.cpp b/arcread.cpp
index a524a96..19cca29 100644
--- a/arcread.cpp
+++ b/arcread.cpp
@@ -666,7 +666,7 @@ void Archive::ConvertUnknownHeader()
   {
     if (*s=='/' || *s=='\\')
       *s=CPATHDIVIDER;
-#if defined(_APPLE) && !defined(UNICODE_SUPPORTED)
+#if (defined(_APPLE) || defined(_BEOS)) && !defined(UNICODE_SUPPORTED)
     if ((byte)*s<32 || (byte)*s>127)
       *s='_';
 #endif
diff --git a/consio.cpp b/consio.cpp
index 42b72a6..90d22c9 100644
--- a/consio.cpp
+++ b/consio.cpp
@@ -141,7 +141,7 @@ void GetPasswordText(wchar *Str,uint MaxLength)
   SetConsoleMode(hConOut,ConOutMode);
 #else
   char StrA[MAXPASSWORD];
-#if defined(_EMX) || defined(_BEOS) || defined(__sparc) || defined(sparc) || defined (__VMS)
+#if defined(_EMX) || defined(__sparc) || defined(sparc) || defined (__VMS)
   fgets(StrA,ASIZE(StrA)-1,stdin);
 #else
   strncpyz(StrA,getpass(""),ASIZE(StrA));
diff --git a/extract.cpp b/extract.cpp
index ddd71a0..adccadf 100644
--- a/extract.cpp
+++ b/extract.cpp
@@ -311,7 +311,7 @@ bool CmdExtract::ExtractCurrentFile(CommandData *Cmd,Archive &Arc,size_t HeaderS
   bool WideName=false;
 #endif
 
-#ifdef _APPLE
+#if defined(_APPLE) || defined(_BEOS)
   if (WideName)
   {
     // Prepare UTF-8 name for OS X. Since we are sure that destination
diff --git a/file.cpp b/file.cpp
index dcf4e61..7a26155 100644
--- a/file.cpp
+++ b/file.cpp
@@ -304,6 +304,8 @@ void File::Write(const void *Data,size_t Size)
         hFile=stderr;
 #endif
         break;
+      default:
+        break;
     }
 #endif
   while (1)
diff --git a/find.cpp b/find.cpp
index 7ba14c0..0f7c3c0 100644
--- a/find.cpp
+++ b/find.cpp
@@ -104,7 +104,7 @@ bool FindFile::Next(struct FindData *fd,bool GetSymLink)
     }
   }
   *fd->NameW=0;
-#ifdef _APPLE
+#if defined(_APPLE) || defined(_BEOS)
   if (!LowAscii(fd->Name))
     UtfToWide(fd->Name,fd->NameW,sizeof(fd->NameW));
 #elif defined(UNICODE_SUPPORTED)
@@ -170,7 +170,7 @@ bool FindFile::FastFind(const char *FindMask,const wchar *FindMaskW,FindData *fd
   strcpy(fd->Name,FindMask);
 
   *fd->NameW=0;
-#ifdef _APPLE
+#if defined(_APPLE) || defined(_BEOS)
   if (!LowAscii(fd->Name))
     UtfToWide(fd->Name,fd->NameW,sizeof(fd->NameW));
 #elif defined(UNICODE_SUPPORTED)
diff --git a/makefile.unix b/makefile.unix
index bd06092..b5e3815 100644
--- a/makefile.unix
+++ b/makefile.unix
@@ -7,7 +7,11 @@ CXXFLAGS=-O2
 LIBFLAGS=-fPIC
 DEFINES=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
 STRIP=strip
-DESTDIR=/usr
+LDFLAGS=-lbsd
+RC=rc
+XRES=xres
+MIMESET=mimeset
+DESTDIR=$(shell finddir B_COMMON_DIRECTORY)
 
 # Linux using LCC
 #CXX=lcc
@@ -114,12 +118,14 @@ install:	install-unrar
 uninstall:	uninstall-unrar
 
 clean:
-	@rm -f *.o *.bak *~
+	@rm -f *.o *.bak *~ *.rsrc
 
 unrar:	clean $(OBJECTS) $(UNRAR_OBJ)
 	@rm -f unrar
 	$(LINK) -o unrar $(LDFLAGS) $(OBJECTS) $(UNRAR_OBJ) $(LIBS)	
-	$(STRIP) unrar
+	$(RC) -o unrar.rsrc unrar.rdef
+	$(XRES) -o unrar unrar.rsrc
+	$(MIMESET) unrar
 
 sfx:	WHAT=SFX_MODULE
 sfx:	clean $(OBJECTS)
@@ -144,3 +150,29 @@ install-lib:
 
 uninstall-lib:
 		rm -f $(DESTDIR)/lib/libunrar.so
+
+MACHINE=$(shell uname -m)
+ifeq ($(MACHINE), BePC)
+	MACHINE = x86-gcc$(word 1, $(subst -, , $(subst ., , $(shell $(CC) -dumpversion))))
+endif
+
+VERSION=4.2.4
+DATE := `date +%F`
+PACKAGE_NAME := unrar-$(VERSION)-$(MACHINE)-$(DATE)
+COMMENT = .OptionalPackageDescription
+DESCRIPTION = dist/$(COMMENT)
+
+haiku_package: unrar
+	-rm -rf dist/common
+	-mkdir -p dist/common/bin
+	-cp unrar dist/common/bin
+	-mkdir -p dist/common/data/licenses
+	-cp license.txt dist/common/data/licenses/UnRAR
+	echo "Package: UnRAR" > $(DESCRIPTION)
+	echo "Version: $(VERSION)-$(MACHINE)-$(DATE)" >> $(DESCRIPTION)
+	echo "Copyright: Alexander Roshal." >> $(DESCRIPTION)
+	echo "Description: Utility to list, test and expand RAR archives." >> $(DESCRIPTION)
+	echo "License: UnRAR" >> $(DESCRIPTION)
+	echo "URL: http://www.rarlab.com/" >> $(DESCRIPTION)
+	cd dist && zip -9 -r -z -y $(PACKAGE_NAME).zip common $(COMMENT) < $(COMMENT)
+
diff --git a/os.hpp b/os.hpp
index 21488a8..ae2d0be 100644
--- a/os.hpp
+++ b/os.hpp
@@ -134,8 +134,9 @@
 #define  NM  1024
 
 #ifdef _BEOS
-#include <be/kernel/fs_info.h>
-#include <be/kernel/fs_attr.h>
+#include <endian.h>
+#include <fs_info.h>
+#include <fs_attr.h>
 #endif
 
 #include <unistd.h>
@@ -206,6 +207,16 @@
   #endif
 #endif
 
+#ifdef _BEOS
+#if LITTLE_ENDIAN
+  #undef BIG_ENDIAN
+#elif BIG_ENDIAN
+  #undef LITTLE_ENDIAN
+#else
+  #error "Byte order must be defined!"
+#endif
+#endif
+
 #if defined(__sparc) || defined(sparc) || defined(__hpux)
   #ifndef BIG_ENDIAN
      #define BIG_ENDIAN
diff --git a/raros.hpp b/raros.hpp
index ce853bd..b63d0f0 100644
--- a/raros.hpp
+++ b/raros.hpp
@@ -29,7 +29,7 @@
   #endif
 #endif
 
-#ifdef __BEOS__
+#if defined(__BEOS__) || defined(__HAIKU__)
   #define _UNIX
   #define _BEOS
 #endif
diff --git a/rartypes.hpp b/rartypes.hpp
index a2d8b44..d8249b1 100644
--- a/rartypes.hpp
+++ b/rartypes.hpp
@@ -7,6 +7,7 @@ typedef unsigned int     uint;   // 32 bits or more
 
 #define PRESENT_INT32 // undefine if signed 32 bits is not available
 
+#ifndef _BEOS 
 typedef unsigned int     uint32; // 32 bits exactly
 typedef   signed int     int32;  // signed 32 bits exactly
 
@@ -20,6 +21,7 @@ typedef     signed __int64  int64; // signed 64 bits
 typedef unsigned long long uint64; // unsigned 64 bits
 typedef   signed long long  int64; // signed 64 bits
 #endif
+#endif // #ifndef _BEOS
 
 
 #if defined(_WIN_ALL) || defined(__GNUC__) || defined(__sgi) || defined(_AIX) || defined(__sun) || defined(__hpux) || defined(_OSF_SOURCE)
diff --git a/rarvm.cpp b/rarvm.cpp
index 8b85800..1f06581 100644
--- a/rarvm.cpp
+++ b/rarvm.cpp
@@ -792,6 +792,8 @@ void RarVM::Optimize(VM_PreparedProgram *Prg)
       case VM_CMP:
         Cmd->OpCode=Cmd->ByteMode ? VM_CMPB:VM_CMPD;
         continue;
+      default:
+		break;
     }
     if ((VM_CmdFlags[Cmd->OpCode] & VMCF_CHFLAGS)==0)
       continue;
@@ -835,6 +837,8 @@ void RarVM::Optimize(VM_PreparedProgram *Prg)
       case VM_NEG:
         Cmd->OpCode=Cmd->ByteMode ? VM_NEGB:VM_NEGD;
         continue;
+      default:
+		break;
     }
   }
 }
@@ -1102,6 +1106,8 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
         SET_VALUE(false,&Mem[VM_GLOBALMEMADDR+0x20],DataSize);
       }
       break;
+    default:
+      break;
   }
 }
 
diff --git a/unicode.cpp b/unicode.cpp
index a3022d2..3e29127 100644
--- a/unicode.cpp
+++ b/unicode.cpp
@@ -13,7 +13,7 @@ bool WideToChar(const wchar *Src,char *Dest,size_t DestSize)
   if (WideCharToMultiByte(CP_ACP,0,Src,-1,Dest,(int)DestSize,NULL,NULL)==0)
     RetCode=false;
 
-#elif defined(_APPLE)
+#elif defined(_APPLE) || defined(_BEOS)
   WideToUtf(Src,Dest,DestSize);
 
 #elif defined(MBFUNCTIONS)
@@ -73,7 +73,7 @@ bool CharToWide(const char *Src,wchar *Dest,size_t DestSize)
   if (MultiByteToWideChar(CP_ACP,0,Src,-1,Dest,(int)DestSize)==0)
     RetCode=false;
 
-#elif defined(_APPLE)
+#elif defined(_APPLE) || defined(_BEOS)
   UtfToWide(Src,Dest,DestSize);
 
 #elif defined(MBFUNCTIONS)
diff --git a/unrar.rdef b/unrar.rdef
new file mode 100644
index 0000000..ab085d2
--- /dev/null
+++ b/unrar.rdef
@@ -0,0 +1,13 @@
+
+resource app_signature "application/x-vnd.Roshal-UnRAR";
+resource app_flags B_MULTIPLE_LAUNCH | B_BACKGROUND_APP;
+
+resource app_version {
+	major = 4,
+	middle = 2,
+	minor = 4,
+	variety = 0,
+	internal = 0,
+	short_info = "4.2.4", 
+	long_info = "4.2.4 Alexander Roshal"
+};
-- 
1.8.3.4

