source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Make `struct roff' be passed into libmdoc and libman upon
@ 2011-07-18  7:46 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-07-18  7:46 UTC (permalink / raw)
  To: source

Log Message:
-----------
Make `struct roff' be passed into libmdoc and libman upon creation.
This is required for supporting in-line equations.  While here, push
registers properly into roff and add an set/get/mod interface.

Modified Files:
--------------
    mdocml:
        Makefile
        libman.h
        libmandoc.h
        libmdoc.h
        man.c
        mdoc.c
        mdoc_validate.c
        read.c
        roff.c

Revision Data
-------------
Index: libmdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmdoc.h,v
retrieving revision 1.74
retrieving revision 1.75
diff -Llibmdoc.h -Llibmdoc.h -u -p -r1.74 -r1.75
--- libmdoc.h
+++ libmdoc.h
@@ -40,6 +40,7 @@ struct	mdoc {
 	enum mdoc_sec	  lastnamed;
 	enum mdoc_sec	  lastsec;
 	struct regset	 *regs; /* registers */
+	struct roff	 *roff;
 };
 
 #define	MACRO_PROT_ARGS	struct mdoc *m, \
Index: man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -Lman.c -Lman.c -u -p -r1.107 -r1.108
--- man.c
+++ man.c
@@ -96,7 +96,7 @@ man_free(struct man *man)
 
 
 struct man *
