]>
git.cameronkatri.com Git - mandoc.git/blob - man_macro.c
1 /* $Id: man_macro.c,v 1.16 2009/06/16 19:55:28 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_verr(man
, line
, ppos
,
86 "next-line scope already open"));
87 man
->flags
|= MAN_NLINE
;
91 if (FL_TLINE
& man_flags
[tok
]) {
92 if (MAN_NLINE
& man
->flags
)
93 return(man_verr(man
, line
, ppos
,
94 "next-line scope already open"));
95 man
->flags
|= MAN_NLINE
;
100 * Note that when TH is pruned, we'll be back at the root, so
101 * make sure that we don't clobber as its sibling.
104 for ( ; man
->last
; man
->last
= man
->last
->parent
) {
107 if (man
->last
->type
== MAN_ROOT
)
109 if ( ! man_valid_post(man
))
111 if ( ! man_action_post(man
))
118 * Same here regarding whether we're back at the root.
121 if (man
->last
->type
!= MAN_ROOT
&& ! man_valid_post(man
))
123 if (man
->last
->type
!= MAN_ROOT
&& ! man_action_post(man
))
125 if (man
->last
->type
!= MAN_ROOT
)
126 man
->next
= MAN_NEXT_SIBLING
;
133 man_macroend(struct man
*m
)
136 for ( ; m
->last
&& m
->last
!= m
->first
;
137 m
->last
= m
->last
->parent
) {
138 if ( ! man_valid_post(m
))
140 if ( ! man_action_post(m
))
143 assert(m
->last
== m
->first
);
145 if ( ! man_valid_post(m
))
147 if ( ! man_action_post(m
))
156 man_args(struct man
*m
, int line
,
157 int *pos
, char *buf
, char **v
)
163 /* First parse non-quoted strings. */
165 if ('\"' != buf
[*pos
]) {
169 if (' ' == buf
[*pos
])
170 if ('\\' != buf
[*pos
- 1])
183 while (buf
[*pos
] && ' ' == buf
[*pos
])
189 if ( ! man_vwarn(m
, line
, *pos
, "trailing spaces"))
196 * If we're a quoted string (and quoted strings are allowed),
197 * then parse ahead to the next quote. If none's found, it's an
198 * error. After, parse to the next word.
203 while (buf
[*pos
] && '\"' != buf
[*pos
])
206 if (0 == buf
[*pos
]) {
207 if ( ! man_vwarn(m
, line
, *pos
, "unterminated quote"))
216 while (buf
[*pos
] && ' ' == buf
[*pos
])
222 if ( ! man_vwarn(m
, line
, *pos
, "trailing spaces"))