source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Make some bit-flags into enums as they should be.
Date: Sat, 1 Jan 2011 12:10:20 -0500 (EST)	[thread overview]
Message-ID: <201101011710.p01HAK5S018028@krisdoz.my.domain> (raw)

Log Message:
-----------
Make some bit-flags into enums as they should be.  Make printing of -Ttree 
tables a little bit smarter.

Modified Files:
--------------
    mdocml:
        mandoc.h
        tbl_data.c
        tree.c

Revision Data
-------------
Index: tbl_data.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/tbl_data.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -Ltbl_data.c -Ltbl_data.c -u -p -r1.4 -r1.5
--- tbl_data.c
+++ tbl_data.c
@@ -68,16 +68,16 @@ data(struct tbl *tbl, struct tbl_span *d
 	if (p[*pos])
 		(*pos)++;
 
-	/* XXX: do the strcmps, then malloc(). */
-
 	if ( ! strcmp(dat->string, "_"))
-		dat->flags |= TBL_DATA_HORIZ;
+		dat->pos = TBL_DATA_HORIZ;
 	else if ( ! strcmp(dat->string, "="))
-		dat->flags |= TBL_DATA_DHORIZ;
+		dat->pos = TBL_DATA_DHORIZ;
 	else if ( ! strcmp(dat->string, "\\_"))
-		dat->flags |= TBL_DATA_NHORIZ;
+		dat->pos = TBL_DATA_NHORIZ;
 	else if ( ! strcmp(dat->string, "\\="))
-		dat->flags |= TBL_DATA_NDHORIZ;
+		dat->pos = TBL_DATA_NDHORIZ;
+	else
+		dat->pos = TBL_DATA_DATA;
 }
 
 int
@@ -119,12 +119,14 @@ tbl_data(struct tbl *tbl, int ln, const 
 		tbl->last_span = tbl->first_span = dp;
 
 	if ( ! strcmp(p, "_")) {
-		dp->flags |= TBL_SPAN_HORIZ;
+		dp->pos = TBL_SPAN_HORIZ;
 		return(1);
 	} else if ( ! strcmp(p, "=")) {
-		dp->flags |= TBL_SPAN_DHORIZ;
+		dp->pos = TBL_SPAN_DHORIZ;
 		return(1);
 	}
+
+	dp->pos = TBL_SPAN_DATA;
 
 	while ('\0' != p[pos])
 		data(tbl, dp, ln, p, &pos);
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -Lmandoc.h -Lmandoc.h -u -p -r1.39 -r1.40
--- mandoc.h
+++ mandoc.h
@@ -181,6 +181,14 @@ struct	tbl_row {
 	struct tbl_cell	 *last;
 };
 
+enum	tbl_datt {
+	TBL_DATA_DATA,
+	TBL_DATA_HORIZ,
+	TBL_DATA_DHORIZ,
+	TBL_DATA_NHORIZ,
+	TBL_DATA_NDHORIZ
+};
+
 /*
  * A cell within a row of data.  The "string" field contains the actual
  * string value that's in the cell.  The rest is layout.
@@ -189,11 +197,13 @@ struct	tbl_dat {
 	struct tbl_cell	 *layout; /* layout cell: CAN BE NULL */
 	struct tbl_dat	 *next;
 	char		 *string;
-	int		  flags;
-#define	TBL_DATA_HORIZ	 (1 << 0)
-#define	TBL_DATA_DHORIZ	 (1 << 1)
-#define	TBL_DATA_NHORIZ	 (1 << 2)
-#define	TBL_DATA_NDHORIZ (1 << 3)
+	enum tbl_datt	  pos;
+};
+
+enum	tbl_spant {
+	TBL_SPAN_DATA, /* span consists of data */
+	TBL_SPAN_HORIZ, /* span is horizontal line */
+	TBL_SPAN_DHORIZ /* span is double horizontal line */
 };
 
 /*
@@ -203,9 +213,7 @@ struct	tbl_span {
 	struct tbl_row	 *layout; /* layout row: CAN BE NULL */
 	struct tbl_dat	 *first;
 	struct tbl_dat	 *last;
-	int		  flags;
-#define	TBL_SPAN_HORIZ	(1 << 0)
-#define	TBL_SPAN_DHORIZ	(1 << 1)
+	enum tbl_spant	  pos;
 	struct tbl_span	 *next;
 };
 
Index: tree.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/tree.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -Ltree.c -Ltree.c -u -p -r1.27 -r1.28
--- tree.c
+++ tree.c
@@ -30,6 +30,7 @@
 
 static	void	print_mdoc(const struct mdoc_node *, int);
 static	void	print_man(const struct man_node *, int);
+static	void	print_span(const struct tbl_span *);
 
 
 /* ARGSUSED */
@@ -58,7 +59,6 @@ print_mdoc(const struct mdoc_node *n, in
 	size_t		  argc, sz;
 	char		**params;
 	struct mdoc_argv *argv;
-	const struct tbl_dat *dp;
 
 	argv = NULL;
 	argc = sz = 0;
@@ -141,12 +141,7 @@ print_mdoc(const struct mdoc_node *n, in
 
 	if (n->span) {
 		assert(NULL == p);
-		printf("tbl: ");
-		for (dp = n->span->first; dp; dp = dp->next) {
-			printf("[%s]", dp->string);
-			if (dp->next)
-				putchar(' ');
-		}
+		print_span(n->span);
 	} else {
 		printf("%s (%s)", p, t);
 
@@ -180,7 +175,6 @@ print_man(const struct man_node *n, int 
 {
 	const char	 *p, *t;
 	int		  i;
-	const struct tbl_dat *dp;
 
 	switch (n->type) {
 	case (MAN_ROOT):
@@ -239,13 +233,8 @@ print_man(const struct man_node *n, int 
 
 	if (n->span) {
 		assert(NULL == p);
-		printf("tbl: ");
-		for (dp = n->span->first; dp; dp = dp->next) {
-			printf("[%s]", dp->string);
-			if (dp->next)
-				putchar(' ');
-		}
-	} else 
+		print_span(n->span);
+	} else
 		printf("%s (%s) %d:%d", p, t, n->line, n->pos);
 
 	putchar('\n');
@@ -254,4 +243,43 @@ print_man(const struct man_node *n, int 
 		print_man(n->child, indent + 1);
 	if (n->next)
 		print_man(n->next, indent);
+}
+
+static void
+print_span(const struct tbl_span *sp)
+{
+	const struct tbl_dat *dp;
+
+	printf("tbl: ");
+
+	switch (sp->pos) {
+	case (TBL_SPAN_HORIZ):
+		putchar('-');
+		return;
+	case (TBL_SPAN_DHORIZ):
+		putchar('=');
+		return;
+	default:
+		break;
+	}
+
+	for (dp = sp->first; dp; dp = dp->next) {
+		switch (dp->pos) {
+		case (TBL_DATA_HORIZ):
+			/* FALLTHROUGH */
+		case (TBL_DATA_NHORIZ):
+			putchar('-');
+			continue;
+		case (TBL_DATA_DHORIZ):
+			/* FALLTHROUGH */
+		case (TBL_DATA_NDHORIZ):
+			putchar('=');
+			continue;
+		default:
+			break;
+		}
+		printf("[%s]", dp->string);
+		if (dp->next)
+			putchar(' ');
+	}
 }
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2011-01-01 17:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201101011710.p01HAK5S018028@krisdoz.my.domain \
    --to=kristaps@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).