version 1.31, 2009/09/17 07:41:28 |
version 1.32, 2009/09/17 08:21:42 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
|
|
#include "chars.h" |
#include "mdoc.h" |
#include "mdoc.h" |
#include "man.h" |
#include "man.h" |
|
|
|
|
#define HTML_NOSPACE (1 << 0) |
#define HTML_NOSPACE (1 << 0) |
#define HTML_NEWLINE (1 << 1) |
#define HTML_NEWLINE (1 << 1) |
struct tagq stack; |
struct tagq stack; |
|
void *symtab; |
}; |
}; |
|
|
#define MDOC_ARGS const struct mdoc_meta *m, \ |
#define MDOC_ARGS const struct mdoc_meta *m, \ |
Line 134 static struct tag *print_otag(struct html *, enum htm |
|
Line 136 static struct tag *print_otag(struct html *, enum htm |
|
static void print_tagq(struct html *, const struct tag *); |
static void print_tagq(struct html *, const struct tag *); |
static void print_stagq(struct html *, const struct tag *); |
static void print_stagq(struct html *, const struct tag *); |
static void print_ctag(struct html *, enum htmltag); |
static void print_ctag(struct html *, enum htmltag); |
static void print_encode(const char *); |
static void print_encode(struct html *, const char *); |
|
static void print_escape(struct html *, const char **); |
static void print_text(struct html *, const char *); |
static void print_text(struct html *, const char *); |
|
static void print_res(struct html *, const char *, int); |
|
static void print_spec(struct html *, const char *, int); |
static int mdoc_root_pre(MDOC_ARGS); |
static int mdoc_root_pre(MDOC_ARGS); |
|
|
static int mdoc_ar_pre(MDOC_ARGS); |
static int mdoc_ar_pre(MDOC_ARGS); |
Line 273 static const struct htmlmdoc mdocs[MDOC_MAX] = { |
|
Line 278 static const struct htmlmdoc mdocs[MDOC_MAX] = { |
|
{NULL, NULL}, /* sp */ |
{NULL, NULL}, /* sp */ |
}; |
}; |
|
|
|
|
void |
void |
html_mdoc(void *arg, const struct mdoc *m) |
html_mdoc(void *arg, const struct mdoc *m) |
{ |
{ |
Line 290 html_mdoc(void *arg, const struct mdoc *m) |
|
Line 294 html_mdoc(void *arg, const struct mdoc *m) |
|
printf("\n"); |
printf("\n"); |
} |
} |
|
|
|
|
void |
void |
html_man(void *arg, const struct man *m) |
html_man(void *arg, const struct man *m) |
{ |
{ |
Line 307 html_man(void *arg, const struct man *m) |
|
Line 310 html_man(void *arg, const struct man *m) |
|
printf("\n"); |
printf("\n"); |
} |
} |
|
|
|
|
void * |
void * |
html_alloc(void) |
html_alloc(void) |
{ |
{ |
Line 317 html_alloc(void) |
|
Line 319 html_alloc(void) |
|
return(NULL); |
return(NULL); |
|
|
SLIST_INIT(&h->stack); |
SLIST_INIT(&h->stack); |
|
if (NULL == (h->symtab = chars_init(CHARS_HTML))) { |
|
free(h); |
|
return(NULL); |
|
} |
return(h); |
return(h); |
} |
} |
|
|
|
|
void |
void |
html_free(void *p) |
html_free(void *p) |
{ |
{ |
Line 337 html_free(void *p) |
|
Line 342 html_free(void *p) |
|
free(h); |
free(h); |
} |
} |
|
|
|
|
static void |
static void |
print_mdoc(MDOC_ARGS) |
print_mdoc(MDOC_ARGS) |
{ |
{ |
Line 353 print_mdoc(MDOC_ARGS) |
|
Line 357 print_mdoc(MDOC_ARGS) |
|
print_tagq(h, t); |
print_tagq(h, t); |
} |
} |
|
|
|
|
static void |
static void |
print_gen_head(struct html *h) |
print_gen_head(struct html *h) |
{ |
{ |
Line 385 print_gen_head(struct html *h) |
|
Line 388 print_gen_head(struct html *h) |
|
print_otag(h, TAG_LINK, 4, link); |
print_otag(h, TAG_LINK, 4, link); |
} |
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static void |
static void |
print_mdoc_head(MDOC_ARGS) |
print_mdoc_head(MDOC_ARGS) |
Line 393 print_mdoc_head(MDOC_ARGS) |
|
Line 395 print_mdoc_head(MDOC_ARGS) |
|
|
|
print_gen_head(h); |
print_gen_head(h); |
print_otag(h, TAG_TITLE, 0, NULL); |
print_otag(h, TAG_TITLE, 0, NULL); |
print_encode(m->title); |
print_encode(h, m->title); |
} |
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static void |
static void |
print_mdoc_title(MDOC_ARGS) |
print_mdoc_title(MDOC_ARGS) |
Line 405 print_mdoc_title(MDOC_ARGS) |
|
Line 406 print_mdoc_title(MDOC_ARGS) |
|
/* TODO */ |
/* TODO */ |
} |
} |
|
|
|
|
static void |
static void |
print_mdoc_node(MDOC_ARGS) |
print_mdoc_node(MDOC_ARGS) |
{ |
{ |
Line 448 print_mdoc_node(MDOC_ARGS) |
|
Line 448 print_mdoc_node(MDOC_ARGS) |
|
print_mdoc_node(m, n->next, h); |
print_mdoc_node(m, n->next, h); |
} |
} |
|
|
|
|
static void |
static void |
print_man(MAN_ARGS) |
print_man(MAN_ARGS) |
{ |
{ |
Line 463 print_man(MAN_ARGS) |
|
Line 462 print_man(MAN_ARGS) |
|
print_tagq(h, t); |
print_tagq(h, t); |
} |
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static void |
static void |
print_man_head(MAN_ARGS) |
print_man_head(MAN_ARGS) |
Line 471 print_man_head(MAN_ARGS) |
|
Line 469 print_man_head(MAN_ARGS) |
|
|
|
print_gen_head(h); |
print_gen_head(h); |
print_otag(h, TAG_TITLE, 0, NULL); |
print_otag(h, TAG_TITLE, 0, NULL); |
print_encode(m->title); |
print_encode(h, m->title); |
} |
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static void |
static void |
print_man_body(MAN_ARGS) |
print_man_body(MAN_ARGS) |
Line 483 print_man_body(MAN_ARGS) |
|
Line 480 print_man_body(MAN_ARGS) |
|
/* TODO */ |
/* TODO */ |
} |
} |
|
|
|
static void |
|
print_spec(struct html *h, const char *p, int len) |
|
{ |
|
const char *rhs; |
|
int i; |
|
size_t sz; |
|
|
|
rhs = chars_a2ascii(h->symtab, p, (size_t)len, &sz); |
|
|
|
if (NULL == rhs) |
|
return; |
|
for (i = 0; i < (int)sz; i++) |
|
putchar(rhs[i]); |
|
} |
|
|
static void |
static void |
print_encode(const char *p) |
print_res(struct html *h, const char *p, int len) |
{ |
{ |
|
const char *rhs; |
|
int i; |
|
size_t sz; |
|
|
printf("%s", p); /* XXX */ |
rhs = chars_a2res(h->symtab, p, (size_t)len, &sz); |
|
|
|
if (NULL == rhs) |
|
return; |
|
for (i = 0; i < (int)sz; i++) |
|
putchar(rhs[i]); |
} |
} |
|
|
|
static void |
|
print_escape(struct html *h, const char **p) |
|
{ |
|
int j, type; |
|
const char *wp; |
|
|
|
wp = *p; |
|
type = 1; |
|
|
|
if (0 == *(++wp)) { |
|
*p = wp; |
|
return; |
|
} |
|
|
|
if ('(' == *wp) { |
|
wp++; |
|
if (0 == *wp || 0 == *(wp + 1)) { |
|
*p = 0 == *wp ? wp : wp + 1; |
|
return; |
|
} |
|
|
|
print_spec(h, wp, 2); |
|
*p = ++wp; |
|
return; |
|
|
|
} else if ('*' == *wp) { |
|
if (0 == *(++wp)) { |
|
*p = wp; |
|
return; |
|
} |
|
|
|
switch (*wp) { |
|
case ('('): |
|
wp++; |
|
if (0 == *wp || 0 == *(wp + 1)) { |
|
*p = 0 == *wp ? wp : wp + 1; |
|
return; |
|
} |
|
|
|
print_res(h, wp, 2); |
|
*p = ++wp; |
|
return; |
|
case ('['): |
|
type = 0; |
|
break; |
|
default: |
|
print_res(h, wp, 1); |
|
*p = wp; |
|
return; |
|
} |
|
|
|
} else if ('f' == *wp) { |
|
if (0 == *(++wp)) { |
|
*p = wp; |
|
return; |
|
} |
|
|
|
switch (*wp) { |
|
case ('B'): |
|
/* TODO */ |
|
break; |
|
case ('I'): |
|
/* TODO */ |
|
break; |
|
case ('P'): |
|
/* FALLTHROUGH */ |
|
case ('R'): |
|
/* TODO */ |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
*p = wp; |
|
return; |
|
|
|
} else if ('[' != *wp) { |
|
print_spec(h, wp, 1); |
|
*p = wp; |
|
return; |
|
} |
|
|
|
wp++; |
|
for (j = 0; *wp && ']' != *wp; wp++, j++) |
|
/* Loop... */ ; |
|
|
|
if (0 == *wp) { |
|
*p = wp; |
|
return; |
|
} |
|
|
|
if (type) |
|
print_spec(h, wp - j, j); |
|
else |
|
print_res(h, wp - j, j); |
|
|
|
*p = wp; |
|
} |
|
|
|
|
|
static void |
|
print_encode(struct html *h, const char *p) |
|
{ |
|
|
|
for (; *p; p++) { |
|
if ('\\' != *p) { |
|
putchar(*p); |
|
continue; |
|
} |
|
print_escape(h, &p); |
|
} |
|
} |
|
|
|
|
static struct tag * |
static struct tag * |
print_otag(struct html *h, enum htmltag tag, |
print_otag(struct html *h, enum htmltag tag, |
int sz, const struct htmlpair *p) |
int sz, const struct htmlpair *p) |
Line 515 print_otag(struct html *h, enum htmltag tag, |
|
Line 647 print_otag(struct html *h, enum htmltag tag, |
|
for (i = 0; i < sz; i++) { |
for (i = 0; i < sz; i++) { |
printf(" %s=\"", htmlattrs[p[i].key]); |
printf(" %s=\"", htmlattrs[p[i].key]); |
assert(p->val); |
assert(p->val); |
print_encode(p[i].val); |
print_encode(h, p[i].val); |
printf("\""); |
printf("\""); |
} |
} |
printf(">"); |
printf(">"); |
Line 590 print_text(struct html *h, const char *p) |
|
Line 722 print_text(struct html *h, const char *p) |
|
h->flags &= ~HTML_NEWLINE; |
h->flags &= ~HTML_NEWLINE; |
|
|
if (p) |
if (p) |
print_encode(p); |
print_encode(h, p); |
|
|
if (*p && 0 == *(p + 1)) |
if (*p && 0 == *(p + 1)) |
switch (*p) { |
switch (*p) { |