Submitted By:            Steffen Pankratz <kratz00_at_gmx_dot_de>
Date:                    2010-02-07
Initial Package Version: 050a
Upstream Status:         Not submitted
Origin:                  Steffen Pankratz
Description:             Added Linux support, fixed many compiler warnings

diff -Naur hwun/src/crc32.pas hwun.patched/src/crc32.pas
--- hwun/src/crc32.pas	2001-12-29 12:49:34.000000000 +0100
+++ hwun.patched/src/crc32.pas	2010-02-07 22:38:37.000000000 +0100
@@ -54,11 +54,8 @@
 
  Procedure CRCaddbuffer(Var CRC:LongInt; Var BUF; Len:Word);
    Type BUFP=Array [0..65534] of Byte;
-   Var SEGM,OFFS,SEGL,OFSL:Word;
-       W:Word;
-       L:LongInt;
+   Var W:Word;
        BP:^BUFP;
-       B:Byte;
        CB:^Byte;
    Begin
     If LEN>0 then begin
@@ -81,4 +78,4 @@
  Begin
   CRCbuildtable;
  End.
-{---------------}
\ No newline at end of file
+{---------------}
diff -Naur hwun/src/hexadeci.pas hwun.patched/src/hexadeci.pas
--- hwun/src/hexadeci.pas	2001-11-11 16:55:18.000000000 +0100
+++ hwun.patched/src/hexadeci.pas	1970-01-01 01:00:00.000000000 +0100
@@ -1,31 +0,0 @@
-Unit HexaDeci;
-
-INTERFACE
-
-Function Hexa(Var L; B1:Byte):String;
-Function Deci(S:String):LongInt;
-
-IMPLEMENTATION
-
-Function Hexa(Var L; B1:Byte):String;
-Var S:String;B0,B2:Byte;
-Begin
- S:='';
- For B0:=1 to B1 do begin
-  If (B0 mod 2=1) then B2:=Mem[Ofs(L)+(B0-1) div 2] mod 16
-                  else B2:=Mem[Ofs(L)+(B0-1) div 2] div 16;
-  If (B2<$0a)then S:=Chr($30+B2)+S else S:=Chr($37+B2)+S;
- end;
- Hexa:=S;
-End;
-
-Function Deci(S:String):LongInt;
-Var B:Byte; L:LongInt;
-Begin
- L:=0; For B:=1 to Length(S) do If (Byte(S[B])>=$30) and (Byte(S[B])<=$39) then L:=L*16+Byte(S[B])-$30
-                           else If (Byte(Upcase(S[B]))>=$41) and (Byte(Upcase(S[B]))<=$46) then L:=L*16+Byte(Upcase(S[B]))-$37;
- Deci:=L;
-End;
-
-Begin
-End.
diff -Naur hwun/src/hwun.pas hwun.patched/src/hwun.pas
--- hwun/src/hwun.pas	2002-01-15 16:33:46.000000000 +0100
+++ hwun.patched/src/hwun.pas	2010-02-07 22:31:33.000000000 +0100
@@ -1,4 +1,4 @@
-uses hexadeci,crc32,sinflate,crt,dos;
+uses sysutils,strutils,crc32,sinflate,crt,dos;
 
 var rollback,useroffset:longint;
     renaming:boolean;
@@ -51,7 +51,6 @@
 
 function bfbyte(var bf:bfile):byte;
 var res:byte;
-    l:longint;
 begin if bfvalid(bf,bf.fp) then begin
   if not bfinmem(bf,bf.fp,1) then bffillbuffer(bf,bf.fp);
   move(bf.b^[bf.fp-bf.bo],res,1);
@@ -79,7 +78,6 @@
 
 function bfbytep(var bf:bfile; p:longint):byte;
 var res:byte;
-    l:longint;
 begin if bfvalid(bf,p) then begin
   if not bfinmem(bf,p,1) then bffillbuffer(bf,p);
   move(bf.b^[p-bf.bo],res,1);
@@ -240,6 +238,11 @@
 
 const hwunversion:word=$050a;
       hwundate:string[$0a]='2002-01-14';
+      (*$IFDEF LINUX*)
+      PathSeparator='/';
+      (*$ELSE*)
+      PathSeparator='\';
+      (*$ENDIF*)
 
 procedure writestatus(s:string);
 begin
@@ -249,10 +252,7 @@
 
 procedure writehwuninfo;
 var b:byte;
-    xp,yp:byte;
 begin
-  xp:=wherex;
-  yp:=wherey;
   textcolor(8);
   textbackground(0);
   gotoxy(1,4);
