diff options
author | unknown <unknown@unknown> | 2009-09-01 13:24:17 +0000 |
---|---|---|
committer | unknown <unknown@unknown> | 2009-09-01 13:24:17 +0000 |
commit | 1e2a739ede68f904c84ea693362fdd4445c4fc16 (patch) | |
tree | c812acb3606017e6a4334a0b6ce24f769c73c5eb /bin/hpuifilter.c | |
parent | 09f0f026fd4931b90016d0090778983da01c294a (diff) | |
download | rancid-1e2a739ede68f904c84ea693362fdd4445c4fc16.tar.gz rancid-1e2a739ede68f904c84ea693362fdd4445c4fc16.tar.xz rancid-1e2a739ede68f904c84ea693362fdd4445c4fc16.zip |
Imported from rancid-2.3.2a10.tar.gz.rancid-2.3.2a10
Diffstat (limited to 'bin/hpuifilter.c')
-rw-r--r-- | bin/hpuifilter.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/bin/hpuifilter.c b/bin/hpuifilter.c index ab437f7..69569d8 100644 --- a/bin/hpuifilter.c +++ b/bin/hpuifilter.c @@ -141,7 +141,7 @@ main(int argc, char **argv, char **ev) hbuf[BUFSZ], /* hlogin buffer */ ptyname[FILENAME_MAX + 1], tbuf[BUFSZ], /* telnet/ssh buffer */ - tbufstr[4] = {ESC, '\r', '\n', '\0'}; + tbufstr[5] = {ESC, '\x07', '\r', '\n', '\0'}; int bytes, /* bytes read/written */ devnull, rval = EX_OK, @@ -533,7 +533,8 @@ int filter(char *buf, int len) { static regmatch_t pmatch[1]; -#define N_REG 14 /* number of regexes in reg[][] */ +#define N_REG 15 /* number of regexes in reg[][] */ +#define N_CRs 2 /* number of CR replacements */ static regex_t preg[N_REG]; static char reg[N_REG][50] = { /* vt100/220 escape codes */ "\x1B""7\x1B\\[1;24r\x1B""8", /* ds */ @@ -551,21 +552,23 @@ filter(char *buf, int len) "\x1B\\[\\?25l", /* vi */ "\x1B\\[K", /* ce */ "\x1B\\[7m", /* mr - ansi */ + "\x07", /* bell */ /* replace these with CR */ "\x1B\\[0m", /* me */ "\x1B""E", }; - char ebuf[256]; + char bufstr[3] = {ESC, '\x07', '\0'}, + ebuf[256]; size_t nmatch = 1; int err, x; static int init = 0; - if (index(buf, ESC) == 0 || len == 0) + if (len == 0 || (err = strcspn(buf, bufstr)) >= len) return(len); - for (x = 0; x < N_REG - 2; x++) { + for (x = 0; x < N_REG - N_CRs; x++) { if (! init) { if ((err = regcomp(&preg[x], reg[x], REG_EXTENDED))) { regerror(err, &preg[x], ebuf, 256); @@ -587,9 +590,9 @@ filter(char *buf, int len) } } - /* no the CR NL replacements */ + /* now the CR NL replacements */ if (! init++) { - for (x = N_REG - 2; x < N_REG; x++) + for (x = N_REG - N_CRs; x < N_REG; x++) if ((err = regcomp(&preg[x], reg[x], REG_EXTENDED))) { regerror(err, &preg[x], ebuf, 256); fprintf(stderr, "%s: regex compile failed: %s\n", progname, @@ -597,7 +600,7 @@ filter(char *buf, int len) abort(); } } - for (x = N_REG - 2; x < N_REG; x++) { + for (x = N_REG - N_CRs; x < N_REG; x++) { if ((err = regexec(&preg[x], buf, nmatch, pmatch, 0))) { if (err != REG_NOMATCH) { regerror(err, &preg[x], ebuf, 256); |