]>
git.cameronkatri.com Git - mandoc.git/blob - ml.c
1 /* $Id: ml.c,v 1.1 2008/12/02 18:26:57 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"
28 static ssize_t
ml_puts(struct md_mbuf
*, const char *);
29 static ssize_t
ml_putchar(struct md_mbuf
*, char);
30 static ssize_t
ml_putstring(struct md_mbuf
*, const char *);
34 ml_puts(struct md_mbuf
*p
, const char *buf
)
37 return(ml_nputs(p
, buf
, strlen(buf
)));
42 ml_putchar(struct md_mbuf
*p
, char buf
)
45 return(ml_nputs(p
, &buf
, 1));
50 ml_putstring(struct md_mbuf
*p
, const char *buf
)
53 return(ml_nputstring(p
, buf
, strlen(buf
)));
58 ml_begintag(struct md_mbuf
*p
, const char *name
,
59 int *argc
, char **argv
)
66 if (-1 == (sz
= ml_nputs(p
, "<", 1)))
70 if (-1 == (sz
= ml_puts(p
, name
)))
74 for (i
= 0; ROFF_ARGMAX
!= argc
[i
]; i
++) {
75 if (-1 == (sz
= ml_nputs(p
, " ", 1)))
79 if (-1 == (sz
= ml_puts(p
, tokargnames
[argc
[i
]])))
83 if (-1 == (sz
= ml_nputs(p
, "=\"", 2)))
87 if (-1 == (sz
= ml_putstring(p
, argv
[i
] ?
92 if (-1 == (sz
= ml_nputs(p
, "\"", 1)))
97 if (-1 == (sz
= ml_nputs(p
, ">", 1)))
105 ml_endtag(struct md_mbuf
*p
, const char *tag
)
111 if (-1 == (sz
= ml_nputs(p
, "</", 2)))
115 if (-1 == (sz
= ml_puts(p
, tag
)))
119 if (-1 == (sz
= ml_nputs(p
, ">", 1)))
127 ml_nputstring(struct md_mbuf
*p
, const char *buf
, size_t bufsz
)
134 for (i
= 0; i
< (int)bufsz
; i
++) {
137 if (-1 == (sz
= ml_nputs(p
, "&", 5)))
141 if (-1 == (sz
= ml_nputs(p
, """, 6)))
145 if (-1 == (sz
= ml_nputs(p
, "<", 4)))
149 if (-1 == (sz
= ml_nputs(p
, ">", 4)))
153 if (-1 == (sz
= ml_putchar(p
, buf
[i
])))
164 ml_nputs(struct md_mbuf
*p
, const char *buf
, size_t sz
)
167 return(0 == md_buf_puts(p
, buf
, sz
) ? -1 : (ssize_t
)sz
);
172 ml_indent(struct md_mbuf
*p
, int indent
)
180 for (i
= 0; i
< MIN(indent
, MAXINDENT
); i
++, res
+= sz
)
181 if (-1 == (sz
= ml_nputs(p
, " ", 4)))