]>
git.cameronkatri.com Git - mandoc.git/blob - man_macro.c
1 /* $Id: man_macro.c,v 1.3 2009/03/23 15:20:51 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
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.
21 #include <err.h> /* XXX */
28 static int man_args(struct man
*, int,
29 int *, char *, char **);
33 man_macro(struct man
*man
, int tok
, int line
,
34 int ppos
, int *pos
, char *buf
)
40 if ( ! man_elem_alloc(man
, line
, ppos
, tok
))
43 man
->next
= MAN_NEXT_CHILD
;
47 w
= man_args(man
, line
, pos
, buf
, &p
);
54 if ( ! man_word_alloc(man
, line
, la
, p
))
56 man
->next
= MAN_NEXT_SIBLING
;
63 man
->next
= MAN_NEXT_SIBLING
;
71 man_args(struct man
*man
, int line
,
72 int *pos
, char *buf
, char **v
)
78 /* First parse non-quoted strings. */
80 if ('\"' != buf
[*pos
]) {
85 if ('\\' != buf
[*pos
- 1])
98 while (buf
[*pos
] && ' ' == buf
[*pos
])
104 warnx("tail whitespace");
109 * If we're a quoted string (and quoted strings are allowed),
110 * then parse ahead to the next quote. If none's found, it's an
111 * error. After, parse to the next word.
116 while (buf
[*pos
] && '\"' != buf
[*pos
])
119 if (0 == buf
[*pos
]) {
120 warnx("unterminated quotation");
128 while (buf
[*pos
] && ' ' == buf
[*pos
])
134 warnx("tail whitespace");