]>
git.cameronkatri.com Git - mandoc.git/blob - mandoc.c
1 /* $Id: mandoc.c,v 1.11 2010/04/07 11:25:38 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. */
89 } else if (*p
== '[') {
94 } else if (*p
== '(') {
101 if (*p
== '+' || *p
== '-') {
113 } else if (*p
== '[') {
120 } else if (*p
== '(') {
129 /* TODO: needs to handle floating point. */
131 if ( ! isdigit((u_char
)*p
))
134 for (i
= 0; isdigit((u_char
)*p
); i
++) {
141 if (terminator
&& terminator
< 3) {
142 if (1 == terminator
&& *p
!= '\'')
144 if (2 == terminator
&& *p
!= ']')
156 if (0 == *++p
|| ! isgraph((u_char
)*p
))
160 if (0 == *++p
|| ! isgraph((u_char
)*p
))
164 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
165 if ( ! isgraph((u_char
)*p
))
167 return(*p
== ']' ? c
: 0);
173 if (0 == *++p
|| ! isgraph((u_char
)*p
))
175 if (0 == *++p
|| ! isgraph((u_char
)*p
))
184 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
185 if ( ! isgraph((u_char
)*p
))
188 return(*p
== ']' ? c
: 0);
193 mandoc_calloc(size_t num
, size_t size
)
197 ptr
= calloc(num
, size
);
208 mandoc_malloc(size_t size
)
223 mandoc_realloc(void *ptr
, size_t size
)
226 ptr
= realloc(ptr
, size
);
237 mandoc_strdup(const char *ptr
)
252 a2time(time_t *t
, const char *fmt
, const char *p
)
257 memset(&tm
, 0, sizeof(struct tm
));
259 pp
= strptime(p
, fmt
, &tm
);
260 if (NULL
!= pp
&& '\0' == *pp
) {
270 * Convert from a manual date string (see mdoc(7) and man(7)) into a
271 * date according to the stipulated date type.
274 mandoc_a2time(int flags
, const char *p
)
278 if (MTIME_MDOCDATE
& flags
) {
279 if (0 == strcmp(p
, "$" "Mdocdate$"))
281 if (a2time(&t
, "$" "Mdocdate: %b %d %Y $", p
))
285 if (MTIME_CANONICAL
& flags
|| MTIME_REDUCED
& flags
)
286 if (a2time(&t
, "%b %d, %Y", p
))
289 if (MTIME_ISO_8601
& flags
)
290 if (a2time(&t
, "%Y-%m-%d", p
))
293 if (MTIME_REDUCED
& flags
) {
294 if (a2time(&t
, "%d, %Y", p
))
296 if (a2time(&t
, "%Y", p
))