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