]>
git.cameronkatri.com Git - mandoc.git/blob - mandoc.c
1 /* $Id: mandoc.c,v 1.25 2010/07/21 20:35:03 kristaps Exp $ */
3 * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
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>
31 #include "libmandoc.h"
33 static int a2time(time_t *, const char *, const char *);
37 mandoc_special(char *p
)
97 if ('+' == *p
|| '-' == *p
)
100 i
= ('s' != *(p
- 1));
118 if (ASCII_HYPH
== *p
)
120 if ('+' == *p
|| '-' == *p
) {
176 for ( ; *p
&& term
!= *p
; p
++)
177 if (ASCII_HYPH
== *p
)
179 return(*p
? (int)(p
- sv
) : 0);
182 for (i
= 0; *p
&& i
< len
; i
++, p
++)
183 if (ASCII_HYPH
== *p
)
185 return(i
== len
? (int)(p
- sv
) : 0);
190 mandoc_calloc(size_t num
, size_t size
)
194 ptr
= calloc(num
, size
);
205 mandoc_malloc(size_t size
)
220 mandoc_realloc(void *ptr
, size_t size
)
223 ptr
= realloc(ptr
, size
);
234 mandoc_strdup(const char *ptr
)
249 a2time(time_t *t
, const char *fmt
, const char *p
)
254 memset(&tm
, 0, sizeof(struct tm
));
256 pp
= strptime(p
, fmt
, &tm
);
257 if (NULL
!= pp
&& '\0' == *pp
) {
267 * Convert from a manual date string (see mdoc(7) and man(7)) into a
268 * date according to the stipulated date type.
271 mandoc_a2time(int flags
, const char *p
)
275 if (MTIME_MDOCDATE
& flags
) {
276 if (0 == strcmp(p
, "$" "Mdocdate$"))
278 if (a2time(&t
, "$" "Mdocdate: %b %d %Y $", p
))
282 if (MTIME_CANONICAL
& flags
|| MTIME_REDUCED
& flags
)
283 if (a2time(&t
, "%b %d, %Y", p
))
286 if (MTIME_ISO_8601
& flags
)
287 if (a2time(&t
, "%Y-%m-%d", p
))
290 if (MTIME_REDUCED
& flags
) {
291 if (a2time(&t
, "%d, %Y", p
))
293 if (a2time(&t
, "%Y", p
))
302 mandoc_eos(const char *p
, size_t sz
, int enclosed
)
311 * End-of-sentence recognition must include situations where
312 * some symbols, such as `)', allow prior EOS punctuation to
317 for (q
= p
+ (int)sz
- 1; q
>= p
; q
--) {
337 return(found
&& (!enclosed
|| isalnum(*q
)));
341 return(found
&& !enclosed
);
346 mandoc_hyph(const char *start
, const char *c
)
350 * Choose whether to break at a hyphenated character. We only
351 * do this if it's free-standing within a word.
354 /* Skip first/last character of buffer. */
355 if (c
== start
|| '\0' == *(c
+ 1))
357 /* Skip first/last character of word. */
358 if ('\t' == *(c
+ 1) || '\t' == *(c
- 1))
360 if (' ' == *(c
+ 1) || ' ' == *(c
- 1))
362 /* Skip double invocations. */
363 if ('-' == *(c
+ 1) || '-' == *(c
- 1))
366 if ('\\' == *(c
- 1))