]>
git.cameronkatri.com Git - mandoc.git/blob - strings.c
1 /* $Id: strings.c,v 1.28 2009/03/13 07:46:10 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
)
99 if (0 == *++p
|| ! isgraph((u_char
)*p
))
103 if (0 == *++p
|| ! isgraph((u_char
)*p
))
107 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
108 if ( ! isgraph((u_char
)*p
))
110 return(*p
== ']' ? c
: 0);
116 if (0 == *++p
|| ! isgraph((u_char
)*p
))
118 if (0 == *++p
|| ! isgraph((u_char
)*p
))
127 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
128 if ( ! isgraph((u_char
)*p
))
131 return(*p
== ']' ? c
: 0);
136 mdoc_iscdelim(char p
)
173 mdoc_isdelim(const char *p
)
180 return(mdoc_iscdelim(*p
));
185 mdoc_atosec(const char *p
)
187 const struct mdoc_secname
*n
;
190 for (i
= 0, n
= secnames
; n
->name
; n
++, i
++)
191 if ( ! (n
->flag
& MSECNAME_META
))
192 if (xstrcmp(p
, n
->name
))
193 return((enum mdoc_sec
)i
);
200 mdoc_atotime(const char *p
)
205 (void)memset(&tm
, 0, sizeof(struct tm
));
207 if (xstrcmp(p
, "$Mdocdate: March 13 2009 $"))
209 if ((pp
= strptime(p
, "$Mdocdate: March 13 2009 $", &tm
)) && 0 == *pp
)
211 /* XXX - this matches "June 1999", which is wrong. */
212 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
214 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
222 mdoc_macro2len(int macro
)