@@ -267,11 +267,11 @@
   for b:=$0d to $0f do begin write(' ³'); gotoxy($4e,wherey); write('³'); writeln; end;
   write(' À'); for b:=wherex to $4d do write('Ä'); write('Ù'); writeln;
   textcolor(7);
-  gotoxy(05,07); write('Approximated offset .... $',hexa(scrnv.offsa,8));
-  gotoxy(05,08); write('Real archive offset .... $',hexa(scrnv.offsr,8));
-  gotoxy(05,09); write('Last file start ........ $',hexa(scrnv.filestart,8));
-  gotoxy(05,10); write('Last file end .......... $',hexa(scrnv.fileend,8));
-  gotoxy(05,11); write('Last file CRC32 ........ $',hexa(scrnv.crc,8));
+  gotoxy(05,07); write('Approximated offset .... $',IntToHex(scrnv.offsa,8));
+  gotoxy(05,08); write('Real archive offset .... $',IntToHex(scrnv.offsr,8));
+  gotoxy(05,09); write('Last file start ........ $',IntToHex(scrnv.filestart,8));
+  gotoxy(05,10); write('Last file end .......... $',IntToHex(scrnv.fileend,8));
+  gotoxy(05,11); write('Last file CRC32 ........ $',IntToHex(scrnv.crc,8));
   gotoxy(42,07); write('Files extracted ........  ',scrnv.extract:8);
   gotoxy(42,08); write('Resolved filenames .....  ',scrnv.renamed:8);
   gotoxy(42,09); write('Multifiles .............  ',scrnv.multiv:8);
@@ -291,8 +291,8 @@
   textcolor(15);
   textbackground(1);
   write('  Heuristic Wise UNpacker v'); b:=hwunversion shr $0c;
-  write(hexa(b,1),'.');
-  write(hexa(hwunversion,3),' (',hwundate,')      (c) by J„germeister Markus  ');
+  write(IntToHex(b,1),'.');
+  write(IntToHex(hwunversion,3),' (',hwundate,')      (c) by J„germeister Markus  ');
   writeln;
   textcolor(1);
   textbackground(0);
@@ -302,7 +302,7 @@
 
 var scheisse:byte;
 
-function inflateread:byte; far;
+function inflateread:byte;
 begin with inflatev do begin
   if inbufferpos>=inbuffersize then begin
     if mfilepos(infile)=mfilesize(infile) then begin
@@ -321,7 +321,7 @@
   inc(inbufferpos);
 end; end;
 
-procedure inflatewrite(w:word); far;
+procedure inflatewrite(w:word);
 begin with inflatev do begin
   inc(outsize,w);
   blockwrite(outfile,SI_WINDOW^,w);
@@ -361,13 +361,13 @@
     fn:string;
 begin
   fn:=paramstr(1);
