version 1.9, 2009/02/25 12:09:20 |
version 1.12, 2009/02/25 15:12:26 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> |
* |
* |
|
|
}; |
}; |
|
|
static void body(struct termp *, |
static void body(struct termp *, |
|
struct termpair *, |
const struct mdoc_meta *, |
const struct mdoc_meta *, |
const struct mdoc_node *); |
const struct mdoc_node *); |
static void header(struct termp *, |
static void header(struct termp *, |
Line 54 static void footer(struct termp *, |
|
Line 55 static void footer(struct termp *, |
|
static void pword(struct termp *, const char *, size_t); |
static void pword(struct termp *, const char *, size_t); |
static void pescape(struct termp *, |
static void pescape(struct termp *, |
const char *, size_t *, size_t); |
const char *, size_t *, size_t); |
|
static void nescape(struct termp *, |
|
const char *, size_t); |
static void chara(struct termp *, char); |
static void chara(struct termp *, char); |
static void stringa(struct termp *, const char *); |
static void stringa(struct termp *, const char *); |
static void style(struct termp *, enum termstyle); |
static void style(struct termp *, enum termstyle); |
Line 89 main(int argc, char *argv[]) |
|
Line 92 main(int argc, char *argv[]) |
|
err(1, "malloc"); |
err(1, "malloc"); |
|
|
header(&termp, mdoc_meta(mdoc)); |
header(&termp, mdoc_meta(mdoc)); |
body(&termp, mdoc_meta(mdoc), mdoc_node(mdoc)); |
body(&termp, NULL, mdoc_meta(mdoc), mdoc_node(mdoc)); |
footer(&termp, mdoc_meta(mdoc)); |
footer(&termp, mdoc_meta(mdoc)); |
|
|
free(termp.buf); |
free(termp.buf); |
Line 200 flushln(struct termp *p) |
|
Line 203 flushln(struct termp *p) |
|
*/ |
*/ |
|
|
if (p->flags & TERMP_NOBREAK) { |
if (p->flags & TERMP_NOBREAK) { |
for ( ; vis <= maxvis; vis++) |
for ( ; vis < maxvis; vis++) |
putchar(' '); |
putchar(' '); |
} else |
} else |
putchar('\n'); |
putchar('\n'); |
Line 218 newln(struct termp *p) |
|
Line 221 newln(struct termp *p) |
|
* vertical space. |
* vertical space. |
*/ |
*/ |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
if (0 == p->col) |
if (0 == p->col) { |
|
p->flags &= ~TERMP_NOLPAD; |
return; |
return; |
|
} |
flushln(p); |
flushln(p); |
|
p->flags &= ~TERMP_NOLPAD; |
} |
} |
|
|
|
|
Line 286 style(struct termp *p, enum termstyle esc) |
|
Line 292 style(struct termp *p, enum termstyle esc) |
|
|
|
|
|
static void |
static void |
|
nescape(struct termp *p, const char *word, size_t len) |
|
{ |
|
|
|
switch (len) { |
|
case (2): |
|
if ('r' == word[0] && 'B' == word[1]) |
|
chara(p, ']'); |
|
else if ('l' == word[0] && 'B' == word[1]) |
|
chara(p, '['); |
|
else if ('<' == word[0] && '-' == word[1]) |
|
stringa(p, "<-"); |
|
else if ('-' == word[0] && '>' == word[1]) |
|
stringa(p, "->"); |
|
else if ('l' == word[0] && 'q' == word[1]) |
|
chara(p, '\"'); |
|
else if ('r' == word[0] && 'q' == word[1]) |
|
chara(p, '\"'); |
|
else if ('b' == word[0] && 'u' == word[1]) |
|
chara(p, 'o'); |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
|
|
|
|
static void |
pescape(struct termp *p, const char *word, size_t *i, size_t len) |
pescape(struct termp *p, const char *word, size_t *i, size_t len) |
{ |
{ |
|
size_t j; |
|
|
(*i)++; |
(*i)++; |
assert(*i < len); |
assert(*i < len); |
Line 296 pescape(struct termp *p, const char *word, size_t *i, |
|
Line 330 pescape(struct termp *p, const char *word, size_t *i, |
|
/* Two-character escapes. */ |
/* Two-character escapes. */ |
(*i)++; |
(*i)++; |
assert(*i + 1 < len); |
assert(*i + 1 < len); |
|
nescape(p, &word[*i], 2); |
if ('r' == word[*i] && 'B' == word[*i + 1]) |
|
chara(p, ']'); |
|
else if ('l' == word[*i] && 'B' == word[*i + 1]) |
|
chara(p, '['); |
|
else if ('<' == word[*i] && '-' == word[*i + 1]) |
|
stringa(p, "<-"); |
|
else if ('-' == word[*i] && '>' == word[*i + 1]) |
|
stringa(p, "->"); |
|
else if ('l' == word[*i] && 'q' == word[*i + 1]) |
|
chara(p, '\"'); |
|
else if ('r' == word[*i] && 'q' == word[*i + 1]) |
|
chara(p, '\"'); |
|
|
|
(*i)++; |
(*i)++; |
return; |
return; |
|
|
Line 331 pescape(struct termp *p, const char *word, size_t *i, |
|
Line 352 pescape(struct termp *p, const char *word, size_t *i, |
|
} |
} |
return; |
return; |
} |
} |
/* n-character escapes. */ |
|
|
(*i)++; |
|
for (j = 0; word[*i] && ']' != word[*i]; (*i)++, j++) |
|
/* Loop... */ ; |
|
|
|
nescape(p, &word[*i - j], j); |
} |
} |
|
|
|
|
Line 406 word(struct termp *p, const char *word) |
|
Line 432 word(struct termp *p, const char *word) |
|
|
|
|
|
static void |
static void |
body(struct termp *p, const struct mdoc_meta *meta, |
body(struct termp *p, struct termpair *ppair, |
|
const struct mdoc_meta *meta, |
const struct mdoc_node *node) |
const struct mdoc_node *node) |
{ |
{ |
int dochild; |
int dochild; |
Line 415 body(struct termp *p, const struct mdoc_meta *meta, |
|
Line 442 body(struct termp *p, const struct mdoc_meta *meta, |
|
/* Pre-processing. */ |
/* Pre-processing. */ |
|
|
dochild = 1; |
dochild = 1; |
|
pair.ppair = ppair; |
pair.type = 0; |
pair.type = 0; |
|
pair.offset = pair.rmargin = 0; |
|
pair.flag = 0; |
|
pair.count = 0; |
|
|
if (MDOC_TEXT != node->type) { |
if (MDOC_TEXT != node->type) { |
if (termacts[node->tok].pre) |
if (termacts[node->tok].pre) |
Line 426 body(struct termp *p, const struct mdoc_meta *meta, |
|
Line 457 body(struct termp *p, const struct mdoc_meta *meta, |
|
|
|
/* Children. */ |
/* Children. */ |
|
|
switch (pair.type) { |
if (TERMPAIR_FLAG & pair.type) |
case (TERMPAIR_FLAG): |
p->flags |= pair.flag; |
p->flags |= pair.data.flag; |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
if (dochild && node->child) |
if (dochild && node->child) |
body(p, meta, node->child); |
body(p, &pair, meta, node->child); |
|
|
switch (pair.type) { |
if (TERMPAIR_FLAG & pair.type) |
case (TERMPAIR_FLAG): |
p->flags &= ~pair.flag; |
p->flags &= ~pair.data.flag; |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
/* Post-processing. */ |
/* Post-processing. */ |
|
|
Line 454 body(struct termp *p, const struct mdoc_meta *meta, |
|
Line 475 body(struct termp *p, const struct mdoc_meta *meta, |
|
/* Siblings. */ |
/* Siblings. */ |
|
|
if (node->next) |
if (node->next) |
body(p, meta, node->next); |
body(p, ppair, meta, node->next); |
} |
} |
|
|
|
|