1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

fftools/textformat: Apply formatting and whitespace changes

Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: softworkz <softworkz@hotmail.com>
This commit is contained in:
softworkz
2025-04-14 05:28:45 +02:00
parent f51c385a8e
commit 8f42d90413
9 changed files with 172 additions and 156 deletions

View File

@ -34,9 +34,9 @@
#include "libavutil/opt.h"
#include "avtextformat.h"
#define SECTION_ID_NONE -1
#define SECTION_ID_NONE (-1)
#define SHOW_OPTIONAL_FIELDS_AUTO -1
#define SHOW_OPTIONAL_FIELDS_AUTO (-1)
#define SHOW_OPTIONAL_FIELDS_NEVER 0
#define SHOW_OPTIONAL_FIELDS_ALWAYS 1
@ -64,14 +64,14 @@ static const char *textcontext_get_formatter_name(void *p)
static const AVOption textcontext_options[] = {
{ "string_validation", "set string validation mode",
OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=AV_TEXTFORMAT_STRING_VALIDATION_REPLACE}, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB-1, .unit = "sv" },
OFFSET(string_validation), AV_OPT_TYPE_INT, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB - 1, .unit = "sv" },
{ "sv", "set string validation mode",
OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=AV_TEXTFORMAT_STRING_VALIDATION_REPLACE}, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB-1, .unit = "sv" },
{ "ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_IGNORE}, .unit = "sv" },
{ "replace", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE}, .unit = "sv" },
{ "fail", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_FAIL}, .unit = "sv" },
{ "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=""}},
{ "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str="\xEF\xBF\xBD"}},
OFFSET(string_validation), AV_OPT_TYPE_INT, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB - 1, .unit = "sv" },
{ "ignore", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_IGNORE }, .unit = "sv" },
{ "replace", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, .unit = "sv" },
{ "fail", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_FAIL }, .unit = "sv" },
{ "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, { .str = "" } },
{ "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, { .str = "\xEF\xBF\xBD" } },
{ NULL }
};
@ -126,7 +126,7 @@ void avtext_context_close(AVTextFormatContext **ptctx)
int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
const struct AVTextFormatSection *sections, int nb_sections,
const AVTextFormatSection *sections, int nb_sections,
int show_value_unit,
int use_value_prefix,
int use_byte_value_binary_prefix,
@ -209,7 +209,7 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form
av_log(NULL, AV_LOG_ERROR, " %s", n);
av_log(NULL, AV_LOG_ERROR, "\n");
}
return ret;
goto fail;
}
}
@ -224,7 +224,7 @@ int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *form
if (ret < 0) {
AVBPrint bp;
av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
bprint_bytes(&bp, p0, p-p0),
bprint_bytes(&bp, p0, p - p0);
av_log(tctx, AV_LOG_ERROR,
"Invalid UTF8 sequence %s found in string validation replace '%s'\n",
bp.str, tctx->string_validation_replacement);
@ -248,15 +248,13 @@ fail:
}
/* Temporary definitions during refactoring */
static const char unit_second_str[] = "s" ;
static const char unit_hertz_str[] = "Hz" ;
static const char unit_byte_str[] = "byte" ;
static const char unit_second_str[] = "s";
static const char unit_hertz_str[] = "Hz";
static const char unit_byte_str[] = "byte";
static const char unit_bit_per_second_str[] = "bit/s";
void avtext_print_section_header(AVTextFormatContext *tctx,
const void *data,
int section_id)
void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
{
tctx->level++;
av_assert0(tctx->level < SECTION_MAX_NB_LEVELS);
@ -273,7 +271,7 @@ void avtext_print_section_footer(AVTextFormatContext *tctx)
{
int section_id = tctx->section[tctx->level]->id;
int parent_section_id = tctx->level ?
tctx->section[tctx->level-1]->id : SECTION_ID_NONE;
tctx->section[tctx->level - 1]->id : SECTION_ID_NONE;
if (parent_section_id != SECTION_ID_NONE) {
tctx->nb_item[tctx->level - 1]++;
@ -285,8 +283,7 @@ void avtext_print_section_footer(AVTextFormatContext *tctx)
tctx->level--;
}
void avtext_print_integer(AVTextFormatContext *tctx,
const char *key, int64_t val)
void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val)
{
const struct AVTextFormatSection *section = tctx->section[tctx->level];
@ -324,11 +321,9 @@ static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const
switch (tctx->string_validation) {
case AV_TEXTFORMAT_STRING_VALIDATION_FAIL:
av_log(tctx, AV_LOG_ERROR,
"Invalid UTF-8 sequence found in string '%s'\n", src);
av_log(tctx, AV_LOG_ERROR, "Invalid UTF-8 sequence found in string '%s'\n", src);
ret = AVERROR_INVALIDDATA;
goto end;
break;
case AV_TEXTFORMAT_STRING_VALIDATION_REPLACE:
av_bprintf(&dstbuf, "%s", tctx->string_validation_replacement);
@ -340,11 +335,10 @@ static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const
av_bprint_append_data(&dstbuf, p0, p-p0);
}
if (invalid_chars_nb && tctx->string_validation == AV_TEXTFORMAT_STRING_VALIDATION_REPLACE) {
if (invalid_chars_nb && tctx->string_validation == AV_TEXTFORMAT_STRING_VALIDATION_REPLACE)
av_log(tctx, AV_LOG_WARNING,
"%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
invalid_chars_nb, src, tctx->string_validation_replacement);
}
end:
av_bprint_finalize(&dstbuf, dstp);
@ -352,7 +346,11 @@ end:
}
struct unit_value {
union { double d; int64_t i; } val;
union {
double d;
int64_t i;
} val;
const char *unit;
};
@ -402,6 +400,7 @@ static char *value_string(AVTextFormatContext *tctx, char *buf, int buf_size, st
snprintf(buf, buf_size, "%f", vald);
else
snprintf(buf, buf_size, "%"PRId64, vali);
av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || tctx->show_value_unit ? " " : "",
prefix_string, tctx->show_value_unit ? uv.unit : "");
}
@ -440,11 +439,10 @@ int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *
if (ret < 0) goto end;
tctx->formatter->print_string(tctx, key1, val1);
end:
if (ret < 0) {
if (ret < 0)
av_log(tctx, AV_LOG_ERROR,
"Invalid key=value string combination %s=%s in section %s\n",
key, val, section->unique_name);
}
av_free(key1);
av_free(val1);
} else {
@ -457,8 +455,7 @@ int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *
return ret;
}
void avtext_print_rational(AVTextFormatContext *tctx,
const char *key, AVRational q, char sep)
void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep)
{
char buf[44];
snprintf(buf, sizeof(buf), "%d%c%d", q.num, sep, q.den);
@ -484,11 +481,10 @@ void avtext_print_time(AVTextFormatContext *tctx, const char *key,
void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration)
{
if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0))
avtext_print_string(tctx, key, "N/A", AV_TEXTFORMAT_PRINT_STRING_OPTIONAL);
} else {
else
avtext_print_integer(tctx, key, ts);
}
}
void avtext_print_data(AVTextFormatContext *tctx, const char *name,
@ -526,6 +522,7 @@ void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name,
if (!tctx->hash)
return;
av_hash_init(tctx->hash);
av_hash_update(tctx->hash, data, size);
snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash));
@ -551,7 +548,7 @@ void avtext_print_integers(AVTextFormatContext *tctx, const char *name,
else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
data += bytes;
size --;
size--;
}
av_bprintf(&bp, "\n");
offset += offset_add;
@ -641,7 +638,8 @@ fail:
return ret;
}
static const AVTextFormatter *registered_formatters[7+1];
static const AVTextFormatter *registered_formatters[7 + 1];
static void formatters_register_all(void)
{
static int initialized;

View File

@ -46,11 +46,11 @@ typedef struct AVTextFormatSection {
#define AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE 16 ///< the items in this array section should be numbered individually by type
int flags;
const int children_ids[SECTION_MAX_NB_CHILDREN+1]; ///< list of children section IDS, terminated by -1
const int children_ids[SECTION_MAX_NB_CHILDREN + 1]; ///< list of children section IDS, terminated by -1
const char *element_name; ///< name of the contained element, if provided
const char *unique_name; ///< unique section name, in case the name is ambiguous
AVDictionary *entries_to_show;
const char *(* get_type)(const void *data); ///< function returning a type if defined, must be defined when SECTION_FLAG_HAS_TYPE is defined
const char *(*get_type)(const void *data); ///< function returning a type if defined, must be defined when SECTION_FLAG_HAS_TYPE is defined
int show_all_entries;
} AVTextFormatSection;
@ -93,7 +93,7 @@ struct AVTextFormatContext {
char *name; ///< name of this formatter instance
void *priv; ///< private data for use by the filter
const struct AVTextFormatSection *sections; ///< array containing all sections
const AVTextFormatSection *sections; ///< array containing all sections
int nb_sections; ///< number of sections
int level; ///< current level, starting from 0

View File

@ -37,11 +37,11 @@ typedef struct AVTextWriter {
int priv_size; ///< private size for the writer private class
const char *name;
int (* init)(AVTextWriterContext *wctx);
void (* uninit)(AVTextWriterContext *wctx);
void (* writer_w8)(AVTextWriterContext *wctx, int b);
void (* writer_put_str)(AVTextWriterContext *wctx, const char *str);
void (* writer_printf)(AVTextWriterContext *wctx, const char *fmt, ...);
int (*init)(AVTextWriterContext *wctx);
void (*uninit)(AVTextWriterContext *wctx);
void (*writer_w8)(AVTextWriterContext *wctx, int b);
void (*writer_put_str)(AVTextWriterContext *wctx, const char *str);
void (*writer_printf)(AVTextWriterContext *wctx, const char *fmt, ...);
} AVTextWriter;
typedef struct AVTextWriterContext {
@ -49,7 +49,6 @@ typedef struct AVTextWriterContext {
const AVTextWriter *writer;
const char *name;
void *priv; ///< private data for use by the writer
} AVTextWriterContext;

View File

@ -78,6 +78,7 @@ static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep,
static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
{
char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
int needs_quoting = !!src[strcspn(src, meta_chars)];
if (needs_quoting)
@ -114,16 +115,16 @@ typedef struct CompactContext {
#undef OFFSET
#define OFFSET(x) offsetof(CompactContext, x)
static const AVOption compact_options[]= {
{"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 },
{"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 },
{"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 },
{"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 },
{"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{NULL},
static const AVOption compact_options[] = {
{ "item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, { .str = "|" }, 0, 0 },
{ "s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, { .str = "|" }, 0, 0 },
{ "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, { .str = "c" }, 0, 0 },
{ "e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, { .str = "c" }, 0, 0 },
{ "print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ "p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ NULL },
};
DEFINE_FORMATTER_CLASS(compact);
@ -139,10 +140,13 @@ static av_cold int compact_init(AVTextFormatContext *wctx)
}
compact->item_sep = compact->item_sep_str[0];
if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str;
else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str;
else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str;
else {
if (!strcmp(compact->escape_mode_str, "none")) {
compact->escape_str = none_escape_str;
} else if (!strcmp(compact->escape_mode_str, "c" )) {
compact->escape_str = c_escape_str;
} 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);
return AVERROR(EINVAL);
}
@ -163,7 +167,7 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void *
if (parent_section &&
(section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE ||
(!(section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) &&
!(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))))) {
!(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))))) {
/* define a prefix for elements not contained in an array or
in a wrapper, or for array elements with a type */
@ -171,10 +175,10 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void *
AVBPrint *section_pbuf = &wctx->section_pbuf[wctx->level];
compact->nested_section[wctx->level] = 1;
compact->has_nested_elems[wctx->level-1] = 1;
compact->has_nested_elems[wctx->level - 1] = 1;
av_bprintf(section_pbuf, "%s%s",
wctx->section_pbuf[wctx->level-1].str, element_name);
wctx->section_pbuf[wctx->level - 1].str, element_name);
if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) {
// add /TYPE to prefix
@ -191,24 +195,25 @@ 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];
wctx->nb_item[wctx->level] = wctx->nb_item[wctx->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])
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);
if (compact->print_section &&
!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
writer_printf(wctx, "%s%c", section->name, compact->item_sep);
}
}
static void compact_print_section_footer(AVTextFormatContext *wctx)
{
const struct AVTextFormatSection *section = wctx->section[wctx->level];
CompactContext *compact = wctx->priv;
if (!compact->nested_section[wctx->level] &&
compact->terminate_line[wctx->level] &&
!(wctx->section[wctx->level]->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
writer_w8(wctx, '\n');
}
@ -217,9 +222,12 @@ static void compact_print_str(AVTextFormatContext *wctx, const char *key, const
CompactContext *compact = wctx->priv;
AVBPrint buf;
if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep);
if (wctx->nb_item[wctx->level])
writer_w8(wctx, compact->item_sep);
if (!compact->nokey)
writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->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));
av_bprint_finalize(&buf, NULL);
@ -229,9 +237,12 @@ static void compact_print_int(AVTextFormatContext *wctx, const char *key, int64_
{
CompactContext *compact = wctx->priv;
if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep);
if (wctx->nb_item[wctx->level])
writer_w8(wctx, compact->item_sep);
if (!compact->nokey)
writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
writer_printf(wctx, "%"PRId64, value);
}
@ -253,15 +264,15 @@ const AVTextFormatter avtextformatter_compact = {
#define OFFSET(x) offsetof(CompactContext, x)
static const AVOption csv_options[] = {
{"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 },
{"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 },
{"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 },
{"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 },
{"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{NULL},
{ "item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, { .str = "," }, 0, 0 },
{ "s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, { .str = "," }, 0, 0 },
{ "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ "escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, { .str = "csv" }, 0, 0 },
{ "e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, { .str = "csv" }, 0, 0 },
{ "print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ "p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ NULL },
};
DEFINE_FORMATTER_CLASS(csv);

View File

@ -56,11 +56,11 @@ typedef struct DefaultContext {
#define OFFSET(x) offsetof(DefaultContext, x)
static const AVOption default_options[] = {
{ "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{ "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{ "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{ "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{NULL},
{ "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ NULL },
};
DEFINE_FORMATTER_CLASS(default);
@ -69,7 +69,7 @@ DEFINE_FORMATTER_CLASS(default);
static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
{
int i;
for (i = 0; src[i] && i < dst_size-1; i++)
for (i = 0; src[i] && i < dst_size - 1; i++)
dst[i] = av_toupper(src[i]);
dst[i] = 0;
return dst;
@ -85,10 +85,10 @@ static void default_print_section_header(AVTextFormatContext *wctx, const void *
av_bprint_clear(&wctx->section_pbuf[wctx->level]);
if (parent_section &&
!(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) {
!(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,
wctx->section_pbuf[wctx->level - 1].str,
upcase_string(buf, sizeof(buf),
av_x_if_null(section->element_name, section->name)));
}
@ -96,7 +96,7 @@ static void default_print_section_header(AVTextFormatContext *wctx, const void *
if (def->noprint_wrappers || def->nested_section[wctx->level])
return;
if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
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));
}
@ -109,7 +109,7 @@ static void default_print_section_footer(AVTextFormatContext *wctx)
if (def->noprint_wrappers || def->nested_section[wctx->level])
return;
if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER|AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
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));
}

View File

@ -57,12 +57,12 @@ typedef struct FlatContext {
#undef OFFSET
#define OFFSET(x) offsetof(FlatContext, x)
static const AVOption flat_options[]= {
{"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 },
{"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 },
{"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{NULL},
static const AVOption flat_options[] = {
{ "sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, { .str = "." }, 0, 0 },
{ "s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, { .str = "." }, 0, 0 },
{ "hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ "h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ NULL },
};
DEFINE_FORMATTER_CLASS(flat);
@ -126,16 +126,18 @@ static void flat_print_section_header(AVTextFormatContext *wctx, const void *dat
av_bprint_clear(buf);
if (!parent_section)
return;
av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level - 1].str);
if (flat->hierarchical ||
!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY|AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) {
!(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);
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];
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];
av_bprintf(buf, "%d%s", n, flat->sep_str);
}
}
@ -166,6 +168,6 @@ const AVTextFormatter avtextformatter_flat = {
.print_section_header = flat_print_section_header,
.print_integer = flat_print_int,
.print_string = flat_print_str,
.flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS|AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT,
.flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS | AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT,
.priv_class = &flat_class,
};

View File

@ -64,9 +64,9 @@ typedef struct INIContext {
#define OFFSET(x) offsetof(INIContext, x)
static const AVOption ini_options[] = {
{"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
{NULL},
{ "hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ "h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 },
{ NULL },
};
DEFINE_FORMATTER_CLASS(ini);
@ -74,9 +74,9 @@ DEFINE_FORMATTER_CLASS(ini);
static char *ini_escape_str(AVBPrint *dst, const char *src)
{
int i = 0;
char c = 0;
char c;
while (c = src[i++]) {
while ((c = src[i++])) {
switch (c) {
case '\b': av_bprintf(dst, "%s", "\\b"); break;
case '\f': av_bprintf(dst, "%s", "\\f"); break;
@ -84,9 +84,11 @@ static char *ini_escape_str(AVBPrint *dst, const char *src)
case '\r': av_bprintf(dst, "%s", "\\r"); break;
case '\t': av_bprintf(dst, "%s", "\\t"); break;
case '\\':
case '#' :
case '=' :
case ':' : av_bprint_chars(dst, '\\', 1);
case '#':
case '=':
case ':':
av_bprint_chars(dst, '\\', 1);
/* fallthrough */
default:
if ((unsigned char)c < 32)
av_bprintf(dst, "\\x00%02x", c & 0xff);
@ -112,23 +114,23 @@ static void ini_print_section_header(AVTextFormatContext *wctx, const void *data
return;
}
if (wctx->nb_item[wctx->level-1])
if (wctx->nb_item[wctx->level - 1])
writer_w8(wctx, '\n');
av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level - 1].str);
if (ini->hierarchical ||
!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY|AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) {
!(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);
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];
av_bprintf(buf, ".%d", n);
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];
av_bprintf(buf, ".%u", n);
}
}
if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY|AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER)))
if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER)))
writer_printf(wctx, "[%s]\n", buf->str);
}
@ -154,6 +156,6 @@ const AVTextFormatter avtextformatter_ini = {
.print_section_header = ini_print_section_header,
.print_integer = ini_print_int,
.print_string = ini_print_str,
.flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS|AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT,
.flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS | AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT,
.priv_class = &ini_class,
};

View File

@ -56,9 +56,9 @@ typedef struct JSONContext {
#undef OFFSET
#define OFFSET(x) offsetof(JSONContext, x)
static const AVOption json_options[]= {
{ "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{ "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
static const AVOption json_options[] = {
{ "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ NULL }
};
@ -76,8 +76,8 @@ static av_cold int json_init(AVTextFormatContext *wctx)
static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
{
static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
static const char json_escape[] = { '"', '\\', '\b', '\f', '\n', '\r', '\t', 0 };
static const char json_subst[] = { '"', '\\', 'b', 'f', 'n', 'r', 't', 0 };
const char *p;
for (p = src; *p; p++) {

View File

@ -58,11 +58,11 @@ typedef struct XMLContext {
#define OFFSET(x) offsetof(XMLContext, x)
static const AVOption xml_options[] = {
{"fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{"q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{"xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
{NULL},
{ "fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ "x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
{ NULL },
};
DEFINE_FORMATTER_CLASS(xml);
@ -115,12 +115,13 @@ static void xml_print_section_header(AVTextFormatContext *wctx, const void *data
}
if (parent_section && (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER) &&
wctx->level && wctx->nb_item[wctx->level-1])
wctx->level && wctx->nb_item[wctx->level - 1])
writer_w8(wctx, '\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);
if (section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS)) {
XML_INDENT();
writer_printf(wctx, "<%s", section->name);
if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) {
AVBPrint buf;
@ -131,7 +132,8 @@ static void xml_print_section_header(AVTextFormatContext *wctx, const void *data
}
writer_printf(wctx, ">\n", section->name);
} else {
XML_INDENT(); writer_printf(wctx, "<%s ", section->name);
XML_INDENT();
writer_printf(wctx, "<%s ", section->name);
xml->within_tag = 1;
}
}
@ -148,7 +150,8 @@ static void xml_print_section_footer(AVTextFormatContext *wctx)
writer_put_str(wctx, "/>\n");
xml->indent_level--;
} else {
XML_INDENT(); writer_printf(wctx, "</%s>\n", section->name);
XML_INDENT();
writer_printf(wctx, "</%s>\n", section->name);
xml->indent_level--;
}
}
@ -195,7 +198,8 @@ static void xml_print_value(AVTextFormatContext *wctx, const char *key,
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 *wctx, const char *key, const char *value)
{
xml_print_value(wctx, key, value, 0, 0);
}