]>
git.cameronkatri.com Git - mandoc.git/blob - mandoc.c
1 /* $Id: mandoc.c,v 1.17 2010/06/01 11:47:28 kristaps Exp $ */
3 * Copyright (c) 2008, 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>
30 #include "libmandoc.h"
32 static int a2time(time_t *, const char *, const char *);
36 mandoc_special(const char *p
)
38 int terminator
; /* Terminator for \s. */
39 int lim
; /* Limit for N in \s. */
91 } else if (*p
== '[') {
96 } else if (*p
== '(') {
103 if (*p
== '+' || *p
== '-') {
115 } else if (*p
== '[') {
122 } else if (*p
== '(') {
131 /* TODO: needs to handle floating point. */
133 if ( ! isdigit((u_char
)*p
))
136 for (i
= 0; isdigit((u_char
)*p
); i
++) {
143 if (terminator
&& terminator
< 3) {
144 if (1 == terminator
&& *p
!= '\'')
146 if (2 == terminator
&& *p
!= ']')
158 if (0 == *++p
|| ! isgraph((u_char
)*p
))
162 if (0 == *++p
|| ! isgraph((u_char
)*p
))
166 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
167 if ( ! isgraph((u_char
)*p
))
169 return(*p
== ']' ? c
: 0);
175 if (0 == *++p
|| ! isgraph((u_char
)*p
))
177 if (0 == *++p
|| ! isgraph((u_char
)*p
))
186 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
187 if ( ! isgraph((u_char
)*p
))
190 return(*p
== ']' ? c
: 0);
195 mandoc_calloc(size_t num
, size_t size
)
199 ptr
= calloc(num
, size
);
210 mandoc_malloc(size_t size
)
225 mandoc_realloc(void *ptr
, size_t size
)
228 ptr
= realloc(ptr
, size
);
239 mandoc_strdup(const char *ptr
)
254 a2time(time_t *t
, const char *fmt
, const char *p
)
259 memset(&tm
, 0, sizeof(struct tm
));
261 pp
= strptime(p
, fmt
, &tm
);
262 if (NULL
!= pp
&& '\0' == *pp
) {
272 * Convert from a manual date string (see mdoc(7) and man(7)) into a
273 * date according to the stipulated date type.
276 mandoc_a2time(int flags
, const char *p
)
280 if (MTIME_MDOCDATE
& flags
) {
281 if (0 == strcmp(p
, "$" "Mdocdate$"))
283 if (a2time(&t
, "$" "Mdocdate: %b %d %Y $", p
))
287 if (MTIME_CANONICAL
& flags
|| MTIME_REDUCED
& flags
)
288 if (a2time(&t
, "%b %d, %Y", p
))
291 if (MTIME_ISO_8601
& flags
)
292 if (a2time(&t
, "%Y-%m-%d", p
))
295 if (MTIME_REDUCED
& flags
) {
296 if (a2time(&t
, "%d, %Y", p
))
298 if (a2time(&t
, "%Y", p
))
307 mandoc_eos(const char *p
, size_t sz
)
314 * End-of-sentence recognition must include situations where
315 * some symbols, such as `)', allow prior EOS punctuation to
320 switch (p
[(int)sz
- 1]) {
330 /* Escaped periods. */
331 if (sz
> 1 && '\\' == p
[(int)sz
- 2])
348 mandoc_hyph(const char *start
, const char *c
)
352 * Choose whether to break at a hyphenated character. We only
353 * do this if it's free-standing within a word.
356 /* Skip first/last character of buffer. */
357 if (c
== start
|| '\0' == *(c
+ 1))
359 /* Skip first/last character of word. */
360 if ('\t' == *(c
+ 1) || '\t' == *(c
- 1))
362 if (' ' == *(c
+ 1) || ' ' == *(c
- 1))
364 /* Skip double invocations. */
365 if ('-' == *(c
+ 1) || '-' == *(c
- 1))
368 if ('\\' == *(c
- 1))