]>
git.cameronkatri.com Git - mandoc.git/blob - out.c
1 /* $Id: out.c,v 1.15 2010/04/07 11:29:55 kristaps Exp $ */
3 * Copyright (c) 2009 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 above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
32 /* See a2roffdeco(). */
33 #define C2LIM(c, l) do { \
35 if ('[' == (c) || '\'' == (c)) \
37 else if ('(' == (c)) \
39 while (/* CONSTCOND */ 0)
41 /* See a2roffdeco(). */
42 #define C2TERM(c, t) do { \
46 else if ('[' == (c)) \
48 else if ('(' == (c)) \
50 while (/* CONSTCOND */ 0)
53 * Convert a `scaling unit' to a consistent form, or fail. Scaling
54 * units are documented in groff.7, mdoc.7, man.7.
57 a2roffsu(const char *src
, struct roffsu
*dst
, enum roffscale def
)
59 char buf
[BUFSIZ
], hasd
;
83 if ( ! isdigit((u_char
)*src
)) {
94 if (BUFSIZ
== i
|| (*src
&& *(src
+ 1)))
122 if (SCALE_MAX
== def
)
139 if ((dst
->scale
= atof(buf
)) < 0)
149 * Correctly writes the time in nroff form, which differs from standard
150 * form in that a space isn't printed in lieu of the extra %e field for
151 * single-digit dates.
154 time2a(time_t t
, char *dst
, size_t sz
)
162 localtime_r(&t
, &tm
);
169 if (0 == (nsz
= strftime(p
, sz
, "%B ", &tm
)))
175 if (0 == strftime(buf
, sizeof(buf
), "%e, ", &tm
))
178 nsz
= strlcat(p
, buf
+ (' ' == buf
[0] ? 1 : 0), sz
);
186 (void)strftime(p
, sz
, "%Y", &tm
);
191 * Returns length of parsed string (the leading "\" should NOT be
192 * included). This can be zero if the current character is the nil
193 * terminator. "d" is set to the type of parsed decorator, which may
194 * have an adjoining "word" of size "sz" (e.g., "(ab" -> "ab", 2).
197 a2roffdeco(enum roffdeco
*d
,
198 const char **word
, size_t *sz
)
207 switch ((set
= *wp
)) {
214 if ('\0' == *(wp
+ 1))
226 * FIXME: this needs work and consolidation (it should
227 * follow the sequence that special characters do, for
228 * one), but isn't a priority at the moment. Note, for
229 * one, that in reality \fB != \FB, although here we let
256 if ('\0' == *(wp
+ 1))
259 *d
= 'F' == set
? DECO_FFONT
: DECO_FONT
;
265 for (j
= 0; *wp
&& ']' != *wp
; wp
++, j
++)
271 *d
= 'F' == set
? DECO_FFONT
: DECO_FONT
;
278 *d
= 'F' == set
? DECO_FFONT
: DECO_FONT
;
291 if ('\0' == *(wp
+ 1))
301 for (j
= 0; *wp
&& ']' != *wp
; wp
++, j
++)
333 if (*wp
== '+' || *wp
== '-')
343 return((int)(wp
- sp
));
353 if ( ! isdigit((u_char
)*wp
))
354 return((int)(wp
- sp
));
356 for (j
= 0; isdigit((u_char
)*wp
); j
++) {
362 if (term
&& term
< 3) {
363 if (1 == term
&& *wp
!= '\'')
364 return((int)(wp
- sp
));
365 if (2 == term
&& *wp
!= ']')
366 return((int)(wp
- sp
));
371 return((int)(wp
- sp
));
376 for (j
= 0; *wp
&& ']' != *wp
; wp
++, j
++)