-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkosh.c
More file actions
57 lines (48 loc) · 1.24 KB
/
kosh.c
File metadata and controls
57 lines (48 loc) · 1.24 KB
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
/*
* kosh.c - console shell for kallistios (A Rough version)
*
* (C) 2000 Jordan DeLong
*/
#include <stdio.h>
#include <assert.h>
#include <kos/thread.h>
#include "kosh.h"
#include "chdir.h"
#include "builtin.h"
/* global exit flag: if someone sets this we quit */
#define KE_YES 1 // Requesting exit
#define KE_NO 0 // Run mode
#define KE_QUITTING -1 // Thread has returned
#define KE_JOINED -2 // Not running
volatile int kosh_exit = KE_JOINED;
/* Our exit semaphore - signaled when the thread exits */
static kthread_t *thd;
static void *kosh_thread(void *p) {
conio_printf(" **** KOSH, The KallistiOS Shell ****\n");
kosh_chdir("/");
while (kosh_exit == KE_NO)
input_oneloop();
conio_printf("Kosh is done\n");
kosh_exit = KE_QUITTING;
return NULL;
}
void kosh_join(void) {
assert( kosh_exit != KE_JOINED );
thd_join(thd, NULL);
kosh_exit = KE_JOINED;
}
int kosh_init(void) {
if (kosh_exit != KE_JOINED)
return -1;
kosh_exit = KE_NO;
kosh_builtins_init();
thd = thd_create(0, kosh_thread, NULL);
return 0;
}
void kosh_shutdown(void) {
if (kosh_exit != KE_JOINED) {
kosh_exit = KE_YES;
kosh_join();
}
kosh_builtins_shutdown();
}