[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mandoc-source
Subject:    mdocml: Initial check-in of table data-row processing.
From:       kristaps () mdocml ! bsd ! lv
Date:       2010-12-29 16:44:24
Message-ID: 201012291644.oBTGiNUa006821 () krisdoz ! my ! domain
[Download RAW message or body]

Log Message:
-----------
Initial check-in of table data-row processing.  For the time being, this
parses table data then throws it away immediately.  It does not yet try
to cross-check data rows against layout or anything.  This copied more
or less completely from tbl.bsd.lv.

Modified Files:
--------------
    mdocml:
        Makefile
        libroff.h
        tbl.c

Added Files:
-----------
    mdocml:
        tbl_data.c

Revision Data
-------------
--- /dev/null
+++ tbl_data.c
@@ -0,0 +1,96 @@
+/*	$Id: tbl_data.c,v 1.1 2010/12/29 16:44:23 kristaps Exp $ */
+/*
+ * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <assert.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "mandoc.h"
+#include "libmandoc.h"
+#include "libroff.h"
+
+static	void	data(struct tbl *, struct tbl_span *, 
+			int, const char *, int *);
+
+void
+data(struct tbl *tbl, struct tbl_span *dp, 
+		int ln, const char *p, int *pos)
+{
+	struct tbl_dat	*dat;
+	int		 sv;
+
+	/* FIXME: warn about losing data contents if cell is HORIZ. */
+
+	dat = mandoc_calloc(1, sizeof(struct tbl_dat));
+
+	if (dp->last) {
+		dp->last->next = dat;
+		dp->last = dat;
+	} else
+		dp->last = dp->first = dat;
+
+	sv = *pos;
+	while (p[*pos] && p[*pos] != tbl->tab)
+		(*pos)++;
+
+	dat->string = mandoc_malloc(*pos - sv + 1);
+	memcpy(dat->string, &p[sv], *pos - sv);
+	dat->string[*pos - sv] = '\0';
+
+	if (p[*pos])
+		(*pos)++;
+
+	/* XXX: do the strcmps, then malloc(). */
+
+	if ( ! strcmp(dat->string, "_"))
+		dat->flags |= TBL_DATA_HORIZ;
+	else if ( ! strcmp(dat->string, "="))
+		dat->flags |= TBL_DATA_DHORIZ;
+	else if ( ! strcmp(dat->string, "\\_"))
+		dat->flags |= TBL_DATA_NHORIZ;
+	else if ( ! strcmp(dat->string, "\\="))
+		dat->flags |= TBL_DATA_NDHORIZ;
+}
+
+struct tbl_span *
+tbl_data(struct tbl *tbl, int ln, const char *p)
+{
+	struct tbl_span	*dp;
+	int		 pos;
+
+	pos = 0;
+
+	if ('\0' == p[pos]) {
+		TBL_MSG(tbl, MANDOCERR_TBL, ln, pos);
+		return(NULL);
+	}
+
+	dp = mandoc_calloc(1, sizeof(struct tbl_span));
+
+	if ( ! strcmp(p, "_")) {
+		dp->flags |= TBL_SPAN_HORIZ;
+		return(dp);
+	} else if ( ! strcmp(p, "=")) {
+		dp->flags |= TBL_SPAN_DHORIZ;
+		return(dp);
+	}
+
+	while ('\0' != p[pos])
+		data(tbl, dp, ln, p, &pos);
+
+	return(dp);
+}
Index: tbl.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/tbl.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -Ltbl.c -Ltbl.c -u -p -r1.7 -r1.8
--- tbl.c
+++ tbl.c
@@ -63,6 +63,8 @@ tbl_read(struct tbl *tbl, int ln, const 
 {
 	int		 len;
 	const char	*cp;
+	struct tbl_dat	*dp;
+	struct tbl_span	*sp;
 
 	cp = &p[offs];
 	len = (int)strlen(cp);
@@ -85,8 +87,19 @@ tbl_read(struct tbl *tbl, int ln, const 
 		return(tbl_option(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
 	case (TBL_PART_LAYOUT):
 		return(tbl_layout(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
-	default:
+	case (TBL_PART_DATA):
 		break;
+	}
+
+	/* XXX: throw away data for now. */
+	if (NULL != (sp = tbl_data(tbl, ln, p))) {
+		while (NULL != (dp = sp->first)) {
+			sp->first = sp->first->next;
+			if (dp->string)
+				free(dp->string);
+			free(dp);
+		}
+		free(sp);
 	}
 	
 	return(ROFF_CONT);
Index: libroff.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libroff.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -Llibroff.h -Llibroff.h -u -p -r1.6 -r1.7
--- libroff.h
+++ libroff.h
@@ -60,6 +60,24 @@ struct	tbl_row {
 	struct tbl_cell	 *last;
 };
 
+struct	tbl_dat {
+	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)
+};
+
+struct	tbl_span {
+	struct tbl_dat	 *first;
+	struct tbl_dat	 *last;
+	int		  flags;
+#define	TBL_SPAN_HORIZ	(1 << 0)
+#define	TBL_SPAN_DHORIZ	(1 << 1)
+};
+
 struct	tbl {
 	mandocmsg	  msg; /* status messages */
 	void		 *data; /* privdata for messages */
@@ -90,6 +108,7 @@ void		 tbl_reset(struct tbl *);
 enum rofferr 	 tbl_read(struct tbl *, int, const char *, int);
 int		 tbl_option(struct tbl *, int, const char *);
 int		 tbl_layout(struct tbl *, int, const char *);
+struct tbl_span	*tbl_data(struct tbl *, int, const char *);
 
 __END_DECLS
 
Index: Makefile
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v
retrieving revision 1.303
retrieving revision 1.304
diff -LMakefile -LMakefile -u -p -r1.303 -r1.304
--- Makefile
+++ Makefile
@@ -31,11 +31,11 @@ CFLAGS    += -g $(WFLAGS) $(VFLAGS) -DHA
 
 LINTFLAGS += $(VFLAGS)
 
-ROFFLNS    = roff.ln tbl.ln tbl_opts.ln tbl_layout.ln
+ROFFLNS    = roff.ln tbl.ln tbl_opts.ln tbl_layout.ln tbl_data.ln
 
-ROFFSRCS   = roff.c tbl.c tbl_opts.c tbl_layout.c
+ROFFSRCS   = roff.c tbl.c tbl_opts.c tbl_layout.c tbl_data.c
 
-ROFFOBJS   = roff.o tbl.o tbl_opts.o tbl_layout.o
+ROFFOBJS   = roff.o tbl.o tbl_opts.o tbl_layout.o tbl_data.o
 
 MANDOCLNS  = mandoc.ln
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic