mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-29 08:37:51 +01:00
Basic shell
This commit is contained in:
@@ -2,48 +2,48 @@
|
||||
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include <sys/fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void ls() {
|
||||
DIR *rfd = opendir("/");
|
||||
struct dirent *cur = readdir(rfd);
|
||||
while (cur) {
|
||||
printf("%s\n", cur->d_name);
|
||||
cur = readdir(rfd);
|
||||
}
|
||||
closedir(rfd);
|
||||
}
|
||||
|
||||
int main() {
|
||||
malloc(100);
|
||||
malloc(100);
|
||||
malloc(100);
|
||||
malloc(100);
|
||||
printf("Who are you?\n");
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
// __getline(&line, &len, stdin);
|
||||
{
|
||||
uint64_t test123 = open("/test123", O_CREAT | O_RDWR);
|
||||
const char *teststr = "test str";
|
||||
write(test123, teststr, 9);
|
||||
close(test123);
|
||||
|
||||
|
||||
printf("hi %s\n", line);
|
||||
// sputchar('h');
|
||||
// sputchar('i');
|
||||
// sputchar('\n');
|
||||
uint64_t test123 = open("/test123", O_CREAT | O_RDWR);
|
||||
const char *teststr = "test str";
|
||||
write(test123, teststr, 9);
|
||||
close(test123);
|
||||
|
||||
test123 = open("/test123", O_RDONLY);
|
||||
char buf[123];
|
||||
read(test123, buf, 9);
|
||||
|
||||
printf("\n %s \n", buf);
|
||||
|
||||
usleep(100);
|
||||
|
||||
execve("/hello2", 0, 0);
|
||||
test123 = open("/test123", O_RDONLY);
|
||||
char buf[123];
|
||||
read(test123, buf, 9);
|
||||
close(test123);
|
||||
printf("\n %s \n", buf);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
printf("\n");
|
||||
char c;
|
||||
scanf(" %c", &c);
|
||||
if (c == 'm') print_mem();
|
||||
if (c == 't') print_tasks();
|
||||
if (c == 'h') execve("/hello2", 0, 0);
|
||||
printf("%c", c);
|
||||
printf("\n> ");
|
||||
char line[30];
|
||||
scanf(" %24[^\n]", line);
|
||||
if (strcmp(line, "ls") == 0) {
|
||||
ls();
|
||||
} else if (strcmp(line, "mem") == 0) {
|
||||
print_mem();
|
||||
} else if (strcmp(line, "tasks") == 0) {
|
||||
print_tasks();
|
||||
} else {
|
||||
execve(line, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user