[BACK]Return to html.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/html.c, Revision 1.2

1.2     ! kristaps    1: /* $Id: xml.c,v 1.10 2008/12/03 14:39:59 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
                      4:  *
                      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
                      8:  * copies.
                      9:  *
                     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.
                     18:  */
                     19: #include <assert.h>
                     20: #include <stdlib.h>
1.2     ! kristaps   21: #include <string.h>
1.1       kristaps   22:
                     23: #include "libmdocml.h"
                     24: #include "private.h"
1.2     ! kristaps   25: #include "ml.h"
        !            26:
        !            27:
        !            28: static ssize_t         html_endtag(struct md_mbuf *,
        !            29:                                const struct md_args *,
        !            30:                                enum md_ns, int);
        !            31: static ssize_t         html_begintag(struct md_mbuf *,
        !            32:                                const struct md_args *,
        !            33:                                enum md_ns, int,
        !            34:                                const int *, const char **);
        !            35: static int             html_begin(struct md_mbuf *,
        !            36:                                const struct md_args *);
        !            37: static int             html_end(struct md_mbuf *,
        !            38:                                const struct md_args *);
        !            39: static ssize_t         html_blocktagname(struct md_mbuf *,
        !            40:                                const struct md_args *, int);
        !            41: static ssize_t         html_blocktagargs(struct md_mbuf *,
        !            42:                                const struct md_args *, int,
        !            43:                                const int *, const char **);
        !            44: static ssize_t         html_inlinetagname(struct md_mbuf *,
        !            45:                                const struct md_args *, int);
        !            46: static ssize_t         html_inlinetagargs(struct md_mbuf *,
        !            47:                                const struct md_args *, int,
        !            48:                                const int *, const char **);
        !            49:
        !            50:
        !            51: static int
        !            52: html_begin(struct md_mbuf *mbuf, const struct md_args *args)
        !            53: {
        !            54:        size_t           res;
        !            55:
        !            56:        res = 0;
        !            57:        if ( ! ml_puts(mbuf, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD "
        !            58:                                "HTML 4.01//EN\" \"http://www.w3.org"
        !            59:                                "/TR/html4/strict.dtd\">\n", &res))
        !            60:                return(0);
        !            61:        if ( ! ml_puts(mbuf, "<html>\n", &res))
        !            62:                return(0);
        !            63:        if ( ! ml_puts(mbuf, "<head>\n", &res))
        !            64:                return(0);
        !            65:        if ( ! ml_puts(mbuf, " <title>Manual page</title>\n", &res))
        !            66:                return(0);
        !            67:        if ( ! ml_puts(mbuf, " <meta http-equiv=\"Content-Type\" "
        !            68:                                "content=\"text/html; "
        !            69:                                "charset=utf-8\">\n", &res))
        !            70:                return(0);
        !            71:        if ( ! ml_puts(mbuf, " <meta name=\"resource-type\" "
        !            72:                                "content=\"document\">\n", &res))
        !            73:                return(0);
        !            74:        if ( ! ml_puts(mbuf, "</head>\n", &res))
        !            75:                return(0);
        !            76:        if ( ! ml_puts(mbuf, "<body>", &res))
        !            77:                return(0);
        !            78:
        !            79:        return(1);
        !            80: }
        !            81:
        !            82:
        !            83: static int
        !            84: html_end(struct md_mbuf *mbuf, const struct md_args *args)
        !            85: {
        !            86:        size_t           res;
        !            87:
        !            88:        res = 0;
        !            89:        if ( ! ml_puts(mbuf, "</body>\n</html>", &res))
        !            90:                return(0);
        !            91:
        !            92:        return(1);
        !            93: }
        !            94:
        !            95:
        !            96: static ssize_t
        !            97: html_blocktagname(struct md_mbuf *mbuf,
        !            98:                const struct md_args *args, int tok)
        !            99: {
        !           100:        size_t           res;
        !           101:
        !           102:        res = 0;
        !           103:
        !           104:        switch (tok) {
        !           105:        case (ROFF_Sh):
        !           106:                if ( ! ml_puts(mbuf, "blockquote", &res))
        !           107:                        return(-1);
        !           108:                break;
        !           109:        case (ROFF_Bd):
        !           110:                if ( ! ml_puts(mbuf, "pre", &res))
        !           111:                        return(-1);
        !           112:                break;
        !           113:        case (ROFF_Bl):
        !           114:                if ( ! ml_puts(mbuf, "ul", &res))
        !           115:                        return(-1);
        !           116:                break;
        !           117:        case (ROFF_It):
        !           118:                if ( ! ml_puts(mbuf, "li", &res))
        !           119:                        return(-1);
        !           120:                break;
        !           121:        default:
        !           122:                if ( ! ml_puts(mbuf, "div", &res))
        !           123:                        return(-1);
        !           124:                break;
        !           125:        }
        !           126:
        !           127:        return((size_t)res);
        !           128: }
        !           129:
        !           130:
        !           131: /* ARGSUSED */
        !           132: static ssize_t
        !           133: html_blocktagargs(struct md_mbuf *mbuf, const struct md_args *args,
        !           134:                int tok, const int *argc, const char **argv)
        !           135: {
        !           136:
        !           137:        switch (tok) {
        !           138:        default:
        !           139:                return(0);
        !           140:        }
        !           141:
        !           142:        return(-1);
        !           143: }
