]>
git.cameronkatri.com Git - mandoc.git/blob - strings.c
1 /* $Id: strings.c,v 1.27 2009/03/09 13:17:49 kristaps Exp $ */
3 * Copyright (c) 2008 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
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
30 * Various string-literal operations: converting scalars to and from
37 #define MSECNAME_META (1 << 0)
40 /* Section names corresponding to mdoc_sec. */
42 static const struct mdoc_secname secnames
[] = {
43 { "PROLOGUE", MSECNAME_META
},
44 { "BODY", MSECNAME_META
},
49 { "IMPLEMENTATION NOTES", 0 },
50 { "RETURN VALUES", 0 },
55 { "COMPATIBILITY", 0 },
67 extern char *strptime(const char *, const char *, struct tm
*);
72 mdoc_isescape(const char *p
)
97 if (0 == *++p
|| ! isgraph((u_char
)*p
))
101 if (0 == *++p
|| ! isgraph((u_char
)*p
))
105 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
106 if ( ! isgraph((u_char
)*p
))
108 return(*p
== ']' ? c
: 0);
114 if (0 == *++p
|| ! isgraph((u_char
)*p
))
116 if (0 == *++p
|| ! isgraph((u_char
)*p
))
125 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
126 if ( ! isgraph((u_char
)*p
))
129 return(*p
== ']' ? c
: 0);
134 mdoc_iscdelim(char p
)
171 mdoc_isdelim(const char *p
)
178 return(mdoc_iscdelim(*p
));
183 mdoc_atosec(const char *p
)
185 const struct mdoc_secname
*n
;
188 for (i
= 0, n
= secnames
; n
->name
; n
++, i
++)
189 if ( ! (n
->flag
& MSECNAME_META
))
190 if (xstrcmp(p
, n
->name
))
191 return((enum mdoc_sec
)i
);
198 mdoc_atotime(const char *p
)
203 (void)memset(&tm
, 0, sizeof(struct tm
));
205 if (xstrcmp(p
, "$Mdocdate: March 9 2009 $"))
207 if ((pp
= strptime(p
, "$Mdocdate: March 9 2009 $", &tm
)) && 0 == *pp
)
209 /* XXX - this matches "June 1999", which is wrong. */
210 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
212 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
220 mdoc_macro2len(int macro
)