ref: 448bf37d981536c7005c3d5c3946b026844c523b
parent: 845bbd9aa28e33ce64d3c4d512c8cccb4d14c7df
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Jan 1 10:41:33 EST 2015
fmt: .hlm request Suggested by Carsten Kunze <carsten.kunze@arcor.de>.
--- a/fmt.c
+++ b/fmt.c
@@ -384,11 +384,11 @@
return ratio * ratio / 100l * (nspc ? nspc : 1);
}
-/* the number of hyphenations in consecutive lines ending at pos (2 at most) */
+/* the number of hyphenations in consecutive lines ending at pos */
static int fmt_hydepth(struct fmt *f, int pos)
{
int n = 0;
- while (pos > 0 && f->words[pos - 1].hy && ++n < 2)
+ while (pos > 0 && f->words[pos - 1].hy && ++n < 5)
pos = f->best_pos[pos];
return n;
}
@@ -395,6 +395,8 @@
static long hycost(int depth)
{
+ if (n_hlm > 0 && depth > n_hlm)
+ return 10000000;
if (depth >= 3)
return n_hycost + n_hycost2 + n_hycost3;
if (depth == 2)
@@ -426,9 +428,8 @@
swid += f->words[i + 1].gap;
nspc++;
}
- if (lwid - (swid * n_ssh / 100) > llen)
- if (pos - i > 1)
- break;
+ if (lwid > llen + swid * n_ssh / 100 && i + 1 < pos)
+ break;
cur = fmt_findcost(f, i) + FMT_COST(llen, lwid, swid, nspc);
if (hyphenated)
cur += hycost(1 + fmt_hydepth(f, i));
@@ -581,7 +582,7 @@
end = end_head;
}
/* recursively add lines */
- n = fmt_break(f, end);
+ n = end > 0 ? fmt_break(f, end) : 0;
f->nwords -= n;
f->fillreq -= n;
fmt_movewords(f, 0, n, f->nwords);
--- a/reg.c
+++ b/reg.c
@@ -37,7 +37,8 @@
".L", ".nI", ".nm", ".nM", ".nn",
".nS", ".m", ".s", ".u", ".v",
".it", ".itn", ".mc", ".mcn",
- ".ce", ".f0", ".hy", ".hycost", ".hycost2",".hycost3", ".i0", ".l0",
+ ".ce", ".f0", ".i0", ".l0",
+ ".hy", ".hycost", ".hycost2", ".hycost3", ".hlm",
".L0", ".m0", ".n0", ".s0", ".ss", ".ssh", ".sss", ".pmll", ".pmllcost",
".ti", ".lt", ".lt0", ".v0",
};
--- a/roff.h
+++ b/roff.h
@@ -469,6 +469,7 @@
#define n_hycost (*nreg(map(".hycost"))) /* hyphenation cost */
#define n_hycost2 (*nreg(map(".hycost2"))) /* hyphenation cost #2 */
#define n_hycost3 (*nreg(map(".hycost3"))) /* hyphenation cost #3 */
+#define n_hlm (*nreg(map(".hlm"))) /* .hlm */
#define n_i0 (*nreg(map(".i0"))) /* last .i */
#define n_ti (*nreg(map(".ti"))) /* pending .ti */
#define n_kn (*nreg(map(".kn"))) /* .kn mode */
--- a/tr.c
+++ b/tr.c
@@ -459,6 +459,11 @@
n_hy = args[1] ? eval_re(args[1], n_hy, '\0') : 1;
}
+static void tr_hlm(char **args)
+{
+ n_hlm = args[1] ? eval_re(args[1], n_hlm, '\0') : 0;
+}
+
static void tr_hycost(char **args)
{
n_hycost = args[1] ? eval_re(args[1], n_hycost, '\0') : 0;
@@ -1003,6 +1008,7 @@
{"fzoom", tr_fzoom},
{"hc", tr_hc},
{"hcode", tr_hcode},
+ {"hlm", tr_hlm},
{"hpf", tr_hpf},
{"hpfa", tr_hpfa},
{"hy", tr_hy},