int mdoc_macro(MACRO_PROT_ARGS) { assert(tok < MDOC_MAX); /* If we're in the body, deny prologue calls. */ if (MDOC_PROLOGUE & mdoc_macros[tok].flags && MDOC_PBODY & m->flags) { mdoc_pmsg(m, line, ppos, MANDOCERR_BADBODY); return(1); } /* If we're in the prologue, deny "body" macros. */ if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && ! (MDOC_PBODY & m->flags)) { mdoc_pmsg(m, line, ppos, MANDOCERR_BADPROLOG); if (NULL == m->meta.msec) m->meta.msec = mandoc_strdup("1"); if (NULL == m->meta.title) m->meta.title = mandoc_strdup("UNKNOWN"); if (NULL == m->meta.vol) m->meta.vol = mandoc_strdup("LOCAL"); if (NULL == m->meta.os) m->meta.os = mandoc_strdup("LOCAL"); if (NULL == m->meta.date) m->meta.date = mandoc_normdate (m->parse, NULL, line, ppos); m->flags |= MDOC_PBODY; } return((*mdoc_macros[tok].fp)(m, tok, line, ppos, pos, buf)); }
static void check_root(CHKARGS) { assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0); if (NULL == man->first->child) mandoc_msg(MANDOCERR_DOC_EMPTY, man->parse, n->line, n->pos, NULL); else man->meta.hasbody = 1; if (NULL == man->meta.title) { mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse, n->line, n->pos, NULL); /* * If a title hasn't been set, do so now (by * implication, date and section also aren't set). */ man->meta.title = mandoc_strdup(""); man->meta.msec = mandoc_strdup(""); man->meta.date = man->quick ? mandoc_strdup("") : mandoc_normdate(man->parse, NULL, n->line, n->pos); } }
static int check_root(CHKARGS) { if (MAN_BLINE & man->flags) man_nmsg(man, n, MANDOCERR_SCOPEEXIT); else if (MAN_ELINE & man->flags) man_nmsg(man, n, MANDOCERR_SCOPEEXIT); man->flags &= ~MAN_BLINE; man->flags &= ~MAN_ELINE; if (NULL == man->first->child) { man_nmsg(man, n, MANDOCERR_NODOCBODY); return(0); } else if (NULL == man->meta.title) { man_nmsg(man, n, MANDOCERR_NOTITLE); /* * If a title hasn't been set, do so now (by * implication, date and section also aren't set). */ man->meta.title = mandoc_strdup("unknown"); man->meta.msec = mandoc_strdup("1"); man->meta.date = mandoc_normdate (man->parse, NULL, n->line, n->pos); } return(1); }
static void check_root(CHKARGS) { assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0); if (n->last == NULL || n->last->type == ROFFT_COMMENT) mandoc_msg(MANDOCERR_DOC_EMPTY, n->line, n->pos, NULL); else man->meta.hasbody = 1; if (NULL == man->meta.title) { mandoc_msg(MANDOCERR_TH_NOTITLE, n->line, n->pos, NULL); /* * If a title hasn't been set, do so now (by * implication, date and section also aren't set). */ man->meta.title = mandoc_strdup(""); man->meta.msec = mandoc_strdup(""); man->meta.date = man->quick ? mandoc_strdup("") : mandoc_normdate(man, NULL, n->line, n->pos); } if (man->meta.os_e && (man->meta.rcsids & (1 << man->meta.os_e)) == 0) mandoc_msg(MANDOCERR_RCS_MISSING, 0, 0, man->meta.os_e == MANDOC_OS_OPENBSD ? "(OpenBSD)" : "(NetBSD)"); }
static void post_TH(CHKARGS) { struct man_node *nb; const char *p; free(man->meta.title); free(man->meta.vol); free(man->meta.source); free(man->meta.msec); free(man->meta.date); man->meta.title = man->meta.vol = man->meta.date = man->meta.msec = man->meta.source = NULL; nb = n; /* ->TITLE<- MSEC DATE SOURCE VOL */ n = n->child; if (n && n->string) { for (p = n->string; '\0' != *p; p++) { /* Only warn about this once... */ if (isalpha((unsigned char)*p) && ! isupper((unsigned char)*p)) { mandoc_vmsg(MANDOCERR_TITLE_CASE, man->parse, n->line, n->pos + (p - n->string), "TH %s", n->string); break; } } man->meta.title = mandoc_strdup(n->string); } else { man->meta.title = mandoc_strdup(""); mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse, nb->line, nb->pos, "TH"); } /* TITLE ->MSEC<- DATE SOURCE VOL */ if (n) n = n->next; if (n && n->string) man->meta.msec = mandoc_strdup(n->string); else { man->meta.msec = mandoc_strdup(""); mandoc_vmsg(MANDOCERR_MSEC_MISSING, man->parse, nb->line, nb->pos, "TH %s", man->meta.title); } /* TITLE MSEC ->DATE<- SOURCE VOL */ if (n) n = n->next; if (n && n->string && '\0' != n->string[0]) { man->meta.date = man->quick ? mandoc_strdup(n->string) : mandoc_normdate(man->parse, n->string, n->line, n->pos); } else { man->meta.date = mandoc_strdup(""); mandoc_msg(MANDOCERR_DATE_MISSING, man->parse, n ? n->line : nb->line, n ? n->pos : nb->pos, "TH"); } /* TITLE MSEC DATE ->SOURCE<- VOL */ if (n && (n = n->next)) man->meta.source = mandoc_strdup(n->string); else if (man->defos != NULL) man->meta.source = mandoc_strdup(man->defos); /* TITLE MSEC DATE SOURCE ->VOL<- */ /* If missing, use the default VOL name for MSEC. */ if (n && (n = n->next)) man->meta.vol = mandoc_strdup(n->string); else if ('\0' != man->meta.msec[0] && (NULL != (p = mandoc_a2msec(man->meta.msec)))) man->meta.vol = mandoc_strdup(p); if (n != NULL && (n = n->next) != NULL) mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse, n->line, n->pos, "TH ... %s", n->string); /* * Remove the `TH' node after we've processed it for our * meta-data. */ man_node_delete(man, man->last); }
static int post_TH(CHKARGS) { const char *p; int line, pos; free(man->meta.title); free(man->meta.vol); free(man->meta.source); free(man->meta.msec); free(man->meta.date); line = n->line; pos = n->pos; man->meta.title = man->meta.vol = man->meta.date = man->meta.msec = man->meta.source = NULL; /* ->TITLE<- MSEC DATE SOURCE VOL */ n = n->child; if (n && n->string) { for (p = n->string; '\0' != *p; p++) { /* Only warn about this once... */ if (isalpha((unsigned char)*p) && ! isupper((unsigned char)*p)) { man_nmsg(man, n, MANDOCERR_UPPERCASE); break; } } man->meta.title = mandoc_strdup(n->string); } else man->meta.title = mandoc_strdup(""); /* TITLE ->MSEC<- DATE SOURCE VOL */ if (n) n = n->next; if (n && n->string) man->meta.msec = mandoc_strdup(n->string); else man->meta.msec = mandoc_strdup(""); /* TITLE MSEC ->DATE<- SOURCE VOL */ if (n) n = n->next; if (n && n->string && '\0' != n->string[0]) { pos = n->pos; man->meta.date = mandoc_normdate (man->parse, n->string, line, pos); } else man->meta.date = mandoc_strdup(""); /* TITLE MSEC DATE ->SOURCE<- VOL */ if (n && (n = n->next)) man->meta.source = mandoc_strdup(n->string); /* TITLE MSEC DATE SOURCE ->VOL<- */ /* If missing, use the default VOL name for MSEC. */ if (n && (n = n->next)) man->meta.vol = mandoc_strdup(n->string); else if ('\0' != man->meta.msec[0] && (NULL != (p = mandoc_a2msec(man->meta.msec)))) man->meta.vol = mandoc_strdup(p); /* * Remove the `TH' node after we've processed it for our * meta-data. */ man_node_delete(man, man->last); return(1); }