-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crappy but working interactive shell :3
- Loading branch information
Showing
4 changed files
with
27 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |