From 7be5fc75543838241bb32d119197e65ad64e15f8 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sun, 17 Jul 2011 12:52:54 +0000 Subject: [PATCH] Warn if equation `define' key is quoted (groff-ism). --- eqn.c | 22 +++++++++++++++++----- mandoc.h | 5 ++++- read.c | 5 ++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/eqn.c b/eqn.c index 3d58d8e6..ca7b14d2 100644 --- a/eqn.c +++ b/eqn.c @@ -1,4 +1,4 @@ -/* $Id: eqn.c,v 1.6 2011/07/17 12:13:37 kristaps Exp $ */ +/* $Id: eqn.c,v 1.7 2011/07/17 12:52:54 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -54,11 +54,12 @@ eqn_read(struct eqn_node **epp, int ln, return(ROFF_IGN); if (6 == sz && 0 == strncmp("define", start, 6)) { - /* - * TODO: warn if key is quoted: groff doesn't seem to - * like this (I don't know why). - */ + if (end && '"' == *end) + mandoc_msg(MANDOCERR_EQNQUOTE, + ep->parse, ln, pos, NULL); + start = eqn_nexttok(ep->parse, ln, pos, &end, &sz); + for (i = 0; i < (int)ep->defsz; i++) { if (ep->defs[i].keysz != sz) continue; @@ -150,6 +151,12 @@ eqn_free(struct eqn_node *p) free(p); } +/* + * Return the current equation token setting "next" on the next one, + * setting the token size in "sz". + * This does the Right Thing for quoted strings, too. + * Returns NULL if no more tokens exist. + */ static const char * eqn_nexttok(struct mparse *mp, int ln, int pos, const char **next, size_t *sz) @@ -177,6 +184,11 @@ eqn_nexttok(struct mparse *mp, int ln, int pos, while (' ' == **next) (*next)++; } else { + /* + * XXX: groff gets confused by this and doesn't always + * do the "right thing" (just terminate it and warn + * about it). + */ if (q) mandoc_msg(MANDOCERR_BADQUOTE, mp, ln, pos, NULL); diff --git a/mandoc.h b/mandoc.h index ff5d302f..1d769828 100644 --- a/mandoc.h +++ b/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.78 2011/07/15 10:14:12 kristaps Exp $ */ +/* $Id: mandoc.h,v 1.79 2011/07/17 12:52:54 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * @@ -104,6 +104,9 @@ enum mandocerr { MANDOCERR_BADESCAPE, /* unknown escape sequence */ MANDOCERR_BADQUOTE, /* unterminated quoted string */ + /* related to equations */ + MANDOCERR_EQNQUOTE, /* unexpected literal in equation */ + MANDOCERR_ERROR, /* ===== start of errors ===== */ /* related to tables */ diff --git a/read.c b/read.c index da273ae1..9516b2bf 100644 --- a/read.c +++ b/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.15 2011/05/26 20:36:21 kristaps Exp $ */ +/* $Id: read.c,v 1.16 2011/07/17 12:52:54 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -146,6 +146,9 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "bad comment style", "bad escape sequence", "unterminated quoted string", + + /* related to equations */ + "unexpected literal in equation", "generic error", -- 2.47.1