mirror of
https://github.com/facebook/zstd.git
synced 2025-08-05 19:15:58 +03:00
Added generator script and simple test
The script will combine decompressor sources into a single file. The example shows this in use.
This commit is contained in:
8
contrib/declib/README.md
Normal file
8
contrib/declib/README.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Single File Zstandard Decompression Library
|
||||||
|
|
||||||
|
Create the file using the shell script:
|
||||||
|
```
|
||||||
|
cd zstd/contrib/declib
|
||||||
|
./combine.sh -r "../../lib ../../lib/common ../../lib/decompress" zstddeclib-in.c > zstddeclib.c
|
||||||
|
```
|
||||||
|
Then add the resulting file to your project (see the [test sources](tests) for examples).
|
80
contrib/declib/combine.sh
Executable file
80
contrib/declib/combine.sh
Executable file
@@ -0,0 +1,80 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Tool to bundle multiple C/C++ source files, inlining any includes.
|
||||||
|
|
||||||
|
# Common file roots
|
||||||
|
ROOTS="./"
|
||||||
|
|
||||||
|
# Files previously visited
|
||||||
|
FOUND=""
|
||||||
|
|
||||||
|
# Prints the script usage then exits
|
||||||
|
function usage {
|
||||||
|
echo "Usage: $0 [-r <paths>] infile"
|
||||||
|
echo " -r file root search paths"
|
||||||
|
echo "Example: $0 -r \"../my/path ../my/other\" in.c > out.c"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Tests if list $1 has item $2
|
||||||
|
function list_has_item {
|
||||||
|
local list="$1"
|
||||||
|
local item="$2"
|
||||||
|
if [[ $list =~ (^|[[:space:]]*)"$item"($|[[:space:]]*) ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Adds the contents of $1 with any of its includes inlined
|
||||||
|
function add_file {
|
||||||
|
# Match the path
|
||||||
|
local file=
|
||||||
|
for root in $ROOTS; do
|
||||||
|
if test -f "$root/$1"; then
|
||||||
|
file="$root/$1"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$file" != "" ]; then
|
||||||
|
# Read the file
|
||||||
|
local line
|
||||||
|
while IFS= read -r line; do
|
||||||
|
if [[ $line =~ ^[[:space:]]*\#[[:space:]]*include[[:space:]]*\"(.*)\".* ]]; then
|
||||||
|
# We have an include directive
|
||||||
|
local inc=${BASH_REMATCH[1]}
|
||||||
|
if ! `list_has_item "$FOUND" "$inc"`; then
|
||||||
|
# And we've not previously encountered it
|
||||||
|
FOUND="$FOUND $inc"
|
||||||
|
echo "/**** start inlining $inc ****/"
|
||||||
|
add_file $inc
|
||||||
|
echo "/**** ended inlining $inc ****/"
|
||||||
|
else
|
||||||
|
echo "/**** skipping file: $inc ****/"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Otherwise write the source line
|
||||||
|
echo "$line"
|
||||||
|
fi
|
||||||
|
done < "$file"
|
||||||
|
else
|
||||||
|
echo "#error Unable to find \"$1\""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts ":r:" opts; do
|
||||||
|
case $opts in
|
||||||
|
r)
|
||||||
|
ROOTS="$ROOTS $OPTARG"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
if [ "$1" != "" ]; then
|
||||||
|
add_file $1
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
fi
|
3392
contrib/declib/tests/simple.c
Normal file
3392
contrib/declib/tests/simple.c
Normal file
File diff suppressed because it is too large
Load Diff
66
contrib/declib/zstddeclib-in.c
Executable file
66
contrib/declib/zstddeclib-in.c
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* \file zstddeclib.c
|
||||||
|
* Single-file Zstandard decompressor.
|
||||||
|
*
|
||||||
|
* Generate using:
|
||||||
|
* \code
|
||||||
|
* makelib.sh -r "../../lib ../../lib/common ../../lib/decompress" zstddeclib-in.c > zstddeclib.c
|
||||||
|
* \endcode
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* BSD License
|
||||||
|
*
|
||||||
|
* For Zstandard software
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name Facebook nor the names of its contributors may be used
|
||||||
|
* to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Settings to bake for the standalone decompressor.
|
||||||
|
*/
|
||||||
|
#define DEBUGLEVEL 0
|
||||||
|
#define XXH_NAMESPACE ZSTD_
|
||||||
|
#define XXH_PRIVATE_API
|
||||||
|
#define XXH_INLINE_ALL
|
||||||
|
#define ZSTD_LEGACY_SUPPORT 0
|
||||||
|
#define ZSTD_LIB_COMPRESSION 0
|
||||||
|
#define ZSTD_LIB_DEPRECATED 0
|
||||||
|
#define ZSTD_NOBENCH
|
||||||
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
|
#define ZSTD_STRIP_ERROR_STRINGS
|
||||||
|
|
||||||
|
#include "debug.c"
|
||||||
|
#include "entropy_common.c"
|
||||||
|
#include "error_private.c"
|
||||||
|
#include "fse_decompress.c"
|
||||||
|
#include "xxhash.c"
|
||||||
|
#include "zstd_common.c"
|
||||||
|
#include "huf_decompress.c"
|
||||||
|
#include "zstd_ddict.c"
|
||||||
|
#include "zstd_decompress.c"
|
||||||
|
#include "zstd_decompress_block.c"
|
Reference in New Issue
Block a user