* mdocml: Support `size' constructs in eqn.7.
@ 2011-07-21 15:21 kristaps
0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-07-21 15:21 UTC (permalink / raw)
To: source
Log Message:
-----------
Support `size' constructs in eqn.7. Generalise mandoc_strontou to this
effect.
Modified Files:
--------------
mdocml:
chars.c
eqn.7
eqn.c
libmandoc.h
mandoc.c
mandoc.h
roff.c
tree.c
Revision Data
-------------
Index: mandoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -Lmandoc.c -Lmandoc.c -u -p -r1.53 -r1.54
--- mandoc.c
+++ mandoc.c
@@ -698,7 +698,7 @@ mandoc_getcontrol(const char *cp, int *p
* 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,
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);
}
-
Index: chars.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/chars.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -Lchars.c -Lchars.c -u -p -r1.47 -r1.48
--- chars.c
+++ chars.c
@@ -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');
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.87
retrieving revision 1.88
diff -Lmandoc.h -Lmandoc.h -u -p -r1.87 -r1.88
--- mandoc.h
+++ mandoc.h
@@ -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 */
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.148
retrieving revision 1.149
diff -Lroff.c -Lroff.c -u -p -r1.148 -r1.149
--- roff.c
+++ roff.c
@@ -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;
Index: eqn.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn.7,v
retrieving revision 1.11
retrieving revision 1.12
diff -Leqn.7 -Leqn.7 -u -p -r1.11 -r1.12
--- eqn.7
+++ eqn.7
@@ -70,6 +70,7 @@ box : text
| box pos box
| box mark
| font box
+ | SIZE text box
text : TEXT
pos : OVER
| SUP
Index: eqn.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -Leqn.c -Leqn.c -u -p -r1.18 -r1.19
--- eqn.c
+++ eqn.c
@@ -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_
{
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_
*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;
Index: libmandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmandoc.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.23 -r1.24
--- libmandoc.h
+++ libmandoc.h
@@ -49,7 +49,7 @@ char *mandoc_normdate(struct mparse *,
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 *);
Index: tree.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/tree.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -Ltree.c -Ltree.c -u -p -r1.42 -r1.43
--- tree.c
+++ tree.c
@@ -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
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:
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-07-21 15:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-21 15:21 mdocml: Support `size' constructs in eqn.7 kristaps
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).