Lines Matching defs:man
1 /* $Id: man.c,v 1.149 2015/01/30 21:28:46 schwarze Exp $ */
30 #include "man.h"
51 static void man_alloc1(struct man *);
52 static void man_breakscope(struct man *, enum mant);
53 static void man_descope(struct man *, int, int);
54 static void man_free1(struct man *);
55 static struct man_node *man_node_alloc(struct man *, int, int,
57 static void man_node_append(struct man *, struct man_node *);
59 static void man_node_unlink(struct man *,
61 static int man_ptext(struct man *, int, char *, int);
62 static int man_pmacro(struct man *, int, char *, int);
66 man_node(const struct man *man)
69 return(man->first);
73 man_meta(const struct man *man)
76 return(&man->meta);
80 man_reset(struct man *man)
83 man_free1(man);
84 man_alloc1(man);
88 man_free(struct man *man)
91 man_free1(man);
92 free(man);
95 struct man *
99 struct man *p;
101 p = mandoc_calloc(1, sizeof(struct man));
114 man_endparse(struct man *man)
117 man_macroend(man);
121 man_parseln(struct man *man, int ln, char *buf, int offs)
124 if (man->last->type != MAN_EQN || ln > man->last->line)
125 man->flags |= MAN_NEWLINE;
127 return (roff_getcontrol(man->roff, buf, &offs) ?
128 man_pmacro(man, ln, buf, offs) :
129 man_ptext(man, ln, buf, offs));
133 man_free1(struct man *man)
136 if (man->first)
137 man_node_delete(man, man->first);
138 free(man->meta.title);
139 free(man->meta.source);
140 free(man->meta.date);
141 free(man->meta.vol);
142 free(man->meta.msec);
146 man_alloc1(struct man *man)
149 memset(&man->meta, 0, sizeof(struct man_meta));
150 man->flags = 0;
151 man->last = mandoc_calloc(1, sizeof(struct man_node));
152 man->first = man->last;
153 man->last->type = MAN_ROOT;
154 man->last->tok = MAN_MAX;
155 man->next = MAN_NEXT_CHILD;
160 man_node_append(struct man *man, struct man_node *p)
163 assert(man->last);
164 assert(man->first);
167 switch (man->next) {
169 man->last->next = p;
170 p->prev = man->last;
171 p->parent = man->last->parent;
174 man->last->child = p;
175 p->parent = man->last;
188 man->flags &= ~MAN_LITERAL;
202 man->last = p;
208 man_valid_post(man);
216 man_node_alloc(struct man *man, int line, int pos,
227 if (man->flags & MAN_NEWLINE)
229 man->flags &= ~MAN_NEWLINE;
234 man_elem_alloc(struct man *man, int line, int pos, enum mant tok)
238 p = man_node_alloc(man, line, pos, MAN_ELEM, tok);
239 man_node_append(man, p);
240 man->next = MAN_NEXT_CHILD;
244 man_head_alloc(struct man *man, int line, int pos, enum mant tok)
248 p = man_node_alloc(man, line, pos, MAN_HEAD, tok);
249 man_node_append(man, p);
250 man->next = MAN_NEXT_CHILD;
254 man_body_alloc(struct man *man, int line, int pos, enum mant tok)
258 p = man_node_alloc(man, line, pos, MAN_BODY, tok);
259 man_node_append(man, p);
260 man->next = MAN_NEXT_CHILD;
264 man_block_alloc(struct man *man, int line, int pos, enum mant tok)
268 p = man_node_alloc(man, line, pos, MAN_BLOCK, tok);
269 man_node_append(man, p);
270 man->next = MAN_NEXT_CHILD;
274 man_word_alloc(struct man *man, int line, int pos, const char *word)
278 n = man_node_alloc(man, line, pos, MAN_TEXT, MAN_MAX);
279 n->string = roff_strdup(man->roff, word);
280 man_node_append(man, n);
281 man->next = MAN_NEXT_SIBLING;
285 man_word_append(struct man *man, const char *word)
290 n = man->last;
291 addstr = roff_strdup(man->roff, word);
296 man->next = MAN_NEXT_SIBLING;
312 man_node_delete(struct man *man, struct man_node *p)
316 man_node_delete(man, p->child);
318 man_node_unlink(man, p);
323 man_addeqn(struct man *man, const struct eqn *ep)
327 n = man_node_alloc(man, ep->ln, ep->pos, MAN_EQN, MAN_MAX);
329 if (ep->ln > man->last->line)
331 man_node_append(man, n);
332 man->next = MAN_NEXT_SIBLING;
333 man_descope(man, ep->ln, ep->pos);
337 man_addspan(struct man *man, const struct tbl_span *sp)
341 man_breakscope(man, MAN_MAX);
342 n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX);
344 man_node_append(man, n);
345 man->next = MAN_NEXT_SIBLING;
346 man_descope(man, sp->line, 0);
350 man_descope(struct man *man, int line, int offs)
358 if (man->flags & MAN_ELINE) {
359 man->flags &= ~MAN_ELINE;
360 man_unscope(man, man->last->parent);
362 if ( ! (man->flags & MAN_BLINE))
364 man->flags &= ~MAN_BLINE;
365 man_unscope(man, man->last->parent);
366 man_body_alloc(man, line, offs, man->last->tok);
370 man_ptext(struct man *man, int line, char *buf, int offs)
376 if (man->flags & MAN_LITERAL) {
377 man_word_alloc(man, line, offs, buf + offs);
378 man_descope(man, line, offs);
392 if (man->last->tok != MAN_SH &&
393 man->last->tok != MAN_SS) {
394 man_elem_alloc(man, line, offs, MAN_sp);
395 man->next = MAN_NEXT_SIBLING;
410 mandoc_msg(MANDOCERR_SPACE_EOL, man->parse,
421 man_word_alloc(man, line, offs, buf + offs);
431 man->last->flags |= MAN_EOS;
433 man_descope(man, line, offs);
438 man_pmacro(struct man *man, int ln, char *buf, int offs)
463 mandoc_msg(MANDOCERR_MACRO, man->parse,
494 mandoc_msg(MANDOCERR_SPACE_EOL, man->parse,
502 man_breakscope(man, tok);
503 bline = man->flags & MAN_BLINE;
508 (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf);
512 if (man->quick && tok == MAN_SH) {
513 n = man->last;
525 if ( ! bline || man->flags & MAN_ELINE ||
529 assert(man->flags & MAN_BLINE);
530 man->flags &= ~MAN_BLINE;
532 man_unscope(man, man->last->parent);
533 man_body_alloc(man, ln, ppos, man->last->tok);
538 man_breakscope(struct man *man, enum mant tok)
548 if (man->flags & MAN_ELINE && (tok == MAN_MAX ||
550 n = man->last;
555 mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse,
560 man_node_delete(man, n);
561 man->flags &= ~MAN_ELINE;
570 if (man->flags & MAN_BLINE && (tok == MAN_MAX ||
572 n = man->last;
583 mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse,
588 man_node_delete(man, n);
589 man->flags &= ~MAN_BLINE;
594 * Unlink a node from its context. If "man" is provided, the last parse
598 man_node_unlink(struct man *man, struct man_node *n)
618 if (man && man->last == n) {
622 man->last = n->prev;
623 man->next = MAN_NEXT_SIBLING;
625 man->last = n->parent;
626 man->next = MAN_NEXT_CHILD;
630 if (man && man->first == n)
631 man->first = NULL;
635 man_mparse(const struct man *man)
638 assert(man && man->parse);
639 return(man->parse);