Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Commit 253ad97

Browse files
committed
Properly setup building and packaging of the lib.
Splitted the lib and the executable. Added some macrodefs to properly link the library. Replaced int in the signature with a enum. Should have the same size and not break compatibility, but increase clarity. Also changed its values hardcoded into the code to the names in the enum. Added support of CMake. Added CPack packaging. Added license as a separate file. Added ReadMe.md with some text.
1 parent 56a849d commit 253ad97

20 files changed

+374
-79
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

.gitmodules

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[submodule "tests/testDataset"]
2+
path = tests/testDataset
3+
url = https://codeberg.org/implode-compression-impls/implode_test_files
4+
branch = merged
5+
shallow = true
6+
[submodule "cmake/Boilerplate"]
7+
path = cmake/Boilerplate
8+
url = https://codeberg.org/KOLANICH-libs/Boilerplate.cmake
9+
branch = master
10+
[submodule "cmake/DoxygenUtils"]
11+
path = cmake/DoxygenUtils
12+
url = https://codeberg.org/KOLANICH-libs/DoxygenUtils.cmake
13+
branch = master

CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
set(CMAKE_USE_RELATIVE_PATHS TRUE)
4+
project("blast")
5+
set("PROJECT_DESCRIPTION" "Free open source PKWare Data Compression Library (DCL) implementation")
6+
set("PROJECT_HOMEPAGE_URL" "https://github.com/madler/zlib/tree/master/contrib/blast")
7+
set(CPACK_PACKAGE_VENDOR "Mark Adler")
8+
9+
set(CPACK_PACKAGE_VERSION_MAJOR "1")
10+
set(CPACK_PACKAGE_VERSION_MINOR "2")
11+
set(CPACK_PACKAGE_VERSION_PATCH "9")
12+
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
13+
14+
set(OUR_CMAKE_MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
15+
set(OUR_CMAKE_3PARTY_MODULES_DIR "${OUR_CMAKE_MODULES_DIR}/thirdParty")
16+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${OUR_CMAKE_MODULES_DIR}" "${OUR_CMAKE_MODULES_DIR}/Boilerplate" "${OUR_CMAKE_MODULES_DIR}/DoxygenUtils" "${OUR_CMAKE_3PARTY_MODULES_DIR}")
17+
18+
include(Boilerplate)
19+
20+
set(Include_dir "${CMAKE_CURRENT_SOURCE_DIR}/include")
21+
file(GLOB_RECURSE HDRFILES "${Include_dir}/*.h" "${Include_dir}/*.hpp")
22+
23+
set(LibSource_dir "${CMAKE_CURRENT_SOURCE_DIR}/lib")
24+
set(BinSource_dir "${CMAKE_CURRENT_SOURCE_DIR}/bin")
25+
set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}/packaging")
26+
set(tests_dir "${CMAKE_CURRENT_SOURCE_DIR}/tests")
27+
28+
29+
set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
30+
set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
31+
set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
32+
33+
add_subdirectory("${LibSource_dir}")
34+
add_subdirectory("${BinSource_dir}")
35+
36+
option(WITH_TESTS ON "Enable testing")
37+
38+
if(WITH_TESTS)
39+
add_subdirectory("${tests_dir}")
40+
enable_testing()
41+
endif()
42+
43+
set(CPACK_DEB_COMPONENT_INSTALL ON)
44+
set(CPACK_RPM_COMPONENT_INSTALL ON)
45+
set(CPACK_NSIS_COMPONENT_INSTALL ON)
46+
#set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
47+
set(CPACK_RPM_ENABLE_COMPONENT_DEPENDS ON)
48+
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
49+
50+
include(CPack)

License.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
The zlib/libpng License
2+
=======================
3+
4+
Copyright (C) 2003, 2012, 2013 Mark Adler
5+
6+
This software is provided 'as-is', without any express or implied warranty. In
7+
no event will the authors be held liable for any damages arising from the use of
8+
this software.
9+
10+
Permission is granted to anyone to use this software for any purpose, including
11+
commercial applications, and to alter it and redistribute it freely, subject to
12+
the following restrictions:
13+
14+
1. The origin of this software must not be misrepresented; you must not claim
15+
that you wrote the original software. If you use this software in a product,
16+
an acknowledgment in the product documentation would be appreciated but is
17+
not required.
18+
19+
2. Altered source versions must be plainly marked as such, and must not be
20+
misrepresented as being the original software.
21+
22+
3. This notice may not be removed or altered from any source distribution.
23+
24+

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
blast: blast.c blast.h
2-
cc -DTEST -o blast blast.c
1+
libblast: ./src/blast.c ./include/blast.h
2+
cc -shared -o ./build/lib/libblast.so ./lib/blast.c -I./include
33

4-
test: blast
5-
blast < test.pk | cmp - test.txt
4+
blast: ./src/blast.c ./include/blast.h libblast
5+
cc -o ./build/bin/blast ./src/blast.c -I./include -l:./build/lib/libblast.so
6+
7+
test: ./build/bin/blast
8+
./build/bin/blast < ./tests/test.pk | cmp - ./tests/test.txt
69

710
clean:
8-
rm -f blast blast.o
11+
rm -f ./build/blast ./build/blast.o

README

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

