summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornasrlol <nsrddyn@gmail.com>2025-02-13 00:01:32 +0100
committernasrlol <nsrddyn@gmail.com>2025-02-13 00:01:32 +0100
commitcbdcb1c53bb6522c1cd8d38d91280500f439e4fb (patch)
treed588f338affa00d9adda561bb0e6143599c49921
parentc55e54448f428e26ff3bb1dd2fd729224a0dacee (diff)
fixed some basic program problems, but at the moment im having issue with a segfault somehow somewhere
-rw-r--r--.clang-tidy147
-rw-r--r--cmake-build-debug/.cmake/api/v1/reply/index-2025-02-12T22-07-31-0839.json (renamed from cmake-build-debug/.cmake/api/v1/reply/index-2025-02-12T21-48-20-0243.json)0
-rw-r--r--folder/file0
-rwxr-xr-xmainbin15728 -> 15784 bytes
-rw-r--r--main.c87
5 files changed, 169 insertions, 65 deletions
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..fd8c681
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,147 @@
+# Generated from CLion Inspection settings
+---
+Checks: '-*,
+bugprone-argument-comment,
+bugprone-assert-side-effect,
+bugprone-bad-signal-to-kill-thread,
+bugprone-branch-clone,
+bugprone-copy-constructor-init,
+bugprone-dangling-handle,
+bugprone-dynamic-static-initializers,
+bugprone-fold-init-type,
+bugprone-forward-declaration-namespace,
+bugprone-forwarding-reference-overload,
+bugprone-inaccurate-erase,
+bugprone-incorrect-roundings,
+bugprone-integer-division,
+bugprone-lambda-function-name,
+bugprone-macro-parentheses,
+bugprone-macro-repeated-side-effects,
+bugprone-misplaced-operator-in-strlen-in-alloc,
+bugprone-misplaced-pointer-arithmetic-in-alloc,
+bugprone-misplaced-widening-cast,
+bugprone-move-forwarding-reference,
+bugprone-multiple-statement-macro,
+bugprone-no-escape,
+bugprone-parent-virtual-call,
+bugprone-posix-return,
+bugprone-reserved-identifier,
+bugprone-sizeof-container,
+bugprone-sizeof-expression,
+bugprone-spuriously-wake-up-functions,
+bugprone-string-constructor,
+bugprone-string-integer-assignment,
+bugprone-string-literal-with-embedded-nul,
+bugprone-suspicious-enum-usage,
+bugprone-suspicious-include,
+bugprone-suspicious-memset-usage,
+bugprone-suspicious-missing-comma,
+bugprone-suspicious-semicolon,
+bugprone-suspicious-string-compare,
+bugprone-suspicious-memory-comparison,
+bugprone-suspicious-realloc-usage,
+bugprone-swapped-arguments,
+bugprone-terminating-continue,
+bugprone-throw-keyword-missing,
+bugprone-too-small-loop-variable,
+bugprone-undefined-memory-manipulation,
+bugprone-undelegated-constructor,
+bugprone-unhandled-self-assignment,
+bugprone-unused-raii,
+bugprone-unused-return-value,
+bugprone-use-after-move,
+bugprone-virtual-near-miss,
+cert-dcl21-cpp,
+cert-dcl58-cpp,
+cert-err34-c,
+cert-err52-cpp,
+cert-err60-cpp,
+cert-flp30-c,
+cert-msc50-cpp,
+cert-msc51-cpp,
+cert-str34-c,
+cppcoreguidelines-interfaces-global-init,
+cppcoreguidelines-narrowing-conversions,
+cppcoreguidelines-pro-type-member-init,
+cppcoreguidelines-pro-type-static-cast-downcast,
+cppcoreguidelines-slicing,
+google-default-arguments,
+google-explicit-constructor,
+google-runtime-operator,
+hicpp-exception-baseclass,
+hicpp-multiway-paths-covered,
+misc-misplaced-const,
+misc-new-delete-overloads,
+misc-no-recursion,
+misc-non-copyable-objects,
+misc-throw-by-value-catch-by-reference,
+misc-unconventional-assign-operator,
+misc-uniqueptr-reset-release,
+modernize-avoid-bind,
+modernize-concat-nested-namespaces,
+modernize-deprecated-headers,
+modernize-deprecated-ios-base-aliases,
+modernize-loop-convert,
+modernize-make-shared,
+modernize-make-unique,
+modernize-pass-by-value,
+modernize-raw-string-literal,
+modernize-redundant-void-arg,
+modernize-replace-auto-ptr,
+modernize-replace-disallow-copy-and-assign-macro,
+modernize-replace-random-shuffle,
+modernize-return-braced-init-list,
+modernize-shrink-to-fit,
+modernize-unary-static-assert,
+modernize-use-auto,
+modernize-use-bool-literals,
+modernize-use-emplace,
+modernize-use-equals-default,
+modernize-use-equals-delete,
+modernize-use-nodiscard,
+modernize-use-noexcept,
+modernize-use-nullptr,
+modernize-use-override,
+modernize-use-transparent-functors,
+modernize-use-uncaught-exceptions,
+mpi-buffer-deref,
+mpi-type-mismatch,
+openmp-use-default-none,
+performance-faster-string-find,
+performance-for-range-copy,
+performance-implicit-conversion-in-loop,
+performance-inefficient-algorithm,
+performance-inefficient-string-concatenation,
+performance-inefficient-vector-operation,
+performance-move-const-arg,
+performance-move-constructor-init,
+performance-no-automatic-move,
+performance-noexcept-move-constructor,
+performance-trivially-destructible,
+performance-type-promotion-in-math-fn,
+performance-unnecessary-copy-initialization,
+performance-unnecessary-value-param,
+portability-simd-intrinsics,
+readability-avoid-const-params-in-decls,
+readability-const-return-type,
+readability-container-size-empty,
+readability-convert-member-functions-to-static,
+readability-delete-null-pointer,
+readability-deleted-default,
+readability-inconsistent-declaration-parameter-name,
+readability-make-member-function-const,
+readability-misleading-indentation,
+readability-misplaced-array-index,
+readability-non-const-parameter,
+readability-redundant-control-flow,
+readability-redundant-declaration,
+readability-redundant-function-ptr-dereference,
+readability-redundant-smartptr-get,
+readability-redundant-string-cstr,
+readability-redundant-string-init,
+readability-simplify-subscript-expr,
+readability-static-accessed-through-instance,
+readability-static-definition-in-anonymous-namespace,
+readability-string-compare,
+readability-uniqueptr-delete-release,
+readability-use-anyofallof' \ No newline at end of file
diff --git a/cmake-build-debug/.cmake/api/v1/reply/index-2025-02-12T21-48-20-0243.json b/cmake-build-debug/.cmake/api/v1/reply/index-2025-02-12T22-07-31-0839.json
index d64b556..d64b556 100644
--- a/cmake-build-debug/.cmake/api/v1/reply/index-2025-02-12T21-48-20-0243.json
+++ b/cmake-build-debug/.cmake/api/v1/reply/index-2025-02-12T22-07-31-0839.json
diff --git a/folder/file b/folder/file
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/folder/file
diff --git a/main b/main
index cd6a581..73fc58a 100755
--- a/main
+++ b/main
Binary files differ
diff --git a/main.c b/main.c
index 901b2c4..0be7c07 100644
--- a/main.c
+++ b/main.c
@@ -1,27 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
-#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
-#include <stdbool.h>
-#include <linux/limits.h>
#define MAX_HISTORY 100
#define MAX_COMMAND_LENGTH 256
-// static int CURRENT_COMMAND_INDEX = 0;
-// static int CURRENT_HISTORY_INDEX = 0;
-// static char *COMMAND_HISTORY[MAX_HISTORY] = { NULL};
-
struct com_struct {
char *com;
char *arg;
};
void test() {
- printf("print to output");
+ printf("\nprint to output");
}
// exit() command
@@ -43,26 +35,14 @@ void ls(const char *path) {
// print the folder|directory name
while ((entry = readdir(dP)) != NULL) {
- printf("s\n", entry->d_name);
+ printf("%s", entry->d_name);
}
closedir(dP);
}
-// pwd command
-char *pwd() {
- char *current_working_directory = malloc(sizeof(char) * 100);
-
- if (getcwd(current_working_directory, sizeof(current_working_directory) != 0)) {
- return current_working_directory;
- } else {
- perror("getcwd() error");
- return "ERROR";
- }
-}
-
// echo command
-char *echo(char *command) {
- char *argv = (char *) malloc(sizeof(char) * 4);
+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;
@@ -76,7 +56,6 @@ char *echo(char *command) {
}
}
if (strcmp(argv, "echo") == 0) {
-
for (int i = separation_index + 1; i < (sizeof(command) - separation_index); i++) {
if (strcmp(&command[i], "\0") != 0) {
break;
@@ -89,60 +68,38 @@ char *echo(char *command) {
}
struct com_struct split_command(char *input) {
-
struct com_struct NEW_COMMAND;
- char *command = (char *) malloc(sizeof(char) * 4);
- char *argument = (char *) malloc(sizeof(char) * 100);
+ const char *command = strtok(input, "");
+ const char *argument = strtok(NULL, "\n");
- if (command == NULL || argument == NULL) {
- printf("found a null pointer when dynamically assigning memory to the command or variable argument");
- exit(1);
- }
-
- int space_position = 0;
- for (int i = 0; i < sizeof(command); i++) {
- if (strcmp(&input[i], " ") == 0) {
- space_position = i;
-
- for (int j = 0; j < space_position; j++) {
- command = &input[j];
- }
- for (int x = space_position; x < sizeof(input) - space_position; x++) {
- argument = &input[x];
- }
- }
-
- }
- NEW_COMMAND.com = command;
- NEW_COMMAND.arg = argument;
+ NEW_COMMAND.com = command ? strdup(command) : NULL;
+ NEW_COMMAND.arg = command ? strdup(argument) : NULL;
return NEW_COMMAND;
-
}
int main(void) {
- char *input = malloc(sizeof(char *) * MAX_COMMAND_LENGTH);
+ while (1) {
+ char *input = malloc(MAX_COMMAND_LENGTH);
- do {
- if (getchar()) {
- printf("\nSHELL> ");
- scanf("%s", input);
+ // print the shell sign
+ printf("\n $ ");
- struct com_struct new_input = split_command(input);
+ // 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) {
- char *path;
- path = (char *) malloc(sizeof(char) * 100);
-
- strcpy(path, new_input.arg);
- ls(path);
- } else if (strcmp(new_input.com, "test") == 0){
+ ls(new_input.arg);
+ } else if (strcmp(new_input.com, "test") == 0) {
test();
- }
+ } else if (strcmp(new_input.com, "exit") == 0) {
+ free(input);
+ free(new_input.com);
+ free(new_input.arg);
+ exit_();
}
}
- while (true);
-
return 0;
}