]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_strings.c
Fixed re-adjustment of scope in exiting roff instructions (libman).
[mandoc.git] / mdoc_strings.c
1 /* $Id: mdoc_strings.c,v 1.14 2010/01/01 17:14:30 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 int
65 mdoc_iscdelim(char p)
66 {
67
68 switch (p) {
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 /* FALLTHROUGH */
91 case('{'):
92 /* FALLTHROUGH */
93 case('}'):
94 return(1);
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)
108 return(0);
109 if (0 != *(p + 1))
110 return(0);
111 return(mdoc_iscdelim(*p));
112 }
113
114
115 enum mdoc_sec
116 mdoc_atosec(const char *p)
117 {
118 int i;
119
120 for (i = 0; i < SECNAME_MAX; i++)
121 if (0 == strcmp(p, secnames[i].name))
122 return(secnames[i].sec);
123
124 return(SEC_CUSTOM);
125 }
126
127
128 /* FIXME: move this into an editable .in file. */
129 size_t
130 mdoc_macro2len(int macro)
131 {
132
133 switch (macro) {
134 case(MDOC_Ad):
135 return(12);
136 case(MDOC_Ao):
137 return(12);
138 case(MDOC_An):
139 return(12);
140 case(MDOC_Aq):
141 return(12);
142 case(MDOC_Ar):
143 return(12);
144 case(MDOC_Bo):
145 return(12);
146 case(MDOC_Bq):
147 return(12);
148 case(MDOC_Cd):
149 return(12);
150 case(MDOC_Cm):
151 return(10);
152 case(MDOC_Do):
153 return(10);
154 case(MDOC_Dq):
155 return(12);
156 case(MDOC_Dv):
157 return(12);
158 case(MDOC_Eo):
159 return(12);
160 case(MDOC_Em):
161 return(10);
162 case(MDOC_Er):
163 return(17);
164 case(MDOC_Ev):
165 return(15);
166 case(MDOC_Fa):
167 return(12);
168 case(MDOC_Fl):
169 return(10);
170 case(MDOC_Fo):
171 return(16);
172 case(MDOC_Fn):
173 return(16);
174 case(MDOC_Ic):
175 return(10);
176 case(MDOC_Li):
177 return(16);
178 case(MDOC_Ms):
179 return(6);
180 case(MDOC_Nm):
181 return(10);
182 case(MDOC_No):
183 return(12);
184 case(MDOC_Oo):
185 return(10);
186 case(MDOC_Op):
187 return(14);
188 case(MDOC_Pa):
189 return(32);
190 case(MDOC_Pf):
191 return(12);
192 case(MDOC_Po):
193 return(12);
194 case(MDOC_Pq):
195 return(12);
196 case(MDOC_Ql):
197 return(16);
198 case(MDOC_Qo):
199 return(12);
200 case(MDOC_So):
201 return(12);
202 case(MDOC_Sq):
203 return(12);
204 case(MDOC_Sy):
205 return(6);
206 case(MDOC_Sx):
207 return(16);
208 case(MDOC_Tn):
209 return(10);
210 case(MDOC_Va):
211 return(12);
212 case(MDOC_Vt):
213 return(12);
214 case(MDOC_Xr):
215 return(10);
216 default:
217 break;
218 };
219 return(0);
220 }