📄 fileutil.c
字号:
/*****************************************************************************
FILE NAME: fileutil.c
DESCRIPTION:
This module contains utility functions used in FSM.
Copyright (c) 2002, VIA Technologies, Inc.
*****************************************************************************/
#include "fsmdefs.h"
#include "String.h"
/*
0 : can't get the first path
!0 : success.
*/
uint32 GetFirstPath(const char * path, uint32 * start, uint32 * length)
{
if(path == NULL)
return 0;
*start = 0;
*length = 0;
while((*path == '/') || (*path == '\\'))
{
path++;
(*start)++;
}
while(*path != 0)
{
if((*path == '/') || (*path == '\\'))
break;
path++;
(*length)++;
}
return (*length != 0);
}
char * ExtractFilename(const char * path)
{
uint32 len;
if(path == NULL)
return NULL;
len = strlen(path);
if(len == 0)
return NULL;
while(len > 0)
{
if((path[len - 1] == '/') || (path[len - 1] == '\\'))
{
break;
}
len--;
}
return ((char *)(&path[len]));
}
/*
0 : no directory found.
!0 : success, directory end char postion is returned in end parameter.
*/
uint32 ExtractDir(const char * path, uint32 * end)
{
char * filename;
if(path == NULL)
return 0;
filename = ExtractFilename(path);
if(filename == NULL)
return 0;
*end = strlen(path) - strlen(filename);
return 1;
}
/* return 1 means matched */
uint32 FsmStringMatched(char *mode, char *src)
{
int i=0;
int j=0;
while(1)
{
if(mode[i]==0)
{
if(src[j]==0)
return 1;
else
return 0;
}
if(src[j]==0)
{
if(mode[i]!='*')
return 0;
else
{
i++;
continue;
}
}
if(mode[i]=='*')
{
while(1)
{
if(mode[i]==0)
return 1;
else if(mode[i]=='*')
{
i++;
continue;
}
else
break;
}
while(1)
{
if(src[j]==0)
return 0;
if(FsmStringMatched(&mode[i],&src[j]) == 1)
return 1;
else
{
j++;
continue;
}
}
}
else if(mode[i]=='?')
{
while(mode[i]=='?')
{
if(src[j]==0)
return 0;
j++; i++;
}
}
else
{
if (src[j]!=mode[i])
return 0;
else
{
i++; j++;
}
}
}
}
/*****************************************************************************
* $Log: fileutil.c $
* Revision 1.3 2004/03/17 12:57:48 zgy
* Revision 1.23 2004/03/16 15:54:13 jjs
* Revision 1.22 2004/03/11 14:35:20 jjs
* moved some function definitions to appropriate files.
* Revision 1.21 2003/11/11 11:30:04 jjs
* Added funtion definition of DfsFilenameValid.
* Revision 1.20 2003/11/05 11:38:29 jjs
* Revision 1.19 2003/11/05 11:07:20 jjs
* replaced the // with / * * /
* Revision 1.17 2003/10/08 21:09:24 jjs
* Revision 1.16 2003/10/08 18:11:38 jjs
* Revision 1.15 2003/10/08 12:43:35 jjs
* Revision 1.14 2003/09/19 14:08:30 wsm
* Revision 1.13 2003/09/16 18:06:10 wsm
* Revision 1.12 2003/09/16 17:02:27 wsm
* Revision 1.11 2003/09/16 11:26:30 wsm
* Revision 1.10 2003/09/15 09:42:43 wsm
* Revision 1.9 2003/09/14 16:57:02 jjs
* Revision 1.8 2003/09/12 15:25:44 wsm
* Revision 1.7 2003/09/12 14:52:43 wsm
* Revision 1.6 2003/09/12 14:26:55 wsm
* Revision 1.5 2003/09/12 10:15:46 wsm
* corretc code style
* Revision 1.4 2003/09/11 14:56:29 wsm
* update output message
* Revision 1.3 2003/09/11 09:47:58 wsm
* update the Macro name
* Revision 1.2 2003/09/10 19:09:34 wsm
* Revision 1.1 2003/09/09 15:07:32 wsm
* Initial revision
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -