]>
git.cameronkatri.com Git - mandoc.git/blob - man_macro.c
1 /* $Id: man_macro.c,v 1.17 2009/06/18 10:53:58 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
] = {
57 man_macro(struct man
*man
, int tok
, int line
,
58 int ppos
, int *pos
, char *buf
)
64 if ( ! man_elem_alloc(man
, line
, ppos
, tok
))
67 man
->next
= MAN_NEXT_CHILD
;
71 w
= man_args(man
, line
, pos
, buf
, &p
);
78 if ( ! man_word_alloc(man
, line
, la
, p
))
80 man
->next
= MAN_NEXT_SIBLING
;
83 if (n
== man
->last
&& (FL_NLINE
& man_flags
[tok
])) {
84 if (MAN_NLINE
& man
->flags
)
85 return(man_perr(man
, line
, ppos
, WLNSCOPE
));
86 man
->flags
|= MAN_NLINE
;
90 if (FL_TLINE
& man_flags
[tok
]) {
91 if (MAN_NLINE
& man
->flags
)
92 return(man_perr(man
, line
, ppos
, WLNSCOPE
));
93 man
->flags
|= MAN_NLINE
;
98 * Note that when TH is pruned, we'll be back at the root, so
99 * make sure that we don't clobber as its sibling.
102 for ( ; man
->last
; man
->last
= man
->last
->parent
) {
105 if (man
->last
->type
== MAN_ROOT
)
107 if ( ! man_valid_post(man
))
109 if ( ! man_action_post(man
))
116 * Same here regarding whether we're back at the root.
119 if (man
->last
->type
!= MAN_ROOT
&& ! man_valid_post(man
))
121 if (man
->last
->type
!= MAN_ROOT
&& ! man_action_post(man
))
123 if (man
->last
->type
!= MAN_ROOT
)
124 man
->next
= MAN_NEXT_SIBLING
;
131 man_macroend(struct man
*m
)
134 for ( ; m
->last
&& m
->last
!= m
->first
;
135 m
->last
= m
->last
->parent
) {
136 if ( ! man_valid_post(m
))
138 if ( ! man_action_post(m
))
141 assert(m
->last
== m
->first
);
143 if ( ! man_valid_post(m
))
145 if ( ! man_action_post(m
))
154 man_args(struct man
*m
, int line
,
155 int *pos
, char *buf
, char **v
)
161 /* First parse non-quoted strings. */
163 if ('\"' != buf
[*pos
]) {
167 if (' ' == buf
[*pos
])
168 if ('\\' != buf
[*pos
- 1])
181 while (buf
[*pos
] && ' ' == buf
[*pos
])
187 if ( ! man_pwarn(m
, line
, *pos
, WTSPACE
))
194 * If we're a quoted string (and quoted strings are allowed),
195 * then parse ahead to the next quote. If none's found, it's an
196 * error. After, parse to the next word.
201 while (buf
[*pos
] && '\"' != buf
[*pos
])
204 if (0 == buf
[*pos
]) {
205 if ( ! man_pwarn(m
, line
, *pos
, WTQUOTE
))
214 while (buf
[*pos
] && ' ' == buf
[*pos
])
220 if ( ! man_pwarn(m
, line
, *pos
, WTSPACE
))