Annotation of mandoc/strings.c, Revision 1.3
1.3 ! kristaps 1: /* $Id: strings.c,v 1.2 2008/12/17 17:18:38 kristaps Exp $ */
1.1 kristaps 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 <ctype.h>
21: #include <stdlib.h>
22: #include <stdio.h>
1.2 kristaps 23: #include <string.h>
1.1 kristaps 24:
25: #include "private.h"
26:
27: int
1.3 ! kristaps 28: mdoc_iscdelim(char p)
1.1 kristaps 29: {
30:
1.3 ! kristaps 31: switch (p) {
1.1 kristaps 32: case('{'):
33: /* FALLTHROUGH */
34: case('.'):
35: /* FALLTHROUGH */
36: case(','):
37: /* FALLTHROUGH */
38: case(';'):
39: /* FALLTHROUGH */
40: case(':'):
41: /* FALLTHROUGH */
42: case('?'):
43: /* FALLTHROUGH */
44: case('!'):
45: /* FALLTHROUGH */
46: case('('):
47: /* FALLTHROUGH */
48: case(')'):
49: /* FALLTHROUGH */
50: case('['):
51: /* FALLTHROUGH */
52: case(']'):
53: /* FALLTHROUGH */
54: case('}'):
55: return(1);
56: default:
57: break;
58: }
59:
60: return(0);
61: }
62:
1.2 kristaps 63:
1.3 ! kristaps 64: int
! 65: mdoc_isdelim(const char *p)
! 66: {
! 67:
! 68: if (0 == *p)
! 69: return(0);
! 70: if (0 != *(p + 1))
! 71: return(0);
! 72: return(mdoc_iscdelim(*p));
! 73: }
! 74:
! 75:
1.2 kristaps 76: enum mdoc_sec
77: mdoc_atosec(size_t sz, const char **p)
78: {
79:
80: assert(sz > 0);
81: if (sz > 2)
82: return(SEC_CUSTOM);
83: if (sz == 2) {
84: if (0 == strcmp(*p, "RETURN") &&
85: 0 == strcmp(*(p + 1), "VALUES"))
86: return(SEC_RETURN_VALUES);
87: if (0 == strcmp(*p, "SEE") &&
88: 0 == strcmp(*(p + 1), "ALSO"))
89: return(SEC_SEE_ALSO);
90: return(SEC_CUSTOM);
91: }
92:
93: if (0 == strcmp(*p, "NAME"))
94: return(SEC_NAME);
95: else if (0 == strcmp(*p, "SYNOPSIS"))
96: return(SEC_SYNOPSIS);
97: else if (0 == strcmp(*p, "DESCRIPTION"))
98: return(SEC_DESCRIPTION);
99: else if (0 == strcmp(*p, "ENVIRONMENT"))
100: return(SEC_ENVIRONMENT);
101: else if (0 == strcmp(*p, "FILES"))
102: return(SEC_FILES);
103: else if (0 == strcmp(*p, "EXAMPLES"))
104: return(SEC_EXAMPLES);
105: else if (0 == strcmp(*p, "DIAGNOSTICS"))
106: return(SEC_DIAGNOSTICS);
107: else if (0 == strcmp(*p, "ERRORS"))
108: return(SEC_ERRORS);
109: else if (0 == strcmp(*p, "STANDARDS"))
110: return(SEC_STANDARDS);
111: else if (0 == strcmp(*p, "HISTORY"))
112: return(SEC_HISTORY);
113: else if (0 == strcmp(*p, "AUTHORS"))
114: return(SEC_AUTHORS);
115: else if (0 == strcmp(*p, "CAVEATS"))
116: return(SEC_CAVEATS);
117: else if (0 == strcmp(*p, "BUGS"))
118: return(SEC_BUGS);
119:
120: return(SEC_CUSTOM);
121: }
122:
123:
124: time_t
125: mdoc_atotime(const char *p)
126: {
127: struct tm tm;
128:
129: if (strptime(p, "%b %d %Y", &tm))
130: return(mktime(&tm));
131: if (strptime(p, "%b %d, %Y", &tm))
132: return(mktime(&tm));
133:
134: return(0);
135: }
136:
137:
138: enum mdoc_msec
139: mdoc_atomsec(const char *p)
140: {
141:
142: if (0 == strcmp(p, "1"))
143: return(MSEC_1);
144: else if (0 == strcmp(p, "2"))
145: return(MSEC_2);
146: else if (0 == strcmp(p, "3"))
147: return(MSEC_3);
148: else if (0 == strcmp(p, "3f"))
149: return(MSEC_3f);
150: else if (0 == strcmp(p, "3p"))
151: return(MSEC_3p);
152: else if (0 == strcmp(p, "4"))
153: return(MSEC_4);
154: else if (0 == strcmp(p, "5"))
155: return(MSEC_5);
156: else if (0 == strcmp(p, "6"))
157: return(MSEC_6);
158: else if (0 == strcmp(p, "7"))
159: return(MSEC_7);
160: else if (0 == strcmp(p, "8"))
161: return(MSEC_8);
162: else if (0 == strcmp(p, "9"))
163: return(MSEC_9);
164: else if (0 == strcmp(p, "X11"))
165: return(MSEC_X11);
166: else if (0 == strcmp(p, "X11R6"))
167: return(MSEC_X11R6);
168: else if (0 == strcmp(p, "local"))
169: return(MSEC_local);
170: else if (0 == strcmp(p, "n"))
171: return(MSEC_n);
172: else if (0 == strcmp(p, "unass"))
173: return(MSEC_unass);
174: else if (0 == strcmp(p, "draft"))
175: return(MSEC_draft);
176: else if (0 == strcmp(p, "paper"))
177: return(MSEC_paper);
178:
179: return(MSEC_DEFAULT);
180: }
181:
182:
183: enum mdoc_vol
184: mdoc_atovol(const char *p)
185: {
186:
187: if (0 == strcmp(p, "AMD"))
188: return(VOL_AMD);
189: else if (0 == strcmp(p, "IND"))
190: return(VOL_IND);
191: else if (0 == strcmp(p, "KM"))
192: return(VOL_KM);
193: else if (0 == strcmp(p, "LOCAL"))
194: return(VOL_LOCAL);
195: else if (0 == strcmp(p, "PRM"))
196: return(VOL_PRM);
197: else if (0 == strcmp(p, "PS1"))
198: return(VOL_PS1);
199: else if (0 == strcmp(p, "SMM"))
200: return(VOL_SMM);
201: else if (0 == strcmp(p, "URM"))
202: return(VOL_URM);
203: else if (0 == strcmp(p, "USD"))
204: return(VOL_USD);
205:
206: return(VOL_DEFAULT);
207: }
208:
209:
210: enum mdoc_arch
211: mdoc_atoarch(const char *p)
212: {
213:
214: if (0 == strcmp(p, "alpha"))
215: return(ARCH_alpha);
216: else if (0 == strcmp(p, "amd64"))
217: return(ARCH_amd64);
218: else if (0 == strcmp(p, "amiga"))
219: return(ARCH_amiga);
220: else if (0 == strcmp(p, "arc"))
221: return(ARCH_arc);
222: else if (0 == strcmp(p, "armish"))
223: return(ARCH_armish);
224: else if (0 == strcmp(p, "aviion"))
225: return(ARCH_aviion);
226: else if (0 == strcmp(p, "hp300"))
227: return(ARCH_hp300);
228: else if (0 == strcmp(p, "hppa"))
229: return(ARCH_hppa);
230: else if (0 == strcmp(p, "hppa64"))
231: return(ARCH_hppa64);
232: else if (0 == strcmp(p, "i386"))
233: return(ARCH_i386);
234: else if (0 == strcmp(p, "landisk"))
235: return(ARCH_landisk);
236: else if (0 == strcmp(p, "luna88k"))
237: return(ARCH_luna88k);
238: else if (0 == strcmp(p, "mac68k"))
239: return(ARCH_mac68k);
240: else if (0 == strcmp(p, "macppc"))
241: return(ARCH_macppc);
242: else if (0 == strcmp(p, "mvme68k"))
243: return(ARCH_mvme68k);
244: else if (0 == strcmp(p, "mvme88k"))
245: return(ARCH_mvme88k);
246: else if (0 == strcmp(p, "mvmeppc"))
247: return(ARCH_mvmeppc);
248: else if (0 == strcmp(p, "pmax"))
249: return(ARCH_pmax);
250: else if (0 == strcmp(p, "sgi"))
251: return(ARCH_sgi);
252: else if (0 == strcmp(p, "socppc"))
253: return(ARCH_socppc);
254: else if (0 == strcmp(p, "sparc"))
255: return(ARCH_sparc);
256: else if (0 == strcmp(p, "sparc64"))
257: return(ARCH_sparc64);
258: else if (0 == strcmp(p, "sun3"))
259: return(ARCH_sun3);
260: else if (0 == strcmp(p, "vax"))
261: return(ARCH_vax);
262: else if (0 == strcmp(p, "zaurus"))
263: return(ARCH_zaurus);
264:
265: return(ARCH_DEFAULT);
266: }
CVSweb