]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_strings.c
Back out OpenBSD special case (ok Ingo Schwarze).
[mandoc.git] / mdoc_strings.c
1 /* $Id: mdoc_strings.c,v 1.18 2010/05/09 21:06:50 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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/types.h>
22
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <time.h>
28
29 #include "libmdoc.h"
30
31 /* FIXME: this file is poorly named. */
32
33 struct mdoc_secname {
34 const char *name; /* Name of section. */
35 enum mdoc_sec sec; /* Corresponding section. */
36 };
37
38 #define SECNAME_MAX (20)
39
40 static const struct mdoc_secname secnames[SECNAME_MAX] = {
41 { "NAME", SEC_NAME },
42 { "LIBRARY", SEC_LIBRARY },
43 { "SYNOPSIS", SEC_SYNOPSIS },
44 { "DESCRIPTION", SEC_DESCRIPTION },
45 { "IMPLEMENTATION NOTES", SEC_IMPLEMENTATION },
46 { "EXIT STATUS", SEC_EXIT_STATUS },
47 { "RETURN VALUES", SEC_RETURN_VALUES },
48 { "ENVIRONMENT", SEC_ENVIRONMENT },
49 { "FILES", SEC_FILES },
50 { "EXAMPLES", SEC_EXAMPLES },
51 { "DIAGNOSTICS", SEC_DIAGNOSTICS },
52 { "COMPATIBILITY", SEC_COMPATIBILITY },
53 { "ERRORS", SEC_ERRORS },
54 { "SEE ALSO", SEC_SEE_ALSO },
55 { "STANDARDS", SEC_STANDARDS },
56 { "HISTORY", SEC_HISTORY },
57 { "AUTHORS", SEC_AUTHORS },
58 { "CAVEATS", SEC_CAVEATS },
59 { "BUGS", SEC_BUGS },
60 { "SECURITY CONSIDERATIONS", SEC_SECURITY }
61 };
62
63
64 /*
65 * FIXME: this is repeated in print_text() (html.c) and term_word()
66 * (term.c).
67 */
68 int
69 mdoc_iscdelim(char p)
70 {
71
72 switch (p) {
73 case('|'):
74 /* FALLTHROUGH */
75 case('('):
76 /* FALLTHROUGH */
77 case('['):
78 return(1);
79 case('.'):
80 /* FALLTHROUGH */
81 case(','):
82 /* FALLTHROUGH */
83 case(';'):
84 /* FALLTHROUGH */
85 case(':'):
86 /* FALLTHROUGH */
87 case('?'):
88 /* FALLTHROUGH */
89 case('!'):
90 /* FALLTHROUGH */
91 case(')'):
92 /* FALLTHROUGH */
93 case(']'):
94 return(2);
95 default:
96 break;
97 }
98
99 return(0);
100 }
101
102
103 int
104 mdoc_isdelim(const char *p)
105 {
106
107 if ('\0' == p[0])
108 return(0);
109 if ('\0' == p[1])
110 return(mdoc_iscdelim(p[0]));
111
112 /*
113 * XXX; account for groff bubu where the \*(Ba reserved string
114 * is treated in exactly the same way as the vertical bar. This
115 * is the only function that checks for this.
116 */
117 return(0 == strcmp(p, "\\*(Ba"));
118 }
119
120
121 enum mdoc_sec
122 mdoc_atosec(const char *p)
123 {
124 int i;
125
126 for (i = 0; i < SECNAME_MAX; i++)
127 if (0 == strcmp(p, secnames[i].name))
128 return(secnames[i].sec);
129
130 return(SEC_CUSTOM);
131 }
132
133
134 /* FIXME: move this into an editable .in file. */
135 size_t
136 mdoc_macro2len(enum mdoct macro)
137 {
138
139 switch (macro) {
140 case(MDOC_Ad):
141 return(12);
142 case(MDOC_Ao):
143 return(12);
144 case(MDOC_An):
145 return(12);
146 case(MDOC_Aq):
147 return(12);
148 case(MDOC_Ar):
149 return(12);
150 case(MDOC_Bo):
151 return(12);
152 case(MDOC_Bq):
153 return(12);
154 case(MDOC_Cd):
155 return(12);
156 case(MDOC_Cm):
157 return(10);
158 case(MDOC_Do):
159 return(10);
160 case(MDOC_Dq):
161 return(12);
162 case(MDOC_Dv):
163 return(12);
164 case(MDOC_Eo):
165 return(12);
166 case(MDOC_Em):
167 return(10);
168 case(MDOC_Er):
169 return(17);
170 case(MDOC_Ev):
171 return(15);
172 case(MDOC_Fa):
173 return(12);
174 case(MDOC_Fl):
175 return(10);
176 case(MDOC_Fo):
177 return(16);
178 case(MDOC_Fn):
179 return(16);
180 case(MDOC_Ic):
181 return(10);
182 case(MDOC_Li):
183 return(16);
184 case(MDOC_Ms):
185 return(6);
186 case(MDOC_Nm):
187 return(10);
188 case(MDOC_No):
189 return(12);
190 case(MDOC_Oo):
191 return(10);
192 case(MDOC_Op):
193 return(14);
194 case(MDOC_Pa):
195 return(32);
196 case(MDOC_Pf):
197 return(12);
198 case(MDOC_Po):
199 return(12);
200 case(MDOC_Pq):
201 return(12);
202 case(MDOC_Ql):
203 return(16);
204 case(MDOC_Qo):
205 return(12);
206 case(MDOC_So):
207 return(12);
208 case(MDOC_Sq):
209 return(12);
210 case(MDOC_Sy):
211 return(6);
212 case(MDOC_Sx):
213 return(16);
214 case(MDOC_Tn):
215 return(10);
216 case(MDOC_Va):
217 return(12);
218 case(MDOC_Vt):
219 return(12);
220 case(MDOC_Xr):
221 return(10);
222 default:
223 break;
224 };
225 return(0);
226 }