diff options
author | Devin J. Pohly <djpohly@gmail.com> | 2018-02-22 01:05:12 -0600 |
---|---|---|
committer | Devin J. Pohly <djpohly@gmail.com> | 2018-02-25 21:53:24 -0600 |
commit | 33201ac65f74e45b4fa60822ba9a538c3cfa9b25 (patch) | |
tree | d14efba42f31bc0f4900a9af90988093464ad781 /st.c | |
parent | 52d6fb1ab1f7d41839edebb63c3408578cd44e3c (diff) | |
download | st-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.c | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -108,6 +108,7 @@ typedef struct { | |||
108 | static void execsh(char **); | 108 | static void execsh(char **); |
109 | static void stty(char **); | 109 | static void stty(char **); |
110 | static void sigchld(int); | 110 | static void sigchld(int); |
111 | static void ttywriteraw(const char *, size_t); | ||
111 | 112 | ||
112 | static void csidump(void); | 113 | static void csidump(void); |
113 | static void csihandle(void); | 114 | static void csihandle(void); |
@@ -786,13 +787,38 @@ ttyread(void) | |||
786 | void | 787 | void |
787 | ttywrite(const char *s, size_t n, int may_echo) | 788 | ttywrite(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 | |||
815 | void | ||
816 | ttywriteraw(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 |