This commit is contained in:
King_DuckZ 2020-05-05 20:22:33 +02:00
parent 35c0b24c92
commit 06b37f8d16
8 changed files with 74 additions and 47 deletions

View file

@ -10,31 +10,22 @@
# include <sys/stat.h> # include <sys/stat.h>
#endif #endif
// le16toh 등등..
#if (defined(__FreeBSD__) || defined(__DARWIN__))
# include <sys/endian.h>
#endif
#ifdef __linux__ // __BYTE_ORDER 가져오기
# include <endian.h>
#endif
#ifdef _UNALZ_ICONV // code page support #ifdef _UNALZ_ICONV // code page support
# include <iconv.h> # include <iconv.h>
#endif #endif
#ifdef __linux__ // iconv.h 때문에 필요 #ifdef __linux__ // __BYTE_ORDER °¡Á®¿À±â
# include <errno.h> # include <errno.h> // iconv.h ¶§¹®¿¡ ÇÊ¿ä
#endif #endif
#ifndef _WIN32 // WIN32 는 무조건 LITTLE 이니까 필요없다.
#define swapint64(Data) (INT64) ( (((Data)&0x00000000000000FFLL) << 56) | (((Data)&0x000000000000FF00LL) << 40) | (((Data)&0x0000000000FF0000LL) << 24) | (((Data)&0x00000000FF000000LL) << 8) | (((Data)&0x000000FF00000000LL) >> 8) | (((Data)&0x0000FF0000000000LL) >> 24) | (((Data)&0x00FF000000000000LL) >> 40) | (((Data)&0xFF00000000000000LL) >> 56) ) #define swapint64(Data) (INT64) ( (((Data)&0x00000000000000FFLL) << 56) | (((Data)&0x000000000000FF00LL) << 40) | (((Data)&0x0000000000FF0000LL) << 24) | (((Data)&0x00000000FF000000LL) << 8) | (((Data)&0x000000FF00000000LL) >> 8) | (((Data)&0x0000FF0000000000LL) >> 24) | (((Data)&0x00FF000000000000LL) >> 40) | (((Data)&0xFF00000000000000LL) >> 56) )
#define swapint32(a) ((((a)&0xff)<<24)+(((a>>8)&0xff)<<16)+(((a>>16)&0xff)<<8)+(((a>>24)&0xff))) #define swapint32(a) ((((a)&0xff)<<24)+(((a>>8)&0xff)<<16)+(((a>>16)&0xff)<<8)+(((a>>24)&0xff)))
#define swapint16(a) (((a)&0xff)<<8)+(((a>>8)&0xff)) #define swapint16(a) (((a)&0xff)<<8)+(((a>>8)&0xff))
#endif
////////////////////////////////////////////////////////////////////////////
//// byte-order : little to host //// //// byte-order : little to host ////
////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32 // little to little #ifdef _WIN32 // little to little
inline UINT16 unalz_le16toh(UINT16 a){return a;} inline UINT16 unalz_le16toh(UINT16 a){return a;}
@ -42,13 +33,23 @@
inline UINT64 unalz_le64toh(UINT64 a){return a;} inline UINT64 unalz_le64toh(UINT64 a){return a;}
#endif #endif
#if (defined(__FreeBSD__) || defined(__DARWIN__)) #ifdef __FreeBSD__
# include <sys/endian.h>
inline UINT16 unalz_le16toh(UINT16 a){return le16toh(a);} inline UINT16 unalz_le16toh(UINT16 a){return le16toh(a);}
inline UINT32 unalz_le32toh(UINT32 a){return le32toh(a);} inline UINT32 unalz_le32toh(UINT32 a){return le32toh(a);}
inline UINT64 unalz_le64toh(UINT64 a){return le64toh(a);} inline UINT64 unalz_le64toh(UINT64 a){return le64toh(a);}
#endif #endif
#ifdef __linux__ // 리눅스에서 little 을 host 로 바꾸는 함수를 모르겠다.. 그래서 그냥 define 된걸로 판단한다. #ifdef __APPLE__
# include <machine/byte_order.h>
inline UINT16 unalz_le16toh(UINT16 a){return NXSwapShort(a);}
inline UINT32 unalz_le32toh(UINT32 a){return NXSwapLong(a);}
inline UINT64 unalz_le64toh(UINT64 a){return NXSwapLongLong(a);}
#endif
#ifdef __linux__
# include <endian.h>
# if __BYTE_ORDER == __BIG_ENDIAN # if __BYTE_ORDER == __BIG_ENDIAN
inline UINT16 unalz_le16toh(UINT16 a){return swapint16(a);} inline UINT16 unalz_le16toh(UINT16 a){return swapint16(a);}
inline UINT32 unalz_le32toh(UINT32 a){return swapint32(a);} inline UINT32 unalz_le32toh(UINT32 a){return swapint32(a);}
@ -58,6 +59,10 @@
inline UINT32 unalz_le32toh(UINT32 a){return (a);} inline UINT32 unalz_le32toh(UINT32 a){return (a);}
inline UINT64 unalz_le64toh(UINT64 a){return (a);} inline UINT64 unalz_le64toh(UINT64 a){return (a);}
# endif # endif
//# include <asm/byteorder.h>
// inline UINT16 unalz_le16toh(UINT16 a){return le16_to_cpu(a);}
// inline UINT32 unalz_le32toh(UINT32 a){return le32_to_cpu(a);}
// inline UINT64 unalz_le64toh(UINT64 a){return le64_to_cpu(a);}
#endif #endif
@ -633,7 +638,7 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi
} }
#endif #endif
// CALLBACK ¼¼Æà // CALLBACK ¼¼ÆÃ
if(m_pFuncCallBack) m_pFuncCallBack(m_posCur->fileName, 0,0,m_pCallbackParam, NULL); if(m_pFuncCallBack) m_pFuncCallBack(m_posCur->fileName, 0,m_posCur->uncompressedSize,m_pCallbackParam, NULL);
ret = ExtractTo(&dest); ret = ExtractTo(&dest);
if(dest.fp!=NULL)fclose(dest.fp); if(dest.fp!=NULL)fclose(dest.fp);
@ -1239,7 +1244,8 @@ BOOL CUnAlz::FOpen(const char* szPathName)
char* temp = strdup(szPathName); // ÆÄÀÏ¸í º¹»ç.. char* temp = strdup(szPathName); // ÆÄÀÏ¸í º¹»ç..
int i; int i;
int nLen = strlen(szPathName); int nLen = strlen(szPathName);
UINT32 dwFileSizeLow,dwFileSizeHigh; UINT64 nFileSizeLow;
UINT32 dwFileSizeHigh;
m_nFileCount = 0; m_nFileCount = 0;
m_nCurFile = 0; m_nCurFile = 0;
m_nVirtualFilePos = 0; m_nVirtualFilePos = 0;
@ -1251,17 +1257,17 @@ BOOL CUnAlz::FOpen(const char* szPathName)
#ifdef _WIN32 #ifdef _WIN32
m_files[i].fp = CreateFileA(temp, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); m_files[i].fp = CreateFileA(temp, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if(m_files[i].fp==INVALID_HANDLE_VALUE) break; if(m_files[i].fp==INVALID_HANDLE_VALUE) break;
dwFileSizeLow = GetFileSize(m_files[i].fp, (DWORD*)&dwFileSizeHigh); nFileSizeLow = GetFileSize(m_files[i].fp, (DWORD*)&dwFileSizeHigh);
#else #else
m_files[i].fp = fopen(temp, "rb"); m_files[i].fp = fopen(temp, "rb");
if(m_files[i].fp==NULL) break; if(m_files[i].fp==NULL) break;
dwFileSizeHigh=0; dwFileSizeHigh=0;
fseek(m_files[i].fp,0,SEEK_END); fseek(m_files[i].fp,0,SEEK_END);
dwFileSizeLow=ftell(m_files[i].fp); // _LARGEFILE64_SOURCE 호환성 문제 발생.. T.T nFileSizeLow=ftell(m_files[i].fp);
fseek(m_files[i].fp,0,SEEK_SET); fseek(m_files[i].fp,0,SEEK_SET);
#endif #endif
m_nFileCount++; m_nFileCount++;
m_files[i].nFileSize = ((INT64)dwFileSizeLow) + (((INT64)dwFileSizeHigh)<<32); m_files[i].nFileSize = ((INT64)nFileSizeLow) + (((INT64)dwFileSizeHigh)<<32);
if(i==0) m_files[i].nMultivolHeaderSize = 0; if(i==0) m_files[i].nMultivolHeaderSize = 0;
else m_files[i].nMultivolHeaderSize = MULTIVOL_HEAD_SIZE; else m_files[i].nMultivolHeaderSize = MULTIVOL_HEAD_SIZE;
m_files[i].nMultivolTailSize = MULTIVOL_TAIL_SIZE; m_files[i].nMultivolTailSize = MULTIVOL_TAIL_SIZE;

View file

@ -38,6 +38,7 @@
- , - ,
2004/10/25 - by yongari : __LP64__ , (le64toh/le132oh/le16toh) 2004/10/25 - by yongari : __LP64__ , (le64toh/le132oh/le16toh)
2004/10/26 - BSD/LINUX : byte-order, libiconv 2004/10/26 - BSD/LINUX : byte-order, libiconv
2004/10/30 - & ..
: ( * ) : ( * )
@ -127,7 +128,8 @@ using namespace std;
#endif #endif
#ifndef ASSERT #ifndef ASSERT
# include <assert.h> # include <assert.h>
# define ASSERT(x) assert(x) //# define ASSERT(x) assert(x)
# define ASSERT(x) {printf("assert file:%s line:%d\n", __FILE__, __LINE__);}
#endif #endif
@ -142,7 +144,7 @@ namespace UNALZ
# pragma pack(1) # pragma pack(1)
#endif #endif
static const char UNALZ_VERSION[] = "CUnAlz0.21"; static const char UNALZ_VERSION[] = "CUnAlz0.23";
static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004 hardkoder@gmail.com"; static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004 hardkoder@gmail.com";

Binary file not shown.

View file

@ -1 +1,4 @@
del *.plg *.obj *.o *.sbr *.pch *.pdb *.res *.bsc *.pcc *.idb *.pdb *.ncb *.aps *.ilk 2*.log *.map *.opt *.exp *.sup *.dpbcd gebug.txt *_d.exe *_d.dll *_d.lib *_debug.dll *_debug.exe *.tlh *.tli /s del *.plg *.obj *.o *.sbr *.pch *.pdb *.res *.bsc *.pcc *.idb *.pdb *.ncb *.aps *.ilk 2*.log *.map *.opt *.exp *.sup *.dpbcd gebug.txt *_d.exe *_d.dll *_d.lib *_debug.dll *_debug.exe *.tlh *.tli *.scc /s
rmdir bin
rmdir release
rmdir debug

View file

@ -10,9 +10,11 @@ void Usage()
# ifdef _UNALZ_UTF8 # ifdef _UNALZ_UTF8
printf(" -utf8 : convert filename's codepage to UTF-8 (default)\n"); printf(" -utf8 : convert filename's codepage to UTF-8 (default)\n");
printf(" -cp949 : convert filename's codepage to CP949\n"); printf(" -cp949 : convert filename's codepage to CP949\n");
printf(" -euc-kr: convert filename's codepage to EUC-KR\n");
# else # else
printf(" -utf8 : convert filename's codepage to UTF-8\n"); printf(" -utf8 : convert filename's codepage to UTF-8\n");
printf(" -cp949 : convert filename's codepage to CP949 (default)\n"); printf(" -cp949 : convert filename's codepage to CP949 (default)\n");
printf(" -euc-kr: convert filename's codepage to EUC-KR\n");
# endif // _UNALZ_UTF8 # endif // _UNALZ_UTF8
#else // no iconv #else // no iconv
printf("USAGE : unalz sourcefile.alz [dest path] \n"); printf("USAGE : unalz sourcefile.alz [dest path] \n");
@ -22,42 +24,52 @@ void Usage()
void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt) void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt)
{ {
// progress // progress
char buf[1000]; static char szFileName[1024]={0};
INT64 percent; INT64 percent;
static INT64 nPrevPercent = -1; static INT64 nPrevPercent = -1;
int buflen;
int i;
// 파일명 출력.. // 파일명 출력..
if(szMessage) if(szMessage)
{ {
//printf("\n"); printf("\n");
printf("unalziiiing : %s ", szMessage); #ifdef _WIN32
sprintf(szFileName, "unalziiiing : %s (%I64dbytes) ", szMessage, nRange);
#else
sprintf(szFileName, "unalziiiing : %s (%lldbytes) ", szMessage, nRange);
#endif
printf("%s", szFileName);
fflush(stdout);
nPrevPercent = -1; nPrevPercent = -1;
return; return;
} }
percent = nCurrent*100/nRange; percent = nCurrent*100/nRange;
if(nPrevPercent==percent) return; // 너무 잦은 업데이트 방지.. if(nPrevPercent/10==percent/10) return; // 너무 잦은 업데이트 방지..
nPrevPercent = percent; nPrevPercent = percent;
#ifdef _WIN32
sprintf(buf, "%I64d/%I64d (%I64d%%)", nCurrent, nRange, percent); printf(".");
#else
sprintf(buf, "%d/%d (%d%%)", (int)nCurrent, (int)nRange, (int)percent); // int64 를 출력할라면 어찌해야 되는지?
#endif
puts(buf);
buflen = strlen(buf);
fflush(stdout); fflush(stdout);
for(i=0;i<buflen;i++) printf("\b"); /*
char buf[1024];
#ifdef _WIN32
sprintf(buf, "\r%s %I64d/%I64d (%I64d%%)", szFileName, nCurrent, nRange, percent);
#else
// sprintf(buf, "\r%s %d/%d (%d%%)", szMessage, (int)nCurrent, (int)nRange, (int)percent); // int64 를 출력할라면 어찌해야 되는지?
sprintf(buf, "\r%s %lld/%lld (%lld%%)", szFileName, nCurrent, Range, percent);
#endif
puts(buf);
fflush(stdout);
*/
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
// printf("unalz v0.20 (2004/10/22) \n"); // printf("unalz v0.20 (2004/10/22) \n");
printf("unalz v0.22 (2004/10/28) \n"); // printf("unalz v0.22 (2004/10/27) \n");
printf("unalz v0.23 (2004/10/30) \n");
printf("copyright(C) 2004 http://www.kipple.pe.kr\n"); printf("copyright(C) 2004 http://www.kipple.pe.kr\n");
if(argc<2) if(argc<2)
@ -84,6 +96,11 @@ int main(int argc, char* argv[])
destcodepage = "CP949"; // cp959 destcodepage = "CP949"; // cp959
count++; count++;
} }
else if(strcmp(argv[count], "-euc-kr")==0)
{
destcodepage = "EUC-KR"; // EUC-KR
count++;
}
if(count>=argc) {Usage();return 0;} // 옵션만 쓰면 어쩌라고.. if(count>=argc) {Usage();return 0;} // 옵션만 쓰면 어쩌라고..
if(destcodepage) unalz.SetDestCodepage(destcodepage); if(destcodepage) unalz.SetDestCodepage(destcodepage);

