mirror of
https://github.com/FDOS/kernel.git
synced 2025-07-23 13:54:30 +02:00
Split 8.3 FCB-style filename extraction from ParseDosName into a new
ConvertNameSZToName83 function, also used by dir_open(). git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1433 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
parent
8e2b96a70b
commit
a21bcd8a85
@ -75,13 +75,13 @@ VOID XlateLcase(BYTE * szFname, COUNT nChars)
|
|||||||
returns number of characters in the directory component (up to the
|
returns number of characters in the directory component (up to the
|
||||||
last backslash, including d:) or negative if error
|
last backslash, including d:) or negative if error
|
||||||
*/
|
*/
|
||||||
int ParseDosName(const char *filename, char *fcbname, BOOL bAllowWildcards)
|
int ParseDosName(const char *filename, BOOL bAllowWildcards)
|
||||||
{
|
{
|
||||||
int nDirCnt, nFileCnt, nExtCnt;
|
int nDirCnt;
|
||||||
const char *lpszLclDir, *lpszLclFile, *lpszLclExt;
|
const char *lpszLclDir, *lpszLclFile;
|
||||||
|
|
||||||
/* Initialize the users data fields */
|
/* Initialize the users data fields */
|
||||||
nDirCnt = nFileCnt = nExtCnt = 0;
|
nDirCnt = 0;
|
||||||
|
|
||||||
/* NB: this code assumes ASCII */
|
/* NB: this code assumes ASCII */
|
||||||
|
|
||||||
@ -101,12 +101,9 @@ int ParseDosName(const char *filename, char *fcbname, BOOL bAllowWildcards)
|
|||||||
filename = lpszLclFile;
|
filename = lpszLclFile;
|
||||||
while (bAllowWildcards ? WildChar(*filename) :
|
while (bAllowWildcards ? WildChar(*filename) :
|
||||||
NameChar(*filename))
|
NameChar(*filename))
|
||||||
{
|
|
||||||
++nFileCnt;
|
|
||||||
++filename;
|
++filename;
|
||||||
}
|
|
||||||
|
|
||||||
if (nFileCnt == 0)
|
if (filename == lpszLclFile)
|
||||||
{
|
{
|
||||||
int err = DE_PATHNOTFND;
|
int err = DE_PATHNOTFND;
|
||||||
if (bAllowWildcards && *filename == '\0' &&
|
if (bAllowWildcards && *filename == '\0' &&
|
||||||
@ -118,35 +115,21 @@ int ParseDosName(const char *filename, char *fcbname, BOOL bAllowWildcards)
|
|||||||
|
|
||||||
/* Now we have pointers set to the directory portion and the */
|
/* Now we have pointers set to the directory portion and the */
|
||||||
/* file portion. Now determine the existance of an extension. */
|
/* file portion. Now determine the existance of an extension. */
|
||||||
lpszLclExt = filename;
|
|
||||||
if ('.' == *filename)
|
if ('.' == *filename)
|
||||||
{
|
{
|
||||||
lpszLclExt = ++filename;
|
++filename;
|
||||||
while (*filename)
|
while (*filename)
|
||||||
{
|
{
|
||||||
if (bAllowWildcards ? WildChar(*filename) :
|
if (bAllowWildcards ? WildChar(*filename) :
|
||||||
NameChar(*filename))
|
NameChar(*filename))
|
||||||
{
|
|
||||||
++nExtCnt;
|
|
||||||
++filename;
|
++filename;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return DE_FILENOTFND;
|
return DE_FILENOTFND;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (*filename)
|
else if (*filename)
|
||||||
return DE_FILENOTFND;
|
return DE_FILENOTFND;
|
||||||
|
|
||||||
/* Finally copy whatever the user wants extracted to the user's */
|
|
||||||
/* buffers. */
|
|
||||||
memset(fcbname, ' ', FNAME_SIZE + FEXT_SIZE);
|
|
||||||
memcpy(fcbname, lpszLclFile, nFileCnt);
|
|
||||||
memcpy(&fcbname[FNAME_SIZE], lpszLclExt, nExtCnt);
|
|
||||||
|
|
||||||
/* Clean up before leaving */
|
|
||||||
|
|
||||||
return nDirCnt;
|
return nDirCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,18 +98,7 @@ f_node_ptr dir_open(register const char *dirname, f_node_ptr fnp)
|
|||||||
/* Convert the name into an absolute name for */
|
/* Convert the name into an absolute name for */
|
||||||
/* comparison... */
|
/* comparison... */
|
||||||
|
|
||||||
memset(fcbname, ' ', FNAME_SIZE + FEXT_SIZE);
|
dirname = ConvertNameSZToName83(fcbname, dirname);
|
||||||
|
|
||||||
for (i = 0; i < FNAME_SIZE + FEXT_SIZE; i++, dirname++)
|
|
||||||
{
|
|
||||||
char c = *dirname;
|
|
||||||
if (c == '.')
|
|
||||||
i = FNAME_SIZE - 1;
|
|
||||||
else if (c != '\0' && c != '\\')
|
|
||||||
fcbname[i] = c;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now search through the directory to */
|
/* Now search through the directory to */
|
||||||
/* find the entry... */
|
/* find the entry... */
|
||||||
@ -309,7 +298,7 @@ COUNT dos_findfirst(UCOUNT attr, BYTE * name)
|
|||||||
/* current directory, do a seek and read. */
|
/* current directory, do a seek and read. */
|
||||||
|
|
||||||
/* Parse out the file name */
|
/* Parse out the file name */
|
||||||
i = ParseDosName(name, SearchDir.dir_name, TRUE);
|
i = ParseDosName(name, TRUE);
|
||||||
if (i < SUCCESS)
|
if (i < SUCCESS)
|
||||||
return i;
|
return i;
|
||||||
/*
|
/*
|
||||||
@ -344,13 +333,10 @@ COUNT dos_findfirst(UCOUNT attr, BYTE * name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now initialize the dirmatch structure. */
|
/* Now initialize the dirmatch structure. */
|
||||||
|
ConvertNameSZToName83(dmp->dm_name_pat, &name[i]);
|
||||||
dmp->dm_drive = name[0] - 'A';
|
dmp->dm_drive = name[0] - 'A';
|
||||||
dmp->dm_attr_srch = attr;
|
dmp->dm_attr_srch = attr;
|
||||||
|
|
||||||
/* Copy the raw pattern from our data segment to the DTA. */
|
|
||||||
fmemcpy(dmp->dm_name_pat, SearchDir.dir_name, FNAME_SIZE + FEXT_SIZE);
|
|
||||||
|
|
||||||
if ((attr & (D_VOLID|D_DIR))==D_VOLID)
|
if ((attr & (D_VOLID|D_DIR))==D_VOLID)
|
||||||
{
|
{
|
||||||
/* Now do the search */
|
/* Now do the search */
|
||||||
@ -393,7 +379,7 @@ COUNT dos_findnext(void)
|
|||||||
/* Select the default to help non-drive specified path */
|
/* Select the default to help non-drive specified path */
|
||||||
/* searches... */
|
/* searches... */
|
||||||
fnp = &fnode[0];
|
fnp = &fnode[0];
|
||||||
dmp = fnp->f_dmp;
|
dmp = &sda_tmp_dm;
|
||||||
fnp->f_dpb = get_dpb(dmp->dm_drive);
|
fnp->f_dpb = get_dpb(dmp->dm_drive);
|
||||||
if (media_check(fnp->f_dpb) < 0)
|
if (media_check(fnp->f_dpb) < 0)
|
||||||
return DE_NFILES;
|
return DE_NFILES;
|
||||||
@ -503,3 +489,23 @@ int FileName83Length(BYTE * filename83)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* this routine converts a name portion of a fully qualified path */
|
||||||
|
/* name, so . and .. are not allowed, only straightforward 8+3 names */
|
||||||
|
const char *ConvertNameSZToName83(char *fcbname, const char *dirname)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
memset(fcbname, ' ', FNAME_SIZE + FEXT_SIZE);
|
||||||
|
|
||||||
|
for (i = 0; i < FNAME_SIZE + FEXT_SIZE; i++, dirname++)
|
||||||
|
{
|
||||||
|
char c = *dirname;
|
||||||
|
if (c == '.')
|
||||||
|
i = FNAME_SIZE - 1;
|
||||||
|
else if (c != '\0' && c != '\\')
|
||||||
|
fcbname[i] = c;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return dirname;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ COUNT dos_close(COUNT fd)
|
|||||||
f_node_ptr split_path(char * path, char * fcbname, f_node_ptr fnp)
|
f_node_ptr split_path(char * path, char * fcbname, f_node_ptr fnp)
|
||||||
{
|
{
|
||||||
/* Start off by parsing out the components. */
|
/* Start off by parsing out the components. */
|
||||||
int dirlength = ParseDosName(path, fcbname, FALSE);
|
int dirlength = ParseDosName(path, FALSE);
|
||||||
|
|
||||||
if (dirlength < SUCCESS)
|
if (dirlength < SUCCESS)
|
||||||
return (f_node_ptr) 0;
|
return (f_node_ptr) 0;
|
||||||
@ -292,6 +292,10 @@ f_node_ptr split_path(char * path, char * fcbname, f_node_ptr fnp)
|
|||||||
fnp = dir_open(path, fnp);
|
fnp = dir_open(path, fnp);
|
||||||
path[dirlength] = tmp;
|
path[dirlength] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Extract the 8.3 filename from the path */
|
||||||
|
ConvertNameSZToName83(fcbname, &path[dirlength]);
|
||||||
|
|
||||||
return fnp;
|
return fnp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ VOID ASMCFUNC DosIdle_hlt(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* dosnames.c */
|
/* dosnames.c */
|
||||||
int ParseDosName(const char *, char *, BOOL);
|
int ParseDosName(const char *, BOOL);
|
||||||
|
|
||||||
/* error.c */
|
/* error.c */
|
||||||
VOID dump(void);
|
VOID dump(void);
|
||||||
@ -146,7 +146,7 @@ BOOL dir_write_update(REG f_node_ptr fnp, BOOL update);
|
|||||||
COUNT dos_findfirst(UCOUNT attr, BYTE * name);
|
COUNT dos_findfirst(UCOUNT attr, BYTE * name);
|
||||||
COUNT dos_findnext(void);
|
COUNT dos_findnext(void);
|
||||||
void ConvertName83ToNameSZ(BYTE FAR * destSZ, BYTE FAR * srcFCBName);
|
void ConvertName83ToNameSZ(BYTE FAR * destSZ, BYTE FAR * srcFCBName);
|
||||||
int FileName83Length(BYTE * filename83);
|
const char *ConvertNameSZToName83(char *destFCBName, const char *srcSZ);
|
||||||
|
|
||||||
/* fatfs.c */
|
/* fatfs.c */
|
||||||
struct dpb FAR *get_dpb(COUNT dsk);
|
struct dpb FAR *get_dpb(COUNT dsk);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user