pathname.cpp File Reference

(r1785/r1282)

#include "camtypes.h"

Go to the source code of this file.

Defines

#define MAXDRIVE   3
#define MAXNAME   8
#define MAXNETNAME   256
#define MAXEXT   16
#define SEPARATOR   _T('/')
#define FULLSTOP   '.'
#define COLON   ':'
#define END_OF_PATH   '\0'
#define END_OF_STRING   '\0'
#define SEPARATOR_SYM   "\\"
#define FULLSTOP_SYM   "."
#define COLON_SYM   ":"
#define END_OF_PATH_SYM   "\0"
#define NET_DRIVE_SYM   "\\\\"

Functions

 DECLARE_SOURCE ("$Revision: 1282 $")
void AbbreviateName (LPTSTR lpszCanon, INT32 cchMax, BOOL bAtLeastName)
BOOL getDrive (const TCHAR **fn, TCHAR *drive)
 Parses the Drive location of file. Scope: Private.
BOOL getNetDrive (const TCHAR **fn, TCHAR *drive, BOOL *pBadCharacter)
 Parses the network Drive location of file and returns whether this was accomplished or not. The network name will consist of the server name followed by a mount point name. Scope: Private.
BOOL getIdentifier (const TCHAR **fn, TCHAR *identifier, UINT32 MaxSize, BOOL *pBadCharacter)
 Parses file or directory identifier Scope: Private.
BOOL getExtension (const TCHAR **fn, TCHAR *ext, UINT32 MaxSize, const TCHAR *StartOfPath)
 Parses from the specified position, which should be the last valid character on the pathname, backwards until we hit either:-
  • a full stop, in which case we have a valid filename extension, which we return
  • a path separator, in which case there is no extension
  • the start of the pathname, in which case there is no extension. Scope: Private.

BOOL getParentDirectory (const TCHAR **fn, TCHAR *directory, UINT32 MaxSize, const TCHAR *StartOfPath)
 Parses from the specified position, which should be something like the first valid character of the filename on the pathname, backwards until we hit either:-
  • a path separator, in which case we return the found name as a possible directory
  • the start of the pathname, in which case there is no directory name. Scope: Private.

BOOL IsReservedChar (const TCHAR **fn)
 Checks if character passed in is a special character allowed in file names. No longer used. Scope: Private Checks if character passed in is a reserved character allowed in file names. Does not check for terminators which are allowed by the callers such as . and backslash. These characters are considered illegal when converting long to short filenames and so it would seem sensible to limit their use. Scope: Private.
BOOL IsDeviceName (const String_256 &path)
 Parses a string representing a path and sees if it refers to a device name which would be illegal.


Define Documentation

#define COLON   ':'
 

Definition at line 126 of file pathname.cpp.

#define COLON_SYM   ":"
 

Definition at line 132 of file pathname.cpp.

#define END_OF_PATH   '\0'
 

Definition at line 127 of file pathname.cpp.

#define END_OF_PATH_SYM   "\0"
 

Definition at line 133 of file pathname.cpp.

#define END_OF_STRING   '\0'
 

Definition at line 128 of file pathname.cpp.

#define FULLSTOP   '.'
 

Definition at line 125 of file pathname.cpp.

#define FULLSTOP_SYM   "."
 

Definition at line 131 of file pathname.cpp.

#define MAXDRIVE   3
 

Definition at line 110 of file pathname.cpp.

#define MAXEXT   16
 

Definition at line 113 of file pathname.cpp.

#define MAXNAME   8
 

Definition at line 111 of file pathname.cpp.

#define MAXNETNAME   256
 

Definition at line 112 of file pathname.cpp.

#define NET_DRIVE_SYM   "\\\\"
 

Definition at line 134 of file pathname.cpp.

#define SEPARATOR   _T('/')
 

Definition at line 118 of file pathname.cpp.

#define SEPARATOR_SYM   "\\"
 

Definition at line 130 of file pathname.cpp.


Function Documentation

void AbbreviateName LPTSTR  lpszCanon,
INT32  cchMax,
BOOL  bAtLeastName
 

