Skip to content

Commit

Permalink
Crappy but working interactive shell :3
Browse files Browse the repository at this point in the history
  • Loading branch information
Twometer committed Jan 27, 2021
1 parent ad88311 commit 397d944
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 46 deletions.
10 changes: 5 additions & 5 deletions kernel/device/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void Keyboard::Initialize()
NewScancode(5, '4');
NewScancode(6, '5');
NewScancode(7, '6');
NewScancode(8, '7');
NewScancode(8, '/');
NewScancode(9, '8');
NewScancode(10, '9');
NewScancode(11, '0');
Expand Down Expand Up @@ -92,15 +92,15 @@ size_t Keyboard::ReadUntil(char *dst, size_t maxSize, char delim)
if (idx < 0)
return 0;

idx++; // include the delim itself

auto bufSize = buf.Size();
auto size = bufSize > maxSize ? maxSize : bufSize;
auto size = idx > maxSize ? maxSize : idx;

for (size_t i = 0; i < size; i++)
dst[i] = buf[i];

buf.RemoveBlock(0, size);

if (buf.Size() > 0 && buf[0] == '\n')
buf.Remove(0);
return size;
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extern "C"
// Banner
TTY::Clear();
TTY::SetColor(0x9f);
printf("nekosys 0.04\n");
printf("nekosys 0.05\n");
kdbg("Booting koneko kernel...\n");
TTY::SetColor(0x07);

Expand Down
4 changes: 2 additions & 2 deletions libc/string/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int streq(const char *a, const char *b)
size_t alen = strlen(a);
size_t blen = strlen(b);
if (alen != blen)
return 0;
return 1;

return memcmp(a, b, alen) != 0;
return memcmp(a, b, alen);
}
57 changes: 19 additions & 38 deletions userland/shell/main.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,32 @@
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <nekosys.h>

int main(int argc, char **argv)
{
printf("Opening file...\n");
FILE *file = fopen("/home/neko/test.txt", "r");
printf("opened\n");
char *buf = new char[512];

fseek(file, 0, SEEK_END);
size_t filesize = ftell(file);
fseek(file, 0, SEEK_SET);
printf("Test file has size %d.\n", filesize);

uint8_t *data = new uint8_t[filesize + 1];
data[filesize] = 0;

fread(data, 1, filesize, file);

printf("File test contents: %s\n", data);

fclose(file);
delete[] data;

printf("sleeping for 5 secs...\n");
//sleep(5);
printf("yay, we're back\n");

printf("Testing spawning\n");
pid_t p = 0;
int result = spawnp(&p, "/bin/hlwrld.app", nullptr, nullptr);
if (result)
{
printf("spawn failed\n");
}
else
for (;;)
{
printf("spawned process as %d\n", p);

if (waitp(p))
printf("wait failed\n");
printf("neko:/ $ "); // Prompt

size_t read = readln(buf, 512); // Command
buf[read] = 0x00;

if (streq(buf, "exit") == 0)
{
break;
}

pid_t pid = 0;
if (spawnp(&pid, buf, nullptr, nullptr))
{
printf("nsh: error: Cannot spawn\n");
}
waitp(pid);
}

printf("reading from console...\n");
char *buf = new char[256];
readln(buf, 256);
printf("read: %s\n", buf);
return 0;
}

0 comments on commit 397d944

Please sign in to comment.