]>
git.cameronkatri.com Git - mandoc.git/blob - mandoc.c
1 /* $Id: mandoc.c,v 1.7 2009/11/02 06:22:45 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.
17 #if defined(__linux__) || defined(__MINT__)
18 # define _GNU_SOURCE /* strptime() */
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
)
77 if (0 == *++p
|| ! isgraph((u_char
)*p
))
81 if (0 == *++p
|| ! isgraph((u_char
)*p
))
85 if (0 == *++p
|| ! isgraph((u_char
)*p
))
89 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
90 if ( ! isgraph((u_char
)*p
))
92 return(*p
== ']' ? c
: 0);
98 if (0 == *++p
|| ! isgraph((u_char
)*p
))
100 if (0 == *++p
|| ! isgraph((u_char
)*p
))
109 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
110 if ( ! isgraph((u_char
)*p
))
113 return(*p
== ']' ? c
: 0);
118 mandoc_calloc(size_t num
, size_t size
)
122 ptr
= calloc(num
, size
);
133 mandoc_malloc(size_t size
)
148 mandoc_realloc(void *ptr
, size_t size
)
151 ptr
= realloc(ptr
, size
);
162 mandoc_strdup(const char *ptr
)
177 a2time(time_t *t
, const char *fmt
, const char *p
)
182 memset(&tm
, 0, sizeof(struct tm
));
184 pp
= strptime(p
, fmt
, &tm
);
185 if (NULL
!= pp
&& '\0' == *pp
) {
195 * Convert from a manual date string (see mdoc(7) and man(7)) into a
196 * date according to the stipulated date type.
199 mandoc_a2time(int flags
, const char *p
)
203 if (MTIME_MDOCDATE
& flags
) {
204 if (0 == strcmp(p
, "$" "Mdocdate$"))
206 if (a2time(&t
, "$" "Mdocdate: %b %d %Y $", p
))
210 if (MTIME_CANONICAL
& flags
|| MTIME_REDUCED
& flags
)
211 if (a2time(&t
, "%b %d, %Y", p
))
214 if (MTIME_ISO_8601
& flags
)
215 if (a2time(&t
, "%Y-%m-%d", p
))
218 if (MTIME_REDUCED
& flags
) {
219 if (a2time(&t
, "%d, %Y", p
))
221 if (a2time(&t
, "%Y", p
))