-/* $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>
*
assert(vsz > 0);
/*
+ * 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.,
- * 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");
- 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");
/*
}
}
+ 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 ( ! (p->flags & TERMP_NORPAD))
- for ( ; vis < maxvis; vis++)
- putchar(' ');
+ for ( ; vis < maxvis; vis++)
+ putchar(' ');
} else
putchar('\n');
-/* $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>
*
DECL_PRE(termp_bf);
DECL_PRE(termp_bsx);
DECL_PRE(termp_bt);
-DECL_PRE(termp_bx);
DECL_PRE(termp_cd);
DECL_PRE(termp_cm);
DECL_PRE(termp_em);
DECL_POST(termp___);
DECL_POST(termp_bl);
+DECL_POST(termp_bx);
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_bx_pre, NULL }, /* Bx */
+ { NULL, termp_bx_post }, /* Bx */
{ 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;
- if (MDOC_HEAD == node->type) {
+ if (MDOC_HEAD == node->type)
p->flags &= ~TERMP_NOBREAK;
- p->flags &= ~TERMP_NORPAD;
- } else if (MDOC_BODY == node->type)
+ else if (MDOC_BODY == node->type)
p->flags &= ~TERMP_NOLPAD;
}
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);
+
return(1);
}
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);
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];
return(1);
}
{
/* FIXME: this can be "type name". */
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_VAR_DECL]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]);
return(1);
}
* 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]);
return(1);
}
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;
termp_ft_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_TYPE]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_TYPE]);
return(1);
}
termp_sx_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_LINK]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK]);
return(1);
}
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]);
return(1);
}
termp_va_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_VAR_DECL]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]);
return(1);
}
/* ARGSUSED */
-static int
-termp_bx_pre(DECL_ARGS)
+static void
+termp_bx_post(DECL_ARGS)
{
+ p->flags |= TERMP_NOSPACE;
word(p, "BSD");
- return(1);
}
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:
termp_pa_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FILE]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FILE]);
return(1);
}
termp_em_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
return(1);
}
termp_cd_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CONFIG]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CONFIG]);
return(1);
}
termp_cm_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_FLAG]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]);
return(1);
}
termp_ic_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD]);
return(1);
}
termp_in_pre(DECL_ARGS)
{
- p->flags |= ttypes[TTYPE_INCLUDE];
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_INCLUDE]);
word(p, "#include");
word(p, "<");
- p->flags &= ~ttypes[TTYPE_INCLUDE];
p->flags |= TERMP_NOSPACE;
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_INCLUDE]);
return(1);
}
if (MDOC_BODY != node->type)
return(1);
- word(p, "(");
+ word(p, "\\&(");
p->flags |= TERMP_NOSPACE;
return(1);
}
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))
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
return(1);
}
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))
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
return(1);
}
termp_sy_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
return(1);
}
termp_ms_pre(DECL_ARGS)
{
- TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMBOL]);
+ TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMBOL]);
return(1);
}