Import mdocml-1.10.9
[dragonfly.git] / contrib / mdocml / mdoc_strings.c
CommitLineData
80387638
SW
1/* $Id: mdoc_strings.c,v 1.24 2010/07/31 23:52:58 schwarze Exp $ */
2/*
3 * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
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 "mandoc.h"
30#include "libmdoc.h"
31
32static const char * const secnames[SEC__MAX] = {
33 NULL,
34 "NAME",
35 "LIBRARY",
36 "SYNOPSIS",
37 "DESCRIPTION",
38 "IMPLEMENTATION NOTES",
39 "RETURN VALUES",
40 "ENVIRONMENT",
41 "FILES",
42 "EXIT STATUS",
43 "EXAMPLES",
44 "DIAGNOSTICS",
45 "COMPATIBILITY",
46 "ERRORS",
47 "SEE ALSO",
48 "STANDARDS",
49 "HISTORY",
50 "AUTHORS",
51 "CAVEATS",
52 "BUGS",
53 "SECURITY CONSIDERATIONS",
54 NULL
55};
56
57/*
58 * FIXME: this is repeated in print_text() (html.c) and term_word()
59 * (term.c).
60 */
61enum mdelim
62mdoc_iscdelim(char p)
63{
64
65 switch (p) {
66 case('('):
67 /* FALLTHROUGH */
68 case('['):
69 return(DELIM_OPEN);
70 case('|'):
71 return(DELIM_MIDDLE);
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 return(DELIM_CLOSE);
88 default:
89 break;
90 }
91
92 return(DELIM_NONE);
93}
94
95
96enum mdelim
97mdoc_isdelim(const char *p)
98{
99
100 if ('\0' == p[0])
101 return(DELIM_NONE);
102 if ('\0' == p[1])
103 return(mdoc_iscdelim(p[0]));
104
105 /*
106 * XXX; account for groff bubu where the \*(Ba reserved string
107 * is treated in exactly the same way as the vertical bar. This
108 * is the only function that checks for this.
109 */
110 return(strcmp(p, "\\*(Ba") ? DELIM_NONE : DELIM_MIDDLE);
111}
112
113
114enum mdoc_sec
115mdoc_str2sec(const char *p)
116{
117 int i;
118
119 for (i = 0; i < (int)SEC__MAX; i++)
120 if (secnames[i] && 0 == strcmp(p, secnames[i]))
121 return((enum mdoc_sec)i);
122
123 return(SEC_CUSTOM);
124}
125
126
127/* FIXME: move this into an editable .in file. */
128size_t
129mdoc_macro2len(enum mdoct macro)
130{
131
132 switch (macro) {
133 case(MDOC_Ad):
134 return(12);
135 case(MDOC_Ao):
136 return(12);
137 case(MDOC_An):
138 return(12);
139 case(MDOC_Aq):
140 return(12);
141 case(MDOC_Ar):
142 return(12);
143 case(MDOC_Bo):
144 return(12);
145 case(MDOC_Bq):
146 return(12);
147 case(MDOC_Cd):
148 return(12);
149 case(MDOC_Cm):
150 return(10);
151 case(MDOC_Do):
152 return(10);
153 case(MDOC_Dq):
154 return(12);
155 case(MDOC_Dv):
156 return(12);
157 case(MDOC_Eo):
158 return(12);
159 case(MDOC_Em):
160 return(10);
161 case(MDOC_Er):
162 return(17);
163 case(MDOC_Ev):
164 return(15);
165 case(MDOC_Fa):
166 return(12);
167 case(MDOC_Fl):
168 return(10);
169 case(MDOC_Fo):
170 return(16);
171 case(MDOC_Fn):
172 return(16);
173 case(MDOC_Ic):
174 return(10);
175 case(MDOC_Li):
176 return(16);
177 case(MDOC_Ms):
178 return(6);
179 case(MDOC_Nm):
180 return(10);
181 case(MDOC_No):
182 return(12);
183 case(MDOC_Oo):
184 return(10);
185 case(MDOC_Op):
186 return(14);
187 case(MDOC_Pa):
188 return(32);
189 case(MDOC_Pf):
190 return(12);
191 case(MDOC_Po):
192 return(12);
193 case(MDOC_Pq):
194 return(12);
195 case(MDOC_Ql):
196 return(16);
197 case(MDOC_Qo):
198 return(12);
199 case(MDOC_So):
200 return(12);
201 case(MDOC_Sq):
202 return(12);
203 case(MDOC_Sy):
204 return(6);
205 case(MDOC_Sx):
206 return(16);
207 case(MDOC_Tn):
208 return(10);
209 case(MDOC_Va):
210 return(12);
211 case(MDOC_Vt):
212 return(12);
213 case(MDOC_Xr):
214 return(10);
215 default:
216 break;
217 };
218 return(0);
219}