From 8c97d3273e89af56cef1bd41aafbd7af34c712c0 Mon Sep 17 00:00:00 2001 From: softworkz Date: Sat, 3 May 2025 09:20:12 +0200 Subject: [PATCH 1/3] fftools/textformat: Rename variables wctx to tctx Signed-off-by: softworkz --- fftools/textformat/tf_compact.c | 74 +++++------ fftools/textformat/tf_default.c | 46 +++---- fftools/textformat/tf_flat.c | 38 +++--- fftools/textformat/tf_ini.c | 36 +++--- fftools/textformat/tf_json.c | 84 ++++++------- fftools/textformat/tf_mermaid.c | 212 ++++++++++++++++---------------- fftools/textformat/tf_mermaid.h | 2 +- fftools/textformat/tf_xml.c | 82 ++++++------ 8 files changed, 287 insertions(+), 287 deletions(-) diff --git a/fftools/textformat/tf_compact.c b/fftools/textformat/tf_compact.c index c6311b5deabf6..62717bba0a5e6 100644 --- a/fftools/textformat/tf_compact.c +++ b/fftools/textformat/tf_compact.c @@ -113,12 +113,12 @@ static const AVOption compact_options[] = { DEFINE_FORMATTER_CLASS(compact); -static av_cold int compact_init(AVTextFormatContext *wctx) +static av_cold int compact_init(AVTextFormatContext *tctx) { - CompactContext *compact = wctx->priv; + CompactContext *compact = tctx->priv; if (strlen(compact->item_sep_str) != 1) { - av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n", + av_log(tctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n", compact->item_sep_str); return AVERROR(EINVAL); } @@ -131,26 +131,26 @@ static av_cold int compact_init(AVTextFormatContext *wctx) } else if (!strcmp(compact->escape_mode_str, "csv" )) { compact->escape_str = csv_escape_str; } else { - av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str); + av_log(tctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str); return AVERROR(EINVAL); } return 0; } -static void compact_print_section_header(AVTextFormatContext *wctx, const void *data) +static void compact_print_section_header(AVTextFormatContext *tctx, const void *data) { - CompactContext *compact = wctx->priv; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + CompactContext *compact = tctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); if (!section) return; - compact->terminate_line[wctx->level] = 1; - compact->has_nested_elems[wctx->level] = 0; + compact->terminate_line[tctx->level] = 1; + compact->has_nested_elems[tctx->level] = 0; - av_bprint_clear(&wctx->section_pbuf[wctx->level]); + av_bprint_clear(&tctx->section_pbuf[tctx->level]); if (parent_section && (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE || (!(section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) && @@ -159,13 +159,13 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void * /* define a prefix for elements not contained in an array or in a wrapper, or for array elements with a type */ const char *element_name = (char *)av_x_if_null(section->element_name, section->name); - AVBPrint *section_pbuf = &wctx->section_pbuf[wctx->level]; + AVBPrint *section_pbuf = &tctx->section_pbuf[tctx->level]; - compact->nested_section[wctx->level] = 1; - compact->has_nested_elems[wctx->level - 1] = 1; + compact->nested_section[tctx->level] = 1; + compact->has_nested_elems[tctx->level - 1] = 1; av_bprintf(section_pbuf, "%s%s", - wctx->section_pbuf[wctx->level - 1].str, element_name); + tctx->section_pbuf[tctx->level - 1].str, element_name); if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) { // add /TYPE to prefix @@ -182,58 +182,58 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void * } av_bprint_chars(section_pbuf, ':', 1); - wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level - 1]; + tctx->nb_item[tctx->level] = tctx->nb_item[tctx->level - 1]; } else { if (parent_section && !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)) && - wctx->level && wctx->nb_item[wctx->level - 1]) - writer_w8(wctx, compact->item_sep); + tctx->level && tctx->nb_item[tctx->level - 1]) + writer_w8(tctx, compact->item_sep); if (compact->print_section && !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) - writer_printf(wctx, "%s%c", section->name, compact->item_sep); + writer_printf(tctx, "%s%c", section->name, compact->item_sep); } } -static void compact_print_section_footer(AVTextFormatContext *wctx) +static void compact_print_section_footer(AVTextFormatContext *tctx) { - CompactContext *compact = wctx->priv; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + CompactContext *compact = tctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); if (!section) return; - if (!compact->nested_section[wctx->level] && - compact->terminate_line[wctx->level] && + if (!compact->nested_section[tctx->level] && + compact->terminate_line[tctx->level] && !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) - writer_w8(wctx, '\n'); + writer_w8(tctx, '\n'); } -static void compact_print_str(AVTextFormatContext *wctx, const char *key, const char *value) +static void compact_print_str(AVTextFormatContext *tctx, const char *key, const char *value) { - CompactContext *compact = wctx->priv; + CompactContext *compact = tctx->priv; AVBPrint buf; - if (wctx->nb_item[wctx->level]) - writer_w8(wctx, compact->item_sep); + if (tctx->nb_item[tctx->level]) + writer_w8(tctx, compact->item_sep); if (!compact->nokey) - writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); + writer_printf(tctx, "%s%s=", tctx->section_pbuf[tctx->level].str, key); av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - writer_put_str(wctx, compact->escape_str(&buf, value, compact->item_sep, wctx)); + writer_put_str(tctx, compact->escape_str(&buf, value, compact->item_sep, tctx)); av_bprint_finalize(&buf, NULL); } -static void compact_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) +static void compact_print_int(AVTextFormatContext *tctx, const char *key, int64_t value) { - CompactContext *compact = wctx->priv; + CompactContext *compact = tctx->priv; - if (wctx->nb_item[wctx->level]) - writer_w8(wctx, compact->item_sep); + if (tctx->nb_item[tctx->level]) + writer_w8(tctx, compact->item_sep); if (!compact->nokey) - writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); + writer_printf(tctx, "%s%s=", tctx->section_pbuf[tctx->level].str, key); - writer_printf(wctx, "%"PRId64, value); + writer_printf(tctx, "%"PRId64, value); } const AVTextFormatter avtextformatter_compact = { diff --git a/fftools/textformat/tf_default.c b/fftools/textformat/tf_default.c index 019bda9d444d7..2c91a8dec4751 100644 --- a/fftools/textformat/tf_default.c +++ b/fftools/textformat/tf_default.c @@ -62,66 +62,66 @@ static inline char *upcase_string(char *dst, size_t dst_size, const char *src) return dst; } -static void default_print_section_header(AVTextFormatContext *wctx, const void *data) +static void default_print_section_header(AVTextFormatContext *tctx, const void *data) { - DefaultContext *def = wctx->priv; + DefaultContext *def = tctx->priv; char buf[32]; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); if (!section) return; - av_bprint_clear(&wctx->section_pbuf[wctx->level]); + av_bprint_clear(&tctx->section_pbuf[tctx->level]); if (parent_section && !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) { - def->nested_section[wctx->level] = 1; - av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:", - wctx->section_pbuf[wctx->level - 1].str, + def->nested_section[tctx->level] = 1; + av_bprintf(&tctx->section_pbuf[tctx->level], "%s%s:", + tctx->section_pbuf[tctx->level - 1].str, upcase_string(buf, sizeof(buf), av_x_if_null(section->element_name, section->name))); } - if (def->noprint_wrappers || def->nested_section[wctx->level]) + if (def->noprint_wrappers || def->nested_section[tctx->level]) return; if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) - writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name)); + writer_printf(tctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name)); } -static void default_print_section_footer(AVTextFormatContext *wctx) +static void default_print_section_footer(AVTextFormatContext *tctx) { - DefaultContext *def = wctx->priv; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + DefaultContext *def = tctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); char buf[32]; if (!section) return; - if (def->noprint_wrappers || def->nested_section[wctx->level]) + if (def->noprint_wrappers || def->nested_section[tctx->level]) return; if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) - writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name)); + writer_printf(tctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name)); } -static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value) +static void default_print_str(AVTextFormatContext *tctx, const char *key, const char *value) { - DefaultContext *def = wctx->priv; + DefaultContext *def = tctx->priv; if (!def->nokey) - writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); - writer_printf(wctx, "%s\n", value); + writer_printf(tctx, "%s%s=", tctx->section_pbuf[tctx->level].str, key); + writer_printf(tctx, "%s\n", value); } -static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) +static void default_print_int(AVTextFormatContext *tctx, const char *key, int64_t value) { - DefaultContext *def = wctx->priv; + DefaultContext *def = tctx->priv; if (!def->nokey) - writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); - writer_printf(wctx, "%"PRId64"\n", value); + writer_printf(tctx, "%s%s=", tctx->section_pbuf[tctx->level].str, key); + writer_printf(tctx, "%"PRId64"\n", value); } const AVTextFormatter avtextformatter_default = { diff --git a/fftools/textformat/tf_flat.c b/fftools/textformat/tf_flat.c index d5517f109bd47..8c93bc4fb2c61 100644 --- a/fftools/textformat/tf_flat.c +++ b/fftools/textformat/tf_flat.c @@ -52,12 +52,12 @@ static const AVOption flat_options[] = { DEFINE_FORMATTER_CLASS(flat); -static av_cold int flat_init(AVTextFormatContext *wctx) +static av_cold int flat_init(AVTextFormatContext *tctx) { - FlatContext *flat = wctx->priv; + FlatContext *flat = tctx->priv; if (strlen(flat->sep_str) != 1) { - av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n", + av_log(tctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n", flat->sep_str); return AVERROR(EINVAL); } @@ -99,12 +99,12 @@ static const char *flat_escape_value_str(AVBPrint *dst, const char *src) return dst->str; } -static void flat_print_section_header(AVTextFormatContext *wctx, const void *data) +static void flat_print_section_header(AVTextFormatContext *tctx, const void *data) { - FlatContext *flat = wctx->priv; - AVBPrint *buf = &wctx->section_pbuf[wctx->level]; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + FlatContext *flat = tctx->priv; + AVBPrint *buf = &tctx->section_pbuf[tctx->level]; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); if (!section) return; @@ -114,37 +114,37 @@ static void flat_print_section_header(AVTextFormatContext *wctx, const void *dat if (!parent_section) return; - av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level - 1].str); + av_bprintf(buf, "%s", tctx->section_pbuf[tctx->level - 1].str); if (flat->hierarchical || !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) { - av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str); + av_bprintf(buf, "%s%s", tctx->section[tctx->level]->name, flat->sep_str); if (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) { int n = parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE - ? wctx->nb_item_type[wctx->level - 1][section->id] - : wctx->nb_item[wctx->level - 1]; + ? tctx->nb_item_type[tctx->level - 1][section->id] + : tctx->nb_item[tctx->level - 1]; av_bprintf(buf, "%d%s", n, flat->sep_str); } } } -static void flat_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) +static void flat_print_int(AVTextFormatContext *tctx, const char *key, int64_t value) { - writer_printf(wctx, "%s%s=%"PRId64"\n", wctx->section_pbuf[wctx->level].str, key, value); + writer_printf(tctx, "%s%s=%"PRId64"\n", tctx->section_pbuf[tctx->level].str, key, value); } -static void flat_print_str(AVTextFormatContext *wctx, const char *key, const char *value) +static void flat_print_str(AVTextFormatContext *tctx, const char *key, const char *value) { - FlatContext *flat = wctx->priv; + FlatContext *flat = tctx->priv; AVBPrint buf; - writer_put_str(wctx, wctx->section_pbuf[wctx->level].str); + writer_put_str(tctx, tctx->section_pbuf[tctx->level].str); av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - writer_printf(wctx, "%s=", flat_escape_key_str(&buf, key, flat->sep)); + writer_printf(tctx, "%s=", flat_escape_key_str(&buf, key, flat->sep)); av_bprint_clear(&buf); - writer_printf(wctx, "\"%s\"\n", flat_escape_value_str(&buf, value)); + writer_printf(tctx, "\"%s\"\n", flat_escape_value_str(&buf, value)); av_bprint_finalize(&buf, NULL); } diff --git a/fftools/textformat/tf_ini.c b/fftools/textformat/tf_ini.c index 895978529549a..c62441d15156b 100644 --- a/fftools/textformat/tf_ini.c +++ b/fftools/textformat/tf_ini.c @@ -86,56 +86,56 @@ static char *ini_escape_str(AVBPrint *dst, const char *src) return dst->str; } -static void ini_print_section_header(AVTextFormatContext *wctx, const void *data) +static void ini_print_section_header(AVTextFormatContext *tctx, const void *data) { - INIContext *ini = wctx->priv; - AVBPrint *buf = &wctx->section_pbuf[wctx->level]; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + INIContext *ini = tctx->priv; + AVBPrint *buf = &tctx->section_pbuf[tctx->level]; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); if (!section) return; av_bprint_clear(buf); if (!parent_section) { - writer_put_str(wctx, "# ffprobe output\n\n"); + writer_put_str(tctx, "# ffprobe output\n\n"); return; } - if (wctx->nb_item[wctx->level - 1]) - writer_w8(wctx, '\n'); + if (tctx->nb_item[tctx->level - 1]) + writer_w8(tctx, '\n'); - av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level - 1].str); + av_bprintf(buf, "%s", tctx->section_pbuf[tctx->level - 1].str); if (ini->hierarchical || !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) { - av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name); + av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", tctx->section[tctx->level]->name); if (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) { unsigned n = parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE - ? wctx->nb_item_type[wctx->level - 1][section->id] - : wctx->nb_item[wctx->level - 1]; + ? tctx->nb_item_type[tctx->level - 1][section->id] + : tctx->nb_item[tctx->level - 1]; av_bprintf(buf, ".%u", n); } } if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) - writer_printf(wctx, "[%s]\n", buf->str); + writer_printf(tctx, "[%s]\n", buf->str); } -static void ini_print_str(AVTextFormatContext *wctx, const char *key, const char *value) +static void ini_print_str(AVTextFormatContext *tctx, const char *key, const char *value) { AVBPrint buf; av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - writer_printf(wctx, "%s=", ini_escape_str(&buf, key)); + writer_printf(tctx, "%s=", ini_escape_str(&buf, key)); av_bprint_clear(&buf); - writer_printf(wctx, "%s\n", ini_escape_str(&buf, value)); + writer_printf(tctx, "%s\n", ini_escape_str(&buf, value)); av_bprint_finalize(&buf, NULL); } -static void ini_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) +static void ini_print_int(AVTextFormatContext *tctx, const char *key, int64_t value) { - writer_printf(wctx, "%s=%"PRId64"\n", key, value); + writer_printf(tctx, "%s=%"PRId64"\n", key, value); } const AVTextFormatter avtextformatter_ini = { diff --git a/fftools/textformat/tf_json.c b/fftools/textformat/tf_json.c index 78ea5dc21f3bf..5f17bf8f8d33f 100644 --- a/fftools/textformat/tf_json.c +++ b/fftools/textformat/tf_json.c @@ -49,9 +49,9 @@ static const AVOption json_options[] = { DEFINE_FORMATTER_CLASS(json); -static av_cold int json_init(AVTextFormatContext *wctx) +static av_cold int json_init(AVTextFormatContext *tctx) { - JSONContext *json = wctx->priv; + JSONContext *json = tctx->priv; json->item_sep = json->compact ? ", " : ",\n"; json->item_start_end = json->compact ? " " : "\n"; @@ -84,119 +84,119 @@ static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx return dst->str; } -#define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ') +#define JSON_INDENT() writer_printf(tctx, "%*c", json->indent_level * 4, ' ') -static void json_print_section_header(AVTextFormatContext *wctx, const void *data) +static void json_print_section_header(AVTextFormatContext *tctx, const void *data) { - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); - JSONContext *json = wctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); + JSONContext *json = tctx->priv; AVBPrint buf; if (!section) return; - if (wctx->level && wctx->nb_item[wctx->level - 1]) - writer_put_str(wctx, ",\n"); + if (tctx->level && tctx->nb_item[tctx->level - 1]) + writer_put_str(tctx, ",\n"); if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER) { - writer_put_str(wctx, "{\n"); + writer_put_str(tctx, "{\n"); json->indent_level++; } else { av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - json_escape_str(&buf, section->name, wctx); + json_escape_str(&buf, section->name, tctx); JSON_INDENT(); json->indent_level++; if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) { - writer_printf(wctx, "\"%s\": [\n", buf.str); + writer_printf(tctx, "\"%s\": [\n", buf.str); } else if (parent_section && !(parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)) { - writer_printf(wctx, "\"%s\": {%s", buf.str, json->item_start_end); + writer_printf(tctx, "\"%s\": {%s", buf.str, json->item_start_end); } else { - writer_printf(wctx, "{%s", json->item_start_end); + writer_printf(tctx, "{%s", json->item_start_end); /* this is required so the parser can distinguish between packets and frames */ if (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE) { if (!json->compact) JSON_INDENT(); - writer_printf(wctx, "\"type\": \"%s\"", section->name); - wctx->nb_item[wctx->level]++; + writer_printf(tctx, "\"type\": \"%s\"", section->name); + tctx->nb_item[tctx->level]++; } } av_bprint_finalize(&buf, NULL); } } -static void json_print_section_footer(AVTextFormatContext *wctx) +static void json_print_section_footer(AVTextFormatContext *tctx) { - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - JSONContext *json = wctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + JSONContext *json = tctx->priv; if (!section) return; - if (wctx->level == 0) { + if (tctx->level == 0) { json->indent_level--; - writer_put_str(wctx, "\n}\n"); + writer_put_str(tctx, "\n}\n"); } else if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) { - writer_w8(wctx, '\n'); + writer_w8(tctx, '\n'); json->indent_level--; JSON_INDENT(); - writer_w8(wctx, ']'); + writer_w8(tctx, ']'); } else { - writer_put_str(wctx, json->item_start_end); + writer_put_str(tctx, json->item_start_end); json->indent_level--; if (!json->compact) JSON_INDENT(); - writer_w8(wctx, '}'); + writer_w8(tctx, '}'); } } -static inline void json_print_item_str(AVTextFormatContext *wctx, +static inline void json_print_item_str(AVTextFormatContext *tctx, const char *key, const char *value) { AVBPrint buf; av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - writer_printf(wctx, "\"%s\":", json_escape_str(&buf, key, wctx)); + writer_printf(tctx, "\"%s\":", json_escape_str(&buf, key, tctx)); av_bprint_clear(&buf); - writer_printf(wctx, " \"%s\"", json_escape_str(&buf, value, wctx)); + writer_printf(tctx, " \"%s\"", json_escape_str(&buf, value, tctx)); av_bprint_finalize(&buf, NULL); } -static void json_print_str(AVTextFormatContext *wctx, const char *key, const char *value) +static void json_print_str(AVTextFormatContext *tctx, const char *key, const char *value) { - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); - JSONContext *json = wctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); + JSONContext *json = tctx->priv; if (!section) return; - if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) - writer_put_str(wctx, json->item_sep); + if (tctx->nb_item[tctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) + writer_put_str(tctx, json->item_sep); if (!json->compact) JSON_INDENT(); - json_print_item_str(wctx, key, value); + json_print_item_str(tctx, key, value); } -static void json_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) +static void json_print_int(AVTextFormatContext *tctx, const char *key, int64_t value) { - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); - JSONContext *json = wctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); + JSONContext *json = tctx->priv; AVBPrint buf; if (!section) return; - if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) - writer_put_str(wctx, json->item_sep); + if (tctx->nb_item[tctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) + writer_put_str(tctx, json->item_sep); if (!json->compact) JSON_INDENT(); av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); - writer_printf(wctx, "\"%s\": %"PRId64, json_escape_str(&buf, key, wctx), value); + writer_printf(tctx, "\"%s\": %"PRId64, json_escape_str(&buf, key, tctx), value); av_bprint_finalize(&buf, NULL); } diff --git a/fftools/textformat/tf_mermaid.c b/fftools/textformat/tf_mermaid.c index 3d864c2e3ec03..54e0d57bc23b8 100644 --- a/fftools/textformat/tf_mermaid.c +++ b/fftools/textformat/tf_mermaid.c @@ -169,15 +169,15 @@ static const AVOption mermaid_options[] = { DEFINE_FORMATTER_CLASS(mermaid); -void av_diagram_init(AVTextFormatContext *tfc, AVDiagramConfig *diagram_config) +void av_diagram_init(AVTextFormatContext *tctx, AVDiagramConfig *diagram_config) { - MermaidContext *mmc = tfc->priv; + MermaidContext *mmc = tctx->priv; mmc->diagram_config = diagram_config; } -static av_cold int has_link_pair(const AVTextFormatContext *tfc, const char *src, const char *dest) +static av_cold int has_link_pair(const AVTextFormatContext *tctx, const char *src, const char *dest) { - MermaidContext *mmc = tfc->priv; + MermaidContext *mmc = tctx->priv; AVBPrint buf; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); @@ -191,9 +191,9 @@ static av_cold int has_link_pair(const AVTextFormatContext *tfc, const char *src return 0; } -static av_cold int mermaid_init(AVTextFormatContext *tfc) +static av_cold int mermaid_init(AVTextFormatContext *tctx) { - MermaidContext *mmc = tfc->priv; + MermaidContext *mmc = tctx->priv; av_bprint_init(&mmc->link_buf, 0, AV_BPRINT_SIZE_UNLIMITED); @@ -201,11 +201,11 @@ static av_cold int mermaid_init(AVTextFormatContext *tfc) return 0; } -static av_cold int mermaid_init_html(AVTextFormatContext *tfc) +static av_cold int mermaid_init_html(AVTextFormatContext *tctx) { - MermaidContext *mmc = tfc->priv; + MermaidContext *mmc = tctx->priv; - int ret = mermaid_init(tfc); + int ret = mermaid_init(tctx); if (ret < 0) return ret; @@ -215,9 +215,9 @@ static av_cold int mermaid_init_html(AVTextFormatContext *tfc) return 0; } -static av_cold int mermaid_uninit(AVTextFormatContext *tfc) +static av_cold int mermaid_uninit(AVTextFormatContext *tctx) { - MermaidContext *mmc = tfc->priv; + MermaidContext *mmc = tctx->priv; av_bprint_finalize(&mmc->link_buf, NULL); av_dict_free(&mmc->link_dict); @@ -241,20 +241,20 @@ static void set_str(const char **dst, const char *src) *dst = av_strdup(src); } -#define MM_INDENT() writer_printf(tfc, "%*c", mmc->indent_level * 2, ' ') +#define MM_INDENT() writer_printf(tctx, "%*c", mmc->indent_level * 2, ' ') -static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *data) +static void mermaid_print_section_header(AVTextFormatContext *tctx, const void *data) { - const AVTextFormatSection *section = tf_get_section(tfc, tfc->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(tfc, tfc->level); + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); if (!section) return; - AVBPrint *buf = &tfc->section_pbuf[tfc->level]; - MermaidContext *mmc = tfc->priv; + AVBPrint *buf = &tctx->section_pbuf[tctx->level]; + MermaidContext *mmc = tctx->priv; const AVTextFormatSectionContext *sec_ctx = data; - if (tfc->level == 0) { + if (tctx->level == 0) { char *directive; AVBPrint css_buf; const char *diag_directive = mmc->diagram_config->diagram_type == AV_DIAGRAMTYPE_ENTITYRELATIONSHIP ? init_directive_er : init_directive; @@ -270,24 +270,24 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d uint64_t length; char *token_pos = av_stristr(mmc->diagram_config->html_template, "__###__"); if (!token_pos) { - av_log(tfc, AV_LOG_ERROR, "Unable to locate the required token (__###__) in the html template."); + av_log(tctx, AV_LOG_ERROR, "Unable to locate the required token (__###__) in the html template."); return; } length = token_pos - mmc->diagram_config->html_template; for (uint64_t i = 0; i < length; i++) - writer_w8(tfc, mmc->diagram_config->html_template[i]); + writer_w8(tctx, mmc->diagram_config->html_template[i]); } - writer_put_str(tfc, directive); + writer_put_str(tctx, directive); switch (mmc->diagram_config->diagram_type) { case AV_DIAGRAMTYPE_GRAPH: - writer_put_str(tfc, "flowchart LR\n"); - ////writer_put_str(tfc, " gradient_def@{ shape: text, label: \"\" }\n"); - writer_put_str(tfc, " gradient_def@{ shape: text, label: \"\" }\n"); + writer_put_str(tctx, "flowchart LR\n"); + ////writer_put_str(tctx, " gradient_def@{ shape: text, label: \"\" }\n"); + writer_put_str(tctx, " gradient_def@{ shape: text, label: \"\" }\n"); break; case AV_DIAGRAMTYPE_ENTITYRELATIONSHIP: - writer_put_str(tfc, "erDiagram\n"); + writer_put_str(tctx, "erDiagram\n"); break; } @@ -298,129 +298,129 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d if (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_SUBGRAPH) { - struct section_data parent_sec_data = mmc->section_data[tfc->level - 1]; - AVBPrint *parent_buf = &tfc->section_pbuf[tfc->level - 1]; + struct section_data parent_sec_data = mmc->section_data[tctx->level - 1]; + AVBPrint *parent_buf = &tctx->section_pbuf[tctx->level - 1]; if (parent_sec_data.subgraph_start_incomplete) { if (parent_buf->len > 0) - writer_printf(tfc, "%s", parent_buf->str); + writer_printf(tctx, "%s", parent_buf->str); - writer_put_str(tfc, "\"]\n"); + writer_put_str(tctx, "\"]\n"); - mmc->section_data[tfc->level - 1].subgraph_start_incomplete = 0; + mmc->section_data[tctx->level - 1].subgraph_start_incomplete = 0; } } - av_freep(&mmc->section_data[tfc->level].section_id); - av_freep(&mmc->section_data[tfc->level].section_type); - av_freep(&mmc->section_data[tfc->level].src_id); - av_freep(&mmc->section_data[tfc->level].dest_id); - mmc->section_data[tfc->level].current_is_textblock = 0; - mmc->section_data[tfc->level].current_is_stadium = 0; - mmc->section_data[tfc->level].subgraph_start_incomplete = 0; - mmc->section_data[tfc->level].link_type = AV_TEXTFORMAT_LINKTYPE_SRCDEST; + av_freep(&mmc->section_data[tctx->level].section_id); + av_freep(&mmc->section_data[tctx->level].section_type); + av_freep(&mmc->section_data[tctx->level].src_id); + av_freep(&mmc->section_data[tctx->level].dest_id); + mmc->section_data[tctx->level].current_is_textblock = 0; + mmc->section_data[tctx->level].current_is_stadium = 0; + mmc->section_data[tctx->level].subgraph_start_incomplete = 0; + mmc->section_data[tctx->level].link_type = AV_TEXTFORMAT_LINKTYPE_SRCDEST; // NOTE: av_strdup() allocations aren't checked if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_SUBGRAPH) { av_bprint_clear(buf); - writer_put_str(tfc, "\n"); + writer_put_str(tctx, "\n"); mmc->indent_level++; if (sec_ctx->context_id) { MM_INDENT(); - writer_printf(tfc, "subgraph %s[\"
", sec_ctx->context_id, section->name); + writer_printf(tctx, "subgraph %s[\"
", sec_ctx->context_id, section->name); } else { - av_log(tfc, AV_LOG_ERROR, "Unable to write subgraph start. Missing id field. Section: %s", section->name); + av_log(tctx, AV_LOG_ERROR, "Unable to write subgraph start. Missing id field. Section: %s", section->name); } - mmc->section_data[tfc->level].subgraph_start_incomplete = 1; - set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); + mmc->section_data[tctx->level].subgraph_start_incomplete = 1; + set_str(&mmc->section_data[tctx->level].section_id, sec_ctx->context_id); } if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_SHAPE) { av_bprint_clear(buf); - writer_put_str(tfc, "\n"); + writer_put_str(tctx, "\n"); mmc->indent_level++; if (sec_ctx->context_id) { - set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); + set_str(&mmc->section_data[tctx->level].section_id, sec_ctx->context_id); switch (mmc->diagram_config->diagram_type) { case AV_DIAGRAMTYPE_GRAPH: if (sec_ctx->context_flags & 1) { MM_INDENT(); - writer_printf(tfc, "%s@{ shape: text, label: \"", sec_ctx->context_id); - mmc->section_data[tfc->level].current_is_textblock = 1; + writer_printf(tctx, "%s@{ shape: text, label: \"", sec_ctx->context_id); + mmc->section_data[tctx->level].current_is_textblock = 1; } else if (sec_ctx->context_flags & 2) { MM_INDENT(); - writer_printf(tfc, "%s([\"", sec_ctx->context_id); - mmc->section_data[tfc->level].current_is_stadium = 1; + writer_printf(tctx, "%s([\"", sec_ctx->context_id); + mmc->section_data[tctx->level].current_is_stadium = 1; } else { MM_INDENT(); - writer_printf(tfc, "%s(\"", sec_ctx->context_id); + writer_printf(tctx, "%s(\"", sec_ctx->context_id); } break; case AV_DIAGRAMTYPE_ENTITYRELATIONSHIP: MM_INDENT(); - writer_printf(tfc, "%s {\n", sec_ctx->context_id); + writer_printf(tctx, "%s {\n", sec_ctx->context_id); break; } } else { - av_log(tfc, AV_LOG_ERROR, "Unable to write shape start. Missing id field. Section: %s", section->name); + av_log(tctx, AV_LOG_ERROR, "Unable to write shape start. Missing id field. Section: %s", section->name); } - set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); + set_str(&mmc->section_data[tctx->level].section_id, sec_ctx->context_id); } if (section->flags & AV_TEXTFORMAT_SECTION_PRINT_TAGS) { if (sec_ctx && sec_ctx->context_type) - writer_printf(tfc, "
", section->name, sec_ctx->context_type); + writer_printf(tctx, "
", section->name, sec_ctx->context_type); else - writer_printf(tfc, "
", section->name); + writer_printf(tctx, "
", section->name); } if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_LINKS) { av_bprint_clear(buf); - mmc->nb_link_captions[tfc->level] = 0; + mmc->nb_link_captions[tctx->level] = 0; if (sec_ctx && sec_ctx->context_type) - set_str(&mmc->section_data[tfc->level].section_type, sec_ctx->context_type); + set_str(&mmc->section_data[tctx->level].section_type, sec_ctx->context_type); ////if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) { //// AVBPrint buf; //// av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); //// av_bprint_escape(&buf, section->get_type(data), NULL, //// AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); - //// writer_printf(tfc, " type=\"%s\"", buf.str); + //// writer_printf(tctx, " type=\"%s\"", buf.str); } } -static void mermaid_print_section_footer(AVTextFormatContext *tfc) +static void mermaid_print_section_footer(AVTextFormatContext *tctx) { - MermaidContext *mmc = tfc->priv; - const AVTextFormatSection *section = tf_get_section(tfc, tfc->level); + MermaidContext *mmc = tctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); if (!section) return; - AVBPrint *buf = &tfc->section_pbuf[tfc->level]; - struct section_data sec_data = mmc->section_data[tfc->level]; + AVBPrint *buf = &tctx->section_pbuf[tctx->level]; + struct section_data sec_data = mmc->section_data[tctx->level]; if (section->flags & AV_TEXTFORMAT_SECTION_PRINT_TAGS) - writer_put_str(tfc, "
"); + writer_put_str(tctx, "
"); if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_SHAPE) { @@ -428,26 +428,26 @@ static void mermaid_print_section_footer(AVTextFormatContext *tfc) case AV_DIAGRAMTYPE_GRAPH: if (sec_data.current_is_textblock) { - writer_printf(tfc, "\"}\n", section->name); + writer_printf(tctx, "\"}\n", section->name); if (sec_data.section_id) { MM_INDENT(); - writer_put_str(tfc, "class "); - writer_put_str(tfc, sec_data.section_id); - writer_put_str(tfc, " ff-"); - writer_put_str(tfc, section->name); - writer_put_str(tfc, "\n"); + writer_put_str(tctx, "class "); + writer_put_str(tctx, sec_data.section_id); + writer_put_str(tctx, " ff-"); + writer_put_str(tctx, section->name); + writer_put_str(tctx, "\n"); } } else if (sec_data.current_is_stadium) { - writer_printf(tfc, "\"]):::ff-%s\n", section->name); + writer_printf(tctx, "\"]):::ff-%s\n", section->name); } else { - writer_printf(tfc, "\"):::ff-%s\n", section->name); + writer_printf(tctx, "\"):::ff-%s\n", section->name); } break; case AV_DIAGRAMTYPE_ENTITYRELATIONSHIP: MM_INDENT(); - writer_put_str(tfc, "}\n\n"); + writer_put_str(tctx, "}\n\n"); break; } @@ -456,15 +456,15 @@ static void mermaid_print_section_footer(AVTextFormatContext *tfc) } else if ((section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_SUBGRAPH)) { MM_INDENT(); - writer_put_str(tfc, "end\n"); + writer_put_str(tctx, "end\n"); if (sec_data.section_id) { MM_INDENT(); - writer_put_str(tfc, "class "); - writer_put_str(tfc, sec_data.section_id); - writer_put_str(tfc, " ff-"); - writer_put_str(tfc, section->name); - writer_put_str(tfc, "\n"); + writer_put_str(tctx, "class "); + writer_put_str(tctx, sec_data.section_id); + writer_put_str(tctx, " ff-"); + writer_put_str(tctx, section->name); + writer_put_str(tctx, "\n"); } mmc->indent_level--; @@ -472,7 +472,7 @@ static void mermaid_print_section_footer(AVTextFormatContext *tfc) if ((section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_LINKS)) if (sec_data.src_id && sec_data.dest_id - && !has_link_pair(tfc, sec_data.src_id, sec_data.dest_id)) + && !has_link_pair(tctx, sec_data.src_id, sec_data.dest_id)) switch (mmc->diagram_config->diagram_type) { case AV_DIAGRAMTYPE_GRAPH: @@ -484,7 +484,7 @@ static void mermaid_print_section_footer(AVTextFormatContext *tfc) if (buf->len > 0) { av_bprintf(&mmc->link_buf, " \"%s", buf->str); - for (unsigned i = 0; i < mmc->nb_link_captions[tfc->level]; i++) + for (unsigned i = 0; i < mmc->nb_link_captions[tctx->level]; i++) av_bprintf(&mmc->link_buf, "
 "); av_bprintf(&mmc->link_buf, "\" =="); @@ -521,61 +521,61 @@ static void mermaid_print_section_footer(AVTextFormatContext *tfc) break; } - if (tfc->level == 0) { + if (tctx->level == 0) { - writer_put_str(tfc, "\n"); + writer_put_str(tctx, "\n"); if (mmc->create_html) { char *token_pos = av_stristr(mmc->diagram_config->html_template, "__###__"); if (!token_pos) { - av_log(tfc, AV_LOG_ERROR, "Unable to locate the required token (__###__) in the html template."); + av_log(tctx, AV_LOG_ERROR, "Unable to locate the required token (__###__) in the html template."); return; } token_pos += strlen("__###__"); - writer_put_str(tfc, token_pos); + writer_put_str(tctx, token_pos); } } - if (tfc->level == 1) { + if (tctx->level == 1) { if (mmc->link_buf.len > 0) { - writer_put_str(tfc, mmc->link_buf.str); + writer_put_str(tctx, mmc->link_buf.str); av_bprint_clear(&mmc->link_buf); } - writer_put_str(tfc, "\n"); + writer_put_str(tctx, "\n"); } } -static void mermaid_print_value(AVTextFormatContext *tfc, const char *key, +static void mermaid_print_value(AVTextFormatContext *tctx, const char *key, const char *str, int64_t num, const int is_int) { - MermaidContext *mmc = tfc->priv; - const AVTextFormatSection *section = tf_get_section(tfc, tfc->level); + MermaidContext *mmc = tctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); if (!section) return; - AVBPrint *buf = &tfc->section_pbuf[tfc->level]; - struct section_data sec_data = mmc->section_data[tfc->level]; + AVBPrint *buf = &tctx->section_pbuf[tctx->level]; + struct section_data sec_data = mmc->section_data[tctx->level]; int exit = 0; if (section->id_key && !strcmp(section->id_key, key)) { - set_str(&mmc->section_data[tfc->level].section_id, str); + set_str(&mmc->section_data[tctx->level].section_id, str); exit = 1; } if (section->dest_id_key && !strcmp(section->dest_id_key, key)) { - set_str(&mmc->section_data[tfc->level].dest_id, str); + set_str(&mmc->section_data[tctx->level].dest_id, str); exit = 1; } if (section->src_id_key && !strcmp(section->src_id_key, key)) { - set_str(&mmc->section_data[tfc->level].src_id, str); + set_str(&mmc->section_data[tctx->level].src_id, str); exit = 1; } if (section->linktype_key && !strcmp(section->linktype_key, key)) { - mmc->section_data[tfc->level].link_type = (AVTextFormatLinkType)num; + mmc->section_data[tctx->level].link_type = (AVTextFormatLinkType)num; exit = 1; } @@ -588,10 +588,10 @@ static void mermaid_print_value(AVTextFormatContext *tfc, const char *key, case AV_DIAGRAMTYPE_GRAPH: if (is_int) { - writer_printf(tfc, "%s: %"PRId64"", key, key, num); + writer_printf(tctx, "%s: %"PRId64"", key, key, num); } else { const char *tmp = av_strireplace(str, "\"", "'"); - writer_printf(tfc, "%s", key, tmp); + writer_printf(tctx, "%s", key, tmp); av_freep(&tmp); } @@ -617,9 +617,9 @@ static void mermaid_print_value(AVTextFormatContext *tfc, const char *key, MM_INDENT(); if (is_int) - writer_printf(tfc, " %s %"PRId64" %s\n", key, num, col_type); + writer_printf(tctx, " %s %"PRId64" %s\n", key, num, col_type); else - writer_printf(tfc, " %s %s %s\n", key, str, col_type); + writer_printf(tctx, " %s %s %s\n", key, str, col_type); } break; } @@ -634,18 +634,18 @@ static void mermaid_print_value(AVTextFormatContext *tfc, const char *key, else av_bprintf(buf, "%s", str); - mmc->nb_link_captions[tfc->level]++; + mmc->nb_link_captions[tctx->level]++; } } -static inline void mermaid_print_str(AVTextFormatContext *tfc, const char *key, const char *value) +static inline void mermaid_print_str(AVTextFormatContext *tctx, const char *key, const char *value) { - mermaid_print_value(tfc, key, value, 0, 0); + mermaid_print_value(tctx, key, value, 0, 0); } -static void mermaid_print_int(AVTextFormatContext *tfc, const char *key, int64_t value) +static void mermaid_print_int(AVTextFormatContext *tctx, const char *key, int64_t value) { - mermaid_print_value(tfc, key, NULL, value, 1); + mermaid_print_value(tctx, key, NULL, value, 1); } const AVTextFormatter avtextformatter_mermaid = { diff --git a/fftools/textformat/tf_mermaid.h b/fftools/textformat/tf_mermaid.h index 6e8f2a9b42195..17227e81af4c4 100644 --- a/fftools/textformat/tf_mermaid.h +++ b/fftools/textformat/tf_mermaid.h @@ -33,7 +33,7 @@ typedef struct AVDiagramConfig { } AVDiagramConfig; -void av_diagram_init(AVTextFormatContext *tfc, AVDiagramConfig *diagram_config); +void av_diagram_init(AVTextFormatContext *tctx, AVDiagramConfig *diagram_config); void av_mermaid_set_html_template(AVTextFormatContext *tfc, const char *html_template); diff --git a/fftools/textformat/tf_xml.c b/fftools/textformat/tf_xml.c index 6b09e09ab4e01..549a57e095c17 100644 --- a/fftools/textformat/tf_xml.c +++ b/fftools/textformat/tf_xml.c @@ -50,45 +50,45 @@ static const AVOption xml_options[] = { DEFINE_FORMATTER_CLASS(xml); -static av_cold int xml_init(AVTextFormatContext *wctx) +static av_cold int xml_init(AVTextFormatContext *tctx) { - XMLContext *xml = wctx->priv; + XMLContext *xml = tctx->priv; if (xml->xsd_strict) { xml->fully_qualified = 1; #define CHECK_COMPLIANCE(opt, opt_name) \ if (opt) { \ - av_log(wctx, AV_LOG_ERROR, \ + av_log(tctx, AV_LOG_ERROR, \ "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \ "You need to disable such option with '-no%s'\n", opt_name, opt_name); \ return AVERROR(EINVAL); \ } ////CHECK_COMPLIANCE(show_private_data, "private"); - CHECK_COMPLIANCE(wctx->show_value_unit, "unit"); - CHECK_COMPLIANCE(wctx->use_value_prefix, "prefix"); + CHECK_COMPLIANCE(tctx->show_value_unit, "unit"); + CHECK_COMPLIANCE(tctx->use_value_prefix, "prefix"); } return 0; } -#define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ') +#define XML_INDENT() writer_printf(tctx, "%*c", xml->indent_level * 4, ' ') -static void xml_print_section_header(AVTextFormatContext *wctx, const void *data) +static void xml_print_section_header(AVTextFormatContext *tctx, const void *data) { - XMLContext *xml = wctx->priv; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); - const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + XMLContext *xml = tctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(tctx, tctx->level); if (!section) return; - if (wctx->level == 0) { + if (tctx->level == 0) { const char *qual = " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" " "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\""; - writer_put_str(wctx, "\n"); - writer_printf(wctx, "<%sffprobe%s>\n", + writer_put_str(tctx, "\n"); + writer_printf(tctx, "<%sffprobe%s>\n", xml->fully_qualified ? "ffprobe:" : "", xml->fully_qualified ? qual : ""); return; @@ -96,60 +96,60 @@ static void xml_print_section_header(AVTextFormatContext *wctx, const void *data if (xml->within_tag) { xml->within_tag = 0; - writer_put_str(wctx, ">\n"); + writer_put_str(tctx, ">\n"); } if (parent_section && (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER) && - wctx->level && wctx->nb_item[wctx->level - 1]) - writer_w8(wctx, '\n'); + tctx->level && tctx->nb_item[tctx->level - 1]) + writer_w8(tctx, '\n'); xml->indent_level++; if (section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS)) { XML_INDENT(); - writer_printf(wctx, "<%s", section->name); + writer_printf(tctx, "<%s", section->name); if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) { AVBPrint buf; av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); av_bprint_escape(&buf, section->get_type(data), NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); - writer_printf(wctx, " type=\"%s\"", buf.str); + writer_printf(tctx, " type=\"%s\"", buf.str); } - writer_printf(wctx, ">\n", section->name); + writer_printf(tctx, ">\n", section->name); } else { XML_INDENT(); - writer_printf(wctx, "<%s ", section->name); + writer_printf(tctx, "<%s ", section->name); xml->within_tag = 1; } } -static void xml_print_section_footer(AVTextFormatContext *wctx) +static void xml_print_section_footer(AVTextFormatContext *tctx) { - XMLContext *xml = wctx->priv; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + XMLContext *xml = tctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); if (!section) return; - if (wctx->level == 0) { - writer_printf(wctx, "\n", xml->fully_qualified ? "ffprobe:" : ""); + if (tctx->level == 0) { + writer_printf(tctx, "\n", xml->fully_qualified ? "ffprobe:" : ""); } else if (xml->within_tag) { xml->within_tag = 0; - writer_put_str(wctx, "/>\n"); + writer_put_str(tctx, "/>\n"); xml->indent_level--; } else { XML_INDENT(); - writer_printf(wctx, "\n", section->name); + writer_printf(tctx, "\n", section->name); xml->indent_level--; } } -static void xml_print_value(AVTextFormatContext *wctx, const char *key, +static void xml_print_value(AVTextFormatContext *tctx, const char *key, const char *str, int64_t num, const int is_int) { AVBPrint buf; - XMLContext *xml = wctx->priv; - const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + XMLContext *xml = tctx->priv; + const AVTextFormatSection *section = tf_get_section(tctx, tctx->level); if (!section) return; @@ -161,42 +161,42 @@ static void xml_print_value(AVTextFormatContext *wctx, const char *key, XML_INDENT(); av_bprint_escape(&buf, key, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); - writer_printf(wctx, "<%s key=\"%s\"", + writer_printf(tctx, "<%s key=\"%s\"", section->element_name, buf.str); av_bprint_clear(&buf); if (is_int) { - writer_printf(wctx, " value=\"%"PRId64"\"/>\n", num); + writer_printf(tctx, " value=\"%"PRId64"\"/>\n", num); } else { av_bprint_escape(&buf, str, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); - writer_printf(wctx, " value=\"%s\"/>\n", buf.str); + writer_printf(tctx, " value=\"%s\"/>\n", buf.str); } xml->indent_level--; } else { - if (wctx->nb_item[wctx->level]) - writer_w8(wctx, ' '); + if (tctx->nb_item[tctx->level]) + writer_w8(tctx, ' '); if (is_int) { - writer_printf(wctx, "%s=\"%"PRId64"\"", key, num); + writer_printf(tctx, "%s=\"%"PRId64"\"", key, num); } else { av_bprint_escape(&buf, str, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); - writer_printf(wctx, "%s=\"%s\"", key, buf.str); + writer_printf(tctx, "%s=\"%s\"", key, buf.str); } } av_bprint_finalize(&buf, NULL); } -static inline void xml_print_str(AVTextFormatContext *wctx, const char *key, const char *value) +static inline void xml_print_str(AVTextFormatContext *tctx, const char *key, const char *value) { - xml_print_value(wctx, key, value, 0, 0); + xml_print_value(tctx, key, value, 0, 0); } -static void xml_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) +static void xml_print_int(AVTextFormatContext *tctx, const char *key, int64_t value) { - xml_print_value(wctx, key, NULL, value, 1); + xml_print_value(tctx, key, NULL, value, 1); } const AVTextFormatter avtextformatter_xml = { From 41fce033704ba2ac262aeebfd6b63edfb01efa3f Mon Sep 17 00:00:00 2001 From: softworkz Date: Thu, 3 Jul 2025 05:49:14 +0200 Subject: [PATCH 2/3] fftools/textformat: Remove redundant casts Signed-off-by: softworkz --- fftools/graph/graphprint.c | 14 +++++++------- fftools/resources/resman.c | 6 +++--- fftools/textformat/avtextformat.c | 8 ++++---- fftools/textformat/tf_compact.c | 2 +- fftools/textformat/tf_default.c | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/fftools/graph/graphprint.c b/fftools/graph/graphprint.c index 242eaf8ba17ce..f940d1d789f9f 100644 --- a/fftools/graph/graphprint.c +++ b/fftools/graph/graphprint.c @@ -161,7 +161,7 @@ static inline char *upcase_string(char *dst, size_t dst_size, const char *src) { unsigned i; for (i = 0; src[i] && i < dst_size - 1; i++) - dst[i] = (char)av_toupper(src[i]); + dst[i] = av_toupper(src[i]); dst[i] = 0; return dst; } @@ -261,7 +261,7 @@ static void print_link(GraphPrintContext *gpc, AVFilterLink *link) case AVMEDIA_TYPE_VIDEO: if (hw_frames_ctx && hw_frames_ctx->data) { - AVHWFramesContext * hwfctx = (AVHWFramesContext *)hw_frames_ctx->data; + AVHWFramesContext *hwfctx = (AVHWFramesContext *)hw_frames_ctx->data; const AVPixFmtDescriptor *pix_desc_hw = av_pix_fmt_desc_get(hwfctx->format); const AVPixFmtDescriptor *pix_desc_sw = av_pix_fmt_desc_get(hwfctx->sw_format); if (pix_desc_hw && pix_desc_sw) @@ -498,7 +498,7 @@ static void print_filtergraph_single(GraphPrintContext *gpc, FilterGraph *fg, AV print_int("input_index", ifilter->index); if (ifilter->linklabel) - print_str("link_label", (const char*)ifilter->linklabel); + print_str("link_label", ifilter->linklabel); if (ifilter->filter) { print_id("filter_id", ifilter->filter->name); @@ -506,9 +506,9 @@ static void print_filtergraph_single(GraphPrintContext *gpc, FilterGraph *fg, AV } if (ifilter->linklabel && ifilter->filter) - av_dict_set(&input_map, ifilter->filter->name, (const char *)ifilter->linklabel, 0); + av_dict_set(&input_map, ifilter->filter->name, ifilter->linklabel, 0); else if (ifilter->input_name && ifilter->filter) - av_dict_set(&input_map, ifilter->filter->name, (const char *)ifilter->input_name, 0); + av_dict_set(&input_map, ifilter->filter->name, ifilter->input_name, 0); print_str("media_type", av_get_media_type_string(media_type)); @@ -529,7 +529,7 @@ static void print_filtergraph_single(GraphPrintContext *gpc, FilterGraph *fg, AV print_str("name", ofilter->output_name); if (fg->outputs[i]->linklabel) - print_str("link_label", (const char*)fg->outputs[i]->linklabel); + print_str("link_label", fg->outputs[i]->linklabel); if (ofilter->filter) { print_id("filter_id", ofilter->filter->name); @@ -1069,7 +1069,7 @@ static int print_filtergraphs_priv(FilterGraph **graphs, int nb_graphs, InputFil goto cleanup; } - avio_write(avio, (const unsigned char *)target_buf.str, FFMIN(target_buf.len, target_buf.size - 1)); + avio_write(avio, target_buf.str, FFMIN(target_buf.len, target_buf.size - 1)); if ((ret = avio_closep(&avio)) < 0) av_log(NULL, AV_LOG_ERROR, "Error closing graph output file, loss of information possible: %s\n", av_err2str(ret)); diff --git a/fftools/resources/resman.c b/fftools/resources/resman.c index aa53e96bf4cc6..4c517b62c0a1c 100644 --- a/fftools/resources/resman.c +++ b/fftools/resources/resman.c @@ -76,7 +76,7 @@ static int decompress_gzip(ResourceManagerContext *ctx, uint8_t *in, unsigned in memset(&strm, 0, sizeof(strm)); // Allocate output buffer with extra byte for null termination - buf = (uint8_t *)av_mallocz(chunk + 1); + buf = av_mallocz(chunk + 1); if (!buf) { av_log(ctx, AV_LOG_ERROR, "Failed to allocate decompression buffer\n"); return AVERROR(ENOMEM); @@ -112,7 +112,7 @@ static int decompress_gzip(ResourceManagerContext *ctx, uint8_t *in, unsigned in buf[*out_len] = 0; // Ensure null termination inflateEnd(&strm); - *out = (char *)buf; + *out = buf; return Z_OK; } #endif @@ -156,7 +156,7 @@ char *ff_resman_get_string(FFResourceId resource_id) char *out = NULL; size_t out_len; - int ret = decompress_gzip(ctx, (uint8_t *)resource_definition.data, *resource_definition.data_len, &out, &out_len); + int ret = decompress_gzip(ctx, resource_definition.data, *resource_definition.data_len, &out, &out_len); if (ret) { av_log(ctx, AV_LOG_ERROR, "Unable to decompress the resource with ID %d\n", resource_id); diff --git a/fftools/textformat/avtextformat.c b/fftools/textformat/avtextformat.c index 651a84578cc78..39ab4cecb7081 100644 --- a/fftools/textformat/avtextformat.c +++ b/fftools/textformat/avtextformat.c @@ -209,8 +209,8 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form /* validate replace string */ { - const uint8_t *p = (uint8_t *)tctx->string_validation_replacement; - const uint8_t *endp = p + strlen((const char *)p); + const uint8_t *p = tctx->string_validation_replacement; + const uint8_t *endp = p + strlen(p); while (*p) { const uint8_t *p0 = p; int32_t code; @@ -313,7 +313,7 @@ void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t va static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src) { - const uint8_t *p, *endp, *srcp = (const uint8_t *)src; + const uint8_t *p, *endp, *srcp = src; AVBPrint dstbuf; AVBPrint invalid_seq; int invalid_chars_nb = 0, ret = 0; @@ -557,7 +557,7 @@ void avtext_print_data_hash(AVTextFormatContext *tctx, const char *key, av_hash_init(tctx->hash); av_hash_update(tctx->hash, data, size); len = snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash)); - av_hash_final_hex(tctx->hash, (uint8_t *)&buf[len], (int)sizeof(buf) - len); + av_hash_final_hex(tctx->hash, &buf[len], (int)sizeof(buf) - len); avtext_print_string(tctx, key, buf, 0); } diff --git a/fftools/textformat/tf_compact.c b/fftools/textformat/tf_compact.c index 62717bba0a5e6..3f38f24f945fb 100644 --- a/fftools/textformat/tf_compact.c +++ b/fftools/textformat/tf_compact.c @@ -158,7 +158,7 @@ static void compact_print_section_header(AVTextFormatContext *tctx, const void * /* define a prefix for elements not contained in an array or in a wrapper, or for array elements with a type */ - const char *element_name = (char *)av_x_if_null(section->element_name, section->name); + const char *element_name = av_x_if_null(section->element_name, section->name); AVBPrint *section_pbuf = &tctx->section_pbuf[tctx->level]; compact->nested_section[tctx->level] = 1; diff --git a/fftools/textformat/tf_default.c b/fftools/textformat/tf_default.c index 2c91a8dec4751..ee0c4137e0615 100644 --- a/fftools/textformat/tf_default.c +++ b/fftools/textformat/tf_default.c @@ -57,7 +57,7 @@ static inline char *upcase_string(char *dst, size_t dst_size, const char *src) unsigned i; for (i = 0; src[i] && i < dst_size - 1; i++) - dst[i] = (char)av_toupper(src[i]); + dst[i] = av_toupper(src[i]); dst[i] = 0; return dst; } From 3fa8bff93bd671ba334b0def55d6ce3a9fab06f7 Mon Sep 17 00:00:00 2001 From: softworkz Date: Sat, 3 May 2025 10:18:27 +0200 Subject: [PATCH 3/3] fftools/textformat: Cleanup unneeded includes Signed-off-by: softworkz --- fftools/textformat/avtextformat.c | 2 -- fftools/textformat/avtextwriters.h | 1 - fftools/textformat/tf_compact.c | 2 -- fftools/textformat/tf_mermaid.c | 2 -- fftools/textformat/tw_avio.c | 3 --- fftools/textformat/tw_buffer.c | 3 --- fftools/textformat/tw_stdout.c | 3 --- 7 files changed, 16 deletions(-) diff --git a/fftools/textformat/avtextformat.c b/fftools/textformat/avtextformat.c index 39ab4cecb7081..ca26139b46b31 100644 --- a/fftools/textformat/avtextformat.c +++ b/fftools/textformat/avtextformat.c @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include #include #include #include diff --git a/fftools/textformat/avtextwriters.h b/fftools/textformat/avtextwriters.h index 8457d7a6ea54c..614f352db8c44 100644 --- a/fftools/textformat/avtextwriters.h +++ b/fftools/textformat/avtextwriters.h @@ -21,7 +21,6 @@ #ifndef FFTOOLS_TEXTFORMAT_AVTEXTWRITERS_H #define FFTOOLS_TEXTFORMAT_AVTEXTWRITERS_H -#include #include "libavformat/avio.h" #include "libavutil/bprint.h" diff --git a/fftools/textformat/tf_compact.c b/fftools/textformat/tf_compact.c index 3f38f24f945fb..b28d4336187ae 100644 --- a/fftools/textformat/tf_compact.c +++ b/fftools/textformat/tf_compact.c @@ -18,10 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include -#include #include #include "avtextformat.h" diff --git a/fftools/textformat/tf_mermaid.c b/fftools/textformat/tf_mermaid.c index 54e0d57bc23b8..faee0e5e9c8f3 100644 --- a/fftools/textformat/tf_mermaid.c +++ b/fftools/textformat/tf_mermaid.c @@ -18,10 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include -#include #include #include "avtextformat.h" diff --git a/fftools/textformat/tw_avio.c b/fftools/textformat/tw_avio.c index 21d3af27df1a9..25468478fa354 100644 --- a/fftools/textformat/tw_avio.c +++ b/fftools/textformat/tw_avio.c @@ -18,13 +18,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include #include #include "avtextwriters.h" #include "libavutil/avassert.h" - #include "libavutil/error.h" /* AVIO Writer */ diff --git a/fftools/textformat/tw_buffer.c b/fftools/textformat/tw_buffer.c index f6e63445d9cba..0437cb61ca185 100644 --- a/fftools/textformat/tw_buffer.c +++ b/fftools/textformat/tw_buffer.c @@ -18,9 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include - #include "avtextwriters.h" #include "libavutil/opt.h" #include "libavutil/bprint.h" diff --git a/fftools/textformat/tw_stdout.c b/fftools/textformat/tw_stdout.c index 3e2a8dd0d4631..66e462c3a2b7e 100644 --- a/fftools/textformat/tw_stdout.c +++ b/fftools/textformat/tw_stdout.c @@ -18,10 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include -#include - #include "avtextwriters.h" #include "libavutil/opt.h"