Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added cat.o
Binary file not shown.
Binary file added cd.o
Binary file not shown.
Binary file added clear.o
Binary file not shown.
Binary file added diff.o
Binary file not shown.
Binary file added ls.o
Binary file not shown.
8 changes: 4 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +94,7 @@ int main() {
save_tree_to_file(&dTree, SAVE_FILE);
} else {
printf("cat: missing argument\n");
printf("사용법: cat <filename>\n")
printf("사용법: cat <filename>\n");
}
}
else if (strcmp(cmd, "cd") == 0) {
Expand Down Expand Up @@ -178,4 +178,4 @@ int main() {
printf("Invalid command: %s\n", cmd);
}
}
}
}
Binary file added main.o
Binary file not shown.
Binary file added program
Binary file not shown.
Binary file added pwd.o
Binary file not shown.
Empty file added test1
Empty file.
Binary file added touch.o
Binary file not shown.
7 changes: 5 additions & 2 deletions tree_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Binary file added tree_io.o
Binary file not shown.
2 changes: 2 additions & 0 deletions tree_state.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
d /
f test1
13 changes: 11 additions & 2 deletions whereis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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, "");
}
}
Binary file added whereis.o
Binary file not shown.