]> git.cameronkatri.com Git - mandoc.git/blob - literals.c
*** empty log message ***
[mandoc.git] / literals.c
1 /* $Id: literals.c,v 1.7 2008/12/10 10:43:57 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 "v2"
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 #define ROFF_VOLname_AMD "AMD"
69 #define ROFF_VOLname_IND "IND"
70 #define ROFF_VOLname_KM "KM"
71 #define ROFF_VOLname_LOCAL "LOCAL"
72 #define ROFF_VOLname_PRM "PRM"
73 #define ROFF_VOLname_PS1 "PS1"
74 #define ROFF_VOLname_SMM "SMM"
75 #define ROFF_VOLname_URM "URM"
76 #define ROFF_VOLname_USD "USD"
77 #define ROFF_ARCHname_ALPHA "alpha"
78 #define ROFF_ARCHname_AMD64 "amd64"
79 #define ROFF_ARCHname_AMIGA "amiga"
80 #define ROFF_ARCHname_ARC "arc"
81 #define ROFF_ARCHname_ARMISH "armish"
82 #define ROFF_ARCHname_AVIION "aviion"
83 #define ROFF_ARCHname_HP300 "hp300"
84 #define ROFF_ARCHname_HPPA "hppa"
85 #define ROFF_ARCHname_HPPA64 "hppa64"
86 #define ROFF_ARCHname_I386 "i386"
87 #define ROFF_ARCHname_LANDISK "landisk"
88 #define ROFF_ARCHname_LUNA88K "luna88k"
89 #define ROFF_ARCHname_MAC68K "mac68k"
90 #define ROFF_ARCHname_MACPPC "macppc"
91 #define ROFF_ARCHname_MVME68K "mvme68k"
92 #define ROFF_ARCHname_MVME88K "mvme88k"
93 #define ROFF_ARCHname_MVMEPPC "mvmeppc"
94 #define ROFF_ARCHname_PMAX "pmax"
95 #define ROFF_ARCHname_SGI "sgi"
96 #define ROFF_ARCHname_SPARC "sparc"
97 #define ROFF_ARCHname_SPARC64 "sparc64"
98 #define ROFF_ARCHname_SUN3 "sun3"
99 #define ROFF_ARCHname_VAX "vax"
100 #define ROFF_ARCHname_ZAURUS "zaurus"
101
102 int
103 roff_sec(const char **p)
104 {
105
106 assert(*p);
107 if (NULL != *(p + 1)) {
108 if (NULL != *(p + 2))
109 return(ROFFSec_OTHER);
110 if (0 == strcmp(*p, ROFFSecname_RETVAL1) &&
111 0 == strcmp(*(p + 1), ROFFSecname_RETVAL2))
112 return(ROFFSec_RETVAL);
113 if (0 == strcmp(*p, ROFFSecname_SEEALSO1) &&
114 0 == strcmp(*(p + 1), ROFFSecname_SEEALSO2))
115 return(ROFFSec_SEEALSO);
116 return(ROFFSec_OTHER);
117 }
118
119 if (0 == strcmp(*p, ROFFSecname_NAME))
120 return(ROFFSec_NAME);
121 else if (0 == strcmp(*p, ROFFSecname_SYNOP))
122 return(ROFFSec_SYNOP);
123 else if (0 == strcmp(*p, ROFFSecname_DESC))
124 return(ROFFSec_DESC);
125 else if (0 == strcmp(*p, ROFFSecname_ENV))
126 return(ROFFSec_ENV);
127 else if (0 == strcmp(*p, ROFFSecname_FILES))
128 return(ROFFSec_FILES);
129 else if (0 == strcmp(*p, ROFFSecname_EX))
130 return(ROFFSec_EX);
131 else if (0 == strcmp(*p, ROFFSecname_DIAG))
132 return(ROFFSec_DIAG);
133 else if (0 == strcmp(*p, ROFFSecname_ERRS))
134 return(ROFFSec_ERRS);
135 else if (0 == strcmp(*p, ROFFSecname_STAND))
136 return(ROFFSec_STAND);
137 else if (0 == strcmp(*p, ROFFSecname_HIST))
138 return(ROFFSec_HIST);
139 else if (0 == strcmp(*p, ROFFSecname_AUTH))
140 return(ROFFSec_AUTH);
141 else if (0 == strcmp(*p, ROFFSecname_CAVEATS))
142 return(ROFFSec_CAVEATS);
143 else if (0 == strcmp(*p, ROFFSecname_BUGS))
144 return(ROFFSec_BUGS);
145 else if (0 == strcmp(*p, ROFFSecname_RETVAL))
146 return(ROFFSec_RETVAL);
147 else if (0 == strcmp(*p, ROFFSecname_SEEALSO))
148 return(ROFFSec_SEEALSO);
149
150 return(ROFFSec_OTHER);
151 }
152
153
154 enum roffmsec
155 roff_msec(const char *p)
156 {
157
158 assert(p);
159 if (0 == strcmp(p, ROFF_MSECname_1))
160 return(ROFF_MSEC_1);
161 else if (0 == strcmp(p, ROFF_MSECname_2))
162 return(ROFF_MSEC_2);
163 else if (0 == strcmp(p, ROFF_MSECname_3))
164 return(ROFF_MSEC_3);
165 else if (0 == strcmp(p, ROFF_MSECname_3p))
166 return(ROFF_MSEC_3p);
167 else if (0 == strcmp(p, ROFF_MSECname_4))
168 return(ROFF_MSEC_4);
169 else if (0 == strcmp(p, ROFF_MSECname_5))
170 return(ROFF_MSEC_5);
171 else if (0 == strcmp(p, ROFF_MSECname_6))
172 return(ROFF_MSEC_6);
173 else if (0 == strcmp(p, ROFF_MSECname_7))
174 return(ROFF_MSEC_7);
175 else if (0 == strcmp(p, ROFF_MSECname_8))
176 return(ROFF_MSEC_8);
177 else if (0 == strcmp(p, ROFF_MSECname_9))
178 return(ROFF_MSEC_9);
179 else if (0 == strcmp(p, ROFF_MSECname_UNASS))
180 return(ROFF_MSEC_UNASS);
181 else if (0 == strcmp(p, ROFF_MSECname_DRAFT))
182 return(ROFF_MSEC_DRAFT);
183 else if (0 == strcmp(p, ROFF_MSECname_PAPER))
184 return(ROFF_MSEC_PAPER);
185
186 return(ROFF_MSEC_MAX);
187 }
188
189
190 char *
191 roff_msecname(enum roffmsec sec)
192 {
193
194 switch (sec) {
195 case(ROFF_MSEC_1):
196 return(ROFF_MSECname_1);
197 case(ROFF_MSEC_2):
198 return(ROFF_MSECname_2);
199 case(ROFF_MSEC_3):
200 return(ROFF_MSECname_3);
201 case(ROFF_MSEC_3p):
202 return(ROFF_MSECname_3p);
203 case(ROFF_MSEC_4):
204 return(ROFF_MSECname_4);
205 case(ROFF_MSEC_5):
206 return(ROFF_MSECname_5);
207 case(ROFF_MSEC_6):
208 return(ROFF_MSECname_6);
209 case(ROFF_MSEC_7):
210 return(ROFF_MSECname_7);
211 case(ROFF_MSEC_8):
212 return(ROFF_MSECname_8);
213 case(ROFF_MSEC_9):
214 return(ROFF_MSECname_9);
215 case(ROFF_MSEC_UNASS):
216 return(ROFF_MSECname_UNASS);
217 case(ROFF_MSEC_DRAFT):
218 return(ROFF_MSECname_DRAFT);
219 case(ROFF_MSEC_PAPER):
220 return(ROFF_MSECname_PAPER);
221 default:
222 break;
223 }
224
225 abort();
226 /* NOTREACHED */
227 }
228
229
230 char *
231 roff_fmtstring(int tok)
232 {
233
234 switch (tok) {
235 case (ROFF_Ex):
236 return ("The %s utility exits 0 on success, and "
237 ">0 if an error occurs.");
238 case (ROFF_Rv):
239 return ("The %s() function returns the value 0 if "
240 "successful; otherwise the value -1 "
241 "is returned and the global variable "
242 "errno is set to indicate the error.");
243 case (ROFF_In):
244 return("#include \\*(Lt%s\\*(Gt");
245 default:
246 break;
247 }
248
249 abort();
250 /* NOTREACHED */
251 }
252
253
254 char *
255 roff_literal(int tok, const int *argc,
256 const char **argv, const char **morep)
257 {
258
259 switch (tok) {
260 case (ROFF_At):
261 assert(NULL == *argv);
262 assert(ROFF_ARGMAX == *argc);
263 if (NULL == *morep)
264 return("AT&T UNIX");
265
266 switch (roff_att(*morep)) {
267 case (ROFF_ATT_V1):
268 return("Version 1 AT&T UNIX");
269 case (ROFF_ATT_V2):
270 return("Version 2 AT&T UNIX");
271 case (ROFF_ATT_V3):
272 return("Version 3 AT&T UNIX");
273 case (ROFF_ATT_V6):
274 return("Version 6 AT&T UNIX");
275 case (ROFF_ATT_V7):
276 return("Version 7 AT&T UNIX");
277 case (ROFF_ATT_32V):
278 return("Version 32v AT&T UNIX");
279 case (ROFF_ATT_V_1):
280 return("AT&T System V.1 UNIX");
281 case (ROFF_ATT_V_4):
282 return("AT&T System V.4 UNIX");
283 default:
284 break;
285 }
286
287 abort();
288 /* NOTREACHED */
289
290 case (ROFF_St):
291 assert(ROFF_ARGMAX != *argc);
292 assert(NULL == *argv);
293 switch (*argc) {
294 case(ROFF_p1003_1_88):
295 return("IEEE Std 1003.1-1988 "
296 "(\\*(LqPOSIX\\*(Rq)");
297 case(ROFF_p1003_1_90):
298 return("IEEE Std 1003.1-1990 "
299 "(\\*(LqPOSIX\\*(Rq)");
300 case(ROFF_p1003_1_96):
301 return("ISO/IEC 9945-1:1996 "
302 "(\\*(LqPOSIX\\*(Rq)");
303 case(ROFF_p1003_1_2001):
304 return("IEEE Std 1003.1-2001 "
305 "(\\*(LqPOSIX\\*(Rq)");
306 case(ROFF_p1003_1_2004):
307 return("IEEE Std 1003.1-2004 "
308 "(\\*(LqPOSIX\\*(Rq)");
309 case(ROFF_p1003_1):
310 return("IEEE Std 1003.1 "
311 "(\\*(LqPOSIX\\*(Rq)");
312 case(ROFF_p1003_1b):
313 return("IEEE Std 1003.1b "
314 "(\\*(LqPOSIX\\*(Rq)");
315 case(ROFF_p1003_1b_93):
316 return("IEEE Std 1003.1b-1993 "
317 "(\\*(LqPOSIX\\*(Rq)");
318 case(ROFF_p1003_1c_95):
319 return("IEEE Std 1003.1c-1995 "
320 "(\\*(LqPOSIX\\*(Rq)");
321 case(ROFF_p1003_1g_2000):
322 return("IEEE Std 1003.1g-2000 "
323 "(\\*(LqPOSIX\\*(Rq)");
324 case(ROFF_p1003_2_92):
325 return("IEEE Std 1003.2-1992 "
326 "(\\*(LqPOSIX.2\\*(Rq)");
327 case(ROFF_p1387_2_95):
328 return("IEEE Std 1387.2-1995 "
329 "(\\*(LqPOSIX.7.2\\*(Rq)");
330 case(ROFF_p1003_2):
331 return("IEEE Std 1003.2 "
332 "(\\*(LqPOSIX.2\\*(Rq)");
333 case(ROFF_p1387_2):
334 return("IEEE Std 1387.2 "
335 "(\\*(LqPOSIX.7.2\\*(Rq)");
336 case(ROFF_isoC_90):
337 return("ISO/IEC 9899:1990 "
338 "(\\*(LqISO C90\\*(Rq)");
339 case(ROFF_isoC_amd1):
340 return("ISO/IEC 9899/AMD1:1995 "
341 "(\\*(LqISO C90\\*(Rq)");
342 case(ROFF_isoC_tcor1):
343 return("ISO/IEC 9899/TCOR1:1994 "
344 "(\\*(LqISO C90\\*(Rq)");
345 case(ROFF_isoC_tcor2):
346 return("ISO/IEC 9899/TCOR2:1995 "
347 "(\\*(LqISO C90\\*(Rq)");
348 case(ROFF_isoC_99):
349 return("ISO/IEC 9899:1999 "
350 "(\\*(LqISO C99\\*(Rq)");
351 case(ROFF_ansiC):
352 return("ANSI X3.159-1989 "
353 "(\\*(LqANSI C\\*(Rq)");
354 case(ROFF_ansiC_89):
355 return("ANSI X3.159-1989 "
356 "(\\*(LqANSI C\\*(Rq)");
357 case(ROFF_ansiC_99):
358 return("ANSI/ISO/IEC 9899-1999 "
359 "(\\*(LqANSI C99\\*(Rq)");
360 case(ROFF_ieee754):
361 return("IEEE Std 754-1985");
362 case(ROFF_iso8802_3):
363 return("ISO 8802-3: 1989");
364 case(ROFF_xpg3):
365 return("X/Open Portability Guide Issue 3 "
366 "(\\*(LqXPG3\\*(Rq)");
367 case(ROFF_xpg4):
368 return("X/Open Portability Guide Issue 4 "
369 "(\\*(LqXPG4\\*(Rq)");
370 case(ROFF_xpg4_2):
371 return("X/Open Portability Guide Issue 4.2 "
372 "(\\*(LqXPG4.2\\*(Rq)");
373 case(ROFF_xpg4_3):
374 return("X/Open Portability Guide Issue 4.3 "
375 "(\\*(LqXPG4.3\\*(Rq)");
376 case(ROFF_xbd5):
377 return("X/Open System Interface Definitions "
378 "Issue 5 (\\*(LqXBD5\\*(Rq)");
379 case(ROFF_xcu5):
380 return("X/Open Commands and Utilities Issue 5 "
381 "(\\*(LqXCU5\\*(Rq)");
382 case(ROFF_xsh5):
383 return("X/Open System Interfaces and Headers "
384 "Issue 5 (\\*(LqXSH5\\*(Rq)");
385 case(ROFF_xns5):
386 return("X/Open Networking Services Issue 5 "
387 "(\\*(LqXNS5\\*(Rq)");
388 case(ROFF_xns5_2d2_0):
389 return("X/Open Networking Services "
390 "Issue 5.2 Draft 2.0 "
391 "(\\*(LqXNS5.2D2.0\\*(Rq)");
392 case(ROFF_xcurses4_2):
393 return("X/Open Curses Issue 4 Version 2 "
394 "(\\*(LqXCURSES4.2\\*(Rq)");
395 case(ROFF_susv2):
396 return("Version 2 of the Single "
397 "UNIX Specification");
398 case(ROFF_susv3):
399 return("Version 3 of the Single "
400 "UNIX Specification");
401 case(ROFF_svid4):
402 return("System V Interface Definition, Fourth "
403 "Edition (\\*(LqSVID4\\*(Rq)");
404 default:
405 break;
406 }
407 abort();
408 /* NOTREACHED */
409
410 case (ROFF_Bt):
411 return("is currently in beta test.");
412 case (ROFF_Ud):
413 return("currently under development.");
414 case (ROFF_Fx):
415 return("FreeBSD");
416 case (ROFF_Nx):
417 return("NetBSD");
418 case (ROFF_Ox):
419 return("OpenBSD");
420 case (ROFF_Ux):
421 return("UNIX");
422 case (ROFF_Bx):
423 return("BSD");
424 case (ROFF_Bsx):
425 return("BSDI BSD/OS");
426 default:
427 break;
428 }
429
430 abort();
431 /* NOTREACHED */
432 }
433
434
435 enum roffatt
436 roff_att(const char *p)
437 {
438
439 assert(p);
440 if (0 == strcmp(p, ROFF_ATTname_V1))
441 return(ROFF_ATT_V1);
442 else if (0 == strcmp(p, ROFF_ATTname_V2))
443 return(ROFF_ATT_V2);
444 else if (0 == strcmp(p, ROFF_ATTname_V3))
445 return(ROFF_ATT_V3);
446 else if (0 == strcmp(p, ROFF_ATTname_V6))
447 return(ROFF_ATT_V6);
448 else if (0 == strcmp(p, ROFF_ATTname_V7))
449 return(ROFF_ATT_V7);
450 else if (0 == strcmp(p, ROFF_ATTname_32V))
451 return(ROFF_ATT_32V);
452 else if (0 == strcmp(p, ROFF_ATTname_V_1))
453 return(ROFF_ATT_V_1);
454 else if (0 == strcmp(p, ROFF_ATTname_V_4))
455 return(ROFF_ATT_V_4);
456
457 return(ROFF_ATT_MAX);
458 }
459
460
461 enum roffvol
462 roff_vol(const char *p)
463 {
464
465 if (0 == strcmp(p, ROFF_VOLname_AMD))
466 return(ROFF_VOL_AMD);
467 else if (0 == strcmp(p, ROFF_VOLname_IND))
468 return(ROFF_VOL_IND);
469 else if (0 == strcmp(p, ROFF_VOLname_KM))
470 return(ROFF_VOL_KM);
471 else if (0 == strcmp(p, ROFF_VOLname_LOCAL))
472 return(ROFF_VOL_LOCAL);
473 else if (0 == strcmp(p, ROFF_VOLname_PRM))
474 return(ROFF_VOL_PRM);
475 else if (0 == strcmp(p, ROFF_VOLname_PS1))
476 return(ROFF_VOL_PS1);
477 else if (0 == strcmp(p, ROFF_VOLname_SMM))
478 return(ROFF_VOL_SMM);
479 else if (0 == strcmp(p, ROFF_VOLname_URM))
480 return(ROFF_VOL_URM);
481 else if (0 == strcmp(p, ROFF_VOLname_USD))
482 return(ROFF_VOL_USD);
483 else if (0 == strcmp(p, ROFF_ARCHname_ALPHA))
484 return(ROFF_ARCH_ALPHA);
485 else if (0 == strcmp(p, ROFF_ARCHname_AMD64))
486 return(ROFF_ARCH_AMD64);
487 else if (0 == strcmp(p, ROFF_ARCHname_AMIGA))
488 return(ROFF_ARCH_AMIGA);
489 else if (0 == strcmp(p, ROFF_ARCHname_ARC))
490 return(ROFF_ARCH_ARC);
491 else if (0 == strcmp(p, ROFF_ARCHname_ARMISH))
492 return(ROFF_ARCH_ARMISH);
493 else if (0 == strcmp(p, ROFF_ARCHname_AVIION))
494 return(ROFF_ARCH_AVIION);
495 else if (0 == strcmp(p, ROFF_ARCHname_HP300))
496 return(ROFF_ARCH_HP300);
497 else if (0 == strcmp(p, ROFF_ARCHname_HPPA))
498 return(ROFF_ARCH_HPPA);
499 else if (0 == strcmp(p, ROFF_ARCHname_HPPA64))
500 return(ROFF_ARCH_HPPA64);
501 else if (0 == strcmp(p, ROFF_ARCHname_I386))
502 return(ROFF_ARCH_I386);
503 else if (0 == strcmp(p, ROFF_ARCHname_LANDISK))
504 return(ROFF_ARCH_LANDISK);
505 else if (0 == strcmp(p, ROFF_ARCHname_LUNA88K))
506 return(ROFF_ARCH_LUNA88K);
507 else if (0 == strcmp(p, ROFF_ARCHname_MAC68K))
508 return(ROFF_ARCH_MAC68K);
509 else if (0 == strcmp(p, ROFF_ARCHname_MACPPC))
510 return(ROFF_ARCH_MACPPC);
511 else if (0 == strcmp(p, ROFF_ARCHname_MVME68K))
512 return(ROFF_ARCH_MVME68K);
513 else if (0 == strcmp(p, ROFF_ARCHname_MVME88K))
514 return(ROFF_ARCH_MVME88K);
515 else if (0 == strcmp(p, ROFF_ARCHname_MVMEPPC))
516 return(ROFF_ARCH_MVMEPPC);
517 else if (0 == strcmp(p, ROFF_ARCHname_PMAX))
518 return(ROFF_ARCH_PMAX);
519 else if (0 == strcmp(p, ROFF_ARCHname_SGI))
520 return(ROFF_ARCH_SGI);
521 else if (0 == strcmp(p, ROFF_ARCHname_SPARC))
522 return(ROFF_ARCH_SPARC);
523 else if (0 == strcmp(p, ROFF_ARCHname_SPARC64))
524 return(ROFF_ARCH_SPARC64);
525 else if (0 == strcmp(p, ROFF_ARCHname_SUN3))
526 return(ROFF_ARCH_SUN3);
527 else if (0 == strcmp(p, ROFF_ARCHname_VAX))
528 return(ROFF_ARCH_VAX);
529 else if (0 == strcmp(p, ROFF_ARCHname_ZAURUS))
530 return(ROFF_ARCH_ZAURUS);
531
532 return(ROFF_VOL_MAX);
533 }