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
30 changes: 16 additions & 14 deletions include/command.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#ifndef COMMAND_H
#define COMMAND_H
#include "include/osproject.h"

#include "include/osproject.h"

void command_ls(int argc, char** argv);
void command_mkdir(int argc, char** argv);
void command_ls(DTree* tree, int argc, char** argv);
void command_mkdir(DTree* tree, int argc, char** argv);
void command_cat(DTree* tree, const char* filename);
void command_alias(AliasTable* table, int argc, char** argv);
void command_rm(int argc, char** argv);
int command_cd (DTree *tree, UList *users, int argc, char **argv);
int command_pwd (DTree *tree, Stack *stack, UList *users);
int command_cp (DTree *tree, int argc, char **argv);
void command_rm(DTree* tree, int argc, char** argv);

int command_cd(DTree* tree, UList* users, int argc, char** argv);
int command_pwd(DTree* tree, Stack* stack, UList* users);
int command_cp(DTree* tree, int argc, char** argv);

int cd(DTree* tree, char* command);
int MovePath(DTree* tree, char* path);
int Movecurrent(DTree* tree, char* segment);

int cd (DTree *tree, char *command);
int MovePath (DTree *tree, char *path);
int Movecurrent(DTree *tree, char *segment);
int pwd(DTree* tree, Stack* stack, char* opt);
int PrintPath(DTree* tree, Stack* stack);
int cp(DTree* tree, char* src, char* dst);

int pwd (DTree *tree, Stack *stack, char *opt);
int PrintPath (DTree *tree, Stack *stack);
int cp (DTree *tree, char *src, char *dst);
void UpdateUserDir(UList* users, DTree* tree);

void UpdateUserDir(UList *users, DTree *tree);
#endif
2 changes: 1 addition & 1 deletion include/ls.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include "osproject.h"

void command_ls(int argc, char** argv);
void command_ls(DTree* tree, int argc, char** argv);

#endif
57 changes: 42 additions & 15 deletions src/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,73 @@
#include <string.h>
#include "../include/ls.h"

extern DTree* tree;//��üƮ��

void print_permissions(int permission[9]) {
const char* rwx = "rwx";
for (int i = 0; i < 9; i++) {
printf("%c", permission[i] ? rwx[i % 3] : '-');
}
}

