version 1.141, 2010/06/07 10:52:44 |
version 1.147, 2010/06/11 07:23:04 |
|
|
#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(char *, enum termenc); |
|
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 46 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(char *outopts) |
term_free(struct termp *p) |
{ |
{ |
|
|
return(term_alloc(outopts, TERMENC_ASCII)); |
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(char *outopts, enum termenc enc) |
term_alloc(enum termenc enc) |
{ |
{ |
struct termp *p; |
struct termp *p; |
const char *toks[2]; |
|
char *v; |
|
size_t width; |
|
|
|
toks[0] = "width"; |
|
toks[1] = NULL; |
|
|
|
p = calloc(1, sizeof(struct termp)); |
p = calloc(1, sizeof(struct termp)); |
if (NULL == p) { |
if (NULL == p) { |
perror(NULL); |
perror(NULL); |
Line 94 term_alloc(char *outopts, enum termenc enc) |
|
Line 89 term_alloc(char *outopts, enum termenc enc) |
|
|
|
p->tabwidth = 5; |
p->tabwidth = 5; |
p->enc = enc; |
p->enc = enc; |
width = 80; |
p->defrmargin = 78; |
|
|
while (outopts && *outopts) |
|
switch (getsubopt(&outopts, UNCONST(toks), &v)) { |
|
case (0): |
|
width = atoi(v); |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
/* Enforce some lower boundary. */ |
|
if (width < 60) |
|
width = 60; |
|
p->defrmargin = width - 2; |
|
return(p); |
return(p); |
} |
} |
|
|
Line 228 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 276 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 298 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 331 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 373 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); |
} |
} |
|
|
|
|