Compare commits

...

3 commits

6 changed files with 67 additions and 83 deletions

View file

@ -40,6 +40,7 @@ KERNEL_SOURCES := \
src/window.c \ src/window.c \
src/keyboard.c \ src/keyboard.c \
src/unicode.c \ src/unicode.c \
src/interpreter.c \
$(KERNEL_SOURCES_$(ARCH)) \ $(KERNEL_SOURCES_$(ARCH)) \
# end of kernel sources list # end of kernel sources list

8
include/interpreter.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef KARLOS_INTERPRETER_H
#define KARLOS_INTERPRETER_H
#include <stdint.h>
void interpret_handle_input_line(const uint8_t *s);
#endif

View file

@ -1,3 +1,4 @@
#include "interpreter.h"
#include "keyboard.h" #include "keyboard.h"
#include "std.h" #include "std.h"
#include "console.h" #include "console.h"
@ -118,8 +119,15 @@ void cin_putc(uint32_t c)
window_glyph_to_framebuffer(&cin_win, cin_cursor_y, cin_cursor_x, true); window_glyph_to_framebuffer(&cin_win, cin_cursor_y, cin_cursor_x, true);
// do something with string // do something with string
void cin_handle_input_line(void); // convert to utf-8 first
cin_handle_input_line(); static uint8_t current_line_utf8[CONSOLE_MAX_COLS * 4];
uint8_t *stemp = current_line_utf8;
unsigned int idx = 0;
while (cin_line[idx] != 0) {
utf8_push_terminated(&stemp, cin_line[idx]);
idx += 1;
}
interpret_handle_input_line(current_line_utf8);
return; return;
} }
@ -194,55 +202,3 @@ void console_editor_key_event_listener(enum editor_key_event_kind kind, uint32_t
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
void cin_handle_input_line() {
// utf8-ize the current line
static uint8_t current_line_utf8[CONSOLE_MAX_COLS * 4];
uint8_t *stemp = current_line_utf8;
unsigned int idx = 0;
while (cin_line[idx] != 0) {
utf8_push_terminated(&stemp, cin_line[idx]);
idx += 1;
}
const uint8_t *s = current_line_utf8;
printf(">>> %s\n", s);
if (memcmp(s, "echo", 4) == 0) {
s += 4;
while (*s == ' ') {
s++;
}
if (*s != '"') {
printf("expected `echo` to be followed by enquoted string\n");
return;
}
s++;
// TODO escaped double quote
while (1) {
glyph g = utf8_next_asserted(&s);
if (g == 0) {
printf("unclosed delimiter\n");
return;
} else if (g == '"') {
break;
} else if (g == '\\') {
g = utf8_next_asserted(&s);
if (g != 'U') {
printf("unknown escape character\n");
return;
}
// TODO error handling
uint32_t codepoint = 0;
for (int i = 0; i < 4; i++) {
codepoint = (codepoint << 4) | hexchar_to_num(utf8_next_asserted(&s));
}
printf("%c", codepoint);
} else {
printf("%c", g);
}
}
putln();
} else {
printf("unknown command\n");
}
}

46
src/interpreter.c Normal file
View file

@ -0,0 +1,46 @@
#include "unicode.h"
#include "std.h"
#include "interpreter.h"
void interpret_handle_input_line(const uint8_t *s) {
printf(">>> %s\n", s);
if (memcmp(s, "echo", 4) == 0) {
s += 4;
while (*s == ' ') {
s++;
}
if (*s != '"') {
printf("expected `echo` to be followed by enquoted string\n");
return;
}
s++;
// TODO escaped double quote
while (1) {
unicode_char c = utf8_next_asserted(&s);
if (c == 0) {
printf("unclosed delimiter\n");
return;
} else if (c == '"') {
break;
} else if (c == '\\') {
c = utf8_next_asserted(&s);
if (c != 'U') {
printf("unknown escape character\n");
return;
}
// TODO error handling
uint32_t codepoint = 0;
for (int i = 0; i < 4; i++) {
codepoint = (codepoint << 4) | hexchar_to_num(utf8_next_asserted(&s));
}
printf("%c", codepoint);
} else {
printf("%c", c);
}
}
putln();
} else {
printf("unknown command\n");
}
}

View file

@ -1,31 +1,3 @@
/*
* Copyright (C) 2017 - 2021 bzt (bztsrc@gitlab)
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* This file is part of the BOOTBOOT Protocol package.
* @brief A sample BOOTBOOT compatible kernel
*
*/
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <cpuid.h> #include <cpuid.h>

View file

@ -219,7 +219,8 @@ void port1_handler(void) {
} }
void port2_handler(void) { void port2_handler(void) {
DEBUG_PRINTF("keycode from port 2: %X8\n", ps2_read_data()); uint8_t data = ps2_read_data();
DEBUG_PRINTF("keycode from port 2: %X8\n", data);
} }
#define PS2_INIT_PRINT #define PS2_INIT_PRINT