📄 fileutil.c
字号:
* Returns NULL on a bad drive number otherwise a pointer to the
* first character in the rest of the path specifier.
*
*************************************************************************/
UINT8 *pc_parsedrive(INT16 *driveno, UINT8 *path)
{
UINT8 *p = path;
INT16 dno = -1;
/* get drive no */
if ( p && *p && (*(p+1) == ':') )
{
if ( ((*p) >= 'A') && ((*p) <= 'Z') )
dno = (INT16) (*p - 'A');
if ( ((*p) >= 'a') && ((*p) <= 'z') )
dno = (INT16) (*p - 'a');
p += 2;
}
else
dno = NU_Get_Default_Drive();
if ( (dno < 0) || (dno >= NDRIVES) )
return(NULL);
else
{
*driveno = dno;
return(p);
}
}
/************************************************************************
* FUNCTION
*
* pc_parsenewname
*
* DESCRIPTION
*
* If use wild card, setup the new file name.
*
* AUTHOR
*
* Kyoichiro Toda
*
* INPUTS
*
* *pfi File directory entry
* **newname File name(wild card)
* **newext File extension(wild card)
* *fname File name buffer
*
* OUTPUTS
*
* Always YES Success compleate.
*
*************************************************************************/
INT pc_parsenewname(DROBJ *pobj, UINT8 *name, UINT8 *ext,
VOID **new_name, VOID **new_ext, UINT8 *fname)
{
LNAMINFO *linfo;
DOSINODE pi;
UINT8 *p;
UINT8 *old;
UINT8 *op_nmend;
UINT8 *op_exend;
UINT8 old_name[EMAXPATH+1];
FINODE *pfi;
*new_name = *new_ext = '\0';
/* get long file name info */
linfo = &pobj->linfo;
/* Setup the old file name */
if (linfo->lnament) /* Long file name */
{
/* Convert directory entry long file name to character long file name. */
pc_cre_longname((UINT8 *)old_name, linfo);
}
else /* Short file name */
{
/* get file directory entry */
pfi = (FINODE *)pobj->finode;
pc_ino2dos(&pi, pfi);
/* Convert directory entry short file name to character short file name. */
pc_cre_shortname((UINT8 *)old_name, pi.fname, pi.fext);
}
/* Mark the old file name end. */
p = old_name;
op_nmend = NULL;
while (*p)
{
if (*p == '.')
{
if (*(p+1) != '.')
op_nmend = p;
}
p++;
}
op_exend = p;
if (!op_nmend)
op_nmend = op_exend;
/* Setup the new file name pointer */
*new_name = fname;
/* Setup the new file name */
p = name;
old = old_name;
while (*p)
{
if (*p == '*')
{
/* More the new file name. */
if (old < op_nmend)
{
while (old != op_nmend)
{
*fname = *old++;
fname++;
}
break;
}
}
else if (*p == '?')
{
*fname = *old;
}
else
{
*fname = *p;
}
fname++; old++; p++;
/* File name end ? */
if ( ext && (p == (ext-1)) )
break;
}
/* Setup the new file extension. */
if (ext)
{
/* file name .ext */
*fname = '.'; fname++;
p = ext;
old = op_nmend + 1;
/* Setup the new file extension pointer */
*new_ext = fname;
while (*p)
{
if (*p == '*')
{
/* More the new file extension. */
if (old < op_exend)
{
while (old != op_exend)
{
*fname = *old++;
fname++;
}
break;
}
}
else if (*p == '?')
{
*fname = *old;
}
else
{
*fname = *p;
}
fname++; old++; p++;
}
}
*fname = '\0';
return(YES);
}
/************************************************************************
* FUNCTION
*
* pc_next_fparse
*
* DESCRIPTION
*
* Next upperbar file name.
* Create a filename~XXX.
*
* AUTHOR
*
* Kyoichiro Toda
*
* INPUTS
*
* filename Upperbar file name.
*
* OUTPUTS
*
* YES Success compleate.
* NO Can't create new filename.
*
*************************************************************************/
INT pc_next_fparse(UINT8 *filename)
{
UINT8 *pfr;
UINT8 *pupbar;
UINT8 *pnamend;
UINT32 tailno = 0L;
UINT32 temp;
UINT8 nm;
INT16 n = 0;
INT16 i;
/* Defaults */
pfr = filename;
pnamend = pupbar = 0;
/* Mark the upperbar opinter and filenumber opinter. */
while (*pfr)
{
/* SPR245 7-20-01 this was the original code
if ( (*(pfr+1) == '\0') || (*(pfr+1) == ' ') )
pnamend = pfr; *****/
if( pnamend == 0 ) /* SPR245 7-21-01 new code */
{
if ( (*(pfr+1) == '\0') || (*(pfr+1) == ' ') )
pnamend = pfr;
} /* End SPR245 new code */
if (*pfr == '~')
pupbar = pfr;
pfr++;
/* File name end ? */
if (*pfr == '.')
break;
}
/* Not use the filename upperbar and filenumber. */
if ( (!pnamend) || (!pupbar) )
return(NO);
/* Take a filename number(~XXX) */
pfr = pnamend;
temp = 1L;
while (pfr != pupbar)
{
tailno += (*pfr - '0') * temp;
temp *= 10L;
pfr--;
}
/* Next a filename number. */
tailno +=1;
/* How many single figures */
temp = tailno;
while (temp)
{
temp /= 10L;
n++;
}
/* Set the upperbar mark. */
if ((pnamend-n) > filename)
*(pnamend-n) = '~';
else
return(NO);
/* Set the next number. */
temp = 1L;
for (i = 0; i < n; i++)
{
nm = (UINT8) (((tailno%(temp*10))/temp) + '0');
temp *= 10L;
if (filename < (pnamend-i))
*(pnamend-i) = nm;
else
return(NO);
}
return(YES);
}
/************************************************************************
* FUNCTION
*
* pc_fileparse
*
* DESCRIPTION
*
* Copy the short file name and the short file extension to the
* buffer of an output from the start pointer of the file name and
* the extension.End each name with '\0'. It will be
* unsuccessfully completed when the character that can not be used
* in the file name is used. When the long file name uses more than
* eight characters in the file name, uses lower case,
* uses ' = ' ' [ '' ] ' ' ; ' ' + ' ' , ' ' ' ' . ', or uses
* more than four characters in the extension, the short file name
* is created by using the first six characters of the long file
* name with an upper bar and 1following it. The upper function
* that calls these function has to prepare at least nine short
* file name buffer and four short file name extension buffer, both
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -