From b7ad35d0403d9853baf9ca7a8ba3a22a06bdaebf Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 14 Mar 2019 18:33:21 +0100 Subject: [PATCH] Terminal: Enough compat work for Lynx to actually load web pages. --- Applications/Terminal/Terminal.cpp | 17 +++++++-- Applications/Terminal/Terminal.h | 2 + LibC/stdlib.cpp | 59 ++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index 36afb29b2dc..1e3a7715700 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -316,8 +316,10 @@ void Terminal::escape$K(const Vector& params) } break; case 1: - // FIXME: Clear from cursor to beginning of screen. - unimplemented_escape(); + // Clear from cursor to beginning of line. + for (int i = 0; i < m_cursor_column; ++i) { + put_character_at(m_cursor_row, i, ' '); + } break; case 2: unimplemented_escape(); @@ -504,7 +506,10 @@ void Terminal::on_char(byte ch) case ExpectBracket: if (ch == '[') m_escape_state = ExpectParameter; - else if (ch == ']') + else if (ch == '(') { + m_swallow_current = true; + m_escape_state = ExpectParameter; + } else if (ch == ']') m_escape_state = ExpectXtermParameter1; else m_escape_state = Normal; @@ -545,10 +550,13 @@ void Terminal::on_char(byte ch) case ExpectFinal: if (is_valid_final_character(ch)) { m_escape_state = Normal; - execute_escape_sequence(ch); + if (!m_swallow_current) + execute_escape_sequence(ch); + m_swallow_current = false; return; } m_escape_state = Normal; + m_swallow_current = false; return; case Normal: break; @@ -559,6 +567,7 @@ void Terminal::on_char(byte ch) return; case '\033': m_escape_state = ExpectBracket; + m_swallow_current = false; return; case 8: // Backspace if (m_cursor_column) { diff --git a/Applications/Terminal/Terminal.h b/Applications/Terminal/Terminal.h index 6cac271c770..a79740a37d0 100644 --- a/Applications/Terminal/Terminal.h +++ b/Applications/Terminal/Terminal.h @@ -145,6 +145,8 @@ private: int m_ptm_fd { -1 }; + bool m_swallow_current { false }; + bool m_in_active_window { false }; bool m_need_full_flush { false }; diff --git a/LibC/stdlib.cpp b/LibC/stdlib.cpp index 68281627ccb..f79328aa1fa 100644 --- a/LibC/stdlib.cpp +++ b/LibC/stdlib.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -404,11 +405,61 @@ int atexit(void (*function)()) assert(false); } -long strtol(const char*, char** endptr, int base) +long strtol(const char* str, char** endptr, int base) { - (void)endptr; - (void)base; - assert(false); + const char* s = str; + unsigned long acc; + int c; + unsigned long cutoff; + int neg = 0; + int any; + int cutlim; + + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + + cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; + cutlim = cutoff % (unsigned long)base; + cutoff /= (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LONG_MIN : LONG_MAX; + errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr) + *endptr = (char*)(any ? s - 1 : str); + return acc; } unsigned long strtoul(const char*, char** endptr, int base)