diff options
Diffstat (limited to 'man.c')
-rw-r--r-- | man.c | 186 |
1 files changed, 69 insertions, 117 deletions
@@ -50,8 +50,7 @@ const char * const *man_macronames = __man_macronames; static struct man_node *man_node_alloc(struct man *, int, int, enum man_type, enum mant); -static int man_node_append(struct man *, - struct man_node *); +static void man_node_append(struct man *, struct man_node *); static void man_node_free(struct man_node *); static void man_node_unlink(struct man *, struct man_node *); @@ -59,7 +58,7 @@ static int man_ptext(struct man *, int, char *, int); static int man_pmacro(struct man *, int, char *, int); static void man_free1(struct man *); static void man_alloc1(struct man *); -static int man_descope(struct man *, int, int); +static void man_descope(struct man *, int, int); const struct man_node * @@ -112,7 +111,8 @@ int man_endparse(struct man *man) { - return(man_macroend(man)); + man_macroend(man); + return(1); } int @@ -133,16 +133,11 @@ man_free1(struct man *man) if (man->first) man_node_delete(man, man->first); - if (man->meta.title) - free(man->meta.title); - if (man->meta.source) - free(man->meta.source); - if (man->meta.date) - free(man->meta.date); - if (man->meta.vol) - free(man->meta.vol); - if (man->meta.msec) - free(man->meta.msec); + free(man->meta.title); + free(man->meta.source); + free(man->meta.date); + free(man->meta.vol); + free(man->meta.msec); } static void @@ -159,13 +154,13 @@ man_alloc1(struct man *man) } -static int +static void man_node_append(struct man *man, struct man_node *p) { assert(man->last); assert(man->first); - assert(MAN_ROOT != p->type); + assert(p->type != MAN_ROOT); switch (man->next) { case MAN_NEXT_SIBLING: @@ -191,15 +186,11 @@ man_node_append(struct man *man, struct man_node *p) man->flags &= ~MAN_LITERAL; break; case MAN_HEAD: - assert(MAN_BLOCK == p->parent->type); + assert(p->parent->type == MAN_BLOCK); p->parent->head = p; break; - case MAN_TAIL: - assert(MAN_BLOCK == p->parent->type); - p->parent->tail = p; - break; case MAN_BODY: - assert(MAN_BLOCK == p->parent->type); + assert(p->parent->type == MAN_BLOCK); p->parent->body = p; break; default: @@ -212,14 +203,11 @@ man_node_append(struct man *man, struct man_node *p) case MAN_TBL: /* FALLTHROUGH */ case MAN_TEXT: - if ( ! man_valid_post(man)) - return(0); + man_valid_post(man); break; default: break; } - - return(1); } static struct man_node * @@ -234,85 +222,61 @@ man_node_alloc(struct man *man, int line, int pos, p->type = type; p->tok = tok; - if (MAN_NEWLINE & man->flags) + if (man->flags & MAN_NEWLINE) p->flags |= MAN_LINE; man->flags &= ~MAN_NEWLINE; return(p); } -int +void man_elem_alloc(struct man *man, int line, int pos, enum mant tok) { struct man_node *p; p = man_node_alloc(man, line, pos, MAN_ELEM, tok); - if ( ! man_node_append(man, p)) - return(0); - man->next = MAN_NEXT_CHILD; - return(1); -} - -int -man_tail_alloc(struct man *man, int line, int pos, enum mant tok) -{ - struct man_node *p; - - p = man_node_alloc(man, line, pos, MAN_TAIL, tok); - if ( ! man_node_append(man, p)) - return(0); + man_node_append(man, p); man->next = MAN_NEXT_CHILD; - return(1); } -int +void man_head_alloc(struct man *man, int line, int pos, enum mant tok) { struct man_node *p; p = man_node_alloc(man, line, pos, MAN_HEAD, tok); - if ( ! man_node_append(man, p)) - return(0); + man_node_append(man, p); man->next = MAN_NEXT_CHILD; - return(1); } -int +void man_body_alloc(struct man *man, int line, int pos, enum mant tok) { struct man_node *p; p = man_node_alloc(man, line, pos, MAN_BODY, tok); - if ( ! man_node_append(man, p)) - return(0); + man_node_append(man, p); man->next = MAN_NEXT_CHILD; - return(1); } -int +void man_block_alloc(struct man *man, int line, int pos, enum mant tok) { struct man_node *p; p = man_node_alloc(man, line, pos, MAN_BLOCK, tok); - if ( ! man_node_append(man, p)) - return(0); + man_node_append(man, p); man->next = MAN_NEXT_CHILD; - return(1); } -int +void man_word_alloc(struct man *man, int line, int pos, const char *word) { struct man_node *n; n = man_node_alloc(man, line, pos, MAN_TEXT, MAN_MAX); n->string = roff_strdup(man->roff, word); - - if ( ! man_node_append(man, n)) - return(0); - + man_node_append(man, n); man->next = MAN_NEXT_SIBLING; - return(1); } void @@ -338,8 +302,7 @@ static void man_node_free(struct man_node *p) { - if (p->string) - free(p->string); + free(p->string); free(p); } @@ -363,12 +326,10 @@ man_addeqn(struct man *man, const struct eqn *ep) n->eqn = ep; if (ep->ln > man->last->line) n->flags |= MAN_LINE; - - if ( ! man_node_append(man, n)) - return(0); - + man_node_append(man, n); man->next = MAN_NEXT_SIBLING; - return(man_descope(man, ep->ln, ep->pos)); + man_descope(man, ep->ln, ep->pos); + return(1); } int @@ -378,15 +339,13 @@ man_addspan(struct man *man, const struct tbl_span *sp) n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX); n->span = sp; - - if ( ! man_node_append(man, n)) - return(0); - + man_node_append(man, n); man->next = MAN_NEXT_SIBLING; - return(man_descope(man, sp->line, 0)); + man_descope(man, sp->line, 0); + return(1); } -static int +static void man_descope(struct man *man, int line, int offs) { /* @@ -395,19 +354,15 @@ man_descope(struct man *man, int line, int offs) * out the block scope (also if applicable). */ - if (MAN_ELINE & man->flags) { + if (man->flags & MAN_ELINE) { man->flags &= ~MAN_ELINE; - if ( ! man_unscope(man, man->last->parent)) - return(0); + man_unscope(man, man->last->parent); } - - if ( ! (MAN_BLINE & man->flags)) - return(1); + if ( ! (man->flags & MAN_BLINE)) + return; man->flags &= ~MAN_BLINE; - - if ( ! man_unscope(man, man->last->parent)) - return(0); - return(man_body_alloc(man, line, offs, man->last->tok)); + man_unscope(man, man->last->parent); + man_body_alloc(man, line, offs, man->last->tok); } static int @@ -417,13 +372,13 @@ man_ptext(struct man *man, int line, char *buf, int offs) /* Literal free-form text whitespace is preserved. */ - if (MAN_LITERAL & man->flags) { - if ( ! man_word_alloc(man, line, offs, buf + offs)) - return(0); - return(man_descope(man, line, offs)); + if (man->flags & MAN_LITERAL) { + man_word_alloc(man, line, offs, buf + offs); + man_descope(man, line, offs); + return(1); } - for (i = offs; ' ' == buf[i]; i++) + for (i = offs; buf[i] == ' '; i++) /* Skip leading whitespace. */ ; /* @@ -431,12 +386,11 @@ man_ptext(struct man *man, int line, char *buf, int offs) * but add a single vertical space elsewhere. */ - if ('\0' == buf[i]) { + if (buf[i] == '\0') { /* Allocate a blank entry. */ - if (MAN_SH != man->last->tok && - MAN_SS != man->last->tok) { - if ( ! man_elem_alloc(man, line, offs, MAN_sp)) - return(0); + if (man->last->tok != MAN_SH && + man->last->tok != MAN_SS) { + man_elem_alloc(man, line, offs, MAN_sp); man->next = MAN_NEXT_SIBLING; } return(1); @@ -463,9 +417,7 @@ man_ptext(struct man *man, int line, char *buf, int offs) buf[i] = '\0'; } - - if ( ! man_word_alloc(man, line, offs, buf + offs)) - return(0); + man_word_alloc(man, line, offs, buf + offs); /* * End-of-sentence check. If the last character is an unescaped @@ -477,7 +429,8 @@ man_ptext(struct man *man, int line, char *buf, int offs) if (mandoc_eos(buf, (size_t)i)) man->last->flags |= MAN_EOS; - return(man_descope(man, line, offs)); + man_descope(man, line, offs); + return(1); } static int @@ -528,7 +481,7 @@ man_pmacro(struct man *man, int ln, char *buf, int offs) /* Jump to the next non-whitespace word. */ - while (buf[offs] && ' ' == buf[offs]) + while (buf[offs] && buf[offs] == ' ') offs++; /* @@ -536,7 +489,7 @@ man_pmacro(struct man *man, int ln, char *buf, int offs) * into the parser as "text", so we only warn about spaces here. */ - if ('\0' == buf[offs] && ' ' == buf[offs - 1]) + if (buf[offs] == '\0' && buf[offs - 1] == ' ') mandoc_msg(MANDOCERR_SPACE_EOL, man->parse, ln, offs - 1, NULL); @@ -546,14 +499,14 @@ man_pmacro(struct man *man, int ln, char *buf, int offs) * macros---they don't print text---so we let those slip by. */ - if ( ! (MAN_NSCOPED & man_macros[tok].flags) && + if ( ! (man_macros[tok].flags & MAN_NSCOPED) && man->flags & MAN_ELINE) { n = man->last; assert(MAN_TEXT != n->type); /* Remove repeated NSCOPED macros causing ELINE. */ - if (MAN_NSCOPED & man_macros[n->tok].flags) + if (man_macros[n->tok].flags & MAN_NSCOPED) n = n->parent; mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, @@ -568,24 +521,24 @@ man_pmacro(struct man *man, int ln, char *buf, int offs) * Remove prior BLINE macro that is being clobbered. */ if ((man->flags & MAN_BLINE) && - (MAN_BSCOPE & man_macros[tok].flags)) { + (man_macros[tok].flags & MAN_BSCOPE)) { n = man->last; /* Might be a text node like 8 in * .TP 8 * .SH foo */ - if (MAN_TEXT == n->type) + if (n->type == MAN_TEXT) n = n->parent; /* Remove element that didn't end BLINE, if any. */ - if ( ! (MAN_BSCOPE & man_macros[n->tok].flags)) + if ( ! (man_macros[n->tok].flags & MAN_BSCOPE)) n = n->parent; - assert(MAN_HEAD == n->type); + assert(n->type == MAN_HEAD); n = n->parent; - assert(MAN_BLOCK == n->type); - assert(MAN_SCOPED & man_macros[n->tok].flags); + assert(n->type == MAN_BLOCK); + assert(man_macros[n->tok].flags & MAN_SCOPED); mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, n->pos, "%s breaks %s", man_macronames[tok], @@ -602,14 +555,13 @@ man_pmacro(struct man *man, int ln, char *buf, int offs) /* Call to handler... */ assert(man_macros[tok].fp); - if ( ! (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf)) - return(0); + (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf); /* In quick mode (for mandocdb), abort after the NAME section. */ - if (man->quick && MAN_SH == tok) { + if (man->quick && tok == MAN_SH) { n = man->last; - if (MAN_BODY == n->type && + if (n->type == MAN_BODY && strcmp(n->prev->child->string, "NAME")) return(2); } @@ -624,12 +576,12 @@ man_pmacro(struct man *man, int ln, char *buf, int offs) man_macros[tok].flags & MAN_NSCOPED) return(1); - assert(MAN_BLINE & man->flags); + assert(man->flags & MAN_BLINE); man->flags &= ~MAN_BLINE; - if ( ! man_unscope(man, man->last->parent)) - return(0); - return(man_body_alloc(man, ln, ppos, man->last->tok)); + man_unscope(man, man->last->parent); + man_body_alloc(man, ln, ppos, man->last->tok); + return(1); } /* @@ -687,7 +639,7 @@ man_deroff(char **dest, const struct man_node *n) char *cp; size_t sz; - if (MAN_TEXT != n->type) { + if (n->type != MAN_TEXT) { for (n = n->child; n; n = n->next) man_deroff(dest, n); return; |