Skip to content

Commit

Permalink
Added CLI interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-n3m0 committed May 9, 2023
1 parent 311942b commit 951fd09
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 85 deletions.
19 changes: 13 additions & 6 deletions Kernel16F.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "Kernel16F.h"
#include "display.h"
#include "filesystem/filesystem.h"
#include "disk_operations/disk.h"
#include "memory_manager/mem_manager.h"
#include "string_manipulation/string_utils.h"
#include "process_manager/proc_man.h"
#include "../display/display.h"
#include "../filesystem/filesystem.h"
#include "../disk_operations/disk.h"
#include "../memory_manager/mem_manager.h"
#include "../string_manipulation/string_utils.h"
#include "../process_manager/proc_man.h"
#include "../cli_interface/cli.h"
void main()
{
// Create the kernels heap
Expand All @@ -19,6 +20,12 @@ void main()
// Initialise the process manager
process_manager_init();

// Initialise the display
display_init();

// Initialise the CLI
cli_init();


{
int f = fopen("0:/START", 'r');
Expand Down
56 changes: 56 additions & 0 deletions cli_interface/cli.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <stdio.h>
#include <string.h>
#include "cli.h"
#include "display.h"

void echo(char* args[]) {
char output[100] = "";
for (int i = 0; args[i] != NULL; i++) {
strcat(output, args[i]);
strcat(output, " ");
}
strcat(output, "\n");
display_write(output);
}

void help(char* args[]) {
char output[100] = "";
strcat(output, "Available commands:\n");
strcat(output, "echo [args...]\n");
strcat(output, "help\n");
strcat(output, "version\n");
display_write(output);
}

void version(char* args[]) {
char output[100] = "";
strcat(output, "Kernel16F version 1.0\n");
display_write(output);
}

void cli_init() {
display_init();
}

void cli_parse_input(char* input_str) {
char* args[10];
char* token = strtok(input_str, " ");
int i = 0;
while (token != NULL) {
args[i++] = token;
token = strtok(NULL, " ");
}
args[i] = NULL;

if (strcmp(args[0], "echo") == 0) {
echo(&args[1]);
} else if (strcmp(args[0], "help") == 0) {
help(&args[1]);
} else if (strcmp(args[0], "version") == 0) {
version(&args[1]);
} else {
char output[100] = "";
strcat(output, "Invalid command. Type 'help' for a list of available commands.\n");
display_write(output);
}
}
7 changes: 7 additions & 0 deletions cli_interface/cli.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef CLI_H
#define CLI_H

void cli_init();
void cli_parse_input(char* input_str);

#endif
72 changes: 0 additions & 72 deletions display.c

This file was deleted.

7 changes: 0 additions & 7 deletions display.h

This file was deleted.

10 changes: 10 additions & 0 deletions display/display.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>
#include "display.h"

void display_init() {
// Initialize the display output
}

void display_write(char* str) {
printf("%s", str);
}
7 changes: 7 additions & 0 deletions display/display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef DISPLAY_H
#define DISPLAY_H

void display_init();
void display_write(char* str);

#endif

0 comments on commit 951fd09

Please sign in to comment.