]> git.cameronkatri.com Git - mandoc.git/blob - literals.c
f4252e94bcd53462a57a850ba80aa064c436f6ed
[mandoc.git] / literals.c
1 /* $Id: literals.c,v 1.5 2008/12/09 17:09:12 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
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19 #include <assert.h>
20 #include <string.h>
21 #include <stdlib.h>
22
23 #include "private.h"
24
25 #define ROFF_ATTname_V1 "v1"
26 #define ROFF_ATTname_V2 "v1"
27 #define ROFF_ATTname_V3 "v3"
28 #define ROFF_ATTname_V6 "v6"
29 #define ROFF_ATTname_V7 "v7"
30 #define ROFF_ATTname_32V "32v"
31 #define ROFF_ATTname_V_1 "V.1"
32 #define ROFF_ATTname_V_4 "V.4"
33
34 #define ROFFSecname_NAME "NAME"
35 #define ROFFSecname_SYNOP "SYNOPSIS"
36 #define ROFFSecname_DESC "DESCRIPTION"
37 #define ROFFSecname_ENV "ENVIRONMENT"
38 #define ROFFSecname_FILES "FILES"
39 #define ROFFSecname_EX "EXAMPLES"
40 #define ROFFSecname_DIAG "DIAGNOSTICS"
41 #define ROFFSecname_ERRS "ERRORS"
42 #define ROFFSecname_STAND "STANDARDS"
43 #define ROFFSecname_HIST "HISTORY"
44 #define ROFFSecname_AUTH "AUTHORS"
45 #define ROFFSecname_CAVEATS "CAVEATS"
46 #define ROFFSecname_BUGS "BUGS"
47 #define ROFFSecname_RETVAL "RETURN VALUES"
48 #define ROFFSecname_RETVAL1 "RETURN"
49 #define ROFFSecname_RETVAL2 "VALUES"
50 #define ROFFSecname_SEEALSO "SEE ALSO"
51 #define ROFFSecname_SEEALSO1 "SEE"
52 #define ROFFSecname_SEEALSO2 "ALSO"
53
54 #define ROFF_MSECname_1 "1"
55 #define ROFF_MSECname_2 "2"
56 #define ROFF_MSECname_3 "3"
57 #define ROFF_MSECname_3p "3p"
58 #define ROFF_MSECname_4 "4"
59 #define ROFF_MSECname_5 "5"
60 #define ROFF_MSECname_6 "6"
61 #define ROFF_MSECname_7 "7"
62 #define ROFF_MSECname_8 "8"
63 #define ROFF_MSECname_9 "9"
64 #define ROFF_MSECname_UNASS "unass"
65 #define ROFF_MSECname_DRAFT "draft"
66 #define ROFF_MSECname_PAPER "paper"
67
68 int
69 roff_sec(const char **p)
70 {
71
72 assert(*p);
73 if (NULL != *(p + 1)) {
74 if (NULL != *(p + 2))
75 return(ROFFSec_OTHER);
76 if (0 == strcmp(*p, ROFFSecname_RETVAL1) &&
77 0 == strcmp(*(p + 1), ROFFSecname_RETVAL2))
78 return(ROFFSec_RETVAL);
79 if (0 == strcmp(*p, ROFFSecname_SEEALSO1) &&
80 0 == strcmp(*(p + 1), ROFFSecname_SEEALSO2))
81 return(ROFFSec_SEEALSO);
82 return(ROFFSec_OTHER);
83 }
84
85 if (0 == strcmp(*p, ROFFSecname_NAME))
86 return(ROFFSec_NAME);
87 else if (0 == strcmp(*p, ROFFSecname_SYNOP))
88 return(ROFFSec_SYNOP);
89 else if (0 == strcmp(*p, ROFFSecname_DESC))
90 return(ROFFSec_DESC);
91 else if (0 == strcmp(*p, ROFFSecname_ENV))
92 return(ROFFSec_ENV);
93 else if (0 == strcmp(*p, ROFFSecname_FILES))
94 return(ROFFSec_FILES);
95 else if (0 == strcmp(*p, ROFFSecname_EX))
96 return(ROFFSec_EX);
97 else if (0 == strcmp(*p, ROFFSecname_DIAG))
98 return(ROFFSec_DIAG);
99 else if (0 == strcmp(*p, ROFFSecname_ERRS))
100 return(ROFFSec_ERRS);
101 else if (0 == strcmp(*p, ROFFSecname_STAND))
102 return(ROFFSec_STAND);
103 else if (0 == strcmp(*p, ROFFSecname_HIST))
104 return(ROFFSec_HIST);
105 else if (0 == strcmp(*p, ROFFSecname_AUTH))
106 return(ROFFSec_AUTH);
107 else if (0 == strcmp(*p, ROFFSecname_CAVEATS))
108 return(ROFFSec_CAVEATS);
109 else if (0 == strcmp(*p, ROFFSecname_BUGS))
110 return(ROFFSec_BUGS);
111 else if (0 == strcmp(*p, ROFFSecname_RETVAL))
112 return(ROFFSec_RETVAL);
113 else if (0 == strcmp(*p, ROFFSecname_SEEALSO))
114 return(ROFFSec_SEEALSO);
115
116 return(ROFFSec_OTHER);
117 }
118
119
120 enum roffmsec
121 roff_msec(const char *p)
122 {
123
124 assert(p);
125 if (0 == strcmp(p, ROFF_MSECname_1))
126 return(ROFF_MSEC_1);
127 else if (0 == strcmp(p, ROFF_MSECname_2))
128 return(ROFF_MSEC_2);
129 else if (0 == strcmp(p, ROFF_MSECname_3))
130 return(ROFF_MSEC_3);
131 else if (0 == strcmp(p, ROFF_MSECname_3p))
132 return(ROFF_MSEC_3p);
133 else if (0 == strcmp(p, ROFF_MSECname_4))
134 return(ROFF_MSEC_4);
135 else if (0 == strcmp(p, ROFF_MSECname_5))
136 return(ROFF_MSEC_5);
137 else if (0 == strcmp(p, ROFF_MSECname_6))
138 return(ROFF_MSEC_6);
139 else if (0 == strcmp(p, ROFF_MSECname_7))
140 return(ROFF_MSEC_7);
141 else if (0 == strcmp(p, ROFF_MSECname_8))
142 return(ROFF_MSEC_8);
143 else if (0 == strcmp(p, ROFF_MSECname_9))
144 return(ROFF_MSEC_9);
145 else if (0 == strcmp(p, ROFF_MSECname_UNASS))
146 return(ROFF_MSEC_UNASS);
147 else if (0 == strcmp(p, ROFF_MSECname_DRAFT))
148 return(ROFF_MSEC_DRAFT);
149 else if (0 == strcmp(p, ROFF_MSECname_PAPER))
150 return(ROFF_MSEC_PAPER);
151
152 return(ROFF_MSEC_MAX);
153 }
154
155
156 char *
157 roff_msecname(enum roffmsec sec)
158 {
159
160 switch (sec) {
161 case(ROFF_MSEC_1):
162 return(ROFF_MSECname_1);
163 case(ROFF_MSEC_2):
164 return(ROFF_MSECname_2);
165 case(ROFF_MSEC_3):
166 return(ROFF_MSECname_3);
167 case(ROFF_MSEC_3p):
168 return(ROFF_MSECname_3p);
169 case(ROFF_MSEC_4):
170 return(ROFF_MSECname_4);
171 case(ROFF_MSEC_5):
172 return(ROFF_MSECname_5);
173 case(ROFF_MSEC_6):
174 return(ROFF_MSECname_6);
175 case(ROFF_MSEC_7):
176 return(ROFF_MSECname_7);
177 case(ROFF_MSEC_8):
178 return(ROFF_MSECname_8);
179 case(ROFF_MSEC_9):
180 return(ROFF_MSECname_9);
181 case(ROFF_MSEC_UNASS):
182 return(ROFF_MSECname_UNASS);
183 case(ROFF_MSEC_DRAFT):
184 return(ROFF_MSECname_DRAFT);
185 case(ROFF_MSEC_PAPER):
186 return(ROFF_MSECname_PAPER);
187 default:
188 break;
189 }
190
191 abort();
192 /* NOTREACHED */
193 }
194
195
196 char *
197 roff_fmtstring(int tok)
198 {
199
200 switch (tok) {
201 case (ROFF_Ex):
202 return ("The %s utility exits 0 on success, and "
203 ">0 if an error occurs.");
204 case (ROFF_Rv):
205 return ("The %s() function returns the value 0 if "
206 "successful; otherwise the value -1 "
207 "is returned and the global variable "
208 "errno is set to indicate the error.");
209 case (ROFF_In):
210 return("#include \\*(Lt%s\\*(Gt");
211 default:
212 break;
213 }
214
215 abort();
216 /* NOTREACHED */
217 }
218
219
220 char *
221 roff_literal(int tok, const int *argc,
222 const char **argv, const char **morep)
223 {
224
225 switch (tok) {
226 case (ROFF_At):
227 assert(NULL == *argv);
228 assert(ROFF_ARGMAX == *argc);
229 if (NULL == *morep)
230 return("AT&T UNIX");
231
232 switch (roff_att(*morep)) {
233 case (ROFF_ATT_V1):
234 return("Version 1 AT&T UNIX");
235 case (ROFF_ATT_V2):
236 return("Version 2 AT&T UNIX");
237 case (ROFF_ATT_V3):
238 return("Version 3 AT&T UNIX");
239 case (ROFF_ATT_V6):
240 return("Version 6 AT&T UNIX");
241 case (ROFF_ATT_V7):
242 return("Version 7 AT&T UNIX");
243 case (ROFF_ATT_32V):
244 return("Version 32v AT&T UNIX");
245 case (ROFF_ATT_V_1):
246 return("AT&T System V.1 UNIX");
247 case (ROFF_ATT_V_4):
248 return("AT&T System V.4 UNIX");
249 default:
250 break;
251 }
252
253 abort();
254 /* NOTREACHED */
255
256 case (ROFF_St):
257 assert(ROFF_ARGMAX != *argc);
258 assert(NULL == *argv);
259 switch (*argc) {
260 case(ROFF_p1003_1_88):
261 return("IEEE Std 1003.1-1988 "
262 "(\\*(LqPOSIX\\*(Rq)");
263 case(ROFF_p1003_1_90):
264 return("IEEE Std 1003.1-1990 "
265 "(\\*(LqPOSIX\\*(Rq)");
266 case(ROFF_p1003_1_96):
267 return("ISO/IEC 9945-1:1996 "
268 "(\\*(LqPOSIX\\*(Rq)");
269 case(ROFF_p1003_1_2001):
270 return("IEEE Std 1003.1-2001 "
271 "(\\*(LqPOSIX\\*(Rq)");
272 case(ROFF_p1003_1_2004):
273 return("IEEE Std 1003.1-2004 "
274 "(\\*(LqPOSIX\\*(Rq)");
275 case(ROFF_p1003_1):
276 return("IEEE Std 1003.1 "
277 "(\\*(LqPOSIX\\*(Rq)");
278 case(ROFF_p1003_1b):
279 return("IEEE Std 1003.1b "
280 "(\\*(LqPOSIX\\*(Rq)");
281 case(ROFF_p1003_1b_93):
282 return("IEEE Std 1003.1b-1993 "
283 "(\\*(LqPOSIX\\*(Rq)");
284 case(ROFF_p1003_1c_95):
285 return("IEEE Std 1003.1c-1995 "
286 "(\\*(LqPOSIX\\*(Rq)");
287 case(ROFF_p1003_1g_2000):
288 return("IEEE Std 1003.1g-2000 "
289 "(\\*(LqPOSIX\\*(Rq)");
290 case(ROFF_p1003_2_92):
291 return("IEEE Std 1003.2-1992 "
292 "(\\*(LqPOSIX.2\\*(Rq)");
293 case(ROFF_p1387_2_95):
294 return("IEEE Std 1387.2-1995 "
295 "(\\*(LqPOSIX.7.2\\*(Rq)");
296 case(ROFF_p1003_2):
297 return("IEEE Std 1003.2 "
298 "(\\*(LqPOSIX.2\\*(Rq)");
299 case(ROFF_p1387_2):
300 return("IEEE Std 1387.2 "
301 "(\\*(LqPOSIX.7.2\\*(Rq)");
302 case(ROFF_isoC_90):
303 return("ISO/IEC 9899:1990 "
304 "(\\*(LqISO C90\\*(Rq)");
305 case(ROFF_isoC_amd1):
306 return("ISO/IEC 9899/AMD1:1995 "
307 "(\\*(LqISO C90\\*(Rq)");
308 case(ROFF_isoC_tcor1):
309 return("ISO/IEC 9899/TCOR1:1994 "
310 "(\\*(LqISO C90\\*(Rq)");
311 case(ROFF_isoC_tcor2):
312 return("ISO/IEC 9899/TCOR2:1995 "
313 "(\\*(LqISO C90\\*(Rq)");
314 case(ROFF_isoC_99):
315 return("ISO/IEC 9899:1999 "
316 "(\\*(LqISO C99\\*(Rq)");
317 case(ROFF_ansiC):
318 return("ANSI X3.159-1989 "
319 "(\\*(LqANSI C\\*(Rq)");
320 case(ROFF_ansiC_89):
321 return("ANSI X3.159-1989 "
322 "(\\*(LqANSI C\\*(Rq)");
323 case(ROFF_ansiC_99):
324 return("ANSI/ISO/IEC 9899-1999 "
325 "(\\*(LqANSI C99\\*(Rq)");
326 case(ROFF_ieee754):
327 return("IEEE Std 754-1985");
328 case(ROFF_iso8802_3):
329 return("ISO 8802-3: 1989");
330 case(ROFF_xpg3):
331 return("X/Open Portability Guide Issue 3 "
332 "(\\*(LqXPG3\\*(Rq)");
333 case(ROFF_xpg4):
334 return("X/Open Portability Guide Issue 4 "
335 "(\\*(LqXPG4\\*(Rq)");
336 case(ROFF_xpg4_2):
337 return("X/Open Portability Guide Issue 4.2 "
338 "(\\*(LqXPG4.2\\*(Rq)");
339 case(ROFF_xpg4_3):
340 return("X/Open Portability Guide Issue 4.3 "
341 "(\\*(LqXPG4.3\\*(Rq)");
342 case(ROFF_xbd5):
343 return("X/Open System Interface Definitions "
344 "Issue 5 (\\*(LqXBD5\\*(Rq)");
345 case(ROFF_xcu5):
346 return("X/Open Commands and Utilities Issue 5 "
347 "(\\*(LqXCU5\\*(Rq)");
348 case(ROFF_xsh5):
349 return("X/Open System Interfaces and Headers "
350 "Issue 5 (\\*(LqXSH5\\*(Rq)");
351 case(ROFF_xns5):
352 return("X/Open Networking Services Issue 5 "
353 "(\\*(LqXNS5\\*(Rq)");
354 case(ROFF_xns5_2d2_0):
355 return("X/Open Networking Services "
356 "Issue 5.2 Draft 2.0 "
357 "(\\*(LqXNS5.2D2.0\\*(Rq)");
358 case(ROFF_xcurses4_2):
359 return("X/Open Curses Issue 4 Version 2 "
360 "(\\*(LqXCURSES4.2\\*(Rq)");
361 case(ROFF_susv2):
362 return("Version 2 of the Single "
363 "UNIX Specification");
364 case(ROFF_susv3):
365 return("Version 3 of the Single "
366 "UNIX Specification");
367 case(ROFF_svid4):
368 return("System V Interface Definition, Fourth "
369 "Edition (\\*(LqSVID4\\*(Rq)");
370 default:
371 break;
372 }
373 abort();
374 /* NOTREACHED */
375
376 case (ROFF_Bt):
377 return("is currently in beta test.");
378 case (ROFF_Ud):
379 return("currently under development.");
380 case (ROFF_Fx):
381 return("FreeBSD");
382 case (ROFF_Nx):
383 return("NetBSD");
384 case (ROFF_Ox):
385 return("OpenBSD");
386 case (ROFF_Ux):
387 return("UNIX");
388 case (ROFF_Bx):
389 return("BSD");
390 case (ROFF_Bsx):
391 return("BSDI BSD/OS");
392 default:
393 break;
394 }
395
396 abort();
397 /* NOTREACHED */
398 }
399
400
401 enum roffatt
402 roff_att(const char *p)
403 {
404
405 assert(p);
406 if (0 == strcmp(p, ROFF_ATTname_V1))
407 return(ROFF_ATT_V1);
408 else if (0 == strcmp(p, ROFF_ATTname_V2))
409 return(ROFF_ATT_V2);
410 else if (0 == strcmp(p, ROFF_ATTname_V3))
411 return(ROFF_ATT_V3);
412 else if (0 == strcmp(p, ROFF_ATTname_V6))
413 return(ROFF_ATT_V6);
414 else if (0 == strcmp(p, ROFF_ATTname_V7))
415 return(ROFF_ATT_V7);
416 else if (0 == strcmp(p, ROFF_ATTname_32V))
417 return(ROFF_ATT_32V);
418 else if (0 == strcmp(p, ROFF_ATTname_V_1))
419 return(ROFF_ATT_V_1);
420 else if (0 == strcmp(p, ROFF_ATTname_V_4))
421 return(ROFF_ATT_V_4);
422
423 return(ROFF_ATT_MAX);
424 }
425