mirror of
https://github.com/reactos/wine.git
synced 2024-11-29 14:40:56 +00:00
491502b951
Thu Oct 30 21:52:23 1997 Martin Boehme <boehme@informatik.mu-luebeck.de> * [windows/nonclient.c] Changed NC_TrackSysMenu to give the same behaviour as MS-Windows, i.e. system menu already appears when mouse button is depressed. Changed NC_HandleNCLButtonDblClk so that double clicks on scroll bar arrows are handled the same way as single clicks. * [windows/winpos.c] Fixed SetWindowPos32 to clear WIN_NO_REDRAW when SWP_SHOWWINDOW is set; this is the way MS-Windows behaves. Thu Oct 30 21:08:57 1997 Morten Welinder <terra@diku.dk> * [controls/status.c] In SW_SetText, fix condition, I hope. * [controls/menu.c] (GetMenuState32): Don't mask return value. Print more debug info. (MENU_MenuBarCalcSize): Be more careful when printing debug information. (MENU_SetItemData): Empty strings are separators. * [graphics/x11drv/text.c] Don't prototype CLIPPING_IntersectClipRect. * [include/dc.h] Prototype CLIPPING_IntersectClipRect. * [objects/font.c] Remove non-portable (and faulty) smartness in FONT_TextMetric*to*. In CreateFont32W and CreateFont16, handle null font name. * [objects/text.c] (TEXT_NextLine): Fix end-of-line bug. * [if1632/shell32.spec] Activate existing implementation of ExtractIconA. * [misc/shell.c] For Control_RunDLL, add types for parameters. Thu Oct 30 14:54:11 1997 Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de> * [controls/static.c] [include/windows.h] [misc/spy.c] Added some win32 defines to static controls, basic SS_BITMAP style handling implemented. [please add more, I am lacking knowledge and time] * [controls/status.c] part_num 255 seems to indicate whole statusline (win95 cdplayer.exe) * [if1632/thunk.c] [tools/build.c] Support lret and 0x66 lret calls for CallTo16_regs (needed for KERNEL32_45) Fixed KERNEL32_45, QT_Thunk (should work now). * [if1632/relay.c][if1632/builtin.c][tools/build.c][if1632/*32.spec] Added string dumping to relay debugging for win32 apifuncs. * [misc/ver.c] Fixed and cleaned up VerQueryValue*. * [multimedia/*.c][include/mmsystem.h][if1632/mmsystem.spec] [if1632/winmm.spec] Win32 support for lowlevel multimedia functions. Added some mixer* lowlevel functions. Some small fixes in the audio lowlevel queue handling, code reformatting/cleanups. * [debugger/hash.c] Don't show difference between 16bit symbols if they are in different segments. * [objects/cursoricon.c] Added GetIconInfo (partial) and CreateIconIndirect. * [windows/mdi.c] Fixed some "bad class" problems and crashes in MDICreateChild, which happen in Win32 (jwp32.exe). Wed Oct 29 00:57:27 1997 Bruce Milner <Bruce.Milner@genetics.utah.edu> * [if1632/winaspi.spec] [misc/aspi.c] [include/aspi.c] [documentation/aspi] [include/callback.h] Added support for 16 bit ASPI calls to linux generic SCSI. The support is not complete, but appears to run my Mustek scanner from within ipplus.exe. Mon Oct 27 00:59:41 1997 Alex Korobka <alex@trantor.pharm.sunysb.edu> * [windows/dce.c] DC reuse framework. Sun Oct 26 18:41:21 1997 Huw D M Davies <h.davies1@physics.oxford.ac.uk> * [graphics/x11drv/xfont.c] Substituted fonts are removed from the alias table. References to the old name are also updated. * [controls/combo.c] LB_SELECTSTRING32 not CB_SELECTSTRING32 should be sent to ComboLBox. Sun Oct 26 14:25:00 1997 Nikita V. Youshchenko <yoush@cs.msu.su> * [include/drive.h] [files/drive.c] [msdos/int21.c] Partially implemented DOS drive mapping (int21 AX=440F). Sat Oct 25 13:03:29 1997 Alexandre Julliard <julliard@lrc.epfl.ch> * [debugger/debug.l] Support '.' in identifiers. Use "x . y" to access structure fields. * [debugger/hash.c] [loader/pe_image.c] Load entry points of Win32 modules only when entering the debugger. * [debugger/break.c] New function DEBUG_AddModuleBreakpoint() to set a breakpoint at the start of every module. * [files/file.c] FILE_mmap() can now fake mmap() for unaligned offsets or broken filesystems. * [include/callback.h] [misc/callback.c] [if1632/thunk.c] Use a table of callbacks instead of macros to differentiate between emulator and Winelib. * [loader/task.c] Initialize current directory from cwd, not from module path. * [tools/build.c] Read CallTo16 prototypes directly from thunk.c source file. * [windows/winproc.c] [windows/mdi.c] Added translation for WM_MDIACTIVATE and WM_MDIGETACTIVE. Fri Oct 24 21:41:25 1997 Uwe Bonnes <bon@elektron.ikp.tu-darmstadt.de> * [files/drive.c] Allow arguments like "a" for the drive related apis. * [memory/global.c] Keep the calculation for dwMemoryLoad in range. * [misc/crtdll.c] Make CRTDLL_getcwd use GetCurrentDirectory32A and alloc its memory if requested. Implemented CRTDLL_rename and CRTDLL_stat needed for lcc-win32:wedit.exe. Implemented CRTDLL__fullpath. * [misc/comm.c] High speed modes for the 16-bit mode Comm functions. * [misc/cpu.c] As applications may treat lpMaximumApplicationAddress as long, use a valid long number. * [misc/main.c] In SystemParametersInfo16 ignore SPI_GETHIGHCONTRAST too. * [misc/ole2nls.c] Implement LCMAP_UPPERCASE for LCMapString32. * [misc/wsprintf] Made WPRINTF_ParseFormatA understand %ws. * [win32/file.c] Ignore FILE_ATTRIBUTE_NORMAL. Stub for ReadFileEx. Fri Oct 24 15:36:02 1997 Doug Ridgway <ridgway@routh.ucsd.edu> * [memory/local.c] Local heap exhaustion message now prints which builtin heap filled. Fri Oct 24 00:46:34 1997 Huw D M Davies <h.davies1@physics.oxford.ac.uk> * [windows/dialog.c] Reversed CreateFont16/32W typo. Thu Oct 23 23:44:20 1997 Kristian Nielsen <kristian.nielsen@risoe.dk> * [if1632/user.spec] Fixed argument list for ChangeClipboardChain. * [windows/mdi.c] Pass correct hInstance to CreateWindow16() in MDICreateChild(). Mon Oct 20 11:51:24 1997 Carsten Fallesen <cf@it.dtu.dk> * [objects/metafile.c] Added support for META_SETTEXTCHAREXTRA. * [objects/region.c] Fixed crash in XPolygonRegion if there is only one point in in the region. * [if1632/gdi32.spec][include/gdi.h][include/windows.h] [objects/gdiobj.c] Completed OBJ_XXX defines in gdi.h, removed OBJ_XXX in gdiobj.c and included gdi.h instead. Implemented GetObjectType32(). Thu Oct 16 17:21:32 1997 Philippe De Muyter <phdm@info.ucl.ac.be> * [documentation/wine.texinfo] Fixed WIN32 and Makefiles entries of Reference manual node, that made makeinfo dump core. Mon Oct 13 17:15:57 1997 Robert Wilhelm <robert@physiol.med.tu-muenchen.de> * [if1632/crtdll.spec] Added missing math functions y0(), y1(), y2(), floor(), frexp(), ldexp(), modf().
646 lines
16 KiB
C
646 lines
16 KiB
C
/*
|
|
* LZ Decompression functions
|
|
*
|
|
* Copyright 1996 Marcus Meissner
|
|
*/
|
|
/*
|
|
* FIXME: return values might be wrong
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <ctype.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include "windows.h"
|
|
#include "file.h"
|
|
#include "heap.h"
|
|
#include "ldt.h"
|
|
#include "lzexpand.h"
|
|
#include "stddebug.h"
|
|
#include "debug.h"
|
|
|
|
|
|
/* The readahead length of the decompressor. Reading single bytes
|
|
* using _lread() would be SLOW.
|
|
*/
|
|
#define GETLEN 2048
|
|
|
|
/* Format of first 14 byte of LZ compressed file */
|
|
struct lzfileheader {
|
|
BYTE magic[8];
|
|
BYTE compressiontype;
|
|
CHAR lastchar;
|
|
DWORD reallength;
|
|
};
|
|
static BYTE LZMagic[8]={'S','Z','D','D',0x88,0xf0,0x27,0x33};
|
|
|
|
static struct lzstate {
|
|
HFILE32 lzfd; /* the handle used by the program */
|
|
HFILE32 realfd; /* the real filedescriptor */
|
|
CHAR lastchar; /* the last char of the filename */
|
|
|
|
DWORD reallength; /* the decompressed length of the file */
|
|
DWORD realcurrent; /* the position the decompressor currently is */
|
|
DWORD realwanted; /* the position the user wants to read from */
|
|
|
|
BYTE table[0x1000]; /* the rotating LZ table */
|
|
UINT32 curtabent; /* CURrent TABle ENTry */
|
|
|
|
BYTE stringlen; /* length and position of current string */
|
|
DWORD stringpos; /* from stringtable */
|
|
|
|
|
|
WORD bytetype; /* bitmask within blocks */
|
|
|
|
BYTE *get; /* GETLEN bytes */
|
|
DWORD getcur; /* current read */
|
|
DWORD getlen; /* length last got */
|
|
} *lzstates=NULL;
|
|
static int nroflzstates=0;
|
|
|
|
/* reads one compressed byte, including buffering */
|
|
#define GET(lzs,b) _lzget(lzs,&b)
|
|
#define GET_FLUSH(lzs) lzs->getcur=lzs->getlen;
|
|
|
|
static int
|
|
_lzget(struct lzstate *lzs,BYTE *b) {
|
|
if (lzs->getcur<lzs->getlen) {
|
|
*b = lzs->get[lzs->getcur++];
|
|
return 1;
|
|
} else {
|
|
int ret = _lread32(lzs->realfd,lzs->get,GETLEN);
|
|
if (ret==HFILE_ERROR32)
|
|
return HFILE_ERROR32;
|
|
if (ret==0)
|
|
return 0;
|
|
lzs->getlen = ret;
|
|
lzs->getcur = 1;
|
|
*b = *(lzs->get);
|
|
return 1;
|
|
}
|
|
}
|
|
/* internal function, reads lzheader
|
|
* returns BADINHANDLE for non filedescriptors
|
|
* return 0 for file not compressed using LZ
|
|
* return UNKNOWNALG for unknown algorithm
|
|
* returns lzfileheader in *head
|
|
*/
|
|
static INT32 read_header(HFILE32 fd,struct lzfileheader *head)
|
|
{
|
|
BYTE buf[14];
|
|
|
|
if (_llseek32(fd,0,SEEK_SET)==-1)
|
|
return LZERROR_BADINHANDLE;
|
|
|
|
/* We can't directly read the lzfileheader struct due to
|
|
* structure element alignment
|
|
*/
|
|
if (_lread32(fd,buf,14)<14)
|
|
return 0;
|
|
memcpy(head->magic,buf,8);
|
|
memcpy(&(head->compressiontype),buf+8,1);
|
|
memcpy(&(head->lastchar),buf+9,1);
|
|
|
|
/* FIXME: consider endianess on non-intel architectures */
|
|
memcpy(&(head->reallength),buf+10,4);
|
|
|
|
if (memcmp(head->magic,LZMagic,8))
|
|
return 0;
|
|
if (head->compressiontype!='A')
|
|
return LZERROR_UNKNOWNALG;
|
|
return 1;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* LZStart16 (LZEXPAND.7)
|
|
*/
|
|
INT16 WINAPI LZStart16(void)
|
|
{
|
|
dprintf_file(stddeb,"LZStart16(void)\n");
|
|
return 1;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZStart32 (LZ32.6)
|
|
*/
|
|
INT32 WINAPI LZStart32(void)
|
|
{
|
|
dprintf_file(stddeb,"LZStart32(void)\n");
|
|
return 1;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZInit16 (LZEXPAND.3)
|
|
*/
|
|
HFILE16 WINAPI LZInit16( HFILE16 hfSrc )
|
|
{
|
|
return LZInit32( hfSrc );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZInit32 (LZ32.2)
|
|
*
|
|
* initializes internal decompression buffers, returns lzfiledescriptor.
|
|
* (return value the same as hfSrc, if hfSrc is not compressed)
|
|
* on failure, returns error code <0
|
|
* lzfiledescriptors range from 0x400 to 0x410 (only 16 open files per process)
|
|
* we use as much as we need, we just OR 0x400 to the passed HFILE.
|
|
*
|
|
* since _llseek uses the same types as libc.lseek, we just use the macros of
|
|
* libc
|
|
*/
|
|
HFILE32 WINAPI LZInit32( HFILE32 hfSrc )
|
|
{
|
|
|
|
struct lzfileheader head;
|
|
struct lzstate *lzs;
|
|
DWORD ret;
|
|
|
|
dprintf_file(stddeb,"LZInit(%d)\n",hfSrc);
|
|
ret=read_header(hfSrc,&head);
|
|
if (ret<=0) {
|
|
_llseek32(hfSrc,0,SEEK_SET);
|
|
return ret?ret:hfSrc;
|
|
}
|
|
lzstates = HeapReAlloc( GetProcessHeap(), 0, lzstates,
|
|
(++nroflzstates)*sizeof(struct lzstate) );
|
|
lzs = lzstates+(nroflzstates-1);
|
|
|
|
memset(lzs,'\0',sizeof(*lzs));
|
|
lzs->realfd = hfSrc;
|
|
lzs->lzfd = hfSrc | 0x400;
|
|
lzs->lastchar = head.lastchar;
|
|
lzs->reallength = head.reallength;
|
|
|
|
lzs->get = HEAP_xalloc( GetProcessHeap(), 0, GETLEN );
|
|
lzs->getlen = 0;
|
|
lzs->getcur = 0;
|
|
|
|
/* Yes, preinitialize with spaces */
|
|
memset(lzs->table,' ',0x1000);
|
|
/* Yes, start 16 byte from the END of the table */
|
|
lzs->curtabent = 0xff0;
|
|
return lzs->lzfd;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZDone (LZEXPAND.9) (LZ32.8)
|
|
*/
|
|
void WINAPI LZDone(void)
|
|
{
|
|
dprintf_file(stddeb,"LZDone()\n");
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetExpandedName16 (LZEXPAND.10)
|
|
*/
|
|
INT16 WINAPI GetExpandedName16( LPCSTR in, LPSTR out )
|
|
{
|
|
return (INT16)GetExpandedName32A( in, out );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetExpandedName32A (LZ32.9)
|
|
*
|
|
* gets the full filename of the compressed file 'in' by opening it
|
|
* and reading the header
|
|
*
|
|
* "file." is being translated to "file"
|
|
* "file.bl_" (with lastchar 'a') is being translated to "file.bla"
|
|
* "FILE.BL_" (with lastchar 'a') is being translated to "FILE.BLA"
|
|
*/
|
|
|
|
INT32 WINAPI GetExpandedName32A( LPCSTR in, LPSTR out )
|
|
{
|
|
struct lzfileheader head;
|
|
HFILE32 fd;
|
|
OFSTRUCT ofs;
|
|
INT32 fnislowercased,ret,len;
|
|
LPSTR s,t;
|
|
|
|
dprintf_file(stddeb,"GetExpandedName(%s)\n",in);
|
|
fd=OpenFile32(in,&ofs,OF_READ);
|
|
if (fd==HFILE_ERROR32)
|
|
return (INT32)(INT16)LZERROR_BADINHANDLE;
|
|
strcpy(out,in);
|
|
ret=read_header(fd,&head);
|
|
if (ret<=0) {
|
|
/* not a LZ compressed file, so the expanded name is the same
|
|
* as the input name */
|
|
_lclose32(fd);
|
|
return 1;
|
|
}
|
|
|
|
|
|
/* look for directory prefix and skip it. */
|
|
s=out;
|
|
while (NULL!=(t=strpbrk(s,"/\\:")))
|
|
s=t+1;
|
|
|
|
/* now mangle the basename */
|
|
if (!*s) {
|
|
/* FIXME: hmm. shouldn't happen? */
|
|
fprintf(stddeb,__FILE__":GetExpandedFileName(), specified a directory or what? (%s)\n",in);
|
|
_lclose32(fd);
|
|
return 1;
|
|
}
|
|
/* see if we should use lowercase or uppercase on the last char */
|
|
fnislowercased=1;
|
|
t=s+strlen(s)-1;
|
|
while (t>=out) {
|
|
if (!isalpha(*t)) {
|
|
t--;
|
|
continue;
|
|
}
|
|
fnislowercased=islower(*t);
|
|
break;
|
|
}
|
|
if (isalpha(head.lastchar)) {
|
|
if (fnislowercased)
|
|
head.lastchar=tolower(head.lastchar);
|
|
else
|
|
head.lastchar=toupper(head.lastchar);
|
|
}
|
|
|
|
/* now look where to replace the last character */
|
|
if (NULL!=(t=strchr(s,'.'))) {
|
|
if (t[1]=='\0') {
|
|
t[0]='\0';
|
|
} else {
|
|
len=strlen(t)-1;
|
|
if (t[len]=='_')
|
|
t[len]=head.lastchar;
|
|
}
|
|
} /* else no modification necessary */
|
|
_lclose32(fd);
|
|
return 1;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetExpandedName32W (LZ32.11)
|
|
*/
|
|
INT32 WINAPI GetExpandedName32W( LPCWSTR in, LPWSTR out )
|
|
{
|
|
char *xin,*xout;
|
|
INT32 ret;
|
|
|
|
xout = HeapAlloc( GetProcessHeap(), 0, lstrlen32W(in)+3 );
|
|
xin = HEAP_strdupWtoA( GetProcessHeap(), 0, in );
|
|
ret = GetExpandedName16(xin,xout);
|
|
if (ret>0) lstrcpyAtoW(out,xout);
|
|
HeapFree( GetProcessHeap(), 0, xin );
|
|
HeapFree( GetProcessHeap(), 0, xout );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZRead16 (LZEXPAND.5)
|
|
*/
|
|
INT16 WINAPI LZRead16( HFILE16 fd, LPVOID buf, UINT16 toread )
|
|
{
|
|
return LZRead32(fd,buf,toread);
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZRead32 (LZ32.4)
|
|
*/
|
|
INT32 WINAPI LZRead32( HFILE32 fd, LPVOID vbuf, UINT32 toread )
|
|
{
|
|
int i,howmuch;
|
|
BYTE b,*buf;
|
|
struct lzstate *lzs;
|
|
|
|
buf=(LPBYTE)vbuf;
|
|
dprintf_file(stddeb,"LZRead32(%d,%p,%d)\n",fd,buf,toread);
|
|
howmuch=toread;
|
|
for (i=0;i<nroflzstates;i++)
|
|
if (lzstates[i].lzfd==fd)
|
|
break;
|
|
if (i==nroflzstates)
|
|
return _lread32(fd,buf,toread);
|
|
lzs=lzstates+i;
|
|
|
|
/* The decompressor itself is in a define, cause we need it twice
|
|
* in this function. (the decompressed byte will be in b)
|
|
*/
|
|
#define DECOMPRESS_ONE_BYTE \
|
|
if (lzs->stringlen) { \
|
|
b = lzs->table[lzs->stringpos]; \
|
|
lzs->stringpos = (lzs->stringpos+1)&0xFFF; \
|
|
lzs->stringlen--; \
|
|
} else { \
|
|
if (!(lzs->bytetype&0x100)) { \
|
|
if (1!=GET(lzs,b)) \
|
|
return toread-howmuch; \
|
|
lzs->bytetype = b|0xFF00; \
|
|
} \
|
|
if (lzs->bytetype & 1) { \
|
|
if (1!=GET(lzs,b)) \
|
|
return toread-howmuch; \
|
|
} else { \
|
|
BYTE b1,b2; \
|
|
\
|
|
if (1!=GET(lzs,b1)) \
|
|
return toread-howmuch; \
|
|
if (1!=GET(lzs,b2)) \
|
|
return toread-howmuch; \
|
|
/* Format: \
|
|
* b1 b2 \
|
|
* AB CD \
|
|
* where CAB is the stringoffset in the table\
|
|
* and D+3 is the len of the string \
|
|
*/ \
|
|
lzs->stringpos = b1|((b2&0xf0)<<4); \
|
|
lzs->stringlen = (b2&0xf)+2; \
|
|
/* 3, but we use a byte already below ... */\
|
|
b = lzs->table[lzs->stringpos];\
|
|
lzs->stringpos = (lzs->stringpos+1)&0xFFF;\
|
|
} \
|
|
lzs->bytetype>>=1; \
|
|
} \
|
|
/* store b in table */ \
|
|
lzs->table[lzs->curtabent++]= b; \
|
|
lzs->curtabent &= 0xFFF; \
|
|
lzs->realcurrent++;
|
|
|
|
/* if someone has seeked, we have to bring the decompressor
|
|
* to that position
|
|
*/
|
|
if (lzs->realcurrent!=lzs->realwanted) {
|
|
/* if the wanted position is before the current position
|
|
* I see no easy way to unroll ... We have to restart at
|
|
* the beginning. *sigh*
|
|
*/
|
|
if (lzs->realcurrent>lzs->realwanted) {
|
|
/* flush decompressor state */
|
|
_llseek32(lzs->realfd,14,SEEK_SET);
|
|
GET_FLUSH(lzs);
|
|
lzs->realcurrent= 0;
|
|
lzs->bytetype = 0;
|
|
lzs->stringlen = 0;
|
|
memset(lzs->table,' ',0x1000);
|
|
lzs->curtabent = 0xFF0;
|
|
}
|
|
while (lzs->realcurrent<lzs->realwanted) {
|
|
DECOMPRESS_ONE_BYTE;
|
|
}
|
|
}
|
|
|
|
while (howmuch) {
|
|
DECOMPRESS_ONE_BYTE;
|
|
lzs->realwanted++;
|
|
*buf++ = b;
|
|
howmuch--;
|
|
}
|
|
return toread;
|
|
#undef DECOMPRESS_ONE_BYTE
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZSeek16 (LZEXPAND.4)
|
|
*/
|
|
LONG WINAPI LZSeek16( HFILE16 fd, LONG off, INT16 type )
|
|
{
|
|
return LZSeek32( fd, off, type );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZSeek32 (LZ32.3)
|
|
*/
|
|
LONG WINAPI LZSeek32( HFILE32 fd, LONG off, INT32 type )
|
|
{
|
|
int i;
|
|
struct lzstate *lzs;
|
|
LONG newwanted;
|
|
|
|
dprintf_file(stddeb,"LZSeek(%d,%ld,%d)\n",fd,off,type);
|
|
for (i=0;i<nroflzstates;i++)
|
|
if (lzstates[i].lzfd==fd)
|
|
break;
|
|
/* not compressed? just use normal _llseek() */
|
|
if (i==nroflzstates)
|
|
return _llseek32(fd,off,type);
|
|
lzs = lzstates+i;
|
|
newwanted = lzs->realwanted;
|
|
switch (type) {
|
|
case 1: /* SEEK_CUR */
|
|
newwanted += off;
|
|
break;
|
|
case 2: /* SEEK_END */
|
|
newwanted = lzs->reallength-off;
|
|
break;
|
|
default:/* SEEK_SET */
|
|
newwanted = off;
|
|
break;
|
|
}
|
|
if (newwanted>lzs->reallength)
|
|
return LZERROR_BADVALUE;
|
|
if (newwanted<0)
|
|
return LZERROR_BADVALUE;
|
|
lzs->realwanted = newwanted;
|
|
return newwanted;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZCopy16 (LZEXPAND.1)
|
|
*/
|
|
LONG WINAPI LZCopy16( HFILE16 src, HFILE16 dest )
|
|
{
|
|
return LZCopy32( src, dest );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZCopy32 (LZ32.0)
|
|
*
|
|
* Copies everything from src to dest
|
|
* if src is a LZ compressed file, it will be uncompressed.
|
|
* will return the number of bytes written to dest or errors.
|
|
*/
|
|
LONG WINAPI LZCopy32( HFILE32 src, HFILE32 dest )
|
|
{
|
|
int i,ret,wret;
|
|
LONG len;
|
|
#define BUFLEN 1000
|
|
BYTE buf[BUFLEN];
|
|
INT32 WINAPI (*xread)(HFILE32,LPVOID,UINT32);
|
|
|
|
dprintf_file(stddeb,"LZCopy(%d,%d)\n",src,dest);
|
|
for (i=0;i<nroflzstates;i++)
|
|
if (src==lzstates[i].lzfd)
|
|
break;
|
|
|
|
/* not compressed? just copy */
|
|
if (i==nroflzstates)
|
|
xread=(INT32(*)(HFILE32,LPVOID,UINT32))_lread32;
|
|
else
|
|
xread=LZRead32;
|
|
len=0;
|
|
while (1) {
|
|
ret=xread(src,buf,BUFLEN);
|
|
if (ret<=0) {
|
|
if (ret==0)
|
|
break;
|
|
if (ret==-1)
|
|
return LZERROR_READ;
|
|
return ret;
|
|
}
|
|
len += ret;
|
|
wret = _lwrite32(dest,buf,ret);
|
|
if (wret!=ret)
|
|
return LZERROR_WRITE;
|
|
}
|
|
return len;
|
|
#undef BUFLEN
|
|
}
|
|
|
|
/* reverses GetExpandedPathname */
|
|
static LPSTR LZEXPAND_MangleName( LPCSTR fn )
|
|
{
|
|
char *p;
|
|
char *mfn = (char *)HEAP_xalloc( GetProcessHeap(), 0,
|
|
strlen(fn) + 3 ); /* "._" and \0 */
|
|
strcpy( mfn, fn );
|
|
if (!(p = strrchr( mfn, '\\' ))) p = mfn;
|
|
if ((p = strchr( p, '.' )))
|
|
{
|
|
p++;
|
|
if (strlen(p) < 3) strcat( p, "_" ); /* append '_' */
|
|
else p[strlen(p)-1] = '_'; /* replace last character */
|
|
}
|
|
else strcat( mfn, "._" ); /* append "._" */
|
|
return mfn;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZOpenFile16 (LZEXPAND.2)
|
|
*/
|
|
HFILE16 WINAPI LZOpenFile16( LPCSTR fn, LPOFSTRUCT ofs, UINT16 mode )
|
|
{
|
|
return LZOpenFile32A( fn, ofs, mode );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZOpenFile32A (LZ32.1)
|
|
*
|
|
* Opens a file. If not compressed, open it as a normal file.
|
|
*/
|
|
HFILE32 WINAPI LZOpenFile32A( LPCSTR fn, LPOFSTRUCT ofs, UINT32 mode )
|
|
{
|
|
HFILE32 fd,cfd;
|
|
|
|
dprintf_file(stddeb,"LZOpenFile(%s,%p,%d)\n",fn,ofs,mode);
|
|
/* 0x70 represents all OF_SHARE_* flags, ignore them for the check */
|
|
fd=OpenFile32(fn,ofs,mode);
|
|
if (fd==HFILE_ERROR32)
|
|
{
|
|
LPSTR mfn = LZEXPAND_MangleName(fn);
|
|
fd = OpenFile32(mfn,ofs,mode);
|
|
HeapFree( GetProcessHeap(), 0, mfn );
|
|
}
|
|
if ((mode&~0x70)!=OF_READ)
|
|
return fd;
|
|
if (fd==HFILE_ERROR32)
|
|
return HFILE_ERROR32;
|
|
cfd=LZInit32(fd);
|
|
if (cfd<=0)
|
|
return fd;
|
|
return cfd;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZOpenFile32W (LZ32.10)
|
|
*/
|
|
HFILE32 WINAPI LZOpenFile32W( LPCWSTR fn, LPOFSTRUCT ofs, UINT32 mode )
|
|
{
|
|
LPSTR xfn;
|
|
LPWSTR yfn;
|
|
HFILE32 ret;
|
|
|
|
xfn = HEAP_strdupWtoA( GetProcessHeap(), 0, fn);
|
|
ret = LZOpenFile16(xfn,ofs,mode);
|
|
HeapFree( GetProcessHeap(), 0, xfn );
|
|
if (ret!=HFILE_ERROR32) {
|
|
/* ofs->szPathName is an array with the OFSTRUCT */
|
|
yfn = HEAP_strdupAtoW( GetProcessHeap(), 0, ofs->szPathName );
|
|
memcpy(ofs->szPathName,yfn,lstrlen32W(yfn)*2+2);
|
|
HeapFree( GetProcessHeap(), 0, yfn );
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZClose16 (LZEXPAND.6)
|
|
*/
|
|
void WINAPI LZClose16( HFILE16 fd )
|
|
{
|
|
return LZClose32( fd );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* LZClose32 (LZ32.5)
|
|
*/
|
|
void WINAPI LZClose32( HFILE32 fd )
|
|
{
|
|
int i;
|
|
|
|
dprintf_file(stddeb,"LZClose(%d)\n",fd);
|
|
for (i=0;i<nroflzstates;i++)
|
|
if (lzstates[i].lzfd==fd)
|
|
break;
|
|
if (i==nroflzstates) {
|
|
_lclose32(fd);
|
|
return;
|
|
}
|
|
if (lzstates[i].get)
|
|
HeapFree( GetProcessHeap(), 0, lzstates[i].get );
|
|
_lclose32(lzstates[i].realfd);
|
|
memmove(lzstates+i,lzstates+i+1,
|
|
sizeof(struct lzstate)*(nroflzstates-i-1));
|
|
nroflzstates--;
|
|
lzstates = HeapReAlloc( GetProcessHeap(), 0, lzstates,
|
|
sizeof(struct lzstate)*nroflzstates );
|
|
}
|
|
|
|
/***********************************************************************
|
|
* CopyLZFile16 (LZEXPAND.8)
|
|
*/
|
|
LONG WINAPI CopyLZFile16( HFILE16 src, HFILE16 dest )
|
|
{
|
|
dprintf_file(stddeb,"CopyLZFile16(%d,%d)\n",src,dest);
|
|
return LZCopy32(src,dest);
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* CopyLZFile32 (LZ32.7)
|
|
*
|
|
* Copy src to dest (including uncompressing src).
|
|
* NOTE: Yes. This is exactly the same function as LZCopy.
|
|
*/
|
|
LONG WINAPI CopyLZFile32( HFILE32 src, HFILE32 dest )
|
|
{
|
|
dprintf_file(stddeb,"CopyLZFile32(%d,%d)\n",src,dest);
|
|
return LZCopy32(src,dest);
|
|
}
|