fileutil.c
来自「好记星的控件,包括button,list,对文件操作」· C语言 代码 · 共 1,674 行 · 第 1/5 页
C
1,674 行
/* Get last slash position and last period position and check length. */
while (*pfr)
{
/* Is current pointer is slash ? */
if (*pfr == BACKSLASH)
pslash = pfr;
/* Is current pointer is period ? */
if (*pfr == '.')
{
/* Note: Not mark the next name period, backslash and NULL */
if ( (*(pfr+1) != '.') && (*(pfr+1) != BACKSLASH) && (*(pfr+1) != '\0') )
pperiod = pfr;
}
/*** victor for UNICODE*/
if ( *pfr > 0x7F){
pfr++;
length++;
}
/****/
pfr++;
length++;
/* Check length */
if (length > EMAXPATH)
return(NUF_LONGPATH);
}
/**** Setup the path pointer ****/
if (pslash) /* Is the path include slash ? */
{
/* Yes, we assume pathname is specified. */
if (colon)
{
*topath = path + 2;
}
else
{
*topath = path;
}
}
else
{
/* No slash */
if (colon)
{
*pfname = path + 2;
}
else
{
*pfname = path;
}
/* Special cases of "." or ".." */
if ( ((**(UINT8 **)pfname == '.') && (*((*(UINT8 **)pfname)+1) == '\0')) ||
((**(UINT8 **)pfname == '.') && (*((*(UINT8 **)pfname)+1) == '.')) && (*((*(UINT8 **)pfname)+2) == '\0') )
{
/**topath = path;*/
return(NU_SUCCESS);
}
else
*topath = '\0';
}
/**** Setup the filename pointer ****/
if (pslash) /* The path include slash.*/
{
if ( *(pslash+1) != '\0' )
*pfname = pslash + 1;
else
*pfname = '\0';
}
else /* No slash */
{
if (colon) /* C:filename...... */
{
if ( *(path+2) != '\0' )
*pfname = path + 2;
else
*pfname = '\0';
}
else /* Only filename */
{
*pfname = path;
}
}
/* Check the filename */
if (*pfname)
{
temp = (UINT8 *)(*pfname);
/* Special cases of .\ or ..\ or . or ..*/
if (*temp == '.')
{
if (*(temp+1) == '.')
{
if ((*(temp+2) != BACKSLASH) && (*(temp+2) != '\0')) /* ..\ or .. */
return(NUF_INVNAME);
}
else if (*(temp+1) == BACKSLASH) /* .\ */
{
if (*(temp+2) != '\0')
return(NUF_INVNAME);
}
else /* . */
{
if (*(temp+1) != '\0')
return(NUF_INVNAME);
}
}
else
{
/* Nothing file extension
Delete filename period. filename..... */
if (!pperiod)
{
while (*temp)
{
if (*temp == '.')
{
/* filename...... -> filename */
if ( (*(temp+1) == '\0') || (*(temp+1) == '.') )
{
*temp = '\0';
}
}
temp++;
}
}
}
}
/* Check the path name */
temp = (UINT8 *)(*topath);
length = 0;
if (*topath)
{
while (temp[length])
{
/* Special cases of .\ or ..\ */
if (temp[0] == '.')
{
if (temp[1] == '.')
{
if (temp[2] == BACKSLASH)
length += 3;
}
else if (temp[1] == BACKSLASH)
{
length += 2;
}
else
return(NUF_INVNAME);
}
/* \..\ or \.\ or \. or \.. */
if (temp[length] == BACKSLASH)
{
if (temp[length+1] == '.')
{
if ((temp[length+2] == '.'))
{
if ( (temp[length+3] != BACKSLASH) && (temp[length+3] != '\0') )
return(NUF_INVNAME);
length += 3;
}
else if ( (temp[length+2] == BACKSLASH) || (temp[length+2] == '\0') )
{
length += 2;
}
else
return(NUF_INVNAME);
}
}
/* other case. exp \sub..\ */
if (temp[length] == '.')
{
if (temp[length+1] == BACKSLASH)
return(NUF_INVNAME);
}
/* Path end ? */
if ( (temp + length) == pslash)
break;
/*** victor for UNICODE */
if ( temp[length] > 0x7F){
length++;
}
/****/
length++;
}
}
/**** Setup the file extension opinter ****/
if ((*pfname) && pperiod)
{
/* Check the file extension
Delete extension period.
xxxx.extension...... -> extension */
temp = pperiod + 1;
while (*temp)
{
if (*temp == '.')
{
if ( (*(temp+1) == '\0') || (*(temp+1) == '.') )
{
*temp = '\0';
}
}
/*** victor for UNICODE */
if ( *temp > 0x7F){
temp++;
}
/****/
temp++;
}
*pfext = pperiod + 1;
}
else
{
*pfext = '\0';
}
return(NU_SUCCESS);
}
/************************************************************************
* FUNCTION
*
* pc_patcomp
*
* DESCRIPTION
*
* Compare strings1 and strings2 as upper letter. Wild card is
* available.
*
* AUTHOR
*
* Takahiro Takahashi
*
*
* INPUTS
*
* *disk_fnam Pointer to filename in disk
* *in_fnam Pointer to filename which
* application specified.
*
* OUTPUTS
*
* YES compare match.
* NO Not match.
*
*
*************************************************************************/
INT pc_patcmp(UINT8 *disk_fnam, UINT8 *in_fnam )
{
/*** victor for UNICODE
UINT8 c1, c2;*/
UINT16 c1, c2;
/****/
/* But E5 in the Pattern matches 0x5 */
if (*in_fnam == PCDELETE)
{
if (*disk_fnam == 0x5)
{
disk_fnam++;
in_fnam++;
}
else
return(NO);
}
for (;;)
{
if (! *disk_fnam) /* End of the filename */
{
if ( (! *in_fnam ) || (*in_fnam == BACKSLASH) )
return(YES);
else
return(NO);
}
if (*in_fnam == '*') /* '*' matches the rest of the name */
{
in_fnam++;
if (! *in_fnam)
return(YES);
for (; *disk_fnam; disk_fnam++) /* Compare after wild card */
{
if (YES == pc_patcmp(disk_fnam, in_fnam))
return(YES);
/*** victor for UNICODE */
if (*disk_fnam > 0x7f)
disk_fnam++;
/****/
}
if ( (*in_fnam == '.') && (*(in_fnam+1) == '*') && (*(in_fnam+2)=='\0') )
return(YES);
return(NO);
}
if (*disk_fnam == '*') /* '*' matches the rest of the name */
{
disk_fnam++;
if (! *disk_fnam)
return(YES);
for (; *in_fnam; in_fnam++) /* Compare after wild card */
{
if (YES == pc_patcmp(in_fnam, disk_fnam) )
return(YES);
/*** victor for UNICODE */
if (*in_fnam > 0x7f)
in_fnam++;
/****/
}
if ( (*disk_fnam == '.') && (*(disk_fnam+1) == '*') && (*(disk_fnam+2) =='\0') )
return(YES);
return(NO);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?