📄 dir_func.c
字号:
//////////////////////////////////////////////////////////////////////////
#include "general.h"
#include "s_isdirreg.h"
#include "the_syscalls.h"
#include "shell_head.h"
//////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
int DIR_Func(void)
{
int temp_dirflag = 0;
int temp_anyflag0 = 0;
int temp_anyflag1 = 0;
int temp_anyflag2 = 0;
int temp_dirindex = 0;
int temp_anyindex0 = 0;
int temp_anyindex1 = 0;
int temp_index = 0;
unsigned char * temp_pChar, * temp_pChar0;
int temp_Ret, temp_len0, temp_len1;
unsigned long temp_size,temp_datetime;
int i,j,k;
shell_nrDirs = 0;
shell_nrFiles = 0;
if (command_params > 1)
{
the_screen_call18("\n\r DIR bad parameters!");
return -1;
}
if (command_params == 0)
{
command_buf[1] = 0;
command_buf[2] = '.';
command_buf[3] = 0;
command_index = 1;
command_params = 1;
temp_dirflag = 1;
}
else
{
temp_index = command_index + 1;
while (command_buf[temp_index])
{
if ((command_buf[temp_index] == '/') ||
(command_buf[temp_index] == ':') ||
(command_buf[temp_index] == '|'))
{
the_screen_call18("\n\r DIR bad parameters!");
return -1;
}
temp_dirflag = 0;
if (command_buf[temp_index] == '\\')
{
if (temp_anyflag0 || temp_anyflag1 || temp_anyflag2)
{
the_screen_call18("\n\r DIR bad parameters!");
return -1;
}
temp_dirflag = 1;
temp_dirindex= temp_index;
}
if (command_buf[temp_index] == '*')
{
if ((temp_index == command_index + 1) || (command_buf[temp_index - 1] == '\\'))
{
temp_anyflag0 = 1;
temp_anyindex0 = temp_index;
}
else
{
if (temp_anyflag1 == 0)
{
temp_anyflag1 = 1;
temp_anyindex1= temp_index;
}
}
}
if (command_buf[temp_index] == '?')
temp_anyflag2 = 1;
temp_index++;
}
if (temp_dirflag == 0)
{
if (temp_dirindex)
{
if ((command_buf[temp_dirindex + 1] == '.') &&
((command_buf[temp_dirindex + 2] == 0) ||
((command_buf[temp_dirindex + 2] == '.') && (command_buf[temp_dirindex + 3] == 0))))
temp_dirflag = 1;
else
{
for (temp_index = command_index + 1; temp_index <= temp_dirindex; temp_index++)
command_buf[temp_index - 2] = command_buf[temp_index];
command_buf[temp_dirindex - 1] = 0;
command_buf[temp_dirindex] = 0;
command_buf[command_index - 2] = temp_dirindex;
command_index = command_index - 2;
command_params= 2;
}
}
else
{
if ((command_buf[command_index + 1] == '.') &&
((command_buf[command_index + 2] == 0) ||
((command_buf[command_index + 2] == '.') && (command_buf[command_index + 3] == 0))))
temp_dirflag = 1;
else
{
command_buf[command_index - 3] = command_index;
command_buf[command_index - 2] = '.';
command_buf[command_index - 1] = 0;
command_buf[command_index] = 0;
command_index = command_index - 3;
command_params = 2;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
temp_pChar = command_buf + command_index + 1;
if (temp_dirflag || temp_anyflag0 || temp_anyflag1 || temp_anyflag2)
temp_Ret = the_file_dirstart(temp_pChar,0,0,0);
else
{
temp_dirflag = 1;
temp_index = command_buf[command_index];
temp_pChar0 = command_buf + temp_index + 1;
temp_Ret = the_file_dirstart(temp_pChar,temp_pChar0,dir_buffer,NAME_LEN + 10);
}
show_string("\n\r ",path0_buf);
if (temp_Ret == -1)
{
show_string("DIR bad parameters!",path0_buf + 6);
the_screen_call18(path0_buf);
}
else if (temp_Ret == 1)
{
if (dir_buffer[0] == 0)
show_nrDirs_nrFiles();
else
{
for (i = 0; i < NAME_LEN; i++)
path0_buf[i + 6] = dir_buffer[i + 1];
i = 0;
while ((i < NAME_LEN) && path0_buf[i + 6])
i++;
while (i < NAME_LEN + 9)
{
path0_buf[i + 6] = 0x20;
i++;
}
temp_datetime = *((unsigned long *)(dir_buffer + NAME_LEN + 2));
temp_size = *((unsigned long *)(dir_buffer + NAME_LEN + 6));
show_size_datetime(temp_size, temp_datetime, path0_buf + NAME_LEN + 15);
the_screen_call18(path0_buf);
shell_nrFiles++;
show_nrDirs_nrFiles();
}
}
else
{
///////////////////////////////////////////////
temp_Ret = the_file_rddir(dir_buffer,1344);
if (temp_dirflag ||
(temp_anyflag0 &&
((command_buf[temp_anyindex0 + 1] == 0) ||
(temp_anyflag1 && (temp_anyindex0 + 1 == temp_anyindex1)))))
{
while (temp_Ret > 0)
{
for (i = 0; i < temp_Ret; i++)
show_Dirs_Files(i);
temp_Ret = the_file_rddir(dir_buffer,1344);
}
show_nrDirs_nrFiles();
}
else
{
if (temp_anyflag0 && temp_anyflag1)
{
//////////////////////////////////////////////////////////
temp_len0 = temp_anyindex1 - temp_anyindex0 - 1;
while (temp_Ret > 0)
{
for (i = 0; i < temp_Ret; i++)
{
j = 0;
while ((j < NAME_LEN) && (dir_buffer[i * (NAME_LEN + 9) + j]))
j++;
temp_len1 = j;
if (temp_len0 > temp_len1)
continue;
temp_len1 = temp_len1 - temp_len0;
j = 0;
while (j <= temp_len1)
{
k = 0;
while (k < temp_len0)
{
if ((command_buf[temp_anyindex0 + k + 1] != '?') &&
(command_buf[temp_anyindex0 + k + 1] != dir_buffer[i * (NAME_LEN + 9) + j + k]))
break;
k++;
}
if (k == temp_len0)
break;
j++;
}
if (j <= temp_len1)
show_Dirs_Files(i);
}
temp_Ret = the_file_rddir(dir_buffer,1344);
}
show_nrDirs_nrFiles();
//////////////////////////////////////////////////////////
}
else if (temp_anyflag0)
{
//////////////////////////////////////////////////////////
temp_len0 = temp_anyindex0 + 1;
while (command_buf[temp_len0])
temp_len0++;
temp_len0 = temp_len0 - temp_anyindex0 - 1;
while (temp_Ret > 0)
{
for (i = 0; i < temp_Ret; i++)
{
j = 0;
while ((j < NAME_LEN) && (dir_buffer[i * (NAME_LEN + 9) + j]))
j++;
temp_len1 = j;
if (temp_len0 > temp_len1)
continue;
j = temp_len1 - temp_len0;
k = 0;
while (k < temp_len0)
{
if ((command_buf[temp_anyindex0 + k + 1] != '?') &&
(command_buf[temp_anyindex0 + k + 1] != dir_buffer[i * (NAME_LEN + 9) + j + k]))
break;
k++;
}
if (k == temp_len0)
show_Dirs_Files(i);
}
temp_Ret = the_file_rddir(dir_buffer,1344);
}
show_nrDirs_nrFiles();
//////////////////////////////////////////////////////////
}
else if (temp_anyflag1)
{
//////////////////////////////////////////////////////////
command_index = command_buf[command_index] + 1;
temp_len0 = temp_anyindex1 - command_index;
while (temp_Ret > 0)
{
for (i = 0; i < temp_Ret; i++)
{
j = 0;
while ((j < NAME_LEN) && (dir_buffer[i * (NAME_LEN + 9) + j]))
j++;
temp_len1 = j;
if (temp_len0 > temp_len1)
continue;
j = 0;
while (j < temp_len0)
{
if ((command_buf[command_index + j] != '?') &&
(command_buf[command_index + j] != dir_buffer[i * (NAME_LEN + 9) + j]))
break;
j++;
}
if (j == temp_len0)
show_Dirs_Files(i);
}
temp_Ret = the_file_rddir(dir_buffer,1344);
}
show_nrDirs_nrFiles();
//////////////////////////////////////////////////////////
}
else
{
//////////////////////////////////////////////////////////
command_index = command_buf[command_index] + 1;
temp_len0 = command_index;
while (command_buf[temp_len0])
temp_len0++;
temp_len0 = temp_len0 - command_index;
while (temp_Ret > 0)
{
for (i = 0; i < temp_Ret; i++)
{
j = 0;
while ((j < NAME_LEN) && (dir_buffer[i * (NAME_LEN + 9) + j]))
j++;
temp_len1 = j;
if (temp_len0 != temp_len1)
continue;
j = 0;
while (j < temp_len0)
{
if ((command_buf[command_index + j] != '?') &&
(command_buf[command_index + j] != dir_buffer[i * (NAME_LEN + 9) + j]))
break;
j++;
}
if (j == temp_len0)
show_Dirs_Files(i);
}
temp_Ret = the_file_rddir(dir_buffer,1344);
}
show_nrDirs_nrFiles();
//////////////////////////////////////////////////////////
}
}
///////////////////////////////////////////////
}
the_file_dirend();
///////////////////////////////////////////////////////////////////////
return 0;
}
//////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -