diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-06-11 12:07:49 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-06-11 12:07:49 +0000 |
commit | 5f01cd9971ff702a524ae0b46f692bf67ec2486e (patch) | |
tree | da8e4de38776c49e96dae23505efa71e3723109a | |
parent | c788f866d218b1363d95abee27eec8df64a79179 (diff) | |
download | mandoc-5f01cd9971ff702a524ae0b46f692bf67ec2486e.tar.gz |
Documented some un-clear parts of main.c.
Fixed footer to be new-groff style (OS DATE OS).
Removed sanity check from mdoc_term (unnecessary).
-rw-r--r-- | main.c | 34 | ||||
-rw-r--r-- | man_term.c | 4 | ||||
-rw-r--r-- | mdoc_term.c | 162 |
3 files changed, 64 insertions, 136 deletions
@@ -190,6 +190,8 @@ main(int argc, char *argv[]) free(blk.buf); if (ln.buf) free(ln.buf); + + /* TODO: have a curp_free routine. */ if (curp.outfree) (*curp.outfree)(curp.outdata); if (curp.mdoc) @@ -231,7 +233,14 @@ man_init(struct curparse *curp) mancb.man_err = merr; mancb.man_warn = manwarn; - pflags = MAN_IGN_MACRO; /* XXX */ + /* + * Default behaviour is to ignore unknown macros. This is + * specified in mandoc.1. + */ + + pflags = MAN_IGN_MACRO; + + /* Override default behaviour... */ if (curp->fflags & NO_IGN_MACRO) pflags &= ~MAN_IGN_MACRO; @@ -254,8 +263,16 @@ mdoc_init(struct curparse *curp) mdoccb.mdoc_err = merr; mdoccb.mdoc_warn = mdocwarn; + /* + * Default behaviour is to ignore unknown macros, escape + * sequences and characters (very liberal). This is specified + * in mandoc.1. + */ + pflags = MDOC_IGN_MACRO | MDOC_IGN_ESCAPE | MDOC_IGN_CHARS; + /* Override default behaviour... */ + if (curp->fflags & IGN_SCOPE) pflags |= MDOC_IGN_SCOPE; if (curp->fflags & NO_IGN_ESCAPE) @@ -363,7 +380,7 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse *curp) continue; } - /* Check for CPP-escaped newline. */ + /* Check for CPP-escaped newline. */ if (pos > 0 && '\\' == ln->buf[pos - 1]) { for (j = pos - 1; j >= 0; j--) @@ -630,9 +647,10 @@ merr(void *arg, int line, int col, const char *msg) struct curparse *curp; curp = (struct curparse *)arg; - warnx("%s:%d: error: %s (column %d)", curp->file, line, msg, col); + + /* Always exit on errors... */ return(0); } @@ -666,6 +684,11 @@ mdocwarn(void *arg, int line, int col, if ( ! (curp->wflags & WARN_WERR)) return(1); + + /* + * If the -Werror flag is passed in, as in gcc, then all + * warnings are considered as errors. + */ warnx("%s: considering warnings as errors", __progname); @@ -689,6 +712,11 @@ manwarn(void *arg, int line, int col, const char *msg) if ( ! (curp->wflags & WARN_WERR)) return(1); + /* + * If the -Werror flag is passed in, as in gcc, then all + * warnings are considered as errors. + */ + warnx("%s: considering warnings as errors", __progname); return(0); @@ -292,7 +292,9 @@ pre_IP(DECL_ARGS) offs = strlen(nn->string); p->flags |= TERMP_NOSPACE; - p->offset += offs; + /* FIXME */ + if ((p->offset += offs) > p->rmargin) + errx(1, "line too long"); return(0); } diff --git a/mdoc_term.c b/mdoc_term.c index 7140dc81..942c5fc4 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -305,8 +305,8 @@ static const struct termact termacts[MDOC_MAX] = { }; #ifdef __linux__ -extern size_t strlcpy(char *, const char *, size_t); -extern size_t strlcat(char *, const char *, size_t); +extern size_t strlcpy(char *, const char *, size_t); +extern size_t strlcat(char *, const char *, size_t); #endif static int arg_hasattr(int, const struct mdoc_node *); @@ -325,12 +325,15 @@ static void print_head(struct termp *, static void print_body(DECL_ARGS); static void print_foot(struct termp *, const struct mdoc_meta *); -static void sanity(const struct mdoc_node *); int mdoc_run(struct termp *p, const struct mdoc *m) { + /* + * Main output function. When this is called, assume that the + * tree is properly formed. + */ print_head(p, mdoc_meta(m)); print_body(p, NULL, mdoc_meta(m), mdoc_node(m)); @@ -356,10 +359,6 @@ print_node(DECL_ARGS) int dochild; struct termpair npair; - /* Some quick sanity-checking. */ - - sanity(node); - /* Pre-processing. */ dochild = 1; @@ -401,6 +400,14 @@ print_foot(struct termp *p, const struct mdoc_meta *meta) struct tm *tm; char *buf, *os; + /* + * Output the footer in new-groff style, that is, three columns + * with the middle being the manual date and flanking columns + * being the operating system: + * + * SYSTEM DATE SYSTEM + */ + if (NULL == (buf = malloc(p->rmargin))) err(1, "malloc"); if (NULL == (os = malloc(p->rmargin))) @@ -417,30 +424,34 @@ print_foot(struct termp *p, const struct mdoc_meta *meta) (void)strlcpy(os, meta->os, p->rmargin); - /* - * This is /slightly/ different from regular groff output - * because we don't have page numbers. Print the following: - * - * OS MDOCDATE - */ - term_vspace(p); - p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; - p->rmargin = p->maxrmargin - strlen(buf); p->offset = 0; + p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2; + p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; term_word(p, os); term_flushln(p); + p->offset = p->rmargin; + p->rmargin = p->maxrmargin - strlen(os); p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; + + term_word(p, buf); + term_flushln(p); + p->offset = p->rmargin; p->rmargin = p->maxrmargin; p->flags &= ~TERMP_NOBREAK; + p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; - term_word(p, buf); + term_word(p, os); term_flushln(p); + p->offset = 0; + p->rmargin = p->maxrmargin; + p->flags = 0; + free(buf); free(os); } @@ -491,9 +502,9 @@ print_head(struct termp *p, const struct mdoc_meta *meta) term_word(p, title); term_flushln(p); - p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; p->offset = p->rmargin; p->rmargin = p->maxrmargin - strlen(title); + p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; term_word(p, buf); term_flushln(p); @@ -506,8 +517,8 @@ print_head(struct termp *p, const struct mdoc_meta *meta) term_word(p, title); term_flushln(p); - p->rmargin = p->maxrmargin; p->offset = 0; + p->rmargin = p->maxrmargin; p->flags &= ~TERMP_NOSPACE; free(title); @@ -515,119 +526,6 @@ print_head(struct termp *p, const struct mdoc_meta *meta) } -static void -sanity(const struct mdoc_node *n) -{ - char *p; - - p = "regular form violated"; - - switch (n->type) { - case (MDOC_TEXT): - if (n->child) - errx(1, p); - if (NULL == n->parent) - errx(1, p); - if (NULL == n->string) - errx(1, p); - switch (n->parent->type) { - case (MDOC_TEXT): - /* FALLTHROUGH */ - case (MDOC_ROOT): - errx(1, p); - /* NOTREACHED */ - default: - break; - } - break; - case (MDOC_ELEM): - if (NULL == n->parent) - errx(1, p); - switch (n->parent->type) { - case (MDOC_TAIL): - /* FALLTHROUGH */ - case (MDOC_BODY): - /* FALLTHROUGH */ - case (MDOC_HEAD): - break; - default: - errx(1, p); - /* NOTREACHED */ - } - if (n->child) switch (n->child->type) { - case (MDOC_TEXT): - break; - default: - errx(1, p); - /* NOTREACHED */ - } - break; - case (MDOC_HEAD): - /* FALLTHROUGH */ - case (MDOC_BODY): - /* FALLTHROUGH */ - case (MDOC_TAIL): - if (NULL == n->parent) - errx(1, p); - if (MDOC_BLOCK != n->parent->type) - errx(1, p); - if (n->child) switch (n->child->type) { - case (MDOC_BLOCK): - /* FALLTHROUGH */ - case (MDOC_ELEM): - /* FALLTHROUGH */ - case (MDOC_TEXT): - break; - default: - errx(1, p); - /* NOTREACHED */ - } - break; - case (MDOC_BLOCK): - if (NULL == n->parent) - errx(1, p); - if (NULL == n->child) - errx(1, p); - switch (n->parent->type) { - case (MDOC_ROOT): - /* FALLTHROUGH */ - case (MDOC_HEAD): - /* FALLTHROUGH */ - case (MDOC_BODY): - /* FALLTHROUGH */ - case (MDOC_TAIL): - break; - default: - errx(1, p); - /* NOTREACHED */ - } - switch (n->child->type) { - case (MDOC_ROOT): - /* FALLTHROUGH */ - case (MDOC_ELEM): - errx(1, p); - /* NOTREACHED */ - default: - break; - } - break; - case (MDOC_ROOT): - if (n->parent) - errx(1, p); - if (NULL == n->child) - errx(1, p); - switch (n->child->type) { - case (MDOC_BLOCK): - break; - default: - errx(1, p); - /* NOTREACHED */ - } - break; - } -} - - static size_t arg_width(const struct mdoc_argv *arg, int pos) { |