]>
git.cameronkatri.com Git - mandoc.git/blob - strings.c
1 /* $Id: strings.c,v 1.25 2009/03/05 13:12:12 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((u_char
)*p
))
69 if (0 == *++p
|| ! isgraph((u_char
)*p
))
73 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
74 if ( ! isgraph((u_char
)*p
))
76 return(*p
== ']' ? c
: 0);
82 if (0 == *++p
|| ! isgraph((u_char
)*p
))
84 if (0 == *++p
|| ! isgraph((u_char
)*p
))
93 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
94 if ( ! isgraph((u_char
)*p
))
97 return(*p
== ']' ? c
: 0);
102 mdoc_iscdelim(char p
)
139 mdoc_isdelim(const char *p
)
146 return(mdoc_iscdelim(*p
));
151 mdoc_atosec(const char *p
)
155 if (0 == strcmp(p
, "NAME"))
157 else if (0 == strcmp(p
, "RETURN VALUES"))
158 return(SEC_RETURN_VALUES
);
159 else if (0 == strcmp(p
, "SEE ALSO"))
160 return(SEC_SEE_ALSO
);
161 else if (0 == strcmp(p
, "SYNOPSIS"))
162 return(SEC_SYNOPSIS
);
163 else if (0 == strcmp(p
, "DESCRIPTION"))
164 return(SEC_DESCRIPTION
);
165 else if (0 == strcmp(p
, "ENVIRONMENT"))
166 return(SEC_ENVIRONMENT
);
167 else if (0 == strcmp(p
, "FILES"))
169 else if (0 == strcmp(p
, "EXAMPLES"))
170 return(SEC_EXAMPLES
);
171 else if (0 == strcmp(p
, "DIAGNOSTICS"))
172 return(SEC_DIAGNOSTICS
);
173 else if (0 == strcmp(p
, "ERRORS"))
175 else if (0 == strcmp(p
, "STANDARDS"))
176 return(SEC_STANDARDS
);
177 else if (0 == strcmp(p
, "HISTORY"))
179 else if (0 == strcmp(p
, "AUTHORS"))
181 else if (0 == strcmp(p
, "CAVEATS"))
183 else if (0 == strcmp(p
, "BUGS"))
191 mdoc_atotime(const char *p
)
196 (void)memset(&tm
, 0, sizeof(struct tm
));
198 if (xstrcmp(p
, "$Mdocdate: March 5 2009 $"))
200 if ((pp
= strptime(p
, "$Mdocdate: March 5 2009 $", &tm
)) && 0 == *pp
)
202 /* XXX - this matches "June 1999", which is wrong. */
203 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
205 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
213 mdoc_atomsec(const char *p
)
216 if (0 == strcmp(p
, "1"))
218 else if (0 == strcmp(p
, "2"))
220 else if (0 == strcmp(p
, "3"))
222 else if (0 == strcmp(p
, "3f"))
224 else if (0 == strcmp(p
, "3p"))
226 else if (0 == strcmp(p
, "4"))
228 else if (0 == strcmp(p
, "5"))
230 else if (0 == strcmp(p
, "6"))
232 else if (0 == strcmp(p
, "7"))
234 else if (0 == strcmp(p
, "8"))
236 else if (0 == strcmp(p
, "9"))
238 else if (0 == strcmp(p
, "X11"))
240 else if (0 == strcmp(p
, "X11R6"))
242 else if (0 == strcmp(p
, "local"))
244 else if (0 == strcmp(p
, "n"))
246 else if (0 == strcmp(p
, "unass"))
248 else if (0 == strcmp(p
, "draft"))
250 else if (0 == strcmp(p
, "paper"))
253 return(MSEC_DEFAULT
);
258 mdoc_atovol(const char *p
)
261 if (0 == strcmp(p
, "AMD"))
263 else if (0 == strcmp(p
, "IND"))
265 else if (0 == strcmp(p
, "KM"))
267 else if (0 == strcmp(p
, "LOCAL"))
269 else if (0 == strcmp(p
, "PRM"))
271 else if (0 == strcmp(p
, "PS1"))
273 else if (0 == strcmp(p
, "SMM"))
275 else if (0 == strcmp(p
, "URM"))
277 else if (0 == strcmp(p
, "USD"))
285 mdoc_atoarch(const char *p
)
288 if (0 == strcmp(p
, "alpha"))
290 else if (0 == strcmp(p
, "amd64"))
292 else if (0 == strcmp(p
, "amiga"))
294 else if (0 == strcmp(p
, "arc"))
296 else if (0 == strcmp(p
, "arm"))
298 else if (0 == strcmp(p
, "armish"))
300 else if (0 == strcmp(p
, "aviion"))
302 else if (0 == strcmp(p
, "hp300"))
304 else if (0 == strcmp(p
, "hppa"))
306 else if (0 == strcmp(p
, "hppa64"))
308 else if (0 == strcmp(p
, "i386"))
310 else if (0 == strcmp(p
, "landisk"))
311 return(ARCH_landisk
);
312 else if (0 == strcmp(p
, "luna88k"))
313 return(ARCH_luna88k
);
314 else if (0 == strcmp(p
, "mac68k"))
316 else if (0 == strcmp(p
, "macppc"))
318 else if (0 == strcmp(p
, "mvme68k"))
319 return(ARCH_mvme68k
);
320 else if (0 == strcmp(p
, "mvme88k"))
321 return(ARCH_mvme88k
);
322 else if (0 == strcmp(p
, "mvmeppc"))
323 return(ARCH_mvmeppc
);
324 else if (0 == strcmp(p
, "pmax"))
326 else if (0 == strcmp(p
, "sgi"))
328 else if (0 == strcmp(p
, "socppc"))
330 else if (0 == strcmp(p
, "sparc"))
332 else if (0 == strcmp(p
, "sparc64"))
333 return(ARCH_sparc64
);
334 else if (0 == strcmp(p
, "sun3"))
336 else if (0 == strcmp(p
, "vax"))
338 else if (0 == strcmp(p
, "zaurus"))
341 return(ARCH_DEFAULT
);
346 mdoc_atoatt(const char *p
)
350 if (0 == strcmp(p
, "v1"))
352 else if (0 == strcmp(p
, "v2"))
354 else if (0 == strcmp(p
, "v3"))
356 else if (0 == strcmp(p
, "v4"))
358 else if (0 == strcmp(p
, "v5"))
360 else if (0 == strcmp(p
, "v6"))
362 else if (0 == strcmp(p
, "v7"))
364 else if (0 == strcmp(p
, "32v"))
366 else if (0 == strcmp(p
, "V"))
368 else if (0 == strcmp(p
, "V.1"))
370 else if (0 == strcmp(p
, "V.2"))
372 else if (0 == strcmp(p
, "V.3"))
374 else if (0 == strcmp(p
, "V.4"))
382 mdoc_type2a(enum mdoc_type type
)
390 return("block-head");
392 return("block-body");
394 return("block-tail");
409 mdoc_arch2a(enum mdoc_arch arch
)
477 mdoc_vol2a(enum mdoc_vol vol
)
482 return("Ancestral Manual Documents");
484 return("Manual Master Index");
486 return("Kernel Manual");
488 return("Local Manual");
490 return("Programmer's Manual");
492 return("Programmer's Supplementary Documents");
494 return("System Manager's Manual");
496 return("Reference Manual");
498 return("User's Supplementary Documents");
511 mdoc_msec2a(enum mdoc_msec msec
)
568 case(MDOC_p1003_1_88
):
569 p
= "IEEE Std 1003.1-1988 (\\(lqPOSIX\\(rq)";
571 case(MDOC_p1003_1_90
):
572 p
= "IEEE Std 1003.1-1990 (\\(lqPOSIX\\(rq)";
574 case(MDOC_p1003_1_96
):
575 p
= "ISO/IEC 9945-1:1996 (\\(lqPOSIX\\(rq)";
577 case(MDOC_p1003_1_2001
):
578 p
= "IEEE Std 1003.1-2001 (\\(lqPOSIX\\(rq)";
580 case(MDOC_p1003_1_2004
):
581 p
= "IEEE Std 1003.1-2004 (\\(lqPOSIX\\(rq)";
584 p
= "IEEE Std 1003.1 (\\(lqPOSIX\\(rq)";
587 p
= "IEEE Std 1003.1b (\\(lqPOSIX\\(rq)";
589 case(MDOC_p1003_1b_93
):
590 p
= "IEEE Std 1003.1b-1993 (\\(lqPOSIX\\(rq)";
592 case(MDOC_p1003_1c_95
):
593 p
= "IEEE Std 1003.1c-1995 (\\(lqPOSIX\\(rq)";
595 case(MDOC_p1003_1g_2000
):
596 p
= "IEEE Std 1003.1g-2000 (\\(lqPOSIX\\(rq)";
598 case(MDOC_p1003_2_92
):
599 p
= "IEEE Std 1003.2-1992 (\\(lqPOSIX.2\\(rq)";
601 case(MDOC_p1387_2_95
):
602 p
= "IEEE Std 1387.2-1995 (\\(lqPOSIX.7.2\\(rq)";
605 p
= "IEEE Std 1003.2 (\\(lqPOSIX.2\\(rq)";
608 p
= "IEEE Std 1387.2 (\\(lqPOSIX.7.2\\(rq)";
611 p
= "ISO/IEC 9899:1990 (\\(lqISO C90\\(rq)";
613 case(MDOC_isoC_amd1
):
614 p
= "ISO/IEC 9899/AMD1:1995 (\\(lqISO C90\\(rq)";
616 case(MDOC_isoC_tcor1
):
617 p
= "ISO/IEC 9899/TCOR1:1994 (\\(lqISO C90\\(rq)";
619 case(MDOC_isoC_tcor2
):
620 p
= "ISO/IEC 9899/TCOR2:1995 (\\(lqISO C90\\(rq)";
623 p
= "ISO/IEC 9899:1999 (\\(lqISO C99\\(rq)";
626 p
= "ANSI X3.159-1989 (\\(lqANSI C\\(rq)";
629 p
= "ANSI X3.159-1989 (\\(lqANSI C\\(rq)";
632 p
= "ANSI/ISO/IEC 9899-1999 (\\(lqANSI C99\\(rq)";
635 p
= "IEEE Std 754-1985";
637 case(MDOC_iso8802_3
):
638 p
= "ISO 8802-3: 1989";
641 p
= "X/Open Portability Guide Issue 3 "
645 p
= "X/Open Portability Guide Issue 4 "
649 p
= "X/Open Portability Guide Issue 4.2 "
650 "(\\(lqXPG4.2\\(rq)";
653 p
= "X/Open Portability Guide Issue 4.3 "
654 "(\\(lqXPG4.3\\(rq)";
657 p
= "X/Open System Interface Definitions Issue 5 "
661 p
= "X/Open Commands and Utilities Issue 5 "
665 p
= "X/Open System Interfaces and Headers Issue 5 "
669 p
= "X/Open Networking Services Issue 5 "
672 case(MDOC_xns5_2d2_0
):
673 p
= "X/Open Networking Services Issue 5.2 Draft 2.0 "
674 "(\\(lqXNS5.2D2.0\\(rq)";
676 case(MDOC_xcurses4_2
):
677 p
= "X/Open Curses Issue 4 Version 2 "
678 "(\\(lqXCURSES4.2\\(rq)";
681 p
= "Version 2 of the Single UNIX Specification";
684 p
= "Version 3 of the Single UNIX Specification";
687 p
= "System V Interface Definition, Fourth Edition "
700 mdoc_att2a(enum mdoc_att c
)
706 p
= "Version 1 AT&T UNIX";
709 p
= "Version 2 AT&T UNIX";
712 p
= "Version 3 AT&T UNIX";
715 p
= "Version 4 AT&T UNIX";
718 p
= "Version 5 AT&T UNIX";
721 p
= "Version 6 AT&T UNIX";
724 p
= "Version 7 AT&T UNIX";
727 p
= "Version 32V AT&T UNIX";
730 p
= "AT&T System V UNIX";
733 p
= "AT&T System V.1 UNIX";
736 p
= "AT&T System V.2 UNIX";
739 p
= "AT&T System V.3 UNIX";
742 p
= "AT&T System V.4 UNIX";
754 mdoc_macro2len(int macro
)