]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_strings.c
`An' gives correct error message in encountering arguments/parameters.
[mandoc.git] / mdoc_strings.c
1 /* $Id: mdoc_strings.c,v 1.9 2009/07/04 09:01:55 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
4 *
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.
8 *
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.
16 */
17 #include <sys/types.h>
18
19 #include <assert.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "libmdoc.h"
25
26 /* FIXME: this file is poorly named. */
27
28 struct mdoc_secname {
29 const char *name; /* Name of section. */
30 enum mdoc_sec sec; /* Corresponding section. */
31 };
32
33 #define SECNAME_MAX (18)
34
35 static const struct mdoc_secname secnames[SECNAME_MAX] = {
36 { "NAME", SEC_NAME },
37 { "LIBRARY", SEC_LIBRARY },
38 { "SYNOPSIS", SEC_SYNOPSIS },
39 { "DESCRIPTION", SEC_DESCRIPTION },
40 { "IMPLEMENTATION NOTES", SEC_IMPLEMENTATION },
41 { "RETURN VALUES", SEC_RETURN_VALUES },
42 { "ENVIRONMENT", SEC_ENVIRONMENT },
43 { "FILES", SEC_FILES },
44 { "EXAMPLES", SEC_EXAMPLES },
45 { "DIAGNOSTICS", SEC_DIAGNOSTICS },
46 { "COMPATIBILITY", SEC_COMPATIBILITY },
47 { "ERRORS", SEC_ERRORS },
48 { "SEE ALSO", SEC_SEE_ALSO },
49 { "STANDARDS", SEC_STANDARDS },
50 { "HISTORY", SEC_HISTORY },
51 { "AUTHORS", SEC_AUTHORS },
52 { "CAVEATS", SEC_CAVEATS },
53 { "BUGS", SEC_BUGS },
54 };
55
56 #ifdef __linux__
57 extern char *strptime(const char *, const char *, struct tm *);
58 #endif
59
60
61 int
62 mdoc_iscdelim(char p)
63 {
64
65 switch (p) {
66 case('|'):
67 /* FALLTHROUGH */
68 case('.'):
69 /* FALLTHROUGH */
70 case(','):
71 /* FALLTHROUGH */
72 case(';'):
73 /* FALLTHROUGH */
74 case(':'):
75 /* FALLTHROUGH */
76 case('?'):
77 /* FALLTHROUGH */
78 case('!'):
79 /* FALLTHROUGH */
80 case('('):
81 /* FALLTHROUGH */
82 case(')'):
83 /* FALLTHROUGH */
84 case('['):
85 /* FALLTHROUGH */
86 case(']'):
87 /* FALLTHROUGH */
88 case('{'):
89 /* FALLTHROUGH */
90 case('}'):
91 return(1);
92 default:
93 break;
94 }
95
96 return(0);
97 }
98
99
100 int
101 mdoc_isdelim(const char *p)
102 {
103
104 if (0 == *p)
105 return(0);
106 if (0 != *(p + 1))
107 return(0);
108 return(mdoc_iscdelim(*p));
109 }
110
111
112 enum mdoc_sec
113 mdoc_atosec(const char *p)
114 {
115 int i;
116
117 for (i = 0; i < SECNAME_MAX; i++)
118 if (0 == strcmp(p, secnames[i].name))
119 return(secnames[i].sec);
120
121 return(SEC_CUSTOM);
122 }
123
124
125 time_t
126 mdoc_atotime(const char *p)
127 {
128 struct tm tm;
129 char *pp;
130
131 bzero(&tm, sizeof(struct tm));
132
133 if (0 == strcmp(p, "$" "Mdocdate$"))
134 return(time(NULL));
135 if ((pp = strptime(p, "$" "Mdocdate: %b %d %Y $", &tm)) && 0 == *pp)
136 return(mktime(&tm));
137 /* XXX - this matches "June 1999", which is wrong. */
138 if ((pp = strptime(p, "%b %d %Y", &tm)) && 0 == *pp)
139 return(mktime(&tm));
140 if ((pp = strptime(p, "%b %d, %Y", &tm)) && 0 == *pp)
141 return(mktime(&tm));
142
143 return(0);
144 }
145
146
147 /* FIXME: move this into an editable .in file. */
148 size_t
149 mdoc_macro2len(int macro)
150 {
151
152 switch (macro) {
153 case(MDOC_Ad):
154 return(12);
155 case(MDOC_Ao):
156 return(12);
157 case(MDOC_An):
158 return(12);
159 case(MDOC_Aq):
160 return(12);
161 case(MDOC_Ar):
162 return(12);
163 case(MDOC_Bo):
164 return(12);
165 case(MDOC_Bq):
166 return(12);
167 case(MDOC_Cd):
168 return(12);
169 case(MDOC_Cm):
170 return(10);
171 case(MDOC_Do):
172 return(10);
173 case(MDOC_Dq):
174 return(12);
175 case(MDOC_Dv):
176 return(12);
177 case(MDOC_Eo):
178 return(12);
179 case(MDOC_Em):
180 return(10);
181 case(MDOC_Er):
182 return(17);
183 case(MDOC_Ev):
184 return(15);
185 case(MDOC_Fa):
186 return(12);
187 case(MDOC_Fl):
188 return(10);
189 case(MDOC_Fo):
190 return(16);
191 case(MDOC_Fn):
192 return(16);
193 case(MDOC_Ic):
194 return(10);
195 case(MDOC_Li):
196 return(16);
197 case(MDOC_Ms):
198 return(6);
199 case(MDOC_Nm):
200 return(10);
201 case(MDOC_No):
202 return(12);
203 case(MDOC_Oo):
204 return(10);
205 case(MDOC_Op):
206 return(14);
207 case(MDOC_Pa):
208 return(32);
209 case(MDOC_Pf):
210 return(12);
211 case(MDOC_Po):
212 return(12);
213 case(MDOC_Pq):
214 return(12);
215 case(MDOC_Ql):
216 return(16);
217 case(MDOC_Qo):
218 return(12);
219 case(MDOC_So):
220 return(12);
221 case(MDOC_Sq):
222 return(12);
223 case(MDOC_Sy):
224 return(6);
225 case(MDOC_Sx):
226 return(16);
227 case(MDOC_Tn):
228 return(10);
229 case(MDOC_Va):
230 return(12);
231 case(MDOC_Vt):
232 return(12);
233 case(MDOC_Xr):
234 return(10);
235 default:
236 break;
237 };
238 return(0);
239 }