]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_strings.c
Make args_checkpunct() use mdoc_isdelim() instead of mdoc_iscdelim(),
[mandoc.git] / mdoc_strings.c
1 /* $Id: mdoc_strings.c,v 1.25 2011/03/17 01:23:29 kristaps 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
32 static 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 enum mdelim
58 mdoc_isdelim(const char *p)
59 {
60
61 if ('\0' == p[0])
62 return(DELIM_NONE);
63
64 if ('\0' == p[1])
65 switch (p[0]) {
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 return(DELIM_NONE);
90 }
91
92 /*
93 * XXX; account for groff bubu where the \*(Ba reserved string
94 * is treated in exactly the same way as the vertical bar. This
95 * is the only function that checks for this.
96 */
97 return(strcmp(p, "\\*(Ba") ? DELIM_NONE : DELIM_MIDDLE);
98 }
99
100
101 enum mdoc_sec
102 mdoc_str2sec(const char *p)
103 {
104 int i;
105
106 for (i = 0; i < (int)SEC__MAX; i++)
107 if (secnames[i] && 0 == strcmp(p, secnames[i]))
108 return((enum mdoc_sec)i);
109
110 return(SEC_CUSTOM);
111 }
112
113
114 /* FIXME: move this into an editable .in file. */
115 size_t
116 mdoc_macro2len(enum mdoct macro)
117 {
118
119 switch (macro) {
120 case(MDOC_Ad):
121 return(12);
122 case(MDOC_Ao):
123 return(12);
124 case(MDOC_An):
125 return(12);
126 case(MDOC_Aq):
127 return(12);
128 case(MDOC_Ar):
129 return(12);
130 case(MDOC_Bo):
131 return(12);
132 case(MDOC_Bq):
133 return(12);
134 case(MDOC_Cd):
135 return(12);
136 case(MDOC_Cm):
137 return(10);
138 case(MDOC_Do):
139 return(10);
140 case(MDOC_Dq):
141 return(12);
142 case(MDOC_Dv):
143 return(12);
144 case(MDOC_Eo):
145 return(12);
146 case(MDOC_Em):
147 return(10);
148 case(MDOC_Er):
149 return(17);
150 case(MDOC_Ev):
151 return(15);
152 case(MDOC_Fa):
153 return(12);
154 case(MDOC_Fl):
155 return(10);
156 case(MDOC_Fo):
157 return(16);
158 case(MDOC_Fn):
159 return(16);
160 case(MDOC_Ic):
161 return(10);
162 case(MDOC_Li):
163 return(16);
164 case(MDOC_Ms):
165 return(6);
166 case(MDOC_Nm):
167 return(10);
168 case(MDOC_No):
169 return(12);
170 case(MDOC_Oo):
171 return(10);
172 case(MDOC_Op):
173 return(14);
174 case(MDOC_Pa):
175 return(32);
176 case(MDOC_Pf):
177 return(12);
178 case(MDOC_Po):
179 return(12);
180 case(MDOC_Pq):
181 return(12);
182 case(MDOC_Ql):
183 return(16);
184 case(MDOC_Qo):
185 return(12);
186 case(MDOC_So):
187 return(12);
188 case(MDOC_Sq):
189 return(12);
190 case(MDOC_Sy):
191 return(6);
192 case(MDOC_Sx):
193 return(16);
194 case(MDOC_Tn):
195 return(10);
196 case(MDOC_Va):
197 return(12);
198 case(MDOC_Vt):
199 return(12);
200 case(MDOC_Xr):
201 return(10);
202 default:
203 break;
204 };
205 return(0);
206 }