X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/1961c1d89494c7fce047f0bc339a5feae46efc7d..5851ee4d2b64ce06c48c8cfb740d681250066ca5:/mdocterm.c?ds=inline diff --git a/mdocterm.c b/mdocterm.c index 35d14168..9a344639 100644 --- a/mdocterm.c +++ b/mdocterm.c @@ -1,4 +1,4 @@ -/* $Id: mdocterm.c,v 1.12 2009/02/25 15:12:26 kristaps Exp $ */ +/* $Id: mdocterm.c,v 1.13 2009/02/25 17:02:47 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -345,6 +345,8 @@ pescape(struct termp *p, const char *word, size_t *i, size_t len) /* FALLTHROUGH */ case ('-'): /* FALLTHROUGH */ + case (' '): + /* FALLTHROUGH */ case ('.'): chara(p, word[*i]); default: @@ -372,7 +374,8 @@ pword(struct termp *p, const char *word, size_t len) ! (p->flags & TERMP_LITERAL)) chara(p, ' '); - p->flags &= ~TERMP_NOSPACE; + if ( ! (p->flags & TERMP_NONOSPACE)) + p->flags &= ~TERMP_NOSPACE; if (p->flags & TERMP_BOLD) style(p, STYLE_BOLD); @@ -530,8 +533,7 @@ static void header(struct termp *p, const struct mdoc_meta *meta) { char *buf, *title; - const char *pp, *msec; - size_t ssz, tsz, ttsz, i;; + const char *pp; if (NULL == (buf = malloc(p->rmargin))) err(1, "malloc"); @@ -568,50 +570,44 @@ header(struct termp *p, const struct mdoc_meta *meta) pp = mdoc_msec2a(MSEC_local); break; } - assert(pp); - - tsz = strlcpy(buf, pp, p->rmargin); - assert(tsz < p->rmargin); - - if ((pp = mdoc_arch2a(meta->arch))) { - tsz = strlcat(buf, " (", p->rmargin); - assert(tsz < p->rmargin); - tsz = strlcat(buf, pp, p->rmargin); - assert(tsz < p->rmargin); - tsz = strlcat(buf, ")", p->rmargin); - assert(tsz < p->rmargin); - } - ttsz = strlcpy(title, meta->title, p->rmargin); + if (mdoc_arch2a(meta->arch)) + (void)snprintf(buf, p->rmargin, "%s(%s)", + pp, mdoc_arch2a(meta->arch)); + else + (void)strlcpy(buf, pp, p->rmargin); - if (NULL == (msec = mdoc_msec2a(meta->msec))) - msec = ""; + pp = mdoc_msec2a(meta->msec); - ssz = (2 * (ttsz + 2 + strlen(msec))) + tsz + 2; + (void)snprintf(title, p->rmargin, "%s(%s)", + meta->title, pp ? pp : ""); - if (ssz > p->rmargin) { - if ((ssz -= p->rmargin) % 2) - ssz++; - ssz /= 2; - - assert(ssz <= ttsz); - title[ttsz - ssz] = 0; - ssz = 1; - } else - ssz = ((p->rmargin - ssz) / 2) + 1; + p->offset = 0; + p->rmargin = (p->maxrmargin - strlen(buf)) / 2; + p->flags |= TERMP_NOBREAK; + p->flags |= TERMP_NOSPACE; - printf("%s(%s)", title, msec); + word(p, title); + flushln(p); - for (i = 0; i < ssz; i++) - printf(" "); + p->offset = p->rmargin; + p->rmargin += strlen(buf); - printf("%s", buf); + word(p, buf); + flushln(p); - for (i = 0; i < ssz; i++) - printf(" "); + exit(1); - printf("%s(%s)\n", title, msec); - fflush(stdout); + p->offset = p->rmargin; + p->rmargin = p->maxrmargin; + p->flags &= ~TERMP_NOBREAK; + + word(p, title); + flushln(p); + + p->rmargin = p->maxrmargin; + p->offset = 0; + p->flags &= ~TERMP_NOSPACE; free(title); free(buf);