ref: 65520b32b06bc03f4dd23383a5e064d4be1107e9
parent: 3f75e6b03cac20d823466414ad8d72dc02232e26
author: Ali Gholami Rudi <[email protected]>
date: Thu Jul 25 12:28:10 EDT 2013
ren: add .mc
--- a/reg.c
+++ b/reg.c
@@ -6,7 +6,7 @@
#include <time.h>
#include "roff.h"
-#define NENVS 32 /* number of environment registers */
+#define NENVS 64 /* number of environment registers */
struct env {
int eregs[NENVS]; /* environment-specific number registers */
@@ -13,6 +13,7 @@
int tabs[NTABS]; /* tab stops */
struct adj *adj; /* per environment line buffer */
char hc[GNLEN]; /* hyphenation character */
+ char mc[GNLEN]; /* margin character (.mc) */
};
static int nregs[NREGS2]; /* global number registers */
@@ -29,7 +30,7 @@
"ln", ".f", ".i", ".j", ".l",
".L", ".nI", ".nm", ".nM", ".nn",
".nS", ".m", ".s", ".u", ".v",
- ".it", ".itn",
+ ".it", ".itn", ".mc", ".mcn",
"\0c", "\0f", "\0h", "\0i", "\0l",
"\0L", "\0n", "\0m", "\0p", "\0s",
"\0t", "\0T", "\0v",
@@ -247,6 +248,11 @@
char *env_hc(void)
{
return env->hc;
+}
+
+char *env_mc(void)
+{
+ return env->mc;
}
/* saving and restoring registers around diverted lines */
--- a/ren.c
+++ b/ren.c
@@ -292,6 +292,18 @@
n_ln++;
}
+/* append margin character */
+static void ren_mc(struct sbuf *sbuf, int w)
+{
+ struct wb wb;
+ wb_init(&wb);
+ if (w < n_l + n_mcn)
+ wb_hmov(&wb, n_l + n_mcn - w);
+ wb_put(&wb, c_mc);
+ sbuf_append(sbuf, sbuf_buf(&wb.sbuf));
+ wb_done(&wb);
+}
+
/* return 1 if triggered a trap */
static int ren_bradj(struct adj *adj, int fill, int ad, int body)
{
@@ -312,6 +324,8 @@
ren_sp(0, 0);
if (!sbuf_empty(&sbuf) && n_nm && body)
ren_lnum(&spre);
+ if (!sbuf_empty(&sbuf) && body && n_mc)
+ ren_mc(&sbuf, w);
ren_ljust(&spre, w, ad, ll, li, lt);
ren_line(&spre, &sbuf);
n_ns = 0;
--- a/roff.h
+++ b/roff.h
@@ -41,6 +41,7 @@
extern int c_c2; /* no-break control character (') */
#define c_ni 4 /* non-interpreted copy mode escape */
#define c_hc env_hc()/* hyphenation character */
+#define c_mc env_mc()/* margin character (.mc) */
/* number registers */
int num_get(int id, int inc);
@@ -72,6 +73,7 @@
void env_done(void);
struct adj *env_adj(void);
char *env_hc(void);
+char *env_mc(void);
int tab_next(int pos);
/* device related variables */
@@ -344,6 +346,8 @@
#define n_nn (*nreg(map(".nn"))) /* remaining .nn */
#define n_nS (*nreg(map(".nS"))) /* s for .nm */
#define n_m (*nreg(REG('.', 'm')))
+#define n_mc (*nreg(map(".mc"))) /* .mc enabled */
+#define n_mcn (*nreg(map(".mcn"))) /* .mc distance */
#define n_o (*nreg(REG('.', 'o')))
#define n_p (*nreg(REG('.', 'p')))
#define n_s (*nreg(REG('.', 's')))
--- a/tr.c
+++ b/tr.c
@@ -491,6 +491,17 @@
}
}
+static void tr_mc(char **args)
+{
+ if (args[1]) {
+ n_mc = 1;
+ strcpy(c_mc, args[1]);
+ n_mcn = args[2] ? eval(args[2], 'm') : SC_EM;
+ } else {
+ n_mc = 0;
+ }
+}
+
static char *arg_regname(char *s, int len)
{
char *e = n_cp ? s + 2 : s + len;
@@ -703,6 +714,7 @@
{"ll", tr_ll},
{"ls", tr_ls},
{"lt", tr_lt},
+ {"mc", tr_mc},
{"mk", tr_mk},
{"na", tr_na},
{"ne", tr_ne},