ReadMe.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
libblast (modified for better packaging)
2+
========
3+
4+
It is the modified version of [Mark @madler Adler](https://github.com/madler)'s [libblast](https://github.com/madler/zlib/tree/master/contrib/blast).
5+
6+
`libblast` is a free and open-source library implementing decompression of PKWare Data Compression Library (DCL) compressed format.
7+
8+
Modifications:
9+
10+
* splitted into a separate git repo for the convenience of ones who want to inline it as a submodule
11+
* changed repo layout for convenience and clarity
12+
* implemented building with CMake
13+
* implemented packaging with CPack
14+
* implemented hardening with [Hardening.cmake](https://codeberg.org/KOLANICH-libs/Hardening.cmake)
15+
16+
17+
Bindings
18+
--------
19+
* https://codeberg.org/implode-compression-impls/pkblast.py - Python bindings of this lib
20+
21+
22+
Other impls
23+
-----------
24+
25+
* https://github.com/agrif/explode - a reimplementation of this lib in Rust.
26+
* https://codeberg.org/implode-compression-impls/pklib - an impl extracted from [Ladislav Zezula](https://github.com/ladislav-zezula)'s [StormLib](https://github.com/ladislav-zezula/StormLib). Contains a compressor, [`libimplode](https://github.com/implode-compression-impls/pklib/tree/master/src/implode)
27+
* https://github.com/Schallaven/pwexplode - a pure python lib for decompression, but it is under GPL-3.0-or-later
28+
* https://github.com/ShieldBattery/implode-decoder - An impl in JS. Based on `libexplode`.

bin/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
file(GLOB_RECURSE SRCFILES "${CMAKE_CURRENT_SOURCE_DIR}/*.c" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
2+
3+
add_executable(blast "${SRCFILES}")
4+
target_include_directories(blast PUBLIC "${Include_dir}")
5+
target_link_libraries(blast PRIVATE libblast)
6+
harden(blast)
7+
8+
cpack_add_component(blast
9+
DISPLAY_NAME "binary"
10+
DESCRIPTION "The decompressor binary for PKWare Data Compression Library (DCL) format"
11+
DEPENDS "library" "library_sdk"
12+
)
13+
14+
install(TARGETS "blast"
15+
RUNTIME
16+
COMPONENT "blast"
17+
)
18+
19+
set("CPACK_DEBIAN_BLAST_PACKAGE_NAME" "blast")
20+
set("CPACK_RPM_BLAST_PACKAGE_NAME" "blast")
21+
22+
set("CPACK_DEBIAN_BLAST_PACKAGE_DEPENDS" "${CPACK_DEBIAN_LIBBLAST_PACKAGE_NAME}")
23+
set("CPACK_RPM_BLAST_PACKAGE_DEPENDS" "${CPACK_RPM_LIBBLAST_PACKAGE_NAME}")
24+
25+
26+
list(APPEND CPACK_COMPONENTS_ALL "blast") # strangely, not populated automatically correctly
27+
28+
pass_through_cpack_vars()

bin/blast.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* blast.c
2+
* Copyright (C) 2003, 2012, 2013 Mark Adler
3+
* For conditions of distribution and use, see copyright notice in blast.h
4+
* version 1.3, 24 Aug 2013
5+
*
6+
* blast.c decompresses data compressed by the PKWare Compression Library.
7+
* This function provides functionality similar to the explode() function of
8+
* the PKWare library, hence the name "blast".
9+
*
10+
* This decompressor is based on the excellent format description provided by
11+
* Ben Rudiak-Gould in comp.compression on August 13, 2001. Interestingly, the
12+
* example Ben provided in the post is incorrect. The distance 110001 should
13+
* instead be 111000. When corrected, the example byte stream becomes:
14+
*
15+
* 00 04 82 24 25 8f 80 7f
16+
*
17+
* which decompresses to "AIAIAIAIAIAIA" (without the quotes).
18+
*/
19+
20+
/*
21+
* Change history:
22+
*
23+
* 1.0 12 Feb 2003 - First version
24+
* 1.1 16 Feb 2003 - Fixed distance check for > 4 GB uncompressed data
25+
* 1.2 24 Oct 2012 - Add note about using binary mode in stdio
26+
* - Fix comparisons of differently signed integers
27+
* 1.3 24 Aug 2013 - Return unused input from blast()
28+
* - Fix test code to correctly report unused input
29+
* - Enable the provision of initial input to blast()
30+
*/
31+
32+
/* Example of how to use blast() */
33+
#include <stdio.h>
34+
#include <stdlib.h>
35+
36+
#include <blast.h>
37+
38+
#define CHUNK 16384
39+
40+
static unsigned inf(void *how, unsigned char **buf)
41+
{
42+
static unsigned char hold[CHUNK];
43+
44+
*buf = hold;
45+
return fread(hold, 1, CHUNK, (FILE *)how);
46+
}
47+
48+
static int outf(void *how, unsigned char *buf, unsigned len)
49+
{
50+
return fwrite(buf, 1, len, (FILE *)how) != len;
51+
}
52+
53+
/* Decompress a PKWare Compression Library stream from stdin to stdout */
54+
int main(void)
55+
{
56+
int ret;
57+
unsigned left;
58+
59+
/* decompress to stdout */
60+
left = 0;
61+
ret = blast(inf, stdin, outf, stdout, &left, NULL);
62+
if (ret != 0)
63+
fprintf(stderr, "blast error: %d\n", ret);
64+
65+
/* count any leftover bytes */
66+
while (getchar() != EOF)
67+
left++;
68+
if (left)
69+
fprintf(stderr, "blast warning: %u unused bytes of input\n", left);
70+
71+
/* return blast() error code */
72+
return ret;
73+
}

cmake/Boilerplate

Submodule Boilerplate added at 4babea6

0 commit comments

Comments
 (0)