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