Compare commits

...

2 Commits

4 changed files with 23 additions and 4 deletions

View File

@ -8,4 +8,5 @@ int strncmp(const char *s1, const char *s2, size_t n);
size_t strlen(const char *str);
char *strstr(const char *haystack, const char *needle);
void *memcpy(void *dest, const void *src, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
void *memset(void *str, int c, size_t n);

View File

@ -0,0 +1,11 @@
#include <stddef.h>
#include <stdint.h>
void *memset(void *str, int c, size_t n)
{
uint8_t *c1 = (uint8_t *)str;
for (size_t i = 0; i < n; i++)
c1[i] = c;
return c1;
}

View File

@ -40,7 +40,7 @@ static CMD_TOK find_command(char *line)
return command;
}
static void read_line(char *buf, size_t size)
static void read_line(void)
{
size_t i = 0;
struct key_event ev;
@ -50,6 +50,9 @@ static void read_line(char *buf, size_t size)
ev = terminal_getkey();
if (ev.c == '\n')
break;
char *buf = screen->line;
i = strlen(screen->line);
const size_t size = sizeof(screen->line);
if (prev_scan_code != ev.scan_code && ev.scan_code) {
if (ev.scan_code == KEY_BACKSPACE && i) {
buf[--i] = '\0';
@ -67,14 +70,14 @@ static void read_line(char *buf, size_t size)
prev_scan_code = ev.scan_code;
}
kprintf(0, "\n");
buf[i] = '\0';
screen->line[i] = '\0';
}
void shell_init(void)
{
while (1) {
kprintf(0, PROMPT);
read_line(screen->line, sizeof(screen->line));
read_line();
switch (find_command(screen->line)) {
case HELP:
kprintf(0, "Welcome to bozOShell, the shell of "
@ -107,5 +110,6 @@ void shell_init(void)
default:
break;
}
memset(screen->line, '\0', sizeof(screen->line));
}
}

View File

@ -1,5 +1,6 @@
#include "ctype.h"
#include "kprintf.h"
#include "shell.h"
#include "string.h"
#include "sys/io.h"
#include "terminal.h"
@ -44,6 +45,8 @@ void terminal_set_screen(int pos)
screen = &screens[pos];
memcpy(TERM_BUF, screen->buffer, sizeof(screen->buffer));
update_cursor();
if (TERM_BUF[0] == vga_entry(' ', VGA_COLOR_WHITE))
kprintf(0, PROMPT);
}
void terminal_setcolor(uint8_t color)