convert line ends
[canaan.git] / prj / tech / libsrc / cpptools / fnamutil.h
blob05181f9ff9d32d75807cb6ef9b174b9a9684312e
1 ///////////////////////////////////////////////////////////////////////////////
2 // $Source: x:/prj/tech/libsrc/cpptools/RCS/fnamutil.h $
3 // $Author: JAEMZ $
4 // $Date: 1997/08/13 19:01:13 $
5 // $Revision: 1.3 $
6 //
7 // File name string manipulation functions
8 //
9 // (c) Copyright 1995-1996 Tom Leonard. All Rights Reserved. Unlimited license granted to Looking Glass Technologies Inc.
12 #ifndef __FNAMUTIL_H
13 #define __FNAMUTIL_H
15 #if defined(__SC__) || defined(__RCC__)
16 #pragma once
17 #endif
19 #ifndef __cplusplus
20 #error "Need C versions of fnamutil"
21 #endif
23 #define __CPPTOOLSAPI
25 enum eFileCondenseCase
27 kFileNoChange,
28 kFileToLower,
29 kFileToUpper
34 // AddFileSpec()
35 // Combine a path and a (possibly absolute) file spec into a new, reduced path
36 // (e.g. AddFileSpec("c:\\foo\\bar", "..\\include\\bar.h")
37 // becomes ("c:\\foo\\include\\bar.h)
38 // and AddFileSpec("c:\\foo\\bar", "d:\\bar.h")
39 // becomes ("d:\\bar.h))
41 // Returns combined path in malloc'd string caller must free
42 // Returns: FALSE if invalid path (i.e., not all dots were removed,
43 // or illegal relative path)
45 BOOL __stdcall __CPPTOOLSAPI AddFileSpec(const char * pszPath, const char * pszFileSpec, char ** ppszOut);
48 // Compute a relative path between this path and a target
50 // Takes: the anchor, the goal, The output
51 // The result is the path relative to this to get to the target,
52 // or else is the full path to the target
54 BOOL __stdcall __CPPTOOLSAPI ComputeAnchoredPath(const char * pszAnchorPath, const char * pszTargetPathIn, char ** ppszOut);
57 // Validity tests
59 BOOL __stdcall __CPPTOOLSAPI IsValidFileSpec(const char * pszFileSpec);
60 BOOL __stdcall __CPPTOOLSAPI IsValidFilePath(const char * pszFilePath);
63 // Get a full path, return FALSE if invalid
65 BOOL __stdcall __CPPTOOLSAPI GetFullPath(const char * pszPath, char ** ppszOut);
68 // ReduceDots()
69 // In-place lexical dot reduction (e.g., "\\a\\b\\..\\c" -> "a\\c")
71 // Takes: File path or file name
72 // Returns: FALSE if invalid path (i.e., not all dots were removed
73 // or illegal relative path)
75 BOOL __stdcall __CPPTOOLSAPI ReduceDots(char *psz);
79 // Utility functions
81 #define _IsSlash(c) (c == '\\')
84 // Return true if this path is a simple component (i.e., is just a file root & ext)
86 #ifdef __STRING_H
87 inline BOOL IsPathSimpleComponent(const char *p)
89 return (p && *p && *(p+1) != ':' && !strchr(p, '\\'));
91 #endif
94 // Return true if this path is full (i.e., has a drive and root)
96 inline BOOL IsFullPath(const char *p)
98 // Check for start of domain or x:\...
99 if (*p)
101 if (_IsSlash(*p))
102 return _IsSlash(*++p);
104 if (*++p == ':')
105 return _IsSlash(*++p);
107 return FALSE;
111 // Return true if this a relative path (no root, no drive, no domain)
113 inline BOOL IsRelativePath(const char *p)
115 return (!*p || (!_IsSlash(*p) && *(p+1) != ':'));
119 // Return true if this a drive relative path (no root, but perhaps a drive)
121 inline BOOL IsDriveRelativePath(const char *p)
123 if (!*p)
124 return TRUE;
126 if (_IsSlash(*p))
127 return FALSE;
129 if (*++p != ':')
130 return TRUE;
132 return !_IsSlash(*++p);
135 char *GetCondensePathStr(
136 const char *pOriginalPath,
137 char *Path,
138 unsigned nCondenseToLen,
139 eFileCondenseCase CaseChange = kFileNoChange,
140 BOOL bRequireDrive = FALSE);
142 #endif /* __FNAMUTIL_H */