source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Sync print_mdoc_head to print_man_head;                     this
@ 2011-09-20  9:02 schwarze
  2011-09-20 11:06 ` mdocml: Sync print_mdoc_head to print_man_head; Kristaps Dzonsons
  0 siblings, 1 reply; 2+ messages in thread
From: schwarze @ 2011-09-20  9:02 UTC (permalink / raw)
  To: source

Log Message:
-----------
Sync print_mdoc_head to print_man_head;                    
this was forgotten after man_term.c rev. 1.25 on March 2, 2010.
The benefit is a sane page header line when .Dt is very long.
Reminded by Thomas Klausner <wiz at NetBSD>, thanks.

Modified Files:
--------------
    mdocml:
        man_term.c
        mdoc_term.c

Revision Data
-------------
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.117
retrieving revision 1.118
diff -Lman_term.c -Lman_term.c -u -p -r1.117 -r1.118
--- man_term.c
+++ man_term.c
@@ -1007,9 +1007,9 @@ print_man_head(struct termp *p, const vo
 	 * point we did so here.
 	 */
 
+	p->offset = 0;
 	p->rmargin = p->maxrmargin;
 
-	p->offset = 0;
 	buf[0] = title[0] = '\0';
 
 	if (m->vol)
@@ -1019,12 +1019,12 @@ print_man_head(struct termp *p, const vo
 	snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
 	titlen = term_strlen(p, title);
 
+	p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
 	p->offset = 0;
 	p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
 	    (p->maxrmargin - 
 	     term_strlen(p, buf) + term_len(p, 1)) / 2 :
 	    p->maxrmargin - buflen;
-	p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
 
 	term_word(p, title);
 	term_flushln(p);
@@ -1046,9 +1046,9 @@ print_man_head(struct termp *p, const vo
 		term_flushln(p);
 	}
 
-	p->rmargin = p->maxrmargin;
-	p->offset = 0;
 	p->flags &= ~TERMP_NOSPACE;
+	p->offset = 0;
+	p->rmargin = p->maxrmargin;
 
 	/* 
 	 * Groff likes to have some leading spaces before content.  Well
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.234
retrieving revision 1.235
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.234 -r1.235
--- mdoc_term.c
+++ mdoc_term.c
@@ -458,13 +458,11 @@ static void
 print_mdoc_head(struct termp *p, const void *arg)
 {
 	char		buf[BUFSIZ], title[BUFSIZ];
+	size_t		buflen, titlen;
 	const struct mdoc_meta *m;
 
 	m = (const struct mdoc_meta *)arg;
 
-	p->rmargin = p->maxrmargin;
-	p->offset = 0;
-
 	/*
 	 * The header is strange.  It has three components, which are
 	 * really two with the first duplicated.  It goes like this:
@@ -478,8 +476,12 @@ print_mdoc_head(struct termp *p, const v
 	 * switches on the manual section.
 	 */
 
+	p->offset = 0;
+	p->rmargin = p->maxrmargin;
+
 	assert(m->vol);
 	strlcpy(buf, m->vol, BUFSIZ);
+	buflen = term_strlen(p, buf);
 
 	if (m->arch) {
 		strlcat(buf, " (", BUFSIZ);
@@ -488,33 +490,38 @@ print_mdoc_head(struct termp *p, const v
 	}
 
 	snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
+	titlen = term_strlen(p, title);
 
-	p->offset = 0;
-	p->rmargin = (p->maxrmargin - 
-			term_strlen(p, buf) + term_len(p, 1)) / 2;
 	p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
+	p->offset = 0;
+	p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
+	    (p->maxrmargin -
+	     term_strlen(p, buf) + term_len(p, 1)) / 2 :
+	    p->maxrmargin - buflen;
 
 	term_word(p, title);
 	term_flushln(p);
 
-	p->offset = p->rmargin;
-	p->rmargin = p->maxrmargin - term_strlen(p, title);
 	p->flags |= TERMP_NOSPACE;
+	p->offset = p->rmargin;
+	p->rmargin = p->offset + buflen + titlen < p->maxrmargin ?
+	    p->maxrmargin - titlen : p->maxrmargin;
 
 	term_word(p, buf);
 	term_flushln(p);
 
-	p->offset = p->rmargin;
-	p->rmargin = p->maxrmargin;
 	p->flags &= ~TERMP_NOBREAK;
-	p->flags |= TERMP_NOSPACE;
-
-	term_word(p, title);
-	term_flushln(p);
+	if (p->rmargin + titlen <= p->maxrmargin) {
+		p->flags |= TERMP_NOSPACE;
+		p->offset = p->rmargin;
+		p->rmargin = p->maxrmargin;
+		term_word(p, title);
+		term_flushln(p);
+	}
 
+	p->flags &= ~TERMP_NOSPACE;
 	p->offset = 0;
 	p->rmargin = p->maxrmargin;
-	p->flags &= ~TERMP_NOSPACE;
 }
 
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mdocml: Sync print_mdoc_head to print_man_head;
  2011-09-20  9:02 mdocml: Sync print_mdoc_head to print_man_head; this schwarze
@ 2011-09-20 11:06 ` Kristaps Dzonsons
  0 siblings, 0 replies; 2+ messages in thread
From: Kristaps Dzonsons @ 2011-09-20 11:06 UTC (permalink / raw)
  To: source; +Cc: schwarze

On 09/20/2011 11:02 AM, schwarze@mdocml.bsd.lv wrote:
> Log Message:
> -----------
> Sync print_mdoc_head to print_man_head;
> this was forgotten after man_term.c rev. 1.25 on March 2, 2010.
> The benefit is a sane page header line when .Dt is very long.
> Reminded by Thomas Klausner<wiz at NetBSD>, thanks.

Ingo,

Can you document what this produces within the respective function 
codes?  In mdoc_term.c we at least mention the normal case (three-column 
pretty), but I'd also like the corner cases documented on the spot.  The 
man_term.c doesn't have anything at all!

Thanks!

Kristaps
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-20 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-20  9:02 mdocml: Sync print_mdoc_head to print_man_head; this schwarze
2011-09-20 11:06 ` mdocml: Sync print_mdoc_head to print_man_head; Kristaps Dzonsons

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).