]>
git.cameronkatri.com Git - mandoc.git/blob - ml.c
1 /* $Id: ml.c,v 1.7 2008/12/05 19:45:15 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.
23 #include "libmdocml.h"
28 extern size_t strlcat(char *, const char *, size_t);
29 extern size_t strlcpy(char *, const char *, size_t);
34 ml_putstring(struct md_mbuf
*p
, const char *buf
, size_t *pos
)
37 return(ml_nputstring(p
, buf
, strlen(buf
), pos
));
42 ml_nputstring(struct md_mbuf
*p
,
43 const char *buf
, size_t sz
, size_t *pos
)
49 for (i
= 0; i
< (int)sz
; i
++) {
54 if (-1 == (v
= rofftok_scan(buf
, &i
)))
94 case (ROFFTok_Hyphen
):
114 case (ROFFTok_Rquote
):
118 case (ROFFTok_Lquote
):
122 case (ROFFTok_Uparrow
):
126 case (ROFFTok_Acute
):
130 case (ROFFTok_Grave
):
150 case (ROFFTok_Plusmin
):
154 case (ROFFTok_Infty
):
166 case (ROFFTok_Quote
):
170 case (ROFFTok_Slash
):
183 /* Ampersand ml-escape. */
189 /* Quotation ml-escape. */
213 if (ssz
> 0 && ! ml_nputs(p
, seq
, ssz
, pos
))
221 ml_nputs(struct md_mbuf
*p
, const char *buf
, size_t sz
, size_t *pos
)
227 if ( ! md_buf_puts(p
, buf
, sz
))
237 ml_puts(struct md_mbuf
*p
, const char *buf
, size_t *pos
)
241 if (0 == (sz
= strlen(buf
)))
244 if ( ! md_buf_puts(p
, buf
, sz
))
254 ml_putchars(struct md_mbuf
*p
, char buf
, size_t count
, size_t *pos
)
258 for (i
= 0; i
< count
; i
++)
259 if ( ! ml_nputs(p
, &buf
, 1, pos
))