ref: 945538cfba3ce64d505ed4e944a21a8d5b85ebb8
parent: 69e9e62bae8ef3eb372d06d143349a5d2b429cee
author: Ali Gholami Rudi <[email protected]>
date: Fri Nov 23 13:56:56 EST 2012
tr: handle the second argument of .de
--- a/tr.c
+++ b/tr.c
@@ -95,24 +95,34 @@
str_set(N_ID(args[1][0], args[1][1]), args[2]);
}
+static char *arg_regname(char *s, int len);
+
static void tr_de(int argc, char **args)
{
struct sbuf sbuf;
+ char buf[4];
+ int end[4] = {'.'};
int c;
+ int i;
if (argc <= 1)
return;
+ if (argc > 2 && args[2]) {
+ end[0] = args[2][0];
+ end[1] = args[2][1];
+ }
sbuf_init(&sbuf);
while ((c = cp_next()) >= 0) {
sbuf_add(&sbuf, c);
if (c == '\n') {
+ sbuf_add(&sbuf, c);
c = cp_next();
if (c == '.') {
- c = cp_next();
- if (c == '.')
+ arg_regname(buf, 4);
+ if (buf[0] == end[0] && buf[1] == end[1])
break;
sbuf_add(&sbuf, '.');
- if (c >= 0)
- sbuf_add(&sbuf, c);
+ for (i = 0; buf[i]; i++)
+ sbuf_add(&sbuf, (unsigned char) buf[i]);
} else {
if (c >= 0)
sbuf_add(&sbuf, c);