diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2012-07-07 18:27:37 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2012-07-07 18:27:37 +0000 |
commit | 0dfc99960bdca3e31faaf1bbb1ab09a6efe9cfab (patch) | |
tree | 252cf9c075a896886d3938ffdfd013f975a15c56 /usr.bin/mandoc | |
parent | c0a01bbc238f32a30ff7f3e2e8e1f7ba16a9d4f4 (diff) |
Support the .cc request; code by kristaps@, tests by me.
Needed for sqlite3(1) as reported by espie@.
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/libmandoc.h | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.c | 28 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.c | 63 |
5 files changed, 69 insertions, 37 deletions
diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h index e438e1fe75d..3c13036f5e6 100644 --- a/usr.bin/mandoc/libmandoc.h +++ b/usr.bin/mandoc/libmandoc.h @@ -1,6 +1,6 @@ -/* $Id: libmandoc.h,v 1.18 2012/06/02 23:18:30 schwarze Exp $ */ +/* $Id: libmandoc.h,v 1.19 2012/07/07 18:27:36 schwarze Exp $ */ /* - * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2009, 2010, 2011, 2012 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 @@ -47,7 +47,6 @@ void mandoc_vmsg(enum mandocerr, struct mparse *, char *mandoc_getarg(struct mparse *, char **, int, int *); char *mandoc_normdate(struct mparse *, char *, int, int); int mandoc_eos(const char *, size_t, int); -int mandoc_getcontrol(const char *, int *); int mandoc_strntoi(const char *, size_t, int); const char *mandoc_a2msec(const char*); @@ -77,6 +76,8 @@ int roff_regisset(const struct roff *, enum regs); unsigned int roff_regget(const struct roff *, enum regs); void roff_regunset(struct roff *, enum regs); char *roff_strdup(const struct roff *, const char *); +int roff_getcontrol(const struct roff *, + const char *, int *); #if 0 char roff_eqndelim(const struct roff *); void roff_openeqn(struct roff *, const char *, diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index eefb4aa02b0..ea6d624a580 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.66 2012/06/02 20:07:09 schwarze Exp $ */ +/* $Id: man.c,v 1.67 2012/07/07 18:27:36 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -127,7 +127,7 @@ man_parseln(struct man *m, int ln, char *buf, int offs) assert( ! (MAN_HALT & m->flags)); - return (mandoc_getcontrol(buf, &offs) ? + return (roff_getcontrol(m->roff, buf, &offs) ? man_pmacro(m, ln, buf, offs) : man_ptext(m, ln, buf, offs)); } diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c index 2bfb58f0e77..768a23b10a0 100644 --- a/usr.bin/mandoc/mandoc.c +++ b/usr.bin/mandoc/mandoc.c @@ -1,4 +1,4 @@ -/* $Id: mandoc.c,v 1.34 2012/05/28 22:45:33 schwarze Exp $ */ +/* $Id: mandoc.c,v 1.35 2012/07/07 18:27:36 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> @@ -597,32 +597,6 @@ mandoc_eos(const char *p, size_t sz, int enclosed) } /* - * Find out whether a line is a macro line or not. If it is, adjust the - * current position and return one; if it isn't, return zero and don't - * change the current position. - */ -int -mandoc_getcontrol(const char *cp, int *ppos) -{ - int pos; - - pos = *ppos; - - if ('\\' == cp[pos] && '.' == cp[pos + 1]) - pos += 2; - else if ('.' == cp[pos] || '\'' == cp[pos]) - pos++; - else - return(0); - - while (' ' == cp[pos] || '\t' == cp[pos]) - pos++; - - *ppos = pos; - return(1); -} - -/* * Convert a string to a long that may not be <0. * If the string is invalid, or is less than 0, return -1. */ diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index 1f812ed1042..afb8f496865 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.87 2012/05/24 23:33:23 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.88 2012/07/07 18:27:36 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -298,7 +298,7 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) m->flags &= ~MDOC_SYNOPSIS; } - return(mandoc_getcontrol(buf, &offs) ? + return(roff_getcontrol(m->roff, buf, &offs) ? mdoc_pmacro(m, ln, buf, offs) : mdoc_ptext(m, ln, buf, offs)); } diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index cc763da3bbd..c3e1a912602 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,6 +1,6 @@ -/* $Id: roff.c,v 1.47 2012/06/02 23:18:30 schwarze Exp $ */ +/* $Id: roff.c,v 1.48 2012/07/07 18:27:36 schwarze Exp $ */ /* - * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -35,6 +35,7 @@ enum rofft { ROFF_am, ROFF_ami, ROFF_am1, + ROFF_cc, ROFF_de, ROFF_dei, ROFF_de1, @@ -104,6 +105,7 @@ struct roff { struct mparse *parse; /* parse point */ struct roffnode *last; /* leaf of stack */ enum roffrule rstack[RSTACK_MAX]; /* stack of !`ie' rules */ + char control; /* control character */ int rstackpos; /* position in rstack */ struct reg regs[REG__MAX]; struct roffkv *strtab; /* user-defined strings & macros */ @@ -168,6 +170,7 @@ static enum rofferr roff_block(ROFF_ARGS); static enum rofferr roff_block_text(ROFF_ARGS); static enum rofferr roff_block_sub(ROFF_ARGS); static enum rofferr roff_cblock(ROFF_ARGS); +static enum rofferr roff_cc(ROFF_ARGS); static enum rofferr roff_ccond(ROFF_ARGS); static enum rofferr roff_cond(ROFF_ARGS); static enum rofferr roff_cond_text(ROFF_ARGS); @@ -216,6 +219,7 @@ static struct roffmac roffs[ROFF_MAX] = { { "am", roff_block, roff_block_text, roff_block_sub, 0, NULL }, { "ami", roff_block, roff_block_text, roff_block_sub, 0, NULL }, { "am1", roff_block, roff_block_text, roff_block_sub, 0, NULL }, + { "cc", roff_cc, NULL, NULL, 0, NULL }, { "de", roff_block, roff_block_text, roff_block_sub, 0, NULL }, { "dei", roff_block, roff_block_text, roff_block_sub, 0, NULL }, { "de1", roff_block, roff_block_text, roff_block_sub, 0, NULL }, @@ -426,6 +430,7 @@ roff_reset(struct roff *r) roff_free1(r); + r->control = 0; memset(&r->regs, 0, sizeof(struct reg) * REG__MAX); for (i = 0; i < PREDEFS_MAX; i++) @@ -646,7 +651,7 @@ roff_parseln(struct roff *r, int ln, char **bufp, assert(ROFF_CONT == e); ppos = pos; - ctl = mandoc_getcontrol(*bufp, &pos); + ctl = roff_getcontrol(r, *bufp, &pos); /* * First, if a scope is open and we're not a macro, pass the @@ -1424,6 +1429,23 @@ roff_TS(ROFF_ARGS) /* ARGSUSED */ static enum rofferr +roff_cc(ROFF_ARGS) +{ + const char *p; + + p = *bufp + pos; + + if ('\0' == *p || '.' == (r->control = *p++)) + r->control = 0; + + if ('\0' != *p) + mandoc_msg(MANDOCERR_ARGCOUNT, r->parse, ln, ppos, NULL); + + return(ROFF_IGN); +} + +/* ARGSUSED */ +static enum rofferr roff_tr(ROFF_ARGS) { const char *p, *first, *second; @@ -1818,3 +1840,38 @@ roff_strdup(const struct roff *r, const char *p) res[(int)ssz] = '\0'; return(res); } + +/* + * Find out whether a line is a macro line or not. + * If it is, adjust the current position and return one; if it isn't, + * return zero and don't change the current position. + * If the control character has been set with `.cc', then let that grain + * precedence. + * This is slighly contrary to groff, where using the non-breaking + * control character when `cc' has been invoked will cause the + * non-breaking macro contents to be printed verbatim. + */ +int +roff_getcontrol(const struct roff *r, const char *cp, int *ppos) +{ + int pos; + + pos = *ppos; + + if (0 != r->control && cp[pos] == r->control) + pos++; + else if (0 != r->control) + return(0); + else if ('\\' == cp[pos] && '.' == cp[pos + 1]) + pos += 2; + else if ('.' == cp[pos] || '\'' == cp[pos]) + pos++; + else + return(0); + + while (' ' == cp[pos] || '\t' == cp[pos]) + pos++; + + *ppos = pos; + return(1); +} |