-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.c
46 lines (40 loc) · 846 Bytes
/
shell.c
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
/**
* WSFN ("Which Stands for Nothing")
*/
#include <stdio.h>
#include <string.h>
#include "wsfn.h"
#define PROG "WSFN"
#define BANNER "Welcome to " PROG "'s World (" __DATE__ ")\n\n"
#define PROMPT PROG "> "
static void init(struct WSFN *vm)
{
printf("init\n");
}
static void move(struct WSFN *vm)
{
printf("move [%d,%d]-[%d,%d]\n", vm->_x, vm->_y, vm->x, vm->y);
}
static char *input(const char *prompt, char *buf, int size, FILE *in)
{
char *p;
#ifndef SILENT
printf(prompt);
#endif
p = fgets(buf, size, in);
if(!p || feof(in)) return NULL;
if( (p = strchr(buf, '\n')) ) *p = '\0';
return buf;
}
int main(int argc, char *argv[])
{
char buf[128];
struct WSFN wsfn = {0};
#ifndef SILENT
printf(BANNER);
#endif
setup(&wsfn, &init, &move);
while(input(PROMPT, buf, sizeof(buf), stdin) )
eval(&wsfn, buf);
return 0;
}