]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_strings.c
1 /* $Id: mdoc_strings.c,v 1.7 2009/06/17 10:53:32 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 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 #include <sys/types.h>
27 /* FIXME: this file is poorly named. */
30 const char *name
; /* Name of section. */
31 enum mdoc_sec sec
; /* Corresponding section. */
34 #define SECNAME_MAX (18)
36 static const struct mdoc_secname secnames
[SECNAME_MAX
] = {
38 { "LIBRARY", SEC_LIBRARY
},
39 { "SYNOPSIS", SEC_SYNOPSIS
},
40 { "DESCRIPTION", SEC_DESCRIPTION
},
41 { "IMPLEMENTATION NOTES", SEC_IMPLEMENTATION
},
42 { "RETURN VALUES", SEC_RETURN_VALUES
},
43 { "ENVIRONMENT", SEC_ENVIRONMENT
},
44 { "FILES", SEC_FILES
},
45 { "EXAMPLES", SEC_EXAMPLES
},
46 { "DIAGNOSTICS", SEC_DIAGNOSTICS
},
47 { "COMPATIBILITY", SEC_COMPATIBILITY
},
48 { "ERRORS", SEC_ERRORS
},
49 { "SEE ALSO", SEC_SEE_ALSO
},
50 { "STANDARDS", SEC_STANDARDS
},
51 { "HISTORY", SEC_HISTORY
},
52 { "AUTHORS", SEC_AUTHORS
},
53 { "CAVEATS", SEC_CAVEATS
},
58 extern char *strptime(const char *, const char *, struct tm
*);
63 mdoc_isescape(const char *p
)
102 if (0 == *++p
|| ! isgraph((u_char
)*p
))
106 if (0 == *++p
|| ! isgraph((u_char
)*p
))
110 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
111 if ( ! isgraph((u_char
)*p
))
113 return(*p
== ']' ? c
: 0);
119 if (0 == *++p
|| ! isgraph((u_char
)*p
))
121 if (0 == *++p
|| ! isgraph((u_char
)*p
))
130 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
131 if ( ! isgraph((u_char
)*p
))
134 return(*p
== ']' ? c
: 0);
139 mdoc_iscdelim(char p
)
178 mdoc_isdelim(const char *p
)
185 return(mdoc_iscdelim(*p
));
190 mdoc_atosec(const char *p
)
194 for (i
= 0; i
< SECNAME_MAX
; i
++)
195 if (0 == strcmp(p
, secnames
[i
].name
))
196 return(secnames
[i
].sec
);
203 mdoc_atotime(const char *p
)
208 bzero(&tm
, sizeof(struct tm
));
210 if (0 == strcmp(p
, "$" "Mdocdate$"))
212 if ((pp
= strptime(p
, "$" "Mdocdate: %b %d %Y $", &tm
)) && 0 == *pp
)
214 /* XXX - this matches "June 1999", which is wrong. */
215 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
217 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
225 mdoc_macro2len(int macro
)