static struct mdoc_node * node_alloc(struct mdoc *m, int line, int pos, enum mdoct tok, enum mdoc_type type) { struct mdoc_node *p; p = mandoc_calloc(1, sizeof(struct mdoc_node)); p->sec = m->lastsec; p->line = line; p->pos = pos; p->tok = tok; p->type = type; /* Flag analysis. */ if (MDOC_SYNOPSIS & m->flags) p->flags |= MDOC_SYNPRETTY; else p->flags &= ~MDOC_SYNPRETTY; if (MDOC_NEWLINE & m->flags) p->flags |= MDOC_LINE; m->flags &= ~MDOC_NEWLINE; return(p); }
struct mdoc_node * mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; p = node_alloc(mdoc, line, pos, tok, MDOC_BLOCK); p->args = args; if (p->args) (args->refcnt)++; switch (tok) { case MDOC_Bd: /* FALLTHROUGH */ case MDOC_Bf: /* FALLTHROUGH */ case MDOC_Bl: /* FALLTHROUGH */ case MDOC_En: /* FALLTHROUGH */ case MDOC_Rs: p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: break; } node_append(mdoc, p); mdoc->next = MDOC_NEXT_CHILD; return(p); }
static void * ml_alloc(char *outopts, enum htmltype type) { struct html *h; const char *toks[4]; char *v; toks[0] = "style"; toks[1] = "man"; toks[2] = "includes"; toks[3] = NULL; h = mandoc_calloc(1, sizeof(struct html)); h->type = type; h->tags.head = NULL; h->symtab = mchars_alloc(); while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { case (0): h->style = v; break; case (1): h->base_man = v; break; case (2): h->base_includes = v; break; default: break; } return(h); }
struct mchars * mchars_alloc(void) { struct mchars *tab; struct ln **htab; struct ln *pp; int i, hash; /* * Constructs a very basic chaining hashtable. The hash routine * is simply the integral value of the first character. * Subsequent entries are chained in the order they're processed. */ tab = mandoc_malloc(sizeof(struct mchars)); htab = mandoc_calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); for (i = 0; i < LINES_MAX; i++) { hash = (int)lines[i].code[0] - PRINT_LO; if (NULL == (pp = htab[hash])) { htab[hash] = &lines[i]; continue; } for ( ; pp->next; pp = pp->next) /* Scan ahead. */ ; pp->next = &lines[i]; } tab->htab = htab; return(tab); }
void mparse_keep(struct mparse *p) { assert(NULL == p->secondary); p->secondary = mandoc_calloc(1, sizeof(struct buf)); }
int mdoc_block_alloc(struct mdoc *m, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; p = node_alloc(m, line, pos, tok, MDOC_BLOCK); p->args = args; if (p->args) (args->refcnt)++; switch (tok) { case (MDOC_Bd): /* FALLTHROUGH */ case (MDOC_Bf): /* FALLTHROUGH */ case (MDOC_Bl): /* FALLTHROUGH */ case (MDOC_Rs): p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: break; } if ( ! node_append(m, p)) return(0); m->next = MDOC_NEXT_CHILD; return(1); }
enum rofferr eqn_end(struct eqn_node **epp) { struct eqn_node *ep; struct eqn_box *root; enum eqn_rest c; ep = *epp; *epp = NULL; ep->eqn.root = mandoc_calloc(1, sizeof(struct eqn_box)); root = ep->eqn.root; root->type = EQN_ROOT; if (0 == ep->sz) return(ROFF_IGN); if (EQN_DESCOPE == (c = eqn_eqn(ep, root))) { EQN_MSG(MANDOCERR_EQNNSCOPE, ep); c = EQN_ERR; } return(EQN_EOF == c ? ROFF_EQN : ROFF_IGN); }
struct eqn_node * eqn_alloc(const char *name, int pos, int line, struct mparse *parse) { struct eqn_node *p; size_t sz; const char *end; p = mandoc_calloc(1, sizeof(struct eqn_node)); if (name && '\0' != *name) { sz = strlen(name); assert(sz); do { sz--; end = name + (int)sz; } while (' ' == *end || '\t' == *end); p->eqn.name = mandoc_strndup(name, sz + 1); } p->parse = parse; p->eqn.ln = line; p->eqn.pos = pos; p->gsize = EQN_DEFSIZE; return(p); }
struct mparse * mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg, const char *defos) { struct mparse *curp; curp = mandoc_calloc(1, sizeof(struct mparse)); curp->options = options; curp->wlevel = wlevel; curp->mmsg = mmsg; curp->defos = defos; curp->roff = roff_alloc(curp, options); curp->man = roff_man_alloc( curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); if (curp->options & MPARSE_MDOC) { mdoc_hash_init(); curp->man->macroset = MACROSET_MDOC; } else if (curp->options & MPARSE_MAN) { man_hash_init(); curp->man->macroset = MACROSET_MAN; } curp->man->first->tok = TOKEN_NONE; return curp; }
struct mparse * mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg, const char *defos) { struct mparse *curp; assert(wlevel <= MANDOCLEVEL_FATAL); curp = mandoc_calloc(1, sizeof(struct mparse)); curp->options = options; curp->wlevel = wlevel; curp->mmsg = mmsg; curp->defos = defos; curp->roff = roff_alloc(curp, options); if (curp->options & MPARSE_MDOC) curp->pmdoc = mdoc_alloc( curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); if (curp->options & MPARSE_MAN) curp->pman = man_alloc(curp->roff, curp, curp->options & MPARSE_QUICK ? 1 : 0); return(curp); }
static struct tbl_cell * cell_alloc(struct tbl_node *tbl, struct tbl_row *rp, enum tbl_cellt pos, int vert) { struct tbl_cell *p, *pp; struct tbl_head *h, *hp; p = mandoc_calloc(1, sizeof(struct tbl_cell)); if (NULL != (pp = rp->last)) { pp->next = p; h = pp->head->next; } else { rp->first = p; h = tbl->first_head; } rp->last = p; p->pos = pos; p->vert = vert; /* Re-use header. */ if (h) { p->head = h; return(p); } hp = mandoc_calloc(1, sizeof(struct tbl_head)); hp->ident = tbl->opts.cols++; hp->vert = vert; if (tbl->last_head) { hp->prev = tbl->last_head; tbl->last_head->next = hp; } else tbl->first_head = hp; tbl->last_head = hp; p->head = hp; return(p); }
enum rofferr eqn_end(struct eqn_node **epp) { struct eqn_node *ep; ep = *epp; *epp = NULL; ep->eqn.root = mandoc_calloc(1, sizeof(struct eqn_box)); ep->eqn.root->expectargs = UINT_MAX; return(eqn_parse(ep, ep->eqn.root)); }
/* * Allocate all volatile resources (parse tree, meta-data, fields). */ static void mdoc_alloc1(struct mdoc *mdoc) { memset(&mdoc->meta, 0, sizeof(struct mdoc_meta)); mdoc->flags = 0; mdoc->lastnamed = mdoc->lastsec = SEC_NONE; mdoc->last = mandoc_calloc(1, sizeof(struct mdoc_node)); mdoc->first = mdoc->last; mdoc->last->type = MDOC_ROOT; mdoc->next = MDOC_NEXT_CHILD; }
static void man_alloc1(struct man *man) { memset(&man->meta, 0, sizeof(struct man_meta)); man->flags = 0; man->last = mandoc_calloc(1, sizeof(struct man_node)); man->first = man->last; man->last->type = MAN_ROOT; man->last->tok = MAN_MAX; man->next = MAN_NEXT_CHILD; }
static void row(struct tbl_node *tbl, int ln, const char *p, int *pos) { struct tbl_row *rp; row: /* * EBNF describing this section: * * row ::= row_list [:space:]* [.]?[\n] * row_list ::= [:space:]* row_elem row_tail * row_tail ::= [:space:]*[,] row_list | * epsilon * row_elem ::= [\t\ ]*[:alpha:]+ */ rp = mandoc_calloc(1, sizeof(struct tbl_row)); if (tbl->last_row) tbl->last_row->next = rp; else tbl->first_row = rp; tbl->last_row = rp; cell: while (isspace((unsigned char)p[*pos])) (*pos)++; /* Safely exit layout context. */ if ('.' == p[*pos]) { tbl->part = TBL_PART_DATA; if (NULL == tbl->first_row) mandoc_msg(MANDOCERR_TBLNOLAYOUT, tbl->parse, ln, *pos, NULL); (*pos)++; return; } /* End (and possibly restart) a row. */ if (',' == p[*pos]) { (*pos)++; goto row; } else if ('\0' == p[*pos]) return; if ( ! cell(tbl, rp, ln, p, pos)) return; goto cell; /* NOTREACHED */ }
struct man * man_alloc(struct roff *roff, struct mparse *parse) { struct man *p; p = mandoc_calloc(1, sizeof(struct man)); man_hash_init(); p->parse = parse; p->roff = roff; man_alloc1(p); return(p); }
struct eqn_node * eqn_alloc(int pos, int line, struct mparse *parse) { struct eqn_node *p; p = mandoc_calloc(1, sizeof(struct eqn_node)); p->parse = parse; p->eqn.ln = line; p->eqn.pos = pos; p->gsize = EQN_DEFSIZE; return(p); }
struct tbl_node * tbl_alloc(int pos, int line, struct mparse *parse) { struct tbl_node *p; p = mandoc_calloc(1, sizeof(struct tbl_node)); p->line = line; p->pos = pos; p->parse = parse; p->part = TBL_PART_OPTS; p->opts.tab = '\t'; p->opts.linesize = 12; p->opts.decimal = '.'; return(p); }
/* * Allocate volatile and non-volatile parse resources. */ struct mdoc * mdoc_alloc(struct regset *regs, void *data, mandocmsg msg) { struct mdoc *p; p = mandoc_calloc(1, sizeof(struct mdoc)); p->msg = msg; p->data = data; p->regs = regs; mdoc_hash_init(); mdoc_alloc1(p); return(p); }
void * html_alloc(const struct manoutput *outopts) { struct html *h; h = mandoc_calloc(1, sizeof(struct html)); h->tags.head = NULL; h->style = outopts->style; h->base_man = outopts->man; h->base_includes = outopts->includes; if (outopts->fragment) h->oflags |= HTML_FRAGMENT; return h; }
struct mparse * mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, mandocmsg mmsg, void *arg) { struct mparse *curp; assert(wlevel <= MANDOCLEVEL_FATAL); curp = mandoc_calloc(1, sizeof(struct mparse)); curp->wlevel = wlevel; curp->mmsg = mmsg; curp->arg = arg; curp->inttype = inttype; curp->roff = roff_alloc(curp); return(curp); }
static struct man_node * man_node_alloc(struct man *man, int line, int pos, enum man_type type, enum mant tok) { struct man_node *p; p = mandoc_calloc(1, sizeof(struct man_node)); p->line = line; p->pos = pos; p->type = type; p->tok = tok; if (MAN_NEWLINE & man->flags) p->flags |= MAN_LINE; man->flags &= ~MAN_NEWLINE; return(p); }
static struct eqn_box * eqn_box_alloc(struct eqn_node *ep, struct eqn_box *parent) { struct eqn_box *bp; bp = mandoc_calloc(1, sizeof(struct eqn_box)); bp->parent = parent; bp->size = ep->gsize; if (NULL == parent->first) parent->first = bp; else parent->last->next = bp; parent->last = bp; return(bp); }
/* * Push a roff node onto the instruction stack. This must later be * removed with roffnode_pop(). */ static void roffnode_push(struct roff *r, enum rofft tok, const char *name, int line, int col) { struct roffnode *p; p = mandoc_calloc(1, sizeof(struct roffnode)); p->tok = tok; if (name) p->name = mandoc_strdup(name); p->parent = r->last; p->line = line; p->col = col; p->rule = p->parent ? p->parent->rule : ROFFRULE_DENY; r->last = p; }
/* * Allocate volatile and non-volatile parse resources. */ struct mdoc * mdoc_alloc(struct roff *roff, struct mparse *parse, const char *defos, int quick) { struct mdoc *p; p = mandoc_calloc(1, sizeof(struct mdoc)); p->parse = parse; p->defos = defos; p->quick = quick; p->roff = roff; mdoc_hash_init(); mdoc_alloc1(p); return(p); }
struct roff * roff_alloc(struct mparse *parse) { struct roff *r; int i; r = mandoc_calloc(1, sizeof(struct roff)); r->parse = parse; r->rstackpos = -1; roffhash_init(); for (i = 0; i < PREDEFS_MAX; i++) roff_setstr(r, predefs[i].name, predefs[i].str, 0); return(r); }
static struct tbl_span * newspan(struct tbl_node *tbl, int line, struct tbl_row *rp) { struct tbl_span *dp; dp = mandoc_calloc(1, sizeof(*dp)); dp->line = line; dp->opts = &tbl->opts; dp->layout = rp; dp->prev = tbl->last_span; if (dp->prev == NULL) { tbl->first_span = dp; tbl->current_span = NULL; } else dp->prev->next = dp; tbl->last_span = dp; return dp; }
static struct tbl_cell * cell_alloc(struct tbl_node *tbl, struct tbl_row *rp, enum tbl_cellt pos) { struct tbl_cell *p, *pp; p = mandoc_calloc(1, sizeof(*p)); p->pos = pos; if ((pp = rp->last) != NULL) { pp->next = p; p->col = pp->col + 1; } else rp->first = p; rp->last = p; if (tbl->opts.cols <= p->col) tbl->opts.cols = p->col + 1; return p; }
/* * Allocate a box as the last child of the parent node. */ static struct eqn_box * eqn_box_alloc(struct eqn_node *ep, struct eqn_box *parent) { struct eqn_box *bp; bp = mandoc_calloc(1, sizeof(struct eqn_box)); bp->parent = parent; bp->parent->args++; bp->expectargs = UINT_MAX; bp->size = ep->gsize; if (NULL != parent->first) { parent->last->next = bp; bp->prev = parent->last; } else parent->first = bp; parent->last = bp; return(bp); }
/* * Calculate the abstract widths and decimal positions of columns in a * table. This routine allocates the columns structures then runs over * all rows and cells in the table. The function pointers in "tbl" are * used for the actual width calculations. */ void tblcalc(struct rofftbl *tbl, const struct tbl_span *sp) { const struct tbl_dat *dp; const struct tbl_head *hp; struct roffcol *col; int spans; /* * Allocate the master column specifiers. These will hold the * widths and decimal positions for all cells in the column. It * must be freed and nullified by the caller. */ assert(NULL == tbl->cols); tbl->cols = mandoc_calloc ((size_t)sp->opts->cols, sizeof(struct roffcol)); hp = sp->head; for ( ; sp; sp = sp->next) { if (TBL_SPAN_DATA != sp->pos) continue; spans = 1; /* * Account for the data cells in the layout, matching it * to data cells in the data section. */ for (dp = sp->first; dp; dp = dp->next) { /* Do not used spanned cells in the calculation. */ if (0 < --spans) continue; spans = dp->spans; if (1 < spans) continue; assert(dp->layout); col = &tbl->cols[dp->layout->head->ident]; tblcalc_data(tbl, col, sp->opts, dp); } } }