Re: [RFC/PATCH 2/3] add a library of code for producing structured output
- From
Erik Faye-Lund <kusmabite@googlemail.com>
- Date
- Apr 11, 2010, 12:51 UTC
- Message-ID
- <g2z40aa078e1004110551s98e34b74w66c5bcc49538ca45@mail.gmail.com>
- In-Reply-To
- <20100411113733.80010.3767.julian@quantumfyre.co.uk>
On Sun, Apr 11, 2010 at 1:37 PM, Julian Phillips <julian@quantumfyre.co.uk> wrote:
Show 65 quoted lines
> Add a library that allows commands to produce structured output in any
> of a range of formats using a single API.
>
> The API includes an OPT_OUTPUT and handle_output_arg so that the
> option handling for different commands will be as similar as possible.
>
> At the moment JSON and XML output options are available - though the
> XML output is _very_ rudimentary.
>
> Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk>
> ---
> Makefile | 3 +
> output-json.c | 128 ++++++++++++++++++++++++++++++++++
> output-xml.c | 68 ++++++++++++++++++
> output.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> output.h | 71 +++++++++++++++++++
> 5 files changed, 482 insertions(+), 0 deletions(-)
> create mode 100644 output-json.c
> create mode 100644 output-xml.c
> create mode 100644 output.c
> create mode 100644 output.h
>
> diff --git a/Makefile b/Makefile
> index 910f471..4ba2a4f 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -576,6 +576,9 @@ LIB_OBJS += merge-recursive.o
> LIB_OBJS += name-hash.o
> LIB_OBJS += notes.o
> LIB_OBJS += object.o
> +LIB_OBJS += output.o
> +LIB_OBJS += output-json.o
> +LIB_OBJS += output-xml.o
> LIB_OBJS += pack-check.o
> LIB_OBJS += pack-refs.o
> LIB_OBJS += pack-revindex.o
> diff --git a/output-json.c b/output-json.c
> new file mode 100644
> index 0000000..0eb66b2
> --- /dev/null
> +++ b/output-json.c
> @@ -0,0 +1,128 @@
> <snip>
> +
> +static void json_str(FILE *file, char *value)
> +{
> + char *quoted = json_quote(value);
> + fprintf(file, "\"%s\"", quoted);
> + free(quoted);
> +}
> +
> <snip>
> diff --git a/output-xml.c b/output-xml.c
> new file mode 100644
> index 0000000..50dd7d6
> --- /dev/null
> +++ b/output-xml.c
> @@ -0,0 +1,68 @@
> <snip>
> +
> +static void xml_str(FILE *file, char *value)
> +{
> + fprintf(file, "\"%s\"", value);
> +}
> +Don't you need to quote this one, like you did in json_str()?
-- Erik "kusma" Faye-Lund