version 1.96, 2009/07/27 13:10:08 |
version 1.100, 2009/09/16 15:08:31 |
|
|
#include "man.h" |
#include "man.h" |
#include "mdoc.h" |
#include "mdoc.h" |
|
|
extern int man_run(struct termp *, |
extern void man_run(struct termp *, |
const struct man *); |
const struct man *); |
extern int mdoc_run(struct termp *, |
extern void mdoc_run(struct termp *, |
const struct mdoc *); |
const struct mdoc *); |
|
|
static struct termp *term_alloc(enum termenc); |
static struct termp *term_alloc(enum termenc); |
Line 39 static void do_reserved(struct termp *, |
|
Line 39 static void do_reserved(struct termp *, |
|
const char *, size_t); |
const char *, size_t); |
static void buffer(struct termp *, char); |
static void buffer(struct termp *, char); |
static void encode(struct termp *, char); |
static void encode(struct termp *, char); |
static int isopendelim(const char *); |
|
static int isclosedelim(const char *); |
|
|
|
|
|
void * |
void * |
Line 51 ascii_alloc(void) |
|
Line 49 ascii_alloc(void) |
|
} |
} |
|
|
|
|
int |
void |
terminal_man(void *arg, const struct man *man) |
terminal_man(void *arg, const struct man *man) |
{ |
{ |
struct termp *p; |
struct termp *p; |
Line 60 terminal_man(void *arg, const struct man *man) |
|
Line 58 terminal_man(void *arg, const struct man *man) |
|
if (NULL == p->symtab) |
if (NULL == p->symtab) |
p->symtab = term_ascii2htab(); |
p->symtab = term_ascii2htab(); |
|
|
return(man_run(p, man)); |
man_run(p, man); |
} |
} |
|
|
|
|
int |
void |
terminal_mdoc(void *arg, const struct mdoc *mdoc) |
terminal_mdoc(void *arg, const struct mdoc *mdoc) |
{ |
{ |
struct termp *p; |
struct termp *p; |
Line 73 terminal_mdoc(void *arg, const struct mdoc *mdoc) |
|
Line 71 terminal_mdoc(void *arg, const struct mdoc *mdoc) |
|
if (NULL == p->symtab) |
if (NULL == p->symtab) |
p->symtab = term_ascii2htab(); |
p->symtab = term_ascii2htab(); |
|
|
return(mdoc_run(p, mdoc)); |
mdoc_run(p, mdoc); |
} |
} |
|
|
|
|
Line 104 term_alloc(enum termenc enc) |
|
Line 102 term_alloc(enum termenc enc) |
|
struct termp *p; |
struct termp *p; |
|
|
if (NULL == (p = malloc(sizeof(struct termp)))) |
if (NULL == (p = malloc(sizeof(struct termp)))) |
err(1, "malloc"); |
return(NULL); |
bzero(p, sizeof(struct termp)); |
bzero(p, sizeof(struct termp)); |
p->maxrmargin = 78; |
p->maxrmargin = 78; |
p->enc = enc; |
p->enc = enc; |
Line 112 term_alloc(enum termenc enc) |
|
Line 110 term_alloc(enum termenc enc) |
|
} |
} |
|
|
|
|
static int |
|
isclosedelim(const char *p) |
|
{ |
|
|
|
if ( ! (*p && 0 == *(p + 1))) |
|
return(0); |
|
|
|
switch (*p) { |
|
case('.'): |
|
/* FALLTHROUGH */ |
|
case(','): |
|
/* FALLTHROUGH */ |
|
case(';'): |
|
/* FALLTHROUGH */ |
|
case(':'): |
|
/* FALLTHROUGH */ |
|
case('?'): |
|
/* FALLTHROUGH */ |
|
case('!'): |
|
/* FALLTHROUGH */ |
|
case(')'): |
|
/* FALLTHROUGH */ |
|
case(']'): |
|
/* FALLTHROUGH */ |
|
case('}'): |
|
return(1); |
|
default: |
|
break; |
|
} |
|
|
|
return(0); |
|
} |
|
|
|
|
|
static int |
|
isopendelim(const char *p) |
|
{ |
|
|
|
if ( ! (*p && 0 == *(p + 1))) |
|
return(0); |
|
|
|
switch (*p) { |
|
case('('): |
|
/* FALLTHROUGH */ |
|
case('['): |
|
/* FALLTHROUGH */ |
|
case('{'): |
|
return(1); |
|
default: |
|
break; |
|
} |
|
|
|
return(0); |
|
} |
|
|
|
|
|
/* |
/* |
* Flush a line of text. A "line" is loosely defined as being something |
* Flush a line of text. A "line" is loosely defined as being something |
* that should be followed by a newline, regardless of whether it's |
* that should be followed by a newline, regardless of whether it's |
Line 392 do_special(struct termp *p, const char *word, size_t l |
|
Line 334 do_special(struct termp *p, const char *word, size_t l |
|
rhs = term_a2ascii(p->symtab, word, len, &sz); |
rhs = term_a2ascii(p->symtab, word, len, &sz); |
|
|
if (NULL == rhs) { |
if (NULL == rhs) { |
#if 1 |
#if 0 |
fputs("Unknown special character: ", stderr); |
fputs("Unknown special character: ", stderr); |
for (i = 0; i < (int)len; i++) |
for (i = 0; i < (int)len; i++) |
fputc(word[i], stderr); |
fputc(word[i], stderr); |
Line 436 do_reserved(struct termp *p, const char *word, size_t |
|
Line 378 do_reserved(struct termp *p, const char *word, size_t |
|
static void |
static void |
do_escaped(struct termp *p, const char **word) |
do_escaped(struct termp *p, const char **word) |
{ |
{ |
int j; |
int j, type; |
const char *wp; |
const char *wp; |
|
|
wp = *word; |
wp = *word; |
|
type = 1; |
|
|
if (0 == *(++wp)) { |
if (0 == *(++wp)) { |
*word = wp; |
*word = wp; |
Line 475 do_escaped(struct termp *p, const char **word) |
|
Line 418 do_escaped(struct termp *p, const char **word) |
|
*word = ++wp; |
*word = ++wp; |
return; |
return; |
case ('['): |
case ('['): |
|
type = 0; |
break; |
break; |
default: |
default: |
do_reserved(p, wp, 1); |
do_reserved(p, wp, 1); |
Line 490 do_escaped(struct termp *p, const char **word) |
|
Line 434 do_escaped(struct termp *p, const char **word) |
|
|
|
switch (*wp) { |
switch (*wp) { |
case ('B'): |
case ('B'): |
p->flags |= TERMP_BOLD; |
p->bold++; |
break; |
break; |
case ('I'): |
case ('I'): |
p->flags |= TERMP_UNDER; |
p->under++; |
break; |
break; |
case ('P'): |
case ('P'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('R'): |
case ('R'): |
p->flags &= ~TERMP_STYLE; |
p->bold = p->under = 0; |
break; |
break; |
default: |
default: |
break; |
break; |
Line 522 do_escaped(struct termp *p, const char **word) |
|
Line 466 do_escaped(struct termp *p, const char **word) |
|
return; |
return; |
} |
} |
|
|
do_special(p, wp - j, (size_t)j); |
if (type) |
|
do_special(p, wp - j, (size_t)j); |
|
else |
|
do_reserved(p, wp - j, (size_t)j); |
*word = wp; |
*word = wp; |
} |
} |
|
|
Line 537 term_word(struct termp *p, const char *word) |
|
Line 484 term_word(struct termp *p, const char *word) |
|
{ |
{ |
const char *sv; |
const char *sv; |
|
|
if (isclosedelim(word)) |
sv = word; |
if ( ! (TERMP_IGNDELIM & p->flags)) |
|
p->flags |= TERMP_NOSPACE; |
|
|
|
|
if (word[0] && 0 == word[1]) |
|
switch (word[0]) { |
|
case('.'): |
|
/* FALLTHROUGH */ |
|
case(','): |
|
/* FALLTHROUGH */ |
|
case(';'): |
|
/* FALLTHROUGH */ |
|
case(':'): |
|
/* FALLTHROUGH */ |
|
case('?'): |
|
/* FALLTHROUGH */ |
|
case('!'): |
|
/* FALLTHROUGH */ |
|
case(')'): |
|
/* FALLTHROUGH */ |
|
case(']'): |
|
/* FALLTHROUGH */ |
|
case('}'): |
|
if ( ! (TERMP_IGNDELIM & p->flags)) |
|
p->flags |= TERMP_NOSPACE; |
|
break; |
|
default: |
|
break; |
|
} |
|
|
if ( ! (TERMP_NOSPACE & p->flags)) |
if ( ! (TERMP_NOSPACE & p->flags)) |
buffer(p, ' '); |
buffer(p, ' '); |
|
|
if ( ! (p->flags & TERMP_NONOSPACE)) |
if ( ! (p->flags & TERMP_NONOSPACE)) |
p->flags &= ~TERMP_NOSPACE; |
p->flags &= ~TERMP_NOSPACE; |
|
|
for (sv = word; *word; word++) |
for ( ; *word; word++) |
if ('\\' != *word) |
if ('\\' != *word) |
encode(p, *word); |
encode(p, *word); |
else |
else |
do_escaped(p, &word); |
do_escaped(p, &word); |
|
|
if (isopendelim(sv)) |
if (sv[0] && 0 == sv[1]) |
p->flags |= TERMP_NOSPACE; |
switch (sv[0]) { |
|
case('('): |
|
/* FALLTHROUGH */ |
|
case('['): |
|
/* FALLTHROUGH */ |
|
case('{'): |
|
p->flags |= TERMP_NOSPACE; |
|
break; |
|
default: |
|
break; |
|
} |
} |
} |
|
|
|
|
Line 574 buffer(struct termp *p, char c) |
|
Line 555 buffer(struct termp *p, char c) |
|
s = p->maxcols * 2; |
s = p->maxcols * 2; |
p->buf = realloc(p->buf, s); |
p->buf = realloc(p->buf, s); |
if (NULL == p->buf) |
if (NULL == p->buf) |
err(1, "realloc"); |
err(1, "realloc"); /* FIXME: shouldn't be here! */ |
p->maxcols = s; |
p->maxcols = s; |
} |
} |
p->buf[(int)(p->col)++] = c; |
p->buf[(int)(p->col)++] = c; |
|
|
encode(struct termp *p, char c) |
encode(struct termp *p, char c) |
{ |
{ |
|
|
if (' ' != c && TERMP_STYLE & p->flags) { |
if (' ' != c) { |
if (TERMP_BOLD & p->flags) { |
if (p->bold) { |
buffer(p, c); |
buffer(p, c); |
buffer(p, 8); |
buffer(p, 8); |
} |
} |
if (TERMP_UNDER & p->flags) { |
if (p->under) { |
buffer(p, '_'); |
buffer(p, '_'); |
buffer(p, 8); |
buffer(p, 8); |
} |
} |