summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Zabka <zabkaste@hu-berlin.de>2020-05-20 21:13:35 +0200
committerStefan Zabka <zabkaste@hu-berlin.de>2020-05-20 21:13:35 +0200
commitf117343477e596937bdfcf0ddce447c0d127b9cf (patch)
tree5ebbbfbd13e4b78cbad2026329261383a77b2893
parent9f7bf8ddf255f06a3c27c13dad87e34a70356d58 (diff)
downloadbetriebssysteme-f117343477e596937bdfcf0ddce447c0d127b9cf.tar.gz
betriebssysteme-f117343477e596937bdfcf0ddce447c0d127b9cf.zip
Fixed another edge case and documentationfixing_prompt
-rw-r--r--02_exercise/prompt_utils.c4
-rw-r--r--02_exercise/prompt_utils.h2
-rw-r--r--02_exercise/prompt_utils_test.c1
-rw-r--r--02_exercise/prompt_utils_test.h4
-rw-r--r--02_exercise/shell.c1
5 files changed, 8 insertions, 4 deletions
diff --git a/02_exercise/prompt_utils.c b/02_exercise/prompt_utils.c
index 819509d..4f86811 100644
--- a/02_exercise/prompt_utils.c
+++ b/02_exercise/prompt_utils.c
@@ -64,7 +64,9 @@ char const *const relative_path(char const *const from_dir, char const *const to
for (size_t j = 0; j < levels_up - 1; j++) {
strcat(return_value, go_up);
}
- strcat(return_value, to_dir + common_position);
+ if (strcmp("/", to_dir) != 0) {
+ strcat(return_value, to_dir + common_position);
+ }
}
arrayRelease((void *)from_dir_indeces);
diff --git a/02_exercise/prompt_utils.h b/02_exercise/prompt_utils.h
index 93de502..908019c 100644
--- a/02_exercise/prompt_utils.h
+++ b/02_exercise/prompt_utils.h
@@ -6,6 +6,6 @@
// Returns the relative path to get from the `from_dir` to the `to_dir`
char const *const relative_path(char const *const from_dir, char const *const to_dir);
-// Returns the position of each element one after the seperator
+// Returns the position of each occurence of the seperator
size_t *get_seperator_indeces(char const *const text, char seperator);
#endif // PROMPT_UTILS_H_INCLUDED \ No newline at end of file
diff --git a/02_exercise/prompt_utils_test.c b/02_exercise/prompt_utils_test.c
index b26ce6f..f648275 100644
--- a/02_exercise/prompt_utils_test.c
+++ b/02_exercise/prompt_utils_test.c
@@ -33,4 +33,5 @@ void test_relative_path() {
test_paths("/Test/b/c", "/Test/b", "..");
test_paths("/", "/Test/a/asd", "./Test/a/asd");
test_paths("/Test/c", "/Test/b", "../b");
+ test_paths("/B/C", "/", "../..");
} \ No newline at end of file
diff --git a/02_exercise/prompt_utils_test.h b/02_exercise/prompt_utils_test.h
index 5c637b2..fbaabde 100644
--- a/02_exercise/prompt_utils_test.h
+++ b/02_exercise/prompt_utils_test.h
@@ -1,5 +1,5 @@
-#ifndef PROMPT_UTILS_H_INCLUDED
-#define PROMPT_UTILS_H_INCLUDED
+#ifndef PROMPT_UTILS_TEST_H_INCLUDED
+#define PROMPT_UTILS_TEST_H_INCLUDED
void test_get_seperator_indeces();
void test_relative_path();
diff --git a/02_exercise/shell.c b/02_exercise/shell.c
index c0c51e1..d155a58 100644
--- a/02_exercise/shell.c
+++ b/02_exercise/shell.c
@@ -20,6 +20,7 @@ void print_prompt(char const *const original_wd, char const *current_wd);
int exec_command(char *command);
int main(void) {
+
char const *const original_wd = get_current_dir_name();
char const *prompt = relative_path(original_wd, original_wd);
printf("%s \n", original_wd);