ref: 8caa9b49f50c87a48c0981d503f3aad70fcb9571
parent: 7dc83e802fffc3e9054df4f04dd8bf601294e0c5
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Apr 26 12:14:47 EDT 2013
ren: add .ce
--- a/reg.c
+++ b/reg.c
@@ -29,6 +29,7 @@
REG('.', 's'),
REG('.', 'u'),
REG('.', 'v'),
+ REG(0, 'c'),
REG(0, 'f'),
REG(0, 'i'),
REG(0, 'l'),
--- a/ren.c
+++ b/ren.c
@@ -201,6 +201,8 @@
n_n = w;
if (n_u && !n_na && (n_j == AD_C || n_j == AD_R))
ljust = n_j == AD_C ? (llen - w) / 2 : llen - w;
+ if (n_ce)
+ ljust = llen > w ? (llen - w) / 2 : 0;
if (cdiv) {
if (cdiv->dl < w)
cdiv->dl = w;
@@ -221,11 +223,12 @@
{
char buf[LNLEN];
int ll, li, lt, els_neg, els_pos;
- int adj_b, w, prev_d;
+ int adj_b, fill, w, prev_d;
ren_first();
- if (!adj_empty(cadj, n_u)) {
- adj_b = n_u && !n_na && n_j == AD_B;
- w = adj_fill(cadj, !force && adj_b, !force && n_u, buf,
+ if (!adj_empty(cadj, !n_ce && n_u)) {
+ adj_b = !n_ce && n_u && !n_na && n_j == AD_B;
+ fill = !n_ce && n_u;
+ w = adj_fill(cadj, !force && adj_b, !force && fill, buf,
&ll, &li, <, &els_neg, &els_pos);
prev_d = n_d;
if (els_neg)
@@ -410,6 +413,13 @@
n_u = 1;
}
+void tr_ce(char **args)
+{
+ if (args[0][0] == '.')
+ ren_br(1);
+ n_ce = args[1] ? atoi(args[1]) : 1;
+}
+
static void escarg_ren(char *d, int cmd, int (*next)(void), void (*back)(int))
{
int c, q;
@@ -632,10 +642,12 @@
ren_back(c);
ren_char(cadj, ren_next, ren_back);
}
- while (adj_full(cadj, n_u))
+ while (adj_full(cadj, !n_ce && n_u))
ren_br(0);
- if (c == '\n')
+ if (c == '\n') { /* end of input line */
n_lb = adj_wid(cadj);
+ n_ce = MAX(0, n_ce - 1);
+ }
if (c != ' ' && c != '\n') {
ren_back(c);
ren_char(cadj, ren_next, ren_back);
--- a/tr.c
+++ b/tr.c
@@ -460,6 +460,7 @@
{"as", tr_as, mkargs_ds},
{"bp", tr_bp},
{"br", tr_br},
+ {"ce", tr_ce},
{"ch", tr_ch},
{"da", tr_di},
{"de", tr_de, mkargs_reg1},
--- a/xroff.h
+++ b/xroff.h
@@ -131,6 +131,7 @@
/* troff commands */
void tr_bp(char **args);
void tr_br(char **args);
+void tr_ce(char **args);
void tr_ch(char **args);
void tr_di(char **args);
void tr_divbeg(char **args);
@@ -225,6 +226,7 @@
#define n_nl (*nreg(REG('n', 'l')))
#define n_pg (*nreg(REG('%', '\0'))) /* % */
#define n_lb (*nreg(REG(0, 'b'))) /* input line beg */
+#define n_ce (*nreg(REG(0, 'c'))) /* .ce remaining */
#define n_f0 (*nreg(REG(0, 'f'))) /* last .f */
#define n_i0 (*nreg(REG(0, 'i'))) /* last .i */
#define n_l0 (*nreg(REG(0, 'l'))) /* last .l */