DECLARE_SOURCE "$Revision: 1282 $"   ) 
 

BOOL getDrive const TCHAR **  fn,
TCHAR drive
 

Parses the Drive location of file. Scope: Private.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/5/93
Parameters:
A pointer to the pointer to the path string [INPUTS]
drive - the parsed Drive Letter [OUTPUTS]
Returns:
TRUE if parsed ok and false otherwise
See also:
PathName();

SetPath();

Returns:
Errors: None

Definition at line 1133 of file pathname.cpp.

01134 {
01135     UINT32 i = 0;   
01136                        
01137     if  (String::IsAlpha(**fn))
01138     {
01139         drive[i++] = **fn;                      // Parse Drive Letter
01140         (*fn)++;
01141         if (**fn == COLON)                      // Parse colon
01142         {
01143             drive[i++] = **fn;
01144             (*fn)++;
01145             if (**fn == SEPARATOR)              // Parse slash
01146             {
01147                 drive[i++] = **fn;
01148                 (*fn)++;
01149             }
01150             else 
01151                 return FALSE;                    // Else Syntax error
01152         }
01153         else 
01154             return FALSE;   
01155     }
01156     else 
01157         return FALSE; 
01158     
01159     drive[i++] = END_OF_STRING;
01160 
01161     return TRUE;
01162 }

BOOL getExtension const TCHAR **  fn,
TCHAR ext,
UINT32  MaxSize,
const TCHAR StartOfPath
 

Parses from the specified position, which should be the last valid character on the pathname, backwards until we hit either:-

  • a full stop, in which case we have a valid filename extension, which we return
  • a path separator, in which case there is no extension
  • the start of the pathname, in which case there is no extension. Scope: Private.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/5/93
Parameters:
A pointer to the pointer to the path string [INPUTS] MaxSize - the maximum size of a network drive name StartOfPath - a pointer to the start of the path string
A file extension [OUTPUTS]
Returns:
TRUE if parsed ok FALSE otherwise
See also:
PathName(); IsValidAndReturnInfo(); SetPath();
Returns:
Errors: None

Definition at line 1350 of file pathname.cpp.

01351 {
01352     UINT32 i = 0; 
01353 
01354     // Search from the specified string end backwards until we find either:-
01355     // - a full stop indicating a valid extension
01356     // - a path separator indicating no file extension is present
01357     // - the start of the file indicating no file extension is present
01358     while ( 
01359             (**fn != SEPARATOR) &&              // is not at a path separating character
01360             (**fn != FULLSTOP) &&               // is not at a full stop character
01361             (*fn != StartOfPath) &&             // is not at the start of the path string
01362             (i < MaxSize)                       // is not maximum size 
01363           )
01364     { 
01365         i++;
01366         (*fn)--;
01367     }
01368         
01369     if (**fn != FULLSTOP)                       // if we are not at a full stop Then Syntax error
01370         return FALSE;
01371         
01372     // Make up the string that we are going to return
01373     // Do it this way as otherwise we would be adding the characters in backwards in the above
01374     // routine as we are scanning backwards!
01375     UINT32 position = 0;    // Start at first character in the string
01376     (*fn)++;            // Move to character after the full stop
01377     while (( i >= 0 ) && (**fn != END_OF_PATH))
01378     {
01379         ext[position++] = **fn;                 // Add current character to File Extension
01380         (*fn)++;                                // Move to next character
01381         i--;                                    // decrement extension letters count
01382     }
01383 
01384     ext[position++] = END_OF_STRING;            // Set end of string 
01385     
01386     return TRUE;
01387 }

BOOL getIdentifier const TCHAR **  fn,
TCHAR identifier,
UINT32  MaxSize,
BOOL *  pBadCharacter
 

Parses file or directory identifier Scope: Private.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/5/93
Parameters:
A pointer to the pointer to the path string [INPUTS] MaxSize - the maximum size of a network drive name A pointer to the current bad character flag
A file or directory identifier [OUTPUTS] A pointer to a potentially new state of the bad character flag which signals a bad/reserved character was found in the string
Returns:
TRUE if parsed ok FALSE otherwise
See also:
PathName();

