source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Generalize the mparse_alloc() and roff_alloc() functions by
@ 2014-03-19 21:51 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-03-19 21:51 UTC (permalink / raw)
  To: source

Log Message:
-----------
Generalize the mparse_alloc() and roff_alloc() functions by giving
them an "options" argument, replacing the existing "inttype" and
"quick" arguments, preparing for a future MPARSE_SO option.
Store this argument in struct mparse and struct roff, replacing the
existing "inttype", "parsetype", and "quick" members.
No functional change except one tiny cosmetic fix in roff_TH().

Modified Files:
--------------
    mdocml:
        libmandoc.h
        main.c
        mandoc.h
        mandocdb.c
        read.c
        roff.c

Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.115 -r1.116
--- mandocdb.c
+++ mandocdb.c
@@ -172,7 +172,7 @@ static	size_t	 utf8(unsigned int, char [
 static	char		 tempfilename[32];
 static	char		*progname;
 static	int		 nodb; /* no database changes */
-static	int		 quick; /* abort the parse early */
+static	int		 mparse_options; /* abort the parse early */
 static	int	 	 use_all; /* use all found files */
 static	int	  	 verb; /* print what we're doing */
 static	int	  	 warnings; /* warn about crap */
@@ -351,6 +351,7 @@ main(int argc, char *argv[])
 
 	path_arg = NULL;
 	op = OP_DEFAULT;
+	mparse_options = MPARSE_SO;
 
 	while (-1 != (ch = getopt(argc, argv, "aC:d:nQT:tu:vW")))
 		switch (ch) {
@@ -371,7 +372,7 @@ main(int argc, char *argv[])
 			nodb = 1;
 			break;
 		case ('Q'):
-			quick = 1;
+			mparse_options |= MPARSE_QUICK;
 			break;
 		case ('T'):
 			if (strcmp(optarg, "utf8")) {
@@ -411,8 +412,7 @@ main(int argc, char *argv[])
 	}
 
 	exitcode = (int)MANDOCLEVEL_OK;
-	mp = mparse_alloc(MPARSE_AUTO, 
-		MANDOCLEVEL_FATAL, NULL, NULL, quick);
+	mp = mparse_alloc(mparse_options, MANDOCLEVEL_FATAL, NULL, NULL);
 	mc = mchars_alloc();
 
 	ohash_init(&mpages, 6, &mpages_info);
@@ -1985,7 +1985,7 @@ dbopen(int real)
 	rc = sqlite3_open_v2(MANDOC_DB "~", &db, ofl, NULL);
 	if (SQLITE_OK == rc) 
 		goto create_tables;
-	if (quick) {
+	if (MPARSE_QUICK & mparse_options) {
 		exitcode = (int)MANDOCLEVEL_SYSERR;
 		say(MANDOC_DB "~", "%s", sqlite3_errmsg(db));
 		return(0);
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.115
retrieving revision 1.116
diff -Lmandoc.h -Lmandoc.h -u -p -r1.115 -r1.116
--- mandoc.h
+++ mandoc.h
@@ -372,15 +372,12 @@ struct	eqn {
 };
 
 /*
- * The type of parse sequence.  This value is usually passed via the
- * mandoc(1) command line of -man and -mdoc.  It's almost exclusively
- * -mandoc but the others have been retained for compatibility.
+ * Parse options.
  */
-enum	mparset {
-	MPARSE_AUTO, /* magically determine the document type */
-	MPARSE_MDOC, /* assume -mdoc */
-	MPARSE_MAN /* assume -man */
-};
+#define	MPARSE_MDOC	1  /* assume -mdoc */
+#define	MPARSE_MAN	2  /* assume -man */
+#define	MPARSE_SO	4  /* honour .so requests */
+#define	MPARSE_QUICK	8  /* abort the parse early */
 
 enum	mandoc_esc {
 	ESCAPE_ERROR = 0, /* bail! unparsable escape */
@@ -422,8 +419,7 @@ int		  mchars_spec2cp(const struct mchar
 			const char *, size_t);
 const char	 *mchars_spec2str(const struct mchars *, 
 			const char *, size_t, size_t *);
-struct mparse	 *mparse_alloc(enum mparset, enum mandoclevel,
-			mandocmsg, char *, int);
+struct mparse	 *mparse_alloc(int, enum mandoclevel, mandocmsg, char *);
 void		  mparse_free(struct mparse *);
 void		  mparse_keep(struct mparse *);
 enum mandoclevel  mparse_readfd(struct mparse *, int, const char *);
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.198
retrieving revision 1.199
diff -Lroff.c -Lroff.c -u -p -r1.198 -r1.199
--- roff.c
+++ roff.c
@@ -103,9 +103,8 @@ struct	roffreg {
 };
 
 struct	roff {
-	enum mparset	 parsetype; /* requested parse type */
 	struct mparse	*parse; /* parse point */
-	int		 quick; /* skip standard macro deletion */
+	int		 options; /* parse options */
 	struct roffnode	*last; /* leaf of stack */
 	int		 rstack[RSTACK_MAX]; /* stack of !`ie' rules */
 	char		 control; /* control character */
@@ -463,14 +462,13 @@ roff_free(struct roff *r)
 
 
 struct roff *
-roff_alloc(enum mparset type, struct mparse *parse, int quick)
+roff_alloc(struct mparse *parse, int options)
 {
 	struct roff	*r;
 
 	r = mandoc_calloc(1, sizeof(struct roff));
-	r->parsetype = type;
 	r->parse = parse;
-	r->quick = quick;
+	r->options = options;
 	r->rstackpos = -1;
 	
 	roffhash_init();
@@ -1552,7 +1550,7 @@ roff_Dd(ROFF_ARGS)
 {
 	const char *const	*cp;
 
-	if (0 == r->quick && MPARSE_MDOC != r->parsetype)
+	if (0 == ((MPARSE_MDOC | MPARSE_QUICK) & r->options))
 		for (cp = __mdoc_reserved; *cp; cp++)
 			roff_setstr(r, *cp, NULL, 0);
 
@@ -1565,7 +1563,7 @@ roff_TH(ROFF_ARGS)
 {
 	const char *const	*cp;
 
-	if (0 == r->quick && MPARSE_MDOC != r->parsetype)
+	if (0 == (MPARSE_QUICK & r->options))
 		for (cp = __man_reserved; *cp; cp++)
 			roff_setstr(r, *cp, NULL, 0);
 
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -Lread.c -Lread.c -u -p -r1.43 -r1.44
--- read.c
+++ read.c
@@ -53,7 +53,7 @@ struct	mparse {
 	enum mandoclevel  file_status; /* status of current parse */
 	enum mandoclevel  wlevel; /* ignore messages below this */
 	int		  line; /* line number in the file */
-	enum mparset	  inttype; /* which parser to use */
+	int		  options; /* parser options */
 	struct man	 *pman; /* persistent man parser */
 	struct mdoc	 *pmdoc; /* persistent mdoc parser */
 	struct man	 *man; /* man parser */
@@ -64,7 +64,6 @@ struct	mparse {
 	const char	 *file; 
 	struct buf	 *secondary;
 	char		 *defos; /* default operating system */
-	int		  quick; /* abort the parse early */
 };
 
 static	void	  resize_buf(struct buf *, size_t);
@@ -255,36 +254,36 @@ pset(const char *buf, int pos, struct mp
 			return;
 	}
 
-	switch (curp->inttype) {
-	case (MPARSE_MDOC):
+	if (MPARSE_MDOC & curp->options) {
 		if (NULL == curp->pmdoc) 
-			curp->pmdoc = mdoc_alloc(curp->roff, curp,
-					curp->defos, curp->quick);
+			curp->pmdoc = mdoc_alloc(
+			    curp->roff, curp, curp->defos,
+			    MPARSE_QUICK & curp->options ? 1 : 0);
 		assert(curp->pmdoc);
 		curp->mdoc = curp->pmdoc;
 		return;
-	case (MPARSE_MAN):
+	} else if (MPARSE_MAN & curp->options) {
 		if (NULL == curp->pman) 
 			curp->pman = man_alloc(curp->roff, curp,
-					curp->quick);
+			    MPARSE_QUICK & curp->options ? 1 : 0);
 		assert(curp->pman);
 		curp->man = curp->pman;
 		return;
-	default:
-		break;
 	}
 
 	if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3))  {
 		if (NULL == curp->pmdoc) 
-			curp->pmdoc = mdoc_alloc(curp->roff, curp,
-					curp->defos, curp->quick);
+			curp->pmdoc = mdoc_alloc(
+			    curp->roff, curp, curp->defos,
+			    MPARSE_QUICK & curp->options ? 1 : 0);
 		assert(curp->pmdoc);
 		curp->mdoc = curp->pmdoc;
 		return;
 	} 
 
 	if (NULL == curp->pman) 
-		curp->pman = man_alloc(curp->roff, curp, curp->quick);
+		curp->pman = man_alloc(curp->roff, curp,
+		    MPARSE_QUICK & curp->options ? 1 : 0);
 	assert(curp->pman);
 	curp->man = curp->pman;
 }
@@ -765,8 +764,8 @@ out:
 }
 
 struct mparse *
-mparse_alloc(enum mparset inttype, enum mandoclevel wlevel,
-		mandocmsg mmsg, char *defos, int quick)
+mparse_alloc(int options, enum mandoclevel wlevel,
+		mandocmsg mmsg, char *defos)
 {
 	struct mparse	*curp;
 
@@ -774,13 +773,12 @@ mparse_alloc(enum mparset inttype, enum 
 
 	curp = mandoc_calloc(1, sizeof(struct mparse));
 
+	curp->options = options;
 	curp->wlevel = wlevel;
 	curp->mmsg = mmsg;
-	curp->inttype = inttype;
 	curp->defos = defos;
-	curp->quick = quick;
 
-	curp->roff = roff_alloc(inttype, curp, curp->quick);
+	curp->roff = roff_alloc(curp, options);
 	return(curp);
 }
 
Index: main.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v
retrieving revision 1.169
retrieving revision 1.170
diff -Lmain.c -Lmain.c -u -p -r1.169 -r1.170
--- main.c
+++ main.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -67,7 +67,7 @@ struct	curparse {
 	char		  outopts[BUFSIZ]; /* buf of output opts */
 };
 
-static	int		  moptions(enum mparset *, char *);
+static	int		  moptions(int *, char *);
 static	void		  mmsg(enum mandocerr, enum mandoclevel,
 				const char *, int, int, const char *);
 static	void		  parse(struct curparse *, int, 
@@ -84,7 +84,7 @@ main(int argc, char *argv[])
 {
 	int		 c;
 	struct curparse	 curp;
-	enum mparset	 type;
+	int		 options;
 	enum mandoclevel rc;
 	char		*defos;
 
@@ -96,7 +96,7 @@ main(int argc, char *argv[])
 
 	memset(&curp, 0, sizeof(struct curparse));
 
-	type = MPARSE_AUTO;
+	options = MPARSE_SO;
 	curp.outtype = OUTT_ASCII;
 	curp.wlevel  = MANDOCLEVEL_FATAL;
 	defos = NULL;
@@ -118,7 +118,7 @@ main(int argc, char *argv[])
 			defos = mandoc_strdup(optarg + 3);
 			break;
 		case ('m'):
-			if ( ! moptions(&type, optarg))
+			if ( ! moptions(&options, optarg))
 				return((int)MANDOCLEVEL_BADARG);
 			break;
 		case ('O'):
@@ -141,7 +141,7 @@ main(int argc, char *argv[])
 			/* NOTREACHED */
 		}
 
-	curp.mp = mparse_alloc(type, curp.wlevel, mmsg, defos, 0);
+	curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
 
 	/*
 	 * Conditionally start up the lookaside buffer before parsing.
@@ -312,15 +312,15 @@ parse(struct curparse *curp, int fd, 
 }
 
 static int
-moptions(enum mparset *tflags, char *arg)
+moptions(int *options, char *arg)
 {
 
 	if (0 == strcmp(arg, "doc"))
-		*tflags = MPARSE_MDOC;
+		*options |= MPARSE_MDOC;
 	else if (0 == strcmp(arg, "andoc"))
-		*tflags = MPARSE_AUTO;
+		/* nothing to do */;
 	else if (0 == strcmp(arg, "an"))
-		*tflags = MPARSE_MAN;
+		*options |= MPARSE_MAN;
 	else {
 		fprintf(stderr, "%s: Bad argument\n", arg);
 		return(0);
Index: libmandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmandoc.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.39 -r1.40
--- libmandoc.h
+++ libmandoc.h
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -66,7 +66,7 @@ int		 man_addspan(struct man *, const st
 int		 man_addeqn(struct man *, const struct eqn *);
 
 void	 	 roff_free(struct roff *);
-struct roff	*roff_alloc(enum mparset, struct mparse *, int);
+struct roff	*roff_alloc(struct mparse *, int);
 void		 roff_reset(struct roff *);
 enum rofferr	 roff_parseln(struct roff *, int, 
 			char **, size_t *, int, int *);
--
 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:[~2014-03-19 21:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-19 21:51 mdocml: Generalize the mparse_alloc() and roff_alloc() functions by schwarze

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).