forked from wandwramp/WRAMPmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.c
109 lines (97 loc) · 2.86 KB
/
cli.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
########################################################################
# This file is part of WRAMPmon, the WRAMP monitor programe.
#
# Copyright (C) 2019 The University of Waikato, Hamilton, New Zealand.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
########################################################################
*/
#include "stdio.h"
#include "commands.h"
#include "token.h"
#include "clib.h"
#include "utils.h"
typedef struct {
char *cmd;
void (*fn)(void);
} cmd_entry;
cmd_entry cmd_table[] = {
{"load", &command_load },
{"dis", &command_dis },
{"vr", &command_vr },
{"sr", &command_sr },
{"sb", &command_sb },
{"vb", &command_vb },
{"rb", &command_rb },
{"vm", &command_vm },
{"sm", &command_sm },
{"go", &command_go },
{"cont", &command_cont },
{"s", &command_s },
{"so", &command_so },
{"about", &command_about },
{"help", &command_help },
{"?", &command_help },
{"cls", &command_cls },
{"iddqd", &command_games },
{"sws_debug", &command_sws_debug },
{(char *)0, &command_help }
};
void welcome()
{
printf("\n");
printf("+------------------------------------------------+\n");
printf("| WRAMPmon 0.9 |\n");
printf("| Copyright 2002-2019 The University of Waikato |\n");
printf("| |\n");
printf("| Written by Dean Armstrong |\n");
printf("| Ported to the Basys3 in 2018 by |\n");
printf("| Daniel Oosterwijk and Tyler Marriner |\n");
printf("+------------------------------------------------+\n");
printf("\n");
printf("Type ? and press enter for available commands.\n\n");
}
void process_cmd(char *cmd)
{
int i;
char *tmp = cmd;
/* Convert the entire command to lower case */
while (*tmp != '\0') {
*tmp = tolower(*tmp);
tmp++;
}
tokenise(cmd);
tmp = get_token();
if (!tmp)
return;
for (i = 0 ; cmd_table[i].cmd ; i++) {
if (strcmp(tmp, cmd_table[i].cmd) == 0)
break;
}
if (!cmd_table[i].cmd) {
printf("Invalid command entered.\n");
return;
}
invoke(cmd_table[i].fn);
}
void cli()
{
char cmd_buf[256];
for (;;) {
printf(" > ");
gets(cmd_buf);
process_cmd(cmd_buf);
}
}