]>
git.cameronkatri.com Git - mandoc.git/blob - strings.c
1 /* $Id: strings.c,v 1.15 2009/02/23 15:34:53 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
*);
76 mdoc_isdelim(const char *p
)
83 return(mdoc_iscdelim(*p
));
88 mdoc_atosec(const char *p
)
92 if (0 == strcmp(p
, "NAME"))
94 else if (0 == strcmp(p
, "RETURN VALUES"))
95 return(SEC_RETURN_VALUES
);
96 else if (0 == strcmp(p
, "SEE ALSO"))
98 else if (0 == strcmp(p
, "SYNOPSIS"))
100 else if (0 == strcmp(p
, "DESCRIPTION"))
101 return(SEC_DESCRIPTION
);
102 else if (0 == strcmp(p
, "ENVIRONMENT"))
103 return(SEC_ENVIRONMENT
);
104 else if (0 == strcmp(p
, "FILES"))
106 else if (0 == strcmp(p
, "EXAMPLES"))
107 return(SEC_EXAMPLES
);
108 else if (0 == strcmp(p
, "DIAGNOSTICS"))
109 return(SEC_DIAGNOSTICS
);
110 else if (0 == strcmp(p
, "ERRORS"))
112 else if (0 == strcmp(p
, "STANDARDS"))
113 return(SEC_STANDARDS
);
114 else if (0 == strcmp(p
, "HISTORY"))
116 else if (0 == strcmp(p
, "AUTHORS"))
118 else if (0 == strcmp(p
, "CAVEATS"))
120 else if (0 == strcmp(p
, "BUGS"))
128 mdoc_atotime(const char *p
)
133 (void)memset(&tm
, 0, sizeof(struct tm
));
135 if (xstrcmp(p
, "$Mdocdate: February 23 2009 $"))
137 if ((pp
= strptime(p
, "$Mdocdate: February 23 2009 $", &tm
)) && 0 == *pp
)
139 /* XXX - this matches "June 1999", which is wrong. */
140 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
142 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
150 mdoc_atomsec(const char *p
)
153 if (0 == strcmp(p
, "1"))
155 else if (0 == strcmp(p
, "2"))
157 else if (0 == strcmp(p
, "3"))
159 else if (0 == strcmp(p
, "3f"))
161 else if (0 == strcmp(p
, "3p"))
163 else if (0 == strcmp(p
, "4"))
165 else if (0 == strcmp(p
, "5"))
167 else if (0 == strcmp(p
, "6"))
169 else if (0 == strcmp(p
, "7"))
171 else if (0 == strcmp(p
, "8"))
173 else if (0 == strcmp(p
, "9"))
175 else if (0 == strcmp(p
, "X11"))
177 else if (0 == strcmp(p
, "X11R6"))
179 else if (0 == strcmp(p
, "local"))
181 else if (0 == strcmp(p
, "n"))
183 else if (0 == strcmp(p
, "unass"))
185 else if (0 == strcmp(p
, "draft"))
187 else if (0 == strcmp(p
, "paper"))
190 return(MSEC_DEFAULT
);
195 mdoc_atovol(const char *p
)
198 if (0 == strcmp(p
, "AMD"))
200 else if (0 == strcmp(p
, "IND"))
202 else if (0 == strcmp(p
, "KM"))
204 else if (0 == strcmp(p
, "LOCAL"))
206 else if (0 == strcmp(p
, "PRM"))
208 else if (0 == strcmp(p
, "PS1"))
210 else if (0 == strcmp(p
, "SMM"))
212 else if (0 == strcmp(p
, "URM"))
214 else if (0 == strcmp(p
, "USD"))
222 mdoc_atoarch(const char *p
)
225 if (0 == strcmp(p
, "alpha"))
227 else if (0 == strcmp(p
, "amd64"))
229 else if (0 == strcmp(p
, "amiga"))
231 else if (0 == strcmp(p
, "arc"))
233 else if (0 == strcmp(p
, "arm"))
235 else if (0 == strcmp(p
, "armish"))
237 else if (0 == strcmp(p
, "aviion"))
239 else if (0 == strcmp(p
, "hp300"))
241 else if (0 == strcmp(p
, "hppa"))
243 else if (0 == strcmp(p
, "hppa64"))
245 else if (0 == strcmp(p
, "i386"))
247 else if (0 == strcmp(p
, "landisk"))
248 return(ARCH_landisk
);
249 else if (0 == strcmp(p
, "luna88k"))
250 return(ARCH_luna88k
);
251 else if (0 == strcmp(p
, "mac68k"))
253 else if (0 == strcmp(p
, "macppc"))
255 else if (0 == strcmp(p
, "mvme68k"))
256 return(ARCH_mvme68k
);
257 else if (0 == strcmp(p
, "mvme88k"))
258 return(ARCH_mvme88k
);
259 else if (0 == strcmp(p
, "mvmeppc"))
260 return(ARCH_mvmeppc
);
261 else if (0 == strcmp(p
, "pmax"))
263 else if (0 == strcmp(p
, "sgi"))
265 else if (0 == strcmp(p
, "socppc"))
267 else if (0 == strcmp(p
, "sparc"))
269 else if (0 == strcmp(p
, "sparc64"))
270 return(ARCH_sparc64
);
271 else if (0 == strcmp(p
, "sun3"))
273 else if (0 == strcmp(p
, "vax"))
275 else if (0 == strcmp(p
, "zaurus"))
278 return(ARCH_DEFAULT
);
283 mdoc_atoatt(const char *p
)
287 if (0 == strcmp(p
, "v1"))
289 else if (0 == strcmp(p
, "v2"))
291 else if (0 == strcmp(p
, "v3"))
293 else if (0 == strcmp(p
, "v4"))
295 else if (0 == strcmp(p
, "v5"))
297 else if (0 == strcmp(p
, "v6"))
299 else if (0 == strcmp(p
, "v7"))
301 else if (0 == strcmp(p
, "32v"))
303 else if (0 == strcmp(p
, "V.1"))
305 else if (0 == strcmp(p
, "V.2"))
307 else if (0 == strcmp(p
, "V.3"))
309 else if (0 == strcmp(p
, "V.4"))
317 mdoc_type2a(enum mdoc_type type
)
325 return("block-head");
327 return("block-body");
329 return("block-tail");
344 mdoc_arch2a(enum mdoc_arch arch
)
412 mdoc_vol2a(enum mdoc_vol vol
)
417 return("OpenBSD Ancestral Manual Documents");
419 return("OpenBSD Manual Master Index");
421 return("OpenBSD Kernel Manual");
423 return("OpenBSD Local Manual");
425 return("OpenBSD Programmer's Manual");
427 return("OpenBSD Programmer's Supplementary Documents");
429 return("OpenBSD System Manager's Manual");
431 return("OpenBSD Reference Manual");
433 return("OpenBSD User's Supplementary Documents");
446 mdoc_msec2a(enum mdoc_msec msec
)