tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* PATCH: break the line at an existing hyphen
@ 2010-05-24 23:32 Ingo Schwarze
  2010-05-24 23:59 ` Kristaps Dzonsons
  2010-05-25 12:49 ` Kristaps Dzonsons
  0 siblings, 2 replies; 5+ messages in thread
From: Ingo Schwarze @ 2010-05-24 23:32 UTC (permalink / raw)
  To: tech

Hi Kristaps and Joerg,

here is the final patch to get bsd.lv in sync with OpenBSD.

I know Kristaps backed something like this out once already,
i guess it got in the way back then, before the term_flushln() cleanup.

But now, after the cleanup, this has become really easy,
it is just three simple steps:

 1. While scanning forward for the first time, remember
    the last hyphen fitting on the line.
 2. When deciding whether to break the line at once,
    don't do it when there is a useable hyphen.
 3. Finally, while scanning forward for the second time,
    i.e. in the output loop, break at the hyphen, if required.

Of course, it is not very difficult to make this a bit fancier
and avoid some breaks that make little sense - but this is what
OpenBSD has now, and it helps us to get in sync.

I would rather put this in than back it out, if only because
it makes automatic comparisons a lot easier...

This final patch is also here:
  /usr/vhosts/mdocml.bsd.lv/patch/schwarze/09.break-at-hyphen.patch

Yours,
  Ingo

P.S.
Yeah, i know, only one comment in here -
but this was committed to OpenBSD long before your
heartful urgings, Kristaps!


Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.139
diff -u -p -r1.139 term.c
--- term.c	24 May 2010 21:51:20 -0000	1.139
+++ term.c	24 May 2010 23:07:01 -0000
@@ -138,6 +138,7 @@ term_flushln(struct termp *p)
 	size_t		 vend;	/* end of word visual position on output */
 	size_t		 bp;    /* visual right border position */
 	int		 j;     /* temporary loop index */
+	int		 jhy;	/* last hyphen before line overflow */
 	size_t		 maxvis, mmax;
 
 	/*
@@ -190,20 +191,24 @@ term_flushln(struct termp *p)
 		 */
 
 		/* LINTED */
-		for ( ; j < (int)p->col; j++) {
+		for (jhy = 0; j < (int)p->col; j++) {
 			if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j])
 				break;
 			if (8 == p->buf[j])
 				vend--;
-			else
+			else {
+				if (vend > vis && vend < bp &&
+				    '-' == p->buf[j])
+					jhy = j;
 				vend++;
+			}
 		}
 
 		/*
 		 * Find out whether we would exceed the right margin.
 		 * If so, break to the next line.
 		 */
-		if (vend > bp && vis > 0) {
+		if (vend > bp && 0 == jhy && vis > 0) {
 			vend -= vis;
 			putchar('\n');
 			if (TERMP_NOBREAK & p->flags) {
@@ -231,6 +236,8 @@ term_flushln(struct termp *p)
 
 		/* Write out the [remaining] word. */
 		for ( ; i < (int)p->col; i++) {
+			if (vend > bp && jhy > 0 && i > jhy)
+				break;
 			if ('\t' == p->buf[i])
 				break;
 			if (' ' == p->buf[i]) {
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

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

* Re: PATCH: break the line at an existing hyphen
  2010-05-24 23:32 PATCH: break the line at an existing hyphen Ingo Schwarze
@ 2010-05-24 23:59 ` Kristaps Dzonsons
  2010-05-25 12:49 ` Kristaps Dzonsons
  1 sibling, 0 replies; 5+ messages in thread
From: Kristaps Dzonsons @ 2010-05-24 23:59 UTC (permalink / raw)
  To: tech

> here is the final patch to get bsd.lv in sync with OpenBSD.
> 
> I know Kristaps backed something like this out once already,
> i guess it got in the way back then, before the term_flushln() cleanup.
> 
> But now, after the cleanup, this has become really easy,
> it is just three simple steps:
> 
>  1. While scanning forward for the first time, remember
>     the last hyphen fitting on the line.
>  2. When deciding whether to break the line at once,
>     don't do it when there is a useable hyphen.
>  3. Finally, while scanning forward for the second time,
>     i.e. in the output loop, break at the hyphen, if required.
> 
> Of course, it is not very difficult to make this a bit fancier
> and avoid some breaks that make little sense - but this is what
> OpenBSD has now, and it helps us to get in sync.
> 
> I would rather put this in than back it out, if only because
> it makes automatic comparisons a lot easier...
> 
> This final patch is also here:
>   /usr/vhosts/mdocml.bsd.lv/patch/schwarze/09.break-at-hyphen.patch
> 
> Yours,
>   Ingo
> 
> P.S.
> Yeah, i know, only one comment in here -
> but this was committed to OpenBSD long before your
> heartful urgings, Kristaps!

Ingo,

Note that I do not agree with one part of this patch: it erroneously 
assumes that a "-" can be broken in any case.  This is not true:

  .Dd $Mdocdate$
  .Dt FOO 1
  .Os
  .Sh NAME
  .Nm foo
  .Nd bar
  .Sh DESCRIPTION
  asdf asdf asdf asdf asdf asdf asdf
  .\" no-break:
  asdf asdf asdf asdf asdf asdf asasas\-df
  .Pp
  asdf asdf asdf asdf asdf asdf asdf
  asdf asdf asdf asdf asdf asdf asasas-df
  .Pp
  asdf asdf asdf asdf asdf asdf asdf
  .\" no-break:
  asdf asdf asdf asdf asdf asdf asasas\(hydf
  .Pp
  asdf asdf asdf asdf asdf asdf asdf
  asdf asdf asdf asdf asdf asa
  .\" no-break:
  .Fl asasas-df

What should happen is that breakable hyphens are cued in the back-end 
with some magic character that's later interpreted in flushln.

However, I'm ok with this as a stop-gap: in fact, implementing cueing 
will merely subsitute the magic character for the '-' check and add some 
extra glue to sub-out the magic bits.

So I give it an ok@ so long as you add a FIXME to this effect that 
Kristaps must add the cuing logic.  I can do this subsequent the release.

Thanks,

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

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

* Re: PATCH: break the line at an existing hyphen
  2010-05-24 23:32 PATCH: break the line at an existing hyphen Ingo Schwarze
  2010-05-24 23:59 ` Kristaps Dzonsons
@ 2010-05-25 12:49 ` Kristaps Dzonsons
  2010-05-26  3:04   ` Ingo Schwarze
  1 sibling, 1 reply; 5+ messages in thread
From: Kristaps Dzonsons @ 2010-05-25 12:49 UTC (permalink / raw)
  To: tech

> here is the final patch to get bsd.lv in sync with OpenBSD.
> 
> I know Kristaps backed something like this out once already,
> i guess it got in the way back then, before the term_flushln() cleanup.
> 
> But now, after the cleanup, this has become really easy,
> it is just three simple steps:
> 
>  1. While scanning forward for the first time, remember
>     the last hyphen fitting on the line.
>  2. When deciding whether to break the line at once,
>     don't do it when there is a useable hyphen.
>  3. Finally, while scanning forward for the second time,
>     i.e. in the output loop, break at the hyphen, if required.
> 
> Of course, it is not very difficult to make this a bit fancier
> and avoid some breaks that make little sense - but this is what
> OpenBSD has now, and it helps us to get in sync.
> 
> I would rather put this in than back it out, if only because
> it makes automatic comparisons a lot easier...
> 
> This final patch is also here:
>   /usr/vhosts/mdocml.bsd.lv/patch/schwarze/09.break-at-hyphen.patch

I've checked in a modified version of this that only breaks at free-form
line hyphens along with a regression test.  It touches term.c (your
exact patch, Ingo, except with ASCII_HYPH instead of the hyphen), html.c
(to print a hyphen (NOT a soft-break, see note)), mdoc.c (sitting in
Ingo's white-space loop), and mandoc.c (for the actual function of
choosing).

The same happens in -man, but I'll wait til Ingo applies his white-space
code to -man for this to be implemented.

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

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

* Re: PATCH: break the line at an existing hyphen
  2010-05-25 12:49 ` Kristaps Dzonsons
@ 2010-05-26  3:04   ` Ingo Schwarze
  2010-05-26 11:37     ` Kristaps Dzonsons
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Schwarze @ 2010-05-26  3:04 UTC (permalink / raw)
  To: tech

Hi Kristaps,

> I've checked in a modified version of this that only breaks at free-form
> line hyphens along with a regression test.  It touches term.c (your
> exact patch, Ingo, except with ASCII_HYPH instead of the hyphen), html.c
> (to print a hyphen (NOT a soft-break, see note)), mdoc.c (sitting in
> Ingo's white-space loop), and mandoc.c (for the actual function of
> choosing).

This is awesome.  It gives much better results than what i had
before, see my commit message.  Thanks!

We are now in full sync, excepting UGLY, which i would like to
kick out of bsd.lv (the #ifdefs, not the code, of course).
Joerg, you wanted to look at UGLY, and comment on it, right?

> The same happens in -man, but I'll wait til Ingo applies his
> white-space code to -man for this to be implemented.

Oh, yet another TODO for me.  :-/

Besides, my nested block patch is pending -
i should polish and submit it.

And i've seen your .Li fix, Kristaps, but wont check it tonight.
I'm away tomorrow; maybe i can check right after midnight...

Yours,
  Ingo
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

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

* Re: PATCH: break the line at an existing hyphen
  2010-05-26  3:04   ` Ingo Schwarze
@ 2010-05-26 11:37     ` Kristaps Dzonsons
  0 siblings, 0 replies; 5+ messages in thread
From: Kristaps Dzonsons @ 2010-05-26 11:37 UTC (permalink / raw)
  To: tech

> We are now in full sync, excepting UGLY, which i would like to
> kick out of bsd.lv (the #ifdefs, not the code, of course).
> Joerg, you wanted to look at UGLY, and comment on it, right?

We can do this after, too; UGLY is enabled by default, so removing the 
ifdef won't change much.

>> The same happens in -man, but I'll wait til Ingo applies his
>> white-space code to -man for this to be implemented.
> 
> Oh, yet another TODO for me.  :-/

It's not an immediate thing but a long-term TODO.  Like I said, I don't 
want to spend too much time on that crap---necessary though it may be.

> Besides, my nested block patch is pending -
> i should polish and submit it.
> 
> And i've seen your .Li fix, Kristaps, but wont check it tonight.
> I'm away tomorrow; maybe i can check right after midnight...

Great!  Once that's ok'd/fixed/checked in to OpenBSD along with the 
other small bug-fixes from today, then let's bag and tag.  The 
description and so on are all ready

I'll try to stay awake as late as I can to catch any notes you may have 
for me.  My only pending nit is Ulrich's report on TH, which is an easy 
fix.  That and the mdoc.7 docs on the patch I sent out and some 
regressions for it.  The regressions won't be runnable on old groff 
because they'll assume Ar prints "file ..." on its first noop 
invocation, which it doesn't on old groff.

Thanks again,

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

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

end of thread, other threads:[~2010-05-26 11:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-24 23:32 PATCH: break the line at an existing hyphen Ingo Schwarze
2010-05-24 23:59 ` Kristaps Dzonsons
2010-05-25 12:49 ` Kristaps Dzonsons
2010-05-26  3:04   ` Ingo Schwarze
2010-05-26 11:37     ` 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).