version 1.147, 2010/06/11 07:23:04 |
version 1.153, 2010/06/28 22:46:21 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
#include "chars.h" |
#include "chars.h" |
#include "out.h" |
#include "out.h" |
#include "term.h" |
#include "term.h" |
#include "man.h" |
|
#include "mdoc.h" |
|
#include "main.h" |
#include "main.h" |
|
|
static void spec(struct termp *, const char *, size_t); |
static void spec(struct termp *, const char *, size_t); |
Line 87 term_alloc(enum termenc enc) |
|
Line 85 term_alloc(enum termenc enc) |
|
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
} |
} |
|
|
p->tabwidth = 5; |
|
p->enc = enc; |
p->enc = enc; |
p->defrmargin = 78; |
|
return(p); |
return(p); |
} |
} |
|
|
Line 137 term_flushln(struct termp *p) |
|
Line 133 term_flushln(struct termp *p) |
|
size_t vbl; /* number of blanks to prepend to output */ |
size_t vbl; /* number of blanks to prepend to output */ |
size_t vend; /* end of word visual position on output */ |
size_t vend; /* end of word visual position on output */ |
size_t bp; /* visual right border position */ |
size_t bp; /* visual right border position */ |
int j; /* temporary loop index */ |
int j; /* temporary loop index for p->buf */ |
int jhy; /* last hyphen before line overflow */ |
int jhy; /* last hyph before overflow w/r/t j */ |
size_t maxvis, mmax; |
size_t maxvis; /* output position of visible boundary */ |
|
size_t mmax; /* used in calculating bp */ |
|
|
/* |
/* |
* First, establish the maximum columns of "visible" content. |
* First, establish the maximum columns of "visible" content. |
Line 198 term_flushln(struct termp *p) |
|
Line 195 term_flushln(struct termp *p) |
|
if (vend > vis && vend < bp && |
if (vend > vis && vend < bp && |
ASCII_HYPH == p->buf[j]) |
ASCII_HYPH == p->buf[j]) |
jhy = j; |
jhy = j; |
vend++; |
vend += (*p->width)(p, p->buf[j]); |
} else |
} else { |
vend--; |
assert(j); |
|
vend -= (*p->width)(p, p->buf[j - 1]); |
|
} |
} |
} |
|
|
/* |
/* |
Line 240 term_flushln(struct termp *p) |
|
Line 239 term_flushln(struct termp *p) |
|
break; |
break; |
if (' ' == p->buf[i]) { |
if (' ' == p->buf[i]) { |
while (' ' == p->buf[i]) { |
while (' ' == p->buf[i]) { |
vbl++; |
vbl += (*p->width)(p, p->buf[i]); |
i++; |
i++; |
} |
} |
break; |
break; |
} |
} |
if (ASCII_NBRSP == p->buf[i]) { |
if (ASCII_NBRSP == p->buf[i]) { |
vbl++; |
vbl += (*p->width)(p, ' '); |
continue; |
continue; |
} |
} |
|
|
Line 261 term_flushln(struct termp *p) |
|
Line 260 term_flushln(struct termp *p) |
|
vbl = 0; |
vbl = 0; |
} |
} |
|
|
if (ASCII_HYPH == p->buf[i]) |
if (ASCII_HYPH == p->buf[i]) { |
(*p->letter)(p, '-'); |
(*p->letter)(p, '-'); |
else |
p->viscol += (*p->width)(p, '-'); |
|
} else { |
(*p->letter)(p, p->buf[i]); |
(*p->letter)(p, p->buf[i]); |
|
p->viscol += (*p->width)(p, p->buf[i]); |
p->viscol += 1; |
} |
} |
} |
vend += vbl; |
vend += vbl; |
vis = vend; |
vis = vend; |
Line 284 term_flushln(struct termp *p) |
|
Line 284 term_flushln(struct termp *p) |
|
if (TERMP_HANG & p->flags) { |
if (TERMP_HANG & p->flags) { |
/* We need one blank after the tag. */ |
/* We need one blank after the tag. */ |
p->overstep = /* LINTED */ |
p->overstep = /* LINTED */ |
vis - maxvis + 1; |
vis - maxvis + (*p->width)(p, ' '); |
|
|
/* |
/* |
* Behave exactly the same way as groff: |
* Behave exactly the same way as groff: |
Line 308 term_flushln(struct termp *p) |
|
Line 308 term_flushln(struct termp *p) |
|
|
|
/* Right-pad. */ |
/* Right-pad. */ |
if (maxvis > vis + /* LINTED */ |
if (maxvis > vis + /* LINTED */ |
((TERMP_TWOSPACE & p->flags) ? 1 : 0)) { |
((TERMP_TWOSPACE & p->flags) ? (*p->width)(p, ' ') : 0)) { |
p->viscol += maxvis - vis; |
p->viscol += maxvis - vis; |
(*p->advance)(p, maxvis - vis); |
(*p->advance)(p, maxvis - vis); |
vis += (maxvis - vis); |
vis += (maxvis - vis); |
Line 484 term_word(struct termp *p, const char *word) |
|
Line 484 term_word(struct termp *p, const char *word) |
|
} |
} |
|
|
if ( ! (TERMP_NOSPACE & p->flags)) { |
if ( ! (TERMP_NOSPACE & p->flags)) { |
bufferc(p, ' '); |
if ( ! (TERMP_KEEP & p->flags)) { |
if (TERMP_SENTENCE & p->flags) |
if (TERMP_PREKEEP & p->flags) |
|
p->flags |= TERMP_KEEP; |
bufferc(p, ' '); |
bufferc(p, ' '); |
|
if (TERMP_SENTENCE & p->flags) |
|
bufferc(p, ' '); |
|
} else |
|
bufferc(p, ASCII_NBRSP); |
} |
} |
|
|
if ( ! (p->flags & TERMP_NONOSPACE)) |
if ( ! (p->flags & TERMP_NONOSPACE)) |
Line 626 encode(struct termp *p, const char *word, size_t sz) |
|
Line 631 encode(struct termp *p, const char *word, size_t sz) |
|
|
|
|
|
size_t |
size_t |
term_vspan(const struct roffsu *su) |
term_len(const struct termp *p, size_t sz) |
{ |
{ |
|
|
|
return((*p->width)(p, ' ') * sz); |
|
} |
|
|
|
|
|
size_t |
|
term_strlen(const struct termp *p, const char *cp) |
|
{ |
|
size_t sz; |
|
|
|
for (sz = 0; *cp; cp++) |
|
sz += (*p->width)(p, *cp); |
|
|
|
return(sz); |
|
} |
|
|
|
|
|
size_t |
|
term_vspan(const struct termp *p, const struct roffsu *su) |
|
{ |
double r; |
double r; |
|
|
switch (su->unit) { |
switch (su->unit) { |
Line 662 term_vspan(const struct roffsu *su) |
|
Line 687 term_vspan(const struct roffsu *su) |
|
|
|
|
|
size_t |
size_t |
term_hspan(const struct roffsu *su) |
term_hspan(const struct termp *p, const struct roffsu *su) |
{ |
{ |
double r; |
double r; |
|
|