version 1.140, 2010/05/25 12:37:20 |
version 1.147, 2010/06/11 07:23:04 |
|
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
|
#include <stdint.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <time.h> |
|
|
|
#include "mandoc.h" |
#include "mandoc.h" |
#include "chars.h" |
#include "chars.h" |
|
|
#include "mdoc.h" |
#include "mdoc.h" |
#include "main.h" |
#include "main.h" |
|
|
static struct termp *term_alloc(enum termenc, size_t); |
|
static void term_free(struct termp *); |
|
static void spec(struct termp *, const char *, size_t); |
static void spec(struct termp *, 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 buffera(struct termp *, const char *, size_t); |
Line 45 static void adjbuf(struct termp *p, size_t); |
|
Line 43 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); |
|
|
|
|
void * |
void |
ascii_alloc(size_t width) |
term_free(struct termp *p) |
{ |
{ |
|
|
return(term_alloc(TERMENC_ASCII, width)); |
if (p->buf) |
|
free(p->buf); |
|
if (p->symtab) |
|
chars_free(p->symtab); |
|
|
|
free(p); |
} |
} |
|
|
|
|
void |
void |
terminal_free(void *arg) |
term_begin(struct termp *p, term_margin head, |
|
term_margin foot, const void *arg) |
{ |
{ |
|
|
term_free((struct termp *)arg); |
p->headf = head; |
|
p->footf = foot; |
|
p->argf = arg; |
|
(*p->begin)(p); |
} |
} |
|
|
|
|
static void |
void |
term_free(struct termp *p) |
term_end(struct termp *p) |
{ |
{ |
|
|
if (p->buf) |
(*p->end)(p); |
free(p->buf); |
|
if (p->symtab) |
|
chars_free(p->symtab); |
|
|
|
free(p); |
|
} |
} |
|
|
|
|
static struct termp * |
struct termp * |
term_alloc(enum termenc enc, size_t width) |
term_alloc(enum termenc enc) |
{ |
{ |
struct termp *p; |
struct termp *p; |
|
|
p = calloc(1, sizeof(struct termp)); |
p = calloc(1, sizeof(struct termp)); |
if (NULL == p) { |
if (NULL == p) { |
perror(NULL); |
perror(NULL); |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
} |
} |
|
|
p->tabwidth = 5; |
p->tabwidth = 5; |
p->enc = enc; |
p->enc = enc; |
/* Enforce some lower boundary. */ |
p->defrmargin = 78; |
if (width < 60) |
|
width = 60; |
|
p->defrmargin = width - 2; |
|
return(p); |
return(p); |
} |
} |
|
|
Line 209 term_flushln(struct termp *p) |
|
Line 209 term_flushln(struct termp *p) |
|
*/ |
*/ |
if (vend > bp && 0 == jhy && vis > 0) { |
if (vend > bp && 0 == jhy && vis > 0) { |
vend -= vis; |
vend -= vis; |
putchar('\n'); |
(*p->endline)(p); |
if (TERMP_NOBREAK & p->flags) { |
if (TERMP_NOBREAK & p->flags) { |
p->viscol = p->rmargin; |
p->viscol = p->rmargin; |
for (j = 0; j < (int)p->rmargin; j++) |
(*p->advance)(p, p->rmargin); |
putchar(' '); |
|
vend += p->rmargin - p->offset; |
vend += p->rmargin - p->offset; |
} else { |
} else { |
p->viscol = 0; |
p->viscol = 0; |
Line 257 term_flushln(struct termp *p) |
|
Line 256 term_flushln(struct termp *p) |
|
* so write preceding white space now. |
* so write preceding white space now. |
*/ |
*/ |
if (vbl) { |
if (vbl) { |
for (j = 0; j < (int)vbl; j++) |
(*p->advance)(p, vbl); |
putchar(' '); |
|
p->viscol += vbl; |
p->viscol += vbl; |
vbl = 0; |
vbl = 0; |
} |
} |
|
|
if (ASCII_HYPH == p->buf[i]) |
if (ASCII_HYPH == p->buf[i]) |
putchar('-'); |
(*p->letter)(p, '-'); |
else |
else |
putchar(p->buf[i]); |
(*p->letter)(p, p->buf[i]); |
|
|
p->viscol += 1; |
p->viscol += 1; |
} |
} |
Line 279 term_flushln(struct termp *p) |
|
Line 277 term_flushln(struct termp *p) |
|
|
|
if ( ! (TERMP_NOBREAK & p->flags)) { |
if ( ! (TERMP_NOBREAK & p->flags)) { |
p->viscol = 0; |
p->viscol = 0; |
putchar('\n'); |
(*p->endline)(p); |
return; |
return; |
} |
} |
|
|
Line 312 term_flushln(struct termp *p) |
|
Line 310 term_flushln(struct termp *p) |
|
if (maxvis > vis + /* LINTED */ |
if (maxvis > vis + /* LINTED */ |
((TERMP_TWOSPACE & p->flags) ? 1 : 0)) { |
((TERMP_TWOSPACE & p->flags) ? 1 : 0)) { |
p->viscol += maxvis - vis; |
p->viscol += maxvis - vis; |
for ( ; vis < maxvis; vis++) |
(*p->advance)(p, maxvis - vis); |
putchar(' '); |
vis += (maxvis - vis); |
} else { /* ...or newline break. */ |
} else { /* ...or newline break. */ |
putchar('\n'); |
(*p->endline)(p); |
p->viscol = p->rmargin; |
p->viscol = p->rmargin; |
for (i = 0; i < (int)p->rmargin; i++) |
(*p->advance)(p, p->rmargin); |
putchar(' '); |
|
} |
} |
} |
} |
|
|
Line 354 term_vspace(struct termp *p) |
|
Line 351 term_vspace(struct termp *p) |
|
|
|
term_newln(p); |
term_newln(p); |
p->viscol = 0; |
p->viscol = 0; |
putchar('\n'); |
(*p->endline)(p); |
} |
} |
|
|
|
|