Fixed TERMP_SETFLAGS and current-flag omission.
-/* $Id: mdocterm.c,v 1.21 2009/02/28 21:31:13 kristaps Exp $ */
+/* $Id: mdocterm.c,v 1.22 2009/03/01 13:06:49 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
+ * If we're breaking normally...
+ *
* If a word is too long and we're within a line, put it
* on the next line. Puke if we're being asked to write
* something that will exceed the right margin (i.e.,
* If a word is too long and we're within a line, put it
* on the next line. Puke if we're being asked to write
* something that will exceed the right margin (i.e.,
- * from a fresh line or when we're not allowed to break
- * the line with TERMP_NOBREAK).
+ * from a fresh line).
+ *
+ * If we're not breaking...
+ *
+ * Don't let the visible size exceed the full margin.
- /* FIXME: allow selective right-margin breaking. */
-
- if (vis && vis + vsz > maxvis) {
- if (p->flags & TERMP_NOBREAK)
+ if ( ! (TERMP_NOBREAK & p->flags)) {
+ if (vis && vis + vsz > maxvis) {
+ putchar('\n');
+ for (j = 0; j < p->offset; j++)
+ putchar(' ');
+ vis = 0;
+ } else if (vis + vsz > maxvis)
errx(1, "word breaks right margin");
errx(1, "word breaks right margin");
- putchar('\n');
- for (j = 0; j < p->offset; j++)
- putchar(' ');
- vis = 0;
- } else if (vis + vsz > maxvis)
+ } else if (vis + vsz > p->maxrmargin)
errx(1, "word breaks right margin");
/*
errx(1, "word breaks right margin");
/*
+ if ((TERMP_NOBREAK & p->flags) && vis >= maxvis) {
+ putchar('\n');
+ for (i = 0; i < p->rmargin; i++)
+ putchar(' ');
+ p->col = 0;
+ return;
+ }
+
/*
* If we're not to right-marginalise it (newline), then instead
* pad to the right margin and stay off.
*/
if (p->flags & TERMP_NOBREAK) {
/*
* If we're not to right-marginalise it (newline), then instead
* pad to the right margin and stay off.
*/
if (p->flags & TERMP_NOBREAK) {
- if ( ! (p->flags & TERMP_NORPAD))
- for ( ; vis < maxvis; vis++)
- putchar(' ');
+ for ( ; vis < maxvis; vis++)
+ putchar(' ');
-/* $Id: term.c,v 1.30 2009/02/28 21:31:13 kristaps Exp $ */
+/* $Id: term.c,v 1.31 2009/03/01 13:06:49 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
DECL_PRE(termp_bf);
DECL_PRE(termp_bsx);
DECL_PRE(termp_bt);
DECL_PRE(termp_bf);
DECL_PRE(termp_bsx);
DECL_PRE(termp_bt);
DECL_PRE(termp_cd);
DECL_PRE(termp_cm);
DECL_PRE(termp_em);
DECL_PRE(termp_cd);
DECL_PRE(termp_cm);
DECL_PRE(termp_em);
DECL_POST(termp___);
DECL_POST(termp_bl);
DECL_POST(termp___);
DECL_POST(termp_bl);
const struct termact __termacts[MDOC_MAX] = {
{ NULL, NULL }, /* \" */
const struct termact __termacts[MDOC_MAX] = {
{ NULL, NULL }, /* \" */
{ termp_bq_pre, termp_bq_post }, /* Bo */
{ termp_bq_pre, termp_bq_post }, /* Bq */
{ termp_bsx_pre, NULL }, /* Bsx */
{ termp_bq_pre, termp_bq_post }, /* Bo */
{ termp_bq_pre, termp_bq_post }, /* Bq */
{ termp_bsx_pre, NULL }, /* Bsx */
- { termp_bx_pre, NULL }, /* Bx */
+ { NULL, termp_bx_post }, /* Bx */
{ NULL, NULL }, /* Db */
{ NULL, NULL }, /* Dc */
{ termp_dq_pre, termp_dq_post }, /* Do */
{ NULL, NULL }, /* Db */
{ NULL, NULL }, /* Dc */
{ termp_dq_pre, termp_dq_post }, /* Do */
- return(strlen(*arg->value) + 2);
+ return(strlen(*arg->value) + 1);
p->offset = pair->offset;
p->rmargin = pair->rmargin;
p->offset = pair->offset;
p->rmargin = pair->rmargin;
- if (MDOC_HEAD == node->type) {
+ if (MDOC_HEAD == node->type)
p->flags &= ~TERMP_NOBREAK;
p->flags &= ~TERMP_NOBREAK;
- p->flags &= ~TERMP_NORPAD;
- } else if (MDOC_BODY == node->type)
+ else if (MDOC_BODY == node->type)
p->flags &= ~TERMP_NOLPAD;
}
p->flags &= ~TERMP_NOLPAD;
}
if (SEC_SYNOPSIS == node->sec)
newln(p);
if (SEC_SYNOPSIS == node->sec)
newln(p);
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_PROG]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_PROG]);
if (NULL == node->child)
word(p, meta->name);
if (NULL == node->child)
word(p, meta->name);
termp_fl_pre(DECL_ARGS)
{
termp_fl_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_FLAG]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]);
word(p, "\\-");
p->flags |= TERMP_NOSPACE;
return(1);
word(p, "\\-");
p->flags |= TERMP_NOSPACE;
return(1);
termp_ar_pre(DECL_ARGS)
{
termp_ar_pre(DECL_ARGS)
{
- if (node->child) {
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_ARG]);
- return(1);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_ARG]);
+ if (NULL == node->child) {
+ word(p, "file");
+ word(p, "...");
- p->flags |= ttypes[TTYPE_CMD_ARG];
- word(p, "file");
- word(p, "...");
- p->flags &= ~ttypes[TTYPE_CMD_ARG];
{
/* FIXME: this can be "type name". */
{
/* FIXME: this can be "type name". */
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_VAR_DECL]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]);
* FIXME: this naming is bad. This value is used, in general,
* for the #include header or other preprocessor statement.
*/
* FIXME: this naming is bad. This value is used, in general,
* for the #include header or other preprocessor statement.
*/
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_DECL]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_DECL]);
switch (node->type) {
case (MDOC_HEAD):
vspace(p);
switch (node->type) {
case (MDOC_HEAD):
vspace(p);
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SECTION]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SECTION]);
break;
case (MDOC_BODY):
p->offset = INDENT;
break;
case (MDOC_BODY):
p->offset = INDENT;
termp_ft_pre(DECL_ARGS)
{
termp_ft_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_TYPE]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_TYPE]);
termp_sx_pre(DECL_ARGS)
{
termp_sx_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_LINK]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK]);
struct mdoc_node *n;
if (node->parent->tok != MDOC_Fo) {
struct mdoc_node *n;
if (node->parent->tok != MDOC_Fo) {
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_ARG]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_ARG]);
termp_va_pre(DECL_ARGS)
{
termp_va_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_VAR_DECL]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]);
-static int
-termp_bx_pre(DECL_ARGS)
+static void
+termp_bx_post(DECL_ARGS)
+ p->flags |= TERMP_NOSPACE;
switch (node->type) {
case (MDOC_HEAD):
vspace(p);
switch (node->type) {
case (MDOC_HEAD):
vspace(p);
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SSECTION]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SSECTION]);
p->offset = INDENT / 2;
break;
default:
p->offset = INDENT / 2;
break;
default:
termp_pa_pre(DECL_ARGS)
{
termp_pa_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FILE]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FILE]);
termp_em_pre(DECL_ARGS)
{
termp_em_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
termp_cd_pre(DECL_ARGS)
{
termp_cd_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CONFIG]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CONFIG]);
termp_cm_pre(DECL_ARGS)
{
termp_cm_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_FLAG]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]);
termp_ic_pre(DECL_ARGS)
{
termp_ic_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD]);
termp_in_pre(DECL_ARGS)
{
termp_in_pre(DECL_ARGS)
{
- p->flags |= ttypes[TTYPE_INCLUDE];
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_INCLUDE]);
word(p, "#include");
word(p, "<");
word(p, "#include");
word(p, "<");
- p->flags &= ~ttypes[TTYPE_INCLUDE];
p->flags |= TERMP_NOSPACE;
p->flags |= TERMP_NOSPACE;
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_INCLUDE]);
if (MDOC_BODY != node->type)
return(1);
if (MDOC_BODY != node->type)
return(1);
p->flags |= TERMP_NOSPACE;
return(1);
}
p->flags |= TERMP_NOSPACE;
return(1);
}
if (NULL == (n = b->head->child)) {
if (arg_hasattr(MDOC_Emphasis, b->argc, b->argv))
if (NULL == (n = b->head->child)) {
if (arg_hasattr(MDOC_Emphasis, b->argc, b->argv))
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
else if (arg_hasattr(MDOC_Symbolic, b->argc, b->argv))
else if (arg_hasattr(MDOC_Symbolic, b->argc, b->argv))
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
assert(MDOC_TEXT == n->type);
if (0 == strcmp("Em", n->data.text.string))
assert(MDOC_TEXT == n->type);
if (0 == strcmp("Em", n->data.text.string))
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
else if (0 == strcmp("Sy", n->data.text.string))
else if (0 == strcmp("Sy", n->data.text.string))
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
termp_sy_pre(DECL_ARGS)
{
termp_sy_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
termp_ms_pre(DECL_ARGS)
{
termp_ms_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMBOL]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMBOL]);
-/* $Id: term.h,v 1.11 2009/02/25 23:18:50 kristaps Exp $ */
+/* $Id: term.h,v 1.12 2009/03/01 13:06:49 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
#define TERMP_LITERAL (1 << 5) /* Literal words. */
#define TERMP_IGNDELIM (1 << 6) /* Delims like regulars. */
#define TERMP_NONOSPACE (1 << 7) /* No space (no autounset). */
#define TERMP_LITERAL (1 << 5) /* Literal words. */
#define TERMP_IGNDELIM (1 << 6) /* Delims like regulars. */
#define TERMP_NONOSPACE (1 << 7) /* No space (no autounset). */
-#define TERMP_NORPAD (1 << 8) /* No rightpad. */
-#define TERMPAIR_SETFLAG(p, fl) \
+#define TERMPAIR_SETFLAG(termp, p, fl) \
do { \
assert(! (TERMPAIR_FLAG & (p)->type)); \
do { \
assert(! (TERMPAIR_FLAG & (p)->type)); \
+ (termp)->flags |= (fl); \
(p)->flag = (fl); \
(p)->type |= TERMPAIR_FLAG; \
} while (0)
(p)->flag = (fl); \
(p)->type |= TERMPAIR_FLAG; \
} while (0)