aboutsummaryrefslogtreecommitdiff
path: root/smash/main.c
blob: 2422363dae3d849d6e0f904bc10a6b637cdb9911 (plain)
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
#include "exec.h"

#include "../lib/sys/io.h"
#include "../lib/cstr/cstr.h"

#define BUFSIZ 1024

void clear_buf(char *buf)
{
	for (int i = 0; i < BUFSIZ; ++i)
		buf[i] = 0;
}

int main(int argc, char *argv[], char *envp[])
{
	char buf[BUFSIZ] = {0};
	char prompt[] = "$ ";
	u64 line_length;

	while (1) {
		write(STDOUT_FD, prompt, cstr_length(prompt));
		read(STDIN_FD, buf, 1024);
		line_length = cstr_length(buf);
		if (line_length > 1) {
			buf[line_length - 1] = 0;
			exec(buf);
		}
		clear_buf(buf);
	}
}