SetPath();

Returns:
Errors: None

Definition at line 1280 of file pathname.cpp.

01281 {    
01282     UINT32 i = 0;
01283 
01284     // While not a Separator or not EOF or Maximum size
01285     // Used to check for (String::IsAlphaNumeric(**fn) || IsSpecialChar(fn))
01286     // to see if it was a valid character or not but this would not allow things like
01287     // spaces which are allowed under NT and Chicago. Reduce check to known problem
01288     // characters such as colons in the wrong place and '/'.
01289     // but must only flag this as an error and continue as we must have a filename at the
01290     // end so that a m4essage such as 'cannot open file: xxxxx.xx' can be shown by using
01291     // the GetFileName call.
01292     // Removed the FULLSTOP test as this was stopping directory names having full stops in
01293 
01294     while ( **fn != SEPARATOR &&        // If not a separator for next directory/filename
01295             **fn != END_OF_PATH &&      // and not terminator 
01296             i < (MaxSize))              // is less than maximum name size
01297     { 
01298         // Check if this is an illegal character for the filing system and if so
01299         // make a note and continue.
01300         if ( IsReservedChar(fn) )
01301         {
01302             *pBadCharacter = TRUE;      // Flag bad character found
01303         }
01304                     
01305         identifier[i++] = **fn;         // Parse the Identifier
01306         (*fn)++;
01307     }
01308 
01309     // if a valid identifier terminator found then return True
01310     // otherwise return False.
01311     // Do not stop on full stops as these are valid in  directory names.
01312     if (**fn == SEPARATOR ||
01313         **fn == END_OF_PATH)
01314     {    
01315         if (**fn == SEPARATOR)
01316         { 
01317             identifier[i++] = **fn;         // Parse the Separator 
01318         }                   
01319 
01320         identifier[i++] = END_OF_STRING;    // Set end of string 
01321 
01322         return TRUE;
01323     }
01324     else 
01325         return FALSE;
01326 }

BOOL getNetDrive const TCHAR **  fn,
TCHAR drive,
BOOL *  pBadCharacter
 

Parses the network Drive location of file and returns whether this was accomplished or not. The network name will consist of the server name followed by a mount point name. Scope: Private.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/9/93
Parameters:
A pointer to the pointer to the path string [INPUTS] A pointer to the current bad character flag state
A network drive Letter [OUTPUTS] A pointer to the potentially new bad character flag state
Returns:
TRUE if parsed ok FALSE otherwise
See also:
PathName();

SetPath();

Returns:
Errors: None

Definition at line 1185 of file pathname.cpp.

01186 {                                               
01187     // Used for storing either <ServerName> or <DirectoryName> 
01188     String_256 identifier;
01189     TCHAR* pId;
01190         
01191     UINT32 i = 0;
01192                        
01193     if  (**fn == SEPARATOR)                         // Parse '\\' bit
01194     {
01195         drive[i++] = **fn;
01196 
01197         (*fn)++;
01198 
01199         if (**fn == SEPARATOR)                  
01200         {
01201 
01202             drive[i++] = **fn;
01203 
01204             (*fn)++;                        
01205 
01206             identifier.Empty();                     
01207                                                     
01208             // We have a valid network name start
01209             // Parse Network drive name(s)
01210             if ( getIdentifier(&(*fn), identifier, MAXNETNAME, pBadCharacter) )
01211             {
01212                 pId = identifier;                   // Copy identifier into drive
01213 
01214                 while (*pId != END_OF_STRING)
01215                 {
01216                     drive[i++] = *pId;
01217                     pId++;
01218                 }
01219 
01220                 (*fn)++;                        
01221 
01222                 identifier.Empty();
01223 
01224                 // We have a valid network drive name and so parse the mount point name
01225                 if ( getIdentifier(&(*fn), identifier, MAXNETNAME, pBadCharacter) )
01226                 {
01227                     pId = identifier;               // Copy identifier into drive
01228 
01229                     while (*pId != END_OF_STRING)
01230                     {
01231                         drive[i++] = *pId;
01232                         pId++;
01233                     }
01234 
01235                     (*fn)++;                        
01236                 
01237                     drive[i++] = END_OF_STRING;
01238 
01239                     // Everything has gone ok so now exit
01240                     return TRUE;
01241                 }
01242                 else 
01243                     return FALSE;
01244             }
01245             else 
01246                 return FALSE;
01247         }
01248         else 
01249             return FALSE;   
01250     }
01251     else 
01252         return FALSE; 
01253 }

