diff options
-rw-r--r-- | usr.bin/mandoc/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/chars.c | 15 | ||||
-rw-r--r-- | usr.bin/mandoc/eqn.c | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/html.c | 59 | ||||
-rw-r--r-- | usr.bin/mandoc/libman.h | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/libmandoc.h | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/libmdoc.h | 17 | ||||
-rw-r--r-- | usr.bin/mandoc/main.c | 83 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/man_html.c | 9 | ||||
-rw-r--r-- | usr.bin/mandoc/man_macro.c | 25 | ||||
-rw-r--r-- | usr.bin/mandoc/man_validate.c | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.c | 62 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 32 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_argv.c | 274 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_html.c | 9 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_macro.c | 35 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_strings.c | 215 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 156 | ||||
-rw-r--r-- | usr.bin/mandoc/out.c | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.c | 10 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_data.c | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_opts.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/term.c | 59 | ||||
-rw-r--r-- | usr.bin/mandoc/term_ps.c | 9 |
26 files changed, 488 insertions, 637 deletions
diff --git a/usr.bin/mandoc/Makefile b/usr.bin/mandoc/Makefile index 1594aea025c..9468b9f6ba7 100644 --- a/usr.bin/mandoc/Makefile +++ b/usr.bin/mandoc/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.53 2011/03/20 23:36:42 schwarze Exp $ +# $OpenBSD: Makefile,v 1.54 2011/04/21 22:59:54 schwarze Exp $ .include <bsd.own.mk> -VERSION=1.10.9 +VERSION=1.10.10 CFLAGS+=-DVERSION=\"${VERSION}\" CFLAGS+=-W -Wall -Wstrict-prototypes @@ -11,7 +11,7 @@ CFLAGS+=-Wno-unused-parameter .endif SRCS= roff.c tbl.c tbl_opts.c tbl_layout.c tbl_data.c eqn.c mandoc.c -SRCS+= mdoc_macro.c mdoc.c mdoc_hash.c mdoc_strings.c \ +SRCS+= mdoc_macro.c mdoc.c mdoc_hash.c \ mdoc_argv.c mdoc_validate.c lib.c att.c \ arch.c vol.c msec.c st.c SRCS+= man_macro.c man.c man_hash.c man_validate.c man_argv.c diff --git a/usr.bin/mandoc/chars.c b/usr.bin/mandoc/chars.c index 0c5a33d8b1b..3b115bdf253 100644 --- a/usr.bin/mandoc/chars.c +++ b/usr.bin/mandoc/chars.c @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.16 2011/01/30 16:05:29 schwarze Exp $ */ +/* $Id: chars.c,v 1.17 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -88,17 +88,8 @@ chars_init(enum chars type) * (they're in-line re-ordered during lookup). */ - tab = malloc(sizeof(struct ctab)); - if (NULL == tab) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - - htab = calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); - if (NULL == htab) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + tab = mandoc_malloc(sizeof(struct ctab)); + 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; diff --git a/usr.bin/mandoc/eqn.c b/usr.bin/mandoc/eqn.c index eaf1187ca70..c7fdffe06c6 100644 --- a/usr.bin/mandoc/eqn.c +++ b/usr.bin/mandoc/eqn.c @@ -1,4 +1,4 @@ -/* $Id: eqn.c,v 1.1 2011/03/21 00:48:02 schwarze Exp $ */ +/* $Id: eqn.c,v 1.2 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -63,6 +63,7 @@ eqn_alloc(int pos, int line) return(p); } +/* ARGSUSED */ void eqn_end(struct eqn_node *e) { diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c index b0261514a8f..b39d28117e0 100644 --- a/usr.bin/mandoc/html.c +++ b/usr.bin/mandoc/html.c @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.23 2011/01/30 16:05:29 schwarze Exp $ */ +/* $Id: html.c,v 1.24 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -116,11 +116,7 @@ ml_alloc(char *outopts, enum htmltype type) toks[2] = "includes"; toks[3] = NULL; - h = calloc(1, sizeof(struct html)); - if (NULL == h) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + h = mandoc_calloc(1, sizeof(struct html)); h->type = type; h->tags.head = NULL; @@ -210,7 +206,7 @@ print_gen_head(struct html *h) } } - +/* ARGSUSED */ static void print_num(struct html *h, const char *p, size_t len) { @@ -221,7 +217,6 @@ print_num(struct html *h, const char *p, size_t len) putchar((int)*rhs); } - static void print_spec(struct html *h, enum roffdeco d, const char *p, size_t len) { @@ -397,11 +392,7 @@ print_otag(struct html *h, enum htmltag tag, /* Push this tags onto the stack of open scopes. */ if ( ! (HTML_NOSTACK & htmltags[tag].flags)) { - t = malloc(sizeof(struct tag)); - if (NULL == t) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + t = mandoc_malloc(sizeof(struct tag)); t->tag = tag; t->next = h->tags.head; h->tags.head = t; @@ -519,29 +510,9 @@ void print_text(struct html *h, const char *word) { - if (word[0] && '\0' == word[1]) - switch (word[0]) { - case('.'): - /* FALLTHROUGH */ - case(','): - /* FALLTHROUGH */ - case(';'): - /* FALLTHROUGH */ - case(':'): - /* FALLTHROUGH */ - case('?'): - /* FALLTHROUGH */ - case('!'): - /* FALLTHROUGH */ - case(')'): - /* FALLTHROUGH */ - case(']'): - if ( ! (HTML_IGNDELIM & h->flags)) - h->flags |= HTML_NOSPACE; - break; - default: - break; - } + if (DELIM_CLOSE == mandoc_isdelim(word)) + if ( ! (HTML_IGNDELIM & h->flags)) + h->flags |= HTML_NOSPACE; if ( ! (HTML_NOSPACE & h->flags)) { /* Manage keeps! */ @@ -571,20 +542,8 @@ print_text(struct html *h, const char *word) h->flags &= ~HTML_IGNDELIM; - /* - * Note that we don't process the pipe: the parser sees it as - * punctuation, but we don't in terms of typography. - */ - if (word[0] && '\0' == word[1]) - switch (word[0]) { - case('('): - /* FALLTHROUGH */ - case('['): - h->flags |= HTML_NOSPACE; - break; - default: - break; - } + if (DELIM_OPEN == mandoc_isdelim(word)) + h->flags |= HTML_NOSPACE; } diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index dcbc2b4137a..a9b260961ff 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.27 2011/01/16 02:56:47 schwarze Exp $ */ +/* $Id: libman.h,v 1.28 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -81,7 +81,7 @@ int man_args(struct man *, int, int *, char *, char **); #define ARGS_EOLN (0) #define ARGS_WORD (1) #define ARGS_QWORD (1) -int man_vmsg(struct man *, enum mandocerr, +void man_vmsg(struct man *, enum mandocerr, int, int, const char *, ...); int man_valid_post(struct man *); int man_valid_pre(struct man *, struct man_node *); diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h index 8d74af567be..8adba0fd797 100644 --- a/usr.bin/mandoc/libmandoc.h +++ b/usr.bin/mandoc/libmandoc.h @@ -1,4 +1,4 @@ -/* $Id: libmandoc.h,v 1.9 2011/03/07 01:35:33 schwarze Exp $ */ +/* $Id: libmandoc.h,v 1.10 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -20,10 +20,7 @@ __BEGIN_DECLS int mandoc_special(char *); -void *mandoc_calloc(size_t, size_t); char *mandoc_strdup(const char *); -void *mandoc_malloc(size_t); -void *mandoc_realloc(void *, size_t); char *mandoc_getarg(char **, mandocmsg, void *, int, int *); char *mandoc_normdate(char *, mandocmsg, void *, int, int); int mandoc_eos(const char *, size_t, int); diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index 6ff3759cbe4..9a06007e6ee 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.43 2010/12/01 22:02:29 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.44 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -81,13 +81,6 @@ enum margverr { ARGV_WORD }; -enum mdelim { - DELIM_NONE = 0, - DELIM_OPEN, - DELIM_MIDDLE, - DELIM_CLOSE -}; - extern const struct mdoc_macro *const mdoc_macros; __BEGIN_DECLS @@ -96,7 +89,7 @@ __BEGIN_DECLS (*(m)->msg)((t), (m)->data, (l), (p), NULL) #define mdoc_nmsg(m, n, t) \ (*(m)->msg)((t), (m)->data, (n)->line, (n)->pos, NULL) -int mdoc_vmsg(struct mdoc *, enum mandocerr, +void mdoc_vmsg(struct mdoc *, enum mandocerr, int, int, const char *, ...); int mdoc_macro(MACRO_PROT_ARGS); int mdoc_word_alloc(struct mdoc *, @@ -114,12 +107,6 @@ int mdoc_endbody_alloc(struct mdoc *m, int line, int pos, void mdoc_node_delete(struct mdoc *, struct mdoc_node *); void mdoc_hash_init(void); enum mdoct mdoc_hash_find(const char *); -enum mdelim mdoc_iscdelim(char); -enum mdelim mdoc_isdelim(const char *); -size_t mdoc_isescape(const char *); -enum mdoc_sec mdoc_str2sec(const char *); -time_t mdoc_atotime(const char *); -size_t mdoc_macro2len(enum mdoct); const char *mdoc_a2att(const char *); const char *mdoc_a2lib(const char *); const char *mdoc_a2st(const char *); diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 338ece9048e..8a1752c2d83 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.74 2011/03/20 23:36:42 schwarze Exp $ */ +/* $Id: main.c,v 1.75 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -35,7 +35,6 @@ #include "roff.h" #define REPARSE_LIMIT 1000 -#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) typedef void (*out_mdoc)(void *, const struct mdoc *); typedef void (*out_man)(void *, const struct man *); @@ -63,11 +62,13 @@ enum outt { }; struct curparse { - const char *file; /* Current parse. */ - int fd; /* Current parse. */ - int line; /* Line number in the file. */ - enum mandoclevel wlevel; /* Ignore messages below this. */ - int wstop; /* Stop after a file with a warning. */ + enum mandoclevel exit_status; /* status of all file parses */ + const char *file; /* current file-name */ + enum mandoclevel file_status; /* error status of current parse */ + int fd; /* current file-descriptor */ + int line; /* line number in the file */ + enum mandoclevel wlevel; /* ignore messages below this */ + int wstop; /* stop after a file with a warning */ enum intt inttype; /* which parser to use */ struct man *pman; /* persistent man parser */ struct mdoc *pmdoc; /* persistent mdoc parser */ @@ -217,7 +218,7 @@ static void fdesc(struct curparse *); static void ffile(const char *, struct curparse *); static int pfile(const char *, struct curparse *); static int moptions(enum intt *, char *); -static int mmsg(enum mandocerr, void *, +static void mmsg(enum mandocerr, void *, int, int, const char *); static void pset(const char *, int, struct curparse *); static int toptions(struct curparse *, char *); @@ -226,8 +227,6 @@ static void version(void) __attribute__((noreturn)); static int woptions(struct curparse *, char *); static const char *progname; -static enum mandoclevel file_status = MANDOCLEVEL_OK; -static enum mandoclevel exit_status = MANDOCLEVEL_OK; int main(int argc, char *argv[]) @@ -246,6 +245,7 @@ main(int argc, char *argv[]) curp.inttype = INTT_AUTO; curp.outtype = OUTT_ASCII; curp.wlevel = MANDOCLEVEL_FATAL; + curp.exit_status = MANDOCLEVEL_OK; /* LINTED */ while (-1 != (c = getopt(argc, argv, "m:O:T:VW:"))) @@ -286,7 +286,7 @@ main(int argc, char *argv[]) while (*argv) { ffile(*argv, &curp); - if (MANDOCLEVEL_OK != exit_status && curp.wstop) + if (MANDOCLEVEL_OK != curp.exit_status && curp.wstop) break; ++argv; } @@ -300,7 +300,7 @@ main(int argc, char *argv[]) if (curp.roff) roff_free(curp.roff); - return((int)exit_status); + return((int)curp.exit_status); } @@ -345,7 +345,7 @@ ffile(const char *file, struct curparse *curp) if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) { perror(curp->file); - exit_status = MANDOCLEVEL_SYSERR; + curp->exit_status = MANDOCLEVEL_SYSERR; return; } @@ -363,7 +363,7 @@ pfile(const char *file, struct curparse *curp) if (-1 == (fd = open(file, O_RDONLY, 0))) { perror(file); - file_status = MANDOCLEVEL_SYSERR; + curp->file_status = MANDOCLEVEL_SYSERR; return(0); } @@ -381,7 +381,7 @@ pfile(const char *file, struct curparse *curp) if (-1 == close(fd)) perror(file); - return(MANDOCLEVEL_FATAL > file_status ? 1 : 0); + return(MANDOCLEVEL_FATAL > curp->file_status ? 1 : 0); } @@ -390,11 +390,7 @@ resize_buf(struct buf *buf, size_t initial) { buf->sz = buf->sz > initial/2 ? 2 * buf->sz : initial; - buf->buf = realloc(buf->buf, buf->sz); - if (NULL == buf->buf) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + buf->buf = mandoc_realloc(buf->buf, buf->sz); } @@ -485,7 +481,7 @@ fdesc(struct curparse *curp) curp->mdoc = NULL; curp->man = NULL; - file_status = MANDOCLEVEL_OK; + curp->file_status = MANDOCLEVEL_OK; /* Make sure the mandotory roff parser is initialised. */ @@ -498,26 +494,26 @@ fdesc(struct curparse *curp) pdesc(curp); - if (MANDOCLEVEL_FATAL <= file_status) + if (MANDOCLEVEL_FATAL <= curp->file_status) goto cleanup; /* NOTE a parser may not have been assigned, yet. */ if ( ! (curp->man || curp->mdoc)) { fprintf(stderr, "%s: Not a manual\n", curp->file); - file_status = MANDOCLEVEL_FATAL; + curp->file_status = MANDOCLEVEL_FATAL; goto cleanup; } /* Clean up the parse routine ASTs. */ if (curp->mdoc && ! mdoc_endparse(curp->mdoc)) { - assert(MANDOCLEVEL_FATAL <= file_status); + assert(MANDOCLEVEL_FATAL <= curp->file_status); goto cleanup; } if (curp->man && ! man_endparse(curp->man)) { - assert(MANDOCLEVEL_FATAL <= file_status); + assert(MANDOCLEVEL_FATAL <= curp->file_status); goto cleanup; } @@ -529,7 +525,7 @@ fdesc(struct curparse *curp) * the requested level, do not produce output. */ - if (MANDOCLEVEL_OK != file_status && curp->wstop) + if (MANDOCLEVEL_OK != curp->file_status && curp->wstop) goto cleanup; /* If unset, allocate output dev now (if applicable). */ @@ -604,8 +600,8 @@ fdesc(struct curparse *curp) assert(curp->roff); roff_reset(curp->roff); - if (exit_status < file_status) - exit_status = file_status; + if (curp->exit_status < curp->file_status) + curp->exit_status = curp->file_status; return; } @@ -624,7 +620,7 @@ pdesc(struct curparse *curp) */ if ( ! read_whole_file(curp, &blk, &with_mmap)) { - file_status = MANDOCLEVEL_SYSERR; + curp->file_status = MANDOCLEVEL_SYSERR; return; } @@ -640,6 +636,11 @@ pdesc(struct curparse *curp) free(blk.buf); } +/* + * Main parse routine for an opened file. This is called for each + * opened file and simply loops around the full input file, possibly + * nesting (i.e., with `so'). + */ static void parsebuf(struct curparse *curp, struct buf blk, int start) { @@ -651,12 +652,6 @@ parsebuf(struct curparse *curp, struct buf blk, int start) int lnn; /* line number in the real file */ unsigned char c; - /* - * Main parse routine for an opened file. This is called for - * each opened file and simply loops around the full input file, - * possibly nesting (i.e., with `so'). - */ - memset(&ln, 0, sizeof(struct buf)); lnn = curp->line; @@ -793,7 +788,7 @@ rerun: pos = 0; continue; case (ROFF_APPEND): - pos = strlen(ln.buf); + pos = (int)strlen(ln.buf); continue; case (ROFF_RERUN): goto rerun; @@ -801,7 +796,7 @@ rerun: pos = 0; continue; case (ROFF_ERR): - assert(MANDOCLEVEL_FATAL <= file_status); + assert(MANDOCLEVEL_FATAL <= curp->file_status); break; case (ROFF_SO): if (pfile(ln.buf + of, curp)) { @@ -818,7 +813,7 @@ rerun: * call, make sure we don't continue parsing. */ - if (MANDOCLEVEL_FATAL <= file_status) + if (MANDOCLEVEL_FATAL <= curp->file_status) break; /* @@ -866,7 +861,7 @@ rerun: curp->line, ln.buf, of); if (0 == rc) { - assert(MANDOCLEVEL_FATAL <= file_status); + assert(MANDOCLEVEL_FATAL <= curp->file_status); break; } @@ -1026,7 +1021,7 @@ woptions(struct curparse *curp, char *arg) return(1); } -static int +static void mmsg(enum mandocerr t, void *arg, int ln, int col, const char *msg) { struct curparse *cp; @@ -1039,7 +1034,7 @@ mmsg(enum mandocerr t, void *arg, int ln, int col, const char *msg) cp = (struct curparse *)arg; if (level < cp->wlevel) - return(1); + return; fprintf(stderr, "%s:%d:%d: %s: %s", cp->file, ln, col + 1, mandoclevels[level], mandocerrs[t]); @@ -1047,8 +1042,6 @@ mmsg(enum mandocerr t, void *arg, int ln, int col, const char *msg) fprintf(stderr, ": %s", msg); fputc('\n', stderr); - if (file_status < level) - file_status = level; - - return(level < MANDOCLEVEL_FATAL); + if (cp->file_status < level) + cp->file_status = level; } diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index 29d879b1563..b7c14eb7a15 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.57 2011/03/20 23:36:42 schwarze Exp $ */ +/* $Id: man.c,v 1.58 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -618,7 +618,7 @@ err: /* Error out. */ } -int +void man_vmsg(struct man *man, enum mandocerr t, int ln, int pos, const char *fmt, ...) { @@ -628,7 +628,7 @@ man_vmsg(struct man *man, enum mandocerr t, va_start(ap, fmt); vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); - return((*man->msg)(t, man->data, ln, pos, buf)); + (*man->msg)(t, man->data, ln, pos, buf); } diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c index 526835e6576..d805cce275e 100644 --- a/usr.bin/mandoc/man_html.c +++ b/usr.bin/mandoc/man_html.c @@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.36 2011/03/20 23:36:42 schwarze Exp $ */ +/* $Id: man_html.c,v 1.37 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -176,6 +176,7 @@ print_man_node(MAN_ARGS) { int child; struct tag *t; + struct htmlpair tag; child = 1; t = h->tags.head; @@ -201,8 +202,10 @@ print_man_node(MAN_ARGS) print_otag(h, TAG_BR, 0, NULL); return; case (MAN_EQN): + PAIR_CLASS_INIT(&tag, "eqn"); + print_otag(h, TAG_SPAN, 1, &tag); print_text(h, n->eqn->data); - return; + break; case (MAN_TBL): /* * This will take care of initialising all of the table @@ -247,6 +250,8 @@ print_man_node(MAN_ARGS) case (MAN_ROOT): man_root_post(m, n, mh, h); break; + case (MAN_EQN): + break; default: if (mans[n->tok].post) (*mans[n->tok].post)(m, n, mh, h); diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c index 413cbbd56ee..a5ad1d12447 100644 --- a/usr.bin/mandoc/man_macro.c +++ b/usr.bin/mandoc/man_macro.c @@ -1,4 +1,4 @@ -/* $Id: man_macro.c,v 1.27 2011/01/16 19:27:25 schwarze Exp $ */ +/* $Id: man_macro.c,v 1.28 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -39,7 +39,7 @@ static enum rew rew_dohalt(enum mant, enum man_type, const struct man_node *); static enum rew rew_block(enum mant, enum man_type, const struct man_node *); -static int rew_warn(struct man *, +static void rew_warn(struct man *, struct man_node *, enum mandocerr); const struct man_macro __man_macros[MAN_MAX] = { @@ -84,17 +84,19 @@ const struct man_macro * const man_macros = __man_macros; /* * Warn when "n" is an explicit non-roff macro. */ -static int +static void rew_warn(struct man *m, struct man_node *n, enum mandocerr er) { if (er == MANDOCERR_MAX || MAN_BLOCK != n->type) - return(1); + return; if (MAN_VALID & n->flags) - return(1); + return; if ( ! (MAN_EXPLICIT & man_macros[n->tok].flags)) - return(1); - return(man_nmsg(m, n, er)); + return; + + assert(er < MANDOCERR_FATAL); + man_nmsg(m, n, er); } @@ -119,16 +121,14 @@ man_unscope(struct man *m, const struct man_node *to, * out to be lost. */ n = m->last->parent; - if ( ! rew_warn(m, m->last, er)) - return(0); + rew_warn(m, m->last, er); if ( ! man_valid_post(m)) return(0); m->last = n; assert(m->last); } - if ( ! rew_warn(m, m->last, er)) - return(0); + rew_warn(m, m->last, er); if ( ! man_valid_post(m)) return(0); @@ -275,8 +275,7 @@ blk_close(MACRO_PROT_ARGS) break; if (NULL == nn) - if ( ! man_pmsg(m, line, ppos, MANDOCERR_NOSCOPE)) - return(0); + man_pmsg(m, line, ppos, MANDOCERR_NOSCOPE); if ( ! rew_scope(MAN_BODY, m, ntok)) return(0); diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 25d320add35..ca981467cfe 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $Id: man_validate.c,v 1.42 2011/03/20 23:36:42 schwarze Exp $ */ +/* $Id: man_validate.c,v 1.43 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -219,9 +219,8 @@ check_text(CHKARGS) if ('\t' == *p) { if (MAN_LITERAL & m->flags) continue; - if (man_pmsg(m, n->line, pos, MANDOCERR_BADTAB)) - continue; - return(0); + man_pmsg(m, n->line, pos, MANDOCERR_BADTAB); + continue; } /* Check the special character. */ diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c index b38a64fd04c..d694cb56107 100644 --- a/usr.bin/mandoc/mandoc.c +++ b/usr.bin/mandoc/mandoc.c @@ -1,6 +1,6 @@ -/* $Id: mandoc.c,v 1.23 2011/03/15 03:03:49 schwarze Exp $ */ +/* $Id: mandoc.c,v 1.24 2011/04/21 22:59:54 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -350,7 +350,7 @@ mandoc_getarg(char **cpp, mandocmsg msg, void *data, int ln, int *pos) while (' ' == *cp) cp++; } - *pos += (cp - start) + (quoted ? 1 : 0); + *pos += (int)(cp - start) + (quoted ? 1 : 0); *cpp = cp; if ('\0' == *cp && msg && (white || ' ' == cp[-1])) @@ -359,7 +359,6 @@ mandoc_getarg(char **cpp, mandocmsg msg, void *data, int ln, int *pos) return(start); } - static int a2time(time_t *t, const char *fmt, const char *p) { @@ -377,7 +376,6 @@ a2time(time_t *t, const char *fmt, const char *p) return(0); } - static char * time2a(time_t t) { @@ -413,7 +411,6 @@ fail: return(NULL); } - char * mandoc_normdate(char *in, mandocmsg msg, void *data, int ln, int pos) { @@ -435,7 +432,6 @@ mandoc_normdate(char *in, mandocmsg msg, void *data, int ln, int pos) return(out ? out : mandoc_strdup(in)); } - int mandoc_eos(const char *p, size_t sz, int enclosed) { @@ -479,7 +475,6 @@ mandoc_eos(const char *p, size_t sz, int enclosed) return(found && !enclosed); } - int mandoc_hyph(const char *start, const char *c) { @@ -506,3 +501,54 @@ mandoc_hyph(const char *start, const char *c) return(1); } + +/* + * Check if a string is a punctuation delimiter. This only applies to + * mdoc(7) documents, but as it's used in both front-ends and back-ends, + * it needs to go here (instead of, say, in libmdoc.h). + */ +enum mdelim +mandoc_isdelim(const char *p) +{ + + if ('\0' == p[0]) + return(DELIM_NONE); + + if ('\0' == p[1]) + switch (p[0]) { + case('('): + /* FALLTHROUGH */ + case('['): + return(DELIM_OPEN); + case('|'): + return(DELIM_MIDDLE); + case('.'): + /* FALLTHROUGH */ + case(','): + /* FALLTHROUGH */ + case(';'): + /* FALLTHROUGH */ + case(':'): + /* FALLTHROUGH */ + case('?'): + /* FALLTHROUGH */ + case('!'): + /* FALLTHROUGH */ + case(')'): + /* FALLTHROUGH */ + case(']'): + return(DELIM_CLOSE); + default: + return(DELIM_NONE); + } + + if ('\\' != p[0]) + return(DELIM_NONE); + + if (0 == strcmp(p + 1, ".")) + return(DELIM_CLOSE); + if (0 == strcmp(p + 1, "*(Ba")) + return(DELIM_MIDDLE); + + return(DELIM_NONE); +} diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 2175e97ad8a..02964787deb 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.35 2011/03/20 23:36:42 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.36 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -312,14 +312,32 @@ struct regset { struct reg regs[REG__MAX]; }; -__BEGIN_DECLS - /* - * Callback function for warnings, errors, and fatal errors as they - * occur in the compilers libroff, libmdoc, and libman. + * A punctuation delimiter, used only in mdoc(7) documents, is opening, + * closing, or "middle mark" punctuation. These govern spacing. + * Opening punctuation (e.g., the opening parenthesis) suppresses the + * following space; closing punctuation (e.g., the closing parenthesis) + * suppresses the leading space; middle punctuation (e.g., the vertical + * bar) can do either. The middle punctuation delimiter bends the rules + * depending on usage. */ -typedef int (*mandocmsg)(enum mandocerr, void *, - int, int, const char *); +enum mdelim { + DELIM_NONE = 0, + DELIM_OPEN, + DELIM_MIDDLE, + DELIM_CLOSE +}; + +typedef void (*mandocmsg)(enum mandocerr, void *, + int, int, const char *); + +__BEGIN_DECLS + +void *mandoc_calloc(size_t, size_t); +void *mandoc_malloc(size_t); +void *mandoc_realloc(void *, size_t); +#define DELIMSZ 6 /* hint: max possible size of a delimiter */ +enum mdelim mandoc_isdelim(const char *); __END_DECLS diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index 24c09e765a3..77e91ad23dc 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.81 2011/03/20 23:36:42 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.82 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -134,6 +134,8 @@ mdoc_free1(struct mdoc *mdoc) free(mdoc->meta.vol); if (mdoc->meta.msec) free(mdoc->meta.msec); + if (mdoc->meta.date) + free(mdoc->meta.date); } @@ -297,7 +299,7 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) } -int +void mdoc_vmsg(struct mdoc *mdoc, enum mandocerr t, int ln, int pos, const char *fmt, ...) { @@ -308,7 +310,7 @@ mdoc_vmsg(struct mdoc *mdoc, enum mandocerr t, vsnprintf(buf, sizeof(buf) - 1, fmt, ap); va_end(ap); - return((*mdoc->msg)(t, mdoc->data, ln, pos, buf)); + (*mdoc->msg)(t, mdoc->data, ln, pos, buf); } diff --git a/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c index a7c56c07f98..937518a7ba9 100644 --- a/usr.bin/mandoc/mdoc_argv.c +++ b/usr.bin/mandoc/mdoc_argv.c @@ -1,6 +1,6 @@ -/* $Id: mdoc_argv.c,v 1.35 2010/12/29 00:47:31 schwarze Exp $ */ +/* $Id: mdoc_argv.c,v 1.36 2011/04/21 22:59:54 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -26,24 +26,12 @@ #include "libmdoc.h" #include "libmandoc.h" -/* - * Routines to parse arguments of macros. Arguments follow the syntax - * of `-arg [val [valN...]]'. Arguments come in all types: quoted - * arguments, multiple arguments per value, no-value arguments, etc. - * - * There's no limit to the number or arguments that may be allocated. - */ - -#define ARGV_NONE (1 << 0) -#define ARGV_SINGLE (1 << 1) -#define ARGV_MULTI (1 << 2) -#define ARGV_OPT_SINGLE (1 << 3) - -#define MULTI_STEP 5 +#define MULTI_STEP 5 /* pre-allocate argument values */ static enum mdocargt argv_a2arg(enum mdoct, const char *); static enum margserr args(struct mdoc *, int, int *, char *, int, char **); +static int args_checkpunct(const char *); static int argv(struct mdoc *, int, struct mdoc_argv *, int *, char *); static int argv_single(struct mdoc *, int, @@ -53,9 +41,14 @@ static int argv_opt_single(struct mdoc *, int, static int argv_multi(struct mdoc *, int, struct mdoc_argv *, int *, char *); -/* Per-argument flags. */ +enum argvflag { + ARGV_NONE, /* no args to flag (e.g., -split) */ + ARGV_SINGLE, /* one arg to flag (e.g., -file xxx) */ + ARGV_MULTI, /* multiple args (e.g., -column xxx yyy) */ + ARGV_OPT_SINGLE /* optional arg (e.g., -offset [xxx]) */ +}; -static int mdoc_argvflags[MDOC_ARG_MAX] = { +static const enum argvflag argvflags[MDOC_ARG_MAX] = { ARGV_NONE, /* MDOC_Split */ ARGV_NONE, /* MDOC_Nosplit */ ARGV_NONE, /* MDOC_Ragged */ @@ -84,7 +77,7 @@ static int mdoc_argvflags[MDOC_ARG_MAX] = { ARGV_NONE /* MDOC_Symbolic */ }; -static int mdoc_argflags[MDOC_MAX] = { +static const int argflags[MDOC_MAX] = { 0, /* Ap */ 0, /* Dd */ 0, /* Dt */ @@ -209,7 +202,6 @@ static int mdoc_argflags[MDOC_MAX] = { 0, /* Ta */ }; - /* * Parse an argument from line text. This comes in the form of -key * [value0...], which may either have a single mandatory value, at least @@ -250,7 +242,7 @@ mdoc_argv(struct mdoc *m, int line, enum mdoct tok, buf[(*pos)++] = '\0'; } - (void)memset(&tmp, 0, sizeof(struct mdoc_argv)); + memset(&tmp, 0, sizeof(struct mdoc_argv)); tmp.line = line; tmp.pos = *pos; @@ -276,13 +268,12 @@ mdoc_argv(struct mdoc *m, int line, enum mdoct tok, arg->argv = mandoc_realloc (arg->argv, arg->argc * sizeof(struct mdoc_argv)); - (void)memcpy(&arg->argv[(int)arg->argc - 1], + memcpy(&arg->argv[(int)arg->argc - 1], &tmp, sizeof(struct mdoc_argv)); return(ARGV_ARG); } - void mdoc_argv_free(struct mdoc_arg *p) { @@ -305,7 +296,6 @@ mdoc_argv_free(struct mdoc_arg *p) free(p); } - void mdoc_argn_free(struct mdoc_arg *p, int iarg) { @@ -324,7 +314,6 @@ mdoc_argn_free(struct mdoc_arg *p, int iarg) p->argv[iarg] = p->argv[iarg+1]; } - enum margserr mdoc_zargs(struct mdoc *m, int line, int *pos, char *buf, int flags, char **v) @@ -333,7 +322,6 @@ mdoc_zargs(struct mdoc *m, int line, int *pos, return(args(m, line, pos, buf, flags, v)); } - enum margserr mdoc_args(struct mdoc *m, int line, int *pos, char *buf, enum mdoct tok, char **v) @@ -341,7 +329,7 @@ mdoc_args(struct mdoc *m, int line, int *pos, int fl; struct mdoc_node *n; - fl = mdoc_argflags[tok]; + fl = argflags[tok]; if (MDOC_It != tok) return(args(m, line, pos, buf, fl, v)); @@ -365,7 +353,6 @@ mdoc_args(struct mdoc *m, int line, int *pos, return(args(m, line, pos, buf, fl, v)); } - static enum margserr args(struct mdoc *m, int line, int *pos, char *buf, int fl, char **v) @@ -373,7 +360,6 @@ args(struct mdoc *m, int line, int *pos, int i; char *p, *pp; enum margserr rc; - enum mdelim d; /* * Parse out the terms (like `val' in `.Xx -arg val' or simply @@ -401,47 +387,24 @@ args(struct mdoc *m, int line, int *pos, * is unterminated. */ if (MDOC_PHRASELIT & m->flags) - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE); m->flags &= ~MDOC_PHRASELIT; return(ARGS_EOLN); } - /* - * If the first character is a closing delimiter and we're to - * look for delimited strings, then pass down the buffer seeing - * if it follows the pattern of [[::delim::][ ]+]+. Note that - * we ONLY care about closing delimiters. - */ - - if ((fl & ARGS_DELIM) && DELIM_CLOSE == mdoc_iscdelim(buf[*pos])) { - for (i = *pos; buf[i]; ) { - d = mdoc_iscdelim(buf[i]); - if (DELIM_NONE == d || DELIM_OPEN == d) - break; - i++; - if ('\0' == buf[i] || ' ' != buf[i]) - break; - i++; - while (buf[i] && ' ' == buf[i]) - i++; - } + *v = &buf[*pos]; - if ('\0' == buf[i]) { - *v = &buf[*pos]; - if (i && ' ' != buf[i - 1]) - return(ARGS_PUNCT); - if (ARGS_NOWARN & fl) - return(ARGS_PUNCT); - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE)) - return(ARGS_ERROR); + if (ARGS_DELIM & fl && args_checkpunct(&buf[*pos])) { + i = strlen(&buf[*pos]) + *pos; + if (i && ' ' != buf[i - 1]) return(ARGS_PUNCT); - } + if (ARGS_NOWARN & fl) + return(ARGS_PUNCT); + mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE); + return(ARGS_PUNCT); } - *v = &buf[*pos]; - /* * First handle TABSEP items, restricted to `Bl -column'. This * ignores conventional token parsing and instead uses tabs or @@ -489,8 +452,7 @@ args(struct mdoc *m, int line, int *pos, /* Whitespace check for eoln case... */ if ('\0' == *p && ' ' == *(p - 1) && ! (ARGS_NOWARN & fl)) - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE); *pos += (int)(p - *v); @@ -534,8 +496,7 @@ args(struct mdoc *m, int line, int *pos, if ('\0' == buf[*pos]) { if (ARGS_NOWARN & fl || MDOC_PPHRASE & m->flags) return(ARGS_QWORD); - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE); return(ARGS_QWORD); } @@ -549,8 +510,7 @@ args(struct mdoc *m, int line, int *pos, (*pos)++; if (0 == buf[*pos] && ! (ARGS_NOWARN & fl)) - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE); return(ARGS_QWORD); } @@ -573,113 +533,132 @@ args(struct mdoc *m, int line, int *pos, (*pos)++; if ('\0' == buf[*pos] && ! (ARGS_NOWARN & fl)) - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE); return(ARGS_WORD); } +/* + * Check if the string consists only of space-separated closing + * delimiters. This is a bit of a dance: the first must be a close + * delimiter, but it may be followed by middle delimiters. Arbitrary + * whitespace may separate these tokens. + */ +static int +args_checkpunct(const char *p) +{ + int i, j; + char buf[DELIMSZ]; + enum mdelim d; + + i = 0; + + /* First token must be a close-delimiter. */ + + for (j = 0; p[i] && ' ' != p[i] && j < DELIMSZ; j++, i++) + buf[j] = p[i]; + if (DELIMSZ == j) + return(0); + + buf[j] = '\0'; + if (DELIM_CLOSE != mandoc_isdelim(buf)) + return(0); + + while (' ' == p[i]) + i++; + + /* Remaining must NOT be open/none. */ + + while (p[i]) { + j = 0; + while (p[i] && ' ' != p[i] && j < DELIMSZ) + buf[j++] = p[i++]; + + if (DELIMSZ == j) + return(0); + + buf[j] = '\0'; + d = mandoc_isdelim(buf); + if (DELIM_NONE == d || DELIM_OPEN == d) + return(0); + + while (' ' == p[i]) + i++; + } + + return('\0' == p[i]); +} + +/* + * Match up an argument string (e.g., `-foo bar' having "foo") with the + * correrct identifier. It must apply to the given macro. If none was + * found (including bad matches), return MDOC_ARG_MAX. + */ static enum mdocargt argv_a2arg(enum mdoct tok, const char *p) { + enum mdocargt args[MDOC_ARG_MAX]; + int i, len; - /* - * Parse an argument identifier from its text. XXX - this - * should really be table-driven to clarify the code. - * - * If you add an argument to the list, make sure that you - * register it here with its one or more macros! - */ + len = 0; switch (tok) { case (MDOC_An): - if (0 == strcmp(p, "split")) - return(MDOC_Split); - else if (0 == strcmp(p, "nosplit")) - return(MDOC_Nosplit); + args[len++] = MDOC_Split; + args[len++] = MDOC_Nosplit; break; - case (MDOC_Bd): - if (0 == strcmp(p, "ragged")) - return(MDOC_Ragged); - else if (0 == strcmp(p, "unfilled")) - return(MDOC_Unfilled); - else if (0 == strcmp(p, "filled")) - return(MDOC_Filled); - else if (0 == strcmp(p, "literal")) - return(MDOC_Literal); - else if (0 == strcmp(p, "file")) - return(MDOC_File); - else if (0 == strcmp(p, "offset")) - return(MDOC_Offset); - else if (0 == strcmp(p, "compact")) - return(MDOC_Compact); - else if (0 == strcmp(p, "centered")) - return(MDOC_Centred); + args[len++] = MDOC_Ragged; + args[len++] = MDOC_Unfilled; + args[len++] = MDOC_Filled; + args[len++] = MDOC_Literal; + args[len++] = MDOC_File; + args[len++] = MDOC_Offset; + args[len++] = MDOC_Compact; + args[len++] = MDOC_Centred; break; - case (MDOC_Bf): - if (0 == strcmp(p, "emphasis")) - return(MDOC_Emphasis); - else if (0 == strcmp(p, "literal")) - return(MDOC_Literal); - else if (0 == strcmp(p, "symbolic")) - return(MDOC_Symbolic); + args[len++] = MDOC_Emphasis; + args[len++] = MDOC_Literal; + args[len++] = MDOC_Symbolic; break; - case (MDOC_Bk): - if (0 == strcmp(p, "words")) - return(MDOC_Words); + args[len++] = MDOC_Words; break; - case (MDOC_Bl): - if (0 == strcmp(p, "bullet")) - return(MDOC_Bullet); - else if (0 == strcmp(p, "dash")) - return(MDOC_Dash); - else if (0 == strcmp(p, "hyphen")) - return(MDOC_Hyphen); - else if (0 == strcmp(p, "item")) - return(MDOC_Item); - else if (0 == strcmp(p, "enum")) - return(MDOC_Enum); - else if (0 == strcmp(p, "tag")) - return(MDOC_Tag); - else if (0 == strcmp(p, "diag")) - return(MDOC_Diag); - else if (0 == strcmp(p, "hang")) - return(MDOC_Hang); - else if (0 == strcmp(p, "ohang")) - return(MDOC_Ohang); - else if (0 == strcmp(p, "inset")) - return(MDOC_Inset); - else if (0 == strcmp(p, "column")) - return(MDOC_Column); - else if (0 == strcmp(p, "width")) - return(MDOC_Width); - else if (0 == strcmp(p, "offset")) - return(MDOC_Offset); - else if (0 == strcmp(p, "compact")) - return(MDOC_Compact); - else if (0 == strcmp(p, "nested")) - return(MDOC_Nested); + args[len++] = MDOC_Bullet; + args[len++] = MDOC_Dash; + args[len++] = MDOC_Hyphen; + args[len++] = MDOC_Item; + args[len++] = MDOC_Enum; + args[len++] = MDOC_Tag; + args[len++] = MDOC_Diag; + args[len++] = MDOC_Hang; + args[len++] = MDOC_Ohang; + args[len++] = MDOC_Inset; + args[len++] = MDOC_Column; + args[len++] = MDOC_Width; + args[len++] = MDOC_Offset; + args[len++] = MDOC_Compact; + args[len++] = MDOC_Nested; break; - case (MDOC_Rv): /* FALLTHROUGH */ case (MDOC_Ex): - if (0 == strcmp(p, "std")) - return(MDOC_Std); + args[len++] = MDOC_Std; break; default: break; } + for (i = 0; i < len; i++) + if (0 == strcmp(p, mdoc_argnames[args[i]])) + return(args[i]); + return(MDOC_ARG_MAX); } - static int argv_multi(struct mdoc *m, int line, struct mdoc_argv *v, int *pos, char *buf) @@ -706,7 +685,6 @@ argv_multi(struct mdoc *m, int line, return(1); } - static int argv_opt_single(struct mdoc *m, int line, struct mdoc_argv *v, int *pos, char *buf) @@ -730,7 +708,6 @@ argv_opt_single(struct mdoc *m, int line, return(1); } - /* * Parse a single, mandatory value from the stream. */ @@ -758,7 +735,6 @@ argv_single(struct mdoc *m, int line, return(1); } - /* * Determine rules for parsing arguments. Arguments can either accept * no parameters, an optional single parameter, one parameter, or @@ -772,16 +748,18 @@ argv(struct mdoc *mdoc, int line, v->sz = 0; v->value = NULL; - switch (mdoc_argvflags[v->arg]) { + switch (argvflags[v->arg]) { case (ARGV_SINGLE): return(argv_single(mdoc, line, v, pos, buf)); case (ARGV_MULTI): return(argv_multi(mdoc, line, v, pos, buf)); case (ARGV_OPT_SINGLE): return(argv_opt_single(mdoc, line, v, pos, buf)); - default: - /* ARGV_NONE */ + case (ARGV_NONE): break; + default: + abort(); + /* NOTREACHED */ } return(1); diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index ec1aa9aca9f..2779ef5838c 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.54 2011/03/20 23:36:42 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.55 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -406,6 +406,7 @@ print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; + struct htmlpair tag; child = 1; t = h->tags.head; @@ -429,8 +430,10 @@ print_mdoc_node(MDOC_ARGS) print_text(h, n->string); return; case (MDOC_EQN): + PAIR_CLASS_INIT(&tag, "eqn"); + print_otag(h, TAG_SPAN, 1, &tag); print_text(h, n->eqn->data); - return; + break; case (MDOC_TBL): /* * This will take care of initialising all of the table @@ -478,6 +481,8 @@ print_mdoc_node(MDOC_ARGS) case (MDOC_ROOT): mdoc_root_post(m, n, h); break; + case (MDOC_EQN): + break; default: if (mdocs[n->tok].post && ENDBODY_NOT == n->end) (*mdocs[n->tok].post)(m, n, h); diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index 23616ab1486..7a02311a1a4 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.64 2011/01/30 18:28:01 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.65 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -595,7 +595,7 @@ append_delims(struct mdoc *m, int line, int *pos, char *buf) else if (ARGS_EOLN == ac) break; - assert(DELIM_NONE != mdoc_isdelim(p)); + assert(DELIM_NONE != mandoc_isdelim(p)); if ( ! mdoc_word_alloc(m, line, la, p)) return(0); @@ -706,8 +706,7 @@ blk_exp_close(MACRO_PROT_ARGS) if ( ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) { /* FIXME: do this in validate */ if (buf[*pos]) - if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_ARGSLOST)) - return(0); + mdoc_pmsg(m, line, ppos, MANDOCERR_ARGSLOST); if ( ! rew_sub(MDOC_BODY, m, tok, line, ppos)) return(0); @@ -850,9 +849,9 @@ in_line(MACRO_PROT_ARGS) return(0); } else if ( ! nc && 0 == cnt) { mdoc_argv_free(arg); - if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY)) - return(0); + mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY); } + if ( ! mdoc_macro(m, ntok, line, la, pos, buf)) return(0); if ( ! nl) @@ -866,7 +865,7 @@ in_line(MACRO_PROT_ARGS) * the word. */ - d = ARGS_QWORD == ac ? DELIM_NONE : mdoc_isdelim(p); + d = ARGS_QWORD == ac ? DELIM_NONE : mandoc_isdelim(p); if (DELIM_NONE != d) { /* @@ -932,8 +931,7 @@ in_line(MACRO_PROT_ARGS) return(0); } else if ( ! nc && 0 == cnt) { mdoc_argv_free(arg); - if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY)) - return(0); + mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY); } if ( ! nl) @@ -1057,7 +1055,7 @@ blk_full(MACRO_PROT_ARGS) ARGS_PHRASE != ac && ARGS_PPHRASE != ac && ARGS_QWORD != ac && - DELIM_OPEN == mdoc_isdelim(p)) { + DELIM_OPEN == mandoc_isdelim(p)) { if ( ! mdoc_word_alloc(m, line, la, p)) return(0); continue; @@ -1220,7 +1218,7 @@ blk_part_imp(MACRO_PROT_ARGS) break; if (NULL == body && ARGS_QWORD != ac && - DELIM_OPEN == mdoc_isdelim(p)) { + DELIM_OPEN == mandoc_isdelim(p)) { if ( ! mdoc_word_alloc(m, line, la, p)) return(0); continue; @@ -1295,9 +1293,9 @@ blk_part_imp(MACRO_PROT_ARGS) * is ugly behaviour nodding its head to OpenBSD's overwhelming * crufty use of `Op' breakage. */ - if (n != body && ! mdoc_vmsg(m, MANDOCERR_SCOPENEST, - line, ppos, "%s broken", mdoc_macronames[tok])) - return(0); + if (n != body) + mdoc_vmsg(m, MANDOCERR_SCOPENEST, line, ppos, + "%s broken", mdoc_macronames[tok]); if (n && ! rew_sub(MDOC_BODY, m, tok, line, ppos)) return(0); @@ -1351,7 +1349,7 @@ blk_part_exp(MACRO_PROT_ARGS) /* Flush out leading punctuation. */ if (NULL == head && ARGS_QWORD != ac && - DELIM_OPEN == mdoc_isdelim(p)) { + DELIM_OPEN == mandoc_isdelim(p)) { assert(NULL == body); if ( ! mdoc_word_alloc(m, line, la, p)) return(0); @@ -1498,7 +1496,7 @@ in_line_argn(MACRO_PROT_ARGS) if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) && ARGS_QWORD != ac && - 0 == j && DELIM_OPEN == mdoc_isdelim(p)) { + 0 == j && DELIM_OPEN == mandoc_isdelim(p)) { if ( ! mdoc_word_alloc(m, line, la, p)) return(0); continue; @@ -1527,7 +1525,7 @@ in_line_argn(MACRO_PROT_ARGS) if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) && ARGS_QWORD != ac && ! flushed && - DELIM_NONE != mdoc_isdelim(p)) { + DELIM_NONE != mandoc_isdelim(p)) { if ( ! rew_elem(m, tok)) return(0); flushed = 1; @@ -1666,7 +1664,8 @@ static int obsolete(MACRO_PROT_ARGS) { - return(mdoc_pmsg(m, line, ppos, MANDOCERR_MACROOBS)); + mdoc_pmsg(m, line, ppos, MANDOCERR_MACROOBS); + return(1); } diff --git a/usr.bin/mandoc/mdoc_strings.c b/usr.bin/mandoc/mdoc_strings.c deleted file mode 100644 index 7da283221e2..00000000000 --- a/usr.bin/mandoc/mdoc_strings.c +++ /dev/null @@ -1,215 +0,0 @@ -/* $Id: mdoc_strings.c,v 1.19 2010/07/31 23:42:04 schwarze Exp $ */ -/* - * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -#include <sys/types.h> - -#include <assert.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> - -#include "mandoc.h" -#include "libmdoc.h" - -static const char * const secnames[SEC__MAX] = { - NULL, - "NAME", - "LIBRARY", - "SYNOPSIS", - "DESCRIPTION", - "IMPLEMENTATION NOTES", - "RETURN VALUES", - "ENVIRONMENT", - "FILES", - "EXIT STATUS", - "EXAMPLES", - "DIAGNOSTICS", - "COMPATIBILITY", - "ERRORS", - "SEE ALSO", - "STANDARDS", - "HISTORY", - "AUTHORS", - "CAVEATS", - "BUGS", - "SECURITY CONSIDERATIONS", - NULL -}; - -/* - * FIXME: this is repeated in print_text() (html.c) and term_word() - * (term.c). - */ -enum mdelim -mdoc_iscdelim(char p) -{ - - switch (p) { - case('('): - /* FALLTHROUGH */ - case('['): - return(DELIM_OPEN); - case('|'): - return(DELIM_MIDDLE); - case('.'): - /* FALLTHROUGH */ - case(','): - /* FALLTHROUGH */ - case(';'): - /* FALLTHROUGH */ - case(':'): - /* FALLTHROUGH */ - case('?'): - /* FALLTHROUGH */ - case('!'): - /* FALLTHROUGH */ - case(')'): - /* FALLTHROUGH */ - case(']'): - return(DELIM_CLOSE); - default: - break; - } - - return(DELIM_NONE); -} - - -enum mdelim -mdoc_isdelim(const char *p) -{ - - if ('\0' == p[0]) - return(DELIM_NONE); - if ('\0' == p[1]) - return(mdoc_iscdelim(p[0])); - - /* - * XXX; account for groff bubu where the \*(Ba reserved string - * is treated in exactly the same way as the vertical bar. This - * is the only function that checks for this. - */ - return(strcmp(p, "\\*(Ba") ? DELIM_NONE : DELIM_MIDDLE); -} - - -enum mdoc_sec -mdoc_str2sec(const char *p) -{ - int i; - - for (i = 0; i < (int)SEC__MAX; i++) - if (secnames[i] && 0 == strcmp(p, secnames[i])) - return((enum mdoc_sec)i); - - return(SEC_CUSTOM); -} - - -/* FIXME: move this into an editable .in file. */ -size_t -mdoc_macro2len(enum mdoct macro) -{ - - switch (macro) { - case(MDOC_Ad): - return(12); - case(MDOC_Ao): - return(12); - case(MDOC_An): - return(12); - case(MDOC_Aq): - return(12); - case(MDOC_Ar): - return(12); - case(MDOC_Bo): - return(12); - case(MDOC_Bq): - return(12); - case(MDOC_Cd): - return(12); - case(MDOC_Cm): - return(10); - case(MDOC_Do): - return(10); - case(MDOC_Dq): - return(12); - case(MDOC_Dv): - return(12); - case(MDOC_Eo): - return(12); - case(MDOC_Em): - return(10); - case(MDOC_Er): - return(12); - case(MDOC_Ev): - return(15); - case(MDOC_Fa): - return(12); - case(MDOC_Fl): - return(10); - case(MDOC_Fo): - return(16); - case(MDOC_Fn): - return(16); - case(MDOC_Ic): - return(10); - case(MDOC_Li): - return(16); - case(MDOC_Ms): - return(6); - case(MDOC_Nm): - return(10); - case(MDOC_No): - return(12); - case(MDOC_Oo): - return(10); - case(MDOC_Op): - return(14); - case(MDOC_Pa): - return(32); - case(MDOC_Pf): - return(12); - case(MDOC_Po): - return(12); - case(MDOC_Pq): - return(12); - case(MDOC_Ql): - return(16); - case(MDOC_Qo): - return(12); - case(MDOC_So): - return(12); - case(MDOC_Sq): - return(12); - case(MDOC_Sy): - return(6); - case(MDOC_Sx): - return(16); - case(MDOC_Tn): - return(10); - case(MDOC_Va): - return(12); - case(MDOC_Vt): - return(12); - case(MDOC_Xr): - return(10); - default: - break; - }; - return(0); -} diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 68eea06ad09..a0620ecee82 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.90 2011/03/20 23:36:42 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.91 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -70,6 +70,8 @@ static void check_args(struct mdoc *, struct mdoc_node *); static int concat(struct mdoc *, char *, const struct mdoc_node *, size_t); +static enum mdoc_sec a2sec(const char *); +static size_t macro2len(enum mdoct); static int ebool(POST_ARGS); static int berr_ge1(POST_ARGS); @@ -173,7 +175,7 @@ static v_pre pres_sh[] = { pre_sh, NULL }; static v_pre pres_ss[] = { pre_ss, NULL }; static v_pre pres_std[] = { pre_std, NULL }; -const struct valids mdoc_valids[MDOC_MAX] = { +static const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Ap */ { pres_dd, posts_dd }, /* Dd */ { pres_dt, posts_dt }, /* Dt */ @@ -317,6 +319,30 @@ static const enum mdoct rsord[RSORD_MAX] = { MDOC__U }; +static const char * const secnames[SEC__MAX] = { + NULL, + "NAME", + "LIBRARY", + "SYNOPSIS", + "DESCRIPTION", + "IMPLEMENTATION NOTES", + "RETURN VALUES", + "ENVIRONMENT", + "FILES", + "EXIT STATUS", + "EXAMPLES", + "DIAGNOSTICS", + "COMPATIBILITY", + "ERRORS", + "SEE ALSO", + "STANDARDS", + "HISTORY", + "AUTHORS", + "CAVEATS", + "BUGS", + "SECURITY CONSIDERATIONS", + NULL +}; int mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n) @@ -416,10 +442,10 @@ check_count(struct mdoc *m, enum mdoc_type type, } t = lvl == CHECK_WARN ? MANDOCERR_ARGCWARN : MANDOCERR_ARGCOUNT; - - return(mdoc_vmsg(m, t, m->last->line, m->last->pos, + mdoc_vmsg(m, t, m->last->line, m->last->pos, "want %s%d children (have %d)", - p, val, m->last->nchild)); + p, val, m->last->nchild); + return(1); } static int @@ -1236,7 +1262,7 @@ post_an(POST_ARGS) static int post_it(POST_ARGS) { - int i, cols, rc; + int i, cols; enum mdoc_list lt; struct mdoc_node *n, *c; enum mandocerr er; @@ -1302,10 +1328,9 @@ post_it(POST_ARGS) else er = MANDOCERR_SYNTARGCOUNT; - rc = mdoc_vmsg(mdoc, er, - mdoc->last->line, mdoc->last->pos, + mdoc_vmsg(mdoc, er, mdoc->last->line, mdoc->last->pos, "columns == %d (have %d)", cols, i); - return(rc); + return(MANDOCERR_ARGCOUNT == er); default: break; } @@ -1366,7 +1391,7 @@ post_bl_block_width(POST_ARGS) width = 6; else if (MDOC_MAX == (tok = mdoc_hash_find(n->norm->Bl.width))) return(1); - else if (0 == (width = mdoc_macro2len(tok))) { + else if (0 == (width = macro2len(tok))) { mdoc_nmsg(mdoc, n, MANDOCERR_BADWIDTH); return(1); } @@ -1423,7 +1448,7 @@ post_bl_block_tag(POST_ARGS) break; } - if (0 != (ssz = mdoc_macro2len(nn->tok))) + if (0 != (ssz = macro2len(nn->tok))) sz = ssz; break; @@ -1817,7 +1842,7 @@ post_sh_head(POST_ARGS) if ( ! concat(mdoc, buf, mdoc->last->child, BUFSIZ)) return(0); - sec = mdoc_str2sec(buf); + sec = a2sec(buf); /* The NAME should be first. */ @@ -2123,7 +2148,8 @@ post_bx(POST_ARGS) n = mdoc->last->child; if (n && NULL != (n = n->next)) - *n->string = toupper((unsigned char)*n->string); + *n->string = (char)toupper + ((unsigned char)*n->string); return(1); } @@ -2250,3 +2276,107 @@ concat(struct mdoc *m, char *p, const struct mdoc_node *n, size_t sz) return(1); } +static enum mdoc_sec +a2sec(const char *p) +{ + int i; + + for (i = 0; i < (int)SEC__MAX; i++) + if (secnames[i] && 0 == strcmp(p, secnames[i])) + return((enum mdoc_sec)i); + + return(SEC_CUSTOM); +} + +static size_t +macro2len(enum mdoct macro) +{ + + switch (macro) { + case(MDOC_Ad): + return(12); + case(MDOC_Ao): + return(12); + case(MDOC_An): + return(12); + case(MDOC_Aq): + return(12); + case(MDOC_Ar): + return(12); + case(MDOC_Bo): + return(12); + case(MDOC_Bq): + return(12); + case(MDOC_Cd): + return(12); + case(MDOC_Cm): + return(10); + case(MDOC_Do): + return(10); + case(MDOC_Dq): + return(12); + case(MDOC_Dv): + return(12); + case(MDOC_Eo): + return(12); + case(MDOC_Em): + return(10); + case(MDOC_Er): + return(17); + case(MDOC_Ev): + return(15); + case(MDOC_Fa): + return(12); + case(MDOC_Fl): + return(10); + case(MDOC_Fo): + return(16); + case(MDOC_Fn): + return(16); + case(MDOC_Ic): + return(10); + case(MDOC_Li): + return(16); + case(MDOC_Ms): + return(6); + case(MDOC_Nm): + return(10); + case(MDOC_No): + return(12); + case(MDOC_Oo): + return(10); + case(MDOC_Op): + return(14); + case(MDOC_Pa): + return(32); + case(MDOC_Pf): + return(12); + case(MDOC_Po): + return(12); + case(MDOC_Pq): + return(12); + case(MDOC_Ql): + return(16); + case(MDOC_Qo): + return(12); + case(MDOC_So): + return(12); + case(MDOC_Sq): + return(12); + case(MDOC_Sy): + return(6); + case(MDOC_Sx): + return(16); + case(MDOC_Tn): + return(10); + case(MDOC_Va): + return(12); + case(MDOC_Vt): + return(12); + case(MDOC_Xr): + return(10); + default: + break; + }; + return(0); +} diff --git a/usr.bin/mandoc/out.c b/usr.bin/mandoc/out.c index 7f2344adf1a..48e3b3c5c8b 100644 --- a/usr.bin/mandoc/out.c +++ b/usr.bin/mandoc/out.c @@ -1,4 +1,4 @@ -/* $Id: out.c,v 1.12 2011/01/30 16:05:29 schwarze Exp $ */ +/* $Id: out.c,v 1.13 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -427,7 +427,8 @@ tblcalc(struct rofftbl *tbl, const struct tbl_span *sp) */ assert(NULL == tbl->cols); - tbl->cols = calloc(sp->tbl->cols, sizeof(struct roffcol)); + tbl->cols = mandoc_calloc + ((size_t)sp->tbl->cols, sizeof(struct roffcol)); hp = sp->head; diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index ce8edf3a82d..300a9a35c53 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.33 2011/04/05 22:19:11 schwarze Exp $ */ +/* $Id: roff.c,v 1.34 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -596,7 +596,7 @@ roff_parse(struct roff *r, const char *buf, int *pos) t = (r->current_string = roff_getstrn(r, mac, maclen)) ? ROFF_USERDEF : roff_hash_find(mac, maclen); - *pos += maclen; + *pos += (int)maclen; while (buf[*pos] && ' ' == buf[*pos]) (*pos)++; @@ -1131,7 +1131,7 @@ roff_rm(ROFF_ARGS) cp = *bufp + pos; while ('\0' != *cp) { - name = roff_getname(r, &cp, ln, cp - *bufp); + name = roff_getname(r, &cp, ln, (int)(cp - *bufp)); if ('\0' != *name) roff_setstr(r, name, NULL, 0); } @@ -1366,7 +1366,7 @@ roff_setstr(struct roff *r, const char *name, const char *string, * One additional byte for the '\n' in multiline mode, * and one for the terminating '\0'. */ - newch = strlen(string) + (multiline ? 2 : 1); + newch = strlen(string) + (multiline ? 2u : 1u); if (NULL == n->string) { n->string = mandoc_malloc(newch); *n->string = '\0'; @@ -1377,7 +1377,7 @@ roff_setstr(struct roff *r, const char *name, const char *string, } /* Skip existing content in the destination buffer. */ - c = n->string + oldch; + c = n->string + (int)oldch; /* Append new content to the destination buffer. */ while (*string) { diff --git a/usr.bin/mandoc/tbl_data.c b/usr.bin/mandoc/tbl_data.c index d0fdb122743..0a27c052083 100644 --- a/usr.bin/mandoc/tbl_data.c +++ b/usr.bin/mandoc/tbl_data.c @@ -1,4 +1,4 @@ -/* $Id: tbl_data.c,v 1.9 2011/02/10 00:06:30 schwarze Exp $ */ +/* $Id: tbl_data.c,v 1.10 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -102,8 +102,10 @@ data(struct tbl_node *tbl, struct tbl_span *dp, return(0); } - dat->string = mandoc_malloc(*pos - sv + 1); - memcpy(dat->string, &p[sv], *pos - sv); + assert(*pos - sv >= 0); + + dat->string = mandoc_malloc((size_t)(*pos - sv + 1)); + memcpy(dat->string, &p[sv], (size_t)(*pos - sv)); dat->string[*pos - sv] = '\0'; if (p[*pos]) diff --git a/usr.bin/mandoc/tbl_opts.c b/usr.bin/mandoc/tbl_opts.c index 5c2f99108e1..fbdefceb333 100644 --- a/usr.bin/mandoc/tbl_opts.c +++ b/usr.bin/mandoc/tbl_opts.c @@ -1,4 +1,4 @@ -/* $Id: tbl_opts.c,v 1.2 2011/01/09 14:30:48 schwarze Exp $ */ +/* $Id: tbl_opts.c,v 1.3 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -188,7 +188,7 @@ again: /* /* Copy up to first non-alpha character. */ for (sv = *pos, i = 0; i < KEY_MAXNAME; i++, (*pos)++) { - buf[i] = tolower((unsigned char)p[*pos]); + buf[i] = (char)tolower((unsigned char)p[*pos]); if ( ! isalpha((unsigned char)buf[i])) break; } diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index 3544fd4d603..058710941f5 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.56 2011/01/30 16:05:29 schwarze Exp $ */ +/* $Id: term.c,v 1.57 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -76,12 +76,7 @@ term_alloc(enum termenc enc) { struct termp *p; - p = calloc(1, sizeof(struct termp)); - if (NULL == p) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - + p = mandoc_calloc(1, sizeof(struct termp)); p->enc = enc; return(p); } @@ -464,29 +459,9 @@ term_word(struct termp *p, const char *word) sv = word; - if (word[0] && '\0' == word[1]) - switch (word[0]) { - case('.'): - /* FALLTHROUGH */ - case(','): - /* FALLTHROUGH */ - case(';'): - /* FALLTHROUGH */ - case(':'): - /* FALLTHROUGH */ - case('?'): - /* FALLTHROUGH */ - case('!'): - /* FALLTHROUGH */ - case(')'): - /* FALLTHROUGH */ - case(']'): - if ( ! (TERMP_IGNDELIM & p->flags)) - p->flags |= TERMP_NOSPACE; - break; - default: - break; - } + if (DELIM_CLOSE == mandoc_isdelim(word)) + if ( ! (TERMP_IGNDELIM & p->flags)) + p->flags |= TERMP_NOSPACE; if ( ! (TERMP_NOSPACE & p->flags)) { if ( ! (TERMP_KEEP & p->flags)) { @@ -510,7 +485,7 @@ term_word(struct termp *p, const char *word) if ((ssz = strcspn(word, "\\")) > 0) encode(p, word, ssz); - word += ssz; + word += (int)ssz; if ('\\' != *word) continue; @@ -549,20 +524,8 @@ term_word(struct termp *p, const char *word) p->flags |= TERMP_NOSPACE; } - /* - * Note that we don't process the pipe: the parser sees it as - * punctuation, but we don't in terms of typography. - */ - if (sv[0] && '\0' == sv[1]) - switch (sv[0]) { - case('('): - /* FALLTHROUGH */ - case('['): - p->flags |= TERMP_NOSPACE; - break; - default: - break; - } + if (DELIM_OPEN == mandoc_isdelim(sv)) + p->flags |= TERMP_NOSPACE; } @@ -575,11 +538,7 @@ adjbuf(struct termp *p, size_t sz) while (sz >= p->maxcols) p->maxcols <<= 2; - p->buf = realloc(p->buf, p->maxcols); - if (NULL == p->buf) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + p->buf = mandoc_realloc(p->buf, p->maxcols); } diff --git a/usr.bin/mandoc/term_ps.c b/usr.bin/mandoc/term_ps.c index db62c52fb3d..512c602ffe0 100644 --- a/usr.bin/mandoc/term_ps.c +++ b/usr.bin/mandoc/term_ps.c @@ -1,4 +1,4 @@ -/* $Id: term_ps.c,v 1.15 2011/03/07 01:58:19 schwarze Exp $ */ +/* $Id: term_ps.c,v 1.16 2011/04/21 22:59:54 schwarze Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -366,14 +366,9 @@ ps_growbuf(struct termp *p, size_t sz) p->engine.ps.psmargsz += sz; - p->engine.ps.psmarg = realloc + p->engine.ps.psmarg = mandoc_realloc (p->engine.ps.psmarg, p->engine.ps.psmargsz); - - if (NULL == p->engine.ps.psmarg) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } } static double ps_hspan(const struct termp *, |