version 1.182, 2011/03/22 14:05:45 |
version 1.187, 2011/05/14 17:54:42 |
|
|
#include "term.h" |
#include "term.h" |
#include "main.h" |
#include "main.h" |
|
|
static void spec(struct termp *, enum roffdeco, |
static void spec(struct termp *, const char *, size_t); |
const char *, size_t); |
|
static void res(struct termp *, const char *, size_t); |
static void res(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); |
Line 48 term_free(struct termp *p) |
|
Line 47 term_free(struct termp *p) |
|
if (p->buf) |
if (p->buf) |
free(p->buf); |
free(p->buf); |
if (p->symtab) |
if (p->symtab) |
chars_free(p->symtab); |
mchars_free(p->symtab); |
|
|
free(p); |
free(p); |
} |
} |
Line 349 term_vspace(struct termp *p) |
|
Line 348 term_vspace(struct termp *p) |
|
static void |
static void |
numbered(struct termp *p, const char *word, size_t len) |
numbered(struct termp *p, const char *word, size_t len) |
{ |
{ |
const char *rhs; |
char c; |
|
|
rhs = chars_num2char(word, len); |
if ('\0' != (c = mchars_num2char(word, len))) |
if (rhs) |
encode(p, &c, 1); |
encode(p, rhs, 1); |
|
} |
} |
|
|
|
|
static void |
static void |
spec(struct termp *p, enum roffdeco d, const char *word, size_t len) |
spec(struct termp *p, const char *word, size_t len) |
{ |
{ |
const char *rhs; |
const char *rhs; |
size_t sz; |
size_t sz; |
|
|
rhs = chars_spec2str(p->symtab, word, len, &sz); |
rhs = mchars_spec2str(p->symtab, word, len, &sz); |
if (rhs) |
if (rhs) |
encode(p, rhs, sz); |
encode(p, rhs, sz); |
else if (DECO_SSPECIAL == d) |
else if (1 == len) |
encode(p, word, len); |
encode(p, word, len); |
} |
} |
|
|
Line 377 res(struct termp *p, const char *word, size_t len) |
|
Line 375 res(struct termp *p, const char *word, size_t len) |
|
const char *rhs; |
const char *rhs; |
size_t sz; |
size_t sz; |
|
|
rhs = chars_res2str(p->symtab, word, len, &sz); |
rhs = mchars_res2str(p->symtab, word, len, &sz); |
if (rhs) |
if (rhs) |
encode(p, rhs, sz); |
encode(p, rhs, sz); |
} |
} |
Line 456 term_fontpop(struct termp *p) |
|
Line 454 term_fontpop(struct termp *p) |
|
void |
void |
term_word(struct termp *p, const char *word) |
term_word(struct termp *p, const char *word) |
{ |
{ |
const char *sv, *seq; |
const char *seq; |
|
int sz; |
size_t ssz; |
size_t ssz; |
enum roffdeco deco; |
enum mandoc_esc esc; |
|
|
sv = word; |
|
|
|
if ( ! (TERMP_NOSPACE & p->flags)) { |
if ( ! (TERMP_NOSPACE & p->flags)) { |
if ( ! (TERMP_KEEP & p->flags)) { |
if ( ! (TERMP_KEEP & p->flags)) { |
if (TERMP_PREKEEP & p->flags) |
if (TERMP_PREKEEP & p->flags) |
Line 480 term_word(struct termp *p, const char *word) |
|
Line 477 term_word(struct termp *p, const char *word) |
|
|
|
p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM); |
p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM); |
|
|
while (*word) { |
while ('\0' != *word) { |
if ((ssz = strcspn(word, "\\")) > 0) |
if ((ssz = strcspn(word, "\\")) > 0) |
encode(p, word, ssz); |
encode(p, word, ssz); |
|
|
Line 488 term_word(struct termp *p, const char *word) |
|
Line 485 term_word(struct termp *p, const char *word) |
|
if ('\\' != *word) |
if ('\\' != *word) |
continue; |
continue; |
|
|
seq = ++word; |
word++; |
word += a2roffdeco(&deco, &seq, &ssz); |
esc = mandoc_escape(&word, &seq, &sz); |
|
if (ESCAPE_ERROR == esc) |
|
break; |
|
|
switch (deco) { |
switch (esc) { |
case (DECO_NUMBERED): |
case (ESCAPE_NUMBERED): |
numbered(p, seq, ssz); |
numbered(p, seq, sz); |
break; |
break; |
case (DECO_RESERVED): |
case (ESCAPE_PREDEF): |
res(p, seq, ssz); |
res(p, seq, sz); |
break; |
break; |
case (DECO_SPECIAL): |
case (ESCAPE_SPECIAL): |
/* FALLTHROUGH */ |
spec(p, seq, sz); |
case (DECO_SSPECIAL): |
|
spec(p, deco, seq, ssz); |
|
break; |
break; |
case (DECO_BOLD): |
case (ESCAPE_FONTBOLD): |
term_fontrepl(p, TERMFONT_BOLD); |
term_fontrepl(p, TERMFONT_BOLD); |
break; |
break; |
case (DECO_ITALIC): |
case (ESCAPE_FONTITALIC): |
term_fontrepl(p, TERMFONT_UNDER); |
term_fontrepl(p, TERMFONT_UNDER); |
break; |
break; |
case (DECO_ROMAN): |
case (ESCAPE_FONTROMAN): |
term_fontrepl(p, TERMFONT_NONE); |
term_fontrepl(p, TERMFONT_NONE); |
break; |
break; |
case (DECO_PREVIOUS): |
case (ESCAPE_FONTPREV): |
term_fontlast(p); |
term_fontlast(p); |
break; |
break; |
|
case (ESCAPE_NOSPACE): |
|
if ('\0' == *word) |
|
p->flags |= TERMP_NOSPACE; |
|
break; |
default: |
default: |
break; |
break; |
} |
} |
|
|
if (DECO_NOSPACE == deco && '\0' == *word) |
|
p->flags |= TERMP_NOSPACE; |
|
} |
} |
} |
} |
|
|
Line 534 adjbuf(struct termp *p, size_t sz) |
|
Line 532 adjbuf(struct termp *p, size_t sz) |
|
while (sz >= p->maxcols) |
while (sz >= p->maxcols) |
p->maxcols <<= 2; |
p->maxcols <<= 2; |
|
|
p->buf = mandoc_realloc(p->buf, p->maxcols); |
p->buf = mandoc_realloc(p->buf, sizeof(int) * p->maxcols); |
} |
} |
|
|
|
|
Line 564 encode(struct termp *p, const char *word, size_t sz) |
|
Line 562 encode(struct termp *p, const char *word, size_t sz) |
|
if (TERMFONT_NONE == (f = term_fonttop(p))) { |
if (TERMFONT_NONE == (f = term_fonttop(p))) { |
if (p->col + sz >= p->maxcols) |
if (p->col + sz >= p->maxcols) |
adjbuf(p, p->col + sz); |
adjbuf(p, p->col + sz); |
memcpy(&p->buf[(int)p->col], word, sz); |
for (i = 0; i < (int)sz; i++) |
p->col += sz; |
p->buf[(int)p->col++] = word[i]; |
return; |
return; |
} |
} |
|
|
Line 602 term_len(const struct termp *p, size_t sz) |
|
Line 600 term_len(const struct termp *p, size_t sz) |
|
size_t |
size_t |
term_strlen(const struct termp *p, const char *cp) |
term_strlen(const struct termp *p, const char *cp) |
{ |
{ |
size_t sz, ssz, rsz, i; |
size_t sz, rsz, i; |
enum roffdeco d; |
int ssz; |
|
enum mandoc_esc esc; |
const char *seq, *rhs; |
const char *seq, *rhs; |
|
|
for (sz = 0; '\0' != *cp; ) |
/* |
/* |
* Account for escaped sequences within string length |
* Account for escaped sequences within string length |
* calculations. This follows the logic in term_word() as we |
* calculations. This follows the logic in term_word() |
* must calculate the width of produced strings. |
* as we must calculate the width of produced strings. |
*/ |
*/ |
|
if ('\\' == *cp) { |
|
seq = ++cp; |
|
cp += a2roffdeco(&d, &seq, &ssz); |
|
|
|
switch (d) { |
sz = 0; |
case (DECO_RESERVED): |
while ('\0' != *cp) |
rhs = chars_res2str |
switch (*cp) { |
|
case ('\\'): |
|
++cp; |
|
esc = mandoc_escape(&cp, &seq, &ssz); |
|
if (ESCAPE_ERROR == esc) |
|
return(sz); |
|
|
|
switch (esc) { |
|
case (ESCAPE_PREDEF): |
|
rhs = mchars_res2str |
(p->symtab, seq, ssz, &rsz); |
(p->symtab, seq, ssz, &rsz); |
break; |
break; |
case (DECO_SPECIAL): |
case (ESCAPE_SPECIAL): |
/* FALLTHROUGH */ |
rhs = mchars_spec2str |
case (DECO_SSPECIAL): |
|
rhs = chars_spec2str |
|
(p->symtab, seq, ssz, &rsz); |
(p->symtab, seq, ssz, &rsz); |
|
|
/* Allow for one-char escapes. */ |
if (ssz != 1 || rhs) |
if (DECO_SSPECIAL != d || rhs) |
|
break; |
break; |
|
|
rhs = seq; |
rhs = seq; |
Line 639 term_strlen(const struct termp *p, const char *cp) |
|
Line 640 term_strlen(const struct termp *p, const char *cp) |
|
break; |
break; |
} |
} |
|
|
if (rhs) |
if (NULL == rhs) |
for (i = 0; i < rsz; i++) |
break; |
sz += (*p->width)(p, *rhs++); |
|
} else if (ASCII_NBRSP == *cp) { |
for (i = 0; i < rsz; i++) |
|
sz += (*p->width)(p, *rhs++); |
|
break; |
|
case (ASCII_NBRSP): |
sz += (*p->width)(p, ' '); |
sz += (*p->width)(p, ' '); |
cp++; |
cp++; |
} else if (ASCII_HYPH == *cp) { |
break; |
|
case (ASCII_HYPH): |
sz += (*p->width)(p, '-'); |
sz += (*p->width)(p, '-'); |
cp++; |
cp++; |
} else |
break; |
|
default: |
sz += (*p->width)(p, *cp++); |
sz += (*p->width)(p, *cp++); |
|
break; |
|
} |
|
|
return(sz); |
return(sz); |
} |
} |