From d371222efb6303518bad21ded632c88cd9515353 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 4 Sep 2024 11:18:26 +0200 Subject: [PATCH] ocispec: fix style Signed-off-by: Giuseppe Scrivano --- src/ocispec/headers.py | 8 ++++---- src/ocispec/json_common.c | 24 ++++++++++++++++-------- src/ocispec/sources.py | 15 +++++++-------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/ocispec/headers.py b/src/ocispec/headers.py index cbf00de2..c8af2fe9 100755 --- a/src/ocispec/headers.py +++ b/src/ocispec/headers.py @@ -232,13 +232,13 @@ def header_reflect(structs, schema_info, header): length = len(structs) toptype = structs[length - 1].typ if length != 0 else "" if toptype == 'object': - header.append(f"{prefix} *{prefix}_parse_file(const char *filename, const struct parser_context *ctx, "\ + header.append(f"{prefix} *{prefix}_parse_file (const char *filename, const struct parser_context *ctx, "\ "parser_error *err);\n\n") - header.append(f"{prefix} *{prefix}_parse_file_stream(FILE *stream, const struct parser_context *ctx, "\ + header.append(f"{prefix} *{prefix}_parse_file_stream (FILE *stream, const struct parser_context *ctx, "\ "parser_error *err);\n\n") - header.append(f"{prefix} *{prefix}_parse_data(const char *jsondata, const struct parser_context *ctx, "\ + header.append(f"{prefix} *{prefix}_parse_data (const char *jsondata, const struct parser_context *ctx, "\ "parser_error *err);\n\n") - header.append(f"char *{prefix}_generate_json(const {prefix} *ptr, const struct parser_context *ctx, "\ + header.append(f"char *{prefix}_generate_json (const {prefix} *ptr, const struct parser_context *ctx, "\ "parser_error *err);\n\n") elif toptype == 'array': header_reflect_top_array(structs[length - 1], prefix, header) diff --git a/src/ocispec/json_common.c b/src/ocispec/json_common.c index 9722b955..9fde1326 100644 --- a/src/ocispec/json_common.c +++ b/src/ocispec/json_common.c @@ -509,7 +509,8 @@ free_json_map_int_int (json_map_int_int *map) define_cleaner_function (json_map_int_int *, free_json_map_int_int) - json_map_int_int *make_json_map_int_int (yajl_val src, const struct parser_context *ctx, parser_error *err) +json_map_int_int * +make_json_map_int_int (yajl_val src, const struct parser_context *ctx, parser_error *err) { __auto_cleanup (free_json_map_int_int) json_map_int_int *ret = NULL; size_t i; @@ -689,7 +690,8 @@ free_json_map_int_bool (json_map_int_bool *map) define_cleaner_function (json_map_int_bool *, free_json_map_int_bool) - json_map_int_bool *make_json_map_int_bool (yajl_val src, const struct parser_context *ctx, parser_error *err) +json_map_int_bool * +make_json_map_int_bool (yajl_val src, const struct parser_context *ctx, parser_error *err) { __auto_cleanup (free_json_map_int_bool) json_map_int_bool *ret = NULL; size_t i; @@ -861,7 +863,8 @@ free_json_map_int_string (json_map_int_string *map) define_cleaner_function (json_map_int_string *, free_json_map_int_string) - json_map_int_string *make_json_map_int_string (yajl_val src, const struct parser_context *ctx, parser_error *err) +json_map_int_string * +make_json_map_int_string (yajl_val src, const struct parser_context *ctx, parser_error *err) { __auto_cleanup (free_json_map_int_string) json_map_int_string *ret = NULL; size_t i; @@ -1020,7 +1023,8 @@ free_json_map_string_int (json_map_string_int *map) define_cleaner_function (json_map_string_int *, free_json_map_string_int) - json_map_string_int *make_json_map_string_int (yajl_val src, const struct parser_context *ctx, parser_error *err) +json_map_string_int * +make_json_map_string_int (yajl_val src, const struct parser_context *ctx, parser_error *err) { __auto_cleanup (free_json_map_string_int) json_map_string_int *ret = NULL; size_t i; @@ -1181,7 +1185,8 @@ free_json_map_string_int64 (json_map_string_int64 *map) define_cleaner_function (json_map_string_int64 *, free_json_map_string_int64) - json_map_string_int64 *make_json_map_string_int64 (yajl_val src, const struct parser_context *ctx, +json_map_string_int64 * +make_json_map_string_int64 (yajl_val src, const struct parser_context *ctx, parser_error *err) { __auto_cleanup (free_json_map_string_int64) json_map_string_int64 *ret = NULL; @@ -1316,7 +1321,8 @@ free_json_map_string_bool (json_map_string_bool *map) define_cleaner_function (json_map_string_bool *, free_json_map_string_bool) - json_map_string_bool *make_json_map_string_bool (yajl_val src, const struct parser_context *ctx, parser_error *err) +json_map_string_bool * +make_json_map_string_bool (yajl_val src, const struct parser_context *ctx, parser_error *err) { __auto_cleanup (free_json_map_string_bool) json_map_string_bool *ret = NULL; size_t i; @@ -1485,7 +1491,8 @@ free_json_map_string_string (json_map_string_string *map) define_cleaner_function (json_map_string_string *, free_json_map_string_string) - json_map_string_string *make_json_map_string_string (yajl_val src, const struct parser_context *ctx, +json_map_string_string * +make_json_map_string_string (yajl_val src, const struct parser_context *ctx, parser_error *err) { __auto_cleanup (free_json_map_string_string) json_map_string_string *ret = NULL; @@ -1628,7 +1635,8 @@ cleanup_yajl_gen (yajl_gen g) define_cleaner_function (yajl_gen, cleanup_yajl_gen) - char *json_marshal_string (const char *str, size_t length, const struct parser_context *ctx, parser_error *err) +char * +json_marshal_string (const char *str, size_t length, const struct parser_context *ctx, parser_error *err) { __auto_cleanup (cleanup_yajl_gen) yajl_gen g = NULL; struct parser_context tmp_ctx = { 0 }; diff --git a/src/ocispec/sources.py b/src/ocispec/sources.py index f1c499d2..c7d479df 100755 --- a/src/ocispec/sources.py +++ b/src/ocispec/sources.py @@ -325,8 +325,8 @@ def parse_obj_arr_obj(obj, c_file, prefix, obj_typename): } for (i = 0; i < tree->u.object.len; i++) - {""" \ - f"if ({condition})" \ + {\n""" \ + f" if ({condition})" \ """{ if (ctx->options & OPT_PARSE_FULLKEY) { @@ -339,13 +339,12 @@ def parse_obj_arr_obj(obj, c_file, prefix, obj_typename): j++; } } - if (ctx->options & OPT_PARSE_STRICT) - { - if (j > 0 && ctx->errfile != NULL) - (void) fprintf (ctx->errfile, "WARNING: unknown key found\\n"); - } + + if ((ctx->options & OPT_PARSE_STRICT) && j > 0 && ctx->errfile != NULL) + (void) fprintf (ctx->errfile, "WARNING: unknown key found\\n"); + if (ctx->options & OPT_PARSE_FULLKEY) - ret->_residual = resi; + ret->_residual = resi; } """)