mandoc(1): Update to 1.9.13.
[dragonfly.git] / usr.bin / mandoc / mdoc_strings.c
CommitLineData
32c903ac 1/* $Id: mdoc_strings.c,v 1.13 2009/11/02 06:22:46 kristaps Exp $ */
589e7c1d
SW
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>
cbce6d97 23#include <time.h>
589e7c1d
SW
24
25#include "libmdoc.h"
26
27/* FIXME: this file is poorly named. */
28
29struct mdoc_secname {
30 const char *name; /* Name of section. */
31 enum mdoc_sec sec; /* Corresponding section. */
32};
33
34#define SECNAME_MAX (20)
35
36static const struct mdoc_secname secnames[SECNAME_MAX] = {
37 { "NAME", SEC_NAME },
38 { "LIBRARY", SEC_LIBRARY },
39 { "SYNOPSIS", SEC_SYNOPSIS },
40 { "DESCRIPTION", SEC_DESCRIPTION },
41 { "IMPLEMENTATION NOTES", SEC_IMPLEMENTATION },
42 { "EXIT STATUS", SEC_EXIT_STATUS },
43 { "RETURN VALUES", SEC_RETURN_VALUES },
44 { "ENVIRONMENT", SEC_ENVIRONMENT },
45 { "FILES", SEC_FILES },
46 { "EXAMPLES", SEC_EXAMPLES },
47 { "DIAGNOSTICS", SEC_DIAGNOSTICS },
48 { "COMPATIBILITY", SEC_COMPATIBILITY },
49 { "ERRORS", SEC_ERRORS },
50 { "SEE ALSO", SEC_SEE_ALSO },
51 { "STANDARDS", SEC_STANDARDS },
52 { "HISTORY", SEC_HISTORY },
53 { "AUTHORS", SEC_AUTHORS },
54 { "CAVEATS", SEC_CAVEATS },
55 { "BUGS", SEC_BUGS },
56 { "SECURITY CONSIDERATIONS", SEC_SECURITY }
57};
58
59
60int
61mdoc_iscdelim(char p)
62{
63
64 switch (p) {
65 case('|'):
66 /* FALLTHROUGH */
67 case('.'):
68 /* FALLTHROUGH */
69 case(','):
70 /* FALLTHROUGH */
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 /* FALLTHROUGH */
87 case('{'):
88 /* FALLTHROUGH */
89 case('}'):
90 return(1);
91 default:
92 break;
93 }
94
95 return(0);
96}
97
98
99int
100mdoc_isdelim(const char *p)
101{
102
103 if (0 == *p)
104 return(0);
105 if (0 != *(p + 1))
106 return(0);
107 return(mdoc_iscdelim(*p));
108}
109
110
111enum mdoc_sec
112mdoc_atosec(const char *p)
113{
114 int i;
115
116 for (i = 0; i < SECNAME_MAX; i++)
117 if (0 == strcmp(p, secnames[i].name))
118 return(secnames[i].sec);
119
120 return(SEC_CUSTOM);
121}
122
123
589e7c1d
SW
124/* FIXME: move this into an editable .in file. */
125size_t
126mdoc_macro2len(int macro)
127{
128
129 switch (macro) {
130 case(MDOC_Ad):
131 return(12);
132 case(MDOC_Ao):
133 return(12);
134 case(MDOC_An):
135 return(12);
136 case(MDOC_Aq):
137 return(12);
138 case(MDOC_Ar):
139 return(12);
140 case(MDOC_Bo):
141 return(12);
142 case(MDOC_Bq):
143 return(12);
144 case(MDOC_Cd):
145 return(12);
146 case(MDOC_Cm):
147 return(10);
148 case(MDOC_Do):
149 return(10);
150 case(MDOC_Dq):
151 return(12);
152 case(MDOC_Dv):
153 return(12);
154 case(MDOC_Eo):
155 return(12);
156 case(MDOC_Em):
157 return(10);
158 case(MDOC_Er):
32c903ac 159 return(17);
589e7c1d
SW
160 case(MDOC_Ev):
161 return(15);
162 case(MDOC_Fa):
163 return(12);
164 case(MDOC_Fl):
165 return(10);
166 case(MDOC_Fo):
167 return(16);
168 case(MDOC_Fn):
169 return(16);
170 case(MDOC_Ic):
171 return(10);
172 case(MDOC_Li):
173 return(16);
174 case(MDOC_Ms):
175 return(6);
176 case(MDOC_Nm):
177 return(10);
178 case(MDOC_No):
179 return(12);
180 case(MDOC_Oo):
181 return(10);
182 case(MDOC_Op):
183 return(14);
184 case(MDOC_Pa):
185 return(32);
186 case(MDOC_Pf):
187 return(12);
188 case(MDOC_Po):
189 return(12);
190 case(MDOC_Pq):
191 return(12);
192 case(MDOC_Ql):
193 return(16);
194 case(MDOC_Qo):
195 return(12);
196 case(MDOC_So):
197 return(12);
198 case(MDOC_Sq):
199 return(12);
200 case(MDOC_Sy):
201 return(6);
202 case(MDOC_Sx):
203 return(16);
204 case(MDOC_Tn):
205 return(10);
206 case(MDOC_Va):
207 return(12);
208 case(MDOC_Vt):
209 return(12);
210 case(MDOC_Xr):
211 return(10);
212 default:
213 break;
214 };
215 return(0);
216}