[FFmpeg-devel] [PATCH] ffprobe: implement generic reindent logic in the JSON writer
Clément Bœsch
ubitux at gmail.com
Sun Jan 8 02:35:00 CET 2012
On Sun, Jan 08, 2012 at 02:27:20AM +0100, Stefano Sabatini wrote:
> Clarify/generalize indent logic, possibly slower.
> ---
> ffprobe.c | 54 ++++++++++++++++++++++++++++++++++++++----------------
> 1 files changed, 38 insertions(+), 16 deletions(-)
>
> diff --git a/ffprobe.c b/ffprobe.c
> index 10dc7db..3a03e21 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -721,6 +721,7 @@ typedef struct {
> char *buf;
> size_t buf_size;
> int print_packets_and_frames;
> + int indent_level;
> } JSONContext;
>
> static av_cold int json_init(WriterContext *wctx, const char *args, void *opaque)
> @@ -777,14 +778,22 @@ static const char *json_escape_str(char **dst, size_t *dst_size, const char *src
>
> static void json_print_header(WriterContext *wctx)
> {
> + JSONContext *json = wctx->priv;
> printf("{");
> + json->indent_level++;
> }
>
> static void json_print_footer(WriterContext *wctx)
> {
> + JSONContext *json = wctx->priv;
> + json->indent_level--;
> printf("\n}\n");
> }
>
> +#define INDENT " "
> +
> +#define JSON_INDENT() { int i; for (i = 0; i < json->indent_level; i++) printf(INDENT); }
> +
I think I already suggested in a "very" old patch that this could be done
with "%*c", json->indent_level * 4, ' '. It might be faster (and cleaner).
Are you against this?
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120108/6a3a125a/attachment.asc>
More information about the ffmpeg-devel
mailing list