summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake-build-debug/.ninja_depsbin0 -> 5532 bytes
-rw-r--r--cmake-build-debug/.ninja_log15
-rw-r--r--cmake-build-debug/CMakeFiles/program.dir/main.c.obin0 -> 8640 bytes
-rw-r--r--cmake-build-debug/Testing/Temporary/LastTest.log3
-rwxr-xr-xcmake-build-debug/programbin0 -> 18400 bytes
-rwxr-xr-xmainbin15784 -> 18712 bytes
-rw-r--r--main.c66
7 files changed, 41 insertions, 43 deletions
diff --git a/cmake-build-debug/.ninja_deps b/cmake-build-debug/.ninja_deps
new file mode 100644
index 0000000..e0144c3
--- /dev/null
+++ b/cmake-build-debug/.ninja_deps
Binary files differ
diff --git a/cmake-build-debug/.ninja_log b/cmake-build-debug/.ninja_log
new file mode 100644
index 0000000..bc4deff
--- /dev/null
+++ b/cmake-build-debug/.ninja_log
@@ -0,0 +1,15 @@
+# ninja log v6
+4 59 1739451526642495194 CMakeFiles/program.dir/main.c.o 910277f4c84ef538
+59 101 1739451526698518737 program 622df6c7ebe735f2
+2 63 1739453226242054412 CMakeFiles/program.dir/main.c.o 910277f4c84ef538
+63 98 1739453226303052489 program 622df6c7ebe735f2
+0 59 1739453281454324375 CMakeFiles/program.dir/main.c.o 910277f4c84ef538
+59 94 1739453281513322537 program 622df6c7ebe735f2
+1 52 1739453293854938532 CMakeFiles/program.dir/main.c.o 910277f4c84ef538
+52 92 1739453293905936947 program 622df6c7ebe735f2
+0 56 1739453764783817143 CMakeFiles/program.dir/main.c.o 910277f4c84ef538
+56 89 1739453764839815509 program 622df6c7ebe735f2
+0 43 1739453927685092584 CMakeFiles/program.dir/main.c.o 910277f4c84ef538
+43 78 1739453927728091344 program 622df6c7ebe735f2
+1 47 1739453962316094847 CMakeFiles/program.dir/main.c.o 910277f4c84ef538
+47 80 1739453962362093523 program 622df6c7ebe735f2
diff --git a/cmake-build-debug/CMakeFiles/program.dir/main.c.o b/cmake-build-debug/CMakeFiles/program.dir/main.c.o
new file mode 100644
index 0000000..0ccb1d6
--- /dev/null
+++ b/cmake-build-debug/CMakeFiles/program.dir/main.c.o
Binary files differ
diff --git a/cmake-build-debug/Testing/Temporary/LastTest.log b/cmake-build-debug/Testing/Temporary/LastTest.log
new file mode 100644
index 0000000..e67e16f
--- /dev/null
+++ b/cmake-build-debug/Testing/Temporary/LastTest.log
@@ -0,0 +1,3 @@
+Start testing: Feb 13 14:39 CET
+----------------------------------------------------------
+End testing: Feb 13 14:39 CET
diff --git a/cmake-build-debug/program b/cmake-build-debug/program
new file mode 100755
index 0000000..5b06251
--- /dev/null
+++ b/cmake-build-debug/program
Binary files differ
diff --git a/main b/main
index 73fc58a..7943572 100755
--- a/main
+++ b/main
Binary files differ
diff --git a/main.c b/main.c
index 0be7c07..52eb63b 100644
--- a/main.c
+++ b/main.c
@@ -5,7 +5,7 @@
#include <unistd.h>
#define MAX_HISTORY 100
-#define MAX_COMMAND_LENGTH 256
+#define MAX_COMMAND_LENGTH 255
struct com_struct {
char *com;
@@ -40,66 +40,46 @@ void ls(const char *path) {
closedir(dP);
}
-// echo command
-char *echo(const char *command) {
- const char *argv = (char *) malloc(sizeof(char) * 4);
- char *command_argument = (char *) malloc(sizeof(char) * 100);
-
- int separation_index = 0;
- for (int i = 0; i < sizeof(command); i++) {
- if (strcmp(&command[i], " ") == 0) {
- separation_index = i;
-
- for (int j = 0; j < separation_index; j++) {
- argv = &command[j];
- }
- }
- }
- if (strcmp(argv, "echo") == 0) {
- for (int i = separation_index + 1; i < (sizeof(command) - separation_index); i++) {
- if (strcmp(&command[i], "\0") != 0) {
- break;
- } else {
- strcpy(&command_argument[i - (separation_index - 1)], &command[i]);
- }
- }
- }
- return command_argument;
-}
-
struct com_struct split_command(char *input) {
struct com_struct NEW_COMMAND;
- const char *command = strtok(input, "");
- const char *argument = strtok(NULL, "\n");
+ const char *command = strtok(input, " ");
+ const char *argument = strtok(NULL, " ");
- NEW_COMMAND.com = command ? strdup(command) : NULL;
- NEW_COMMAND.arg = command ? strdup(argument) : NULL;
+ NEW_COMMAND.com = strdup(command);
+ NEW_COMMAND.arg = strdup(argument);
return NEW_COMMAND;
}
int main(void) {
while (1) {
- char *input = malloc(MAX_COMMAND_LENGTH);
+ char *input = malloc(sizeof(char *) * MAX_COMMAND_LENGTH);
- // print the shell sign
- printf("\n $ ");
+ printf("\n$ ");
- // get the user input, store it and split it up
fgets(input, MAX_COMMAND_LENGTH, stdin);
const struct com_struct new_input = split_command(input);
- if (strcmp(new_input.com, "ls") == 0) {
- ls(new_input.arg);
- } else if (strcmp(new_input.com, "test") == 0) {
- test();
- } else if (strcmp(new_input.com, "exit") == 0) {
+ new_input.com[strcspn(new_input.com, "\n")] = '\0';
+ new_input.arg[strcspn(new_input.arg, "\n")] = '\0';
+
+ if (strcmp(new_input.com, "exit\n") == 0) {
+ exit_();
free(input);
free(new_input.com);
free(new_input.arg);
- exit_();
+ return 0;
+ }
+ if (strcmp(new_input.com, "ls\n") == 0) {
+ printf("DETECTED LS COMMAND");
+ ls(new_input.arg);
+ }
+ if (strcmp(new_input.com, "echo\n") == 0) {
+ printf("DETECTED ECHO COMMAND");
+ printf("%s", new_input.arg);
+ free(new_input.arg);
}
}
- return 0;
}
+