]> git.cameronkatri.com Git - mandoc.git/blob - mandoc.c
Fixed mdoc_nwarn/mdoc_nerr considering themselves err/warn instead of warn/err (BIG...
[mandoc.git] / mandoc.c
1 /* $Id: mandoc.c,v 1.1 2009/07/04 09:01:55 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 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 above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17 #include <assert.h>
18 #include <ctype.h>
19 #include <stdlib.h>
20
21 #include "libmandoc.h"
22
23 int
24 mandoc_special(const char *p)
25 {
26 int c;
27
28 if ('\\' != *p++)
29 return(0);
30
31 switch (*p) {
32 case ('\\'):
33 /* FALLTHROUGH */
34 case ('\''):
35 /* FALLTHROUGH */
36 case ('`'):
37 /* FALLTHROUGH */
38 case ('q'):
39 /* FALLTHROUGH */
40 case ('-'):
41 /* FALLTHROUGH */
42 case ('~'):
43 /* FALLTHROUGH */
44 case ('^'):
45 /* FALLTHROUGH */
46 case ('%'):
47 /* FALLTHROUGH */
48 case ('0'):
49 /* FALLTHROUGH */
50 case (' '):
51 /* FALLTHROUGH */
52 case ('|'):
53 /* FALLTHROUGH */
54 case ('&'):
55 /* FALLTHROUGH */
56 case ('.'):
57 /* FALLTHROUGH */
58 case (':'):
59 /* FALLTHROUGH */
60 case ('e'):
61 return(2);
62 case ('f'):
63 if (0 == *++p || ! isgraph((u_char)*p))
64 return(0);
65 return(3);
66 case ('*'):
67 if (0 == *++p || ! isgraph((u_char)*p))
68 return(0);
69 switch (*p) {
70 case ('('):
71 if (0 == *++p || ! isgraph((u_char)*p))
72 return(0);
73 return(4);
74 case ('['):
75 for (c = 3, p++; *p && ']' != *p; p++, c++)
76 if ( ! isgraph((u_char)*p))
77 break;
78 return(*p == ']' ? c : 0);
79 default:
80 break;
81 }
82 return(3);
83 case ('('):
84 if (0 == *++p || ! isgraph((u_char)*p))
85 return(0);
86 if (0 == *++p || ! isgraph((u_char)*p))
87 return(0);
88 return(4);
89 case ('['):
90 break;
91 default:
92 return(0);
93 }
94
95 for (c = 3, p++; *p && ']' != *p; p++, c++)
96 if ( ! isgraph((u_char)*p))
97 break;
98
99 return(*p == ']' ? c : 0);
100 }
101