ref: bb8d4fe83ef6e55a2189b1563512d129fc419700
parent: 9dafaab5aeb1533792b3e134ada90d5ab9a4d635
author: Ali Gholami Rudi <[email protected]>
date: Sun May 5 14:00:13 EDT 2013
reg: basic .ta support
--- a/reg.c
+++ b/reg.c
@@ -9,6 +9,7 @@
struct env {
int eregs[NENVS]; /* environment-specific number registers */
+ int tabs[NTABS]; /* tab stops */
struct adj *adj; /* per environment line buffer */
};
@@ -151,6 +152,7 @@
static void env_set(int id)
{
+ int i;
env = &envs[id];
if (!env->adj) {
env->adj = adj_alloc();
@@ -168,6 +170,8 @@
n_lt = SC_IN * 65 / 10;
adj_ll(env->adj, n_l);
adj_in(env->adj, n_i);
+ for (i = 0; i < NTABS; i++)
+ env->tabs[i] = i * SC_IN / 2;
}
}
@@ -233,4 +237,20 @@
n_s = o->s;
n_f0 = o->f0;
n_s0 = o->s0;
+}
+
+void tr_ta(char **args)
+{
+ int i;
+ for (i = 0; i < NARGS && args[i]; i++)
+ env->tabs[i] = eval_re(args[i], i > 0 ? env->tabs[i - 1] : 0, 'm');
+}
+
+int tab_next(int pos)
+{
+ int i;
+ for (i = 0; i < LEN(env->tabs); i++)
+ if (env->tabs[i] > pos)
+ return env->tabs[i];
+ return pos;
}
--- a/ren.c
+++ b/ren.c
@@ -509,7 +509,8 @@
wb_hmov(wb, eval(arg, 'm'));
break;
case 'k':
- num_set(REG(arg[0], arg[1]), f_hpos() - n_lb);
+ num_set(REG(arg[0], arg[1]),
+ wb == &ren_wb ? f_hpos() - n_lb : wb_wid(wb));
break;
case 'L':
ren_vline(wb, arg);
@@ -564,6 +565,11 @@
nextchar(c, next);
if (c[0] == ' ' || c[0] == '\n') {
wb_put(wb, c);
+ return;
+ }
+ if (c[0] == '\t' || c[0] == '') {
+ n = wb == &ren_wb ? f_hpos() : wb_wid(wb);
+ wb_hmov(wb, tab_next(n) - n);
return;
}
if (c[0] == c_ec) {
--- a/tr.c
+++ b/tr.c
@@ -613,6 +613,7 @@
{"so", tr_so},
{"sp", tr_sp},
{"sv", tr_sv},
+ {"ta", tr_ta},
{"ti", tr_ti},
{"tl", tr_tl, mkargs_null},
{"tm", tr_tm, mkargs_eol},
--- a/xroff.h
+++ b/xroff.h
@@ -20,6 +20,7 @@
#define NPREV 16 /* environment stack depth */
#define NTRAPS 1024 /* number of traps per page */
#define NIES 128 /* number of nested .ie commands */
+#define NTABS 16 /* the number of tab stops */
/* escape sequences */
#define ESC_Q "bCDhHlLNoSvwxX" /* quoted escape sequences */
@@ -62,6 +63,7 @@
void env_init(void);
void env_free(void);
struct adj *env_adj(void);
+int tab_next(int pos);
/* device related variables */
extern int dev_res;
@@ -237,6 +239,7 @@
void tr_rt(char **args);
void tr_sp(char **args);
void tr_sv(char **args);
+void tr_ta(char **args);
void tr_ti(char **args);
void tr_wh(char **args);