📄 fsel.c
字号:
/*
*********************************************************************************************************
* USDK80
* The FIFO
*
*
* All Rights Reserved
*
* File : fsel.c
* By : phchen
*********************************************************************************************************
*/
#include "string.h"
#include "fs_api.h"
char *EXT_FEL[2];
int api_sel_init(void)
{
EXT_FEL[0] = 0;
EXT_FEL[1] = 0;
return 1;
}
int api_sel_exit(void)
{
EXT_FEL[0] = 0;
EXT_FEL[1] = 0;
return 1;
}
int api_sel_open(char mode, int param)
{
int i;
for(i = 0;i < 2;i++)
if(EXT_FEL[i] == 0)
{
EXT_FEL[i] = (char*)param;
return i+1;
}
return -1;
}
int api_sel_close(int sel)
{
EXT_FEL[sel - 1] = 0;
return 1;
}
int api_sel_SetMode(int sel, unsigned char mode, int param)
{
EXT_FEL[sel - 1] = (char*)param;
return 1;
}
int api_sel_TotalFileNum(int sel)
{
struct FS_DIRENT *dirEnt;
FS_DIR *dir;
char ext[4];
char *EXT;
int i, j;
EXT = EXT_FEL[sel - 1];
ext[0] = ' ';
ext[1] = ' ';
ext[2] = ' ';
ext[3] = 0;
dir = FS_OpenDir("\\");
for(i=0;;)
{
dirEnt = FS_ReadDir(dir, ext);
if(!dirEnt )
{
FS_CloseDir(dir);
return i;
}
for(j = 0; EXT[j<<2] != 0; j++)
{
if( memcmp(dirEnt->d_name + 9, &EXT[j<<2], 3) == 0)
{
i++;
break;
}
}
}
}
int api_fsel_getNextFileNo(int sel, int fileNo)
{
int dirEntPtr;
struct FS_DIRENT *dirEnt;
FS_DIR *dir;
char ext[4];
char *EXT;
int i, j, n;
EXT = EXT_FEL[sel - 1];
ext[0] = ' ';
ext[1] = ' ';
ext[2] = ' ';
ext[3] = 0;
n = fileNo + 1;
dir = FS_OpenDir("\\");
for(i=0; i<n;)
{
dirEntPtr = (int)FS_ReadDir(dir, ext);
if(dirEntPtr <= 0)
{
FS_CloseDir(dir);
return 0;
}
for(j = 0; EXT[j<<2] != 0; j++)
{
dirEnt = (struct FS_DIRENT *)dirEntPtr;
if( memcmp(dirEnt->d_name + 9, &EXT[j<<2], 3) == 0)
{
i++;
break;
}
}
}
FS_CloseDir(dir);
return n;
}
int api_sel_CurFileNo(int sel)
{
return 1;
}
int api_sel_TotalTypeNum(int sel)
{
return 1;
}
int api_sel_CurTypeNo(int sel)
{
return 1;
}
int api_sel_typeNoByFileNo(int sel, int fileNo)
{
return 1;
}
FS_FILE *api_sel_OpenNextFileByNo(int sel, int *num)
{
struct FS_DIRENT *dirEnt;
int dirEntPtr;
FS_DIR *dir;
FS_FILE *file;
char ext[4];
char *EXT;
int i, j, n;
EXT = EXT_FEL[sel - 1];
ext[0] = ' ';
ext[1] = ' ';
ext[2] = ' ';
ext[3] = 0;
n = *num + 1;
dir = FS_OpenDir("\\");
for(i=0; i<n;)
{
dirEntPtr = (int)FS_ReadDir(dir, ext);
if(dirEntPtr <= 0)
{
FS_CloseDir(dir);
return 0;
}
for(j = 0; EXT[j<<2] != 0; j++)
{
dirEnt = (struct FS_DIRENT *)dirEntPtr;
if( memcmp(dirEnt->d_name + 9, &EXT[j<<2], 3) == 0)
{
i++;
break;
}
}
}
dirEnt = (struct FS_DIRENT *)dirEntPtr;
file = FS_FOpen(dirEnt->d_name, "rb");
if(file == NULL)
{
for(;;);
}
FS_CloseDir(dir);
if(file)
{
*num = n;
}
return file;
}
FS_FILE *api_sel_OpenPrevFileByNo(int sel, int *num)
{
struct FS_DIRENT *dirEnt;
FS_DIR *dir;
FS_FILE *file;
char ext[4];
char *EXT;
int i, j, n;
EXT = EXT_FEL[sel - 1];
ext[0] = ' ';
ext[1] = ' ';
ext[2] = ' ';
ext[3] = 0;
n = *num - 1;
if(0 == n )
{
return 0;
}
dir = FS_OpenDir("\\");
for(i = 0; i< n;)
{
dirEnt = FS_ReadDir(dir, ext);
if(dirEnt != 0)
{
FS_CloseDir(dir);
return 0;
}
for(j = 0; EXT[j<<2] != 0; j++)
{
if( memcmp(dirEnt->d_name + 9, &EXT[j<<2], 3) == 0)
{
i++;
break;
}
}
}
file = FS_FOpen(dirEnt->d_name, "rb");
if(file == NULL)
{
for(;;);
}
FS_CloseDir(dir);
//file = FS_FOpen("1.hex", "rb");
//if(1 == *num)
//{
// return 0;
//}
if(file)
{
*num = n;
}
return file;
}
FS_FILE *api_sel_OpenFilebyNo(int sel, int num)
{
struct FS_DIRENT *dirEnt;
FS_DIR *dir;
FS_FILE *file;
char ext[4];
char *EXT;
int i, j;
EXT = EXT_FEL[sel - 1];
ext[0] = ' ';
ext[1] = ' ';
ext[2] = ' ';
ext[3] = 0;
dir = FS_OpenDir("\\");
for(i=0; i< num;)
{
dirEnt = FS_ReadDir(dir, ext);
if(!dirEnt )
{
FS_CloseDir(dir);
return 0;
}
for(j = 0; EXT[j<<2] != 0; j++)
{
if( memcmp(dirEnt->d_name + 9, &EXT[j<<2], 3) == 0)
{
i++;
break;
}
}
}
file = FS_FOpen(dirEnt->d_name, "rb");
if(file == NULL)
{
for(;;);
}
FS_CloseDir(dir);
//file = FS_FOpen("1.hex", "rb");
return file;
}
// 返回:文件序号
int api_sel_SetFullPath(int sel, int param)
{
return 1;
}
int api_sel_GetFullPath(int sel, int param)
{
return 1;
}
int api_sel_GetFileNameByNo(int sel, char *buffer, int num)
{
struct FS_DIRENT *dirEnt;
FS_DIR *dir;
char ext[4];
char *EXT;
int i, j;
EXT = EXT_FEL[sel - 1];
ext[0] = ' ';
ext[1] = ' ';
ext[2] = ' ';
ext[3] = 0;
dir = FS_OpenDir("\\");
for(i=0; i< num;)
{
dirEnt = FS_ReadDir(dir, ext);
if(!dirEnt )
{
FS_CloseDir(dir);
return 0;
}
for(j = 0; EXT[j<<2] != 0; j++)
{
if( memcmp(dirEnt->d_name + 9, &EXT[j<<2], 3) == 0)
{
i++;
break;
}
}
}
//for( i = 0; i < 32; i++)
// buffer[i] = dirEnt->d_name[i];
strcpy( buffer, dirEnt->d_name);
FS_CloseDir(dir);
return 1;
}
int api_sel_GetNextFileNameByNo(int sel, char *buffer, int fileNo)
{
struct FS_DIRENT *dirEnt;
int dirEntPtr;
FS_DIR *dir;
char ext[4];
char *EXT;
int i, j, n;
EXT = EXT_FEL[sel - 1];
ext[0] = ' ';
ext[1] = ' ';
ext[2] = ' ';
ext[3] = 0;
n = fileNo + 1;
dir = FS_OpenDir("\\");
for(i=0; i<n;)
{
dirEntPtr = (int)FS_ReadDir(dir, ext);
if(dirEntPtr <= 0)
{
FS_CloseDir(dir);
return 0;
}
for(j = 0; EXT[j<<2] != 0; j++)
{
dirEnt = (struct FS_DIRENT *)dirEntPtr;
if( memcmp(dirEnt->d_name + 9, &EXT[j<<2], 3) == 0)
{
i++;
break;
}
}
}
dirEnt = (struct FS_DIRENT *)dirEntPtr;
strcpy( buffer, dirEnt->d_name);
FS_CloseDir(dir);
return n;
}
int api_sel_GetTypeNameByNo(int sel, char *buffer, int typeNo)
{
return 1;
}
int api_sel_GetFileInfoByFileNo(int sel, int fileNo, int param)
{
return 1;
}
/*
int _sel_GetFileNameByNo(int fileno, char *buffer, char ext[][4], int extno)
{
struct FS_DIRENT *dirEnt;
FS_DIR *dir;
char EXT_ALL[4];
int i,j;
EXT_ALL[0] = ' ';
EXT_ALL[1] = ' ';
EXT_ALL[2] = ' ';
EXT_ALL[3] = 0;
dir = FS_OpenDir("\\");
for(i=0; i< num;)
{
dirEnt = FS_ReadDir(dir, EXT_ALL);
if(!dirEnt )
{
FS_CloseDir(dir);
return 0;
}
for(j=0;j<extno;j++)
{
if( memcmp(dirEnt->d_name + 9, ext[j], 3) == 0)
{
i++;
break;
}
}
}
strcpy( buffer, dirEnt->d_name);
FS_CloseDir(dir);
return 1;
}
int _sel_GetTotalNo(char ext[][4], int extno)
{
struct FS_DIRENT *dirEnt;
FS_DIR *dir;
char EXT_ALL[4];
int i,j;
EXT_ALL[0] = ' ';
EXT_ALL[1] = ' ';
EXT_ALL[2] = ' ';
EXT_ALL[3] = 0;
dir = FS_OpenDir("\\");
for(i=0;;)
{
dirEnt = FS_ReadDir(dir, EXT_ALL);
if(!dirEnt )
{
FS_CloseDir(dir);
return i;
}
for(j=0;j<extno;j++)
{
if( memcmp(dirEnt->d_name + 9, ext[j], 3) == 0)
{
i++;
break;
}
}
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -