ref: 530fdaf748fa76b50dcfdcb6573aa2c223b70798
parent: ad7078ab39dda36b08c4e673202bf5b34cd56acb
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Mar 2 08:41:27 EST 2018
tr: .shift request Suggested and tested by aksr <aksr@t-com.me>.
--- a/in.c
+++ b/in.c
@@ -158,6 +158,19 @@
return n;
}
+void in_shift(void)
+{
+ struct inbuf *cur = buf;
+ while (cur && !cur->args)
+ cur = cur->prev;
+ if (cur && cur->args) {
+ free(cur->args[1]);
+ memmove(cur->args + 1, cur->args + 2,
+ (NARGS - 2) * sizeof(cur->args[0]));
+ cur->args[NARGS - 1] = NULL;
+ }
+}
+
char *in_filename(void)
{
struct inbuf *cur = buf;
--- a/roff.h
+++ b/roff.h
@@ -192,6 +192,7 @@
void in_queue(char *path); /* queue the given input file */
char *in_arg(int i); /* look up argument */
int in_nargs(void); /* number of arguments */
+void in_shift(void); /* shift the arguments */
void in_back(int c); /* push back input character */
int in_top(void); /* the first pushed-back character */
char *in_filename(void); /* current filename */
--- a/tr.c
+++ b/tr.c
@@ -369,6 +369,13 @@
in_nx(args[1]);
}
+static void tr_shift(char **args)
+{
+ int n = args[1] ? atoi(args[1]) : 1;
+ while (n-- >= 1)
+ in_shift();
+}
+
static void tr_ex(char **args)
{
in_ex();
@@ -1140,6 +1147,7 @@
{"rr", tr_rr},
{"rs", tr_rs},
{"rt", tr_rt},
+ {"shift", tr_shift},
{"so", tr_so},
{"sp", tr_sp},
{"ss", tr_ss},