version 1.174, 2010/10/02 15:15:55 |
version 1.182, 2011/03/22 14:05:45 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* 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 <string.h> |
#include <string.h> |
|
|
#include "mandoc.h" |
#include "mandoc.h" |
#include "chars.h" |
|
#include "out.h" |
#include "out.h" |
#include "term.h" |
#include "term.h" |
#include "main.h" |
#include "main.h" |
Line 80 term_alloc(enum termenc enc) |
|
Line 79 term_alloc(enum termenc enc) |
|
{ |
{ |
struct termp *p; |
struct termp *p; |
|
|
p = calloc(1, sizeof(struct termp)); |
p = mandoc_calloc(1, sizeof(struct termp)); |
if (NULL == p) { |
|
perror(NULL); |
|
exit((int)MANDOCLEVEL_SYSERR); |
|
} |
|
|
|
p->enc = enc; |
p->enc = enc; |
return(p); |
return(p); |
} |
} |
Line 146 term_flushln(struct termp *p) |
|
Line 140 term_flushln(struct termp *p) |
|
* an indentation, but can be, for tagged lists or columns, a |
* an indentation, but can be, for tagged lists or columns, a |
* small set of values. |
* small set of values. |
*/ |
*/ |
assert (p->rmargin > p->offset); |
assert (p->rmargin >= p->offset); |
dv = p->rmargin - p->offset; |
dv = p->rmargin - p->offset; |
maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0; |
maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0; |
dv = p->maxrmargin - p->offset; |
dv = p->maxrmargin - p->offset; |
Line 353 term_vspace(struct termp *p) |
|
Line 347 term_vspace(struct termp *p) |
|
|
|
|
|
static void |
static void |
|
numbered(struct termp *p, const char *word, size_t len) |
|
{ |
|
const char *rhs; |
|
|
|
rhs = chars_num2char(word, len); |
|
if (rhs) |
|
encode(p, rhs, 1); |
|
} |
|
|
|
|
|
static void |
spec(struct termp *p, enum roffdeco d, const char *word, size_t len) |
spec(struct termp *p, enum roffdeco d, const char *word, size_t len) |
{ |
{ |
const char *rhs; |
const char *rhs; |
Line 457 term_word(struct termp *p, const char *word) |
|
Line 462 term_word(struct termp *p, const char *word) |
|
|
|
sv = word; |
sv = word; |
|
|
if (word[0] && '\0' == word[1]) |
|
switch (word[0]) { |
|
case('.'): |
|
/* FALLTHROUGH */ |
|
case(','): |
|
/* FALLTHROUGH */ |
|
case(';'): |
|
/* FALLTHROUGH */ |
|
case(':'): |
|
/* FALLTHROUGH */ |
|
case('?'): |
|
/* FALLTHROUGH */ |
|
case('!'): |
|
/* FALLTHROUGH */ |
|
case(')'): |
|
/* FALLTHROUGH */ |
|
case(']'): |
|
if ( ! (TERMP_IGNDELIM & p->flags)) |
|
p->flags |= TERMP_NOSPACE; |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
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 503 term_word(struct termp *p, const char *word) |
|
Line 484 term_word(struct termp *p, const char *word) |
|
if ((ssz = strcspn(word, "\\")) > 0) |
if ((ssz = strcspn(word, "\\")) > 0) |
encode(p, word, ssz); |
encode(p, word, ssz); |
|
|
word += ssz; |
word += (int)ssz; |
if ('\\' != *word) |
if ('\\' != *word) |
continue; |
continue; |
|
|
Line 511 term_word(struct termp *p, const char *word) |
|
Line 492 term_word(struct termp *p, const char *word) |
|
word += a2roffdeco(&deco, &seq, &ssz); |
word += a2roffdeco(&deco, &seq, &ssz); |
|
|
switch (deco) { |
switch (deco) { |
|
case (DECO_NUMBERED): |
|
numbered(p, seq, ssz); |
|
break; |
case (DECO_RESERVED): |
case (DECO_RESERVED): |
res(p, seq, ssz); |
res(p, seq, ssz); |
break; |
break; |
Line 538 term_word(struct termp *p, const char *word) |
|
Line 522 term_word(struct termp *p, const char *word) |
|
if (DECO_NOSPACE == deco && '\0' == *word) |
if (DECO_NOSPACE == deco && '\0' == *word) |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
} |
} |
|
|
/* |
|
* Note that we don't process the pipe: the parser sees it as |
|
* punctuation, but we don't in terms of typography. |
|
*/ |
|
if (sv[0] && '\0' == sv[1]) |
|
switch (sv[0]) { |
|
case('('): |
|
/* FALLTHROUGH */ |
|
case('['): |
|
p->flags |= TERMP_NOSPACE; |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
} |
|
|
|
|
Line 565 adjbuf(struct termp *p, size_t sz) |
|
Line 534 adjbuf(struct termp *p, size_t sz) |
|
while (sz >= p->maxcols) |
while (sz >= p->maxcols) |
p->maxcols <<= 2; |
p->maxcols <<= 2; |
|
|
p->buf = realloc(p->buf, p->maxcols); |
p->buf = mandoc_realloc(p->buf, p->maxcols); |
if (NULL == p->buf) { |
|
perror(NULL); |
|
exit((int)MANDOCLEVEL_SYSERR); |
|
} |
|
} |
} |
|
|
|
|
Line 677 term_strlen(const struct termp *p, const char *cp) |
|
Line 642 term_strlen(const struct termp *p, const char *cp) |
|
if (rhs) |
if (rhs) |
for (i = 0; i < rsz; i++) |
for (i = 0; i < rsz; i++) |
sz += (*p->width)(p, *rhs++); |
sz += (*p->width)(p, *rhs++); |
|
} else if (ASCII_NBRSP == *cp) { |
|
sz += (*p->width)(p, ' '); |
|
cp++; |
|
} else if (ASCII_HYPH == *cp) { |
|
sz += (*p->width)(p, '-'); |
|
cp++; |
} else |
} else |
sz += (*p->width)(p, *cp++); |
sz += (*p->width)(p, *cp++); |
|
|