]>
git.cameronkatri.com Git - mandoc.git/blob - strings.c
1 /* $Id: strings.c,v 1.20 2009/02/26 16:08:11 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
))
67 if (0 == *++p
|| ! isgraph((int)*p
))
76 for (c
= 3, p
++; *p
&& ']' != *p
; p
++, c
++)
77 if ( ! isgraph((int)*p
))
80 return(*p
== ']' ? c
: 0);
122 mdoc_isdelim(const char *p
)
129 return(mdoc_iscdelim(*p
));
134 mdoc_atosec(const char *p
)
138 if (0 == strcmp(p
, "NAME"))
140 else if (0 == strcmp(p
, "RETURN VALUES"))
141 return(SEC_RETURN_VALUES
);
142 else if (0 == strcmp(p
, "SEE ALSO"))
143 return(SEC_SEE_ALSO
);
144 else if (0 == strcmp(p
, "SYNOPSIS"))
145 return(SEC_SYNOPSIS
);
146 else if (0 == strcmp(p
, "DESCRIPTION"))
147 return(SEC_DESCRIPTION
);
148 else if (0 == strcmp(p
, "ENVIRONMENT"))
149 return(SEC_ENVIRONMENT
);
150 else if (0 == strcmp(p
, "FILES"))
152 else if (0 == strcmp(p
, "EXAMPLES"))
153 return(SEC_EXAMPLES
);
154 else if (0 == strcmp(p
, "DIAGNOSTICS"))
155 return(SEC_DIAGNOSTICS
);
156 else if (0 == strcmp(p
, "ERRORS"))
158 else if (0 == strcmp(p
, "STANDARDS"))
159 return(SEC_STANDARDS
);
160 else if (0 == strcmp(p
, "HISTORY"))
162 else if (0 == strcmp(p
, "AUTHORS"))
164 else if (0 == strcmp(p
, "CAVEATS"))
166 else if (0 == strcmp(p
, "BUGS"))
174 mdoc_atotime(const char *p
)
179 (void)memset(&tm
, 0, sizeof(struct tm
));
181 if (xstrcmp(p
, "$Mdocdate: February 26 2009 $"))
183 if ((pp
= strptime(p
, "$Mdocdate: February 26 2009 $", &tm
)) && 0 == *pp
)
185 /* XXX - this matches "June 1999", which is wrong. */
186 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
188 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
196 mdoc_atomsec(const char *p
)
199 if (0 == strcmp(p
, "1"))
201 else if (0 == strcmp(p
, "2"))
203 else if (0 == strcmp(p
, "3"))
205 else if (0 == strcmp(p
, "3f"))
207 else if (0 == strcmp(p
, "3p"))
209 else if (0 == strcmp(p
, "4"))
211 else if (0 == strcmp(p
, "5"))
213 else if (0 == strcmp(p
, "6"))
215 else if (0 == strcmp(p
, "7"))
217 else if (0 == strcmp(p
, "8"))
219 else if (0 == strcmp(p
, "9"))
221 else if (0 == strcmp(p
, "X11"))
223 else if (0 == strcmp(p
, "X11R6"))
225 else if (0 == strcmp(p
, "local"))
227 else if (0 == strcmp(p
, "n"))
229 else if (0 == strcmp(p
, "unass"))
231 else if (0 == strcmp(p
, "draft"))
233 else if (0 == strcmp(p
, "paper"))
236 return(MSEC_DEFAULT
);
241 mdoc_atovol(const char *p
)
244 if (0 == strcmp(p
, "AMD"))
246 else if (0 == strcmp(p
, "IND"))
248 else if (0 == strcmp(p
, "KM"))
250 else if (0 == strcmp(p
, "LOCAL"))
252 else if (0 == strcmp(p
, "PRM"))
254 else if (0 == strcmp(p
, "PS1"))
256 else if (0 == strcmp(p
, "SMM"))
258 else if (0 == strcmp(p
, "URM"))
260 else if (0 == strcmp(p
, "USD"))
268 mdoc_atoarch(const char *p
)
271 if (0 == strcmp(p
, "alpha"))
273 else if (0 == strcmp(p
, "amd64"))
275 else if (0 == strcmp(p
, "amiga"))
277 else if (0 == strcmp(p
, "arc"))
279 else if (0 == strcmp(p
, "arm"))
281 else if (0 == strcmp(p
, "armish"))
283 else if (0 == strcmp(p
, "aviion"))
285 else if (0 == strcmp(p
, "hp300"))
287 else if (0 == strcmp(p
, "hppa"))
289 else if (0 == strcmp(p
, "hppa64"))
291 else if (0 == strcmp(p
, "i386"))
293 else if (0 == strcmp(p
, "landisk"))
294 return(ARCH_landisk
);
295 else if (0 == strcmp(p
, "luna88k"))
296 return(ARCH_luna88k
);
297 else if (0 == strcmp(p
, "mac68k"))
299 else if (0 == strcmp(p
, "macppc"))
301 else if (0 == strcmp(p
, "mvme68k"))
302 return(ARCH_mvme68k
);
303 else if (0 == strcmp(p
, "mvme88k"))
304 return(ARCH_mvme88k
);
305 else if (0 == strcmp(p
, "mvmeppc"))
306 return(ARCH_mvmeppc
);
307 else if (0 == strcmp(p
, "pmax"))
309 else if (0 == strcmp(p
, "sgi"))
311 else if (0 == strcmp(p
, "socppc"))
313 else if (0 == strcmp(p
, "sparc"))
315 else if (0 == strcmp(p
, "sparc64"))
316 return(ARCH_sparc64
);
317 else if (0 == strcmp(p
, "sun3"))
319 else if (0 == strcmp(p
, "vax"))
321 else if (0 == strcmp(p
, "zaurus"))
324 return(ARCH_DEFAULT
);
329 mdoc_atoatt(const char *p
)
333 if (0 == strcmp(p
, "v1"))
335 else if (0 == strcmp(p
, "v2"))
337 else if (0 == strcmp(p
, "v3"))
339 else if (0 == strcmp(p
, "v4"))
341 else if (0 == strcmp(p
, "v5"))
343 else if (0 == strcmp(p
, "v6"))
345 else if (0 == strcmp(p
, "v7"))
347 else if (0 == strcmp(p
, "32v"))
349 else if (0 == strcmp(p
, "V.1"))
351 else if (0 == strcmp(p
, "V.2"))
353 else if (0 == strcmp(p
, "V.3"))
355 else if (0 == strcmp(p
, "V.4"))
363 mdoc_type2a(enum mdoc_type type
)
371 return("block-head");
373 return("block-body");
375 return("block-tail");
390 mdoc_arch2a(enum mdoc_arch arch
)
458 mdoc_vol2a(enum mdoc_vol vol
)
463 return("OpenBSD Ancestral Manual Documents");
465 return("OpenBSD Manual Master Index");
467 return("OpenBSD Kernel Manual");
469 return("OpenBSD Local Manual");
471 return("OpenBSD Programmer's Manual");
473 return("OpenBSD Programmer's Supplementary Documents");
475 return("OpenBSD System Manager's Manual");
477 return("OpenBSD Reference Manual");
479 return("OpenBSD User's Supplementary Documents");
492 mdoc_msec2a(enum mdoc_msec msec
)
549 case(MDOC_p1003_1_88
):
550 p
= "IEEE Std 1003.1-1988 (\\(lqPOSIX\\(rq)";
552 case(MDOC_p1003_1_90
):
553 p
= "IEEE Std 1003.1-1990 (\\(lqPOSIX\\(rq)";
555 case(MDOC_p1003_1_96
):
556 p
= "ISO/IEC 9945-1:1996 (\\(lqPOSIX\\(rq)";
558 case(MDOC_p1003_1_2001
):
559 p
= "IEEE Std 1003.1-2001 (\\(lqPOSIX\\(rq)";
561 case(MDOC_p1003_1_2004
):
562 p
= "IEEE Std 1003.1-2004 (\\(lqPOSIX\\(rq)";
565 p
= "IEEE Std 1003.1 (\\(lqPOSIX\\(rq)";
568 p
= "IEEE Std 1003.1b (\\(lqPOSIX\\(rq)";
570 case(MDOC_p1003_1b_93
):
571 p
= "IEEE Std 1003.1b-1993 (\\(lqPOSIX\\(rq)";
573 case(MDOC_p1003_1c_95
):
574 p
= "IEEE Std 1003.1c-1995 (\\(lqPOSIX\\(rq)";
576 case(MDOC_p1003_1g_2000
):
577 p
= "IEEE Std 1003.1g-2000 (\\(lqPOSIX\\(rq)";
579 case(MDOC_p1003_2_92
):
580 p
= "IEEE Std 1003.2-1992 (\\(lqPOSIX.2\\(rq)";
582 case(MDOC_p1387_2_95
):
583 p
= "IEEE Std 1387.2-1995 (\\(lqPOSIX.7.2\\(rq)";
586 p
= "IEEE Std 1003.2 (\\(lqPOSIX.2\\(rq)";
589 p
= "IEEE Std 1387.2 (\\(lqPOSIX.7.2\\(rq)";
592 p
= "ISO/IEC 9899:1990 (\\(lqISO C90\\(rq)";
594 case(MDOC_isoC_amd1
):
595 p
= "ISO/IEC 9899/AMD1:1995 (\\(lqISO C90\\(rq)";
597 case(MDOC_isoC_tcor1
):
598 p
= "ISO/IEC 9899/TCOR1:1994 (\\(lqISO C90\\(rq)";
600 case(MDOC_isoC_tcor2
):
601 p
= "ISO/IEC 9899/TCOR2:1995 (\\(lqISO C90\\(rq)";
604 p
= "ISO/IEC 9899:1999 (\\(lqISO C99\\(rq)";
607 p
= "ANSI X3.159-1989 (\\(lqANSI C\\(rq)";
610 p
= "ANSI X3.159-1989 (\\(lqANSI C\\(rq)";
613 p
= "ANSI/ISO/IEC 9899-1999 (\\(lqANSI C99\\(rq)";
616 p
= "IEEE Std 754-1985";
618 case(MDOC_iso8802_3
):
619 p
= "ISO 8802-3: 1989";
622 p
= "X/Open Portability Guide Issue 3 "
626 p
= "X/Open Portability Guide Issue 4 "
630 p
= "X/Open Portability Guide Issue 4.2 "
631 "(\\(lqXPG4.2\\(rq)";
634 p
= "X/Open Portability Guide Issue 4.3 "
635 "(\\(lqXPG4.3\\(rq)";
638 p
= "X/Open System Interface Definitions Issue 5 "
642 p
= "X/Open Commands and Utilities Issue 5 "
646 p
= "X/Open System Interfaces and Headers Issue 5 "
650 p
= "X/Open Networking Services Issue 5 "
653 case(MDOC_xns5_2d2_0
):
654 p
= "X/Open Networking Services Issue 5.2 Draft 2.0 "
655 "(\\(lqXNS5.2D2.0\\(rq)";
657 case(MDOC_xcurses4_2
):
658 p
= "X/Open Curses Issue 4 Version 2 "
659 "(\\(lqXCURSES4.2\\(rq)";
662 p
= "Version 2 of the Single UNIX Specification";
665 p
= "Version 3 of the Single UNIX Specification";
668 p
= "System V Interface Definition, Fourth Edition "
681 mdoc_att2a(enum mdoc_att c
)
687 p
= "Version 1 AT&T UNIX";
690 p
= "Version 2 AT&T UNIX";
693 p
= "Version 3 AT&T UNIX";
696 p
= "Version 4 AT&T UNIX";
699 p
= "Version 5 AT&T UNIX";
702 p
= "Version 6 AT&T UNIX";
705 p
= "Version 7 AT&T UNIX";
708 p
= "Version 32V AT&T UNIX";
711 p
= "AT&T System V.1 UNIX";
714 p
= "AT&T System V.2 UNIX";
717 p
= "AT&T System V.3 UNIX";
720 p
= "AT&T System V.4 UNIX";
732 mdoc_macro2len(int macro
)