]>
git.cameronkatri.com Git - mandoc.git/blob - man_macro.c
1 /* $Id: man_macro.c,v 1.18 2009/07/24 20:22:24 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 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 above
7 * copyright notice and this permission notice appear in all copies.
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.
24 #define FL_NLINE (1 << 0)
25 #define FL_TLINE (1 << 1)
27 static int man_args(struct man
*, int,
28 int *, char *, char **);
30 static int man_flags
[MAN_MAX
] = {
58 man_macro(struct man
*man
, int tok
, int line
,
59 int ppos
, int *pos
, char *buf
)
65 if ( ! man_elem_alloc(man
, line
, ppos
, tok
))
68 man
->next
= MAN_NEXT_CHILD
;
72 w
= man_args(man
, line
, pos
, buf
, &p
);
79 if ( ! man_word_alloc(man
, line
, la
, p
))
81 man
->next
= MAN_NEXT_SIBLING
;
84 if (n
== man
->last
&& (FL_NLINE
& man_flags
[tok
])) {
85 if (MAN_NLINE
& man
->flags
)
86 return(man_perr(man
, line
, ppos
, WLNSCOPE
));
87 man
->flags
|= MAN_NLINE
;
91 if (FL_TLINE
& man_flags
[tok
]) {
92 if (MAN_NLINE
& man
->flags
)
93 return(man_perr(man
, line
, ppos
, WLNSCOPE
));
94 man
->flags
|= MAN_NLINE
;
99 * Note that when TH is pruned, we'll be back at the root, so
100 * make sure that we don't clobber as its sibling.
103 for ( ; man
->last
; man
->last
= man
->last
->parent
) {
106 if (man
->last
->type
== MAN_ROOT
)
108 if ( ! man_valid_post(man
))
110 if ( ! man_action_post(man
))
117 * Same here regarding whether we're back at the root.
120 if (man
->last
->type
!= MAN_ROOT
&& ! man_valid_post(man
))
122 if (man
->last
->type
!= MAN_ROOT
&& ! man_action_post(man
))
124 if (man
->last
->type
!= MAN_ROOT
)
125 man
->next
= MAN_NEXT_SIBLING
;
132 man_macroend(struct man
*m
)
135 for ( ; m
->last
&& m
->last
!= m
->first
;
136 m
->last
= m
->last
->parent
) {
137 if ( ! man_valid_post(m
))
139 if ( ! man_action_post(m
))
142 assert(m
->last
== m
->first
);
144 if ( ! man_valid_post(m
))
146 if ( ! man_action_post(m
))
155 man_args(struct man
*m
, int line
,
156 int *pos
, char *buf
, char **v
)
162 /* First parse non-quoted strings. */
164 if ('\"' != buf
[*pos
]) {
168 if (' ' == buf
[*pos
])
169 if ('\\' != buf
[*pos
- 1])
182 while (buf
[*pos
] && ' ' == buf
[*pos
])
188 if ( ! man_pwarn(m
, line
, *pos
, WTSPACE
))
195 * If we're a quoted string (and quoted strings are allowed),
196 * then parse ahead to the next quote. If none's found, it's an
197 * error. After, parse to the next word.
202 while (buf
[*pos
] && '\"' != buf
[*pos
])
205 if (0 == buf
[*pos
]) {
206 if ( ! man_pwarn(m
, line
, *pos
, WTQUOTE
))
215 while (buf
[*pos
] && ' ' == buf
[*pos
])
221 if ( ! man_pwarn(m
, line
, *pos
, WTSPACE
))