Skip to content

Commit 60ba940

Browse files
committed
Complete reorganization of code to support the compression code to be built as a DLL/LIB and the test program to use that as necessary. Migration not entirely complete as the test program cannot use the static LIB version.
1 parent 05c43a0 commit 60ba940

32 files changed

+807
-266
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*.lznt1
22
*.xpress
33
*.xpress_huff
4+
x86
5+
x64
46

57
# Compiled Object files
68
*.slo

build-c++.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
:: Make sure both mingw-w32\bin and mingw-w64\bin are in the PATH
55

66
::-Werror
7-
set FLAGS=-mconsole -static-libgcc -static-libstdc++ -O3 -march=core2 -Wall -s
8-
set FILES=compression.cpp Dictionary.cpp Bitstream.cpp lznt1.cpp lzx.cpp xpress.cpp xpress_huff.cpp test.cpp
9-
set OUT=compression
7+
set FLAGS=-mconsole -static-libgcc -static-libstdc++ -O3 -march=core2 -Wall -s -Ilibrary
8+
set FILES=test.cpp
9+
set OUT=test
1010

1111
echo Compiling 32-bit...
1212
i686-w64-mingw32-g++ %FLAGS% %FILES% -o %OUT%.exe

build-c.bat

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
:: This builds using MinGW-w64 for 32 and 64 bit (http://mingw-w64.sourceforge.net/)
44
:: Make sure both mingw-w32\bin and mingw-w64\bin are in the PATH
55

6+
::-Werror
7+
set FLAGS=-mconsole -static-libgcc -O3 -march=core2 -Wall -s -Ilibrary
8+
set FILES=test.cpp
9+
set OUT=test
10+
611
echo Compiling 32-bit...
7-
i686-w64-mingw32-gcc -mconsole -static-libgcc -O3 -march=core2 -o compression.exe -s ^
8-
compression.c Dictionary.c Bitstream.c lznt1.c lzx.c xpress.c xpress_huff.c test.c ^
12+
i686-w64-mingw32-gcc %FLAGS% %FILES% -o %OUT%.exe
913

1014
echo.
1115

1216
echo Compiling 64-bit...
1317

14-
x86_64-w64-mingw32-gcc -mconsole -static-libgcc -O3 -march=core2 -o compression64.exe -s ^
15-
compression.c Dictionary.c Bitstream.c lznt1.c lzx.c xpress.c xpress_huff.c test.c
18+
x86_64-w64-mingw32-gcc %FLAGS% %FILES% -o %OUT%64.exe
1619

1720
pause

compression.sln

Lines changed: 0 additions & 26 deletions
This file was deleted.

Bitstream.cpp renamed to library/Bitstream.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
#include "stdafx.h"
21
#include "Bitstream.h"
32

3+
#ifdef __cplusplus_cli
4+
#pragma unmanaged
5+
#endif
6+
7+
#if defined(_MSC_VER) && defined(NDEBUG)
8+
#pragma optimize("t", on)
9+
#endif
10+
411

512
// Reading functions:
613
void BSReadInit(InputBitstream* bstr, const_bytes in, size_t len)

Bitstream.h renamed to library/Bitstream.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
#pragma once
2-
31
////////////////////////////// Bitstreams //////////////////////////////////////////////////////////
42
// A bitstream that allows either reading or writing, but not both at the same time.
53
// It reads uint16s for bits and 16 bits can be reliably read at a time
4+
5+
#ifndef BITSTREAM_H
6+
#define BITSTREAM_H
7+
#include "compression-api.h"
8+
69
struct _Bitstream
710
{
811
union
@@ -32,3 +35,5 @@ void BSWriteInit(OutputBitstream* bstr, bytes out, size_t len);
3235
bool BSWriteBits(OutputBitstream* bstr, uint32_t b, byte n);
3336
bool BSWriteByte(OutputBitstream* bstr, byte b);
3437
void BSWriteFinish(OutputBitstream* bstr);
38+
39+
#endif

Dictionary.cpp renamed to library/Dictionary.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "stdafx.h"
21
#include "Dictionary.h"
32

43
// Implementation designed for being extremely fast at the expense of memory
@@ -13,7 +12,9 @@
1312
#pragma unmanaged
1413
#endif
1514

15+
#if defined(_MSC_VER) && defined(NDEBUG)
1616
#pragma optimize("t", on)
17+
#endif
1718

1819
#define MAX_BYTE 0x100 // maximum byte value (+1 for 0)
1920
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) // minimum of 2 values

Dictionary.h renamed to library/Dictionary.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#pragma once
2-
31
/////////////////// Dictionary /////////////////////////////////////////////////
42
// The dictionary system used for LZNT1 and XPRESS compression.
53
//
@@ -9,6 +7,10 @@
97
// completely agnostic to it and any of the function implementations.
108

119

10+
#ifndef DICTIONARY_H
11+
#define DICTIONARY_H
12+
#include "compression-api.h"
13+
1214
struct _Dictionary;
1315
typedef struct _Dictionary Dictionary;
1416

@@ -35,3 +37,5 @@ bool Dictionary_Add(Dictionary* d, const_bytes data, const size_t max_len);
3537
// Returns the length of the string found, or 0 if nothing of length >= 3 was found
3638
// offset is set to the offset from the current position to the string
3739
uint_fast16_t Dictionary_Find(const Dictionary* d, const Dictionary* d2, const_bytes data, const uint_fast16_t max_len, const_bytes search, uint_fast16_t* offset);
40+
41+
#endif

library/build-c++.bat

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@echo off
2+
3+
:: This builds using MinGW-w64 for 32 and 64 bit (http://mingw-w64.sourceforge.net/)
4+
:: Make sure both mingw-w32\bin and mingw-w64\bin are in the PATH
5+
6+
::-Werror
7+
set FLAGS=-static-libgcc -static-libstdc++ -O3 -march=core2 -Wall -s -D UNICODE -D _UNICODE -D COMPRESSION_API_EXPORT
8+
set FILES=compression.cpp Dictionary.cpp Bitstream.cpp lznt1.cpp lzx.cpp xpress.cpp xpress_huff.cpp
9+
set OUT=MSCompression
10+
11+
echo Compiling 32-bit...
12+
i686-w64-mingw32-g++ %FLAGS% -D COMPRESSION_API_DLL -shared %FILES% -o %OUT%.dll -Wl,--out-implib,lib%OUT%.dll.a
13+
14+
i686-w64-mingw32-g++ %FLAGS% -D COMPRESSION_API_LIB -c %FILES%
15+
i686-w64-mingw32-ar rcs lib%OUT%.a *.o
16+
del /F /Q *.o >NUL 2>&1
17+
18+
echo.
19+
20+
echo Compiling 64-bit...
21+
22+
x86_64-w64-mingw32-g++ %FLAGS% -D COMPRESSION_API_DLL -shared %FILES% -o %OUT%64.dll -Wl,--out-implib,lib%OUT%64.dll.a
23+
24+
x86_64-w64-mingw32-g++ %FLAGS% -D COMPRESSION_API_LIB -c %FILES%
25+
x86_64-w64-mingw32-ar rcs lib%OUT%64.a *.o
26+
del /F /Q *.o >NUL 2>&1
27+
28+
pause

library/build-c.bat

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@echo off
2+
3+
:: This builds using MinGW-w64 for 32 and 64 bit (http://mingw-w64.sourceforge.net/)
4+
:: Make sure both mingw-w32\bin and mingw-w64\bin are in the PATH
5+
6+
::-Werror
7+
set FLAGS=-static-libgcc -O3 -march=core2 -Wall -s -D UNICODE -D _UNICODE -D COMPRESSION_API_EXPORT
8+
set FILES=compression.cpp Dictionary.cpp Bitstream.cpp lznt1.cpp lzx.cpp xpress.cpp xpress_huff.cpp
9+
set OUT=MSCompression
10+
11+
echo Compiling 32-bit...
12+
i686-w64-mingw32-gcc %FLAGS% -D COMPRESSION_API_DLL -shared %FILES% -o %OUT%.dll -Wl,--out-implib,lib%OUT%.dll.a
13+
14+
i686-w64-mingw32-gcc %FLAGS% -D COMPRESSION_API_LIB -c %FILES%
15+
i686-w64-mingw32-ar rcs lib%OUT%.a *.o
16+
del /F /Q *.o >NUL 2>&1
17+
18+
echo.
19+
20+
echo Compiling 64-bit...
21+
22+
x86_64-w64-mingw32-gcc %FLAGS% -D COMPRESSION_API_DLL -shared %FILES% -o %OUT%64.dll -Wl,--out-implib,lib%OUT%64.dll.a
23+
24+
x86_64-w64-mingw32-gcc %FLAGS% -D COMPRESSION_API_LIB -c %FILES%
25+
x86_64-w64-mingw32-ar rcs lib%OUT%64.a *.o
26+
del /F /Q *.o >NUL 2>&1
27+
28+
pause

0 commit comments

Comments
 (0)