1.1       kristaps  144:
                    145:
                    146: /* ARGSUSED */
1.2     ! kristaps  147: static ssize_t
        !           148: html_inlinetagargs(struct md_mbuf *mbuf, const struct md_args *args,
        !           149:                int tok, const int *argc, const char **argv)
        !           150: {
        !           151:
        !           152:        switch (tok) {
        !           153:        default:
        !           154:                return(0);
        !           155:        }
        !           156:
        !           157:        return(-1);
        !           158: }
        !           159:
        !           160:
        !           161: static ssize_t
        !           162: html_inlinetagname(struct md_mbuf *mbuf,
        !           163:                const struct md_args *args, int tok)
        !           164: {
        !           165:        size_t           res;
        !           166:
        !           167:        res = 0;
        !           168:
        !           169:        switch (tok) {
        !           170:        case (ROFF_Sh):
        !           171:                if ( ! ml_puts(mbuf, "h1", &res))
        !           172:                        return(-1);
        !           173:                break;
        !           174:        case (ROFF_Ss):
        !           175:                if ( ! ml_puts(mbuf, "h2", &res))
        !           176:                        return(-1);
        !           177:                break;
        !           178:        default:
        !           179:                if ( ! ml_puts(mbuf, "span", &res))
        !           180:                        return(-1);
        !           181:                break;
        !           182:        }
        !           183:
        !           184:        return((ssize_t)res);
        !           185: }
        !           186:
        !           187:
        !           188: static ssize_t
        !           189: html_begintag(struct md_mbuf *mbuf, const struct md_args *args,
        !           190:                enum md_ns ns, int tok,
        !           191:                const int *argc, const char **argv)
        !           192: {
        !           193:
        !           194:        assert(ns != MD_NS_DEFAULT);
        !           195:        if (MD_NS_BLOCK == ns) {
        !           196:                if ( ! html_blocktagname(mbuf, args, tok))
        !           197:                        return(0);
        !           198:                return(html_blocktagargs(mbuf, args,
        !           199:                                        tok, argc, argv));
        !           200:        }
        !           201:
        !           202:        if ( ! html_inlinetagname(mbuf, args, tok))
        !           203:                return(0);
        !           204:        return(html_inlinetagargs(mbuf, args, tok, argc, argv));
        !           205: }
        !           206:
        !           207:
        !           208: static ssize_t
        !           209: html_endtag(struct md_mbuf *mbuf, const struct md_args *args,
        !           210:                enum md_ns ns, int tok)
        !           211: {
        !           212:
        !           213:        assert(ns != MD_NS_DEFAULT);
        !           214:        if (MD_NS_BLOCK == ns)
        !           215:                return(html_blocktagname(mbuf, args, tok));
        !           216:
        !           217:        return(html_inlinetagname(mbuf, args, tok));
        !           218: }
        !           219:
        !           220:
1.1       kristaps  221: int
                    222: md_line_html(void *data, char *buf)
                    223: {
                    224:
1.2     ! kristaps  225:        return(mlg_line((struct md_mlg *)data, buf));
1.1       kristaps  226: }
                    227:
                    228:
                    229: int
                    230: md_exit_html(void *data, int flush)
                    231: {
                    232:
1.2     ! kristaps  233:        return(mlg_exit((struct md_mlg *)data, flush));
1.1       kristaps  234: }
                    235:
                    236:
                    237: void *
                    238: md_init_html(const struct md_args *args,
                    239:                struct md_mbuf *mbuf, const struct md_rbuf *rbuf)
                    240: {
                    241:
1.2     ! kristaps  242:        return(mlg_alloc(args, rbuf, mbuf, html_begintag,
        !           243:                                html_endtag, html_begin, html_end));
1.1       kristaps  244: }
1.2     ! kristaps  245:

CVSweb