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

Annotation of mandoc/ml.c, Revision 1.2

1.2     ! kristaps    1: /* $Id: ml.c,v 1.1 2008/12/02 18:26:57 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 <stdlib.h>
                     20: #include <string.h>
                     21:
                     22: #include "libmdocml.h"
                     23: #include "private.h"
1.2     ! kristaps   24: #include "ml.h"
1.1       kristaps   25:
1.2     ! kristaps   26: #ifdef __linux__
        !            27: extern size_t            strlcat(char *, const char *, size_t);
        !            28: extern size_t            strlcpy(char *, const char *, size_t);
        !            29: #endif
1.1       kristaps   30:
                     31:
1.2     ! kristaps   32: int
        !            33: ml_nputstring(struct md_mbuf *p,
        !            34:                const char *buf, size_t sz, size_t *pos)
1.1       kristaps   35: {
                     36:        int              i;
                     37:
1.2     ! kristaps   38:        for (i = 0; i < (int)sz; i++) {
1.1       kristaps   39:                switch (buf[i]) {
                     40:                case ('&'):
1.2     ! kristaps   41:                        if ( ! ml_nputs(p, "&amp;", 5, pos))
        !            42:                                return(0);
1.1       kristaps   43:                        break;
                     44:                case ('"'):
1.2     ! kristaps   45:                        if ( ! ml_nputs(p, "&quot;", 6, pos))
        !            46:                                return(0);
1.1       kristaps   47:                        break;
                     48:                case ('<'):
1.2     ! kristaps   49:                        if ( ! ml_nputs(p, "&lt;", 4, pos))
        !            50:                                return(0);
1.1       kristaps   51:                        break;
                     52:                case ('>'):
1.2     ! kristaps   53:                        if ( ! ml_nputs(p, "&gt;", 4, pos))
        !            54:                                return(0);
1.1       kristaps   55:                        break;
                     56:                default:
1.2     ! kristaps   57:                        if ( ! ml_nputs(p, &buf[i], 1, pos))
        !            58:                                return(0);
1.1       kristaps   59:                        break;
                     60:                }
                     61:        }
1.2     ! kristaps   62:        return(1);
1.1       kristaps   63: }
                     64:
                     65:
1.2     ! kristaps   66: int
        !            67: ml_nputs(struct md_mbuf *p, const char *buf, size_t sz, size_t *pos)
1.1       kristaps   68: {
                     69:
1.2     ! kristaps   70:        if ( ! md_buf_puts(p, buf, sz))
        !            71:                return(0);
        !            72:
        !            73:        *pos += sz;
        !            74:        return(1);
1.1       kristaps   75: }
                     76:
                     77:
1.2     ! kristaps   78: int
        !            79: ml_putchars(struct md_mbuf *p, char buf, size_t count, size_t *pos)
1.1       kristaps   80: {
                     81:        size_t           i;
                     82:
1.2     ! kristaps   83:        for (i = 0; i < count; i++)
        !            84:                if ( ! ml_nputs(p, &buf, 1, pos))
        !            85:                        return(0);
1.1       kristaps   86:
1.2     ! kristaps   87:        return(1);
1.1       kristaps   88: }

CVSweb