-man_alloc(struct regset *regs, struct mparse *parse)
+man_alloc(struct roff *roff, struct mparse *parse)
 {
 	struct man	*p;
 
@@ -104,7 +104,7 @@ man_alloc(struct regset *regs, struct mp
 
 	man_hash_init();
 	p->parse = parse;
-	p->regs = regs;
+	p->roff = roff;
 
 	man_alloc1(p);
 	return(p);
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.188
retrieving revision 1.189
diff -Lmdoc.c -Lmdoc.c -u -p -r1.188 -r1.189
--- mdoc.c
+++ mdoc.c
@@ -193,14 +193,14 @@ mdoc_free(struct mdoc *mdoc)
  * Allocate volatile and non-volatile parse resources.  
  */
 struct mdoc *
-mdoc_alloc(struct regset *regs, struct mparse *parse)
+mdoc_alloc(struct roff *roff, struct mparse *parse)
 {
 	struct mdoc	*p;
 
 	p = mandoc_calloc(1, sizeof(struct mdoc));
 
 	p->parse = parse;
-	p->regs = regs;
+	p->roff = roff;
 
 	mdoc_hash_init();
 	mdoc_alloc1(p);
@@ -290,8 +290,8 @@ mdoc_parseln(struct mdoc *m, int ln, cha
 	 * whether this mode is on or off.
 	 * Note that this mode is also switched by the Sh macro.
 	 */
-	if (m->regs->regs[(int)REG_nS].set) {
-		if (m->regs->regs[(int)REG_nS].v.u)
+	if (roff_regisset(m->roff, REG_nS)) {
+		if (roff_regget(m->roff, REG_nS))
 			m->flags |= MDOC_SYNOPSIS;
 		else
 			m->flags &= ~MDOC_SYNOPSIS;
Index: libman.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libman.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -Llibman.h -Llibman.h -u -p -r1.51 -r1.52
--- libman.h
+++ libman.h
@@ -37,6 +37,7 @@ struct	man {
 	struct man_node	*first; /* the first parsed node */
 	struct man_meta	 meta; /* document meta-data */
 	struct regset	*regs; /* registers */
+	struct roff	*roff;
 };
 
 #define	MACRO_PROT_ARGS	  struct man *m, \
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -Lroff.c -Lroff.c -u -p -r1.146 -r1.147
--- roff.c
+++ roff.c
@@ -71,6 +71,16 @@ enum	roffrule {
 	ROFFRULE_DENY
 };
 
+/*
+ * A single register entity.  If "set" is zero, the value of the
+ * register should be the default one, which is per-register.
+ * Registers are assumed to be unsigned ints for now.
+ */
+struct	reg {
+	int		  set; /* whether set or not */
+	unsigned int	  u; /* unsigned integer */
+};
+
 struct	roffstr {
 	char		*name; /* key of symbol */
 	char		*string; /* current value */
@@ -82,7 +92,7 @@ struct	roff {
 	struct roffnode	*last; /* leaf of stack */
 	enum roffrule	 rstack[RSTACK_MAX]; /* stack of !`ie' rules */
 	int		 rstackpos; /* position in rstack */
-	struct regset	*regs; /* read/writable registers */
+	struct reg	 regs[REG__MAX];
 	struct roffstr	*first_string; /* user-defined strings & macros */
 	const char	*current_string; /* value of last called user macro */
 	struct tbl_node	*first_tbl; /* first table parsed */
@@ -351,6 +361,8 @@ roff_reset(struct roff *r)
 
 	roff_free1(r);
 
+	memset(&r->regs, 0, sizeof(struct reg) * REG__MAX);
+
 	for (i = 0; i < PREDEFS_MAX; i++) 
 		roff_setstr(r, predefs[i].name, predefs[i].str, 0);
 }
@@ -366,13 +378,12 @@ roff_free(struct roff *r)
 
 
 struct roff *
-roff_alloc(struct regset *regs, struct mparse *parse)
+roff_alloc(struct mparse *parse)
 {
 	struct roff	*r;
 	int		 i;
 
 	r = mandoc_calloc(1, sizeof(struct roff));
-	r->regs = regs;
 	r->parse = parse;
 	r->rstackpos = -1;
 	
@@ -1104,6 +1115,26 @@ roff_ds(ROFF_ARGS)
 	return(ROFF_IGN);
 }
 
+int
+roff_regisset(const struct roff *r, enum regs reg)
+{
+
+	return(r->regs[(int)reg].set);
+}
+
+unsigned int
+roff_regget(const struct roff *r, enum regs reg)
+{
+
+	return(r->regs[(int)reg].u);
+}
+
+void
+roff_regunset(struct roff *r, enum regs reg)
+{
+
+	r->regs[(int)reg].set = 0;
+}
 
 /* ARGSUSED */
 static enum rofferr
@@ -1112,18 +1143,16 @@ roff_nr(ROFF_ARGS)
 	const char	*key;
 	char		*val;
 	int		 iv;
-	struct reg	*rg;
 
 	val = *bufp + pos;
 	key = roff_getname(r, &val, ln, pos);
-	rg = r->regs->regs;
 
 	if (0 == strcmp(key, "nS")) {
-		rg[(int)REG_nS].set = 1;
+		r->regs[(int)REG_nS].set = 1;
 		if ((iv = mandoc_strntou(val, strlen(val), 10)) >= 0)
-			rg[REG_nS].v.u = (unsigned)iv;
+			r->regs[(int)REG_nS].u = (unsigned)iv;
 		else
-			rg[(int)REG_nS].v.u = 0u;
+			r->regs[(int)REG_nS].u = 0u;
 	}
 
 	return(ROFF_IGN);
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.169
retrieving revision 1.170
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.169 -r1.170
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -899,7 +899,7 @@ pre_sh(PRE_ARGS)
 	if (MDOC_BLOCK != n->type)
 		return(1);
 
-	mdoc->regs->regs[(int)REG_nS].set = 0;
+	roff_regunset(mdoc->roff, REG_nS);
 	return(check_parent(mdoc, n, MDOC_MAX, MDOC_ROOT));
 }
 
Index: Makefile
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v
retrieving revision 1.357
retrieving revision 1.358
diff -LMakefile -LMakefile -u -p -r1.357 -r1.358
--- Makefile
+++ Makefile
@@ -33,6 +33,9 @@ INSTALL_LIB	 = $(INSTALL) -m 0644
 INSTALL_SOURCE	 = $(INSTALL) -m 0644
 INSTALL_MAN	 = $(INSTALL_DATA)
 
+# Linux needs -ldb to compile mandocdb.
+#DBLIB		 = -ldb
+
 all: mandoc preconv
 
 SRCS		 = Makefile \
@@ -353,9 +356,8 @@ mandoc: $(MANDOC_OBJS) libmandoc.a
 llib-lmandoc.ln: $(MANDOC_LNS)
 	$(LINT) $(LINTFLAGS) -Cmandoc $(MANDOC_LNS)
 
-# You'll need -ldb for Linux.
 mandocdb: $(MANDOCDB_OBJS) libmandoc.a
-	$(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a -ldb
+	$(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a $(DBLIB)
 
 llib-lmandocdb.ln: $(MANDOCDB_LNS)
 	$(LINT) $(LINTFLAGS) -Cmandocdb $(MANDOCDB_LNS)
Index: libmandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmandoc.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.22 -r1.23
--- libmandoc.h
+++ libmandoc.h
@@ -34,35 +34,6 @@ enum	regs {
 	REG__MAX
 };
 
-/*
- * A register (struct reg) can consist of many types: this consists of
- * normalised types from the original string form.  For the time being,
- * there's only an unsigned integer type.
- */
-union	regval {
-	unsigned  u; /* unsigned integer */
-};
-
-/*
- * A single register entity.  If "set" is zero, the value of the
- * register should be the default one, which is per-register.  It's
- * assumed that callers know which type in "v" corresponds to which
- * register value.
- */
-struct	reg {
-	int		  set; /* whether set or not */
-	union regval	  v; /* parsed data */
-};
-
-/*
- * The primary interface to setting register values is in libroff,
- * although libmdoc and libman from time to time will manipulate
- * registers (such as `.Sh SYNOPSIS' enabling REG_nS).
- */
-struct	regset {
-	struct reg	  regs[REG__MAX];
-};
-
 __BEGIN_DECLS
 
 struct	roff;
@@ -81,7 +52,7 @@ int		 mandoc_getcontrol(const char *, in
 int		 mandoc_strntou(const char *, size_t, int);
 
 void	 	 mdoc_free(struct mdoc *);
-struct	mdoc	*mdoc_alloc(struct regset *, struct mparse *);
+struct	mdoc	*mdoc_alloc(struct roff *, struct mparse *);
 void		 mdoc_reset(struct mdoc *);
 int	 	 mdoc_parseln(struct mdoc *, int, char *, int);
 int		 mdoc_endparse(struct mdoc *);
@@ -89,7 +60,7 @@ int		 mdoc_addspan(struct mdoc *, const 
 int		 mdoc_addeqn(struct mdoc *, const struct eqn *);
 
 void	 	 man_free(struct man *);
-struct	man	*man_alloc(struct regset *, struct mparse *);
+struct	man	*man_alloc(struct roff *, struct mparse *);
 void		 man_reset(struct man *);
 int	 	 man_parseln(struct man *, int, char *, int);
 int		 man_endparse(struct man *);
@@ -97,11 +68,14 @@ int		 man_addspan(struct man *, const st
 int		 man_addeqn(struct man *, const struct eqn *);
 
 void	 	 roff_free(struct roff *);
-struct roff	*roff_alloc(struct regset *, struct mparse *);
+struct roff	*roff_alloc(struct mparse *);
 void		 roff_reset(struct roff *);
 enum rofferr	 roff_parseln(struct roff *, int, 
 			char **, size_t *, int, int *);
 void		 roff_endparse(struct roff *);
+int		 roff_regisset(const struct roff *, enum regs);
+unsigned int	 roff_regget(const struct roff *, enum regs);
+void		 roff_regunset(struct roff *, enum regs);
 
 const struct tbl_span	*roff_span(const struct roff *);
 const struct eqn	*roff_eqn(const struct roff *);
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lread.c -Lread.c -u -p -r1.17 -r1.18
--- read.c
+++ read.c
@@ -59,7 +59,6 @@ struct	mparse {
 	struct man	 *man; /* man parser */
 	struct mdoc	 *mdoc; /* mdoc parser */
 	struct roff	 *roff; /* roff parser (!NULL) */
-	struct regset	  regs; /* roff registers */
 	int		  reparse_count; /* finite interp. stack */
 	mandocmsg	  mmsg; /* warning/error message handler */
 	void		 *arg; /* argument to mmsg */
@@ -243,13 +242,13 @@ pset(const char *buf, int pos, struct mp
 	switch (curp->inttype) {
 	case (MPARSE_MDOC):
 		if (NULL == curp->pmdoc) 
-			curp->pmdoc = mdoc_alloc(&curp->regs, curp);
+			curp->pmdoc = mdoc_alloc(curp->roff, curp);
 		assert(curp->pmdoc);
 		curp->mdoc = curp->pmdoc;
 		return;
 	case (MPARSE_MAN):
 		if (NULL == curp->pman) 
-			curp->pman = man_alloc(&curp->regs, curp);
+			curp->pman = man_alloc(curp->roff, curp);
 		assert(curp->pman);
 		curp->man = curp->pman;
 		return;
@@ -259,14 +258,14 @@ pset(const char *buf, int pos, struct mp
 
 	if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3))  {
 		if (NULL == curp->pmdoc) 
-			curp->pmdoc = mdoc_alloc(&curp->regs, curp);
+			curp->pmdoc = mdoc_alloc(curp->roff, curp);
 		assert(curp->pmdoc);
 		curp->mdoc = curp->pmdoc;
 		return;
 	} 
 
 	if (NULL == curp->pman) 
-		curp->pman = man_alloc(&curp->regs, curp);
+		curp->pman = man_alloc(curp->roff, curp);
 	assert(curp->pman);
 	curp->man = curp->pman;
 }
@@ -687,15 +686,13 @@ mparse_alloc(enum mparset inttype, enum 
 	curp->arg = arg;
 	curp->inttype = inttype;
 
-	curp->roff = roff_alloc(&curp->regs, curp);
+	curp->roff = roff_alloc(curp);
 	return(curp);
 }
 
 void
 mparse_reset(struct mparse *curp)
 {
-
-	memset(&curp->regs, 0, sizeof(struct regset));
 
 	roff_reset(curp->roff);
 
--
 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-18  7:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-18  7:46 mdocml: Make `struct roff' be passed into libmdoc and libman upon 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).