]>
git.cameronkatri.com Git - mandoc.git/blob - strings.c
1 /* $Id: strings.c,v 1.31 2009/03/21 13:47:02 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
)
105 if (0 == *++p
|| ! isgraph((u_char
)*p
))
109 if (0 == *++p
|| ! isgraph((u_char
)*p
))
113 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
114 if ( ! isgraph((u_char
)*p
))
116 return(*p
== ']' ? c
: 0);
122 if (0 == *++p
|| ! isgraph((u_char
)*p
))
124 if (0 == *++p
|| ! isgraph((u_char
)*p
))
133 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
134 if ( ! isgraph((u_char
)*p
))
137 return(*p
== ']' ? c
: 0);
142 mdoc_iscdelim(char p
)
179 mdoc_isdelim(const char *p
)
186 return(mdoc_iscdelim(*p
));
191 mdoc_atosec(const char *p
)
193 const struct mdoc_secname
*n
;
196 for (i
= 0, n
= secnames
; n
->name
; n
++, i
++)
197 if ( ! (n
->flag
& MSECNAME_META
))
198 if (xstrcmp(p
, n
->name
))
199 return((enum mdoc_sec
)i
);
206 mdoc_atotime(const char *p
)
211 (void)memset(&tm
, 0, sizeof(struct tm
));
213 if (xstrcmp(p
, "$Mdocdate: March 21 2009 $"))
215 if ((pp
= strptime(p
, "$Mdocdate: March 21 2009 $", &tm
)) && 0 == *pp
)
217 /* XXX - this matches "June 1999", which is wrong. */
218 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
220 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
228 mdoc_macro2len(int macro
)