aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2018-02-22 01:05:12 -0600
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:53:24 -0600
commit33201ac65f74e45b4fa60822ba9a538c3cfa9b25 (patch)
treed14efba42f31bc0f4900a9af90988093464ad781 /st.c
parent52d6fb1ab1f7d41839edebb63c3408578cd44e3c (diff)
downloadst-33201ac65f74e45b4fa60822ba9a538c3cfa9b25.tar.gz
st-33201ac65f74e45b4fa60822ba9a538c3cfa9b25.zip
Move CRLF input processing into ttywrite
This also allows us to remove the crlf field from the Key struct, since the only difference it made was converting "\r" to "\r\n" (which is now done automatically in ttywrite). In addition, MODE_CRLF is no longer referenced from x.c. Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Diffstat (limited to 'st.c')
-rw-r--r--st.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/st.c b/st.c
index 7d546da..3ebf8c6 100644
--- a/st.c
+++ b/st.c
@@ -108,6 +108,7 @@ typedef struct {
108static void execsh(char **); 108static void execsh(char **);
109static void stty(char **); 109static void stty(char **);
110static void sigchld(int); 110static void sigchld(int);
111static void ttywriteraw(const char *, size_t);
111 112
112static void csidump(void); 113static void csidump(void);
113static void csihandle(void); 114static void csihandle(void);
@@ -786,13 +787,38 @@ ttyread(void)
786void 787void
787ttywrite(const char *s, size_t n, int may_echo) 788ttywrite(const char *s, size_t n, int may_echo)
788{ 789{
789 fd_set wfd, rfd; 790 const char *next;
790 ssize_t r;
791 size_t lim = 256;
792 791
793 if (may_echo && IS_SET(MODE_ECHO)) 792 if (may_echo && IS_SET(MODE_ECHO))
794 twrite(s, n, 1); 793 twrite(s, n, 1);
795 794
795 if (!IS_SET(MODE_CRLF)) {
796 ttywriteraw(s, n);
797 return;
798 }
799
800 /* This is similar to how the kernel handles ONLCR for ttys */
801 while (n > 0) {
802 if (*s == '\r') {
803 next = s + 1;
804 ttywriteraw("\r\n", 2);
805 } else {
806 next = memchr(s, '\r', n);
807 DEFAULT(next, s + n);
808 ttywriteraw(s, next - s);
809 }
810 n -= next - s;
811 s = next;
812 }
813}
814
815void
816ttywriteraw(const char *s, size_t n)
817{
818 fd_set wfd, rfd;
819 ssize_t r;
820 size_t lim = 256;
821
796 /* 822 /*
797 * Remember that we are using a pty, which might be a modem line. 823 * Remember that we are using a pty, which might be a modem line.
798 * Writing too much will clog the line. That's why we are doing this 824 * Writing too much will clog the line. That's why we are doing this