View file

@ -7,7 +7,6 @@ CFLAGS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
LDFLAGS= LDFLAGS=
#CFLAGS = -DDARWIN #CFLAGS = -DDARWIN
#LDFLAGS=-liconv #LDFLAGS=-liconv
SRCS=main.cpp UnAlz.cpp UnAlzBz2decompress.c UnAlzBzip2.cpp UnAlzbzlib.c
#nothing: #nothing:
all: all:
@ -31,6 +30,7 @@ posix: unalz
$(CPP) -c UnAlz.cpp -c main.cpp $(CFLAGS) -D_UNALZ_ICONV $(CPP) -c UnAlz.cpp -c main.cpp $(CFLAGS) -D_UNALZ_ICONV
$(CPP) $(LINKOBJ) $(LDFLAGS) -liconv -o $(BIN) $(CPP) $(LINKOBJ) $(LDFLAGS) -liconv -o $(BIN)
posix-utf8: unalz posix-utf8: unalz
$(CPP) -c UnAlz.cpp -c main.cpp $(CFLAGS) -D_UNALZ_ICONV -D_UNALZ_UTF8 $(CPP) -c UnAlz.cpp -c main.cpp $(CFLAGS) -D_UNALZ_ICONV -D_UNALZ_UTF8
$(CPP) $(LINKOBJ) $(LDFLAGS) -liconv -o $(BIN) $(CPP) $(LINKOBJ) $(LDFLAGS) -liconv -o $(BIN)

View file

@ -2,8 +2,7 @@
PROG= unalz PROG= unalz
NOMAN= NOMAN=
SRCS= main.cpp UnAlz.cpp UnAlzBz2decompress.c UnAlzBzip2.cpp \ SRCS= main.cpp UnAlz.cpp UnAlzBz2decompress.c UnAlzBzip2.cpp UnAlzbzlib.c
UnAlzbzlib.c
LDADD+= -lz -lbz2 -liconv -lstdc++ LDADD+= -lz -lbz2 -liconv -lstdc++
.include <bsd.prog.mk> .include <bsd.prog.mk>

Binary file not shown.