void command_ls(int argc, char** argv) {//������ �Լ��� ls,ls-a,ls-al�� ���� �������� �ʰ�
int show_all = 0, long_format = 0;//�ѹ��� ���� + ������ ls-la���� ����
void print_long_format(TNode* node) {
printf("%c", node->type);
print_permissions(node->permission);
printf(" %d %d %5d %02d-%02d %02d:%02d %s\n",
node->UID, node->GID, node->SIZE,
node->month, node->day, node->hour, node->minute,
node->name);
}

void print_short_format(TNode* node) {
if (strlen(node->name) < 8)
printf("%s\t\t", node->name);
else
printf("%s\t", node->name);
}

void command_ls(DTree* tree, int argc, char** argv) {
int show_all = 0, long_format = 0;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-a") == 0) show_all = 1;
else if (strcmp(argv[i], "-l") == 0) long_format = 1;
else if (strcmp(argv[i], "-al") == 0 || strcmp(argv[i], "-la") == 0)
show_all = long_format = 1;
}

int count = 0;

if (show_all) {
// "." ���
TNode* current = tree->current;
if (long_format) print_long_format(current);
else print_short_format(current);
count++;

// ".." ���
TNode* parent = current->Parent;
if (parent) {
if (long_format) print_long_format(parent);
else print_short_format(parent);
count++;
}

if (!long_format && count % 5 == 0) printf("\n");
}

TNode* node = tree->current->left;
while (node != NULL) {
while (node) {
if (!show_all && node->name[0] == '.') {
node = node->right;
continue;
}

if (long_format) {
printf("%c", node->type);
print_permissions(node->permission);
printf(" %d %d %5d %02d-%02d %02d:%02d %s\n",
node->UID, node->GID, node->SIZE,
node->month, node->day, node->hour, node->minute,
node->name);
}
if (long_format) print_long_format(node);
else {
printf("%s ", node->name);
print_short_format(node);
if (++count % 5 == 0) printf("\n");
}

node = node->right;
}

if (!long_format) printf("\n");
if (!long_format && count % 5 != 0) printf("\n");
}
95 changes: 64 additions & 31 deletions src/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,79 @@
#include "../include/osproject.h"
#include "../include/command.h"

extern DTree* tree;
void delete_node(DTree* dTree, const char* path, int recursive, int force, int verbose) {
TNode* currentN = dTree->current;
TNode* target = NULL;
TNode* tmpDir = NULL;
char tmp[MAXDIRECTORY];
char tmp2[MAXDIRECTORY];
char tmp3[MAXDIRECTORY];
char* str;
int val;

void delete_node(TNode* parent, const char* name, int recursive, int force, int verbose) {
TNode* prev = NULL;
TNode* curr = parent->left;
strncpy(tmp, path, MAXDIRECTORY);

while (curr) {
if (strcmp(curr->name, name) == 0) {
if (curr->type == 'd' && !recursive) {
if (!force)
printf("rm: ���丮 '%s'�� ������� -r �ɼ��� �ʿ��մϴ�.\n", name);
return;
}
// ��ΰ� ���Ե� ���
if (strchr(path, '/')) {
strncpy(tmp2, getDir(path), MAXDIRECTORY);
val = MovePath(dTree, tmp2);
if (val != 0) {
if (!force)
printf("rm: '%s': �׷� �����̳� ���͸��� �����ϴ�.\n", tmp2);
return;
}

if (curr->type == 'd' && recursive) {
while (curr->left)
delete_node(curr, curr->left->name, recursive, force, verbose);
}
str = strtok(tmp, "/");
while (str != NULL) {
strncpy(tmp3, str, MAXNAME);
str = strtok(NULL, "/");
}
}
else {
strncpy(tmp3, path, MAXNAME);
}

if (verbose)
printf("������: %s\n", curr->name);
// ���͸����� �������� �Ǻ�
target = ExistDir(dTree, tmp3, 'd');
if (target && !recursive) {
if (!force)
printf("rm: ���丮 '%s'�� ������� -r �ɼ��� �ʿ��մϴ�.\n", tmp3);
dTree->current = currentN;
return;
}
if (!target) {
target = ExistDir(dTree, tmp3, 'f');
}

if (prev)
prev->right = curr->right;
else
parent->left = curr->right;
if (!target) {
if (!force)
printf("rm: '%s': �׷� �����̳� ���͸��� �����ϴ�.\n", tmp3);
dTree->current = currentN;
return;
}

free(curr);
return;
}
// ���� Ȯ��
if (!force && (IsPermission(dTree->current, 'w') != 0 || IsPermission(target, 'w') != 0)) {
printf("rm: '%s'��(��) ���� �� �����ϴ�: Permission denied\n", tmp3);
dTree->current = currentN;
return;
}

prev = curr;
curr = curr->right;
// ��� ���� ó��
if (target->type == 'd' && recursive) {
while (target->left)
delete_node(dTree, target->left->name, recursive, force, verbose);
}

if (!force)
printf("rm: '%s': �׷� �����̳� ���͸��� �����ϴ�.\n", name);
// ���� ����
if (verbose)
printf("������: %s\n", tmp3);
RemoveDir(dTree, tmp3);

dTree->current = currentN; // ����ġ ����
}

void command_rm(int argc, char** argv) {
void command_rm(DTree* tree, int argc, char** argv) {
int recursive = 0, force = 0, verbose = 0;

int i = 1;
Expand All @@ -53,13 +86,13 @@ void command_rm(int argc, char** argv) {
else if (argv[i][j] == 'f') force = 1;
else if (argv[i][j] == 'v') verbose = 1;
else {
printf("�� �� ���� �ɼ�: -%c\n", argv[i][j]);
printf("rm: �� �� ���� �ɼ� -- '%c'\n", argv[i][j]);
return;
}
}
}

for (; i < argc; i++) {
delete_node(tree->current, argv[i], recursive, force, verbose);
delete_node(tree, argv[i], recursive, force, verbose);
}
}