aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-07-21 15:21:13 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-07-21 15:21:13 +0000
commit3ee412a268eff0c9e52bb141dc3289eda00a6d53 (patch)
treec7806e338a7f518f1e0d02ab42c28e4ce822a405
parent610da288ad1c36332f5bc333692f49e2326fa30d (diff)
downloadmandoc-3ee412a268eff0c9e52bb141dc3289eda00a6d53.tar.gz
mandoc-3ee412a268eff0c9e52bb141dc3289eda00a6d53.tar.zst
mandoc-3ee412a268eff0c9e52bb141dc3289eda00a6d53.zip
Support `size' constructs in eqn.7. Generalise mandoc_strontou to this
effect.
-rw-r--r--chars.c6
-rw-r--r--eqn.73
-rw-r--r--eqn.c16
-rw-r--r--libmandoc.h4
-rw-r--r--mandoc.c13
-rw-r--r--mandoc.h4
-rw-r--r--roff.c4
-rw-r--r--tree.c12
8 files changed, 39 insertions, 23 deletions
diff --git a/chars.c b/chars.c
index d0fd8724..369aac2f 100644
--- a/chars.c
+++ b/chars.c
@@ -1,4 +1,4 @@
-/* $Id: chars.c,v 1.47 2011/07/07 06:41:50 kristaps Exp $ */
+/* $Id: chars.c,v 1.48 2011/07/21 15:21:13 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -111,7 +111,7 @@ mchars_num2char(const char *p, size_t sz)
{
int i;
- if ((i = mandoc_strntou(p, sz, 10)) < 0)
+ if ((i = mandoc_strntoi(p, sz, 10)) < 0)
return('\0');
return(isprint(i) ? i : '\0');
}
@@ -121,7 +121,7 @@ mchars_num2uc(const char *p, size_t sz)
{
int i;
- if ((i = mandoc_strntou(p, sz, 16)) < 0)
+ if ((i = mandoc_strntoi(p, sz, 16)) < 0)
return('\0');
/* FIXME: make sure we're not in a bogus range. */
return(i > 0x80 && i <= 0x10FFFF ? i : '\0');
diff --git a/eqn.7 b/eqn.7
index 7304a307..0bf04700 100644
--- a/eqn.7
+++ b/eqn.7
@@ -1,4 +1,4 @@
-.\" $Id: eqn.7,v 1.11 2011/07/21 14:13:00 kristaps Exp $
+.\" $Id: eqn.7,v 1.12 2011/07/21 15:21:13 kristaps Exp $
.\"
.\" Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -70,6 +70,7 @@ box : text
| box pos box
| box mark
| font box
+ | SIZE text box
text : TEXT
pos : OVER
| SUP
diff --git a/eqn.c b/eqn.c
index 23dd934e..706a31cf 100644
--- a/eqn.c
+++ b/eqn.c
@@ -1,4 +1,4 @@
-/* $Id: eqn.c,v 1.18 2011/07/21 14:13:00 kristaps Exp $ */
+/* $Id: eqn.c,v 1.19 2011/07/21 15:21:13 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -19,6 +19,7 @@
#endif
#include <assert.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -188,7 +189,7 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last, struct eqn_box **sv)
{
size_t sz;
const char *start;
- int c, i, nextc;
+ int c, i, nextc, size;
enum eqn_fontt font;
struct eqn_box *bp;
@@ -201,6 +202,7 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last, struct eqn_box **sv)
*sv = last;
nextc = 1;
font = EQNFONT_NONE;
+ size = EQN_DEFSIZE;
again:
if (NULL == (start = eqn_nexttok(ep, &sz)))
return(0);
@@ -242,14 +244,22 @@ again:
goto again;
}
- /* Exit this [hopefully] subexpression. */
+ if (sz == 4 && 0 == strncmp("size", start, 1)) {
+ if (NULL == (start = eqn_nexttok(ep, &sz)))
+ return(0);
+ size = mandoc_strntoi(start, sz, 10);
+ goto again;
+ }
if (sz == 1 && 0 == strncmp("}", start, 1))
return(1);
bp = mandoc_calloc(1, sizeof(struct eqn_box));
bp->font = font;
+ bp->size = size;
+
font = EQNFONT_NONE;
+ size = EQN_DEFSIZE;
if (nextc)
last->child = bp;
diff --git a/libmandoc.h b/libmandoc.h
index 737f70fe..ad3ed254 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmandoc.h,v 1.23 2011/07/18 07:46:41 kristaps Exp $ */
+/* $Id: libmandoc.h,v 1.24 2011/07/21 15:21:13 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -49,7 +49,7 @@ char *mandoc_normdate(struct mparse *, char *, int, int);
int mandoc_eos(const char *, size_t, int);
int mandoc_hyph(const char *, const char *);
int mandoc_getcontrol(const char *, int *);
-int mandoc_strntou(const char *, size_t, int);
+int mandoc_strntoi(const char *, size_t, int);
void mdoc_free(struct mdoc *);
struct mdoc *mdoc_alloc(struct roff *, struct mparse *);
diff --git a/mandoc.c b/mandoc.c
index 465965a4..891b9511 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc.c,v 1.53 2011/05/24 21:31:23 kristaps Exp $ */
+/* $Id: mandoc.c,v 1.54 2011/07/21 15:21:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -698,7 +698,7 @@ mandoc_getcontrol(const char *cp, int *ppos)
* If the string is invalid, or is less than 0, return -1.
*/
int
-mandoc_strntou(const char *p, size_t sz, int base)
+mandoc_strntoi(const char *p, size_t sz, int base)
{
char buf[32];
char *ep;
@@ -716,11 +716,10 @@ mandoc_strntou(const char *p, size_t sz, int base)
if (buf[0] == '\0' || *ep != '\0')
return(-1);
- if ((errno == ERANGE &&
- (v == LONG_MAX || v == LONG_MIN)) ||
- (v > INT_MAX || v < 0))
- return(-1);
+ if (v > INT_MAX)
+ v = INT_MAX;
+ if (v < INT_MIN)
+ v = INT_MIN;
return((int)v);
}
-
diff --git a/mandoc.h b/mandoc.h
index cd29e688..556a88a8 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.87 2011/07/21 14:13:00 kristaps Exp $ */
+/* $Id: mandoc.h,v 1.88 2011/07/21 15:21:13 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -322,6 +322,8 @@ enum eqn_post {
* grammar.
*/
struct eqn_box {
+ int size; /* font size of expression */
+#define EQN_DEFSIZE INT_MIN
enum eqn_boxt type; /* type of node */
struct eqn_box *child; /* child node */
struct eqn_box *next; /* next in tree */
diff --git a/roff.c b/roff.c
index bc7e74cc..66fab654 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.148 2011/07/21 10:24:35 kristaps Exp $ */
+/* $Id: roff.c,v 1.149 2011/07/21 15:21:13 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -1149,7 +1149,7 @@ roff_nr(ROFF_ARGS)
if (0 == strcmp(key, "nS")) {
r->regs[(int)REG_nS].set = 1;
- if ((iv = mandoc_strntou(val, strlen(val), 10)) >= 0)
+ if ((iv = mandoc_strntoi(val, strlen(val), 10)) >= 0)
r->regs[(int)REG_nS].u = (unsigned)iv;
else
r->regs[(int)REG_nS].u = 0u;
diff --git a/tree.c b/tree.c
index 1c03c716..3d7f9085 100644
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,4 @@
-/* $Id: tree.c,v 1.42 2011/07/21 14:13:00 kristaps Exp $ */
+/* $Id: tree.c,v 1.43 2011/07/21 15:21:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -19,6 +19,7 @@
#endif
#include <assert.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@@ -270,17 +271,20 @@ print_box(const struct eqn_box *ep, int indent)
switch (ep->type) {
case (EQN_ROOT):
- printf("eqn-root(%d, %d, %d)\n",
+ printf("eqn-root(%d, %d, %d, %d)\n",
+ EQN_DEFSIZE == ep->size ? 0 : ep->size,
ep->pos, ep->font, ep->mark);
print_box(ep->child, indent + 1);
break;
case (EQN_SUBEXPR):
- printf("eqn-subxpr(%d, %d, %d)\n",
+ printf("eqn-subxpr(%d, %d, %d, %d)\n",
+ EQN_DEFSIZE == ep->size ? 0 : ep->size,
ep->pos, ep->font, ep->mark);
print_box(ep->child, indent + 1);
break;
case (EQN_TEXT):
- printf("eqn-text(%d, %d, %d): [%s]\n",
+ printf("eqn-text(%d, %d, %d, %d): [%s]\n",
+ EQN_DEFSIZE == ep->size ? 0 : ep->size,
ep->pos, ep->font, ep->mark, ep->text);
break;
default: