📄 fileutil.c
字号:
}
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) != '\\') && (*(temp+2) != '\0')) /* ..\ or .. */
return(NUF_INVNAME);
}
else if (*(temp+1) == '\\') /* .\ */
{
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] == '\\')
length += 3;
}
else if (temp[1] == '\\')
{
length += 2;
}
else
return(NUF_INVNAME);
}
/* \..\ or \.\ or \. or \.. */
if (temp[length] == '\\')
{
if (temp[length+1] == '.')
{
if ((temp[length+2] == '.'))
{
if ( (temp[length+3] != '\\') && (temp[length+3] != '\0') )
return(NUF_INVNAME);
length += 3;
}
else if ( (temp[length+2] == '\\') || (temp[length+2] == '\0') )
{
length += 2;
}
else
return(NUF_INVNAME);
}
}
/* other case. exp \sub..\ */
if (temp[length] == '.')
{
if (temp[length+1] == '\\')
return(NUF_INVNAME);
}
/* Path end ? */
if ( (temp + length) == pslash)
break;
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';
}
}
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 )
{
UINT8 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);
}
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);
}
if ( (*disk_fnam == '.') && (*(disk_fnam+1) == '*') && (*(disk_fnam+2) =='\0') )
return(YES);
return(NO);
}
/* Convert to upper letter */
if ( (*disk_fnam >= 'a') && (*disk_fnam <= 'z') )
c1 = (UINT8) ('A' + *disk_fnam - 'a');
else
c1 = *disk_fnam;
/* Convert to upper letter */
if ( (*in_fnam >= 'a') && (*in_fnam <= 'z') )
c2 = (UINT8) ('A' + *in_fnam - 'a');
else
c2 = *in_fnam;
if (c1 != c2 )
if (c2 != '?') /* ? is wild card */
return(NO);
disk_fnam++;
in_fnam++;
}
}
/************************************************************************
* FUNCTION
*
* pc_strcat
*
* DESCRIPTION
*
* strcat
*
* AUTHOR
*
* Kyoichiro Toda
*
* INPUTS
*
* to To data buffer
* from From data buffer
*
* OUTPUTS
*
* None.
*
*************************************************************************/
VOID pc_strcat(UINT8 *to, UINT8 *from)
{
while (*to) to++;
while (*from) *to++ = *from++;
*to = '\0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -