From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.rz.uni-karlsruhe.de (Debian-exim@smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id o4ONW3C6008692 for ; Mon, 24 May 2010 17:32:04 -0600 (MDT) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.63 #1) id 1OGh7q-0001wo-6v; Tue, 25 May 2010 01:32:02 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.71) (envelope-from ) id 1OGh7q-00052y-5W for tech@mdocml.bsd.lv; Tue, 25 May 2010 01:32:02 +0200 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1OGh7q-0003Xm-4a for tech@mdocml.bsd.lv; Tue, 25 May 2010 01:32:02 +0200 Received: from schwarze by usta.de with local (Exim 4.71) (envelope-from ) id 1OGh7p-0005bI-Qo for tech@mdocml.bsd.lv; Tue, 25 May 2010 01:32:01 +0200 Date: Tue, 25 May 2010 01:32:01 +0200 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: PATCH: break the line at an existing hyphen Message-ID: <20100524233201.GI21391@iris.usta.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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