]>
git.cameronkatri.com Git - mandoc.git/blob - strings.c
896971a9e56eeea28b3394d1a22646bd33e8a10e
1 /* $Id: strings.c,v 1.22 2009/02/27 10:55:16 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
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
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.
29 * Convert scalars to and from string format.
35 extern char *strptime(const char *, const char *, struct tm
*);
40 mdoc_isescape(const char *p
)
65 if (0 == *++p
|| ! isgraph((int)*p
))
69 if (0 == *++p
|| ! isgraph((int)*p
))
77 if (0 == *++p
|| ! isgraph((int)*p
))
79 if (0 == *++p
|| ! isgraph((int)*p
))
88 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
89 if ( ! isgraph((int)*p
))
92 return(*p
== ']' ? c
: 0);
134 mdoc_isdelim(const char *p
)
141 return(mdoc_iscdelim(*p
));
146 mdoc_atosec(const char *p
)
150 if (0 == strcmp(p
, "NAME"))
152 else if (0 == strcmp(p
, "RETURN VALUES"))
153 return(SEC_RETURN_VALUES
);
154 else if (0 == strcmp(p
, "SEE ALSO"))
155 return(SEC_SEE_ALSO
);
156 else if (0 == strcmp(p
, "SYNOPSIS"))
157 return(SEC_SYNOPSIS
);
158 else if (0 == strcmp(p
, "DESCRIPTION"))
159 return(SEC_DESCRIPTION
);
160 else if (0 == strcmp(p
, "ENVIRONMENT"))
161 return(SEC_ENVIRONMENT
);
162 else if (0 == strcmp(p
, "FILES"))
164 else if (0 == strcmp(p
, "EXAMPLES"))
165 return(SEC_EXAMPLES
);
166 else if (0 == strcmp(p
, "DIAGNOSTICS"))
167 return(SEC_DIAGNOSTICS
);
168 else if (0 == strcmp(p
, "ERRORS"))
170 else if (0 == strcmp(p
, "STANDARDS"))
171 return(SEC_STANDARDS
);
172 else if (0 == strcmp(p
, "HISTORY"))
174 else if (0 == strcmp(p
, "AUTHORS"))
176 else if (0 == strcmp(p
, "CAVEATS"))
178 else if (0 == strcmp(p
, "BUGS"))
186 mdoc_atotime(const char *p
)
191 (void)memset(&tm
, 0, sizeof(struct tm
));
193 if (xstrcmp(p
, "$Mdocdate: February 27 2009 $"))
195 if ((pp
= strptime(p
, "$Mdocdate: February 27 2009 $", &tm
)) && 0 == *pp
)
197 /* XXX - this matches "June 1999", which is wrong. */
198 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
200 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
208 mdoc_atomsec(const char *p
)
211 if (0 == strcmp(p
, "1"))
213 else if (0 == strcmp(p
, "2"))
215 else if (0 == strcmp(p
, "3"))
217 else if (0 == strcmp(p
, "3f"))
219 else if (0 == strcmp(p
, "3p"))
221 else if (0 == strcmp(p
, "4"))
223 else if (0 == strcmp(p
, "5"))
225 else if (0 == strcmp(p
, "6"))
227 else if (0 == strcmp(p
, "7"))
229 else if (0 == strcmp(p
, "8"))
231 else if (0 == strcmp(p
, "9"))
233 else if (0 == strcmp(p
, "X11"))
235 else if (0 == strcmp(p
, "X11R6"))
237 else if (0 == strcmp(p
, "local"))
239 else if (0 == strcmp(p
, "n"))
241 else if (0 == strcmp(p
, "unass"))
243 else if (0 == strcmp(p
, "draft"))
245 else if (0 == strcmp(p
, "paper"))
248 return(MSEC_DEFAULT
);
253 mdoc_atovol(const char *p
)
256 if (0 == strcmp(p
, "AMD"))
258 else if (0 == strcmp(p
, "IND"))
260 else if (0 == strcmp(p
, "KM"))
262 else if (0 == strcmp(p
, "LOCAL"))
264 else if (0 == strcmp(p
, "PRM"))
266 else if (0 == strcmp(p
, "PS1"))
268 else if (0 == strcmp(p
, "SMM"))
270 else if (0 == strcmp(p
, "URM"))
272 else if (0 == strcmp(p
, "USD"))
280 mdoc_atoarch(const char *p
)
283 if (0 == strcmp(p
, "alpha"))
285 else if (0 == strcmp(p
, "amd64"))
287 else if (0 == strcmp(p
, "amiga"))
289 else if (0 == strcmp(p
, "arc"))
291 else if (0 == strcmp(p
, "arm"))
293 else if (0 == strcmp(p
, "armish"))
295 else if (0 == strcmp(p
, "aviion"))
297 else if (0 == strcmp(p
, "hp300"))
299 else if (0 == strcmp(p
, "hppa"))
301 else if (0 == strcmp(p
, "hppa64"))
303 else if (0 == strcmp(p
, "i386"))
305 else if (0 == strcmp(p
, "landisk"))
306 return(ARCH_landisk
);
307 else if (0 == strcmp(p
, "luna88k"))
308 return(ARCH_luna88k
);
309 else if (0 == strcmp(p
, "mac68k"))
311 else if (0 == strcmp(p
, "macppc"))
313 else if (0 == strcmp(p
, "mvme68k"))
314 return(ARCH_mvme68k
);
315 else if (0 == strcmp(p
, "mvme88k"))
316 return(ARCH_mvme88k
);
317 else if (0 == strcmp(p
, "mvmeppc"))
318 return(ARCH_mvmeppc
);
319 else if (0 == strcmp(p
, "pmax"))
321 else if (0 == strcmp(p
, "sgi"))
323 else if (0 == strcmp(p
, "socppc"))
325 else if (0 == strcmp(p
, "sparc"))
327 else if (0 == strcmp(p
, "sparc64"))
328 return(ARCH_sparc64
);
329 else if (0 == strcmp(p
, "sun3"))
331 else if (0 == strcmp(p
, "vax"))
333 else if (0 == strcmp(p
, "zaurus"))
336 return(ARCH_DEFAULT
);
341 mdoc_atoatt(const char *p
)
345 if (0 == strcmp(p
, "v1"))
347 else if (0 == strcmp(p
, "v2"))
349 else if (0 == strcmp(p
, "v3"))
351 else if (0 == strcmp(p
, "v4"))
353 else if (0 == strcmp(p
, "v5"))
355 else if (0 == strcmp(p
, "v6"))
357 else if (0 == strcmp(p
, "v7"))
359 else if (0 == strcmp(p
, "32v"))
361 else if (0 == strcmp(p
, "V.1"))
363 else if (0 == strcmp(p
, "V.2"))
365 else if (0 == strcmp(p
, "V.3"))
367 else if (0 == strcmp(p
, "V.4"))
375 mdoc_type2a(enum mdoc_type type
)
383 return("block-head");
385 return("block-body");
387 return("block-tail");
402 mdoc_arch2a(enum mdoc_arch arch
)
470 mdoc_vol2a(enum mdoc_vol vol
)
475 return("Ancestral Manual Documents");
477 return("Manual Master Index");
479 return("Kernel Manual");
481 return("Local Manual");
483 return("Programmer's Manual");
485 return("Programmer's Supplementary Documents");
487 return("System Manager's Manual");
489 return("Reference Manual");
491 return("User's Supplementary Documents");
504 mdoc_msec2a(enum mdoc_msec msec
)
561 case(MDOC_p1003_1_88
):
562 p
= "IEEE Std 1003.1-1988 (\\(lqPOSIX\\(rq)";
564 case(MDOC_p1003_1_90
):
565 p
= "IEEE Std 1003.1-1990 (\\(lqPOSIX\\(rq)";
567 case(MDOC_p1003_1_96
):
568 p
= "ISO/IEC 9945-1:1996 (\\(lqPOSIX\\(rq)";
570 case(MDOC_p1003_1_2001
):
571 p
= "IEEE Std 1003.1-2001 (\\(lqPOSIX\\(rq)";
573 case(MDOC_p1003_1_2004
):
574 p
= "IEEE Std 1003.1-2004 (\\(lqPOSIX\\(rq)";
577 p
= "IEEE Std 1003.1 (\\(lqPOSIX\\(rq)";
580 p
= "IEEE Std 1003.1b (\\(lqPOSIX\\(rq)";
582 case(MDOC_p1003_1b_93
):
583 p
= "IEEE Std 1003.1b-1993 (\\(lqPOSIX\\(rq)";
585 case(MDOC_p1003_1c_95
):
586 p
= "IEEE Std 1003.1c-1995 (\\(lqPOSIX\\(rq)";
588 case(MDOC_p1003_1g_2000
):
589 p
= "IEEE Std 1003.1g-2000 (\\(lqPOSIX\\(rq)";
591 case(MDOC_p1003_2_92
):
592 p
= "IEEE Std 1003.2-1992 (\\(lqPOSIX.2\\(rq)";
594 case(MDOC_p1387_2_95
):
595 p
= "IEEE Std 1387.2-1995 (\\(lqPOSIX.7.2\\(rq)";
598 p
= "IEEE Std 1003.2 (\\(lqPOSIX.2\\(rq)";
601 p
= "IEEE Std 1387.2 (\\(lqPOSIX.7.2\\(rq)";
604 p
= "ISO/IEC 9899:1990 (\\(lqISO C90\\(rq)";
606 case(MDOC_isoC_amd1
):
607 p
= "ISO/IEC 9899/AMD1:1995 (\\(lqISO C90\\(rq)";
609 case(MDOC_isoC_tcor1
):
610 p
= "ISO/IEC 9899/TCOR1:1994 (\\(lqISO C90\\(rq)";
612 case(MDOC_isoC_tcor2
):
613 p
= "ISO/IEC 9899/TCOR2:1995 (\\(lqISO C90\\(rq)";
616 p
= "ISO/IEC 9899:1999 (\\(lqISO C99\\(rq)";
619 p
= "ANSI X3.159-1989 (\\(lqANSI C\\(rq)";
622 p
= "ANSI X3.159-1989 (\\(lqANSI C\\(rq)";
625 p
= "ANSI/ISO/IEC 9899-1999 (\\(lqANSI C99\\(rq)";
628 p
= "IEEE Std 754-1985";
630 case(MDOC_iso8802_3
):
631 p
= "ISO 8802-3: 1989";
634 p
= "X/Open Portability Guide Issue 3 "
638 p
= "X/Open Portability Guide Issue 4 "
642 p
= "X/Open Portability Guide Issue 4.2 "
643 "(\\(lqXPG4.2\\(rq)";
646 p
= "X/Open Portability Guide Issue 4.3 "
647 "(\\(lqXPG4.3\\(rq)";
650 p
= "X/Open System Interface Definitions Issue 5 "
654 p
= "X/Open Commands and Utilities Issue 5 "
658 p
= "X/Open System Interfaces and Headers Issue 5 "
662 p
= "X/Open Networking Services Issue 5 "
665 case(MDOC_xns5_2d2_0
):
666 p
= "X/Open Networking Services Issue 5.2 Draft 2.0 "
667 "(\\(lqXNS5.2D2.0\\(rq)";
669 case(MDOC_xcurses4_2
):
670 p
= "X/Open Curses Issue 4 Version 2 "
671 "(\\(lqXCURSES4.2\\(rq)";
674 p
= "Version 2 of the Single UNIX Specification";
677 p
= "Version 3 of the Single UNIX Specification";
680 p
= "System V Interface Definition, Fourth Edition "
693 mdoc_att2a(enum mdoc_att c
)
699 p
= "Version 1 AT&T UNIX";
702 p
= "Version 2 AT&T UNIX";
705 p
= "Version 3 AT&T UNIX";
708 p
= "Version 4 AT&T UNIX";
711 p
= "Version 5 AT&T UNIX";
714 p
= "Version 6 AT&T UNIX";
717 p
= "Version 7 AT&T UNIX";
720 p
= "Version 32V AT&T UNIX";
723 p
= "AT&T System V.1 UNIX";
726 p
= "AT&T System V.2 UNIX";
729 p
= "AT&T System V.3 UNIX";
732 p
= "AT&T System V.4 UNIX";
744 mdoc_macro2len(int macro
)