Lines Matching defs:mdoc

1 /*	$Id: mdoc.c,v 1.238 2015/02/12 13:00:52 schwarze Exp $ */
30 #include "mdoc.h"
86 static void mdoc_node_unlink(struct mdoc *,
88 static void mdoc_free1(struct mdoc *);
89 static void mdoc_alloc1(struct mdoc *);
90 static struct mdoc_node *node_alloc(struct mdoc *, int, int,
92 static void node_append(struct mdoc *, struct mdoc_node *);
93 static int mdoc_ptext(struct mdoc *, int, char *, int);
94 static int mdoc_pmacro(struct mdoc *, int, char *, int);
98 mdoc_node(const struct mdoc *mdoc)
101 return(mdoc->first);
105 mdoc_meta(const struct mdoc *mdoc)
108 return(&mdoc->meta);
115 mdoc_free1(struct mdoc *mdoc)
118 if (mdoc->first)
119 mdoc_node_delete(mdoc, mdoc->first);
120 free(mdoc->meta.msec);
121 free(mdoc->meta.vol);
122 free(mdoc->meta.arch);
123 free(mdoc->meta.date);
124 free(mdoc->meta.title);
125 free(mdoc->meta.os);
126 free(mdoc->meta.name);
133 mdoc_alloc1(struct mdoc *mdoc)
136 memset(&mdoc->meta, 0, sizeof(struct mdoc_meta));
137 mdoc->flags = 0;
138 mdoc->lastnamed = mdoc->lastsec = SEC_NONE;
139 mdoc->last = mandoc_calloc(1, sizeof(struct mdoc_node));
140 mdoc->first = mdoc->last;
141 mdoc->last->type = MDOC_ROOT;
142 mdoc->last->tok = MDOC_MAX;
143 mdoc->next = MDOC_NEXT_CHILD;
153 mdoc_reset(struct mdoc *mdoc)
156 mdoc_free1(mdoc);
157 mdoc_alloc1(mdoc);
165 mdoc_free(struct mdoc *mdoc)
168 mdoc_free1(mdoc);
169 free(mdoc);
175 struct mdoc *
179 struct mdoc *p;
181 p = mandoc_calloc(1, sizeof(struct mdoc));
194 mdoc_endparse(struct mdoc *mdoc)
197 mdoc_macroend(mdoc);
201 mdoc_addeqn(struct mdoc *mdoc, const struct eqn *ep)
205 n = node_alloc(mdoc, ep->ln, ep->pos, MDOC_MAX, MDOC_EQN);
207 if (ep->ln > mdoc->last->line)
209 node_append(mdoc, n);
210 mdoc->next = MDOC_NEXT_SIBLING;
214 mdoc_addspan(struct mdoc *mdoc, const struct tbl_span *sp)
218 n = node_alloc(mdoc, sp->line, 0, MDOC_MAX, MDOC_TBL);
220 node_append(mdoc, n);
221 mdoc->next = MDOC_NEXT_SIBLING;
229 mdoc_parseln(struct mdoc *mdoc, int ln, char *buf, int offs)
232 if (mdoc->last->type != MDOC_EQN || ln > mdoc->last->line)
233 mdoc->flags |= MDOC_NEWLINE;
241 if (roff_getreg(mdoc->roff, "nS"))
242 mdoc->flags |= MDOC_SYNOPSIS;
244 mdoc->flags &= ~MDOC_SYNOPSIS;
246 return(roff_getcontrol(mdoc->roff, buf, &offs) ?
247 mdoc_pmacro(mdoc, ln, buf, offs) :
248 mdoc_ptext(mdoc, ln, buf, offs));
256 if (mdoc->flags & MDOC_PBODY) {
259 mdoc->parse, line, ppos,
264 if (mdoc->meta.title == NULL) {
266 mdoc->parse, line, ppos, "%s %s",
268 mdoc->meta.title = mandoc_strdup("UNTITLED");
270 if (NULL == mdoc->meta.vol)
271 mdoc->meta.vol = mandoc_strdup("LOCAL");
272 mdoc->flags |= MDOC_PBODY;
274 (*mdoc_macros[tok].fp)(mdoc, tok, line, ppos, pos, buf);
279 node_append(struct mdoc *mdoc, struct mdoc_node *p)
282 assert(mdoc->last);
283 assert(mdoc->first);
286 switch (mdoc->next) {
288 mdoc->last->next = p;
289 p->prev = mdoc->last;
290 p->parent = mdoc->last->parent;
293 mdoc->last->child = p;
294 p->parent = mdoc->last;
322 mdoc_valid_pre(mdoc, p);
343 mdoc->last = p;
349 mdoc_valid_post(mdoc);
357 node_alloc(struct mdoc *mdoc, int line, int pos,
363 p->sec = mdoc->lastsec;
371 if (MDOC_SYNOPSIS & mdoc->flags)
375 if (MDOC_NEWLINE & mdoc->flags)
377 mdoc->flags &= ~MDOC_NEWLINE;
383 mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
387 p = node_alloc(mdoc, line, pos, tok, MDOC_TAIL);
388 node_append(mdoc, p);
389 mdoc->next = MDOC_NEXT_CHILD;
393 mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
397 assert(mdoc->first);
398 assert(mdoc->last);
399 p = node_alloc(mdoc, line, pos, tok, MDOC_HEAD);
400 node_append(mdoc, p);
401 mdoc->next = MDOC_NEXT_CHILD;
406 mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
410 p = node_alloc(mdoc, line, pos, tok, MDOC_BODY);
411 node_append(mdoc, p);
412 mdoc->next = MDOC_NEXT_CHILD;
417 mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok,
424 p = node_alloc(mdoc, line, pos, tok, MDOC_BODY);
428 node_append(mdoc, p);
429 mdoc->next = MDOC_NEXT_SIBLING;
434 mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
439 p = node_alloc(mdoc, line, pos, tok, MDOC_BLOCK);
459 node_append(mdoc, p);
460 mdoc->next = MDOC_NEXT_CHILD;
465 mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos,
470 p = node_alloc(mdoc, line, pos, tok, MDOC_ELEM);
482 node_append(mdoc, p);
483 mdoc->next = MDOC_NEXT_CHILD;
487 mdoc_word_alloc(struct mdoc *mdoc, int line, int pos, const char *p)
491 n = node_alloc(mdoc, line, pos, MDOC_MAX, MDOC_TEXT);
492 n->string = roff_strdup(mdoc->roff, p);
493 node_append(mdoc, n);
494 mdoc->next = MDOC_NEXT_SIBLING;
498 mdoc_word_append(struct mdoc *mdoc, const char *p)
503 n = mdoc->last;
504 addstr = roff_strdup(mdoc->roff, p);
509 mdoc->next = MDOC_NEXT_SIBLING;
526 mdoc_node_unlink(struct mdoc *mdoc, struct mdoc_node *n)
548 if (mdoc && mdoc->last == n) {
550 mdoc->last = n->prev;
551 mdoc->next = MDOC_NEXT_SIBLING;
553 mdoc->last = n->parent;
554 mdoc->next = MDOC_NEXT_CHILD;
558 if (mdoc && mdoc->first == n)
559 mdoc->first = NULL;
563 mdoc_node_delete(struct mdoc *mdoc, struct mdoc_node *p)
568 mdoc_node_delete(mdoc, p->child);
572 mdoc_node_unlink(mdoc, p);
577 mdoc_node_relink(struct mdoc *mdoc, struct mdoc_node *p)
580 mdoc_node_unlink(mdoc, p);
581 node_append(mdoc, p);
589 mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int offs)
594 assert(mdoc->last);
595 n = mdoc->last;
607 mdoc->flags |= MDOC_FREECOL;
608 mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf);
617 mdoc->flags |= MDOC_FREECOL;
618 mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf);
647 if (MDOC_LITERAL & mdoc->flags)
664 mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
667 if (buf[offs] == '\0' && ! (mdoc->flags & MDOC_LITERAL)) {
668 mandoc_msg(MANDOCERR_FI_BLANK, mdoc->parse,
676 mdoc_elem_alloc(mdoc, line, offs, MDOC_sp, NULL);
677 mdoc->next = MDOC_NEXT_SIBLING;
678 mdoc_valid_post(mdoc);
682 mdoc_word_alloc(mdoc, line, offs, buf+offs);
684 if (mdoc->flags & MDOC_LITERAL)
696 mdoc->last->flags |= MDOC_EOS;
705 mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs)
729 mandoc_msg(MANDOCERR_MACRO, mdoc->parse,
760 mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
768 if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) {
769 mdoc_macro(mdoc, tok, ln, sv, &offs, buf);
773 n = mdoc->last;
774 assert(mdoc->last);
783 mdoc->flags |= MDOC_FREECOL;
784 mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf);
798 mdoc->flags |= MDOC_FREECOL;
799 mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf);
805 mdoc_macro(mdoc, tok, ln, sv, &offs, buf);
809 if (mdoc->quick && MDOC_Sh == tok &&
810 SEC_NAME != mdoc->last->sec)