meta: rename to fx
This commit is contained in:
@@ -1,30 +1,30 @@
|
||||
#include <assert.h>
|
||||
#include <blue/compress/compressor.h>
|
||||
#include <blue/compress/zstd.h>
|
||||
#include <blue/core/ringbuffer.h>
|
||||
#include <fx/compress/compressor.h>
|
||||
#include <fx/compress/zstd.h>
|
||||
#include <fx/core/ringbuffer.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUF_SIZE 32
|
||||
|
||||
int refill_input_buffer(FILE *fp, b_ringbuffer *dest)
|
||||
int refill_input_buffer(FILE *fp, fx_ringbuffer *dest)
|
||||
{
|
||||
while (1) {
|
||||
void *buf;
|
||||
size_t capacity;
|
||||
b_status status
|
||||
= b_ringbuffer_open_write_buffer(dest, &buf, &capacity);
|
||||
if (status == B_ERR_NO_SPACE) {
|
||||
fx_status status
|
||||
= fx_ringbuffer_open_write_buffer(dest, &buf, &capacity);
|
||||
if (status == FX_ERR_NO_SPACE) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t r = fread(buf, 1, capacity, fp);
|
||||
|
||||
b_ringbuffer_close_write_buffer(dest, &buf, r);
|
||||
fx_ringbuffer_close_write_buffer(dest, &buf, r);
|
||||
|
||||
if (r == 0) {
|
||||
return ferror(fp) ? -1 : 0;
|
||||
@@ -38,24 +38,24 @@ int refill_input_buffer(FILE *fp, b_ringbuffer *dest)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flush_output_buffer(FILE *fp, b_ringbuffer *src)
|
||||
int flush_output_buffer(FILE *fp, fx_ringbuffer *src)
|
||||
{
|
||||
while (1) {
|
||||
const void *buf;
|
||||
size_t capacity;
|
||||
b_status status
|
||||
= b_ringbuffer_open_read_buffer(src, &buf, &capacity);
|
||||
if (status == B_ERR_NO_DATA) {
|
||||
fx_status status
|
||||
= fx_ringbuffer_open_read_buffer(src, &buf, &capacity);
|
||||
if (status == FX_ERR_NO_DATA) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!B_OK(status)) {
|
||||
if (!FX_OK(status)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t w = fwrite(buf, 1, capacity, fp);
|
||||
|
||||
b_ringbuffer_close_read_buffer(src, &buf, w);
|
||||
fx_ringbuffer_close_read_buffer(src, &buf, w);
|
||||
|
||||
if (w < capacity) {
|
||||
return -1;
|
||||
@@ -72,11 +72,11 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_mode mode;
|
||||
fx_compressor_mode mode;
|
||||
if (!strcmp(argv[1], "C")) {
|
||||
mode = B_COMPRESSOR_MODE_COMPRESS;
|
||||
mode = FX_COMPRESSOR_MODE_COMPRESS;
|
||||
} else if (!strcmp(argv[1], "D")) {
|
||||
mode = B_COMPRESSOR_MODE_DECOMPRESS;
|
||||
mode = FX_COMPRESSOR_MODE_DECOMPRESS;
|
||||
} else {
|
||||
fprintf(stderr, "invalid mode %s\n", argv[1]);
|
||||
return -1;
|
||||
@@ -95,24 +95,24 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_status status = B_SUCCESS;
|
||||
b_type compressor_type = B_TYPE_ZSTD_COMPRESSOR;
|
||||
b_compressor *compressor = b_object_create(compressor_type);
|
||||
fx_status status = FX_SUCCESS;
|
||||
fx_type compressor_type = FX_TYPE_ZSTD_COMPRESSOR;
|
||||
fx_compressor *compressor = fx_object_create(compressor_type);
|
||||
|
||||
size_t inbuf_size, outbuf_size;
|
||||
b_compressor_get_buffer_size(
|
||||
fx_compressor_get_buffer_size(
|
||||
compressor_type, mode, &inbuf_size, &outbuf_size);
|
||||
|
||||
b_ringbuffer *in = b_ringbuffer_create(inbuf_size);
|
||||
b_ringbuffer *out = b_ringbuffer_create(outbuf_size);
|
||||
fx_ringbuffer *in = fx_ringbuffer_create(inbuf_size);
|
||||
fx_ringbuffer *out = fx_ringbuffer_create(outbuf_size);
|
||||
|
||||
if (!in || !out) {
|
||||
fprintf(stderr, "memory allocation failure");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_set_buffer(compressor, in, out);
|
||||
b_compressor_set_mode(compressor, mode);
|
||||
fx_compressor_set_buffer(compressor, in, out);
|
||||
fx_compressor_set_mode(compressor, mode);
|
||||
|
||||
int ret = 0;
|
||||
while (1) {
|
||||
@@ -122,21 +122,21 @@ int main(int argc, const char **argv)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!b_ringbuffer_available_data_remaining(in)) {
|
||||
if (!fx_ringbuffer_available_data_remaining(in)) {
|
||||
break;
|
||||
}
|
||||
|
||||
status = b_compressor_step(compressor);
|
||||
status = fx_compressor_step(compressor);
|
||||
|
||||
if (status == B_ERR_NO_DATA) {
|
||||
if (status == FX_ERR_NO_DATA) {
|
||||
break;
|
||||
} else if (status == B_ERR_NO_SPACE) {
|
||||
} else if (status == FX_ERR_NO_SPACE) {
|
||||
ret = flush_output_buffer(out_fp, out);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "write error\n");
|
||||
break;
|
||||
}
|
||||
} else if (!B_OK(status)) {
|
||||
} else if (!FX_OK(status)) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@@ -148,16 +148,16 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mode == B_COMPRESSOR_MODE_COMPRESS) {
|
||||
while (!b_compressor_eof(compressor)) {
|
||||
status = b_compressor_end(compressor);
|
||||
if (!B_OK(status)) {
|
||||
if (mode == FX_COMPRESSOR_MODE_COMPRESS) {
|
||||
while (!fx_compressor_eof(compressor)) {
|
||||
status = fx_compressor_end(compressor);
|
||||
if (!FX_OK(status)) {
|
||||
fprintf(stderr,
|
||||
"compression finalisation error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!b_ringbuffer_available_data_remaining(out)) {
|
||||
if (!fx_ringbuffer_available_data_remaining(out)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -171,13 +171,13 @@ int main(int argc, const char **argv)
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
b_compressor_unref(compressor);
|
||||
fx_compressor_unref(compressor);
|
||||
|
||||
fclose(in_fp);
|
||||
fclose(out_fp);
|
||||
|
||||
b_ringbuffer_unref(in);
|
||||
b_ringbuffer_unref(out);
|
||||
fx_ringbuffer_unref(in);
|
||||
fx_ringbuffer_unref(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user