2024-08-31 18:25:48 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "../include/syscall.h"
|
2024-09-01 11:56:39 +08:00
|
|
|
#include "../include/string.h"
|
2024-09-01 20:09:41 +08:00
|
|
|
#include "../include/cpos.h"
|
|
|
|
|
|
|
|
extern void print_info();
|
|
|
|
|
|
|
|
static int gets(char *buf) {
|
2024-09-01 11:56:39 +08:00
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
char c;
|
2024-09-01 20:09:41 +08:00
|
|
|
|
2024-09-01 11:56:39 +08:00
|
|
|
while ((c = syscall_getch()) != '\n') {
|
|
|
|
if (c == '\b') {
|
|
|
|
if (index > 0) {
|
|
|
|
index--;
|
2024-09-01 14:56:38 +08:00
|
|
|
printf("\b \b");
|
2024-09-01 11:56:39 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
buf[index++] = c;
|
|
|
|
printf("%c",c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf[index] = '\0';
|
|
|
|
printf("%c",c);
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_parse(char *cmd_str, char **argv, char token) {
|
|
|
|
int arg_idx = 0;
|
|
|
|
while (arg_idx < 50) {
|
|
|
|
argv[arg_idx] = NULL;
|
|
|
|
arg_idx++;
|
|
|
|
}
|
|
|
|
char *next = cmd_str;
|
|
|
|
int argc = 0;
|
|
|
|
|
|
|
|
while (*next) {
|
|
|
|
while (*next == token) *next++;
|
|
|
|
if (*next == 0) break;
|
|
|
|
argv[argc] = next;
|
|
|
|
while (*next && *next != token) *next++;
|
|
|
|
if (*next) *next++ = 0;
|
|
|
|
if (argc > 50) return -1;
|
|
|
|
argc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return argc;
|
|
|
|
}
|
2024-08-31 18:25:48 +08:00
|
|
|
|
|
|
|
int main(){
|
|
|
|
printf("CoolPotOS UserShell v0.0.1\n");
|
2024-09-01 11:56:39 +08:00
|
|
|
char com[100];
|
|
|
|
char *argv[50];
|
|
|
|
int argc = -1;
|
|
|
|
char *buffer[255];
|
2024-09-01 16:43:58 +08:00
|
|
|
|
2024-08-31 18:25:48 +08:00
|
|
|
while (1){
|
2024-09-01 11:56:39 +08:00
|
|
|
syscall_get_cd(buffer);
|
2024-09-01 20:09:41 +08:00
|
|
|
printf("\03343cd80;default@localhost: \0334169E1;%s\\\033c6c6c6;$ ",buffer);
|
|
|
|
|
|
|
|
if (gets(com) <= 0) continue;
|
2024-09-01 11:56:39 +08:00
|
|
|
|
|
|
|
argc = cmd_parse(com, argv, ' ');
|
|
|
|
|
2024-09-01 20:09:41 +08:00
|
|
|
|
|
|
|
|
2024-09-01 11:56:39 +08:00
|
|
|
if (argc == -1) {
|
|
|
|
printf("[Shell]: Error: out of arguments buffer\n");
|
|
|
|
continue;
|
|
|
|
}
|
2024-08-31 18:25:48 +08:00
|
|
|
|
2024-09-01 20:09:41 +08:00
|
|
|
if (!strcmp("version", argv[0])){
|
|
|
|
print_info();
|
|
|
|
}else if (!strcmp("help", argv[0]) || !strcmp("?", argv[0]) || !strcmp("h", argv[0])) {
|
2024-09-01 11:56:39 +08:00
|
|
|
printf("-=[CoolPotShell Helper]=-\n");
|
|
|
|
printf("help ? h Print shell help info.\n");
|
|
|
|
printf("version Print os version.\n");
|
|
|
|
printf("type <name> Read a file.\n");
|
|
|
|
printf("ls List all files.\n");
|
|
|
|
printf("mkdir <name> Make a directory.\n");
|
|
|
|
printf("del rm <name> Delete a file.\n");
|
|
|
|
printf("sysinfo Print system info.\n");
|
2024-09-01 14:56:38 +08:00
|
|
|
printf("proc [kill<pid>|list] List all running processes.\n");
|
2024-09-01 11:56:39 +08:00
|
|
|
printf("reset Reset OS.\n");
|
|
|
|
printf("shutdown exit Shutdown OS.\n");
|
|
|
|
printf("debug Print os debug info.\n");
|
|
|
|
printf("disk[list|<ID>|cg<ID>]List or view disks.\n");
|
|
|
|
printf("cd <path> Change shell top directory.\n");
|
|
|
|
printf("sb3 <name> Player a wav sound file.\n");
|
|
|
|
printf("exec <path> Execute a application.\n");
|
|
|
|
} else printf("\033ff3030;[Shell]: Unknown command '%s'.\033c6c6c6;\n", argv[0]);
|
2024-08-31 18:25:48 +08:00
|
|
|
}
|
|
|
|
}
|