diff --git a/cat.o b/cat.o new file mode 100644 index 0000000..036f2ce Binary files /dev/null and b/cat.o differ diff --git a/cd.o b/cd.o new file mode 100644 index 0000000..66108a8 Binary files /dev/null and b/cd.o differ diff --git a/clear.o b/clear.o new file mode 100644 index 0000000..2e475c7 Binary files /dev/null and b/clear.o differ diff --git a/diff.o b/diff.o new file mode 100644 index 0000000..c9cc886 Binary files /dev/null and b/diff.o differ diff --git a/ls.o b/ls.o new file mode 100644 index 0000000..2848ae8 Binary files /dev/null and b/ls.o differ diff --git a/main.c b/main.c index 827e52e..efde73e 100644 --- a/main.c +++ b/main.c @@ -18,12 +18,12 @@ DirectoryTree dTree; void initialize_directory_tree(DirectoryTree* dTree) { TreeNode* root = malloc(sizeof(TreeNode)); // 메모리 할당 - strcpy(root->name, "/"); + strcpy(root->name, ""); root->type = 'd'; root->left = NULL; root->right = NULL; root->parent = NULL; - strncpy(dTree->root->name, "/", MAX_NAME_LENGTH); + //strncpy(dTree->root->name, "/", MAX_NAME_LENGTH); dTree->root->type = 'd'; dTree->root->mode = 755; dTree->root->size = 4096; @@ -94,7 +94,7 @@ int main() { save_tree_to_file(&dTree, SAVE_FILE); } else { printf("cat: missing argument\n"); - printf("사용법: cat \n") + printf("사용법: cat \n"); } } else if (strcmp(cmd, "cd") == 0) { @@ -178,4 +178,4 @@ int main() { printf("Invalid command: %s\n", cmd); } } -} \ No newline at end of file +} diff --git a/main.o b/main.o new file mode 100644 index 0000000..0deb994 Binary files /dev/null and b/main.o differ diff --git a/program b/program new file mode 100755 index 0000000..62e8bf0 Binary files /dev/null and b/program differ diff --git a/pwd.o b/pwd.o new file mode 100644 index 0000000..4fddc92 Binary files /dev/null and b/pwd.o differ diff --git a/test1 b/test1 new file mode 100644 index 0000000..e69de29 diff --git a/touch.o b/touch.o new file mode 100644 index 0000000..2fa81b5 Binary files /dev/null and b/touch.o differ diff --git a/tree_io.c b/tree_io.c index 619a3e9..4480756 100644 --- a/tree_io.c +++ b/tree_io.c @@ -51,7 +51,7 @@ void load_tree_from_file(DirectoryTree* dTree, const char* filename) { // Ʈ ʱȭ perror("fopen"); // κ: ޽ TreeNode* root = malloc(sizeof(TreeNode)); // Ʈ ʱȭ - strcpy(root->name, "/"); + strcpy(root->name, ""); root->type = 'd'; root->left = NULL; root->right = NULL; @@ -62,7 +62,10 @@ void load_tree_from_file(DirectoryTree* dTree, const char* filename) { return; } dTree->root = load_tree_helper(file, 0); + if (dTree->root && strcmp(dTree->root->name, "/") == 0) { + strcpy(dTree->root->name, ""); + } dTree->current = dTree->root; strcpy(dTree->current_path, "Team4:"); fclose(file); -} \ No newline at end of file +} diff --git a/tree_io.o b/tree_io.o new file mode 100644 index 0000000..ebfb0e0 Binary files /dev/null and b/tree_io.o differ diff --git a/tree_state.txt b/tree_state.txt new file mode 100644 index 0000000..8bcb53c --- /dev/null +++ b/tree_state.txt @@ -0,0 +1,2 @@ +d / + f test1 diff --git a/whereis.c b/whereis.c index 10788b3..860486b 100644 --- a/whereis.c +++ b/whereis.c @@ -6,7 +6,16 @@ void whereis_helper(TreeNode *node, const char *target, char *path) { if (node == NULL) return; char new_path[1024]; - snprintf(new_path, sizeof(new_path), "%s/%s", path, node->name); + if (strcmp(path, "") == 0) { + // path가 빈 문자열이면 루트 기준 시작 + snprintf(new_path, sizeof(new_path), "/%s", node->name); + } else if (path[strlen(path) - 1] == '/') { + // path가 /로 끝나면 슬래시 하나만 유지 + snprintf(new_path, sizeof(new_path), "%s%s", path, node->name); + } else { + // 평범한 연결 + snprintf(new_path, sizeof(new_path), "%s/%s", path, node->name); + } if (strcmp(node->name, target) == 0) { printf("Found: %s\n", new_path); @@ -18,4 +27,4 @@ void whereis_helper(TreeNode *node, const char *target, char *path) { void whereis(DirectoryTree *dTree, const char *target) { whereis_helper(dTree->root, target, ""); -} \ No newline at end of file +} diff --git a/whereis.o b/whereis.o new file mode 100644 index 0000000..240a24f Binary files /dev/null and b/whereis.o differ