Add ls comand

master
germanFid 2022-06-22 20:59:30 +03:00
parent 570cf96e60
commit 446bf42b31
1 changed files with 30 additions and 3 deletions

View File

@ -219,8 +219,6 @@ int executeCommand(char* command, char* minorArg, Folder* majorArgFolder, File*
{
if (!strcmp(command, "cd"))
{
printf("COMMAND: cd\n");
printf("%d", majorArgFile);
if (!majorArgIsFolder)
{
return FAILURE;
@ -230,6 +228,26 @@ int executeCommand(char* command, char* minorArg, Folder* majorArgFolder, File*
return SUCCESS;
}
if (!strcmp(command, "ls"))
{
Folder* PrintDirectory;
if (!majorArgIsFolder)
{
PrintDirectory = *CurrentFolder;
}
else
{
PrintDirectory = majorArgFolder;
}
if (minorArg != NULL)
print_list(PrintDirectory, 1);
else
print_list(PrintDirectory, 0);
}
else
{
printf("Unknown command: %s", command);
@ -265,8 +283,17 @@ int commandParserHandler(char* input, Folder* RootFolder, Folder** CurrentFolder
{
case 0:
// команда
for (size_t i = 0; i < strlen(istr); i++)
{
if (istr[i] == '\n')
{
istr[i] = '\0';
}
}
if (checkCommandValid(istr)) // Если команда неправильная
{
printf("Incorrect Command!");
result = FAILURE;
goto cleanup;
}
@ -312,7 +339,7 @@ int commandParserHandler(char* input, Folder* RootFolder, Folder** CurrentFolder
istr = strtok(NULL, sep); // Выделяем следующую часть
}
printf("%s, %s, %s", command, arg1, arg2);
printf("%s, %s, %s\n", command, arg1, arg2);
result = executeCommand(command, arg1, ResultFolder, ResultFile, ResultFolder != NULL, RootFolder, CurrentFolder);
// printf("- exec: %d", r);