mirror of
https://github.com/facebook/zstd.git
synced 2025-08-07 06:23:00 +03:00
added contrib\gen_html
This commit is contained in:
36
contrib/gen_html/Makefile
Normal file
36
contrib/gen_html/Makefile
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# ##########################################################################
|
||||||
|
# Copyright (c) 2016-present, Facebook, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This source code is licensed under the BSD-style license found in the
|
||||||
|
# LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
# of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
# ##########################################################################
|
||||||
|
|
||||||
|
|
||||||
|
CFLAGS ?= -O3
|
||||||
|
CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wno-comment
|
||||||
|
CFLAGS += $(MOREFLAGS)
|
||||||
|
FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Define *.exe as extension for Windows systems
|
||||||
|
ifneq (,$(filter Windows%,$(OS)))
|
||||||
|
EXT =.exe
|
||||||
|
else
|
||||||
|
EXT =
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: default gen_html
|
||||||
|
|
||||||
|
default: gen_html
|
||||||
|
|
||||||
|
gen_html: gen_html.cpp
|
||||||
|
$(CXX) $(FLAGS) $^ -o $@$(EXT)
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@$(RM) gen_html$(EXT)
|
||||||
|
@echo Cleaning completed
|
25
contrib/gen_html/README.md
Normal file
25
contrib/gen_html/README.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
gen_html - a program for automatic generation of zstd manual
|
||||||
|
============================================================
|
||||||
|
|
||||||
|
#### Introduction
|
||||||
|
|
||||||
|
This simple C++ program generates a single-page HTML manual from `zstd.h`.
|
||||||
|
|
||||||
|
The format of recognized comment blocks is following:
|
||||||
|
- comments of type `/*!` mean: this is a function declaration; switch comments with declarations
|
||||||
|
- comments of type `/**` and `/*-` mean: this is a comment; use a `<H2>` header for the first line
|
||||||
|
- comments of type `/*=` and `/**=` mean: use a `<H3>` header and show also all functions until first empty line
|
||||||
|
- comments of type `/*X` where `X` is different from above-mentioned are ignored
|
||||||
|
|
||||||
|
Moreover:
|
||||||
|
- `ZSTDLIB_API` is removed to improve readability
|
||||||
|
- `typedef`s are detected and included even if uncommented
|
||||||
|
- comments of type `/**<` and `/*!<` are detected and only function declaration is highlighted (bold)
|
||||||
|
|
||||||
|
|
||||||
|
#### Usage
|
||||||
|
|
||||||
|
The program requires 3 parameters:
|
||||||
|
```
|
||||||
|
gen_html [zstd_version] [input_file] [output_html]
|
||||||
|
```
|
216
contrib/gen_html/gen_html.cpp
Normal file
216
contrib/gen_html/gen_html.cpp
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-present, Przemyslaw Skibinski, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
/* trim string at the beginning and at the end */
|
||||||
|
void trim(string& s, string characters)
|
||||||
|
{
|
||||||
|
size_t p = s.find_first_not_of(characters);
|
||||||
|
s.erase(0, p);
|
||||||
|
|
||||||
|
p = s.find_last_not_of(characters);
|
||||||
|
if (string::npos != p)
|
||||||
|
s.erase(p+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* trim C++ style comments */
|
||||||
|
void trim_comments(string &s)
|
||||||
|
{
|
||||||
|
size_t spos, epos;
|
||||||
|
|
||||||
|
spos = s.find("/*");
|
||||||
|
epos = s.find("*/");
|
||||||
|
s = s.substr(spos+3, epos-(spos+3));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* get lines until a given terminator */
|
||||||
|
vector<string> get_lines(vector<string>& input, int& linenum, string terminator)
|
||||||
|
{
|
||||||
|
vector<string> out;
|
||||||
|
string line;
|
||||||
|
size_t epos;
|
||||||
|
|
||||||
|
while ((size_t)linenum < input.size()) {
|
||||||
|
line = input[linenum];
|
||||||
|
|
||||||
|
if (terminator.empty() && line.empty()) { linenum--; break; }
|
||||||
|
|
||||||
|
epos = line.find(terminator);
|
||||||
|
if (!terminator.empty() && epos!=string::npos) {
|
||||||
|
out.push_back(line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
out.push_back(line);
|
||||||
|
linenum++;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* print line with ZSTDLIB_API removed and C++ comments not bold */
|
||||||
|
void print_line(stringstream &sout, string line)
|
||||||
|
{
|
||||||
|
size_t spos;
|
||||||
|
|
||||||
|
if (line.substr(0,12) == "ZSTDLIB_API ") line = line.substr(12);
|
||||||
|
spos = line.find("/*");
|
||||||
|
if (spos!=string::npos) {
|
||||||
|
sout << line.substr(0, spos);
|
||||||
|
sout << "</b>" << line.substr(spos) << "<b>" << endl;
|
||||||
|
} else {
|
||||||
|
// fprintf(stderr, "lines=%s\n", line.c_str());
|
||||||
|
sout << line << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
char exclam;
|
||||||
|
int linenum, chapter = 1;
|
||||||
|
vector<string> input, lines, comments, chapters;
|
||||||
|
string line, version;
|
||||||
|
size_t spos, l;
|
||||||
|
stringstream sout;
|
||||||
|
ifstream istream;
|
||||||
|
ofstream ostream;
|
||||||
|
|
||||||
|
if (argc < 4) {
|
||||||
|
cout << "usage: " << argv[0] << " [zstd_version] [input_file] [output_html]" << endl;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
version = "zstd " + string(argv[1]) + " Manual";
|
||||||
|
|
||||||
|
istream.open(argv[2], ifstream::in);
|
||||||
|
if (!istream.is_open()) {
|
||||||
|
cout << "Error opening file " << argv[2] << endl;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream.open(argv[3], ifstream::out);
|
||||||
|
if (!ostream.is_open()) {
|
||||||
|
cout << "Error opening file " << argv[3] << endl;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (getline(istream, line)) {
|
||||||
|
input.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (linenum=0; (size_t)linenum < input.size(); linenum++) {
|
||||||
|
line = input[linenum];
|
||||||
|
|
||||||
|
/* typedefs are detected and included even if uncommented */
|
||||||
|
if (line.substr(0,7) == "typedef" && line.find("{")!=string::npos) {
|
||||||
|
lines = get_lines(input, linenum, "}");
|
||||||
|
sout << "<pre><b>";
|
||||||
|
for (l=0; l<lines.size(); l++) {
|
||||||
|
print_line(sout, lines[l]);
|
||||||
|
}
|
||||||
|
sout << "</b></pre><BR>" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* comments of type /**< and /*!< are detected and only function declaration is highlighted (bold) */
|
||||||
|
if ((line.find("/**<")!=string::npos || line.find("/*!<")!=string::npos) && line.find("*/")!=string::npos) {
|
||||||
|
sout << "<pre><b>";
|
||||||
|
print_line(sout, line);
|
||||||
|
sout << "</b></pre><BR>" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* comments of type /*= and /**= mean: use a <H3> header and show also all functions until first empty line */
|
||||||
|
if ((line.substr(0,3) == "/*=" || line.substr(0,4) == "/**=") && line.find("*/")!=string::npos) {
|
||||||
|
trim_comments(line);
|
||||||
|
trim(line, "= ");
|
||||||
|
sout << "<h3>" << line << "</h3><pre><b>";
|
||||||
|
lines = get_lines(input, ++linenum, "");
|
||||||
|
for (l=0; l<lines.size(); l++) {
|
||||||
|
print_line(sout, lines[l]);
|
||||||
|
}
|
||||||
|
sout << "</b></pre><BR>" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
spos = line.find("/*!");
|
||||||
|
if (spos==string::npos)
|
||||||
|
spos = line.find("/**");
|
||||||
|
if (spos==string::npos)
|
||||||
|
spos = line.find("/*-");
|
||||||
|
|
||||||
|
if (spos==string::npos)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
exclam = line[spos+2];
|
||||||
|
comments = get_lines(input, linenum, "*/");
|
||||||
|
if (!comments.empty()) comments[0] = line.substr(spos+3);
|
||||||
|
if (!comments.empty()) comments[comments.size()-1] = comments[comments.size()-1].substr(0, comments[comments.size()-1].find("*/"));
|
||||||
|
for (l=0; l<comments.size(); l++) {
|
||||||
|
if (comments[l].find(" *")==0) comments[l] = comments[l].substr(2);
|
||||||
|
else if (comments[l].find(" *")==0) comments[l] = comments[l].substr(3);
|
||||||
|
trim(comments[l], "*-");
|
||||||
|
}
|
||||||
|
while (!comments.empty() && comments[comments.size()-1].empty()) comments.pop_back(); // remove empty line at the end
|
||||||
|
while (!comments.empty() && comments[0].empty()) comments.erase(comments.begin()); // remove empty line at the start
|
||||||
|
|
||||||
|
/* comments of type /*! mean: this is a function declaration; switch comments with declarations */
|
||||||
|
if (exclam == '!') {
|
||||||
|
if (!comments.empty()) comments.erase(comments.begin()); /* remove first line like "ZSTD_XXX() :" */
|
||||||
|
linenum++;
|
||||||
|
lines = get_lines(input, linenum, "");
|
||||||
|
|
||||||
|
sout << "<pre><b>";
|
||||||
|
for (l=0; l<lines.size(); l++) {
|
||||||
|
// fprintf(stderr, "line[%d]=%s\n", l, lines[l].c_str());
|
||||||
|
print_line(sout, lines[l]);
|
||||||
|
}
|
||||||
|
sout << "</b><p>";
|
||||||
|
for (l=0; l<comments.size(); l++) {
|
||||||
|
print_line(sout, comments[l]);
|
||||||
|
}
|
||||||
|
sout << "</p></pre><BR>" << endl << endl;
|
||||||
|
} else { /* comments of type /** and /*- mean: this is a comment; use a <H2> header for the first line */
|
||||||
|
if (comments.empty()) continue;
|
||||||
|
|
||||||
|
trim(comments[0], " ");
|
||||||
|
sout << "<a name=\"Chapter" << chapter << "\"></a><h2>" << comments[0] << "</h2><pre>";
|
||||||
|
chapters.push_back(comments[0]);
|
||||||
|
chapter++;
|
||||||
|
|
||||||
|
for (l=1; l<comments.size(); l++) {
|
||||||
|
print_line(sout, comments[l]);
|
||||||
|
}
|
||||||
|
if (comments.size() > 1)
|
||||||
|
sout << "<BR></pre>" << endl << endl;
|
||||||
|
else
|
||||||
|
sout << "</pre>" << endl << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream << "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n<title>" << version << "</title>\n</head>\n<body>" << endl;
|
||||||
|
ostream << "<h1>" << version << "</h1>\n";
|
||||||
|
|
||||||
|
ostream << "<hr>\n<a name=\"Contents\"></a><h2>Contents</h2>\n<ol>\n";
|
||||||
|
for (size_t i=0; i<chapters.size(); i++)
|
||||||
|
ostream << "<li><a href=\"#Chapter" << i+1 << "\">" << chapters[i].c_str() << "</a></li>\n";
|
||||||
|
ostream << "</ol>\n<hr>\n";
|
||||||
|
|
||||||
|
ostream << sout.str();
|
||||||
|
ostream << "</html>" << endl << "</body>" << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
14
lib/zstd.h
14
lib/zstd.h
@@ -43,7 +43,7 @@ extern "C" {
|
|||||||
- repeated calls of the compression function (described as Streaming compression)
|
- repeated calls of the compression function (described as Streaming compression)
|
||||||
The compression ratio achievable on small data can be highly improved using compression with a dictionary in:
|
The compression ratio achievable on small data can be highly improved using compression with a dictionary in:
|
||||||
- a single step (described as Simple dictionary API)
|
- a single step (described as Simple dictionary API)
|
||||||
- a single step, reusing a dictionary (described as Fast Dictionary API)
|
- a single step, reusing a dictionary (described as Fast dictionary API)
|
||||||
|
|
||||||
Advanced and experimantal functions can be accessed using #define ZSTD_STATIC_LINKING_ONLY before including zstd.h.
|
Advanced and experimantal functions can be accessed using #define ZSTD_STATIC_LINKING_ONLY before including zstd.h.
|
||||||
These APIs shall never be used with a dynamic library.
|
These APIs shall never be used with a dynamic library.
|
||||||
@@ -157,7 +157,7 @@ ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
|
|||||||
|
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
* Fast Dictionary API
|
* Fast dictionary API
|
||||||
****************************/
|
****************************/
|
||||||
typedef struct ZSTD_CDict_s ZSTD_CDict;
|
typedef struct ZSTD_CDict_s ZSTD_CDict;
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ typedef struct ZSTD_outBuffer_s {
|
|||||||
|
|
||||||
|
|
||||||
/*-***********************************************************************
|
/*-***********************************************************************
|
||||||
* Streaming compression - howto
|
* Streaming compression - HowTo
|
||||||
*
|
*
|
||||||
* A ZSTD_CStream object is required to track streaming operation.
|
* A ZSTD_CStream object is required to track streaming operation.
|
||||||
* Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
|
* Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
|
||||||
@@ -269,7 +269,7 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output
|
|||||||
|
|
||||||
|
|
||||||
/*-***************************************************************************
|
/*-***************************************************************************
|
||||||
* Streaming decompression howto
|
* Streaming decompression - HowTo
|
||||||
*
|
*
|
||||||
* A ZSTD_DStream object is required to track streaming operations.
|
* A ZSTD_DStream object is required to track streaming operations.
|
||||||
* Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
|
* Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
|
||||||
@@ -339,7 +339,7 @@ static const size_t ZSTD_frameHeaderSize_max = ZSTD_FRAMEHEADERSIZE_MAX;
|
|||||||
static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable frame length */
|
static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable frame length */
|
||||||
|
|
||||||
|
|
||||||
/*--- Types ---*/
|
/*--- Advanced types ---*/
|
||||||
typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt } ZSTD_strategy; /* from faster to stronger */
|
typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt } ZSTD_strategy; /* from faster to stronger */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -422,7 +422,7 @@ ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
|
|||||||
ZSTD_parameters params);
|
ZSTD_parameters params);
|
||||||
|
|
||||||
|
|
||||||
/*--- Advanced Decompression functions ---*/
|
/*--- Advanced decompression functions ---*/
|
||||||
|
|
||||||
/*! ZSTD_estimateDCtxSize() :
|
/*! ZSTD_estimateDCtxSize() :
|
||||||
* Gives the potential amount of memory allocated to create a ZSTD_DCtx */
|
* Gives the potential amount of memory allocated to create a ZSTD_DCtx */
|
||||||
@@ -442,7 +442,7 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|||||||
|
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
* Advanced Streaming functions
|
* Advanced streaming functions
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
/*===== Advanced Streaming compression functions =====*/
|
/*===== Advanced Streaming compression functions =====*/
|
||||||
|
Reference in New Issue
Block a user