aboutsummaryrefslogtreecommitdiff
path: root/src/sysbin/shell/main.c
blob: 19290254b684eedd09867bcf3188d20cbc05696f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <string.h>
#include <malloc.h>
#include <user_region.h>
#include <debug.h>

#include <stdio.h>
#include <unistd.h>

#include <syscall.h>

void ls(char* dir) {
	fd_t f = open(dir, FM_READDIR);
	if (f) {
		dirent_t i;
		int ent_no = 0;
		while (readdir(f, ent_no++, &i)) {
			printf("%s\n", i.name);
		}
		close(f);
	} else {
		printf("Could not open directory '%s'\n", dir);
	}
}

int main(int argc, char **argv) {
	dbg_printf("[shell] Starting\n");

	/*fctl(stdio, FC_SET_BLOCKING, 0);*/

	puts("Kogata shell.\n");

	chdir("sys:");

	while(true) {
		char buf[256];
		printf("\n%s> ", getcwd(buf, 256));

		getline(buf, 256);
		if (!strncmp(buf, "cd ", 3)) {
			chdir(buf + 3);
		} else if (!strcmp(buf, "ls")) {
			if (getcwd(buf, 256)) {
				ls(buf);
			}
		} else if (!strncmp(buf, "ls ", 3)) {
			char buf2[256];
			if (getcwd(buf2, 256)) {
				if (pathncat(buf2, buf + 3, 256)) {
					ls(buf2);
				}
			}
		} else if (!strcmp(buf, "exit")) {
			break;
		} else {
			printf("No such command.\n");
		}
	}
	printf("Bye.\n");

	return 0;
}

/* vim: set ts=4 sw=4 tw=0 noet :*/