ref: bd9f2e1a9953674874080f9c2478fc0041a98049
parent: cf5d7677e060b048d908ceb0600157e902f32220
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Aug 31 14:43:09 EDT 2013
wb: fix handling the first and the last two characters for .hy
--- a/roff.h
+++ b/roff.h
@@ -240,8 +240,8 @@
/* hyphenation flags */
#define HY_MASK 0x0f /* enable hyphenation */
#define HY_LAST 0x02 /* do not hyphenate last lines */
-#define HY_FINAL 0x04 /* do not hyphenate the final character */
-#define HY_FIRSTTWO 0x08 /* do not hyphenate the first two characters */
+#define HY_FINAL2 0x04 /* do not hyphenate the final two characters */
+#define HY_FIRST2 0x08 /* do not hyphenate the first two characters */
#define HY_ANY 0x10 /* break at any possible position */
void hyphenate(char *hyphs, char *word);
--- a/wb.c
+++ b/wb.c
@@ -359,7 +359,7 @@
return 0;
}
-static char *dashpos(char *s, int w, struct wb *w1, int any)
+static char *dashpos(char *s, int w, struct wb *w1, int flg)
{
char d[ILNLEN];
char *r = NULL;
@@ -367,7 +367,7 @@
skipreqs(&s, w1);
while ((c = escread(&s, d)) >= 0) {
wb_putc(w1, c, d);
- if (wb_wid(w1) > w && (!any || r))
+ if (wb_wid(w1) > w && (!(flg & HY_ANY) || r))
continue;
if (!c && (!strcmp("-", d) || (!strcmp("em", d) || !strcmp("hy", d))))
r = s;
@@ -423,8 +423,8 @@
if (strlen(word) < 4)
return NULL;
hyphenate(hyph, word);
- beg = flg & HY_FIRSTTWO ? 3 : 2;
- end = strlen(word) - (flg & HY_FINAL ? 2 : 1);
+ beg = flg & HY_FIRST2 ? 3 : 2;
+ end = strlen(word) - (flg & HY_FINAL2 ? 2 : 1);
for (i = beg; i < end; i++)
if (map[i] && hyph[i] && (fits[i] || ((flg & HY_ANY) && !r)))
r = map[i];
@@ -455,14 +455,14 @@
char *dp, *hp, *p;
if (skipreqs(&s, w1))
return 1;
- dp = dashpos(sbuf_buf(&wb->sbuf), w, w1, flg & HY_ANY);
- hp = indicatorpos(sbuf_buf(&wb->sbuf), w, w1, flg & HY_ANY);
+ dp = dashpos(sbuf_buf(&wb->sbuf), w, w1, flg);
+ hp = indicatorpos(sbuf_buf(&wb->sbuf), w, w1, flg);
if (hp && dp)
p = flg & HY_ANY ? MIN(dp, hp) : MAX(dp, hp);
else
p = dp ? dp : hp;
if (!p && flg & HY_MASK)
- p = hyphpos(sbuf_buf(&wb->sbuf), w, w1, flg & HY_ANY);
+ p = hyphpos(sbuf_buf(&wb->sbuf), w, w1, flg);
if (p)
dohyph(sbuf_buf(&wb->sbuf), p, p != dp, w1, w2);
return !p;