]>
git.cameronkatri.com Git - mandoc.git/blob - xml.c
5ff28cb7f4cf73d76d76d21df6dad4f4bf38869f
1 /* $Id: xml.c,v 1.15 2008/12/05 17:43:14 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
22 #include "libmdocml.h"
27 static ssize_t
xml_endtag(struct md_mbuf
*, void *,
28 const struct md_args
*,
30 static ssize_t
xml_begintag(struct md_mbuf
*, void *,
31 const struct md_args
*,
33 const int *, const char **);
34 static int xml_begin(struct md_mbuf
*,
35 const struct md_args
*,
37 const char *, const char *,
38 const char *, const char *);
39 static int xml_end(struct md_mbuf
*,
40 const struct md_args
*);
45 xml_begin(struct md_mbuf
*mbuf
, const struct md_args
*args
,
46 const struct tm
*tm
, const char *os
,
47 const char *title
, const char *section
,
52 if ( ! ml_puts(mbuf
, "<?xml version=\"1.0\" "
53 "encoding=\"UTF-8\"?>\n", &res
))
55 if ( ! ml_puts(mbuf
, "<mdoc xmlns:block=\"block\" "
56 "xmlns:special=\"special\" "
57 "xmlns:inline=\"inline\">", &res
))
66 xml_end(struct md_mbuf
*mbuf
, const struct md_args
*args
)
71 if ( ! ml_puts(mbuf
, "</mdoc>", &res
))
80 xml_begintag(struct md_mbuf
*mbuf
, void *data
,
81 const struct md_args
*args
, enum md_ns ns
,
82 int tok
, const int *argc
, const char **argv
)
86 /* FIXME: doesn't print arguments! */
92 if ( ! ml_nputs(mbuf
, "block:", 6, &res
))
96 if ( ! ml_nputs(mbuf
, "body:", 5, &res
))
100 if ( ! ml_nputs(mbuf
, "head:", 5, &res
))
104 if ( ! ml_nputs(mbuf
, "inline:", 7, &res
))
111 if ( ! ml_puts(mbuf
, toknames
[tok
], &res
))
114 return((ssize_t
)res
);
120 xml_endtag(struct md_mbuf
*mbuf
, void *data
,
121 const struct md_args
*args
, enum md_ns ns
, int tok
)
129 if ( ! ml_nputs(mbuf
, "block:", 6, &res
))
133 if ( ! ml_nputs(mbuf
, "inline:", 7, &res
))
137 if ( ! ml_nputs(mbuf
, "body:", 5, &res
))
141 if ( ! ml_nputs(mbuf
, "head:", 5, &res
))
148 if ( ! ml_puts(mbuf
, toknames
[tok
], &res
))
151 return((ssize_t
)res
);
156 md_line_xml(void *data
, char *buf
)
159 return(mlg_line((struct md_mlg
*)data
, buf
));
164 md_exit_xml(void *data
, int flush
)
167 return(mlg_exit((struct md_mlg
*)data
, flush
));
172 md_init_xml(const struct md_args
*args
,
173 struct md_mbuf
*mbuf
, const struct md_rbuf
*rbuf
)
176 return(mlg_alloc(args
, NULL
, rbuf
, mbuf
, xml_begintag
,
177 xml_endtag
, xml_begin
, xml_end
));