From 8bf013602dbc29695883e00b999ac5703a254d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 24 Jul 2021 01:06:42 +0200 Subject: Handle tabs converted to spaces in echo from server --- rtty.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/rtty.c b/rtty.c index 50b79e8..297b699 100644 --- a/rtty.c +++ b/rtty.c @@ -130,14 +130,16 @@ main(int argc, char *argv[]) * Escaped commands are recognized only after a * remote shell prompt. */ - if(!(escape && bufin[0] == '!' + if(escape && bufin[0] == '!' && (strcmp(bufout+strlen(bufout)-2, "$ ") == 0 || strcmp(bufout+strlen(bufout)-2, "% ") == 0 - || strcmp(bufout+strlen(bufout)-2, "# ") == 0))){ - dprintf(fdin, "%s", bufin); - continue; - } + || strcmp(bufout+strlen(bufout)-2, "# ") == 0)) + goto escape; + + dprintf(fdin, "%s", bufin); + continue; +escape: /* * Get remote working directory. (The response * looks like "pwd\n(directory)\n(prompt)".) @@ -169,8 +171,7 @@ main(int argc, char *argv[]) found: if(eargv[i+1]){ - fprintf(stderr, - "more than one file given\n"); + fprintf(stderr, "more than one file given\n"); goto done; } @@ -244,7 +245,7 @@ done: } /* - * System output is read from the output pipe and copied + * Remote output is read from the output pipe and copied * to standard out for the user to see. */ FD_SET(fdout, &rfds1); @@ -257,6 +258,7 @@ done: * skipped, assuming that bufin contains the * command in its entirety. */ + i = 0; p = bufin; q = bufout; for(;;){ @@ -264,15 +266,19 @@ done: q++; break; } - if(*q == 13){ + if(*q == '\r'){ q++; continue; } + if(*p == '\t' && strspn(q, " ") >= 8-i%8){ + p++; q += 8-i%8; i += 8-i%8; + continue; + } if(*p != *q){ q = bufout; break; } - p++; q++; + p++; q++; i++; } /* Don't skip the echo again. */ -- cgit v1.2.3