2000-05-06 21:34:20 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
|
|
|
/* dosnames.c */
|
|
|
|
/* DOS-C */
|
|
|
|
/* */
|
|
|
|
/* Generic parsing functions for file name specifications */
|
|
|
|
/* */
|
|
|
|
/* Copyright (c) 1994 */
|
|
|
|
/* Pasquale J. Villani */
|
|
|
|
/* All Rights Reserved */
|
|
|
|
/* */
|
|
|
|
/* This file is part of DOS-C. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is free software; you can redistribute it and/or */
|
|
|
|
/* modify it under the terms of the GNU General Public License */
|
|
|
|
/* as published by the Free Software Foundation; either version */
|
|
|
|
/* 2, or (at your option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is distributed in the hope that it will be useful, but */
|
|
|
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
|
|
|
|
/* the GNU General Public License for more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public */
|
|
|
|
/* License along with DOS-C; see the file COPYING. If not, */
|
|
|
|
/* write to the Free Software Foundation, 675 Mass Ave, */
|
|
|
|
/* Cambridge, MA 02139, USA. */
|
|
|
|
/* */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
#include "portab.h"
|
|
|
|
|
|
|
|
#ifdef VERSION_STRINGS
|
2001-11-18 15:01:12 +01:00
|
|
|
static BYTE *dosnamesRcsId =
|
|
|
|
"$Id$";
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "globals.h"
|
|
|
|
|
2002-02-03 23:40:24 +01:00
|
|
|
const char _DirWildNameChars[] = "*?./\\\"[]:|<>+=;,";
|
2001-11-18 00:26:45 +01:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
#define PathSep(c) ((c)=='/'||(c)=='\\')
|
|
|
|
#define DriveChar(c) (((c)>='A'&&(c)<='Z')||((c)>='a'&&(c)<='z'))
|
2002-08-04 03:14:18 +02:00
|
|
|
#define DirChar(c) (((unsigned char)(c)) >= ' ' && \
|
|
|
|
!strchr(_DirWildNameChars+5, (c)))
|
|
|
|
#define WildChar(c) (((unsigned char)(c)) >= ' ' && \
|
|
|
|
!strchr(_DirWildNameChars+2, (c)))
|
|
|
|
#define NameChar(c) (((unsigned char)(c)) >= ' ' && \
|
|
|
|
!strchr(_DirWildNameChars, (c)))
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
VOID XlateLcase(BYTE * szFname, COUNT nChars);
|
2001-07-22 03:58:58 +02:00
|
|
|
VOID DosTrimPath(BYTE * lpszPathNamep);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Should be converted to a portable version after v1.0 is released. */
|
2001-11-04 20:47:39 +01:00
|
|
|
#if 0
|
2000-05-06 21:34:20 +02:00
|
|
|
VOID XlateLcase(BYTE * szFname, COUNT nChars)
|
|
|
|
{
|
|
|
|
while (nChars--)
|
|
|
|
{
|
|
|
|
if (*szFname >= 'a' && *szFname <= 'z')
|
|
|
|
*szFname -= ('a' - 'A');
|
|
|
|
++szFname;
|
|
|
|
}
|
|
|
|
}
|
2001-11-04 20:47:39 +01:00
|
|
|
#endif
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2000-06-21 20:16:46 +02:00
|
|
|
/*
|
|
|
|
MSD durring an FindFirst search string looks like this;
|
|
|
|
(*), & (.) == Current directory *.*
|
|
|
|
(\) == Root directory *.*
|
|
|
|
(..) == Back one directory *.*
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
This always has a "truename" as input, so we may do some shortcuts
|
2002-08-04 03:14:18 +02:00
|
|
|
|
|
|
|
returns number of characters in the directory component (up to the
|
|
|
|
last backslash, including d:) or negative if error
|
2000-06-21 20:16:46 +02:00
|
|
|
*/
|
2002-08-04 03:14:18 +02:00
|
|
|
int ParseDosName(const char *filename, char *fcbname, BOOL bAllowWildcards)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2002-08-04 03:14:18 +02:00
|
|
|
int nDirCnt, nFileCnt, nExtCnt;
|
|
|
|
const char *lpszLclDir, *lpszLclFile, *lpszLclExt;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Initialize the users data fields */
|
|
|
|
nDirCnt = nFileCnt = nExtCnt = 0;
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* NB: this code assumes ASCII */
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Now see how long a directory component we have. */
|
2002-08-04 03:14:18 +02:00
|
|
|
lpszLclDir = lpszLclFile = filename;
|
|
|
|
filename += 2;
|
|
|
|
|
|
|
|
while (DirChar(*filename))
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2002-08-04 03:14:18 +02:00
|
|
|
if (*filename == '\\')
|
|
|
|
lpszLclFile = filename + 1;
|
|
|
|
++filename;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2002-08-04 03:14:18 +02:00
|
|
|
nDirCnt = lpszLclFile - lpszLclDir;
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Fix lengths to maximums allowed by MS-DOS. */
|
2001-11-18 15:01:12 +01:00
|
|
|
if (nDirCnt > PARSE_MAX - 1)
|
|
|
|
nDirCnt = PARSE_MAX - 1;
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Parse out the file name portion. */
|
2002-08-04 03:14:18 +02:00
|
|
|
filename = lpszLclFile;
|
|
|
|
while (bAllowWildcards ? WildChar(*filename) :
|
|
|
|
NameChar(*filename))
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
++nFileCnt;
|
2002-08-04 03:14:18 +02:00
|
|
|
++filename;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2000-06-01 08:37:38 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
if (nFileCnt == 0)
|
2002-08-04 03:14:18 +02:00
|
|
|
{
|
2000-06-01 08:37:38 +02:00
|
|
|
/* Lixing Yuan Patch */
|
2001-11-18 15:01:12 +01:00
|
|
|
if (bAllowWildcards) /* for find first */
|
|
|
|
{
|
2002-08-04 03:14:18 +02:00
|
|
|
if (*filename != '\0')
|
2001-11-18 15:01:12 +01:00
|
|
|
return DE_FILENOTFND;
|
|
|
|
if (nDirCnt == 1) /* for d:\ */
|
|
|
|
return DE_NFILES;
|
2002-08-04 03:14:18 +02:00
|
|
|
memset(fcbname, '?', FNAME_SIZE + FEXT_SIZE);
|
|
|
|
return nDirCnt;
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return DE_FILENOTFND;
|
2002-08-04 03:14:18 +02:00
|
|
|
}
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Now we have pointers set to the directory portion and the */
|
|
|
|
/* file portion. Now determine the existance of an extension. */
|
2002-08-04 03:14:18 +02:00
|
|
|
lpszLclExt = filename;
|
|
|
|
if ('.' == *filename)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2002-08-04 03:14:18 +02:00
|
|
|
lpszLclExt = ++filename;
|
|
|
|
while (*filename)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2002-08-04 03:14:18 +02:00
|
|
|
if (bAllowWildcards ? WildChar(*filename) :
|
|
|
|
NameChar(*filename))
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
++nExtCnt;
|
2002-08-04 03:14:18 +02:00
|
|
|
++filename;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
else
|
|
|
|
{
|
2000-05-06 21:34:20 +02:00
|
|
|
return DE_FILENOTFND;
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
}
|
2002-08-04 03:14:18 +02:00
|
|
|
else if (*filename)
|
2000-05-06 21:34:20 +02:00
|
|
|
return DE_FILENOTFND;
|
|
|
|
|
|
|
|
/* Finally copy whatever the user wants extracted to the user's */
|
|
|
|
/* buffers. */
|
2002-08-04 03:14:18 +02:00
|
|
|
memset(fcbname, ' ', FNAME_SIZE + FEXT_SIZE);
|
|
|
|
memcpy(fcbname, lpszLclFile, nFileCnt);
|
|
|
|
memcpy(&fcbname[FNAME_SIZE], lpszLclExt, nExtCnt);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Clean up before leaving */
|
2000-06-01 08:37:38 +02:00
|
|
|
|
2002-08-04 03:14:18 +02:00
|
|
|
return nDirCnt;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|