summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-11-23 19:10:03 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-11-23 19:10:03 +0000
commitf112f081ce6342cac8aaa76066abd437028e89ae (patch)
tree5904b8960b75a0996618fa1add5ce427149e9d89
parentdb7d65ce12b3c123e790060a4a62e61637bf6d9b (diff)
downloadmandoc-f112f081ce6342cac8aaa76066abd437028e89ae.tar.gz
mandoc-f112f081ce6342cac8aaa76066abd437028e89ae.tar.zst
mandoc-f112f081ce6342cac8aaa76066abd437028e89ae.zip
Initial support for Sh.
Debugging things (will be changed out).
-rw-r--r--html4_strict.c107
-rw-r--r--libmdocml.h4
-rw-r--r--mdocml.c3
3 files changed, 99 insertions, 15 deletions
diff --git a/html4_strict.c b/html4_strict.c
index 66561adf..f430e0f5 100644
--- a/html4_strict.c
+++ b/html4_strict.c
@@ -1,4 +1,4 @@
-/* $Id: html4_strict.c,v 1.1 2008/11/23 16:53:18 kristaps Exp $ */
+/* $Id: html4_strict.c,v 1.2 2008/11/23 19:10:03 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -83,30 +83,30 @@ struct roffnode {
struct rofftree {
struct roffnode *last;
-
time_t date;
char title[256];
char section[256];
char volume[256];
-
int state;
-#define ROFF_PRELUDE (1 << 0)
#define ROFF_PRELUDE_Os (1 << 1)
#define ROFF_PRELUDE_Dt (1 << 2)
#define ROFF_PRELUDE_Dd (1 << 3)
};
-static int rofffind(const char *);
-static int roffparse(const struct md_args *,
+static int rofffind(const char *);
+static int roffparse(const struct md_args *,
struct md_mbuf *,
const struct md_rbuf *,
const char *, size_t,
struct rofftree *);
-static int textparse(struct md_mbuf *,
+static int textparse(struct md_mbuf *,
const struct md_rbuf *,
const char *, size_t,
const struct rofftree *);
+static void dbg_enter(const struct md_args *, int);
+static void dbg_leave(const struct md_args *, int);
+
int
md_exit_html4_strict(const struct md_args *args, struct md_mbuf *out,
@@ -340,6 +340,9 @@ roff_Dd(ROFFCALL_ARGS)
tree->date = time(NULL);
tree->state |= ROFF_PRELUDE_Dd;
+
+ (void)printf("Dd\n");
+
return(1);
}
@@ -374,6 +377,9 @@ roff_Dt(ROFFCALL_ARGS)
/* TODO: parse titles from buffer. */
tree->state |= ROFF_PRELUDE_Dt;
+
+ (void)printf("Dt\n");
+
return(1);
}
@@ -397,6 +403,8 @@ roff_Os(ROFFCALL_ARGS)
tree->last = node->parent;
free(node);
+ dbg_leave(arg, ROFF_Os);
+
return(1);
}
@@ -430,6 +438,8 @@ roff_Os(ROFFCALL_ARGS)
tree->state |= ROFF_PRELUDE_Os;
tree->last = node;
+ dbg_enter(arg, ROFF_Os);
+
return(1);
}
@@ -437,15 +447,86 @@ roff_Os(ROFFCALL_ARGS)
static int
roff_Sh(ROFFCALL_ARGS)
{
+ struct roffnode *node;
assert(arg);
- /*assert(out);*/(void)out;
- assert(in);
- /*assert(buf);*/(void)buf;
- (void)sz;
- (void)pos;
- (void)type;
assert(tree);
+ assert(tree->last);
+ assert(in);
+
+ if (ROFF_EXIT == type) {
+ assert(tree->last->tok == ROFF_Sh);
+
+ node = tree->last;
+ tree->last = node->parent;
+ free(node);
+
+ dbg_leave(arg, ROFF_Sh);
+
+ return(1);
+ }
+
+ assert(out);
+ assert(buf);
+ assert(sz > 0);
+ assert(pos > 0);
+
+ node = malloc(sizeof(struct roffnode));
+ if (NULL == node) {
+ warn("malloc");
+ return(0);
+ }
+ node->tok = ROFF_Sh;
+ node->parent = tree->last;
+
+ tree->last = node;
+
+ dbg_enter(arg, ROFF_Sh);
+
return(1);
}
+
+static int dbg_lvl = 0; /* FIXME: de-globalise. */
+
+
+static void
+dbg_enter(const struct md_args *args, int tokid)
+{
+ int i;
+
+ assert(args);
+ if ( ! (args->dbg & MD_DBG_TREE))
+ return;
+
+ assert(tokid >= 0 && tokid <= ROFF_Max);
+
+ for (i = 0; i < dbg_lvl; i++)
+ (void)printf(" ");
+
+ (void)printf("%s\n", tokens[tokid].name);
+
+ if (ROFF_LAYOUT == tokens[tokid].type)
+ dbg_lvl++;
+}
+
+
+static void
+dbg_leave(const struct md_args *args, int tokid)
+{
+ int i;
+
+ assert(args);
+ if ( ! (args->dbg & MD_DBG_TREE))
+ return;
+
+ assert(tokid >= 0 && tokid <= ROFF_Max);
+ assert(dbg_lvl > 0);
+
+ dbg_lvl--;
+ for (i = 0; i < dbg_lvl; i++)
+ (void)printf(" ");
+
+ (void)printf("%s\n", tokens[tokid].name);
+}
+
diff --git a/libmdocml.h b/libmdocml.h
index 60ea7f8f..7d760af8 100644
--- a/libmdocml.h
+++ b/libmdocml.h
@@ -1,4 +1,4 @@
-/* $Id: libmdocml.h,v 1.3 2008/11/22 20:15:34 kristaps Exp $ */
+/* $Id: libmdocml.h,v 1.4 2008/11/23 19:10:03 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -42,6 +42,8 @@ enum md_type {
struct md_args {
union md_params params;/* Parameters for parser. */
enum md_type type; /* Type of parser. */
+ int dbg; /* Debug level. */
+#define MD_DBG_TREE (1 << 0)
};
struct md_buf {
diff --git a/mdocml.c b/mdocml.c
index 99cdc120..e27748f0 100644
--- a/mdocml.c
+++ b/mdocml.c
@@ -1,4 +1,4 @@
-/* $Id: mdocml.c,v 1.6 2008/11/23 11:05:25 kristaps Exp $ */
+/* $Id: mdocml.c,v 1.7 2008/11/23 19:10:03 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -72,6 +72,7 @@ main(int argc, char *argv[])
in = *argv++;
args.type = MD_HTML4_STRICT;
+ args.dbg = MD_DBG_TREE;
return(begin_io(&args, out ? out : "-", in ? in : "-"));
}