BOOL getParentDirectory const TCHAR **  fn,
TCHAR directory,
UINT32  MaxSize,
const TCHAR StartOfPath
 

Parses from the specified position, which should be something like the first valid character of the filename on the pathname, backwards until we hit either:-

  • a path separator, in which case we return the found name as a possible directory
  • the start of the pathname, in which case there is no directory name. Scope: Private.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/3/95
Parameters:
A pointer to the pointer to the path string [INPUTS] MaxSize - the maximum size of a network drive name StartOfPath - a pointer to the start of the path string
The parent directory name [OUTPUTS]
Returns:
TRUE if parsed ok FALSE otherwise
See also:
GetTruncatedPath();
Returns:
Errors: None

Definition at line 1410 of file pathname.cpp.

01411 {
01412     UINT32 i = 0; 
01413 
01414     // Note where we are in the path
01415     const TCHAR* CurrentPosition = *fn;
01416 
01417     // If we are tsarting on a separator then skip it 
01418     if (**fn == SEPARATOR)
01419         (*fn)--;
01420 
01421     // Search from the specified string end backwards until we find either:-
01422     // - a path separator indicating we have found a potential parent directory.
01423     // - the start of the file indicating no parent directory is present
01424     while ( 
01425             (**fn != SEPARATOR) &&              // is not at a path separating character
01426             (*fn != StartOfPath) &&             // is not at the start of the path string
01427             (i < MaxSize)                       // is not maximum size 
01428           )
01429     { 
01430         i++;
01431         (*fn)--;
01432     }
01433         
01434     if (**fn != SEPARATOR)                      // if we are not at a directory separator
01435         return FALSE;                           //  Then Syntax error
01436         
01437     // Make up the string that we are going to return
01438     // Do it this way as otherwise we would be adding the characters in backwards in the above
01439     // routine as we are scanning backwards!
01440     UINT32 position = 0;    // Start at first character in the string
01441     while (( i >= 0 ) && (*fn != CurrentPosition))
01442     {
01443         directory[position++] = **fn;           // Add current character to directory name
01444         (*fn)++;                                // Move to next character
01445         i--;                                    // decrement directory name letters count
01446     }
01447 
01448     directory[position++] = END_OF_STRING;      // Set end of string 
01449     
01450     return TRUE;
01451 }

BOOL IsDeviceName const String_256 path  ) 
 

Parses a string representing a path and sees if it refers to a device name which would be illegal.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/5/93
Parameters:
String representing a pathname [INPUTS]
None [OUTPUTS]
Returns:
TRUE if the pathname is a device name or FALSE otherwise.

Errors: None

Definition at line 1568 of file pathname.cpp.

