Skip to content

Commit

Permalink
clean up (#124)
Browse files Browse the repository at this point in the history
update ci tag to 0.3.6
  • Loading branch information
liquidaty authored Mar 24, 2023
1 parent bb21ae3 commit 5a7e862
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ${{ matrix.os }}

env:
TAG: "0.3.5"
TAG: "0.3.6"
AMD64_LINUX_GCC: amd64-linux-gcc
AMD64_LINUX_CLANG: amd64-linux-clang
AMD64_WINDOWS_MINGW: amd64-windows-mingw
Expand Down
17 changes: 0 additions & 17 deletions app/2db.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,10 @@ static void zsv_2db_delete(zsv_2db_handle data) {
free(data->json_parser.row_values);

yajl_helper_parse_state_free(&data->json_parser.st);
// if(data->json_parser.handle)
// yajl_free(data->json_parser.handle);

free(data);
}

static int zsv_2db_json_parse_err(struct zsv_2db_data *data,
unsigned char *last_parsed_buff,
size_t last_parsed_buff_len
) {
unsigned char *str = yajl_get_error(data->json_parser.st.yajl, 1,
last_parsed_buff, last_parsed_buff_len);
if(str) {
fprintf(stderr, "Error parsing JSON: %s", (const char *)str);
yajl_free_error(data->json_parser.st.yajl, str);
}
return 1;
}

/* sqlite3 helper functions */

static int zsv_2db_sqlite3_exec_2db(sqlite3 *db, const char *sql) {
Expand Down Expand Up @@ -768,13 +753,11 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *zs
break;
yajl_status stat = yajl_parse(zsv_2db_yajl_handle(data), buff, bytes_read);
if(stat != yajl_status_ok)
// err = zsv_2db_json_parse_err(data, buff, bytes_read);
err = yajl_helper_print_err(data->json_parser.st.yajl, buff, bytes_read);
}

if(!err) {
if(yajl_complete_parse(zsv_2db_yajl_handle(data)) != yajl_status_ok)
// err = zsv_2db_json_parse_err(data, buff, bytes_read);
err = yajl_helper_print_err(data->json_parser.st.yajl, buff, bytes_read);
else if(zsv_2db_err(data) || zsv_2db_finish(data))
err = 1;
Expand Down
20 changes: 11 additions & 9 deletions app/prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,9 @@ zsv_prop_get_or_set_is_prop_file(
) {
static struct zsv_dir_filter ctx = {
#ifndef ZSV_IS_PROP_FILE_HANDLER
.handler = zsv_is_prop_file,
.filter = zsv_is_prop_file,
#else
.handler = ZSV_IS_PROP_FILE_HANDLER,
.filter = ZSV_IS_PROP_FILE_HANDLER,
#endif
#ifndef ZSV_IS_PROP_FILE_DEPTH
.max_depth = 1
Expand All @@ -588,8 +588,8 @@ zsv_prop_get_or_set_is_prop_file(
};

if(set) {
if(!(ctx.handler = custom_is_prop_file)) {
ctx.handler = zsv_is_prop_file;
if(!(ctx.filter = custom_is_prop_file)) {
ctx.filter = zsv_is_prop_file;
max_depth = 1;
} else
ctx.max_depth = max_depth;
Expand All @@ -600,8 +600,10 @@ zsv_prop_get_or_set_is_prop_file(
static int zsv_prop_foreach_list(struct zsv_foreach_dirent_handle *h, size_t depth) {
if(!h->is_dir) {
struct zsv_dir_filter *ctx = (struct zsv_dir_filter *)h->ctx;
if(ctx->handler(h, depth))
h->ctx = ctx->ctx;
if(ctx->filter(h, depth))
printf("%s\n", h->entry);
h->ctx = ctx;
}
return 0;
}
Expand Down Expand Up @@ -689,7 +691,8 @@ struct zsv_prop_foreach_copy_ctx {
static int zsv_prop_foreach_copy(struct zsv_foreach_dirent_handle *h, size_t depth) {
if(!h->is_dir) {
struct zsv_prop_foreach_copy_ctx *ctx = h->ctx;
if(ctx->zsv_dir_filter.handler(h, depth)) {
h->ctx = ctx->zsv_dir_filter.ctx;
if(ctx->zsv_dir_filter.filter(h, depth)) {
char *dest_prop_filepath;
asprintf(&dest_prop_filepath, "%s%s", ctx->dest_cache_dir, h->parent_and_entry + strlen((const char *)ctx->src_cache_dir));
if(!dest_prop_filepath) {
Expand Down Expand Up @@ -743,6 +746,7 @@ static int zsv_prop_foreach_copy(struct zsv_foreach_dirent_handle *h, size_t dep
free(dest_prop_filepath);
}
}
h->ctx = ctx;
}
return 0;
}
Expand Down Expand Up @@ -829,14 +833,12 @@ static int zsv_prop_execute_export(const char *src, const char *dest, unsigned c
err = errno = ENOMEM, perror(NULL);
else {
struct zsv_dir_filter zsv_dir_filter = *zsv_prop_get_or_set_is_prop_file(NULL, 0, 0);
err = zsv_dir_to_json(parent_dir, dest, &zsv_dir_filter, verbose);
err = zsv_dir_to_json(parent_dir, (const unsigned char *)dest, &zsv_dir_filter, verbose);
}
free(parent_dir);
return err;
}



static int zsv_prop_execute_import(const char *dest, const char *src, unsigned char force,
unsigned char dry, unsigned char verbose) {
int err = 0;
Expand Down
1 change: 0 additions & 1 deletion app/utils/dirs_from_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ int zsv_dir_from_json(const unsigned char *target_dir,
if(src == stdin) {
src = NULL;
tmp_fn = zsv_get_temp_filename("zsv_prop_XXXXXXXX");
src = (const char *)tmp_fn;
FILE *tmp_f;
if(!tmp_fn) {
err = errno = ENOMEM;
Expand Down
11 changes: 7 additions & 4 deletions app/utils/dirs_to_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ struct zsv_dir_foreach_to_json_ctx {
static int zsv_dir_foreach_to_json(struct zsv_foreach_dirent_handle *h, size_t depth) {
if(!h->is_dir) {
struct zsv_dir_foreach_to_json_ctx *ctx = h->ctx;
if(ctx->zsv_dir_filter.handler(h, depth) && !ctx->err) {
h->ctx = ctx->zsv_dir_filter.ctx;
if(ctx->zsv_dir_filter.filter(h, depth) && !ctx->err) {
char suffix = 0;
if(strlen(h->parent_and_entry) > 5 && !zsv_stricmp((const unsigned char *)h->parent_and_entry + strlen(h->parent_and_entry) - 5, (const unsigned char *)".json"))
suffix = 'j'; // json
Expand Down Expand Up @@ -62,6 +63,7 @@ static int zsv_dir_foreach_to_json(struct zsv_foreach_dirent_handle *h, size_t d
}
}
}
h->ctx = ctx;
}
return 0;
}
Expand All @@ -75,14 +77,15 @@ static int zsv_dir_foreach_to_json(struct zsv_foreach_dirent_handle *h, size_t d
* @param parent_dir : directory to export
* @param dest : file path to output to, or NULL to output to stdout
*/
int zsv_dir_to_json(const unsigned char *parent_dir, const char *dest,
int zsv_dir_to_json(const unsigned char *parent_dir,
const unsigned char *output_filename,
struct zsv_dir_filter *zsv_dir_filter,
unsigned char verbose
) {
int err = 0;
FILE *fdest = dest ? fopen(dest, "wb") : stdout;
FILE *fdest = output_filename ? fopen((const char *)output_filename, "wb") : stdout;
if(!fdest)
err = errno, perror(dest);
err = errno, perror((const char *)output_filename);
else {
struct zsv_dir_foreach_to_json_ctx ctx = { 0 };
ctx.zsv_dir_filter = *zsv_dir_filter;
Expand Down
14 changes: 8 additions & 6 deletions include/zsv/utils/dirs.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ int zsv_foreach_dirent(const char *dir_path,
);

struct zsv_dir_filter {
zsv_foreach_dirent_handler handler;
size_t max_depth;
zsv_foreach_dirent_handler filter; /* filter function; return 1 to process this node */
size_t max_depth; /* max depth to recurse */
void *ctx; /* pointer to pass to filter function */
};

/**
Expand All @@ -102,11 +103,12 @@ struct zsv_dir_filter {
* Files named with .json suffix will be exported as JSON (content must be valid JSON)
* Files named with any other suffix will be exported as a single string value (do not try with large files)
*
* @param parent_dir : directory to export
* @param dest : file path to output to, or NULL to output to stdout
* @param file_filter:
* @param parent_dir : directory to export
* @param output_filename : file path to output to, or NULL to output to stdout
* @param file_filter : filter determining which files to export
*/
int zsv_dir_to_json(const unsigned char *parent_dir, const char *dest,
int zsv_dir_to_json(const unsigned char *parent_dir,
const unsigned char *output_filename,
struct zsv_dir_filter *file_filter,
unsigned char verbose
);
Expand Down

0 comments on commit 5a7e862

Please sign in to comment.