version 1.1, 2008/11/23 16:53:18 |
version 1.2, 2008/11/23 19:10:03 |
Line 83 struct roffnode { |
|
Line 83 struct roffnode { |
|
|
|
struct rofftree { |
struct rofftree { |
struct roffnode *last; |
struct roffnode *last; |
|
|
time_t date; |
time_t date; |
char title[256]; |
char title[256]; |
char section[256]; |
char section[256]; |
char volume[256]; |
char volume[256]; |
|
|
int state; |
int state; |
#define ROFF_PRELUDE (1 << 0) |
|
#define ROFF_PRELUDE_Os (1 << 1) |
#define ROFF_PRELUDE_Os (1 << 1) |
#define ROFF_PRELUDE_Dt (1 << 2) |
#define ROFF_PRELUDE_Dt (1 << 2) |
#define ROFF_PRELUDE_Dd (1 << 3) |
#define ROFF_PRELUDE_Dd (1 << 3) |
}; |
}; |
|
|
static int rofffind(const char *); |
static int rofffind(const char *); |
static int roffparse(const struct md_args *, |
static int roffparse(const struct md_args *, |
struct md_mbuf *, |
struct md_mbuf *, |
const struct md_rbuf *, |
const struct md_rbuf *, |
const char *, size_t, |
const char *, size_t, |
struct rofftree *); |
struct rofftree *); |
static int textparse(struct md_mbuf *, |
static int textparse(struct md_mbuf *, |
const struct md_rbuf *, |
const struct md_rbuf *, |
const char *, size_t, |
const char *, size_t, |
const struct rofftree *); |
const struct rofftree *); |
|
|
|
static void dbg_enter(const struct md_args *, int); |
|
static void dbg_leave(const struct md_args *, int); |
|
|
|
|
int |
int |
md_exit_html4_strict(const struct md_args *args, struct md_mbuf *out, |
md_exit_html4_strict(const struct md_args *args, struct md_mbuf *out, |
const struct md_rbuf *in, void *data) |
const struct md_rbuf *in, void *data) |
Line 340 roff_Dd(ROFFCALL_ARGS) |
|
Line 340 roff_Dd(ROFFCALL_ARGS) |
|
|
|
tree->date = time(NULL); |
tree->date = time(NULL); |
tree->state |= ROFF_PRELUDE_Dd; |
tree->state |= ROFF_PRELUDE_Dd; |
|
|
|
(void)printf("Dd\n"); |
|
|
return(1); |
return(1); |
} |
} |
|
|
Line 374 roff_Dt(ROFFCALL_ARGS) |
|
Line 377 roff_Dt(ROFFCALL_ARGS) |
|
/* TODO: parse titles from buffer. */ |
/* TODO: parse titles from buffer. */ |
|
|
tree->state |= ROFF_PRELUDE_Dt; |
tree->state |= ROFF_PRELUDE_Dt; |
|
|
|
(void)printf("Dt\n"); |
|
|
return(1); |
return(1); |
} |
} |
|
|
Line 397 roff_Os(ROFFCALL_ARGS) |
|
Line 403 roff_Os(ROFFCALL_ARGS) |
|
tree->last = node->parent; |
tree->last = node->parent; |
free(node); |
free(node); |
|
|
|
dbg_leave(arg, ROFF_Os); |
|
|
return(1); |
return(1); |
} |
} |
|
|
Line 430 roff_Os(ROFFCALL_ARGS) |
|
Line 438 roff_Os(ROFFCALL_ARGS) |
|
tree->state |= ROFF_PRELUDE_Os; |
tree->state |= ROFF_PRELUDE_Os; |
tree->last = node; |
tree->last = node; |
|
|
|
dbg_enter(arg, ROFF_Os); |
|
|
return(1); |
return(1); |
} |
} |
|
|
Line 437 roff_Os(ROFFCALL_ARGS) |
|
Line 447 roff_Os(ROFFCALL_ARGS) |
|
static int |
static int |
roff_Sh(ROFFCALL_ARGS) |
roff_Sh(ROFFCALL_ARGS) |
{ |
{ |
|
struct roffnode *node; |
|
|
assert(arg); |
assert(arg); |
/*assert(out);*/(void)out; |
|
assert(in); |
|
/*assert(buf);*/(void)buf; |
|
(void)sz; |
|
(void)pos; |
|
(void)type; |
|
assert(tree); |
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); |
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); |
} |
} |
|
|