01569 {
01570 #if defined(__WXMSW__)  
01571     const INT32         buffer_size = 256;
01572     TCHAR               buffer[buffer_size];            // create buffer of characters
01573     // First use a Windows call to try and see if the pathname supplied is a
01574     // known device name. Use a 256 string as a buffer as not particular bothered
01575     // by what is returned, only if something is returned  
01576     DWORD i;
01577     i = QueryDosDevice(path, buffer, buffer_size);  // See if known Windows device name
01578 
01579     // returns i = number of characters supplied in pBuffer, if 0 then failed
01580     //TRACE( _T("QueryDosDevice returns %d\n"),i);
01581     if (i>0)
01582         return TRUE;                        // valid device name, therefore passes
01583 #endif
01584     
01585     // Check our pathname against some known basic names as a final check
01586     // Device names will in general have three letters with a possible number
01587     // and possible colon on the end.
01588     String_256 temp;                        // general workspace string
01589     
01590     // work out in temp the left most three characters and then compare this with
01591     // some known bad values
01592     path.Left(&temp,4);                     // temp = left most 4 characters of path
01593 
01594     if ( temp.IsIdentical(TEXT(SEPARATOR_SYM) TEXT(SEPARATOR_SYM) TEXT(".") TEXT(SEPARATOR_SYM)))       // NT device name starts with this
01595         return TRUE;                        // if start this then no more checks required
01596 
01597     path.Left(&temp,3);                     // temp = left most 3 characters of path
01598     temp.toUpper();                         // Now convert to upper case
01599 
01600     if ( (temp.IsIdentical(TEXT("LPT"))) ||     // basic DOS print device
01601          (temp.IsIdentical(TEXT("COM"))) ||     // basic DOS communication port
01602          (temp.IsIdentical(TEXT("NUL"))) ||     // basic DOS null device
01603          (temp.IsIdentical(TEXT("AUX"))))       // basic DOS auxiliary port
01604     {
01605         // Check that the length of the name is correct i.e. 3, 4 or 5 long
01606         const TCHAR *dn;                        // device name pointer
01607         dn = path;                          // set to point to the current path
01608         
01609         switch (path.Length())
01610         {
01611             case 3:
01612                 // correct length and passed the test above so its a device name
01613                 // drop through to after case and return True
01614             break;
01615     
01616             case 4:
01617                 // check for number or a colon on the end
01618                 // position is from 0.. and so want character number 3
01619                 dn += 3;                        // point to third character in name                     
01620                 if ( ( !String::IsNumeric(*dn) ) && ( *dn != COLON ) )
01621                     return FALSE;               // not colon or number
01622                 // drop through to after case and return True
01623             break;
01624 
01625             case 5:
01626                 // check for number and colon on the end 
01627                 // position is from 0.. and so want character number 3
01628                 dn += 3;                        // point to third character in name                     
01629                 // first check that the second to last character is a number
01630                 if ( !String::IsNumeric(*dn) )
01631                     return FALSE;               // not a number so return False
01632                 // now check that the last character is a colon
01633                 dn += 1;                        // move to last character
01634                 if ( *dn != COLON )
01635                     return FALSE;               // not a colon so return False
01636                 // drop through to after case and return True
01637             break;
01638         
01639             default:
01640                 // In all other cases can return False as wrong length
01641                 return FALSE;
01642             break;
01643         } // end switch
01644         return TRUE;    // passed above tests so return True
01645     }
01646     else
01647         return FALSE;   // failed in three letter comparisons so not a recognised device
01648 }

BOOL IsReservedChar const TCHAR **  fn  ) 
 

Checks if character passed in is a special character allowed in file names. No longer used. Scope: Private Checks if character passed in is a reserved character allowed in file names. Does not check for terminators which are allowed by the callers such as . and backslash. These characters are considered illegal when converting long to short filenames and so it would seem sensible to limit their use. Scope: Private.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/08/94
Parameters:
A pointer to the pointer to the path string [INPUTS]
None [OUTPUTS]
Returns:
True if the character is a reserved character not allowed in filenames and False otherwise
See also:
PathName();
Returns:
Errors: None

Definition at line 1528 of file pathname.cpp.

01529 {
01530     const TCHAR SLASH       = '/';
01531     const TCHAR OPENSQUARE  = '[';
01532     const TCHAR CLOSESQUARE = ']';
01533     const TCHAR QUOTES      = '"';
01534     const TCHAR COLON_TCHAR = ':';
01535     const TCHAR SEMICOLON   = ';';
01536     const TCHAR COMMA       = ',';
01537     const TCHAR EQUALS      = '=';
01538     
01539     if ((**fn != SLASH) &&
01540         (**fn != OPENSQUARE) &&
01541         (**fn != CLOSESQUARE) &&
01542         (**fn != QUOTES) &&
01543         (**fn != COLON_TCHAR) &&
01544         (**fn != SEMICOLON) &&
01545         (**fn != COMMA) &&
01546         (**fn != EQUALS))
01547         return FALSE;
01548     else
01549         return TRUE;
01550 }


Generated on Sat Nov 10 03:49:35 2007 for Camelot by  doxygen 1.4.4