version 1.159, 2010/07/04 22:04:04 |
version 1.165, 2010/07/26 21:58:41 |
|
|
#include "mandoc.h" |
#include "mandoc.h" |
#include "chars.h" |
#include "chars.h" |
#include "out.h" |
#include "out.h" |
#include "regs.h" |
|
#include "term.h" |
#include "term.h" |
#include "main.h" |
#include "main.h" |
|
|
static void spec(struct termp *, const char *, size_t); |
static void spec(struct termp *, enum roffdeco, |
|
const char *, size_t); |
static void res(struct termp *, const char *, size_t); |
static void res(struct termp *, const char *, size_t); |
static void buffera(struct termp *, const char *, size_t); |
|
static void bufferc(struct termp *, char); |
static void bufferc(struct termp *, char); |
static void adjbuf(struct termp *p, size_t); |
static void adjbuf(struct termp *p, size_t); |
static void encode(struct termp *, const char *, size_t); |
static void encode(struct termp *, const char *, size_t); |
Line 242 term_flushln(struct termp *p) |
|
Line 241 term_flushln(struct termp *p) |
|
if ('\t' == p->buf[i]) |
if ('\t' == p->buf[i]) |
break; |
break; |
if (' ' == p->buf[i]) { |
if (' ' == p->buf[i]) { |
while (' ' == p->buf[i]) { |
j = i; |
vbl += (*p->width)(p, p->buf[i]); |
while (' ' == p->buf[i]) |
i++; |
i++; |
} |
vbl += (i - j) * (*p->width)(p, ' '); |
break; |
break; |
} |
} |
if (ASCII_NBRSP == p->buf[i]) { |
if (ASCII_NBRSP == p->buf[i]) { |
Line 361 term_vspace(struct termp *p) |
|
Line 360 term_vspace(struct termp *p) |
|
|
|
|
|
static void |
static void |
spec(struct termp *p, const char *word, size_t len) |
spec(struct termp *p, enum roffdeco d, const char *word, size_t len) |
{ |
{ |
const char *rhs; |
const char *rhs; |
size_t sz; |
size_t sz; |
|
|
rhs = chars_a2ascii(p->symtab, word, len, &sz); |
rhs = chars_spec2str(p->symtab, word, len, &sz); |
if (rhs) |
if (rhs) |
encode(p, rhs, sz); |
encode(p, rhs, sz); |
|
else if (DECO_SSPECIAL == d) |
|
encode(p, word, len); |
} |
} |
|
|
|
|
Line 378 res(struct termp *p, const char *word, size_t len) |
|
Line 379 res(struct termp *p, const char *word, size_t len) |
|
const char *rhs; |
const char *rhs; |
size_t sz; |
size_t sz; |
|
|
rhs = chars_a2res(p->symtab, word, len, &sz); |
rhs = chars_res2str(p->symtab, word, len, &sz); |
if (NULL == rhs) { |
|
rhs = roff_getstrn(word, len); |
|
if (rhs) |
|
sz = strlen(rhs); |
|
} |
|
if (rhs) |
if (rhs) |
encode(p, rhs, sz); |
encode(p, rhs, sz); |
} |
} |
Line 509 term_word(struct termp *p, const char *word) |
|
Line 505 term_word(struct termp *p, const char *word) |
|
|
|
p->flags &= ~TERMP_SENTENCE; |
p->flags &= ~TERMP_SENTENCE; |
|
|
/* FIXME: use strcspn. */ |
|
|
|
while (*word) { |
while (*word) { |
if ('\\' != *word) { |
if ((ssz = strcspn(word, "\\")) > 0) |
encode(p, word, 1); |
encode(p, word, ssz); |
word++; |
|
|
word += ssz; |
|
if ('\\' != *word) |
continue; |
continue; |
} |
|
|
|
seq = ++word; |
seq = ++word; |
sz = a2roffdeco(&deco, &seq, &ssz); |
sz = a2roffdeco(&deco, &seq, &ssz); |
Line 526 term_word(struct termp *p, const char *word) |
|
Line 521 term_word(struct termp *p, const char *word) |
|
res(p, seq, ssz); |
res(p, seq, ssz); |
break; |
break; |
case (DECO_SPECIAL): |
case (DECO_SPECIAL): |
spec(p, seq, ssz); |
/* FALLTHROUGH */ |
|
case (DECO_SSPECIAL): |
|
spec(p, deco, seq, ssz); |
break; |
break; |
case (DECO_BOLD): |
case (DECO_BOLD): |
term_fontrepl(p, TERMFONT_BOLD); |
term_fontrepl(p, TERMFONT_BOLD); |
Line 553 term_word(struct termp *p, const char *word) |
|
Line 550 term_word(struct termp *p, const char *word) |
|
* Note that we don't process the pipe: the parser sees it as |
* Note that we don't process the pipe: the parser sees it as |
* punctuation, but we don't in terms of typography. |
* punctuation, but we don't in terms of typography. |
*/ |
*/ |
if (sv[0] && 0 == sv[1]) |
if (sv[0] && '\0' == sv[1]) |
switch (sv[0]) { |
switch (sv[0]) { |
case('('): |
case('('): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
Line 584 adjbuf(struct termp *p, size_t sz) |
|
Line 581 adjbuf(struct termp *p, size_t sz) |
|
|
|
|
|
static void |
static void |
buffera(struct termp *p, const char *word, size_t sz) |
|
{ |
|
|
|
if (p->col + sz >= p->maxcols) |
|
adjbuf(p, p->col + sz); |
|
|
|
memcpy(&p->buf[(int)p->col], word, sz); |
|
p->col += sz; |
|
} |
|
|
|
|
|
static void |
|
bufferc(struct termp *p, char c) |
bufferc(struct termp *p, char c) |
{ |
{ |
|
|
Line 619 encode(struct termp *p, const char *word, size_t sz) |
|
Line 604 encode(struct termp *p, const char *word, size_t sz) |
|
*/ |
*/ |
|
|
if (TERMFONT_NONE == (f = term_fonttop(p))) { |
if (TERMFONT_NONE == (f = term_fonttop(p))) { |
buffera(p, word, sz); |
if (p->col + sz >= p->maxcols) |
|
adjbuf(p, p->col + sz); |
|
memcpy(&p->buf[(int)p->col], word, sz); |
|
p->col += sz; |
return; |
return; |
} |
} |
|
|
|
/* Pre-buffer, assuming worst-case. */ |
|
|
|
if (p->col + 1 + (sz * 3) >= p->maxcols) |
|
adjbuf(p, p->col + 1 + (sz * 3)); |
|
|
for (i = 0; i < (int)sz; i++) { |
for (i = 0; i < (int)sz; i++) { |
if ( ! isgraph((u_char)word[i])) { |
if ( ! isgraph((u_char)word[i])) { |
bufferc(p, word[i]); |
p->buf[(int)p->col++] = word[i]; |
continue; |
continue; |
} |
} |
|
|
if (TERMFONT_UNDER == f) |
if (TERMFONT_UNDER == f) |
bufferc(p, '_'); |
p->buf[(int)p->col++] = '_'; |
else |
else |
bufferc(p, word[i]); |
p->buf[(int)p->col++] = word[i]; |
|
|
bufferc(p, 8); |
p->buf[(int)p->col++] = 8; |
bufferc(p, word[i]); |
p->buf[(int)p->col++] = word[i]; |
} |
} |
} |
} |
|
|