mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Generate inline headers for use declarations
This commit is contained in:
1 parent
c5b5efd7c8
commit
9867cd5e3a
6 files changed
+549
-16
No files matched your search
@@ -18,6 +18,14 @@
|
||||
// It also holds functions to parse and validate these flag values.
|
||||
package commonflags
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go/build"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
CcompilersDefault = "clang,gcc"
|
||||
CcompilersUsage = `comma-separated list of C compilers, e.g. "clang,gcc"`
|
||||
@@ -34,6 +42,9 @@ const (
|
||||
RepsUsage = `the number of repetitions per benchmark`
|
||||
)
|
||||
|
||||
// TODO: do IsAlphaNumericIsh and IsValidUsePath belong in a separate package,
|
||||
// such as lang/validate? Perhaps together with token.Unescape?
|
||||
|
||||
// IsAlphaNumericIsh returns whether s contains only ASCII alpha-numerics and a
|
||||
// limited set of punctuation such as commas and slahes, but not containing
|
||||
// e.g. spaces, semi-colons, colons or backslashes.
|
||||
@@ -51,3 +62,18 @@ func IsAlphaNumericIsh(s string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValidUsePath(s string) bool {
|
||||
return s == path.Clean(s) && s != "" && s[0] != '.' && s[0] != '/'
|
||||
}
|
||||
|
||||
func WuffsRoot() (string, error) {
|
||||
// TODO: look for a WUFFSROOT environment variable?
|
||||
for _, p := range filepath.SplitList(build.Default.GOPATH) {
|
||||
p = filepath.Join(p, "src", "github.com", "google", "wuffs")
|
||||
if o, err := os.Stat(p); err == nil && o.IsDir() {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
return "", errors.New("could not find Wuffs root directory")
|
||||
}
|
||||
@@ -19,9 +19,11 @@ package cgen
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/google/wuffs/lang/base38"
|
||||
@@ -29,6 +31,8 @@ import (
|
||||
"github.com/google/wuffs/lang/check"
|
||||
"github.com/google/wuffs/lang/generate"
|
||||
|
||||
cf "github.com/google/wuffs/cmd/commonflags"
|
||||
|
||||
a "github.com/google/wuffs/lang/ast"
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
@@ -166,6 +170,7 @@ type gen struct {
|
||||
structMap map[t.ID]*a.Struct
|
||||
currFunk funk
|
||||
funks map[t.QID]funk
|
||||
wuffsRoot string
|
||||
usesSeen map[string]struct{}
|
||||
}
|
||||
|
||||
@@ -577,11 +582,16 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
wuffsBaseHeaderHStart = []byte("#ifndef WUFFS_BASE_HEADER_H\n")
|
||||
wuffsBaseHeaderHEnd = []byte("#endif // WUFFS_BASE_HEADER_H\n")
|
||||
)
|
||||
|
||||
func (g *gen) writeUse(b *buffer, n *a.Use) error {
|
||||
useDirname := g.tm.ByID(n.Path())
|
||||
useDirname, _ = t.Unescape(useDirname)
|
||||
|
||||
// TODO: sanity check useDirname?
|
||||
// TODO: sanity check useDirname via commonflags.IsValidUsePath?
|
||||
|
||||
if g.usesSeen == nil {
|
||||
g.usesSeen = map[string]struct{}{}
|
||||
@@ -590,7 +600,37 @@ func (g *gen) writeUse(b *buffer, n *a.Use) error {
|
||||
}
|
||||
g.usesSeen[useDirname] = struct{}{}
|
||||
|
||||
if g.wuffsRoot == "" {
|
||||
var err error
|
||||
g.wuffsRoot, err = cf.WuffsRoot()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
hdrFilename := filepath.Join(g.wuffsRoot, "gen", "h", filepath.FromSlash(useDirname)+".h")
|
||||
hdr, err := ioutil.ReadFile(hdrFilename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.printf("// ---------------- BEGIN USE %q\n\n", useDirname)
|
||||
|
||||
// Inline the previously generated .h file, stripping out the redundant
|
||||
// copy of the WUFFS_BASE_HEADER_H code.
|
||||
if i := bytes.Index(hdr, wuffsBaseHeaderHStart); i < 0 {
|
||||
return fmt.Errorf("use %q: previously generated header %q could not be inlined", useDirname, hdrFilename)
|
||||
} else {
|
||||
b.Write(hdr[:i])
|
||||
hdr = hdr[i+len(wuffsBaseHeaderHStart):]
|
||||
}
|
||||
if i := bytes.Index(hdr, wuffsBaseHeaderHEnd); i < 0 {
|
||||
return fmt.Errorf("use %q: previously generated header %q could not be inlined", useDirname, hdrFilename)
|
||||
} else {
|
||||
b.Write(hdr[i+len(wuffsBaseHeaderHEnd):])
|
||||
}
|
||||
|
||||
b.writeb('\n')
|
||||
b.printf("// ---------------- END USE %q\n\n", useDirname)
|
||||
return nil
|
||||
}
|
||||
|
||||
+3
-1
@@ -27,6 +27,8 @@ import (
|
||||
|
||||
"github.com/google/wuffs/lang/generate"
|
||||
|
||||
cf "github.com/google/wuffs/cmd/commonflags"
|
||||
|
||||
a "github.com/google/wuffs/lang/ast"
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
@@ -89,7 +91,7 @@ func (h *genHelper) gen(dirname string, recursive bool) error {
|
||||
}
|
||||
h.seen[dirname] = struct{}{}
|
||||
|
||||
if dirname != path.Clean(dirname) || dirname == "" || dirname[0] == '.' || dirname[0] == '/' {
|
||||
if !cf.IsValidUsePath(dirname) {
|
||||
return fmt.Errorf("invalid package path %q", dirname)
|
||||
}
|
||||
|
||||
|
||||
+3
-14
@@ -16,14 +16,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
cf "github.com/google/wuffs/cmd/commonflags"
|
||||
)
|
||||
|
||||
var commands = []struct {
|
||||
@@ -63,7 +63,7 @@ func main1() error {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
wuffsRoot, err := findWuffsRoot()
|
||||
wuffsRoot, err := cf.WuffsRoot()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -79,17 +79,6 @@ func main1() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func findWuffsRoot() (string, error) {
|
||||
// TODO: look for a WUFFSROOT environment variable?
|
||||
for _, p := range filepath.SplitList(build.Default.GOPATH) {
|
||||
p = filepath.Join(p, "src", "github.com", "google", "wuffs")
|
||||
if o, err := os.Stat(p); err == nil && o.IsDir() {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
return "", errors.New("could not find Wuffs root directory")
|
||||
}
|
||||
|
||||
func listDir(wuffsRoot string, dirname string, returnSubdirs bool) (filenames []string, dirnames []string, err error) {
|
||||
f, err := os.Open(filepath.Join(wuffsRoot, filepath.FromSlash(dirname)))
|
||||
if err != nil {
|
||||
|
||||
@@ -111,6 +111,244 @@ typedef struct {
|
||||
|
||||
// ---------------- BEGIN USE "std/flate"
|
||||
|
||||
#ifndef WUFFS_FLATE_H
|
||||
#define WUFFS_FLATE_H
|
||||
|
||||
// Code generated by wuffs-c. DO NOT EDIT.
|
||||
|
||||
// ---------------- Use Declarations
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
// Status codes are int32_t values:
|
||||
// - the sign bit indicates a non-recoverable status code: an error
|
||||
// - bits 10-30 hold the packageid: a namespace
|
||||
// - bits 8-9 are reserved
|
||||
// - bits 0-7 are a package-namespaced numeric code
|
||||
//
|
||||
// Do not manipulate these bits directly. Use the API functions such as
|
||||
// wuffs_flate__status__is_error instead.
|
||||
typedef int32_t wuffs_flate__status;
|
||||
|
||||
#define wuffs_flate__packageid 967230 // 0x000EC23E
|
||||
|
||||
#define WUFFS_FLATE__STATUS_OK 0 // 0x00000000
|
||||
#define WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define WUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define WUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define WUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define WUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define WUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_FLATE__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000A
|
||||
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
-1157040128 // 0xBB08F800
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_UNDER_SUBSCRIBED \
|
||||
-1157040127 // 0xBB08F801
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT \
|
||||
-1157040126 // 0xBB08F802
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_REPETITION \
|
||||
-1157040125 // 0xBB08F803
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE -1157040124 // 0xBB08F804
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_MINIMUM_CODE_LENGTH \
|
||||
-1157040123 // 0xBB08F805
|
||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE -1157040122 // 0xBB08F806
|
||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
||||
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
||||
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||
-1157040119 // 0xBB08F809
|
||||
#define WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xBB08F80A
|
||||
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||
-1157040117 // 0xBB08F80B
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||
-1157040116 // 0xBB08F80C
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||
-1157040115 // 0xBB08F80D
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||
-1157040114 // 0xBB08F80E
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||
-1157040113 // 0xBB08F80F
|
||||
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xBB08F810
|
||||
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xBB08F811
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||
-1157040110 // 0xBB08F812
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
||||
-1157040109 // 0xBB08F813
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xBB08F814
|
||||
#define WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
||||
-1157040107 // 0xBB08F815
|
||||
|
||||
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
||||
|
||||
const char* wuffs_flate__status__string(wuffs_flate__status s);
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
// ---------------- Structs
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// wuffs_flate__flate_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint32_t f_huffs[2][1234];
|
||||
uint32_t f_n_huffs_bits[2];
|
||||
uint8_t f_history[32768];
|
||||
uint32_t f_history_index;
|
||||
uint8_t f_code_lengths[320];
|
||||
bool f_end_of_block;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
wuffs_flate__status v_z;
|
||||
uint64_t v_n_copied;
|
||||
uint32_t v_already_full;
|
||||
} c_decode[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_final;
|
||||
uint32_t v_type;
|
||||
} c_decode_blocks[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_length;
|
||||
uint32_t v_n_copied;
|
||||
uint64_t scratch;
|
||||
} c_decode_uncompressed[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_i;
|
||||
} c_init_fixed_huffman[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
uint32_t v_n_lit;
|
||||
uint32_t v_n_dist;
|
||||
uint32_t v_n_clen;
|
||||
uint32_t v_i;
|
||||
uint32_t v_mask;
|
||||
uint32_t v_table_entry;
|
||||
uint32_t v_table_entry_n_bits;
|
||||
uint32_t v_n_extra_bits;
|
||||
uint8_t v_rep_symbol;
|
||||
uint32_t v_rep_count;
|
||||
} c_init_dynamic_huffman[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
uint32_t v_table_entry;
|
||||
uint32_t v_table_entry_n_bits;
|
||||
uint32_t v_lmask;
|
||||
uint32_t v_dmask;
|
||||
uint32_t v_redir_top;
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_distance;
|
||||
uint32_t v_n_copied;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
} c_decode_huffman_slow[1];
|
||||
} private_impl;
|
||||
} wuffs_flate__flate_decoder;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// wuffs_flate__adler32__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_state;
|
||||
|
||||
} private_impl;
|
||||
} wuffs_flate__adler32;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// wuffs_flate__zlib_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
wuffs_flate__flate_decoder f_flate;
|
||||
wuffs_flate__adler32 f_adler;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint16_t v_x;
|
||||
uint32_t v_checksum;
|
||||
wuffs_flate__status v_z;
|
||||
uint64_t scratch;
|
||||
} c_decode[1];
|
||||
} private_impl;
|
||||
} wuffs_flate__zlib_decoder;
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other wuffs_flate__flate_decoder__* function.
|
||||
//
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// wuffs_flate__zlib_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other wuffs_flate__zlib_decoder__* function.
|
||||
//
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
||||
wuffs_flate__zlib_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WUFFS_FLATE_H
|
||||
|
||||
// ---------------- END USE "std/flate"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -111,6 +111,244 @@ typedef struct {
|
||||
|
||||
// ---------------- BEGIN USE "std/flate"
|
||||
|
||||
#ifndef WUFFS_FLATE_H
|
||||
#define WUFFS_FLATE_H
|
||||
|
||||
// Code generated by wuffs-c. DO NOT EDIT.
|
||||
|
||||
// ---------------- Use Declarations
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
// Status codes are int32_t values:
|
||||
// - the sign bit indicates a non-recoverable status code: an error
|
||||
// - bits 10-30 hold the packageid: a namespace
|
||||
// - bits 8-9 are reserved
|
||||
// - bits 0-7 are a package-namespaced numeric code
|
||||
//
|
||||
// Do not manipulate these bits directly. Use the API functions such as
|
||||
// wuffs_flate__status__is_error instead.
|
||||
typedef int32_t wuffs_flate__status;
|
||||
|
||||
#define wuffs_flate__packageid 967230 // 0x000EC23E
|
||||
|
||||
#define WUFFS_FLATE__STATUS_OK 0 // 0x00000000
|
||||
#define WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define WUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define WUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define WUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define WUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define WUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_FLATE__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000A
|
||||
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
-1157040128 // 0xBB08F800
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_UNDER_SUBSCRIBED \
|
||||
-1157040127 // 0xBB08F801
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT \
|
||||
-1157040126 // 0xBB08F802
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_REPETITION \
|
||||
-1157040125 // 0xBB08F803
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE -1157040124 // 0xBB08F804
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_MINIMUM_CODE_LENGTH \
|
||||
-1157040123 // 0xBB08F805
|
||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE -1157040122 // 0xBB08F806
|
||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
||||
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
||||
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||
-1157040119 // 0xBB08F809
|
||||
#define WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xBB08F80A
|
||||
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||
-1157040117 // 0xBB08F80B
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||
-1157040116 // 0xBB08F80C
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||
-1157040115 // 0xBB08F80D
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||
-1157040114 // 0xBB08F80E
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||
-1157040113 // 0xBB08F80F
|
||||
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xBB08F810
|
||||
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xBB08F811
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||
-1157040110 // 0xBB08F812
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
||||
-1157040109 // 0xBB08F813
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xBB08F814
|
||||
#define WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
||||
-1157040107 // 0xBB08F815
|
||||
|
||||
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
||||
|
||||
const char* wuffs_flate__status__string(wuffs_flate__status s);
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
// ---------------- Structs
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// wuffs_flate__flate_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint32_t f_huffs[2][1234];
|
||||
uint32_t f_n_huffs_bits[2];
|
||||
uint8_t f_history[32768];
|
||||
uint32_t f_history_index;
|
||||
uint8_t f_code_lengths[320];
|
||||
bool f_end_of_block;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
wuffs_flate__status v_z;
|
||||
uint64_t v_n_copied;
|
||||
uint32_t v_already_full;
|
||||
} c_decode[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_final;
|
||||
uint32_t v_type;
|
||||
} c_decode_blocks[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_length;
|
||||
uint32_t v_n_copied;
|
||||
uint64_t scratch;
|
||||
} c_decode_uncompressed[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_i;
|
||||
} c_init_fixed_huffman[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
uint32_t v_n_lit;
|
||||
uint32_t v_n_dist;
|
||||
uint32_t v_n_clen;
|
||||
uint32_t v_i;
|
||||
uint32_t v_mask;
|
||||
uint32_t v_table_entry;
|
||||
uint32_t v_table_entry_n_bits;
|
||||
uint32_t v_n_extra_bits;
|
||||
uint8_t v_rep_symbol;
|
||||
uint32_t v_rep_count;
|
||||
} c_init_dynamic_huffman[1];
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
uint32_t v_table_entry;
|
||||
uint32_t v_table_entry_n_bits;
|
||||
uint32_t v_lmask;
|
||||
uint32_t v_dmask;
|
||||
uint32_t v_redir_top;
|
||||
uint32_t v_redir_mask;
|
||||
uint32_t v_length;
|
||||
uint32_t v_distance;
|
||||
uint32_t v_n_copied;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
} c_decode_huffman_slow[1];
|
||||
} private_impl;
|
||||
} wuffs_flate__flate_decoder;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// wuffs_flate__adler32__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_state;
|
||||
|
||||
} private_impl;
|
||||
} wuffs_flate__adler32;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// wuffs_flate__zlib_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
wuffs_flate__flate_decoder f_flate;
|
||||
wuffs_flate__adler32 f_adler;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint16_t v_x;
|
||||
uint32_t v_checksum;
|
||||
wuffs_flate__status v_z;
|
||||
uint64_t scratch;
|
||||
} c_decode[1];
|
||||
} private_impl;
|
||||
} wuffs_flate__zlib_decoder;
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other wuffs_flate__flate_decoder__* function.
|
||||
//
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// wuffs_flate__zlib_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other wuffs_flate__zlib_decoder__* function.
|
||||
//
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
||||
wuffs_flate__zlib_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WUFFS_FLATE_H
|
||||
|
||||
// ---------------- END USE "std/flate"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in new issue
Block a user