-  bo:=mopen(hwunv.infile,olddir+'\'+fn);
+  bo:=mopen(hwunv.infile,olddir+PathSeparator+fn);
   if bo then begin if fn[length(fn)-3]='.' then fn:=copy(fn,1,length(fn)-4);
-  end else bo:=mopen(hwunv.infile,olddir+'\'+fn+'.exe');
+  end else bo:=mopen(hwunv.infile,olddir+PathSeparator+fn+'.exe');
   if bo then begin
     writestatus('Installation is made of 01 file');
     fileno:=2;
-    while mappend(hwunv.infile,olddir+'\'+fn+'.w'+chr(fileno div 10+48)+chr(fileno mod 10+48)) do begin
+    while mappend(hwunv.infile,olddir+PathSeparator+fn+'.w'+chr(fileno div 10+48)+chr(fileno mod 10+48)) do begin
       writestatus('Installation is made of '+chr(fileno div 10+48)+chr(fileno mod 10+48)+' files');
       inc(fileno);
     end;
@@ -383,7 +383,7 @@
 procedure approximate;
 type tbuf=array[$0000..$c1ff] of byte;
 var buf:^tbuf;
-    l0,l1,l2,l3:longint;
+    l0,l1,l2:longint;
 begin
   new(buf);
   writestatus('Approximating to archive offset');
@@ -489,7 +489,7 @@
       mblockread(hwunv.infile,len2,$02);
       if len1+len2>0 then mblockread(hwunv.infile,buf,len1+len2);
     end;
-    inflate(hwunv.infile,'WISE'+hexa(scrnv.extract,4));
+    inflate(hwunv.infile,'WISE'+IntToHex(scrnv.extract,4));
     scrnv.filestart:=fs;
     scrnv.crc:=inflatev.crc;
     if hwunv.pkzip then inflatev.crc:=$04034b50;
@@ -522,9 +522,9 @@
 procedure renamefiles;
 var bf:bfile;
     df:bfile;
-    fn,nn:string;
+    nn:string;
     fileno:longint;
-    sh0,sh1,sh2,offs,l,l0,l1,l2,l3,l4,l5,res:longint;
+    sh0,sh1,offs,l,l0,l1,l2,l3,l4,l5,res:longint;
     instcnt:longint;
     f:file;
 begin
@@ -534,7 +534,7 @@
   instcnt:=0;
   while (fileno<scrnv.extract) and (fileno<6) and (res<>0) do begin
     inc(fileno);
-    bfopen(bf,'WISE'+hexa(fileno,4));
+    bfopen(bf,'WISE'+IntToHex(fileno,4));
     l:=$0000;
     while (res<>0) and (l<bf.fs) do begin
       while (l<bf.fs) and ((bfbytep(bf,l+0)<>$25) or (bfbytep(bf,l+1)<>$5c)) do inc(l);
@@ -627,12 +627,15 @@
             if (nn[l0]='\') and (nn[l0-1]='\') then nn:=copy(nn,1,l0-1)+copy(nn,l0+1,length(nn)-l0) else
             inc(l0);
           end;
-          assign(f,'WISE'+hexa(l1,4));
+          assign(f,'WISE'+IntToHex(l1,4));
          { Make directories }
           l0:=0;
           while l0<length(nn) do begin
             inc(l0);
             if nn[l0]='\' then begin
+               (*$IFDEF LINUX*)
+               nn:=copy(nn,1,l0-1)+ PathSeparator +copy(nn,l0+1,length(nn)-l0);
+               (*$ENDIF*)
               {$I-} MkDir(copy(nn,1,l0-1)); l:=IoResult; {$I+}
             end;
           end;
@@ -658,8 +661,8 @@
         end else if res=$80 then begin
           inc(instcnt);
          { Rename file }
-          assign(f,'WISE'+hexa(l1,4));
-          {$I-} rename(f,'INST'+hexa(instcnt,4)); l0:=IoResult; {$I+}
+          assign(f,'WISE'+IntToHex(l1,4));
+          {$I-} rename(f,'INST'+IntToHex(instcnt,4)); l0:=IoResult; {$I+}
           inc(scrnv.inst);
         end;
         scrnv.percent:=trunc(l5/scrnv.extract/4*1000)+9000;
@@ -698,11 +701,11 @@
     writeln('          - real archive offset finder now stable (own inflate)');
     writeln('          - renaming routine now very secure');
     writeln;
-    writeln(' Contact: jaegermeister.markus@gmx.de, http://jmeister.cjb.net');
+    writeln(' Contact: jaegermeister.markus@gmx.de, http://jmeister.cjb.net/');
   end else begin
     {$I-} mkdir(paramstr(2)); {$I+} l:=ioresult;
     getdir(0,olddir);
-    if olddir[length(olddir)]='\' then olddir:=copy(olddir,1,length(olddir)-1);
+    if olddir[length(olddir)]=PathSeparator then olddir:=copy(olddir,1,length(olddir)-1);
     {$I-} chdir(paramstr(2)); {$I+} l:=ioresult;
     if l<>0 then begin
       writehwuninfo;
@@ -717,10 +720,10 @@
       b:=1;
       while b<=length(options) do begin
         if upcase(options[b])='B' then begin
-          rollback:=deci(copy(options,b+1,4));
+          rollback:=Hex2Dec(copy(options,b+1,4));
           inc(b,4);
         end else if upcase(options[b])='U' then begin
-          useroffset:=deci(copy(options,b+1,4));
+          useroffset:=Hex2Dec(copy(options,b+1,4));
           inc(b,4);
         end else if upcase(options[b])='R' then begin
           renaming:=FALSE;
diff -Naur hwun/src/sinflate.pas hwun.patched/src/sinflate.pas
--- hwun/src/sinflate.pas	2002-01-15 01:07:58.000000000 +0100
+++ hwun.patched/src/sinflate.pas	2010-02-07 22:24:02.000000000 +0100
@@ -182,8 +182,6 @@
 
 IMPLEMENTATION
 
-uses hexadeci;
-
 function SI_GetError:string;
   var s:string;
   begin
@@ -468,7 +466,7 @@
       Lengthcode,CodeLength:byte;
       RepeatAmount:word;
       RepeatValue:byte;
-      ActualCodeLength,HighestCodeLength,Actual2,Highest2:byte;
+      ActualCodeLength,HighestCodeLength,Highest2:byte;
       BuildSuccess:boolean;
   begin
    { Read codelength codelengths (first tree) }
@@ -629,7 +627,6 @@
     Literal:word;
     Length:word;
     Distance:word;
-    Stored:pointer;
   begin
    { Force ReadBits to read a byte first }
     BitNumber:=8;
